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 |
|
|
26 |
str << getName() << " [OPTIONS]"
|
|
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
|
|
32 |
<< "some slaves, this is dependant on the last slave" << endl
|
|
33 |
<< "configuration." << endl
|
|
34 |
<< endl
|
|
35 |
<< "Command-specific options:" << endl
|
|
36 |
<< " --slave -s <index> Positive numerical ring position," << endl
|
|
37 |
<< " or 'all' for all slaves (default)." << endl
|
|
38 |
<< endl
|
|
39 |
<< numericInfo();
|
|
40 |
|
|
41 |
return str.str();
|
|
42 |
}
|
|
43 |
|
|
44 |
/****************************************************************************/
|
|
45 |
|
|
46 |
void CommandXml::execute(MasterDevice &m, const StringVector &args)
|
|
47 |
{
|
|
48 |
m.open(MasterDevice::Read);
|
|
49 |
|
|
50 |
if (slavePosition == -1) {
|
|
51 |
unsigned int numSlaves = m.slaveCount(), i;
|
|
52 |
|
|
53 |
for (i = 0; i < numSlaves; i++) {
|
|
54 |
generateSlaveXml(m, i);
|
|
55 |
}
|
|
56 |
} else {
|
|
57 |
generateSlaveXml(m, slavePosition);
|
|
58 |
}
|
|
59 |
}
|
|
60 |
|
|
61 |
/****************************************************************************/
|
|
62 |
|
|
63 |
void CommandXml::generateSlaveXml(MasterDevice &m, uint16_t slavePosition)
|
|
64 |
{
|
|
65 |
ec_ioctl_slave_t slave;
|
|
66 |
ec_ioctl_slave_sync_t sync;
|
|
67 |
ec_ioctl_slave_sync_pdo_t pdo;
|
|
68 |
string pdoType;
|
|
69 |
ec_ioctl_slave_sync_pdo_entry_t entry;
|
|
70 |
unsigned int i, j, k;
|
|
71 |
|
|
72 |
m.getSlave(&slave, slavePosition);
|
|
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++) {
|
|
98 |
m.getSync(&sync, slavePosition, i);
|
|
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++) {
|
|
109 |
m.getSync(&sync, slavePosition, i);
|
|
110 |
|
|
111 |
for (j = 0; j < sync.pdo_count; j++) {
|
|
112 |
m.getPdo(&pdo, slavePosition, i, j);
|
|
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++) {
|
|
125 |
m.getPdoEntry(&entry, slavePosition, i, j, k);
|
|
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 |
/*****************************************************************************/
|