let ScanRequest do all the work
This commit is contained in:
+22
-22
@@ -103,7 +103,6 @@ result_t ScanRequest::prepare(unsigned char ownMasterAddress)
|
|||||||
bool ScanRequest::notify(result_t result, SymbolString& slave)
|
bool ScanRequest::notify(result_t result, SymbolString& slave)
|
||||||
{
|
{
|
||||||
unsigned char dstAddress = m_master[1];
|
unsigned char dstAddress = m_master[1];
|
||||||
ostringstream scanResult;
|
|
||||||
if (result == RESULT_OK) {
|
if (result == RESULT_OK) {
|
||||||
if (m_message==m_messageMap->getScanMessage()) {
|
if (m_message==m_messageMap->getScanMessage()) {
|
||||||
Message* message = m_messageMap->getScanMessage(dstAddress);
|
Message* message = m_messageMap->getScanMessage(dstAddress);
|
||||||
@@ -120,27 +119,30 @@ bool ScanRequest::notify(result_t result, SymbolString& slave)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (result==RESULT_OK)
|
if (result==RESULT_OK)
|
||||||
result = m_message->decodeLastData(scanResult, 0, true); // decode data
|
result = m_message->decodeLastData(m_scanResult, 0, true); // decode data
|
||||||
}
|
}
|
||||||
if (result < RESULT_OK) {
|
if (result < RESULT_OK) {
|
||||||
if (!m_slaves.empty())
|
if (!m_slaves.empty())
|
||||||
m_slaves.pop_front();
|
m_slaves.pop_front();
|
||||||
if (result == RESULT_ERR_TIMEOUT)
|
if (result == RESULT_ERR_TIMEOUT)
|
||||||
logInfo(lf_bus, "scan %2.2x timed out, %d remain", dstAddress, m_slaves.size());
|
logInfo(lf_bus, "scan %2.2x timed out (%d slaves left)", dstAddress, m_slaves.size());
|
||||||
else
|
else
|
||||||
logError(lf_bus, "scan %2.2x failed, %d remain: %s", dstAddress, m_slaves.size(), getResultCode(result));
|
logError(lf_bus, "scan %2.2x failed (%d slaves left): %s", dstAddress, m_slaves.size(), getResultCode(result));
|
||||||
m_busHandler->addScanResult(dstAddress, "", result); // TODO combine all data from one slave and then store in BusHandler
|
m_busHandler->setScanResult(dstAddress, m_scanResult.str(), result);
|
||||||
// skip remaining secondary messages
|
// skip remaining secondary messages
|
||||||
|
m_messages.clear();
|
||||||
|
} else if (m_messages.empty()) {
|
||||||
|
m_busHandler->setScanResult(dstAddress, m_scanResult.str(), result);
|
||||||
|
if (!m_slaves.empty())
|
||||||
|
m_slaves.pop_front();
|
||||||
|
logNotice(lf_bus, "scan %2.2x completed (%d slaves left)", dstAddress, m_slaves.size());
|
||||||
|
}
|
||||||
|
if (m_slaves.empty())
|
||||||
|
return false;
|
||||||
|
if (m_messages.empty()) {
|
||||||
m_messages = m_allMessages;
|
m_messages = m_allMessages;
|
||||||
} else {
|
m_scanResult.str("");
|
||||||
m_busHandler->addScanResult(dstAddress, scanResult.str(), result);
|
m_scanResult.clear();
|
||||||
// check for remaining secondary messages
|
|
||||||
if (m_messages.empty()) {
|
|
||||||
if (!m_slaves.empty())
|
|
||||||
m_slaves.pop_front();
|
|
||||||
logNotice(lf_bus, "scan %2.2x completed, %d remain", dstAddress, m_slaves.size());
|
|
||||||
m_messages = m_allMessages;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
m_index = 0;
|
m_index = 0;
|
||||||
m_message = m_messages.front();
|
m_message = m_messages.front();
|
||||||
@@ -847,19 +849,17 @@ result_t BusHandler::startScan(bool full)
|
|||||||
return RESULT_OK;
|
return RESULT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BusHandler::addScanResult(unsigned char dstAddress, string str, result_t result)
|
void BusHandler::setScanResult(unsigned char dstAddress, string str, result_t result)
|
||||||
{
|
{
|
||||||
if (result==RESULT_ERR_NO_SIGNAL)
|
if (result==RESULT_ERR_NO_SIGNAL)
|
||||||
return;
|
return;
|
||||||
m_seenAddresses[dstAddress] |= SCAN_INIT;
|
m_seenAddresses[dstAddress] |= SCAN_INIT;
|
||||||
if (result!=RESULT_OK)
|
if (result==RESULT_OK) {
|
||||||
return;
|
m_seenAddresses[dstAddress] |= SCAN_DONE;
|
||||||
m_seenAddresses[dstAddress] |= SCAN_DONE;
|
logNotice(lf_bus, "scan %2.2x: %s", dstAddress, str.c_str());
|
||||||
logNotice(lf_bus, "scan %2.2x: %s", dstAddress, str.c_str());
|
}
|
||||||
if (m_scanResults.find(dstAddress) == m_scanResults.end())
|
if (str.length()>0)
|
||||||
m_scanResults[dstAddress] = str;
|
m_scanResults[dstAddress] = str;
|
||||||
else
|
|
||||||
m_scanResults[dstAddress] += str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BusHandler::formatScanResult(ostringstream& output)
|
void BusHandler::formatScanResult(ostringstream& output)
|
||||||
|
|||||||
@@ -244,6 +244,9 @@ private:
|
|||||||
/** the slave addresses to scan. */
|
/** the slave addresses to scan. */
|
||||||
deque<unsigned char> m_slaves;
|
deque<unsigned char> m_slaves;
|
||||||
|
|
||||||
|
/** the @a ostringstream for building the scan result of a single slave. */
|
||||||
|
ostringstream m_scanResult;
|
||||||
|
|
||||||
/** the @a BusHandler instance to notify of final scan result. */
|
/** the @a BusHandler instance to notify of final scan result. */
|
||||||
BusHandler* m_busHandler;
|
BusHandler* m_busHandler;
|
||||||
|
|
||||||
@@ -360,12 +363,12 @@ public:
|
|||||||
result_t startScan(bool full=false);
|
result_t startScan(bool full=false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a scan result @a string for a scanned slave address.
|
* Set the scan result @a string for a scanned slave address.
|
||||||
* @param dstAddress the scanned slave address.
|
* @param dstAddress the scanned slave address.
|
||||||
* @param str the scan result @a string to add.
|
* @param str the scan result @a string to set.
|
||||||
* @param result the scan result code.
|
* @param result the scan result code.
|
||||||
*/
|
*/
|
||||||
void addScanResult(unsigned char dstAddress, string str, result_t result);
|
void setScanResult(unsigned char dstAddress, string str, result_t result);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format the scan result to the @a ostringstream.
|
* Format the scan result to the @a ostringstream.
|
||||||
|
|||||||
Reference in New Issue
Block a user