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