Compare commits

..

12 Commits

20 changed files with 471 additions and 595 deletions

View File

@@ -33,8 +33,6 @@ QMAKE_CXXFLAGS += -C
QMAKE_CXXFLAGS += -O2 -O QMAKE_CXXFLAGS += -O2 -O
QMAKE_CXXFLAGS += -g QMAKE_CXXFLAGS += -g
QMAKE_CXXFLAGS += -Wno-deprecated-copy QMAKE_CXXFLAGS += -Wno-deprecated-copy
# QMAKE_CXXFLAGS += -fsanitize=address
# QMAKE_CXXFLAGS += -fno-omit-frame-pointer
QMAKE_LFLAGS += -Wl,-e,main QMAKE_LFLAGS += -Wl,-e,main
@@ -92,7 +90,9 @@ HEADERS += \
$${PWD}/include/sendWRcmd.h \ $${PWD}/include/sendWRcmd.h \
$${PWD}/include/storeINdata.h \ $${PWD}/include/storeINdata.h \
$${PWD}/include/tslib.h \ $${PWD}/include/tslib.h \
$${PWD}/include/shared_mem_buffer.h $${PWD}/include/shared_mem_buffer.h \
$${PWD}/include/reporting_thread.h \
$${PWD}/include/download_thread.h
SOURCES += \ SOURCES += \
$${PWD}/src/datei.cpp \ $${PWD}/src/datei.cpp \
@@ -103,7 +103,9 @@ SOURCES += \
$${PWD}/src/sendWRcmd.cpp \ $${PWD}/src/sendWRcmd.cpp \
$${PWD}/src/storeINdata.cpp \ $${PWD}/src/storeINdata.cpp \
$${PWD}/src/tslib.cpp \ $${PWD}/src/tslib.cpp \
$${PWD}/src/shared_mem_buffer.cpp $${PWD}/src/shared_mem_buffer.cpp \
$${PWD}/src/reporting_thread.cpp \
$${PWD}/src/download_thread.cpp
# INTERFACE = DeviceController # INTERFACE = DeviceController

199
dCArun/CArun.cpp Normal file
View File

@@ -0,0 +1,199 @@
#include "CArun.h"
#include "datei.h"
#define UPDATE_PERIOD_MS 100
// period to call chain steps
#define VENDINGTIMEOUT_MS 30000
CArun::CArun(QObject *parent)
: QObject{parent}
{
loadPlugIn(1);
timerChainCtrl = new QTimer(this);
connect(timerChainCtrl, SIGNAL(timeout()), this, SLOT(chainControl()));
timerChainCtrl->setSingleShot(0);
timerChainCtrl->start(UPDATE_PERIOD_MS); // 1000: call every 1000ms
}
char CArun::loadPlugIn(char lade1_entlade2)
{
plugInDir.cd("plugins");
QPluginLoader *pluginLoader = new QPluginLoader();
pluginLoader->setFileName("/usr/lib/libCAmaster.so"); // for ptu5
if (lade1_entlade2==2)
{
pluginLoader->unload();
return 0;
}
if (!pluginLoader->load())
{
qDebug()<<"cannot load plugin";
} else
qDebug() <<"loaded plugin: " << pluginLoader->fileName();
if (!pluginLoader->isLoaded())
{
qDebug()<<pluginLoader->errorString();
return 0;
}
QObject *plugin = pluginLoader->instance();
if ( plugin == nullptr)
{
// make instance of the root component (which can hold more then one clases)
// also loads the lib if not yet done
qDebug()<<"cannot start instance";
return 0;
}
HWaccess= qobject_cast<hwinf *>(plugin);
// make instance to class "hwinf" in dll_HWapi.h over "interfaces.h"
qDebug()<<"loadPlugIn, HWAccess: " << HWaccess;
return 0;
}
void CArun::chainControl(void)
{
#define FILENAME_COMPORT "../comport.csv" // TODO: use absolute path
// use settings (ini-file)
QString bs, cn;
int br, ci;
// load and use last settings: --------------------
QByteArray myBA;
myBA=datei_readFromFile(FILENAME_COMPORT);
if (myBA.length()>0)
{
bs=csv_getEntryAsString(myBA,0); // read the 's' war 2!??
br=csv_getEntryAsInt(myBA,1); // z.B. 5 (5.Eintrag in der Baud-Liste)
bs=csv_getEntryAsString(myBA,2); // z.B 115200
cn=csv_getEntryAsString(myBA,3); // z.B. COM9
ci=csv_getEntryAsInt(myBA,4); // Eintragsnummer in COM-Fenster
HWaccess->dc_openSerial(br,bs,cn,1);
} else
{
// vermutlich wird dies hier ausgeführt, weil eine csv-Datei wird nicht installiert
// open with default settings
qDebug()<<"CArunGui: open serial with default values";
bs="115200";
br=5;
//cn="COM14"; // Windows
cn="ttymxc2"; // PTU5
ci=2;
HWaccess->dc_openSerial(br,bs,cn,1);
}
// TIMER myTO: hat keinen timeout-slot!
// wird nur verwendet, um isActive() abzufragen, d.h. ~x zu warten
// pruefen, of Port nach x s open:
if (HWaccess->dc_isPortOpen())
{
} else
{
// wenn nicht: step 6
}
myTO->start(100);
}
} else
if (myStep==2)
{
if (!myTO->isActive())
{
HWaccess->dc_requTestResponse();
myStep++;
myTO->start(100);
}
} else
if (myStep==3)
{
if (!myTO->isActive())
{
if (HWaccess->dc_readAnswTestResponse())
myStep++; // response was correct
else
{
myStep=6; // 13.12.23: start Autoconnect cycle
qDebug()<<"CArunGui: got no answer from DC, retry..";
}
myTO->start(100);
}
} else
if (myStep==4)
{
HWaccess->dc_autoRequest(1);
AutSendButton->setChecked(true); // taste "druecken"
myStep++;
myTO->start(2000);
} else
if (myStep==5)
{
if (!myTO->isActive())
{
if (HWaccess->sys_areDCdataValid())
{
qDebug()<<"CArunGui: DC is connected";
myStep=7; // OK, connection is up and running
} else
{
qDebug()<<"CArunGui: auto request is not running, retry...";
myStep++;
myTO->start(100);
}
}
} else
if (myStep==6)
{
// restart autoconnect cycle
myTO->start(100); // restart
myStep=0;
} else
if (myStep==7)
{
// stay here, DC connection is up and running
} else
{
}
if (myNextStep)
{
*nextScreen=myNextStep;
myNextStep=0;
}
return false;
}

42
dCArun/CArun.h Normal file
View File

@@ -0,0 +1,42 @@
#ifndef CARUN_H
#define CARUN_H
#include <QObject>
#include <QTimer>
#include <QDebug>
#include <QDateTime>
#include <QPluginLoader>
#include <QDir>
#include "plugin.h"
#include "stepList.h"
//#include "stepList.h" // define all working chain steps here
class CArun : public QObject
{
Q_OBJECT
public:
explicit CArun(QObject *parent = nullptr);
QTimer *timerChainCtrl;
QTimer *timerVendingTimeout;
char loadPlugIn(char lade1_entlade2);
QDir plugInDir;
private:
hwinf *HWaccess=nullptr; // global pointer to plugin-class
signals:
void chainControl();
void vendingTimeout();
};
#endif // CARUN_H

View File

@@ -41,6 +41,7 @@ DEFINES+=APP_BUILD_TIME=\\\"$$BUILD_TIME\\\"
DEFINES+=APP_EXTENDED_VERSION=\\\"$$EXTENDED_VERSION\\\" DEFINES+=APP_EXTENDED_VERSION=\\\"$$EXTENDED_VERSION\\\"
SOURCES += \ SOURCES += \
CArun.cpp \
main.cpp \ main.cpp \
mainwindow.cpp \ mainwindow.cpp \
tslib.cpp \ tslib.cpp \
@@ -48,6 +49,7 @@ SOURCES += \
datei.cpp datei.cpp
HEADERS += \ HEADERS += \
CArun.h \
guidefs.h \ guidefs.h \
mainwindow.h \ mainwindow.h \
stepList.h \ stepList.h \

View File

@@ -1,15 +1,14 @@
#include "mainwindow.h" #include "CArun.h"
//#include "message_handler.h" //#include "message_handler.h"
#include <QApplication> #include <QCoreApplication>
int thisisglobal;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int ret; QCoreApplication myapp(argc, argv);
QApplication myapp(argc, argv);
QApplication::setApplicationName("CArunGui"); QCoreApplication::setOrganizationName("ATB");
QApplication::setApplicationVersion(APP_VERSION); QCoreApplication::setApplicationName("CArun");
QCoreApplication::setApplicationVersion(APP_VERSION);
/* /*
if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling
@@ -18,16 +17,9 @@ int main(int argc, char *argv[])
//setDebugLevel(QtMsgType::QtDebugMsg); //setDebugLevel(QtMsgType::QtDebugMsg);
} }
*/ */
MainWindow myMainWin; CArun carun;
QSize myMainSize={800, 480}; // breite, höhe, PTU: 800x440
myMainWin.setMinimumSize(myMainSize);
myMainWin.setMaximumSize(myMainSize);
myMainWin.setWindowTitle("CArun_V4.2 run cash agent master lib");
//myMainWin.show();
ret=myapp.exec(); return myapp.exec();
return ret;
} }

View File

@@ -134,8 +134,7 @@
class DownloadThread;
class hwinf;
class T_datif : public QObject class T_datif : public QObject
{ {
Q_OBJECT Q_OBJECT
@@ -166,14 +165,13 @@ class T_datif : public QObject
T_prot *myDCIF; T_prot *myDCIF;
QTimer *datif_trigger; QTimer *datif_trigger;
uint8_t selectedSlaveAddr; uint8_t selectedSlaveAddr;
hwinf *m_hw = nullptr;
private slots: private slots:
char datif_cycleSend(); char datif_cycleSend();
void StoredRecData(); void StoredRecData();
public: public:
T_datif(hwinf *hw, QObject *parent = nullptr); T_datif(QObject *parent = nullptr);
void resetChain(void); void resetChain(void);
char isPortOpen(void); char isPortOpen(void);

View File

@@ -93,13 +93,14 @@ private:
void sub_storeSendingText(QByteArray *buf) const; void sub_storeSendingText(QByteArray *buf) const;
QTimer *hwapi_TimerPayment; QTimer *hwapi_TimerPayment;
QSharedMemory *m_sharedMem; QSharedMemory *m_sharedMem;
ReportingThread *m_reportingThread = nullptr; ReportingThread *m_reportingThread;
DownloadThread *m_downloadThread = nullptr; DownloadThread *m_downloadThread;
//QTimer *hwapi_triggerBL; //QTimer *hwapi_triggerBL;
public: public:
explicit hwapi(QWidget *parent = nullptr); explicit hwapi(QWidget *parent = nullptr);
#ifdef THIS_IS_CA_MASTER #ifdef THIS_IS_CA_MASTER
T_datif *myDatif; T_datif *myDatif;
#endif #endif
@@ -1383,9 +1384,7 @@ signals:
void hwapi_doorCBinAndAllDoorsClosed(void) const override; void hwapi_doorCBinAndAllDoorsClosed(void) const override;
void hwapi_doorAllDoorsClosed(void) const override; void hwapi_doorAllDoorsClosed(void) const override;
void hwapi_coinAttached() const override;
private slots: private slots:
//void hwapi_slotPrintFinished_OK(void); //void hwapi_slotPrintFinished_OK(void);
@@ -1413,8 +1412,7 @@ signals:
void sub_slotCoin15(void); void sub_slotCoin15(void);
void sub_slotCoin16(void); void sub_slotCoin16(void);
void coinAttached();
}; };

View File

@@ -2390,6 +2390,7 @@ signals:
virtual void hwapi_doorCBinAndAllDoorsClosed(void) const=0; virtual void hwapi_doorCBinAndAllDoorsClosed(void) const=0;
virtual void hwapi_doorAllDoorsClosed(void) const=0; virtual void hwapi_doorAllDoorsClosed(void) const=0;
virtual void hwapi_coinAttached() const = 0;
// NOTE: declaring a "pure virtual" "signal" should be an error and thus not valid. // NOTE: declaring a "pure virtual" "signal" should be an error and thus not valid.
/* GH Version, bringt Fehler /* GH Version, bringt Fehler

View File

@@ -3,7 +3,6 @@
#include <QThread> #include <QThread>
#include <QString> #include <QString>
// #include <functional>
class hwapi; class hwapi;
class ReportingThread : public QThread { class ReportingThread : public QThread {
@@ -13,14 +12,6 @@ public:
ReportingThread(hwapi *hw); ReportingThread(hwapi *hw);
~ReportingThread(); ~ReportingThread();
//void setFunction(std::function<void(QString const&)> f) {
// m_f = f;
//}
//std::function<void(QString const&)> function() {
// return m_f;
//}
protected: protected:
// reporting thread does not have a running event queue, and therefore // reporting thread does not have a running event queue, and therefore
// no slots. signals work the usual way. // no slots. signals work the usual way.
@@ -29,7 +20,6 @@ protected:
private: private:
hwapi *m_hw; hwapi *m_hw;
QString m_fileToDownload; QString m_fileToDownload;
//std::function<void(QString const&)> m_f;
}; };
#endif // REPORTING_THREAD_H_INCLUDED #endif // REPORTING_THREAD_H_INCLUDED

View File

@@ -15,6 +15,7 @@
#include <QDebug> #include <QDebug>
#include "datIf.h" #include "datIf.h"
#include <QSharedMemory> #include <QSharedMemory>
#include <atomic>
#include "sendWRcmd.h" #include "sendWRcmd.h"
#include "controlBus.h" #include "controlBus.h"
#include "storeINdata.h" #include "storeINdata.h"
@@ -35,6 +36,10 @@ class T_runProc : public QObject
void restoreDeviceParameter(struct T_devices *deviceSettings); void restoreDeviceParameter(struct T_devices *deviceSettings);
#ifndef THIS_IS_CA_MASTER
std::atomic_bool m_coinAttached{false};
#endif
private slots: private slots:
void runProc_slotProcess(void); void runProc_slotProcess(void);
bool bl_performComplStart(void); bool bl_performComplStart(void);
@@ -80,6 +85,7 @@ signals:
void runProc_doorCBinAndAllDoorsClosed(void); void runProc_doorCBinAndAllDoorsClosed(void);
void runProc_doorAllDoorsClosed(void); void runProc_doorAllDoorsClosed(void);
void runProc_coinAttached();
}; };

View File

@@ -321,10 +321,6 @@ struct SharedMem
std::atomic_bool m_finished{false}; std::atomic_bool m_finished{false};
} m_downLoadDC; } m_downLoadDC;
// meta-data
char os_release[64];
char date_of_creation[32];
char creator[128]; // name of application plus pid
static QSharedMemory *getShm(std::size_t s = 0); static QSharedMemory *getShm(std::size_t s = 0);

View File

@@ -1,18 +1,16 @@
TEMPLATE = lib TEMPLATE = lib
TARGET = CAmaster TARGET = CAmaster
VERSION="1.0.2" VERSION="1.0.1"
HEADERS += \ HEADERS += \
../include/com.h \ ../include/com.h \
../include/datIf.h \ ../include/datIf.h \
../include/prot.h \ ../include/prot.h
../include/download_thread.h
SOURCES += \ SOURCES += \
../src/com.cpp \ ../src/com.cpp \
../src/datIf.cpp \ ../src/datIf.cpp \
../src/prot.cpp \ ../src/prot.cpp
../src/download_thread.cpp
include(../DCLibraries.pri) include(../DCLibraries.pri)

View File

@@ -1,12 +1,6 @@
TEMPLATE = lib TEMPLATE = lib
TARGET = CAslave TARGET = CAslave
VERSION="1.0.2" VERSION="1.0.1"
HEADERS += \
../include/reporting_thread.h
SOURCES += \
../src/reporting_thread.cpp
include(../DCLibraries.pri) include(../DCLibraries.pri)

View File

@@ -9,14 +9,10 @@ History:
#include "sendWRcmd.h" #include "sendWRcmd.h"
#include "controlBus.h" #include "controlBus.h"
#include "storeINdata.h" #include "storeINdata.h"
#include "download_thread.h"
#include <QDebug> #include <QDebug>
#include <datei.h> #include <datei.h>
#include <QDir> #include <QDir>
#include <QString>
#include <QDateTime>
@@ -58,10 +54,8 @@ static uint8_t datif_pNextCmd, datif_sendSlowCmd;
//#define DATIF_CTR_GOTRESPVAL 100 //#define DATIF_CTR_GOTRESPVAL 100
T_datif::T_datif(hwinf *hw, QObject *parent) : QObject(parent) T_datif::T_datif(QObject *parent) : QObject(parent)
{ {
m_hw = hw;
QByteArray myBA; QByteArray myBA;
QDir myDir("../dmd"); QDir myDir("../dmd");
@@ -176,22 +170,10 @@ char T_datif::datif_cycleSend()
// b) Antwort meldet Fehler -> 2x wiederholen (nach einer Luecke von 10ms ) // b) Antwort meldet Fehler -> 2x wiederholen (nach einer Luecke von 10ms )
// c) gar keine Antwort, Timeout nach 100ms -> 2x wiederholen (nach einer Luecke von 10ms ) // c) gar keine Antwort, Timeout nach 100ms -> 2x wiederholen (nach einer Luecke von 10ms )
// cycl_running=0: nichts zu tun 1: Mitteilung: Kommando wurde soeben abgesendet, 2,3,4 = Wiederholung // cycl_running=0: nichts zu tun 1: Mitteilung: Kommando wurde soeben abgesendet, 2,3,4 = Wiederholung
if (cycl_running == 0) {
if (m_hw) {
if (m_hw->dcDownloadRequested()) { // only happens in ca-master
qCritical() << "DOWNLOAD REQUESTED";
if (!m_hw->dcDownloadThreadStart()) {
qCritical() << "DOWNLOAD-THREAD NOT RUNNING WITHIN 1000ms";
} else {
qCritical() << "DOWNLOAD-THREAD RUNNING";
}
return 0;
}
}
} else {
// 21.9.23 doRepeat hier raus sonst gehts warten auch nicht mehr (BL)
// if (cycl_running && doRepeat)
if (cycl_running) // 21.9.23 doRepeat hier raus sonst gehts warten auch nicht mehr (BL)
// if (cycl_running && doRepeat)
{
// request is still running, wait for response before next sending // request is still running, wait for response before next sending
//qDebug()<< "datif wait for response"; //qDebug()<< "datif wait for response";
datif_trigger->stop(); datif_trigger->stop();

View File

@@ -104,121 +104,8 @@ void DownloadThread::run() {
m_hw->dcDownloadRequestAck(); m_hw->dcDownloadRequestAck();
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qCritical() << "DownloadThread::run(): DOWNLOAD THREAD STARTED";
<< "DownloadThread::run(): DOWNLOAD THREAD STARTED:";
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< " DownloadThread::run(): Filename:" << m_hw->dcDownloadFileName();
QDateTime const start = QDateTime::currentDateTime();
#if 1
QFile fn(m_hw->dcDownloadFileName());
if (!fn.exists()) {
// output via CONSOLE() etc
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< " DownloadThread::run(): Filename:" << m_hw->dcDownloadFileName() << "DOES NOT EXIST";;
} else {
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< "DownloadThread::run(): DC-CONTROLLER SW-VERSION BEFORE"
<< m_hw->dc_getSWversion();
// load binary device controller file into memory
QByteArray ba = loadBinaryDCFile(m_hw->dcDownloadFileName());
if (ba.size() > 0) {
uint16_t const totalBlocks = (((ba.size())%64)==0) ? (ba.size()/64) : (ba.size()/64)+1;
m_hw->dcDownloadSetTotalBlockNumber(totalBlocks);
// fill last block of data to be sent with 0xFF
ba = ba.leftJustified(totalBlocks*64, (char)(0xFF));
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< "DownloadThread::run(): TOTAL NUMBER OF BYTES TO SEND TO DC" << ba.size();
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< "DownloadThread::run(): TOTAL NUMBER OF BLOCKS" << totalBlocks;
m_hw->dc_autoRequest(true); // turn auto-request setting on
m_hw->request_DC2_HWversion();
m_hw->request_DC2_SWversion();
QThread::sleep(1);
// m_hw->dc_autoRequest(false); // turn auto-request setting on
resetDeviceController();
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< "DownloadThread::run(): RESET DEVICE-CONTROLLER";
if (startBootloader()) {
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< "DownloadThread::run(): STARTED BOOT-LOADER";
m_hw->dc_autoRequest(false);// turn auto-request setting off for
// download of binary dc
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< "DownloadThread::run(): TOTAL NUMBER OF FIRMWARE BLOCKS" << totalBlocks;
int currentBlock = 0; // download of binary dc
DownloadResult res = DownloadResult::OK;
while (res != DownloadResult::ERROR && currentBlock < totalBlocks) {
if ((res = sendNextAddress(currentBlock)) != DownloadResult::ERROR) {
if ((res = sendNextDataBlock(ba, currentBlock)) != DownloadResult::ERROR) {
m_hw->dcDownloadSetCurrentBlockNumber(currentBlock);
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< "DownloadThread::run(): currentBlockNumber ..." << currentBlock;
currentBlock += 1;
}
}
}
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< QString("DownloadThread::run(): last 64-byte block %1").arg(currentBlock);
int const rest = ba.size() % 64;
int const offset = ba.size() - rest;
char const *startAddress = ba.constData() + offset;
if (rest > 0) {
// SHOULD NEVER HAPPEN !!!
uint8_t local[66];
memset(local, 0xFF, sizeof(local));
memcpy(local, startAddress, rest);
qCritical() << "DownloadThread::run(): ERROR SEND REMAINING" << rest << "BYTES";
m_hw->bl_sendDataBlock(64, local);
} else {
m_hw->bl_sendLastBlock();
m_hw->dcDownloadSetCurrentBlockNumber(currentBlock);
qCritical() << "DownloadThread::run(): currentBlockNumber" << currentBlock;
// QThread::msleep(250);
}
qCritical() << "DownloadThread::run(): last result" << (int)sendStatus(m_hw->bl_wasSendingDataOK());
stopBootloader(); // stop bootloader several times: if it
QThread::sleep(1); // is not stopped, then the PSA has to be
}
// restarted manually (!!!)
stopBootloader();
QThread::sleep(1);
}
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< "DownloadThread::run(): STOPPED BOOT-LOADER";
stopBootloader(); // there is no harm in stopping the bootloader even
// if it was not started at all
m_hw->dc_autoRequest(true);
}
#else // test
// load binary device controller file into memory // load binary device controller file into memory
QByteArray ba = loadBinaryDCFile(m_hw->dcDownloadFileName()); QByteArray ba = loadBinaryDCFile(m_hw->dcDownloadFileName());
if (ba.size() > 0) { if (ba.size() > 0) {
@@ -228,59 +115,61 @@ void DownloadThread::run() {
// fill last block of data to be sent with 0xFF // fill last block of data to be sent with 0xFF
ba = ba.leftJustified(totalBlocks*64, (char)(0xFF)); ba = ba.leftJustified(totalBlocks*64, (char)(0xFF));
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< "DownloadThread::run(): TOTAL NUMBER OF BYTES TO SEND TO DC" << ba.size();
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< "DownloadThread::run(): TOTAL NUMBER OF BLOCKS" << totalBlocks;
m_hw->dc_autoRequest(true); // turn auto-request setting on
m_hw->request_DC2_HWversion();
m_hw->request_DC2_SWversion();
QThread::sleep(1);
resetDeviceController(); resetDeviceController();
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< "DownloadThread::run(): RESET DEVICE-CONTROLLER";
QThread::sleep(1);
if (startBootloader()) { if (startBootloader()) {
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< "DownloadThread::run(): STARTED BOOT-LOADER";
m_hw->dc_autoRequest(false);// turn auto-request setting off for qCritical() << "DownloadThread::run(): TOTAL NUMBER OF BYTES TO SEND TO DC" << ba.size();
// download of binary dc qCritical() << "DownloadThread::run(): TOTAL NUMBER OF BLOCKS" << totalBlocks;
for (uint16_t currentBlock = 0; currentBlock <= totalBlocks; ++currentBlock) {
m_hw->dcDownloadSetCurrentBlockNumber(currentBlock); int currentBlock = 0;
qCritical() << "DownloadThread::run(): currentBlockNumber" << currentBlock; DownloadResult res = DownloadResult::OK;
QThread::msleep(250); qCritical() << "64-byte block " << currentBlock;
while (res != DownloadResult::ERROR && currentBlock < totalBlocks) {
if ((res = sendNextAddress(currentBlock)) != DownloadResult::ERROR) {
if ((res = sendNextDataBlock(ba, currentBlock)) != DownloadResult::ERROR) {
m_hw->dcDownloadSetCurrentBlockNumber(currentBlock);
currentBlock += 1;
}
}
} }
m_hw->dc_autoRequest(true); // turn auto-request setting on again
}
qCritical() << "DownloadThread::run(): last 64-byte block %04d" << currentBlock;
int const rest = ba.size() % 64;
int const offset = ba.size() - rest;
char const *startAddress = ba.constData() + offset;
if (rest > 0) {
// SHOULD NEVER HAPPEN !!!
uint8_t local[66];
memset(local, 0xFF, sizeof(local));
memcpy(local, startAddress, rest);
qCritical() << "DownloadThread::run(): ERROR SEND REMAINING" << rest << "BYTES";
m_hw->bl_sendDataBlock(64, local);
} else {
m_hw->bl_sendLastBlock();
m_hw->dcDownloadSetCurrentBlockNumber(currentBlock);
}
qCritical() << "DownloadThread::run(): last result" << (int)sendStatus(m_hw->bl_wasSendingDataOK());
}
stopBootloader(); // there is no harm in stopping the bootloader even stopBootloader(); // there is no harm in stopping the bootloader even
// if it was not started at all } // if it was not started at all
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< "DownloadThread::run(): STOPPED BOOT-LOADER"; #if 0
// test code:
uint16_t const totalBlocks = 100;
m_hw->dcDownloadSetTotalBlockNumber(totalBlocks);
for (uint16_t currentBlock = 0; currentBlock <= totalBlocks; ++currentBlock) {
m_hw->dcDownloadSetCurrentBlockNumber(currentBlock);
QThread::msleep(100);
} }
#endif #endif
m_hw->dcDownloadSetRunning(false); m_hw->dcDownloadSetRunning(false);
m_hw->dcDownloadSetFinished(true); m_hw->dcDownloadSetFinished(true);
QDateTime const end = QDateTime::currentDateTime(); qCritical() << QDateTime::currentDateTime().toString(Qt::ISODate) + "DOWNLOAD THREAD FINISHED";
quint64 secs = start.secsTo(end);
QString runtime;
if (secs % 60) {
runtime = QString("%1min %2s").arg(secs / 60).arg(secs % 60);
} else {
runtime = QString("%1min").arg((secs / 60) + 1);
}
qCritical() << end.time().toString(Qt::ISODateWithMs)
<< QString("DOWNLOAD THREAD FINISHED (RUNTIME %1)")
.arg(runtime);
// the object deletes itself ! This is the last line in run(). // the object deletes itself ! This is the last line in run().
// Never touch the object after this statement // Never touch the object after this statement
@@ -304,6 +193,7 @@ DownloadThread::sendNextAddress(int bNum) const {
int noAnswerCount = 0; int noAnswerCount = 0;
int errorCount = 0; int errorCount = 0;
if ( bNum==0 || bNum==1024 || bNum==2048 || bNum==3072 || bNum==4096 ) { if ( bNum==0 || bNum==1024 || bNum==2048 || bNum==3072 || bNum==4096 ) {
// qDebug() << "addr-block" << bNum << "...";
while (noAnswerCount <= 250) { while (noAnswerCount <= 250) {
m_hw->bl_sendAddress(bNum); m_hw->bl_sendAddress(bNum);
QThread::msleep(100); QThread::msleep(100);
@@ -342,6 +232,9 @@ DownloadThread::sendNextDataBlock(QByteArray const &binary, int bNum) const {
memcpy(local, binary.constData() + bAddr, 64); memcpy(local, binary.constData() + bAddr, 64);
local[64] = local[65] = 0x00; local[64] = local[65] = 0x00;
// QByteArray b((const char *)(&local[0]), 64);
// qCritical() << "SNDB" << bNum << b.size() << b.toHex();
while (noAnswerCount <= 250) { while (noAnswerCount <= 250) {
m_hw->bl_sendDataBlock(64, local); m_hw->bl_sendDataBlock(64, local);
QThread::msleep(10); QThread::msleep(10);
@@ -354,7 +247,9 @@ DownloadThread::sendNextDataBlock(QByteArray const &binary, int bNum) const {
} }
} else { } else {
// qInfo() << "data for block" << bNum << "OK"; // qInfo() << "data for block" << bNum << "OK";
// TODO: hier ins shared mem schreiben
// TODO: hier ins shared mem schreiben
return res; return res;
} }
} else { } else {
@@ -366,65 +261,50 @@ DownloadThread::sendNextDataBlock(QByteArray const &binary, int bNum) const {
} }
bool DownloadThread::startBootloader() const { bool DownloadThread::startBootloader() const {
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qDebug() << "starting bootloader...";
<< "starting bootloader...";
int nTry = 5; int nTry = 5;
while (--nTry >= 0) { while (--nTry >= 0) {
m_hw->bl_startBL(); m_hw->bl_startBL();
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) << "bl_startBL() ..." << nTry; QThread::msleep(5000);
QThread::msleep(500);
m_hw->bl_checkBL(); m_hw->bl_checkBL();
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) << "bl_checkBL() ..." << nTry;
QThread::msleep(500);
if (m_hw->bl_isUp()) { if (m_hw->bl_isUp()) {
qInfo() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) << "bootloader... isUP" << nTry; qInfo() << "starting bootloader...OK";
QThread::msleep(5000);
return true; return true;
} else { } else {
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qCritical() << "bootloader not up (" << nTry << ")";
<< "bootloader not up (" << nTry << ")";
} }
} }
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qCritical() << "starting bootloader...FAILED";
<< "starting bootloader FAILED";
return false; return false;
} }
bool DownloadThread::stopBootloader() const { bool DownloadThread::stopBootloader() const {
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qDebug() << "stopping bootloader...";
<< "stopping bootloader...";
int nTry = 5; int nTry = 5;
while (--nTry >= 0) { while (--nTry >= 0) {
m_hw->bl_stopBL(); m_hw->bl_stopBL();
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< "bl_stopBL() ...";
QThread::msleep(500); QThread::msleep(500);
m_hw->bl_checkBL();
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) << "bl_checkBL() ..." << nTry;
if (!m_hw->bl_isUp()) { if (!m_hw->bl_isUp()) {
qInfo() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qInfo() << "stopping bootloader...OK";
<< "stopping bootloader OK";
return true; return true;
} }
} }
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qCritical() << "stopping bootloader...FAILED";
<< "stopping bootloader FAILED";
return false; return false;
} }
bool DownloadThread::resetDeviceController() const { bool DownloadThread::resetDeviceController() const {
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qDebug() << "resetting device controller...";
<< "resetting device controller...";
m_hw->bl_rebootDC(); m_hw->bl_rebootDC();
// wait maximally 3 seconds, before starting bootloader // wait maximally 3 seconds, before starting bootloader
QThread::sleep(1); QThread::sleep(1);
qInfo() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qInfo() << "resetting device controller...OK";
<< "resetting device controller...OK";
return true; return true;
} }
QByteArray DownloadThread::loadBinaryDCFile(QString filename) const { QByteArray DownloadThread::loadBinaryDCFile(QString filename) const {
qInfo() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qDebug() << "loading dc binary" << filename << "...";
<< "loading dc binary" << filename << "...";
QFile file(filename); // closed in destructor call QFile file(filename); // closed in destructor call
if (!file.exists()) { if (!file.exists()) {

View File

@@ -22,12 +22,11 @@
#include "hwapi.h" #include "hwapi.h"
#include "download_thread.h" #include "download_thread.h"
#include "reporting_thread.h" #include "reporting_thread.h"
#include "shared_mem_buffer.h"
#include <cstring> #include <cstring>
#include <QThread> #include <QThread>
#include <QDebug> #include <QDebug>
#include <QApplication>
static uint32_t hwapi_lastStartAmount; static uint32_t hwapi_lastStartAmount;
static uint32_t hwapi_lastTotalAmount; static uint32_t hwapi_lastTotalAmount;
@@ -59,11 +58,6 @@ hwapi::hwapi(QWidget *parent) : QObject(parent)
qCritical() << "Creating/attaching shared memory failed"; qCritical() << "Creating/attaching shared memory failed";
} }
Q_ASSERT_X(sizeof(SharedMem) == m_sharedMem->size(), "check shm-sizes",
QString("sizes different %1 != %2")
.arg(sizeof(SharedMem))
.arg(m_sharedMem->size()).toStdString().c_str());
//if (shdMem_firstUse()) // für Master raus //if (shdMem_firstUse()) // für Master raus
// { // {
@@ -73,7 +67,7 @@ hwapi::hwapi(QWidget *parent) : QObject(parent)
#error "SLAVE LIB COMPILED INTO MASTER" #error "SLAVE LIB COMPILED INTO MASTER"
#endif #endif
myDatif = new T_datif(this); // für die CAslave-Lib auskommentieren! myDatif = new T_datif(); // für die CAslave-Lib auskommentieren!
#endif #endif
@@ -134,8 +128,7 @@ hwapi::hwapi(QWidget *parent) : QObject(parent)
connect(runProcess, SIGNAL(runProc_doorCoinBoxInserted()), this, SLOT(sub_slotCoin14())); // hwapi_doorCoinBoxInserted())); connect(runProcess, SIGNAL(runProc_doorCoinBoxInserted()), this, SLOT(sub_slotCoin14())); // hwapi_doorCoinBoxInserted()));
connect(runProcess, SIGNAL(runProc_doorCBinAndAllDoorsClosed()), this, SLOT(sub_slotCoin15())); // hwapi_doorCBinAndAllDoorsClosed())); connect(runProcess, SIGNAL(runProc_doorCBinAndAllDoorsClosed()), this, SLOT(sub_slotCoin15())); // hwapi_doorCBinAndAllDoorsClosed()));
connect(runProcess, SIGNAL(runProc_doorAllDoorsClosed()), this, SLOT(sub_slotCoin16())); // hwapi_doorAllDoorsClosed())); connect(runProcess, SIGNAL(runProc_doorAllDoorsClosed()), this, SLOT(sub_slotCoin16())); // hwapi_doorAllDoorsClosed()));
connect(runProcess, SIGNAL(runProc_coinAttached()), this, SLOT(coinAttached()));
} }
void hwapi::hwapi_slotPayProc(void) void hwapi::hwapi_slotPayProc(void)
@@ -233,6 +226,9 @@ void hwapi::sub_slotCoin16(void)
emit hwapi_doorAllDoorsClosed(); emit hwapi_doorAllDoorsClosed();
} }
void hwapi::coinAttached() {
emit hwapi_coinAttached();
}
/* /*
@@ -2640,23 +2636,12 @@ void hwapi::bl_openBinary(void) const
void hwapi::bl_sendDataBlock(uint8_t length, uint8_t *buffer) const void hwapi::bl_sendDataBlock(uint8_t length, uint8_t *buffer) const
{ {
// send 64 byte from bin file // send 64 byte from bin file
// gh, 09/02/2024: extend sendBuf. Buffer sometimes too small, sendLen=81 uint8_t LL=length, sendBuf[80], sendLen;
uint8_t LL=length, sendBuf[80+32], sendLen;
if (LL>64) LL=64; if (LL>64) LL=64;
memset(sendBuf, 0, sizeof(sendBuf)); tslib_strclr(sendBuf,0,80);
sendLen=dcBL_prepareDC_BLcmd(0x22, LL, buffer, sendBuf); // pack into protocol frame sendLen=dcBL_prepareDC_BLcmd(0x22, LL, buffer, sendBuf); // pack into protocol frame
// qCritical() << "(" __func__ << ":" << __LINE__ << ") sendLen=" << sendLen
// << ":" << QByteArray((const char *)sendBuf, sendLen);
sendWRcmd_setSendBlock160(sendLen, sendBuf); // send 140 bytes sendWRcmd_setSendBlock160(sendLen, sendBuf); // send 140 bytes
// if (sendLen > 80) {
// qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
// << QByteArray((const char *)&sendBuf[80], 32).toHex(':');
// }
delay(100); delay(100);
} }
@@ -3349,21 +3334,15 @@ void hwapi::sys_restoreDeviceParameter(struct T_devices *deviceSettings) const
// attention: only applies if function "sys_sendDeviceParameter()" was used to send this settings before // attention: only applies if function "sys_sendDeviceParameter()" was used to send this settings before
// cannot be used to see settings programmed by JsonFile // cannot be used to see settings programmed by JsonFile
uint8_t buf[64]; uint8_t buf[64];
uint8_t LL, nn; uint8_t LL;
tslib_strclr(buf,0,64); tslib_strclr(buf,0,64);
uint8_t *start;
//runProcess->epi_restore64BdevParameter(&LL, buf); // wozu die??? //runProcess->epi_restore64BdevParameter(&LL, buf); // wozu die???
epi_restoreRbDeviceSettings(&LL, buf); // viel besser, stimmt immer epi_restoreRbDeviceSettings(&LL, buf); // viel besser, stimmt immer
// Puffer in struct eintragen: Q_STATIC_ASSERT(sizeof(*deviceSettings) <= sizeof(buf));
start = &deviceSettings->kindOfPrinter;
nn=0; memcpy(deviceSettings, buf, sizeof(*deviceSettings));
do
{
*start = buf[nn];
start++;
} while(++nn<LL);
} }
bool hwapi::sys_areDCdataValid(void) const bool hwapi::sys_areDCdataValid(void) const
@@ -4428,7 +4407,6 @@ QObject const *hwapi::getAPI() {
} }
bool hwapi::dcDownloadRequest(QString const &dcFileToDownload) const { bool hwapi::dcDownloadRequest(QString const &dcFileToDownload) const {
// called by worker-thread (see atbupdatetool)
SharedMem *data = SharedMem::getData(); SharedMem *data = SharedMem::getData();
if (!data) { if (!data) {
return false; return false;
@@ -4452,15 +4430,9 @@ bool hwapi::dcDownloadRequest(QString const &dcFileToDownload) const {
} }
bool hwapi::dcDownloadRequested() const { bool hwapi::dcDownloadRequested() const {
SharedMem *data = SharedMem::getData(); SharedMem const *data = SharedMem::getData();
Q_ASSERT_X(data != nullptr, "check", "pointer invalid"); // should be false at entry
Q_ASSERT_X((void *)data == m_sharedMem->data(), "compare pointers", "pointers different"); return data ? data->m_downLoadDC.m_requested.load() : false;
Q_ASSERT_X(sizeof(*data) == m_sharedMem->size(), "compare sizes", "sizes different");
// called by download-thread
// 1: true at entry: reset atomically to false
// 2: false at entry: no change
return data ? data->m_downLoadDC.m_requested.exchange(false) : false;
} }
bool hwapi::dcDownloadResetRequest() const { bool hwapi::dcDownloadResetRequest() const {
@@ -4472,11 +4444,13 @@ bool hwapi::dcDownloadResetRequest() const {
} }
bool hwapi::dcDownloadRequestAck() const { bool hwapi::dcDownloadRequestAck() const {
// called by download-thread
SharedMem *data = SharedMem::getData(); SharedMem *data = SharedMem::getData();
if (data) { if (data) {
data->m_downLoadDC.m_running = true; if (data->m_downLoadDC.m_requested) {
data->m_downLoadDC.m_finished = false; data->m_downLoadDC.m_requested = false;
data->m_downLoadDC.m_running = true;
data->m_downLoadDC.m_finished = false;
}
} }
return false; return false;
} }
@@ -4486,16 +4460,14 @@ bool hwapi::dcDownloadRunning() const {
if (data) { if (data) {
int cnt = 10; int cnt = 10;
while (--cnt > 0) { while (--cnt > 0) {
bool running = data->m_downLoadDC.m_running; bool running = data->m_downLoadDC.m_running.load();
bool finished = data->m_downLoadDC.m_finished; bool finished = data->m_downLoadDC.m_finished.load();
if ((running == true) && (finished == false)) { if (!running || finished) {
// see dcDownloadRequestAck() if (cnt < 3) {
break; qCritical() << "DOWNLOAD THREAD NOT RUNNING" << running << finished;
} }
if (cnt < 3) { QThread::msleep(500);
qCritical() << "DOWNLOAD THREAD NOT RUNNING" << running << finished; } else break;
}
QThread::msleep(500);
} }
// qCritical() << "DOWNLOAD RUNNING" << cnt << (cnt > 0); // qCritical() << "DOWNLOAD RUNNING" << cnt << (cnt > 0);
return (cnt > 0); return (cnt > 0);
@@ -4504,16 +4476,18 @@ bool hwapi::dcDownloadRunning() const {
} }
void hwapi::dcDownloadThreadFinalize(DownloadThread *dthread) { void hwapi::dcDownloadThreadFinalize(DownloadThread *dthread) {
Q_UNUSED(dthread); delete dthread;
// delete dthread;
m_downloadThread = nullptr; m_downloadThread = nullptr;
} }
bool hwapi::dcDownloadFinished() { bool hwapi::dcDownloadFinished() {
int cnt = 10; SharedMem const *data = SharedMem::getDataConst();
while (dcDownloadRunning()) { if (data) {
if (--cnt == 0) { int cnt = 10;
return false; while ((--cnt > 0) &&
((data->m_downLoadDC.m_running.load() == true) &&
(data->m_downLoadDC.m_finished.load() == false))) {
QThread::sleep(1);
} }
//if (cnt > 0) { //if (cnt > 0) {
@@ -4522,13 +4496,12 @@ bool hwapi::dcDownloadFinished() {
// return true; // return true;
//} //}
} }
return true; return false;
} }
// download thread // download thread
bool hwapi::dcDownloadThreadStart() { bool hwapi::dcDownloadThreadStart() {
// called by timer in datIf.cpp: T_datif::datif_cycleSend()
m_downloadThread = new DownloadThread(this); m_downloadThread = new DownloadThread(this);
if (m_downloadThread) { if (m_downloadThread) {
m_downloadThread->start(); m_downloadThread->start();
@@ -4560,7 +4533,6 @@ bool hwapi::dcDownloadReportThreadStart() { // only start reporting thread
if (cnt > 0) { if (cnt > 0) {
m_reportingThread = new ReportingThread(this); m_reportingThread = new ReportingThread(this);
if (m_reportingThread) { if (m_reportingThread) {
m_reportingThread->moveToThread(QApplication::instance()->thread());
m_reportingThread->start(); m_reportingThread->start();
cnt = 10; cnt = 10;
while (--cnt > 0 && !dcDownloadReportThreadRunning()) { while (--cnt > 0 && !dcDownloadReportThreadRunning()) {
@@ -4592,9 +4564,7 @@ void hwapi::dcDownloadReportThreadQuit() {
} }
bool hwapi::dcDownloadReportThreadFinished() const { bool hwapi::dcDownloadReportThreadFinished() const {
// if the pointer to the underlying c++-object is not valid, the thread return m_reportingThread ? m_reportingThread->isFinished() : false;
// counts as finished
return m_reportingThread ? m_reportingThread->isFinished() : true;
} }
bool hwapi::dcDownloadReportStart() const { bool hwapi::dcDownloadReportStart() const {
@@ -4620,10 +4590,8 @@ bool hwapi::dcDownloadReportFinished() {
} }
if (dcDownloadReportThreadFinished()) { if (dcDownloadReportThreadFinished()) {
if (m_reportingThread) { delete m_reportingThread;
delete m_reportingThread; m_reportingThread = nullptr;
m_reportingThread = nullptr;
}
} }
return true; return true;

View File

@@ -4,16 +4,10 @@
#include <QDateTime> #include <QDateTime>
#include <QDebug> #include <QDebug>
#include <QApplication>
#include <QCoreApplication>
#include <cmath>
#include <algorithm>
ReportingThread::ReportingThread(hwapi *hw) ReportingThread::ReportingThread(hwapi *hw)
: m_hw(hw) : m_hw(hw)
, m_fileToDownload(m_hw->dcDownloadFileName()) { , m_fileToDownload(m_hw->dcDownloadFileName()) {
// , m_f([](QString const&){}) {
} }
ReportingThread::~ReportingThread() { ReportingThread::~ReportingThread() {
@@ -23,10 +17,7 @@ ReportingThread::~ReportingThread() {
// each component which has connects for the corresponding signals. // each component which has connects for the corresponding signals.
void ReportingThread::run() { void ReportingThread::run() {
qCritical() qCritical() << QDateTime::currentDateTime() << "START DOWNLOAD THREAD";
<< QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "START REPORT THREAD"
<< "(PART OF APPLICATION" << QCoreApplication::applicationName() << ")";
static QString report(""); static QString report("");
@@ -34,9 +25,9 @@ void ReportingThread::run() {
while (!m_hw->dcDownloadGetRunning()) { while (!m_hw->dcDownloadGetRunning()) {
if (--cnt > 0) { if (--cnt > 0) {
report = QString("%1 waiting for download to start %2") report = QString("%1 waiting for download to start %2")
.arg(QDateTime::currentDateTime().time().toString(Qt::ISODate)) .arg(QDateTime::currentDateTime().toString(Qt::ISODate))
.arg(cnt); .arg(cnt);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") STATUS" << report; qCritical() << __LINE__ << "STATUS" << report;
emit m_hw->hwapi_reportDCDownloadStatus(report); emit m_hw->hwapi_reportDCDownloadStatus(report);
QThread::sleep(1); QThread::sleep(1);
} else break; } else break;
@@ -100,79 +91,33 @@ void ReportingThread::run() {
#endif #endif
uint16_t totalBlocks = m_hw->dcDownloadGetTotalBlockNumber(); uint16_t const totalBlocks = m_hw->dcDownloadGetTotalBlockNumber();
cnt = 10;
while(--cnt > 0 && totalBlocks == 0) {
totalBlocks = m_hw->dcDownloadGetTotalBlockNumber();
qCritical() << QDateTime::currentDateTime() << __PRETTY_FUNCTION__
<< QString("line=%1 TOTAL BLOCKS=%2 (%3)")
.arg(__LINE__).arg(totalBlocks).arg(cnt);
QThread::sleep(1);
}
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate) << __PRETTY_FUNCTION__ qCritical() << QDateTime::currentDateTime() << "TOTAL BLOCKS" << totalBlocks;
<< QString("line=%1 TOTAL BLOCKS=%2").arg(__LINE__).arg(totalBlocks);
if (totalBlocks) { if (totalBlocks) {
QDateTime const start = QDateTime::currentDateTime(); qint64 const start = QDateTime::currentMSecsSinceEpoch();
double durationMillis = 0;
uint16_t currentBlockNumber = 0; uint16_t currentBlockNumber = 0;
uint16_t prevBlockNumber = ~0;
uint64_t estimatedMinutesLeftMax = ~0ULL;
uint64_t estimatedSecondsLeftMax = ~0ULL;
uint64_t estimatedMinutesLeftPrev = 0;
uint64_t estimatedSecondsLeftPrev = 0;
while (m_hw->dcDownloadGetRunning()) { while (m_hw->dcDownloadGetRunning()) {
currentBlockNumber = m_hw->dcDownloadGetCurrentBlockNumber(); currentBlockNumber = m_hw->dcDownloadGetCurrentBlockNumber();
if (prevBlockNumber != currentBlockNumber) {
double durationSecs = start.secsTo(QDateTime::currentDateTime());
double const timeAveragePerBlock = (currentBlockNumber > 0) ? (durationSecs / currentBlockNumber) : durationSecs; durationMillis += QDateTime::currentMSecsSinceEpoch() - start;
uint64_t estimatedSecondsLeft = lround((timeAveragePerBlock * (totalBlocks - currentBlockNumber)));
uint64_t estimatedMinutesLeft =
((estimatedSecondsLeft % 60) == 0) ?
(estimatedSecondsLeft / 60) :
((estimatedSecondsLeft + 60) / 60);
estimatedSecondsLeft = (estimatedSecondsLeft % 60); double const timeAveragePerBlock = (currentBlockNumber > 0) ? (durationMillis / currentBlockNumber) : durationMillis;
double const estimatedSecondsLeft = (timeAveragePerBlock * (totalBlocks - currentBlockNumber)) / 1000.0;
if ((estimatedMinutesLeft <= estimatedMinutesLeftMax) double percent = ((double)currentBlockNumber / (double)totalBlocks) * 100.0;
|| (estimatedSecondsLeft <= estimatedSecondsLeftMax)) { report = QString(": total blocks %1, current block %2 [%3] (est. time left: %4s)")
estimatedMinutesLeftMax = estimatedMinutesLeft; .arg(totalBlocks)
estimatedSecondsLeftMax = estimatedSecondsLeft; .arg(currentBlockNumber)
estimatedMinutesLeftPrev = estimatedMinutesLeft; .arg(percent, 0, 'f', 2)
estimatedSecondsLeftPrev = estimatedSecondsLeft; .arg(estimatedSecondsLeft, 0, 'f', 2);
double percent = ((double)currentBlockNumber / (double)totalBlocks) * 100.0; qCritical() << "RT report" << report;
report = QString(": total blocks %1, current block %2 [%3] (est. time left: %4min %5s)")
.arg(totalBlocks)
.arg(currentBlockNumber)
.arg(percent, 0, 'f', 2)
.arg(estimatedMinutesLeft)
.arg(estimatedSecondsLeft, 2);
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate) emit m_hw->hwapi_reportDCDownloadStatus(report);
<< QString("line=%1: RT report").arg(__LINE__) << report;
emit m_hw->hwapi_reportDCDownloadStatus(report);
} else {
double percent = ((double)currentBlockNumber / (double)totalBlocks) * 100.0;
report = QString(": total blocks %1, current block %2 [%3] (est. time left: %4min %5s)")
.arg(totalBlocks)
.arg(currentBlockNumber)
.arg(percent, 0, 'f', 2)
.arg(estimatedMinutesLeftPrev)
.arg(estimatedSecondsLeftPrev, 2);
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< QString("line=%1: RT report").arg(__LINE__) << report;
emit m_hw->hwapi_reportDCDownloadStatus(report);
}
prevBlockNumber = currentBlockNumber;
}
QThread::msleep(100); QThread::msleep(100);
} }
@@ -188,7 +133,7 @@ void ReportingThread::run() {
} }
} }
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate) << __PRETTY_FUNCTION__ qCritical() << QDateTime::currentDateTime() << __PRETTY_FUNCTION__
<< QString("line=%1 REPORT THREAD ABOUT TO FINISH").arg(__LINE__); << QString("line=%1 REPORT THREAD ABOUT TO FINISH").arg(__LINE__);
cnt = 10; cnt = 10;

View File

@@ -48,6 +48,16 @@ T_runProc::T_runProc()
void T_runProc::runProc_slotProcess(void) void T_runProc::runProc_slotProcess(void)
{ {
#ifndef THIS_IS_CA_MASTER #ifndef THIS_IS_CA_MASTER
bool const coinAttached = epi_getDI_CoinAttach();
// exchange: (atomically) replaces the underlying value of m_coinAttached
// with the value of coinAttached, returns the value of m_coinAttached
// before the call
if (m_coinAttached.exchange(coinAttached) == false) {
if (coinAttached) {
// old value was false, and new value is true
emit runProc_coinAttached();
}
}
cash_paymentProcessing(); cash_paymentProcessing();
doors_supervise(); doors_supervise();
bl_performComplStart(); // neu 1.12.23 bl_performComplStart(); // neu 1.12.23
@@ -641,11 +651,8 @@ void T_runProc::bl_rebootDC(void)
// BL is working for 5s after power-on-reset. // BL is working for 5s after power-on-reset.
uint8_t len, buf[20]; uint8_t len, buf[20];
memset(buf, 0x00, sizeof(buf));
len=dcBL_restartDC(buf); len=dcBL_restartDC(buf);
qCritical() << __func__ << QByteArray((const char *)buf, len).toHex(':');
sendWRcmd_setSendBlock160(len, buf); sendWRcmd_setSendBlock160(len, buf);
} }
@@ -655,13 +662,8 @@ void T_runProc::bl_startBL(void)
// otherwise the BL jumps to normal DC application // otherwise the BL jumps to normal DC application
uint8_t len, buf[20]; uint8_t len, buf[20];
memset(buf, 0x00, sizeof(buf));
len=dcBL_activatBootloader(buf); len=dcBL_activatBootloader(buf);
qCritical() << __func__ << QByteArray((const char *)buf, len).toHex(':');
sendWRcmd_setSendBlock160(len, buf); sendWRcmd_setSendBlock160(len, buf);
epi_setNowIsBootload(true); epi_setNowIsBootload(true);
} }
@@ -669,11 +671,8 @@ void T_runProc::bl_checkBL(void)
{ {
// call this function in order to get information, afterwards use "bl_isUp()" // call this function in order to get information, afterwards use "bl_isUp()"
uint8_t len, buf[20]; uint8_t len, buf[20];
memset(buf, 0x00, sizeof(buf));
len=dcBL_readFWversion(buf); len=dcBL_readFWversion(buf);
qCritical() << __func__ << QByteArray((const char *)buf, len).toHex(':');
sendWRcmd_setSendBlock160(len, buf); sendWRcmd_setSendBlock160(len, buf);
} }
@@ -684,7 +683,6 @@ bool T_runProc::bl_isUp(void)
for (nn=0; nn<160; nn++) receivedData[nn]=0; for (nn=0; nn<160; nn++) receivedData[nn]=0;
LL=epi_getRawRecLength(); LL=epi_getRawRecLength();
if (LL>0) if (LL>0)
{ {
epi_getRawReceivedData(receivedData); epi_getRawReceivedData(receivedData);
@@ -697,24 +695,13 @@ bool T_runProc::bl_isUp(void)
//epi_clrRawReceivedString(); //epi_clrRawReceivedString();
return true; return true;
} }
// response to "start BL"
// response to "start BL" { 2, 101, 48, 223, 131, 3} if (receivedData[0]==2 && receivedData[1]==101 && receivedData[2]==48 &&
static uint8_t const cmp[6] = {0x02, 0x65, 0x30, 0xdf, 0x83, 0x03}; receivedData[3]==223 && receivedData[4] ==131 )
{
if (LL >= 6 && LL <= 13) { qDebug() << "hwapi_bl_isUp: got BL response to start";
// (1) "02:63:34:35:62:33:03:02:65:30:df:83:03" //epi_clrRawReceivedString();
// (2) "02:65:30:df:83:03" return true;
// qCritical() << "(" << __func__ << ":" << __LINE__
// << ") CHECK" << QByteArray((char const*)receivedData, LL).toHex(':');
for (int i=0; i <= LL-6; ++i) {
if (memcmp(cmp, &receivedData[i], 6) == 0) {
qCritical() << "(" << __func__ << ":" << __LINE__
<< ") BL RESPONSE to bl_start(): BOOTLOADER IS UP";
return true;
}
}
} }
} }
return false; return false;

View File

@@ -1,13 +1,7 @@
#include "shared_mem_buffer.h" #include "shared_mem_buffer.h"
#include <QDebug> #include <QDebug>
#include <QFile>
#include <QString>
#include <QTextStream>
#include <QDateTime>
#include <QCoreApplication>
#include <atomic> #include <atomic>
#include <algorithm>
#ifdef QT_POSIX_IPC #ifdef QT_POSIX_IPC
// The POSIX backend can be explicitly selected using the -feature-ipc_posix // The POSIX backend can be explicitly selected using the -feature-ipc_posix
@@ -15,124 +9,33 @@
// macro will be defined. -> we use SystemV shared memory // macro will be defined. -> we use SystemV shared memory
#error "QT_POSIX_IPC defined" #error "QT_POSIX_IPC defined"
#else #else
#ifdef linux #ifdef __linux__
#include <stdlib.h>
#include <string.h>
#include <sys/ipc.h> // ftok #include <sys/ipc.h> // ftok
#endif #endif
#endif #endif
//static bool shdMemFirstUse; //static bool shdMemFirstUse;
static QString read1stLineOfFile(QString fileName) { // read for instance /etc/os-release
QFile f(fileName);
if (f.exists()) {
if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream in(&f);
in.setCodec("UTF-8");
while(!in.atEnd()) {
return in.readLine();
}
}
}
return "N/A";
}
//QSharedMemory *SharedMemBuffer::getShm(std::size_t size) { //QSharedMemory *SharedMemBuffer::getShm(std::size_t size) {
QSharedMemory *SharedMem::getShm(std::size_t size) { QSharedMemory *SharedMem::getShm(std::size_t size) {
static QSharedMemory shMem; static QSharedMemory shMem;
if (size > 0) { if (size > 0) {
#ifdef linux #ifdef __linux__
static const long nativeKey = ftok("/etc/os-release", 'H'); //static const long nativeKey = ftok("/etc/os-release", 'H');
static const QString fkey = std::to_string(nativeKey).c_str(); //static const QString fkey = std::to_string(nativeKey).c_str();
//static const QString fkey = "0123456?000=7"; static const QString fkey = "0123456?000=7";
#else #else
static const QString fkey = "0123456?000=9"; static const QString fkey = "0123456?000=9";
#endif #endif
qCritical() << __func__ << ":" << __LINE__ << ": size" << size;
shMem.setKey(fkey); shMem.setKey(fkey);
if (!shMem.isAttached()) { if (!shMem.isAttached()) {
if (shMem.create(size)) { if (shMem.create(size)) {
qCritical() << __func__ << ":" << __LINE__ << ": created shared memory";
#ifdef linux
if ((size != (std::size_t)shMem.size()) || (sizeof(SharedMem) != shMem.size())) {
qCritical() << __func__ << ":" << __LINE__
<< "size=" << size
<< "shMem.size=" << shMem.size()
<< "sizeof(SharedMem)=" << sizeof(SharedMem)
<< "ABOUT TO REBOOT SYSTEM...";
if (system("reboot")) {
// reboot system -> shared memory re-created
}
}
struct SharedMem *sh = (SharedMem *)(shMem.data());
memset(sh->indat_HWversion, 0x00, sizeof(sh->indat_HWversion));
memset(sh->indat_SWversion, 0x00, sizeof(sh->indat_SWversion));
memset(sh->os_release, 0x00, sizeof(sh->os_release));
memset(sh->date_of_creation, 0x00, sizeof(sh->date_of_creation));
memset(sh->creator, 0x00, sizeof(sh->creator));
QString const &os_release = read1stLineOfFile("/etc/os-release");
strncpy(sh->os_release, os_release.toStdString().c_str(),
std::min((int)os_release.size(), (int)sizeof(sh->os_release)-1));
QString const &currentDateTime = QDateTime::currentDateTime().toString(Qt::ISODate);
char const *current = currentDateTime.toUtf8().constData();
strncpy(sh->date_of_creation, current,
std::min((int)strlen(current), (int)sizeof(sh->date_of_creation)-1));
QString const &appPid = QString("%1 (%2)").arg(QCoreApplication::applicationName())
.arg(QCoreApplication::applicationPid());
strncpy(sh->creator, appPid.toStdString().c_str(),
std::min((int)strlen(appPid.toStdString().c_str()),
(int)sizeof(sh->creator)-1));
qCritical() << "os-release:" << sh->os_release;
qCritical() << " creator:" << sh->creator;
qCritical() << " date:" << sh->date_of_creation;
#else
Q_ASSERT_X(size != shMem.size(), "compare sizes", "sizes different");
Q_ASSERT_X(sizeof(SharedMem) != shMem.size(), "compare sizes", "sizes different");
#endif
return &shMem; return &shMem;
} else { } else {
if (shMem.error() == QSharedMemory::AlreadyExists) { if (shMem.error() == QSharedMemory::AlreadyExists) {
if (shMem.attach()) { if (shMem.attach()) {
#ifdef linux
if ((size != (std::size_t)shMem.size()) || (sizeof(SharedMem) != shMem.size())) {
qCritical() << __func__ << ":" << __LINE__
<< "size=" << size
<< "shMem.size=" << shMem.size()
<< "sizeof(SharedMem)=" << sizeof(SharedMem)
<< "ABOUT TO REBOOT SYSTEM...";
if (system("reboot")) {
// reboot system -> shared memory re-created
}
}
#else
Q_ASSERT_X(size != shMem.size(), "compare sizes", "sizes different");
Q_ASSERT_X(sizeof(SharedMem) != shMem.size(), "compare sizes", "sizes different");
#endif
QString const &appPid = QString("%1 (%2)").arg(QCoreApplication::applicationName())
.arg(QCoreApplication::applicationPid());
qCritical() << __func__ << ":" << __LINE__ << appPid << "attached shared memory";
struct SharedMem const *sh = (SharedMem const *)(shMem.data());
qCritical() << "os-release:" << sh->os_release;
qCritical() << " creator:" << sh->creator;
qCritical() << " date:" << sh->date_of_creation;
return &shMem; return &shMem;
} }
} }
@@ -140,13 +43,6 @@ QSharedMemory *SharedMem::getShm(std::size_t size) {
qCritical() << shMem.nativeKey() << shMem.key() << shMem.data() qCritical() << shMem.nativeKey() << shMem.key() << shMem.data()
<< shMem.error() << shMem.errorString(); << shMem.error() << shMem.errorString();
return nullptr; return nullptr;
} else {
qCritical() << __func__ << ":" << __LINE__ << "shared memory already attached";
struct SharedMem const *sh = (SharedMem const *)(shMem.data());
qCritical() << "os-release:" << sh->os_release;
qCritical() << " creator:" << sh->creator;
qCritical() << " date:" << sh->date_of_creation;
} }
} }
return &shMem; return &shMem;

View File

@@ -6,8 +6,6 @@
#include "shared_mem_buffer.h" #include "shared_mem_buffer.h"
#include "datei.h" #include "datei.h"
#include <QTextCodec>
// gpi: grafical access to PI: access from external devices over device controller FOR GUI // 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) // epi: external access from GUI to PI: FOR external devices (DC)
@@ -66,64 +64,66 @@ bool indat_isMdbOn()
void gpi_storeHWver(QString text) void gpi_storeHWver(QString text)
{ {
QString prev(QByteArray(SharedMem::read()->indat_HWversion, versionBufferLen-1)); // change Qstring to array of chars, because shared mem allowes no QString!
prev = prev.trimmed(); int nn, LL = text.length();
if (LL >= versionBufferLen)
LL=versionBufferLen-1; // leave place for termination
QString const textTruncated = text.mid(0, qMin(versionBufferLen-1, text.size())).trimmed(); for (nn=0; nn<LL; nn++)
{
if (textTruncated.startsWith("DC2C", Qt::CaseInsensitive) SharedMem::write()->indat_HWversion[nn] = text.at(nn).toLatin1();
&& textTruncated != prev) {
QTextCodec *codec = QTextCodec::codecForName("Windows-1252");
QString string = codec->toUnicode(textTruncated.toUtf8());
if (!string.isEmpty()) {
memset(SharedMem::write()->indat_HWversion, 0, versionBufferLen);
char *p = (char *)SharedMem::write()->indat_HWversion;
char *q = (char *)string.constData();
for (int i=0; i < qMin(versionBufferLen, string.size()); ++i) {
int const j = (sizeof(QChar) == 2) ? i*2 : i;
if (q[j]) {
*p++ = q[j];
}
}
}
} }
for (nn=LL; nn<versionBufferLen; nn++)
SharedMem::write()->indat_HWversion[nn] =0;
} }
QString epi_loadHWver(void) QString epi_loadHWver(void)
{ {
QString text(SharedMem::read()->indat_HWversion); // load array of chars from SM and change to QString
return text.mid(0, qMin(versionBufferLen-1, text.size())).trimmed(); int nn, LL = versionBufferLen;
char cc;
QString myStr;
myStr.clear();
for (nn=0; nn<LL; nn++)
{
cc = SharedMem::read()->indat_HWversion[nn];
myStr.append(cc);
}
return myStr;
} }
void gpi_storeSWver(QString text) void gpi_storeSWver(QString text)
{ {
QString prev(QByteArray(SharedMem::read()->indat_SWversion, 12)); int nn, LL = text.length();
prev = prev.trimmed(); if (LL >= versionBufferLen)
LL=versionBufferLen-1; // leave place for termination
QString const textTruncated = text.mid(0, qMin(12, text.size())).trimmed(); for (nn=0; nn<LL; nn++)
{
if (textTruncated.startsWith("DC2C", Qt::CaseInsensitive) SharedMem::write()->indat_SWversion[nn] = text.at(nn).toLatin1();
&& textTruncated != prev) {
QTextCodec *codec = QTextCodec::codecForName("Windows-1252");
QString string = codec->toUnicode(textTruncated.toUtf8());
if (!string.isEmpty()) {
memset(SharedMem::write()->indat_SWversion, 0, versionBufferLen);
char *p = (char *)SharedMem::write()->indat_SWversion;
char *q = (char *)string.constData();
for (int i=0; i < qMin(versionBufferLen, string.size()); ++i) {
int const j = (sizeof(QChar) == 2) ? i*2 : i;
if (q[j]) {
*p++ = q[j];
}
}
}
} }
for (nn=LL; nn<versionBufferLen; nn++)
SharedMem::write()->indat_SWversion[nn] =0;
} }
QString epi_loadSWver(void) QString epi_loadSWver(void)
{ {
QString text(SharedMem::read()->indat_SWversion); int nn, LL = versionBufferLen;
return text.mid(0, qMin(12, text.size())).trimmed(); char cc;
QString myStr;
myStr.clear();
for (nn=0; nn<LL; nn++)
{
cc = SharedMem::read()->indat_SWversion[nn];
myStr.append(cc);
}
return myStr;
} }
void gpi_storeDCstate(QString text) void gpi_storeDCstate(QString text)
@@ -2203,8 +2203,8 @@ void gpi_storeRawReceivedData(uint8_t RdDlen, uint8_t *receivedData)
SharedMem::write()->Sdata_LengthRawData=lrd; SharedMem::write()->Sdata_LengthRawData=lrd;
for (nn=0; nn<lrd; nn++) for (nn=0; nn<lrd; nn++)
SharedMem::write()->Sdata_rawData[nn]=receivedData[nn]; SharedMem::write()->Sdata_rawData[nn]=receivedData[nn];
//qDebug()<<"dcBL got data"<< Sdata_LengthRawData << "bytes :)"; //qDebug()<<"dcBL got data"<< Sdata_LengthRawData << "bytes :)";
} }
uint8_t epi_getRawReceivedData(uint8_t *receivedData) uint8_t epi_getRawReceivedData(uint8_t *receivedData)