Compare commits
14 Commits
1.99.5
...
209132054f
Author | SHA1 | Date | |
---|---|---|---|
209132054f | |||
0f7ab3c71c | |||
2b2cd25276 | |||
08bb513c7b | |||
36a8f07069 | |||
900b0ef952 | |||
26a11e6c56 | |||
6321f9068f | |||
9daa5e17cb | |||
de61de85f1
|
|||
4e58fbe4e1
|
|||
647dc9fe4b
|
|||
433af98de7
|
|||
492d30aaf0
|
@@ -114,7 +114,7 @@ void CArun::chainControl(void)
|
||||
case SETUP_STEP::OPEN_SERIAL_PORT:
|
||||
qCritical() << "CArun: SETUP_STEP::OPEN_SERIAL_PORT";
|
||||
this->openSerialPort();
|
||||
this->setupStep = SETUP_STEP::CHECK_VALID_DATA;
|
||||
this->setupStep = SETUP_STEP::TEST_OPEN_PORT;
|
||||
this->timerChainCtrl->start();
|
||||
break;
|
||||
case SETUP_STEP::TEST_OPEN_PORT:
|
||||
@@ -151,7 +151,7 @@ void CArun::chainControl(void)
|
||||
|
||||
this->HWaccess->dc_autoRequest(1);
|
||||
this->setupStep = SETUP_STEP::CHECK_VALID_DATA;
|
||||
this->timerChainCtrl->start();
|
||||
this->timerChainCtrl->start(2000);
|
||||
break;
|
||||
case SETUP_STEP::CHECK_VALID_DATA:
|
||||
qCritical() << "CArun: SETUP_STEP::CHECK_VALID_DATA";
|
||||
|
@@ -7,6 +7,7 @@
|
||||
//#include <QString>
|
||||
#include <QTimer>
|
||||
#include <QSerialPort>
|
||||
#include <QVector>
|
||||
#include "tslib.h"
|
||||
#include "controlBus.h"
|
||||
#include "interfaces.h"
|
||||
@@ -32,6 +33,10 @@ class T_com : public QObject //, public QPlainTextEdit
|
||||
// QSerialPort *CatSerial = nullptr;
|
||||
QSerialPort *CatSerial;
|
||||
|
||||
QVector<uint16_t> readCmds; // list of active commands sent to DC
|
||||
|
||||
|
||||
|
||||
//char oeffneSerialPort();
|
||||
char open_Serial_Port();
|
||||
void closeSerialPort();
|
||||
@@ -61,6 +66,9 @@ public:
|
||||
bool readFromSerial(QByteArray &data, uint16_t &sendLength);
|
||||
// retval: true: data available
|
||||
|
||||
QVector<uint16_t> &getReadCmds() { return readCmds; }
|
||||
QVector<uint16_t> const &getReadCmds() const { return readCmds; }
|
||||
|
||||
/*
|
||||
uint8_t getAllPortPins(void);
|
||||
// rs232pins: all signals bitwise coded in one byte:
|
||||
|
@@ -161,11 +161,15 @@ class T_datif : public QObject
|
||||
// blockNr=transmitted in WRITEADDRESS low byte
|
||||
|
||||
int datif_noResponseCtr;
|
||||
int datif_nowNewDyns;
|
||||
int datif_nowNewStats;
|
||||
|
||||
T_prot *myDCIF;
|
||||
QTimer *datif_trigger;
|
||||
uint8_t selectedSlaveAddr;
|
||||
|
||||
bool waitForTestResponse = false;
|
||||
|
||||
private slots:
|
||||
char datif_cycleSend();
|
||||
void StoredRecData();
|
||||
|
@@ -122,6 +122,9 @@ public:
|
||||
uint8_t *RdDlen, uint8_t *receivedData);
|
||||
// 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:
|
||||
void framerecieved(); //bool gotINdata);
|
||||
|
70
src/com.cpp
70
src/com.cpp
@@ -20,13 +20,71 @@ void T_com::writeToSerial(const QByteArray &data, uint16_t sendLength)
|
||||
{
|
||||
sendBuffer=data;
|
||||
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.
|
||||
|
||||
static int errorCnt = 0;
|
||||
|
||||
if (readCmds.size() == 0) { // no other read command active: ok
|
||||
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";
|
||||
}
|
||||
|
||||
QByteArray buffer(data);
|
||||
|
||||
int bytesToWrite = buffer.size();
|
||||
while (bytesToWrite > 0 && !buffer.isEmpty()) {
|
||||
int bytesWritten = CatSerial->write(buffer);
|
||||
if (bytesWritten != -1 && CatSerial->waitForBytesWritten(1000)) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// 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];
|
||||
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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -6,6 +6,7 @@ History:
|
||||
|
||||
*/
|
||||
#include "datIf.h"
|
||||
#include "hwapi.h"
|
||||
#include "sendWRcmd.h"
|
||||
#include "controlBus.h"
|
||||
#include "storeINdata.h"
|
||||
@@ -91,6 +92,8 @@ T_datif::T_datif(QObject *parent) : QObject(parent)
|
||||
epi_resetDcDataValid(1); // data are not yet valid, no response from DC by now
|
||||
|
||||
datif_noResponseCtr=0;
|
||||
datif_nowNewDyns=0;
|
||||
datif_nowNewStats=0;
|
||||
|
||||
datif_repeatCtr=0;
|
||||
datif_cmdWasPerformed=0; // 0: no response by now
|
||||
@@ -151,13 +154,24 @@ char T_datif::datif_cycleSend()
|
||||
{
|
||||
//qDebug() << "com port not available"; // wird ununterbrochen ausgegeben
|
||||
epi_resetDcDataValid(2); // DC data not valid
|
||||
datif_nowNewDyns=0;
|
||||
datif_nowNewStats=0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// supervise if DC data are valid
|
||||
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!
|
||||
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
|
||||
if (gpi_wantToResetSupervision())
|
||||
@@ -360,6 +374,9 @@ char T_datif::datif_cycleSend()
|
||||
{
|
||||
dif_scanStep=0; // always start from beginning
|
||||
epi_resetDcDataValid(4);
|
||||
datif_nowNewDyns=0;
|
||||
datif_nowNewStats=0;
|
||||
|
||||
}
|
||||
|
||||
datif_cmdWasPerformed=0; // 0: no response by now
|
||||
@@ -384,7 +401,7 @@ char T_datif::sendINrequestsAutomatic(void)
|
||||
uint8_t datif_maxNrCommands=35, datif_sendNow;
|
||||
|
||||
// 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;
|
||||
|
||||
// special commands:
|
||||
@@ -497,6 +514,8 @@ char T_datif::loadRecDataFromFrame()
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(receivedData, 0x00, sizeof(receivedData));
|
||||
|
||||
ret=myDCIF->getReceivedInData(&SlaveAdr, &readSource, &readAddress, &RdDleng, receivedData);
|
||||
// nur true wenn CommandState OK und readState OK
|
||||
|
||||
@@ -529,6 +548,51 @@ char T_datif::loadRecDataFromFrame()
|
||||
|
||||
gpi_storeRecPayLoad(RdDleng, receivedData); // save for host (user of hwapi)
|
||||
|
||||
if (myDCIF && myDCIF->getSerialPort()) {
|
||||
QVector<uint16_t> &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) {
|
||||
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__ << "received wrong test-response"
|
||||
<< QString(QByteArray((char const *)receivedData, RdDleng));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// usual handling of response
|
||||
}
|
||||
readCmds.clear();
|
||||
} 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();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// uint8_t nn;
|
||||
//qDebug() << "\n datif: got valid data, rdsrc:" << readSource << " rdadd:" << readAddress
|
||||
// << " rdlen:" << RdDleng;
|
||||
@@ -996,18 +1060,24 @@ char T_datif::loadRecDataFromFrame()
|
||||
uit2=uchar2uint(receivedData[7],receivedData[6]); // value of last coin
|
||||
//if (uitmp>0) // nur 1x bei neuer Münze 6.10.23 aendern:
|
||||
// beim Wechsler hat die kleinste Muenze immer coin type 0!
|
||||
|
||||
if (uitmp>10000 || uit2>10000)
|
||||
{
|
||||
uitmp=0;
|
||||
uit2=0;
|
||||
}
|
||||
if ((newInsertedAmount != lastInsertedAmount) || uit2>0 )
|
||||
{
|
||||
gpi_storeCurrentPayment(newInsertedAmount, uitmp, uit2);
|
||||
emit datif_gotNewCoin(); // OR BILL if (uitmp & 0x8000)>0
|
||||
//qDebug()<<"emit new coin";
|
||||
lastInsertedAmount=newInsertedAmount;
|
||||
//qCritical()<<"datif 112 store and emit new coin "<<newInsertedAmount<<" "<<uitmp<<" "<<uit2;
|
||||
|
||||
if (uit2==3 || uit2==5 || uit2==10 || uit2==20 || uit2==50 || uit2==100 || uit2==200 || uit2==500)
|
||||
{
|
||||
// valid coin
|
||||
if ((newInsertedAmount != lastInsertedAmount) || uit2>0 )
|
||||
{
|
||||
gpi_storeCurrentPayment(newInsertedAmount, uitmp, uit2);
|
||||
emit datif_gotNewCoin(); // OR BILL if (uitmp & 0x8000)>0
|
||||
//qDebug()<<"emit new coin";
|
||||
lastInsertedAmount=newInsertedAmount;
|
||||
//qCritical()<<"datif 112 store and emit new coin "<<newInsertedAmount<<" "<<uitmp<<" "<<uit2;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -1035,6 +1105,7 @@ char T_datif::loadRecDataFromFrame()
|
||||
if (RdDleng>28)
|
||||
{
|
||||
gpi_storeDeviceConditions(RdDleng, receivedData);
|
||||
datif_nowNewStats=1; // 24.7.24 new
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1043,9 +1114,9 @@ char T_datif::loadRecDataFromFrame()
|
||||
|
||||
if (RdDleng>60)
|
||||
{
|
||||
epi_setDcDataValid(); // DC-Data are valid as DC responded.
|
||||
// Could be set to every response but this (31)
|
||||
// is a very common and very important request
|
||||
//epi_setDcDataValid(); // 24.7.24 remove here
|
||||
datif_nowNewDyns=1; // 24.7.24 new
|
||||
|
||||
gpi_storeDynMachineConditions(RdDleng, receivedData);
|
||||
|
||||
gpi_storeDI_CoinAttach(receivedData[6]); // new, 14.2.24 needed for direct coin insertion
|
||||
|
@@ -56,7 +56,7 @@ hwapi::hwapi(QObject *parent) : QObject(parent)
|
||||
#error "SLAVE LIB COMPILED INTO MASTER"
|
||||
#endif
|
||||
|
||||
myDatif = new T_datif(); // für die CAslave-Lib auskommentieren!
|
||||
myDatif = new T_datif(this); // für die CAslave-Lib auskommentieren!
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -368,6 +368,9 @@ uint8_t recBuffer[FRAME_MAXLEN];
|
||||
// read from "VCP":
|
||||
mySerialPort->readFromSerial(Indata, recLength);
|
||||
//qDebug()<<"prot: got data " << recLength;
|
||||
|
||||
memset(recBuffer, 0x00, sizeof(recBuffer));
|
||||
|
||||
if (recLength>FRAME_MAXLEN)
|
||||
recLength=FRAME_MAXLEN;
|
||||
for (int nn=0; nn<recLength; nn++)
|
||||
|
Reference in New Issue
Block a user