Compare commits

..

27 Commits

Author SHA1 Message Date
4cc964e8c2 Include memory for all json file names. 2023-12-10 14:43:57 +01:00
f910b7d057 DownloadThread: add real dc-download implementation. 2023-12-10 14:43:06 +01:00
5dd90e9597 Use enum value as array index. 2023-12-10 14:42:28 +01:00
47f09067ea Added functionality for actually downloading a real dc. 2023-12-08 19:00:43 +01:00
65163354bd First draft implementation of reporting thread sending reports to ATBUpdateTool, which
contains the necessary connects.
2023-12-08 13:02:22 +01:00
5f88c8f856 Test implementation of download thread without an actual download of dc. 2023-12-08 13:01:47 +01:00
4efbbcbb5a Implement download interfcae api. 2023-12-08 13:00:48 +01:00
1155b83ca9 Removed dcDownloadStart().
dcDownloadRequested():	return if download of dc has been requested.
dcDownloadResetRequested(): reset state of m_requested.
2023-12-08 12:58:31 +01:00
631550b55e dcDownloadRequest(): declare as const and set m_finished = true; 2023-12-08 12:55:10 +01:00
9e5c379e8a Make download api in include/interfaces.h available for Qt using
signals/slots.
2023-12-08 12:51:16 +01:00
6b9e795206 Reordered and extended interface-api for download-thread and reporting-thread:
virtual bool dcDownloadRequest(QString const &fileToDownload) const;
virtual bool dcDownloadRequested() const;
virtual bool dcDownloadResetRequest() const;
virtual bool dcDownloadRequestAck() const;
virtual bool dcDownloadRunning() const;
virtual bool dcDownloadFinished();

virtual bool dcDownloadReportStart() const;
virtual bool dcDownloadReportRunning() const;

virtual bool dcDownloadReportFinished();
virtual bool dcDownloadThreadStart();
virtual bool dcDownloadThreadRunning() const;
virtual void dcDownloadThreadFinalize(DownloadThread *);

virtual bool dcDownloadThreadFinished() const;
virtual bool dcDownloadReportThreadStart();
virtual bool dcDownloadReportThreadRunning() const;
virtual void dcDownloadReportThreadFinalize();
virtual void dcDownloadReportThreadQuit();

virtual bool dcDownloadReportThreadFinished() const;
virtual QString dcDownloadFileName() const;
virtual bool dcDownloadSetRequested(bool requested);
virtual bool dcDownloadSetRunning(bool running);
virtual bool dcDownloadSetFinished(bool finished);
virtual void dcDownloadSetTotalBlockNumber(uint16_t totalBlockNumber);
virtual void dcDownloadSetCurrentBlockNumber(uint16_t currentBlockNumber);
virtual bool dcDownloadGetRequested() const;
virtual bool dcDownloadGetRunning() const;
virtual bool dcDownloadGetFinished() const;
virtual uint16_t dcDownloadGetTotalBlockNumber() const;
virtual uint16_t dcDownloadGetCurrentBlockNumber() const;
2023-12-08 12:44:53 +01:00
b7ff6dcdbe devl continue 2023-12-06 16:35:17 +01:00
2025a75d56 Save as changing to master. 2023-12-06 14:53:52 +01:00
6176285b89 Keep test code. 2023-12-03 19:55:23 +01:00
0344150950 dd reporting thread signals. 2023-12-03 19:54:21 +01:00
68813a49c5 Add reporting thread and download thread. 2023-12-03 19:53:18 +01:00
8e287e3163 Add reporting thread and download thread. 2023-12-03 19:52:48 +01:00
fd58f41c87 Implement helpers:
virtual void dcDownloadStart() {}^M
virtual bool dcDownloadRequested() const { return false; }^M
virtual void dcDownloadResetRequest() {}^M
virtual QString dcDownloadFileName() const { return ""; }^M
virtual void dcDownloadReportStart() {}^M
2023-12-02 09:47:51 +01:00
ece75887e2 Add helpers:
virtual void dcDownloadStart() {}^M
virtual bool dcDownloadRequested() const { return false; }^M
virtual void dcDownloadResetRequest() {}^M
virtual QString dcDownloadFileName() const { return ""; }^M
virtual void dcDownloadReportStart() {}^M
2023-12-02 09:47:26 +01:00
cee4caf77d Add helpers:
virtual void dcDownloadStart() {}^M
virtual bool dcDownloadRequested() const { return false; }^M
virtual void dcDownloadResetRequest() {}^M
virtual QString dcDownloadFileName() const { return ""; }^M
virtual void dcDownloadReportStart() {}^M
2023-12-02 09:46:58 +01:00
6b2830ee83 start download thread in cycleSend() when reuested 2023-12-02 09:46:18 +01:00
cd4bddd169 Minor: only hwinf as parameter needed 2023-12-02 09:44:59 +01:00
8a380c9845 Minor: only hwinf as parameter needed 2023-12-02 09:44:51 +01:00
23619543b2 Minor: only hwinf as parameter needed 2023-12-02 09:44:32 +01:00
be16fe4981 Minor: only hwinf as parameter needed 2023-12-02 09:44:18 +01:00
cf621c02bd Pass hwinf into constructor. Add pointer to download thread. 2023-12-02 09:42:50 +01:00
ee26eef50f Save development files. 2023-12-01 14:28:07 +01:00
24 changed files with 375 additions and 882 deletions

View File

@@ -21,15 +21,14 @@ INCLUDEPATH += ../include
win32 {
BUILD_DATE=$$system("date /t")
BUILD_TIME=$$system("time /t")
GIT_COMMIT=""
EXTENDED_VERSION=""
} else {
BUILD_DATE=$$system("date +%d-%m-%y")
BUILD_TIME=$$system("date +%H:%M:%S")
GIT_COMMIT=$$system("git log -1 --format=oneline | cut -d' ' -f1")
EXTENDED_VERSION="$${VERSION}-$${GIT_COMMIT}"
}
GIT_COMMIT=$$system("git log -1 --format=oneline | cut -d' ' -f1")
EXTENDED_VERSION="$${VERSION}-$${GIT_COMMIT}"
DEFINES+=APP_VERSION=\\\"$$VERSION\\\"
DEFINES+=APP_BUILD_DATE=\\\"$$BUILD_DATE\\\"

View File

@@ -375,9 +375,6 @@ bool T_winComPort::working(uint16_t *nextScreen, uint8_t *useNavi)
// bit0,1: enable/disable button "next"
// bit2,3: enable/disable button "home"
// bit4,5: enable/disable button "back"
QString bs, cn;
int br, ci;
this->updateGui();
*nextScreen=0; // 0=no change
@@ -388,29 +385,22 @@ bool T_winComPort::working(uint16_t *nextScreen, uint8_t *useNavi)
// 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);
CB_portSel->setCurrentIndex(ci); // den Port aus der Datei hier vorgeben
connectButton->setChecked(true); // connect Taste "druecken"
} else
{
// 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);
//uint32_t len= datei_nrOfEntriesInFile(myBA);
//uint64_t ulltmp=csv_getEntryAs2Ulong(myBA,0);
//qDebug()<<"win_startup load long numer: "<<ulltmp;
QString bs=csv_getEntryAsString(myBA,0); // read the 's' war 2!??
int br=csv_getEntryAsInt(myBA,1); // z.B. 5 (5.Eintrag in der Baud-Liste)
bs=csv_getEntryAsString(myBA,2); // z.B 115200
QString cn=csv_getEntryAsString(myBA,3); // z.B. COM9
int ci=csv_getEntryAsInt(myBA,4); // Eintragsnummer in COM-Fenster
//qDebug()<<"win_startup loaded com settings: "<<br<<" "<<bs<<" "<<cn;
HWaccess->dc_openSerial(br,bs,cn,1);
//CB_baudSel->setCurrentIndex(br); // im BR auswahlfenster diese Baud vorgeben
CB_portSel->setCurrentIndex(ci); // den Port aus der Datei hier vorgeben
connectButton->setChecked(true); // connect Taste "druecken"
}
myTO->start(100); // restart
myStep++;
} else
@@ -420,13 +410,9 @@ bool T_winComPort::working(uint16_t *nextScreen, uint8_t *useNavi)
if (!myTO->isActive())
{
if (HWaccess->dc_isPortOpen())
{
myStep++;
} else
{
myStep=6; // 13.12.23: start Autoconnect cycle
qDebug()<<"CArunGui: port is still closed, restarting..";
}
else
myStep=99; // stop automatic connection and wait for manual start
myTO->start(100);
}
} else
@@ -448,10 +434,7 @@ bool T_winComPort::working(uint16_t *nextScreen, uint8_t *useNavi)
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..";
}
myStep=99; // stop automatic connection and wait for manual start
myTO->start(100);
}
@@ -462,38 +445,23 @@ bool T_winComPort::working(uint16_t *nextScreen, uint8_t *useNavi)
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);
}
}
// got next screen:
//myNextStep=2; // nicht bei CArun
myStep++;
} else
if (myStep==6)
{
// restart autoconnect cycle
myTO->start(100); // restart
myStep=0;
// stop here, everything done
} else
if (myStep==7)
{
// stay here, DC connection is up and running
} else
{
@@ -502,6 +470,7 @@ bool T_winComPort::working(uint16_t *nextScreen, uint8_t *useNavi)
if (myNextStep)
{
//qDebug()<<"fenster1 working: "<< myNextStep;
*nextScreen=myNextStep;
myNextStep=0;
}

View File

@@ -81,27 +81,37 @@ contains( CONFIG, PTU5_YOCTO ) {
}
HEADERS += \
$${PWD}/include/com.h \
$${PWD}/include/datei.h \
$${PWD}/include/runProc.h \
$${PWD}/include/controlBus.h \
$${PWD}/include/datIf.h \
$${PWD}/include/dcBL.h \
$${PWD}/include/hwapi.h \
$${PWD}/include/interfaces.h \
$${PWD}/include/prot.h \
$${PWD}/include/sendWRcmd.h \
$${PWD}/include/storeINdata.h \
$${PWD}/include/tslib.h \
$${PWD}/include/shared_mem_buffer.h
$${PWD}/include/shared_mem_buffer.h \
$${PWD}/include/download_thread.h \
$${PWD}/include/reporting_thread.h
SOURCES += \
$${PWD}/src/com.cpp \
$${PWD}/src/datei.cpp \
$${PWD}/src/runProc.cpp \
$${PWD}/src/controlBus.cpp \
$${PWD}/src/datIf.cpp \
$${PWD}/src/dcBL.cpp \
$${PWD}/src/hwapi.cpp \
$${PWD}/src/prot.cpp \
$${PWD}/src/sendWRcmd.cpp \
$${PWD}/src/storeINdata.cpp \
$${PWD}/src/tslib.cpp \
$${PWD}/src/shared_mem_buffer.cpp
$${PWD}/src/shared_mem_buffer.cpp \
$${PWD}/src/download_thread.cpp \
$${PWD}/src/reporting_thread.cpp
# INTERFACE = DeviceController

View File

@@ -1,5 +1,4 @@
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS = lib_ca_master lib_ca_slave CArunGUI dCArun

View File

@@ -25,16 +25,15 @@ INCLUDEPATH += ../include
win32 {
BUILD_DATE=$$system("date /t")
BUILD_TIME=$$system("time /t")
GIT_COMMIT=""
EXTENDED_VERSION=""
} else {
BUILD_DATE=$$system("date +%d-%m-%y")
BUILD_TIME=$$system("date +%H:%M:%S")
GIT_COMMIT=$$system("git log -1 --format=oneline | cut -d' ' -f1")
EXTENDED_VERSION="$${VERSION}-$${GIT_COMMIT}"
}
GIT_COMMIT=$$system("git log -1 --format=oneline | cut -d' ' -f1")
EXTENDED_VERSION="$${VERSION}-$${GIT_COMMIT}"
DEFINES+=APP_VERSION=\\\"$$VERSION\\\"
DEFINES+=APP_BUILD_DATE=\\\"$$BUILD_DATE\\\"
DEFINES+=APP_BUILD_TIME=\\\"$$BUILD_TIME\\\"

View File

@@ -375,9 +375,6 @@ bool T_winComPort::working(uint16_t *nextScreen, uint8_t *useNavi)
// bit0,1: enable/disable button "next"
// bit2,3: enable/disable button "home"
// bit4,5: enable/disable button "back"
QString bs, cn;
int br, ci;
this->updateGui();
*nextScreen=0; // 0=no change
@@ -388,29 +385,22 @@ bool T_winComPort::working(uint16_t *nextScreen, uint8_t *useNavi)
// 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);
CB_portSel->setCurrentIndex(ci); // den Port aus der Datei hier vorgeben
connectButton->setChecked(true); // connect Taste "druecken"
} else
{
// 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);
//uint32_t len= datei_nrOfEntriesInFile(myBA);
//uint64_t ulltmp=csv_getEntryAs2Ulong(myBA,0);
//qDebug()<<"win_startup load long numer: "<<ulltmp;
QString bs=csv_getEntryAsString(myBA,0); // read the 's' war 2!??
int br=csv_getEntryAsInt(myBA,1); // z.B. 5 (5.Eintrag in der Baud-Liste)
bs=csv_getEntryAsString(myBA,2); // z.B 115200
QString cn=csv_getEntryAsString(myBA,3); // z.B. COM9
int ci=csv_getEntryAsInt(myBA,4); // Eintragsnummer in COM-Fenster
//qDebug()<<"win_startup loaded com settings: "<<br<<" "<<bs<<" "<<cn;
HWaccess->dc_openSerial(br,bs,cn,1);
//CB_baudSel->setCurrentIndex(br); // im BR auswahlfenster diese Baud vorgeben
CB_portSel->setCurrentIndex(ci); // den Port aus der Datei hier vorgeben
connectButton->setChecked(true); // connect Taste "druecken"
}
myTO->start(100); // restart
myStep++;
} else
@@ -420,13 +410,9 @@ bool T_winComPort::working(uint16_t *nextScreen, uint8_t *useNavi)
if (!myTO->isActive())
{
if (HWaccess->dc_isPortOpen())
{
myStep++;
} else
{
myStep=6; // 13.12.23: start Autoconnect cycle
qDebug()<<"CArunGui: port is still closed, restarting..";
}
else
myStep=99; // stop automatic connection and wait for manual start
myTO->start(100);
}
} else
@@ -448,10 +434,7 @@ bool T_winComPort::working(uint16_t *nextScreen, uint8_t *useNavi)
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..";
}
myStep=99; // stop automatic connection and wait for manual start
myTO->start(100);
}
@@ -462,38 +445,23 @@ bool T_winComPort::working(uint16_t *nextScreen, uint8_t *useNavi)
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);
}
}
// got next screen:
//myNextStep=2; // nicht bei CArun
myStep++;
} else
if (myStep==6)
{
// restart autoconnect cycle
myTO->start(100); // restart
myStep=0;
// stop here, everything done
} else
if (myStep==7)
{
// stay here, DC connection is up and running
} else
{
@@ -502,6 +470,7 @@ bool T_winComPort::working(uint16_t *nextScreen, uint8_t *useNavi)
if (myNextStep)
{
//qDebug()<<"fenster1 working: "<< myNextStep;
*nextScreen=myNextStep;
myNextStep=0;
}

View File

@@ -133,9 +133,8 @@
#define SENDCOMBINED 0
class DownloadThread;
class hwinf;
class DownloadThread;
class T_datif : public QObject
{
Q_OBJECT
@@ -166,7 +165,8 @@ class T_datif : public QObject
T_prot *myDCIF;
QTimer *datif_trigger;
uint8_t selectedSlaveAddr;
hwinf *m_hw = nullptr;
DownloadThread *m_downloadThread;
hwinf *m_hw;
private slots:
char datif_cycleSend();

View File

@@ -1,7 +1,6 @@
#ifndef DATEI_H
#define DATEI_H
#include <stdint.h>
#include <QFile>
#include <QFileInfo>
#include <QDebug>

View File

@@ -26,8 +26,6 @@ V4.0 6.9.2023: activating DC-Bootloader in slve-lib (SM)
#ifndef hwapi_H
#define hwapi_H
#include <stdint.h>
//#include <QTabWidget>
#include <QtPlugin>
#include <QTimer>
#include <QObject>
@@ -39,11 +37,11 @@ V4.0 6.9.2023: activating DC-Bootloader in slve-lib (SM)
#include "controlBus.h"
#include "storeINdata.h"
#include "dcBL.h"
//#include <../plugins/interfaces.h>
#include "interfaces.h"
#include "shared_mem_buffer.h"
#include "runProc.h"
#include "interfaces.h"
#include "download_thread.h"
#include "reporting_thread.h"
/*
* select Plugin Type here
@@ -75,13 +73,10 @@ V4.0 6.9.2023: activating DC-Bootloader in slve-lib (SM)
//#undef THIS_IS_CA_MASTER
//for CAmaster:
//#define THIS_IS_CA_MASTER
class QSharedMemory;
class DownloadThread;
class ReportingThread;
class DownloadThread;
class hwapi : public QObject,
public hwinf
{
@@ -93,13 +88,13 @@ private:
void sub_storeSendingText(QByteArray *buf) const;
QTimer *hwapi_TimerPayment;
QSharedMemory *m_sharedMem;
ReportingThread *m_reportingThread = nullptr;
DownloadThread *m_downloadThread = nullptr;
//QTimer *hwapi_triggerBL;
ReportingThread *m_reportingThread;
DownloadThread *m_downloadThread;
public:
explicit hwapi(QWidget *parent = nullptr);
#ifdef THIS_IS_CA_MASTER
T_datif *myDatif;
#endif
@@ -1301,15 +1296,8 @@ public:
uint8_t bna_getCurrentNotes(uint16_t latestBill, uint16_t *currentNotes) const override;
// returns number of collected bank notes since start-command (current transaction)
// return value: numbers of bills or 99 in case of error
// latestBill: not used
// in case of error: currentNotes[0,1,2,3] = 1..4 error number(s)
// in normal case:
// currentNotes[0]: last bill in cent (e.g. 1000 = 10€)
// currentNotes[1]: bin 1 = bill is still in escrow else bill is stacked
// note: by now (dec2023) escrow is not used, bills always go to stacker (box)
// currentNotes[2]: total sum of bills in cent, low word (16bit)
// currentNotes[3]: total sum of bills in cent, high word (16bit)
// latestBill: last accepted bank note, value in cent
// currentNotes an array with up to 16 (further) notes collected
void bna_requestStackerLevel(void) const override;
@@ -1318,6 +1306,7 @@ public:
// countOfBills: array of up to 16 sums, countOfBills[0]=nr of 5€-bills in stacker
// countOfBills[1] for 10€ and so on
// download device controller
bool dcDownloadRequest(QString const &fileToDownload) const override;
bool dcDownloadRequested() const override;
@@ -1330,6 +1319,7 @@ public:
bool dcDownloadReportRunning() const override;
bool dcDownloadReportFinished() override;
bool dcDownloadThreadStart() override;
bool dcDownloadThreadRunning() const override;
void dcDownloadThreadFinalize(DownloadThread *) override;
@@ -1354,38 +1344,34 @@ public:
virtual QObject const *getAPI() override;
signals:
signals: // for download
void hwapi_reportDCDownloadStatus(QString const&) const;
void hwapi_reportDCDownloadSuccess(QString const&) const;
void hwapi_reportDCDownloadFailure(QString const&) const;
// already declared in interfaces.h
void hwapi_templatePrintFinished_OK(void) const;
void hwapi_templatePrintFinished_Err(void) const;
void hwapi_templatePrintFinished_OK(void) const override;
void hwapi_templatePrintFinished_Err(void) const override;
void hwapi_coinCollectionJustStarted(void) const;
void hwapi_coinCollectionAborted(void) const;
void hwapi_coinCollectionJustStarted(void) const override;
void hwapi_coinCollectionAborted(void) const override;
void hwapi_gotNewCoin(void) const;
void hwapi_payStopByMax(void) const;
void hwapi_payStopByPushbutton(void) const;
void hwapi_gotNewCoin(void) const override;
void hwapi_payStopByMax(void) const override;
void hwapi_payStopByPushbutton(void) const override;
void hwapi_payStopByEscrow(void) const override;
void hwapi_payStopByError(void) const override;
void hwapi_payStopByTimeout(void) const override;
void hwapi_payCancelled(void) const override;
void hwapi_coinProcessJustStopped(void) const override;
void hwapi_payStopByEscrow(void) const;
void hwapi_payStopByError(void) const;
void hwapi_payStopByTimeout(void) const;
void hwapi_payCancelled(void) const;
void hwapi_coinProcessJustStopped(void) const;
// new from 2023.06.12
void hwapi_doorServiceDoorOpened(void) const override;
void hwapi_doorVaultDoorOpened(void) const override;
void hwapi_doorCoinBoxRemoved(void) const override;
void hwapi_doorCoinBoxInserted(void) const override;
void hwapi_doorCBinAndAllDoorsClosed(void) const override;
void hwapi_doorAllDoorsClosed(void) const override;
void hwapi_doorServiceDoorOpened(void) const;
void hwapi_doorVaultDoorOpened(void) const;
void hwapi_doorCoinBoxRemoved(void) const;
void hwapi_doorCoinBoxInserted(void) const;
void hwapi_doorCBinAndAllDoorsClosed(void) const;
void hwapi_doorAllDoorsClosed(void) const;
private slots:
//void hwapi_slotPrintFinished_OK(void);

View File

@@ -2,6 +2,7 @@
#define INTERFACE_H
#include <QtPlugin>
#include <QString>
@@ -24,8 +25,7 @@ struct T_emp
// dynamic:
uint8_t state; // step counter of EMP (electronic coin checker) FSM (finite state machine):
/*
// 0=start command
// 0=start command
// 1=powered, do emp ini, send reset
// 2=delay
// 3=wait for response, requesting status after response
@@ -40,7 +40,7 @@ struct T_emp
// 90: stop all, 1s delay
// 99: off, all stopped
*/
uint8_t pollingRunning;
uint8_t paymentRunning;
@@ -239,7 +239,6 @@ struct T_dynamicCondition
uint8_t lastVDoorState;
uint8_t lastCBstate;
char paymentInProgress;
// Version Szeged: aug2023
// 0: stopped by timeout
// 1: running 2: wait4lastCoin
// 3: payment stopped manually, coins in Escrow
@@ -248,21 +247,6 @@ struct T_dynamicCondition
// 6: coins encashed 7:coins returned
// 8: CoinChecker or MDB on Error
// since Schoenau with bill and changer, nov2023
//0 = no payment
//will be set to 1 by cash_startCollection()
//neu 1: wait for devices getting ready for payment
//2 = payment,
//3 = wait for last coin/bill
//4 = Bezahlvorgang manuell beendet
//5 = payment stopped autom, amount collected, coins in Escrow
//6 = Bezahlvorgang beendet weil ZK voll
//4,5,6: payment done, keep on polling, wait for cash or return command
//7 = encash collected money from coin escrow into cash box
//8 = return "amountToReturn", can be complete inserted amount or only overpayment
//9 = wait for changer result
//10= print refund receipt with "amountToReturn"
char res1;
uint16_t U_Batt;
@@ -414,6 +398,7 @@ struct T_bna
};
class hwapi;
class DownloadThread;
class hwinf
{
@@ -2270,23 +2255,14 @@ public:
virtual void bna_requestCurrentNotes() const {}
// send command to DC in order to get transaction data
virtual uint8_t bna_getCurrentNotes(uint16_t latestBill, uint16_t *currentNotes) const
{
virtual uint8_t bna_getCurrentNotes(uint16_t latestBill, uint16_t *currentNotes) const {
Q_UNUSED(latestBill);
Q_UNUSED(currentNotes);
return 0;
}
// returns number of collected bank notes since start-command (current transaction)
// return value: numbers of bills or 99 in case of error
// latestBill: not used
// in case of error: currentNotes[0,1,2,3] = 1..4 error number(s)
// in normal case:
// currentNotes[0]: last bill in cent (e.g. 1000 = 10€)
// currentNotes[1]: bin 1 = bill is still in escrow else bill is stacked
// note: by now (dec2023) escrow is not used, bills always go to stacker (box)
// currentNotes[2]: total sum of bills in cent, low word (16bit)
// currentNotes[3]: total sum of bills in cent, high word (16bit)
// latestBill: last accepted bank note, value in cent
// currentNotes an array with up to 16 (further) notes collected
virtual void bna_requestStackerLevel() const {}
@@ -2350,49 +2326,12 @@ public:
virtual QObject const *getAPI() { return nullptr; }
signals:
/*
NOTE: the difference between a virtual Qt signal and a normal Qt signal:
A Qt virtual signal is a connection that is established using a pointer
or reference and is not connected to an object or data. It is therefore
not bound to a particular object, but to a specific class (object type).
Qt virtual signals are useful because they allow you to create
connections without worrying about whether an object or a specific data
element has been destroyed.
https://www.youtube.com/watch?v=HTH3VFfqsXw
*/
virtual void hwapi_reportDCDownloadStatus(QString const&) const {}
virtual void hwapi_reportDCDownloadSuccess(QString const&) const {}
virtual void hwapi_reportDCDownloadFailure(QString const&) const {}
virtual void hwapi_templatePrintFinished_OK(void) const=0;
virtual void hwapi_templatePrintFinished_Err(void) const=0;
virtual void hwapi_coinCollectionJustStarted(void) const=0;
virtual void hwapi_coinCollectionAborted(void) const=0;
virtual void hwapi_gotNewCoin(void) const=0;
virtual void hwapi_payStopByMax(void) const=0;
virtual void hwapi_payStopByPushbutton(void) const=0;
virtual void hwapi_payStopByEscrow(void) const=0;
virtual void hwapi_payStopByError(void) const=0;
virtual void hwapi_payStopByTimeout(void) const=0;
virtual void hwapi_payCancelled(void) const=0;
virtual void hwapi_coinProcessJustStopped(void) const=0;
virtual void hwapi_doorServiceDoorOpened(void) const=0;
virtual void hwapi_doorVaultDoorOpened(void) const=0;
virtual void hwapi_doorCoinBoxRemoved(void) const=0;
virtual void hwapi_doorCoinBoxInserted(void) const=0;
virtual void hwapi_doorCBinAndAllDoorsClosed(void) const=0;
virtual void hwapi_doorAllDoorsClosed(void) const=0;
signals: // for download
void hwapi_reportDCDownloadStatus(QString const&) const;
void hwapi_reportDCDownloadSuccess(QString const&) const;
void hwapi_reportDCDownloadFailure(QString const&) const;
// NOTE: declaring a "pure virtual" "signal" should be an error and thus not valid.
/* GH Version, bringt Fehler
void hwapi_templatePrintFinished_OK() const;
void hwapi_templatePrintFinished_Err() const;
@@ -2415,7 +2354,6 @@ signals:
void hwapi_doorCoinBoxInserted() const;
void hwapi_doorCBinAndAllDoorsClosed() const;
void hwapi_doorAllDoorsClosed() const;
*/
};

View File

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

View File

@@ -2,7 +2,6 @@
#ifndef RUN_PROCESS_H
#define RUN_PROCESS_H
#include <stdint.h>
#include <QMainWindow>
#include <QString>
#include <QTimer>
@@ -26,7 +25,7 @@
class T_runProc : public QObject
{
Q_OBJECT
QTimer *hwapi_TimerPayment, *hwapi_triggerBL, *myTO;
QTimer *hwapi_TimerPayment, *hwapi_triggerBL;
void sub_emp_getAllParameters(struct T_emp *emp);
void changer_getAllParameters(struct T_changer *mw);

View File

@@ -300,6 +300,7 @@ struct SharedMem
uint8_t p_nextFDcmdsInQueue;
// download of device controller and json files
struct DCDownload {
enum class FILE_INDEX {
@@ -321,11 +322,6 @@ struct SharedMem
std::atomic_bool m_finished{false};
} 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 SharedMem *getData()

View File

@@ -527,9 +527,6 @@ void gpi_storeDcDataValid(bool isVal);
bool epi_areDcDataValid();
void epi_setDcDataValid(void);
void epi_resetDcDataValid(void);
void epi_clearDynData(void);

View File

@@ -1,42 +1,11 @@
TEMPLATE = lib
TARGET = CAmaster
VERSION="1.0.2"
HEADERS += \
../include/com.h \
../include/datIf.h \
../include/prot.h \
../include/download_thread.h
SOURCES += \
../src/com.cpp \
../src/datIf.cpp \
../src/prot.cpp \
../src/download_thread.cpp
VERSION="1.0.0"
include(../DCLibraries.pri)
win32 {
BUILD_DATE=$$system("date /t")
BUILD_TIME=$$system("time /t")
GIT_COMMIT=""
EXTENDED_VERSION=""
EXTENDED_VERSION_LIB=""
} else {
BUILD_DATE=$$system("date +%d-%m-%y")
BUILD_TIME=$$system("date +%H:%M:%S")
GIT_COMMIT=$$system("git log -1 --format=oneline . | cut -d' ' -f1")
EXTENDED_VERSION_LIB="libCAmaster-$${VERSION}-$${GIT_COMMIT}"
}
DEFINES+=APP_VERSION=\\\"$$VERSION\\\"
DEFINES+=APP_BUILD_DATE=\\\"$$BUILD_DATE\\\"
DEFINES+=APP_BUILD_TIME=\\\"$$BUILD_TIME\\\"
DEFINES+=APP_EXTENDED_VERSION=\\\"$$EXTENDED_VERSION\\\"
DEFINES+=APP_EXTENDED_VERSION_LIB=\\\"$$EXTENDED_VERSION_LIB\\\"
DEFINES+=THIS_IS_CA_MASTER
DEFINES-=THIS_IS_CA_SLAVE
DESTDIR=$${_PRO_FILE_PWD_}/../build
unix {

View File

@@ -1,36 +1,12 @@
TEMPLATE = lib
TARGET = CAslave
VERSION="1.0.2"
HEADERS += \
../include/reporting_thread.h
SOURCES += \
../src/reporting_thread.cpp
VERSION="1.0.0"
include(../DCLibraries.pri)
win32 {
BUILD_DATE=$$system("date /t")
BUILD_TIME=$$system("time /t")
GIT_COMMIT=""
EXTENDED_VERSION=""
EXTENDED_VERSION_LIB=""
} else {
BUILD_DATE=$$system("date +%d-%m-%y")
BUILD_TIME=$$system("date +%H:%M:%S")
GIT_COMMIT=$$system("git log -1 --format=oneline . | cut -d' ' -f1")
EXTENDED_VERSION_LIB_="libCAslave-$${VERSION}-$${GIT_COMMIT}"
}
DEFINES+=APP_VERSION=\\\"$$VERSION\\\"
DEFINES+=APP_BUILD_DATE=\\\"$$BUILD_DATE\\\"
DEFINES+=APP_BUILD_TIME=\\\"$$BUILD_TIME\\\"
DEFINES+=APP_EXTENDED_VERSION=\\\"$$EXTENDED_VERSION\\\"
DEFINES+=APP_EXTENDED_VERSION_LIB=\\\"$$EXTENDED_VERSION_LIB\\\"
DEFINES+=THIS_IS_CA_SLAVE
DEFINES-=THIS_IS_CA_MASTER
DESTDIR=$${_PRO_FILE_PWD_}/../build
unix {

View File

@@ -1,22 +1,14 @@
/*
History:
06.12.2023: weitere IN-requests in Autorequest übernommen
Umschaltung mit/ohne Verkauf, während VK nur 12 wichtige, sonst alle 36
*/
#include "datIf.h"
#include "sendWRcmd.h"
#include "controlBus.h"
#include "storeINdata.h"
#include "download_thread.h"
#include "hwapi.h"
#include <QDebug>
#include <datei.h>
#include <QDir>
#include <QString>
#include <QDateTime>
@@ -94,8 +86,7 @@ T_datif::T_datif(hwinf *hw, QObject *parent) : QObject(parent)
dif_scanStep=0;
selectedSlaveAddr=FIX_SLAVE_ADDR;
cycl_running=0;
epi_resetDcDataValid(); // data are not yet valid, no response from DC by now
gpi_storeDcDataValid(0); // data are not yet valid, no response from DC by now
datif_noResponseCtr=0;
datif_repeatCtr=0;
@@ -151,14 +142,14 @@ char T_datif::datif_cycleSend()
if ( !myDCIF->isPortOpen())
{
//qDebug() << "com port not available"; // wird ununterbrochen ausgegeben
epi_resetDcDataValid(); // DC data not valid
gpi_storeDcDataValid(0); // DC data not valid
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
epi_resetDcDataValid(); // DC data has not updated for >=5s -> no longer valid!
gpi_storeDcDataValid(0); // DC data has not updated for >=5s -> no longer valid!
// Ueberwachung ob ein oder mehrere Commands am Stueck erfolgreich waren
if (gpi_wantToResetSupervision())
@@ -176,22 +167,10 @@ char T_datif::datif_cycleSend()
// 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 )
// 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
//qDebug()<< "datif wait for response";
datif_trigger->stop();
@@ -224,8 +203,21 @@ char T_datif::datif_cycleSend()
return 0;
}
if (m_hw->dcDownloadRequested()) { // only happens in ca-master
m_hw->dcDownloadResetRequest();
// start download-thread.
m_downloadThread = new DownloadThread(m_hw);
m_downloadThread->start();
int cnt = 10;
while (--cnt > 0 && !m_downloadThread->isRunning()) {
QThread::msleep(100);
}
if (cnt <= 0) {
qCritical() << "DOWNLOAD-THREAD NOT RUNNING WITHIN 1000ms";
}
}
// 17.7.2023: repeat commands if result was !=OK -------------------------------------------------------------------
if (datif_cmdWasPerformed==2 && doRepeat) // Cmd was not or false performed und Wiederholen erwuenscht
@@ -363,7 +355,7 @@ char T_datif::datif_cycleSend()
else
{
dif_scanStep=0; // always start from beginning
epi_resetDcDataValid();
gpi_storeDcDataValid(0);
}
datif_cmdWasPerformed=0; // 0: no response by now
@@ -376,20 +368,9 @@ char T_datif::datif_cycleSend()
char T_datif::sendINrequestsAutomatic(void)
{
//qDebug() << "send IN request " << dif_scanStep;
//uint8_t datif_autoRequCommandList[30]={11, 12, 14, 17, 18, 19, 22, 23, 27, 30,
// 31, 32, 33, 35, 102, 103, 104, 106, 107, 109,
// 114,0,0,0,0,0,0,0,0,0};
// extension 6.12.23, complete list:
uint8_t datif_autoRequCommandList[40]={11, 12, 13, 14, 17, 18, 19, 21, 22, 23,
24, 25, 27, 30, 31, 32, 33, 35, 39, 40,
41, 42, 102,103,104,106,107,108,109,110,
112,113,114,115,116,0, 0, 0, 0, 0};
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_maxVendingCmds=13;
// uint8_t datif_autoRequCommandList[50]={11, 12, 18, 104, 106, 103, 14, 27, 109, 17, 19, 23, 30, 31, 32, 33, 114, 35};
uint8_t datif_autoRequCommandList[30]={11, 12, 14, 17, 18, 19, 22, 23, 27, 30, 31, 32, 33, 35, 102, 103, 104, 106, 107, 109, 114,0,0,0,0,0,0,0,0,0};
uint8_t datif_maxNrCommands=21, datif_sendNow;
// special commands:
// 102: get IOs run constantly!!!
@@ -399,44 +380,40 @@ char T_datif::sendINrequestsAutomatic(void)
// 107, 22: MDB: poll if needed
doRepeat=true; // 20.9.23 15uhr (after release)
if (gpi_getNowCoinPay())
if (datif_sendSlowCmd>0)
{
// send only important commands while transaction in progress
if (datif_pNextCmd>=datif_maxVendingCmds ) datif_pNextCmd=0;
datif_sendNow=datif_vendRequCommandList[datif_pNextCmd++];
// send special command, slowly
datif_sendNow=datif_autoRequCommandList[datif_pNextCmd++];
if (datif_pNextCmd >= datif_maxNrCommands)
datif_pNextCmd=0;
if (datif_sendNow>0) // never send Command 0
{
datif_sendIOrequest(0, datif_sendNow, 0);
//qDebug() << "datif, VEND-request: " << datif_sendNow;
} else
else
datif_pNextCmd=0; // falls in der Liste 0 vorkommt dann von vorne beginnen
//qDebug()<< "datif send request " << datif_sendNow;
} else
{
// no transaction, request all but request DI's more frequently
if (datif_sendSlowCmd>0) // send slow and fast commands alternating
if (gpi_getNowCoinPay())
{
// send special command, slowly
if (datif_pNextCmd>=datif_maxNrCommands ) datif_pNextCmd=0;
datif_sendNow=datif_autoRequCommandList[datif_pNextCmd++];
if (datif_sendNow>0) // never send Command 0
{
datif_sendIOrequest(0, datif_sendNow, 0);
// qDebug() << "datif, auto-requ: " << datif_sendNow;
} else
datif_pNextCmd=0; // falls in der Liste 0 vorkommt dann von vorne beginnen
// request coin input, high priority
datif_sendIOrequest(0, 112, 0);
//qDebug()<< "datif send request 112 get coins";
} else
{
// request inputs, high priority
datif_sendIOrequest(0, 31, 0); // 102
// while coin collection DIs are polled slower
//qDebug()<< "datif send requ.31 get DIs";
// while coin collection DIs are polled slowly with datif_autoRequCommandList[]
//qDebug()<< "datif send request 102 get DIs";
}
if (++datif_sendSlowCmd>1) datif_sendSlowCmd=0; // 0,1,0,1,0,1,0....
}
if (++datif_sendSlowCmd>1) datif_sendSlowCmd=0; // 0,1,0,1,0,1,0....
return 0; // 25.9.2023, wichtig sonst bleibt die komplette PTU stehen!!!!
}
@@ -480,7 +457,7 @@ char T_datif::loadRecDataFromFrame()
uint32_t ultmp;
//int portNr;
bool ret;
uint8_t uctmp; //, nn; //, res; // maxai
uint8_t uctmp; //, res; // maxai
char ctmp;
//static uint8_t lastResult;
//uint8_t prnResult;
@@ -1055,7 +1032,7 @@ char T_datif::loadRecDataFromFrame()
case 31: // Get dynamic machine conditions (doors, voltage, alarm….)
if (RdDleng>50)
{
epi_setDcDataValid(); // DC-Data are valid as DC responded.
gpi_storeDcDataValid(1); // DC-Data are valid as DC responded.
// Could be set to every response but this (31)
// is a very common and very important request
gpi_storeDynMachineConditions(RdDleng, receivedData);
@@ -1102,11 +1079,11 @@ char T_datif::loadRecDataFromFrame()
/*
qDebug()<<"datif cmd38 got vault data. blockNr: "<<readAddress;
if (readAddress==0)
for (nn=0; nn<64; nn+=8)
{
qDebug()<<receivedData[nn]<<" "<<receivedData[nn+1]<<" "<<receivedData[nn+2]<<" "<<receivedData[nn+3]<<" "
<<receivedData[nn+4]<<" "<<receivedData[nn+5]<<" "<<receivedData[nn+6]<<" "<<receivedData[nn+7];
}
for (nn=0; nn<64; nn+=8)
{
qDebug()<<receivedData[nn]<<" "<<receivedData[nn+1]<<" "<<receivedData[nn+2]<<" "<<receivedData[nn+3]<<" "
<<receivedData[nn+4]<<" "<<receivedData[nn+5]<<" "<<receivedData[nn+6]<<" "<<receivedData[nn+7];
}
*/
//}
break;
@@ -1146,7 +1123,9 @@ char T_datif::loadRecDataFromFrame()
break;
case 42: // get BNA box content and value of types
//qDebug()<< "CAslave datif_got 42";
// qDebug()<< "CAmaster datif_got 42 ";
// for (uctmp=0; uctmp<64; uctmp++)
// qDebug()<<receivedData[uctmp]<<" ";
if (RdDleng>60)
{

View File

@@ -104,10 +104,7 @@ void DownloadThread::run() {
m_hw->dcDownloadRequestAck();
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DownloadThread::run(): DOWNLOAD THREAD STARTED:";
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< " DownloadThread::run(): Filename:" << m_hw->dcDownloadFileName();
qCritical() << "DownloadThread::run(): DOWNLOAD THREAD STARTED";
// load binary device controller file into memory
QByteArray ba = loadBinaryDCFile(m_hw->dcDownloadFileName());
@@ -118,31 +115,13 @@ void DownloadThread::run() {
// fill last block of data to be sent with 0xFF
ba = ba.leftJustified(totalBlocks*64, (char)(0xFF));
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DownloadThread::run(): TOTAL NUMBER OF BYTES TO SEND TO DC" << ba.size();
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "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();
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DownloadThread::run(): RESET DEVICE-CONTROLLER";
QThread::sleep(1);
if (startBootloader()) {
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DownloadThread::run(): STARTED BOOT-LOADER";
m_hw->dc_autoRequest(false);// turn auto-request setting off for
// download of binary dc
#if 0
int currentBlock = 0; // download of binary dc
qCritical() << "DownloadThread::run(): TOTAL NUMBER OF BYTES TO SEND TO DC" << ba.size();
qCritical() << "DownloadThread::run(): TOTAL NUMBER OF BLOCKS" << totalBlocks;
int currentBlock = 0;
DownloadResult res = DownloadResult::OK;
qCritical() << "64-byte block " << currentBlock;
while (res != DownloadResult::ERROR && currentBlock < totalBlocks) {
@@ -170,31 +149,27 @@ void DownloadThread::run() {
} 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());
#else
for (uint16_t currentBlock = 0; currentBlock <= totalBlocks; ++currentBlock) {
m_hw->dcDownloadSetCurrentBlockNumber(currentBlock);
qCritical() << "DownloadThread::run(): currentBlockNumber" << currentBlock;
QThread::msleep(250);
}
#endif
m_hw->dc_autoRequest(true); // turn auto-request setting on again
}
stopBootloader(); // there is no harm in stopping the bootloader even
// if it was not started at all
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DownloadThread::run(): STOPPED BOOT-LOADER";
} // if it was not started at all
#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
m_hw->dcDownloadSetRunning(false);
m_hw->dcDownloadSetFinished(true);
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DOWNLOAD THREAD FINISHED";
qCritical() << QDateTime::currentDateTime().toString(Qt::ISODate) + "DOWNLOAD THREAD FINISHED";
// the object deletes itself ! This is the last line in run().
// Never touch the object after this statement
@@ -286,59 +261,45 @@ DownloadThread::sendNextDataBlock(QByteArray const &binary, int bNum) const {
}
bool DownloadThread::startBootloader() const {
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "starting bootloader...";
qDebug() << "starting bootloader...";
int nTry = 5;
while (--nTry >= 0) {
m_hw->bl_startBL();
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate) << "bl_startBL() ..." << nTry;
QThread::msleep(1000);
QThread::msleep(5000);
m_hw->bl_checkBL();
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate) << "bl_checkBL() ..." << nTry;
QThread::msleep(1000);
if (m_hw->bl_isUp()) {
qInfo() << QDateTime::currentDateTime().time().toString(Qt::ISODate) << "bootloader... isUP" << nTry;
qInfo() << "starting bootloader...OK";
QThread::msleep(5000);
return true;
} else {
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "bootloader not up (" << nTry << ")";
qCritical() << "bootloader not up (" << nTry << ")";
}
}
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "starting bootloader FAILED";
qCritical() << "starting bootloader...FAILED";
return false;
}
bool DownloadThread::stopBootloader() const {
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "stopping bootloader...";
qDebug() << "stopping bootloader...";
int nTry = 5;
while (--nTry >= 0) {
m_hw->bl_stopBL();
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "bl_stopBL() ...";
QThread::msleep(500);
m_hw->bl_checkBL();
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate) << "bl_checkBL() ..." << nTry;
if (!m_hw->bl_isUp()) {
qInfo() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "stopping bootloader OK";
qInfo() << "stopping bootloader...OK";
return true;
}
}
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "stopping bootloader FAILED";
qCritical() << "stopping bootloader...FAILED";
return false;
}
bool DownloadThread::resetDeviceController() const {
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "resetting device controller...";
qDebug() << "resetting device controller...";
m_hw->bl_rebootDC();
// wait maximally 3 seconds, before starting bootloader
QThread::sleep(1);
qInfo() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "resetting device controller...OK";
qInfo() << "resetting device controller...OK";
return true;
}

View File

@@ -20,14 +20,12 @@
*/
#include "hwapi.h"
#include "download_thread.h"
#include "reporting_thread.h"
#include "shared_mem_buffer.h"
#include "download_thread.h"
#include <algorithm>
#include <cstring>
#include <QThread>
#include <QDebug>
#include <QApplication>
#include <atomic>
static uint32_t hwapi_lastStartAmount;
static uint32_t hwapi_lastTotalAmount;
@@ -41,12 +39,6 @@ static uint8_t bl_startupStep;
hwapi::hwapi(QWidget *parent) : QObject(parent)
{
// constructor
qCritical() << " hwapi::hwapi() APP_VERSION:" << APP_VERSION;
qCritical() << " hwapi::hwapi() APP_BUILD_DATE:" << APP_BUILD_DATE;
qCritical() << " hwapi::hwapi() APP_BUILD_TIME:" << APP_BUILD_TIME;
qCritical() << " hwapi::hwapi() APP_EXTENDED_VERSION:" << APP_EXTENDED_VERSION;
qCritical() << "hwapi::hwapi() APP_EXTENDED_VERSION_LIB:" << APP_EXTENDED_VERSION_LIB;
// create or attach shared memory segment
m_sharedMem = SharedMem::getShm(sizeof(SharedMem));
@@ -59,28 +51,13 @@ hwapi::hwapi(QWidget *parent) : QObject(parent)
qCritical() << "Creating/attaching shared memory failed";
}
Q_ASSERT_X(sizeof(SharedMem) != m_sharedMem->size(),
"compare sizes", "sizes different");
//if (shdMem_firstUse()) // für Master raus
// {
#ifdef THIS_IS_CA_MASTER
#ifdef THIS_IS_CA_SLAVE
#error "SLAVE LIB COMPILED INTO MASTER"
#endif
myDatif = new T_datif(this); // für die CAslave-Lib auskommentieren!
#endif
#ifdef THIS_IS_CA_SLAVE
#ifdef THIS_IS_CA_MASTER
#error "MASTER LIB COMPILED INTO MASTER"
#endif
#else
qCritical()<<"hwapi: error CAslave cannot include T_datif";
#endif
// }
@@ -138,6 +115,10 @@ hwapi::hwapi(QWidget *parent) : QObject(parent)
void hwapi::hwapi_slotPayProc(void)
{
//cash_paymentProcessing();
//doors_supervise();
//dcBL_cycle();
}
@@ -1811,8 +1792,6 @@ void hwapi::prn_sendText(QByteArray *buf) const
uint16_t nn, pp, mm, leng_byt, leng_blk, llb, freeStak;
uint8_t tmp66[66];
qCritical() << __PRETTY_FUNCTION__ << "RESET DC DATA VALID";
epi_clearDynMachineConditions(); // 24.6.23
gpi_storeDcDataValid(0);
@@ -2917,8 +2896,6 @@ bool hwapi::prn_printTemplate(uint8_t nrOftemplate) const
{
// return true if sending, false if cmd-stack is full
qCritical() << __PRETTY_FUNCTION__ << "RESET DC DATA VALID";
epi_clearDynMachineConditions(); // 24.6.23
gpi_storeDcDataValid(0);
@@ -3023,8 +3000,6 @@ bool hwapi::log_getVaultRecord(struct T_vaultRecord *retVR) const
bool hwapi::prn_printAccountReceipt(void) const
{
qCritical() << __PRETTY_FUNCTION__ << "RESET DC DATA VALID";
epi_clearDynMachineConditions(); // 24.6.23
gpi_storeDcDataValid(0);
return sendFDcmd_set(154, 0,0, 0,0,0,0);
@@ -3032,8 +3007,6 @@ bool hwapi::prn_printAccountReceipt(void) const
bool hwapi::prn_printTestTicket(void) const
{
qCritical() << __PRETTY_FUNCTION__ << "RESET DC DATA VALID";
// return true if sending to DC OK, false if cmd-stack is full
epi_clearDynMachineConditions(); // 24.6.23
gpi_storeDcDataValid(0);
@@ -3089,9 +3062,7 @@ bool hwapi::cash_cancelPayment(void) const
{
// DB1: 1=encash 2=cancel & return coins
// 3=stop and keep coins in escrow
//epi_setNowCoinPay(false); // new since 20.9.23
// am 6.12.23 wieder raus, waehrend Druck und wechseln auch schnell abfragen
epi_setNowCoinPay(false); // new since 20.9.23
//qCritical() << "cash cancel payment and return coins";
return sendFDcmd_set(156, 0,0, 2,0,0,0);
}
@@ -3101,8 +3072,7 @@ bool hwapi::cash_stopPayment(void) const
{
// DB1: 1=encash 2=cancel & return coins
// 3=stop and keep coins in escrow
//epi_setNowCoinPay(false); // new since 20.9.23
// am 6.12.23 wieder raus, waehrend Druck und wechseln auch schnell abfragen
epi_setNowCoinPay(false); // new since 20.9.23
//qCritical() << "cash stop payment and keep coins in escrow";
// qCritical() << "emitting signal StopByPushbutton 2";
emit hwapi_payStopByPushbutton();
@@ -3463,8 +3433,6 @@ bool hwapi::prn_printKombiticket(uint8_t nrOfKombi) const
if ((nrOfKombi<1) || (nrOfKombi>8))
return false;
qCritical() << __PRETTY_FUNCTION__ << "RESET DC DATA VALID";
epi_clearDynMachineConditions(); // 24.6.23
gpi_storeDcDataValid(0);
@@ -3595,8 +3563,6 @@ bool hwapi::log_getVaultData(uint8_t *data) const
// new from 1.8.23
bool hwapi::prn_printOneAccountReceipt(uint16_t accountNr) const
{
qCritical() << __PRETTY_FUNCTION__ << "RESET DC DATA VALID";
// print one out of eight stored last accounting receipts
// function log_getHoldAccountNumbers() gives a list of acc-Nr. of the stored receipts
epi_clearDynMachineConditions(); // 24.6.23
@@ -4416,7 +4382,6 @@ QObject const *hwapi::getAPI() {
}
bool hwapi::dcDownloadRequest(QString const &dcFileToDownload) const {
// called by worker-thread (see atbupdatetool)
SharedMem *data = SharedMem::getData();
if (!data) {
return false;
@@ -4440,15 +4405,9 @@ bool hwapi::dcDownloadRequest(QString const &dcFileToDownload) const {
}
bool hwapi::dcDownloadRequested() const {
SharedMem *data = SharedMem::getData();
Q_ASSERT_X(data != nullptr, "check", "pointer invalid");
Q_ASSERT_X((void *)data != m_sharedMem->data(), "compare pointers", "pointers different");
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;
SharedMem const *data = SharedMem::getData();
// should be false at entry
return data ? data->m_downLoadDC.m_requested.load() : false;
}
bool hwapi::dcDownloadResetRequest() const {
@@ -4460,11 +4419,13 @@ bool hwapi::dcDownloadResetRequest() const {
}
bool hwapi::dcDownloadRequestAck() const {
// called by download-thread
SharedMem *data = SharedMem::getData();
if (data) {
data->m_downLoadDC.m_running = true;
data->m_downLoadDC.m_finished = false;
if (data->m_downLoadDC.m_requested) {
data->m_downLoadDC.m_requested = false;
data->m_downLoadDC.m_running = true;
data->m_downLoadDC.m_finished = false;
}
}
return false;
}
@@ -4474,16 +4435,14 @@ bool hwapi::dcDownloadRunning() const {
if (data) {
int cnt = 10;
while (--cnt > 0) {
bool running = data->m_downLoadDC.m_running;
bool finished = data->m_downLoadDC.m_finished;
if ((running == true) && (finished == false)) {
// see dcDownloadRequestAck()
break;
}
if (cnt < 3) {
qCritical() << "DOWNLOAD THREAD NOT RUNNING" << running << finished;
}
QThread::msleep(500);
bool running = data->m_downLoadDC.m_running.load();
bool finished = data->m_downLoadDC.m_finished.load();
if (!running || finished) {
if (cnt < 3) {
qCritical() << "DOWNLOAD THREAD NOT RUNNING" << running << finished;
}
QThread::msleep(500);
} else break;
}
// qCritical() << "DOWNLOAD RUNNING" << cnt << (cnt > 0);
return (cnt > 0);
@@ -4492,16 +4451,18 @@ bool hwapi::dcDownloadRunning() const {
}
void hwapi::dcDownloadThreadFinalize(DownloadThread *dthread) {
Q_UNUSED(dthread);
// delete dthread;
delete dthread;
m_downloadThread = nullptr;
}
bool hwapi::dcDownloadFinished() {
int cnt = 10;
while (dcDownloadRunning()) {
if (--cnt == 0) {
return false;
SharedMem const *data = SharedMem::getDataConst();
if (data) {
int cnt = 10;
while ((--cnt > 0) &&
((data->m_downLoadDC.m_running.load() == true) &&
(data->m_downLoadDC.m_finished.load() == false))) {
QThread::sleep(1);
}
//if (cnt > 0) {
@@ -4510,13 +4471,12 @@ bool hwapi::dcDownloadFinished() {
// return true;
//}
}
return true;
return false;
}
// download thread
bool hwapi::dcDownloadThreadStart() {
// called by timer in datIf.cpp: T_datif::datif_cycleSend()
m_downloadThread = new DownloadThread(this);
if (m_downloadThread) {
m_downloadThread->start();
@@ -4548,7 +4508,6 @@ bool hwapi::dcDownloadReportThreadStart() { // only start reporting thread
if (cnt > 0) {
m_reportingThread = new ReportingThread(this);
if (m_reportingThread) {
m_reportingThread->moveToThread(QApplication::instance()->thread());
m_reportingThread->start();
cnt = 10;
while (--cnt > 0 && !dcDownloadReportThreadRunning()) {
@@ -4580,9 +4539,7 @@ void hwapi::dcDownloadReportThreadQuit() {
}
bool hwapi::dcDownloadReportThreadFinished() const {
// if the pointer to the underlying c++-object is not valid, the thread
// counts as finished
return m_reportingThread ? m_reportingThread->isFinished() : true;
return m_reportingThread ? m_reportingThread->isFinished() : false;
}
bool hwapi::dcDownloadReportStart() const {
@@ -4608,10 +4565,8 @@ bool hwapi::dcDownloadReportFinished() {
}
if (dcDownloadReportThreadFinished()) {
if (m_reportingThread) {
delete m_reportingThread;
m_reportingThread = nullptr;
}
delete m_reportingThread;
m_reportingThread = nullptr;
}
return true;

View File

@@ -1,16 +1,5 @@
#ifdef WIN32
#include <QCoreApplication>
#include "tslib.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
return a.exec();
}
#else
#ifndef WIN32
#undef _FORTIFY_SOURCE
@@ -18,11 +7,11 @@ int main(int argc, char *argv[])
#include <stdio.h>
// Must define the interpreter to be the dynamic linker
//#ifdef __LP64__
//#error "__LP64__ not defined for PTU5"
//#else
//const char service_interp[] __attribute__((section(".interp"))) = "/lib/ld-linux-armhf.so.3";
//#endif
#ifdef __LP64__
#error "__LP64__ not defined for PTU5"
#else
const char service_interp[] __attribute__((section(".interp"))) = "/lib/ld-linux-armhf.so.3";
#endif
int main(int argc, char *argv[]) {

View File

@@ -4,15 +4,10 @@
#include <QDateTime>
#include <QDebug>
#include <QApplication>
#include <QCoreApplication>
#include <cmath>
ReportingThread::ReportingThread(hwapi *hw)
: m_hw(hw)
, m_fileToDownload(m_hw->dcDownloadFileName()) {
// , m_f([](QString const&){}) {
}
ReportingThread::~ReportingThread() {
@@ -22,10 +17,7 @@ ReportingThread::~ReportingThread() {
// each component which has connects for the corresponding signals.
void ReportingThread::run() {
qCritical()
<< QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "START REPORT THREAD"
<< "(PART OF APPLICATION" << QCoreApplication::applicationName() << ")";
qCritical() << QDateTime::currentDateTime() << "START DOWNLOAD THREAD";
static QString report("");
@@ -33,9 +25,9 @@ void ReportingThread::run() {
while (!m_hw->dcDownloadGetRunning()) {
if (--cnt > 0) {
report = QString("%1 waiting for download to start %2")
.arg(QDateTime::currentDateTime().time().toString(Qt::ISODate))
.arg(QDateTime::currentDateTime().toString(Qt::ISODate))
.arg(cnt);
qCritical() << "(" << __func__ << ":" << __LINE__ << ") STATUS" << report;
qCritical() << __LINE__ << "STATUS" << report;
emit m_hw->hwapi_reportDCDownloadStatus(report);
QThread::sleep(1);
} else break;
@@ -104,37 +96,28 @@ void ReportingThread::run() {
qCritical() << QDateTime::currentDateTime() << "TOTAL BLOCKS" << totalBlocks;
if (totalBlocks) {
QDateTime const start = QDateTime::currentDateTime();
qint64 const start = QDateTime::currentMSecsSinceEpoch();
double durationMillis = 0;
uint16_t currentBlockNumber = 0;
uint16_t prevBlockNumber = ~0;
while (m_hw->dcDownloadGetRunning()) {
currentBlockNumber = m_hw->dcDownloadGetCurrentBlockNumber();
if (prevBlockNumber != currentBlockNumber) {
double durationSecs = start.secsTo(QDateTime::currentDateTime());
double const timeAveragePerBlock = (currentBlockNumber > 0) ? (durationSecs / currentBlockNumber) : durationSecs;
long estimatedSecondsLeft = lround((timeAveragePerBlock * (totalBlocks - currentBlockNumber)));
long estimatedMinutesLeft =
((estimatedSecondsLeft % 60) == 0) ?
(estimatedSecondsLeft / 60) :
((estimatedSecondsLeft + 60) / 60);
estimatedSecondsLeft = (estimatedSecondsLeft % 60);
durationMillis += QDateTime::currentMSecsSinceEpoch() - start;
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(estimatedMinutesLeft)
.arg(estimatedSecondsLeft, 2);
double const timeAveragePerBlock = (currentBlockNumber > 0) ? (durationMillis / currentBlockNumber) : durationMillis;
double const estimatedSecondsLeft = (timeAveragePerBlock * (totalBlocks - currentBlockNumber)) / 1000.0;
qCritical() << m_hw << "RT report" << report;
double percent = ((double)currentBlockNumber / (double)totalBlocks) * 100.0;
report = QString(": total blocks %1, current block %2 [%3] (est. time left: %4s)")
.arg(totalBlocks)
.arg(currentBlockNumber)
.arg(percent, 0, 'f', 2)
.arg(estimatedSecondsLeft, 0, 'f', 2);
emit m_hw->hwapi_reportDCDownloadStatus(report);
qCritical() << "RT report" << report;
prevBlockNumber = currentBlockNumber;
}
emit m_hw->hwapi_reportDCDownloadStatus(report);
QThread::msleep(100);
}

View File

@@ -2,6 +2,7 @@
#include <QDebug>
#include "controlBus.h"
#include "dcBL.h"
#include "interfaces.h"
static uint32_t hwapi_lastStartAmount;
static uint32_t hwapi_lastTotalAmount;
@@ -28,31 +29,25 @@ T_runProc::T_runProc()
QTimer *runProc_callProcesses = new QTimer();
connect(runProc_callProcesses, SIGNAL(timeout()), this, SLOT(runProc_slotProcess()));
runProc_callProcesses->setSingleShot(false);
runProc_callProcesses->start(10); // in ms
runProc_callProcesses->start(100); // in ms
hwapi_lastDoorState=0; // default: all doors (should be) closed, coin box inserted
// bit0: upper door 1:middle 2:lower 3=cash-box out
// hwapi_triggerBL = new QTimer();
// connect(hwapi_triggerBL, SIGNAL(timeout()), this, SLOT(bl_performComplStart()));
// hwapi_triggerBL->setSingleShot(false);
// hwapi_triggerBL->stop();
myTO = new QTimer();
myTO->setSingleShot(true);
myTO->start(200);
hwapi_triggerBL = new QTimer();
connect(hwapi_triggerBL, SIGNAL(timeout()), this, SLOT(bl_performComplStart()));
hwapi_triggerBL->setSingleShot(false);
hwapi_triggerBL->stop();
}
void T_runProc::runProc_slotProcess(void)
{
#ifndef THIS_IS_CA_MASTER
cash_paymentProcessing();
doors_supervise();
bl_performComplStart(); // neu 1.12.23
dcBL_cycle();
#endif
}
bool T_runProc::cash_startPayment(uint32_t amount)
@@ -165,7 +160,6 @@ uint8_t T_runProc::cash_paymentProcessing(void)
sub_getDynMachineConditions(&myDynMachCond);
payInProg= myDynMachCond.paymentInProgress;
// Version Szeged: aug2023
// 0: stopped by timeout
// 1: running 2: wait4lastCoin
// 3: payment stopped manually, coins in Escrow
@@ -175,26 +169,9 @@ uint8_t T_runProc::cash_paymentProcessing(void)
// 7: coins returned 2 cases: due to cancel-button or printer-error
// 8: CoinChecker or MDB on Error
// since Schoenau with bill and changer, nov2023
//0 = no payment
//will be set to 1 by cash_startCollection()
//neu 1: wait for devices getting ready for payment
//2 = payment,
//3 = wait for last coin/bill
//4 = Bezahlvorgang manuell beendet
//5 = payment stopped autom, amount collected, coins in Escrow
//6 = Bezahlvorgang beendet weil ZK voll
//4,5,6: payment done, keep on polling, wait for cash or return command
//7 = encash collected money from coin escrow into cash box
//8 = return "amountToReturn", can be complete inserted amount or only overpayment
//9 = wait for changer result
//10= print refund receipt with "amountToReturn"
// qCritical() << "emitting signal payCancelled";
// emit runProc_payCancelled();
/*
// gabs bei Szeged, jetzt nicht mehr:
if (payInProg==8)
{
// coin checker faulty, cannot start
@@ -205,11 +182,11 @@ uint8_t T_runProc::cash_paymentProcessing(void)
emit runProc_coinCollectionAborted();
//sendFDcmd_set(156, 0,0, 2,0,0,0); // cancel payment
}
return 10; // error cannot start
}*/
// if (empState>=10 && empState<=12 && (payInProg==1 || payInProg==2) ) // Szeged
if ( payInProg==2 ) //8.12.23
return 10; // error cannot start
}
if (empState>=10 && empState<=12 && (payInProg==1 || payInProg==2) )
{
// coin acceptance is active now:
if (hwapi_paymentStarted==1) // && (( payInProg==0) || ( payInProg>5))) //16.6.23
@@ -242,8 +219,7 @@ uint8_t T_runProc::cash_paymentProcessing(void)
} else
//if (payInProg==3) // user pressed "Next/Continue", keep coin
if (payInProg==4) // user pressed "Next/Continue", keep coin since nov2023
if (payInProg==3) // user pressed "Next/Continue", keep coin
{
hwapi_paymentStarted++;
collActiv=3;
@@ -251,8 +227,7 @@ uint8_t T_runProc::cash_paymentProcessing(void)
emit runProc_payStopByPushbutton();
} else
//if (payInProg==4) // max achieved, keep coins
if (payInProg==5) // max achieved, keep coins since nov2023
if (payInProg==4) // max achieved, keep coins
{
hwapi_paymentStarted++;
collActiv=4;
@@ -260,8 +235,7 @@ uint8_t T_runProc::cash_paymentProcessing(void)
emit runProc_payStopByMax();
} else
//if (payInProg==5) // escrow full, keep coins
if (payInProg==6) // escrow full, keep coins since nov2023
if (payInProg==5) // escrow full, keep coins
{
hwapi_paymentStarted++;
collActiv=5;
@@ -269,14 +243,14 @@ uint8_t T_runProc::cash_paymentProcessing(void)
emit runProc_payStopByEscrow();
}
// 5.10.23 raus, geht auf 99 wenn Betrag erreicht, ist aber kein fehler
/* 5.10.23 raus, geht auf 99 wenn Betrag erreicht, ist aber kein fehler
if ( (empState<10) || (empState>12)) // error
{
//collActiv=13;
//hwapi_paymentStarted=90;
//qCritical() << "emitting signal payStopByError" << empState;
//emit runProc_payStopByError();
}
collActiv=13;
hwapi_paymentStarted=90;
qCritical() << "emitting signal payStopByError" << empState;
emit runProc_payStopByError();
} */
}
@@ -284,8 +258,7 @@ uint8_t T_runProc::cash_paymentProcessing(void)
{
// coin collection finished, but coins kept until printing done
collActiv=2;
//if (payInProg==6) // coins encashed
if (payInProg==7) // coins encashed since nov2023
if (payInProg==6) // coins encashed
{
collActiv=6;
hwapi_paymentStarted++;
@@ -293,8 +266,7 @@ uint8_t T_runProc::cash_paymentProcessing(void)
emit runProc_coinProcessJustStopped();
} else
//if (payInProg==7) // coins returned, printing failed
if (payInProg==0) // coins returned, printing failed since nov2023
if (payInProg==7) // coins returned, printing failed
{
collActiv=7;
hwapi_paymentStarted++;
@@ -641,11 +613,8 @@ void T_runProc::bl_rebootDC(void)
// BL is working for 5s after power-on-reset.
uint8_t len, buf[20];
memset(buf, 0x00, sizeof(buf));
len=dcBL_restartDC(buf);
qCritical() << __func__ << QByteArray((const char *)buf, len).toHex(':');
sendWRcmd_setSendBlock160(len, buf);
}
@@ -655,13 +624,8 @@ void T_runProc::bl_startBL(void)
// otherwise the BL jumps to normal DC application
uint8_t len, buf[20];
memset(buf, 0x00, sizeof(buf));
len=dcBL_activatBootloader(buf);
qCritical() << __func__ << QByteArray((const char *)buf, len).toHex(':');
sendWRcmd_setSendBlock160(len, buf);
epi_setNowIsBootload(true);
}
@@ -669,11 +633,8 @@ void T_runProc::bl_checkBL(void)
{
// call this function in order to get information, afterwards use "bl_isUp()"
uint8_t len, buf[20];
memset(buf, 0x00, sizeof(buf));
len=dcBL_readFWversion(buf);
qCritical() << __func__ << QByteArray((const char *)buf, len).toHex(':');
sendWRcmd_setSendBlock160(len, buf);
}
@@ -693,7 +654,7 @@ bool T_runProc::bl_isUp(void)
receivedData[3]==45 && receivedData[4] ==95 && receivedData[5]==176)
{
qDebug() << "got BL response to readFWversion";
//epi_clrRawReceivedString();
epi_clrRawReceivedString();
return true;
}
// response to "start BL"
@@ -701,7 +662,7 @@ bool T_runProc::bl_isUp(void)
receivedData[3]==223 && receivedData[4] ==131 )
{
qDebug() << "hwapi_bl_isUp: got BL response to start";
//epi_clrRawReceivedString();
epi_clrRawReceivedString();
return true;
}
}
@@ -716,8 +677,7 @@ void T_runProc::bl_completeStart(void)
bool T_runProc::bl_performComplStart(void)
{
bool result;
// must be called cyclic by timer
static uint8_t retryCtr;
if ((bl_startupStep<1) || (bl_startupStep>10))
@@ -731,69 +691,58 @@ bool T_runProc::bl_performComplStart(void)
if (bl_startupStep==2)
{
qDebug()<<"rebooting";
bl_rebootDC();
myTO->stop();
myTO->start(500);
hwapi_triggerBL->stop();
hwapi_triggerBL->start(1000); // call next step in 1s
retryCtr=0;
bl_startupStep++;
} else
if (bl_startupStep==3)
{
if (!myTO->isActive())
{
qDebug()<<"starting BL";
bl_startBL();
myTO->stop();
myTO->start(500);
bl_startupStep++;
}
//qDebug()<<"starting BL";
bl_startBL();
hwapi_triggerBL->stop();
hwapi_triggerBL->start(100);
bl_startupStep++;
} else
if (bl_startupStep==4)
{
if (!myTO->isActive())
{
qDebug()<<"checking BL";
bl_checkBL();
myTO->stop();
myTO->start(200);
bl_startupStep++;
}
//if (!myTO->isActive())
//{
bl_checkBL();
hwapi_triggerBL->stop();
hwapi_triggerBL->start(100);
bl_startupStep++;
//}
} else
if (bl_startupStep==5)
{
if (!myTO->isActive())
hwapi_triggerBL->stop();
if (bl_isUp())
{
qDebug()<<"step 5";
result = bl_isUp();
qDebug()<<"BL result: "<< result;
if (result)
bl_startupStep=99;
// BL is up and running
} else
{
retryCtr++; // start again
if (retryCtr>=15)
{
bl_startupStep=99;
qDebug()<<"BL is working now...";
// BL is up and running
return true;
//qDebug()<<"BL error!!!";
} else
{
retryCtr++; // start again
if (retryCtr>=10)
{
bl_startupStep=99;
qDebug()<<"BL error!!!";
} else
{
bl_startupStep=3;
myTO->stop();
myTO->start(200);
qDebug()<<"BL retry...";
}
bl_startupStep=3;
//qDebug()<<"BL retry...";
}
}
}
return false;
return true;
}

View File

@@ -1,13 +1,7 @@
#include "shared_mem_buffer.h"
#include <QDebug>
#include <QFile>
#include <QString>
#include <QTextStream>
#include <QDateTime>
#include <QCoreApplication>
#include <atomic>
#include <algorithm>
#ifdef QT_POSIX_IPC
// 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
#error "QT_POSIX_IPC defined"
#else
#ifdef linux
#include <stdlib.h>
#include <string.h>
#ifdef __linux__
#include <sys/ipc.h> // ftok
#endif
#endif
//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 *SharedMem::getShm(std::size_t size) {
static QSharedMemory shMem;
if (size > 0) {
#ifdef linux
static const long nativeKey = ftok("/etc/os-release", 'H');
static const QString fkey = std::to_string(nativeKey).c_str();
//static const QString fkey = "0123456?000=7";
#ifdef __linux__
//static const long nativeKey = ftok("/etc/os-release", 'H');
//static const QString fkey = std::to_string(nativeKey).c_str();
static const QString fkey = "0123456?000=7";
#else
static const QString fkey = "0123456?000=9";
#endif
qCritical() << __func__ << ":" << __LINE__ << ": size" << size;
shMem.setKey(fkey);
if (!shMem.isAttached()) {
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;
} else {
if (shMem.error() == QSharedMemory::AlreadyExists) {
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;
}
}
@@ -140,13 +43,6 @@ QSharedMemory *SharedMem::getShm(std::size_t size) {
qCritical() << shMem.nativeKey() << shMem.key() << shMem.data()
<< shMem.error() << shMem.errorString();
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;

View File

@@ -12,7 +12,6 @@
// store power on/off condition of the devices to control the data request
//static bool indat_savePrnPwr;
@@ -64,42 +63,66 @@ bool indat_isMdbOn()
void gpi_storeHWver(QString text)
{
QString hwVersion((char const *)SharedMem::read()->indat_HWversion);
if (hwVersion != text) {
char const *p = text.toUtf8().constData();
if (qstrlen(p) > 0) {
memset(SharedMem::write()->indat_HWversion, 0, versionBufferLen);
memcpy(SharedMem::write()->indat_HWversion, p,
qMin((uint)versionBufferLen, qstrlen(p)) - 1);
}
}
// change Qstring to array of chars, because shared mem allowes no QString!
int nn, LL = text.length();
if (LL >= versionBufferLen)
LL=versionBufferLen-1; // leave place for termination
qCritical() << "HW TEXT" << epi_loadHWver();
for (nn=0; nn<LL; nn++)
{
SharedMem::write()->indat_HWversion[nn] = text.at(nn).toLatin1();
}
for (nn=LL; nn<versionBufferLen; nn++)
SharedMem::write()->indat_HWversion[nn] =0;
}
QString epi_loadHWver(void)
{
return QString((char const*)SharedMem::read()->indat_HWversion);
// load array of chars from SM and change to QString
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)
{
QString swVersion((char const *)SharedMem::read()->indat_SWversion);
if (swVersion != text) {
char const *p = text.toUtf8().constData();
if (qstrlen(p) > 0) {
memset(SharedMem::write()->indat_SWversion, 0, versionBufferLen);
memcpy(SharedMem::write()->indat_SWversion, p,
qMin((uint)versionBufferLen, qstrlen(p)) - 1);
}
}
int nn, LL = text.length();
if (LL >= versionBufferLen)
LL=versionBufferLen-1; // leave place for termination
for (nn=0; nn<LL; nn++)
{
SharedMem::write()->indat_SWversion[nn] = text.at(nn).toLatin1();
}
for (nn=LL; nn<versionBufferLen; nn++)
SharedMem::write()->indat_SWversion[nn] =0;
qCritical() << "SW TEXT" << epi_loadSWver();
}
QString epi_loadSWver(void)
{
return QString((char const*)SharedMem::read()->indat_SWversion);
int nn, LL = versionBufferLen;
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)
@@ -1961,7 +1984,7 @@ void epi_iniVRstorage(void)
void gpi_storeVaultRecord(uint8_t blkNr, uint8_t *data )
{
uint16_t start=blkNr, ii;
qDebug()<<"storing vault data "<<blkNr;
//qDebug()<<"storing vault data "<<blkNr;
SharedMem::write()->store_gotNrBlocksOfVaultRec |= (1<<start); // setze pro Block ein bit, wir brauchen block 0...5
// also muss store_gotNrBlocksOfVaultRec auf 0x1F stehen
start<<=6; // *64
@@ -2031,50 +2054,13 @@ uint16_t epi_getNrOfCoinsInCashBox(void)
void gpi_storeDcDataValid(bool isVal)
{
bool now=SharedMem::read()->store_DcDataAreValid;
if (isVal != now)
{
SharedMem::write()->store_DcDataAreValid = isVal;
#ifdef THIS_IS_CA_MASTER
qDebug()<<"master lib sets DcDataValid to "<<isVal;
#else
qDebug()<<"slave lib sets DcDataValid to "<<isVal;
#endif
}
SharedMem::write()->store_DcDataAreValid = isVal;
}
void epi_setDcDataValid(void)
{
bool now=SharedMem::read()->store_DcDataAreValid;
if (now==false)
{
SharedMem::write()->store_DcDataAreValid = true;
#ifdef THIS_IS_CA_MASTER
qDebug()<<"master lib SET DcDataValid";
#else
qDebug()<<"slave lib SET DcDataValid";
#endif
}
}
void epi_resetDcDataValid(void)
{
bool now=SharedMem::read()->store_DcDataAreValid;
if (now==true)
{
SharedMem::write()->store_DcDataAreValid = false;
#ifdef THIS_IS_CA_MASTER
qDebug()<<"master lib RESET DcDataValid";
#else
qDebug()<<"slave lib RESET DcDataValid";
#endif
}
}
bool epi_areDcDataValid()
{
return SharedMem::read()->store_DcDataAreValid;
}
// ....................................................................................