From 4b2d402cc0eb59da07e601dc3c257c76cd88956b Mon Sep 17 00:00:00 2001 From: Pascal Sachs Date: Tue, 3 Aug 2021 11:04:07 +0200 Subject: [PATCH 1/2] Fix CRC calculation for TX frames * Add number of command bytes, since they must not be included when deciding if a CRC should be included * CRC is added every third byte excluding command bytes --- src/SensirionI2CTxFrame.cpp | 10 ++++++---- src/SensirionI2CTxFrame.h | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) 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_ */ From 3b7b3c8fca4841b80f067e0dba54a8247363a80e Mon Sep 17 00:00:00 2001 From: Pascal Sachs Date: Tue, 3 Aug 2021 11:11:49 +0200 Subject: [PATCH 2/2] Prepare for 0.5.2 Release Bugfix release to fix CRC insertion in I2C TX frames --- CHANGELOG.rst | 13 +++++++++++-- library.properties | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) 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.