Skip to content

Commit 2db8158

Browse files
authored
Merge pull request #10 from Guswib/main
Fixing begin of the TX-frame and issues with recieving an error frame.
2 parents 7c74d1b + b741584 commit 2db8158

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0
88

99
`Unreleased`_
1010
-------------
11+
- update to SensirionShdlcTxFrame::begin so the buffer is always filled from position 0.
12+
. 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.
1113

1214
`0.7.1`_ 2024-04-30
1315
-------------------

src/SensirionShdlcCommunication.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,18 @@ uint16_t SensirionShdlcCommunication::receiveFrame(SensirionShdlcRxFrame& frame,
124124
return RxFrameError | BufferSizeError;
125125
}
126126

127-
size_t i = 0;
128-
while (i < dataLength) {
129-
error = unstuffByte(current, serial, startTime, timeoutMicros);
130-
if (error) {
131-
return error;
127+
// An error frame does not have any data eventhough the value of "dataLength" is not zero.
128+
// Therefore, only read data from the buffer if the frame state is 0, i.e, the frame is not of an error frame.
129+
130+
if(frame._state == 0 ){
131+
for(size_t i = 0; i < dataLength; i++){
132+
error = unstuffByte(current, serial, startTime, timeoutMicros);
133+
if (error) {
134+
return error;
135+
}
136+
frame._buffer[i] = current;
137+
checksum += current;
132138
}
133-
frame._buffer[i] = current;
134-
checksum += current;
135-
i++;
136139
}
137140

138141
uint8_t expectedChecksum = ~checksum;

src/SensirionShdlcTxFrame.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838

3939
uint16_t SensirionShdlcTxFrame::begin(uint8_t command, uint8_t address,
4040
uint8_t dataLength) {
41-
_buffer[_index++] = 0x7e;
41+
_index=0; //sets the index to point towards the start of the buffer.
42+
_buffer[_index] = 0x7e;
4243
uint16_t error = addUInt8(address);
4344
error |= addUInt8(command);
4445
error |= addUInt8(dataLength);

0 commit comments

Comments
 (0)