extracted helper method, prepared scan state

This commit is contained in:
john30
2015-10-31 17:42:04 +01:00
parent 79c924aa1e
commit 75ff3d3c0b
2 changed files with 43 additions and 42 deletions
+29 -40
View File
@@ -638,17 +638,9 @@ result_t BusHandler::setState(BusState state, result_t result, bool firstRepetit
else if (state == bs_sendSyn || (result != RESULT_OK && !firstRepetition)) { else if (state == bs_sendSyn || (result != RESULT_OK && !firstRepetition)) {
logDebug(lf_bus, "notify request: %s", getResultCode(result)); logDebug(lf_bus, "notify request: %s", getResultCode(result));
unsigned char dstAddress = m_currentRequest->m_master[1]; unsigned char dstAddress = m_currentRequest->m_master[1];
if (result == RESULT_OK && isValidAddress(dstAddress, false) && !m_seenAddresses[dstAddress]) { if (result == RESULT_OK)
unsigned char master = getMasterAddress(dstAddress); addSeenAddress(dstAddress);
if (master != SYN && !m_seenAddresses[master]) {
m_seenAddresses[master] = true;
m_masterCount++;
if (m_autoLockCount && m_masterCount>m_lockCount)
m_lockCount = m_masterCount;
logNotice(lf_bus, "new master %2.2x", master);
}
m_seenAddresses[dstAddress] = true;
}
bool restart = m_currentRequest->notify( bool restart = m_currentRequest->notify(
result == RESULT_ERR_SYN && (m_state == bs_recvCmdAck || m_state == bs_recvRes) ? RESULT_ERR_TIMEOUT : result, m_response result == RESULT_ERR_SYN && (m_state == bs_recvCmdAck || m_state == bs_recvRes) ? RESULT_ERR_TIMEOUT : result, m_response
); );
@@ -706,6 +698,25 @@ result_t BusHandler::setState(BusState state, result_t result, bool firstRepetit
return result; return result;
} }
void BusHandler::addSeenAddress(unsigned char address)
{
if (!isValidAddress(address, false))
return;
if (!isMaster(address)) {
m_seenAddresses[address] |= SEEN;
address = getMasterAddress(address);
if (address==SYN)
return;
}
if (m_seenAddresses[address]==0) {
m_masterCount++;
if (m_autoLockCount && m_masterCount>m_lockCount)
m_lockCount = m_masterCount;
logNotice(lf_bus, "new master %2.2x", address);//TODO scan
m_seenAddresses[address] |= SEEN;
}
}
void BusHandler::receiveCompleted() void BusHandler::receiveCompleted()
{ {
unsigned char srcAddress = m_command[0], dstAddress = m_command[1]; unsigned char srcAddress = m_command[0], dstAddress = m_command[1];
@@ -713,38 +724,16 @@ void BusHandler::receiveCompleted()
logError(lf_bus, "invalid self-addressed message from %2.2x", srcAddress); logError(lf_bus, "invalid self-addressed message from %2.2x", srcAddress);
return; return;
} }
if (isMaster(srcAddress) && !m_seenAddresses[srcAddress]) { addSeenAddress(srcAddress);
m_masterCount++; addSeenAddress(dstAddress);
if (m_autoLockCount && m_masterCount>m_lockCount)
m_lockCount = m_masterCount;
logNotice(lf_bus, "new master %2.2x", srcAddress);
}
bool master = isMaster(dstAddress); bool master = isMaster(dstAddress);
m_seenAddresses[srcAddress] = true;
if (dstAddress == BROADCAST) if (dstAddress == BROADCAST)
logInfo(lf_update, "update BC cmd: %s", m_command.getDataStr().c_str()); logInfo(lf_update, "update BC cmd: %s", m_command.getDataStr().c_str());
else if (master) { else if (master)
logInfo(lf_update, "update MM cmd: %s", m_command.getDataStr().c_str()); logInfo(lf_update, "update MM cmd: %s", m_command.getDataStr().c_str());
if (!m_seenAddresses[dstAddress]) { else
m_masterCount++;
if (m_autoLockCount && m_masterCount>m_lockCount)
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()); logInfo(lf_update, "update MS cmd: %s / %s", m_command.getDataStr().c_str(), m_response.getDataStr().c_str());
unsigned char masterAddr = getMasterAddress(dstAddress);
if (masterAddr != SYN && !m_seenAddresses[masterAddr]) {
m_seenAddresses[masterAddr] = true;
m_masterCount++;
if (m_autoLockCount && m_masterCount>m_lockCount)
m_lockCount = m_masterCount;
logNotice(lf_bus, "new master %2.2x", masterAddr);
}
m_seenAddresses[dstAddress] = true;
}
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;
@@ -821,9 +810,9 @@ result_t BusHandler::startScan(bool full)
for (unsigned char slave = 1; slave != 0; slave++) { // 0 is known to be a master for (unsigned char slave = 1; slave != 0; slave++) { // 0 is known to be a master
if (!isValidAddress(slave, false) || isMaster(slave)) if (!isValidAddress(slave, false) || isMaster(slave))
continue; continue;
if (!full && !m_seenAddresses[slave]) { if (!full && m_seenAddresses[slave]==0) {
unsigned char master = getMasterAddress(slave); // check if we saw the corresponding master already unsigned char master = getMasterAddress(slave); // check if we saw the corresponding master already
if (master == SYN || !m_seenAddresses[master]) if (master == SYN || m_seenAddresses[master]==0)
continue; continue;
} }
+14 -2
View File
@@ -67,6 +67,12 @@ enum BusState {
bs_sendSyn, //!< send SYN for completed transfer [active set+get] bs_sendSyn, //!< send SYN for completed transfer [active set+get]
}; };
/** bit for the seen state: seen. */
#define SEEN 1
/** bit for the seen state: scanned. */
#define SCANNED 1
class BusHandler; class BusHandler;
/** /**
@@ -372,6 +378,12 @@ private:
*/ */
result_t setState(BusState state, result_t result, bool firstRepetition=false); result_t setState(BusState state, result_t result, bool firstRepetition=false);
/**
* Add a seen bus address.
* @param address the seen bus address.
*/
void addSeenAddress(unsigned char address);
/** /**
* Called when a passive reception was successfully completed. * Called when a passive reception was successfully completed.
*/ */
@@ -465,8 +477,8 @@ private:
/** whether the response CRC is valid. */ /** whether the response CRC is valid. */
bool m_responseCrcValid; bool m_responseCrcValid;
/** the participating bus addresses seen so far. */ /** the participating bus addresses seen so far (0 if not seen yet, or combination of @a SEEN bits). */
bool m_seenAddresses[256]; unsigned char m_seenAddresses[256];
/** the @a Message instance used for scanning. */ /** the @a Message instance used for scanning. */
Message* m_scanMessage; Message* m_scanMessage;