diff --git a/src/ebusd/mainloop.cpp b/src/ebusd/mainloop.cpp index 66f2bd6e..924b7a18 100644 --- a/src/ebusd/mainloop.cpp +++ b/src/ebusd/mainloop.cpp @@ -108,7 +108,7 @@ MainLoop::MainLoop(const struct options& opt, BusHandler* busHandler, : Thread(), m_busHandler(busHandler), m_protocol(busHandler->getProtocol()), m_reconnectCount(0), m_userList(opt.accessLevel), m_messages(messages), m_scanHelper(scanHelper), m_address(opt.address), m_scanConfig(opt.scanConfig), - m_initialScan(opt.readOnly ? ESC : opt.initialScan), m_scanRetries(opt.scanRetries), + m_initialScan(opt.readOnly ? (symbol_t)ESC : opt.initialScan), m_scanRetries(opt.scanRetries), m_scanStatus(SCAN_STATUS_NONE), m_polling(opt.pollInterval > 0), m_enableHex(opt.enableHex), m_shutdown(false), m_runUpdateCheck(opt.updateCheck), m_httpClient(), m_requestQueue(requestQueue) { if (opt.aclFile[0]) { @@ -676,7 +676,7 @@ result_t MainLoop::executeRead(const vector& args, const string& levels, if (dest) { dstAddress = address; } else { - srcAddress = address == m_address ? SYN : address; + srcAddress = address == m_address ? (symbol_t)SYN : address; } } else if (args[argPos] == "-p") { argPos++; @@ -933,7 +933,7 @@ result_t MainLoop::executeWrite(const vector& args, const string levels, if (dest) { dstAddress = address; } else { - srcAddress = address == m_address ? SYN : address; + srcAddress = address == m_address ? (symbol_t)SYN : address; } } else if (args[argPos] == "-c") { argPos++; @@ -1110,7 +1110,7 @@ result_t MainLoop::parseHexAndSend(const vector& args, size_t& argPos, b if (ret != RESULT_OK || !isValidAddress(address, false) || !isMaster(address)) { return RESULT_ERR_INVALID_ADDR; } - srcAddress = address == m_address ? SYN : address; + srcAddress = address == m_address ? (symbol_t)SYN : address; } else if (args[argPos] == "-n") { autoLength = true; } else { diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index a76f519f..2c496ce6 100644 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -200,7 +200,7 @@ uint64_t Message::createKey(const MasterSymbolString& master, size_t maxIdLength } uint64_t key = (uint64_t)idLength << (8 * 7 + 5); key |= (uint64_t)getMasterNumber(master[0]) << (8 * 7); // QQ address for passive message - key |= (uint64_t)(anyDestination ? SYN : master[1]) << (8 * 6); // ZZ address + key |= (uint64_t)(anyDestination ? (symbol_t)SYN : master[1]) << (8 * 6); // ZZ address key |= (uint64_t)master[2] << (8 * 5); // PB key |= (uint64_t)master[3] << (8 * 4); // SB int exp = 3; diff --git a/src/lib/ebus/symbol.cpp b/src/lib/ebus/symbol.cpp index 92ef757b..3b0e96f7 100755 --- a/src/lib/ebus/symbol.cpp +++ b/src/lib/ebus/symbol.cpp @@ -145,14 +145,21 @@ result_t SymbolString::parseHexEscaped(const string& str) { return inEscape ? RESULT_ERR_ESC : RESULT_OK; } -const string SymbolString::getStr(size_t skipFirstSymbols) const { +const string SymbolString::getStr(size_t skipFirstSymbols, size_t maxLength, bool withLength) const { ostringstream sstr; + if (maxLength == 0) { + maxLength = m_data.size(); + } + size_t lengthOffset = withLength ? 254 : (m_isMaster ? 4 : 0); for (size_t i = 0; i < m_data.size(); i++) { if (skipFirstSymbols > 0) { skipFirstSymbols--; - } else { + } else if (i != lengthOffset) { sstr << nouppercase << setw(2) << hex << setfill('0') << static_cast(m_data[i]); + if (--maxLength == 0) { + break; + } } } return sstr.str(); diff --git a/src/lib/ebus/symbol.h b/src/lib/ebus/symbol.h index e3d0f489..43f73693 100755 --- a/src/lib/ebus/symbol.h +++ b/src/lib/ebus/symbol.h @@ -72,20 +72,21 @@ using std::ostringstream; /** the base type for symbols sent to/from the eBUS. */ typedef unsigned char symbol_t; -/** escape symbol, either followed by 0x00 for the value 0xA9, or 0x01 for the value 0xAA. */ -#define ESC ((symbol_t)0xA9) - -/** synchronization symbol. */ -#define SYN ((symbol_t)0xAA) - -/** positive acknowledge symbol. */ -#define ACK ((symbol_t)0x00) - -/** negative acknowledge symbol. */ -#define NAK ((symbol_t)0xFF) - -/** the broadcast destination address. */ -#define BROADCAST ((symbol_t)0xFE) +/** + * List of predefined eBUS symbols. + */ +enum PredefinedSymbol : symbol_t { + /** escape symbol, either followed by 0x00 for the value 0xA9, or 0x01 for the value 0xAA. */ + ESC = 0xA9, + /** synchronization symbol. */ + SYN = 0xAA, + /** positive acknowledge symbol. */ + ACK = 0x00, + /** negative acknowledge symbol. */ + NAK = 0xFF, + /** the broadcast destination address. */ + BROADCAST = 0xFE, +}; /** * Parse an unsigned int value. @@ -156,9 +157,11 @@ class SymbolString { /** * Return the symbols as hex string. * @param skipFirstSymbols the number of first symbols to skip. + * @param maxLength the maximum number of symbols to include (or 0 for all). + * @param withLength whether to include the NN length field. * @return the symbols as hex string. */ - const string getStr(size_t skipFirstSymbols = 0) const; + const string getStr(size_t skipFirstSymbols = 0, size_t maxLength = 0, bool withLength = true) const; /** * Dump the data in JSON format to the output.