unexpected syn is now an error, simplified, log self-update requests specially

This commit is contained in:
john30
2015-02-15 18:36:14 +01:00
parent 1f422e0685
commit 2e92b15ec5
4 changed files with 26 additions and 27 deletions
+21 -23
View File
@@ -145,7 +145,7 @@ bool ActiveBusRequest::notify(result_t result, SymbolString& slave)
result_t BusHandler::sendAndWait(SymbolString& master, SymbolString& slave)
{
result_t result = RESULT_SYN;
result_t result = RESULT_ERR_NO_SIGNAL;
ActiveBusRequest request(master, slave);
for (int sendRetries=m_failedSendRetries+1; sendRetries>=0; sendRetries--) {
@@ -322,7 +322,8 @@ result_t BusHandler::handleSymbol()
m_remainLockCount--;
else if (sending == false && m_remainLockCount == 0 && m_command.size() == 1)
m_remainLockCount = 1; // wait for next AUTO-SYN after SYN / address / SYN (bus locked for own priority)
return setState(bs_ready, RESULT_SYN);
return setState(bs_ready, RESULT_ERR_SYN);
}
unsigned char headerLen, crcPos;
@@ -425,13 +426,9 @@ result_t BusHandler::handleSymbol()
return setState(bs_recvCmd, RESULT_ERR_NAK);
}
if (m_currentRequest != NULL)
return setState(bs_skip, RESULT_ERR_NAK);
return setState(bs_skip, RESULT_ERR_NAK);
}
if (m_currentRequest != NULL)
return setState(bs_skip, RESULT_ERR_ACK);
return setState(bs_skip, RESULT_ERR_ACK);
@@ -439,12 +436,9 @@ result_t BusHandler::handleSymbol()
headerLen = 0;
crcPos = m_response.size() > headerLen ? headerLen + 1 + m_response[headerLen] : 0xff;
result = m_response.push_back(recvSymbol, true, m_response.size() < crcPos);
if (result < RESULT_OK) {
if (m_currentRequest != NULL)
return setState(bs_skip, result);
if (result < RESULT_OK)
return setState(bs_skip, result);
}
if (result == RESULT_OK && crcPos != 0xff && m_response.size() == crcPos + 1) { // CRC received
m_responseCrcValid = m_response[headerLen + 1 + m_response[headerLen]] == m_response.getCRC();
if (m_responseCrcValid) {
@@ -665,7 +659,15 @@ void BusHandler::receiveCompleted()
}
Message* message = m_messages->find(m_command);
if (message != NULL) {
if (message == NULL) {
if (dstAddress == BROADCAST)
logNotice(lf_update, "unknown BC cmd: %s", m_command.getDataStr().c_str());
else if (master == true)
logNotice(lf_update, "unknown MM cmd: %s", m_command.getDataStr().c_str());
else
logNotice(lf_update, "unknown MS cmd: %s / %s", m_command.getDataStr().c_str(), m_response.getDataStr().c_str());
}
else {
string clazz = message->getClass();
string name = message->getName();
ostringstream output;
@@ -674,25 +676,21 @@ void BusHandler::receiveCompleted()
logError(lf_update, "unable to parse %s %s from %s / %s: %s", clazz.c_str(), name.c_str(), m_command.getDataStr().c_str(), m_response.getDataStr().c_str(), getResultCode(result));
else {
string data = output.str();
if (message->getDstAddress() == SYN) { // any destination
if (m_answer == true && dstAddress == (master ? m_ownMasterAddress : m_ownSlaveAddress)) {
logNotice(lf_update, "self-update %s %s QQ=%2.2x: %s", clazz.c_str(), name.c_str(), srcAddress, data.c_str()); // TODO store in database of internal variables
}
else if (message->getDstAddress() == SYN) { // any destination
if (message->getSrcAddress() == SYN) // any destination and any source
logNotice(lf_update, "update %s %s QQ=%2.2x ZZ=%2.2x: %s", clazz.c_str(), name.c_str(), srcAddress, dstAddress, data.c_str());
else
logNotice(lf_update, "update %s %s ZZ=%2.2x: %s", clazz.c_str(), name.c_str(), dstAddress, data.c_str());
} else if (message->getSrcAddress() == SYN) // any source
logNotice(lf_update, "update %s %s QQ=%2.2x: %s", clazz.c_str(), name.c_str(), srcAddress, data.c_str());
}
else if (message->getSrcAddress() == SYN) // any source
logNotice(lf_update, "update %s %s from QQ=%2.2x: %s", clazz.c_str(), name.c_str(), srcAddress, data.c_str());
else
logNotice(lf_update, "update %s %s: %s", clazz.c_str(), name.c_str(), data.c_str());
}
}
else {
if (dstAddress == BROADCAST)
logNotice(lf_update, "unknown BC cmd: %s", m_command.getDataStr().c_str());
else if (master == true)
logNotice(lf_update, "unknown MM cmd: %s", m_command.getDataStr().c_str());
else
logNotice(lf_update, "unknown MS cmd: %s / %s", m_command.getDataStr().c_str(), m_response.getDataStr().c_str());
}
}
result_t BusHandler::startScan(bool full)
+1 -1
View File
@@ -220,7 +220,7 @@ public:
* @param slave reference to @a SymbolString for filling in the received slave data.
*/
ActiveBusRequest(SymbolString& master, SymbolString& slave)
: BusRequest(master, false), m_result(RESULT_SYN), m_slave(slave) {}
: BusRequest(master, false), m_result(RESULT_ERR_NO_SIGNAL), m_slave(slave) {}
/**
* Destructor.
+2 -1
View File
@@ -26,7 +26,6 @@ const char* getResultCode(result_t resultCode) {
switch (resultCode) {
case RESULT_OK: return "done";
case RESULT_IN_ESC: return "escape sequence received";
case RESULT_SYN: return "SYN received";
case RESULT_EMPTY: return "empty";
case RESULT_ERR_GENERIC_IO: return "ERR: generic I/O error";
case RESULT_ERR_DEVICE: return "ERR: generic device error";
@@ -49,6 +48,8 @@ const char* getResultCode(result_t resultCode) {
case RESULT_ERR_ACK: return "ERR: ACK error";
case RESULT_ERR_NAK: return "ERR: NAK received";
case RESULT_ERR_NO_SIGNAL: return "ERR: no signal";
case RESULT_ERR_SYN: return "ERR: SYN received";
default:
if (resultCode >= 0)
return "done: unknown result code";
+2 -2
View File
@@ -25,8 +25,7 @@
static const int RESULT_OK = 0; //!< success
static const int RESULT_IN_ESC = 1; //!< start of escape sequence received
static const int RESULT_SYN = 2; //!< regular SYN after message received
static const int RESULT_EMPTY = 3; //!< empty result
static const int RESULT_EMPTY = 2; //!< empty result
static const int RESULT_ERR_GENERIC_IO = -1; //!< generic I/O error (usually fatal)
static const int RESULT_ERR_DEVICE = -2; //!< generic device error (usually fatal)
@@ -52,6 +51,7 @@ static const int RESULT_ERR_ACK = -19; //!< ACK error
static const int RESULT_ERR_NAK = -20; //!< NAK received
static const int RESULT_ERR_NO_SIGNAL = -21; //!< no signal found on the bus
static const int RESULT_ERR_SYN = -22; //!< SYN received instead of answer
/** type for result code. */
typedef int result_t;