calculate symbol rate and add current+max rate to state command, add shortcut "s" for state command

This commit is contained in:
john30
2015-02-15 19:40:32 +01:00
parent 7bead7fa7b
commit c91ea5f40f
3 changed files with 48 additions and 7 deletions
+21 -3
View File
@@ -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);
}
+19
View File
@@ -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;
+8 -4
View File
@@ -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";
}