Allow the pre_object_upload_hook to modify size

Change-Id: Ia95a1e8e3ba7e6bde3286f4eb15f8ba7f0cb85b2
pull/92/head
Lars Danielsson 2020-09-23 14:50:43 +02:00
parent 71bb37091f
commit c814d2dacf
4 changed files with 40 additions and 42 deletions

View File

@ -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)

View File

@ -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,

View File

@ -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)

View File

@ -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[];