1142
|
1 |
/*****************************************************************************
|
|
2 |
*
|
|
3 |
* $Id$
|
|
4 |
*
|
|
5 |
****************************************************************************/
|
|
6 |
|
|
7 |
#include <iostream>
|
|
8 |
#include <iomanip>
|
|
9 |
using namespace std;
|
|
10 |
|
|
11 |
#include "CommandPdos.h"
|
|
12 |
|
|
13 |
/*****************************************************************************/
|
|
14 |
|
|
15 |
CommandPdos::CommandPdos():
|
|
16 |
Command("pdos", "List Sync managers, Pdo assignment and mapping.")
|
|
17 |
{
|
|
18 |
}
|
|
19 |
|
|
20 |
/*****************************************************************************/
|
|
21 |
|
|
22 |
string CommandPdos::helpString() const
|
|
23 |
{
|
|
24 |
stringstream str;
|
|
25 |
|
|
26 |
str << getName() << " [OPTIONS]" << endl
|
|
27 |
<< endl
|
|
28 |
<< getBriefDescription() << endl
|
|
29 |
<< endl
|
|
30 |
<< "The information is displayed in three layers, which are" << endl
|
|
31 |
<< "indented accordingly:" << endl
|
|
32 |
<< endl
|
|
33 |
<< "1) Sync managers - Contains the sync manager information" << endl
|
|
34 |
<< " from the SII: Index, physical start address, default" << endl
|
|
35 |
<< " size (value from the SII), control register and enable" << endl
|
|
36 |
<< " word. Example:" << endl
|
|
37 |
<< endl
|
|
38 |
<< " SM3: PhysAddr 0x1100, DefaultSize 0, ControlRegister 0x20,"
|
|
39 |
<< "Enable 1" << endl
|
|
40 |
<< endl
|
|
41 |
<< "2) Assigned Pdos - Pdo direction, hexadecimal index and" << endl
|
|
42 |
<< " -if available- the Pdo name. Example:" << endl
|
|
43 |
<< endl
|
|
44 |
<< " TxPdo 0x1a00 \"Channel1\"" << endl
|
|
45 |
<< endl
|
|
46 |
<< "3) Mapped Pdo entries - Pdo entry index and subindex (both" << endl
|
|
47 |
<< " hexadecimal), the length in bit and -if available- the" << endl
|
|
48 |
<< " description. Example:" << endl
|
|
49 |
<< endl
|
|
50 |
<< " Pdo entry 0x3101:01, 8 bit, \"Status\"" << endl
|
|
51 |
<< endl
|
|
52 |
<< "Note, that the displayed Pdo assignment and Pdo mapping" << endl
|
|
53 |
<< "information can either originate from the SII or from the" << endl
|
|
54 |
<< "CoE communication area." << endl
|
|
55 |
<< endl
|
|
56 |
<< "Command-specific options:" << endl
|
|
57 |
<< " --slave -s <index> Positive numerical ring position," << endl
|
|
58 |
<< " or 'all' forall slaves (default)." << endl
|
|
59 |
<< endl
|
|
60 |
<< numericInfo();
|
|
61 |
|
|
62 |
return str.str();
|
|
63 |
}
|
|
64 |
|
|
65 |
/****************************************************************************/
|
|
66 |
|
|
67 |
void CommandPdos::execute(MasterDevice &m, const StringVector &args)
|
|
68 |
{
|
|
69 |
m.open(MasterDevice::Read);
|
|
70 |
|
|
71 |
if (slavePosition == -1) {
|
|
72 |
unsigned int numSlaves = m.slaveCount(), i;
|
|
73 |
|
|
74 |
for (i = 0; i < numSlaves; i++) {
|
|
75 |
listSlavePdos(m, i, true);
|
|
76 |
}
|
|
77 |
} else {
|
|
78 |
listSlavePdos(m, slavePosition, false);
|
|
79 |
}
|
|
80 |
}
|
|
81 |
|
|
82 |
/****************************************************************************/
|
|
83 |
|
|
84 |
void CommandPdos::listSlavePdos(
|
|
85 |
MasterDevice &m,
|
|
86 |
uint16_t slavePosition,
|
|
87 |
bool withHeader
|
|
88 |
)
|
|
89 |
{
|
|
90 |
ec_ioctl_slave_t slave;
|
|
91 |
ec_ioctl_slave_sync_t sync;
|
|
92 |
ec_ioctl_slave_sync_pdo_t pdo;
|
|
93 |
ec_ioctl_slave_sync_pdo_entry_t entry;
|
|
94 |
unsigned int i, j, k;
|
|
95 |
|
|
96 |
m.getSlave(&slave, slavePosition);
|
|
97 |
|
|
98 |
if (withHeader)
|
|
99 |
cout << "=== Slave " << slavePosition << " ===" << endl;
|
|
100 |
|
|
101 |
for (i = 0; i < slave.sync_count; i++) {
|
|
102 |
m.getSync(&sync, slavePosition, i);
|
|
103 |
|
|
104 |
cout << "SM" << i << ":"
|
|
105 |
<< " PhysAddr 0x"
|
|
106 |
<< hex << setfill('0')
|
|
107 |
<< setw(4) << sync.physical_start_address
|
|
108 |
<< ", DefaultSize "
|
|
109 |
<< dec << setfill(' ') << setw(4) << sync.default_size
|
|
110 |
<< ", ControlRegister 0x"
|
|
111 |
<< hex << setfill('0') << setw(2)
|
|
112 |
<< (unsigned int) sync.control_register
|
|
113 |
<< ", Enable " << dec << (unsigned int) sync.enable
|
|
114 |
<< endl;
|
|
115 |
|
|
116 |
for (j = 0; j < sync.pdo_count; j++) {
|
|
117 |
m.getPdo(&pdo, slavePosition, i, j);
|
|
118 |
|
|
119 |
cout << " " << (sync.control_register & 0x04 ? "R" : "T")
|
|
120 |
<< "xPdo 0x"
|
|
121 |
<< hex << setfill('0')
|
|
122 |
<< setw(4) << pdo.index
|
|
123 |
<< " \"" << pdo.name << "\"" << endl;
|
|
124 |
|
|
125 |
if (getVerbosity() == Quiet)
|
|
126 |
continue;
|
|
127 |
|
|
128 |
for (k = 0; k < pdo.entry_count; k++) {
|
|
129 |
m.getPdoEntry(&entry, slavePosition, i, j, k);
|
|
130 |
|
|
131 |
cout << " Pdo entry 0x"
|
|
132 |
<< hex << setfill('0')
|
|
133 |
<< setw(4) << entry.index
|
|
134 |
<< ":" << setw(2) << (unsigned int) entry.subindex
|
|
135 |
<< ", " << dec << (unsigned int) entry.bit_length
|
|
136 |
<< " bit, \"" << entry.name << "\"" << endl;
|
|
137 |
}
|
|
138 |
}
|
|
139 |
}
|
|
140 |
}
|
|
141 |
|
|
142 |
/*****************************************************************************/
|