Compare commits

...

20 Commits

Author SHA1 Message Date
8714071a30 loadRecDataFromFrame():
When reading next message, check readCount + 1 == writeCount. If not, there
	must be something wrong: ignore this message and set readCount <- writeCount.
2024-10-16 13:06:07 +02:00
87bc5b5c1e writeToSerial():
Always write next message. Set writeCount. Clear() serial line before sending.
	Flush() serial line after sending.
2024-10-16 13:03:20 +02:00
ff746a45bc Use readCount to track number of read messages. 2024-10-16 13:02:27 +02:00
d540f1b467 Use writeCount instaed of readCmds. 2024-10-16 13:01:41 +02:00
ca2d9e1b5a Minor: added debug output in error case 2024-10-15 12:45:38 +02:00
4c770349bf removed waitForBytesWritten() 2024-10-15 12:44:56 +02:00
209132054f Added sanity check if there is a command active but no data can be read on the serial line 2024-10-15 10:51:20 +02:00
0f7ab3c71c Minor: adding comments 2024-10-15 10:49:30 +02:00
2b2cd25276 Minor: add waitForTestResponse 2024-10-15 10:08:49 +02:00
08bb513c7b Minor: set recBuf to a definite value 2024-10-15 10:08:11 +02:00
36a8f07069 Pass "this" as parent 2024-10-15 10:07:29 +02:00
900b0ef952 loadRecDataFromFrame():
Read last message if only one command to device controller is active.
	Otherwise assume that the data is obsolete. Trigger the sending
	of a known test-response to find new valid data-stream.
2024-10-15 10:04:40 +02:00
26a11e6c56 writeToSerial():
Only write to serial interface if no current command has been
	sent to DC already.
2024-10-15 10:00:34 +02:00
6321f9068f Add helpers getReadSource() getSerialPort(). 2024-10-15 09:57:49 +02:00
9daa5e17cb Introduce a vector of commands currently sent to device controller. 2024-10-15 09:54:09 +02:00
de61de85f1 Merge branch 'fix_validDataIssue' 2024-09-26 13:26:19 +02:00
4e58fbe4e1 Add plausibility check for inserted coins 2024-09-26 11:48:39 +02:00
647dc9fe4b Handle: valid data problem while start with coin attached:
Enable command 30 also during sell
2024-09-26 11:45:10 +02:00
433af98de7 Fix: setupStep sequence 2024-07-25 15:34:47 +02:00
492d30aaf0 Fix: T.S.: set DCdataValid 2024-07-24 17:33:38 +02:00
8 changed files with 131 additions and 21 deletions

View File

@@ -114,7 +114,7 @@ void CArun::chainControl(void)
case SETUP_STEP::OPEN_SERIAL_PORT: case SETUP_STEP::OPEN_SERIAL_PORT:
qCritical() << "CArun: SETUP_STEP::OPEN_SERIAL_PORT"; qCritical() << "CArun: SETUP_STEP::OPEN_SERIAL_PORT";
this->openSerialPort(); this->openSerialPort();
this->setupStep = SETUP_STEP::CHECK_VALID_DATA; this->setupStep = SETUP_STEP::TEST_OPEN_PORT;
this->timerChainCtrl->start(); this->timerChainCtrl->start();
break; break;
case SETUP_STEP::TEST_OPEN_PORT: case SETUP_STEP::TEST_OPEN_PORT:
@@ -151,7 +151,7 @@ void CArun::chainControl(void)
this->HWaccess->dc_autoRequest(1); this->HWaccess->dc_autoRequest(1);
this->setupStep = SETUP_STEP::CHECK_VALID_DATA; this->setupStep = SETUP_STEP::CHECK_VALID_DATA;
this->timerChainCtrl->start(); this->timerChainCtrl->start(2000);
break; break;
case SETUP_STEP::CHECK_VALID_DATA: case SETUP_STEP::CHECK_VALID_DATA:
qCritical() << "CArun: SETUP_STEP::CHECK_VALID_DATA"; qCritical() << "CArun: SETUP_STEP::CHECK_VALID_DATA";

View File

@@ -7,6 +7,7 @@
//#include <QString> //#include <QString>
#include <QTimer> #include <QTimer>
#include <QSerialPort> #include <QSerialPort>
#include <QVector>
#include "tslib.h" #include "tslib.h"
#include "controlBus.h" #include "controlBus.h"
#include "interfaces.h" #include "interfaces.h"
@@ -32,6 +33,8 @@ class T_com : public QObject //, public QPlainTextEdit
// QSerialPort *CatSerial = nullptr; // QSerialPort *CatSerial = nullptr;
QSerialPort *CatSerial; QSerialPort *CatSerial;
uint32_t writeCount = 0;
//char oeffneSerialPort(); //char oeffneSerialPort();
char open_Serial_Port(); char open_Serial_Port();
void closeSerialPort(); void closeSerialPort();
@@ -61,6 +64,8 @@ public:
bool readFromSerial(QByteArray &data, uint16_t &sendLength); bool readFromSerial(QByteArray &data, uint16_t &sendLength);
// retval: true: data available // retval: true: data available
uint32_t getWriteCount() { return writeCount; }
/* /*
uint8_t getAllPortPins(void); uint8_t getAllPortPins(void);
// rs232pins: all signals bitwise coded in one byte: // rs232pins: all signals bitwise coded in one byte:

View File

@@ -161,11 +161,16 @@ class T_datif : public QObject
// blockNr=transmitted in WRITEADDRESS low byte // blockNr=transmitted in WRITEADDRESS low byte
int datif_noResponseCtr; int datif_noResponseCtr;
int datif_nowNewDyns;
int datif_nowNewStats;
T_prot *myDCIF; T_prot *myDCIF;
QTimer *datif_trigger; QTimer *datif_trigger;
uint8_t selectedSlaveAddr; uint8_t selectedSlaveAddr;
bool waitForTestResponse = false;
uint32_t readCount = 0;
private slots: private slots:
char datif_cycleSend(); char datif_cycleSend();
void StoredRecData(); void StoredRecData();

View File

@@ -122,6 +122,9 @@ public:
uint8_t *RdDlen, uint8_t *receivedData); uint8_t *RdDlen, uint8_t *receivedData);
// retval: data valid, only one time true // retval: data valid, only one time true
uint16_t getReadSource() { return readSource; } // readSource contains last command sent to device controller
T_com *getSerialPort() { return mySerialPort; } // utility function
signals: signals:
void framerecieved(); //bool gotINdata); void framerecieved(); //bool gotINdata);

View File

@@ -1,5 +1,6 @@
#include "com.h" #include "com.h"
#include <QDebug> #include <QDebug>
#include <QDateTime>
//#include "controlBus.h" //#include "controlBus.h"
////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////
@@ -20,13 +21,53 @@ void T_com::writeToSerial(const QByteArray &data, uint16_t sendLength)
{ {
sendBuffer=data; sendBuffer=data;
sendLen=sendLength; sendLen=sendLength;
if (CatSerial->isOpen())
{
//qDebug() << "sending..." << sendBuffer;
CatSerial->write(sendBuffer);
} else
qDebug() << "error sending, port is not open";
// logic: exactly one command is sent to DC. no other command can be sent
// until the respond has been read from the serial line.
if (CatSerial->isOpen()) {
if (CatSerial->error() != QSerialPort::NoError) {
qCritical() << __func__ << "" << __LINE__ << "ERROR on serial line" << CatSerial->errorString();
CatSerial->clearError();
qCritical() << __func__ << "" << __LINE__ << "cleared error on serial line";
}
if (!CatSerial->atEnd()) {
qCritical() << QString("ERROR %1 bytes available on serial line before write").arg(CatSerial->bytesAvailable());
qCritical() << CatSerial->readAll().toHex(':');
CatSerial->clear();
qCritical() << __func__ << "" << __LINE__ << "read all data from serial line";
}
CatSerial->clear();
QByteArray buffer(data);
int bytesToWrite = buffer.size();
while (bytesToWrite > 0 && !buffer.isEmpty()) {
int bytesWritten = CatSerial->write(buffer);
if (bytesWritten != -1) {
bytesToWrite -= bytesWritten;
buffer = buffer.right(bytesWritten);
} else {
qCritical() << __func__ << ":" << __LINE__
<< QString("ERROR %1 for sending %2").arg(CatSerial->errorString()).arg(data.toHex(':').constData());
CatSerial->clearError();
qCritical() << __func__ << ":" << __LINE__ << "cleared error on serial line. returning ...";
return;
}
}
CatSerial->flush();
writeCount += 1;
// only for debugging
// qCritical() << __func__ << ":" << __LINE__ << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
// << "write cmd" << (unsigned int)data.constData()[2];
} else {
qCritical() << __func__ << ":" << __LINE__
<< "ERROR sending" << data.toHex(':') << "port is not open";
}
} }
@@ -82,6 +123,7 @@ T_com::T_com(QObject *parent) : QObject(parent)
ChkConnectTimer->setSingleShot(false); ChkConnectTimer->setSingleShot(false);
ChkConnectTimer->start(100); // in ms ChkConnectTimer->start(100); // in ms
com_want2read=0; com_want2read=0;
writeCount = 0;
} }

View File

@@ -6,10 +6,12 @@ History:
*/ */
#include "datIf.h" #include "datIf.h"
#include "hwapi.h"
#include "sendWRcmd.h" #include "sendWRcmd.h"
#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>
@@ -91,6 +93,8 @@ T_datif::T_datif(QObject *parent) : QObject(parent)
epi_resetDcDataValid(1); // data are not yet valid, no response from DC by now epi_resetDcDataValid(1); // data are not yet valid, no response from DC by now
datif_noResponseCtr=0; datif_noResponseCtr=0;
datif_nowNewDyns=0;
datif_nowNewStats=0;
datif_repeatCtr=0; datif_repeatCtr=0;
datif_cmdWasPerformed=0; // 0: no response by now datif_cmdWasPerformed=0; // 0: no response by now
@@ -122,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)
@@ -151,13 +156,24 @@ char T_datif::datif_cycleSend()
{ {
//qDebug() << "com port not available"; // wird ununterbrochen ausgegeben //qDebug() << "com port not available"; // wird ununterbrochen ausgegeben
epi_resetDcDataValid(2); // DC data not valid epi_resetDcDataValid(2); // DC data not valid
datif_nowNewDyns=0;
datif_nowNewStats=0;
return 0; return 0;
} }
// supervise if DC data are valid // supervise if DC data are valid
datif_noResponseCtr++; // inc every 20ms datif_noResponseCtr++; // inc every 20ms
if (datif_noResponseCtr>250) // no life sign from device controller (DC) for about 3s if (datif_noResponseCtr>50) // no life sign from device controller (DC) for about a sec
{
epi_resetDcDataValid(3); // DC data has not updated for >=5s -> no longer valid! epi_resetDcDataValid(3); // DC data has not updated for >=5s -> no longer valid!
datif_nowNewDyns=0;
datif_nowNewStats=0;
}
// 24.7.24 new, data are valid if dynamic machine conditions AND dyn machine states came in
if (datif_nowNewDyns && datif_nowNewStats && !epi_areDcDataValid() )
epi_setDcDataValid();
// Ueberwachung ob ein oder mehrere Commands am Stueck erfolgreich waren // Ueberwachung ob ein oder mehrere Commands am Stueck erfolgreich waren
if (gpi_wantToResetSupervision()) if (gpi_wantToResetSupervision())
@@ -360,6 +376,9 @@ char T_datif::datif_cycleSend()
{ {
dif_scanStep=0; // always start from beginning dif_scanStep=0; // always start from beginning
epi_resetDcDataValid(4); epi_resetDcDataValid(4);
datif_nowNewDyns=0;
datif_nowNewStats=0;
} }
datif_cmdWasPerformed=0; // 0: no response by now datif_cmdWasPerformed=0; // 0: no response by now
@@ -384,7 +403,7 @@ char T_datif::sendINrequestsAutomatic(void)
uint8_t datif_maxNrCommands=35, datif_sendNow; uint8_t datif_maxNrCommands=35, datif_sendNow;
// send quicker while transaction is ongoing: // send quicker while transaction is ongoing:
uint8_t datif_vendRequCommandList[15]={102,107,108,110,112,115,116,31,32,40,41,42,23,0,0}; uint8_t datif_vendRequCommandList[15]={102,107,108,110,112,115,116,30,31,32,40,41,42,23,0};
uint8_t datif_maxVendingCmds=13; uint8_t datif_maxVendingCmds=13;
// special commands: // special commands:
@@ -497,6 +516,8 @@ char T_datif::loadRecDataFromFrame()
return 0; return 0;
} }
memset(receivedData, 0x00, sizeof(receivedData));
ret=myDCIF->getReceivedInData(&SlaveAdr, &readSource, &readAddress, &RdDleng, receivedData); ret=myDCIF->getReceivedInData(&SlaveAdr, &readSource, &readAddress, &RdDleng, receivedData);
// nur true wenn CommandState OK und readState OK // nur true wenn CommandState OK und readState OK
@@ -529,6 +550,30 @@ 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()) {
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(':');
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 {
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;
}
}
// uint8_t nn; // uint8_t nn;
//qDebug() << "\n datif: got valid data, rdsrc:" << readSource << " rdadd:" << readAddress //qDebug() << "\n datif: got valid data, rdsrc:" << readSource << " rdadd:" << readAddress
// << " rdlen:" << RdDleng; // << " rdlen:" << RdDleng;
@@ -996,11 +1041,16 @@ char T_datif::loadRecDataFromFrame()
uit2=uchar2uint(receivedData[7],receivedData[6]); // value of last coin uit2=uchar2uint(receivedData[7],receivedData[6]); // value of last coin
//if (uitmp>0) // nur 1x bei neuer Münze 6.10.23 aendern: //if (uitmp>0) // nur 1x bei neuer Münze 6.10.23 aendern:
// beim Wechsler hat die kleinste Muenze immer coin type 0! // beim Wechsler hat die kleinste Muenze immer coin type 0!
if (uitmp>10000 || uit2>10000) if (uitmp>10000 || uit2>10000)
{ {
uitmp=0; uitmp=0;
uit2=0; uit2=0;
} }
if (uit2==3 || uit2==5 || uit2==10 || uit2==20 || uit2==50 || uit2==100 || uit2==200 || uit2==500)
{
// valid coin
if ((newInsertedAmount != lastInsertedAmount) || uit2>0 ) if ((newInsertedAmount != lastInsertedAmount) || uit2>0 )
{ {
gpi_storeCurrentPayment(newInsertedAmount, uitmp, uit2); gpi_storeCurrentPayment(newInsertedAmount, uitmp, uit2);
@@ -1009,6 +1059,7 @@ char T_datif::loadRecDataFromFrame()
lastInsertedAmount=newInsertedAmount; lastInsertedAmount=newInsertedAmount;
//qCritical()<<"datif 112 store and emit new coin "<<newInsertedAmount<<" "<<uitmp<<" "<<uit2; //qCritical()<<"datif 112 store and emit new coin "<<newInsertedAmount<<" "<<uitmp<<" "<<uit2;
} }
}
break; break;
@@ -1035,6 +1086,7 @@ char T_datif::loadRecDataFromFrame()
if (RdDleng>28) if (RdDleng>28)
{ {
gpi_storeDeviceConditions(RdDleng, receivedData); gpi_storeDeviceConditions(RdDleng, receivedData);
datif_nowNewStats=1; // 24.7.24 new
} }
break; break;
@@ -1043,9 +1095,9 @@ char T_datif::loadRecDataFromFrame()
if (RdDleng>60) if (RdDleng>60)
{ {
epi_setDcDataValid(); // DC-Data are valid as DC responded. //epi_setDcDataValid(); // 24.7.24 remove here
// Could be set to every response but this (31) datif_nowNewDyns=1; // 24.7.24 new
// is a very common and very important request
gpi_storeDynMachineConditions(RdDleng, receivedData); gpi_storeDynMachineConditions(RdDleng, receivedData);
gpi_storeDI_CoinAttach(receivedData[6]); // new, 14.2.24 needed for direct coin insertion gpi_storeDI_CoinAttach(receivedData[6]); // new, 14.2.24 needed for direct coin insertion

View File

@@ -56,7 +56,7 @@ hwapi::hwapi(QObject *parent) : QObject(parent)
#error "SLAVE LIB COMPILED INTO MASTER" #error "SLAVE LIB COMPILED INTO MASTER"
#endif #endif
myDatif = new T_datif(); // für die CAslave-Lib auskommentieren! myDatif = new T_datif(this); // für die CAslave-Lib auskommentieren!
#endif #endif

View File

@@ -368,6 +368,9 @@ uint8_t recBuffer[FRAME_MAXLEN];
// read from "VCP": // read from "VCP":
mySerialPort->readFromSerial(Indata, recLength); mySerialPort->readFromSerial(Indata, recLength);
//qDebug()<<"prot: got data " << recLength; //qDebug()<<"prot: got data " << recLength;
memset(recBuffer, 0x00, sizeof(recBuffer));
if (recLength>FRAME_MAXLEN) if (recLength>FRAME_MAXLEN)
recLength=FRAME_MAXLEN; recLength=FRAME_MAXLEN;
for (int nn=0; nn<recLength; nn++) for (int nn=0; nn<recLength; nn++)