Compare commits

...

2 Commits

2 changed files with 44 additions and 7 deletions

@ -21,7 +21,12 @@ void T_com::writeToSerial(const QByteArray &data, uint16_t sendLength)
sendBuffer=data;
sendLen=sendLength;
if (readCmds.size() == 0) { // no other read command active
// logic: exactly one command is sent to DC. no other command can be sent
// until the respond has been read from the serial line.
static int errorCnt = 0;
if (readCmds.size() == 0) { // no other read command active: ok
if (CatSerial->isOpen())
{
if (CatSerial->error() != QSerialPort::NoError) {
@ -53,14 +58,32 @@ void T_com::writeToSerial(const QByteArray &data, uint16_t sendLength)
return;
}
}
readCmds.append(data.constData()[2]);
// save last command sent.
readCmds.append(data.constData()[2]); // 2: index of the last command
} else {
qCritical() << __func__ << ":" << __LINE__
<< "ERROR sending" << data.toHex(':') << "port is not open";
}
} else {
qCritical() << __func__ << "" << __LINE__ << "ERROR detected active read cmd" << readCmds[0];
readCmds.clear();
qCritical() << __func__ << "" << __LINE__ << "ERROR detected active read cmd" << readCmds[0];
if (CatSerial->isOpen()) {
int availableBytes = CatSerial->bytesAvailable();
qCritical() << __func__ << "" << __LINE__ << "ERROR available bytes" << availableBytes;
if (availableBytes == 0) {
errorCnt += 1;
if (errorCnt > 100) {
readCmds.clear();
errorCnt = 0;
}
} else {
errorCnt = 0;
}
} else {
qCritical() << __func__ << ":" << __LINE__
<< "ERROR sending" << data.toHex(':') << "port is not open";
}
}
}

@ -551,26 +551,40 @@ char T_datif::loadRecDataFromFrame()
if (myDCIF && myDCIF->getSerialPort()) {
QVector<uint16_t> &readCmds = myDCIF->getSerialPort()->getReadCmds();
if (readCmds.size() == 1) {
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) {
if (readCmds[0] == CMD2DC_TestSerial) {
if (QString(QByteArray((char const *)receivedData, RdDleng)) == "< SlaveResponse") {
waitForTestResponse = false;
((hwapi *)parent())->dc_autoRequest(true);
qCritical() << __func__ << ":" << __LINE__ << "turn on auto-request";
((hwapi *)parent())->dc_autoRequest(true); // return autorequest to true
} else {
qCritical() << __func__ << ":" << __LINE__ << "received wrong test-response"
<< QString(QByteArray((char const *)receivedData, RdDleng));
}
}
} else {
// usual handling of response
}
readCmds.clear();
} else {
} else { // error
qCritical() << __func__ << ":" << __LINE__ << ":" << readSource << myDCIF->getReadSource() << readCmds[0];
qCritical() << __func__ << ":" << __LINE__ << ":" << QByteArray((char const *)receivedData, RdDleng).toHex(':');
readCmds.clear();
return 0;
}
} 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__ << "turn off auto-request";
qCritical() << __func__ << ":" << __LINE__ << "send request for test-response";
waitForTestResponse = true;
((hwapi *)parent())->dc_autoRequest(false);
((hwapi *)parent())->dc_requTestResponse();