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

Fixing begin of the TX-frame and issues with recieving an error frame. #10

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
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
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.
Guswib marked this conversation as resolved.
Show resolved Hide resolved

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
3 changes: 2 additions & 1 deletion src/SensirionShdlcTxFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@

uint16_t SensirionShdlcTxFrame::begin(uint8_t command, uint8_t address,
uint8_t dataLength) {
_buffer[_index++] = 0x7e;
_index=0; //sets the index to point towards the start of the buffer.
_buffer[_index] = 0x7e;
uint16_t error = addUInt8(address);
error |= addUInt8(command);
error |= addUInt8(dataLength);
Expand Down
Loading