Skip to content

Commit

Permalink
Merge branch 'fix-crc-calculation' into 'main'
Browse files Browse the repository at this point in the history
Fix CRC calculation for TX frames

See merge request MSO-SW/drivers/arduino/arduino-core!28
  • Loading branch information
psachs committed Aug 3, 2021
2 parents 78e9091 + 3b7b3c8 commit 39c5932
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
13 changes: 11 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ All notable changes to this project will be documented in this file.
The format is based on `Keep a Changelog <https://keepachangelog.com/en/1.0.0/>`_
and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_.

`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
-------------------

Expand All @@ -14,7 +23,6 @@ Changed

- Adjusted deprecation warnings


`0.5.0`_ 2021-07-07
-------------------

Expand Down Expand Up @@ -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
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.5.1
version=0.5.2
author=Sensirion
maintainer=Sensirion
sentence=Library containing code base for Sensirion Sensor Libraries.
Expand Down
10 changes: 6 additions & 4 deletions src/SensirionI2CTxFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<uint8_t>((command & 0xFF00) >> 8);
instance._buffer[1] = static_cast<uint8_t>((command & 0x00FF) >> 0);
return instance;
}

Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion src/SensirionI2CTxFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -184,6 +185,7 @@ class SensirionI2CTxFrame {
uint8_t* _buffer;
size_t _bufferSize;
size_t _index;
size_t _numCommandBytes;
};

#endif /* SENSIRION_I2C_TX_FRAME_H_ */

0 comments on commit 39c5932

Please sign in to comment.