author | Florian Pose <fp@igh-essen.com> |
Fri, 30 Nov 2012 15:24:38 +0100 | |
branch | stable-1.5 |
changeset 2452 | abc1d1caead7 |
parent 2369 | 2536d60dea6e |
child 2453 | d461b1f07296 |
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 <iostream> |
|
31 |
#include <iomanip> |
|
32 |
using namespace std; |
|
33 |
||
34 |
#include "CommandDomains.h" |
|
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
35 |
#include "MasterDevice.h" |
1142 | 36 |
|
37 |
/*****************************************************************************/ |
|
38 |
||
39 |
CommandDomains::CommandDomains(): |
|
40 |
Command("domains", "Show configured domains.") |
|
41 |
{ |
|
42 |
} |
|
43 |
||
44 |
/*****************************************************************************/ |
|
45 |
||
1968
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1955
diff
changeset
|
46 |
string CommandDomains::helpString(const string &binaryBaseName) const |
1142 | 47 |
{ |
48 |
stringstream str; |
|
49 |
||
1968
4f682084c643
Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents:
1955
diff
changeset
|
50 |
str << binaryBaseName << " " << getName() << " [OPTIONS]" << endl |
1142 | 51 |
<< endl |
1804 | 52 |
<< getBriefDescription() << endl |
53 |
<< endl |
|
54 |
<< "Without the --verbose option, the domains are displayed" << endl |
|
1142 | 55 |
<< "one-per-line. Example:" << endl |
1804 | 56 |
<< endl |
57 |
<< "Domain0: LogBaseAddr 0x00000000, Size 6, WorkingCounter 0/1" |
|
58 |
<< endl << endl |
|
59 |
<< "The domain's base address for the logical datagram" << endl |
|
60 |
<< "(LRD/LWR/LRW) is displayed followed by the domain's" << endl |
|
61 |
<< "process data size in byte. The last values are the current" << endl |
|
62 |
<< "datagram working counter sum and the expected working" << endl |
|
63 |
<< "counter sum. If the values are equal, all PDOs were" << endl |
|
1167 | 64 |
<< "exchanged during the last cycle." << endl |
65 |
<< endl |
|
1804 | 66 |
<< "If the --verbose option is given, the participating slave" << endl |
67 |
<< "configurations/FMMUs and the current process data are" << endl |
|
68 |
<< "additionally displayed:" << endl |
|
69 |
<< endl |
|
70 |
<< "Domain1: LogBaseAddr 0x00000006, Size 6, WorkingCounter 0/1" |
|
71 |
<< endl |
|
72 |
<< " SlaveConfig 1001:0, SM3 ( Input), LogAddr 0x00000006, Size 6" |
|
73 |
<< endl |
|
1955
09c2bd224d3f
Dropped '0x' before process data bytes to fit on an 80 col console.
Florian Pose <fp@igh-essen.com>
parents:
1869
diff
changeset
|
74 |
<< " 00 00 00 00 00 00" << endl |
1804 | 75 |
<< endl |
76 |
<< "The process data are displayed as hexadecimal bytes." << endl |
|
77 |
<< endl |
|
78 |
<< "Command-specific options:" << endl |
|
79 |
<< " --domain -d <index> Positive numerical domain index." << endl |
|
80 |
<< " If ommitted, all domains are" << endl |
|
1167 | 81 |
<< " displayed." << endl |
1804 | 82 |
<< endl |
83 |
<< " --verbose -v Show FMMUs and process data" << endl |
|
84 |
<< " in addition." << endl |
|
85 |
<< endl |
|
86 |
<< numericInfo(); |
|
1142 | 87 |
|
1804 | 88 |
return str.str(); |
1142 | 89 |
} |
90 |
||
91 |
/****************************************************************************/ |
|
92 |
||
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
93 |
void CommandDomains::execute(const StringVector &args) |
1142 | 94 |
{ |
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1827
diff
changeset
|
95 |
MasterIndexList masterIndices; |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1827
diff
changeset
|
96 |
bool doIndent; |
1804 | 97 |
DomainList domains; |
98 |
DomainList::const_iterator di; |
|
99 |
||
1373
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
100 |
if (args.size()) { |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
101 |
stringstream err; |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
102 |
err << "'" << getName() << "' takes no arguments!"; |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
103 |
throwInvalidUsageException(err); |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
104 |
} |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
105 |
|
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1827
diff
changeset
|
106 |
masterIndices = getMasterIndices(); |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1827
diff
changeset
|
107 |
doIndent = masterIndices.size() > 1; |
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
108 |
MasterIndexList::const_iterator mi; |
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1827
diff
changeset
|
109 |
for (mi = masterIndices.begin(); |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1827
diff
changeset
|
110 |
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
|
111 |
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
|
112 |
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
|
113 |
domains = selectedDomains(m); |
1142 | 114 |
|
1827
489be2180f71
Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
115 |
if (domains.size() && doIndent) { |
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
116 |
cout << "Master" << dec << *mi << endl; |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
117 |
} |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
118 |
|
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
119 |
for (di = domains.begin(); di != domains.end(); di++) { |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
120 |
showDomain(m, *di, doIndent); |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
121 |
} |
1804 | 122 |
} |
1142 | 123 |
} |
124 |
||
125 |
/****************************************************************************/ |
|
126 |
||
1166 | 127 |
void CommandDomains::showDomain( |
1804 | 128 |
MasterDevice &m, |
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
129 |
const ec_ioctl_domain_t &domain, |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
130 |
bool doIndent |
1804 | 131 |
) |
1142 | 132 |
{ |
133 |
unsigned char *processData; |
|
134 |
ec_ioctl_domain_data_t data; |
|
135 |
unsigned int i, j; |
|
136 |
ec_ioctl_domain_fmmu_t fmmu; |
|
137 |
unsigned int dataOffset; |
|
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
138 |
string indent(doIndent ? " " : ""); |
2369
2536d60dea6e
Partial WC output in domains command.
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
139 |
unsigned int wc_sum = 0, dev_idx; |
2536d60dea6e
Partial WC output in domains command.
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
140 |
|
2536d60dea6e
Partial WC output in domains command.
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
141 |
for (dev_idx = 0; dev_idx < EC_NUM_DEVICES; dev_idx++) { |
2536d60dea6e
Partial WC output in domains command.
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
142 |
wc_sum += domain.working_counter[dev_idx]; |
2536d60dea6e
Partial WC output in domains command.
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
143 |
} |
1804 | 144 |
|
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
145 |
cout << indent << "Domain" << dec << domain.index << ":" |
1804 | 146 |
<< " LogBaseAddr 0x" |
147 |
<< hex << setfill('0') |
|
1142 | 148 |
<< setw(8) << domain.logical_base_address |
1804 | 149 |
<< ", Size " << dec << setfill(' ') |
1142 | 150 |
<< setw(3) << domain.data_size |
1804 | 151 |
<< ", WorkingCounter " |
2369
2536d60dea6e
Partial WC output in domains command.
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
152 |
<< wc_sum << "/" |
2536d60dea6e
Partial WC output in domains command.
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
153 |
<< domain.expected_working_counter; |
2536d60dea6e
Partial WC output in domains command.
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
154 |
if (EC_NUM_DEVICES == 2) { |
2536d60dea6e
Partial WC output in domains command.
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
155 |
cout << " (" << domain.working_counter[EC_DEVICE_MAIN] |
2536d60dea6e
Partial WC output in domains command.
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
156 |
<< "+" << domain.working_counter[EC_DEVICE_BACKUP] |
2536d60dea6e
Partial WC output in domains command.
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
157 |
<< ")"; |
2536d60dea6e
Partial WC output in domains command.
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
158 |
} |
2536d60dea6e
Partial WC output in domains command.
Florian Pose <fp@igh-essen.com>
parents:
1968
diff
changeset
|
159 |
cout << endl; |
1142 | 160 |
|
161 |
if (!domain.data_size || getVerbosity() != Verbose) |
|
162 |
return; |
|
163 |
||
164 |
processData = new unsigned char[domain.data_size]; |
|
165 |
||
166 |
try { |
|
1166 | 167 |
m.getData(&data, domain.index, domain.data_size, processData); |
1142 | 168 |
} catch (MasterDeviceException &e) { |
169 |
delete [] processData; |
|
170 |
throw e; |
|
171 |
} |
|
172 |
||
173 |
for (i = 0; i < domain.fmmu_count; i++) { |
|
1166 | 174 |
m.getFmmu(&fmmu, domain.index, i); |
1142 | 175 |
|
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
176 |
cout << indent << " SlaveConfig " |
1142 | 177 |
<< dec << fmmu.slave_config_alias |
178 |
<< ":" << fmmu.slave_config_position |
|
179 |
<< ", SM" << (unsigned int) fmmu.sync_index << " (" |
|
180 |
<< setfill(' ') << setw(6) |
|
181 |
<< (fmmu.dir == EC_DIR_INPUT ? "Input" : "Output") |
|
182 |
<< "), LogAddr 0x" |
|
183 |
<< hex << setfill('0') |
|
184 |
<< setw(8) << fmmu.logical_address |
|
185 |
<< ", Size " << dec << fmmu.data_size << endl; |
|
186 |
||
187 |
dataOffset = fmmu.logical_address - domain.logical_base_address; |
|
188 |
if (dataOffset + fmmu.data_size > domain.data_size) { |
|
189 |
stringstream err; |
|
190 |
delete [] processData; |
|
191 |
err << "Fmmu information corrupted!"; |
|
192 |
throwCommandException(err); |
|
193 |
} |
|
194 |
||
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
195 |
cout << indent << " " << hex << setfill('0'); |
1142 | 196 |
for (j = 0; j < fmmu.data_size; j++) { |
197 |
if (j && !(j % BreakAfterBytes)) |
|
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
198 |
cout << endl << indent << " "; |
1955
09c2bd224d3f
Dropped '0x' before process data bytes to fit on an 80 col console.
Florian Pose <fp@igh-essen.com>
parents:
1869
diff
changeset
|
199 |
cout << setw(2) |
1142 | 200 |
<< (unsigned int) *(processData + dataOffset + j) << " "; |
201 |
} |
|
202 |
cout << endl; |
|
203 |
} |
|
204 |
||
205 |
delete [] processData; |
|
206 |
} |
|
207 |
||
208 |
/*****************************************************************************/ |