loadRecDataFromFrame():

When reading next message, check readCount + 1 == writeCount. If not, there
	must be something wrong: ignore this message and set readCount <- writeCount.
This commit is contained in:
Gerhard Hoffmann 2024-10-16 13:06:07 +02:00
parent 87bc5b5c1e
commit 8714071a30

View File

@ -11,6 +11,7 @@ History:
#include "controlBus.h" #include "controlBus.h"
#include "storeINdata.h" #include "storeINdata.h"
#include <QDebug> #include <QDebug>
#include <QDateTime>
#include <datei.h> #include <datei.h>
#include <QDir> #include <QDir>
@ -125,6 +126,7 @@ T_datif::T_datif(QObject *parent) : QObject(parent)
datif_pNextCmd=0; datif_pNextCmd=0;
datif_sendSlowCmd=0; datif_sendSlowCmd=0;
readCount = 0;
} }
void T_datif::resetChain(void) void T_datif::resetChain(void)
@ -549,50 +551,25 @@ char T_datif::loadRecDataFromFrame()
gpi_storeRecPayLoad(RdDleng, receivedData); // save for host (user of hwapi) gpi_storeRecPayLoad(RdDleng, receivedData); // save for host (user of hwapi)
if (myDCIF && myDCIF->getSerialPort()) { if (myDCIF && myDCIF->getSerialPort()) {
QVector<uint16_t> &readCmds = myDCIF->getSerialPort()->getReadCmds(); uint32_t writeCount = myDCIF->getSerialPort()->getWriteCount();
if ((readCount + 1) == writeCount) { // there can be only one command sent to the DC
if (readCmds.size() == 1) { // there can be only one command been sent to the DC readCount = writeCount;
// the command number active at the moment must be the same as the saved one if (readSource != myDCIF->getReadSource()) {
if (readSource == myDCIF->getReadSource() && readSource == readCmds[0]) { qCritical() << __func__ << ":" << __LINE__ << ": ERROR length" << RdDleng << ", ignore data"
// 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)
<< QByteArray((char const *)receivedData, RdDleng).toHex(':'); << QByteArray((char const *)receivedData, RdDleng).toHex(':');
readCmds.clear(); qCritical() << __func__ << ":" << __LINE__ << "would be interpretated as" << readSource << myDCIF->getReadSource();
return 0; return 0;
} else {
// only for debugging
// qCritical() << __func__ << ":" << __LINE__ << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) << readSource << myDCIF->getReadSource();
} }
} else { } else {
// error: read commands has not size 1 as it should be: turn off qCritical() << __func__ << ":" << __LINE__ << QString(": ERROR readCount + 1 != writeCount: %1 != %2").arg(readCount + 1).arg(writeCount);
// auto requests and send explicit request for test-response: qCritical() << __func__ << ":" << __LINE__ << ": ERROR length" << RdDleng << ", ignore data"
// once this response has been received, turn on the autmatic requests << QByteArray((char const *)receivedData, RdDleng).toHex(':');
// again. qCritical() << __func__ << ":" << __LINE__ << "would be interpretated as" << readSource << myDCIF->getReadSource();
readCmds.clear();
if (parent()) { readCount = writeCount;
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();
}
return 0; return 0;
} }
} }