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