author | Florian Pose |
Tue, 13 Feb 2018 17:16:01 +0100 | |
branch | stable-1.5 |
changeset 2698 | 9e65f782e8a1 |
parent 2694 | ab97efc5513a |
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 "CommandSdos.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 |
CommandSdos::CommandSdos(): |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1184
diff
changeset
|
40 |
SdoCommand("sdos", "List SDO dictionaries.") |
1142 | 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:
1869
diff
changeset
|
46 |
string CommandSdos::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:
1869
diff
changeset
|
50 |
str << binaryBaseName << " " << getName() << " [OPTIONS]" << endl |
1804 | 51 |
<< endl |
52 |
<< getBriefDescription() << endl |
|
53 |
<< endl |
|
54 |
<< "SDO dictionary information is displayed in two layers," << endl |
|
55 |
<< "which are indented accordingly:" << endl |
|
56 |
<< endl |
|
57 |
<< "1) SDOs - Hexadecimal SDO index and the name. Example:" << endl |
|
58 |
<< endl |
|
59 |
<< " SDO 0x1018, \"Identity object\"" << endl |
|
60 |
<< endl |
|
61 |
<< "2) SDO entries - SDO index and SDO entry subindex (both" << endl |
|
62 |
<< " hexadecimal) followed by the access rights (see" << endl |
|
1382
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
63 |
<< " below), the data type, the length in bit, and the" << endl |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
64 |
<< " description. Example:" << endl |
1804 | 65 |
<< endl |
66 |
<< " 0x1018:01, rwrwrw, uint32, 32 bit, \"Vendor id\"" << endl |
|
67 |
<< endl |
|
1382
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
68 |
<< "The access rights are specified for the AL states PREOP," << endl |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
69 |
<< "SAFEOP and OP. An 'r' means, that the entry is readable" << endl |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
70 |
<< "in the corresponding state, an 'w' means writable," << endl |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
71 |
<< "respectively. If a right is not granted, a dash '-' is" << endl |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
72 |
<< "shown." << endl |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
73 |
<< endl |
1804 | 74 |
<< "If the --quiet option is given, only the SDOs are output." |
75 |
<< endl << endl |
|
76 |
<< "Command-specific options:" << endl |
|
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
77 |
<< " --alias -a <alias>" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
78 |
<< " --position -p <pos> Slave selection. See the help of" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
79 |
<< " the 'slaves' command." << endl |
1804 | 80 |
<< " --quiet -q Only output SDOs (without the" << endl |
81 |
<< " SDO entries)." << endl |
|
82 |
<< endl |
|
83 |
<< numericInfo(); |
|
1142 | 84 |
|
1804 | 85 |
return str.str(); |
1142 | 86 |
} |
87 |
||
88 |
/****************************************************************************/ |
|
89 |
||
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
90 |
void CommandSdos::execute(const StringVector &args) |
1142 | 91 |
{ |
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1827
diff
changeset
|
92 |
MasterIndexList masterIndices; |
1151 | 93 |
SlaveList slaves; |
94 |
SlaveList::const_iterator si; |
|
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
95 |
bool showHeader, multiMaster; |
1151 | 96 |
|
1373
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
97 |
if (args.size()) { |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
98 |
stringstream err; |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
99 |
err << "'" << getName() << "' takes no arguments!"; |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
100 |
throwInvalidUsageException(err); |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
101 |
} |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
102 |
|
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1827
diff
changeset
|
103 |
masterIndices = getMasterIndices(); |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1827
diff
changeset
|
104 |
multiMaster = 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
|
105 |
MasterIndexList::const_iterator mi; |
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1827
diff
changeset
|
106 |
for (mi = masterIndices.begin(); |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1827
diff
changeset
|
107 |
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
|
108 |
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
|
109 |
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
|
110 |
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
|
111 |
showHeader = multiMaster || slaves.size() > 1; |
1142 | 112 |
|
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
113 |
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
|
114 |
listSlaveSdos(m, *si, showHeader); |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
115 |
} |
1142 | 116 |
} |
117 |
} |
|
118 |
||
119 |
/****************************************************************************/ |
|
120 |
||
121 |
void CommandSdos::listSlaveSdos( |
|
1804 | 122 |
MasterDevice &m, |
1151 | 123 |
const ec_ioctl_slave_t &slave, |
1804 | 124 |
bool showHeader |
125 |
) |
|
1142 | 126 |
{ |
127 |
ec_ioctl_slave_sdo_t sdo; |
|
128 |
ec_ioctl_slave_sdo_entry_t entry; |
|
129 |
unsigned int i, j; |
|
1184
75cd6681eb08
Introduced SdoCommand class to replace coe_datatypes.[ch]; added CoE abort codes in user space-
Florian Pose <fp@igh-essen.com>
parents:
1157
diff
changeset
|
130 |
const DataType *d; |
2421 | 131 |
|
1827
489be2180f71
Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
132 |
if (showHeader && slave.sdo_count) |
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
133 |
cout << "=== Master " << m.getIndex() |
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
134 |
<< ", Slave " << slave.position << " ===" << endl; |
1142 | 135 |
|
136 |
for (i = 0; i < slave.sdo_count; i++) { |
|
1151 | 137 |
m.getSdo(&sdo, slave.position, i); |
1142 | 138 |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1184
diff
changeset
|
139 |
cout << "SDO 0x" |
1142 | 140 |
<< hex << setfill('0') |
141 |
<< setw(4) << sdo.sdo_index |
|
142 |
<< ", \"" << sdo.name << "\"" << endl; |
|
143 |
||
144 |
if (getVerbosity() == Quiet) |
|
145 |
continue; |
|
146 |
||
147 |
for (j = 0; j <= sdo.max_subindex; j++) { |
|
2694
ab97efc5513a
Ignore missing SDO entries in output.
Florian Pose <fp@igh.de>
parents:
2421
diff
changeset
|
148 |
try { |
ab97efc5513a
Ignore missing SDO entries in output.
Florian Pose <fp@igh.de>
parents:
2421
diff
changeset
|
149 |
m.getSdoEntry(&entry, slave.position, -i, j); |
ab97efc5513a
Ignore missing SDO entries in output.
Florian Pose <fp@igh.de>
parents:
2421
diff
changeset
|
150 |
} |
ab97efc5513a
Ignore missing SDO entries in output.
Florian Pose <fp@igh.de>
parents:
2421
diff
changeset
|
151 |
catch (MasterDeviceException &e) { |
ab97efc5513a
Ignore missing SDO entries in output.
Florian Pose <fp@igh.de>
parents:
2421
diff
changeset
|
152 |
continue; |
ab97efc5513a
Ignore missing SDO entries in output.
Florian Pose <fp@igh.de>
parents:
2421
diff
changeset
|
153 |
} |
1142 | 154 |
|
155 |
cout << " 0x" << hex << setfill('0') |
|
156 |
<< setw(4) << sdo.sdo_index << ":" |
|
157 |
<< setw(2) << (unsigned int) entry.sdo_entry_subindex |
|
1382
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
158 |
<< ", " |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
159 |
<< (entry.read_access[EC_SDO_ENTRY_ACCESS_PREOP] ? "r" : "-") |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
160 |
<< (entry.write_access[EC_SDO_ENTRY_ACCESS_PREOP] ? "w" : "-") |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
161 |
<< (entry.read_access[EC_SDO_ENTRY_ACCESS_SAFEOP] ? "r" : "-") |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
162 |
<< (entry.write_access[EC_SDO_ENTRY_ACCESS_SAFEOP] ? "w" : "-") |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
163 |
<< (entry.read_access[EC_SDO_ENTRY_ACCESS_OP] ? "r" : "-") |
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1373
diff
changeset
|
164 |
<< (entry.write_access[EC_SDO_ENTRY_ACCESS_OP] ? "w" : "-") |
1142 | 165 |
<< ", "; |
166 |
||
167 |
if ((d = findDataType(entry.data_type))) { |
|
168 |
cout << d->name; |
|
169 |
} else { |
|
170 |
cout << "type " << setw(4) << entry.data_type; |
|
171 |
} |
|
172 |
||
173 |
cout << ", " << dec << entry.bit_length << " bit, \"" |
|
174 |
<< entry.description << "\"" << endl; |
|
175 |
} |
|
176 |
} |
|
177 |
} |
|
178 |
||
179 |
/*****************************************************************************/ |