author | Florian Pose <fp@igh-essen.com> |
Thu, 02 Oct 2008 07:14:00 +0000 | |
changeset 1243 | 13cb18b91627 |
parent 1222 | 7348d6abb6cb |
child 1327 | 4d179b06dd3c |
permissions | -rw-r--r-- |
1142 | 1 |
/***************************************************************************** |
2 |
* |
|
3 |
* $Id$ |
|
4 |
* |
|
5 |
****************************************************************************/ |
|
6 |
||
7 |
#include <iostream> |
|
8 |
#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
|
9 |
#include <string.h> |
1142 | 10 |
using namespace std; |
11 |
||
12 |
#include "CommandXml.h" |
|
13 |
||
14 |
/*****************************************************************************/ |
|
15 |
||
16 |
CommandXml::CommandXml(): |
|
17 |
Command("xml", "Generate slave information XML.") |
|
18 |
{ |
|
19 |
} |
|
20 |
||
21 |
/*****************************************************************************/ |
|
22 |
||
23 |
string CommandXml::helpString() const |
|
24 |
{ |
|
25 |
stringstream str; |
|
26 |
||
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
27 |
str << getName() << " [OPTIONS]" << endl |
1142 | 28 |
<< endl |
29 |
<< getBriefDescription() << endl |
|
30 |
<< endl |
|
31 |
<< "Note that the Pdo information can either originate" << endl |
|
32 |
<< "from the SII or from the CoE communication area. For" << endl |
|
1144
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
33 |
<< "slaves, that support configuring Pdo assignment and" << endl |
7dbfdd61812c
Bugfixes and improvements.
Florian Pose <fp@igh-essen.com>
parents:
1142
diff
changeset
|
34 |
<< "mapping, the output depends on the last configuration." << endl |
1142 | 35 |
<< endl |
36 |
<< "Command-specific options:" << endl |
|
1157
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
37 |
<< " --alias -a <alias>" << endl |
04d1c950cf9d
Added --help for alias and position parameters.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
38 |
<< " --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
|
39 |
<< " the 'slaves' command." << endl |
1142 | 40 |
<< endl |
41 |
<< numericInfo(); |
|
42 |
||
43 |
return str.str(); |
|
44 |
} |
|
45 |
||
46 |
/****************************************************************************/ |
|
47 |
||
48 |
void CommandXml::execute(MasterDevice &m, const StringVector &args) |
|
49 |
{ |
|
1151 | 50 |
SlaveList slaves; |
51 |
SlaveList::const_iterator si; |
|
52 |
||
1142 | 53 |
m.open(MasterDevice::Read); |
1151 | 54 |
slaves = selectedSlaves(m); |
1142 | 55 |
|
1151 | 56 |
for (si = slaves.begin(); si != slaves.end(); si++) { |
57 |
generateSlaveXml(m, *si); |
|
1142 | 58 |
} |
59 |
} |
|
60 |
||
61 |
/****************************************************************************/ |
|
62 |
||
1151 | 63 |
void CommandXml::generateSlaveXml( |
64 |
MasterDevice &m, |
|
65 |
const ec_ioctl_slave_t &slave |
|
66 |
) |
|
1142 | 67 |
{ |
68 |
ec_ioctl_slave_sync_t sync; |
|
69 |
ec_ioctl_slave_sync_pdo_t pdo; |
|
70 |
string pdoType; |
|
71 |
ec_ioctl_slave_sync_pdo_entry_t entry; |
|
72 |
unsigned int i, j, k; |
|
73 |
||
74 |
cout |
|
75 |
<< "<?xml version=\"1.0\" ?>" << endl |
|
76 |
<< " <EtherCATInfo>" << endl |
|
77 |
<< " <!-- Slave " << slave.position << " -->" << endl |
|
78 |
<< " <Vendor>" << endl |
|
79 |
<< " <Id>" << slave.vendor_id << "</Id>" << endl |
|
80 |
<< " </Vendor>" << endl |
|
81 |
<< " <Descriptions>" << endl |
|
82 |
<< " <Devices>" << endl |
|
83 |
<< " <Device>" << endl |
|
84 |
<< " <Type ProductCode=\"#x" |
|
85 |
<< hex << setfill('0') << setw(8) << slave.product_code |
|
86 |
<< "\" RevisionNo=\"#x" |
|
87 |
<< hex << setfill('0') << setw(8) << slave.revision_number |
|
88 |
<< "\">" << slave.order << "</Type>" << endl; |
|
89 |
||
90 |
if (strlen(slave.name)) { |
|
91 |
cout |
|
92 |
<< " <Name><![CDATA[" |
|
93 |
<< slave.name |
|
94 |
<< "]]></Name>" << endl; |
|
95 |
} |
|
96 |
||
97 |
for (i = 0; i < slave.sync_count; i++) { |
|
1151 | 98 |
m.getSync(&sync, slave.position, i); |
1142 | 99 |
|
100 |
cout |
|
101 |
<< " <Sm Enable=\"" << dec << (unsigned int) sync.enable |
|
102 |
<< "\" StartAddress=\"" << sync.physical_start_address |
|
103 |
<< "\" ControlByte=\"" << (unsigned int) sync.control_register |
|
104 |
<< "\" DefaultSize=\"" << sync.default_size |
|
105 |
<< "\" />" << endl; |
|
106 |
} |
|
107 |
||
108 |
for (i = 0; i < slave.sync_count; i++) { |
|
1151 | 109 |
m.getSync(&sync, slave.position, i); |
1142 | 110 |
|
111 |
for (j = 0; j < sync.pdo_count; j++) { |
|
1151 | 112 |
m.getPdo(&pdo, slave.position, i, j); |
1142 | 113 |
pdoType = (sync.control_register & 0x04 ? "R" : "T"); |
114 |
pdoType += "xPdo"; |
|
115 |
||
116 |
cout |
|
117 |
<< " <" << pdoType |
|
118 |
<< " Sm=\"" << i << "\" Fixed=\"1\" Mandatory=\"1\">" << endl |
|
119 |
<< " <Index>#x" |
|
120 |
<< hex << setfill('0') << setw(4) << pdo.index |
|
121 |
<< "</Index>" << endl |
|
122 |
<< " <Name>" << pdo.name << "</Name>" << endl; |
|
123 |
||
124 |
for (k = 0; k < pdo.entry_count; k++) { |
|
1151 | 125 |
m.getPdoEntry(&entry, slave.position, i, j, k); |
1142 | 126 |
|
127 |
cout |
|
128 |
<< " <Entry>" << endl |
|
129 |
<< " <Index>#x" |
|
130 |
<< hex << setfill('0') << setw(4) << entry.index |
|
131 |
<< "</Index>" << endl; |
|
132 |
if (entry.index) |
|
133 |
cout |
|
134 |
<< " <SubIndex>" |
|
135 |
<< dec << (unsigned int) entry.subindex |
|
136 |
<< "</SubIndex>" << endl; |
|
137 |
||
138 |
cout |
|
139 |
<< " <BitLen>" |
|
140 |
<< dec << (unsigned int) entry.bit_length |
|
141 |
<< "</BitLen>" << endl; |
|
142 |
||
143 |
if (entry.index) { |
|
144 |
cout |
|
145 |
<< " <Name>" << entry.name |
|
146 |
<< "</Name>" << endl |
|
147 |
<< " <DataType>"; |
|
148 |
||
149 |
if (entry.bit_length == 1) { |
|
150 |
cout << "BOOL"; |
|
151 |
} else if (!(entry.bit_length % 8)) { |
|
152 |
if (entry.bit_length <= 64) |
|
153 |
cout << "UINT" << (unsigned int) entry.bit_length; |
|
154 |
else |
|
155 |
cout << "STRING(" |
|
156 |
<< (unsigned int) (entry.bit_length / 8) |
|
157 |
<< ")"; |
|
158 |
} else { |
|
159 |
cerr << "Invalid bit length " |
|
160 |
<< (unsigned int) entry.bit_length << endl; |
|
161 |
} |
|
162 |
||
163 |
cout << "</DataType>" << endl; |
|
164 |
} |
|
165 |
||
166 |
cout << " </Entry>" << endl; |
|
167 |
} |
|
168 |
||
169 |
cout |
|
170 |
<< " </" << pdoType << ">" << endl; |
|
171 |
} |
|
172 |
} |
|
173 |
||
174 |
cout |
|
175 |
<< " </Device>" << endl |
|
176 |
<< " </Devices>" << endl |
|
177 |
<< " </Descriptions>" << endl |
|
178 |
<< "</EtherCATInfo>" << endl; |
|
179 |
} |
|
180 |
/*****************************************************************************/ |