Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDO: fix broken block download #210

Merged
merged 1 commit into from
Jul 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions stack/CO_SDO.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,24 +219,26 @@ static void CO_SDO_receive(void *object, const CO_CANrxMsg_t *msg){
/* check correct sequence number. */
if(seqno == (SDO->sequence + 1U)) {
/* sequence is correct */
uint8_t i;

SDO->sequence++;
/* check if buffer can store whole message just in case */
if (CO_SDO_BUFFER_SIZE - SDO->bufferOffset >= 7) {
uint8_t i;

/* copy data */
for(i=1; i<8; i++) {
SDO->ODF_arg.data[SDO->bufferOffset++] = msg->data[i]; //SDO->ODF_arg.data is equal as SDO->databuffer
if(SDO->bufferOffset >= CO_SDO_BUFFER_SIZE) {
/* buffer full, break reception */
SDO->sequence++;

/* copy data */
for(i=1; i<8; i++) {
SDO->ODF_arg.data[SDO->bufferOffset++] = msg->data[i]; //SDO->ODF_arg.data is equal as SDO->databuffer
}

/* break reception if last segment, block ends or block sequence is too large */
if(((CANrxData[0] & 0x80U) == 0x80U) || (SDO->sequence >= SDO->blksize)) {
SDO->state = CO_SDO_ST_DOWNLOAD_BL_SUB_RESP;
CO_SDO_receive_done(SDO);
break;
}
}

/* break reception if last segment, block ends or block sequence is too large */
if(((CANrxData[0] & 0x80U) == 0x80U) || (SDO->sequence >= SDO->blksize)) {
SDO->state = CO_SDO_ST_DOWNLOAD_BL_SUB_RESP;
} else {
/* buffer is full, ignore this segment, send response without resetting sequence */
SDO->state = CO_SDO_ST_DOWNLOAD_BL_SUB_RESP_2;
CO_SDO_receive_done(SDO);
}
}
Expand Down