add enum for predefined symbols, enhance getStr()
This commit is contained in:
@@ -108,7 +108,7 @@ MainLoop::MainLoop(const struct options& opt, BusHandler* busHandler,
|
|||||||
: Thread(), m_busHandler(busHandler), m_protocol(busHandler->getProtocol()), m_reconnectCount(0),
|
: Thread(), m_busHandler(busHandler), m_protocol(busHandler->getProtocol()), m_reconnectCount(0),
|
||||||
m_userList(opt.accessLevel), m_messages(messages),
|
m_userList(opt.accessLevel), m_messages(messages),
|
||||||
m_scanHelper(scanHelper), m_address(opt.address), m_scanConfig(opt.scanConfig),
|
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_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) {
|
m_shutdown(false), m_runUpdateCheck(opt.updateCheck), m_httpClient(), m_requestQueue(requestQueue) {
|
||||||
if (opt.aclFile[0]) {
|
if (opt.aclFile[0]) {
|
||||||
@@ -676,7 +676,7 @@ result_t MainLoop::executeRead(const vector<string>& args, const string& levels,
|
|||||||
if (dest) {
|
if (dest) {
|
||||||
dstAddress = address;
|
dstAddress = address;
|
||||||
} else {
|
} else {
|
||||||
srcAddress = address == m_address ? SYN : address;
|
srcAddress = address == m_address ? (symbol_t)SYN : address;
|
||||||
}
|
}
|
||||||
} else if (args[argPos] == "-p") {
|
} else if (args[argPos] == "-p") {
|
||||||
argPos++;
|
argPos++;
|
||||||
@@ -933,7 +933,7 @@ result_t MainLoop::executeWrite(const vector<string>& args, const string levels,
|
|||||||
if (dest) {
|
if (dest) {
|
||||||
dstAddress = address;
|
dstAddress = address;
|
||||||
} else {
|
} else {
|
||||||
srcAddress = address == m_address ? SYN : address;
|
srcAddress = address == m_address ? (symbol_t)SYN : address;
|
||||||
}
|
}
|
||||||
} else if (args[argPos] == "-c") {
|
} else if (args[argPos] == "-c") {
|
||||||
argPos++;
|
argPos++;
|
||||||
@@ -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)) {
|
if (ret != RESULT_OK || !isValidAddress(address, false) || !isMaster(address)) {
|
||||||
return RESULT_ERR_INVALID_ADDR;
|
return RESULT_ERR_INVALID_ADDR;
|
||||||
}
|
}
|
||||||
srcAddress = address == m_address ? SYN : address;
|
srcAddress = address == m_address ? (symbol_t)SYN : address;
|
||||||
} else if (args[argPos] == "-n") {
|
} else if (args[argPos] == "-n") {
|
||||||
autoLength = true;
|
autoLength = true;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ uint64_t Message::createKey(const MasterSymbolString& master, size_t maxIdLength
|
|||||||
}
|
}
|
||||||
uint64_t key = (uint64_t)idLength << (8 * 7 + 5);
|
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)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[2] << (8 * 5); // PB
|
||||||
key |= (uint64_t)master[3] << (8 * 4); // SB
|
key |= (uint64_t)master[3] << (8 * 4); // SB
|
||||||
int exp = 3;
|
int exp = 3;
|
||||||
|
|||||||
@@ -145,14 +145,21 @@ result_t SymbolString::parseHexEscaped(const string& str) {
|
|||||||
return inEscape ? RESULT_ERR_ESC : RESULT_OK;
|
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;
|
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++) {
|
for (size_t i = 0; i < m_data.size(); i++) {
|
||||||
if (skipFirstSymbols > 0) {
|
if (skipFirstSymbols > 0) {
|
||||||
skipFirstSymbols--;
|
skipFirstSymbols--;
|
||||||
} else {
|
} else if (i != lengthOffset) {
|
||||||
sstr << nouppercase << setw(2) << hex
|
sstr << nouppercase << setw(2) << hex
|
||||||
<< setfill('0') << static_cast<unsigned>(m_data[i]);
|
<< setfill('0') << static_cast<unsigned>(m_data[i]);
|
||||||
|
if (--maxLength == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return sstr.str();
|
return sstr.str();
|
||||||
|
|||||||
+18
-15
@@ -72,20 +72,21 @@ using std::ostringstream;
|
|||||||
/** the base type for symbols sent to/from the eBUS. */
|
/** the base type for symbols sent to/from the eBUS. */
|
||||||
typedef unsigned char symbol_t;
|
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)
|
* List of predefined eBUS symbols.
|
||||||
|
*/
|
||||||
/** synchronization symbol. */
|
enum PredefinedSymbol : symbol_t {
|
||||||
#define SYN ((symbol_t)0xAA)
|
/** escape symbol, either followed by 0x00 for the value 0xA9, or 0x01 for the value 0xAA. */
|
||||||
|
ESC = 0xA9,
|
||||||
/** positive acknowledge symbol. */
|
/** synchronization symbol. */
|
||||||
#define ACK ((symbol_t)0x00)
|
SYN = 0xAA,
|
||||||
|
/** positive acknowledge symbol. */
|
||||||
/** negative acknowledge symbol. */
|
ACK = 0x00,
|
||||||
#define NAK ((symbol_t)0xFF)
|
/** negative acknowledge symbol. */
|
||||||
|
NAK = 0xFF,
|
||||||
/** the broadcast destination address. */
|
/** the broadcast destination address. */
|
||||||
#define BROADCAST ((symbol_t)0xFE)
|
BROADCAST = 0xFE,
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse an unsigned int value.
|
* Parse an unsigned int value.
|
||||||
@@ -156,9 +157,11 @@ class SymbolString {
|
|||||||
/**
|
/**
|
||||||
* Return the symbols as hex string.
|
* Return the symbols as hex string.
|
||||||
* @param skipFirstSymbols the number of first symbols to skip.
|
* @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.
|
* @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.
|
* Dump the data in JSON format to the output.
|
||||||
|
|||||||
Reference in New Issue
Block a user