From cd6be6002d2f8820d0716e07330f904d455f39ca Mon Sep 17 00:00:00 2001 From: John Date: Sat, 17 Dec 2022 16:48:07 +0100 Subject: [PATCH] tolerate side data to be retrieved until timeout --- src/lib/ebus/device.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/lib/ebus/device.cpp b/src/lib/ebus/device.cpp index 6896422d..c43c8784 100755 --- a/src/lib/ebus/device.cpp +++ b/src/lib/ebus/device.cpp @@ -41,6 +41,7 @@ #include #include #include "lib/ebus/data.h" +#include "lib/utils/clock.h" #include "lib/utils/tcpsocket.h" namespace ebusd { @@ -297,6 +298,7 @@ result_t Device::recv(unsigned int timeout, symbol_t* value, ArbitrationState* a } bool repeated = false; timeout += m_latency; + uint64_t until = clockGetMillis() + timeout; do { bool isAvailable = available(); if (!isAvailable && timeout > 0) { @@ -359,7 +361,11 @@ result_t Device::recv(unsigned int timeout, symbol_t* value, ArbitrationState* a timeout = m_latency+ENHANCED_COMPLETE_WAIT_DURATION; continue; } - return RESULT_ERR_TIMEOUT; + uint64_t now = clockGetMillis(); + if (now >= until) { + return RESULT_ERR_TIMEOUT; + } + timeout = static_cast(until - now); } while (true); if (m_enhancedProto || *value != SYN || m_arbitrationMaster == SYN || m_arbitrationCheck) { if (m_listener != nullptr) { @@ -449,7 +455,7 @@ bool Device::available() { if (!m_enhancedProto) { return true; } - // peek into the received enhanced proto bytes to determine symbol availability + // peek into the received enhanced proto bytes to determine received bus symbol availability for (size_t pos = 0; pos < m_bufLen; pos++) { symbol_t ch = m_buffer[(pos+m_bufPos)%m_bufSize]; if (!(ch&ENH_BYTE_FLAG)) { @@ -463,6 +469,7 @@ bool Device::available() { if (pos+1 >= m_bufLen) { return false; } + symbol_t cmd = (ch >> 2)&0xf; // peek into next byte to check if enhanced sequence is ok ch = m_buffer[(pos+m_bufPos+1)%m_bufSize]; if (!(ch&ENH_BYTE_FLAG) || (ch&ENH_BYTE_MASK) != ENH_BYTE2) { @@ -480,6 +487,10 @@ bool Device::available() { pos--; continue; } + if (cmd != ENH_RES_RECEIVED && cmd != ENH_RES_STARTED && cmd != ENH_RES_FAILED) { + pos++; + continue; + } #ifdef DEBUG_RAW_TRAFFIC fprintf(stdout, "raw avail enhanced @%d+%d %2.2x %2.2x\n", m_bufPos, pos, m_buffer[(pos+m_bufPos)%m_bufSize], ch); fflush(stdout);