diff --git a/src/ebusd/busloop.cpp b/src/ebusd/busloop.cpp index f0f333fb..f4484787 100644 --- a/src/ebusd/busloop.cpp +++ b/src/ebusd/busloop.cpp @@ -307,38 +307,56 @@ void BusLoop::collectCycData(const int numRecv) void BusLoop::analyseCycData() { - //TODO check the input data for validity + int lenMaster = m_sstr[4]; + SymbolString master; - static bool skipfirst = false; + for (int i = 0; i < 5+lenMaster; i++) + master.push_back(m_sstr[i], true , true); - if (skipfirst == true) { - L.log(cyc, trace, "%s", m_sstr.getDataStr().c_str()); - - int index = m_commands->storeCycData(m_sstr.getDataStr()); - - if (index == -1) { - L.log(cyc, debug, " command not found"); - } - else if (index == -2) { - L.log(cyc, debug, " no commands defined"); - } - else if (index == -3) { - L.log(cyc, debug, " search skipped - string too short"); - } - else { - string tmp; - tmp += (*m_commands)[index][1]; - tmp += " "; - tmp += (*m_commands)[index][2]; - L.log(cyc, event, " cycle [%4d] %s", index, tmp.c_str()); - } - - // collect Slave address - if (index != -3) - collectSlave(); + if (m_sstr[5+lenMaster] != master.getCRC()) { + L.log(cyc, trace, "ERR_CYC_CRC_M %s - %02x %02x", master.getDataStr().c_str(), m_sstr[5+lenMaster], master.getCRC()); + return; } - else - skipfirst = true; + + if (m_sstr[1] != BROADCAST || isMaster(m_sstr[1]) == false) { + int lenSlave = m_sstr[5+lenMaster+2]; + SymbolString slave; + + for (int i = 5+lenMaster+2; i < 5+lenMaster+3+lenSlave; i++) + slave.push_back(m_sstr[i], true , true); + + if (m_sstr[5+lenMaster+3+lenSlave] != slave.getCRC()) { + L.log(cyc, trace, "ERR_CYC_CRC_S %s - %02x %02x", slave.getDataStr().c_str(), m_sstr[5+lenMaster+3+lenSlave], slave.getCRC()); + return; + } + } + + + L.log(cyc, trace, "%s", m_sstr.getDataStr().c_str()); + + int index = m_commands->storeCycData(m_sstr.getDataStr()); + + if (index == -1) { + L.log(cyc, debug, " command not found"); + } + else if (index == -2) { + L.log(cyc, debug, " no commands defined"); + } + else if (index == -3) { + L.log(cyc, debug, " search skipped - string too short"); + } + else { + string tmp; + tmp += (*m_commands)[index][1]; + tmp += " "; + tmp += (*m_commands)[index][2]; + L.log(cyc, event, " cycle [%4d] %s", index, tmp.c_str()); + } + + // collect Slave address + if (index != -3) + collectSlave(); + } void BusLoop::collectSlave()