|
1 /***************************************************************************** |
|
2 * |
|
3 * $Id$ |
|
4 * |
|
5 ****************************************************************************/ |
|
6 |
|
7 #include <list> |
|
8 #include <iostream> |
|
9 #include <iomanip> |
|
10 #include <sstream> |
|
11 using namespace std; |
|
12 |
|
13 #include "globals.h" |
|
14 |
|
15 /*****************************************************************************/ |
|
16 |
|
17 const char *help_config = |
|
18 "[OPTIONS]\n" |
|
19 "\n" |
|
20 "\n" |
|
21 "Command-specific options:\n"; |
|
22 |
|
23 /*****************************************************************************/ |
|
24 |
|
25 struct ConfigInfo { |
|
26 string alias; |
|
27 string pos; |
|
28 string ident; |
|
29 string att; |
|
30 string op; |
|
31 }; |
|
32 |
|
33 typedef list<ec_ioctl_config_t> ConfigList; |
|
34 |
|
35 void showDetailedConfigs(const ConfigList &configList); |
|
36 void listConfigs(const ConfigList &configList); |
|
37 |
|
38 /*****************************************************************************/ |
|
39 |
|
40 bool operator<(const ec_ioctl_config_t &a, const ec_ioctl_config_t &b) |
|
41 { |
|
42 return a.alias < b.alias |
|
43 || (a.alias == b.alias && a.position < b.position); |
|
44 } |
|
45 |
|
46 /*****************************************************************************/ |
|
47 |
|
48 /** Lists the bus configuration. |
|
49 */ |
|
50 void command_config(void) |
|
51 { |
|
52 ec_ioctl_master_t master; |
|
53 unsigned int i; |
|
54 ec_ioctl_config_t config; |
|
55 ConfigList configList; |
|
56 |
|
57 masterDev.open(MasterDevice::Read); |
|
58 masterDev.getMaster(&master); |
|
59 |
|
60 for (i = 0; i < master.config_count; i++) { |
|
61 masterDev.getConfig(&config, i); |
|
62 configList.push_back(config); |
|
63 } |
|
64 |
|
65 configList.sort(); |
|
66 |
|
67 if (verbosity == Verbose) { |
|
68 showDetailedConfigs(configList); |
|
69 } else { |
|
70 listConfigs(configList); |
|
71 } |
|
72 } |
|
73 |
|
74 /*****************************************************************************/ |
|
75 |
|
76 /** Lists the complete bus configuration. |
|
77 */ |
|
78 void showDetailedConfigs(const ConfigList &configList) |
|
79 { |
|
80 ConfigList::const_iterator configIter; |
|
81 unsigned int j, k, l; |
|
82 ec_ioctl_config_pdo_t pdo; |
|
83 ec_ioctl_config_pdo_entry_t entry; |
|
84 ec_ioctl_config_sdo_t sdo; |
|
85 |
|
86 for (configIter = configList.begin(); |
|
87 configIter != configList.end(); |
|
88 configIter++) { |
|
89 |
|
90 cout << "Alias: " |
|
91 << dec << configIter->alias << endl |
|
92 << "Position: " << configIter->position << endl |
|
93 << "Vendor Id: 0x" |
|
94 << hex << setfill('0') |
|
95 << setw(8) << configIter->vendor_id << endl |
|
96 << "Product code: 0x" |
|
97 << setw(8) << configIter->product_code << endl |
|
98 << "Attached: " << (configIter->attached ? "yes" : "no") << endl |
|
99 << "Operational: " << (configIter->operational ? "yes" : "no") << endl; |
|
100 |
|
101 for (j = 0; j < EC_MAX_SYNC_MANAGERS; j++) { |
|
102 if (configIter->syncs[j].pdo_count) { |
|
103 cout << "SM" << dec << j << " (" |
|
104 << (configIter->syncs[j].dir == EC_DIR_INPUT |
|
105 ? "Input" : "Output") << ")" << endl; |
|
106 for (k = 0; k < configIter->syncs[j].pdo_count; k++) { |
|
107 masterDev.getConfigPdo(&pdo, configIter->config_index, j, k); |
|
108 |
|
109 cout << " Pdo 0x" << hex |
|
110 << setw(4) << pdo.index |
|
111 << " \"" << pdo.name << "\"" << endl; |
|
112 |
|
113 for (l = 0; l < pdo.entry_count; l++) { |
|
114 masterDev.getConfigPdoEntry(&entry, |
|
115 configIter->config_index, j, k, l); |
|
116 |
|
117 cout << " Pdo entry 0x" << hex |
|
118 << setw(4) << entry.index << ":" |
|
119 << setw(2) << (unsigned int) entry.subindex |
|
120 << ", " << dec << (unsigned int) entry.bit_length |
|
121 << " bit, \"" << entry.name << "\"" << endl; |
|
122 } |
|
123 } |
|
124 } |
|
125 } |
|
126 |
|
127 cout << "Sdo configuration:" << endl; |
|
128 if (configIter->sdo_count) { |
|
129 for (j = 0; j < configIter->sdo_count; j++) { |
|
130 masterDev.getConfigSdo(&sdo, configIter->config_index, j); |
|
131 |
|
132 cout << " 0x" |
|
133 << hex << setfill('0') |
|
134 << setw(4) << sdo.index << ":" |
|
135 << setw(2) << (unsigned int) sdo.subindex |
|
136 << ", " << dec << sdo.size << " byte: " << hex; |
|
137 |
|
138 switch (sdo.size) { |
|
139 case 1: |
|
140 cout << "0x" << setw(2) |
|
141 << (unsigned int) *(uint8_t *) &sdo.data; |
|
142 break; |
|
143 case 2: |
|
144 cout << "0x" << setw(4) |
|
145 << le16tocpu(*(uint16_t *) &sdo.data); |
|
146 break; |
|
147 case 4: |
|
148 cout << "0x" << setw(8) |
|
149 << le32tocpu(*(uint32_t *) &sdo.data); |
|
150 break; |
|
151 default: |
|
152 cout << "???"; |
|
153 } |
|
154 |
|
155 cout << endl; |
|
156 } |
|
157 } else { |
|
158 cout << " None." << endl; |
|
159 } |
|
160 |
|
161 cout << endl; |
|
162 } |
|
163 } |
|
164 |
|
165 /*****************************************************************************/ |
|
166 |
|
167 /** Lists the bus configuration. |
|
168 */ |
|
169 void listConfigs(const ConfigList &configList) |
|
170 { |
|
171 ConfigList::const_iterator configIter; |
|
172 stringstream str; |
|
173 ConfigInfo info; |
|
174 typedef list<ConfigInfo> ConfigInfoList; |
|
175 ConfigInfoList list; |
|
176 ConfigInfoList::const_iterator iter; |
|
177 unsigned int maxAliasWidth = 0, maxPosWidth = 0, |
|
178 maxAttWidth = 0, maxOpWidth = 0; |
|
179 |
|
180 for (configIter = configList.begin(); |
|
181 configIter != configList.end(); |
|
182 configIter++) { |
|
183 |
|
184 str << dec << configIter->alias; |
|
185 info.alias = str.str(); |
|
186 str.clear(); |
|
187 str.str(""); |
|
188 |
|
189 str << configIter->position; |
|
190 info.pos = str.str(); |
|
191 str.clear(); |
|
192 str.str(""); |
|
193 |
|
194 str << hex << setfill('0') |
|
195 << "0x" << setw(8) << configIter->vendor_id |
|
196 << "/0x" << setw(8) << configIter->product_code; |
|
197 info.ident = str.str(); |
|
198 str.clear(); |
|
199 str.str(""); |
|
200 |
|
201 str << (configIter->attached ? "attached" : "-"); |
|
202 info.att = str.str(); |
|
203 str.clear(); |
|
204 str.str(""); |
|
205 |
|
206 str << (configIter->operational ? "operational" : "-"); |
|
207 info.op = str.str(); |
|
208 str.clear(); |
|
209 str.str(""); |
|
210 |
|
211 list.push_back(info); |
|
212 |
|
213 if (info.alias.length() > maxAliasWidth) |
|
214 maxAliasWidth = info.alias.length(); |
|
215 if (info.pos.length() > maxPosWidth) |
|
216 maxPosWidth = info.pos.length(); |
|
217 if (info.att.length() > maxAttWidth) |
|
218 maxAttWidth = info.att.length(); |
|
219 if (info.op.length() > maxOpWidth) |
|
220 maxOpWidth = info.op.length(); |
|
221 } |
|
222 |
|
223 for (iter = list.begin(); iter != list.end(); iter++) { |
|
224 cout << setfill(' ') << right |
|
225 << setw(maxAliasWidth) << iter->alias |
|
226 << ":" << left |
|
227 << setw(maxPosWidth) << iter->pos |
|
228 << " " |
|
229 << iter->ident |
|
230 << " " |
|
231 << setw(maxAttWidth) << iter->att << " " |
|
232 << setw(maxOpWidth) << iter->op << " " |
|
233 << endl; |
|
234 } |
|
235 } |
|
236 |
|
237 /*****************************************************************************/ |