add enhanced error codes

This commit is contained in:
john30
2020-02-15 12:39:24 +01:00
parent f2aae4cb2b
commit 2ddd7df758
2 changed files with 54 additions and 8 deletions
+12
View File
@@ -50,6 +50,14 @@ first second
`<FAILED> <master>` `<FAILED> <master>`
Indicates that the last arbitration request failed (arbitration was lost or sending failed). 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. The data byte in `d` contains the master address that has won the arbitration.
* eBUS communication error
`<ERROR_EBUS> <error>`
Indicates an error in the eBUS UART.
The data byte in `d` contains the error message.
* host communication error
`<ERROR_HOST> <error>`
Indicates an error in the host UART.
The data byte in `d` contains the error message.
## Symbols ## Symbols
@@ -70,6 +78,10 @@ These are the predefined symbols as used above.
* STARTED 0x2 * STARTED 0x2
* FAILED 0xa * FAILED 0xa
### Error codes (from interface to ebusd)
* ERR_FRAMING 0x00: framing error
* ERR_OVERRUN 0x00: buffer overrun error
## Examples ## Examples
+42 -8
View File
@@ -40,6 +40,8 @@
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <fstream> #include <fstream>
#include <ios>
#include <iomanip>
#include "lib/ebus/data.h" #include "lib/ebus/data.h"
namespace ebusd { namespace ebusd {
@@ -58,6 +60,12 @@ namespace ebusd {
#define ENH_REQ_START ((uint8_t)0x2) #define ENH_REQ_START ((uint8_t)0x2)
#define ENH_RES_STARTED ((uint8_t)0x2) #define ENH_RES_STARTED ((uint8_t)0x2)
#define ENH_RES_FAILED ((uint8_t)0xa) #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_FLAG ((uint8_t)0x80)
#define ENH_BYTE_MASK ((uint8_t)0xc0) #define ENH_BYTE_MASK ((uint8_t)0xc0)
@@ -450,13 +458,13 @@ bool Device::read(symbol_t* value, bool isAvailable, ArbitrationState* arbitrati
} }
return false; return false;
} }
ch2 = (symbol_t)(((ch&0x03)<<6) | (ch2&0x3f)); symbol_t data = (symbol_t)(((ch&0x03)<<6) | (ch2&0x3f));
ch = (ch>>2)&0xf; symbol_t cmd = (ch>>2)&0xf;
switch (ch) { switch (cmd) {
case ENH_RES_STARTED: case ENH_RES_STARTED:
*arbitrationState = as_won; *arbitrationState = as_won;
if (m_listener != NULL) { if (m_listener != NULL) {
m_listener->notifyDeviceData(ch2, false); m_listener->notifyDeviceData(data, false);
} }
m_arbitrationMaster = SYN; m_arbitrationMaster = SYN;
m_arbitrationCheck = false; m_arbitrationCheck = false;
@@ -464,15 +472,15 @@ bool Device::read(symbol_t* value, bool isAvailable, ArbitrationState* arbitrati
case ENH_RES_FAILED: case ENH_RES_FAILED:
*arbitrationState = as_lost; *arbitrationState = as_lost;
if (m_listener != NULL) { if (m_listener != NULL) {
m_listener->notifyDeviceData(ch2, false); m_listener->notifyDeviceData(data, false);
} }
m_arbitrationMaster = SYN; m_arbitrationMaster = SYN;
m_arbitrationCheck = false; m_arbitrationCheck = false;
break; break;
case ENH_RES_RECEIVED: case ENH_RES_RECEIVED:
*value = ch2; *value = data;
return true; return true;
case ENH_RES_RESETTED: // TODO case ENH_RES_RESETTED:
if (*arbitrationState != as_none) { if (*arbitrationState != as_none) {
*arbitrationState = as_error; *arbitrationState = as_error;
} }
@@ -481,9 +489,35 @@ bool Device::read(symbol_t* value, bool isAvailable, ArbitrationState* arbitrati
m_listener->notifyStatus(false, "reset"); m_listener->notifyStatus(false, "reset");
} }
break; 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<unsigned>(data);
break;
}
string str = stream.str();
m_listener->notifyStatus(true, str.c_str());
}
if (*arbitrationState != as_none) {
*arbitrationState = as_error;
}
break;
default: default:
if (m_listener != nullptr) { 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<unsigned>(cmd);
string str = stream.str();
m_listener->notifyStatus(true, str.c_str());
} }
return false; return false;
} }