author | Florian Pose <fp@igh-essen.com> |
Fri, 19 Mar 2010 11:05:17 +0100 | |
changeset 1875 | 01d31e749ee2 |
parent 1869 | 14f634f5b613 |
child 1879 | 7539329b5cf6 |
permissions | -rw-r--r-- |
1514
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1 |
/***************************************************************************** |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2 |
* |
1524
e7bdab4d6189
Committed misteriously modified files...
Florian Pose <fp@igh-essen.com>
parents:
1514
diff
changeset
|
3 |
* $Id$ |
1514
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
4 |
* |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
5 |
* Copyright (C) 2006-2009 Florian Pose, Ingenieurgemeinschaft IgH |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
6 |
* |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
7 |
* This file is part of the IgH EtherCAT Master. |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
8 |
* |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it and/or |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
10 |
* modify it under the terms of the GNU General Public License version 2, as |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
11 |
* published by the Free Software Foundation. |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
12 |
* |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
13 |
* The IgH EtherCAT Master is distributed in the hope that it will be useful, |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
16 |
* Public License for more details. |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
17 |
* |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
18 |
* You should have received a copy of the GNU General Public License along |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
19 |
* with the IgH EtherCAT Master; if not, write to the Free Software |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
20 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
21 |
* |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
22 |
* --- |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
23 |
* |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
24 |
* The license mentioned above concerns the source code only. Using the |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
25 |
* EtherCAT technology and brand is only permitted in compliance with the |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
26 |
* industrial property and similar rights of Beckhoff Automation GmbH. |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
27 |
* |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
28 |
****************************************************************************/ |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
29 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
30 |
#include <iostream> |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
31 |
#include <iomanip> |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
32 |
#include <string.h> |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
33 |
using namespace std; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
34 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
35 |
#include "CommandCStruct.h" |
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
36 |
#include "MasterDevice.h" |
1514
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
37 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
38 |
/*****************************************************************************/ |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
39 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
40 |
CommandCStruct::CommandCStruct(): |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
41 |
Command("cstruct", "Generate slave PDO information in C language.") |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
42 |
{ |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
43 |
} |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
44 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
45 |
/*****************************************************************************/ |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
46 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
47 |
string CommandCStruct::helpString() const |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
48 |
{ |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
49 |
stringstream str; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
50 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
51 |
str << getName() << " [OPTIONS]" << endl |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
52 |
<< endl |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
53 |
<< getBriefDescription() << endl |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
54 |
<< endl |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
55 |
<< "The output C code can be used directly with the" << endl |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
56 |
<< "ecrt_slave_config_pdos() function of the application" << endl |
1804 | 57 |
<< "interface." << endl |
1514
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
58 |
<< endl |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
59 |
<< "Command-specific options:" << endl |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
60 |
<< " --alias -a <alias>" << endl |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
61 |
<< " --position -p <pos> Slave selection. See the help of" << endl |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
62 |
<< " the 'slaves' command." << endl |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
63 |
<< endl |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
64 |
<< numericInfo(); |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
65 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
66 |
return str.str(); |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
67 |
} |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
68 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
69 |
/****************************************************************************/ |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
70 |
|
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
71 |
void CommandCStruct::execute(const StringVector &args) |
1514
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
72 |
{ |
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1827
diff
changeset
|
73 |
MasterIndexList masterIndices; |
1514
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
74 |
SlaveList slaves; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
75 |
SlaveList::const_iterator si; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
76 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
77 |
if (args.size()) { |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
78 |
stringstream err; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
79 |
err << "'" << getName() << "' takes no arguments!"; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
80 |
throwInvalidUsageException(err); |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
81 |
} |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
82 |
|
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1827
diff
changeset
|
83 |
masterIndices = getMasterIndices(); |
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
84 |
MasterIndexList::const_iterator mi; |
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1827
diff
changeset
|
85 |
for (mi = masterIndices.begin(); |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1827
diff
changeset
|
86 |
mi != masterIndices.end(); mi++) { |
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
87 |
MasterDevice m(*mi); |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
88 |
m.open(MasterDevice::Read); |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
89 |
slaves = selectedSlaves(m); |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
90 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
91 |
for (si = slaves.begin(); si != slaves.end(); si++) { |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
92 |
generateSlaveCStruct(m, *si); |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
93 |
} |
1514
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
94 |
} |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
95 |
} |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
96 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
97 |
/****************************************************************************/ |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
98 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
99 |
void CommandCStruct::generateSlaveCStruct( |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
100 |
MasterDevice &m, |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
101 |
const ec_ioctl_slave_t &slave |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
102 |
) |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
103 |
{ |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
104 |
ec_ioctl_slave_sync_t sync; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
105 |
ec_ioctl_slave_sync_pdo_t pdo; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
106 |
ec_ioctl_slave_sync_pdo_entry_t entry; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
107 |
unsigned int i, j, k, pdo_pos = 0, entry_pos = 0; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
108 |
stringstream id, syncs, pdos, entries; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
109 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
110 |
if (!slave.sync_count) |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
111 |
return; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
112 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
113 |
id << "slave_" << dec << slave.position << "_"; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
114 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
115 |
for (i = 0; i < slave.sync_count; i++) { |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
116 |
m.getSync(&sync, slave.position, i); |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
117 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
118 |
syncs << " {" << dec << sync.sync_index |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
119 |
<< ", " << (EC_READ_BIT(&sync.control_register, 2) ? |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
120 |
"EC_DIR_OUTPUT" : "EC_DIR_INPUT") |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
121 |
<< ", " << dec << (unsigned int) sync.pdo_count |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
122 |
<< ", "; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
123 |
if (sync.pdo_count) { |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
124 |
syncs << id.str() << "pdos + " << dec << pdo_pos; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
125 |
} else { |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
126 |
syncs << "NULL"; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
127 |
} |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
128 |
syncs << ", " << (EC_READ_BIT(&sync.control_register, 6) ? |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
129 |
"EC_WD_ENABLE" : "EC_WD_DISABLE") |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
130 |
<< "},"; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
131 |
syncs << endl; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
132 |
pdo_pos += sync.pdo_count; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
133 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
134 |
for (j = 0; j < sync.pdo_count; j++) { |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
135 |
m.getPdo(&pdo, slave.position, i, j); |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
136 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
137 |
pdos << " {0x" << hex << setfill('0') |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
138 |
<< setw(4) << pdo.index |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
139 |
<< ", " << dec << (unsigned int) pdo.entry_count |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
140 |
<< ", "; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
141 |
if (pdo.entry_count) { |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
142 |
pdos << id.str() << "pdo_entries + " << dec << entry_pos; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
143 |
} else { |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
144 |
pdos << "NULL"; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
145 |
} |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
146 |
pdos << "},"; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
147 |
if (strlen((const char *) pdo.name)) { |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
148 |
pdos << " /* " << pdo.name << " */"; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
149 |
} |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
150 |
pdos << endl; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
151 |
entry_pos += pdo.entry_count; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
152 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
153 |
for (k = 0; k < pdo.entry_count; k++) { |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
154 |
m.getPdoEntry(&entry, slave.position, i, j, k); |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
155 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
156 |
entries << " {0x" << hex << setfill('0') |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
157 |
<< setw(4) << entry.index |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
158 |
<< ", 0x" << setw(2) << (unsigned int) entry.subindex |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
159 |
<< ", " << dec << (unsigned int) entry.bit_length |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
160 |
<< "},"; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
161 |
if (strlen((const char *) entry.name)) { |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
162 |
entries << " /* " << entry.name << " */"; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
163 |
} |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
164 |
entries << endl; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
165 |
} |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
166 |
} |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
167 |
} |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
168 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
169 |
cout |
1827
489be2180f71
Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
170 |
<< "/* Master " << m.getIndex() << ", Slave " << slave.position; |
1514
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
171 |
if (strlen(slave.order)) { |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
172 |
cout << ", \"" << slave.order << "\""; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
173 |
} |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
174 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
175 |
cout << endl |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
176 |
<< " * Vendor ID: 0x" << hex << setfill('0') |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
177 |
<< setw(8) << slave.vendor_id << endl |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
178 |
<< " * Product code: 0x" << hex << setfill('0') |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
179 |
<< setw(8) << slave.product_code << endl |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
180 |
<< " * Revision number: 0x" << hex << setfill('0') |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
181 |
<< setw(8) << slave.revision_number << endl |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
182 |
<< " */" << endl |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
183 |
<< endl; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
184 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
185 |
if (entry_pos) { |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
186 |
cout << "ec_pdo_entry_info_t " << id.str() |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
187 |
<< "pdo_entries[] = {" << endl |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
188 |
<< entries.str() |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
189 |
<< "};" << endl |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
190 |
<< endl; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
191 |
} |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
192 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
193 |
if (pdo_pos) { |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
194 |
cout << "ec_pdo_info_t " << id.str() << "pdos[] = {" << endl |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
195 |
<< pdos.str() |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
196 |
<< "};" << endl |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
197 |
<< endl; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
198 |
} |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
199 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
200 |
cout << "ec_sync_info_t " << id.str() << "syncs[] = {" << endl |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
201 |
<< syncs.str() |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
202 |
<< "};" << endl |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
203 |
<< endl; |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
204 |
} |
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
205 |
|
85ac1c91045d
Added 'ethercat cstruct' command to output PDO information in C language.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
206 |
/*****************************************************************************/ |