author | Florian Pose <fp@igh-essen.com> |
Fri, 15 May 2009 09:06:28 +0000 | |
changeset 1466 | 362147819ca1 |
parent 1456 | bd1f69a429f3 |
child 1467 | 013a4e42a9fb |
permissions | -rw-r--r-- |
1142 | 1 |
/***************************************************************************** |
2 |
* |
|
1363
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
3 |
* $Id$ |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
4 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
5 |
* Copyright (C) 2006-2009 Florian Pose, Ingenieurgemeinschaft IgH |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
6 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
7 |
* This file is part of the IgH EtherCAT Master. |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
8 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it and/or |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
10 |
* modify it under the terms of the GNU General Public License version 2, as |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
11 |
* published by the Free Software Foundation. |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
12 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
13 |
* The IgH EtherCAT Master is distributed in the hope that it will be useful, |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
16 |
* Public License for more details. |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
17 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
18 |
* You should have received a copy of the GNU General Public License along |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
19 |
* with the IgH EtherCAT Master; if not, write to the Free Software |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
20 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
21 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
22 |
* --- |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
23 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
24 |
* The license mentioned above concerns the source code only. Using the |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
25 |
* EtherCAT technology and brand is only permitted in compliance with the |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
26 |
* industrial property and similar rights of Beckhoff Automation GmbH. |
1142 | 27 |
* |
28 |
****************************************************************************/ |
|
29 |
||
30 |
#include <list> |
|
31 |
#include <iostream> |
|
32 |
#include <iomanip> |
|
33 |
#include <sstream> |
|
34 |
using namespace std; |
|
35 |
||
36 |
#include "CommandConfig.h" |
|
37 |
||
38 |
/*****************************************************************************/ |
|
39 |
||
40 |
CommandConfig::CommandConfig(): |
|
41 |
Command("config", "Show slave configurations.") |
|
42 |
{ |
|
43 |
} |
|
44 |
||
45 |
/*****************************************************************************/ |
|
46 |
||
47 |
string CommandConfig::helpString() const |
|
48 |
{ |
|
49 |
stringstream str; |
|
50 |
||
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
51 |
str << getName() << " [OPTIONS]" << endl |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
52 |
<< endl |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
53 |
<< getBriefDescription() << endl |
1142 | 54 |
<< endl |
55 |
<< "Without the --verbose option, slave configurations are" << endl |
|
56 |
<< "output one-per-line. Example:" << endl |
|
57 |
<< endl |
|
1147
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
58 |
<< "1001:0 0x0000003b/0x02010000 3 OP" << endl |
1142 | 59 |
<< "| | | |" << endl |
1147
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
60 |
<< "| | | \\- Application-layer" << endl |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
61 |
<< "| | | state of the attached" << endl |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
62 |
<< "| | | slave, or '-', if no" << endl |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
63 |
<< "| | | slave is attached." << endl |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
64 |
<< "| | \\- Absolute decimal ring" << endl |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
65 |
<< "| | position of the attached" << endl |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
66 |
<< "| | slave, or '-' if none" << endl |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
67 |
<< "| | attached." << endl |
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
68 |
<< "| \\- Expected vendor ID and product code (both" << endl |
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
69 |
<< "| hexadecimal)." << endl |
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
70 |
<< "\\- Alias address and relative position (both decimal)." << endl |
1142 | 71 |
<< endl |
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
72 |
<< "With the --verbose option given, the configured PDOs and" << endl |
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
73 |
<< "SDOs are output in addition." << endl |
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
74 |
<< endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
75 |
<< "Configuration selection:" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
76 |
<< " Slave configurations can be selected with" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
77 |
<< " the --alias and --position parameters as follows:" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
78 |
<< endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
79 |
<< " 1) If neither the --alias nor the --position option" << endl |
1167 | 80 |
<< " is given, all slave configurations are displayed." << endl |
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
81 |
<< " 2) If only the --position option is given, an alias" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
82 |
<< " of zero is assumed (see 4))." << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
83 |
<< " 3) If only the --alias option is given, all slave" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
84 |
<< " configurations with the given alias address" << endl |
1167 | 85 |
<< " are displayed." << endl |
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
86 |
<< " 4) If both the --alias and the --position option are" << endl |
1167 | 87 |
<< " given, the selection can match a single" << endl |
88 |
<< " configuration, that is displayed, if it exists." << endl |
|
1142 | 89 |
<< endl |
90 |
<< "Command-specific options:" << endl |
|
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
91 |
<< " --alias -a <alias> Configuration alias (see above)." << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
92 |
<< " --position -p <pos> Relative position (see above)." << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
93 |
<< " --verbose -v Show detailed configurations." << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
94 |
<< endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1156
diff
changeset
|
95 |
<< numericInfo(); |
1142 | 96 |
|
97 |
return str.str(); |
|
98 |
} |
|
99 |
||
100 |
/*****************************************************************************/ |
|
101 |
||
102 |
/** Lists the bus configuration. |
|
103 |
*/ |
|
104 |
void CommandConfig::execute(MasterDevice &m, const StringVector &args) |
|
105 |
{ |
|
1156
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1148
diff
changeset
|
106 |
ConfigList configs; |
1142 | 107 |
|
1373
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
108 |
if (args.size()) { |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
109 |
stringstream err; |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
110 |
err << "'" << getName() << "' takes no arguments!"; |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
111 |
throwInvalidUsageException(err); |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
112 |
} |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
113 |
|
1142 | 114 |
m.open(MasterDevice::Read); |
1156
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1148
diff
changeset
|
115 |
configs = selectedConfigs(m); |
1142 | 116 |
|
117 |
if (getVerbosity() == Verbose) { |
|
1156
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1148
diff
changeset
|
118 |
showDetailedConfigs(m, configs); |
1142 | 119 |
} else { |
1156
ecaf2a896ea3
Implemented alias and position for configs.
Florian Pose <fp@igh-essen.com>
parents:
1148
diff
changeset
|
120 |
listConfigs(m, configs); |
1142 | 121 |
} |
122 |
} |
|
123 |
||
124 |
/*****************************************************************************/ |
|
125 |
||
126 |
/** Lists the complete bus configuration. |
|
127 |
*/ |
|
128 |
void CommandConfig::showDetailedConfigs( |
|
129 |
MasterDevice &m, |
|
130 |
const ConfigList &configList |
|
131 |
) |
|
132 |
{ |
|
133 |
ConfigList::const_iterator configIter; |
|
134 |
unsigned int j, k, l; |
|
1147
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
135 |
ec_ioctl_slave_t slave; |
1142 | 136 |
ec_ioctl_config_pdo_t pdo; |
137 |
ec_ioctl_config_pdo_entry_t entry; |
|
138 |
ec_ioctl_config_sdo_t sdo; |
|
139 |
||
140 |
for (configIter = configList.begin(); |
|
141 |
configIter != configList.end(); |
|
142 |
configIter++) { |
|
143 |
||
144 |
cout << "Alias: " |
|
145 |
<< dec << configIter->alias << endl |
|
146 |
<< "Position: " << configIter->position << endl |
|
147 |
<< "Vendor Id: 0x" |
|
148 |
<< hex << setfill('0') |
|
149 |
<< setw(8) << configIter->vendor_id << endl |
|
150 |
<< "Product code: 0x" |
|
151 |
<< setw(8) << configIter->product_code << endl |
|
1147
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
152 |
<< "Attached slave: "; |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
153 |
|
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
154 |
if (configIter->slave_position != -1) { |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
155 |
m.getSlave(&slave, configIter->slave_position); |
1172
74ee632c3b5e
Fixed attached slave position in 'ethercat config' -> decimal.
Florian Pose <fp@igh-essen.com>
parents:
1167
diff
changeset
|
156 |
cout << dec << configIter->slave_position |
1148
1762296870bd
Renamed state field to al_state.
Florian Pose <fp@igh-essen.com>
parents:
1147
diff
changeset
|
157 |
<< " (" << alStateString(slave.al_state) << ")" << endl; |
1147
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
158 |
} else { |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
159 |
cout << "none" << endl; |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
160 |
} |
1142 | 161 |
|
162 |
for (j = 0; j < EC_MAX_SYNC_MANAGERS; j++) { |
|
163 |
if (configIter->syncs[j].pdo_count) { |
|
164 |
cout << "SM" << dec << j << " (" |
|
165 |
<< (configIter->syncs[j].dir == EC_DIR_INPUT |
|
166 |
? "Input" : "Output") << ")" << endl; |
|
167 |
for (k = 0; k < configIter->syncs[j].pdo_count; k++) { |
|
168 |
m.getConfigPdo(&pdo, configIter->config_index, j, k); |
|
169 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
170 |
cout << " PDO 0x" << hex << setw(4) << pdo.index << endl; |
1142 | 171 |
|
172 |
for (l = 0; l < pdo.entry_count; l++) { |
|
173 |
m.getConfigPdoEntry(&entry, |
|
174 |
configIter->config_index, j, k, l); |
|
175 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
176 |
cout << " PDO entry 0x" << hex << setfill('0') |
1142 | 177 |
<< setw(4) << entry.index << ":" |
178 |
<< setw(2) << (unsigned int) entry.subindex |
|
1188
3b4e82d9904b
Don't show Pdo (entry) names in configuration output.
Florian Pose <fp@igh-essen.com>
parents:
1172
diff
changeset
|
179 |
<< ", " << dec << setfill(' ') |
3b4e82d9904b
Don't show Pdo (entry) names in configuration output.
Florian Pose <fp@igh-essen.com>
parents:
1172
diff
changeset
|
180 |
<< setw(2) << (unsigned int) entry.bit_length |
3b4e82d9904b
Don't show Pdo (entry) names in configuration output.
Florian Pose <fp@igh-essen.com>
parents:
1172
diff
changeset
|
181 |
<< " bit" << endl; |
1142 | 182 |
} |
183 |
} |
|
184 |
} |
|
185 |
} |
|
186 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1254
diff
changeset
|
187 |
cout << "SDO configuration:" << endl; |
1142 | 188 |
if (configIter->sdo_count) { |
189 |
for (j = 0; j < configIter->sdo_count; j++) { |
|
190 |
m.getConfigSdo(&sdo, configIter->config_index, j); |
|
191 |
||
192 |
cout << " 0x" |
|
193 |
<< hex << setfill('0') |
|
194 |
<< setw(4) << sdo.index << ":" |
|
195 |
<< setw(2) << (unsigned int) sdo.subindex |
|
196 |
<< ", " << dec << sdo.size << " byte: " << hex; |
|
197 |
||
198 |
switch (sdo.size) { |
|
199 |
case 1: |
|
200 |
cout << "0x" << setw(2) |
|
201 |
<< (unsigned int) *(uint8_t *) &sdo.data; |
|
202 |
break; |
|
203 |
case 2: |
|
204 |
cout << "0x" << setw(4) |
|
1254
c19d273a9e76
Moved byteorder macros to ecrt.h.
Florian Pose <fp@igh-essen.com>
parents:
1188
diff
changeset
|
205 |
<< le16_to_cpup(&sdo.data); |
1142 | 206 |
break; |
207 |
case 4: |
|
208 |
cout << "0x" << setw(8) |
|
1254
c19d273a9e76
Moved byteorder macros to ecrt.h.
Florian Pose <fp@igh-essen.com>
parents:
1188
diff
changeset
|
209 |
<< le32_to_cpup(&sdo.data); |
1142 | 210 |
break; |
211 |
default: |
|
212 |
cout << "???"; |
|
213 |
} |
|
214 |
||
215 |
cout << endl; |
|
216 |
} |
|
217 |
} else { |
|
218 |
cout << " None." << endl; |
|
219 |
} |
|
220 |
||
1455
aa18fcfe0fd1
Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
221 |
if (configIter->dc_assign_activate) { |
aa18fcfe0fd1
Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
222 |
int i; |
aa18fcfe0fd1
Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
223 |
|
aa18fcfe0fd1
Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
224 |
cout << "DC configuration:" << endl |
aa18fcfe0fd1
Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
225 |
<< " AssignActivate: 0x" << hex << setfill('0') |
aa18fcfe0fd1
Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
226 |
<< setw(4) << configIter->dc_assign_activate << endl; |
aa18fcfe0fd1
Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
227 |
|
1456
bd1f69a429f3
Fixed output of 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1455
diff
changeset
|
228 |
cout << " Cycle [ns] Shift [ns]" << endl; |
1455
aa18fcfe0fd1
Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
229 |
for (i = 0; i < EC_SYNC_SIGNAL_COUNT; i++) { |
1456
bd1f69a429f3
Fixed output of 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1455
diff
changeset
|
230 |
cout << " SYNC" << dec << i << " " |
bd1f69a429f3
Fixed output of 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1455
diff
changeset
|
231 |
<< setfill(' ') << right |
1455
aa18fcfe0fd1
Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
232 |
<< setw(11) << configIter->dc_sync[i].cycle_time |
1456
bd1f69a429f3
Fixed output of 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1455
diff
changeset
|
233 |
<< " " |
1455
aa18fcfe0fd1
Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
234 |
<< setw(11) << configIter->dc_sync[i].shift_time |
aa18fcfe0fd1
Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
235 |
<< endl; |
aa18fcfe0fd1
Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
236 |
} |
aa18fcfe0fd1
Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
237 |
} |
1142 | 238 |
cout << endl; |
239 |
} |
|
240 |
} |
|
241 |
||
242 |
/*****************************************************************************/ |
|
243 |
||
244 |
/** Lists the bus configuration. |
|
245 |
*/ |
|
1147
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
246 |
void CommandConfig::listConfigs( |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
247 |
MasterDevice &m, |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
248 |
const ConfigList &configList |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
249 |
) |
1142 | 250 |
{ |
251 |
ConfigList::const_iterator configIter; |
|
252 |
stringstream str; |
|
253 |
Info info; |
|
254 |
typedef list<Info> InfoList; |
|
255 |
InfoList list; |
|
256 |
InfoList::const_iterator iter; |
|
257 |
unsigned int maxAliasWidth = 0, maxPosWidth = 0, |
|
1147
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
258 |
maxSlavePosWidth = 0, maxStateWidth = 0; |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
259 |
ec_ioctl_slave_t slave; |
1142 | 260 |
|
261 |
for (configIter = configList.begin(); |
|
262 |
configIter != configList.end(); |
|
263 |
configIter++) { |
|
264 |
||
265 |
str << dec << configIter->alias; |
|
266 |
info.alias = str.str(); |
|
267 |
str.clear(); |
|
268 |
str.str(""); |
|
269 |
||
270 |
str << configIter->position; |
|
271 |
info.pos = str.str(); |
|
272 |
str.clear(); |
|
273 |
str.str(""); |
|
274 |
||
275 |
str << hex << setfill('0') |
|
276 |
<< "0x" << setw(8) << configIter->vendor_id |
|
277 |
<< "/0x" << setw(8) << configIter->product_code; |
|
278 |
info.ident = str.str(); |
|
279 |
str.clear(); |
|
280 |
str.str(""); |
|
281 |
||
1147
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
282 |
if (configIter->slave_position != -1) { |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
283 |
m.getSlave(&slave, configIter->slave_position); |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
284 |
|
1172
74ee632c3b5e
Fixed attached slave position in 'ethercat config' -> decimal.
Florian Pose <fp@igh-essen.com>
parents:
1167
diff
changeset
|
285 |
str << dec << configIter->slave_position; |
1147
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
286 |
info.slavePos = str.str(); |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
287 |
str.clear(); |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
288 |
str.str(""); |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
289 |
|
1148
1762296870bd
Renamed state field to al_state.
Florian Pose <fp@igh-essen.com>
parents:
1147
diff
changeset
|
290 |
str << alStateString(slave.al_state); |
1147
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
291 |
info.state = str.str(); |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
292 |
str.clear(); |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
293 |
str.str(""); |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
294 |
} else { |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
295 |
str << "-"; |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
296 |
info.slavePos = str.str(); |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
297 |
str.clear(); |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
298 |
str.str(""); |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
299 |
|
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
300 |
str << "-"; |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
301 |
info.state = str.str(); |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
302 |
str.clear(); |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
303 |
str.str(""); |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
304 |
} |
1142 | 305 |
|
306 |
list.push_back(info); |
|
307 |
||
308 |
if (info.alias.length() > maxAliasWidth) |
|
309 |
maxAliasWidth = info.alias.length(); |
|
310 |
if (info.pos.length() > maxPosWidth) |
|
311 |
maxPosWidth = info.pos.length(); |
|
1147
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
312 |
if (info.slavePos.length() > maxSlavePosWidth) |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
313 |
maxSlavePosWidth = info.slavePos.length(); |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
314 |
if (info.state.length() > maxStateWidth) |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
315 |
maxStateWidth = info.state.length(); |
1142 | 316 |
} |
317 |
||
318 |
for (iter = list.begin(); iter != list.end(); iter++) { |
|
319 |
cout << setfill(' ') << right |
|
320 |
<< setw(maxAliasWidth) << iter->alias |
|
321 |
<< ":" << left |
|
322 |
<< setw(maxPosWidth) << iter->pos |
|
323 |
<< " " |
|
324 |
<< iter->ident |
|
325 |
<< " " |
|
1147
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
326 |
<< setw(maxSlavePosWidth) << iter->slavePos << " " |
0eac1ee8512a
Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
1144
diff
changeset
|
327 |
<< setw(maxStateWidth) << iter->state << " " |
1142 | 328 |
<< endl; |
329 |
} |
|
330 |
} |
|
331 |
||
332 |
/*****************************************************************************/ |