author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Mon, 30 Jul 2018 11:18:45 +0200 | |
branch | stable-1.5 |
changeset 2703 | 045624f7f4c3 |
parent 2436 | 960cc1bb6b4a |
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> |
|
2436
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
32 |
#include <cstring> |
1142 | 33 |
using namespace std; |
34 |
||
35 |
#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
|
36 |
#include "MasterDevice.h" |
1142 | 37 |
|
38 |
/*****************************************************************************/ |
|
39 |
||
40 |
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
|
41 |
Command("pdos", "List Sync managers, PDO assignment and mapping.") |
1142 | 42 |
{ |
43 |
} |
|
44 |
||
45 |
/*****************************************************************************/ |
|
46 |
||
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
|
47 |
string CommandPdos::helpString(const string &binaryBaseName) const |
1142 | 48 |
{ |
49 |
stringstream str; |
|
50 |
||
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
|
51 |
str << binaryBaseName << " " << getName() << " [OPTIONS]" << endl |
1142 | 52 |
<< endl |
1804 | 53 |
<< getBriefDescription() << endl |
54 |
<< endl |
|
2436
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
55 |
<< "For the default skin (see --skin option) the information" << endl |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
56 |
<< "is displayed in three layers, which are" << endl |
1804 | 57 |
<< "indented accordingly:" << endl |
58 |
<< endl |
|
59 |
<< "1) Sync managers - Contains the sync manager information" << endl |
|
60 |
<< " from the SII: Index, physical start address, default" << endl |
|
61 |
<< " size, control register and enable word. Example:" << endl |
|
62 |
<< endl |
|
63 |
<< " SM3: PhysAddr 0x1100, DefaultSize 0, ControlRegister 0x20, " |
|
64 |
<< "Enable 1" << endl |
|
65 |
<< endl |
|
66 |
<< "2) Assigned PDOs - PDO direction, hexadecimal index and" << endl |
|
67 |
<< " 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
|
68 |
<< " are seen from the slave's point of view. Example:" << endl |
1804 | 69 |
<< endl |
70 |
<< " TxPDO 0x1a00 \"Channel1\"" << endl |
|
71 |
<< endl |
|
72 |
<< "3) Mapped PDO entries - PDO entry index and subindex (both" << endl |
|
73 |
<< " hexadecimal), the length in bit and the description, if" << endl |
|
74 |
<< " available. Example:" << endl |
|
75 |
<< endl |
|
76 |
<< " PDO entry 0x3101:01, 8 bit, \"Status\"" << endl |
|
77 |
<< endl |
|
78 |
<< "Note, that the displayed PDO assignment and PDO mapping" << endl |
|
79 |
<< "information can either originate from the SII or from the" << endl |
|
80 |
<< "CoE communication area." << endl |
|
81 |
<< endl |
|
2436
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
82 |
<< "The \"etherlab\" skin outputs a template configuration" << endl |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
83 |
<< "for EtherLab's generic EtherCAT slave block." << endl |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
84 |
<< endl |
1804 | 85 |
<< "Command-specific options:" << endl |
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
86 |
<< " --alias -a <alias>" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
87 |
<< " --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
|
88 |
<< " the 'slaves' command." << endl |
2436
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
89 |
<< " --skin -s <skin> Choose output skin. Possible values are" |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
90 |
<< endl |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
91 |
<< " \"default\" and \"etherlab\"." << endl |
1804 | 92 |
<< endl |
93 |
<< numericInfo(); |
|
1142 | 94 |
|
1804 | 95 |
return str.str(); |
1142 | 96 |
} |
97 |
||
98 |
/****************************************************************************/ |
|
99 |
||
1826
ec6223c3b7ec
Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
100 |
void CommandPdos::execute(const StringVector &args) |
1142 | 101 |
{ |
1869
14f634f5b613
Open master device as late as possible.
Florian Pose <fp@igh-essen.com>
parents:
1827
diff
changeset
|
102 |
MasterIndexList masterIndices; |
1151 | 103 |
SlaveList slaves; |
104 |
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
|
105 |
bool showHeader, multiMaster; |
2421 | 106 |
|
1373
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
107 |
if (args.size()) { |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
108 |
stringstream err; |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
109 |
err << "'" << getName() << "' takes no arguments!"; |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
110 |
throwInvalidUsageException(err); |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
111 |
} |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
112 |
|
2436
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
113 |
if (getSkin().empty() || getSkin() == "default") { |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
114 |
masterIndices = getMasterIndices(); |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
115 |
multiMaster = masterIndices.size() > 1; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
116 |
MasterIndexList::const_iterator mi; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
117 |
for (mi = masterIndices.begin(); |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
118 |
mi != masterIndices.end(); mi++) { |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
119 |
MasterDevice m(*mi); |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
120 |
m.open(MasterDevice::Read); |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
121 |
slaves = selectedSlaves(m); |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
122 |
showHeader = multiMaster || slaves.size() > 1; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
123 |
|
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
124 |
for (si = slaves.begin(); si != slaves.end(); si++) { |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
125 |
listSlavePdos(m, *si, showHeader); |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
126 |
} |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
127 |
} |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
128 |
} |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
129 |
else if (getSkin() == "etherlab") { |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
130 |
masterIndices = getMasterIndices(); |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
131 |
MasterIndexList::const_iterator mi; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
132 |
for (mi = masterIndices.begin(); |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
133 |
mi != masterIndices.end(); mi++) { |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
134 |
MasterDevice m(*mi); |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
135 |
m.open(MasterDevice::Read); |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
136 |
slaves = selectedSlaves(m); |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
137 |
|
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
138 |
for (si = slaves.begin(); si != slaves.end(); si++) { |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
139 |
etherlabConfig(m, *si); |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
140 |
} |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
141 |
} |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
142 |
} |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
143 |
else { |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
144 |
stringstream err; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
145 |
err << "Invalid skin '" << getSkin() << "'!"; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
146 |
throwInvalidUsageException(err); |
1142 | 147 |
} |
148 |
} |
|
149 |
||
150 |
/****************************************************************************/ |
|
151 |
||
152 |
void CommandPdos::listSlavePdos( |
|
1804 | 153 |
MasterDevice &m, |
1151 | 154 |
const ec_ioctl_slave_t &slave, |
1804 | 155 |
bool showHeader |
156 |
) |
|
1142 | 157 |
{ |
158 |
ec_ioctl_slave_sync_t sync; |
|
159 |
ec_ioctl_slave_sync_pdo_t pdo; |
|
160 |
ec_ioctl_slave_sync_pdo_entry_t entry; |
|
161 |
unsigned int i, j, k; |
|
2421 | 162 |
|
1827
489be2180f71
Improved multi-master capabilities of ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
1826
diff
changeset
|
163 |
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
|
164 |
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
|
165 |
<< ", Slave " << slave.position << " ===" << endl; |
1142 | 166 |
|
167 |
for (i = 0; i < slave.sync_count; i++) { |
|
1151 | 168 |
m.getSync(&sync, slave.position, i); |
1142 | 169 |
|
170 |
cout << "SM" << i << ":" |
|
171 |
<< " PhysAddr 0x" |
|
172 |
<< hex << setfill('0') |
|
173 |
<< setw(4) << sync.physical_start_address |
|
174 |
<< ", DefaultSize " |
|
175 |
<< dec << setfill(' ') << setw(4) << sync.default_size |
|
176 |
<< ", ControlRegister 0x" |
|
177 |
<< hex << setfill('0') << setw(2) |
|
178 |
<< (unsigned int) sync.control_register |
|
179 |
<< ", Enable " << dec << (unsigned int) sync.enable |
|
180 |
<< endl; |
|
181 |
||
182 |
for (j = 0; j < sync.pdo_count; j++) { |
|
1151 | 183 |
m.getPdo(&pdo, slave.position, i, j); |
1142 | 184 |
|
185 |
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
|
186 |
<< "xPDO 0x" |
1142 | 187 |
<< hex << setfill('0') |
188 |
<< setw(4) << pdo.index |
|
189 |
<< " \"" << pdo.name << "\"" << endl; |
|
190 |
||
191 |
if (getVerbosity() == Quiet) |
|
192 |
continue; |
|
193 |
||
194 |
for (k = 0; k < pdo.entry_count; k++) { |
|
1151 | 195 |
m.getPdoEntry(&entry, slave.position, i, j, k); |
1142 | 196 |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1187
diff
changeset
|
197 |
cout << " PDO entry 0x" |
1142 | 198 |
<< hex << setfill('0') |
199 |
<< setw(4) << entry.index |
|
200 |
<< ":" << setw(2) << (unsigned int) entry.subindex |
|
1187
aa616c3286ce
Show Pdo bit lengths right-aligned.
Florian Pose <fp@igh-essen.com>
parents:
1167
diff
changeset
|
201 |
<< ", " << dec << setfill(' ') |
aa616c3286ce
Show Pdo bit lengths right-aligned.
Florian Pose <fp@igh-essen.com>
parents:
1167
diff
changeset
|
202 |
<< setw(2) << (unsigned int) entry.bit_length |
1142 | 203 |
<< " bit, \"" << entry.name << "\"" << endl; |
204 |
} |
|
205 |
} |
|
206 |
} |
|
207 |
} |
|
208 |
||
2436
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
209 |
/****************************************************************************/ |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
210 |
|
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
211 |
void CommandPdos::etherlabConfig( |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
212 |
MasterDevice &m, |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
213 |
const ec_ioctl_slave_t &slave |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
214 |
) |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
215 |
{ |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
216 |
ec_ioctl_slave_sync_t sync; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
217 |
ec_ioctl_slave_sync_pdo_t pdo; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
218 |
ec_ioctl_slave_sync_pdo_entry_t entry; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
219 |
unsigned int i, j, k; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
220 |
|
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
221 |
cout << "%" << endl |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
222 |
<< "% Master " << m.getIndex() << ", Slave " << slave.position; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
223 |
if (strlen(slave.order)) { |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
224 |
cout << ", \"" << slave.order << "\""; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
225 |
} |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
226 |
cout << endl |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
227 |
<< "%" << endl |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
228 |
<< "function rv = slave" << slave.position << "()" << endl << endl; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
229 |
|
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
230 |
cout << "% Slave configuration" << endl << endl; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
231 |
|
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
232 |
cout << "rv.SlaveConfig.vendor = " << slave.vendor_id << ";" << endl |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
233 |
<< "rv.SlaveConfig.product = hex2dec('" |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
234 |
<< hex << setfill('0') << setw(8) << slave.product_code << "');" |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
235 |
<< endl |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
236 |
<< "rv.SlaveConfig.description = '" << slave.order << "';" << endl |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
237 |
<< "rv.SlaveConfig.sm = { ..." << endl; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
238 |
|
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
239 |
/* slave configuration */ |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
240 |
for (i = 0; i < slave.sync_count; i++) { |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
241 |
m.getSync(&sync, slave.position, i); |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
242 |
|
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
243 |
cout << " {" << dec << i << ", " |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
244 |
<< (sync.control_register & 0x04 ? 0 : 1) << ", {" << endl; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
245 |
|
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
246 |
for (j = 0; j < sync.pdo_count; j++) { |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
247 |
m.getPdo(&pdo, slave.position, i, j); |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
248 |
|
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
249 |
cout << " {hex2dec('" << |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
250 |
hex << setfill('0') << setw(4) << pdo.index << "'), [" |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
251 |
<< endl; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
252 |
|
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
253 |
for (k = 0; k < pdo.entry_count; k++) { |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
254 |
m.getPdoEntry(&entry, slave.position, i, j, k); |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
255 |
|
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
256 |
cout << " hex2dec('" |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
257 |
<< hex << setfill('0') << setw(4) << entry.index |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
258 |
<< "'), hex2dec('" |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
259 |
<< setw(2) << (unsigned int) entry.subindex |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
260 |
<< "'), " << dec << setfill(' ') << setw(3) |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
261 |
<< (unsigned int) entry.bit_length |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
262 |
<< "; ..." << endl; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
263 |
} |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
264 |
|
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
265 |
cout << " ]}, ..." << endl; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
266 |
} |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
267 |
cout << " }}, ..." << endl; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
268 |
} |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
269 |
|
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
270 |
cout << " };" << endl << endl; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
271 |
|
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
272 |
cout << "% Port configuration" << endl << endl; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
273 |
|
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
274 |
unsigned int input = 1, output = 1; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
275 |
for (i = 0; i < slave.sync_count; i++) { |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
276 |
m.getSync(&sync, slave.position, i); |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
277 |
|
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
278 |
for (j = 0; j < sync.pdo_count; j++) { |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
279 |
m.getPdo(&pdo, slave.position, i, j); |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
280 |
|
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
281 |
for (k = 0; k < pdo.entry_count; k++) { |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
282 |
m.getPdoEntry(&entry, slave.position, i, j, k); |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
283 |
|
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
284 |
if (!entry.index) { |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
285 |
continue; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
286 |
} |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
287 |
|
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
288 |
string dir; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
289 |
unsigned int port; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
290 |
|
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
291 |
if (sync.control_register & 0x04) { |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
292 |
dir = "input"; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
293 |
port = input++; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
294 |
} |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
295 |
else { |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
296 |
dir = "output"; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
297 |
port = output++; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
298 |
} |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
299 |
|
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
300 |
stringstream var; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
301 |
var << "rv.PortConfig." << dir << "(" << dec << port |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
302 |
<< ")"; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
303 |
|
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
304 |
cout << var.str() << ".pdo = [" |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
305 |
<< i << ", " << j << ", " << k << ", 0];" << endl; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
306 |
cout << var.str() << ".pdo_data_type = " |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
307 |
<< 1000 + (unsigned int) entry.bit_length |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
308 |
<< ";" << endl << endl; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
309 |
} |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
310 |
} |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
311 |
} |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
312 |
|
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
313 |
cout << "end" << endl; |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
314 |
} |
960cc1bb6b4a
EtherLab skin for 'ethercat pdos' command.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
315 |
|
1142 | 316 |
/*****************************************************************************/ |