author | Florian Pose <fp@igh-essen.com> |
Mon, 28 Jul 2008 09:12:21 +0000 | |
changeset 1156 | ecaf2a896ea3 |
parent 1155 | bd4e5b544473 |
child 1157 | 04d1c950cf9d |
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 "CommandSiiRead.h" |
|
12 |
#include "byteorder.h" |
|
13 |
||
14 |
/*****************************************************************************/ |
|
15 |
||
16 |
CommandSiiRead::CommandSiiRead(): |
|
17 |
Command("sii_read", "Output a slave's SII contents.") |
|
18 |
{ |
|
19 |
} |
|
20 |
||
21 |
/*****************************************************************************/ |
|
22 |
||
23 |
string CommandSiiRead::helpString() const |
|
24 |
{ |
|
25 |
stringstream str; |
|
26 |
||
27 |
str << getName() << " [OPTIONS]" << endl |
|
28 |
<< endl |
|
29 |
<< getBriefDescription() << endl |
|
30 |
<< endl |
|
31 |
<< "Without the --verbose option, binary SII contents are" << endl |
|
32 |
<< "output." << endl |
|
33 |
<< endl |
|
34 |
<< "With the --verbose option given, a textual representation" << endl |
|
35 |
<< "of the data is output, that is separated by SII category" << endl |
|
36 |
<< "names." << endl |
|
37 |
<< endl |
|
38 |
<< "Command-specific options:" << endl |
|
39 |
<< " --slave -s <index> Positive numerical ring position" << endl |
|
40 |
<< " (mandatory)." << endl |
|
41 |
<< " --verbose -v Output textual data with" << endl |
|
42 |
<< " category names." << endl |
|
43 |
<< endl |
|
44 |
<< numericInfo(); |
|
45 |
||
46 |
return str.str(); |
|
47 |
} |
|
48 |
||
49 |
/****************************************************************************/ |
|
50 |
||
51 |
void CommandSiiRead::execute(MasterDevice &m, const StringVector &args) |
|
52 |
{ |
|
1151 | 53 |
SlaveList slaves; |
54 |
ec_ioctl_slave_t *slave; |
|
1142 | 55 |
ec_ioctl_slave_sii_t data; |
56 |
unsigned int i; |
|
57 |
const uint16_t *categoryHeader; |
|
58 |
uint16_t categoryType, categorySize; |
|
59 |
stringstream err; |
|
60 |
||
1151 | 61 |
m.open(MasterDevice::Read); |
62 |
slaves = selectedSlaves(m); |
|
63 |
||
64 |
if (slaves.size() != 1) { |
|
1155
bd4e5b544473
Common message for single slave selections.
Florian Pose <fp@igh-essen.com>
parents:
1151
diff
changeset
|
65 |
throwSingleSlaveRequired(slaves.size()); |
1142 | 66 |
} |
1151 | 67 |
slave = &slaves.front(); |
68 |
data.slave_position = slave->position; |
|
1142 | 69 |
|
1151 | 70 |
if (!slave->sii_nwords) |
1142 | 71 |
return; |
72 |
||
73 |
data.offset = 0; |
|
1151 | 74 |
data.nwords = slave->sii_nwords; |
1142 | 75 |
data.words = new uint16_t[data.nwords]; |
76 |
||
77 |
try { |
|
78 |
m.readSii(&data); |
|
79 |
} catch (MasterDeviceException &e) { |
|
80 |
delete [] data.words; |
|
81 |
throw e; |
|
82 |
} |
|
83 |
||
84 |
if (getVerbosity() == Verbose) { |
|
85 |
cout << "SII Area:" << hex << setfill('0'); |
|
86 |
for (i = 0; i < min(data.nwords, 0x0040U) * 2; i++) { |
|
87 |
if (i % BreakAfterBytes) { |
|
88 |
cout << " "; |
|
89 |
} else { |
|
90 |
cout << endl << " "; |
|
91 |
} |
|
92 |
cout << setw(2) << (unsigned int) *((uint8_t *) data.words + i); |
|
93 |
} |
|
94 |
cout << endl; |
|
95 |
||
96 |
if (data.nwords > 0x0040U) { |
|
97 |
// cycle through categories |
|
98 |
categoryHeader = data.words + 0x0040U; |
|
99 |
categoryType = le16tocpu(*categoryHeader); |
|
100 |
while (categoryType != 0xffff) { |
|
101 |
cout << "SII Category 0x" << hex |
|
102 |
<< setw(4) << categoryType |
|
103 |
<< " (" << getCategoryName(categoryType) << ")" << flush; |
|
104 |
||
105 |
if (categoryHeader + 1 > data.words + data.nwords) { |
|
106 |
err << "SII data seem to be corrupted!"; |
|
107 |
throwCommandException(err); |
|
108 |
} |
|
109 |
categorySize = le16tocpu(*(categoryHeader + 1)); |
|
110 |
cout << ", " << dec << categorySize << " words" << flush; |
|
111 |
||
112 |
if (categoryHeader + 2 + categorySize |
|
113 |
> data.words + data.nwords) { |
|
114 |
err << "SII data seem to be corrupted!"; |
|
115 |
throwCommandException(err); |
|
116 |
} |
|
117 |
||
118 |
cout << hex; |
|
119 |
for (i = 0; i < categorySize * 2U; i++) { |
|
120 |
if (i % BreakAfterBytes) { |
|
121 |
cout << " "; |
|
122 |
} else { |
|
123 |
cout << endl << " "; |
|
124 |
} |
|
125 |
cout << setw(2) << (unsigned int) |
|
126 |
*((uint8_t *) (categoryHeader + 2) + i); |
|
127 |
} |
|
128 |
cout << endl; |
|
129 |
||
130 |
if (categoryHeader + 2 + categorySize + 1 |
|
131 |
> data.words + data.nwords) { |
|
132 |
err << "SII data seem to be corrupted!"; |
|
133 |
throwCommandException(err); |
|
134 |
} |
|
135 |
categoryHeader += 2 + categorySize; |
|
136 |
categoryType = le16tocpu(*categoryHeader); |
|
137 |
} |
|
138 |
} |
|
139 |
} else { |
|
140 |
for (i = 0; i < data.nwords; i++) { |
|
141 |
uint16_t *w = data.words + i; |
|
142 |
cout << *(uint8_t *) w << *((uint8_t *) w + 1); |
|
143 |
} |
|
144 |
} |
|
145 |
||
146 |
delete [] data.words; |
|
147 |
} |
|
148 |
||
149 |
/****************************************************************************/ |
|
150 |
||
151 |
const CommandSiiRead::CategoryName CommandSiiRead::categoryNames[] = { |
|
152 |
{0x000a, "STRINGS"}, |
|
153 |
{0x0014, "DataTypes"}, |
|
154 |
{0x001e, "General"}, |
|
155 |
{0x0028, "FMMU"}, |
|
156 |
{0x0029, "SyncM"}, |
|
157 |
{0x0032, "TXPDO"}, |
|
158 |
{0x0033, "RXPDO"}, |
|
159 |
{0x003c, "DC"}, |
|
160 |
{} |
|
161 |
}; |
|
162 |
||
163 |
/****************************************************************************/ |
|
164 |
||
165 |
const char *CommandSiiRead::getCategoryName(uint16_t type) |
|
166 |
{ |
|
167 |
const CategoryName *cn = categoryNames; |
|
168 |
||
169 |
while (cn->type) { |
|
170 |
if (cn->type == type) { |
|
171 |
return cn->name; |
|
172 |
} |
|
173 |
cn++; |
|
174 |
} |
|
175 |
||
176 |
return "unknown"; |
|
177 |
} |
|
178 |
||
179 |
/*****************************************************************************/ |