author | Florian Pose <fp@igh-essen.com> |
Thu, 19 Mar 2009 08:42:33 +0000 | |
changeset 1372 | 6b45c4c6f56f |
parent 1363 | 11c0b2caa253 |
child 1373 | e651000f1ff1 |
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 |
||
1142 | 76 |
m.open(MasterDevice::Read); |
1151 | 77 |
slaves = selectedSlaves(m); |
1142 | 78 |
|
1151 | 79 |
for (si = slaves.begin(); si != slaves.end(); si++) { |
80 |
generateSlaveXml(m, *si); |
|
1142 | 81 |
} |
82 |
} |
|
83 |
||
84 |
/****************************************************************************/ |
|
85 |
||
1151 | 86 |
void CommandXml::generateSlaveXml( |
87 |
MasterDevice &m, |
|
88 |
const ec_ioctl_slave_t &slave |
|
89 |
) |
|
1142 | 90 |
{ |
91 |
ec_ioctl_slave_sync_t sync; |
|
92 |
ec_ioctl_slave_sync_pdo_t pdo; |
|
93 |
string pdoType; |
|
94 |
ec_ioctl_slave_sync_pdo_entry_t entry; |
|
95 |
unsigned int i, j, k; |
|
96 |
||
97 |
cout |
|
98 |
<< "<?xml version=\"1.0\" ?>" << endl |
|
99 |
<< " <EtherCATInfo>" << endl |
|
100 |
<< " <!-- Slave " << slave.position << " -->" << endl |
|
101 |
<< " <Vendor>" << endl |
|
102 |
<< " <Id>" << slave.vendor_id << "</Id>" << endl |
|
103 |
<< " </Vendor>" << endl |
|
104 |
<< " <Descriptions>" << endl |
|
105 |
<< " <Devices>" << endl |
|
106 |
<< " <Device>" << endl |
|
107 |
<< " <Type ProductCode=\"#x" |
|
108 |
<< hex << setfill('0') << setw(8) << slave.product_code |
|
109 |
<< "\" RevisionNo=\"#x" |
|
110 |
<< hex << setfill('0') << setw(8) << slave.revision_number |
|
111 |
<< "\">" << slave.order << "</Type>" << endl; |
|
112 |
||
113 |
if (strlen(slave.name)) { |
|
114 |
cout |
|
115 |
<< " <Name><![CDATA[" |
|
116 |
<< slave.name |
|
117 |
<< "]]></Name>" << endl; |
|
118 |
} |
|
119 |
||
120 |
for (i = 0; i < slave.sync_count; i++) { |
|
1151 | 121 |
m.getSync(&sync, slave.position, i); |
1142 | 122 |
|
123 |
cout |
|
124 |
<< " <Sm Enable=\"" << dec << (unsigned int) sync.enable |
|
125 |
<< "\" StartAddress=\"" << sync.physical_start_address |
|
126 |
<< "\" ControlByte=\"" << (unsigned int) sync.control_register |
|
127 |
<< "\" DefaultSize=\"" << sync.default_size |
|
128 |
<< "\" />" << endl; |
|
129 |
} |
|
130 |
||
131 |
for (i = 0; i < slave.sync_count; i++) { |
|
1151 | 132 |
m.getSync(&sync, slave.position, i); |
1142 | 133 |
|
134 |
for (j = 0; j < sync.pdo_count; j++) { |
|
1151 | 135 |
m.getPdo(&pdo, slave.position, i, j); |
1142 | 136 |
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
|
137 |
pdoType += "xPdo"; // last 2 letters lowercase in XML! |
1142 | 138 |
|
139 |
cout |
|
140 |
<< " <" << pdoType |
|
141 |
<< " Sm=\"" << i << "\" Fixed=\"1\" Mandatory=\"1\">" << endl |
|
142 |
<< " <Index>#x" |
|
143 |
<< hex << setfill('0') << setw(4) << pdo.index |
|
144 |
<< "</Index>" << endl |
|
145 |
<< " <Name>" << pdo.name << "</Name>" << endl; |
|
146 |
||
147 |
for (k = 0; k < pdo.entry_count; k++) { |
|
1151 | 148 |
m.getPdoEntry(&entry, slave.position, i, j, k); |
1142 | 149 |
|
150 |
cout |
|
151 |
<< " <Entry>" << endl |
|
152 |
<< " <Index>#x" |
|
153 |
<< hex << setfill('0') << setw(4) << entry.index |
|
154 |
<< "</Index>" << endl; |
|
155 |
if (entry.index) |
|
156 |
cout |
|
157 |
<< " <SubIndex>" |
|
158 |
<< dec << (unsigned int) entry.subindex |
|
159 |
<< "</SubIndex>" << endl; |
|
160 |
||
161 |
cout |
|
162 |
<< " <BitLen>" |
|
163 |
<< dec << (unsigned int) entry.bit_length |
|
164 |
<< "</BitLen>" << endl; |
|
165 |
||
166 |
if (entry.index) { |
|
167 |
cout |
|
168 |
<< " <Name>" << entry.name |
|
169 |
<< "</Name>" << endl |
|
170 |
<< " <DataType>"; |
|
171 |
||
172 |
if (entry.bit_length == 1) { |
|
173 |
cout << "BOOL"; |
|
174 |
} else if (!(entry.bit_length % 8)) { |
|
175 |
if (entry.bit_length <= 64) |
|
176 |
cout << "UINT" << (unsigned int) entry.bit_length; |
|
177 |
else |
|
178 |
cout << "STRING(" |
|
179 |
<< (unsigned int) (entry.bit_length / 8) |
|
180 |
<< ")"; |
|
181 |
} else { |
|
182 |
cerr << "Invalid bit length " |
|
183 |
<< (unsigned int) entry.bit_length << endl; |
|
184 |
} |
|
185 |
||
186 |
cout << "</DataType>" << endl; |
|
187 |
} |
|
188 |
||
189 |
cout << " </Entry>" << endl; |
|
190 |
} |
|
191 |
||
192 |
cout |
|
193 |
<< " </" << pdoType << ">" << endl; |
|
194 |
} |
|
195 |
} |
|
196 |
||
197 |
cout |
|
198 |
<< " </Device>" << endl |
|
199 |
<< " </Devices>" << endl |
|
200 |
<< " </Descriptions>" << endl |
|
201 |
<< "</EtherCATInfo>" << endl; |
|
202 |
} |
|
203 |
/*****************************************************************************/ |