From 2ddd7df75863687c96cd51ea8abf73881b1fe89d Mon Sep 17 00:00:00 2001 From: john30 Date: Sat, 15 Feb 2020 12:39:24 +0100 Subject: [PATCH] add enhanced error codes --- docs/enhanced_proto.md | 12 ++++++++++ src/lib/ebus/device.cpp | 50 ++++++++++++++++++++++++++++++++++------- 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/docs/enhanced_proto.md b/docs/enhanced_proto.md index 8621da99..36ea9604 100644 --- a/docs/enhanced_proto.md +++ b/docs/enhanced_proto.md @@ -50,6 +50,14 @@ first second ` ` Indicates that the last arbitration request failed (arbitration was lost or sending failed). The data byte in `d` contains the master address that has won the arbitration. + * eBUS communication error + ` ` + Indicates an error in the eBUS UART. + The data byte in `d` contains the error message. + * host communication error + ` ` + Indicates an error in the host UART. + The data byte in `d` contains the error message. ## Symbols @@ -70,6 +78,10 @@ These are the predefined symbols as used above. * STARTED 0x2 * FAILED 0xa +### Error codes (from interface to ebusd) + * ERR_FRAMING 0x00: framing error + * ERR_OVERRUN 0x00: buffer overrun error + ## Examples diff --git a/src/lib/ebus/device.cpp b/src/lib/ebus/device.cpp index c9517a61..46ae6486 100755 --- a/src/lib/ebus/device.cpp +++ b/src/lib/ebus/device.cpp @@ -40,6 +40,8 @@ #include #include #include +#include +#include #include "lib/ebus/data.h" namespace ebusd { @@ -58,6 +60,12 @@ namespace ebusd { #define ENH_REQ_START ((uint8_t)0x2) #define ENH_RES_STARTED ((uint8_t)0x2) #define ENH_RES_FAILED ((uint8_t)0xa) +#define ENH_RES_ERROR_EBUS ((uint8_t)0xb) +#define ENH_RES_ERROR_HOST ((uint8_t)0xc) + +// ebusd enhanced error codes for the ERROR_* responses +#define ENH_ERR_FRAMING ((uint8_t)0x00) +#define ENH_ERR_OVERRUN ((uint8_t)0x01) #define ENH_BYTE_FLAG ((uint8_t)0x80) #define ENH_BYTE_MASK ((uint8_t)0xc0) @@ -450,13 +458,13 @@ bool Device::read(symbol_t* value, bool isAvailable, ArbitrationState* arbitrati } return false; } - ch2 = (symbol_t)(((ch&0x03)<<6) | (ch2&0x3f)); - ch = (ch>>2)&0xf; - switch (ch) { + symbol_t data = (symbol_t)(((ch&0x03)<<6) | (ch2&0x3f)); + symbol_t cmd = (ch>>2)&0xf; + switch (cmd) { case ENH_RES_STARTED: *arbitrationState = as_won; if (m_listener != NULL) { - m_listener->notifyDeviceData(ch2, false); + m_listener->notifyDeviceData(data, false); } m_arbitrationMaster = SYN; m_arbitrationCheck = false; @@ -464,15 +472,15 @@ bool Device::read(symbol_t* value, bool isAvailable, ArbitrationState* arbitrati case ENH_RES_FAILED: *arbitrationState = as_lost; if (m_listener != NULL) { - m_listener->notifyDeviceData(ch2, false); + m_listener->notifyDeviceData(data, false); } m_arbitrationMaster = SYN; m_arbitrationCheck = false; break; case ENH_RES_RECEIVED: - *value = ch2; + *value = data; return true; - case ENH_RES_RESETTED: // TODO + case ENH_RES_RESETTED: if (*arbitrationState != as_none) { *arbitrationState = as_error; } @@ -481,9 +489,35 @@ bool Device::read(symbol_t* value, bool isAvailable, ArbitrationState* arbitrati m_listener->notifyStatus(false, "reset"); } break; + case ENH_RES_ERROR_EBUS: + case ENH_RES_ERROR_HOST: + if (m_listener != nullptr) { + ostringstream stream; + stream << (cmd==ENH_RES_ERROR_EBUS ? "eBUS comm error: " : "host comm error: "); + switch (data) { + case ENH_ERR_FRAMING: + stream << "framing"; + break; + case ENH_ERR_OVERRUN: + stream << "overrun"; + break; + default: + stream << "unknown 0x" << std::setw(2) << std::setfill('0') << std::hex << static_cast(data); + break; + } + string str = stream.str(); + m_listener->notifyStatus(true, str.c_str()); + } + if (*arbitrationState != as_none) { + *arbitrationState = as_error; + } + break; default: if (m_listener != nullptr) { - m_listener->notifyStatus(true, "unexpected enhanced command"); + ostringstream stream; + stream << "unexpected enhanced command 0x" << std::setw(2) << std::setfill('0') << std::hex << static_cast(cmd); + string str = stream.str(); + m_listener->notifyStatus(true, str.c_str()); } return false; }