equal
deleted
inserted
replaced
68 |
68 |
69 /*****************************************************************************/ |
69 /*****************************************************************************/ |
70 |
70 |
71 /** \cond */ |
71 /** \cond */ |
72 |
72 |
73 EC_SYSFS_READ_ATTR(image_size); |
73 EC_SYSFS_READ_ATTR(size); |
|
74 EC_SYSFS_READ_ATTR(data); |
74 |
75 |
75 static struct attribute *def_attrs[] = { |
76 static struct attribute *def_attrs[] = { |
76 &attr_image_size, |
77 &attr_size, |
|
78 &attr_data, |
77 NULL, |
79 NULL, |
78 }; |
80 }; |
79 |
81 |
80 static struct sysfs_ops sysfs_ops = { |
82 static struct sysfs_ops sysfs_ops = { |
81 .show = &ec_show_domain_attribute, |
83 .show = &ec_show_domain_attribute, |
378 return 0; |
380 return 0; |
379 } |
381 } |
380 |
382 |
381 /*****************************************************************************/ |
383 /*****************************************************************************/ |
382 |
384 |
|
385 /** Outputs domain data. |
|
386 */ |
|
387 size_t ec_domain_output_data( |
|
388 const ec_domain_t *domain, /**< EtherCAT domain. */ |
|
389 char *buffer /**< Output buffer */ |
|
390 ) |
|
391 { |
|
392 off_t off = 0; |
|
393 ec_datagram_t *datagram; |
|
394 |
|
395 list_for_each_entry(datagram, &domain->datagrams, list) { |
|
396 if (off + datagram->data_size > PAGE_SIZE) |
|
397 return -EFBIG; // file too large |
|
398 memcpy(buffer + off, datagram->data, datagram->data_size); |
|
399 off += datagram->data_size; |
|
400 } |
|
401 |
|
402 return off; |
|
403 } |
|
404 |
|
405 /*****************************************************************************/ |
|
406 |
383 /** |
407 /** |
384 Formats attribute data for SysFS reading. |
408 Formats attribute data for SysFS reading. |
385 \return number of bytes to read |
409 \return number of bytes to read |
386 */ |
410 */ |
387 |
411 |
390 char *buffer /**< memory to store data in */ |
414 char *buffer /**< memory to store data in */ |
391 ) |
415 ) |
392 { |
416 { |
393 ec_domain_t *domain = container_of(kobj, ec_domain_t, kobj); |
417 ec_domain_t *domain = container_of(kobj, ec_domain_t, kobj); |
394 |
418 |
395 if (attr == &attr_image_size) { |
419 if (attr == &attr_size) { |
396 return sprintf(buffer, "%i\n", domain->data_size); |
420 return sprintf(buffer, "%u\n", domain->data_size); |
|
421 } else if (attr == &attr_data) { |
|
422 return ec_domain_output_data(domain, buffer); |
397 } |
423 } |
398 |
424 |
399 return 0; |
425 return 0; |
400 } |
426 } |
401 |
427 |