calculate symbol rate and add current+max rate to state command, add shortcut "s" for state command
This commit is contained in:
@@ -170,10 +170,27 @@ result_t BusHandler::sendAndWait(SymbolString& master, SymbolString& slave)
|
||||
|
||||
void BusHandler::run()
|
||||
{
|
||||
unsigned int symCount = 0;
|
||||
time_t lastTime;
|
||||
time(&lastTime);
|
||||
do {
|
||||
if (m_device->isValid() == true)
|
||||
handleSymbol();
|
||||
else {
|
||||
if (m_device->isValid() == true) {
|
||||
result_t result = handleSymbol();
|
||||
if (result != RESULT_ERR_TIMEOUT)
|
||||
symCount++;
|
||||
time_t now;
|
||||
time(&now);
|
||||
if (now != lastTime) {
|
||||
m_symPerSec = symCount / (now-lastTime);
|
||||
if (m_symPerSec > m_maxSymPerSec) {
|
||||
m_maxSymPerSec = m_symPerSec;
|
||||
if (m_maxSymPerSec > 100)
|
||||
logNotice(lf_bus, "max. symbols per second: %d", m_maxSymPerSec);
|
||||
}
|
||||
lastTime = now;
|
||||
symCount = 0;
|
||||
}
|
||||
} else {
|
||||
if (Wait(10) == false)
|
||||
break;
|
||||
result_t result = m_device->open();
|
||||
@@ -182,6 +199,7 @@ void BusHandler::run()
|
||||
logNotice(lf_bus, "re-opened %s", m_device->getName());
|
||||
else
|
||||
logError(lf_bus, "unable to open %s: %s", m_device->getName(), getResultCode(result));
|
||||
symCount = 0;
|
||||
}
|
||||
} while (isRunning() == true);
|
||||
}
|
||||
|
||||
@@ -273,6 +273,7 @@ public:
|
||||
m_lockCount(lockCount), m_remainLockCount(lockCount),
|
||||
m_pollInterval(pollInterval), m_lastReceive(0), m_lastPoll(0),
|
||||
m_currentRequest(NULL), m_nextSendPos(0),
|
||||
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_scanMessage(NULL) {
|
||||
@@ -327,6 +328,18 @@ public:
|
||||
*/
|
||||
bool hasSignal() { return m_state != bs_noSignal; }
|
||||
|
||||
/**
|
||||
* Return the current symbol rate.
|
||||
* @return the number of received symbols in the last second.
|
||||
*/
|
||||
unsigned int getSymbolRate() { return m_symPerSec; }
|
||||
|
||||
/**
|
||||
* Return the maximum seen symbol rate.
|
||||
* @return the maximum number of received symbols per second ever seen.
|
||||
*/
|
||||
unsigned int getMaxSymbolRate() { return m_maxSymPerSec; }
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
@@ -404,6 +417,12 @@ private:
|
||||
* (only relevant if m_request is set and state is @a bs_command or @a bs_response). */
|
||||
unsigned char m_nextSendPos;
|
||||
|
||||
/** the number of received symbols in the last second. */
|
||||
unsigned int m_symPerSec;
|
||||
|
||||
/** the maximum number of received symbols per second ever seen. */
|
||||
unsigned int m_maxSymPerSec;
|
||||
|
||||
/** the current @a BusState. */
|
||||
BusState m_state;
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ string MainLoop::decodeMessage(const string& data, bool& connected, bool& listen
|
||||
return executeFind(args);
|
||||
if (strcasecmp(str, "L") == 0 || strcasecmp(str, "LISTEN") == 0)
|
||||
return executeListen(args, listening);
|
||||
if (strcasecmp(str, "STATE") == 0)
|
||||
if (strcasecmp(str, "S") == 0 || strcasecmp(str, "STATE") == 0)
|
||||
return executeState(args);
|
||||
if (strcasecmp(str, "SCAN") == 0)
|
||||
return executeScan(args);
|
||||
@@ -522,9 +522,13 @@ string MainLoop::executeState(vector<string> &args)
|
||||
return "usage: 'state'\n"
|
||||
" Report bus state.";
|
||||
|
||||
if (m_busHandler->hasSignal() == true)
|
||||
return "signal acquired";
|
||||
|
||||
if (m_busHandler->hasSignal() == true) {
|
||||
ostringstream result;
|
||||
result << "signal acquired, "
|
||||
<< static_cast<unsigned>(m_busHandler->getSymbolRate()) << " symbols/sec, max. "
|
||||
<< static_cast<unsigned>(m_busHandler->getMaxSymbolRate()) << " symbols/sec";
|
||||
return result.str();
|
||||
}
|
||||
return "no signal";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user