From 8714071a30f0f224d3282e8b118647b933c95fbd Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Wed, 16 Oct 2024 13:06:07 +0200 Subject: [PATCH] loadRecDataFromFrame(): When reading next message, check readCount + 1 == writeCount. If not, there must be something wrong: ignore this message and set readCount <- writeCount. --- src/datIf.cpp | 57 +++++++++++++++------------------------------------ 1 file changed, 17 insertions(+), 40 deletions(-) diff --git a/src/datIf.cpp b/src/datIf.cpp index 9ef3efa..0b470da 100755 --- a/src/datIf.cpp +++ b/src/datIf.cpp @@ -11,6 +11,7 @@ History: #include "controlBus.h" #include "storeINdata.h" #include +#include #include #include @@ -125,6 +126,7 @@ T_datif::T_datif(QObject *parent) : QObject(parent) datif_pNextCmd=0; datif_sendSlowCmd=0; + readCount = 0; } void T_datif::resetChain(void) @@ -549,50 +551,25 @@ char T_datif::loadRecDataFromFrame() gpi_storeRecPayLoad(RdDleng, receivedData); // save for host (user of hwapi) if (myDCIF && myDCIF->getSerialPort()) { - QVector &readCmds = myDCIF->getSerialPort()->getReadCmds(); - - if (readCmds.size() == 1) { // there can be only one command been sent to the DC - // the command number active at the moment must be the same as the saved one - if (readSource == myDCIF->getReadSource() && readSource == readCmds[0]) { - // maybe we have sent a explicit request for a test-response - if (waitForTestResponse) { - qCritical() << __func__ << ":" << __LINE__ << "turn on auto-request"; - if (readCmds[0] == CMD2DC_TestSerial) { - if (QString(QByteArray((char const *)receivedData, RdDleng)) == "< SlaveResponse") { - waitForTestResponse = false; - qCritical() << __func__ << ":" << __LINE__ << "turn on auto-request"; - ((hwapi *)parent())->dc_autoRequest(true); // return autorequest to true - } else { - qCritical() << __func__ << ":" << __LINE__ << "ERROR received wrong test-response" - << QString(QByteArray((char const *)receivedData, RdDleng)); - } - } - } else { - // usual handling of response - // qCritical() << __func__ << ":" << __LINE__ << ":" << readSource << myDCIF->getReadSource() << readCmds[0]; - // qCritical() << __func__ << ":" << __LINE__ << ":" << QByteArray((char const *)receivedData, RdDleng).toHex(':'); - } - readCmds.clear(); - } else { // error - qCritical() << __func__ << ":" << __LINE__ << ": ERROR " << readSource << myDCIF->getReadSource() << readCmds[0]; - qCritical() << __func__ << ":" << __LINE__ << ": ERROR length" << RdDleng << QString(", ignore data for cmd 0x%1").arg(readCmds[0], 0, 16) + uint32_t writeCount = myDCIF->getSerialPort()->getWriteCount(); + if ((readCount + 1) == writeCount) { // there can be only one command sent to the DC + readCount = writeCount; + if (readSource != myDCIF->getReadSource()) { + qCritical() << __func__ << ":" << __LINE__ << ": ERROR length" << RdDleng << ", ignore data" << QByteArray((char const *)receivedData, RdDleng).toHex(':'); - readCmds.clear(); + qCritical() << __func__ << ":" << __LINE__ << "would be interpretated as" << readSource << myDCIF->getReadSource(); return 0; + } else { + // only for debugging + // qCritical() << __func__ << ":" << __LINE__ << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) << readSource << myDCIF->getReadSource(); } } else { - // error: read commands has not size 1 as it should be: turn off - // auto requests and send explicit request for test-response: - // once this response has been received, turn on the autmatic requests - // again. - readCmds.clear(); - if (parent()) { - qCritical() << __func__ << ":" << __LINE__ << "ERROR turn off auto-request"; - qCritical() << __func__ << ":" << __LINE__ << "ERROR send request for test-response"; - waitForTestResponse = true; - ((hwapi *)parent())->dc_autoRequest(false); - ((hwapi *)parent())->dc_requTestResponse(); - } + qCritical() << __func__ << ":" << __LINE__ << QString(": ERROR readCount + 1 != writeCount: %1 != %2").arg(readCount + 1).arg(writeCount); + qCritical() << __func__ << ":" << __LINE__ << ": ERROR length" << RdDleng << ", ignore data" + << QByteArray((char const *)receivedData, RdDleng).toHex(':'); + qCritical() << __func__ << ":" << __LINE__ << "would be interpretated as" << readSource << myDCIF->getReadSource(); + + readCount = writeCount; return 0; } }