reconnect the device after one minute of no signal and add reconnect count to info result, removed extra blank line from info result

This commit is contained in:
john30
2016-11-20 13:14:25 +01:00
parent f88d0188bb
commit d1f6d5e67d
4 changed files with 39 additions and 10 deletions
+8 -6
View File
@@ -252,7 +252,7 @@ void BusHandler::run()
time_t lastTime; time_t lastTime;
time(&lastTime); time(&lastTime);
do { do {
if (m_device->isValid()) { if (m_device->isValid() && !m_reconnect) {
result_t result = handleSymbol(); result_t result = handleSymbol();
if (result != RESULT_ERR_TIMEOUT) if (result != RESULT_ERR_TIMEOUT)
symCount++; symCount++;
@@ -262,20 +262,22 @@ void BusHandler::run()
m_symPerSec = symCount / (unsigned int)(now-lastTime); m_symPerSec = symCount / (unsigned int)(now-lastTime);
if (m_symPerSec > m_maxSymPerSec) { if (m_symPerSec > m_maxSymPerSec) {
m_maxSymPerSec = m_symPerSec; m_maxSymPerSec = m_symPerSec;
if (m_maxSymPerSec > 100) if (m_maxSymPerSec > 100) {
logNotice(lf_bus, "max. symbols per second: %d", m_maxSymPerSec); logNotice(lf_bus, "max. symbols per second: %d", m_maxSymPerSec);
}
} }
lastTime = now; lastTime = now;
symCount = 0; symCount = 0;
} }
} else { } else {
if (!Wait(10)) if (!Wait(10)) {
break; break;
}
m_reconnect = false;
result_t result = m_device->open(); result_t result = m_device->open();
if (result == RESULT_OK) {
if (result == RESULT_OK)
logNotice(lf_bus, "re-opened %s", m_device->getName()); logNotice(lf_bus, "re-opened %s", m_device->getName());
else { } else {
logError(lf_bus, "unable to open %s: %s", m_device->getName(), getResultCode(result)); logError(lf_bus, "unable to open %s: %s", m_device->getName(), getResultCode(result));
setState(bs_noSignal, result); setState(bs_noSignal, result);
} }
+9 -1
View File
@@ -316,7 +316,7 @@ public:
const unsigned int transferLatency, const unsigned int busAcquireTimeout, const unsigned int slaveRecvTimeout, const unsigned int transferLatency, const unsigned int busAcquireTimeout, const unsigned int slaveRecvTimeout,
const unsigned int lockCount, const bool generateSyn, const unsigned int lockCount, const bool generateSyn,
const unsigned int pollInterval) const unsigned int pollInterval)
: WaitThread(), m_device(device), m_messages(messages), : WaitThread(), m_device(device), m_reconnect(false), m_messages(messages),
m_ownMasterAddress(ownAddress), m_ownSlaveAddress((unsigned char)(ownAddress+5)), m_answer(answer), m_ownMasterAddress(ownAddress), m_ownSlaveAddress((unsigned char)(ownAddress+5)), m_answer(answer),
m_busLostRetries(busLostRetries), m_failedSendRetries(failedSendRetries), m_busLostRetries(busLostRetries), m_failedSendRetries(failedSendRetries),
m_transferLatency(transferLatency), m_busAcquireTimeout(busAcquireTimeout), m_slaveRecvTimeout(slaveRecvTimeout), m_transferLatency(transferLatency), m_busAcquireTimeout(busAcquireTimeout), m_slaveRecvTimeout(slaveRecvTimeout),
@@ -424,6 +424,11 @@ public:
*/ */
bool hasSignal() { return m_state != bs_noSignal; } bool hasSignal() { return m_state != bs_noSignal; }
/**
* Reconnect the device.
*/
void reconnect() { m_reconnect = true; }
/** /**
* Return the current symbol rate. * Return the current symbol rate.
* @return the number of received symbols in the last second. * @return the number of received symbols in the last second.
@@ -488,6 +493,9 @@ private:
/** the @a Device instance for accessing the bus. */ /** the @a Device instance for accessing the bus. */
Device* m_device; Device* m_device;
/** set to @p true when the device shall be reconnected. */
bool m_reconnect;
/** the @a MessageMap instance with all known @a Message instances. */ /** the @a MessageMap instance with all known @a Message instances. */
MessageMap* m_messages; MessageMap* m_messages;
+19 -3
View File
@@ -25,6 +25,9 @@
using namespace std; using namespace std;
/** the number of seconds of permanent missing signal after which to reconnect the device. */
#define RECONNECT_MISSING_SIGNAL 60
/** the known column names (pairs of full length name and short length name). */ /** the known column names (pairs of full length name and short length name). */
static const char* columnNames[] = { static const char* columnNames[] = {
"type", "t", "type", "t",
@@ -42,7 +45,9 @@ static const char* columnNames[] = {
static const size_t columnCount = sizeof(columnNames) / sizeof(char*); static const size_t columnCount = sizeof(columnNames) / sizeof(char*);
MainLoop::MainLoop(const struct options opt, Device *device, MessageMap* messages) MainLoop::MainLoop(const struct options opt, Device *device, MessageMap* messages)
: Thread(), m_device(device), m_messages(messages), m_address(opt.address), m_scanConfig(opt.scanConfig), m_initialScan(opt.initialScan), m_enableHex(opt.enableHex) : Thread(), m_device(device), m_reconnectCount(0), m_messages(messages),
m_address(opt.address), m_scanConfig(opt.scanConfig),
m_initialScan(opt.initialScan), m_enableHex(opt.enableHex)
{ {
// setup Device // setup Device
m_device->setLogRaw(opt.logRaw); m_device->setLogRaw(opt.logRaw);
@@ -98,7 +103,7 @@ MainLoop::~MainLoop()
void MainLoop::run() void MainLoop::run()
{ {
bool reload = true; bool reload = true;
time_t lastTaskRun, now; time_t lastTaskRun, now, lastSignal = 0;
int taskDelay = 5; int taskDelay = 5;
unsigned char lastScanAddress = 0; // 0 is known to be a master unsigned char lastScanAddress = 0; // 0 is known to be a master
time(&now); time(&now);
@@ -112,9 +117,19 @@ void MainLoop::run()
time(&now); time(&now);
if (now<lastTaskRun) { if (now<lastTaskRun) {
// clock skew // clock skew
if (now<lastSignal) {
lastSignal -= lastTaskRun-now;
}
lastTaskRun = now; lastTaskRun = now;
} else if (now > lastTaskRun+taskDelay) { } else if (now > lastTaskRun+taskDelay) {
logDebug(lf_main, "performing regular tasks"); logDebug(lf_main, "performing regular tasks");
if (m_busHandler->hasSignal()) {
lastSignal = now;
} else if (lastSignal && now > lastSignal+RECONNECT_MISSING_SIGNAL) {
lastSignal = 0;
m_busHandler->reconnect();
m_reconnectCount++;
}
if (m_scanConfig) { if (m_scanConfig) {
if (m_initialScan != ESC && reload && m_busHandler->hasSignal()) { if (m_initialScan != ESC && reload && m_busHandler->hasSignal()) {
result_t result = RESULT_ERR_NO_SIGNAL; result_t result = RESULT_ERR_NO_SIGNAL;
@@ -1135,11 +1150,12 @@ string MainLoop::executeInfo(vector<string> &args)
} else { } else {
result << "signal: no signal\n"; result << "signal: no signal\n";
} }
result << "reconnects: " << static_cast<unsigned>(m_reconnectCount) << "\n";
result << "masters: " << static_cast<unsigned>(m_busHandler->getMasterCount()) << "\n"; result << "masters: " << static_cast<unsigned>(m_busHandler->getMasterCount()) << "\n";
result << "messages: " << static_cast<unsigned>(m_messages->size()) << "\n"; result << "messages: " << static_cast<unsigned>(m_messages->size()) << "\n";
result << "conditional: " << static_cast<unsigned>(m_messages->sizeConditional()) << "\n"; result << "conditional: " << static_cast<unsigned>(m_messages->sizeConditional()) << "\n";
result << "poll: " << static_cast<unsigned>(m_messages->sizePoll()) << "\n"; result << "poll: " << static_cast<unsigned>(m_messages->sizePoll()) << "\n";
result << "update: " << static_cast<unsigned>(m_messages->sizePassive()) << "\n"; result << "update: " << static_cast<unsigned>(m_messages->sizePassive());
m_busHandler->formatSeenInfo(result); m_busHandler->formatSeenInfo(result);
return result.str(); return result.str();
} }
+3
View File
@@ -69,6 +69,9 @@ private:
/** the @a Device instance. */ /** the @a Device instance. */
Device* m_device; Device* m_device;
/** the number of reconnects requested from the @a Device. */
unsigned int m_reconnectCount;
/** the @a MessageMap instance. */ /** the @a MessageMap instance. */
MessageMap* m_messages; MessageMap* m_messages;