Skip to content

Commit

Permalink
Workaround for ModBus CRC problems, closes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
hn committed Aug 12, 2023
1 parent d73ea44 commit 76d81ce
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@ $ sudo apt-get install python3-pip
$ pip3 install -U platformio # see PlatformIO docs
$ platformio platform install https://github.com/kuba2k2/libretiny # see LibreTiny docs
$
$ # Apply workaround until https://github.com/kuba2k2/libretiny/issues/154 is fixed
$ cd .platformio
$ wget https://raw.githubusercontent.com/hn/ginlong-solis/libretiny-ringbuffer-workaround.diff
$ patch -p1 < libretiny-ringbuffer-workaround.diff
$ cd ..
$
$ git clone https://github.com/kuba2k2/libretiny-esphome
$ cd libretiny-esphome
$ pip3 install -r requirements.txt
Expand Down
32 changes: 32 additions & 0 deletions libretiny-ringbuffer-workaround.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Workaround for the Arduino ringbuffer, so that it can no longer have a permanently
inconsistent state. Implemented by removing the redunant storage of the buffer
state in three variables.
--- a/packages/framework-arduino-api/api/RingBuffer.h 2023-08-12 13:07:59.074806708 +0200
+++ b/packages/framework-arduino-api/api/RingBuffer.h 2023-08-11 15:35:11.847630525 +0200
@@ -37,7 +37,6 @@
{
public:
uint8_t _aucBuffer[N] ;
- volatile int _iHead ;
volatile int _iTail ;
volatile int _numElems;

@@ -74,17 +73,12 @@
// current location of the tail), we're about to overflow the buffer
// and so we don't write the character or advance the head.
if (!isFull())
- {
- _aucBuffer[_iHead] = c ;
- _iHead = nextIndex(_iHead);
- _numElems++;
- }
+ _aucBuffer[(_iTail + _numElems++) % N] = c ;
}

template <int N>
void RingBufferN<N>::clear()
{
- _iHead = 0;
_iTail = 0;
_numElems = 0;
}

0 comments on commit 76d81ce

Please sign in to comment.