Skip to content

Commit f9c8d0d

Browse files
authored
fix VS1 protocol
1 parent 44e2e65 commit f9c8d0d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/VS1/VS1.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ bool VS1::write(const Datapoint& datapoint, const uint8_t* data, uint8_t length)
159159

160160
bool VS1::begin() {
161161
if (_interface->begin()) {
162+
while (_interface->available()) {
163+
_interface->read(); // clear rx buffer
164+
}
162165
_setState(State::INIT);
163166
return true;
164167
}
@@ -188,7 +191,8 @@ void VS1::loop() {
188191
break;
189192
}
190193
// double timeout to accomodate for connection initialization
191-
if (_currentDatapoint && _currentMillis - _requestTime > 4000UL) {
194+
if (_currentDatapoint && _currentMillis - _requestTime > 5000UL) {
195+
_bytesTransferred = 0;
192196
_setState(State::INIT);
193197
_tryOnError(OptolinkResult::TIMEOUT);
194198
}
@@ -226,6 +230,7 @@ void VS1::_syncEnq() {
226230
if (_currentMillis - _lastMillis < 50) {
227231
if (_currentDatapoint && _interface->write(&VitoWiFiInternals::ProtocolBytes.ENQ_ACK, 1) == 1) {
228232
_setState(State::SEND);
233+
_send(); // speed up things
229234
}
230235
} else {
231236
_setState(State::INIT);
@@ -262,7 +267,7 @@ void VS1::_receive() {
262267
++_bytesTransferred;
263268
_lastMillis = _currentMillis;
264269
}
265-
if (_bytesTransferred == _currentRequest.length()) {
270+
if (_bytesTransferred == _currentDatapoint.length()) {
266271
_bytesTransferred = 0;
267272
_setState(State::SYNC_RECV);
268273
_tryOnResponse();
@@ -271,7 +276,7 @@ void VS1::_receive() {
271276

272277
void VS1::_tryOnResponse() {
273278
if (_onResponseCallback) {
274-
_onResponseCallback(_responseBuffer, _currentRequest.length(), _currentDatapoint);
279+
_onResponseCallback(_responseBuffer, _currentDatapoint.length(), _currentDatapoint);
275280
}
276281
_currentDatapoint = Datapoint(nullptr, 0, 0, noconv);
277282
}

0 commit comments

Comments
 (0)