Skip to content

Commit

Permalink
Merge pull request #7 from Sensirion/fix-low-level-error
Browse files Browse the repository at this point in the history
Fix low level error
  • Loading branch information
psachs authored Apr 30, 2024
2 parents 36c288d + 2a7aaf3 commit 7c74d1b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0
`Unreleased`_
-------------

`0.7.1`_ 2024-04-30
-------------------

- Add undefined low level error to avoid fallback to "Frame already contains data" error.
- Fix missing low level error when not enough data available for I2C.


`0.7.0`_ 2024-04-09
-------------------
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Sensirion Core
version=0.7.0
version=0.7.1
author=Sensirion
maintainer=Sensirion
sentence=Library containing code base for Sensirion Sensor Libraries.
Expand Down
13 changes: 13 additions & 0 deletions src/SensirionErrors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ void errorToString(uint16_t error, char errorMessage[],
break;
case HighLevelError::WriteError:
switch (lowLevelError) {
case LowLevelError::Undefined:
strncpy(errorMessage, "Write error",
errorMessageSize);
return;
case LowLevelError::SerialWriteError:
strncpy(errorMessage, "Error writing to serial",
errorMessageSize);
Expand All @@ -81,6 +85,9 @@ void errorToString(uint16_t error, char errorMessage[],
break;
case HighLevelError::ReadError:
switch (lowLevelError) {
case LowLevelError::Undefined:
strncpy(errorMessage, "Read error", errorMessageSize);
return;
case LowLevelError::NonemptyFrameError:
strncpy(errorMessage, "Frame already contains data",
errorMessageSize);
Expand Down Expand Up @@ -117,6 +124,9 @@ void errorToString(uint16_t error, char errorMessage[],
}
case HighLevelError::TxFrameError:
switch (lowLevelError) {
case LowLevelError::Undefined:
strncpy(errorMessage, "Tx frame error", errorMessageSize);
return;
case LowLevelError::BufferSizeError:
strncpy(errorMessage, "Not enough space in buffer",
errorMessageSize);
Expand All @@ -125,6 +135,9 @@ void errorToString(uint16_t error, char errorMessage[],
break;
case HighLevelError::RxFrameError:
switch (lowLevelError) {
case LowLevelError::Undefined:
strncpy(errorMessage, "Rx frame error", errorMessageSize);
return;
case LowLevelError::BufferSizeError:
strncpy(errorMessage, "Not enough space in buffer",
errorMessageSize);
Expand Down
3 changes: 2 additions & 1 deletion src/SensirionErrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ enum HighLevelError : uint16_t {
SensorSpecificError = 0x8000,
};

enum LowLevelError : uint16_t {
enum LowLevelError : uint8_t {
// general errors
Undefined = 0,
NonemptyFrameError,
NoDataError,
BufferSizeError,
Expand Down
2 changes: 1 addition & 1 deletion src/SensirionI2CCommunication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ uint16_t SensirionI2CCommunication::receiveFrame(uint8_t address,
uint8_t available = i2cBus.requestFrom(address, bytesToRead,
static_cast<uint8_t>(stop));
if (bytesToRead != available) {
return ReadError;
return ReadError | NotEnoughDataError;
}
while (available > 0) {
frame._buffer[i++] = i2cBus.read();
Expand Down

0 comments on commit 7c74d1b

Please sign in to comment.