Compare commits
No commits in common. "209132054f94d56b9521b620a38b42036cd6863e" and "2b2cd252767204335659a1cb0aa26994b023930e" have entirely different histories.
209132054f
...
2b2cd25276
27
src/com.cpp
27
src/com.cpp
@ -21,12 +21,7 @@ void T_com::writeToSerial(const QByteArray &data, uint16_t sendLength)
|
|||||||
sendBuffer=data;
|
sendBuffer=data;
|
||||||
sendLen=sendLength;
|
sendLen=sendLength;
|
||||||
|
|
||||||
// logic: exactly one command is sent to DC. no other command can be sent
|
if (readCmds.size() == 0) { // no other read command active
|
||||||
// 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->isOpen())
|
||||||
{
|
{
|
||||||
if (CatSerial->error() != QSerialPort::NoError) {
|
if (CatSerial->error() != QSerialPort::NoError) {
|
||||||
@ -58,32 +53,14 @@ void T_com::writeToSerial(const QByteArray &data, uint16_t sendLength)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
readCmds.append(data.constData()[2]);
|
||||||
// save last command sent.
|
|
||||||
readCmds.append(data.constData()[2]); // 2: index of the last command
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
qCritical() << __func__ << ":" << __LINE__
|
qCritical() << __func__ << ":" << __LINE__
|
||||||
<< "ERROR sending" << data.toHex(':') << "port is not open";
|
<< "ERROR sending" << data.toHex(':') << "port is not open";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qCritical() << __func__ << "" << __LINE__ << "ERROR detected active read cmd" << readCmds[0];
|
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();
|
readCmds.clear();
|
||||||
errorCnt = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
errorCnt = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
qCritical() << __func__ << ":" << __LINE__
|
|
||||||
<< "ERROR sending" << data.toHex(':') << "port is not open";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -551,40 +551,26 @@ char T_datif::loadRecDataFromFrame()
|
|||||||
if (myDCIF && myDCIF->getSerialPort()) {
|
if (myDCIF && myDCIF->getSerialPort()) {
|
||||||
QVector<uint16_t> &readCmds = myDCIF->getSerialPort()->getReadCmds();
|
QVector<uint16_t> &readCmds = myDCIF->getSerialPort()->getReadCmds();
|
||||||
|
|
||||||
if (readCmds.size() == 1) { // there can be only one command been sent to the DC
|
if (readCmds.size() == 1) {
|
||||||
// the command number active at the moment must be the same as the saved one
|
|
||||||
if (readSource == myDCIF->getReadSource() && readSource == readCmds[0]) {
|
if (readSource == myDCIF->getReadSource() && readSource == readCmds[0]) {
|
||||||
// maybe we have sent a explicit request for a test-response
|
|
||||||
if (waitForTestResponse) {
|
if (waitForTestResponse) {
|
||||||
if (readCmds[0] == CMD2DC_TestSerial) {
|
if (readCmds[0] == CMD2DC_TestSerial) {
|
||||||
if (QString(QByteArray((char const *)receivedData, RdDleng)) == "< SlaveResponse") {
|
if (QString(QByteArray((char const *)receivedData, RdDleng)) == "< SlaveResponse") {
|
||||||
waitForTestResponse = false;
|
waitForTestResponse = false;
|
||||||
qCritical() << __func__ << ":" << __LINE__ << "turn on auto-request";
|
((hwapi *)parent())->dc_autoRequest(true);
|
||||||
((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();
|
readCmds.clear();
|
||||||
} else { // error
|
} else {
|
||||||
qCritical() << __func__ << ":" << __LINE__ << ":" << readSource << myDCIF->getReadSource() << readCmds[0];
|
qCritical() << __func__ << ":" << __LINE__ << ":" << readSource << myDCIF->getReadSource() << readCmds[0];
|
||||||
qCritical() << __func__ << ":" << __LINE__ << ":" << QByteArray((char const *)receivedData, RdDleng).toHex(':');
|
qCritical() << __func__ << ":" << __LINE__ << ":" << QByteArray((char const *)receivedData, RdDleng).toHex(':');
|
||||||
readCmds.clear();
|
readCmds.clear();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else {
|
} 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();
|
readCmds.clear();
|
||||||
if (parent()) {
|
if (parent()) {
|
||||||
qCritical() << __func__ << ":" << __LINE__ << "turn off auto-request";
|
|
||||||
qCritical() << __func__ << ":" << __LINE__ << "send request for test-response";
|
|
||||||
waitForTestResponse = true;
|
waitForTestResponse = true;
|
||||||
((hwapi *)parent())->dc_autoRequest(false);
|
((hwapi *)parent())->dc_autoRequest(false);
|
||||||
((hwapi *)parent())->dc_requTestResponse();
|
((hwapi *)parent())->dc_requTestResponse();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user