Compare commits
2 Commits
8714071a30
...
proposal_s
Author | SHA1 | Date | |
---|---|---|---|
fbe53ea845 | |||
bab771cece |
@@ -7,7 +7,6 @@
|
||||
//#include <QString>
|
||||
#include <QTimer>
|
||||
#include <QSerialPort>
|
||||
#include <QVector>
|
||||
#include "tslib.h"
|
||||
#include "controlBus.h"
|
||||
#include "interfaces.h"
|
||||
@@ -33,8 +32,6 @@ class T_com : public QObject //, public QPlainTextEdit
|
||||
// QSerialPort *CatSerial = nullptr;
|
||||
QSerialPort *CatSerial;
|
||||
|
||||
uint32_t writeCount = 0;
|
||||
|
||||
//char oeffneSerialPort();
|
||||
char open_Serial_Port();
|
||||
void closeSerialPort();
|
||||
@@ -64,8 +61,6 @@ public:
|
||||
bool readFromSerial(QByteArray &data, uint16_t &sendLength);
|
||||
// retval: true: data available
|
||||
|
||||
uint32_t getWriteCount() { return writeCount; }
|
||||
|
||||
/*
|
||||
uint8_t getAllPortPins(void);
|
||||
// rs232pins: all signals bitwise coded in one byte:
|
||||
|
@@ -168,9 +168,6 @@ class T_datif : public QObject
|
||||
QTimer *datif_trigger;
|
||||
uint8_t selectedSlaveAddr;
|
||||
|
||||
bool waitForTestResponse = false;
|
||||
uint32_t readCount = 0;
|
||||
|
||||
private slots:
|
||||
char datif_cycleSend();
|
||||
void StoredRecData();
|
||||
|
@@ -121,8 +121,13 @@ public:
|
||||
explicit hwapi(QObject *parent = nullptr);
|
||||
|
||||
|
||||
|
||||
#ifdef THIS_IS_CA_MASTER
|
||||
T_datif *myDatif;
|
||||
#else // THIS_IS_CA_SLAVE
|
||||
QString getVersions();
|
||||
void resetVersions();
|
||||
bool m_resetVersions = false;
|
||||
#endif
|
||||
|
||||
T_runProc *runProcess;
|
||||
@@ -1401,6 +1406,8 @@ public:
|
||||
|
||||
|
||||
signals:
|
||||
void hwapi_restoredVersions();
|
||||
|
||||
void hwapi_reportDCDownloadStatus(QString const&) const override;
|
||||
void hwapi_reportDCDownloadSuccess(QString const&) const override;
|
||||
void hwapi_reportDCDownloadFailure(QString const&) const override;
|
||||
|
@@ -122,9 +122,6 @@ 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);
|
||||
|
54
src/com.cpp
54
src/com.cpp
@@ -1,6 +1,5 @@
|
||||
#include "com.h"
|
||||
#include <QDebug>
|
||||
#include <QDateTime>
|
||||
//#include "controlBus.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -21,53 +20,13 @@ 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.
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -123,7 +82,6 @@ T_com::T_com(QObject *parent) : QObject(parent)
|
||||
ChkConnectTimer->setSingleShot(false);
|
||||
ChkConnectTimer->start(100); // in ms
|
||||
com_want2read=0;
|
||||
writeCount = 0;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -6,12 +6,10 @@ History:
|
||||
|
||||
*/
|
||||
#include "datIf.h"
|
||||
#include "hwapi.h"
|
||||
#include "sendWRcmd.h"
|
||||
#include "controlBus.h"
|
||||
#include "storeINdata.h"
|
||||
#include <QDebug>
|
||||
#include <QDateTime>
|
||||
#include <datei.h>
|
||||
#include <QDir>
|
||||
|
||||
@@ -126,7 +124,6 @@ T_datif::T_datif(QObject *parent) : QObject(parent)
|
||||
datif_pNextCmd=0;
|
||||
datif_sendSlowCmd=0;
|
||||
|
||||
readCount = 0;
|
||||
}
|
||||
|
||||
void T_datif::resetChain(void)
|
||||
@@ -516,8 +513,6 @@ 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
|
||||
|
||||
@@ -550,30 +545,6 @@ char T_datif::loadRecDataFromFrame()
|
||||
|
||||
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;
|
||||
//qDebug() << "\n datif: got valid data, rdsrc:" << readSource << " rdadd:" << readAddress
|
||||
// << " rdlen:" << RdDleng;
|
||||
|
@@ -11,6 +11,7 @@
|
||||
#include "hwapi.h"
|
||||
#include "download_thread.h"
|
||||
#include "reporting_thread.h"
|
||||
#include "storeINdata.h" // epi_loadSWVer, epi_loadHWVer
|
||||
|
||||
#include <cstring>
|
||||
#include <QThread>
|
||||
@@ -25,6 +26,37 @@ static uint8_t hwapi_lastDoorState;
|
||||
static uint8_t bl_startupStep;
|
||||
|
||||
|
||||
#ifdef THIS_IS_CA_MASTER
|
||||
#else // THIS_IS_CA_SLAVE
|
||||
QString hwapi::getVersions() {
|
||||
if (m_sharedMem != nullptr) {
|
||||
// check if sw/hw-versions have been restored (see resetVersions()).
|
||||
// emit a signal in such a case.
|
||||
QString const &sw = epi_loadSWver(); // command 11
|
||||
QString const &hw = epi_loadHWver(); // command 12
|
||||
if (!sw.isEmpty() && !hw.isEmpty() && m_resetVersions) {
|
||||
emit hwapi_restoredVersions();
|
||||
return sw + " " + hw;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void hwapi::resetVersions() {
|
||||
if (m_sharedMem != nullptr) {
|
||||
// command 11 and 12 are included in the requests sent automatically,
|
||||
// first 11, then 12. The results are used to refresh corresponding
|
||||
// shared memory locations.
|
||||
// set these locations to the empty string in the opposite order as
|
||||
// the commands are sent.
|
||||
// purpose: only when both locations are not empty again, we can be
|
||||
// sure that data are not obsolete.
|
||||
gpi_storeHWver(""); // command 12
|
||||
gpi_storeSWver(""); // command 11
|
||||
m_resetVersions = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
hwapi::hwapi(QObject *parent) : QObject(parent)
|
||||
{
|
||||
@@ -56,7 +88,7 @@ hwapi::hwapi(QObject *parent) : QObject(parent)
|
||||
#error "SLAVE LIB COMPILED INTO MASTER"
|
||||
#endif
|
||||
|
||||
myDatif = new T_datif(this); // für die CAslave-Lib auskommentieren!
|
||||
myDatif = new T_datif(); // für die CAslave-Lib auskommentieren!
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -368,9 +368,6 @@ 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++)
|
||||
|
@@ -6,6 +6,11 @@
|
||||
#include "shared_mem_buffer.h"
|
||||
#include "datei.h"
|
||||
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
|
||||
static QMutex SWHD_mutex;
|
||||
|
||||
// gpi: grafical access to PI: access from external devices over device controller FOR GUI
|
||||
// epi: external access from GUI to PI: FOR external devices (DC)
|
||||
|
||||
@@ -64,6 +69,7 @@ bool indat_isMdbOn()
|
||||
|
||||
void gpi_storeHWver(QString text)
|
||||
{
|
||||
QMutexLocker locker(&SWHD_mutex);
|
||||
// change Qstring to array of chars, because shared mem allowes no QString!
|
||||
int nn, LL = text.length();
|
||||
if (LL >= versionBufferLen)
|
||||
@@ -79,6 +85,7 @@ void gpi_storeHWver(QString text)
|
||||
|
||||
QString epi_loadHWver(void)
|
||||
{
|
||||
QMutexLocker locker(&SWHD_mutex);
|
||||
// load array of chars from SM and change to QString
|
||||
int nn, LL = versionBufferLen;
|
||||
char cc;
|
||||
@@ -96,6 +103,7 @@ QString epi_loadHWver(void)
|
||||
|
||||
void gpi_storeSWver(QString text)
|
||||
{
|
||||
QMutexLocker locker(&SWHD_mutex);
|
||||
int nn, LL = text.length();
|
||||
if (LL >= versionBufferLen)
|
||||
LL=versionBufferLen-1; // leave place for termination
|
||||
@@ -111,6 +119,7 @@ void gpi_storeSWver(QString text)
|
||||
|
||||
QString epi_loadSWver(void)
|
||||
{
|
||||
QMutexLocker locker(&SWHD_mutex);
|
||||
int nn, LL = versionBufferLen;
|
||||
char cc;
|
||||
QString myStr;
|
||||
|
Reference in New Issue
Block a user