tolerate side data to be retrieved until timeout

This commit is contained in:
John
2022-12-17 16:48:07 +01:00
parent 4bbcc7918f
commit cd6be6002d
+13 -2
View File
@@ -41,6 +41,7 @@
#include <ios> #include <ios>
#include <iomanip> #include <iomanip>
#include "lib/ebus/data.h" #include "lib/ebus/data.h"
#include "lib/utils/clock.h"
#include "lib/utils/tcpsocket.h" #include "lib/utils/tcpsocket.h"
namespace ebusd { namespace ebusd {
@@ -297,6 +298,7 @@ result_t Device::recv(unsigned int timeout, symbol_t* value, ArbitrationState* a
} }
bool repeated = false; bool repeated = false;
timeout += m_latency; timeout += m_latency;
uint64_t until = clockGetMillis() + timeout;
do { do {
bool isAvailable = available(); bool isAvailable = available();
if (!isAvailable && timeout > 0) { 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; timeout = m_latency+ENHANCED_COMPLETE_WAIT_DURATION;
continue; continue;
} }
return RESULT_ERR_TIMEOUT; uint64_t now = clockGetMillis();
if (now >= until) {
return RESULT_ERR_TIMEOUT;
}
timeout = static_cast<unsigned>(until - now);
} while (true); } while (true);
if (m_enhancedProto || *value != SYN || m_arbitrationMaster == SYN || m_arbitrationCheck) { if (m_enhancedProto || *value != SYN || m_arbitrationMaster == SYN || m_arbitrationCheck) {
if (m_listener != nullptr) { if (m_listener != nullptr) {
@@ -449,7 +455,7 @@ bool Device::available() {
if (!m_enhancedProto) { if (!m_enhancedProto) {
return true; 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++) { for (size_t pos = 0; pos < m_bufLen; pos++) {
symbol_t ch = m_buffer[(pos+m_bufPos)%m_bufSize]; symbol_t ch = m_buffer[(pos+m_bufPos)%m_bufSize];
if (!(ch&ENH_BYTE_FLAG)) { if (!(ch&ENH_BYTE_FLAG)) {
@@ -463,6 +469,7 @@ bool Device::available() {
if (pos+1 >= m_bufLen) { if (pos+1 >= m_bufLen) {
return false; return false;
} }
symbol_t cmd = (ch >> 2)&0xf;
// peek into next byte to check if enhanced sequence is ok // peek into next byte to check if enhanced sequence is ok
ch = m_buffer[(pos+m_bufPos+1)%m_bufSize]; ch = m_buffer[(pos+m_bufPos+1)%m_bufSize];
if (!(ch&ENH_BYTE_FLAG) || (ch&ENH_BYTE_MASK) != ENH_BYTE2) { if (!(ch&ENH_BYTE_FLAG) || (ch&ENH_BYTE_MASK) != ENH_BYTE2) {
@@ -480,6 +487,10 @@ bool Device::available() {
pos--; pos--;
continue; continue;
} }
if (cmd != ENH_RES_RECEIVED && cmd != ENH_RES_STARTED && cmd != ENH_RES_FAILED) {
pos++;
continue;
}
#ifdef DEBUG_RAW_TRAFFIC #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); 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); fflush(stdout);