added "all" to "grab" command for grabbing known messages as well, adjusted to unlimited message ID length
This commit is contained in:
+16
-12
@@ -744,15 +744,7 @@ void BusHandler::receiveCompleted()
|
|||||||
|
|
||||||
deque<Message*> messages = m_messages->findAll(m_command);
|
deque<Message*> messages = m_messages->findAll(m_command);
|
||||||
Message* message = messages.size()>0 ? messages.front() : NULL;
|
Message* message = messages.size()>0 ? messages.front() : NULL;
|
||||||
if (message == NULL) {
|
if (m_grabUnknownMessages==gr_all || (message==NULL && m_grabUnknownMessages==gr_unknown)) {
|
||||||
if (dstAddress == BROADCAST)
|
|
||||||
logNotice(lf_update, "unknown BC cmd: %s", m_command.getDataStr().c_str());
|
|
||||||
else if (master)
|
|
||||||
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 data;
|
||||||
string key = data = m_command.getDataStr();
|
string key = data = m_command.getDataStr();
|
||||||
if (key.length() > 2*(1+1+2+1+4))
|
if (key.length() > 2*(1+1+2+1+4))
|
||||||
@@ -761,6 +753,13 @@ void BusHandler::receiveCompleted()
|
|||||||
data += " / " + m_response.getDataStr();
|
data += " / " + m_response.getDataStr();
|
||||||
m_grabbedUnknownMessages[key] = data;
|
m_grabbedUnknownMessages[key] = data;
|
||||||
}
|
}
|
||||||
|
if (message == NULL) {
|
||||||
|
if (dstAddress == BROADCAST)
|
||||||
|
logNotice(lf_update, "unknown BC cmd: %s", m_command.getDataStr().c_str());
|
||||||
|
else if (master)
|
||||||
|
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());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
string circuit = message->getCircuit();
|
string circuit = message->getCircuit();
|
||||||
@@ -799,7 +798,7 @@ result_t BusHandler::startScan(bool full)
|
|||||||
deque<Message*> messages = m_messages->findAll("scan", "");
|
deque<Message*> messages = m_messages->findAll("scan", "");
|
||||||
for (deque<Message*>::iterator it = messages.begin(); it < messages.end(); it++) {
|
for (deque<Message*>::iterator it = messages.begin(); it < messages.end(); it++) {
|
||||||
Message* message = *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
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BusHandler::enableGrab(bool enable)
|
bool BusHandler::enableGrab(bool enable, bool all)
|
||||||
{
|
{
|
||||||
m_grabUnknownMessages = enable;
|
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_grabbedUnknownMessages.clear();
|
||||||
|
m_grabUnknownMessages = request;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BusHandler::formatGrabResult(ostringstream& output)
|
void BusHandler::formatGrabResult(ostringstream& output)
|
||||||
|
|||||||
+12
-3
@@ -72,6 +72,13 @@ enum BusState {
|
|||||||
bs_sendSyn, //!< send SYN for completed transfer [active set+get]
|
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. */
|
/** bit for the seen state: seen. */
|
||||||
#define SEEN 0x01
|
#define SEEN 0x01
|
||||||
|
|
||||||
@@ -301,7 +308,7 @@ public:
|
|||||||
m_symPerSec(0), m_maxSymPerSec(0),
|
m_symPerSec(0), m_maxSymPerSec(0),
|
||||||
m_state(bs_noSignal), m_repeat(false),
|
m_state(bs_noSignal), m_repeat(false),
|
||||||
m_command(false), m_commandCrcValid(false), m_response(false), m_responseCrcValid(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));
|
memset(m_seenAddresses, 0, sizeof(m_seenAddresses));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,8 +375,10 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Start or stop grabbing unknown messages.
|
* Start or stop grabbing unknown messages.
|
||||||
* @param enable true to enable grabbing, false to disable it.
|
* @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.
|
* Format the grabbed unknown messages to the @a ostringstream.
|
||||||
@@ -543,7 +552,7 @@ private:
|
|||||||
map<unsigned char, string> m_scanResults;
|
map<unsigned char, string> m_scanResults;
|
||||||
|
|
||||||
/** whether to grab unknown messages. */
|
/** 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).*/
|
/** the grabbed unknown messages by ID prefix (QQZZPBSBNNDD with up to 4 DD bytes).*/
|
||||||
map<string, string> m_grabbedUnknownMessages;
|
map<string, string> m_grabbedUnknownMessages;
|
||||||
|
|||||||
+12
-29
@@ -758,22 +758,9 @@ string MainLoop::executeFind(vector<string> &args)
|
|||||||
char str[32];
|
char str[32];
|
||||||
for (deque<Message*>::iterator it = messages.begin(); it < messages.end();) {
|
for (deque<Message*>::iterator it = messages.begin(); it < messages.end();) {
|
||||||
Message* message = *it++;
|
Message* message = *it++;
|
||||||
if (!id.empty()) {
|
if (!id.empty() && !message->checkIdMatch(id)) {
|
||||||
vector<unsigned char> msgId = message->getId();
|
|
||||||
if (id.size()>msgId.size()) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
bool mismatch = false;
|
|
||||||
for (size_t pos = 0; pos<id.size(); pos++) {
|
|
||||||
if (id[pos]!=msgId[pos]) {
|
|
||||||
mismatch = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mismatch) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
time_t lastup = message->getLastUpdateTime();
|
time_t lastup = message->getLastUpdateTime();
|
||||||
if (onlyWithData && lastup == 0)
|
if (onlyWithData && lastup == 0)
|
||||||
continue;
|
continue;
|
||||||
@@ -870,27 +857,23 @@ string MainLoop::executeState(vector<string> &args)
|
|||||||
|
|
||||||
string MainLoop::executeGrab(vector<string> &args)
|
string MainLoop::executeGrab(vector<string> &args)
|
||||||
{
|
{
|
||||||
if (args.size() == 1) {
|
bool all = args.size() == 2 && strcasecmp(args[1].c_str(), "ALL") == 0;
|
||||||
m_busHandler->enableGrab();
|
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 (args.size() == 2 && strcasecmp(args[1].c_str(), "STOP") == 0) {
|
if (strcasecmp(args[1].c_str(), "RESULT") == 0) {
|
||||||
m_busHandler->enableGrab(false);
|
|
||||||
|
|
||||||
return getResultCode(RESULT_OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.size() == 2 && strcasecmp(args[1].c_str(), "RESULT") == 0) {
|
|
||||||
ostringstream result;
|
ostringstream result;
|
||||||
m_busHandler->formatGrabResult(result);
|
m_busHandler->formatGrabResult(result);
|
||||||
return result.str();
|
return result.str();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return "usage: grab [stop]\n"
|
return "usage: grab [all|stop]\n"
|
||||||
" or: grab result\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<string> &args)
|
string MainLoop::executeScan(vector<string> &args)
|
||||||
@@ -1031,7 +1014,7 @@ string MainLoop::executeHelp()
|
|||||||
" listen|l Listen for updates: listen [stop]\n"
|
" listen|l Listen for updates: listen [stop]\n"
|
||||||
" state|s Report bus state\n"
|
" state|s Report bus state\n"
|
||||||
" info|i Report information about the daemon, the configuration, and seen devices.\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"
|
" Report the messages: grab result\n"
|
||||||
" scan Scan slaves: scan [full]\n"
|
" scan Scan slaves: scan [full]\n"
|
||||||
" Report scan result: scan result\n"
|
" Report scan result: scan result\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user