95 stringstream err; |
95 stringstream err; |
96 err << "Invalid debug level '" << commandArgs[0] << "'!"; |
96 err << "Invalid debug level '" << commandArgs[0] << "'!"; |
97 throw MasterException(err.str()); |
97 throw MasterException(err.str()); |
98 } |
98 } |
99 |
99 |
100 if (ioctl(fd, EC_IOCTL_DEBUG_LEVEL, debugLevel) < 0) { |
100 if (ioctl(fd, EC_IOCTL_SET_DEBUG, debugLevel) < 0) { |
101 stringstream err; |
101 stringstream err; |
102 err << "Failed to set debug level: " << strerror(errno); |
102 err << "Failed to set debug level: " << strerror(errno); |
103 throw MasterException(err.str()); |
103 throw MasterException(err.str()); |
104 } |
104 } |
105 } |
105 } |
148 } else { |
148 } else { |
149 cout << "0x" << hex << setfill('0') << slave.vendor_id |
149 cout << "0x" << hex << setfill('0') << slave.vendor_id |
150 << ":0x" << slave.product_code; |
150 << ":0x" << slave.product_code; |
151 } |
151 } |
152 |
152 |
|
153 cout << endl; |
|
154 } |
|
155 } |
|
156 |
|
157 /****************************************************************************/ |
|
158 |
|
159 void Master::showMaster() |
|
160 { |
|
161 ec_ioctl_master_t data; |
|
162 stringstream err; |
|
163 unsigned int i; |
|
164 |
|
165 getMaster(&data); |
|
166 |
|
167 cout |
|
168 << "Master" << index << endl |
|
169 << " State: "; |
|
170 |
|
171 switch (data.mode) { |
|
172 case 0: cout << "Waiting for device..."; break; |
|
173 case 1: cout << "Idle"; break; |
|
174 case 2: cout << "Operation"; break; |
|
175 default: |
|
176 err << "Invalid master state " << data.mode; |
|
177 throw MasterException(err.str()); |
|
178 } |
|
179 |
|
180 cout << endl |
|
181 << " Slaves: " << data.slave_count << endl; |
|
182 |
|
183 for (i = 0; i < 2; i++) { |
|
184 cout << " Device" << i << ": "; |
|
185 if (data.devices[i].address[0] == 0x00 |
|
186 && data.devices[i].address[1] == 0x00 |
|
187 && data.devices[i].address[2] == 0x00 |
|
188 && data.devices[i].address[3] == 0x00 |
|
189 && data.devices[i].address[4] == 0x00 |
|
190 && data.devices[i].address[5] == 0x00) { |
|
191 cout << "None."; |
|
192 } else { |
|
193 cout << hex << setfill('0') |
|
194 << setw(2) << (unsigned int) data.devices[i].address[0] << ":" |
|
195 << setw(2) << (unsigned int) data.devices[i].address[1] << ":" |
|
196 << setw(2) << (unsigned int) data.devices[i].address[2] << ":" |
|
197 << setw(2) << (unsigned int) data.devices[i].address[3] << ":" |
|
198 << setw(2) << (unsigned int) data.devices[i].address[4] << ":" |
|
199 << setw(2) << (unsigned int) data.devices[i].address[5] << " (" |
|
200 << (data.devices[i].attached ? "attached" : "waiting...") |
|
201 << ")" << endl << dec |
|
202 << " Tx count: " << data.devices[i].tx_count << endl |
|
203 << " Rx count: " << data.devices[i].rx_count; |
|
204 } |
153 cout << endl; |
205 cout << endl; |
154 } |
206 } |
155 } |
207 } |
156 |
208 |
157 /****************************************************************************/ |
209 /****************************************************************************/ |
442 |
494 |
443 /****************************************************************************/ |
495 /****************************************************************************/ |
444 |
496 |
445 unsigned int Master::slaveCount() |
497 unsigned int Master::slaveCount() |
446 { |
498 { |
447 int ret; |
499 ec_ioctl_master_t data; |
448 |
500 |
449 if ((ret = ioctl(fd, EC_IOCTL_SLAVE_COUNT, 0)) < 0) { |
501 getMaster(&data); |
450 stringstream err; |
502 return data.slave_count; |
451 err << "Failed to get number of slaves: " << strerror(errno); |
503 } |
452 throw MasterException(err.str()); |
504 |
453 } |
505 /****************************************************************************/ |
454 |
506 |
455 return ret; |
507 void Master::getMaster(ec_ioctl_master_t *data) |
|
508 { |
|
509 if (ioctl(fd, EC_IOCTL_MASTER, data) < 0) { |
|
510 stringstream err; |
|
511 err << "Failed to get master information: " << strerror(errno); |
|
512 throw MasterException(err.str()); |
|
513 } |
456 } |
514 } |
457 |
515 |
458 /****************************************************************************/ |
516 /****************************************************************************/ |
459 |
517 |
460 void Master::getDomain(ec_ioctl_domain_t *data, unsigned int index) |
518 void Master::getDomain(ec_ioctl_domain_t *data, unsigned int index) |