Skip to content

Commit

Permalink
SensirionShdlcCommunication::receiveFrame
Browse files Browse the repository at this point in the history
Fixes issues when an error frame is read, and the datalength-values is not 0.
  • Loading branch information
Guswib committed Nov 2, 2024
1 parent 451d4eb commit b741584
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0

`Unreleased`_
-------------
- update to SensirionShdlcTxFrame::begin so the buffer is always filled from position 0.
. update to SensirionShdlcCommunication::receiveFrame - if an error frame is recieved, the data part of the frame should not be read even if the length is not 0.

`0.7.1`_ 2024-04-30
-------------------
Expand Down
19 changes: 11 additions & 8 deletions src/SensirionShdlcCommunication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,18 @@ uint16_t SensirionShdlcCommunication::receiveFrame(SensirionShdlcRxFrame& frame,
return RxFrameError | BufferSizeError;
}

size_t i = 0;
while (i < dataLength) {
error = unstuffByte(current, serial, startTime, timeoutMicros);
if (error) {
return error;
// An error frame does not have any data eventhough the value of "dataLength" is not zero.
// Therefore, only read data from the buffer if the frame state is 0, i.e, the frame is not of an error frame.

if(frame._state == 0 ){
for(size_t i = 0; i < dataLength; i++){
error = unstuffByte(current, serial, startTime, timeoutMicros);
if (error) {
return error;
}
frame._buffer[i] = current;
checksum += current;
}
frame._buffer[i] = current;
checksum += current;
i++;
}

uint8_t expectedChecksum = ~checksum;
Expand Down

0 comments on commit b741584

Please sign in to comment.