Skip to content

Commit

Permalink
add enum for predefined symbols, enhance getStr()
Browse files Browse the repository at this point in the history
  • Loading branch information
john30 committed May 5, 2024
1 parent 9b476a6 commit c084dd2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/ebusd/mainloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down Expand Up @@ -676,7 +676,7 @@ result_t MainLoop::executeRead(const vector<string>& 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++;
Expand Down Expand Up @@ -933,7 +933,7 @@ result_t MainLoop::executeWrite(const vector<string>& 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++;
Expand Down Expand Up @@ -1110,7 +1110,7 @@ result_t MainLoop::parseHexAndSend(const vector<string>& 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 {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ebus/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 9 additions & 2 deletions src/lib/ebus/symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned>(m_data[i]);
if (--maxLength == 0) {
break;
}
}
}
return sstr.str();
Expand Down
33 changes: 18 additions & 15 deletions src/lib/ebus/symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit c084dd2

Please sign in to comment.