author | Florian Pose <fp@igh-essen.com> |
Mon, 15 Jun 2009 15:58:09 +0000 | |
changeset 1472 | 6ca667095c67 |
parent 1373 | e651000f1ff1 |
child 1474 | 758a9bd3e549 |
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> |
|
1222
7348d6abb6cb
Applied patch by Karsten Schwinne, adding a few header files necessary
Florian Pose <fp@igh-essen.com>
parents:
1157
diff
changeset
|
32 |
#include <string.h> |
1142 | 33 |
using namespace std; |
34 |
||
35 |
#include "CommandXml.h" |
|
36 |
||
37 |
/*****************************************************************************/ |
|
38 |
||
39 |
CommandXml::CommandXml(): |
|
40 |
Command("xml", "Generate slave information XML.") |
|
41 |
{ |
|
42 |
} |
|
43 |
||
44 |
/*****************************************************************************/ |
|
45 |
||
46 |
string CommandXml::helpString() const |
|
47 |
{ |
|
48 |
stringstream str; |
|
49 |
||
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
50 |
str << getName() << " [OPTIONS]" << endl |
1142 | 51 |
<< endl |
52 |
<< getBriefDescription() << endl |
|
53 |
<< endl |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1222
diff
changeset
|
54 |
<< "Note that the PDO information can either originate" << endl |
1142 | 55 |
<< "from the SII or from the CoE communication area. For" << endl |
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1222
diff
changeset
|
56 |
<< "slaves, that support configuring PDO assignment and" << endl |
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
57 |
<< "mapping, the output depends on the last configuration." << endl |
1142 | 58 |
<< endl |
59 |
<< "Command-specific options:" << endl |
|
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
60 |
<< " --alias -a <alias>" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
61 |
<< " --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
|
62 |
<< " the 'slaves' command." << endl |
1142 | 63 |
<< endl |
64 |
<< numericInfo(); |
|
65 |
||
66 |
return str.str(); |
|
67 |
} |
|
68 |
||
69 |
/****************************************************************************/ |
|
70 |
||
71 |
void CommandXml::execute(MasterDevice &m, const StringVector &args) |
|
72 |
{ |
|
1151 | 73 |
SlaveList slaves; |
74 |
SlaveList::const_iterator si; |
|
75 |
||
1373
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
76 |
if (args.size()) { |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
77 |
stringstream err; |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
78 |
err << "'" << getName() << "' takes no arguments!"; |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
79 |
throwInvalidUsageException(err); |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
80 |
} |
e651000f1ff1
Complain about given arguments if none are required.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
81 |
|
1142 | 82 |
m.open(MasterDevice::Read); |
1151 | 83 |
slaves = selectedSlaves(m); |
1142 | 84 |
|
1151 | 85 |
for (si = slaves.begin(); si != slaves.end(); si++) { |
86 |
generateSlaveXml(m, *si); |
|
1142 | 87 |
} |
88 |
} |
|
89 |
||
90 |
/****************************************************************************/ |
|
91 |
||
1151 | 92 |
void CommandXml::generateSlaveXml( |
93 |
MasterDevice &m, |
|
94 |
const ec_ioctl_slave_t &slave |
|
95 |
) |
|
1142 | 96 |
{ |
97 |
ec_ioctl_slave_sync_t sync; |
|
98 |
ec_ioctl_slave_sync_pdo_t pdo; |
|
99 |
string pdoType; |
|
100 |
ec_ioctl_slave_sync_pdo_entry_t entry; |
|
101 |
unsigned int i, j, k; |
|
102 |
||
103 |
cout |
|
104 |
<< "<?xml version=\"1.0\" ?>" << endl |
|
105 |
<< " <EtherCATInfo>" << endl |
|
106 |
<< " <!-- Slave " << slave.position << " -->" << endl |
|
107 |
<< " <Vendor>" << endl |
|
108 |
<< " <Id>" << slave.vendor_id << "</Id>" << endl |
|
109 |
<< " </Vendor>" << endl |
|
110 |
<< " <Descriptions>" << endl |
|
111 |
<< " <Devices>" << endl |
|
112 |
<< " <Device>" << endl |
|
113 |
<< " <Type ProductCode=\"#x" |
|
114 |
<< hex << setfill('0') << setw(8) << slave.product_code |
|
115 |
<< "\" RevisionNo=\"#x" |
|
116 |
<< hex << setfill('0') << setw(8) << slave.revision_number |
|
117 |
<< "\">" << slave.order << "</Type>" << endl; |
|
118 |
||
119 |
if (strlen(slave.name)) { |
|
120 |
cout |
|
121 |
<< " <Name><![CDATA[" |
|
122 |
<< slave.name |
|
123 |
<< "]]></Name>" << endl; |
|
124 |
} |
|
125 |
||
126 |
for (i = 0; i < slave.sync_count; i++) { |
|
1151 | 127 |
m.getSync(&sync, slave.position, i); |
1142 | 128 |
|
129 |
cout |
|
130 |
<< " <Sm Enable=\"" << dec << (unsigned int) sync.enable |
|
131 |
<< "\" StartAddress=\"" << sync.physical_start_address |
|
132 |
<< "\" ControlByte=\"" << (unsigned int) sync.control_register |
|
133 |
<< "\" DefaultSize=\"" << sync.default_size |
|
134 |
<< "\" />" << endl; |
|
135 |
} |
|
136 |
||
137 |
for (i = 0; i < slave.sync_count; i++) { |
|
1151 | 138 |
m.getSync(&sync, slave.position, i); |
1142 | 139 |
|
140 |
for (j = 0; j < sync.pdo_count; j++) { |
|
1151 | 141 |
m.getPdo(&pdo, slave.position, i, j); |
1142 | 142 |
pdoType = (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:
1222
diff
changeset
|
143 |
pdoType += "xPdo"; // last 2 letters lowercase in XML! |
1142 | 144 |
|
145 |
cout |
|
146 |
<< " <" << pdoType |
|
147 |
<< " Sm=\"" << i << "\" Fixed=\"1\" Mandatory=\"1\">" << endl |
|
148 |
<< " <Index>#x" |
|
149 |
<< hex << setfill('0') << setw(4) << pdo.index |
|
150 |
<< "</Index>" << endl |
|
151 |
<< " <Name>" << pdo.name << "</Name>" << endl; |
|
152 |
||
153 |
for (k = 0; k < pdo.entry_count; k++) { |
|
1151 | 154 |
m.getPdoEntry(&entry, slave.position, i, j, k); |
1142 | 155 |
|
156 |
cout |
|
157 |
<< " <Entry>" << endl |
|
158 |
<< " <Index>#x" |
|
159 |
<< hex << setfill('0') << setw(4) << entry.index |
|
160 |
<< "</Index>" << endl; |
|
161 |
if (entry.index) |
|
162 |
cout |
|
163 |
<< " <SubIndex>" |
|
164 |
<< dec << (unsigned int) entry.subindex |
|
165 |
<< "</SubIndex>" << endl; |
|
166 |
||
167 |
cout |
|
168 |
<< " <BitLen>" |
|
169 |
<< dec << (unsigned int) entry.bit_length |
|
170 |
<< "</BitLen>" << endl; |
|
171 |
||
172 |
if (entry.index) { |
|
173 |
cout |
|
174 |
<< " <Name>" << entry.name |
|
175 |
<< "</Name>" << endl |
|
176 |
<< " <DataType>"; |
|
177 |
||
178 |
if (entry.bit_length == 1) { |
|
179 |
cout << "BOOL"; |
|
180 |
} else if (!(entry.bit_length % 8)) { |
|
181 |
if (entry.bit_length <= 64) |
|
182 |
cout << "UINT" << (unsigned int) entry.bit_length; |
|
183 |
else |
|
184 |
cout << "STRING(" |
|
185 |
<< (unsigned int) (entry.bit_length / 8) |
|
186 |
<< ")"; |
|
187 |
} else { |
|
188 |
cerr << "Invalid bit length " |
|
189 |
<< (unsigned int) entry.bit_length << endl; |
|
190 |
} |
|
191 |
||
192 |
cout << "</DataType>" << endl; |
|
193 |
} |
|
194 |
||
195 |
cout << " </Entry>" << endl; |
|
196 |
} |
|
197 |
||
198 |
cout |
|
199 |
<< " </" << pdoType << ">" << endl; |
|
200 |
} |
|
201 |
} |
|
202 |
||
203 |
cout |
|
204 |
<< " </Device>" << endl |
|
205 |
<< " </Devices>" << endl |
|
206 |
<< " </Descriptions>" << endl |
|
207 |
<< "</EtherCATInfo>" << endl; |
|
208 |
} |
|
209 |
/*****************************************************************************/ |