Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/arduino_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions .github/workflows/build_arduino_ide.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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 }}
Expand Down
30 changes: 9 additions & 21 deletions .github/workflows/build_platformio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -16,25 +17,21 @@ 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:
PLATFORMIO_CI_SRC: ${{ matrix.example }}

build-for-esp32:
runs-on: ubuntu-latest
container: ghcr.io/bertmelis/pio-test-container
strategy:
matrix:
example: [
Expand All @@ -45,43 +42,34 @@ 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:
PLATFORMIO_CI_SRC: ${{ matrix.example }}

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:
Expand Down
13 changes: 2 additions & 11 deletions .github/workflows/cppcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 3 additions & 6 deletions .github/workflows/cpplint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
1 change: 0 additions & 1 deletion src/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/Interface/SoftwareSerialInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SoftwareSerialInterface::SoftwareSerialInterface(SoftwareSerial* interface)
}

bool SoftwareSerialInterface::begin() {
_interface->begin(4800, SWSERIAL_8E2);
_interface->begin(4800, EspSoftwareSerial::SWSERIAL_8E2);
return (*_interface);
}

Expand Down
72 changes: 37 additions & 35 deletions src/VS1/VS1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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();
Expand All @@ -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);
}
Expand All @@ -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
Expand All @@ -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()) {
Expand All @@ -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);
}
Expand Down
11 changes: 4 additions & 7 deletions src/VS1/VS1.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ class VS1 {
private:
enum class State {
INIT,
INIT_ACK,
IDLE,
PROBE_ACK,
SYNC_ENQ,
SYNC_RECV,
SEND,
RECEIVE,
UNDEFINED
Expand All @@ -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();

Expand Down
Loading