1142
|
1 |
/*****************************************************************************
|
|
2 |
*
|
|
3 |
* $Id$
|
|
4 |
*
|
|
5 |
****************************************************************************/
|
|
6 |
|
|
7 |
#include <iostream>
|
|
8 |
#include <iomanip>
|
|
9 |
using namespace std;
|
|
10 |
|
|
11 |
#include "CommandSdos.h"
|
|
12 |
#include "coe_datatypes.h"
|
|
13 |
|
|
14 |
/*****************************************************************************/
|
|
15 |
|
|
16 |
CommandSdos::CommandSdos():
|
|
17 |
Command("sdos", "List Sdo dictionaries.")
|
|
18 |
{
|
|
19 |
}
|
|
20 |
|
|
21 |
/*****************************************************************************/
|
|
22 |
|
|
23 |
string CommandSdos::helpString() const
|
|
24 |
{
|
|
25 |
stringstream str;
|
|
26 |
|
|
27 |
str << getName() << " [OPTIONS]" << endl
|
|
28 |
<< endl
|
|
29 |
<< getBriefDescription() << endl
|
|
30 |
<< endl
|
|
31 |
<< "Sdo dictionary information is displayed in two layers," << endl
|
|
32 |
<< "which are indented accordingly:" << endl
|
|
33 |
<< endl
|
|
34 |
<< "1) Sdos - Hexadecimal Sdo index and the name. Example:" << endl
|
|
35 |
<< endl
|
|
36 |
<< " Sdo 0x1018, \"Identity object\"" << endl
|
|
37 |
<< endl
|
|
38 |
<< "2) Sdo entries - Sdo index and Sdo entry subindex (both" << endl
|
|
39 |
<< " hexadecimal) followed by the data type, the length in" << endl
|
|
40 |
<< " bit, and the description. Example:" << endl
|
|
41 |
<< endl
|
|
42 |
<< " 0x1018:01, uint32, 32 bit, \"Vendor id\"" << endl
|
|
43 |
<< endl
|
|
44 |
<< "If the --quiet option is given, only the Sdos are printed."
|
|
45 |
<< endl << endl
|
|
46 |
<< "Command-specific options:" << endl
|
|
47 |
<< " --slave -s <index> Positive numerical ring position," << endl
|
|
48 |
<< " 'all' for all slaves (default)." << endl
|
|
49 |
<< " --quiet -q Print only Sdos (without Sdo" << endl
|
|
50 |
<< " entries)." << endl
|
|
51 |
<< endl
|
|
52 |
<< numericInfo();
|
|
53 |
|
|
54 |
return str.str();
|
|
55 |
}
|
|
56 |
|
|
57 |
/****************************************************************************/
|
|
58 |
|
|
59 |
void CommandSdos::execute(MasterDevice &m, const StringVector &args)
|
|
60 |
{
|
|
61 |
m.open(MasterDevice::Read);
|
|
62 |
|
|
63 |
if (slavePosition == -1) {
|
|
64 |
unsigned int numSlaves = m.slaveCount(), i;
|
|
65 |
|
|
66 |
for (i = 0; i < numSlaves; i++) {
|
|
67 |
listSlaveSdos(m, i, true);
|
|
68 |
}
|
|
69 |
} else {
|
|
70 |
listSlaveSdos(m, slavePosition, false);
|
|
71 |
}
|
|
72 |
}
|
|
73 |
|
|
74 |
/****************************************************************************/
|
|
75 |
|
|
76 |
void CommandSdos::listSlaveSdos(
|
|
77 |
MasterDevice &m,
|
|
78 |
uint16_t slavePosition,
|
|
79 |
bool withHeader
|
|
80 |
)
|
|
81 |
{
|
|
82 |
ec_ioctl_slave_t slave;
|
|
83 |
ec_ioctl_slave_sdo_t sdo;
|
|
84 |
ec_ioctl_slave_sdo_entry_t entry;
|
|
85 |
unsigned int i, j;
|
|
86 |
const CoEDataType *d;
|
|
87 |
|
|
88 |
m.getSlave(&slave, slavePosition);
|
|
89 |
|
|
90 |
if (withHeader)
|
|
91 |
cout << "=== Slave " << slavePosition << " ===" << endl;
|
|
92 |
|
|
93 |
for (i = 0; i < slave.sdo_count; i++) {
|
|
94 |
m.getSdo(&sdo, slavePosition, i);
|
|
95 |
|
|
96 |
cout << "Sdo 0x"
|
|
97 |
<< hex << setfill('0')
|
|
98 |
<< setw(4) << sdo.sdo_index
|
|
99 |
<< ", \"" << sdo.name << "\"" << endl;
|
|
100 |
|
|
101 |
if (getVerbosity() == Quiet)
|
|
102 |
continue;
|
|
103 |
|
|
104 |
for (j = 0; j <= sdo.max_subindex; j++) {
|
|
105 |
m.getSdoEntry(&entry, slavePosition, -i, j);
|
|
106 |
|
|
107 |
cout << " 0x" << hex << setfill('0')
|
|
108 |
<< setw(4) << sdo.sdo_index << ":"
|
|
109 |
<< setw(2) << (unsigned int) entry.sdo_entry_subindex
|
|
110 |
<< ", ";
|
|
111 |
|
|
112 |
if ((d = findDataType(entry.data_type))) {
|
|
113 |
cout << d->name;
|
|
114 |
} else {
|
|
115 |
cout << "type " << setw(4) << entry.data_type;
|
|
116 |
}
|
|
117 |
|
|
118 |
cout << ", " << dec << entry.bit_length << " bit, \""
|
|
119 |
<< entry.description << "\"" << endl;
|
|
120 |
}
|
|
121 |
}
|
|
122 |
}
|
|
123 |
|
|
124 |
/*****************************************************************************/
|