author | Florian Pose <fp@igh-essen.com> |
Fri, 23 Jul 2010 09:30:42 +0200 | |
changeset 1953 | 968a531e5a89 |
parent 1869 | 14f634f5b613 |
child 1968 | 4f682084c643 |
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 "CommandPdos.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 |
CommandPdos::CommandPdos(): |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1187
diff
changeset
|
40 |
Command("pdos", "List Sync managers, PDO assignment and mapping.") |
1142 | 41 |
{ |
42 |
} |
|
43 |
||
44 |
/*****************************************************************************/ |
|
45 |
||
46 |
string CommandPdos::helpString() const |
|
47 |
{ |
|
48 |
stringstream str; |
|
49 |
||
50 |
str << getName() << " [OPTIONS]" << endl |
|
51 |
<< endl |
|
1804 | 52 |
<< getBriefDescription() << endl |
53 |
<< endl |
|
54 |
<< "The information is displayed in three layers, which are" << endl |
|
55 |
<< "indented accordingly:" << endl |
|
56 |
<< endl |
|
57 |
<< "1) Sync managers - Contains the sync manager information" << endl |
|
58 |
<< " from the SII: Index, physical start address, default" << endl |
|
59 |
<< " size, control register and enable word. Example:" << endl |
|
60 |
<< endl |
|
61 |
<< " SM3: PhysAddr 0x1100, DefaultSize 0, ControlRegister 0x20, " |
|
62 |
<< "Enable 1" << endl |
|
63 |
<< endl |
|
64 |
<< "2) Assigned PDOs - PDO direction, hexadecimal index and" << endl |
|
65 |
<< " the PDO name, if avaliable. Note that a 'Tx' and 'Rx'" << endl |
|
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
66 |
<< " are seen from the slave's point of view. Example:" << endl |
1804 | 67 |
<< endl |
68 |
<< " TxPDO 0x1a00 \"Channel1\"" << endl |
|
69 |
<< endl |
|
70 |
<< "3) Mapped PDO entries - PDO entry index and subindex (both" << endl |
|
71 |
<< " hexadecimal), the length in bit and the description, if" << endl |
|
72 |
<< " available. Example:" << endl |
|
73 |
<< endl |
|
74 |
<< " PDO entry 0x3101:01, 8 bit, \"Status\"" << endl |
|
75 |
<< endl |
|
76 |
<< "Note, that the displayed PDO assignment and PDO mapping" << endl |
|
77 |
<< "information can either originate from the SII or from the" << endl |
|
78 |
<< "CoE communication area." << endl |
|
79 |
<< endl |
|
80 |
<< "Command-specific options:" << endl |
|
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
81 |
<< " --alias -a <alias>" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
82 |
<< " --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
|
83 |
<< " the 'slaves' command." << endl |
1804 | 84 |
<< endl |
85 |
<< numericInfo(); |
|
1142 | 86 |
|
1804 | 87 |
return str.str(); |
1142 | 88 |
} |
89 |
||
90 |
/****************************************************************************/ |
|
91 |
||
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
92 |
void CommandPdos::execute(const StringVector &args) |
1142 | 93 |
{ |
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1827
diff
changeset
|
94 |
MasterIndexList masterIndices; |
1151 | 95 |
SlaveList slaves; |
96 |
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
|
97 |
bool showHeader, multiMaster; |
1151 | 98 |
|
1373
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
99 |
if (args.size()) { |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
100 |
stringstream err; |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
101 |
err << "'" << getName() << "' takes no arguments!"; |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
102 |
throwInvalidUsageException(err); |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
103 |
} |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
104 |
|
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1827
diff
changeset
|
105 |
masterIndices = getMasterIndices(); |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1827
diff
changeset
|
106 |
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
|
107 |
MasterIndexList::const_iterator mi; |
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1827
diff
changeset
|
108 |
for (mi = masterIndices.begin(); |
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1827
diff
changeset
|
109 |
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
|
110 |
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
|
111 |
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
|
112 |
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
|
113 |
showHeader = multiMaster || slaves.size() > 1; |
1142 | 114 |
|
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
115 |
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
|
116 |
listSlavePdos(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
|
117 |
} |
1142 | 118 |
} |
119 |
} |
|
120 |
||
121 |
/****************************************************************************/ |
|
122 |
||
123 |
void CommandPdos::listSlavePdos( |
|
1804 | 124 |
MasterDevice &m, |
1151 | 125 |
const ec_ioctl_slave_t &slave, |
1804 | 126 |
bool showHeader |
127 |
) |
|
1142 | 128 |
{ |
129 |
ec_ioctl_slave_sync_t sync; |
|
130 |
ec_ioctl_slave_sync_pdo_t pdo; |
|
131 |
ec_ioctl_slave_sync_pdo_entry_t entry; |
|
132 |
unsigned int i, j, k; |
|
133 |
||
1827
489be2180f71
Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
134 |
if (showHeader && slave.sync_count) |
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
135 |
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
|
136 |
<< ", Slave " << slave.position << " ===" << endl; |
1142 | 137 |
|
138 |
for (i = 0; i < slave.sync_count; i++) { |
|
1151 | 139 |
m.getSync(&sync, slave.position, i); |
1142 | 140 |
|
141 |
cout << "SM" << i << ":" |
|
142 |
<< " PhysAddr 0x" |
|
143 |
<< hex << setfill('0') |
|
144 |
<< setw(4) << sync.physical_start_address |
|
145 |
<< ", DefaultSize " |
|
146 |
<< dec << setfill(' ') << setw(4) << sync.default_size |
|
147 |
<< ", ControlRegister 0x" |
|
148 |
<< hex << setfill('0') << setw(2) |
|
149 |
<< (unsigned int) sync.control_register |
|
150 |
<< ", Enable " << dec << (unsigned int) sync.enable |
|
151 |
<< endl; |
|
152 |
||
153 |
for (j = 0; j < sync.pdo_count; j++) { |
|
1151 | 154 |
m.getPdo(&pdo, slave.position, i, j); |
1142 | 155 |
|
156 |
cout << " " << (sync.control_register & 0x04 ? "R" : "T") |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1187
diff
changeset
|
157 |
<< "xPDO 0x" |
1142 | 158 |
<< hex << setfill('0') |
159 |
<< setw(4) << pdo.index |
|
160 |
<< " \"" << pdo.name << "\"" << endl; |
|
161 |
||
162 |
if (getVerbosity() == Quiet) |
|
163 |
continue; |
|
164 |
||
165 |
for (k = 0; k < pdo.entry_count; k++) { |
|
1151 | 166 |
m.getPdoEntry(&entry, slave.position, i, j, k); |
1142 | 167 |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1187
diff
changeset
|
168 |
cout << " PDO entry 0x" |
1142 | 169 |
<< hex << setfill('0') |
170 |
<< setw(4) << entry.index |
|
171 |
<< ":" << setw(2) << (unsigned int) entry.subindex |
|
1187
aa616c3286ce
Show Pdo bit lengths right-aligned.
Florian Pose <fp@igh-essen.com>
parents:
1167
diff
changeset
|
172 |
<< ", " << dec << setfill(' ') |
aa616c3286ce
Show Pdo bit lengths right-aligned.
Florian Pose <fp@igh-essen.com>
parents:
1167
diff
changeset
|
173 |
<< setw(2) << (unsigned int) entry.bit_length |
1142 | 174 |
<< " bit, \"" << entry.name << "\"" << endl; |
175 |
} |
|
176 |
} |
|
177 |
} |
|
178 |
} |
|
179 |
||
180 |
/*****************************************************************************/ |