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