diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 9dec260..6e77e6e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,15 @@ All notable changes to this project will be documented in this file. The format is based on `Keep a Changelog `_ and this project adheres to `Semantic Versioning `_. +`0.5.2`_ 2021-08-03 +------------------- + +Fixed +..... + +- Fix CRC insertion in ``SensirionI2CTxFrame`` when more then one parameter + is sent to the sensor. + `0.5.1`_ 2021-07-08 ------------------- @@ -14,7 +23,6 @@ Changed - Adjusted deprecation warnings - `0.5.0`_ 2021-07-07 ------------------- @@ -121,7 +129,8 @@ Removed - Initial release -.. _Unreleased: https://github.com/Sensirion/arduino-core/compare/0.5.1...main +.. _Unreleased: https://github.com/Sensirion/arduino-core/compare/0.5.2...main +.. _0.5.2: https://github.com/Sensirion/arduino-core/compare/0.5.1...0.5.2 .. _0.5.1: https://github.com/Sensirion/arduino-core/compare/0.5.0...0.5.1 .. _0.5.0: https://github.com/Sensirion/arduino-core/compare/0.4.3...0.5.0 .. _0.4.3: https://github.com/Sensirion/arduino-core/compare/0.4.2...0.4.3 diff --git a/library.properties b/library.properties index 0e2ddb9..ff826f8 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Sensirion Core -version=0.5.1 +version=0.5.2 author=Sensirion maintainer=Sensirion sentence=Library containing code base for Sensirion Sensor Libraries. diff --git a/src/SensirionI2CTxFrame.cpp b/src/SensirionI2CTxFrame.cpp index a803ee2..b55242c 100644 --- a/src/SensirionI2CTxFrame.cpp +++ b/src/SensirionI2CTxFrame.cpp @@ -37,8 +37,9 @@ #include "SensirionErrors.h" SensirionI2CTxFrame::SensirionI2CTxFrame(uint8_t buffer[], size_t bufferSize, - size_t index) - : _buffer(buffer), _bufferSize(bufferSize), _index(index) { + size_t numCommandBytes) + : _buffer(buffer), _bufferSize(bufferSize), _index(numCommandBytes), + _numCommandBytes(numCommandBytes) { } SensirionI2CTxFrame::SensirionI2CTxFrame(uint8_t buffer[], size_t bufferSize) @@ -57,7 +58,8 @@ SensirionI2CTxFrame SensirionI2CTxFrame::createWithUInt16Command(uint16_t command, uint8_t buffer[], size_t bufferSize) { SensirionI2CTxFrame instance = SensirionI2CTxFrame(buffer, bufferSize, 2); - instance.addCommand(command); + instance._buffer[0] = static_cast((command & 0xFF00) >> 8); + instance._buffer[1] = static_cast((command & 0x00FF) >> 0); return instance; } @@ -144,7 +146,7 @@ uint16_t SensirionI2CTxFrame::_addByte(uint8_t data) { return TxFrameError | BufferSizeError; } _buffer[_index++] = data; - if (_index % 2 == 0) { + if ((_index - _numCommandBytes) % 3 == 2) { if (_bufferSize <= _index) { return TxFrameError | BufferSizeError; } diff --git a/src/SensirionI2CTxFrame.h b/src/SensirionI2CTxFrame.h index 2343804..27660c5 100644 --- a/src/SensirionI2CTxFrame.h +++ b/src/SensirionI2CTxFrame.h @@ -175,7 +175,8 @@ class SensirionI2CTxFrame { uint16_t addBytes(const uint8_t data[], size_t dataLength); private: - SensirionI2CTxFrame(uint8_t buffer[], size_t bufferSize, size_t index); + SensirionI2CTxFrame(uint8_t buffer[], size_t bufferSize, + size_t numCommandBytes); static uint8_t _generateCRC(const uint8_t* data, size_t count); @@ -184,6 +185,7 @@ class SensirionI2CTxFrame { uint8_t* _buffer; size_t _bufferSize; size_t _index; + size_t _numCommandBytes; }; #endif /* SENSIRION_I2C_TX_FRAME_H_ */