From c917b43d340e960fd1ebefe073bff9ed39b5ea81 Mon Sep 17 00:00:00 2001 From: Bert Melis Date: Thu, 26 Sep 2024 13:37:29 +0200 Subject: [PATCH 1/3] Update CI --- .github/workflows/arduino_lint.yml | 2 +- .github/workflows/build_arduino_ide.yml | 4 ++-- .github/workflows/build_platformio.yml | 30 ++++++++----------------- .github/workflows/cppcheck.yml | 13 ++--------- .github/workflows/cpplint.yml | 9 +++----- 5 files changed, 17 insertions(+), 41 deletions(-) diff --git a/.github/workflows/arduino_lint.yml b/.github/workflows/arduino_lint.yml index 84b2ab6..6c5a256 100644 --- a/.github/workflows/arduino_lint.yml +++ b/.github/workflows/arduino_lint.yml @@ -5,5 +5,5 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: arduino/arduino-lint-action@v1 \ No newline at end of file diff --git a/.github/workflows/build_arduino_ide.yml b/.github/workflows/build_arduino_ide.yml index 7dd637c..54102c4 100644 --- a/.github/workflows/build_arduino_ide.yml +++ b/.github/workflows/build_arduino_ide.yml @@ -12,7 +12,7 @@ jobs: fqbn: - esp8266:esp8266:generic steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: arduino/compile-sketches@v1 with: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -36,7 +36,7 @@ jobs: fqbn: - esp32:esp32:esp32 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: arduino/compile-sketches@v1 with: github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/build_platformio.yml b/.github/workflows/build_platformio.yml index 48d2fa6..676dc72 100644 --- a/.github/workflows/build_platformio.yml +++ b/.github/workflows/build_platformio.yml @@ -5,6 +5,7 @@ on: [push, pull_request] jobs: build-for-esp8266: runs-on: ubuntu-latest + container: ghcr.io/bertmelis/pio-test-container strategy: matrix: example: [ @@ -16,18 +17,13 @@ jobs: examples/softwareserial/softwareserial.ino ] steps: - - uses: actions/checkout@v3 - - uses: actions/cache@v3 + - uses: actions/checkout@v4 + - uses: actions/cache@v4 with: path: | ~/.cache/pip ~/.platformio/.cache key: ${{ runner.os }}-pio - - uses: actions/setup-python@v4 - with: - python-version: '3.9' - - name: Install PlatformIO Core - run: pip install --upgrade platformio - name: Build PlatformIO examples run: pio ci --lib="." --board=d1_mini env: @@ -35,6 +31,7 @@ jobs: build-for-esp32: runs-on: ubuntu-latest + container: ghcr.io/bertmelis/pio-test-container strategy: matrix: example: [ @@ -45,18 +42,13 @@ jobs: examples/simple-read-GWG/simple-read-GWG.ino ] steps: - - uses: actions/checkout@v3 - - uses: actions/cache@v3 + - uses: actions/checkout@v4 + - uses: actions/cache@v4 with: path: | ~/.cache/pip ~/.platformio/.cache key: ${{ runner.os }}-pio - - uses: actions/setup-python@v4 - with: - python-version: '3.9' - - name: Install PlatformIO Core - run: pip install --upgrade platformio - name: Build PlatformIO examples run: pio ci --lib="." --board=lolin32 env: @@ -64,24 +56,20 @@ jobs: build-for-linux: runs-on: ubuntu-latest + container: ghcr.io/bertmelis/pio-test-container strategy: matrix: example: [ examples/linux/main.cpp ] steps: - - uses: actions/checkout@v3 - - uses: actions/cache@v3 + - uses: actions/checkout@v4 + - uses: actions/cache@v4 with: path: | ~/.cache/pip ~/.platformio/.cache key: ${{ runner.os }}-pio - - uses: actions/setup-python@v4 - with: - python-version: '3.9' - - name: Install PlatformIO Core - run: pip install --upgrade platformio - name: Build PlatformIO examples run: pio ci --lib="." --project-conf="./examples/linux/platformio.ini" env: diff --git a/.github/workflows/cppcheck.yml b/.github/workflows/cppcheck.yml index bcab4ec..f730127 100644 --- a/.github/workflows/cppcheck.yml +++ b/.github/workflows/cppcheck.yml @@ -4,19 +4,10 @@ on: [push, pull_request] jobs: build: - runs-on: ubuntu-latest - + container: ghcr.io/bertmelis/pio-test-container steps: - - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install platformio + - uses: actions/checkout@v4 - name: Cppcheck run: | pio check --flags "--suppress=unusedFunction --inline-suppr" --skip-packages --fail-on-defect=low --fail-on-defect=medium --fail-on-defect=high \ No newline at end of file diff --git a/.github/workflows/cpplint.yml b/.github/workflows/cpplint.yml index 734bf79..d912707 100644 --- a/.github/workflows/cpplint.yml +++ b/.github/workflows/cpplint.yml @@ -4,18 +4,15 @@ on: [push, pull_request] jobs: build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: - python-version: '3.10' + python-version: '3.11' - name: Install dependencies run: | - python -m pip install --upgrade pip pip install cpplint - name: Linting run: | From 421b077e7262ed4c925b6383e431e6aed0485281 Mon Sep 17 00:00:00 2001 From: Bert Melis Date: Thu, 3 Oct 2024 17:27:29 +0200 Subject: [PATCH 2/3] fix VS1 --- src/Constants.h | 1 - src/VS1/VS1.cpp | 72 +++++++++++++++++++++++++------------------------ src/VS1/VS1.h | 11 +++----- 3 files changed, 41 insertions(+), 43 deletions(-) diff --git a/src/Constants.h b/src/Constants.h index 4e1b240..6445fd5 100644 --- a/src/Constants.h +++ b/src/Constants.h @@ -64,7 +64,6 @@ constexpr struct { uint8_t ENQ = 0x05; uint8_t EOT = 0x04; uint8_t SYNC[3] = {0x16, 0x00, 0x00}; - uint8_t PROBE[4] = {0xF7, 0x00, 0xF8, 0x02}; } ProtocolBytes; enum class ParserResult { diff --git a/src/VS1/VS1.cpp b/src/VS1/VS1.cpp index 27ba562..aaec45a 100644 --- a/src/VS1/VS1.cpp +++ b/src/VS1/VS1.cpp @@ -158,8 +158,14 @@ bool VS1::write(const Datapoint& datapoint, const uint8_t* data, uint8_t length) } bool VS1::begin() { - _setState(State::INIT); - return _interface->begin(); + if (_interface->begin()) { + while (_interface->available()) { + _interface->read(); // clear rx buffer + } + _setState(State::INIT); + return true; + } + return false; } void VS1::loop() { @@ -168,14 +174,11 @@ void VS1::loop() { case State::INIT: _init(); break; - case State::INIT_ACK: - _initAck(); + case State::SYNC_ENQ: + _syncEnq(); break; - case State::IDLE: - _idle(); - break; - case State::PROBE_ACK: - _probeAck(); + case State::SYNC_RECV: + _syncRecv(); break; case State::SEND: _send(); @@ -189,6 +192,7 @@ void VS1::loop() { } // double timeout to accomodate for connection initialization if (_currentDatapoint && _currentMillis - _requestTime > 4000UL) { + _bytesTransferred = 0; _setState(State::INIT); _tryOnError(OptolinkResult::TIMEOUT); } @@ -205,10 +209,12 @@ void VS1::_setState(State state) { _state = state; } +// wait for ENQ or reset connection if ENQ is not coming void VS1::_init() { if (_interface->available()) { if (_interface->read() == VitoWiFiInternals::ProtocolBytes.ENQ) { - _setState(State::IDLE); + _lastMillis = _currentMillis; + _setState(State::SYNC_ENQ); } } else { if (_currentMillis - _lastMillis > 3000UL) { // reset should Vitotronic be connected with VS2 @@ -218,38 +224,32 @@ void VS1::_init() { } } -void VS1::_initAck() { - if (_interface->write(&VitoWiFiInternals::ProtocolBytes.ENQ_ACK, 1) == 1) { - _setState(State::IDLE); - _lastMillis = _currentMillis; +// if we want to send something within 50msec of receiving the ENQ, send ENQ_ACK and move to SEND +// if > 50msec, return to INIT +void VS1::_syncEnq() { + if (_currentMillis - _lastMillis < 50) { + if (_currentDatapoint && _interface->write(&VitoWiFiInternals::ProtocolBytes.ENQ_ACK, 1) == 1) { + _setState(State::SEND); + _send(); // speed up things + } } else { _setState(State::INIT); } } -void VS1::_idle() { - if (_currentDatapoint) { - _setState(State::SEND); - } else if (_currentMillis - _lastMillis > 500) { - if (_interface->write(&VitoWiFiInternals::ProtocolBytes.PROBE[0], 4) == 4) { - _lastMillis = _currentMillis; - _setState(State::PROBE_ACK); - } else { - _setState(State::INIT); +// if we want to send something within 50msec of previous SEND, send again +// if > 50msec, return to INIT +void VS1::_syncRecv() { + if (_currentMillis - _lastMillis < 50) { + if (_currentDatapoint) { + _setState(State::SEND); } - } -} - -void VS1::_probeAck() { - if (_interface->available() == 2) { - _interface->read(); - _interface->read(); - _setState(State::IDLE); - } else if (_currentMillis - _lastMillis > 1000UL) { + } else { _setState(State::INIT); } } +// send request and move to RECEIVE void VS1::_send() { _bytesTransferred += _interface->write(&_currentRequest[_bytesTransferred], _currentRequest.length() - _bytesTransferred); if (_bytesTransferred == _currentRequest.length()) { @@ -259,22 +259,24 @@ void VS1::_send() { } } +// wait for data to receive +// when done, move to SYN_RECV void VS1::_receive() { while (_interface->available()) { _responseBuffer[_bytesTransferred] = _interface->read(); ++_bytesTransferred; _lastMillis = _currentMillis; } - if (_bytesTransferred == _currentRequest.length()) { + if (_bytesTransferred == _currentDatapoint.length()) { _bytesTransferred = 0; - _setState(State::IDLE); + _setState(State::SYNC_RECV); _tryOnResponse(); } } void VS1::_tryOnResponse() { if (_onResponseCallback) { - _onResponseCallback(_responseBuffer, _currentRequest.length(), _currentDatapoint); + _onResponseCallback(_responseBuffer, _currentDatapoint.length(), _currentDatapoint); } _currentDatapoint = Datapoint(nullptr, 0, 0, noconv); } diff --git a/src/VS1/VS1.h b/src/VS1/VS1.h index 89c94f1..c58ed46 100644 --- a/src/VS1/VS1.h +++ b/src/VS1/VS1.h @@ -59,9 +59,8 @@ class VS1 { private: enum class State { INIT, - INIT_ACK, - IDLE, - PROBE_ACK, + SYNC_ENQ, + SYNC_RECV, SEND, RECEIVE, UNDEFINED @@ -81,10 +80,8 @@ class VS1 { inline void _setState(State state); void _init(); - void _initAck(); - void _idle(); - void _probeAck(); - void _sync(); + void _syncEnq(); + void _syncRecv(); void _send(); void _receive(); From e13681954e50d8d4cba47475d43511b13c3c70f6 Mon Sep 17 00:00:00 2001 From: Bert Melis Date: Thu, 3 Oct 2024 17:33:12 +0200 Subject: [PATCH 3/3] Update to latest softwareserial --- src/Interface/SoftwareSerialInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Interface/SoftwareSerialInterface.cpp b/src/Interface/SoftwareSerialInterface.cpp index b7fb655..48291be 100644 --- a/src/Interface/SoftwareSerialInterface.cpp +++ b/src/Interface/SoftwareSerialInterface.cpp @@ -18,7 +18,7 @@ SoftwareSerialInterface::SoftwareSerialInterface(SoftwareSerial* interface) } bool SoftwareSerialInterface::begin() { - _interface->begin(4800, SWSERIAL_8E2); + _interface->begin(4800, EspSoftwareSerial::SWSERIAL_8E2); return (*_interface); }