equal
deleted
inserted
replaced
49 if ((fd = ::open(deviceName.str().c_str(), |
49 if ((fd = ::open(deviceName.str().c_str(), |
50 perm == ReadWrite ? O_RDWR : O_RDONLY)) == -1) { |
50 perm == ReadWrite ? O_RDWR : O_RDONLY)) == -1) { |
51 stringstream err; |
51 stringstream err; |
52 err << "Failed to open master device " << deviceName.str() << ": " |
52 err << "Failed to open master device " << deviceName.str() << ": " |
53 << strerror(errno); |
53 << strerror(errno); |
54 throw MasterDeviceException(err.str()); |
54 throw MasterDeviceException(err); |
55 } |
55 } |
56 } |
56 } |
57 } |
57 } |
58 |
58 |
59 /****************************************************************************/ |
59 /****************************************************************************/ |
81 void MasterDevice::getMaster(ec_ioctl_master_t *data) |
81 void MasterDevice::getMaster(ec_ioctl_master_t *data) |
82 { |
82 { |
83 if (ioctl(fd, EC_IOCTL_MASTER, data) < 0) { |
83 if (ioctl(fd, EC_IOCTL_MASTER, data) < 0) { |
84 stringstream err; |
84 stringstream err; |
85 err << "Failed to get master information: " << strerror(errno); |
85 err << "Failed to get master information: " << strerror(errno); |
86 throw MasterDeviceException(err.str()); |
86 throw MasterDeviceException(err); |
87 } |
87 } |
88 } |
88 } |
89 |
89 |
90 /****************************************************************************/ |
90 /****************************************************************************/ |
91 |
91 |
94 data->config_index = index; |
94 data->config_index = index; |
95 |
95 |
96 if (ioctl(fd, EC_IOCTL_CONFIG, data) < 0) { |
96 if (ioctl(fd, EC_IOCTL_CONFIG, data) < 0) { |
97 stringstream err; |
97 stringstream err; |
98 err << "Failed to get slave configuration: " << strerror(errno); |
98 err << "Failed to get slave configuration: " << strerror(errno); |
99 throw MasterDeviceException(err.str()); |
99 throw MasterDeviceException(err); |
100 } |
100 } |
101 } |
101 } |
102 |
102 |
103 /****************************************************************************/ |
103 /****************************************************************************/ |
104 |
104 |
114 data->pdo_pos = pdo_pos; |
114 data->pdo_pos = pdo_pos; |
115 |
115 |
116 if (ioctl(fd, EC_IOCTL_CONFIG_PDO, data) < 0) { |
116 if (ioctl(fd, EC_IOCTL_CONFIG_PDO, data) < 0) { |
117 stringstream err; |
117 stringstream err; |
118 err << "Failed to get slave config Pdo: " << strerror(errno); |
118 err << "Failed to get slave config Pdo: " << strerror(errno); |
119 throw MasterDeviceException(err.str()); |
119 throw MasterDeviceException(err); |
120 } |
120 } |
121 } |
121 } |
122 |
122 |
123 /****************************************************************************/ |
123 /****************************************************************************/ |
124 |
124 |
136 data->entry_pos = entry_pos; |
136 data->entry_pos = entry_pos; |
137 |
137 |
138 if (ioctl(fd, EC_IOCTL_CONFIG_PDO_ENTRY, data) < 0) { |
138 if (ioctl(fd, EC_IOCTL_CONFIG_PDO_ENTRY, data) < 0) { |
139 stringstream err; |
139 stringstream err; |
140 err << "Failed to get slave config Pdo entry: " << strerror(errno); |
140 err << "Failed to get slave config Pdo entry: " << strerror(errno); |
141 throw MasterDeviceException(err.str()); |
141 throw MasterDeviceException(err); |
142 } |
142 } |
143 } |
143 } |
144 |
144 |
145 /****************************************************************************/ |
145 /****************************************************************************/ |
146 |
146 |
154 data->sdo_pos = sdo_pos; |
154 data->sdo_pos = sdo_pos; |
155 |
155 |
156 if (ioctl(fd, EC_IOCTL_CONFIG_SDO, data) < 0) { |
156 if (ioctl(fd, EC_IOCTL_CONFIG_SDO, data) < 0) { |
157 stringstream err; |
157 stringstream err; |
158 err << "Failed to get slave config Sdo: " << strerror(errno); |
158 err << "Failed to get slave config Sdo: " << strerror(errno); |
159 throw MasterDeviceException(err.str()); |
159 throw MasterDeviceException(err); |
160 } |
160 } |
161 } |
161 } |
162 |
162 |
163 /****************************************************************************/ |
163 /****************************************************************************/ |
164 |
164 |
171 err << "Failed to get domain: "; |
171 err << "Failed to get domain: "; |
172 if (errno == EINVAL) |
172 if (errno == EINVAL) |
173 err << "Domain " << index << " does not exist!"; |
173 err << "Domain " << index << " does not exist!"; |
174 else |
174 else |
175 err << strerror(errno); |
175 err << strerror(errno); |
176 throw MasterDeviceException(err.str()); |
176 throw MasterDeviceException(err); |
177 } |
177 } |
178 } |
178 } |
179 |
179 |
180 /****************************************************************************/ |
180 /****************************************************************************/ |
181 |
181 |
187 data->target = mem; |
187 data->target = mem; |
188 |
188 |
189 if (ioctl(fd, EC_IOCTL_DOMAIN_DATA, data) < 0) { |
189 if (ioctl(fd, EC_IOCTL_DOMAIN_DATA, data) < 0) { |
190 stringstream err; |
190 stringstream err; |
191 err << "Failed to get domain data: " << strerror(errno); |
191 err << "Failed to get domain data: " << strerror(errno); |
192 throw MasterDeviceException(err.str()); |
192 throw MasterDeviceException(err); |
193 } |
193 } |
194 } |
194 } |
195 |
195 |
196 /****************************************************************************/ |
196 /****************************************************************************/ |
197 |
197 |
204 err << "Failed to get slave: "; |
204 err << "Failed to get slave: "; |
205 if (errno == EINVAL) |
205 if (errno == EINVAL) |
206 err << "Slave " << slaveIndex << " does not exist!"; |
206 err << "Slave " << slaveIndex << " does not exist!"; |
207 else |
207 else |
208 err << strerror(errno); |
208 err << strerror(errno); |
209 throw MasterDeviceException(err.str()); |
209 throw MasterDeviceException(err); |
210 } |
210 } |
211 } |
211 } |
212 |
212 |
213 /****************************************************************************/ |
213 /****************************************************************************/ |
214 |
214 |
222 fmmu->fmmu_index = fmmuIndex; |
222 fmmu->fmmu_index = fmmuIndex; |
223 |
223 |
224 if (ioctl(fd, EC_IOCTL_DOMAIN_FMMU, fmmu)) { |
224 if (ioctl(fd, EC_IOCTL_DOMAIN_FMMU, fmmu)) { |
225 stringstream err; |
225 stringstream err; |
226 err << "Failed to get domain FMMU: " << strerror(errno); |
226 err << "Failed to get domain FMMU: " << strerror(errno); |
227 throw MasterDeviceException(err.str()); |
227 throw MasterDeviceException(err); |
228 } |
228 } |
229 } |
229 } |
230 |
230 |
231 /****************************************************************************/ |
231 /****************************************************************************/ |
232 |
232 |
240 sync->sync_index = syncIndex; |
240 sync->sync_index = syncIndex; |
241 |
241 |
242 if (ioctl(fd, EC_IOCTL_SLAVE_SYNC, sync)) { |
242 if (ioctl(fd, EC_IOCTL_SLAVE_SYNC, sync)) { |
243 stringstream err; |
243 stringstream err; |
244 err << "Failed to get sync manager: " << strerror(errno); |
244 err << "Failed to get sync manager: " << strerror(errno); |
245 throw MasterDeviceException(err.str()); |
245 throw MasterDeviceException(err); |
246 } |
246 } |
247 } |
247 } |
248 |
248 |
249 /****************************************************************************/ |
249 /****************************************************************************/ |
250 |
250 |
260 pdo->pdo_pos = pdoPos; |
260 pdo->pdo_pos = pdoPos; |
261 |
261 |
262 if (ioctl(fd, EC_IOCTL_SLAVE_SYNC_PDO, pdo)) { |
262 if (ioctl(fd, EC_IOCTL_SLAVE_SYNC_PDO, pdo)) { |
263 stringstream err; |
263 stringstream err; |
264 err << "Failed to get Pdo: " << strerror(errno); |
264 err << "Failed to get Pdo: " << strerror(errno); |
265 throw MasterDeviceException(err.str()); |
265 throw MasterDeviceException(err); |
266 } |
266 } |
267 } |
267 } |
268 |
268 |
269 /****************************************************************************/ |
269 /****************************************************************************/ |
270 |
270 |
282 entry->entry_pos = entryPos; |
282 entry->entry_pos = entryPos; |
283 |
283 |
284 if (ioctl(fd, EC_IOCTL_SLAVE_SYNC_PDO_ENTRY, entry)) { |
284 if (ioctl(fd, EC_IOCTL_SLAVE_SYNC_PDO_ENTRY, entry)) { |
285 stringstream err; |
285 stringstream err; |
286 err << "Failed to get Pdo entry: " << strerror(errno); |
286 err << "Failed to get Pdo entry: " << strerror(errno); |
287 throw MasterDeviceException(err.str()); |
287 throw MasterDeviceException(err); |
288 } |
288 } |
289 } |
289 } |
290 |
290 |
291 /****************************************************************************/ |
291 /****************************************************************************/ |
292 |
292 |
300 sdo->sdo_position = sdoPosition; |
300 sdo->sdo_position = sdoPosition; |
301 |
301 |
302 if (ioctl(fd, EC_IOCTL_SLAVE_SDO, sdo)) { |
302 if (ioctl(fd, EC_IOCTL_SLAVE_SDO, sdo)) { |
303 stringstream err; |
303 stringstream err; |
304 err << "Failed to get Sdo: " << strerror(errno); |
304 err << "Failed to get Sdo: " << strerror(errno); |
305 throw MasterDeviceException(err.str()); |
305 throw MasterDeviceException(err); |
306 } |
306 } |
307 } |
307 } |
308 |
308 |
309 /****************************************************************************/ |
309 /****************************************************************************/ |
310 |
310 |
320 entry->sdo_entry_subindex = entrySubindex; |
320 entry->sdo_entry_subindex = entrySubindex; |
321 |
321 |
322 if (ioctl(fd, EC_IOCTL_SLAVE_SDO_ENTRY, entry)) { |
322 if (ioctl(fd, EC_IOCTL_SLAVE_SDO_ENTRY, entry)) { |
323 stringstream err; |
323 stringstream err; |
324 err << "Failed to get Sdo entry: " << strerror(errno); |
324 err << "Failed to get Sdo entry: " << strerror(errno); |
325 throw MasterDeviceException(err.str()); |
325 throw MasterDeviceException(err); |
326 } |
326 } |
327 } |
327 } |
328 |
328 |
329 /****************************************************************************/ |
329 /****************************************************************************/ |
330 |
330 |
333 ) |
333 ) |
334 { |
334 { |
335 if (ioctl(fd, EC_IOCTL_SLAVE_SII_READ, data) < 0) { |
335 if (ioctl(fd, EC_IOCTL_SLAVE_SII_READ, data) < 0) { |
336 stringstream err; |
336 stringstream err; |
337 err << "Failed to read SII: " << strerror(errno); |
337 err << "Failed to read SII: " << strerror(errno); |
338 throw MasterDeviceException(err.str()); |
338 throw MasterDeviceException(err); |
339 } |
339 } |
340 } |
340 } |
341 |
341 |
342 /****************************************************************************/ |
342 /****************************************************************************/ |
343 |
343 |
346 ) |
346 ) |
347 { |
347 { |
348 if (ioctl(fd, EC_IOCTL_SLAVE_SII_WRITE, data) < 0) { |
348 if (ioctl(fd, EC_IOCTL_SLAVE_SII_WRITE, data) < 0) { |
349 stringstream err; |
349 stringstream err; |
350 err << "Failed to write SII: " << strerror(errno); |
350 err << "Failed to write SII: " << strerror(errno); |
351 throw MasterDeviceException(err.str()); |
351 throw MasterDeviceException(err); |
352 } |
352 } |
353 } |
353 } |
354 |
354 |
355 /****************************************************************************/ |
355 /****************************************************************************/ |
356 |
356 |
357 void MasterDevice::setDebug(unsigned int debugLevel) |
357 void MasterDevice::setDebug(unsigned int debugLevel) |
358 { |
358 { |
359 if (ioctl(fd, EC_IOCTL_MASTER_DEBUG, debugLevel) < 0) { |
359 if (ioctl(fd, EC_IOCTL_MASTER_DEBUG, debugLevel) < 0) { |
360 stringstream err; |
360 stringstream err; |
361 err << "Failed to set debug level: " << strerror(errno); |
361 err << "Failed to set debug level: " << strerror(errno); |
362 throw MasterDeviceException(err.str()); |
362 throw MasterDeviceException(err); |
363 } |
363 } |
364 } |
364 } |
365 |
365 |
366 /****************************************************************************/ |
366 /****************************************************************************/ |
367 |
367 |
374 err << "Abort code 0x" << hex << setfill('0') |
374 err << "Abort code 0x" << hex << setfill('0') |
375 << setw(8) << data->abort_code; |
375 << setw(8) << data->abort_code; |
376 } else { |
376 } else { |
377 err << strerror(errno); |
377 err << strerror(errno); |
378 } |
378 } |
379 throw MasterDeviceException(err.str()); |
379 throw MasterDeviceException(err); |
380 } |
380 } |
381 } |
381 } |
382 |
382 |
383 /****************************************************************************/ |
383 /****************************************************************************/ |
384 |
384 |
391 err << "Abort code 0x" << hex << setfill('0') |
391 err << "Abort code 0x" << hex << setfill('0') |
392 << setw(8) << data->abort_code; |
392 << setw(8) << data->abort_code; |
393 } else { |
393 } else { |
394 err << strerror(errno); |
394 err << strerror(errno); |
395 } |
395 } |
396 throw MasterDeviceException(err.str()); |
396 throw MasterDeviceException(err); |
397 } |
397 } |
398 } |
398 } |
399 |
399 |
400 /****************************************************************************/ |
400 /****************************************************************************/ |
401 |
401 |
414 err << "Failed to request slave state: "; |
414 err << "Failed to request slave state: "; |
415 if (errno == EINVAL) |
415 if (errno == EINVAL) |
416 err << "Slave " << slavePosition << " does not exist!"; |
416 err << "Slave " << slavePosition << " does not exist!"; |
417 else |
417 else |
418 err << strerror(errno); |
418 err << strerror(errno); |
419 throw MasterDeviceException(err.str()); |
419 throw MasterDeviceException(err); |
420 } |
420 } |
421 } |
421 } |
422 |
422 |
423 /*****************************************************************************/ |
423 /*****************************************************************************/ |