diff --git a/src/ebusd/bushandler.cpp b/src/ebusd/bushandler.cpp index 382a31de..e49de79f 100644 --- a/src/ebusd/bushandler.cpp +++ b/src/ebusd/bushandler.cpp @@ -744,6 +744,15 @@ void BusHandler::receiveCompleted() deque messages = m_messages->findAll(m_command); Message* message = messages.size()>0 ? messages.front() : NULL; + if (m_grabUnknownMessages==gr_all || (message==NULL && m_grabUnknownMessages==gr_unknown)) { + string data; + string key = data = m_command.getDataStr(); + if (key.length() > 2*(1+1+2+1+4)) + key = key.substr(0, 2*(1+1+2+1+4)); // QQZZPBSBNN + up to 4 DD bytes + if (dstAddress != BROADCAST && !master) + data += " / " + m_response.getDataStr(); + m_grabbedUnknownMessages[key] = data; + } if (message == NULL) { if (dstAddress == BROADCAST) logNotice(lf_update, "unknown BC cmd: %s", m_command.getDataStr().c_str()); @@ -751,16 +760,6 @@ void BusHandler::receiveCompleted() logNotice(lf_update, "unknown MM cmd: %s", m_command.getDataStr().c_str()); else logNotice(lf_update, "unknown MS cmd: %s / %s", m_command.getDataStr().c_str(), m_response.getDataStr().c_str()); - - if (m_grabUnknownMessages) { - string data; - string key = data = m_command.getDataStr(); - if (key.length() > 2*(1+1+2+1+4)) - key = key.substr(0, 2*(1+1+2+1+4)); // QQZZPBSBNN + up to 4 DD bytes - if (dstAddress != BROADCAST && !master) - data += " / " + m_response.getDataStr(); - m_grabbedUnknownMessages[key] = data; - } } else { string circuit = message->getCircuit(); @@ -799,7 +798,7 @@ result_t BusHandler::startScan(bool full) deque messages = m_messages->findAll("scan", ""); for (deque::iterator it = messages.begin(); it < messages.end(); it++) { Message* message = *it; - if (message->getId()[0] == 0x07 && message->getId()[1] == 0x04) + if (message->getPrimaryCommand() == 0x07 && message->getSecondaryCommand() == 0x04) messages.erase(it--); // query pb 0x07 / sb 0x04 only once } @@ -938,10 +937,15 @@ result_t BusHandler::scanAndWait(unsigned char dstAddress, SymbolString& slave) return result; } -void BusHandler::enableGrab(bool enable) +bool BusHandler::enableGrab(bool enable, bool all) { - m_grabUnknownMessages = enable; - m_grabbedUnknownMessages.clear(); + GrabRequest request = enable ? (all ? gr_all : gr_unknown) : gr_none; + if (request==m_grabUnknownMessages) + return false; + if (m_grabUnknownMessages==gr_none) + m_grabbedUnknownMessages.clear(); + m_grabUnknownMessages = request; + return true; } void BusHandler::formatGrabResult(ostringstream& output) diff --git a/src/ebusd/bushandler.h b/src/ebusd/bushandler.h index ff4a6a3d..7cfc349f 100644 --- a/src/ebusd/bushandler.h +++ b/src/ebusd/bushandler.h @@ -72,6 +72,13 @@ enum BusState { bs_sendSyn, //!< send SYN for completed transfer [active set+get] }; +/** the possible grab request kinds. */ +enum GrabRequest { + gr_none, //!< no grabbing at all + gr_unknown, //!< grab unknown messages only + gr_all, //!< grab all messages +}; + /** bit for the seen state: seen. */ #define SEEN 0x01 @@ -301,7 +308,7 @@ public: m_symPerSec(0), m_maxSymPerSec(0), m_state(bs_noSignal), m_repeat(false), m_command(false), m_commandCrcValid(false), m_response(false), m_responseCrcValid(false), - m_grabUnknownMessages(false) { + m_grabUnknownMessages(gr_none) { memset(m_seenAddresses, 0, sizeof(m_seenAddresses)); } @@ -368,8 +375,10 @@ public: /** * Start or stop grabbing unknown messages. * @param enable true to enable grabbing, false to disable it. + * @param all true to grab all messages, false to grab unknown messages only (only relevant if @a enable is true). + * @return true when the grabbing was changed. */ - void enableGrab(bool enable=true); + bool enableGrab(bool enable=true, bool all=false); /** * Format the grabbed unknown messages to the @a ostringstream. @@ -543,7 +552,7 @@ private: map m_scanResults; /** whether to grab unknown messages. */ - bool m_grabUnknownMessages; + GrabRequest m_grabUnknownMessages; /** the grabbed unknown messages by ID prefix (QQZZPBSBNNDD with up to 4 DD bytes).*/ map m_grabbedUnknownMessages; diff --git a/src/ebusd/mainloop.cpp b/src/ebusd/mainloop.cpp index bab60a0a..e77d306a 100644 --- a/src/ebusd/mainloop.cpp +++ b/src/ebusd/mainloop.cpp @@ -758,21 +758,8 @@ string MainLoop::executeFind(vector &args) char str[32]; for (deque::iterator it = messages.begin(); it < messages.end();) { Message* message = *it++; - if (!id.empty()) { - vector msgId = message->getId(); - if (id.size()>msgId.size()) { - continue; - } - bool mismatch = false; - for (size_t pos = 0; poscheckIdMatch(id)) { + continue; } time_t lastup = message->getLastUpdateTime(); if (onlyWithData && lastup == 0) @@ -870,27 +857,23 @@ string MainLoop::executeState(vector &args) string MainLoop::executeGrab(vector &args) { - if (args.size() == 1) { - m_busHandler->enableGrab(); + bool all = args.size() == 2 && strcasecmp(args[1].c_str(), "ALL") == 0; + if (args.size() == 1 || all) + return m_busHandler->enableGrab(true, all) ? "grab started" : "grab continued"; - return getResultCode(RESULT_OK); + if (args.size() == 2) { + if (strcasecmp(args[1].c_str(), "STOP") == 0) + return m_busHandler->enableGrab(false) ? "grab stopped" : "grab not running"; + + if (strcasecmp(args[1].c_str(), "RESULT") == 0) { + ostringstream result; + m_busHandler->formatGrabResult(result); + return result.str(); + } } - - if (args.size() == 2 && strcasecmp(args[1].c_str(), "STOP") == 0) { - m_busHandler->enableGrab(false); - - return getResultCode(RESULT_OK); - } - - if (args.size() == 2 && strcasecmp(args[1].c_str(), "RESULT") == 0) { - ostringstream result; - m_busHandler->formatGrabResult(result); - return result.str(); - } - - return "usage: grab [stop]\n" + return "usage: grab [all|stop]\n" " or: grab result\n" - " Grab unknown messages or stop it, or report the seen unknown messages."; + " Start or stop grabbing unknown or all messages, or report the grabbed messages."; } string MainLoop::executeScan(vector &args) @@ -1031,7 +1014,7 @@ string MainLoop::executeHelp() " listen|l Listen for updates: listen [stop]\n" " state|s Report bus state\n" " info|i Report information about the daemon, the configuration, and seen devices.\n" - " grab|g Grab unknown messages: grab [stop]\n" + " grab|g Grab messages: grab [all|stop]\n" " Report the messages: grab result\n" " scan Scan slaves: scan [full]\n" " Report scan result: scan result\n"