diff --git a/soes/ecat_slv.c b/soes/ecat_slv.c index 16b3fc2..e1e6438 100644 --- a/soes/ecat_slv.c +++ b/soes/ecat_slv.c @@ -96,7 +96,7 @@ uint32_t ESC_download_post_objecthandler (uint16_t index, uint8_t subindex, uint uint32_t ESC_upload_pre_objecthandler (uint16_t index, uint8_t subindex, void * data, - size_t size, + size_t *size, uint16_t flags) { if (ESCvar.pre_object_upload_hook != NULL) diff --git a/soes/esc.h b/soes/esc.h index fda0b0d..73f5328 100644 --- a/soes/esc.h +++ b/soes/esc.h @@ -326,7 +326,7 @@ typedef struct esc_cfg uint32_t (*pre_object_upload_hook) (uint16_t index, uint8_t subindex, void * data, - size_t size, + size_t *size, uint16_t flags); uint32_t (*post_object_upload_hook) (uint16_t index, uint8_t subindex, @@ -450,7 +450,7 @@ typedef struct uint32_t (*pre_object_upload_hook) (uint16_t index, uint8_t subindex, void * data, - size_t size, + size_t *size, uint16_t flags); uint32_t (*post_object_upload_hook) (uint16_t index, uint8_t subindex, diff --git a/soes/esc_coe.c b/soes/esc_coe.c index 58fe954..bc046fa 100644 --- a/soes/esc_coe.c +++ b/soes/esc_coe.c @@ -330,17 +330,18 @@ static void SDO_upload (void) } coeres->index = htoes (index); coeres->subindex = subindex; - if (size <= 32) + coeres->command = COE_COMMAND_UPLOADRESPONSE + + COE_SIZE_INDICATOR; + /* convert bits to bytes */ + size = BITS2BYTES(size); + if (size <= 4) { /* expedited response i.e. length<=4 bytes */ - coeres->command = COE_COMMAND_UPLOADRESPONSE + - COE_SIZE_INDICATOR + COE_EXPEDITED_INDICATOR + dss; - /* convert bits to bytes */ - size = BITS2BYTES(size); + coeres->command += COE_EXPEDITED_INDICATOR + dss; void *dataptr = ((objd + nsub)->data) ? (objd + nsub)->data : (void *)&((objd + nsub)->value); abort = ESC_upload_pre_objecthandler (index, subindex, - dataptr, size, (objd + nsub)->flags); + dataptr, (size_t *)&size, (objd + nsub)->flags); if (abort == 0) { if ((objd + nsub)->data == NULL) @@ -362,34 +363,31 @@ static void SDO_upload (void) else { /* normal response i.e. length>4 bytes */ - coeres->command = COE_COMMAND_UPLOADRESPONSE + - COE_SIZE_INDICATOR; - /* convert bits to bytes */ - size = BITS2BYTES(size); - /* set total size in bytes */ - ESCvar.frags = size; - coeres->size = htoel (size); - if ((size + COE_HEADERSIZE) > ESC_MBXDSIZE) - { - /* segmented transfer needed */ - /* limit to mailbox size */ - size = ESC_MBXDSIZE - COE_HEADERSIZE; - /* number of bytes done */ - ESCvar.fragsleft = size; - /* signal segmented transfer */ - ESCvar.segmented = MBXSEU; - ESCvar.data = (objd + nsub)->data; - ESCvar.flags = (objd + nsub)->flags; - } - else - { - ESCvar.segmented = 0; - } - coeres->mbxheader.length = htoes (COE_HEADERSIZE + size); abort = ESC_upload_pre_objecthandler (index, subindex, - (objd + nsub)->data, ESCvar.frags, (objd + nsub)->flags); + (objd + nsub)->data, (size_t *)&size, (objd + nsub)->flags); if (abort == 0) { + /* set total size in bytes */ + ESCvar.frags = size; + coeres->size = htoel (size); + if ((size + COE_HEADERSIZE) > ESC_MBXDSIZE) + { + /* segmented transfer needed */ + /* limit to mailbox size */ + size = ESC_MBXDSIZE - COE_HEADERSIZE; + /* number of bytes done */ + ESCvar.fragsleft = size; + /* signal segmented transfer */ + ESCvar.segmented = MBXSEU; + ESCvar.data = (objd + nsub)->data; + ESCvar.flags = (objd + nsub)->flags; + } + else + { + ESCvar.segmented = 0; + } + coeres->mbxheader.length = htoes (COE_HEADERSIZE + size); + /* use dynamic data */ copy2mbx ((objd + nsub)->data, (&(coeres->size)) + 1, size); } @@ -597,8 +595,14 @@ static void SDO_upload_complete_access (void) return; } + /* expedited bits used calculation */ + uint8_t dss = (size > 24) ? 0 : (4 * (3 - ((size - 1) >> 3))); + + /* convert bits to bytes */ + size = BITS2BYTES(size); + abortcode = ESC_upload_pre_objecthandler(index, subindex, - objd->data, BITS2BYTES(size), objd->flags | COMPLETE_ACCESS_FLAG); + objd->data, (size_t *)&size, objd->flags | COMPLETE_ACCESS_FLAG); if (abortcode != 0) { SDO_abort (index, subindex, abortcode); @@ -612,12 +616,6 @@ static void SDO_upload_complete_access (void) COE_COMMAND_UPLOADRESPONSE | COE_COMPLETEACCESS | COE_SIZE_INDICATOR, index, subindex); - /* expedited bits used calculation */ - uint8_t dss = (size > 24) ? 0 : (4 * (3 - ((size - 1) >> 3))); - - /* convert bits to bytes */ - size = BITS2BYTES(size); - ESCvar.segmented = 0; if (size <= 4) diff --git a/soes/esc_coe.h b/soes/esc_coe.h index 689750c..0b2e7a6 100644 --- a/soes/esc_coe.h +++ b/soes/esc_coe.h @@ -127,7 +127,7 @@ extern uint32_t ESC_download_pre_objecthandler (uint16_t index, extern uint32_t ESC_upload_pre_objecthandler (uint16_t index, uint8_t subindex, void * data, - size_t size, + size_t *size, uint16_t flags); extern uint32_t ESC_upload_post_objecthandler (uint16_t index, uint8_t subindex, uint16_t flags); extern const _objectlist SDOobjects[];