From 0e6fcb60b1f6f7a3d083c4da38bf8cda9cbccab6 Mon Sep 17 00:00:00 2001 From: john30 Date: Sat, 7 Mar 2015 14:31:34 +0100 Subject: [PATCH] log and count new masters, added master count to state command --- src/ebusd/bushandler.cpp | 45 +++++++++++++++++++++++----------------- src/ebusd/bushandler.h | 18 +++++++++------- src/ebusd/mainloop.cpp | 5 +++-- 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/src/ebusd/bushandler.cpp b/src/ebusd/bushandler.cpp index 95fbd81f..b532651c 100644 --- a/src/ebusd/bushandler.cpp +++ b/src/ebusd/bushandler.cpp @@ -369,8 +369,7 @@ result_t BusHandler::handleSymbol() } // arbitration lost. if same priority class found, try again after next AUTO-SYN m_remainLockCount = isMaster(recvSymbol) ? 2 : 1; // number of SYN to wait for before next send try - if ((recvSymbol & 0x0f) != (sendSymbol & 0x0f) - && m_lockCount > m_remainLockCount) + if ((recvSymbol & 0x0f) != (sendSymbol & 0x0f) && m_lockCount > m_remainLockCount) // if different priority class found, try again after N AUTO-SYN symbols (at least next AUTO-SYN) m_remainLockCount = m_lockCount; setState(m_state, RESULT_ERR_BUS_LOST); // try again later @@ -604,12 +603,13 @@ result_t BusHandler::setState(BusState state, result_t result, bool firstRepetit logDebug(lf_bus, "notify request: %s", getResultCode(result)); unsigned char dstAddress = m_currentRequest->m_master[1]; if (result == RESULT_OK && isValidAddress(dstAddress, false) && !m_seenAddresses[dstAddress]) { - if (m_autoLockCount) { - unsigned char master = getMasterAddress(dstAddress); - if (master != SYN && !m_seenAddresses[master]) { - m_seenAddresses[master] = true; - m_lockCount++; - } + unsigned char master = getMasterAddress(dstAddress); + if (master != SYN && !m_seenAddresses[master]) { + m_seenAddresses[master] = true; + m_masterCount++; + if (m_autoLockCount) + m_lockCount = m_masterCount; + logNotice(lf_bus, "new master %2.2x", master); } m_seenAddresses[dstAddress] = true; } @@ -671,28 +671,35 @@ result_t BusHandler::setState(BusState state, result_t result, bool firstRepetit void BusHandler::receiveCompleted() { unsigned char srcAddress = m_command[0], dstAddress = m_command[1]; - bool master = isMaster(dstAddress); - if (m_autoLockCount && isMaster(srcAddress) && !m_seenAddresses[srcAddress]) { - m_lockCount++; + if (isMaster(srcAddress) && !m_seenAddresses[srcAddress]) { + m_masterCount++; + if (m_autoLockCount) + m_lockCount = m_masterCount; + logNotice(lf_bus, "new master %2.2x", srcAddress); } + bool master = isMaster(dstAddress); m_seenAddresses[srcAddress] = true; if (dstAddress == BROADCAST) logInfo(lf_update, "update BC cmd: %s", m_command.getDataStr().c_str()); else if (master) { logInfo(lf_update, "update MM cmd: %s", m_command.getDataStr().c_str()); - if (m_autoLockCount && !m_seenAddresses[dstAddress]) { - m_lockCount++; + if (!m_seenAddresses[dstAddress]) { + m_masterCount++; + if (m_autoLockCount) + m_lockCount = m_masterCount; + logNotice(lf_bus, "new master %2.2x", dstAddress); } m_seenAddresses[dstAddress] = true; } else { logInfo(lf_update, "update MS cmd: %s / %s", m_command.getDataStr().c_str(), m_response.getDataStr().c_str()); - if (m_autoLockCount) { - unsigned char master = getMasterAddress(dstAddress); - if (master != SYN && !m_seenAddresses[master]) { - m_seenAddresses[master] = true; - m_lockCount++; - } + unsigned char masterAddr = getMasterAddress(dstAddress); + if (masterAddr != SYN && !m_seenAddresses[masterAddr]) { + m_seenAddresses[masterAddr] = true; + m_masterCount++; + if (m_autoLockCount) + m_lockCount = m_masterCount; + logNotice(lf_bus, "new master %2.2x", masterAddr); } m_seenAddresses[dstAddress] = true; } diff --git a/src/ebusd/bushandler.h b/src/ebusd/bushandler.h index de1d60d4..369c7f89 100644 --- a/src/ebusd/bushandler.h +++ b/src/ebusd/bushandler.h @@ -270,7 +270,7 @@ public: m_ownMasterAddress(ownAddress), m_ownSlaveAddress((unsigned char)(ownAddress+5)), m_answer(answer), m_busLostRetries(busLostRetries), m_failedSendRetries(failedSendRetries), m_busAcquireTimeout(busAcquireTimeout), m_slaveRecvTimeout(slaveRecvTimeout), - m_autoLockCount(lockCount==0), m_lockCount(lockCount==0 ? 1 : lockCount), m_remainLockCount(lockCount), + m_masterCount(1), m_autoLockCount(lockCount==0), m_lockCount(lockCount==0 ? 1 : lockCount), m_remainLockCount(m_autoLockCount), m_pollInterval(pollInterval), m_lastReceive(0), m_lastPoll(0), m_currentRequest(NULL), m_nextSendPos(0), m_symPerSec(0), m_maxSymPerSec(0), @@ -302,13 +302,6 @@ public: */ virtual void run(); - /** - * Get the last received data for the @a Message. - * @param message the @a Message instance. - * @return the last received data for the @a Message, or the empty string if not available. - */ - string getReceivedData(Message* message); - /** * Initiate a scan of the slave addresses. * @param full true for a full scan (all slaves), false for scanning only already seen slaves. @@ -340,6 +333,12 @@ public: */ unsigned int getMaxSymbolRate() { return m_maxSymPerSec; } + /** + * Return the number of masters already seen. + * @return the number of masters already seen (including ebusd itself). + */ + unsigned int getMasterCount() { return m_masterCount; } + private: /** @@ -389,6 +388,9 @@ private: /** the maximum time in microseconds an addressed slave is expected to acknowledge. */ const unsigned int m_slaveRecvTimeout; + /** the number of masters already seen. */ + unsigned int m_masterCount; + /** whether m_lockCount shall be detected automatically. */ const bool m_autoLockCount; diff --git a/src/ebusd/mainloop.cpp b/src/ebusd/mainloop.cpp index 9dca87c9..6f1c062f 100644 --- a/src/ebusd/mainloop.cpp +++ b/src/ebusd/mainloop.cpp @@ -565,8 +565,9 @@ string MainLoop::executeState(vector &args) if (m_busHandler->hasSignal()) { ostringstream result; result << "signal acquired, " - << static_cast(m_busHandler->getSymbolRate()) << " symbols/sec, max. " - << static_cast(m_busHandler->getMaxSymbolRate()) << " symbols/sec"; + << static_cast(m_busHandler->getSymbolRate()) << " symbols/sec (" + << static_cast(m_busHandler->getMaxSymbolRate()) << " max), " + << static_cast(m_busHandler->getMasterCount()) << " masters"; return result.str(); } return "no signal";