diff --git a/ATBUpdateTool.ini b/ATBUpdateTool.ini new file mode 100644 index 0000000..4279629 --- /dev/null +++ b/ATBUpdateTool.ini @@ -0,0 +1,18 @@ +[REPOSITORY_URL] +repository-url="https://git.mimbach49.de/GerhardHoffmann" + +[DIRECTORIES] +plugin-directory="/usr/lib/" +working-directory="/opt/app/tools/atbupdate/" + +[PLUGINS] +plugin-name="libCAslave.so" + +[FLAGS] +no-psa-hardware-update=false +dry-run=false +extended-version=false +yocto-version=false +yocto-install=false +always-download-config=false +always-download-dc=false diff --git a/DCPlugin/.gitignore b/DCPlugin/.gitignore deleted file mode 100644 index ccd3243..0000000 --- a/DCPlugin/.gitignore +++ /dev/null @@ -1,41 +0,0 @@ -# C++ objects and libs - -*.slo -*.lo -*.o -*.a -*.la -*.lai -*.so -*.dll -*.dylib - -# Qt-es - -*.pro.user -*.pro.user.* -moc_*.cpp -qrc_*.cpp -Makefile -Makefile.* -*-build-* - -# -*.autosave -ui_*.h -version.h -version.txt - -packages/* -*.pro.orig -Output/setup.exe -.directory - -*~ -resources/icons/*.png -resources/icons/*.jpg -resources/icons/*.gif -resources/style/*.qss -text/*.html -!text/*_template.html -text/*.xml diff --git a/DCPlugin/DCPlugin.pri b/DCPlugin/DCPlugin.pri deleted file mode 100644 index 1f6add0..0000000 --- a/DCPlugin/DCPlugin.pri +++ /dev/null @@ -1,25 +0,0 @@ -INCLUDEPATH += $${PWD}/include -DEPENDPATH += $${PWD} - -HEADERS += $${PWD}/include/com.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 - -SOURCES += $${PWD}/src/com.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 diff --git a/DCPlugin/DCPlugin.pro b/DCPlugin/DCPlugin.pro deleted file mode 100644 index b968520..0000000 --- a/DCPlugin/DCPlugin.pro +++ /dev/null @@ -1,94 +0,0 @@ -TEMPLATE = lib -CONFIG += plugin -#CONFIG += c++11 console -#CONFIG -= app_bundle -#QT += widgets -QT -= gui -QT += widgets serialport - -INCLUDEPATH += $${PWD}/plugins -INCLUDEPATH += $${PWD}/include - -QMAKE_CXXFLAGS += -Wno-deprecated-copy - -# default -ARCH = PTU5 - -include(DCPlugin.pri) - -contains( CONFIG, DesktopLinux ) { - QMAKE_CC = ccache $$QMAKE_CC - QMAKE_CXX = ccache $$QMAKE_CXX - QMAKE_CXXFLAGS += -std=c++11 - # QMAKE_CXXFLAGS += -Wno-deprecated-ctor - linux-clang { QMAKE_CXXFLAGS += -Qunused-arguments } - ARCH = DesktopLinux -} - -contains( CONFIG, PTU5 ) { - # QMAKE_CC = ccache $$QMAKE_CC - # QMAKE_CXX = ccache $$QMAKE_CXX - QMAKE_CXXFLAGS += -std=c++11 - linux-clang { QMAKE_CXXFLAGS += -Qunused-arguments } - CONFIG += link_pkgconfig - ARCH = PTU5 -} - -contains( CONFIG, PTU5_YOCTO ) { - greaterThan(QT_MAJOR_VERSION, 4): QT += serialport - PTU5BASEPATH = /opt/devel/ptu5 - ARCH = PTU5 - - # add qmqtt lib - #LIBS += -lQt5Qmqtt -} - -TARGET = ATBDeviceControllerPlugin -#DESTDIR = ../plugins -INTERFACE = DeviceController -INTERFACE_DEFINITION = $${PWD}/include/ATBAPP/DeviceControllerInterface.h - -DEFINES += DEVICECONTROLLERPLUGIN_LIBRARY - -# The following define makes your compiler emit warnings if you use -# any Qt feature that has been marked deprecated (the exact warnings -# depend on your compiler). Please consult the documentation of the -# deprecated API in order to know how to port your code away from it. -DEFINES += QT_DEPRECATED_WARNINGS - -# You can also make your code fail to compile if it uses deprecated APIs. -# In order to do so, uncomment the following line. -# You can also select to disable deprecated APIs only up to a certain version of Qt. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - - - -# Default rules for deployment. -#qnx: target.path = /tmp/$${TARGET}/bin -#else: unix:!android: target.path = /opt/$${TARGET}/bin -#!isEmpty(target.path): INSTALLS += target - -# ATBAPP interface -HEADERS += \ - src/ATBAPP/ATBAPPplugin.h \ - src/ATBAPP/DeviceControllerInterface.h \ - src/ATBAPP/ATBHealthEvent.h \ - src/ATBAPP/ATBDeviceControllerPlugin.h - -SOURCES += \ - src/ATBAPP/ATBHealthEvent.cpp \ - src/ATBAPP/ATBDeviceControllerPlugin.cpp - -DISTFILES += \ - generate-version.sh - - -# Define how to create version.h -VERSION_H = $$PWD/include/version.h -version.output = $$PWD/include/version.h -version.commands = $$PWD/generate-version.sh $${ARCH} $${TARGET} $${INTERFACE} $${INTERFACE_DEFINITION} $${VERSION_H} -version.depends = FORCE -version.input = VERSION_H -version.variable_out = HEADERS -QMAKE_EXTRA_COMPILERS += version -QMAKE_CLEAN += $${PWD}/include/version.h diff --git a/DCPlugin/README.md b/DCPlugin/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/DCPlugin/generate-version.sh b/DCPlugin/generate-version.sh deleted file mode 100755 index dcbcdae..0000000 --- a/DCPlugin/generate-version.sh +++ /dev/null @@ -1,155 +0,0 @@ -#!/bin/bash - -VERSION_STRING="" - -#GIT='/cygdrive/c/Program Files \(x86\)/Git/bin/git' -GIT=git - - - - -parse_git_branch () { - $GIT branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/" -} - - -ARCH=$1 -TARGET=$2 -INTERFACE=$3 -INTERFACE_DEFINITION=$4 -VERSION_H=$5 - -SCRIPT=$(readlink -f $0) -SCRIPTPATH=`dirname $SCRIPT` -OUTPUTDIR=$(pwd) -echo " current dir is : " $(pwd) -echo $SCRIPT -echo $SCRIPTPATH - -echo "changing dir to script path: " $SCRIPTPATH -cd $SCRIPTPATH - -# set version string ################################################################## -if [ -z $VERSION_STRING ] ; then - VERSION_STRING=$(date +%Y%m%d_%H%M) -fi -GIT_DESCRIBE=$($GIT describe) -GIT_BRANCH=$(parse_git_branch) - -# extract path from branchname: -IFS='_' read -ra TMP_ARRAY <<< "${GIT_BRANCH}" -BRANCH_PATH=${TMP_ARRAY[0]} - - - -# detect if we have a development version: -if [ ${#TMP_ARRAY[1]} -gt 0 ] ; then - DEV_SUFFIX="_dev" -else - DEV_SUFFIX="" -fi - -# detect if git status is dirty -GIT_DESCRIBE_DIRTY=$($GIT describe --dirty) -if [ "${GIT_DESCRIBE_DIRTY:(-6)}" == "-dirty" ] ; then - DIRTY_SUFFIX="_dirty" -else - DIRTY_SUFFIX="" -fi - - -if [ -n "$DIRTY_SUFFIX" ] || [ -n "$DEV_SUFFIX" ] ; then - DEVDIRTY=true -else - DEVDIRTY=false -fi - - -# extract interface definition - -# -#Q_DECLARE_INTERFACE(CCInterface, -# "eu.atb.ptu.plugin.CCInterface/2.9.0") -# -> extract whole string within quotation marks -INTERFACE_VERSION=$(grep 'eu.atb.ptu.plugin.' ${INTERFACE_DEFINITION}) -# get string within quotes: -INTERFACE_VERSION=`echo ${INTERFACE_VERSION} | awk -F \" '{print $2}'` - - -# -# write version.h - - -echo " TARGET is: $TARGET" -echo " ARCH is: $ARCH" -echo " " -echo " PluginName: $TARGET" -echo " Interface: $INTERFACE" -echo " InterfaceVersion: $INTERFACE_VERSION" -echo " " -echo " new version is: $VERSION_STRING" -echo " git describe is: $GIT_DESCRIBE" -echo " git branch is: $GIT_BRANCH" -echo " branch-path is: $BRANCH_PATH" -echo " " - -echo " dev suffix: $DEV_SUFFIX" -echo " dirty suffix: $DIRTY_SUFFIX" - - -PLUGIN_VERSION=${VERSION_STRING} -#ATB_QT_GIT_DESCRIBE=${GIT_DESCRIBE}_${GIT_BRANCH} -PLUGIN_GIT_DESCRIBE=${GIT_DESCRIBE}_${BRANCH_PATH}${DEV_SUFFIX}${DIRTY_SUFFIX} - -#TARGET=IngenicoZVT_CCPlugin - - -# build version.h ##################################################################### - -echo " building new version info (version.h) ..." - - - - -echo "#ifndef VERSION_H" > ${VERSION_H} -echo "#define VERSION_H" >> ${VERSION_H} -echo "" >> ${VERSION_H} -echo "" >> ${VERSION_H} -echo "#define INTERFACE_VERSION \"${INTERFACE_VERSION}\"" >> ${VERSION_H} -echo "#define PLUGIN_VERSION \"${PLUGIN_VERSION}\"" >> ${VERSION_H} -echo "" >> ${VERSION_H} -echo "#define PLUGIN_GIT_DESCRIBE \"${PLUGIN_GIT_DESCRIBE}\"" >> ${VERSION_H} -echo "" >> ${VERSION_H} -echo "" >> ${VERSION_H} - -cat <> ${VERSION_H} - -const std::string pluginInfoString = R"( -{ - "Interface": "${INTERFACE}", - "InterfaceVersion": "${INTERFACE_VERSION}", - "PluginName": "${TARGET}", - "Version": "${PLUGIN_VERSION}", - "git-describe": "${PLUGIN_GIT_DESCRIBE}", -} -)"; - -EOT - -echo "" >> ${VERSION_H} -echo "" >> ${VERSION_H} -if [ ${DEVDIRTY} == "true" ] ; then -echo "#define DEVDIRTY" >> ${VERSION_H} -echo "" >> ${VERSION_H} -echo "" >> ${VERSION_H} -fi -echo "#define SYSTEM_ARCH \"${ARCH}\"" >> ${VERSION_H} -echo "#define ARCH_${ARCH}" >> ${VERSION_H} -echo "" >> ${VERSION_H} -echo "" >> ${VERSION_H} -echo "#endif //VERSION_H" >> ${VERSION_H} - - - - - diff --git a/DCPlugin/include/com.h b/DCPlugin/include/com.h deleted file mode 100644 index 69a8ea4..0000000 --- a/DCPlugin/include/com.h +++ /dev/null @@ -1,105 +0,0 @@ -//CAT is always master, no receive before request - -#ifndef SER_H -#define SER_H -#include -#include -#include -#include -#include -#include "tslib.h" -#include "controlBus.h" - -#define MAXTELEGRAMLEN 90 - -// display all inputs and outputs in output window: -//#define PRINTALLDEBUGS 1 - -class T_com : public QMainWindow //, public QPlainTextEdit -{ - Q_OBJECT - - // complete send message (protocol frame) - QByteArray sendBuffer; //[MAXTELEGRAMLEN]; - uint16_t sendLen; // >0: Daten Sendebereit, nach senden wieder auf 0 setzen - - // right after reception: - QByteArray rawInput; //[MAXTELEGRAMLEN]; - uint16_t rawInLen; // 0: keine neuen Daten erhalten - -// QSerialPort *CatSerial = nullptr; - QSerialPort *CatSerial; - - //char oeffneSerialPort(); - char open_Serial_Port(); - void closeSerialPort(); - void receiveByLength(void); - -private slots: - void readSomeBytes(void); - void serialSendComplete(void); - //void incomingWake(void); //bool LevelOfTheBit); - void receiveTO(void); - void ser_ISR100ms(); - - - -public: - T_com(QWidget *parent = nullptr); - ~T_com(); - - QTimer *serRecTime; - - bool isPortOpen(void); - - void writeToSerial(const QByteArray &data, uint16_t sendLength); - - void receiveFixLen(int64_t nrOfbytesToReceive); - - bool readFromSerial(QByteArray &data, uint16_t &sendLength); - // retval: true: data available - -/* - uint8_t getAllPortPins(void); - // rs232pins: all signals bitwise coded in one byte: - // readback output: bit 0=TxD(=output) bit2=DTR (=output) bit 6=RTS (=output) - // unused inputs: bit1=RxD bit 3=DCD bit 5 = RING - // handshake inputs: bit 4=DSR (0x10) bit 7=CTS (0x80) - - bool getHSin_CTS(void); - // return the CTS Handshake input): true= high level (+8V) - - bool getHSin_DSR(void); - // return the DSR Handshake input): true= high level (+8V) - - bool setHSout_RTS(bool hsout); - // hsout true=positiv voltage +12V false= -12V - // retval: true=setting OK - - bool setHSout_DTR(bool hsout); - // hsout true=positiv voltage +12V false= -12V - // retval: true=setting OK -*/ - -signals: - void receivingFinished(); - void sendingFinished(); - //void wasWokenBySerialHandshake(); - -}; - - - -#endif // SER_H - - - - - - - - - - - - diff --git a/DCPlugin/include/controlBus.h b/DCPlugin/include/controlBus.h deleted file mode 100644 index 3dc8b11..0000000 --- a/DCPlugin/include/controlBus.h +++ /dev/null @@ -1,194 +0,0 @@ -#ifndef CONTROLBUS_H -#define CONTROLBUS_H - - -#include -#include "tslib.h" -#include - - -// /////////////////////////////////////////////////////////////////////////////////// -// control serial interface gui <--> serial -// /////////////////////////////////////////////////////////////////////////////////// - - -void epi_setSerial(int BaudNr, QString BaudStr, QString ComName, uint8_t connect); - // Actions: open serial port with parameters - -void epi_closeSerial(void); -// Actions: close serial port - -// Actions, GUI Buttons -> API, start cyclic transmission -void epi_startEmmision(char start); // 1: start sending activated - -//void epi_setPeriodicSendTimeVal(uint16_t val); - - -// Port -> API -void gpi_serialChanged(void); - // serial confirms that port was closed or opened - -// Actions, API -> serialPort -uint8_t gpi_getSerialConn(void); // connect if 1, disconnect if 0 - -int gpi_getBaudNr(void); - -QString gpi_getComPortName(void); - - -void gpi_serialIsOpen(bool offen); - -bool epi_isSerialPortOpen(); - // true: port is open false: port is closed - - - - - -// Meldung von TabCom an Datif: starte zyklische Sendung: -bool gpi_isEmmisionOn(void); - -//uint16_t gpi_getPeriodicSendTimeVal(); - -//bool gpi_PeriodicSendTimeHasChanged(); - -//void epi_setCurrSlavAddr(int slavAd); - -//int gpi_getCurrSlavAddr(void); - - - - -// /////////////////////////////////////////////////////////////////////////////////// -// Status Display gui <--> serial -// /////////////////////////////////////////////////////////////////////////////////// - -//--------------------- - // Statuszeile COM Port (serial Port) (open, closed) -// Display in tab_com -QString epi_getTxt4comStateLine(void); -void epi_clrTxt4comStateLine(); - // GUI: get Text for serial Comport-State Line - -//--------------------- -// Statuszeile Handshakes (serial Control) flow.cpp -// geht überhaupt was raus? kommt überhaupt was zurück? -// I -QString epi_getTxt4HsStateLine(void); -void epi_clrTxt4HsStateLine(); - // GUI: get Text - -// II Master receive state (empfangenes Telgramm OK? crc? length? ) -// Statuszeile Auswertung der SlaveResponse (serial Frame, CRC usw) (prot.cpp) -QString epi_getTxt4masterStateLine(void); -void epi_clrTxt4masterStateLine(); - -// III Slave receive (from Master) OK? if then show results, if not then show errors -// entweder Empfangsfehler anzeigen (crc? length?) oder result OUT-OK, OUT_ERR, IN_OK, IN_ERR -// Hintergrund: wenn der Slave Fehler im Master-Telegramm gefunden hat, dann kann er es auch -// nicht verwenden und nichts ausgeben oder einlesen -QString epi_getTxt4resultStateLine(void); -void epi_clrTxt4resultStateLine(); - -// IV Statuszeile Sende- und Empfangsdaten (Datif) -// Display in tab_com -QString epi_getTxt4dataStateLine(void); -void epi_clrTxt4dataStateLine(); -// GUI: get Text for serial Comport-State Line - -// V, unten, Datif -QString epi_getTxt4datifLine(void); -void epi_clrTxt4datifLine(); - -//--------------------- - - // sende-empfangs-Rohdaten-Fenster -// Display in tab_com -QString epi_getTxt4RsDiagWin(void); -void epi_clrTxt4RsDiagWin(); - -QString epi_get2ndTxt4RsDiagWin(void); -void epi_clr2ndTxt4RsDiagWin(); - - -// Statuszeile COM Port (serial Port) (open, closed) -// Display in tab_com -void gpi_setTxt4comStateLine(QString txtline); - // serial: write Text to be displayed in serial Comport-State line (like "connected") - // used in vcp.cpp, links in tabCom - - -// Statuszeile Handshakes (serial Control) -// I obere Zeile -void gpi_setTxt4HsStateLine(QString txtline); - // used in flow.cc - -// II -void gpi_setTxt4masterStateLine(QString txtline); - -// III -void gpi_setTxt4resultStateLine(QString txtline); - -// IV -void gpi_setTxt4dataStateLine(QString txtline); - // serial: write Text to be displayed in serial Comport-State line (like "connected") - // used in prot.cpp - -// V unten: -void gpi_setTxt4datifLine(QString txtline); - - -// sende-empfangs-Rohdaten-Fenster -// Display in tab_com -void gpi_setTxt4RsDiagWin(QString txtline); -void gpi_set2ndTxt4RsDiagWin(QString txtline); - -// /////////////////////////////////////////////////////////////////////////////////// -// Memory for Slave responses, common data -// /////////////////////////////////////////////////////////////////////////////////// - -bool epi_getResult_serialTestOK(); -// retval: true: test was successful, got right response - - -// result of serial line test, slave sent fixed string -void gpi_storeResult_serialTestOK(bool wasOn); - - -// /////////////////////////////////////////////////////////////////////////////////// -// restore just received data -// /////////////////////////////////////////////////////////////////////////////////// - - -uint8_t gpi_startNewRequest(); - // called by Datif - -uint8_t gpi_storeResultOfLastRequest(bool answisok); - // written by Datif - -uint8_t epi_getResultOfLastRequest(); - // retval: 0: in progress 1: OK 2: error - - -void gpi_storeRecPayLoad(uint8_t RdDlen, uint8_t const *receivedData); - // stored by Datif - -uint16_t epi_getLastPayLoad(uint16_t plBufSiz, uint8_t *payLoad); - // get data back in *pl, max 64 byte - // retval = nr of bytes received. If host buffer too small then - // only plBufSíz bytes are copied to pl - // plBufSíz=size of host buffer - - - -#endif - - - - - - - - - - diff --git a/DCPlugin/include/datIf.h b/DCPlugin/include/datIf.h deleted file mode 100644 index 0b173e2..0000000 --- a/DCPlugin/include/datIf.h +++ /dev/null @@ -1,341 +0,0 @@ -// Data Interface between slave (DC) and pi buffer -// determines sending and receiving order of data -// cares for storing input data and restoring output data - - - -#ifndef DIF_H -#define DIF_H -#include -#include "tslib.h" -#include "prot.h" -#include "dcBL.h" - - -#include -#include -#include -#include -#include -#include -#include - - - -#define CMD2DC_sendTime 20 -#define CMD2DC_setWakeFrequ 112 -#define CMD2DC_MOV_UPLOCK 113 -#define CMD2DC_MOV_DNLOCK 114 -#define CMD2DC_UPPER_DOOR 115 -#define CMD2DC_LOWER_DOOR 116 -#define CMD2DC_VAULT_DOOR 117 -#define CMD2DC_REJMOT_ON 118 -#define CMD2DC_REJMOT_RUN 119 -#define CMD2DC_LED_COIN 100 -#define CMD2DC_LED_ILLU 101 -#define CMD2DC_LED_TICKET 102 -#define CMD2DC_LED_START 104 -#define CMD2DC_LED_PIN 103 -#define CMD2DC_LED_IN 105 -#define CMD2DC_FAN 106 -#define CMD2DC_SIREN 107 -#define CMD2DC_BARRIER 108 -#define CMD2DC_WAKEPTU 109 -#define CMD2DC_SWITCHAUXPWR 110 -#define CMD2DC_SWITCHAUXDDR 18 -#define CMD2DC_SWITCHAUXOUT 19 -#define CMD2DC_UCONTACTON 111 -#define CMD2DC_DEVICE_PARAM 23 -#define CMD2DC_SEND_MACH_ID 11 -#define CMD2DC_RDBK_DEV_PARA 14 - -#define CMD2DC_RDBK_MACH_ID 15 - -#define CMD2DC_MDB_ON 120 -#define CMD2DC_MDB_GET_STATE 107 // REQ -#define CMD2DC_MDB_DORESET 121 -#define CMD2DC_MDB_SETWAK 122 -//#define CMD2DC_MDB_GETWAK 0x2812 // REQ not nec. -#define CMD2DC_MDB_SENDCMD 123 -#define CMD2DC_MDB_SENDMSG 12 -#define CMD2DC_MDB_GETRESP 22 // REQ - -#define CMD2DC_EMP_SET 24 -#define CMD2DC_EMP_GET_ALL 23 // REQ -#define CMD2DC_EMP_STARTPOLL 124 -#define CMD2DC_EMP_STARTPAY 125 -#define CMD2DC_EMP_STOPPAY 126 -#define CMD2DC_EMP_GOTCOIN 108 // REQ -#define CMD2DC_SHUTTER_OPEN 129 -#define CMD2DC_ESCR_OPEN 132 -#define CMD2DC_ESCR_TAKE 133 -#define CMD2DC_ESCR_RETURN 134 -#define CMD2DC_MOD_ON 135 -#define CMD2DC_MOD_WAK 136 -#define CMD2DC_CRED_ON 137 -#define CMD2DC_CRED_WAK 138 - -// READ Commands ((e.g. get input) -#define CMD2DC_TestSerial 10 -#define CMD2DC_GetSerialConfig 105 -#define CMD2DC_RdBkHWversion 11 -#define CMD2DC_RdBkSWversion 12 -#define CMD2DC_RdBkDCstate 101 -#define CMD2DC_RdBkUID 18 -#define CMD2DC_RdBkTime 104 -#define CMD2DC_RdBkAnalog 106 -#define CMD2DC_GetAllInputs 102 -#define CMD2DC_RdBkAllOutputs 103 -#define CMD2DC_MIFREADERON 127 -#define CMD2DC_ATB_CREATE 128 - - - - -// Mif read data: -#define CMD2DC_RdBk_MifState 109 -#define CMD2DC_RdBk_MifData 24 - - - - -#define CMD2DC_RdBk_AtbCardType 25 -#define CMD2DC_SHUTTER_COIN 131 -#define CMD2DC_SHUTTER_OPEN3S 130 -#define CMD2DC_SEND_SHUT_TIME 0x2915 -#define CMD2DC_ESCR_TAKE 133 -#define CMD2DC_ESCR_RETURN 134 -#define CMD2DC_PRINTERON 139 -#define CMD2DC_RdBk_PrnState 110 -#define CMD2DC_RdBk_PrnFonts 26 -#define CMD2DC_RdBk_AllPrnData 27 - // nr of params: -#define CMD2DC_PRI_SYS_CMD 25 // 3 -#define CMD2DC_PRI_ESC_CMD 26 // 4 -#define CMD2DC_PRI_SETUP 27 // 5 -#define CMD2DC_PRI_MOVE 140 // 2 -#define CMD2DC_PRI_SETFONT 141 // 4 -#define CMD2DC_PRI_SETLETTER 142 // 3 -#define CMD2DC_PRI_CUT 143 // 1 -#define CMD2DC_PRI_PRINT_TXT 13 // 64 -#define CMD2DC_PRI_LF 144 // 1 -#define CMD2DC_PRI_PRIFONTTABLE 145 -#define CMD2DC_PRI_BARCODE 14 // ca 15...25 -#define CMD2DC_STOR_QR_DATA 15 // 150 -#define CMD2DC_PRI_QR_CODE 146 // 0 -#define CMD2DC_PRI_LOGOFROMFLASH 147 // 2 -#define CMD2DC_PRI_STORE_DOC 16 // 1 -#define CMD2DC_PRI_DOCUMENT_NR 17 // 1 + 64 -#define CMD2DC_PRI_CLEAR_DOC 148 // 1 - - -/* -// WRITE Commands (e.g. switch relay) -#define CMD2DC_sendTime 0x1310 -#define CMD2DC_setWakeFrequ 0x1320 - -#define CMD2DC_MOV_UPLOCK 0x1801 -#define CMD2DC_MOV_DNLOCK 0x1802 -#define CMD2DC_UPPER_DOOR 0x1810 -#define CMD2DC_LOWER_DOOR 0x1811 -#define CMD2DC_VAULT_DOOR 0x1812 - -// neu 7.10.21: -#define CMD2DC_REJMOT_ON 0x1813 -#define CMD2DC_REJMOT_RUN 0x1814 - - -#define CMD2DC_LED_COIN 0x1204 -#define CMD2DC_LED_ILLU 0x1205 -#define CMD2DC_LED_TICKET 0x1206 -#define CMD2DC_LED_START 0x1208 -#define CMD2DC_LED_PIN 0x1207 -#define CMD2DC_LED_IN 0x1209 -#define CMD2DC_FAN 0x1210 -#define CMD2DC_SIREN 0x1211 -#define CMD2DC_BARRIER 0x1212 -#define CMD2DC_WAKEPTU 0x1218 -#define CMD2DC_SWITCHAUXPWR 0x1220 -#define CMD2DC_SWITCHAUXDDR 0x1222 -#define CMD2DC_SWITCHAUXOUT 0x1224 -#define CMD2DC_UCONTACTON 0x1226 - -#define CMD2DC_DEVICE_PARAM 0x2000 -#define CMD2DC_SEND_MACH_ID 0x2002 -#define CMD2DC_RDBK_DEV_PARA 0x2001 -#define CMD2DC_RDBK_MACH_ID 0x2003 - - - -// --------------------------- MDB -------------- -#define CMD2DC_MDB_ON 0x2800 -#define CMD2DC_MDB_GET_STATE 0x2801 // REQ -#define CMD2DC_MDB_DORESET 0x2802 -#define CMD2DC_MDB_SETWAK 0x2811 -//#define CMD2DC_MDB_GETWAK 0x2812 // REQ not nec. -#define CMD2DC_MDB_SENDCMD 0x2820 -#define CMD2DC_MDB_SENDMSG 0x2821 -#define CMD2DC_MDB_GETRESP 0x2822 // REQ - -// --------------------------- EMP -------------- -#define CMD2DC_EMP_SET 0x2830 -#define CMD2DC_EMP_GET_ALL 0x2831 // REQ -#define CMD2DC_EMP_STARTPOLL 0x2832 -#define CMD2DC_EMP_STARTPAY 0x2834 -#define CMD2DC_EMP_STOPPAY 0x2836 -#define CMD2DC_EMP_GOTCOIN 0x2837 // REQ - - - - - - - - -#define CMD2DC_SHUTTER_OPEN 0x2911 -#define CMD2DC_ESCR_OPEN 0x2920 -#define CMD2DC_ESCR_TAKE 0x2921 -#define CMD2DC_ESCR_RETURN 0x2922 -#define CMD2DC_MOD_ON 0x2940 -#define CMD2DC_MOD_WAK 0x2941 -#define CMD2DC_CRED_ON 0x2960 -#define CMD2DC_CRED_WAK 0x2961 - - -// READ Commands ((e.g. get input) -#define CMD2DC_TestSerial 0x1101 -#define CMD2DC_GetSerialConfig 0x1107 -#define CMD2DC_RdBkHWversion 0x110A -#define CMD2DC_RdBkSWversion 0x110B -#define CMD2DC_RdBkDCstate 0x110C - -#define CMD2DC_RdBkUID 0x1305 -#define CMD2DC_RdBkTime 0x1313 -#define CMD2DC_RdBkAnalog 0x1550 -#define CMD2DC_GetAllInputs 0x1201 -#define CMD2DC_RdBkAllOutputs 0x1202 - - -#define CMD2DC_MIFREADERON 0x2900 -#define CMD2DC_ATB_CREATE 0x2907 -// Mif read data: -#define CMD2DC_RdBk_MifState 0x2902 -#define CMD2DC_RdBk_MifData 0x2903 -#define CMD2DC_RdBk_AtbCardType 0x2905 -//#define CMD2DC_RdBk_CardData 0x2906 - - - - -// higher Level operation commands -//#define CMD2DC_SHUTTER_ONE 0x2912 -#define CMD2DC_SHUTTER_COIN 0x2913 -#define CMD2DC_SHUTTER_OPEN3S 0x2912 -#define CMD2DC_SEND_SHUT_TIME 0x2915 - -#define CMD2DC_ESCR_TAKE 0x2921 -#define CMD2DC_ESCR_RETURN 0x2922 - - -#define CMD2DC_PRINTERON 0x2A01 -#define CMD2DC_RdBk_PrnState 0x2A02 -#define CMD2DC_RdBk_PrnFonts 0x2A12 -#define CMD2DC_RdBk_AllPrnData 0x2A40 - - // nr of params: -#define CMD2DC_PRI_SYS_CMD 0x2A03 // 3 -#define CMD2DC_PRI_ESC_CMD 0x2A04 // 4 -#define CMD2DC_PRI_SETUP 0x2A05 // 5 -#define CMD2DC_PRI_MOVE 0x2A06 // 2 -#define CMD2DC_PRI_SETFONT 0x2A10 // 4 -#define CMD2DC_PRI_SETLETTER 0x2A11 // 3 -#define CMD2DC_PRI_CUT 0x2A13 // 1 - -#define CMD2DC_PRI_PRINT_TXT 0x2A14 // 64 - -#define CMD2DC_PRI_LF 0x2A15 // 1 -#define CMD2DC_PRI_PRIFONTTABLE 0x2A16 -#define CMD2DC_PRI_BARCODE 0x2A17 // ca 15...25 - -#define CMD2DC_STOR_QR_DATA 0x2A18 // 150 -#define CMD2DC_PRI_QR_CODE 0x2A19 // 0 - -#define CMD2DC_PRI_LOGOFROMFLASH 0x2A1A // 2 - -#define CMD2DC_PRI_STORE_DOC 0x2A41 // 1 -#define CMD2DC_PRI_DOCUMENT_NR 0x2A42 // 1 + 64 -#define CMD2DC_PRI_CLEAR_DOC 0x2A43 // 1 - -*/ - - - - -#define FIX_SLAVE_ADDR 0 -#define SEND_ATONCE 1 -#define SENDCOMBINED 0 - - - - -class T_datif : public QMainWindow -{ - Q_OBJECT - - char sendINrequestsAutomatic(void); - // sende alle Befehle um die Eingangsdaten abzufragen der Reihe nach - char loadRecDataFromFrame(); - void datif_startSending(void); - void datif_sendIOrequest(uint16_t WRcmd, uint16_t RDcmd, uint8_t nrOfWrData); - - void datif_send8byteOutCmd(uint16_t WRcmd, uint16_t RDcmd); - - bool verifyLineTestresponse(uint8_t RdDlen, uint8_t *receivedData); - void datif_OUT_setTime(void); - uint8_t datif_OUT_SendRandomData(uint8_t *buf, uint8_t Length); - - void datif_send64byteOutCmd(uint16_t WRcmd, uint16_t addr, uint16_t RDcmd); - - void datif_sendToMemory(uint16_t WRcmd, uint16_t docNr, uint16_t blockNr, uint8_t *data64); - // send printer documents to DC2 memory - // docNr: 0...15(31) with 1280 byte each (20 blocks a 64byte) - // blockNr=0...19 with 64byte each - // docNr =transmitted in WRITEADDRESS high byte - // blockNr=transmitted in WRITEADDRESS low byte - - - T_prot *myDCIF; - QTimer *datif_trigger; - uint8_t selectedSlaveAddr; - -private slots: - char datif_cycleSend(); - void StoredRecData(); - -public: - T_datif(QWidget *parent = nullptr); - - T_prot *getProt() { return myDCIF; } - T_prot const *getProt() const { return myDCIF; } - - void resetChain(void); - char isPortOpen(void); - void sendWRcommand(uint16_t nxtAsCmd); - // Sende Schreibbefehle die bereits vorher asynchron gespeichert wurden - void send_requests(uint16_t nextWrCmd); - void sendHighLevel(uint16_t nxtHLCmd); - bool areDataValid(void); - -signals: - void ResponseRecieved(); - //the requested data are stored in peripheral image - // can be loaded with epi - - void datif_templatePrintFinished_OK(); - void datif_templatePrintFinished_Err(); - - void datif_gotNewCoin(); - -}; - -#endif // CI_H diff --git a/DCPlugin/include/dcBL.h b/DCPlugin/include/dcBL.h deleted file mode 100644 index f605270..0000000 --- a/DCPlugin/include/dcBL.h +++ /dev/null @@ -1,102 +0,0 @@ -#ifndef DCBL_H -#define DCBL_H -#include -#include "qbytearray.h" -#include "qstring.h" -#include - -uint8_t dcBL_prepareDC_BLcmd(uint8_t Cmd, uint8_t SendDataLength, uint8_t *sendData, uint8_t *outBuf); -// make BL protocol, retval = outbuf length (5...133) -// bring data in correct form: start always with 0x02 finish with 0x03 and append checksum -// 0x02 Cmd < ...sendData ..> CRC CRC 0x03 -// Data length = 0...64 -// special conversion: if data contain 2 or 3 (STX, ETX) then write two bytes: 0x1B (=ESC) and data|0x80 -// so maxlength = 5 + 2 x 64 (if all data are 2 or 3) without 2,3: maxlength = 5 + 64 - -uint8_t dcBL_readBLversion(uint8_t *sendData); - // minimum size of sendData-buffer: 5byte retval: length - -uint8_t dcBL_readFWversion(uint8_t *sendData); - // minimum size of sendData-buffer: 5byte retval: length - -uint8_t dcBL_exitBL(uint8_t *sendData); - // minimum size of sendData-buffer: 5byte retval: length - -uint8_t dcBL_sendFlashStartAddr2BL(uint32_t startAddr, uint8_t *sendData); - // minimum size of sendData-buffer: 13byte retval: length (9...13) - -uint8_t dcBL_writeLastPage(uint8_t *sendData); - // minimum size of sendData-buffer: 5byte retval: length - -uint8_t dcBL_restartDC(uint8_t *sendData); - // minimum size of sendData-buffer: 20 byte retval: length - -uint8_t dcBL_activatBootloader(uint8_t *sendData); - // minimum size of sendData-buffer: 20 byte retval: length - -uint8_t dcBL_getResponse(uint8_t *respBuff); - // retval: nr of received bytes - -bool dcBL_responseOK(); - // retval: 0: response OK (cmd |0x80) 1: response error (cmd or "0xe0") - -bool dcBL_importBinFile(QByteArray readBinFile, uint32_t fileSize, char withDispl); - - - -bool dcBL_isTextMemFree(void); - -void dcBL_writeText(QString newTxt); - -bool dcBL_checkForText(void); - // if pointer at 0 then no more content - -QString dcBL_readText(void); - // read from 0...9 (oldest first) - - - -void dcBL_iniChain(void); - -uint8_t dcBL_startChain(void); - -uint8_t dcBL_runChain(void); - -void dcBL_iniLoading(void); - -void dcBL_startLoading(void); - -uint8_t dcBL_sendHexfile(void); - - -uint8_t dcBL_getResult(void); -// call after every step to what's going on.... -// 1: connected to BL -// 2: transmission started -// 3: transmission successful - - - -#define RAW_BL_DATALEN 150 -void gpi_storeRawReceivedData(uint8_t RdDlen, uint8_t *receivedData); - -uint8_t epi_getRawReceivedData(uint8_t *receivedData); - // retval=length, will be zeroed after first reading - -uint8_t epi_getRawRecLength(void); - // retval=length - -QString epi_getRawReceivedString(); - -void epi_clrRawReceivedString(); - - -uint8_t dcBL_sendSuccess(uint8_t lastCommand); - // return val: 0: no response by now 1:error 10: OK - // lastCommand=0x21 for sendAddr or 0x22 for send data - -char dcBL_loadBinary(char withDisplay); - - - -#endif // DCBL_H diff --git a/DCPlugin/include/hwChk.h b/DCPlugin/include/hwChk.h deleted file mode 100755 index 7163675..0000000 --- a/DCPlugin/include/hwChk.h +++ /dev/null @@ -1,35 +0,0 @@ - -#ifndef hwchk_H -#define hwchk_H - -#include -#include -#include -#include "interfaces.h" -//#include "datIf.h" -#include -#include -#include "hwapi.h" - -//class QSharedMemory; -class hwChk : public QObject, - public hwinf -{ - Q_OBJECT -// Q_PLUGIN_METADATA(IID "Atb.Psa2020.software.HWapi/1.0" ) //FILE "HWapi.json") -// Q_INTERFACES(hwinf) -//private: -// QSharedMemory *m_sharedMem; - -public: - explicit hwChk(QWidget *parent = nullptr); - virtual ~hwChk(); - - -public: - hwinf *HWaccess; - - -}; - -#endif diff --git a/DCPlugin/include/hwapi.h b/DCPlugin/include/hwapi.h deleted file mode 100644 index 9489e08..0000000 --- a/DCPlugin/include/hwapi.h +++ /dev/null @@ -1,1231 +0,0 @@ - -#ifndef hwapi_H -#define hwapi_H - -#include -#include -#include "interfaces.h" -#include "datIf.h" - -class QSharedMemory; -class hwapi : public QObject, - public hwinf -{ - Q_OBJECT - Q_INTERFACES(hwinf) -private: - void sub_storeSendingText(QByteArray *buf) const; - - DownloadResult sendNextAddress(int bNum) const; - DownloadResult sendNextDataBlock(QByteArray const &b, int bNum) const; - DownloadResult sendStatus(int ret) const; - DownloadResult dc_downloadBinary(QByteArray const &binary) const; - - bool startBootloader() const; - bool stopBootloader() const; - bool openSerial(int br, QString baudrate, QString comPort) const; - bool closeSerial(QString comport) const; - bool resetDeviceController() const; - QByteArray loadBinaryDCFile(QString filename) const; - bool downloadBinaryToDC(QString const &bFile) const; - - QSharedMemory *m_sharedMem; -public: - explicit hwapi(QObject *parent = nullptr); - virtual ~hwapi(); - - T_datif *myDatif; - - - virtual QStringList dc_getStatus() const override; - - // ------------------------------------------------------------------------------ - // Level 0 commands, interface - // open, close, change serial interface - // actually not neccessary as it is opened automatically on program start - // start automatic READ requests - // ------------------------------------------------------------------------------ - - bool dc_openSerial(int BaudNr, QString BaudStr, QString ComName, uint8_t connect) const override; - // BaudNr: 0:1200 1:9600 2:19200 3:38400 4:57600 5:115200 - // BaudStr: for exapmle "19200" - // ComName: for example "COM48" - // connect: 0, 1 - - bool dc_closeSerial(void) const override; - - bool dc_isPortOpen(void) const override ; - - void dc_autoRequest(bool on) const override ; - // select if READ-Requests are sent manually one by one or automatically - // automatically request ALL digital and analog sensors, get time/date, get status information - - bool dc_updateDC(QString binFileName, QString baudrate, - QString comPort) const override; - - bool dc_updatePrinterTemplate(enum FileTypeJson type, - QVector templateIdx, - QVector fnames, - QString br, - QString serial = QString()) const override; - - bool dc_printTemplate(enum FileTypeJson type, - QVector templateIdx, - QString br, - QString serial = QString()) const override; - // ------------------------------------------------------------------------------ - // Level 1, control device-controller (functions of µC) - // check serial connection to deviceController - // read response from DC2 (input data) - // some test function for serial communication - // also Bootloader is here - // ------------------------------------------------------------------------------ - - void dc_requTestResponse() const override; - // tell DC2 to return his TestString in order - // to test the serial and the baudrate - // must always be triggered manually, is never sent automatically - - bool dc_readAnswTestResponse() const override; - // retval: true: test was successful, got right response - - uint8_t dc_isRequestDone(void) const override; - // retval: 0: request is still in progress - // 1: answer from DC2 was OK - // 2: wrong answer from DC2 - - uint16_t dc_getCompletePayLoad(uint16_t plBufSiz, uint8_t *payLoad) const override; - // get data back in *pl, max 64 byte, can be used for diagnosis - // retval = nr of bytes received. If host buffer too small then - // only plBufSíz bytes are copied to pl - // plBufSíz=size of host buffer - - void dc_setWakeFrequency(uint8_t period) const override; - // RTC wakes DC2 (and PTU) by hardware signal every 32seconds - // change wake signal period to 1...64s - - void dc_OrderToReset(void) const override; - // want DC2 to reset (in order to start Bootloader) - - QString dc_getSerialState(void) const override; - void dc_clrSerialStateText(void) const override; - - void bl_sendDataDirectly(uint8_t length, uint8_t *buf) const override; - // send without protocol frame, needed for the DC bootloader - - uint8_t getRawRecLength(void) const override; - - uint8_t getRawReceivedData(uint8_t *receivedData) const override; - - QString dc_getSerialParams(void) const override; - - QString dc_getHWversion(void) const override; - - QString dc_getSWversion(void) const override; - - QString dc_getState(void) const override; - - QString dc_getTxt4RsDiagWin(void) const override; - void dc_clrTxt4RsDiagWin(void) const override; - QString dc_get2ndTxt4RsDiagWin(void) const override; - void dc_clr2ndTxt4RsDiagWin(void) const override; - QString dc_getTxt4HsStateLine(void) const override; - void dc_clrTxt4HsStateLine(void) const override; - QString dc_getTxt4masterStateLine(void) const override; - void dc_clrTxt4masterStateLine(void) const override; - QString dc_getTxt4resultStateLine(void) const override; - void dc_clrTxt4resultStateLine(void) const override; - QString dc_getdataStateLine(void) const override; - void dc_clrTxt4dataStateLine(void) const override; - QString dc_getdatifLine(void) const override; - void dc_clrTxt4datifLine(void) const override; - - // using DC2 Bootloader - void bl_iniChain(void) const override; - bool bl_importBinFile(QByteArray readBinFile, uint32_t fileSize, char withDispl) const override; - uint8_t bl_activatBootloader(uint8_t *sendData) const override; - uint8_t bl_startChain(void) const override; - uint8_t bl_readBLversion(uint8_t *sendData) const override; - // minimum size of sendData-buffer: 5byte retval: length - uint8_t bl_readFWversion(uint8_t *sendData) const override; - // minimum size of sendData-buffer: 5byte retval: length - - uint8_t bl_prepareDC_BLcmd(uint8_t Cmd, uint8_t SendDataLength, uint8_t *sendData, uint8_t *outBuf) const override; - // make BL protocol, retval = outbuf length (5...133) - // bring data in correct form: start always with 0x02 finish with 0x03 and append checksum - // 0x02 Cmd < ...sendData ..> CRC CRC 0x03 - // Data length = 0...64 - // special conversion: if data contain 2 or 3 (STX, ETX) then write two bytes: 0x1B (=ESC) and data|0x80 - // so maxlength = 5 + 2 x 64 (if all data are 2 or 3) without 2,3: maxlength = 5 + 64 - - uint8_t bl_exitBL(uint8_t *sendData) const override; - // minimum size of sendData-buffer: 5byte retval: length - - // ------------------------------------------------------------------------------ - // Level 2 DC2-onboard devices - // WR: set time - // RD. get time, get measure, get test results - // ------------------------------------------------------------------------------ - - // get UID, get time/date test results memory, RTC analog values -/* - struct Trtc_DateTime - { - uint8_t rtc_hour; - uint8_t rtc_min; - uint8_t rtc_sec; - uint8_t rtc_dayOfMonth; - uint8_t rtc_month; - uint8_t rtc_year; - uint8_t rtc_dayOfWeek; - }; -*/ - uint8_t rtc_getDateTime(struct Trtc_DateTime *rtc_DateTime) const override; - - uint8_t rtc_setDateTime(void) const override; - // synch DC2 with PC or PTU system time and date - - void rtc_getTime(uint8_t *hh, uint8_t *mm, uint8_t *ss) const override; - // get time directly - - void rtc_getDate(uint8_t *yy, uint8_t *mm, uint8_t *dd) const override; - // get date directly - - uint8_t rtc_getToday(uint8_t *dow, uint16_t *minOfToday, uint32_t *secOfToday) const override; - // dow=day of week, 1=monday...7 - // minOfToday: 0=midnight...1439= 23:59 - // secOfToday: 0=midnight...86399= 23:59:59 - - bool rtc_isLeapYear(uint8_t *lastLeapYear, uint8_t *NextLeapYear) const override; - // retval true: this year is leap year - - bool rtc_isLeapYear() const override; - - void rtc_getWeek(uint8_t *DayOfWeek, uint8_t *HoursOfWeek, uint16_t *MinutesOfWeek) const override; - // DayOfWeek: 1=monday...7 - // HoursOfWeek: 0=Monday 0:00 o'clock...167=Sunday 23:00 - // MinutesOfWeek: 0=Monday 0:00 o'clock...10079=Sunday 23:59 - - void rtc_getMonth(uint8_t *DayOfMonth, uint16_t *HoursOfMonth, uint16_t *MinutesOfMonth) const override; - // DayOfMonth: 1...31 - // HoursOfMonth: 0 = 0:00o'clock of 1.day in month up to 743 - // MinutesOfMonth:0 = 0:00o'clock of 1.day in month up to 44639 - - void rtc_getYear(uint16_t *DayOfYear, uint16_t *HoursOfYear, uint32_t *MinutesOfYear) const override; - // DayOfYear: 1...366 1= 1.Jan of this current year - // HoursOfYear: 0=1.Jan 0:00o'clock ...8783=31.12 23 o'clock - // MinutesOfYear: 0=1.Jan 0:00o'clock ...527039=31.12 23:59 o'clock - - QString rtc_getTimStr(void) const override; - QString rtc_getDatStr(void) const override; - QString rtc_getTimDatStr(void) const override; - - // UID - void dc_getUID8byte(uint8_t *buf8byteUid) const override; - QString dc_getUIDstr() const override; - uint64_t dc_getUIDnumber(void) const override; - - - // Analog inputs: - uint32_t dc_getTemperature(void) const override; // in Sax-Format 0...400 (0=-50,0°C 100=0,0°C 141=20,5°C 400=150,0°C) - QString dc_getTemperaturStr(void) const override; - - uint32_t dc_getVoltage(void) const override; // in mV, 0...65,535V - QString dc_getVoltagStr(void) const override; - - bool dc_mainFuseIsOk(void) const override; - - // ------------------------------------------------------------------------------ - // Level 3: digital outputs and simple switching of connected devices - // simple processes like flashing a led or open flap for 1s - // ------------------------------------------------------------------------------ - - void lock_switchContactPower(bool on) const override; - - // Locks move until stop cmd (0) - uint8_t lock_switchUpperLock(uint8_t dir) const override; - // dir 0=off 1=up 2=down - uint8_t lock_switchLowerLock(uint8_t dir) const override; - // dir 0=off 1=up 2=down - void lock_switchVaultDoor(void) const override; - - void coin_switchRejectMotor(uint8_t dir) const override; - - void coin_rejectCoins(void) const override; - - // LEDs - void led_switchLedIllumination(uint8_t on) const override; - void led_switchLedService(uint8_t on) const override; - void led_switchLedPaper(uint8_t on, uint8_t ton, uint8_t tof) const override; - void led_switchLedPinPad(uint8_t on, uint8_t ton, uint8_t tof) const override; - void led_switchLedStart(uint8_t on, uint8_t ton, uint8_t tof) const override; - void led_switchLedCoinbassin(uint8_t on, uint8_t ton, uint8_t tof) const override; - - void fan_switchFan(bool on) const override; - void alarm_switchSiren(bool on) const override; - void bar_OpenBarrier(bool open) const override; - void ptu_switchWake(bool WAKEACTIVE) const override; - - void prn_switchPower(bool on) const override; - - void mif_readerOn(bool on) const override; - void shut_move(bool open) const override; - void esc_moveFlaps(uint8_t flap ) const override; - // 0: close both 1: open take-flap 2: open return - - void mdb_switchPower(bool on) const override; - void mdb_switchWake(bool WAKEACTIVE) const override; - - void mod_switchPower(bool on) const override; - void credit_switchPower(bool on) const override; - - void aux_power(bool on) const override; - void aux_setUsage(uint8_t PinDirection) const override; - void aux_setOutputs(uint8_t PinIsHigh) const override; - - - void mod_switchWake(bool WAKEACTIVE) const override; - - void credit_switchWake(bool WAKEACTIVE) const override; - - - - - // ------------------------------------------------------------------------------ - // Level 3: digital inputs of connected devices - // ------------------------------------------------------------------------------ - - bool door_isContactPowerOn(void) const override; - - uint8_t door_getSwitches(void) const override; - // retval: bit0: upper door 1: low door 2:vault door - - bool door_isUpperDoorOpen(void) const override; - - bool door_isLowerDoorOpen(void) const override; - - bool vault_isVaultDoorOpen(void) const override; - - uint8_t vault_getSwitches(void) const override; - // retval bit0: cash box, bit 1: bill box - - bool vault_isCoinVaultIn(void) const override; - - bool vault_isBillVaultIn(void) const override; - - uint8_t door_getLocks(void) const override; - // retval bit0: upper lever is up - // bit1: upper lever is down - // bit2: lower lever is up - // bit3: lower lever is down - - bool door_upperDoorIsLocked(void) const override; - - bool door_upperDoorIsUnlocked(void) const override; - - bool door_lowerDoorIsLocked(void) const override; - - bool door_lowerDoorIsUnlocked(void) const override; - - bool bar_optoIn1isOn(void) const override; - - bool bar_optoIn2isOn(void) const override; - - bool ptu_WakeINisActive(void) const override; - - bool prn_isPrinterPowerOn(void) const override; - uint8_t prn_PrnFuseIsOk(void) const override; - //retval: 0: fuse blown 1: fuse OK 2:unknown as printer power is off - - bool prn_readyINisActive(void) const override; - - bool mif_cardIsAttached(void) const override; - bool mif_isMifarePowerOn(void) const override; - - bool mdb_WakeINisActive(void) const override; - bool mdb_testIsmdbTxDon(void) const override; - bool mdb_isMdbPowerOn(void) const override; - - bool coid_isAttached(void) const override; - bool coin_escrowIsOpen(void) const override; - - bool aux_isAuxPowerOn(void) const override; - - uint8_t aux_getAuxInputs(void) const override; - - bool mod_isGsmPowerOn(void) const override; - - bool cred_isCreditPowerOn(void) const override; - - bool cash_getRejectMotorHomePos(void) const override; - - uint8_t cash_getLowPaperSensor(void) const override; - // 0: Sensor sees paper 1: no paper 99: off - - - // ------------------------------------------------------------------------------ - // Level1,2,3 RD request commands - // ------------------------------------------------------------------------------ - - // all read-requests can be sent manually by the following functions - // or automatically in background by: void hwapi::dc_autoRequest(bool on) - // in other words: - // if automatic-reading is on, then there's no need to send any of these commands, - // but it's allowed to send them in order to speed up the refreshing of the inputs - - void request_DC2serialConfig() const override; - void request_DC2_HWversion() const override; - void request_DC2_SWversion() const override; - void request_DC2_condition() const override; - void request_DC2_UID() const override; - void request_DC2_TimeAndDate() const override; - void request_DC2_analogues() const override; - void request_DC2_digitalInputs() const override; - void request_DC2_digitalOutputs() const override; - - // ------------------------------------------------------------------------------ - // the folowing device state requests are deploed only if device is powered up: - void request_PrinterHwState() const override; - void request_PrinterCurrentFonts() const override; - void request_PrinterStateComplete() const override; - - void request_MifareReaderState() const override; - void request_MifareCardType() const override; - void request_MifareAtbType() const override; - void request_MifareID() const override; - void request_MifareData(uint8_t dataBlockNumber) const override; - // dataBlockNumber must be 0....11, returns 64byte of data - - void request_MDB_Status() const override; - void request_MDB_lastResponse() const override; - void request_EMP_allParameters() const override; - void request_EMP_lastCoin() const override; - - - - // ------------------------------------------------------------------------------ - // Level 3: readback digital outputs of connected devices - // these functions are not needed for normal operation - // but can be used to test and verify conditions - - // There are two options: - // 1) the important things like power-outputs and wake lines are - // measured at DC2-terminals (after transistors) and come as input to DC-board - // 2) others like Leds are read from µC-pins by DC-board - // ------------------------------------------------------------------------------ - - bool test_getDO_mdbRXtst(void) const override; - - uint8_t lock_getDO_motors(void) const override; - // bit0: upper lock forward bit 1 backward - // bit2: lower lock forward bit 3 backward - - uint8_t test_serialState(void) const override; - // test on-board signals for the serials - // serial drv on/off, Serial mux1, Serial mux2 - bool test_serialIsOn(void) const override; - bool test_serialMux1isSetToPrinter(void) const override; - bool test_serialMux1isSetToModem(void) const override; - bool test_serialMux2isSetToCredit(void) const override; - bool test_serialMux2isSetToMifare(void) const override; - - bool led_coinIsOn(void) const override; - bool led_frontIsOn(void) const override; - bool led_ticketIsOn(void) const override; - bool led_pinIsOn(void) const override; - bool led_StartIsOn(void) const override; - bool led_insideIsOn(void) const override; - - bool fan_isOn(void) const override; - bool siren_isOn(void) const override; - bool bar_relayIsOn(void) const override; - bool ptu_WakeOutIsOn(void) const override; - - bool aux_powerIsOn(void) const override; - - bool coin_shutterIsOpen(void) const override; - bool coin_shutterTestOutput(void) const override; - - uint8_t coin_escrowFlapOpened(void) const override; - // retval: 1:return flap is open 2:take flap is open 0:closed - - - - // ------------------------------------------------------------------------------ - // Level4 ( Timer processes, device supervision by DC, processes with more then one devices - // WRITE - // ------------------------------------------------------------------------------ - - - void sendDeviceSettings(uint8_t kindOfPrinter, uint8_t kindOfCoinChecker, - uint8_t kindOfMifareReader, uint8_t suppressSleep, - uint8_t kindOfModem, uint8_t kindOfCredit ) const override; - // enable hardware in device controller: - // kindOfPrinter: 0:off 1: GPT4672 (only this one implemented) - // kindOfCoinChecker: 0:off 1:EMP820 2:EMP900 3: C²_changer - // kindOfMifareReader: 0:off 1: SL025 (only this one implemented) - // suppressSleep: 0:sleep allowed 1: sleep surpressed for special reason - // kindOfModem: 0:off 1: ATB_Sunlink_LTE (not yet implemented) - // kindOfCredit: 0:off 1: cVendTopp 2:cVendPin (not yet implemented) - - void request_ReadbackDeviceSettings() const override; - - void readback_DeviceSettings(uint8_t *length, uint8_t *data) const override; - // refer to DC2 manual for exact content - // state 5.5.21: byte[0]=kindOfPrinter byte[1]=kindOfCoinChecker - // byte[2]=kindOfMifarereadr byte[3]=suppress sleep mode - // byte[4]=kindOfModem byte[5]=kind of cc terminal - - uint8_t emp_returnLastCoin(uint16_t *value, uint8_t *signal) const override; - // use for changer - - void sendMachineID(uint16_t customerNr, uint16_t machineNr, - uint16_t borough, uint16_t zone, - uint16_t alias, char *location) const override; - - void request_ReadbackMachineID() const override; - - void readback_machineIDdata(uint8_t *length, uint8_t *data) const override; - // state 5.5.21: byte[0,1]=customer number byte[2,3]=machine number - // byte[4,5]=borough byte[6,7]=zone byte[8,9]=alias name - // byte[10...41]=location - - - // Locks stops automatically at end switch or by timeout - uint8_t lock_openUpperDoor(void) const override; - uint8_t lock_closeUpperDoor(void) const override; - - uint8_t lock_openLowerDoor(void) const override; - uint8_t lock_closeLowerDoor(void) const override; - - - void shut_openOnce(void) const override; - // and close automatic after shutter time - - void shut_openForCoin(bool start) const override; - // open flap if coin is attached - // once process is started it runs until stop command - - void shut_sendOpeningTime(uint16_t timeIn_ms ) const override; - // after this time without retrigger the flap is closed - - void esc_takeMoney(void) const override; - // and close automatically after escrow time (1s) - - void esc_returnMoney(void) const override; - // and close automatically after escrow time (1s) - - void mif_creatAtbCard(uint8_t cardType) const override; - - - // ------------------------------------------------------------------------------ - // read response from DC2 (input data) - // ------------------------------------------------------------------------------ - - uint8_t mif_returnReaderStateAndCardType(uint8_t *buf, uint8_t maxBufferSize) const override; - // retval 0=OK 1=error host buffer too small - /* data description, new fast version: - byte 0= still the same: current read state: - 0=power off 1=reader-fault 2=ready - 3=just reading 4=read complete - 5=read partial, removed too early - 6=state unknown - - byte 1: reader state 1=ok 0=nok - byte 2: card preent (0,1) - byte 3: card selected (0) - byte 4: card type: 0...5 - byte 5: card allowed (0=no 1=MifareClassic 1k or 4k) - byte 6: CardSize: 1 or 4 (kB) - byte 7: length of UID 4 or 7 (byte) - */ - - bool mif_readerIsOK(void) const override; - - bool mif_cardAttached(void) const override; - - uint8_t mif_readResult(void) const override; - // result: 0: unknown or still in progress - // 1: card read successful - // 2: reading error - - QString mif_cardUID(void) const override; - - uint8_t mif_getCardDataDec(uint8_t blkNr, uint8_t *buf, uint8_t maxBufferSize) const override; - - QString mif_getCardDataStr(uint8_t blockNumber) const override; - // with blockNumber=0...11 - - - - - // ---------------------------------------------------------------------------------------------------------- - // --------------------------------------------- PRINTER ---------------------------------------------------- - // ---------------------------------------------------------------------------------------------------------- - - // read printer condition and settings - - uint8_t prn_getHwState(struct Tprn_hw_state *prn_hw_state) const override; - // retval: status byte - // byte 0 = 0: prnter OK, >0: error - // bit0: paper low 1: no paper 2: temperature error - // 3: head open 4: paper jam in cutter - // 6: no response 7: bad response from printer - // and return struct "Tprn_hw_state" - - bool prn_isUpAndReady(void) const override; - // true: printer is powered, serial is ok, no error, printer is connected and resonding - - void prn_getCurrentFontSetting(struct Tprn_currentSettings *prn_fonts) const override; - - - // send Commands to printer: - - void prn_sendText(QByteArray *buf) const override; - // up to 1280 bytes - - void prn_sendPrnSysCmd(uint8_t para1, uint8_t para2, uint32_t para3) const override; - // send three byte through to printer, see printers manual - - void prn_sendPrnEscCmd(uint8_t para1, uint8_t para2, uint8_t para3, uint8_t para4) const override; - // send four byte through to printer, see printers manual - - - void prn_sendPrnSetup(uint16_t paperSpeed, uint8_t density, uint8_t alignment, uint8_t orientation) const override; - // send 5 byte: byte 0,1: speed 5...250 mm/s - // byte2: density 0....(25)....50 - // byte3: alignment 'l', 'c', 'r' = left, center, right - // byte4: orientation 0, 90, 180 = 0°, 90°, 180° rotation (by now not supported!) - // not batched! don't use twice within 100ms - - void prn_movePaper(uint8_t wayInMm, uint8_t direction) const override; - //direction: 1=forward 2=backward - // - void prn_setFonts(uint8_t font, uint8_t size, uint8_t width, uint8_t height) const override; - // font = kind of font 5...11 (0..22) - // size = 6...20, 9..9: too tiny 10: small ...12 = normal size ...20=huge - // width: 0...4 0=1x 1=2x 2=4x (huge!) 3=8x 4=16x (3,4 make no sense) - // heigth: 0...7 = 1x...8x only 0,1,2,(3) make sense - - void prn_setLetters(uint8_t bold, uint8_t invers, uint8_t underlined) const override; - // bold: 0/1 - // invers: 0/1 - // underlined: 0/1 - - void prn_cut(uint8_t kindof) const override; - // kindof: 1=full cut 2=partial cut 3=eject (5xLF + full cut) - - void prn_newLine(uint8_t nrOfLines) const override; - - void prn_printCompleteFontTable(void) const override; - - - void prn_printBarcode(uint8_t kindOf, uint8_t withText, uint8_t offset, uint8_t rotation, uint8_t dataLeng, uint8_t *data) const override; - // kind of barcode: 0=Code39 1=Code128 2=EAN13 3= 2/5interleaved 4=UPC-A 5=EAN8 - // withText: print readable text below - // offset: move by pixel from left border - // rotation - // dataLeng in byte - - void prn_sendQRdata(QByteArray *buf) const override; - // maximal 150 alphanummeric bytes - - void prn_printQRcode(void) const override; - // QRcode may have 1...150 alphanummeric data, must be transfered in advance - - - void prn_printLogo(uint8_t nrOfLogo, uint8_t offset ) const override; - // nrOfLogo: 1..4 in flash 5...8 in Ram - // offset: in mm form left border - - - - // ......................................................... - // Parking Ticket (print-out document) designer TD - // ......................................................... - - // Predefine document Layout (e.g. parking ticket) in advance and stroe it for quick and easy use - // in opposite to the above "single" commands you need only one or a few commands at vending time. - // Stored text is just send to printer once the printing command is issued - // stored commands within the text are interpreted and executed right at the place (in ticket) they are - // example: start bold, , stop bold - // Predefinition of up to 16 ticket Layouts is possible, 0...1280 byte each - // Number 0..15, al keept non-volatile - // up to 8 dynamic values can be defined in the template ("print val3 here") and will be sent with printing command - // example: print current time at this point (the time of printing not the storage time!!) - - void pri_startTicketDesign(void) const override; - // start for every new printer document, reseting collecting buffer - - // all further functions write/append text, numbers and command to the ticket-buffer, up to 1278 bytes allowed - // return val of the appending functions: true=ok false=too long, buffer full - - int pri_TD_getCurrentSize(void) const override; - // retval: 0...1278 - - bool pri_TD_addText(QByteArray text) const override; - // example: pri_TD_addText("Hello") const override; - // example: pri_TD_addText(tempStr) const override; - // retval: true=ok false=too long, buffer full - - bool pri_TD_addValue(int val) const override; - // +/- 0...2^(31) - - bool pri_TD_addNewLine(void) const override; - - bool pri_TD_addSign(char sign) const override; - // example: '.' ' ' 0x20 'W' '$' - - bool pri_TD_addCommand(char group, char attribute, char p1, char p2, char p3, char p4, char p5) const override; - // always add 8 byte to the ticket layout: ESC & group & attribute & parameter1...5 - /* complete list of possible commands: - group 50 : paper - attribute 10 : move forward - p1: wayInMm p2: direction - attribute 11 : cut - p1: kind of, 1=full 2=partial, 3=eject - attribute 12 : new line(s) - p1: nr of lines 1...100 - - group 51 : fonts - attribute 10 : kind of font see description above - p1: 0...8 - attribute 11 : font size - p1: 6...20 - attribute 12 : font width - p1: 0...4 - attribute 13 : font heigth - p1: 0...7 - attribute 14 : switch bold print on/off - p1: 0=off 1=on - attribute 15 : switch invers print on/off - p1: 0=off 1=on - attribute 16 : switch underlined print on/off - p1: 0=off 1=on - - group 52 : print graphics - attribute 10 : print barcode with dynamic data 6 and 7 - p1...p5 = kindOf, withText, offset, rotation, dataLeng, see description above - attribute 11 : print QRcode with preset data - - attribute 12 : print Logo - p1=nrOfLogo, p2=offset - - group 53 : print dynamics - attribute 10 : - p1: 1...8 = print dynData 0..7 at this place - - */ - - char prn_clearDocument(uint8_t documentNumber) const override; - // clear memory buffer for ONE document - // function takes a second! don't send right before "store doc" - - bool prn_store_Document(uint8_t documentNumber ) const override; - - // send the predefined Layout (generated with above TD functions) to DeviceController to save - // documentNumber=0...15 - // maximal 1280 bytes each - // allowed: 0x20...0xFF, 0x0A, 0x0C, 0x1B (LF, CR, Esc) - // 0x1B=start of embedded command (next 7bytes = command) - - // with a print command a set of 8 dynamic strings can be sent - // the place in the ticket layout is predefined (already in DC memory) - // the dynamics are first calculated at printing time - - bool prn_printDocument(uint8_t documentNumber, struct T_dynDat *dynTicketData) const override; - - - - - - // ---------------------------------------------------------------------------------------------------------- - // --------------------------------------------- MDB Bus ---------------------------------------------------- - // ---------------------------------------------------------------------------------------------------------- - - //void mdb_switchPower(bool on) const override; defined above - //void mdb_switchWake(bool WAKEACTIVE) const override; defined above -// bool mdb_WakeINisActive(void) const override; -// bool mdb_testIsmdbTxDon(void) const override; -// bool mdb_isMdbPowerOn(void) const override; -// void request_MDB_Status() const override; -// void request_MDB_lastResponse() const override; - - - void mdb_sendBusReset(void) const override; - - void mdb_sendCommand(uint8_t toMdbDevice, uint8_t mdbCommand) const override; - // send one bus command directly over mdb bus, refer to mdb manual for commands - // this command is not needed in normal operation, just for new or special things - - void mdb_sendMessage(uint8_t toMdbDevice, uint8_t mdbCommand, uint8_t nrOfData, uint8_t *dataBuffer) const override; - // nrOfData = sizeOf(dataBuffer) maximal 34 byte according mdb specs - // same as mdb_sendCommand, just with data - - bool mdb_busIsReadyToWork() const override; - - bool mdb_deviceVoltageOK() const override; - - bool mdb_busVoltageOk() const override; - - uint8_t mdb_getLastDeviceResponse(uint8_t *fromDevice, uint8_t *lastRequest, - uint8_t *responseLength, uint8_t *responseBuffer) const override; - // fromDevice: device nr from which data was requested 0,1,2,3 - // lastRequest: sent mdb command - // responseLength: nr of payload data (after mdb-ack) 0...34 - // responseBuffer holds payload data (answer from mdb device) - // return val: mdb result of this request: 1=got ACK 2=got 3xNAK 3=no or bad response 4:got Data (after ACK) - - - - - - // ---------------------------------------------------------------------------------------------------------- - // ---------------------------------- Electronic Coin Validator EMP ----------------------------------------- - // ---------------------------------------------------------------------------------------------------------- - - - void emp_sendSettings(uint16_t coinAcceptance, uint8_t tokenChannel, uint16_t *coinDenomination ) const override; - // coinAcceptance: bit0=coin1 (lowest donomination) bit15=coin16 bitH=accept bit L = deny coin (no validation) - // tokenChannel 0...31: if this signal comes from emp then a token was inserted - // coinDenomination = array of 16 coin values (e.g. 5, 10, 20...) - - void emp_pollingOnOff(uint8_t on) const override; - - void emp_startCoinAcceptance(void) const override; - - void emp_stopCoinAcceptance(void) const override; - - void emp_getAllParameters(struct T_emp *emp) const override; - // see struct in hwapi.h - // usage example: - // hwapi *HWaccess const override; - // HWaccess = new hwapi() const override; - // struct T_emp myEmp const override; - // HWaccess->emp_getAllParameters(&myEmp) const override; - // readval=myEmp.pollingRunning const override; - - uint8_t emp_chkIfCoinInserted(void) const override; - // retval: 0...16 coins left in FIFO - - void emp_getNewCoinRecord(uint8_t *valid, uint8_t *signal, uint8_t *error, uint16_t *value) const override; - // with every call ONE coin is taken out of FIFO and pointer decremented - // valid: should be 1 - // signal: comes right from coin checker, 0...15 (0=first programmed coin type) 0xFF=no signal - // error: was reported from EMP as dynamic signal right after coin insertion (instead of - // coin signal), example: 3=unknown coin 4=coin is blocked by host. 0xFF=no error - // value: of the coin. Depends on parameter "coinDenomination" in function "emp_sendSettings" - // if coinDenomination[coin 0..15] = 0 then the value programmed in coin checker is taken - // if coinDenomination > 0 then this value is taken. - // Useful in case of two currencies (adapt to local currency) or for token. - - // function gives more details as "emp getLastCoin()" but "emp getLastCoin()" is easier to use - - // alternativ to emp_getNewCoinRecord( ): - uint8_t emp_giveLastCoin(uint16_t *value, uint8_t *signal) const override; - // retval: 0: NO coin stored 1: valid coin 2: got wrong coin or coin denied - // value: if retval1: value of the coin if reval=2: error number - // 0xFF means NO error or NO signal (as 0 is a valid error/signal) - // signal: channel nr reported from checker 0...15 - - - - - -// neu, 25.3.23 - - void bl_rebootDC(void) const override; - - void bl_startBL(void) const override; - bool bl_checkBL(void) const override; - bool bl_isUp(void) const override; - // return true is bl is up and running - // also initializes "sendFile" - - void bl_sendAddress(uint16_t blockNumber) const override; - // send start address, nr of 64byte-block, start with 0 - // will be sent only for folling block-numbers: - // 0, 1024, 2048, 3072 and 4096, so basically every 64kByte - - uint8_t bl_wasSendingAddOK(void) const override; - // return val: 0: no response by now 1:error 10: OK - - void bl_openBinary(void) const override; - - void bl_sendDataBlock(uint8_t length, uint8_t *buffer) const override; - // send 64 byte from bin file - - void bl_sendLastBlock(void) const override; - - uint8_t bl_wasSendingDataOK(void) const override; - // return val: 0: no response by now 1:error 10: OK - - void bl_stopBL(void) const override; - - - // Bootlader, not used or obsolete - //bool bl_isDiagAvailable(void) const override; - //QString dc_getDiagText(void) const override; - //void bl_startSending(void) const override; - //void bl_sendFile(void) const override; - - - -// neu, ab 6.4.23 -// bereits vorhanden, nochmal getestet/verbessert: - // void led_switchLedPaper(uint8_t on, uint8_t ton, uint8_t tof) const override; - // void alarm_switchSiren(bool on) const override; - - // void mif_readerOn(bool on) const override; - // bool mif_cardIsAttached(void) const override; - - // void shut_move(bool open) const override; - // void esc_moveFlaps(uint8_t flap ) const override; - // 0: close both 1: open take-flap 2: open return - // void shut_openOnce(void) const override; - // and close automatic after shutter time - // void shut_openForCoin(bool start) const override; - // open flap if coin is attached - // once process is started it runs until stop command - // void shut_sendOpeningTime(uint16_t timeIn_ms ) const override; - // after this time without retrigger the flap is closed - // void esc_takeMoney(void) const override; - // and close automatically after escrow time (1s) - // void esc_returnMoney(void) const override; - // and close automatically after escrow time (1s) - - // void prn_switchPower(bool on) const override; - // void prn_sendText(QByteArray *buf) const override; - // up to 1280 bytes - - // uint8_t rtc_setDateTime(void) const override; - // send system time - - //void sendDeviceSettings(uint8_t kindOfPrinter, uint8_t kindOfCoinChecker, - // uint8_t kindOfMifareReader, uint8_t suppressSleep, - // uint8_t kindOfModem, uint8_t kindOfCredit ) const override; - - //void sendMachineID(uint16_t customerNr, uint16_t machineNr, - // uint16_t borough, uint16_t zone, - // uint16_t alias, char *location) const override; - - - bool rtc_setTimeDateDirect(struct Trtc_DateTime *DateTime) const override; - // return true if successful. could fail if more the 8 commands are waiting - - bool rtc_getExtendedTime(uint8_t *leng, uint8_t *data) const override; - bool rtc_getExtendedTime(struct T_extTime *exTime) const override; - - bool sys_runCompleteTest(void) const override; - // warning: lasts 20s in one pace - - bool sys_ready4sending(void) const override; - // return true if a Json-file can be sent - - bool sys_sendJsonFileToDc(uint8_t kindOfFile, uint8_t nrOfTemplate, uint8_t *content ) const override; - // kindOfFile: 1=config, 2=device, 3=cash, 4=serial, 5=time, 6=printer - // nrOfTemplate=1...32 if kindOfFile==6 - // content = content of the Json file, max 800byte ascii signs - // file is 0-terminated! - // return false if sending is not possible, wait a second - - bool prn_sendDynamicPrnValues(uint8_t *dynPrnVal ) const override; - // dynPrnVal = array of 8 Variables with 8 byte each, come as ascii string - // like: char prn_dynPrnVal[8][8]; - // return true if sending, false if cmd-stack is full - - bool prn_printTemplate(uint8_t nrOftemplate) const override; - // print one of the templates loaded by Json prior - // nr = 1..32 - // return true if sending, false if cmd-stack is full - - void log_getHoldAccountNumbers(uint8_t *nrOfVals, uint16_t *accNr ) const override; - // returns all acc nrs of the backuped vault records - // use: uint16_t backupedAccNumbers[8] - - bool log_selectVaultRecord(uint16_t accountNr ) const override; - // return true if sending, false if cmd-stack is full - // and trigger transfer - - bool log_chkIfVaultRecordAvailable(void) const override; - // return true if completly received - - bool log_getVaultRecord(struct T_vaultRecord *retVR) const override; - // which was selected by: log_selectVaultRecord() - // to be forwarded to Ismas - - bool prn_printAccountReceipt(void) const override; - // return true if sending to DC OK, false if cmd-stack is full - - bool prn_printTestTicket(void) const override; - // return true if sending to DC OK, false if cmd-stack is full - - bool cash_startPayment(uint32_t amount) const override; - // 17.4.23TS: extended to 32bit - - bool cash_cancelPayment(void) const override; - // and return coins - - bool cash_stopPayment(void) const override; - // and keep coins in escrow - - uint32_t getInsertedAmount(void) const override; - - uint16_t getLastInsertedCoin(void) const override; - - bool getAllInsertedCoins(uint16_t *types, uint16_t *values) const override; - // alle bei diesem Verkauf eingeworfenen Münzen sind gespeichert, max 64 - - - // after ticket/goods issue: - bool vend_success(void) const override; - // conclude payment process, encash all inserted coins to vault. Printing was successful - // if possible return change - - bool vend_failed(void) const override; - // conclude payment process and return all inserted coins - - - - - - uint8_t mif_getCardType(QString *cardholder) const override; - // return 1,2,3,4 = upper, lower access card, printer test, coin test - // cardholder: 7byte Name-String - - uint64_t sys_getWakeSource(void) const override; - // retval: 6 bytes, bit coded, 1=event keeps DC awake - - uint8_t sys_getWakeReason(void) const override; - // Master was woken by following reason: - // 1: MDB Event - // 2: Coin Event - // ( 3: Master Event) - will not set the wake line - // ( 4: 32s pulse) - will not set the wake line - // 5: Door Event - // ( 6: Diag Event) - will not set the wake line - // 7: 30min-Pulse for HB - - void sys_getDeviceConditions(uint8_t *leng, uint8_t *data) const override; - - void sys_getDeviceConditions(struct T_moduleCondition *devCond) const override; - - void sys_getDynMachineConditions(uint8_t *leng, uint8_t *data) const override; - void sys_getDynMachineConditions(struct T_dynamicCondition *dynMachCond) const override; - - - uint32_t cash_getAmountInVault(void) const override; - - uint16_t cash_getNrCoinsInVault(void) const override; - - uint8_t prn_getPrintResult() const override; - - uint8_t prn_getCurrentPrinterState() const override; - // 0: printer OK - // bit0: near paper end bit1: no paper - // bit2: temperature error bit3: error head open - // bit4: paper jam in cutter - // bit6: no response bit7: serial rec. error - // bit5: printer not ready - - void sys_sendDeviceParameter(struct T_devices *deviceSettings) const override; - - void sys_restoreDeviceParameter(struct T_devices *deviceSettings) const override; - - - /* --------------------------------------------------------------------------------------------- - // ------------ supervise all hardware components - // ------------ assess the machine state - - 1. check if DC startup test is through, retrigger if not - 2. get results and find errors - 3. in case of error check if component is used (e.g. billreader is seldom used) - 4: check doors - 5. return value: 0: no response from DC - 1: no Test results and Test not running. need retrigger! - 2: state not clear by now, test ongoing, wait - 3: Service or battery door is open, goto INTRUSION MODE - from here: after valid ID-card goto SERVICE MODE - 4: vault door is open, goto INTRUSION MODE - from here: after valid ID-card and vault door closed goto TEST MODE - in TEST MODE: complete system check decides if vending mode allowed - 5: All doors are closed but errors found, - goto OOO MODE (out-of-order) - from here: run system test until problem is fixed - 6: All doors are closed, no error, maybe warnings, - goto VENDING MODE (normal operation) - (priority sinks from 0 to 6) - - --------------------------------------------------------------------------------------------- */ - - uint8_t sys_componentAssessment(void) const override; - // this function decides if vending mode is possible, independant from door - // return >0 in case of error - // is inncluded in sys_superviseSystem - - uint8_t sys_superviseSystem(void) const override; - // this function proofs if vending is possible depending of doors state - - - uint8_t sys_getSystemErrors(void) const override; - - // --------------------------------------------------------------------------------------------- - // --------------------------------------------------------------------------------------------- - // --------------------------------------------------------------------------------------------- - -signals: - void hwapi_templatePrintFinished_OK(void) const override; - void hwapi_templatePrintFinished_Err(void) const override; - void hwapi_gotNewCoin(void) const override; - void hwapi_vendStopByMax(void) const override; - void hwapi_vendStopByPushbutton(void) const override; - - private slots: - void hwapi_slotPrintFinished_OK(void); - void hwapi_slotPrintFinished_Err(void); - void hwapi_slotGotCoin(void); - -}; - - -#endif - - - -/* - // Coin checker and changer mdb4.2 / section 5 - // Level 2 Commands (predefined device msg acc. mdb manual and auto-poll) - uint8_t mdb_coin_startPolling(bool on) const override; // send ether one command (from list below) - // or a poll command in the proper polling grid (e.g. every 100ms) - uint8_t mdb_coin_reset() const override; - uint8_t mdb_coin_setup() const override; - uint8_t mdb_coin_tubestatus() const override; - uint8_t mdb_coin_pollManually(void) const override; - uint8_t mdb_coin_type(uint16_t coinEnable, uint16_t dispenseEnable) const override; - uint8_t mdb_coin_dispense(uint8_t disp) const override; - uint8_t mdb_coin_expansion(uint8_t subCmd, uint8_t send[32]) const override; - uint8_t mdb_coin_getResponse(void) const override; - // 0: no response 1: got ACK 2: got NAK 3 got ACK with additional data - uint8_t mdb_coin_getDataLen(void) const override; - // return nr of byte received from any mdb device - uint8_t mdb_coin_getData(uint8_t *mdb_data, uint8_t maxBufferSize) const override; - - - - // Bill validator // section 6 - uint8_t mdb_bill_startPolling(bool on) const override; - uint8_t mdb_bill_reset() const override; - uint8_t mdb_bill_setup() const override; - uint8_t mdb_bill_security(uint16_t secLevel) const override; - uint8_t mdb_bill_pollManually(void) const override; - uint8_t mdb_bill_billType(uint16_t billEnable, uint16_t escrowEnable) const override; - uint8_t mdb_bill_escrow(uint8_t action) const override; - uint16_t mdb_bill_stacker(void) const override; - uint8_t mdb_bill_expansion(uint8_t subCmd, uint8_t send[32]) const override; - uint8_t mdb_bill_gotPollResponse(void) const override; - // 0: no response 1: got ACK 2: got NAK 3 got ACK with additional data - uint8_t mdb_bill_getDataLen(void) const override; - uint8_t mdb_bill_getPollData(uint8_t *mdb_data, uint8_t maxBufferSize) const override; - - - - // Level 3 Commands - all cash devices are used together and automatically - // -->easiest way to use - - // setting up payment: - uint8_t cash_getAcceptance(struct Tcash_state *cash_state) const override; - // return device specific parameters, (e.g. which tubes are installed) - // to be requested before/after payment - uint8_t cash_setMaxReturn(uint32_t amount) const override; // Security Limit - uint8_t cash_setMaxAcceptance(uint32_t amount) const override; // can pay up to this amount - // example: set to 12€ (=max price step), then the 3rd 5€ bill would be kept in escrow - // or with coins: max. insertable = 13,95€ (11,95€ is still <12€, plus a 2€-coin) - uint8_t cash_setCoinsToBeAccepted(uint16_t coinVal[2][16]) const override; - // up to 16 coins per currency in one or two currencies - // [0]=first currency, e.g. Huf [1]=2nd, like euros - uint8_t cash_setBillsToBeAccepted(uint32_t billVal[2][16]) const override; - uint8_t cash_setOpeningTime(uint16_t opentime_100ms) const override; // coin slot is opening/closing automatically - uint8_t cash_setWaitForLastCoinTime(uint16_t lastCoinTime_100ms) const override; - // while this time coin/bill aceptance is still active after "disable payment" command - uint8_t cash_getAllsettings(struct TcashSettings cashSettings) const override; - // return all above set own parameters - - // starting payment - uint8_t cash_powerUp(bool on) const override; // power up/down devices (bill takes up to 3s) - uint8_t cash_enablePayment(bool start) const override; // start/stop accepting bills and coins - - // running payment - bool gotNewCoinBill(void) const override; // true on every insertion, only once - uint8_t cash_getInserted(struct Tcash_pay *payment_state) const override; - - // finishing payment - uint8_t cash_coinEscrowTake(void) const override; - uint8_t cash_coinEscrowReturn(void) const override; - uint8_t cash_return(uint32_t amount) const override; -*/ - - -/* - uint8_t cc_setCondition(uint16_t chgCmd) const override; // e.g. change to state registered, sleep, open, off.... - uint16_t cc_getCondition(void) const override; // e.g. now socket open - bool cc_sendBufferFree(void) const override; // sending allowed (before writing) and sending finished (after writing) - uint8_t cc_sendDataBlk(uint16_t len, uint8_t *buf) const override; - void cc_wantReadData(uint16_t nrOfData) const override; // start reading - uint16_t cc_gotData(void) const override; // return nr of received bytes - uint8_t cc_loadDataBlk(uint16_t len, uint8_t *buf) const override; - uint8_t cc_getWorkFlow(void) const override; - // off, activated, gotStart_wait4card, wait4pin, gotPin, callingBank, CardAccepted..... - uint8_t cc_setupSerial(struct TserialParams serialParameter) const override; - uint8_t cc_getCurrentSerialSettings(struct TserialParams *serialParameter) const override; -*/ - - -/* - -struct TcashSettings -{ - uint32_t MaxReturnAmount const override; - uint32_t MaxAcceptAmount const override; - uint32_t CoinsAcceptedCur[2][16] const override; - uint32_t BillsAcceptedCur[2][16] const override; - uint32_t availableReturnAmount const override; - -} const override; - - -struct Tcc_hw_state -{ - bool powerRdBk const override; // prn pwr is on - bool rsSwOk const override; // serial switch (printer or modem) is set to CreditCard (iUC) - bool rsDrvOk const override; // RS232 converter for PTU, Printer and Modem in on - uint8_t HwState const override; // idle, off, on, ready - bool gotAnswer const override; // cable OK? - uint8_t moduleType const override; - uint8_t protocolType const override; - -} const override; - - -*/ - - -/* - // not yet implemented - uint8_t mod_power(bool on) const override; - uint8_t mod_getHwState(struct Tmod_hw_state *mod_hw_state) const override; - uint8_t mod_setCondition(uint16_t chgCmd) const override; // e.g. change to state registered, sleep, open, off.... - uint16_t mod_getCondition(void) const override; // e.g. now socket open - bool mod_sendBufferFree(void) const override; // sending allowed (before writing) and sending finished (after writing) - uint8_t mod_sendDataBlk(uint16_t len, uint8_t *buf) const override; - void mod_wantReadData(uint16_t nrOfData) const override; // start reading - uint16_t mod_gotData(void) const override; // return nr of received bytes - uint8_t mod_loadDataBlk(uint16_t len, uint8_t *buf) const override; - uint8_t mod_setupSerial(struct TserialParams serialParameter) const override; - uint8_t mod_getCurrentSerialSettings(struct TserialParams *serialParameter) const override; - - // Credit Card Terminal: - uint8_t cc_power(bool on) const override; - uint8_t cc_getHwState(struct Tcc_hw_state *cc_hw_state) const override; - -*/ - diff --git a/DCPlugin/include/interfaces.h b/DCPlugin/include/interfaces.h deleted file mode 100644 index 5261c31..0000000 --- a/DCPlugin/include/interfaces.h +++ /dev/null @@ -1,1710 +0,0 @@ -#ifndef INTERFACE_H -#define INTERFACE_H - -#include -#include - -struct T_emp { - // Fixdata from EMP: - uint8_t shaft; // = changer level - uint16_t countryCode; - uint8_t scale; - uint8_t decimals; - uint8_t coinValues[16]; - uint16_t routing; - - // Master specs: - uint8_t gotSetup; // 1: got specifications from master 0: no specs - uint16_t coinAccept; // bit 0 = coin1 bit H=accept - uint8_t tokenChannel; - uint16_t denomination[16]; - - // dynamic: - uint8_t state; // step counter of EMP (electronic coin checker) FSM (finite state machine): - // 0=Emp & Bus power off, 1=powered, poll off 2=polling on - // 3=device responded, requesting status - // 4=waiting for status 5=have status, - // 6: IDLE, have paramters from master, polling running, ready for payment - // Master can stop/start polling and acceptance - // 7: end of transaction, polling on, accept off, reporting coins, (wait for last coin) - // 8: transaction running, polling on, acceptance on, reporting coins, - - uint8_t pollingRunning; - uint8_t paymentRunning; -}; - -struct Trtc_DateTime { - uint8_t rtc_hour; - uint8_t rtc_min; - uint8_t rtc_sec; - uint8_t rtc_dayOfMonth; - uint8_t rtc_month; - uint8_t rtc_year; - uint8_t rtc_dayOfWeek; -}; - -struct Tprn_hw_state { - // hardware (IO's) - bool powerRdBk; // prn pwr is on - bool rsSwOk; // serial switch (printer or modem) is set to printer - bool rsDrvOk; // RS232 converter for PTU, Printer and Modem in on - - bool ReadyLine; // HW signal from printer showing ready - bool inIdle; // powered and free from errors - bool paperNearEnd; // paper roll runs out - bool noPaper; - bool ErrorTemp; - bool HeadOpen; - bool cutterJam; - bool noResponse; // printer is not connected, cable broken, wrong baudrate - bool badResponse; -}; - -struct Tprn_currentSettings { - uint8_t currFont; - uint8_t currSize; - uint8_t currHeigth; - uint8_t currWidth; - bool nowBold; - bool nowInvers; - bool nowUnderlined; - uint8_t currDensity; - uint8_t currSpeed; - bool nowAligned; -}; - -struct T_dynDat { - uint8_t licensePlate[8]; - uint8_t vendingPrice[8]; - uint8_t parkingEnd[8]; - uint8_t currentTime[8]; - uint8_t currentDate[8]; - uint8_t dynDat5[8]; - uint8_t dynDat6[8]; - uint8_t dynDat7[8]; -}; - -struct T_vaultRecord { - // Kassenbeleg (Abrechnungsdatensatz = Kassenwechsel-Datensatz) - char startbuffer[4]; // Psa> // never move or change this 1st entry - uint16_t AccountingNumber; - uint16_t CUNU; - uint16_t MANU; - uint16_t resint1; - //uint16_t resint2; - - char label1buffer[4]; // tim> - uint8_t year; - uint8_t month; - uint8_t dom; - uint8_t hour; - uint8_t min; - uint8_t sec; - uint8_t DoW; - uint8_t reschar3; - - char label2buffer[4]; // abs> - uint32_t AbsIncome1; - uint32_t AbsReserve; - uint32_t AbsNrOfCuts; - -//16 - char label3buffer[4]; // mw > - - // Verkauf, Tür zu: - uint32_t VKcoinsInserted[16]; // nur für Wechsler, soviel wurde eingeworfen - uint32_t VKcoinsReturned[6]; // nur für Wechsler, Anzahl Münzen pro Typ, soviel wurde zurückgegeben -//88 - // Service, Tür offen: - uint16_t ServCoinsInserted[16]; // nur für Wechsler, soviel wurde eingeworfen - uint16_t ServCoinsReturned[6]; // nur für Wechsler, Anzahl Münzen pro Typ, soviel wurde zurückgegeben - uint16_t resint3; - uint16_t resint4; - uint16_t currentTubeContent[6]; // nur für Wechsler, aktueller Füllstand - uint16_t resint5; - uint16_t resint6; -// 56 - char label4buffer[4]; // box> - uint16_t coinsInVault[16]; - uint16_t billsInStacker[8]; -// 48 - char label5buffer[4]; // val> - // actually constant unless exchange rate is changed - uint16_t coinDenomination[16]; // 5..50000 (z.B. 2? sind in Ungarn 760Ft) - uint16_t billDenom[8]; - uint16_t tubeDenom[6]; - uint16_t exchangeRate; - uint16_t resint9; -// 64 - char endofblock[4]; // end> -// 316 byte Block im Speicher -}; - -struct T_moduleCondition { - // store conditon of all system components, hold in RAM - // 0 means unknown, not yet tested/used - // 1 means OK - // 50..99 = HINT / Notification - // 100..150 = WARNING - // 200..250 = ERROR - - uint8_t ram; - uint8_t intEe; - uint8_t extEe; - - uint8_t rtc; // 1: time/date OK 100: time not plausible 200: hardware error - uint8_t boardHw; - uint8_t printer; - uint8_t modem; - - uint8_t signal; // 1...99 - uint8_t regist; // 100:not 1:reg 2:ping OK 3:gotTime - uint8_t mdbBus; - uint8_t coinChecker; // EMP, OMP or mei-cashflow - - uint8_t coinEscrow; - uint8_t mifareReader; - uint8_t creditTerm; - uint8_t coinReject; - - uint8_t coinSafe; - uint8_t billSafe; - uint8_t voltage; // 1:11..14V - uint8_t temper; - - uint8_t poweronTest; - uint8_t doorState; // 1: alles zu 200: t?r offen + bit1(S) +bit2(CB) + bit3(CB) - uint8_t doorWasOpened; // 1: all doors are closed 200: any door was just opened - uint8_t changer; // can only be tested by usage - - uint8_t coinBlocker; // can only be tested by usage - uint8_t billReader; // can only be tested by usage - uint8_t ResetReason; - uint8_t allModulesChecked; - -}; - -struct T_dynamicCondition { - char allDoorsDebounced; // 99: undefined, 0=all closed, bit1=upper door open 2=midlle door open 3=lower door open - char openedAuthorized; - uint8_t CBinDebounced; - char upperDoor; // 99: undefined 0:closed 1:open - char middleDoor; // 99: undefined 0:closed 1:open - char lowerDoor; // 99: undefined 0:closed 1:open - char reserve; // not used, always 0 - char billBox; - char modeAbrech; - char onAlarm; // 0:alarm aus 1:alarm 2:alarm mit Sirene 3: Sirenentest - char nowCardTest; - char nowPayment; - char lastMifCardType; - uint8_t lastSDoorState; - uint8_t lastVDoorState; - uint8_t lastCBstate; // 99: undefined 0:not there 1:insered - char paymentInProgress; - char res1; - uint16_t U_Batt; - uint16_t Temperatur; - uint16_t nrCoinsInBox; - uint32_t amountInBox; - uint32_t totalTransVolume; - uint32_t totalNrOfVends; - char jsonValid_config; - char jsonValid_device; - char jsonValid_cash; - char jsonValid_print; - char jsonValid_serial; - char jsonValid_time; - char lastFileType; -// 44 - uint8_t MifCardHolder[8]; - uint8_t resultOfLastTemplPrint; - // 0: unknown or printing in progress - // 1: OK, doc was printed 2: error, doc was not printed - uint8_t lastPrinterStatus; - // 0: printer OK - // bit0: near paper end bit1: no paper - // bit2: temperature error bit3: error head open - // bit4: paper jam in cutter - // bit6: no response bit7: serial rec. error - // bit5: printer not ready - uint8_t startupTestIsRunning; - //54 -}; - -struct T_extTime { - uint8_t Hours; - uint8_t Min; - uint8_t Sec; - uint8_t Year; - uint8_t Month; - uint8_t Day; - uint8_t DOW; - uint8_t res1; - uint16_t MinOfDay; - uint16_t res2; - uint32_t SecOfDay; - uint8_t isLeapYear; - uint8_t nxtLeapYear; - uint8_t lastLeapYear; - uint8_t hoursOfThisWeek; - uint16_t minutesOfThisWeek; - uint16_t hoursOfThisMonth; - uint16_t daysOfThisYear; - uint16_t GetHoursOfYear; - uint16_t res3; - uint32_t GetMinutesOfYear; - uint8_t getWakeIntvSec; - uint8_t res4; - uint16_t res5; - uint32_t MinutesOfMillenium; -}; - -typedef uint8_t UCHAR; -typedef uint16_t UINT; - -struct T_devices -{ - // set by master, used(1) or notused (0) or type 2....20 - - UCHAR kindOfPrinter; // 0:off 1:Gebe - UCHAR kindOfCoinChecker; // 0: without 1=EMP820 2=EMP900 3=currenza c² (MW) - UCHAR kindOfMifareReader; // by now only stronglink SL025 =1 - UCHAR suppressSleepMode; // 0:sleep allowed 1: no sleep - - UCHAR kindOfModem; // 0:off 1:Sunlink - UCHAR kindOfCreditcard; // 0:off 1:Feig NFC - UCHAR CoinEscrow; - UCHAR CoinRejectUnit; - - UCHAR CoinShutter; - UCHAR BillAcceptor; - UCHAR usevaultLock; - UCHAR autoAlarm; // 1: switch on siren for 1min in doors opened unauthorized - - UCHAR autoOpen; // 1: open door covers after valid ATBcard - UCHAR printAccReceipt; // 0/1 - UCHAR printDoorReceipt; - UCHAR printTokenTicket; - - UINT VaultFullWarnLevel; - UINT VaultFullErrorLevel; - -}; - - -class hwinf { -public: - enum class DownloadResult {OK, ERROR, TIMEOUT, NOP}; - enum class FileTypeJson {CONFIG=1, DEVICE, CASH, SERIAL, TIME, PRINTER}; - - virtual ~hwinf() {} - - virtual QStringList dc_getStatus() const = 0; - - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - // Use serial interface and protocol stack in Cashagent-Library - // Sending Output data to DeviceController DC2b - // Sending input requests to DC2 (single or auto-batch) - // Getting input data as receiver payload - // Furthermore the Cashagent-Library answers with status strings about sending and reading result - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - - virtual bool dc_openSerial(int BaudNr, QString BaudStr, QString ComName, uint8_t connect) const = 0; - // Command: open serial interface - // BaudNr: 0:1200 1:9600 2:19200 3:38400 4:57600 5:115200 - // BaudStr: for exapmle "19200" - // ComName: for example "COM48" - // connect: 0, 1 - - virtual bool dc_closeSerial(void) const = 0; - // Command: close serial interface in order to save power while power down - // or if another port must be used - - virtual bool dc_isPortOpen(void) const =0; - // returns true if port open (don't send unless open. Sending to closed port will crash program) - - - - virtual uint8_t test_serialState(void) const =0; - // test on-board signals for the serials - // serial drv on/off, Serial mux1, Serial mux2 - - virtual bool test_serialIsOn(void) const =0; - - virtual bool dc_updateDC(QString binFileName, - QString baudrate, - QString comPort) const = 0; - // download binary file down into device controller - - virtual bool dc_updatePrinterTemplate(enum FileTypeJson type, - QVector templateIdx, - QVector fnames, - QString br, - QString serial = QString()) const = 0; - - virtual bool dc_printTemplate(enum FileTypeJson type, - QVector templateIdx, - QString br, - QString serial = QString()) const = 0; - - virtual void dc_autoRequest(bool on) const =0; - // on = true: select that all READ-Requests are sent automatically - // on = false: select that all READ-Requests are sent manually one by one - // Every input information from DC2 must be requested - // ( digital and analog sensors, get time/date, get status information ) - - virtual uint8_t dc_isRequestDone(void) const =0; - // retval: 0: request is still in progress - // 1: answer from DC2 was OK - // 2: wrong answer from DC2 - - virtual uint16_t dc_getCompletePayLoad(uint16_t plBufSiz, uint8_t *payLoad) const =0; - // get data back in "payLoad", max 64 byte, can be used for diagnosis - // retval = nr of bytes received. If host buffer too small then - // only plBufSiz bytes are copied to "payLoad" - // plBufSiz­z=size of host buffer - - virtual void dc_requTestResponse() const =0; - // tell DC2 to send a test-string, useful to see if cable and baudrate is OK - - virtual bool dc_readAnswTestResponse() const =0; - // retval: true: test was successful, got right response - - virtual uint8_t getRawRecLength(void) const =0; - // only needed if protocol stack in Cashagent-Library is bypassed - - virtual uint8_t getRawReceivedData(uint8_t *receivedData) const =0; - // only needed if protocol stack in Cashagent-Library is bypassed - - virtual QString dc_getSerialState(void) const =0; - // get result of opening-command like "ttyS0 opened with 115200 8N1! - // or error messages like "comport not available..." - // was saved by last opening event, can be passed for 100ms - - virtual void dc_clrSerialStateText(void) const =0; - // clear above text to avoid multiple repetive displaying - - - virtual QString dc_getTxt4HsStateLine(void) const =0; - // return string with status of handshakes - - virtual void dc_clrTxt4HsStateLine(void) const =0; - // clear above text to avoid multiple repetive displaying - - - virtual QString dc_getTxt4masterStateLine(void) const =0; - // returns string telling if the received packet is valid and complies protocol - // if OK: "slave response OK" in case of error: "wrong length received", "wrong start sign received", - // "received datalen to big", "wrong data len received", "wrong crc received" - - virtual void dc_clrTxt4masterStateLine(void) const =0; - // clear above text to avoid multiple repetive displaying - - - virtual QString dc_getTxt4resultStateLine(void) const =0; - // returns string telling response of DC. First question: did DC get a correct request telegram? - // and if: 2nd question did DC perform the contained output and input commands - // if OK: "Slave OUT and IN Result: 0 0" - // in case of error: "slave got wrong start sign" ..length" ...crc" ... address" - // slave does not perform and command! - // 2nd) received telegram was OK, DC tried to perform the master commands. result - // result of writing data (e.g switching leds and motors, sending stuff to printer...) - // OUT = 0: OK 1: unknown command 2: operation not possible - // result of reading data (e.g. switches, voltages, accepted coins, printer status....) - // IN = 0: OK 1: unknown command 2: could not read due to hardware error 3: could not read because device is off - - virtual void dc_clrTxt4resultStateLine(void) const =0; - // clear above text to avoid multiple repetive displaying - - - virtual QString dc_getdataStateLine(void) const =0; - // check if recveied input data are ok/valid - // OK-string : "valid INdata...." with protocol details - // not OK: string empty - - virtual void dc_clrTxt4dataStateLine(void) const =0; - // clear above text to avoid multiple repetive displaying - - - virtual QString dc_getdatifLine(void) const =0; - // returns string with result of function dc_requTestResponse() - // "correct" or "false" - - virtual void dc_clrTxt4datifLine(void) const =0; - // clear above text to avoid multiple repetive displaying - - - virtual QString dc_getTxt4RsDiagWin(void) const =0; - // returns string to be displayed in "serial traffic" window - // details about sent and received protocol - - virtual void dc_clrTxt4RsDiagWin(void) const =0; - // clear above text to avoid multiple repetive displaying - - virtual QString dc_get2ndTxt4RsDiagWin(void) const =0; - // returns string to be displayed in "serial traffic" window - // details about sent and received protocol - - virtual void dc_clr2ndTxt4RsDiagWin(void) const =0; - // clear above text to avoid multiple repetive displaying - - -// 28 functions - - - - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - // DC2b internal data - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - - - virtual QString dc_getSerialParams(void) const =0; - // get DC2 serial settings (not very meaningful as they will not come if different from master settings) - - virtual QString dc_getHWversion(void) const =0; - // get DC2 hardware version - - virtual QString dc_getSWversion(void) const =0; - // get DC2 software version - - virtual QString dc_getState(void) const =0; - // get DC2 status (every OK or any error/warning? ) - - - // UID - unique number, different in every DC - virtual void dc_getUID8byte(uint8_t *buf8byteUid) const =0; - // get 8 single bytes in buffer - - virtual QString dc_getUIDstr() const =0; - // get as string - - virtual uint64_t dc_getUIDnumber(void) const =0; - // get UID as one long number - - // Analog values: - virtual uint32_t dc_getTemperature(void) const =0; - // in Sax-Format 0...400 (0=-50,0°C 100=0,0°C 141=20,5°C 400=150,0°C) - - virtual QString dc_getTemperaturStr(void) const =0; - // as string like "-12,5°C" - - virtual uint32_t dc_getVoltage(void) const =0; - // as value in mV, 0...65,535V - - virtual QString dc_getVoltagStr(void) const =0; - // as string in mV - - virtual bool dc_mainFuseIsOk(void) const=0; - // true if 12V fuse is OK - // false: fuse blown, DC will continue working but no 12V device can be used! - - virtual void dc_setWakeFrequency(uint8_t period) const =0; - // RTC wakes DC2 (and PTU) by hardware signal every 32seconds - // change wake signal period to 1...64s - - virtual void dc_OrderToReset(void) const =0; - // want DC2 to reset (in order to start Bootloader) - - - - // all read-requests can be sent manually by the following functions - // or automatically in background by: void hwapi::dc_autoRequest(bool on) - // in other words: - // if automatic-reading is on, then there's no need to send any of these commands, - // but it's allowed to send them in order to speed up the refreshing of the inputs - - virtual void request_DC2serialConfig() const =0; - // read-request can be sent manually by this function, not needed if auto-request is on - - virtual void request_DC2_HWversion() const =0; - // read-request can be sent manually by this function, not needed if auto-request is on - virtual void request_DC2_SWversion() const =0; - // read-request can be sent manually by this function, not needed if auto-request is on - virtual void request_DC2_condition() const =0; - // read-request can be sent manually by this function, not needed if auto-request is on - virtual void request_DC2_UID() const =0; - // read-request can be sent manually by this function, not needed if auto-request is on - - - virtual void request_DC2_analogues() const =0; - // read-request can be sent manually by this function, not needed if auto-request is on - virtual void request_DC2_digitalInputs() const =0; - // read-request can be sent manually by this function, not needed if auto-request is on - virtual void request_DC2_digitalOutputs() const =0; - // read-request can be sent manually by this function, not needed if auto-request is on - -// 22 - - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - // using DC2 Bootloader - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - - virtual void bl_sendDataDirectly(uint8_t length, uint8_t *buf) const =0; - // send without protocol frame, needed for the DC bootloader - - virtual void bl_iniChain(void) const =0; - - virtual bool bl_importBinFile(QByteArray readBinFile, uint32_t fileSize, char withDispl) const =0; - - virtual uint8_t bl_activatBootloader(uint8_t *sendData) const =0; - - virtual uint8_t bl_startChain(void) const =0; - - virtual uint8_t bl_readBLversion(uint8_t *sendData) const =0; - // minimum size of sendData-buffer: 5byte retval: length - - virtual uint8_t bl_readFWversion(uint8_t *sendData) const =0; - // minimum size of sendData-buffer: 5byte retval: length - - virtual uint8_t bl_prepareDC_BLcmd(uint8_t Cmd, uint8_t SendDataLength, uint8_t *sendData, uint8_t *outBuf) const =0; - // make BL protocol, retval = outbuf length (5...133) - // bring data in correct form: start always with 0x02 finish with 0x03 and append checksum - // 0x02 Cmd < ...sendData ..> CRC CRC 0x03 - // Data length = 0...64 - // special conversion: if data contain 2 or 3 (STX, ETX) then write two bytes: 0x1B (=ESC) and data|0x80 - // so maxlength = 5 + 2 x 64 (if all data are 2 or 3) without 2,3: maxlength = 5 + 64 - - virtual uint8_t bl_exitBL(uint8_t *sendData) const =0; - // minimum size of sendData-buffer: 5byte retval: length - - - - -// 9 - - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - // get Time and Date from DC2b (contains a buffered real time clock) valid for about three days without power - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - - virtual uint8_t rtc_getDateTime(struct Trtc_DateTime *rtc_DateTime) const =0; - - virtual uint8_t rtc_setDateTime(void) const =0; - // synch DC2 with PC or PTU system time and date - - virtual void rtc_getTime(uint8_t *hh, uint8_t *mm, uint8_t *ss) const =0; - // get time directly - - virtual void rtc_getDate(uint8_t *yy, uint8_t *mm, uint8_t *dd) const =0; - // get date directly - - virtual uint8_t rtc_getToday(uint8_t *dow, uint16_t *minOfToday, uint32_t *secOfToday) const =0; - // dow=day of week, 1=monday...7 - // minOfToday: 0=midnight...1439= 23:59 - // secOfToday: 0=midnight...86399= 23:59:59 - - virtual bool rtc_isLeapYear(uint8_t *lastLeapYear, uint8_t *NextLeapYear) const =0; - // retval true: this year is leap year - - virtual bool rtc_isLeapYear() const =0; - - virtual void rtc_getWeek(uint8_t *DayOfWeek, uint8_t *HoursOfWeek, uint16_t *MinutesOfWeek) const =0; - // DayOfWeek: 1=monday...7 - // HoursOfWeek: 0=Monday 0:00 o'clock...167=Sunday 23:00 - // MinutesOfWeek: 0=Monday 0:00 o'clock...10079=Sunday 23:59 - - virtual void rtc_getMonth(uint8_t *DayOfMonth, uint16_t *HoursOfMonth, uint16_t *MinutesOfMonth) const =0; - // DayOfMonth: 1...31 - // HoursOfMonth: 0 = 0:00o'clock of 1.day in month up to 743 - // MinutesOfMonth:0 = 0:00o'clock of 1.day in month up to 44639 - - virtual void rtc_getYear(uint16_t *DayOfYear, uint16_t *HoursOfYear, uint32_t *MinutesOfYear) const =0; - // DayOfYear: 1...366 1= 1.Jan of this current year - // HoursOfYear: 0=1.Jan 0:00o'clock ...8783=31.12 23 o'clock - // MinutesOfYear: 0=1.Jan 0:00o'clock ...527039=31.12 23:59 o'clock - - virtual QString rtc_getTimStr(void) const =0; - virtual QString rtc_getDatStr(void) const =0; - virtual QString rtc_getTimDatStr(void) const =0; - - - - - virtual void request_DC2_TimeAndDate() const =0; - // read-request can be sent manually by this function, not needed if auto-request is on - - - -// 14 - - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - // PTU, Master - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - - virtual void ptu_switchWake(bool WAKEACTIVE) const =0; - - virtual bool ptu_WakeINisActive(void) const =0; - - virtual bool ptu_WakeOutIsOn(void) const =0; - - virtual void sendDeviceSettings(uint8_t kindOfPrinter, uint8_t kindOfCoinChecker, - uint8_t kindOfMifareReader, uint8_t suppressSleep, - uint8_t kindOfModem, uint8_t kindOfCredit ) const =0; - // enable hardware in device controller: - // kindOfPrinter: 0:off 1: GPT4672 (only this one implemented) - // kindOfCoinChecker: 0:off 1:EMP820 2:EMP900 3: C²_changer - // kindOfMifareReader: 0:off 1: SL025 (only this one implemented) - // suppressSleep: 0:sleep allowed 1: sleep surpressed for special reason - // kindOfModem: 0:off 1: ATB_Sunlink_LTE (not yet implemented) - // kindOfCredit: 0:off 1: cVendTopp 2:cVendPin (not yet implemented) - - - virtual void request_ReadbackDeviceSettings() const =0; - - virtual void readback_DeviceSettings(uint8_t *length, uint8_t *data) const =0; -/* - buf66[0]=devPara.kindOfPrinter; - buf66[1]=devPara.kindOfCoinChecker; - buf66[2]=devPara.kindOfMifareReader; - buf66[3]=devPara.suppressSleepMode; - buf66[4]=devPara.kindOfModem; - buf66[5]=devPara.kindOfCreditcard; - buf66[6]=devPara.CoinEscrow; - buf66[7]=devPara.CoinRejectUnit; - buf66[8]=devPara.CoinShutter; - buf66[9]=devPara.BillAcceptor; - buf66[10]=devPara.usevaultLock; - buf66[11]=devPara.autoAlarm; - buf66[12]=devPara.autoOpen; - buf66[13]=devPara.printAccReceipt; - buf66[14]=devPara.printDoorReceipt; - buf66[15]=devPara.printTokenTicket; - uitmp=devPara.VaultFullWarnLevel; - buf66[16]=swl_getOneByteFromUint(uitmp, GETLOWBYT); - buf66[17]=swl_getOneByteFromUint(uitmp, GETHIGHBYT); - uitmp=devPara.VaultFullErrorLevel; - buf66[18]=swl_getOneByteFromUint(uitmp, GETLOWBYT); - buf66[19]=swl_getOneByteFromUint(uitmp, GETHIGHBYT); - -*/ - - virtual void sendMachineID(uint16_t customerNr, uint16_t machineNr, - uint16_t borough, uint16_t zone, - uint16_t alias, char *location) const =0; - - virtual void request_ReadbackMachineID() const =0; - - virtual void readback_machineIDdata(uint8_t *length, uint8_t *data) const =0; - // state 5.5.21: byte[0,1]=customer number byte[2,3]=machine number - // byte[4,5]=borough byte[6,7]=zone byte[8,9]=alias name - // byte[10...41]=location - // 12.4.23TS still the same - - - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - // Printer - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - - - - virtual void prn_switchPower(bool on) const =0; - - virtual bool prn_isPrinterPowerOn(void) const =0; - - virtual uint8_t prn_PrnFuseIsOk(void) const=0; - //retval: 0: fuse blown 1: fuse OK 2:unknown as printer power is off - - virtual bool prn_readyINisActive(void) const =0; - - virtual uint8_t cash_getLowPaperSensor(void) const=0; - // 0: Sensor sees paper 1: no paper 99: off - - // the following device state requests are deployed only if device is powered up: - virtual void request_PrinterHwState() const =0; - virtual void request_PrinterCurrentFonts() const =0; - virtual void request_PrinterStateComplete() const =0; - - virtual bool test_serialMux1isSetToPrinter(void) const =0; - - // read printer condition and settings - - virtual uint8_t prn_getHwState(struct Tprn_hw_state *prn_hw_state) const =0; - // retval: status byte - // byte 0 = 0: prnter OK, >0: error - // bit0: paper low 1: no paper 2: temperature error - // 3: head open 4: paper jam in cutter - // 6: no response 7: bad response from printer - // and return struct "Tprn_hw_state" - - virtual bool prn_isUpAndReady(void) const =0; - // true: printer is powered, serial is ok, no error, printer is connected and resonding - - virtual void prn_getCurrentFontSetting(struct Tprn_currentSettings *prn_fonts) const =0; - - - // send Commands to printer: - - virtual void prn_sendText(QByteArray *buf) const =0; - // up to 1280 bytes - - virtual void prn_sendPrnSysCmd(uint8_t para1, uint8_t para2, uint32_t para3) const =0; - // send three byte through to printer, see printers manual - - virtual void prn_sendPrnEscCmd(uint8_t para1, uint8_t para2, uint8_t para3, uint8_t para4) const =0; - // send four byte through to printer, see printers manual - - - virtual void prn_sendPrnSetup(uint16_t paperSpeed, uint8_t density, uint8_t alignment, uint8_t orientation) const =0; - // send 5 byte: byte 0,1: speed 5...250 mm/s - // byte2: density 0....(25)....50 - // byte3: alignment 'l', 'c', 'r' = left, center, right - // byte4: orientation 0, 90, 180 = 0°, 90°, 180° rotation (by now not supported!) - // not batched! don't use twice within 100ms - - virtual void prn_movePaper(uint8_t wayInMm, uint8_t direction) const =0; - //direction: 1=forward 2=backward - // - virtual void prn_setFonts(uint8_t font, uint8_t size, uint8_t width, uint8_t height) const =0; - // font = kind of font 5...11 (0..22) - // size = 6...20, 9..9: too tiny 10: small ...12 = normal size ...20=huge - // width: 0...4 0=1x 1=2x 2=4x (huge!) 3=8x 4=16x (3,4 make no sense) - // heigth: 0...7 = 1x...8x only 0,1,2,(3) make sense - - virtual void prn_setLetters(uint8_t bold, uint8_t invers, uint8_t underlined) const =0; - // bold: 0/1 - // invers: 0/1 - // underlined: 0/1 - - virtual void prn_cut(uint8_t kindof) const =0; - // kindof: 1=full cut 2=partial cut 3=eject (5xLF + full cut) - - virtual void prn_newLine(uint8_t nrOfLines) const =0; - - virtual void prn_printCompleteFontTable(void) const =0; - - virtual void prn_printBarcode(uint8_t kindOf, uint8_t withText, uint8_t offset, uint8_t rotation, uint8_t dataLeng, uint8_t *data) const =0; - // kind of barcode: 0=Code39 1=Code128 2=EAN13 3= 2/5interleaved 4=UPC-A 5=EAN8 - // withText: print readable text below - // offset: move by pixel from left border - // rotation - // dataLeng in byte - - virtual void prn_sendQRdata(QByteArray *buf) const =0; - // maximal 150 alphanummeric bytes - - virtual void prn_printQRcode(void) const =0; - // QRcode may have 1...150 alphanummeric data, must be transfered in advance - - - virtual void prn_printLogo(uint8_t nrOfLogo, uint8_t offset ) const =0; - // nrOfLogo: 1..4 in flash 5...8 in Ram - // offset: in mm form left border - - - - // ......................................................... - // Parking Ticket (print-out document) designer TD - // ......................................................... - - // Predefine document Layout (e.g. parking ticket) in advance and stroe it for quick and easy use - // in opposite to the above "single" commands you need only one or a few commands at vending time. - // Stored text is just send to printer once the printing command is issued - // stored commands within the text are interpreted and executed right at the place (in ticket) they are - // example: start bold, , stop bold - // Predefinition of up to 16 ticket Layouts is possible, 0...1280 byte each - // Number 0..15, al keept non-volatile - // up to 8 dynamic values can be defined in the template ("print val3 here") and will be sent with printing command - // example: print current time at this point (the time of printing not the storage time!!) - - virtual void pri_startTicketDesign(void) const =0; - // start for every new printer document, reseting collecting buffer - - // all further functions write/append text, numbers and command to the ticket-buffer, up to 1278 bytes allowed - // return val of the appending functions: true=ok false=too long, buffer full - - virtual int pri_TD_getCurrentSize(void) const =0; - // retval: 0...1278 - - virtual bool pri_TD_addText(QByteArray text) const =0; - // example: pri_TD_addText("Hello") const =0; - // example: pri_TD_addText(tempStr) const =0; - // retval: true=ok false=too long, buffer full - - virtual bool pri_TD_addValue(int val) const =0; - // +/- 0...2^(31) - - virtual bool pri_TD_addNewLine(void) const =0; - - virtual bool pri_TD_addSign(char sign) const =0; - // example: '.' ' ' 0x20 'W' '$' - - virtual bool pri_TD_addCommand(char group, char attribute, char p1, char p2, char p3, char p4, char p5) const =0; - // always add 8 byte to the ticket layout: ESC & group & attribute & parameter1...5 - /* complete list of possible commands: - group 50 : paper - attribute 10 : move forward - p1: wayInMm p2: direction - attribute 11 : cut - p1: kind of, 1=full 2=partial, 3=eject - attribute 12 : new line(s) - p1: nr of lines 1...100 - - group 51 : fonts - attribute 10 : kind of font see description above - p1: 0...8 - attribute 11 : font size - p1: 6...20 - attribute 12 : font width - p1: 0...4 - attribute 13 : font heigth - p1: 0...7 - attribute 14 : switch bold print on/off - p1: 0=off 1=on - attribute 15 : switch invers print on/off - p1: 0=off 1=on - attribute 16 : switch underlined print on/off - p1: 0=off 1=on - - group 52 : print graphics - attribute 10 : print barcode with dynamic data 6 and 7 - p1...p5 = kindOf, withText, offset, rotation, dataLeng, see description above - attribute 11 : print QRcode with preset data - - attribute 12 : print Logo - p1=nrOfLogo, p2=offset - - group 53 : print dynamics - attribute 10 : - p1: 1...8 = print dynData 0..7 at this place - - */ - - virtual char prn_clearDocument(uint8_t documentNumber) const =0; - // clear memory buffer for ONE document - // function takes a second! don't send right before "store doc" - - virtual bool prn_store_Document(uint8_t documentNumber ) const =0; - // send the predefined Layout (generated with above TD functions) to DeviceController to save - // documentNumber=0...15 - // maximal 1280 bytes each - // allowed: 0x20...0xFF, 0x0A, 0x0C, 0x1B (LF, CR, Esc) - // 0x1B=start of embedded command (next 7bytes = command) - - // with a print command a set of 8 dynamic strings can be sent - // the place in the ticket layout is predefined (already in DC memory) - // the dynamics are first calculated at printing time - - virtual bool prn_printDocument(uint8_t documentNumber, struct T_dynDat *dynTicketData) const =0; - - -// 36 - - - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - // Mifare Card Reader - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - - virtual void mif_readerOn(bool on) const =0; - - virtual bool mif_cardIsAttached(void) const =0; - virtual bool mif_isMifarePowerOn(void) const =0; - - virtual void request_MifareReaderState() const =0; - virtual void request_MifareCardType() const =0; - virtual void request_MifareAtbType() const =0; - virtual void request_MifareID() const =0; - virtual void request_MifareData(uint8_t dataBlockNumber) const =0; - //virtual void request_MifareData() const =0; - - // dataBlockNumber must be 0....11, returns 64byte of data - - - virtual bool test_serialMux2isSetToMifare(void) const =0; - - virtual void mif_creatAtbCard(uint8_t cardType) const =0; - - /* data description: - byte 0: current read state: 0=power off 1=reader-fault 2=ready - 3=just reading 4=read complete - 5=read partial, removed too early - 6=state unknown - byte 1,2: read data length from card - 3: 1=reader is OK (reported serial nr is OK) 0=wrong or no reader - 4...15: reader version, expected "ATB25-1.8" - byte16: 1=card is present 0:not - 17: 0 - 18: card type reported from reader - 19: 1=allowed card type 0=not - 20: card size: 1 or 4 (dec) = card size - 21: LengthOfUID: 4 or 7 (dec) (byte) - 22: UID 8 byte in hex - byte 30: sector logged: 0 - byte 31: current sector: 0 - byte 32: result, always 0 - */ - virtual uint8_t mif_returnReaderStateAndCardType(uint8_t *buf, uint8_t maxBufferSize) const =0; - // retval 0=OK 1=error host buffer too small - - virtual bool mif_readerIsOK(void) const =0; - - virtual bool mif_cardAttached(void) const =0; - - virtual uint8_t mif_readResult(void) const =0; - // result: 0: unknown or still in progress - // 1: card read successful - // 2: reading error - - //virtual void mif_clearDataBuffer(void) const =0; - - virtual QString mif_cardUID(void) const =0; - // returns string with 8 byte - - //virtual bool mif_isBlockAvailable(uint8_t blkNr) const =0; - //blkNr=0...11 - - //virtual uint32_t mif_getAvailableDataBlocks(void) const =0; - // bit0=1 if block 0 = valid ...up to ... bit 11=1 if block 11=read - - virtual uint8_t mif_getCardDataDec(uint8_t blkNr, uint8_t *buf, uint8_t maxBufferSize) const =0; - - virtual QString mif_getCardDataStr(uint8_t blockNumber) const =0; - // with blockNumber=0...11 - - // read mifare data independant from blocks - //virtual uint16_t mif_getNrOfAvailableDataBytes(void) const =0; - - //virtual bool mif_getCardData768byteDec(uint8_t *buf, uint16_t bufferSize) const =0; - - //virtual bool mif_getCardDataDec(uint16_t fromAddr, uint16_t toAddr, uint8_t *buf, uint16_t bufferSize) const =0; - - //virtual QString mif_getCardDataStr(bool useHexFormat, char seperator) const =0; - -// 16 - - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - // Credit Card Terminal - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - - virtual void credit_switchPower(bool on) const =0; - // the same as modem power - - virtual bool cred_isCreditPowerOn(void) const =0; - - virtual bool test_serialMux2isSetToCredit(void) const =0; - - virtual void credit_switchWake(bool WAKEACTIVE) const =0; - -// 4 - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - // Modem - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - - virtual void mod_switchPower(bool on) const=0; - - virtual bool mod_isGsmPowerOn(void) const =0; - - virtual bool test_serialMux1isSetToModem(void) const =0; - - virtual void mod_switchWake(bool WAKEACTIVE) const=0; - -// 2 - - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - // MDB Bus - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - - virtual void mdb_switchPower(bool on) const =0; - virtual void mdb_switchWake(bool WAKEACTIVE) const =0; - - virtual bool mdb_WakeINisActive(void) const =0; - virtual bool mdb_testIsmdbTxDon(void) const =0; - virtual bool mdb_isMdbPowerOn(void) const =0; - - virtual void request_MDB_Status() const =0; - virtual void request_MDB_lastResponse() const =0; - - virtual bool test_getDO_mdbRXtst(void) const =0; - // readback digital outputs of connected devices - // these functions are not needed for normal operation - // but can be used to test and verify conditions - - virtual void mdb_sendBusReset(void) const =0; - - virtual void mdb_sendCommand(uint8_t toMdbDevice, uint8_t mdbCommand) const =0; - // send one bus command directly over mdb bus, refer to mdb manual for commands - // this command is not needed in normal operation, just for new or special things - - virtual void mdb_sendMessage(uint8_t toMdbDevice, uint8_t mdbCommand, uint8_t nrOfData, uint8_t *dataBuffer) const =0; - // nrOfData = sizeOf(dataBuffer) maximal 34 byte according mdb specs - // same as mdb_sendCommand, just with data - - virtual bool mdb_busIsReadyToWork() const =0; - - virtual bool mdb_deviceVoltageOK() const =0; - - virtual bool mdb_busVoltageOk() const =0; - - virtual uint8_t mdb_getLastDeviceResponse(uint8_t *fromDevice, uint8_t *lastRequest, - uint8_t *responseLength, uint8_t *responseBuffer) const =0; - // fromDevice: device nr from which data was requested 0,1,2,3 - // lastRequest: sent mdb command - // responseLength: nr of payload data (after mdb-ack) 0...34 - // responseBuffer holds payload data (answer from mdb device) - // return val: mdb result of this request: 1=got ACK 2=got 3xNAK 3=no or bad response 4:got Data (after ACK) - - -// 15 - - - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - // Coin Changer, Checker (EMP) - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - - virtual void request_EMP_allParameters() const =0; - - virtual void request_EMP_lastCoin() const =0; - - virtual uint8_t emp_returnLastCoin(uint16_t *value, uint8_t *signal) const =0; - // use for changer - - - // ---------------------------------- Electronic Coin Validator EMP ----------------------------------------- - - virtual void emp_sendSettings(uint16_t coinAcceptance, uint8_t tokenChannel, uint16_t *coinDenomination ) const =0; - // coinAcceptance: bit0=coin1 (lowest donomination) bit15=coin16 bitH=accept bit L = deny coin (no validation) - // tokenChannel 0...31: if this signal comes from emp then a token was inserted - // coinDenomination = array of 16 coin values (e.g. 5, 10, 20...) - - virtual void emp_pollingOnOff(uint8_t on) const =0; - - virtual void emp_startCoinAcceptance(void) const =0; - - virtual void emp_stopCoinAcceptance(void) const =0; - - virtual void emp_getAllParameters(struct T_emp *emp) const =0; - // see struct in hwapi.h - // usage example: - // hwapi *HWaccess const =0; - // HWaccess = new hwapi() const =0; - // struct T_emp myEmp const =0; - // HWaccess->emp_getAllParameters(&myEmp) const =0; - // readval=myEmp.pollingRunning const =0; - - virtual uint8_t emp_chkIfCoinInserted(void) const =0; - // retval: 0...16 coins left in FIFO - - virtual void emp_getNewCoinRecord(uint8_t *valid, uint8_t *signal, uint8_t *error, uint16_t *value) const =0; - // with every call ONE coin is taken out of FIFO and pointer decremented - // valid: should be 1 - // signal: comes right from coin checker, 0...15 (0=first programmed coin type) 0xFF=no signal - // error: was reported from EMP as dynamic signal right after coin insertion (instead of - // coin signal), example: 3=unknown coin 4=coin is blocked by host. 0xFF=no error - // value: of the coin. Depends on parameter "coinDenomination" in function "emp_sendSettings" - // if coinDenomination[coin 0..15] = 0 then the value programmed in coin checker is taken - // if coinDenomination > 0 then this value is taken. - // Useful in case of two currencies (adapt to local currency) or for token. - - // function gives more details as "emp getLastCoin()" but "emp getLastCoin()" is easier to use - - // alternativ to emp_getNewCoinRecord( ): - virtual uint8_t emp_giveLastCoin(uint16_t *value, uint8_t *signal) const =0; - // retval: 0: NO coin stored 1: valid coin 2: got wrong coin or coin denied - // value: if retval1: value of the coin if reval=2: error number - // 0xFF means NO error or NO signal (as 0 is a valid error/signal) - // signal: channel nr reported from checker 0...15 - -// 11 - - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - // Coin blocker, Coin Escrow, Coin reject - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - - virtual void shut_move(bool open) const =0; - virtual void esc_moveFlaps(uint8_t flap ) const =0; - // 0: close both 1: open take-flap 2: open return - - virtual void coin_switchRejectMotor(uint8_t dir) const =0; - virtual bool coid_isAttached(void) const =0; - virtual bool coin_escrowIsOpen(void) const =0; - virtual bool cash_getRejectMotorHomePos(void) const=0; - - - virtual bool coin_shutterIsOpen(void) const =0; - virtual bool coin_shutterTestOutput(void) const =0; - - virtual uint8_t coin_escrowFlapOpened(void) const =0; - // retval: 1:return flap is open 2:take flap is open 0:closed - - virtual void shut_openOnce(void) const =0; - // and close automatic after shutter time - - virtual void shut_openForCoin(bool start) const =0; - // open flap if coin is attached - // once process is started it runs until stop command - - virtual void shut_sendOpeningTime(uint16_t timeIn_ms ) const =0; - // after this time without retrigger the flap is closed - - virtual void esc_takeMoney(void) const =0; - // and close automatically after escrow time (1s) - - virtual void esc_returnMoney(void) const =0; - // and close automatically after escrow time (1s) - - virtual void coin_rejectCoins(void) const =0; - -// 15 - - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - // MDB Bill evaluator - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - - - - - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - // doors, locks, cashboxes - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - - virtual void lock_switchContactPower(bool on) const =0; - - virtual bool door_isContactPowerOn(void) const =0; - - virtual uint8_t door_getLocks(void) const =0; - // retval bit0: upper lever is up (=open) - // bit1: upper lever is down (=locked) - // bit2: lower lever is up - // bit3: lower lever is down (=locked) - - virtual bool door_upperDoorIsLocked(void) const =0; - - virtual bool door_upperDoorIsUnlocked(void) const =0; - - virtual uint8_t lock_switchUpperLock(uint8_t dir) const =0; - // dir 0=off 1=up 2=down - // move lock until stop cmd (0) - - virtual uint8_t lock_openUpperDoor(void) const =0; - // Locks stops automatically at end switch or by timeout - - virtual uint8_t lock_closeUpperDoor(void) const =0; - // Locks stops automatically at end switch or by timeout - - virtual uint8_t door_getSwitches(void) const =0; - // retval: bit0: upper door 1: low door 2:vault door - - virtual bool door_isUpperDoorOpen(void) const =0; - - - virtual bool door_lowerDoorIsLocked(void) const =0; - - virtual bool door_lowerDoorIsUnlocked(void) const =0; - - virtual uint8_t lock_switchLowerLock(uint8_t dir) const =0; - // dir 0=off 1=up 2=down - // move lock until stop cmd (0) - - virtual uint8_t lock_getDO_motors(void) const =0; - // bit0: upper lock forward bit 1 backward - // bit2: lower lock forward bit 3 backward - - virtual uint8_t lock_openLowerDoor(void) const =0; - // there's no closing function as Lock always makes one complete cycle and can be locked again immed. - - virtual uint8_t lock_closeLowerDoor(void) const =0; - - virtual bool door_isLowerDoorOpen(void) const =0; - - virtual uint8_t vault_getSwitches(void) const =0; - // retval bit0: cash box, bit 1: bill box - - virtual bool vault_isVaultDoorOpen(void) const =0; - - virtual void lock_switchVaultDoor(void) const =0; - - virtual bool vault_isCoinVaultIn(void) const =0; - - virtual bool vault_isBillVaultIn(void) const =0; - -// 21 - - - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - // LEDs, Barrier, Alarm, Relais, Aux - // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - - virtual void led_switchLedIllumination(uint8_t on) const = 0; - - virtual void led_switchLedCoinbassin(uint8_t on, uint8_t ton, uint8_t tof) const =0; - - virtual bool led_coinIsOn(void) const =0; - // read back digital output from DC-uC-Port - virtual bool led_frontIsOn(void) const =0; - - virtual void led_switchLedService(uint8_t on) const =0; - // on=1 off=0 - virtual bool led_insideIsOn(void) const =0; - - virtual void led_switchLedPaper(uint8_t on, uint8_t ton, uint8_t tof) const =0; - virtual bool led_ticketIsOn(void) const =0; - - virtual void led_switchLedStart(uint8_t on, uint8_t ton, uint8_t tof) const =0; - virtual bool led_StartIsOn(void) const =0; - - virtual void led_switchLedPinPad(uint8_t on, uint8_t ton, uint8_t tof) const =0; - virtual bool led_pinIsOn(void) const =0; - - - virtual void fan_switchFan(bool on) const =0; - virtual void alarm_switchSiren(bool on) const =0; - virtual bool fan_isOn(void) const =0; - - virtual bool siren_isOn(void) const =0; - - virtual void bar_OpenBarrier(bool open) const =0; - virtual bool bar_relayIsOn(void) const =0; - - virtual bool bar_optoIn1isOn(void) const =0; - - virtual bool bar_optoIn2isOn(void) const =0; - - virtual void aux_power(bool on) const =0; - virtual bool aux_powerIsOn(void) const =0; - - virtual void aux_setUsage(uint8_t PinDirection) const =0; - virtual void aux_setOutputs(uint8_t PinIsHigh) const =0; - - virtual bool aux_isAuxPowerOn(void) const =0; - - virtual uint8_t aux_getAuxInputs(void) const =0; - - - -// ------------------------------------------------------------------------------------ -// 27.3.2023: Use Device-Controller's Bootloader to send hex-file -// ------------------------------------------------------------------------------------ - - virtual void bl_rebootDC(void) const =0; - - virtual void bl_startBL(void) const = 0; - // send command within 4s after DC power-on, otherwise bl is left - - virtual bool bl_checkBL(void) const = 0; - // send command to verify if bl is up - - virtual bool bl_isUp(void) const =0; - // return true is bl is up and running - // also initializes "sendFile" - - virtual void bl_sendAddress(uint16_t blockNumber) const=0; - // send start address, nr of 64byte-block, start with 0 - // will be sent only for following block-numbers: - // 0, 1024, 2048, 3072 and 4096, so basically every 64kByte - // for other addresses nothing happens - - virtual uint8_t bl_wasSendingAddOK(void) const=0; - // return val: 0: no response by now 1:error 10: OK - - virtual void bl_openBinary(void) const=0; - // to be used within CashAgent, momentary not processed - - virtual void bl_sendDataBlock(uint8_t length, uint8_t *buffer) const=0; - // send 64 byte from bin file - - virtual void bl_sendLastBlock(void) const=0; - // send this command after all data are transfered - - virtual uint8_t bl_wasSendingDataOK(void) const=0; - // return val: 0: no response by now 1:error 10: OK - - virtual void bl_stopBL(void) const=0; - // leave BL and start (the new) application - - //virtual bool bl_isDiagAvailable(void) const=0; - - //virtual QString dc_getDiagText(void) const=0; - - - // Komplett-schreib Funktion, noch nicht getestet - // Nachteil: keine Rückmeldung wie lang's noch dauert - //virtual void bl_startSending(void) const=0; - // call once after BL is working and file is loaded - //virtual void bl_sendFile(void) const=0; - // call cyclic while loading bin-file to bootloader - - - - -// ------------------------------------------------------------------------------------ -// 6.4.2023: new functions for coin collection and printing -// some new system functions -// ------------------------------------------------------------------------------------ - - virtual bool rtc_setTimeDateDirect(struct Trtc_DateTime *DateTime) const=0; - // return true if sending, false if cmd-stack is full - - virtual bool rtc_getExtendedTime(uint8_t *leng, uint8_t *data) const=0; -/* - buf[0]=GlobTime.Hours; - buf[1]=GlobTime.Min; - buf[2]=GlobTime.Sec; - buf[3]=GlobTime.Year; - buf[4]=GlobTime.Month; - buf[5]=GlobTime.Day; - buf[6]=GlobTime.DOW; - buf[7]=' '; // immer auf 32bit auffüllen sonst Speicherproblem beim Master! - uitmp=GlobTime.MinOfDay; - buf[8]=swl_getOneByteFromUint(uitmp, 0); - buf[9]=swl_getOneByteFromUint(uitmp, 1); - buf[10]=' '; - buf[11]=' '; - ultmp=GlobTime.SecOfDay; - buf[12]=swl_getOneByteFromUlong(ultmp, 0); - buf[13]=swl_getOneByteFromUlong(ultmp, 1); - buf[14]=swl_getOneByteFromUlong(ultmp, 2); - buf[15]=swl_getOneByteFromUlong(ultmp, 3); - - buf[16]=swl_isLeap(GlobTime.Year); - buf[17]=swl_getNextLeapYear(GlobTime.Year); - buf[18]=swl_getLastLeapYear(GlobTime.Year); - buf[19]=swl_hoursOfThisWeek(GlobTime.DOW, GlobTime.Hours); - - uitmp=swl_minutesOfThisWeek(GlobTime.DOW, GlobTime.Hours, GlobTime.Min); - buf[20]=swl_getOneByteFromUint(uitmp, 0); // 0=low byte 1=high byte - buf[21]=swl_getOneByteFromUint(uitmp, 1); - - uitmp=swl_hoursOfThisMonth(GlobTime.Day, GlobTime.Hours); - buf[22]=swl_getOneByteFromUint(uitmp, 0); - buf[23]=swl_getOneByteFromUint(uitmp, 1); - - uitmp=swl_minutesOfThisMonth(GlobTime.Day, GlobTime.Hours, GlobTime.Min); - buf[24]=swl_getOneByteFromUint(uitmp, 0); - buf[25]=swl_getOneByteFromUint(uitmp, 1); - - uitmp=swl_GetDaysOfYear(GlobTime.Year, GlobTime.Month, GlobTime.Day); - buf[26]=swl_getOneByteFromUint(uitmp, 0); - buf[27]=swl_getOneByteFromUint(uitmp, 1); - - uitmp=swl_GetHoursOfYear(GlobTime.Year, GlobTime.Month, GlobTime.Day, GlobTime.Hours); - buf[28]=swl_getOneByteFromUint(uitmp, 0); - buf[29]=swl_getOneByteFromUint(uitmp, 1); - buf[30]=0; - buf[31]=0; - ultmp= swl_GetMinutesOfYear(GlobTime.Year, GlobTime.Month, GlobTime.Day, - GlobTime.Hours, GlobTime.Min); - buf[32]=swl_getOneByteFromUlong(ultmp, 0); - buf[33]=swl_getOneByteFromUlong(ultmp, 1); - buf[34]=swl_getOneByteFromUlong(ultmp, 2); - buf[35]=swl_getOneByteFromUlong(ultmp, 3); - - buf[36]=rtc_getSqwaveSettings(); - buf[37]=0; - buf[38]=0; - buf[39]=0; - - ultmp= 0; // Minutes of the Millenium - buf[40]=swl_getOneByteFromUlong(ultmp, 0); - buf[41]=swl_getOneByteFromUlong(ultmp, 1); - buf[42]=swl_getOneByteFromUlong(ultmp, 2); - buf[43]=swl_getOneByteFromUlong(ultmp, 3); - - dc2prot_setReadData(44, buf); - - */ - - virtual bool rtc_getExtendedTime(struct T_extTime *exTime) const=0; - - virtual bool sys_runCompleteTest(void) const=0; - // warning: lasts 20s in one pace - // return true if sending, false if cmd-stack is full - - virtual bool sys_ready4sending(void) const=0; - // return true if a Json-file can be sent - - virtual bool sys_sendJsonFileToDc(uint8_t kindOfFile, uint8_t nrOfTemplate, uint8_t *content ) const=0; - // kindOfFile: 1=config, 2=device, 3=cash, 4=serial, 5=time, 6=printer - // nrOfTemplate=1...32 if kindOfFile==6 - // content = content of the Json file, max 800byte ascii signs - // file is 0-terminated - // return true if sending, false if cmd-stack is full - - virtual bool prn_sendDynamicPrnValues(uint8_t *dynPrnVal ) const=0; - // dynPrnVal = array of 8 Variables with 8 byte each, come as ascii string - // like: char prn_dynPrnVal[8][8]; - // return true if sending, false if cmd-stack is full - - virtual bool prn_printTemplate(uint8_t nrOftemplate) const=0; - // print one of the templates loaded by Json prior - // nr = 1..32 - // return true if sending, false if cmd-stack is full - - virtual void log_getHoldAccountNumbers(uint8_t *nrOfVals, uint16_t *accNr ) const=0; - // returns all acc nrs of the backuped vault records - // use: uint16_t backupedAccNumbers[8] - - virtual bool log_selectVaultRecord(uint16_t accountNr ) const=0; - // return true if sending, false if cmd-stack is full - // and trigger transfer - - virtual bool log_chkIfVaultRecordAvailable(void) const=0; - // return true if completly received - - virtual bool log_getVaultRecord(struct T_vaultRecord *retVR) const=0; - // which was selected by: log_selectVaultRecord() - // to be forwarded to Ismas - - virtual bool prn_printAccountReceipt(void) const=0; - // return true if sending to DC OK, false if cmd-stack is full - - virtual bool prn_printTestTicket(void) const=0; - // return true if sending to DC OK, false if cmd-stack is full - - virtual bool cash_startPayment(uint32_t amount) const=0; - // 17.4.23TS: extended to 32bit - - virtual uint32_t getInsertedAmount(void) const=0; - - virtual uint16_t getLastInsertedCoin(void) const=0; - - virtual bool getAllInsertedCoins(uint16_t *types, uint16_t *values) const=0; - // all inserted coins (max 64) since "cash_startPayment" - - virtual bool cash_cancelPayment(void) const=0; - // and return coins - - virtual bool cash_stopPayment(void) const=0; - // and keep coins in escrow - - // after ticket/goods issue: - virtual bool vend_success(void) const=0; - // conclude payment process, encash all inserted coins to vault. Printing was successful - // if possible return change - - virtual bool vend_failed(void) const=0; - // conclude payment process and return all inserted coins - - - virtual uint8_t mif_getCardType(QString *cardholder) const=0; - // return 1,2,3,4 = upper, lower access card, printer test, coin test - // cardholder: 7byte Name-String - - virtual uint64_t sys_getWakeSource(void) const =0; - // retval: 6 bytes, bit coded, 1=event keeps DC awake - - virtual uint8_t sys_getWakeReason(void) const=0; - // Master was woken by following reason: - // 1: MDB Event - // 2: Coin Event - // ( 3: Master Event) - will not set the wake line - // ( 4: 32s pulse) - will not set the wake line - // 5: Door Event - // ( 6: Diag Event) - will not set the wake line - // 7: 30min-Pulse for HB - - virtual void sys_getDeviceConditions(uint8_t *leng, uint8_t *data) const=0; - /* - - outBuf[0]=modCond.ram; - outBuf[1]=modCond.intEe; - outBuf[2]=modCond.extEe; - outBuf[3]=modCond.rtc; - outBuf[4]=modCond.boardHw; - outBuf[5]=modCond.printer; - outBuf[6]=modCond.modem; - outBuf[7]=modCond.signal; - outBuf[8]=modCond.regist; - outBuf[9]=modCond.mdbBus; - outBuf[10]=modCond.coinChecker; - outBuf[11]=modCond.coinEscrow; - outBuf[12]=modCond.mifareReader; - outBuf[13]=modCond.creditTerm; - outBuf[14]=modCond.coinReject; - outBuf[15]=modCond.coinSafe; - outBuf[16]=modCond.billSafe; - outBuf[17]=modCond.voltage; - outBuf[18]=modCond.temper; - outBuf[19]=modCond.poweronTest; - outBuf[20]=modCond.doorState; - outBuf[21]=modCond.doorWasOpened; - outBuf[22]=modCond.changer; - outBuf[23]=modCond.coinBlocker; - outBuf[24]=modCond.billReader; - outBuf[25]=modCond.ResetReason; - outBuf[26]=modCond.allModulesChecked; - outBuf[27]=modCond.alarmState; - outBuf[28]=0; - outBuf[29]=0; - - */ - - virtual void sys_getDeviceConditions(struct T_moduleCondition *devCond) const=0; - virtual void sys_getDynMachineConditions(uint8_t *leng, uint8_t *data) const=0; -/* - - outBuf[pBuf++]=dynCond.allDoorsDebounced; - outBuf[pBuf++]=dynCond.openedAuthorized; - outBuf[pBuf++]=dynCond.CBinDebounced; - outBuf[pBuf++]=dynCond.upperDoor; - - outBuf[pBuf++]=dynCond.middleDoor; - outBuf[pBuf++]=dynCond.lowerDoor; - outBuf[pBuf++]=dynCond.coinBox; - outBuf[pBuf++]=dynCond.billBox; - - outBuf[pBuf++]=dynCond.modeAbrech; - outBuf[pBuf++]=dynCond.onAlarm; - outBuf[pBuf++]=dynCond.nowCardTest; - outBuf[pBuf++]=dynCond.nowPayment; - - outBuf[pBuf++]=dynCond.lastMifCardType; - outBuf[pBuf++]=dynCond.lastSDoorState; - outBuf[pBuf++]=dynCond.lastVDoorState; - outBuf[pBuf++]=dynCond.lastCBstate; - - outBuf[pBuf++]=dynCond.paymentInProgress; - outBuf[pBuf++]=0; - uitmp=dynCond.U_Batt; - outBuf[pBuf++]=swl_getOneByteFromUint(uitmp, GETLOWBYT); - outBuf[pBuf++]=swl_getOneByteFromUint(uitmp, GETHIGHBYT); - uitmp=dynCond.Temperatur; - outBuf[pBuf++]=swl_getOneByteFromUint(uitmp, GETLOWBYT); - outBuf[pBuf++]=swl_getOneByteFromUint(uitmp, GETHIGHBYT); - - uitmp=dynCond.nrCoinsInBox; // send seperate also - outBuf[pBuf++]=swl_getOneByteFromUint(uitmp, GETLOWBYT); - outBuf[pBuf++]=swl_getOneByteFromUint(uitmp, GETHIGHBYT); - - ultmp=dynCond.amountInBox; // send seperate also - outBuf[pBuf++]=swl_getOneByteFromUlong(ultmp, GETLOWESTBYT); - outBuf[pBuf++]=swl_getOneByteFromUlong(ultmp, GETLOWMID); - outBuf[pBuf++]=swl_getOneByteFromUlong(ultmp, GETHIGHMID); - outBuf[pBuf++]=swl_getOneByteFromUlong(ultmp, GETHIGHESTBYT); - - ultmp=dynCond.totalTransVolume; - outBuf[pBuf++]=swl_getOneByteFromUlong(ultmp, GETLOWESTBYT); - outBuf[pBuf++]=swl_getOneByteFromUlong(ultmp, GETLOWMID); - outBuf[pBuf++]=swl_getOneByteFromUlong(ultmp, GETHIGHMID); - outBuf[pBuf++]=swl_getOneByteFromUlong(ultmp, GETHIGHESTBYT); - - ultmp=dynCond.totalNrOfVends; - outBuf[pBuf++]=swl_getOneByteFromUlong(ultmp, GETLOWESTBYT); - outBuf[pBuf++]=swl_getOneByteFromUlong(ultmp, GETLOWMID); - outBuf[pBuf++]=swl_getOneByteFromUlong(ultmp, GETHIGHMID); - outBuf[pBuf++]=swl_getOneByteFromUlong(ultmp, GETHIGHESTBYT); -// 36 - outBuf[pBuf++]=dynCond.jsonValid_config; - outBuf[pBuf++]=dynCond.jsonValid_device; - outBuf[pBuf++]=dynCond.jsonValid_cash; - outBuf[pBuf++]=dynCond.jsonValid_print; - outBuf[pBuf++]=dynCond.jsonValid_serial; - outBuf[pBuf++]=dynCond.jsonValid_time; - outBuf[pBuf++]=dynCond.lastFileType; - outBuf[pBuf++]=0; - -*/ - - virtual void sys_getDynMachineConditions(struct T_dynamicCondition *dynMachCond) const=0; - - // content of Cashbox - virtual uint32_t cash_getAmountInVault(void) const=0; - - virtual uint16_t cash_getNrCoinsInVault(void) const=0; - - - virtual uint8_t prn_getPrintResult() const=0; - - // in case of print-error get detailed error: - virtual uint8_t prn_getCurrentPrinterState() const=0; - // 0: printer OK - // bit0: near paper end bit1: no paper - // bit2: temperature error bit3: error head open - // bit4: paper jam in cutter - // bit6: no response bit7: serial rec. error - // bit5: printer not ready - - virtual void sys_sendDeviceParameter(struct T_devices *deviceSettings) const=0; - - virtual void sys_restoreDeviceParameter(struct T_devices *deviceSettings) const=0; - - /* --------------------------------------------------------------------------------------------- - // ------------ supervise all hardware components - // ------------ assess the machine state - - 1. check if DC startup test is through, retrigger if not - 2. get results and find errors - 3. in case of error check if component is used (e.g. billreader is seldom used) - 4: check doors - 5. return value: 0: no response from DC - 1: no Test results and Test not running. need retrigger! - 2: state not clear by now, test ongoing, wait - 3: Service or battery door is open, goto INTRUSION MODE - from here: after valid ID-card goto SERVICE MODE - 4: vault door is open, goto INTRUSION MODE - from here: after valid ID-card and vault door closed goto TEST MODE - in TEST MODE: complete system check decides if vending mode allowed - 5: All doors are closed but errors found, - goto OOO MODE (out-of-order) - from here: run system test until problem is fixed - 6: All doors are closed, no error, maybe warnings, - goto VENDING MODE (normal operation) - (priority sinks from 0 to 6) - - --------------------------------------------------------------------------------------------- */ - - virtual uint8_t sys_componentAssessment(void) const=0; - // this function decides if vending mode is possible, independant from door - // return >0 in case of error - // is inncluded in sys_superviseSystem - - virtual uint8_t sys_superviseSystem(void) const=0; - // this function proofs if vending is possible depending of doors state - - virtual uint8_t sys_getSystemErrors(void) const=0; - - - // retrigger System-Check with: - // bool hwapi::sys_runCompleteTest(void) const - - - - - - - - - // --------------------------------------------------------------------------------------------- - // --------------------------------------------------------------------------------------------- - // --------------------------------------------------------------------------------------------- - -signals: - virtual void hwapi_templatePrintFinished_OK(void) const=0; - virtual void hwapi_templatePrintFinished_Err(void) const=0; - virtual void hwapi_gotNewCoin(void) const=0; - virtual void hwapi_vendStopByMax(void) const=0; - virtual void hwapi_vendStopByPushbutton(void) const=0; - -}; - - -// History -// 11.10.2021: V1.0 222 functions -// 23.12.2021: V1.1 added block-parameter to function "read mifare data" -// 30.12.2021: V1.2 added function: mif_clearDataBuffer(), mif_isBlockAvailable(uint8_t blkNr) and mif_getAvailableDataBlocks() -// 1.1.2022: V1.3 Mifare extended. ( background: read 16 x 48byte from card to DC, read 12 x 64byte from DC to CA) -// new: read full card with 768bytes from HWapi without block borders -// added: mif_getNrOfAvailableDataBytes mif_getCardData768byteDec(uint8_t *buf, uint16_t bufferSize) -// mif_getCardDataDec(uint16_t fromAddr, uint16_t toAddr, uint8_t *buf, uint16_t bufferSize) -// mif_getCardDataStr(bool useHexFormat, char seperator) - -// 29.03.2023: V3.1 some extensions for PSA1256_ptu5, -// V3.2 Bootloader improvement -// 12.04.2023: V3.3 new features extended: loading and using Json-files, cash-collection, cash-data-logging -// 14.04.2023: V3.4 new features extended: sys_getDynMachineConditions, sys_getDeviceConditions and -// rtc_getExtendedTime return struct in addition. New function to select and get VaultRecord -// - -//#define HWINF_iid "Atb.Psa2020.software.HWapi/3.1" -//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/3.1" -//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/3.3" -//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/3.4" -#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/3.5" - - - -Q_DECLARE_INTERFACE(hwinf, HWINF_iid) - - -#endif - - - diff --git a/DCPlugin/include/prot.h b/DCPlugin/include/prot.h deleted file mode 100644 index 93304c0..0000000 --- a/DCPlugin/include/prot.h +++ /dev/null @@ -1,129 +0,0 @@ - -#ifndef SERIAL_FRAME_H -#define SERIAL_FRAME_H - -#include -#include -#include -#include -#include "tslib.h" -#include "com.h" - -/* - get's OUT-data from datif, - get's IN-data from datif - get's send command from datif - makes frame and calls: isSerialFree(), setSendData(), - if not free retrigger datif sending period (normally 500ms or 50ms for direct cmds) - - with control-signal: gotReceiveData(): - getRecData(); - send results to diag window/line - send IN-data to datif -*/ - -#define FRAME_DATALEN 64 -#define FRAME_MAXLEN FRAME_DATALEN+20 -#define BL_DATA_LEN 150 - -#define DATALEN_SEND_FAST 4 -#define DATALEN_SEND_LONG 64 -#define HEADERLEN_SEND 4 -#define TELEGRAMLEN_SEND_FAST 12 -#define TELEGRAMLEN_SEND_LONG 70 -#define STARTSIGN_SEND_FAST 0x3F -#define STARTSIGN_SEND_LONG 0x3D - -#define DATALEN_RECEIVE_FAST 8 -#define DATALEN_RECEIVE_LONG 64 -#define HEADERLEN_RECEIVE 2 -#define TELEGRAMLEN_RECEIVE_FAST 12 -#define TELEGRAMLEN_RECEIVE_LONG 68 -#define STARTSIGN_RECEIVE_FAST 0x5F -#define STARTSIGN_RECEIVE_LONG 0x5D - - -class T_prot : public QMainWindow -{ - Q_OBJECT - - // Dateneingang von Datif: - uint8_t SendDataValid; // bit1: WR OK bit 2: RD OK - uint16_t slaveAddr; - - uint16_t WriteCommand; - uint16_t WriteAddr; - uint8_t WrDataLength; - uint8_t ui8OutputData[FRAME_DATALEN]; - char chOut_Data[FRAME_DATALEN]; - uint8_t kindOfData; // 0: binaries, 1:text - - uint16_t ReadCommand; - uint16_t ReadAddr; - uint16_t reserve; - - // Ausgangs-Daten, werden vom Datif geholt: - // nur wenn CommandState und readState OK - uint8_t RecSlaveAddr; - bool INdataValid; // nur true wenn CommandState OK und readState OK - uint16_t readSource; // diese (Eingangs-)Daten stehen im Puffer - uint16_t readAddress; // von dieser Adr wurden die Daten gelesen - //uint8_t lastWakeSrc; // falls der Slave den Master geweckt hat - uint8_t RdDataLength; - uint8_t InputData[FRAME_DATALEN]; - - // 11.11.2020: - uint8_t BLsendDataLength; - uint8_t ui8BLsendData[BL_DATA_LEN]; - - T_com *mySerialPort; - - void startPacking(void); - void startFastPacking(void); - uint8_t FramecheckInData(uint8_t *Inbuf, uint16_t LL); - uint8_t FastCheckInData(uint8_t *Inbuf, uint16_t LL); - - uint8_t CheckInResult(uint8_t *Inbuf); - - uint8_t ShowFastInData(uint8_t *recBuffer); - uint8_t ShowInData(uint8_t *recBuffer); // was CheckInData - void setRecLen(uint16_t WriteCmd); - -private slots: - void analyseRecData(void); - -public: - T_com *getSerialPort() { return mySerialPort; } - T_com const *getSerialPort() const { return mySerialPort; } - - T_prot(); - bool isPortOpen(void); - bool isSerialFree(void); - void setUserWriteData(uint16_t WriteCmd, uint16_t WrAddr, uint8_t WrDatLen, uint8_t *data); - void setUserWriteData(uint16_t WriteCmd, uint16_t WrAddr); - void setUserWriteData(uint16_t WriteCmd); - void setUserWriteText(uint16_t WriteCmd, uint16_t WrAddr, uint8_t WrDatLen, char *data); - - void setUserWrite1DB(uint16_t WriteCmd, uint16_t WrAddr, uint8_t val); - void setUserWrite2DB(uint16_t WriteCmd, uint16_t WrAddr, uint8_t val0, uint8_t val1); - - void setUserReadData( uint16_t ReadCmd, uint16_t RdAddr, uint16_t reserv); - void setUserReadData( uint16_t ReadCmd, uint16_t RdAddr); - void setUserReadData( uint16_t ReadCmd); - - void setBLsendData( uint8_t len, uint8_t *buf); - - void receiveFixLen(int64_t nrOfbytesToReceive); - - void sendUserData(uint16_t slaveAdr); - bool ifDataReceived(); - bool getReceivedInData(uint8_t *SlavAddr, uint16_t *readSrc, uint16_t *readAddr, - uint8_t *RdDlen, uint8_t *receivedData); - // retval: data valid, only one time true -signals: - void framerecieved(); //bool gotINdata); - void rawDataRecieved(); - -}; - -#endif // T_prot_H diff --git a/DCPlugin/include/sendWRcmd.h b/DCPlugin/include/sendWRcmd.h deleted file mode 100644 index 1b12e46..0000000 --- a/DCPlugin/include/sendWRcmd.h +++ /dev/null @@ -1,250 +0,0 @@ - -#ifndef SENDWRCMDS_DEFS_H -#define SENDWRCMDS_DEFS_H - -#include -#include "tslib.h" -#include - -// asynch. Commands -// store OUTPUT commands until time to send -// problem: OUT commands are set if a button is pressed or a transaction event happens -// so it's never synchron with sending grid -// but sending must apply the 100ms time grid as we have to wait for the response before sending the next command!!! - -// Level 0 (DC direct) -#define SENDDIRCMD_TestSerial 1 -#define SENDDIRCMD_MakeReset 2 -#define SENDDIRCMD_setTime 3 -#define SENDDIRCMD_setWakeFrequ 4 - -// Level 1 (DC DO's switching connected parts) -#define SENDDIRCMD_MOVEUP_LOCK 5 -#define SENDDIRCMD_MOVEDN_LOCK 6 -#define SENDDIRCMD_OPENUP_DOOR 7 -#define SENDDIRCMD_OPENDN_DOOR 8 -#define SENDDIRCMD_LEDILLU 9 -#define SENDDIRCMD_LEDCOIN 10 -#define SENDDIRCMD_LEDTICKET 11 -#define SENDDIRCMD_LEDPAD 12 -#define SENDDIRCMD_LEDSTART 13 -#define SENDDIRCMD_LEDINSIDE 14 -//#define SENDDIRCMD_LED_ALL 15 -#define SENDDIRCMD_FAN 16 -#define SENDDIRCMD_LAERM 17 -#define SENDDIRCMD_REL1 18 -#define SENDDIRCMD_WAKEPTU 20 -#define SENDDIRCMD_AUXPWR 21 -#define SENDDIRCMD_AUXDDR 22 -#define SENDDIRCMD_AUXOUT 23 - -#define SENDDIRCMD_UCONTACT_ON 30 -#define SENDDIRCMD_PRN2_SWONOFF 31 - -#define SENDDIRCMD_MIF_SWONOFF 32 // 0x2900 -#define SENDDIRCMD_MIF_ATBCREATE 33 // 0x2907 - -#define SENDDIRCMD_MOD_SWONOFF 40 -#define SENDDIRCMD_MOD_WAKE 41 -#define SENDDIRCMD_MDB_POWER 42 -#define SENDDIRCMD_MDB_WAKE 43 -#define SENDDIRCMD_CRED_ON 44 -#define SENDDIRCMD_CRED_WAKE 45 - -#define SENDDIRCMD_SHUT_MOV 50 -#define SENDDIRCMD_ESCRO_MOV 51 -#define SENDDIR_OPENVAULT 52 -#define SENDDIR_REJMOT_ON 53 -#define SENDDIR_REJMOT_RUN 54 - -// Level 2 (serial from DC to devices) -#define SEND_REQU_SERCONF 100 -#define SEND_REQU_HWversion 101 -#define SEND_REQU_SWversion 102 -#define SEND_REQU_CONDITION 103 -#define SEND_REQU_UID 104 -#define SEND_REQU_TIME 105 - // includes wake frequency -#define SEND_REQU_ANALOGS 110 -#define SEND_REQU_DIG_INPUTS 111 -#define SEND_REQU_DIG_OUTPUTS 112 - -#define SEND_REQU_PRN_STATE 120 -#define SEND_REQU_PRN_FONTS 121 -#define SEND_REQU_PRN_ALL 122 - -#define SEND_REQU_MIFSTATE 123 - // Type and state of reader - -#define SEND_REQU_MIFDATA 124 - // Type, UID, Header of card - // read one card sector - // sectors must be addressed by RD_ADD - -#define SEND_REQU_MIF_ATB_TYPE 125 - -#define SEND_REQU_MDB_GETSTAT 126 -//#define SEND_REQU_MDB_GETWAK 127 -#define SEND_REQU_MDB_GETRESP 128 -#define SEND_REQU_EMP_GETALL 129 -#define SEND_REQU_EMP_GETCOIN 130 - - -#define SENDDIRCMD_DEVICE_PARA 131 -#define SENDDIRCMD_MACHINE_ID 132 -#define SEND_REQU_DEVICE_PARA 133 -#define SEND_REQU_MACINE_ID 134 - - -// further: mdb state, coinchecker state, bill state, modem state, credit_state.... - -#define SENDDIRCMD_SHUTOPENBYTIME 60 -#define SENDDIRCMD_SHUTOPENBYCOIN 61 -//#define SENDDIRCMD_SHUT_SENDTIME 62 - -#define SENDDIRCMD_ESCRO_TAKE 63 -#define SENDDIRCMD_ESCRO_GIVE 64 - -#define SENDDIRCMD_PRN_SYS_CMD 70 -#define SENDDIRCMD_PRN_ESC_CMD 71 -#define SENDDIRCMD_PRN_SETUP 72 -#define SENDDIRCMD_PRN_MOVE 73 -#define SENDDIRCMD_PRN_SETFONT 74 -#define SENDDIRCMD_PRN_SETLETT 75 -#define SENDDIRCMD_PRN_CUT 76 -//#define SENDDIRCMD_PRN_TXT // not needed -#define SENDDIRCMD_PRN_LF 78 -#define SENDDIRCMD_PRN_FONTTAB 79 -#define SENDDIRCMD_PRN_BC 80 -#define SENDDIRCMD_PRN_QR 81 -#define SENDDIRCMD_PRN_STOREDQR 82 -#define SENDDIRCMD_PRN_LOGO_FL 83 -//#define SENDDIRCMD_PRN_LOGO_GRAF 84 -//#define SENDDIRCMD_PRN_LOGODAT 85 -//#define SENDDIRCMD_PRN_STORBC 86 -#define SENDDIRCMD_PRN_STORQR 87 -#define SENDDIRCMD_PRN_DOC 88 -#define SENDDIRCMD_PRN_CLEARDOC 89 - -//#define SENDDIRCMD_MDB_POWER 42 -//#define SENDDIRCMD_MDB_WAKE 43 -#define SENDDIRCMD_MDB_RES 90 -#define SENDDIRCMD_MDB_SENDCMD 91 -#define SENDDIRCMD_MDB_SNDMSG 92 -#define SENDDIRCMD_EMP_SETT 93 -#define SENDDIRCMD_EMP_POLL 94 -#define SENDDIRCMD_EMP_STARPPAY 95 -#define SENDDIRCMD_EMP_STOPPAY 96 - - - - -// obsolete: -#define SENDDIRCMD_PRN1_SENDTEXT 54 -#define SENDDIRCMD_PRN1_SENDCMD 55 -#define SENDDIRCMD_PRN1_SERPAR 56 -#define SENDDIRCMD_PRN_LEVEL2_4B 58 -#define SENDDIRCMD_PRN_LEVEL2_64 59 - - -// highest priority -#define CMDSTACKDEPTH 16 -// means: up to 16 cmd can be stored. They are issued one by one every 100ms -void sendWRcmd_clrCmdStack(void); -bool sendWRcmd_setSendCommand0(uint16_t nextCmd); - // GUI or app sends a command to DC transfered by serial - -uint16_t sendWRcmd_getSendCommand0(void); - -// lower priority -#define CMD4STACKDEPTH 8 -void sendWRcmd_clrCmd4Stack(void); -bool sendWRcmd_setSendCommand4(uint16_t nextCmd, uint8_t dat1, uint8_t dat2, uint8_t dat3, uint8_t dat4); -uint16_t sendWRcmd_getSendCommand4(uint8_t *dat1, uint8_t *dat2, uint8_t *dat3, uint8_t *dat4); - -#define CMD8STACKDEPTH 4 -void sendWRcmd_clrCmd8Stack(void); -bool sendWRcmd_setSendCommand8(uint16_t nextCmd, uint8_t dat1, uint8_t dat2, uint16_t dat3, uint32_t dat4); -uint16_t sendWRcmd_getSendCommand8(uint8_t *dat1, uint8_t *dat2, uint16_t *dat3, uint32_t *dat4); - - - -// lowest priority -// wait for resonse before send next! -bool sendWRcmd_setSendBlock160(uint8_t leng, uint8_t *buf); -uint8_t sendWRcmd_getSendBlock160(uint8_t *leng, uint8_t *buf); - // retval = *leng - -void sendWRcmd_INI(void); - - - -uint8_t epi_store64ByteSendData(uint8_t length, uint8_t *buf); - // HWapi writes data to be forwarded to DC and further to mdb-device - // not batched! don't use twice within 100ms - -uint8_t gpi_restore64ByteSendData(uint8_t *length, uint8_t *buf); - // datif reads data to forward to dc - - - -// ONE printer doc consists of 20 x 64 byte -#define MAXNROF_PRNBYTES 64 -#define MAXNROF_PRNBLOCKS 20 - -void epi_resetPrinterStack(void); - -uint8_t epi_storePrnText(char *buf, uint8_t leng); - // store text and binary data from Gui in next higher free memory 0....9 - -uint8_t gpi_restorePrnText(uint8_t *retbuf); - // read printer text and send to slave, size of retbuf== 64 - -uint8_t gpi_chk4remainingText(void); - // retval: 0: no more textline left (to send) >0: nr of lines - -void epi_storeUserOfSendingTextBuffer(uint8_t user, uint8_t para1, uint8_t para2, uint8_t para3, uint8_t para4 ); - // user=1: Text-Print is using this buffer - // 2: QR-code-Printer is using this buffer - -uint8_t gpi_getUserOfSendingTextBuffer(uint8_t *para1, uint8_t *para2, uint8_t *para3, uint8_t *para4); - // user=1: Text-Print is using this buffer - // 2: QR-code-Printer is using this buffer - -#define FDCMD_STACKDEPTH 16 -void sendFDcmd_clrStack(void); -bool sendFDcmd_set(uint8_t nextWrCmd, uint8_t nextRdCmd, uint8_t blockNum, uint8_t dat1, uint8_t dat2, uint8_t dat3, uint8_t dat4); - // write Command to memory, wait for transport -bool sendFDcmd_get(uint8_t *nextWrCmd, uint8_t *nextRdCmd, uint8_t *blockNum, uint8_t *dat1, uint8_t *dat2, uint8_t *dat3, uint8_t *dat4); - -uint8_t check4FDshortCmd(void); - // returns number of waiting command, maxFDCMD_STACKDEPTH - -uint8_t check4freeFDshortCmd(void); - // returns number of free places in short-command stack - -#define FDLONG_STACKDEPTH 16 -void longFDcmd_clrStack(void); -bool longFDcmd_set(uint8_t nextWrCmd, uint8_t nextRdCmd, uint8_t blockNum, uint8_t length, uint8_t *data); - // write Command to memory, wait for transport - // data buffer size always 64! data[64], padded with 0 -bool longFDcmd_get(uint8_t *nextWrCmd, uint8_t *nextRdCmd, uint8_t *blockNum, uint8_t *length, uint8_t *data); - -uint8_t check4FDlongCmd(void); - // returns number of waiting command - -uint8_t check4freeFDlongCmd(void); - // returns number of free places in long-command stack - - - -uint8_t epi_store64BdevParameter(uint8_t length, uint8_t *buf); - // HWapi writes data to be stored - -uint8_t epi_restore64BdevParameter(uint8_t *length, uint8_t *buf); - - - -#endif - - diff --git a/DCPlugin/include/shared_mem_buffer.h b/DCPlugin/include/shared_mem_buffer.h deleted file mode 100644 index 07cc2b8..0000000 --- a/DCPlugin/include/shared_mem_buffer.h +++ /dev/null @@ -1,296 +0,0 @@ -#ifndef SHARED_MEM_BUFFER_INCLUDED_H -#define SHARED_MEM_BUFFER_INCLUDED_H - -#include -#include - -#include - -struct SharedMemBuffer { - struct rs { - char comportName[16]; // z.B. "COM48" - char baudStr[16]; // z.B. "19200" - int baudNr; // 0...5 oder -1 - uint8_t connect; // 0,1 - bool portIsOpen; - } rs; - - char AutoEmissionOn; // 1: zyklisch Anfragen zum Slave senden - - struct datif { - uint16_t sendingPeriod; - bool sendingPer_changed; - } datif; - -#if 0 - // controlBus.cpp - char txt4comStateLine[32]; - char txt4HsStateLine[32]; - char txt4masterStateLine[32]; - char txt4resultStateLine[32]; - char txt4dataLine[32]; - char txt4datifReceive[32]; - char txt4diagWindow[32]; - char sndTxt4diagWindow[32]; - bool Sdata_serialTestResult[32]; - uint8_t Sdata_pProtResultOk[32]; - uint16_t Sdata_receivedDataLength[32]; - uint8_t Sdata_receivedDataBlock[64]; - - // datif.cpp - uint8_t dif_dataStep; - uint8_t dif_scanStep; - uint8_t RDBLKNR; - uint8_t datif_OutCmdpara1; - uint8_t datif_OutCmdpara2; - uint8_t datif_OutCmdpara3; - uint8_t datif_OutCmdpara4; - - uint16_t datif_OutCmdpara5; - uint32_t datif_OutCmdpara6; - uint8_t cycl_running; - - // dcBL.cpp - uint8_t dcBL_LastBLcmd; // stored the last sent cmd in order to analys response - uint8_t dcBL_AtbBinFile[300000]; - uint32_t dcBL_fileSize; - uint16_t dcBL_nrOfBlocks; - uint16_t dcBL_fileCrc; - uint8_t dcBL_myBuf[300000]; // same content like "dcBL_AtbBinFile" but bytewise - - char BlResp[50][32]; - uint8_t dcBL_step; - uint8_t dcBL_state; - uint16_t dcBL_BlkCtr; - uint16_t dcBL_cyclCtr; - uint16_t repeatCtr; - uint8_t Sdata_rawData[150]; - uint8_t Sdata_LengthRawData; - - // hwapi.cpp - uint16_t hwapi_shutterTime; - char ticketTemplate[1024]; - - // sendWRcmd.cpp - uint16_t nextAsynchsendCmd0[16]; - uint8_t nrOfCmdsInQueue; - uint16_t nextAsynchsendCmd4[8]; - uint8_t nextCmd4para1[8]; - uint8_t nextCmd4para2[8]; - uint8_t nextCmd4para3[8]; - uint8_t nextCmd4para4[8]; - uint8_t nrOfCmds4InQueue; - uint16_t nextAsynchsendCmd8[4]; - uint8_t nextCmd8para1[4]; - uint8_t nextCmd8para2[4]; - uint16_t nextCmd8para3[4]; - uint32_t nextCmd8para4[4]; - uint8_t nrOfCmds8InQueue; - uint8_t sendAsynchDataBuf[160]; // no stack, only ONE buffer - uint8_t sendAsyDatLen; - uint8_t Sdata_mdbSendBuffer[64]; - uint8_t Sdata_mdbSendLen; - uint8_t prnDataParameters[4]; - uint8_t prnDataBufferUser; - char Sdata_PRN_TEXT[20][64]; - uint8_t pPrnDataBuff; // points to next PRINTER_BLOCK - uint8_t nextFDwrCmd[16]; - uint8_t nextFDrdCmd[16]; - uint8_t nextFDblkNr[16]; - - uint8_t nextFDpara1[16]; - uint8_t nextFDpara2[16]; - uint8_t nextFDpara3[16]; - uint8_t nextFDpara4[16]; - uint8_t p_nextFDcmdsInQueue; - uint8_t longFDwrCmd[16]; - uint8_t longFDrdCmd[16]; - uint8_t longFDblkNr[16]; - uint8_t longFDlength[16]; - - uint8_t longFDpara[16][64]; - uint8_t p_longFDcmdsInQueue; - - // storeInData.cpp - bool indat_savePrnPwr; - bool indat_saveMifPwr; - bool indat_MdbIsOn; -#endif - - uint8_t ndbs; - uint8_t pari; - uint8_t nsb; - uint8_t br; - -#define MAXNROF_GENSTR 16 - char genStrings[MAXNROF_GENSTR][64]; - -#define MAXNROF_AI 4 - uint16_t AI_val[MAXNROF_AI]; - - struct DigitalInputs { - uint8_t doorSwitch; - uint8_t vaultSwitch; - uint8_t lockSwitch; - uint8_t opto; - uint8_t aux; - bool wakeFromPtu; - bool wakeFromMdb; - bool wakeFromModem; - bool PrnReady; - bool CoinAttach; - bool CoinEscrowOpen; - bool mifCardTap; - bool contactPwrOn; - bool mifarePwrOn; - bool rdbk_mdbTxd; - bool AuxPwrOn; - bool gsmPwrOn; - bool creditPwrOn; - bool printerPwrOn; - bool mdbPwrOn; - bool rejMot_home; - uint8_t npe_sensor; - } din; - - struct DigitalOutputs { - uint8_t mbdRxTst; - uint8_t motorBits; - uint8_t serialSwitch; // serial drv on/off, Serial mux1, Serial mux2 - uint8_t ledsAndFan; - uint8_t laermUndRelay; - uint8_t ptuWake; - uint8_t auxPower; - uint8_t coinShutter; - uint8_t coinEscrow; - uint8_t printerPower; - } dout; - - struct Sdata { -#define NROFMIFSTATEBYTES 40 -#define PRN_STATE_ARRAY_SIZE 20 -#define PRN_STATE_FONT_SIZE 20 - uint8_t MIF_STATE[NROFMIFSTATEBYTES]; - uint8_t MIF_DATA[12][64]; - uint8_t PRN_STATE[PRN_STATE_ARRAY_SIZE]; - uint8_t PRN_FONTS[PRN_STATE_FONT_SIZE]; - bool mdb_busRdy; - bool mdb_V12on; - bool mdb_V5on; - uint8_t mdbNrOfRecData; - uint8_t RecBuff[40]; - uint8_t empNrOfsettings; - uint8_t emp_settingsBuff[66]; - uint8_t NrOfDeviceSetting; - uint8_t DeviceSettingBuff[66]; - uint8_t NrOfMachineIDSetting; - uint8_t NrOfMachineIDBuff[66]; - uint64_t slaveUID; - uint8_t UIDstr[8]; -#define MAXNROF_MEASURE 4 - uint32_t measurement[MAXNROF_MEASURE]; - bool serialTestResult; - uint8_t pProtResultOk; - uint16_t receivedDataLength; - uint8_t receivedDataBlock[64]; - } Sdata; - - uint8_t mif_cardType; - uint8_t mif_cardHolder[8]; - -#define MEMDEPTH_GOTCOINS (16) - struct T_coin { - uint8_t valid; - uint8_t signal; - uint8_t error; - uint8_t pad; - uint16_t value; - } gotCoin[MEMDEPTH_GOTCOINS]; - uint8_t ctr_gotCoin; - - struct store { - uint32_t insertedAmount; - uint16_t lastCoinType[64]; - uint16_t lastCoinValue[64]; - uint64_t wakeSrc; - uint8_t rbDevParamLen; - uint8_t rbDevParams[66]; - uint8_t deviceCondLen; - uint8_t deviceCond[66]; - uint8_t machCondLen; - uint8_t machCond[66]; - uint8_t DcBackupNrOfAccNr; - uint16_t DcBackupAccNr[16]; // z.Z. nur 8 - uint8_t gotNrBlocksOfVaultRec; - uint8_t vaultrecord[360]; - uint32_t amount; - uint16_t nrOfCoins; - bool dcDataValid; - uint8_t wakeReason; - - } store; - - struct T_globTime { - // Reihenfolge nicht vertauschen!!!!! - uint8_t hour; - uint8_t minute; - uint8_t second; - uint8_t Year; - uint8_t Month; - uint8_t DayOfMonth; - uint8_t DayOfWeek; // 1=monday...7 - uint8_t reserve1; - - uint16_t MinutesOfToday; - uint16_t reserve2; - - uint32_t SecondsOfToday; - - uint8_t IsLeapyear; - uint8_t nextLeap; - uint8_t lastLeap; - uint8_t hoursOfWeek; - - uint16_t minOfWeek; - uint16_t hoursOfMonth; - uint16_t minOfMonth; - uint16_t dayOfYear; - uint16_t hoursOfYear; - uint16_t reserve3; - - uint32_t minOfYear; - - uint8_t squareOutMode; - uint8_t free1; - uint16_t reserve4; - uint32_t minOfMillenium; - // bis hierher 44byts - uint32_t free2; - uint32_t free3; - uint32_t free4; - } getGlobalTime; - - static QSharedMemory *getShm(std::size_t s = 0); - static SharedMemBuffer *getData() { - return (SharedMemBuffer *)getShm()->data(); - } - static SharedMemBuffer const *getDataConst() { - return (SharedMemBuffer const *)getShm()->data(); - } - -#if 0 - static std::atomic __sharedMemLocked; - - static bool sharedMemLocked() { - return __sharedMemLocked; - } - static void setSharedMemLocked() { - __sharedMemLocked = true; - } - static void setSharedMemUnlocked() { - __sharedMemLocked = false; - } -#endif -}; - -#endif // SHARED_MEM_BUFFER_INCLUDED_H diff --git a/DCPlugin/include/storeINdata.h b/DCPlugin/include/storeINdata.h deleted file mode 100644 index 2a3083c..0000000 --- a/DCPlugin/include/storeINdata.h +++ /dev/null @@ -1,427 +0,0 @@ - -#ifndef STOREINDATA_H -#define STOREINDATA_H - -#include -//#include "tslib.h" -#include - - -#define MAXNROF_AO 3 -//#define MAXNROF_GENSTR 16 -#define MAXNROF_CONTR_PORTS 11 -#define MAXNROF_DIports 2 -#define MAXNROF_DOports 2 -#define MAXNROF_CTR 2 -#define MEASCHAN_TEMPERATURE 0 -#define MEASCHAN_VOLTAGE 1 - - -// gpi: DC-driver stores data for graphic peripheral interface -// epi: gui reads values from external peripheral interface - - -// store power on/off condition of the devices to control the data request - -void indat_storePrinterPower(bool isOn); -bool indat_isPrinterOn(); - -void indat_storeMifarePower(bool isOn); -bool indat_isMifareOn(); - -void indat_storeMDBisOn(bool isOn); -bool indat_isMdbOn(); - -void gpi_storeSlaveSerParams(uint8_t slaveBaudRate, uint8_t NrDataBits, - uint8_t parity, uint8_t NrStopBits); - -void epi_getSlaveSerParams(uint8_t *slaveBaudRate, uint8_t *NrDataBits, - uint8_t *parity, uint8_t *NrStopBits); - -QString epi_getSlaveParamSTR(); - -void gpi_storeGenerals(uint8_t genNr, QString text); - // 0=HW 1=SW 2=State -QString epi_loadGenerals(uint8_t genNr); -// genNr=0=HW 1=SW 2=State - - -void gpi_storeUID(uint8_t const *buf8byteUid); -// buffer size: 8 byte -void epi_getUIDdec(uint8_t *buf8byteUid); -// buffer size: 8 byte -QString epi_getUIDstr(); - - - - - -// /////////////////////////////////////////////////////////////////////////////////// -// Time and Date -// /////////////////////////////////////////////////////////////////////////////////// - -uint8_t epi_getSquareMode(); -void gpi_backupSquareMode(uint8_t squMode); - -void gpi_backupTime(uint8_t *timeBuffer, uint8_t Leng); // 104, <=8byte -void epi_getTime(uint8_t *hh, uint8_t *mm, uint8_t *ss); -void epi_getDate(uint8_t *yy, uint8_t *mm, uint8_t *dd); -void epi_getToday(uint8_t *dow, uint16_t *minOfToday, uint32_t *secOfToday); -bool epi_isLeapYear(uint8_t *lastLeapYear, uint8_t *NextLeapYear); -bool epi_isLeapYear(); -void epi_getSpecialWeekTimeDate(uint8_t *DayOfWeek, uint8_t *HoursOfWeek, uint16_t *MinutesOfWeek); -void epi_getSpecialMonthTimeDate(uint8_t *DayOfMonth, uint16_t *HoursOfMonth, uint16_t *MinutesOfMonth); -void epi_getSpecialYearTimeDate(uint16_t *DayOfYear, uint16_t *HoursOfYear, uint32_t *MinutesOfYear); - - -// /////////////////////////////////////////////////////////////////////////////////// -// Analog values -// /////////////////////////////////////////////////////////////////////////////////// - - -// #define MAXNROF_AI 4 - -void gpi_storeAIs(uint8_t aiNr, uint16_t val); // rs -> Sdata - -uint8_t gpi_getMaxNrAIs(); - -uint16_t epi_loadAIs(uint8_t aiNr); // Sdata -> gui - // return value of one ADC with channel nr: aiNr 0...15 - -uint32_t epi_loadMeasureValue(uint8_t ValueNr); - // ValueNr 0=ADC0, 1=ADC1 aso... - -void gpi_storeMeasureValue(uint8_t ValueNr, uint32_t val); - // in mV, also bis 65,535V - -QString epi_getSlaveTemperatureStr(); - -QString epi_getSlaveVoltageStr(); - // value in "meas_volt" in mV, also bis 65,535V. Value range [6000...16000] (6V...16V) - -// /////////////////////////////////////////////////////////////////////////////////// -// digital inputs -// /////////////////////////////////////////////////////////////////////////////////// - -void gpi_storeDI_doorSwitches(uint8_t upperDoor, uint8_t lowerDoor, uint8_t vaultDoor); - -uint8_t epi_getDI_doorSwitches(void); - // bit0: upper door 1: low door 2:vault door - -void gpi_storeDI_vaultSwitches(uint8_t CashBoxIn, uint8_t BillBoxIn); - -uint8_t epi_getDI_vaultSwitches(void); - // bit0: cash box 1: bill box in - -void gpi_storeDI_lockSwitches(uint8_t indatUL, uint8_t indatLL); - // D5: bit 0: upper lockbar up bit1:down - // D6: bit 0: lower lockbar up bit1:down - -uint8_t epi_getDI_lockSwitches(void); - // retval: bit 0: upper lockbar up bit1: upper lockbar is down - // bit 2: lower lockbar up bit1: lower lockbar is down - - -void gpi_storeDI_optos(uint8_t indatOpto); - // OptoIn bit 0,1: optoin 1,2 - -uint8_t epi_getDI_optos(void); - // bit0: opto in 1 1: opto in 2 - -uint8_t gpi_storeDI_auxIn(uint8_t indatAuxIn); // Aux0...5 -uint8_t epi_getDI_auxIn(void); // bit0: auxin 1 ... 5: auxin 6 - -bool gpi_storeDI_ptuWake(bool w); -bool epi_getDI_ptuWake(void); - -bool gpi_storeDI_mbdWake(bool w); -bool epi_getDI_mdbWake(void); - -bool gpi_storeDI_prnReady(bool ready); -bool epi_getDI_prnReady(void); - -bool gpi_storeDI_CoinAttach(bool attach); -bool epi_getDI_CoinAttach(void); - -bool gpi_storeDI_CoinEscrow(bool ce); -bool epi_getDI_CoinEscrow(void); - -bool gpi_storeDI_mifareCardTapped(bool tapped); -bool epi_getDI_mifareCardTapped(void); - -bool gpi_storeDI_modemWake(bool w); -bool epi_getDI_modemWake(void); - -bool gpi_storeDI_contactPowerIsOn(bool on); -bool epi_getDI_contactPwr(void); - -bool gpi_storeDI_MifarePowerIsOn(bool on); -bool epi_getDI_mifarePwr(void); - -bool gpi_storeDI_readbackMdbTxD(bool rdbkMdbTxd); -bool epi_getDI_mdbTxd(void); - -bool gpi_storeDI_AuxPowerIsOn(bool on); -bool epi_getDI_auxPwr(void); - -bool gpi_storeDI_GsmPowerIsOn(bool on); -bool epi_getDI_gsmPwr(void); - -bool gpi_storeDI_CreditPowerIsOn(bool on); -bool epi_getDI_creditPwr(void); - -bool gpi_storeDI_PrinterPowerIsOn(bool on); -bool epi_getDI_printerPwr(void); - -bool gpi_storeDI_MdbPowerIsOn(bool on); -bool epi_getDI_mdbPwr(void); - -bool gpi_storeDI_rejMot_home(bool reject); -bool epi_getDI_rejectMotor_homepos(void); - -uint8_t gpi_storeDI_paperLow(uint8_t di); -uint8_t epi_getDI_npe_sensor(void); - // 0: Sensor sees paper 1: no paper 99: off - -// /////////////////////////////////////////////////////////////////////////////////// -// readback digital outputs -// /////////////////////////////////////////////////////////////////////////////////// - -uint8_t gpi_storeDO_mdbRxTst(uint8_t do_mbdRxTst); -bool epi_getDO_mdbRxTestOut(void); - -uint8_t gpi_storeDO_motorOutputs(uint8_t Pwr); -uint8_t epi_getDO_motorOuts(void); - // bit0: upper lock forward bit 1 backward - // bit2: lower lock forward bit 3 backward - -uint8_t gpi_storeDO_serialSwitch(uint8_t state); - // serial drv on/off, Serial mux1, Serial mux2 -uint8_t epi_getDO_serialSwitch(void); - // serial drv on/off, Serial mux1, Serial mux2 - -bool epi_getDO_serialDriverIsOn(void); -bool epi_getDO_serialMux1isSetToPrinter(void); - // mux1 off: serial is switched to printer - -bool epi_getDO_serialMux1isSetToModem(void); - // mux1 on: serial is switched to modem -bool epi_getDO_serialMux2isSetToCredit(void); - // mux2 off: serial is switched to credit card terminal -bool epi_getDO_serialMux2isSetToMifare(void); - // mux2 on: serial is switched to mifare reader - -uint8_t gpi_storeDO_ledsAndFan(uint8_t ledState); -bool epi_getDO_led_coin(void); -bool epi_getDO_led_front(void); -bool epi_getDO_led_ticket(void); -bool epi_getDO_led_pin(void); -bool epi_getDO_led_start(void); -bool epi_getDO_led_inside(void); -bool epi_getDO_fan(void); - -uint8_t gpi_storeDO_sirenAndRelay(uint8_t sirenRelay); -bool epi_getDO_sirene(void); -bool epi_getDO_relay(void); - -uint8_t gpi_storeDO_ptuWake(uint8_t state); -bool epi_getDO_ptuWake(void); - -uint8_t gpi_storeDO_auxPower(uint8_t pwr); -bool epi_getDO_auxPower(void); - -uint8_t gpi_storeDO_coinShutter(uint8_t state); -bool epi_getDO_coinShutterOpen(void); -bool epi_getDO_coinShutterTest(void); - -uint8_t gpi_storeDO_coinEscrow(uint8_t state); -uint8_t epi_getDO_coinEscrow(void); - // retval: 1:return flap is open 2:take flap is open 0:closed - -uint8_t gpi_storeDO_printerPwrOn(uint8_t state); -uint8_t epi_getDO_printerPwr(void); - -// --------------------------------------------------------------------------------------------- -// counterchecks, make sure that DC-outputs are correct - -/* -bool epi_cntchk_wakePtu(void); -bool epi_cntchk_enabDrv01(void); // no communication possible if 0 !!!!! -bool epi_cntchk_swRs1toModem(void); -bool epi_cntchk_modemWake(void); -bool epi_cntchk_enabDrv2(void); -bool epi_cntchk_swRs2toMIF(void); - -bool epi_cntchk_shutterIsOpen(void); - // counter check if shutter is really open, PJ4 must be OUT and HIGH, PB5 must be OUT and HIGH - // retval TRUE: shutter is open FALSE: shutter is closed - -bool epi_cntchk_escrowReturnIsOpen(void); -bool epi_cntchk_escrowTakeIsOpen(void); -bool epi_cntchk_aux1DirOut(uint8_t auxNr); -bool epi_cntchk_aux1OutHigh(uint8_t auxNr); - -bool epi_cntchk_ledPaperOn(void); -bool epi_cntchk_ledPinpadOn(void); -bool epi_cntchk_ledStartOn(void); -bool epi_cntchk_ledServiceOn(void); -bool epi_cntchk_ledCoinOn(void); -bool epi_cntchk_ledIllumOn(void); -bool epi_cntchk_FanOn(void); -bool epi_cntchk_RelaisOn(void); -bool epi_cntchk_LaermOn(void); -bool epi_cntchk_Mot1Ron(void); -bool epi_cntchk_Mot1Fon(void); -bool epi_cntchk_Mot2Ron(void); -bool epi_cntchk_Mot2Fon(void); -*/ - - -// ------------------------------------------------------------------------------------ -// MDB Sendind Data are store here for next transport to DC (Device Controller) -// Transport to Slave runs every 100ms, answer from mdb-slave (e.g. coin changer) comes right -// with next slave answer - -// start with: SENDDIRCMD_EXCHGMDB, - // send crude data from here to DC, DC to mdb slaves, mdb answer, return here within 50ms - -uint8_t gpi_storeMdbRecData(uint8_t length, uint8_t *buf); - // datif store received mdb data -uint8_t epi_getMdbResponse(void); - // 0=no response 1=ACK 2=NAK 3=ACK with data -uint8_t epi_getMdbRecLength(void); - // 0...31 -uint8_t epi_restoreMdbRecData(uint8_t *buf); - // hwapi reads received mdb data from PI - -uint8_t gpi_storeMifReaderStateAndCardType(uint8_t const *buf); - -/* data description: -byte 0: current read state: 0=power off 1=reader-fault 2=ready - 3=just reading 4=read complete - 5=read partial, removed too early - 6=state unknown -byte 1,2: read data length from card -3: 1=reader is OK (reported serial nr is OK) 0=wrong or no reader -4...15: reader version, expected "SL025-1.8" -byte16: 1=card is present 0:not -17: 0 -18: card type reported from reader -19: 1=allowed card type 0=not -20: card size: 1 or 4 (dec) = card size -21: LengthOfUID: 4 or 7 (dec) (byte) -22: UID 8 byte in hex -byte 30: sector logged: 0 -byte 31: current sector: 0 -byte 32: result, always 0 -*/ - -uint8_t epi_restoreMifState(uint8_t *buf, uint8_t maxBufferSize); - // retval 0=OK 1=error host buffer too small -bool gpi_storeMifCardData(uint8_t blkNr, uint8_t const *receivedData); - // blkNr=0...11 receivedData[64] -uint8_t epi_restoreMifData(uint8_t blkNr, uint8_t *buf, uint8_t maxBufferSize); - // blkNr=0...11 return buf[64] - // retval: 1=error 0=OK - -void epi_restorePrinterState(uint8_t *buf); -void gpi_storePrinterState(uint8_t const *buf); - -void epi_restorePrinterFonts(uint8_t *buf); -void gpi_storePrinterFonts(uint8_t const *buf); - -bool gpi_storeMdbState(bool busReady, bool V12on, bool V5on); -bool epi_restoreMdbBusReady(void); -bool epi_restoreMdbV12Ready(void); -bool epi_restoreMdbV5Ready(void); - -void gpi_storeMdbResponse(uint8_t leng, uint8_t const *data); -void epi_restoreMdbResponse(uint8_t *leng, uint8_t *data); - // last received mdb answer (from mdb device) - // only needed if a special command was sent directly - // DB0: mdb Device-Nr - // DB1: last sent mdb command - // DB2: nr of received (payload) data bytes (apart from ACK, can be 0....34) - // DB3...DB38: rec.data (payload) - -void gpi_storeEmpSettings(uint8_t leng, uint8_t const *data); -void epi_restoreEmpSettings(uint8_t *leng, uint8_t *data); - -/* -void gpi_storeEmpCoinSignal(uint8_t leng, uint8_t *data); - -void epi_restoreEmpCoinSignal(uint8_t *leng, uint8_t *data); - // return 5 byte: - // data[0]=got coin 0xFF=emp reported an error 0=got nothing - // data[1]=emp-signal of last inserted coin - // data[2,3]=emp-value of last inserted coin - // data[4] = emp-error or warning - -void epi_clearEmpCoinSignal(); -*/ - - -void gpi_storeEmpCoinSignal(uint8_t leng, uint8_t const *data); - -uint8_t epi_isNewCoinLeft(void); - // retval: 0...16 coins left in FIFO -void epi_restoreEmpCoinSignal(uint8_t *valid, uint8_t *signal, uint8_t *error, uint16_t *value); - -void gpi_storeRbDeviceSettings(uint8_t leng, uint8_t const *data); -void epi_restoreRbDeviceSettings(uint8_t *leng, uint8_t *data); - -void gpi_storeMachineIDsettings(uint8_t leng, uint8_t const *data); -void epi_restoreMachineIDsettings(uint8_t *leng, uint8_t *data); - -void epi_clearCurrentPayment(void); -void gpi_storeCurrentPayment(uint32_t insertedAmount, uint16_t lastCoinType, uint16_t lastCoinValue); - -uint32_t epi_CurrentPaymentGetAmount(void); -uint16_t epi_CurrentPaymentGetLastCoin(void); - -bool epi_CurrentPaymentGetAllCoins(uint16_t *types, uint16_t *values); - // alle bei diesem Verkauf eingeworfenen Münzen sind gespeichert falls die jmd. braucht - -void gpi_storeWakeSources(uint8_t const *receivedData); -uint64_t epi_getWakeSources(void); -uint8_t epi_getWakeReason(void); - -void gpi_storeExtendedTime(uint8_t leng, uint8_t const *data); -void epi_restoreExtendedTime(uint8_t *leng, uint8_t *data); - -void gpi_storeDeviceConditions(uint8_t leng, uint8_t const *data); -void epi_restoreDeviceConditions(uint8_t *leng, uint8_t *data); - -void gpi_storeDynMachineConditions(uint8_t leng, uint8_t const *data); -void epi_restoreDynMachineConditions(uint8_t *leng, uint8_t *data); - -void gpi_storeDCbackupAccNr(uint8_t leng, uint8_t const *data); -void epi_restoreDCbackupAccNr(uint8_t *leng, uint16_t *accNrs); - // return accNrs[0..7] - -void epi_iniVRstorage(void); -void gpi_storeVaultRecord(uint8_t blkNr, uint8_t const *data); -bool epi_checkIfVaultRecordAvailable(void); -bool epi_restoreVaultRecord(uint16_t *length, uint8_t *buf); - // true if completly received - -void gpi_storeCBlevel(uint32_t amount, uint16_t nrOfCoins); - -uint32_t epi_getCashBoxContent(void); -uint16_t epi_getNrOfCoinsInCashBox(void); - -void gpi_storeNewMifareCard(uint8_t typ, uint8_t const *holder); - -uint8_t epi_mifGetCardType(uint8_t const *holder); - //holder[8] = name of card holder - // retval Type of MifareCard, 1=upper door, 2=lower door 3=test printer 4=test coins - -void gpi_storeDcDataValid(bool isVal); -bool gpi_areDcDataValid(); - - - -#endif - - - diff --git a/DCPlugin/include/tslib.h b/DCPlugin/include/tslib.h deleted file mode 100644 index bc38ade..0000000 --- a/DCPlugin/include/tslib.h +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef TSLIB_H -#define TSLIB_H -#include -#include - - -#define LOWBYTE false -#define HIGHBYTE true - -uint16_t uchar2uint(char Highbyte, char Lowbyte); -uint16_t uchar2uint(uint8_t Highbyte, uint8_t Lowbyte); -uint32_t uchar2ulong(uint8_t Highbyte, uint8_t MHbyte, uint8_t MLbyte, uint8_t Lowbyte); - -uint8_t uint2uchar(uint16_t uival, bool getHighB); - -uint8_t ulong2uchar(uint32_t ulval, uint8_t getBytNr); - // getBytNr: 0=LSB 3=MSB - - -void delay(uint16_t MilliSec); - -#define MITSEK 1 -#define OHNESEK 0 -#define HourSys12h 1 -#define HourSys24h 0 - -void GetTimeString(uint8_t hours, uint8_t minutes, uint8_t seconds, uint8_t System12h, uint8_t ShowSec, uint8_t *buf); - // generate time as ascii string from integers hours/minutes/seconds - // System12h=0: 24h system =1: 12h System - // ShowSec=0: String has 5 digits (hh:mm) =1: String has 8 digits (hh:mm:ss) - // return String in *buf // 12 byte für buf! - -#define DateFormatDeutsch 0 -#define DateFormatAmerica 1 -#define UsePointSeperator 0 -#define UseSlashSeperator 1 - - -void GetDateString(uint8_t day, uint8_t month, uint8_t yearhigh, uint8_t yearlow, uint8_t format, uint8_t sep, uint8_t *buf); - // generate date as ascii string from integers day/month/year - // yearhigh in europe always 20 (not in arabia) - // format= 0: dd.mm.yyyy (deutsch) - // 1: mm.dd.yyyy (amerika) - // 2: yyyy.mm.dd (Iran, Dubai) - // 3: dd.yyyy.mm - // 4: mm.yyyy.dd - // 5: yyyy.dd.mm - // sep: 0: use . as seperator 1: use / as seperator - // return String in *buf // 11 byte für buf! - - -void GetShortDateString(uint8_t day, uint8_t month, uint8_t yearlow, uint8_t format, uint8_t sep, uint8_t *buf); - // generate date as ascii string from integers day/month/year - // format= 0: dd.mm.yy (deutsch) - // 1: mm.dd.yy (amerika) - // 2: yy.mm.dd (Iran, Dubai) - // 3: dd.yy.mm - // 4: mm.yy.dd - // 5: yy.dd.mm - // sep: 0: use . as seperator 1: use / as seperator - // return String in *buf // 11byte für buf! - - -uint16_t tslib_strlen(char *buf); -uint16_t tslib_strlen(uint8_t *buf); - -void tslib_strclr(char *buf, char clrsign, uint16_t len); -void tslib_strclr(uint8_t *buf, char clrsign, uint16_t len); - -void tslib_strcpy(char *srcbuf, char *destbuf, uint16_t len); -void tslib_strcpy(char *srcbuf, uint8_t *destbuf, uint16_t len); -void tslib_strcpy(uint8_t *srcbuf, uint8_t *destbuf, uint16_t len); - - -uint16_t tslib_calcCrcCcitt(uint16_t BufLength, uint8_t *buf); - -bool tslib_isDecAsciiNumber(char sign); -bool tslib_isHexAsciiNumber(char sign); - - -int tslib_getMinimum(int val1, int val2); - -void tslib_text2array(QByteArray text, char *aray, uint16_t maxArayLen); - // usage: tslib_text2array("my text", ctmp, 50); - -void biox_CopyBlock(uint8_t *src, uint16_t srcPos, uint8_t *dest, uint16_t destPos, uint16_t len); - // both buffers starting from pos 0 - - -#endif // TSLIB_H diff --git a/DCPlugin/src/ATBAPP/ATBAPPplugin.h b/DCPlugin/src/ATBAPP/ATBAPPplugin.h deleted file mode 100644 index ec017f5..0000000 --- a/DCPlugin/src/ATBAPP/ATBAPPplugin.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef ATBAPPPLUGIN_H -#define ATBAPPPLUGIN_H - -/*********************************************************** - * a simple class with only one method for plugin info - */ -#include -#include - -class ATBAPPplugin -{ - -public: - virtual const QString & getPluginInfo() = 0; -}; - -Q_DECLARE_INTERFACE(ATBAPPplugin, - "eu.atb.ptu.plugin.ATBAPPplugin/0.9") - - - -#endif // ATBAPPPLUGIN_H diff --git a/DCPlugin/src/ATBAPP/ATBDeviceControllerPlugin.cpp b/DCPlugin/src/ATBAPP/ATBDeviceControllerPlugin.cpp deleted file mode 100644 index d0520b2..0000000 --- a/DCPlugin/src/ATBAPP/ATBDeviceControllerPlugin.cpp +++ /dev/null @@ -1,293 +0,0 @@ -#include "src/ATBAPP/ATBDeviceControllerPlugin.h" -#include "src/ATBAPP/ATBHealthEvent.h" - -#include -#include - - -ATBDeviceControllerPlugin::ATBDeviceControllerPlugin(QObject *parent) : QObject(parent), - pluginState(PLUGIN_STATE::NOT_INITIALIZED) -{ - this->pluginInfo = QString::fromUtf8(pluginInfoString.c_str()); - - this->hw = new hwapi(); - - connect(dynamic_cast(hw), SIGNAL(hwapi_templatePrintFinished_OK()), this, SLOT(onPrintFinishedOK())); - connect(dynamic_cast(hw), SIGNAL(hwapi_templatePrintFinished_Err()), this, SLOT(onPrintFinishedERR())); - connect(dynamic_cast(hw), SIGNAL(hwapi_gotNewCoin()), this, SLOT(onCashGotCoin())); - connect(dynamic_cast(hw), SIGNAL(hwapi_vendStopByMax()), this, SLOT(onCashVendStopByMax())); -} - -ATBDeviceControllerPlugin::~ATBDeviceControllerPlugin() {} - -PLUGIN_STATE ATBDeviceControllerPlugin::initDCPlugin(QObject *healthEventReceiver, const QSettings & settings) -{ - this->healthEventReceiver = healthEventReceiver; - - // read variables from setting - QString serialPort = settings.value("DEVICE_CONTROLLER/serialPort", "ttymxc2").toString(); - QByteArray printerEncoding = settings.value("DEVICE_CONTROLLER/printerEnconding", "ISO 8859-2").toString().toLatin1(); - - - - // open serial port - hw->dc_openSerial(5, "115200", serialPort, 1); - - - // text encoding for printer - this->codec = QTextCodec::codecForName(printerEncoding); - - - - this->pluginState = PLUGIN_STATE::INITIALIZED; - - return pluginState; -} - - -// TASKS: Cash handling ------------------------------------------------------- -void ATBDeviceControllerPlugin::requestStartCashInput(const QString & amount) -{ - qCritical() << "Start Cash vending with amount = " << amount; - - uint32_t amountInt = static_cast(amount.toUInt()); - hw->cash_startPayment(amountInt); -} - -void ATBDeviceControllerPlugin::requestStopCashInput() -{ - hw->cash_stopPayment(); -} - -void ATBDeviceControllerPlugin::cashCollect() -{ - hw->vend_success(); -} - -void ATBDeviceControllerPlugin::cashAbort() -{ - hw->vend_failed(); -} - - -// TASKS: printing ------------------------------------------------------------ -void ATBDeviceControllerPlugin::requestPrintTicket(const QHash & printingData) -{ - struct T_dynDat *dynTicketData = new T_dynDat; - memset(dynTicketData, 0, sizeof(*dynTicketData)); - - qCritical() << "ATBDeviceControllerPlugin::requestPrintTicket( " << endl - << " licenseplate = " << printingData["licenseplate"] << endl - << " amount = " << printingData["amount"] << endl - << " parkingEnd = " << printingData["parkingEnd"] << endl - << " currentTime = " << printingData["currentTime"] << endl - << " currentDate = " << printingData["currentDate"] << endl; - - - // set dynamic printer data: - memcpy((char*)dynTicketData->licensePlate, codec->fromUnicode(printingData["licenseplate"].toString()).data(), 8); - memcpy((char*)dynTicketData->vendingPrice, codec->fromUnicode(printingData["amount"].toString()).data(), 8); - - QDateTime parkingEndQDateTime = QDateTime::fromString(printingData["parkingEnd"].toString(), Qt::ISODate); - QDateTime currentDateTime = QDateTime::fromString(printingData["currentTime"].toString(), Qt::ISODate); - - memcpy((char*)dynTicketData->parkingEnd, codec->fromUnicode(parkingEndQDateTime.toString("hh:mm")).data(), 8); - memcpy((char*)dynTicketData->currentTime, codec->fromUnicode(currentDateTime.toString("hh:mm")).data(), 8); - memcpy((char*)dynTicketData->currentDate, codec->fromUnicode(currentDateTime.toString("dd.MM.yy")).data(), 8); - - // DEBUG - qCritical() << "ATBDeviceControllerPlugin::requestPrintTicket()"; - - if (!this->hw->dc_isPortOpen()) { - qCritical() << " ... serial port is not open!"; - this->onPrintFinishedERR(); - return; - } - - - // TODO: wird hier nur 'licensePlate' gedruckt? - if (!this->hw->prn_sendDynamicPrnValues(dynTicketData->licensePlate)) { - this->errorCode = "hwapi::prn_sendDynamicPrnValues"; - this->errorDescription = "hwapi method 'hwapi::prn_sendDynamicPrnValues' result is false"; - - qCritical() << "ERROR:"; - qCritical() << "ATBDeviceControllerPlugin::requestPrintTicket( " << endl - << " licenseplate = " << printingData["licenseplate"] << endl - << " amount = " << printingData["amount"] << endl - << " parkingEnd = " << printingData["parkingEnd"] << endl - << " currentTime = " << printingData["currentTime"] << endl - << " currentDate = " << printingData["currentDate"] << endl; - - - this->onPrintFinishedERR(); - return; - } - - QTimer::singleShot(1000, this, SLOT(onPrinterDataPrepared())); -} - - - -void ATBDeviceControllerPlugin::onPrinterDataPrepared() -{ - this->currentTemplate = 1; - this->onPrinterPrintNextTemplate(); -} - - -void ATBDeviceControllerPlugin::onPrinterPrintNextTemplate() -{ - qCritical() << " ... print template " << this->currentTemplate; - - if (!this->hw->prn_printTemplate(this->currentTemplate)) { - this->errorCode = "hwapi::prn_printTemplate"; - this->errorDescription = QString("hwapi method 'hwapi::onPrinterPrintNextTemplate(%1)' result is false").arg(this->currentTemplate); - this->onPrintFinishedERR(); - return; - } - - if (this->currentTemplate >= 3) { - // all templates are printed - this->currentTemplate = 0; - - // FAKE SIGNAL: - QTimer::singleShot(1000, this, SLOT(onPrintFinishedOK())); - } - else { - // print next template - this->currentTemplate++; - QTimer::singleShot(3000, this, SLOT(onPrinterPrintNextTemplate())); - } - -} - - -/************************************************************************************************ - * private slots, interface to low level hwapi - * - */ -void ATBDeviceControllerPlugin::onPrintFinishedOK() -{ - // DEBUG - qCritical() << "ATBDeviceControllerPlugin::onPrintFinishedOK()"; - - emit this->printTicketFinished(nsDeviceControllerInterface::RESULT_STATE::SUCCESS, - "", - ""); -} -void ATBDeviceControllerPlugin::onPrintFinishedERR() -{ - // DEBUG - qCritical() << "ATBDeviceControllerPlugin::onPrintFinishedERR()"; - - - this->errorCode = "PRINTER"; // TODO: get more detailed error code from low level API - this->errorDescription = "Printer error"; // TODO: get more detailed error description from low level API - - emit this->printTicketFinished(nsDeviceControllerInterface::RESULT_STATE::ERROR_BACKEND, - this->errorCode, - this->errorDescription); -} - - - -/************************************************************************************************ - * cash payment - */ -void ATBDeviceControllerPlugin::onCashGotCoin() -{ - // DEBUG - qCritical() << "ATBDeviceControllerPlugin::onGotCoin()"; - - uint32_t amountInt = this->hw->getInsertedAmount(); - - QString amountString = QString::number(amountInt); - - - emit this->cashInputEvent(nsDeviceControllerInterface::RESULT_STATE::SUCCESS, - nsDeviceControllerInterface::CASH_STATE::CACHE_INPUT, - amountString, - "", - ""); -} - - -void ATBDeviceControllerPlugin::onCashVendStopByMax() -{ - // DEBUG - qCritical() << "ATBDeviceControllerPlugin::onCashVendStopByMax()"; - - uint32_t amountInt = this->hw->getInsertedAmount(); - - QString amountString = QString::number(amountInt); - - emit this->cashInputFinished(nsDeviceControllerInterface::RESULT_STATE::SUCCESS, - amountString, - "", - ""); - -} - -/************************************************************************************************ - * Mandatory plugin methods - * - */ - -PLUGIN_STATE ATBDeviceControllerPlugin::getState() -{ - return this->pluginState; -} - -QString & ATBDeviceControllerPlugin::getLastError() -{ - return this->errorCode; -} - -const QString & ATBDeviceControllerPlugin::getLastErrorDescription() -{ - return this->errorDescription; -} - -const QString & ATBDeviceControllerPlugin::getPluginInfo() -{ - return this->pluginInfo; -} - - -const QString ATBDeviceControllerPlugin::getString(nsDeviceControllerInterface::RESULT_STATE resultState) -{ - QString str; - - switch (resultState) { - case nsDeviceControllerInterface::RESULT_STATE::SUCCESS: - str = QString("RESULT_STATE::SUCCESS"); - break; - case nsDeviceControllerInterface::RESULT_STATE::ERROR_BACKEND: - str = QString("RESULT_STATE::ERROR_BACKEND"); - break; - case nsDeviceControllerInterface::RESULT_STATE::ERROR_TIMEOUT: - str = QString("RESULT_STATE::ERROR_TIMEOUT"); - break; - case nsDeviceControllerInterface::RESULT_STATE::ERROR_PROCESS: - str = QString("RESULT_STATE::ERROR_PROCESS"); - break; - case nsDeviceControllerInterface::RESULT_STATE::ERROR_RETRY: - str = QString("RESULT_STATE::ERROR_RETRY"); - break; - case nsDeviceControllerInterface::RESULT_STATE::INFO: - str = QString("RESULT_STATE::INFO"); - break; - } - return str; - -} - - - -/************************************************************************************************ - * ... end - */ - -#if QT_VERSION < 0x050000 -Q_EXPORT_PLUGIN2( ATBDeviceControllerPlugin, ATBDeviceControllerPlugin ) -#endif diff --git a/DCPlugin/src/ATBAPP/ATBDeviceControllerPlugin.h b/DCPlugin/src/ATBAPP/ATBDeviceControllerPlugin.h deleted file mode 100644 index 6e8285b..0000000 --- a/DCPlugin/src/ATBAPP/ATBDeviceControllerPlugin.h +++ /dev/null @@ -1,125 +0,0 @@ -#ifndef ATBDEVICECONTROLLERPLUGIN_H -#define ATBDEVICECONTROLLERPLUGIN_H - -#include - -#include "src/ATBAPP/DeviceControllerInterface.h" -#include "src/ATBAPP/ATBAPPplugin.h" -#include "version.h" - - - -#include "hwapi.h" - -#include -#include -#include -#include - - -class QTextCodec; - - -using namespace nsDeviceControllerInterface; - -class QSettings; - -class ATBDeviceControllerPlugin : public QObject, - public DeviceControllerInterface -{ - Q_OBJECT - Q_INTERFACES(ATBAPPplugin) - Q_INTERFACES(DeviceControllerInterface) - #if QT_VERSION >= 0x050000 - Q_PLUGIN_METADATA( IID "ATBDeviceControllerPlugin" ) - #endif - -public: - explicit ATBDeviceControllerPlugin(QObject *parent = nullptr); - ~ATBDeviceControllerPlugin(); - - // ---------------------------------------------------------------------------- - // interface: - PLUGIN_STATE initDCPlugin(QObject *healthEventReceiver, const QSettings & settings); - - // TASKS: Cash handling ------------------------------------------------------- - void requestStartCashInput(const QString & amount); - void requestStopCashInput(); - void cashCollect(); - void cashAbort(); - - // TASKS: printing ------------------------------------------------------------ - void requestPrintTicket(const QHash & printingData); - - // mandantory ATBAPP plugin methods: ------------------------------------------ - nsDeviceControllerInterface::PLUGIN_STATE getState(); - QString & getLastError(); - const QString & getLastErrorDescription(); - - const QString & getPluginInfo(); - - // helpers e.g. for debug / log - const QString getString(nsDeviceControllerInterface::RESULT_STATE resultState); - - - - - -signals: - void printTicketFinished(nsDeviceControllerInterface::RESULT_STATE resultState, - const QString & errorCode, - const QString & errorDescription); - - void cashInputEvent(nsDeviceControllerInterface::RESULT_STATE resultState, - nsDeviceControllerInterface::CASH_STATE cashState, - const QString & newCashValue, - const QString & errorCode, - const QString & errorDescription); - - void cashInputFinished(nsDeviceControllerInterface::RESULT_STATE resultState, - const QString & newCashValue, - const QString & errorCode, - const QString & errorDescription); - - void requestServiceMode(); - - void Error( - const QString & errorCode, - const QString & errorDescription); - - - - -private: - QString errorCode; - QString errorDescription; - QString pluginInfo; - - int currentTemplate; - - - bool useDebug; - - PLUGIN_STATE pluginState; - - QObject* healthEventReceiver; - - hwinf* hw; - - QTextCodec *codec; - -private slots: - // printer - - void onPrinterDataPrepared(); - void onPrinterPrintNextTemplate(); - - void onPrintFinishedOK(); - void onPrintFinishedERR(); - - // cash payment - void onCashGotCoin(); - void onCashVendStopByMax(); -}; - -#endif // ATBDEVICECONTROLLERPLUGIN_H diff --git a/DCPlugin/src/ATBAPP/ATBHealthEvent.cpp b/DCPlugin/src/ATBAPP/ATBHealthEvent.cpp deleted file mode 100644 index 3805a2a..0000000 --- a/DCPlugin/src/ATBAPP/ATBHealthEvent.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "src/ATBAPP/ATBHealthEvent.h" - -ATBHealthEvent::ATBHealthEvent(ATB_HEALTH_MODE mode, const QString & errorNumber, const QString & errorDescription) : - QEvent(ATB_HEALTH_EVENT), - healthMode(mode), - errorNumber(errorNumber), - errorDescription(errorDescription) -{ - -} - -QString ATBHealthEvent::getErrorNumber() -{ - return this->errorNumber; -} - -QString ATBHealthEvent::getErrorDescription() -{ - return this->errorDescription; -} - -ATB_HEALTH_MODE ATBHealthEvent::getMode() -{ - return this->healthMode; -} diff --git a/DCPlugin/src/ATBAPP/ATBHealthEvent.h b/DCPlugin/src/ATBAPP/ATBHealthEvent.h deleted file mode 100644 index b0874d7..0000000 --- a/DCPlugin/src/ATBAPP/ATBHealthEvent.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef ATBHEALTHEVENT_H -#define ATBHEALTHEVENT_H - -#include -#include - -enum class ATB_HEALTH_MODE : quint8; - -const QEvent::Type ATB_HEALTH_EVENT = static_cast(QEvent::User + 1); - - -class ATBHealthEvent : public QEvent -{ - -public: - ATBHealthEvent(ATB_HEALTH_MODE mode, const QString & errorNumber, const QString & errorDescription); - - QString getErrorNumber(); - QString getErrorDescription(); - ATB_HEALTH_MODE getMode(); - -signals: - -public slots: - - -private: - ATB_HEALTH_MODE healthMode; - QString errorNumber; - QString errorDescription; -}; - - -enum class ATB_HEALTH_MODE : quint8 { - WARNING, - ERROR, - WARNING_CORRECTION, - ERROR_CORRECTION, - DEBUG, - STATE, - UNSPECIFIED -}; - -#endif // ATBHEALTHEVENT_H diff --git a/DCPlugin/src/ATBAPP/DeviceControllerInterface.h b/DCPlugin/src/ATBAPP/DeviceControllerInterface.h deleted file mode 100644 index 3d5d3e8..0000000 --- a/DCPlugin/src/ATBAPP/DeviceControllerInterface.h +++ /dev/null @@ -1,142 +0,0 @@ -#ifndef DEVICECONTROLLERINTERFACE_H -#define DEVICECONTROLLERINTERFACE_H - -#include - -#include -#include - -#include "ATBAPPplugin.h" - -namespace nsDeviceControllerInterface { - enum class PLUGIN_STATE : quint8; - enum class RESULT_STATE : quint8; - enum class CASH_STATE : quint8; -} - - -class DeviceControllerInterface : public ATBAPPplugin -{ - Q_INTERFACES(ATBAPPplugin) - -public: - virtual ~DeviceControllerInterface() {} - - virtual nsDeviceControllerInterface::PLUGIN_STATE initDCPlugin(QObject *healthEventReceiver, - const QSettings & settings) = 0; - - // TASKS: Cash handling ------------------------------------------------------- - /** - * enables coin input - * amount = "0": pay-up - * amount > "0": pay-down - */ - virtual void requestStartCashInput(const QString & amount) = 0; - - /** - * called e.g. on Button "NEXT" in pay-up (direct coin input) - */ - virtual void requestStopCashInput() = 0; - - /** - * called e.g. on Button "NEXT" in pay-up (direct coin input) - */ - virtual void cashCollect() = 0; - virtual void cashAbort() = 0; - - - - // TASKS: printing ------------------------------------------------------------ - virtual void requestPrintTicket(const QHash & printingData) = 0; - - - // mandantory ATBAPP plugin methods: - virtual nsDeviceControllerInterface::PLUGIN_STATE getState() = 0; - virtual const QString & getLastError() = 0; - virtual const QString & getLastErrorDescription() = 0; - - // return a plugin description in JSON or XML - // -> ATBAPPplugin::getPluginInfo() - - // helpers e.g. for debug / log - virtual const QString getString(nsDeviceControllerInterface::RESULT_STATE resultState) = 0; - - -signals: - virtual void printTicketFinished(nsDeviceControllerInterface::RESULT_STATE resultState, - const QString & errorCode, - const QString & errorDescription) = 0; - - /** - * emitted on e.g. a coin input - */ - virtual void cashInputEvent(nsDeviceControllerInterface::RESULT_STATE resultState, - nsDeviceControllerInterface::CASH_STATE cashState, - const QString & newCashValue, - /* additional variables? */ - const QString & errorCode, - const QString & errorDescription) = 0; - - /** - * emitted if cashInput has been stopped, e.g. in result to task requestStopCashInput(): - * -> shutter is blocked - * -> no cash input is possible - * -> coins are in cache - */ - virtual void cashInputFinished(nsDeviceControllerInterface::RESULT_STATE resultState, - const QString & newCashValue, - /* additional variables? */ - const QString & errorCode, - const QString & errorDescription) = 0; - - - /** - * emitted e.g. if service door is opened - */ - virtual void requestServiceMode() = 0; - - /** - * emitted on error - * depending on errorCode: - * -> interrupt selling process - * -> machine can go to state OOO - * -> send error event to ISMAS - * -> ... - */ - virtual void Error( - /* additional variables? */ - const QString & errorCode, - const QString & errorDescription) = 0; - -}; - - -Q_DECLARE_INTERFACE(DeviceControllerInterface, - "eu.atb.ptu.plugin.DeviceControllerInterface/1.0") - - -namespace nsDeviceControllerInterface { - - enum class PLUGIN_STATE : quint8 { - NOT_INITIALIZED = 0, - INITIALIZED = 1 - }; - - enum class RESULT_STATE : quint8 { - SUCCESS = 1, // operation was successfull - ERROR_BACKEND, // error from backend (e.g. backend replies with error) - ERROR_TIMEOUT, // the operation timed out - ERROR_PROCESS, // internal plugin error, should not occur (this is a bug in implementation) - ERROR_RETRY, // retry operation - INFO // informational (e.g. display a message, log something etc.) - }; - - enum class CASH_STATE : quint8 { - CACHE_EMPTY, // Cache still empty, default state - CACHE_INPUT, // Coins are in Cache - OVERPAYED, - /* t.b.d. */ - }; -} - -#endif // DEVICECONTROLLERINTERFACE_H diff --git a/DCPlugin/src/com.cpp b/DCPlugin/src/com.cpp deleted file mode 100644 index 01f9292..0000000 --- a/DCPlugin/src/com.cpp +++ /dev/null @@ -1,449 +0,0 @@ -#include "com.h" -#include -//#include "controlBus.h" - -////////////////////////////////////////////////////////////////////////////////// -/// -/// serial hardware layer -/// -////////////////////////////////////////////////////////////////////////////////// - -static int64_t com_want2read; -// ------------------------------------------------------------------------------------------------------------- -// --------- PUBLIC -------------------------------------------------------------------------------------------- -// ------------------------------------------------------------------------------------------------------------- - -void T_com::writeToSerial(const QByteArray &data, uint16_t sendLength) -{ - sendBuffer=data; - sendLen=sendLength; - if (CatSerial->isOpen()) - { - //qDebug() << "sending..." << sendBuffer; - CatSerial->write(sendBuffer); - } else - qDebug() << "error sending, port is not open"; - -} - - -bool T_com::readFromSerial(QByteArray &data, uint16_t &sendLength) -{ - // return one time true if new data (completly) read. - // return new data in &data and &sendLength to other objects - uint16_t ll=rawInLen; - if (!CatSerial->isOpen()) - return false; - data.clear(); - data.append(rawInput); - sendLength=ll; - rawInLen=0; // beim 2. Aufruf 0 zurück weil nichts neues da - if (ll>0) - return true; - return false; -} - - -// ------------------------------------------------------------------------------------------------------------- -// --------- PRIVATES -------------------------------------------------------------------------------------- -// ------------------------------------------------------------------------------------------------------------- - - -T_com::T_com(QWidget *parent) : QMainWindow(parent) -{ - // port settings come from tabCom->Sdata->serial - - gpi_serialChanged(); - CatSerial = new QSerialPort(); // PortHW object for Control&Analyse Tool - //CatSerial->clear(); - //CatSerial->clearError(); - - connect(CatSerial, &QSerialPort::readyRead, this, &T_com::readSomeBytes); - // still reading, not sure if complete, undefined number of calls while reading - - connect(CatSerial, &QSerialPort::bytesWritten, this, &T_com::serialSendComplete); - // system confirms sending complete - - //connect(CatSerial, &QSerialPort::dataTerminalReadyChanged, this, &T_com::incomingWake); - //connect(CatSerial, &QSerialPort::requestToSendChanged, this, &T_com::incomingWake); - - // timer detects time gap in input flow - serRecTime = new QTimer(); - connect(serRecTime, SIGNAL(timeout()), this, SLOT(receiveTO())); - serRecTime->setSingleShot(true); // single shot! only one impulse if receive complete - serRecTime->stop(); // on hold - - // check COM-TAB periodic if user wants to connect or disconnect - QTimer *ChkConnectTimer = new QTimer(); - connect(ChkConnectTimer, SIGNAL(timeout()), this, SLOT(ser_ISR100ms())); - ChkConnectTimer->setSingleShot(false); - ChkConnectTimer->start(100); // in ms - com_want2read=0; -} - - - - -T_com::~T_com() -{ - if (CatSerial->isOpen()) - CatSerial->close(); -} - - -void T_com::ser_ISR100ms() -{ - //qDebug() << "~~>LIB" << "ENTER..."; - // call every 100ms to check if user(HMI) wants to connect or disconnect - uint8_t chkConn = gpi_getSerialConn(); // from global GUI buffer (Sdata) - - //qDebug() << "~~>LIB" << "checking connect button... " << chkConn; - - switch (chkConn) - { - case 0: // 0 button "connect" was just released - //qDebug() << "close serial port" << chkConn; - closeSerialPort(); - gpi_serialChanged(); // set chkConn to 2, thus getting edge - break; - case 1: // 1 button "connect" was just pressed - //qDebug() << "open serial port" << chkConn; - open_Serial_Port(); - gpi_serialChanged(); // set chkConn to 2, thus getting edge - break; - } - - - if (CatSerial->isOpen()) { - gpi_serialIsOpen(true); - } else { - gpi_serialIsOpen(false); - } - - //qDebug() << "LEAVE " << chkConn; -} - -// ------------------------------------------------------------------------------------------------------------- -// ------------------------------------------------------------------------------------------------------------- -// ------------------------------------------------------------------------------------------------------------- - -char T_com::open_Serial_Port() -{ - //qDebug() << "ENTER"; - - bool ret; - QString myString=nullptr, myPortName=nullptr, myBaudStr=nullptr; - int myBaudNr; - - if (CatSerial->isOpen()) { - qDebug() << "!!!IS OPEN!!!"; - return 0; // opening twice is not allowed - } - - //qDebug() << "connecting..." << myPortName; - myPortName=gpi_getComPortName(); // was selected and stored from GUI - CatSerial->setPortName(myPortName); - myBaudNr=gpi_getBaudNr(); // was selected and stored from GUI - - //qDebug() << "myPortName" << myPortName << ", myBaudNr" << myBaudNr; - - switch (myBaudNr) - { - // 0:1200 1:9600 2:19200 3:38400 4:57600 5:115200 - case 0: CatSerial->setBaudRate(QSerialPort::Baud1200); myBaudStr="1200"; break; - case 1: CatSerial->setBaudRate(QSerialPort::Baud9600); myBaudStr="9600"; break; - case 2: CatSerial->setBaudRate(QSerialPort::Baud19200); myBaudStr="19200"; break; - case 3: CatSerial->setBaudRate(QSerialPort::Baud38400); myBaudStr="38400"; break; - case 4: CatSerial->setBaudRate(QSerialPort::Baud57600); myBaudStr="57600"; break; - case 5: CatSerial->setBaudRate(QSerialPort::Baud115200); myBaudStr="115200"; break; - } - - CatSerial->setDataBits(QSerialPort::Data8); - // alt: QSerialPort::Data5,6,7,8 - - CatSerial->setParity(QSerialPort::NoParity); - // alt: EvenParity, OddParity, NoParity - - CatSerial->setStopBits(QSerialPort::OneStop); - // alternative: OneStop, TwoStop, OneAndHalfStop - - CatSerial->setFlowControl(QSerialPort::NoFlowControl); - // alt: HardwareControl, SoftwareControl, NoFlowControl - - ret=CatSerial->open(QIODevice::ReadWrite); - // alt: QIODevice::ReadWrite QIODevice::ReadOnly QIODevice::WriteOnly - if (!ret) - { - myString.clear(); - myString = "error "; - myString.append(CatSerial->errorString()); - qDebug() << myString; - gpi_setTxt4comStateLine(myString); - - //qDebug() << "LEAVE"; - - return 0; - } else - { - myString.clear(); - myString.append(myPortName); - //lang=myString.size(); - myString.append(" opened with "); - myString.append(myBaudStr); - myString.append(" 8N1"); - qDebug() << myString; - gpi_setTxt4comStateLine(myString); - gpi_setTxt4RsDiagWin(myString+"\n"); - - } - - //qDebug() << "LEAVE"; - return 0; -} - -void T_com::closeSerialPort() -{ - //qDebug() << "ENTER"; - - if (CatSerial->isOpen()) - { - qDebug() << "closing connection"; - CatSerial->close(); - gpi_setTxt4comStateLine("closed"); - gpi_setTxt4RsDiagWin("closed"); - - } - - //qDebug() << "LEAVE"; -} - - -void T_com::readSomeBytes(void) -{ - // called by serial-read-detection - // restart off-time as input flow is ongoing - - // timer for slow receive - // and serves as timeout for fast receive is msg is shorter as expected - serRecTime->stop(); - serRecTime->start(20); // in ms - - //qDebug()<< "com-rec read some bytes"; - - this->receiveByLength(); // since 14.12.21: fast receive -} - -void T_com::receiveFixLen(int64_t nrOfbytesToReceive) -{ - // call this before sending a request to slave - // then we know exactly when reception is complete -> much faster - com_want2read=nrOfbytesToReceive; - // since 14.12.21: FastDevice Protocol has two lengthen: - // fast: 12byte reception long: 68byte -} - -void T_com::receiveByLength(void) -{ - - if (CatSerial->isOpen()) - { - QString myString=nullptr, tmpStr=nullptr; - int64_t nrOfBytesreceived = CatSerial->bytesAvailable(); // nr of received bytes - - //qDebug()<< "com-rec current Len: "<< nrOfBytesreceived; - - if (nrOfBytesreceived >= com_want2read) - { - QByteArray data = CatSerial->readAll(); // erst auslesen wenn alles da! löscht den Empfangspuffer - serRecTime->stop(); // stop timeout to avoid 2nd emit - rawInLen=uint16_t (nrOfBytesreceived); - rawInput.clear(); - rawInput.append(data); - // report "new data received" to other objects - //qDebug()<< "com-recFinished by Len "<< rawInLen; - emit receivingFinished(); - } - } -} - -void T_com::receiveTO(void) -{ - // no new input data for 20ms, --> assuming frame complete - // save data in private "rawInput"-buffer - - if (CatSerial->isOpen()) - { - - QString myString=nullptr, tmpStr=nullptr; - int64_t nrOfBytesreceived = CatSerial->bytesAvailable(); // nr of received bytes - QByteArray data = CatSerial->readAll(); - - rawInLen=uint16_t (nrOfBytesreceived); - rawInput.clear(); - rawInput.append(data); - //rawInput[rawInLen]=0; // Zwangsterminierung bei QByteArray nicht nötig - - // diag display in serial in/out window and debug window - myString.clear(); - myString.setNum(rawInLen); - myString.append(" in: "); - //myString.append(rawInput); - for (int ii=0; ii0x80 dann wird EIN Byte 16 stellig angezeigt - int ll=tmpStr.length(); - if (ll>2) - { - myString.append(tmpStr[ll-2]); - myString.append(tmpStr[ll-1]); - } else - { - myString.append(tmpStr); - } - myString.append(" "); - } - myString.append("\n"); - #ifdef PRINTALLDEBUGS - qDebug() << "VCP:" << myString; // display all inputs and outputs in output window - #endif - gpi_setTxt4RsDiagWin(myString); - //gpi_set2ndTxt4RsDiagWin(myString); - - // report "new data received" to other objects - //qDebug()<< "com-recFinished by TO"; - emit receivingFinished(); - } -} - -void T_com::serialSendComplete(void) -{ - // system confirms sending complete, diag display - QString myString=nullptr, tmpStr=nullptr; - - myString.clear(); - myString.setNum(sendLen); - myString.append(" out: "); - - for (int ii=0; ii0x80 dann 16stellig - int ll=tmpStr.length(); - if (ll>2) - { - //qDebug() << "long_string" << ll << "\n"; - myString.append(tmpStr[ll-2]); - myString.append(tmpStr[ll-1]); - - } else - { - myString.append(tmpStr); - } - myString.append(" "); - } - -#ifdef PRINTALLDEBUGS - myString.append("\n"); - qDebug() << myString; // display all output data in out-window -#endif - - gpi_setTxt4RsDiagWin(myString); - - emit sendingFinished(); // for whom it may interest -} - - -bool T_com::isPortOpen(void) -{ - if (CatSerial->isOpen()) - return true; - return false; -} - - - -// ------------------------------------------------------------------------------------------------------------- -// ------------------------------------------------------------------------------------------------------------- -// ------------------------------------------------------------------------------------------------------------- - -/* -uint8_t T_com::getAllPortPins(void) -{ - uint8_t rs232pins=0; - rs232pins= uint8_t(CatSerial->pinoutSignals()); - // rs232pins: all signals bitwise coded in one byte: - // readback output: bit 0=TxD(=output) bit2=DTR (=output) bit 6=RTS (=output) - // unused inputs: bit1=RxD bit 3=DCD bit 5 = RING - // handshake inputs: bit 4=DSR (0x10) bit 7=CTS (0x80) - //qDebug()<<"serial port pins: " << rs232pins; - return rs232pins; -} - -bool T_com::getHSin_CTS(void) -{ - // return the used Handshake IN (CTS, alt. DSR): true= high level (+8V) - - uint8_t rs232pins=0; - - rs232pins= uint8_t(CatSerial->pinoutSignals()); - // rs232pins: all signals bitwise coded in one byte: - // readback output: bit 0=TxD(=output) bit2=DTR (=output) bit 6=RTS (=output) - // unused inputs: bit1=RxD bit 3=DCD bit 5 = RING - // handshake inputs: bit 4=DSR (0x10) bit 7=CTS (0x80) - - if (rs232pins & 0x80) // CTS - return true; - - return false; -} - - -bool T_com::getHSin_DSR(void) -{ - uint8_t rs232pins=0; - rs232pins= uint8_t(CatSerial->pinoutSignals()); - if (rs232pins & 0x10) // DSR - return true; - return false; -} - -void T_com::incomingWake(void) //(bool LevelOfTheBit) -{ - emit wasWokenBySerialHandshake(); -} - -bool T_com::setHSout_RTS(bool hsout) -{ - // hsout true=positiv voltage +12V false= -12V - // retval: true=setting OK - - bool cc; - // 10.5.19, am Windows-PC nachgemessen, funktioniert gut - // false ergibt -12V true ergibt +12V - - cc=CatSerial->setRequestToSend(hsout); // RTS out - // retval true means "setting was successful" - - // alternative: use DTR as Handshake: - //cc=CatSerial->setDataTerminalReady(false); // DTR out - // retval true means "setting was successful" - //qDebug()<<"RTS " <setDataTerminalReady(hsout); // DTR out - // retval true means "setting was successful" - //qDebug()<<"DTR " < -#include - -#include -#include -#include "tslib.h" -#include "shared_mem_buffer.h" - -// /////////////////////////////////////////////////////////////////////////////////// -// control serial interface gui <--> serial -// /////////////////////////////////////////////////////////////////////////////////// -void epi_setSerial(int BaudNr, - QString BaudStr, - QString ComName, - uint8_t connect) { - memset(&SharedMemBuffer::getData()->rs.comportName[0], 0x00, - sizeof(SharedMemBuffer::getData()->rs.comportName)); - strncpy(SharedMemBuffer::getData()->rs.comportName, - ComName.toStdString().c_str(), - sizeof(SharedMemBuffer::getData()->rs.comportName)-1); - - memset(&SharedMemBuffer::getData()->rs.baudStr[0], 0x00, - sizeof(SharedMemBuffer::getData()->rs.baudStr)); - strncpy(SharedMemBuffer::getData()->rs.baudStr, - BaudStr.toStdString().c_str(), - sizeof(SharedMemBuffer::getData()->rs.baudStr)-1); - - SharedMemBuffer::getData()->rs.baudNr = BaudNr; - SharedMemBuffer::getData()->rs.connect = connect; -} - -void epi_closeSerial(void) { - SharedMemBuffer::getData()->rs.connect = 0; -} - -void gpi_serialChanged(void) { - // serial confirms that port was closed or opened - // rs_connect=2; // Flanke, nur 1x öffnen/schließen - SharedMemBuffer::getData()->rs.connect = 2; -} - -uint8_t gpi_getSerialConn(void) { - return SharedMemBuffer::getDataConst()->rs.connect; -} - -int gpi_getBaudNr(void) { - return SharedMemBuffer::getDataConst()->rs.baudNr; -} - -QString gpi_getComPortName(void) { - return SharedMemBuffer::getDataConst()->rs.comportName; -} - -void gpi_serialIsOpen(bool offen) { - SharedMemBuffer::getData()->rs.portIsOpen = offen; -} - -bool epi_isSerialPortOpen() { - // true: port is open false: port is closed - return SharedMemBuffer::getDataConst()->rs.portIsOpen; -} - -// /////////////////////////////////////////////////////////////////////////////////// -// Control transfer gui <--> serial -// /////////////////////////////////////////////////////////////////////////////////// - -void epi_startEmmision(char start) { - SharedMemBuffer::getData()->AutoEmissionOn = start; -} - -bool gpi_isEmmisionOn(void) { - return SharedMemBuffer::getDataConst()->AutoEmissionOn; -} - -uint16_t gpi_getPeriodicSendTimeVal() { - SharedMemBuffer::getData()->datif.sendingPer_changed = 0; - if ((SharedMemBuffer::getDataConst()->datif.sendingPeriod < 3) || - (SharedMemBuffer::getDataConst()->datif.sendingPeriod > 10000)) { - return 130; // ms, default - } - return SharedMemBuffer::getDataConst()->datif.sendingPeriod; -} - -void epi_setPeriodicSendTimeVal(uint16_t val) { - if (val>=3 && val<10000) { - SharedMemBuffer::getData()->datif.sendingPer_changed = 1; - SharedMemBuffer::getData()->datif.sendingPeriod = val; - } -} - -bool gpi_PeriodicSendTimeHasChanged() { - return SharedMemBuffer::getDataConst()->datif.sendingPer_changed; -} - -// /////////////////////////////////////////////////////////////////////////////////// -// Status Display gui <--> serial -// /////////////////////////////////////////////////////////////////////////////////// - -// linke Spalte, über Connect Button -static QString txt4comStateLine; - -QString epi_getTxt4comStateLine(void) { - // GUI: get Text for serial Comport-State Line - return txt4comStateLine; -} - -void gpi_setTxt4comStateLine(QString txtline) { - // serial: write Text to be displayed in serial Comport-State line (like "connected") - txt4comStateLine.clear(); - if (txtline=="") - txt4comStateLine.clear(); - else - txt4comStateLine=txtline; -} - -void epi_clrTxt4comStateLine() { - txt4comStateLine.clear(); -} - -// rechte Spalte, oberste Statuszeile -// I) "Handshakes" (serial Control) flow.cpp -// geht überhaupt was raus? kommt überhaupt was zurück? -static QString txt4HsStateLine; - -QString epi_getTxt4HsStateLine(void) { - return txt4HsStateLine; -} - -void gpi_setTxt4HsStateLine(QString txtline) { - txt4HsStateLine.clear(); - if (txtline=="") - txt4HsStateLine.clear(); - else - txt4HsStateLine=txtline; -} - -void epi_clrTxt4HsStateLine() { - txt4HsStateLine.clear(); -} - -// II) Master receive state (empfangenes Telgramm OK? crc? length? ) -// Statuszeile Auswertung der SlaveResponse (serial Frame, CRC usw) (prot.cpp) -static QString txt4masterStateLine; - -QString epi_getTxt4masterStateLine(void) { - return txt4masterStateLine; -} - -void gpi_setTxt4masterStateLine(QString txtline) { - txt4masterStateLine.clear(); - if (txtline=="") - txt4masterStateLine.clear(); - else - txt4masterStateLine=txtline; -} - -void epi_clrTxt4masterStateLine() { - txt4masterStateLine.clear(); -} - -//--------------------------------------------------------------------------------------------- - -// III Slave receive (from Master) OK? if then show results, if not then show errors -// entweder Empfangsfehler anzeigen (crc? length?) oder result OUT-OK, OUT_ERR, IN_OK, IN_ERR -// Hintergrund: wenn der Slave Fehler im Master-Telegramm gefunden hat, dann kann er es auch -// nicht verwenden und nichts ausgeben oder einlesen - -static QString txt4resultStateLine; - -QString epi_getTxt4resultStateLine(void) { - return txt4resultStateLine; -} - -void gpi_setTxt4resultStateLine(QString txtline) { - txt4resultStateLine.clear(); - if (txtline=="") - txt4resultStateLine.clear(); - else - txt4resultStateLine=txtline; -} - -void epi_clrTxt4resultStateLine() { - txt4resultStateLine.clear(); -} - -//--------------------------------------------------------------------------------------------- - -// IV Statuszeile Empfangsdaten -static QString txt4dataLine; - -QString epi_getTxt4dataStateLine(void) { - // GUI: get Text for serial Comport-State Line - return txt4dataLine; - -} - -void gpi_setTxt4dataStateLine(QString txtline) { - // serial: write Text to be displayed in serial Comport-State line (like "connected") - txt4dataLine.clear(); - if (txtline=="") - txt4dataLine.clear(); - else - txt4dataLine=txtline; -} - -void epi_clrTxt4dataStateLine() { - txt4dataLine.clear(); -} - -//--------------------------------------------------------------------------------------------- - -// 5. Zeile: Datif Ergebnis, Daten brauchbar? - -static QString txt4datifReceive; - -QString epi_getTxt4datifLine(void) { - return txt4datifReceive; -} - -void gpi_setTxt4datifLine(QString txtline) { - txt4datifReceive.clear(); - if (txtline=="") - txt4datifReceive.clear(); - else - txt4datifReceive=txtline; -} - -void epi_clrTxt4datifLine() { - txt4datifReceive.clear(); -} - -//--------------------------------------------------------------------------------------------- -//--------------------------------------------------------------------------------------------- - -static QString txt4diagWindow; - -QString epi_getTxt4RsDiagWin(void) { - return txt4diagWindow; -} - -void gpi_setTxt4RsDiagWin(QString txtline) { - txt4diagWindow.clear(); - if (txtline=="") - txt4diagWindow.clear(); - else - txt4diagWindow=txtline; -} - -void epi_clrTxt4RsDiagWin() { - txt4diagWindow.clear(); -} - -//--------------------------------------------------------------------------------------------- - -static QString sndTxt4diagWindow; - -QString epi_get2ndTxt4RsDiagWin(void) { - return sndTxt4diagWindow; -} - -void gpi_set2ndTxt4RsDiagWin(QString txtline) { - sndTxt4diagWindow.clear(); - if (txtline=="") - sndTxt4diagWindow.clear(); - else - sndTxt4diagWindow=txtline; -} - -void epi_clr2ndTxt4RsDiagWin() { - sndTxt4diagWindow.clear(); -} - -// /////////////////////////////////////////////////////////////////////////////////// -// Memory for Slave responses, common data -// /////////////////////////////////////////////////////////////////////////////////// -void gpi_storeResult_serialTestOK(bool wasOk) { - SharedMemBuffer::getData()->Sdata.serialTestResult = wasOk; -} - -bool epi_getResult_serialTestOK() { - // retval: true: test was successful, got right response - return SharedMemBuffer::getDataConst()->Sdata.serialTestResult; -} - -// /////////////////////////////////////////////////////////////////////////////////// -// Store received data for hwapi -// /////////////////////////////////////////////////////////////////////////////////// -void gpi_startNewRequest() { - SharedMemBuffer::getData()->Sdata.pProtResultOk = 0; -} - -void gpi_storeResultOfLastRequest(bool answisok) { - SharedMemBuffer::getData()->Sdata.pProtResultOk = answisok ? 1 : 2; -} - -uint8_t epi_getResultOfLastRequest() { - // retval: 0: in progress 1: OK 2: error - return SharedMemBuffer::getDataConst()->Sdata.pProtResultOk; -} - -void gpi_storeRecPayLoad(uint8_t RdDlen, uint8_t const *receivedData) { - SharedMemBuffer::getData()->Sdata.receivedDataLength - = std::min(RdDlen, (uint8_t)(64)); - memset((char *)(&SharedMemBuffer::getData()->Sdata.receivedDataBlock[0]), - 0x00, sizeof(SharedMemBuffer::getData()->Sdata.receivedDataBlock)); - strncpy((char *)(&SharedMemBuffer::getData()->Sdata.receivedDataBlock[0]), - (char const *)receivedData, - sizeof(SharedMemBuffer::getData()->Sdata.receivedDataBlock)-1); -} - -uint16_t epi_getLastPayLoad(uint16_t plBufSiz, uint8_t *payLoad) { - // get data back in *pl, max 64 byte - // retval = nr of bytes received. If host buffer too small then - // only plBufSíz bytes are copied to pl - // plBufSíz=size of host buffer - - uint16_t ml = std::min(plBufSiz, (uint16_t)(64)); - if (SharedMemBuffer::getDataConst()->Sdata.receivedDataLength < ml) { - ml = SharedMemBuffer::getDataConst()->Sdata.receivedDataLength; - } - strncpy((char *)payLoad, - (char const *)(&SharedMemBuffer::getData()->Sdata.receivedDataBlock[0]), - ml); - - return SharedMemBuffer::getDataConst()->Sdata.receivedDataLength; -} diff --git a/DCPlugin/src/datIf.cpp b/DCPlugin/src/datIf.cpp deleted file mode 100644 index ddc9bc1..0000000 --- a/DCPlugin/src/datIf.cpp +++ /dev/null @@ -1,1812 +0,0 @@ -#include "datIf.h" -#include "sendWRcmd.h" -#include "controlBus.h" -#include "storeINdata.h" -#include - -// called from MainWindow() - - -#define DATIF_MAXCMDS 16 -static uint8_t dif_dataStep; -static uint8_t dif_scanStep, RDBLKNR; - - -static uint8_t datif_OutCmdpara1, datif_OutCmdpara2, datif_OutCmdpara3, datif_OutCmdpara4; -static uint16_t datif_OutCmdpara5; -static uint32_t datif_OutCmdpara6; -static uint8_t cycl_running; - -//static bool datif_DCdataValid; - -T_datif::T_datif(QWidget *parent) : QMainWindow(parent) -{ - - myDCIF = new T_prot(); - - // valid data was received, storing - connect(myDCIF, SIGNAL(framerecieved()), this, SLOT(StoredRecData())); - - // new, 9.11.20 data for DC-bootloader received not matchind Pprot - //connect(myDCIF, SIGNAL(rawDataRecieved()), this, SLOT(BLdataRecData())); - - // cyclic transmission of INPUT-Requests - datif_trigger = new QTimer(); - connect(datif_trigger, SIGNAL(timeout()), this, SLOT(datif_cycleSend())); - datif_trigger->setSingleShot(false); - datif_trigger->start(10); // in ms, 80 gut, default 100 50....200 - - // passing Signal through - //connect(myDCIF, SIGNAL(framerecieved()), this, SLOT( ResponseRecieved() )); - - datif_OutCmdpara1=0; - datif_OutCmdpara2=0; - datif_OutCmdpara3=0; - datif_OutCmdpara4=0; - dif_dataStep=1; - - dif_scanStep=0; - selectedSlaveAddr=FIX_SLAVE_ADDR; - cycl_running=0; - //datif_DCdataValid=0; - gpi_storeDcDataValid(0); -} - -void T_datif::resetChain(void) -{ - dif_scanStep=0; -} - -char T_datif::datif_cycleSend() -{ - // cyclic transmission of INPUT-Requests - // call cyclic to send next request every 100ms, then wait for response before sending again!!! - uint16_t nxtAsCmd; - uint8_t dataSendBuf[160], dataBufLen, dbl, who; - static uint8_t BlockCounter; - - uint8_t nextWrCmd, nextRdCmd, blockNum, dat1, dat2, dat3, dat4; - uint8_t length, data[66]; - bool b_ret; - - if (cycl_running) - { - // request is still running, wait for response before next sending - datif_trigger->stop(); - datif_trigger->start(10); - cycl_running++; - if (cycl_running>10) - cycl_running=0; - return 0; - } - if (myDCIF->isPortOpen()) - { - #ifdef USEHANDSHAKES - if (myDCIF->isSerialFree()) - #endif - { - // new, from 11.4.23: direkt access to fastDevice Interface - // always use this three functions to send data: - //void myDCIF->setUserWriteData(uint16_t WriteCmd, uint16_t WrAddr, uint8_t WrDatLen, uint8_t *data); - //void myDCIF->setUserWriteData(uint16_t WriteCmd, uint16_t WrAddr); - //void myDCIF->setUserWriteData(uint16_t WriteCmd); - //void myDCIF->setUserWrite1DB (uint16_t WriteCmd, uint16_t WrAddr, uint8_t val); - //void myDCIF->setUserWrite2DB (uint16_t WriteCmd, uint16_t WrAddr, uint8_t val0, uint8_t val1); - - //void myDCIF->setUserReadData( uint16_t ReadCmd, uint16_t RdAddr, uint16_t reserv); - //void myDCIF->setUserReadData( uint16_t ReadCmd, uint16_t RdAddr); - //void myDCIF->setUserReadData( uint16_t ReadCmd); - - //void myDCIF->sendUserData(uint16_t slaveAdr); - - if (check4FDshortCmd()) - { - b_ret=sendFDcmd_get(&nextWrCmd, &nextRdCmd, &blockNum, &dat1, &dat2, &dat3, &dat4); - if (b_ret) - { - data[0]=dat1; data[1]=dat2; data[2]=dat3; data[3]=dat4; data[4]=0; - myDCIF->setUserWriteData(nextWrCmd, blockNum, 4, data); - myDCIF->setUserReadData(nextRdCmd); - myDCIF->sendUserData(selectedSlaveAddr); - } - } - - if (check4FDlongCmd()) - { - b_ret=longFDcmd_get(&nextWrCmd, &nextRdCmd, &blockNum, &length, data); - if (b_ret) - { - myDCIF->setUserWriteData(nextWrCmd, blockNum, length, data); - myDCIF->setUserReadData(nextRdCmd); - myDCIF->sendUserData(selectedSlaveAddr); - } - } - - // direct commands have highest prio (setting OUTPUTS) - nxtAsCmd=sendWRcmd_getSendCommand0(); // command was stored by Gui - if (nxtAsCmd>0) - { - cycl_running=1; - // qDebug() << "datif: send next cmd0"; - sendWRcommand(nxtAsCmd); - send_requests(nxtAsCmd); - sendHighLevel(nxtAsCmd); - BlockCounter=0; - return 0; - } - - nxtAsCmd=sendWRcmd_getSendCommand4(&datif_OutCmdpara1, &datif_OutCmdpara2, &datif_OutCmdpara3, &datif_OutCmdpara4); - // command was stored by Gui - if (nxtAsCmd>0) - { - cycl_running=1; - //qDebug() << "datif: send next cmd4"; - sendWRcommand(nxtAsCmd); - send_requests(nxtAsCmd); - sendHighLevel(nxtAsCmd); - BlockCounter=0; - return 0; - } - - nxtAsCmd=sendWRcmd_getSendCommand8(&datif_OutCmdpara1, &datif_OutCmdpara2, &datif_OutCmdpara5, &datif_OutCmdpara6); - // command was stored by Gui - if (nxtAsCmd>0) - { - cycl_running=1; - //qDebug() << "datif: send next cmd8"; - sendWRcommand(nxtAsCmd); - send_requests(nxtAsCmd); - sendHighLevel(nxtAsCmd); - BlockCounter=0; - return 0; - } - - dbl=sendWRcmd_getSendBlock160(&dataBufLen, dataSendBuf); // used for bootloader - if (dbl>0) - { - cycl_running=1; - //qDebug() << "datif: sending 160 byte block, len: " << dataBufLen; - datif_OUT_SendRandomData(dataSendBuf, dataBufLen); - BlockCounter=0; - return 0; - } - - dbl=gpi_chk4remainingText(); - if (dbl>0) - { - cycl_running=1; - //qDebug() << "datif: sending printer text "; - gpi_restorePrnText(&dataSendBuf[0]); - // can hold 1280 byte, get next 64 - //for (uint8_t nn=0; nn<64; nn++) - // qDebug() << dataSendBuf[nn] << " "; - - - who=gpi_getUserOfSendingTextBuffer(&datif_OutCmdpara1, &datif_OutCmdpara2, &datif_OutCmdpara3, &datif_OutCmdpara4); - - if (who==1) - { - epi_store64ByteSendData(64, dataSendBuf); // "dueway", copy this 64 back to pi, used by datif_ send64byteOutCmd - datif_send64byteOutCmd(CMD2DC_PRI_PRINT_TXT, 0, 0); - } else - if (who==2) - { - epi_store64ByteSendData(64, dataSendBuf); // "dueway", copy this 64 back to pi, used by datif_ send64byteOutCmd - datif_send64byteOutCmd(CMD2DC_STOR_QR_DATA, 0, 0); - } else - if (who==3) - { - //qDebug() << "datif: sending printer text, docnr: " <11) - RDBLKNR=0; - datif_OutCmdpara1=RDBLKNR; - - } break; - - case 17: - //datif_sendIOrequest(0, CMD2DC_GetAllInputs, 0); - datif_sendIOrequest(0, 19, 0); - break; - - case 18: - if (indat_isMdbOn()) - datif_sendIOrequest(0, CMD2DC_MDB_GET_STATE, 0); // 107 - //else - // dif_scanStep=24; unsinn - break; - - case 19: - datif_sendIOrequest(0, 30, 0); - break; - - case 20: - //if (indat_isMdbOn()) - datif_sendIOrequest(0, CMD2DC_MDB_GETRESP, 0); // 22 - - break; - - case 21: - datif_sendIOrequest(0, CMD2DC_GetAllInputs, 0); - break; - - case 22: - //if (indat_isMdbOn()) // kein eigener Schalter für EMP - datif_sendIOrequest(0, CMD2DC_EMP_GET_ALL, 0); // 23 - break; - - case 23: - datif_sendIOrequest(0, 31, 0); - break; - - case 24: - //if (indat_isMdbOn()) // kein eigener Schalter für EMP - datif_sendIOrequest(0, CMD2DC_EMP_GOTCOIN, 0); // 108 - break; - - case 25: - datif_sendIOrequest(0, 32, 0); - break; - - case 26: - datif_sendIOrequest(0, 33, 0); - break; - - - } - - dif_scanStep++; - if (dif_scanStep>26) - dif_scanStep=5; - -return 0; - -} - - -char T_datif::isPortOpen(void) -{ - return (myDCIF->isPortOpen()); -} - - -// ############################################################################## -// ############################################################################## -// ############################################################################## -// Empfangsdaten einsortieren -// ---------------------------------------------------------------------------------------------- - - - -void T_datif::StoredRecData() -{ - //qDebug() << "StoreRecData called"; - // call automatically by T_prot - //if (myDCIF->ifDataReceived()) - //if (neu) - { - // just a wrapper as we need a retval - // "neu" is the same as "INdataValid" - loadRecDataFromFrame(); - } - cycl_running=0; -} - -char T_datif::loadRecDataFromFrame() -{ - // necessary data in T_prot: - uint16_t readSource, uitmp,uit2; - uint16_t readAddress; - //uint8_t pp; - uint8_t SlaveAdr, RdDleng; - uint8_t receivedData[FRAME_DATALEN]; - QString localStr; - uint32_t ultmp; - //int portNr; - bool ret; - uint8_t uctmp; // maxai - char ctmp; - static uint8_t lastResult; - uint8_t prnResult; - static uint32_t lastInsertedAmount; - uint32_t newInsertedAmount; - - ret=myDCIF->getReceivedInData(&SlaveAdr, &readSource, &readAddress, &RdDleng, receivedData); - // retval: data valid, only one time true, true if CommandState OK and readState OK - gpi_storeResultOfLastRequest(ret); - if (ret==false) - { - // qDebug() << "datif: rec data not valid"; - return 0; - } - - gpi_storeRecPayLoad(RdDleng, receivedData); // save for host (user of hwapi) - - //qDebug() << "\n datif: got valid data, rdsrc:" << readSource << " rdadd:" << readAddress - // << " rdlen:" << RdDleng; -// qDebug("datif_recData: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d ", -// receivedData[0], receivedData[1], receivedData[2], receivedData[3], -// receivedData[4], receivedData[5], receivedData[6], receivedData[7], -// receivedData[8], receivedData[9], receivedData[10], receivedData[11], -// receivedData[12], receivedData[13], receivedData[14], receivedData[15]); - - // readSource: reflects the READ Command if possible - // readAddress: reflects the requested read/write address if slave could perform - // lastWakeSrc: if Slave wakes master, this ist the reason for it (e.g. button pressed) - // RdDataLength: number of bytes in receivedData - - //firstDB=receivedData[0]; // just shorter, is used very often - //scndDB=receivedData[1]; - //thrdDB=receivedData[2]; - - localStr.clear(); - -// receivedData[0]='a'; -// receivedData[1]='B'; -// receivedData[2]='1'; -// receivedData[3]='-'; - - - for (int ii=0; ii>2)&3)); - uctmp=receivedData[1]; - gpi_storeDI_contactPowerIsOn(uctmp&0x10); - gpi_storeDI_optos((uctmp>>5)&3); - uctmp=receivedData[2]; - gpi_storeDI_auxIn(uctmp); - - uctmp=receivedData[3]; - gpi_storeDI_ptuWake(uctmp&1); - gpi_storeDI_readbackMdbTxD(uctmp&2); - gpi_storeDI_prnReady(uctmp&4); - gpi_storeDI_CoinAttach(uctmp&8); - gpi_storeDI_CoinEscrow(uctmp&16); - gpi_storeDI_mifareCardTapped(uctmp&32); - gpi_storeDI_rejMot_home(uctmp&64); - - uctmp=receivedData[4]; - //gpi_storeDI_modemWake(0); // gibt's gar nicht! - gpi_storeDI_mbdWake(uctmp&1); - gpi_storeDI_MifarePowerIsOn(uctmp&2); - gpi_storeDI_AuxPowerIsOn(uctmp&8); - gpi_storeDI_GsmPowerIsOn(uctmp&16); - gpi_storeDI_CreditPowerIsOn(uctmp&32); - gpi_storeDI_PrinterPowerIsOn(uctmp&64); - - //gpi_storeMdbState(uctmp&4, uctmp&128, uctmp&4); // hat ein eigenes Cmd weiter unten! - gpi_storeDI_MdbPowerIsOn(uctmp&128); - - gpi_storeDI_paperLow(receivedData[5]); - break; - - case CMD2DC_RdBkAllOutputs: //103 - - /* -// alle DO's in einen 8byte Puffer zusammenstellen, werden in einen Rutsch zum Master gesendet - - outBuf[0]: bit 0: TestMdbInput - 1: RS1 drv enabled - 2: RS1switch: 1=GSM 0=printer - 3: RS2switch: H: mifare L: credit - 4: Vbarcode=Vaux is on - - outBuf[1]: bit 0: coin led - 1: 0 - 2: paper led - 3: pinpad led - 4: start led - 5: service led - - outBuf[2]: bit 0: siren - 1: relay - 2: ptu wake - 3: shutter - 4: shutter test - 5: escrowGive - 6: escrowTake - 7: prn power - - outBuf[3]: Motor 1: 0:off 1=vorwärts / öffnen 2=rückw./zu 3: beide ein - outBuf[4]: Motor 2: 0:off 1=vorwärts / öffnen 2=rückw./zu 3: beide ein - */ - - uctmp=receivedData[0]; - gpi_storeDO_mdbRxTst(uctmp&1); - gpi_storeDO_auxPower(uctmp&0x10); - gpi_storeDO_serialSwitch((uctmp>>1)&7); // serial drv 0:on/off, 1:Serial mux1, 2:Serial mux2 - - uctmp=receivedData[1]; - gpi_storeDO_ledsAndFan(uctmp); - // bit0: coinled 1:front_illu 2: paper-led 3:pinpad-led 4:start-led 5:service-led 6:fan - - uctmp=receivedData[2]; - gpi_storeDO_sirenAndRelay(uctmp&3); // bit0: siren 1:relay - gpi_storeDO_ptuWake(uctmp&4); - - - gpi_storeDO_coinShutter(uctmp>>3); // bit0: Coin shutter output, bit1: input-test-output - gpi_storeDO_coinEscrow(uctmp>>5); // retval: 1:return flap is open 2:take flap is open 0:closed - gpi_storeDO_printerPwrOn(uctmp&0x80); - - uctmp=(receivedData[4] & 3); - uctmp<<=2; - if (receivedData[3] & 1) uctmp |=1; - if (receivedData[3] & 2) uctmp |=2; - gpi_storeDO_motorOutputs(uctmp); - // bit0: upper lock forw bit 1 backw bit2: lowLock forw bit3: LL backw - break; - - - case CMD2DC_RdBk_MifState: //109 - // get reader status and card type - - //gpi_storeMifReaderStateAndCardType(receivedData); - gpi_storeNewMifareCard(receivedData[0], &receivedData[1]); - - break; - - case CMD2DC_RdBk_MifData: //24 - // one block of data (64byte) comes in - // blkNr 0...11 in "Addr" - gpi_storeMifCardData(readAddress, receivedData); -//qDebug()<<"datif storing mif data: (adr/data) "<0: error - // bit0: paper low 1: no paper 2: temperature error - // 3: head open 4: paper jam in cutter - // 6: no response 7: bad response from printer - - gpi_storePrinterState(receivedData); // derzeit 10bytes ( 0x2A02) - break; - - case CMD2DC_RdBk_PrnFonts: // 26 - //D0: font table/type - //D1: size - //D2: height - //D3: width - //D4: bold - //D5: invers - //D6: underlined - //D7: density - //D8: speed - //D9: Alignment - gpi_storePrinterFonts(receivedData); // derzeit 10bytes - break; - - case CMD2DC_RdBk_AllPrnData: // 27 - gpi_storePrinterState(receivedData); // derzeit 10bytes ( 0x2A02) - gpi_storePrinterFonts(&receivedData[10]); // derzeit 10bytes - /* - qDebug()<<"printer fonts stored " <40) - //datif_DCdataValid=1; // das hier sind die wichtigsten Daten, deshalb hierrein! - gpi_storeDcDataValid(1); - - gpi_storeDynMachineConditions(RdDleng, receivedData); - - prnResult=receivedData[52]; - if (prnResult != lastResult) - { - // new result - if (prnResult==1) - { - emit datif_templatePrintFinished_OK(); - } else - if (prnResult==2) - { - emit datif_templatePrintFinished_Err(); - } - - lastResult=prnResult; - } - - break; - - case 32: // Get current cash level (in vault) - // bytes 0..3: amount bytes 4,5=Nr.ofCoins in vault - ultmp=uchar2ulong(receivedData[3],receivedData[2],receivedData[1],receivedData[0]); - uitmp=uchar2uint(receivedData[5],receivedData[4]); - gpi_storeCBlevel(ultmp, uitmp); - break; - - case 33: // Get all backuped acc. Numbers - // 8 UINTs with acc-nr - gpi_storeDCbackupAccNr(RdDleng, receivedData); - break; - - case 38: // Get stored account record backup -/* - -struct T_vaultRecord -{ - UCHAR startbuffer[4]; // Psa> // never move or change this 1st entry - UINT AccountingNumber; - UINT CUNU; - UINT MANU; - UINT resint1; - //UINT resint2; - - UCHAR label1buffer[4]; // tim> - UCHAR year; - UCHAR month; - UCHAR dom; - UCHAR hour; - UCHAR min; - UCHAR sec; - UCHAR DoW; - UCHAR reschar3; - - UCHAR label2buffer[4]; // abs> - ULONG AbsIncome1; - ULONG AbsReserve; - ULONG AbsNrOfCuts; - -//16 - UCHAR label3buffer[4]; // mw > - - // Verkauf, Tür zu: - ULONG VKcoinsInserted[16]; // nur für Wechsler, soviel wurde eingeworfen - ULONG VKcoinsReturned[6]; // nur für Wechsler, Anzahl Münzen pro Typ, soviel wurde zurückgegeben -//88 - - // Service, Tür offen: - UINT ServCoinsInserted[16]; // nur für Wechsler, soviel wurde eingeworfen - UINT ServCoinsReturned[6]; // nur für Wechsler, Anzahl Münzen pro Typ, soviel wurde zurückgegeben - UINT resint3; - UINT resint4; - UINT currentTubeContent[6]; // nur für Wechsler, aktueller Füllstand - UINT resint5; - UINT resint6; -// 56 - - UCHAR label4buffer[4]; // box> - UINT coinsInVault[16]; - UINT billsInStacker[8]; -// 48 - - UCHAR label5buffer[4]; // val> - // actually constant unless exchange rate is changed - UINT coinDenomination[16]; // 5..50000 (z.B. 2€ sind in Ungarn 760Ft) - UINT billDenom[8]; - UINT tubeDenom[6]; - UINT exchangeRate; - UINT resint9; - -// 64 - - UCHAR endofblock[4]; // end> -// 316 byte Block im Speicher -*/ - // readAddress, &RdDleng, receivedData - gpi_storeVaultRecord(readAddress, receivedData ); // always 64byte - break; - - } - - return 0; -} - -// fehlen: 112, 113,14,17, 19, 30,31,32,33, - -// subs: - -// ---------------------------------------------------------------------------------------------- -// erstelle WRITE Datensätze -// ---------------------------------------------------------------------------------------------- - -// always use this three functions to send data: -//void myDCIF->setUserWriteData(uint16_t WriteCmd, uint16_t WrAddr, uint8_t WrDatLen, uint8_t *data); -//void myDCIF->setUserWriteData(uint16_t WriteCmd, uint16_t WrAddr); -//void myDCIF->setUserWriteData(uint16_t WriteCmd); -//void myDCIF->setUserWrite1DB (uint16_t WriteCmd, uint16_t WrAddr, uint8_t val); -//void myDCIF->setUserWrite2DB (uint16_t WriteCmd, uint16_t WrAddr, uint8_t val0, uint8_t val1); - -//void myDCIF->setUserReadData( uint16_t ReadCmd, uint16_t RdAddr, uint16_t reserv); -//void myDCIF->setUserReadData( uint16_t ReadCmd, uint16_t RdAddr); -//void myDCIF->setUserReadData( uint16_t ReadCmd); - -//void myDCIF->sendUserData(uint16_t slaveAdr); - -void T_datif::datif_startSending(void) -{ - // egal ob WR und RD Daten gesetzt wurden - myDCIF->sendUserData(selectedSlaveAddr); // starte Sendung - gpi_startNewRequest(); - cycl_running=1; - -} - -// allgemeine Schreib/Lese-Funktion -void T_datif::datif_sendIOrequest(uint16_t WRcmd, uint16_t RDcmd, uint8_t nrOfWrData) -{ - uint8_t data[6]; - - if (nrOfWrData>4) nrOfWrData=0; - tslib_strclr(data,0,6); - - if (nrOfWrData>0) - data[0]=datif_OutCmdpara1; - if (nrOfWrData>1) - data[1]=datif_OutCmdpara2; - if (nrOfWrData>2) - data[2]=datif_OutCmdpara3; - if (nrOfWrData>3) - data[3]=datif_OutCmdpara4; - data[4]=0; data[5]=0; - - myDCIF->setUserWriteData(WRcmd, 0, nrOfWrData, data); - myDCIF->setUserReadData(RDcmd); - myDCIF->sendUserData(selectedSlaveAddr); - cycl_running=1; - -} - -void T_datif::datif_send8byteOutCmd(uint16_t WRcmd, uint16_t RDcmd) -{ - uint8_t data[10]; - uint16_t uitmp; - uint32_t ultmp; - - tslib_strclr(data,0,10); // 8 used - - data[0]=datif_OutCmdpara1; - data[1]=datif_OutCmdpara2; - uitmp=datif_OutCmdpara5; - ultmp=datif_OutCmdpara6; - - data[2]=uint8_t(uitmp); - uitmp>>=8; - data[3]=uint8_t(uitmp); - - data[4]=uint8_t(ultmp); - ultmp>>=8; - data[5]=uint8_t(ultmp); - ultmp>>=8; - data[6]=uint8_t(ultmp); - ultmp>>=8; - data[7]=uint8_t(ultmp); - - data[8]=0; data[9]=0; - - myDCIF->setUserWriteData(WRcmd, 0, 8, data); - myDCIF->setUserReadData(RDcmd); - myDCIF->sendUserData(selectedSlaveAddr); - cycl_running=1; - -} - - -bool T_datif::verifyLineTestresponse(uint8_t RdDlen, uint8_t *receivedData) -{ - if (RdDlen < 16) - return false; - QString myStr; - char ctmp; - - myStr.clear(); - myStr.append("< Slave Response"); - - for (int nn=0; nn<16; nn++) - { - ctmp=receivedData[nn]; - if (myStr[nn] != ctmp) - { - //qDebug() << " datif cmd 10: got wrong string "; - //qDebug() << myStr; - //qDebug() << receivedData; - //qDebug() << nn; - return false; - } - } - return true; -} - - -// RTC ---------------------------------------------------------------------- - -void T_datif::datif_OUT_setTime(void) -{ - // send PC time/date to slave - //uint8_t hour,min, sec, year, month, day, dayOfWeek, - //uint8_t dayOfYear, isLeap, weekOfYear; - uint8_t buff[15]; - uint16_t uitmp; - - QTime *systTime = new QTime(); - // qDebug() << systTime->currentTime().hour() <<":" - // << systTime->currentTime().minute() <<":" - // << systTime->currentTime().second(); - - buff[0]=uint8_t(systTime->currentTime().hour()); - buff[1]=uint8_t(systTime->currentTime().minute()); - buff[2]=uint8_t(systTime->currentTime().second()); - - - QDate *systDate = new QDate(); - systDate->currentDate(); - - uitmp= uint16_t(systDate->currentDate().year()); - buff[3]=uint8_t(uitmp); - buff[4]=uint8_t(uitmp>>8); - - buff[5]=uint8_t(systDate->currentDate().month()); - buff[6]=uint8_t(systDate->currentDate().day()); - buff[7]=uint8_t(systDate->currentDate().dayOfWeek()); - -// uitmp=systDate->currentDate().dayOfYear(); -// buff[8]=uint8_t(uitmp); -// buff[9]=uint8_t(uitmp>>8); - -// buff[10]=uint8_t(systDate->currentDate().isLeapYear(systDate->currentDate().year())); -// buff[11]=uint8_t(systDate->currentDate().weekNumber()); //weekOfYear -// buff[12]=0; - - //myDCIF->setUserWriteData(0x1310,0,8, buff); - myDCIF->setUserWriteData(CMD2DC_sendTime,0,8, buff); - myDCIF->setUserReadData(0); - myDCIF->sendUserData(selectedSlaveAddr); // jetzt wegsckicken - cycl_running=1; - -} - -// 0x2311: set time to RTC -// 0x2312: set date to RTC - -uint8_t T_datif::datif_OUT_SendRandomData(uint8_t *buf, uint8_t Length) -{ - uint8_t len=Length; - - myDCIF->setBLsendData(len, buf ); - myDCIF->setUserReadData(0); - myDCIF->sendUserData(selectedSlaveAddr); - cycl_running=1; - - return 0; - -} - - - - -void T_datif::datif_send64byteOutCmd(uint16_t WRcmd, uint16_t addr, uint16_t RDcmd) -{ - // sending length is already defined by stored data - // not batched! don't use twice within 100ms - uint8_t LL; - uint8_t data[66]; - - tslib_strclr(data,0,66); // up to 64 used - gpi_restore64ByteSendData(&LL, data); // LL bytes was stored to be sent - myDCIF->setUserWriteData(WRcmd, addr, LL, data); - myDCIF->setUserReadData(RDcmd); - myDCIF->sendUserData(selectedSlaveAddr); - cycl_running=1; - -} - -void T_datif::datif_sendToMemory(uint16_t WRcmd, uint16_t docNr, uint16_t blockNr, uint8_t *data64) -{ - // send printer documents to DC2 memory - // docNr: 0...15(31) with 1280 byte each (20 blocks a 64byte) - // blockNr=0...19 with 64byte each - // docNr =transmitted in WRITEADDRESS high byte - // blockNr=transmitted in WRITEADDRESS low byte - - uint16_t aa=0; - - aa=docNr; - aa<<=8; - aa |=blockNr; - myDCIF->setUserWriteData(WRcmd, aa, 64, data64); - myDCIF->setUserReadData(0); - myDCIF->sendUserData(selectedSlaveAddr); - cycl_running=1; - -} - - - diff --git a/DCPlugin/src/dcBL.cpp b/DCPlugin/src/dcBL.cpp deleted file mode 100644 index 0d114f7..0000000 --- a/DCPlugin/src/dcBL.cpp +++ /dev/null @@ -1,1461 +0,0 @@ -//#include -#include "dcBL.h" -#include -//#include "tabFw.h" -#include "sendWRcmd.h" - - -// File sits "behind" the HWapi and in front of "PI", so all necessary Bootloader functions can be called from HWapi - - - -uint16_t ucharTOuint(uint8_t Highbyte, uint8_t Lowbyte) -{ - uint16_t uitmp; - uitmp=0; - uitmp |= uint8_t(Highbyte); - uitmp<<=8; - uitmp |= uint8_t(Lowbyte); - return uitmp; -} - -#define GETLOWBYTE 0 -#define GETHIGHBYTE 1 - -uint8_t uintTOuchar(uint16_t uival, uint8_t getHighB) -{ - // getHighB: low=GetLowByte - uint16_t uitmp=uival; - if (getHighB==0) - return uint8_t(uitmp); - uitmp>>=8; - return uint8_t(uitmp); - -} - -//#define GETLOWBYTE 0 -//#define GETHIGHBYTE 1 -#define GETMIDLOWBYTE 2 -#define GETMIDHIGHBYTE 3 - -uint8_t ulongTOuchar(uint32_t ulval, uint8_t whichByte) -{ - - uint32_t ultmp=ulval; - if (whichByte==GETLOWBYTE) - return uint8_t(ultmp); - ultmp>>=8; - if (whichByte==GETMIDLOWBYTE) - return uint8_t(ultmp); - ultmp>>=8; - if (whichByte==GETMIDHIGHBYTE) - return uint8_t(ultmp); - ultmp>>=8; - if (whichByte==GETHIGHBYTE) - return uint8_t(ultmp); - return 0; -} - -void strclr(uint8_t *buf, uint8_t clrsign, uint8_t len) -{ - uint16_t nn; - - for (nn=0; nn> (7 - nn)) & 0x01); - if (B15H) - { - crc ^= 0x1021; - } - } - } - - for (nn = 0; nn < 16; nn++) - { - B15H = 0; - if(crc & 0x8000) - B15H = 1; - crc = (crc << 1) | 0x00; - if (B15H) - { - crc ^= 0x1021; - } - } - return crc; - -} - - -#define SEND_STX 2 -#define SEND_ETX 3 -#define SEND_ESC 0x1B - -static uint8_t dcBL_LastBLcmd; // stored the last sent cmd in order to analys response - // cmd echo'ed: error cmd or'ed with 0x80: OK - -uint8_t dcBL_prepareDC_BLcmd(uint8_t Cmd, uint8_t SendDataLength, uint8_t *sendData, uint8_t *outBuf) -{ - // make BL protocol, retval = outbuf length (5...133) - // bring data in correct form: start always with 0x02 finish with 0x03 and append checksum - // 0x02 Cmd < ...sendData ..> CRC CRC 0x03 - // Data length = 0...64 - // special conversion: if data contain 2 or 3 (STX, ETX) then write two bytes: 0x1B (=ESC) and data|0x80 - // so maxlength = 5 + 2 x 64 (if all data are 2 or 3) without 2,3: maxlength = 5 + 64 - - // 26.01.2021: noch einen Fehler gefunden: die "special conversion" fehlt bei der angehaengten Checksumme!!! - - uint8_t myBuf[140], pp=0, HB, LB; - uint8_t crcBuf[140], mm=0; - uint8_t nn, uctmp, currLen=0; - uint16_t calcCrc; - - strclr(myBuf, 0, 140); - strclr(crcBuf, 0, 140); // extra Puffer because STX must not be caculated - - myBuf[pp++]=SEND_STX; - myBuf[pp++]=Cmd; - crcBuf[mm++]=Cmd; - dcBL_LastBLcmd=Cmd; - - // append data: - for (nn=0; nn0 && recLen<150) - { - epi_getRawReceivedData(respBuff); - epi_clrRawReceivedString(); - dcBL_writeText("dcBL gotResponse"); - - if (display) - { -/* - // Antwort ins Fenster schreiben: - QString tmpStr="", myStr="~~> "; - - tmpStr.setNum(recLen); - myStr.append(tmpStr); - myStr.append(" bytes received: "); - for (int nn=0; nn block wiederholen. In den anderen Fällen NICHT wiederholen - // sonst ist der block doppelt im Flash!!!!!!!! - if (recLen>0 && recLen<5) - { - dcBL_writeText("error wrong length"); - //exactError=1; -qDebug()<<" DCBL_chkResp wrong length "; - return 10; // OK - } - if (buf[0] !=2) - { - dcBL_writeText("error wrong start"); - //exactError=2; -qDebug()<<" DCBL_chkResp wrong start "; - return 10; // OK - } - if (buf[0]==2 && buf[1]=='e' && buf[2]=='0' ) - { - dcBL_writeText("error wrong crc"); - //exactError=3; // DC reports wrong crc -qDebug()<<" DCBL_chkResp wrong crc"; - return 1; // error - } - if (buf[0]==2 && buf[1]==dcBL_LastBLcmd ) - { - dcBL_writeText("error wrong cmd"); - //exactError=4; // wrong cmd -qDebug()<<" DCBL_chkResp wrong cmd"; - return 10; // OK - } - //tmpStr.clear(); - //tmpStr.setNum(exactError); - //dcBL_writeText(tmpStr); - return 1; // error -} - - - -uint8_t dcBL_sendSuccess(uint8_t lastCommand) -{ - // return val: 0: no response by now 1:error 10: OK - - uint8_t buf[152], recLen; - - recLen=dcBL_getResponse(buf,0); - if (recLen==0) - return 0; // no response by now - - if (buf[0]==2 && buf[1]==(lastCommand | 0x80) ) - return 10; // OK - return 1; -} - -// ----------------------------------------------------------------------------------------------- -// --- ATB Bin-File Handling --------------------------------------------------------------------- -// ----------------------------------------------------------------------------------------------- - -/* example read file from HDD: - uint8_t uit8tmp; - QString stemp=" "; - - QFile file("/own/H2B/dc2.bin"); - //QFile file("/own/H2B/dc2.hex"); // laesst sich genauso oeffnen - - // TODO: use File-Open-Dialog-Box - - if (!file.exists()) - { - qDebug()<<"file not exists"; - } else - { - if (!file.open(QIODevice::ReadOnly) ) - { - qDebug()<<"cannot open"; - } else - { - qDebug()<<"loading...."; - qDebug()<<"size: " << file.size() <<"\n"; - QByteArray myBin = file.readAll(); - - // Kontrolle: - int ii=0; - do - { - uit8tmp=(uint8_t)myBin[ii++]; - //qDebug() << uit8tmp << " "; // Anzeige in dez - stemp.setNum(uit8tmp,16); - qDebug() << stemp << " "; // Anzeige in hex - - } while (ii<100); - } - } - - */ - - -// ------------------------------------------------------------------------- - -char dcBL_loadBinary(char withDisplay) -{ - // same function as in "tabFw" - //uint8_t uit8tmp; - uint32_t ultmp, fileLen; - QString tmpStr="", s2tmp=""; - - qDebug()<<"dcBL loading DC2c binary..."; - QFile file("../dc2c4.bin"); - if (!file.exists()) - { - //qDebug()<<"file _own_H2B_dc2.bin does not exist"; - dcBL_writeText("file _own_H2B_dc2.bin does not exist"); - return 1; - } - if (!file.open(QIODevice::ReadOnly) ) - { - //qDebug()<<"cannot open"; - dcBL_writeText("cannot open"); - return 1; - } - - //qDebug()<<"loading...."; - //qDebug()<<"size: " << file.size() <<"\n"; - if (withDisplay) - { - s2tmp="loading file with "; - tmpStr.setNum(file.size()); - s2tmp.append(tmpStr); - s2tmp.append(" bytes"); - dcBL_writeText(s2tmp); - } - QByteArray myBin = file.readAll(); - fileLen=uint32_t(file.size()); - - // Rest des Blockes mit 0xFF füllen - for (ultmp=fileLen; ultmp<(fileLen+70); ultmp++) - myBin[ultmp]=char(0xFF); - - /* // Kontrolle: - qDebug()<<"dcBL_loadBinary: "; - int ii=59500; - do - { - uit8tmp=uint8_t(myBin[ii++]); - s2tmp.clear(); - //qDebug() << uit8tmp << " "; // Anzeige in dez - s2tmp.setNum(uit8tmp,16); - qDebug() << s2tmp << " "; // Anzeige in hex - - } while (ii<60100); - */ - - dcBL_importBinFile(myBin, fileLen, withDisplay); - return 0; - -} - - -static QByteArray dcBL_AtbBinFile; -static uint32_t dcBL_fileSize; -static uint16_t dcBL_nrOfBlocks; -static uint16_t dcBL_fileCrc; -//static uint8_t dcBL_myBuf[2570000]; // same content like "dcBL_AtbBinFile" but bytewise -static uint8_t dcBL_myBuf[300000]; // same content like "dcBL_AtbBinFile" but bytewise - -bool dcBL_importBinFile(QByteArray readBinFile, uint32_t fileSize, char withDispl) -{ - uint16_t uitmp; - uint32_t ultmp; - uint32_t LL; - QString tmpStr="", s2tmp=""; - - dcBL_AtbBinFile=readBinFile; - dcBL_fileSize=fileSize; - - //if (dcBL_fileSize>258048) // 27.3.23TS woher kommt die Zahl??? - // das hex file hat 278kB - // hex file nicht erlaubt??? - if (dcBL_fileSize>=300000) - return false; // keep last file - ultmp=dcBL_fileSize; - ultmp %=64; - uitmp=uint16_t(ultmp); - ultmp=dcBL_fileSize; - ultmp /=64; - dcBL_nrOfBlocks=uint16_t(ultmp); - if (uitmp>0) - dcBL_nrOfBlocks++; // letzter Block hat !=64 byte - - // type conversion for crc calc - for (LL=0; LLalso sicherstellen dass das Laden des Binfiles 100%ig in Ordnung ist. - QByteArray BINFILECOPY1, BINFILECOPY2, BINFILECOPY3; - uint32_t BinFileCpyLen1, BinFileCpyLen2, BinFileCpyLen3, LL; - uint8_t repeat=0, nn=0, stopp=0; - //char cc; - - do - { - //dcBL_writeText("loading 1st time:"); - //qDebug() <<"loading 1st time:"; - dcBL_loadBinary(0); - // file jetzt in: "QByteArray dcBL_AtbBinFile" mit Laenge "uint32_t dcBL_fileSize" - BINFILECOPY1=dcBL_AtbBinFile; - BinFileCpyLen1=dcBL_fileSize; - - //dcBL_writeText("loading 2nd time:"); - //qDebug() <<"loading 2. time:"; - dcBL_loadBinary(0); - // file jetzt in: "QByteArray dcBL_AtbBinFile" mit Laenge "uint32_t dcBL_fileSize" - BINFILECOPY2=dcBL_AtbBinFile; - BinFileCpyLen2=dcBL_fileSize; - - //dcBL_writeText("loading 3rd time:"); - //qDebug() <<"loading 3. time:"; - dcBL_loadBinary(0); - // file jetzt in: "QByteArray dcBL_AtbBinFile" mit Laenge "uint32_t dcBL_fileSize" - BINFILECOPY3=dcBL_AtbBinFile; - BinFileCpyLen3=dcBL_fileSize; - -//cc=BINFILECOPY2[100]; -//if (cc>0) -// BINFILECOPY2[100]=0; -//else -// BINFILECOPY2[100]=1; - - repeat=0; - if (BinFileCpyLen1 !=BinFileCpyLen2 || BinFileCpyLen1 !=BinFileCpyLen3) - { - dcBL_writeText("file length wrong"); - qDebug() <<"length error"; - - repeat=1; // load both again.... - } - if (repeat==0) - { - LL=0; stopp=0; - //qDebug() <<"1. loop"; - - do - { - if (dcBL_AtbBinFile[LL] != BINFILECOPY1[LL]) - stopp=1; - } while((++LL < dcBL_fileSize) && !stopp); - - if (stopp) - { - dcBL_writeText("file compare1 wrong "); - repeat=1; // load both again.... - } - } - - if (repeat==0) - { - LL=0; stopp=0; - //qDebug() <<"2. loop"; - do - { - if (dcBL_AtbBinFile[LL] != BINFILECOPY2[LL]) - stopp=1; - } while((++LL < dcBL_fileSize) && !stopp); - - if (stopp) - { - dcBL_writeText("file compare2 wrong "); - repeat=1; // load both again.... - } else - dcBL_writeText("file OK"); - } - - } while (++nn<3 && repeat); // 3 trials - - qDebug() << "compare finito " << nn << " " << repeat; - - if (repeat==0) - return true; // file OK - return false; // error, could not load correctly - -} - - - - -uint8_t dcBL_getAtbFileHeader(uint8_t *buf) -{ - // this header is prepended by the pc-direct-loader-tool - // (so the uC-BL expects this!) here it is sent seperately: - uint8_t myBuf[30], pp=0, len; - - myBuf[pp++]='A'; - myBuf[pp++]='T'; - myBuf[pp++]='B'; - myBuf[pp++]='-'; - myBuf[pp++]='D'; - myBuf[pp++]='C'; - myBuf[pp++]='2'; - myBuf[pp++]='-'; - myBuf[pp++]=ulongTOuchar(dcBL_fileSize, GETHIGHBYTE); - myBuf[pp++]=ulongTOuchar(dcBL_fileSize, GETMIDHIGHBYTE); - myBuf[pp++]=ulongTOuchar(dcBL_fileSize, GETMIDLOWBYTE); - myBuf[pp++]=ulongTOuchar(dcBL_fileSize, GETLOWBYTE); - myBuf[pp++]='-'; - myBuf[pp++]=uintTOuchar(dcBL_fileCrc, GETHIGHBYTE); - myBuf[pp++]=uintTOuchar(dcBL_fileCrc, GETLOWBYTE); - myBuf[pp++]='-'; - len=pp; - //tslib_strcpy(myBuf, buf, (len+3)); - len=dcBL_prepareDC_BLcmd(0x32, len, myBuf, buf); - return len; -} - -uint8_t dcBL_getFileBlock(uint16_t blockPointer, uint8_t *buf) -{ - // blockPointer=0....4095 - uint32_t addr, LL; //, BL; - //uint8_t uit8tmp; - //QString stemp=" "; - - addr=uint32_t(blockPointer); - addr<<=6; // *64 =Start address -/* - if ( (addr+63)>dcBL_fileSize) - { - BL=dcBL_fileSize-addr+1; // Block Length - for (LL=0; LL<64; LL++) - buf[LL]=0; - if (BL>64) BL=64; // security limitation - // only BL bytes are left to give - for (LL=0; LL0) - return true; - return false; -} - -QString dcBL_readText(void) -{ - // read from 0...9 (oldest first) - if (pBlResp<=0) // should never be <0 - return ""; - QString locStr=BlResp[1]; // store memory[1] - - // move memories down by one: 2->1 3->2 4>3....9->8. Place 1 is free now - // example: if pBlResp==3 then we have still text 2 and 3 to display. 1 will be transfered now with this call - int nn; - for (nn=1; nn0) pBlResp--; - return locStr; -} - - - -// ------------------------------------------------------------------------- - - -static uint8_t dcBL_step, dcBL_state; -static uint16_t dcBL_BlkCtr, dcBL_cyclCtr, repeatCtr; - -void dcBL_iniChain(void) -{ - int nn; - dcBL_step=0; - dcBL_cyclCtr=0; - dcBL_state=0; - dcBL_BlkCtr=0; - repeatCtr=0; - - // delete output window: - pBlResp=0; - for (nn=0;nn17) - { - dcBL_iniChain(); - dcBL_step=1; - //epi_clrRawReceivedString(); - qDebug()<<"starting chain..."; - //qDebug()<6 && recBuff[0]==2 && recBuff[1]==99 && recBuff[2]==52) - // && recBuff[3]==53 && recBuff[4]==98 && recBuff[5]==51 && recBuff[6]==3 ) - { - dcBL_writeText("BL started"); - dcBL_cyclCtr=0; - dcBL_step++; - return 0; - } - //qDebug()<10) // 50 gibt 6,2s - { - // cancel, report error - dcBL_writeText("cannot start BL, cancel"); - dcBL_state=3; - dcBL_step=0; // stop chain - return 0; - } */ - - dcBL_step++; - repeatCtr=0; - break; - - case 6: // request Version number - len=dcBL_readFWversion(buf); - sendWRcmd_setSendBlock160(len, buf); - dcBL_writeText("request version nr..."); - dcBL_cyclCtr=0; - dcBL_step++; - break; - - case 7: // wait for answer 2 146 45 45 95 176 3 - - if (gotResp==ISOK) - { - dcBL_state=1; // BL started - dcBL_step++; - repeatCtr=0; - return 0; - } else - if (gotResp==ISWRONG) - { - if (++repeatCtr<3) - { - dcBL_step--; - }else - { - dcBL_step=0; // stop chain - } - } - - if (++dcBL_cyclCtr>10) - { - dcBL_writeText("cancel"); - dcBL_step=0; // stop chain - } - break; - - case 8: // send start address - if (dcBL_BlkCtr==0 || dcBL_BlkCtr==1024 || dcBL_BlkCtr==2048 || dcBL_BlkCtr==3072 || dcBL_BlkCtr==4096) - { - ultmp=uint32_t(dcBL_BlkCtr); - ultmp*=64; - len=dcBL_sendFlashStartAddr2BL(ultmp, buf); - sendWRcmd_setSendBlock160(len, buf); - dcBL_writeText("sending start address"); - dcBL_cyclCtr=0; - dcBL_step++; - return 0; - } else - dcBL_step=12; - break; - - case 9: // wait for answer 2 161 68 59 3 - if (gotResp==ISOK) - { - dcBL_step=12; // Header nicht senden, unnötig - dcBL_BlkCtr=0; // 0 - repeatCtr=0; - return 0; - } else - if (gotResp==ISWRONG) - { - if (++repeatCtr<3) - { - dcBL_step--; - } else - { - dcBL_step=0; // stop chain - } - } - if (++dcBL_cyclCtr>10) - { - dcBL_writeText("cancel"); - dcBL_step=0; // stop chain - } - break; - - - case 12: // send binary 64 byte wise - - len=dcBL_getFileBlock(dcBL_BlkCtr, buf); // read from file, len = 0...64 - //lastBlkLength=len; // recognize last block or end - sendLen=dcBL_prepareDC_BLcmd(0x22, len, buf, sendBuf); // pack into protocol frame - - - // Kontrolle: - qDebug()<<"dcBL sending: "; - ii=0; - do - { - uit8tmp=(uint8_t)sendBuf[ii++]; - //qDebug() << uit8tmp << " "; // Anzeige in dez - stemp.setNum(uit8tmp,16); - qDebug() << stemp << " "; // Anzeige in hex - - } while (ii<100); - - - sendWRcmd_setSendBlock160(sendLen, sendBuf); // send 140 bytes - delay(100); - //dcBL_writeText("blk nr: "); - tmpStr.setNum(dcBL_BlkCtr); - dcBL_writeText(tmpStr); - delay(100); - //qDebug()<<"sending: " << buf; - dcBL_cyclCtr=0; - dcBL_BlkCtr++; - dcBL_step++; - break; - - case 13: // wait for answer 2 162 116 88 3 - - if (gotResp==ISOK) - { - // check if next address is needed (every 1024Blocks = 65536bytes) - if (dcBL_BlkCtr==1024 || dcBL_BlkCtr==2048 || dcBL_BlkCtr==3072 || dcBL_BlkCtr==4096) - { - dcBL_step=8; - return 0; - } - - // check for EOF: - if (dcBL_BlkCtr >= dcBL_nrOfBlocks) - { - dcBL_writeText("last block successful sent..."); - dcBL_step++; // stop chain - dcBL_state=3; // transmission SUCCESSFUL - return 0; - } - dcBL_state=2; // transmission started - dcBL_step--; // send next data block - repeatCtr=0; - return 0; - } - if (gotResp==ISWRONG) - { - if (++repeatCtr<3) - { - dcBL_writeText("error"); - dcBL_BlkCtr--; - dcBL_step--; // send same block again - } else - { - dcBL_step=0; // stop chain - } - } - if (++dcBL_cyclCtr>30) // longer TO due to flashing - { - dcBL_writeText("cancel"); - dcBL_step=0; // stop chain - } - break; - - case 14: // - dcBL_writeText("finish writing flash"); - len=dcBL_writeLastPage(buf); // nur zur Sicherheit - sendWRcmd_setSendBlock160(len, buf); - dcBL_step++; - break; - - case 15: // wait for answer - if (gotResp==ISOK) - { - dcBL_step++; - repeatCtr=0; - return 0; - } else - if (gotResp==ISWRONG) - { - if (++repeatCtr>3) - { - dcBL_step--; - } - } - if (++dcBL_cyclCtr>10) - { - dcBL_writeText("cancel"); - dcBL_step=0; // stop chain - } - break; - - - case 16: // - dcBL_writeText("exit BL, bye"); - len=dcBL_exitBL(buf); - sendWRcmd_setSendBlock160(len, buf); - dcBL_step++; - - break; - - case 17: // wait for answer, not sure if it comes! - if (gotResp==ISOK) - { - dcBL_step++; - repeatCtr=0; - return 0; - } else - if (gotResp==ISWRONG) - { - if (++repeatCtr>10) - { - dcBL_step--; - } - } - if (++dcBL_cyclCtr>30) - { - dcBL_writeText("cancel"); - dcBL_step=0; // stop chain - } - break; - - case 18: - dcBL_step=0; - break; - } - - return 0; -} - - - -void dcBL_iniLoading(void) -{ - dcBL_iniChain(); -} - - -// nicht verwendet -void dcBL_startLoading(void) -{ - if (dcBL_step==0 || dcBL_step>17) - { - //dcBL_iniChain(); - dcBL_step=1; - //epi_clrRawReceivedString(); - qDebug()<<"DCBL start sending hexfile..."; - dcBL_writeText("DCBL start sending hexfile..."); - dcBL_BlkCtr=0; - dcBL_cyclCtr=0; - } - -} - - -// nicht verwendet -uint8_t dcBL_sendHexfile(void) -{ - QString tmpStr=""; - uint8_t buf[70], sendBuf[160], len, sendLen, gotResp; //, recLen; recBuff[160], ii, - QString stemp=" "; - uint32_t ultmp; - //uint8_t uit8tmp, ii; - - - gotResp=dcBL_ChkResponse(); - - switch (dcBL_step) - { - case 1: // send start address - if (dcBL_BlkCtr==0 || dcBL_BlkCtr==1024 || dcBL_BlkCtr==2048 || dcBL_BlkCtr==3072 || dcBL_BlkCtr==4096) - { - ultmp=uint32_t(dcBL_BlkCtr); - ultmp*=64; - len=dcBL_sendFlashStartAddr2BL(ultmp, buf); - sendWRcmd_setSendBlock160(len, buf); - qDebug()<<" DCBL_CYCL_sending HexFile address "; - dcBL_writeText("sending addr"); - dcBL_step++; - return 0; - } else - dcBL_step=12; - break; - - case 2: // wait for answer 2 161 68 59 3 - if (gotResp==ISOK) - { - dcBL_step=12; // Header nicht senden, unnötig - dcBL_BlkCtr=0; // 0 - repeatCtr=0; - return 0; - } else - if (gotResp==ISWRONG) - { - if (++repeatCtr<3) - { - dcBL_step--; - } else - { - dcBL_step=0; // stop chain - qDebug()<<" DCBL_CYCL_got wrong resp to addr"; - dcBL_writeText("wrong resp"); - } - } - if (++dcBL_cyclCtr>100) - { - dcBL_writeText("cancel"); - qDebug()<<" DCBL_CYCL_step 2 got NO resp to addr"; - dcBL_step=0; // stop chain - } - break; - - case 12: // send binary 64 byte wise - - len=dcBL_getFileBlock(dcBL_BlkCtr, buf); // read from file, len = 0...64 - //lastBlkLength=len; // recognize last block or end - sendLen=dcBL_prepareDC_BLcmd(0x22, len, buf, sendBuf); // pack into protocol frame -/* - // Kontrolle: - qDebug()<<"dcBL sending: "; - ii=0; - do - { - uit8tmp=(uint8_t)sendBuf[ii++]; - //qDebug() << uit8tmp << " "; // Anzeige in dez - stemp.setNum(uit8tmp,16); - qDebug() << stemp << " "; // Anzeige in hex - - } while (ii<100); -*/ - sendWRcmd_setSendBlock160(sendLen, sendBuf); // send 140 bytes - delay(100); - dcBL_writeText("blk nr: "); - tmpStr.setNum(dcBL_BlkCtr); - dcBL_writeText(tmpStr); - delay(100); - qDebug()<<"DCBL sending blk nr: " << dcBL_BlkCtr; - dcBL_cyclCtr=0; - dcBL_BlkCtr++; - dcBL_step++; - break; - - case 13: // wait for answer 2 162 116 88 3 - - if (gotResp==ISOK) - { - // check if next address is needed (every 1024Blocks = 65536bytes) - if (dcBL_BlkCtr==1024 || dcBL_BlkCtr==2048 || dcBL_BlkCtr==3072 || dcBL_BlkCtr==4096) - { - dcBL_step=8; - return 0; - } - - // check for EOF: - if (dcBL_BlkCtr >= dcBL_nrOfBlocks) - { - dcBL_writeText("last block successful sent..."); - dcBL_step++; // stop chain - dcBL_state=3; // transmission SUCCESSFUL - return 0; - } - dcBL_state=2; // transmission started - dcBL_step--; // send next data block - repeatCtr=0; - return 0; - } - if (gotResp==ISWRONG) - { - if (++repeatCtr<3) - { - dcBL_writeText("error"); - dcBL_BlkCtr--; - dcBL_step--; // send same block again - } else - { - dcBL_step=0; // stop chain - } - } - if (++dcBL_cyclCtr>30) // longer TO due to flashing - { - dcBL_writeText("cancel"); - dcBL_step=0; // stop chain - } - break; - - case 14: // - dcBL_writeText("finish writing flash"); - len=dcBL_writeLastPage(buf); // nur zur Sicherheit - sendWRcmd_setSendBlock160(len, buf); - dcBL_step++; - break; - - case 15: // wait for answer - if (gotResp==ISOK) - { - dcBL_step++; - repeatCtr=0; - return 0; - } else - if (gotResp==ISWRONG) - { - if (++repeatCtr>3) - { - dcBL_step--; - } - } - if (++dcBL_cyclCtr>10) - { - dcBL_writeText("cancel"); - dcBL_step=0; // stop chain - } - break; - - } - return 0; -} - - - - - -uint8_t dcBL_getResult(void) -{ - // call after every step to what's going on.... - // 1: connected to BL - // 2: transmission started - // 3: transmission successful - - return dcBL_state; -} - -// ------------------------------------------------------------------------- -// ------------------------------------------------------------------------- -// ------------------------------------------------------------------------- - - -static uint8_t Sdata_rawData[RAW_BL_DATALEN]; - -static uint8_t Sdata_LengthRawData; - -void gpi_storeRawReceivedData(uint8_t RdDlen, uint8_t *receivedData) -{ - uint8_t nn; - Sdata_LengthRawData=RdDlen; - if (Sdata_LengthRawData>RAW_BL_DATALEN) - Sdata_LengthRawData=RAW_BL_DATALEN; - for (nn=0; nn0x80 dann wird EIN Byte 16 stellig angezeigt - int ll=tmpStr.length(); - if (ll>2) - { - myString.append(tmpStr[ll-2]); - myString.append(tmpStr[ll-1]); - } else - { - myString.append(tmpStr); - } - myString.append(" "); - - } - //ret=Sdata_LengthRawData; - //Sdata_LengthRawData=0; - return myString; -} - -void epi_clrRawReceivedString() -{ - Sdata_LengthRawData=0; -} - - - - - - - - - diff --git a/DCPlugin/src/hwChk.cpp b/DCPlugin/src/hwChk.cpp deleted file mode 100755 index ddac2ed..0000000 --- a/DCPlugin/src/hwChk.cpp +++ /dev/null @@ -1,25 +0,0 @@ - -#include -#include "hwChk.h" - - -hwChk::hwChk(QWidget *parent) : QObject(parent) -{ - -// myDCIF = new T_prot(); -// h: T_prot *myDCIF; - - //myDatif = new T_datif(); - HWaccess = new hwinf(); - - struct T_moduleCondition dcModCond; - sys_getDeviceConditions(dcModCond); - - -} - -hwChk::~hwChk() -{ - -} - diff --git a/DCPlugin/src/hwapi.cpp b/DCPlugin/src/hwapi.cpp deleted file mode 100644 index 9178cdf..0000000 --- a/DCPlugin/src/hwapi.cpp +++ /dev/null @@ -1,4064 +0,0 @@ -/* - * API to the PSA2020 Hardware - * All data come in from device controller via serial interface and will be stored - * PI is updated every 100ms - * This api uses stored data and returns them in the following functions - * created: Q1/2020 TS until Q2/21 - * - */ - -#include -#include -#include -#include - -#include - -#include "tslib.h" -#include "hwapi.h" - -#include "sendWRcmd.h" -#include "controlBus.h" -#include "storeINdata.h" -#include "dcBL.h" -#include "shared_mem_buffer.h" -#include -#include -#include "interfaces.h" - -static uint32_t hwapi_lastStartAmount; - -static const QMap baudrateMap = { - {"1200" , 0}, {"9600" , 1}, {"19200" , 2}, {"38400" , 3}, - {"57600" , 4}, {"115200" , 5} -}; - -hwapi::hwapi(QObject *parent) : QObject(parent) { - // create or attach shared memory segment - // !!! The compoment creating the shared memory MUST be ATBQT !!! - m_sharedMem = SharedMemBuffer::getShm(sizeof(SharedMemBuffer)); - if (m_sharedMem) { - if (m_sharedMem->isAttached()) { - qInfo() << "Shared memory (" - << sizeof(SharedMemBuffer) << "bytes) created and attached"; - } - } else { - qCritical() << "Creating/attaching shared memory failed"; - } - sendWRcmd_INI(); - myDatif = new T_datif(); - - connect(myDatif, SIGNAL(datif_templatePrintFinished_OK()), this, SLOT(hwapi_slotPrintFinished_OK())); - connect(myDatif, SIGNAL(datif_templatePrintFinished_Err()), this, SLOT(hwapi_slotPrintFinished_Err())); - connect(myDatif, SIGNAL(datif_gotNewCoin()), this, SLOT(hwapi_slotGotCoin())); -} - -hwapi::~hwapi() { - if (m_sharedMem && m_sharedMem->isAttached()) { - m_sharedMem->detach(); - } -} - -void hwapi::hwapi_slotPrintFinished_OK(void) { - emit hwapi_templatePrintFinished_OK(); -} - -void hwapi::hwapi_slotPrintFinished_Err(void) { - emit hwapi_templatePrintFinished_Err(); -} - -void hwapi::hwapi_slotGotCoin(void) { - // new coin was inserted while transaction and new amount reported: - emit hwapi_gotNewCoin(); - - uint32_t newSum=epi_CurrentPaymentGetAmount(); - - if (newSum>=hwapi_lastStartAmount) - emit hwapi_vendStopByMax(); - -} - -void hwapi::sub_storeSendingText(QByteArray *buf) const { - - char local[70], copie[1350]; // 64byte more then max buffer size! - int LL, nn, len, maxruns=20; - - epi_resetPrinterStack(); - // make a copy of the incoming byteArray as the byteArray can not be moved (crash!) - tslib_strclr(copie, 0, 1350); - LL=buf->length(); - for (nn=0; nnat(nn); - } - - tslib_strclr(local, 0, 66); - LL=buf->length(); - if (LL>1280) - { - qDebug()<<"reducing text size from " << LL << " to 1280 bytes"; - LL=1280; // Limit size - } else - qDebug()<<"\n printing text with " << LL << " bytes: "; - - do - { - len=tslib_getMinimum(LL, 64); - tslib_strclr(local, 0, 66); - for (nn=0; nn0 && LL>0); - -} - - -// ------------------------------------------------------------------------------ -// Level 0 commands, interface -// open, close, change serial interface -// actually not neccessary as it is opened automatically on program start -// start automatic READ requests -// ------------------------------------------------------------------------------ - -bool hwapi::dc_openSerial(int BaudNr, QString BaudStr, - QString ComName, uint8_t connect) const { - // BaudNr: 0:1200 1:9600 2:19200 3:38400 4:57600 5:115200 - // BaudStr: for exapmle "19200" - // ComName: for example "COM48" - // connect: 0, 1 - //qDebug() << "~~>LIB" << "dc_openSerial called... " ; - - epi_setSerial(BaudNr, BaudStr, ComName, connect); - - // Actions: open serial port with parameters - for (int i = 0; i < 10; ++i) { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - if (dc_isPortOpen()) { - return true; - } - } - return false; -} - -QStringList hwapi::dc_getStatus() const { - QStringList status; - - if (m_sharedMem) { - SharedMemBuffer const *shMem = SharedMemBuffer::getDataConst(); - status += QString("comport : %1").arg(shMem->rs.comportName); - status += QString("baudrate : %1").arg(shMem->rs.baudNr); - status += QString("baudNr : %1").arg(shMem->rs.baudStr); - status += QString("connect : %1").arg(shMem->rs.connect); - status += QString("port open: %1").arg(shMem->rs.portIsOpen); - // to be continued - } - - return status; -} - -bool hwapi::dc_closeSerial(void) const { - epi_closeSerial(); - for (int i = 0; i < 10; ++i) { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - if (!dc_isPortOpen()) { - return true; - } - } - return false; -} - -bool hwapi::dc_isPortOpen(void) const { - if (myDatif) { - T_prot* prot = myDatif->getProt(); - if (prot) { - T_com *com = prot->getSerialPort(); - if (com) { - return com->isPortOpen(); - } - } - } - return false; - //return epi_isSerialPortOpen(); -} - -void hwapi::dc_autoRequest(bool on) const -{ - // automatically request ALL digital and analog sensors, get time/date, get status information - if (on) - epi_startEmmision(1); - else - epi_startEmmision(0); -} - -/******************************************************************************/ -// -// LEVEL 2: Help-functions for hwapi::dc_updateDC. -// -/******************************************************************************/ -hwapi::DownloadResult hwapi::sendStatus(int ret) const { - switch (ret) { // return values of dc are: - case 0: // 0: no answer by now - return DownloadResult::NOP; // 1: error - case 10: // 10: success - return DownloadResult::OK; - default:; - } - return DownloadResult::ERROR; -} - -hwapi::DownloadResult hwapi::sendNextAddress(int bNum) const { - // sends address only if blockNumber is one of 0, 1024, 2048, 3072, 4096 - int noAnswerCount = 0; - int errorCount = 0; - if ( bNum==0 || bNum==1024 || bNum==2048 || bNum==3072 || bNum==4096 ) { - qDebug() << "addr-block" << bNum << "..."; - while (noAnswerCount <= 250) { - bl_sendAddress(bNum); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - DownloadResult const res = sendStatus(bl_wasSendingAddOK()); - if (res != DownloadResult::NOP) { - if (res == DownloadResult::ERROR) { - if (++errorCount >= 10) { - qCritical() << "addr-block" << bNum << "...FAILED"; - return res; - } - } else { // res == DownloadResult::OK - qInfo() << "addr-block" << bNum << "...OK"; - return res; - } - } else { - noAnswerCount += 1; // no answer by now - } - } - // wait max. about 3 seconds - return DownloadResult::TIMEOUT; - } - // blockNumber is not one of 0, 1024, 2048, 3072, 4096 -> do nothing - return DownloadResult::NOP; -} - -hwinf::DownloadResult hwapi::sendNextDataBlock(QByteArray const &binary, - int bNum) const { - uint8_t local[66]; - int const bAddr = bNum * 64; - int noAnswerCount = 0; - int errorCount = 0; - - memcpy(local, binary.constData() + bAddr, 64); - local[64] = local[65] = 0x00; - - qDebug() << "data for addr" << bAddr << "..."; - - while (noAnswerCount <= 250) { - bl_sendDataBlock(64, local); - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - DownloadResult const res = sendStatus(bl_wasSendingDataOK()); - if (res != DownloadResult::NOP) { - if (res == DownloadResult::ERROR) { - if (++errorCount >= 10) { - qCritical() << "data for addr" << bAddr << "...FAILED"; - return res; - } - } else { - qInfo() << "data for addr" << bAddr << "...OK"; - return res; - } - } else { - noAnswerCount += 1; // no answer by now - } - } - // wait max. about 3 seconds - return DownloadResult::TIMEOUT; -} - -hwinf::DownloadResult hwapi::dc_downloadBinary(QByteArray const &b) const { - int const nBlocks = (((b.size())%64)==0) ? (b.size()/64) : (b.size()/64)+1; - - qInfo() << "total number of bytes to send to dc" << b.size(); - qInfo() << "total number of blocks to send to dc" << nBlocks; - - int bNum = 0; - DownloadResult res = DownloadResult::OK; - while (res != DownloadResult::ERROR && bNum < nBlocks) { - if ((res = sendNextAddress(bNum)) != DownloadResult::ERROR) { - if ((res = sendNextDataBlock(b, bNum)) != DownloadResult::ERROR) { - bNum += 1; - } - } - } - if (res != DownloadResult::ERROR) { - bl_sendLastBlock(); - } - return res; -} - -bool hwapi::startBootloader() const { - qDebug() << "starting bootloader..."; - int nTry = 5; - while (--nTry >= 0) { - bl_startBL(); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - if (bl_isUp()) { - qInfo() << "starting bootloader...OK"; - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - return true; - } - } - qCritical() << "starting bootloader...FAILED"; - return false; -} - -bool hwapi::stopBootloader() const { - qDebug() << "stopping bootloader..."; - int nTry = 5; - while (--nTry >= 0) { - bl_stopBL(); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - if (!bl_isUp()) { - qInfo() << "stopping bootloader...OK"; - return true; - } - } - qCritical() << "stopping bootloader...FAILED"; - return false; -} - -// br is a index into a table, used for historical reasons. -bool hwapi::openSerial(int br, QString baudrate, QString comPort) const { - qDebug() << "opening serial" << br << baudrate << comPort << "..."; - if (dc_openSerial(br, baudrate, comPort, 1)) { // 1 for connect - qInfo() << "opening serial" << br << baudrate << comPort << "...OK"; - return true; - } - qCritical() << "opening serial" << br << baudrate << comPort << "...FAILED"; - return false; -} - -bool hwapi::closeSerial(QString comPort) const { - qDebug() << "closing serial" << comPort << "..."; - if (dc_closeSerial()) { - qInfo() << "closing serial" << comPort << "...OK"; - return true; - } else { - qCritical() << "closing serial" << comPort << "...FAILED"; - } - return false; -} - -bool hwapi::resetDeviceController() const { - qDebug() << "resetting device controller..."; - if (stopBootloader()) { // first stop a (maybe) running bootloader - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - dc_OrderToReset(); - // wait maximally 3 seconds, before starting bootloader - std::this_thread::sleep_for(std::chrono::milliseconds(1500)); - qInfo() << "resetting device controller...OK"; - return true; - } - return false; -} - -QByteArray hwapi::loadBinaryDCFile(QString filename) const { - qDebug() << "loading dc binary" << filename << "..."; - - QFile file(filename); // closed in destructor call - if (!file.exists()) { - qCritical() << file.fileName() << "does not exist"; - return QByteArray(); - } - if (!file.open(QIODevice::ReadOnly)) { - qCritical() << "cannot open file" << file.fileName(); - return QByteArray(); - } - qInfo() << "loading dc binary" << filename << "...OK"; - return file.readAll(); -} - -bool hwapi::downloadBinaryToDC(QString const &bFile) const { - qDebug() << "sending" << bFile << "to dc..."; - QByteArray const dcBinary = loadBinaryDCFile(bFile); - if (dcBinary.size() > 0) { - if (dc_downloadBinary(dcBinary) != DownloadResult::OK) { - qCritical() << "sending" << bFile << "to dc...FAILED"; - return false; - } else { - qInfo() << "sending" << bFile << "to dc...OK"; - } - } else { - qCritical() << "sending" << bFile << "to dc...FAILED"; - qCritical() << "loading binary" << bFile << "FAILED"; - return false; - } - return true; -} - -/******************************************************************************/ -// -// LEVEL 3: hwapi::dc_updateDC. -// -/******************************************************************************/ -bool hwapi::dc_updateDC(QString bFile, QString br, QString serial) const { - if (!baudrateMap.contains(br)) { // sanity check - qCritical() << "passed wrong baudrate" << br; - return false; - } - - qDebug() << "updating dc: " << bFile << br << serial << "..."; - - if (!openSerial(baudrateMap.value(br), br, serial)) { - return false; - } - if (!resetDeviceController()) { - closeSerial(serial); - return false; - } - if (!startBootloader()) { - closeSerial(serial); - return false; - } - if (!downloadBinaryToDC(bFile)) { - stopBootloader(); - closeSerial(serial); - qCritical() << "updating dc: " << bFile << br << serial << "...FAILED"; - return false; - } - - qInfo() << "updating dc: " << bFile << br << serial << "...OK"; - - stopBootloader(); - closeSerial(serial); - return true; -} - -/******************************************************************************/ -// -// LEVEL 3: hwapi::dc_updatePrinterTemplate -// -/******************************************************************************/ -bool hwapi::dc_updatePrinterTemplate(enum FileTypeJson type, - QVector templatesIdx, - QVector fnames, - QString br, - QString serial) const { - // sanity checks - if (!baudrateMap.contains(br)) { - qCritical() << "passed wrong baudrate" << br; - return false; - } - if (templatesIdx.size() != fnames.size()) { - qCritical() << "list sizes must be equal" << br; - return false; - } - if (!std::all_of(templatesIdx.cbegin(), templatesIdx.cend(), - [](int i) { return i >= 1 && i <= 32; })) { - qCritical() << "wrong template indices"; - return false; - } - if (type != FileTypeJson::PRINTER) { - qCritical() << "wrong file type" << (uint8_t)type; - return false; - } - - qDebug() << "updating: " << fnames << br << serial << "..."; - - if (!serial.isNull()) { - if (!openSerial(baudrateMap.value(br), br, serial)) { - return false; - } - } - - int nTry = 50; - while (!sys_ready4sending()) { // wait max. 5 seconds - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - if (--nTry <= 0) { - qCritical() << "sys not ready for sending"; - if (!serial.isNull()) { - closeSerial(serial); - } - return false; - } - } - - bool ret = true; - for (int i = 0; i < fnames.size(); ++i) { - QFile file(fnames[i]); - if (file.exists() && file.open(QIODevice::ReadOnly)) { - QByteArray ba = file.readAll(); - if (ba.size() <= 800) { // max. size is 800 bytes - if (sys_sendJsonFileToDc((uint8_t)(type), - templatesIdx[i], - (uint8_t *)ba.data())) { - std::this_thread::sleep_for(std::chrono::seconds(1)); - qInfo() << "sent file" << fnames[i] << "to dc"; - } - } - } else { - qCritical() << fnames[i] << "!!! does not exist!!!"; - ret = false; - continue; - } - } - if (!serial.isNull()) { - closeSerial(serial); - } - return ret; -} - -bool hwapi::dc_printTemplate(enum FileTypeJson type, - QVector templateIdx, - QString br, - QString serial) const { - // sanity checks - if (!baudrateMap.contains(br)) { - qCritical() << "passed wrong baudrate" << br; - return false; - } - if (!std::all_of(templateIdx.cbegin(), templateIdx.cend(), - [](int i) { return i >= 1 && i <= 32; })) { - qCritical() << "wrong template indices"; - return false; - } - if (type != FileTypeJson::PRINTER) { - qCritical() << "wrong file type" << (uint8_t)type; - return false; - } - - qDebug() << "printing: " << templateIdx << br << serial << "..."; - - if (!serial.isNull()) { - if (!openSerial(baudrateMap.value(br), br, serial)) { - return false; - } - } - - int nTry = 50; - while (!sys_ready4sending()) { // wait max. 5 seconds - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - if (--nTry <= 0) { - qCritical() << "sys not ready for sending"; - if (!serial.isNull()) { - closeSerial(serial); - } - return false; - } - } - - bool ret = true; - struct T_dynDat dynTicketData; - memset (&dynTicketData, 0x00, sizeof(dynTicketData)); - - // lassen sich auch veraendern - memcpy(&dynTicketData.licensePlate[0], "WEN1230", 8); - memcpy(&dynTicketData.vendingPrice[0], "1234", 8); - memcpy(&dynTicketData.parkingEnd[0], "12:00:00", 8); - memcpy(&dynTicketData.currentTime[0], "14:15:00", 8); - memcpy(&dynTicketData.currentDate[0], "01.01.2023", 8); - - for (int i = 0; i < templateIdx.size(); ++i) { - // dynamische Daten werden gespeichert - if (prn_sendDynamicPrnValues(&dynTicketData.licensePlate[0])) { - // angabe welches template beim drucken benutzt werden soll - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - if (prn_printTemplate(templateIdx[i])) { - qDebug() << "printing template" << templateIdx[i]; - std::this_thread::sleep_for(std::chrono::seconds(3)); - } - } else { - ret = false; - continue; - } - } - if (!serial.isNull()) { - closeSerial(serial); - } - return ret; - -} - -// ------------------------------------------------------------------------------ -// Level 1, control device-controller (functions of µC) -// check serial connection to deviceController -// read response from DC2 (input data) -// some test function for serial communication -// also Bootloader is here -// ------------------------------------------------------------------------------ - -void hwapi::dc_requTestResponse() const -{ - sendWRcmd_setSendCommand0(SENDDIRCMD_TestSerial); -} - -bool hwapi::dc_readAnswTestResponse() const -{ - return epi_getResult_serialTestOK(); -} - -uint8_t hwapi::dc_isRequestDone(void) const -{ - // retval: 0: request is still in progress - // 1: answer from DC2 was OK - // 2: wrong answer from DC2 - return epi_getResultOfLastRequest(); -} - -uint16_t hwapi::dc_getCompletePayLoad(uint16_t plBufSiz, uint8_t *payLoad) const -{ - // get data back in *pl, max 64 byte, can be used for diagnosis - // retval = nr of bytes received. If host buffer too small then - // only plBufSíz bytes are copied to pl - // plBufSíz=size of host buffer - - return epi_getLastPayLoad( plBufSiz, payLoad); - -} - -void hwapi::dc_setWakeFrequency(uint8_t period) const -{ - // RTC wakes DC2 (and PTU) by hardware signal every 32seconds - // change wake signal period to 1...64s - sendWRcmd_setSendCommand4(SENDDIRCMD_setWakeFrequ, period,0,0,0); -} - -void hwapi::dc_OrderToReset(void) const -{ - uint8_t len, buf[160]; - - len=dcBL_restartDC(buf); - sendWRcmd_setSendBlock160(len, buf); - //sendWRcmd_setSendCommand0(SENDDIRCMD_MakeReset); - // not needed, sendWRcmd_setSendBlock160() starts sending as well... -} - -QString hwapi::dc_getSerialState(void) const -{ -// geht - return epi_getTxt4comStateLine(); -} - -void hwapi::dc_clrSerialStateText(void) const -{ - epi_clrTxt4comStateLine(); -} - - - -void hwapi::bl_sendDataDirectly(uint8_t length, uint8_t *buf) const -{ - // send without protocol frame, needed for the DC bootloader - sendWRcmd_setSendBlock160(length, buf); - -} - -uint8_t hwapi::getRawRecLength(void) const -{ - return epi_getRawRecLength(); -} - -uint8_t hwapi::getRawReceivedData(uint8_t *receivedData) const -{ - return epi_getRawReceivedData(receivedData); -} - - - - -QString hwapi::dc_getSerialParams(void) const -{ - return epi_getSlaveParamSTR(); -} - -QString hwapi::dc_getHWversion(void) const -{ - return epi_loadGenerals(0); -} - -QString hwapi::dc_getSWversion(void) const -{ - return epi_loadGenerals(1); -} - -QString hwapi::dc_getState(void) const -{ - return epi_loadGenerals(2); -} - - -// ------------------------------------------------------------------------------ -// Level 2 DC2-onboard devices -// WR: set time -// RD. get time, get measure, get test results -// ------------------------------------------------------------------------------ - -// get UID, get time/date test results memory, RTC analog values - -// ---------------------------------------------------------------------------------------------------------- -// Date and Time -// ---------------------------------------------------------------------------------------------------------- - -uint8_t hwapi::rtc_getDateTime(struct Trtc_DateTime *rtc_DateTime) const -{ -// void epi_getTime(uint8_t *hh, uint8_t *mm, uint8_t *ss); -// void epi_getDate(uint8_t *yy, uint8_t *mm, uint8_t *dd); -// void epi_getToday(uint8_t *dow, uint16_t *minOfToday, uint32_t *secOfToday); - uint8_t H, M, S; - uint16_t unused16; - uint32_t unused32; - - epi_getTime(&H, &M, &S); - rtc_DateTime->rtc_hour=H; - rtc_DateTime->rtc_min=M; - rtc_DateTime->rtc_sec=S; - - epi_getDate(&H, &M, &S); - rtc_DateTime->rtc_year=H; - rtc_DateTime->rtc_month=M; - rtc_DateTime->rtc_dayOfMonth=S; - - epi_getToday(&H, &unused16, &unused32); - rtc_DateTime->rtc_dayOfWeek=H; - return 0; -} - -uint8_t hwapi::rtc_setDateTime(void) const -{ - sendWRcmd_setSendCommand0(SENDDIRCMD_setTime); - return 0; -} - - -void hwapi::rtc_getTime(uint8_t *hh, uint8_t *mm, uint8_t *ss) const -{ - epi_getTime(hh, mm, ss); -} - -void hwapi::rtc_getDate(uint8_t *yy, uint8_t *mm, uint8_t *dd) const -{ - epi_getDate(yy, mm, dd); -} - -uint8_t hwapi::rtc_getToday(uint8_t *dow, uint16_t *minOfToday, uint32_t *secOfToday) const -{ - // dow=day of week, 1=monday...7 - // minOfToday: 0=midnight...1439= 23:59 - // secOfToday: 0=midnight...86399= 23:59:59 - - epi_getToday(dow, minOfToday, secOfToday); - return 0; -} - -bool hwapi::rtc_isLeapYear(uint8_t *lastLeapYear, uint8_t *NextLeapYear) const -{ - return epi_isLeapYear(lastLeapYear, NextLeapYear); -} - - -bool hwapi::rtc_isLeapYear(void) const -{ - return epi_isLeapYear(); -} - -void hwapi::rtc_getWeek(uint8_t *DayOfWeek, uint8_t *HoursOfWeek, uint16_t *MinutesOfWeek) const -{ - epi_getSpecialWeekTimeDate(DayOfWeek, HoursOfWeek, MinutesOfWeek); -} - -void hwapi::rtc_getMonth(uint8_t *DayOfMonth, uint16_t *HoursOfMonth, uint16_t *MinutesOfMonth) const -{ - epi_getSpecialMonthTimeDate(DayOfMonth, HoursOfMonth, MinutesOfMonth); -} - -void hwapi::rtc_getYear(uint16_t *DayOfYear, uint16_t *HoursOfYear, uint32_t *MinutesOfYear) const -{ - epi_getSpecialYearTimeDate(DayOfYear, HoursOfYear, MinutesOfYear); -} - - -QString hwapi::rtc_getTimStr() const -{ - uint8_t hh, mm, ss, buf[20], nn; - QString qbuf; - char ctmp; - qbuf.clear(); - for (nn=0; nn<20; nn++) buf[nn]=0; - epi_getTime(&hh, &mm, &ss); - GetTimeString(hh, mm, ss, HourSys24h, MITSEK, buf); // about 12byte long - for (nn=0; nn<20; nn++) - { - ctmp=buf[nn]; - qbuf[nn]=ctmp; - } - return qbuf; -} - -QString hwapi::rtc_getDatStr() const -{ - uint8_t day, month, year, buf[20], nn; - QString qbuf; - char ctmp; - - qbuf.clear(); - for (nn=0; nn<20; nn++) buf[nn]=0; - epi_getDate(&year, &month, &day); - GetDateString(day, month, 0x20, year, DateFormatDeutsch, 0, buf); - for (nn=0; nn<20; nn++) - { - ctmp= buf[nn]; - qbuf[nn]=ctmp; - } - return qbuf; -} - -QString hwapi::rtc_getTimDatStr() const -{ - // style: 0: hh:mm 1: hh:mm:ss - QString qbuf; - - qbuf.clear(); - qbuf.append(rtc_getTimStr()); - qbuf.append(" "); - qbuf.append(rtc_getDatStr()); - return qbuf; -} - - - - - -// UID -void hwapi::dc_getUID8byte(uint8_t *buf8byteUid) const -{ - epi_getUIDdec(buf8byteUid); -} - -QString hwapi::dc_getUIDstr() const -{ - return epi_getUIDstr(); -} - -uint64_t hwapi::dc_getUIDnumber(void) const -{ - uint64_t retval=0; - uint8_t buf8byteUid[12], nn; - - epi_getUIDdec(buf8byteUid); - for (nn=8; nn>0; nn--) - { - retval+=buf8byteUid[nn-1]; - retval<<=8; // *256 - } - return retval; -} - - - -uint32_t hwapi::dc_getTemperature(void) const -{ - // - return epi_loadMeasureValue(MEASCHAN_TEMPERATURE); -} - -QString hwapi::dc_getTemperaturStr(void) const -{ - return epi_getSlaveTemperatureStr(); -} - - -uint32_t hwapi::dc_getVoltage(void) const -{ - // in mV, e.g. 12300 = 12,3V - return epi_loadMeasureValue(MEASCHAN_VOLTAGE); -} - -QString hwapi::dc_getVoltagStr(void) const -{ - return epi_getSlaveVoltageStr(); -} - -bool hwapi::dc_mainFuseIsOk(void) const -{ - uint32_t ulong=epi_loadMeasureValue(MEASCHAN_VOLTAGE); // in mV, e.g. 12300 = 12,3V - if (ulong>3000) - return true; - return false; -} - -// ------------------------------------------------------------------------------ -// Level 3: digital outputs and simple switching of connected devices -// simple processes like flashing a led or open flap for 1s -// ------------------------------------------------------------------------------ - -// Locks: -uint8_t hwapi::lock_switchUpperLock(uint8_t dir) const -{ - // dir 0=off 1=up 2=down - sendWRcmd_setSendCommand4(SENDDIRCMD_MOVEUP_LOCK ,dir,0,0,0); - return 0; -} - -uint8_t hwapi::lock_switchLowerLock(uint8_t dir) const -{ - // dir 0=off 1=up 2=down - sendWRcmd_setSendCommand4(SENDDIRCMD_MOVEDN_LOCK ,dir,0,0,0); - return 0; -} - -void hwapi::lock_switchVaultDoor(void) const -{ - - sendWRcmd_setSendCommand0(SENDDIR_OPENVAULT); -} - -void hwapi::coin_switchRejectMotor(uint8_t dir) const -{ - - sendWRcmd_setSendCommand4(SENDDIR_REJMOT_ON, dir, 0,0,0); -} - -void hwapi::coin_rejectCoins(void) const -{ - - sendWRcmd_setSendCommand0(SENDDIR_REJMOT_RUN); -} - - -void hwapi::led_switchLedService(uint8_t on) const -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_LEDINSIDE, on, 0, 0, 0); -} - -void hwapi::led_switchLedPaper(uint8_t on, uint8_t ton, uint8_t tof) const -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_LEDTICKET, on, ton, tof, 0); -} - -void hwapi::led_switchLedPinPad(uint8_t on, uint8_t ton, uint8_t tof) const -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_LEDPAD, on, ton, tof, 0); -} - -void hwapi::led_switchLedStart(uint8_t on, uint8_t ton, uint8_t tof) const -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_LEDSTART, on, ton, tof, 0); -} - -void hwapi::led_switchLedCoinbassin(uint8_t on, uint8_t ton, uint8_t tof) const -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_LEDCOIN, on, ton, tof, 0); -} - -void hwapi::fan_switchFan(bool on) const -{ - //return epi_storeDOsToSend(DOBYTE3, FAN_ON, on); - sendWRcmd_setSendCommand4(SENDDIRCMD_FAN, on, 0, 0, 0); -} - -void hwapi::alarm_switchSiren(bool on) const -{ - //return epi_storeDOsToSend(DOBYTE4, LAERM, on); - sendWRcmd_setSendCommand4(SENDDIRCMD_LAERM, on, 0, 0, 0); -} - -void hwapi::bar_OpenBarrier(bool open) const -{ - //return epi_storeDOsToSend(DOBYTE4, REL1, open); - sendWRcmd_setSendCommand4(SENDDIRCMD_REL1, open, 0, 0, 0); -} - -void hwapi::ptu_switchWake(bool WAKEACTIVE) const -{ - //return epi_storeDOsToSend(DOBYTE1, CTS_PTU, WAKEACTIVE); - sendWRcmd_setSendCommand4(SENDDIRCMD_WAKEPTU, WAKEACTIVE,0,0,0); -} - -// AUX-IO's or barcode reader -void hwapi::aux_power(bool on) const -{ -// return epi_storeDOsToSend(DOBYTE2, BARC_POW_ON, on); - sendWRcmd_setSendCommand4(SENDDIRCMD_AUXPWR, on,0,0,0); -} - -void hwapi::aux_setUsage(uint8_t PinDirection) const -{ - // bit 0= Aux1 bit5=Aux6 1=output 0=input with pullup - - // return epi_storeDOsToSend(DOBYTE6, nr, PinDirection); - sendWRcmd_setSendCommand4(SENDDIRCMD_AUXDDR, PinDirection,0,0,0); -} - -void hwapi::aux_setOutputs(uint8_t PinIsHigh) const -{ - // PinIsHigh bit 0..5 =Aux1...6 1=output high 0=set output low - - //return epi_storeDOsToSend(DOBYTE5, nr, PinIsHigh); - sendWRcmd_setSendCommand4(SENDDIRCMD_AUXOUT, PinIsHigh,0,0,0); -} - -void hwapi::lock_switchContactPower(bool on) const -{ - //epi_storeDOsToSend(DOBYTE2, U_SW_ON, on); - sendWRcmd_setSendCommand4(SENDDIRCMD_UCONTACT_ON, on, 0,0,0); -} - -void hwapi::prn_switchPower(bool on) const -{ - // also switches and enables serial driver - sendWRcmd_setSendCommand4(SENDDIRCMD_PRN2_SWONOFF, on,0,0,0); - indat_storePrinterPower(on); - // PRINTER-ON/OFF zusätzlich statisch abspeichern - // Status-request soll nur gesendet werden wenn der Drucker ein ist - // Status-Abfrage (hier in HWapi) gibt 0 zurück wenn power-off - // dito mit allen anderen Geräten! - - // pi ---> storeINdata.cpp speichert diese statische Info (printer on/off) UND - // auch alles rückgelesene - -} - - -void hwapi::mif_readerOn(bool on) const -{ - // DC2 also switches and enables serial driver - sendWRcmd_setSendCommand4(SENDDIRCMD_MIF_SWONOFF, on,0,0,0); -} - -void hwapi::mif_creatAtbCard(uint8_t cardType) const -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_MIF_SWONOFF, cardType, 0,0,0); -} - - -void hwapi::mod_switchPower(bool on) const -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_MOD_SWONOFF, on,0,0,0); -} - -void hwapi::mod_switchWake(bool WAKEACTIVE) const -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_MOD_WAKE, WAKEACTIVE,0,0,0); -} - -void hwapi::mdb_switchPower(bool on) const -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_MDB_POWER, on,0,0,0); -} - -void hwapi::mdb_switchWake(bool WAKEACTIVE) const -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_MDB_WAKE, WAKEACTIVE,0,0,0); -} - -void hwapi::credit_switchPower(bool on) const -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_CRED_ON, on,0,0,0); -} - -void hwapi::credit_switchWake(bool WAKEACTIVE) const -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_CRED_WAKE, WAKEACTIVE,0,0,0); -} - -void hwapi::shut_move(bool open) const -{ - // true:open false:close - sendWRcmd_setSendCommand4(SENDDIRCMD_SHUT_MOV, open, 0,0,0); -} - -void hwapi::esc_moveFlaps(uint8_t flap ) const -{ - // 0: close both 1: open take-flap 2: open return - sendWRcmd_setSendCommand4(SENDDIRCMD_ESCRO_MOV, flap, 0,0,0); -} - - -// ------------------------------------------------------------------------------ -// Level 3: digital inputs of connected devices -// ------------------------------------------------------------------------------ - - - -uint8_t hwapi::door_getSwitches(void) const -{ - // retval // bit0: upper door 1: low door 2:vault door - uint8_t ret; - - ret= epi_getDI_doorSwitches(); - // bit0: upper door 1: low door 2:vault door - ret &= 0x08; - return ret; -} - -bool hwapi::door_isUpperDoorOpen(void) const -{ - uint8_t ret; - - ret= epi_getDI_doorSwitches(); - // bit0: upper door 1: low door 2:vault door - if (ret & 1) - return true; - return false; -} - -bool hwapi::door_isLowerDoorOpen(void) const -{ - uint8_t ret; - - ret= epi_getDI_doorSwitches(); - // bit0: upper door 1: low door 2:vault door - if (ret & 2) - return true; - return false; -} - -bool hwapi::vault_isVaultDoorOpen(void) const -{ - uint8_t ret; - - ret= epi_getDI_doorSwitches(); - // bit0: upper door 1: low door 2:vault door - if (ret & 4) - return true; - return false; -} - - -uint8_t hwapi::vault_getSwitches(void) const -{ - // retval bit0: cash box, bit 1: bill box - uint8_t ret; - - ret=epi_getDI_vaultSwitches(); // bit0: cash box 1: bill box in - ret&=0x03; - return ret; -} - -bool hwapi::vault_isCoinVaultIn(void) const -{ - uint8_t ret; - - ret=epi_getDI_vaultSwitches(); // bit0: cash box 1: bill box in - if (ret & 1) - return true; - return false; -} - -bool hwapi::vault_isBillVaultIn(void) const -{ - uint8_t ret; - - ret=epi_getDI_vaultSwitches(); // bit0: cash box 1: bill box in - if (ret & 2) - return true; - return false; -} - - - -uint8_t hwapi::door_getLocks(void) const -{ - // retval bit0: upper lever is up - // bit1: upper lever is down - // bit2: lower lever is up - // bit3: lower lever is down - - uint8_t ret; - - ret= epi_getDI_lockSwitches(); - // retval: bit 0: upper lockbar up bit1: upper lockbar is down - // bit 2: lower lockbar up bit1: lower lockbar is down - ret&=0x0F; - return ret; -} - -bool hwapi::door_upperDoorIsLocked(void) const -{ - uint8_t ret; - - ret= epi_getDI_lockSwitches(); - if (ret & 2) - return true; - return false; -} - -bool hwapi::door_upperDoorIsUnlocked(void) const -{ - uint8_t ret; - - ret= epi_getDI_lockSwitches(); - if (ret & 1) - return true; - return false; -} - -bool hwapi::door_lowerDoorIsLocked(void) const -{ - uint8_t ret; - - ret= epi_getDI_lockSwitches(); - if (ret & 8) - return true; - return false; -} - -bool hwapi::door_lowerDoorIsUnlocked(void) const -{ - uint8_t ret; - - ret= epi_getDI_lockSwitches(); - if (ret & 4) - return true; - return false; -} - - - -bool hwapi::bar_optoIn1isOn(void) const -{ - uint8_t ret=epi_getDI_optos(); - // bit0: opto in 1 1: opto in 2 - if (ret & 1) - return true; - return false; -} - -bool hwapi::bar_optoIn2isOn(void) const -{ - uint8_t ret=epi_getDI_optos(); - // bit0: opto in 1 1: opto in 2 - if (ret & 2) - return true; - return false; -} - - -uint8_t hwapi::aux_getAuxInputs(void) const -{ - // retval: bit0=Aux1....Bit5=Aux6 - // 0: input low 1:input high - - uint8_t ret=epi_getDI_auxIn(); - // bit0: auxin 1 ... 5: auxin 6 - ret &=0x3F; - return ret; -} - -bool hwapi::ptu_WakeINisActive(void) const -{ - return epi_getDI_ptuWake(); -} - -bool hwapi::mdb_WakeINisActive(void) const -{ - return epi_getDI_mdbWake(); -} - -bool hwapi::prn_readyINisActive(void) const -{ - return epi_getDI_prnReady(); -} - -bool hwapi::coid_isAttached(void) const -{ - return epi_getDI_CoinAttach(); -} - -bool hwapi::coin_escrowIsOpen(void) const -{ - return epi_getDI_CoinEscrow(); -} - -bool hwapi::mif_cardIsAttached(void) const -{ - return epi_getDI_mifareCardTapped(); -} - -//bool hwapi::mod_WakeINisActive(void) -//{ -// return epi_getDI_modemWake(); -//} - - - -bool hwapi::door_isContactPowerOn(void) const -{ - return epi_getDI_contactPwr(); -} - -bool hwapi::mif_isMifarePowerOn(void) const -{ - bool mo=indat_isMifareOn(); - bool mi=epi_getDI_mifarePwr(); - if (mo && mi) - return true; - return false; -} - -bool hwapi::mdb_testIsmdbTxDon(void) const -{ - return epi_getDI_mdbTxd(); -} - -bool hwapi::aux_isAuxPowerOn(void) const -{ - return epi_getDI_auxPwr(); -} - -bool hwapi::mod_isGsmPowerOn(void) const -{ - return epi_getDI_gsmPwr(); -} - -bool hwapi::cred_isCreditPowerOn(void) const -{ - return epi_getDI_creditPwr(); -} - -bool hwapi::prn_isPrinterPowerOn(void) const -{ - return epi_getDI_printerPwr(); -} - -uint8_t hwapi::prn_PrnFuseIsOk(void) const -{ - //retval: 0: fuse blown 1: fuse OK 2:unknown as printer power is off - if (!epi_getDO_printerPwr()) - return 2; // unknown as printer power is off - if (epi_getDI_printerPwr()) - return 1; // printer voltage is OK - return 0; // fuse blown -} - -bool hwapi::mdb_isMdbPowerOn(void) const -{ - return epi_getDI_mdbPwr(); -} - - -bool hwapi::cash_getRejectMotorHomePos(void) const -{ - return epi_getDI_rejectMotor_homepos(); -} - -uint8_t hwapi::cash_getLowPaperSensor(void) const -{ - // 0: Sensor sees paper 1: no paper 99: off - return epi_getDI_npe_sensor(); - -} - -// ------------------------------------------------------------------------------ -// Level1,2,3 RD request commands -// ------------------------------------------------------------------------------ - -// the following requests can be sent manually -// or automatically in background by: void hwapi::dc_autoRequest(bool on) -// in other words: -// if automatic-reading is on then there's no need to send any of these commands! - - -void hwapi::request_DC2serialConfig() const -{ - sendWRcmd_setSendCommand0(SEND_REQU_SERCONF); -} - -void hwapi::request_DC2_HWversion() const -{ - sendWRcmd_setSendCommand0(SEND_REQU_HWversion); -} - -void hwapi::request_DC2_SWversion() const -{ - sendWRcmd_setSendCommand0(SEND_REQU_SWversion); -} - -void hwapi::request_DC2_condition() const -{ - sendWRcmd_setSendCommand0(SEND_REQU_CONDITION); -} - -void hwapi::request_DC2_UID() const -{ - sendWRcmd_setSendCommand0(SEND_REQU_UID); -} - -void hwapi::request_DC2_TimeAndDate() const -{ - sendWRcmd_setSendCommand0(SEND_REQU_TIME); -} - -void hwapi::request_DC2_analogues() const -{ - sendWRcmd_setSendCommand0(SEND_REQU_ANALOGS); -} - -void hwapi::request_DC2_digitalInputs() const -{ - sendWRcmd_setSendCommand0(SEND_REQU_DIG_INPUTS); -} - -void hwapi::request_DC2_digitalOutputs() const -{ - sendWRcmd_setSendCommand0(SEND_REQU_DIG_OUTPUTS); -} - -// ------------------------------------------------------------------------------ -// the folowing device state requests are deployed only if device is powered up: - -void hwapi::request_PrinterHwState() const -{ - - sendWRcmd_setSendCommand0(SEND_REQU_PRN_STATE); -} - -void hwapi::request_PrinterCurrentFonts() const -{ - sendWRcmd_setSendCommand0(SEND_REQU_PRN_FONTS); -} - -void hwapi::request_PrinterStateComplete() const -{ - sendWRcmd_setSendCommand0(SEND_REQU_PRN_ALL); -} - - - - - -void hwapi::request_MifareReaderState() const -{ - sendWRcmd_setSendCommand0(SEND_REQU_MIFSTATE); -} - -void hwapi::request_MifareCardType() const -{ - //uint8_t blkAdr=0; - //sendWRcmd_setSendCommand4(SEND_REQU_MIFDATA, blkAdr,0,0,0); - sendWRcmd_setSendCommand0(SEND_REQU_MIFSTATE); -} - -void hwapi::request_MifareAtbType() const -{ - //sendWRcmd_setSendCommand0(SEND_REQU_MIF_ATB_TYPE); - sendWRcmd_setSendCommand0(SEND_REQU_MIFSTATE); - -} - -void hwapi::request_MifareID() const -{ - uint8_t sequenceNumber=0; - sendWRcmd_setSendCommand4(SEND_REQU_MIFDATA, sequenceNumber,0,0,0); // 1st data = card sequence =blk nr (0...15) -} - -void hwapi::request_MifareData(uint8_t dataBlockNumber) const -{ - if (dataBlockNumber<12) // 1k cards return 12 data blocks, 4k cards would return 54 data blocks (not implemented) - sendWRcmd_setSendCommand4(SEND_REQU_MIFDATA, dataBlockNumber,0,0,0); // 1st data = card sequence =blk nr (0...15) -} - - - -void hwapi::request_MDB_Status() const -{ - sendWRcmd_setSendCommand0(SEND_REQU_MDB_GETSTAT); -} - -//void hwapi::request_MDB_wakeInLine() const -//{ -// sendWRcmd_setSendCommand0(SEND_REQU_MDB_GETWAK); -//} - -void hwapi::request_MDB_lastResponse() const -{ - sendWRcmd_setSendCommand0(SEND_REQU_MDB_GETRESP); -} - -void hwapi::request_EMP_allParameters() const -{ - sendWRcmd_setSendCommand0(SEND_REQU_EMP_GETALL); -} - -void hwapi::request_EMP_lastCoin() const -{ - sendWRcmd_setSendCommand0(SEND_REQU_EMP_GETCOIN); - -} - - - -// ------------------------------------------------------------------------------ -// Level 3: readback digital outputs of connected devices -// these functions are not needed for normal operation -// but can be used to test and verify conditions - -// There are two options: -// 1) the important things like power-outputs and wake lines are -// measured at DC2-terminals (after transistors) and come as input to DC-board -// 2) others like Leds are read from µC-pins by DC-board -// ------------------------------------------------------------------------------ - -bool hwapi::test_getDO_mdbRXtst(void) const -{ - return epi_getDO_mdbRxTestOut(); -} - -uint8_t hwapi::lock_getDO_motors(void) const -{ - // bit0: upper lock forward bit 1 backward - // bit2: lower lock forward bit 3 backward - - return epi_getDO_motorOuts(); -} - -uint8_t hwapi::test_serialState(void) const -{ - // test on-board signals for the serials - // serial drv on/off, Serial mux1, Serial mux2 - - uint8_t ret=epi_getDO_serialSwitch(); - // serial drv on/off, Serial mux1, Serial mux2 - ret &=0x07; - return ret; -} - -bool hwapi::test_serialIsOn(void) const -{ - return epi_getDO_serialDriverIsOn(); -} - -bool hwapi::test_serialMux1isSetToPrinter(void) const -{ - return epi_getDO_serialMux1isSetToPrinter(); - // mux1 off: serial is switched to printer -} - -bool hwapi::test_serialMux1isSetToModem(void) const -{ - return epi_getDO_serialMux1isSetToModem(); - // mux1 on: serial is switched to modem -} - -bool hwapi::test_serialMux2isSetToCredit(void) const -{ - return epi_getDO_serialMux2isSetToCredit(); - // mux2 off: serial is switched to credit card terminal -} - -bool hwapi::test_serialMux2isSetToMifare(void) const -{ - return epi_getDO_serialMux2isSetToMifare(); - // mux2 on: serial is switched to mifare reader -} - -bool hwapi::led_coinIsOn(void) const -{ - return epi_getDO_led_coin(); -} - -bool hwapi::led_frontIsOn(void) const -{ - return epi_getDO_led_front(); -} - -bool hwapi::led_ticketIsOn(void) const -{ - return epi_getDO_led_ticket(); -} - -bool hwapi::led_pinIsOn(void) const -{ - return epi_getDO_led_pin(); -} - -bool hwapi::led_StartIsOn(void) const -{ - return epi_getDO_led_start(); -} - -bool hwapi::led_insideIsOn(void) const -{ - return epi_getDO_led_inside(); -} - -bool hwapi::fan_isOn(void) const -{ - return epi_getDO_fan(); -} - -bool hwapi::siren_isOn(void) const -{ - return epi_getDO_sirene(); -} - -bool hwapi::bar_relayIsOn(void) const -{ - return epi_getDO_relay(); -} - -bool hwapi::ptu_WakeOutIsOn(void) const -{ - return epi_getDO_ptuWake(); -} - -bool hwapi::aux_powerIsOn(void) const -{ - return epi_getDO_auxPower(); -} - - -bool hwapi::coin_shutterIsOpen(void) const -{ - return epi_getDO_coinShutterOpen(); -} - -bool hwapi::coin_shutterTestOutput(void) const -{ - return epi_getDO_coinShutterTest(); -} - -uint8_t hwapi::coin_escrowFlapOpened(void) const -{ - // retval: 1:return flap is open 2:take flap is open 0:closed - - return epi_getDO_coinEscrow(); -} - - - -void hwapi::sendDeviceSettings(uint8_t kindOfPrinter, uint8_t kindOfCoinChecker, - uint8_t kindOfMifareReader, uint8_t suppressSleep, - uint8_t kindOfModem, uint8_t kindOfCredit) const -{ - uint8_t buf[64]; - - tslib_strclr(buf,0,64); - buf[0]=kindOfPrinter; - buf[1]=kindOfCoinChecker; - buf[2]=kindOfMifareReader; - buf[3]=suppressSleep; - buf[4]=kindOfModem; - buf[5]=kindOfCredit; - - epi_store64ByteSendData(6, buf); - sendWRcmd_setSendCommand0(SENDDIRCMD_DEVICE_PARA); - - -} - -void hwapi::request_ReadbackDeviceSettings() const -{ - sendWRcmd_setSendCommand0(SEND_REQU_DEVICE_PARA); -} - - -void hwapi::readback_DeviceSettings(uint8_t *length, uint8_t *data) const -{ - - epi_restoreRbDeviceSettings(length, data); -/* - buf66[0]=devPara.kindOfPrinter; - buf66[1]=devPara.kindOfCoinChecker; - buf66[2]=devPara.kindOfMifareReader; - buf66[3]=devPara.suppressSleepMode; - buf66[4]=devPara.kindOfModem; - buf66[5]=devPara.kindOfCreditcard; - buf66[6]=devPara.CoinEscrow; - buf66[7]=devPara.CoinRejectUnit; - buf66[8]=devPara.CoinShutter; - buf66[9]=devPara.BillAcceptor; - buf66[10]=devPara.usevaultLock; - buf66[11]=devPara.autoAlarm; - buf66[12]=devPara.autoOpen; - buf66[13]=devPara.printAccReceipt; - buf66[14]=devPara.printDoorReceipt; - buf66[15]=devPara.printTokenTicket; - uitmp=devPara.VaultFullWarnLevel; - buf66[16]=swl_getOneByteFromUint(uitmp, GETLOWBYT); - buf66[17]=swl_getOneByteFromUint(uitmp, GETHIGHBYT); - uitmp=devPara.VaultFullErrorLevel; - buf66[18]=swl_getOneByteFromUint(uitmp, GETLOWBYT); - buf66[19]=swl_getOneByteFromUint(uitmp, GETHIGHBYT); - -*/ -} - -// .................................................................................... - -void hwapi::sendMachineID(uint16_t customerNr, uint16_t machineNr, - uint16_t borough, uint16_t zone, - uint16_t alias, char *location) const -{ - uint8_t buf[64]; - - tslib_strclr(buf,0,64); - buf[0]=uint2uchar(customerNr, LOWBYTE); - buf[1]=uint2uchar(customerNr, HIGHBYTE); - buf[2]=uint2uchar(machineNr, LOWBYTE); - buf[3]=uint2uchar(machineNr, HIGHBYTE); - buf[4]=uint2uchar(borough, LOWBYTE); - buf[5]=uint2uchar(borough, HIGHBYTE); - buf[6]=uint2uchar(zone, LOWBYTE); - buf[7]=uint2uchar(zone, HIGHBYTE); - buf[8]=uint2uchar(alias, LOWBYTE); - buf[9]=uint2uchar(alias, HIGHBYTE); - tslib_strcpy(location, &buf[10], 32); - - epi_store64ByteSendData(42, buf); - sendWRcmd_setSendCommand0(SENDDIRCMD_MACHINE_ID); - - -} - -void hwapi::request_ReadbackMachineID() const -{ - sendWRcmd_setSendCommand0(SEND_REQU_MACINE_ID); -} - - -void hwapi::readback_machineIDdata(uint8_t *length, uint8_t *data) const -{ - epi_restoreMachineIDsettings(length, data); -/* - buf66[0]=swl_getOneByteFromUint(machPara.customerNumber, GETLOWBYT); - buf66[1]=swl_getOneByteFromUint(machPara.customerNumber, GETHIGHBYT); - buf66[2]=swl_getOneByteFromUint(machPara.machineNumber, GETLOWBYT); - buf66[3]=swl_getOneByteFromUint(machPara.machineNumber, GETHIGHBYT); - buf66[4]=swl_getOneByteFromUint(machPara.borough, GETLOWBYT); - buf66[5]=swl_getOneByteFromUint(machPara.borough, GETHIGHBYT); - buf66[6]=swl_getOneByteFromUint(machPara.zone, GETLOWBYT); - buf66[7]=swl_getOneByteFromUint(machPara.zone, GETHIGHBYT); - buf66[8]=swl_getOneByteFromUint(machPara.alias, GETLOWBYT); - buf66[9]=swl_getOneByteFromUint(machPara.alias, GETHIGHBYT); - for (pp=0; pp<32; pp++) - buf66[10+pp]=machPara.location[pp]; - dc2prot_setReadData(42, buf66); - -*/ -} - - -// .................................................................................... - - - - - -static uint16_t hwapi_shutterTime; - -// locks, 2.Level: (Motor stops automatical on end switch or by 5s timeout) -uint8_t hwapi::lock_openUpperDoor(void) const -{ - //bool sendWRcmd_setSendCommand4(uint16_t nextCmd, uint8_t dat1, uint8_t dat2, uint8_t dat3, uint8_t dat4); - // commands are defined in PIdefines.h - sendWRcmd_setSendCommand4(SENDDIRCMD_OPENUP_DOOR, 1, 0, 0, 0); - // paras: dat2: 1=upper door lock 2=lower - // dat1: 1=open 2=close - return 0; -} - - -uint8_t hwapi::lock_closeUpperDoor(void) const -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_OPENUP_DOOR, 2, 0, 0, 0); - return 0; -} - -uint8_t hwapi::lock_openLowerDoor(void) const -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_OPENDN_DOOR, 1, 0, 0, 0); - return 0; -} - -uint8_t hwapi::lock_closeLowerDoor(void) const -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_OPENDN_DOOR, 2, 0, 0, 0); - return 0; -} - -void hwapi::shut_openOnce(void) const -{ - // and close automatic after shutter time - uint16_t zeit=hwapi_shutterTime; - zeit/=100; - sendWRcmd_setSendCommand4(SENDDIRCMD_SHUTOPENBYTIME, uint8_t(zeit) ,0,0,0); - -} - -void hwapi::shut_openForCoin(bool start) const -{ - // start=true: start opening flap if coin is attached - // start=false: stop process - - uint16_t zeit=hwapi_shutterTime; - zeit/=100; - sendWRcmd_setSendCommand4(SENDDIRCMD_SHUTOPENBYCOIN, uint8_t(start), uint8_t(zeit),0,0); - -} - -void hwapi::shut_sendOpeningTime(uint16_t timeIn_ms ) const -{ - // after this time without retrigger the flap is closed - //sendWRcmd_setSendCommand4(SENDDIRCMD_SHUT_SENDTIME, timeIn100ms,0,0,0); - hwapi_shutterTime=timeIn_ms; - -} - - -void hwapi::esc_takeMoney(void) const -{ - // and close automatically after escrow time (1s) - sendWRcmd_setSendCommand0(SENDDIRCMD_ESCRO_TAKE); -} - -void hwapi::esc_returnMoney(void) const -{ - // and close automatically after time - sendWRcmd_setSendCommand0(SENDDIRCMD_ESCRO_GIVE); - -} - - - - - - - -// ---------------------------------------------------------------------------------------------------------- -// --------------------------------------------- MIFARE ----------------------------------------------------- -// ---------------------------------------------------------------------------------------------------------- - - -uint8_t hwapi::mif_returnReaderStateAndCardType(uint8_t *buf, uint8_t maxBufferSize) const -{ - // retval 0=OK 1=error host buffer too small - - /* data description: - - new fast version: - byte 0= still the same: current read state: - 0=power off 1=reader-fault 2=ready - 3=just reading 4=read complete - 5=read partial, removed too early - 6=state unknown - - byte 1: reader state 1=ok 0=nok - byte 2: card present (0,1) - byte 3: card selected (0) - byte 4: card type: 0...5 - byte 5: card allowed (0=no 1=MifareClassic 1k or 4k) - byte 6: CardSize: 1 or 4 (kB) - byte 7: length of UID 4 or 7 (byte) - */ - - return epi_restoreMifState(buf, maxBufferSize); -} - -/* OLD data description: -byte 0: current read state: 0=power off 1=reader-fault 2=ready - 3=just reading 4=read complete - 5=read partial, removed too early - 6=state unknown -byte 1,2: read data length from card -3: 1=reader is OK (reported serial nr is OK) 0=wrong or no reader -4...15: reader version, expected "ATB25-1.8" -16: 1=card is present 0:not -17: 0 -18: card type reported from reader -19: 1=allowed card type 0=not -20: card size: 1 or 4 (dec) = card size -21: LengthOfUID: 4 or 7 (dec) (byte) -22: UID 8 byte in hex -byte 30: sector logged: 0 -byte 31: current sector: 0 -byte 32: result, always 0 -*/ - -bool hwapi::mif_readerIsOK(void) const -{ - - uint8_t buf[40]; // old version had 40 bytes, new version only 8 - uint8_t ret= epi_restoreMifState(buf, 40); - if (ret==0 && buf[0]>1 && buf[1]>0) - return 1; - return 0; // error -} - -bool hwapi::mif_cardAttached(void) const -{ - - uint8_t buf[40]; - uint8_t ret= epi_restoreMifState(buf, 40); - if (ret==0 && buf[0]>1 && buf[2]>0) // reader OK - if (buf[16]>0) - return 1; - return 0; // error -} - -uint8_t hwapi::mif_readResult(void) const -{ - // result: 0: unknown or still in progress - // 1: card read successful - // 2: reading error - - uint8_t buf[40]; - uint8_t ret= epi_restoreMifState(buf, 40); - // data read successful && Reader OK && card attached && ... - if (ret==0 && buf[1]>0 && buf[2]>0) - { -// byte 0: current read state: 0=power off 1=reader-fault 2=ready -// 3=just reading 4=read complete -// 5=read partial, removed too early -// 6=state unknown - - if (buf[0]==1 || buf[0]==5 || buf[0]==6) - return 2; - if (buf[0]==4) - return 1; - - } - return 0; // error - -} - - -QString hwapi::mif_cardUID(void) const -{ - QString myStr; - - uint8_t buf[65], ret; - - //uint8_t ret= epi_restoreMifState(buf, 40); - myStr.clear(); -/* - if (ret==0 && buf[0]==4 && buf[3]>0 && buf[16]>0 && buf[19]>0) - { - // UID in buf[22...29] - for (int ii=0;ii<8; ii++) - { - - myStr+=QString::number(buf[ii+22],16); - myStr+=" "; // make a gap between numbers - } - } -*/ - - ret=epi_restoreMifData(0, buf, 64); - if (ret) - return myStr; // return empty string on error - else - { - buf[8]=0; - //myStr.append(buf); - for (int ii=0;ii<8; ii++) - { - - myStr+=QString::number(buf[ii],16); // 16: return in hex format - myStr+=" "; // make a gap between numbers - } - - return myStr; - } - - -} - - -uint8_t hwapi::mif_getCardDataDec(uint8_t blkNr, uint8_t *buf, uint8_t maxBufferSize) const -{ - // blkNr=0...11 return buf[64] maxBufferSize must be >=64 - - return epi_restoreMifData(blkNr, buf, maxBufferSize); - // blkNr=0...11 return buf[64] - -} - -QString hwapi::mif_getCardDataStr(uint8_t blockNumber) const -{ - // with blockNumber=0...11 - QString myStr; - uint8_t buf[66]; - - myStr.clear(); - if (blockNumber>11) - return myStr; - - epi_restoreMifData(blockNumber, buf, 66); - - for (int ii=0; ii<64; ii++) - { - //myStr+=QString::number(buf[ii],10); // decimals as ascii - myStr+=QString::number(buf[ii],16); // hex numbers as ascii - myStr+=" "; // make a gap between numbers - } - return myStr; -} - - - - - -// ---------------------------------------------------------------------------------------------------------- -// --------------------------------------------- PRINTER ---------------------------------------------------- -// ---------------------------------------------------------------------------------------------------------- - -// already above: -// void hwapi::prn_switchPower(bool on) 0x2A01 -// bool hwapi::prn_readyINisActive(void) -// bool hwapi::prn_isPrinterPowerOn(void) -// void hwapi::request_PrinterHwState() 0x2A02 -// void hwapi::request_PrinterCurrentFonts() 0x2A12 -// void hwapi::request_PrinterStateComplete() // =request_PrinterHwState + request_PrinterCurrentFonts - -uint8_t hwapi::prn_getHwState(struct Tprn_hw_state *prn_hw_state) const -{ - // return printer hardware state: power is on? rs-driver on? rs_switch ok? hw-ready-line ok? - // printer on error or ok? - uint8_t prnHWstate[20]; - - epi_restorePrinterState(prnHWstate); - // byte 1...6 come right from printer, see printer manual - // byte 0 = all important infos: - // byte 0 = 0: prnter OK, >0: error - // bit0: paper low 1: no paper 2: temperature error - // 3: head open 4: paper jam in cutter - // 6: no response 7: bad response from printer - - prn_hw_state->powerRdBk = epi_getDI_printerPwr(); - prn_hw_state->rsSwOk = epi_getDO_serialMux1isSetToPrinter(); // mux1 off: serial is switched to printer - prn_hw_state->rsDrvOk = epi_getDO_serialDriverIsOn(); - prn_hw_state->ReadyLine = epi_getDI_prnReady(); - - if (prnHWstate[0]==0) - prn_hw_state->inIdle = true; // no errors - else - prn_hw_state->inIdle = false; // off or errors - - if (prnHWstate[0] & 1) - prn_hw_state->paperNearEnd=true; - else - prn_hw_state->paperNearEnd = false; - - if (prnHWstate[0] & 2) - prn_hw_state->noPaper=true; - else - prn_hw_state->noPaper = false; - - if (prnHWstate[0] & 4) - prn_hw_state->ErrorTemp=true; - else - prn_hw_state->ErrorTemp = false; - - if (prnHWstate[0] & 8) - prn_hw_state->HeadOpen=true; - else - prn_hw_state->HeadOpen = false; - - if (prnHWstate[0] & 16) - prn_hw_state->cutterJam=true; - else - prn_hw_state->cutterJam = false; - - - if (prnHWstate[0] & 64) - prn_hw_state->noResponse=true; - else - prn_hw_state->noResponse = false; - - if (prnHWstate[0] & 128) - prn_hw_state->badResponse=true; - else - prn_hw_state->badResponse = false; - return prnHWstate[0]; - -} - -bool hwapi::prn_isUpAndReady(void) const -{ - struct Tprn_hw_state prnHwNow; - - prn_getHwState(&prnHwNow); - if (prnHwNow.inIdle && prnHwNow.rsSwOk && prnHwNow.rsDrvOk && prnHwNow.powerRdBk ) - return true; - return false; -} - -void hwapi::prn_getCurrentFontSetting(struct Tprn_currentSettings *prn_fonts) const -{ - uint8_t prnFonts[22]; - - epi_restorePrinterFonts(&prnFonts[0]); - prn_fonts->currFont = prnFonts[0]; - prn_fonts->currSize = prnFonts[1]; - prn_fonts->currHeigth= prnFonts[2]; - prn_fonts->currWidth = prnFonts[3]; - prn_fonts->nowBold = prnFonts[4]; - prn_fonts->nowInvers = prnFonts[5]; - prn_fonts->nowUnderlined= prnFonts[6]; - prn_fonts->currDensity = prnFonts[7]; - prn_fonts->currSpeed = prnFonts[8]; - prn_fonts->nowAligned = prnFonts[9]; - -} - - -void hwapi::prn_sendText(QByteArray *buf) const -{ - sub_storeSendingText(buf); - epi_storeUserOfSendingTextBuffer(1,0,0,0,0); // 1=print text - - -} - - -void hwapi::prn_sendPrnSysCmd(uint8_t para1, uint8_t para2, uint32_t para3) const -{ - // send three byte through to printer, see printers manual - sendWRcmd_setSendCommand8(SENDDIRCMD_PRN_SYS_CMD, para1, para2, 0, para3); -} - -void hwapi::prn_sendPrnEscCmd(uint8_t para1, uint8_t para2, uint8_t para3, uint8_t para4) const -{ - // send four byte through to printer, see printers manual - sendWRcmd_setSendCommand4(SENDDIRCMD_PRN_ESC_CMD, para1, para2, para3, para4); -} - -void hwapi::prn_sendPrnSetup(uint16_t paperSpeed, uint8_t density, uint8_t alignment, uint8_t orientation) const -{ - // send 5 byte: byte 0,1: speed 5...250 mm/s - // byte2: density 0....(25)....50 - // byte3: alignment 'l', 'c', 'r' = left, center, right - // byte4: orientation 0, 90, 180 = 0°, 90°, 180° rotation (by now not supported!) - // not batched! don't use twice within 100ms - - uint8_t buf[10]; - uint16_t uitmp; - - uitmp=paperSpeed; - buf[0]=uint8_t(uitmp); - uitmp>>=8; - buf[1]=uint8_t(uitmp); - buf[2]=density; - buf[3]=alignment; - buf[4]=orientation; - buf[5]=0; - epi_store64ByteSendData(5, buf); - sendWRcmd_setSendCommand0(SENDDIRCMD_PRN_SETUP); -} - -void hwapi::prn_movePaper(uint8_t wayInMm, uint8_t direction) const -{ - //direction: 1=forward 2=backward - sendWRcmd_setSendCommand4(SENDDIRCMD_PRN_MOVE, wayInMm, direction, 0,0); -} - - -void hwapi::prn_setFonts(uint8_t font, uint8_t size, uint8_t width, uint8_t height) const -{ - // font = kind of font 0...8 - // size = 6...20, 9..9: too tiny 10: small ...12 = normal size ...20=huge - // width: 0...4 0=1x 1=2x 2=4x (huge!) 3=8x 4=16x (3,4 make no sense) - // heigth: 0...7 = 1x...8x only 0,1,2,(3) make sense - sendWRcmd_setSendCommand4(SENDDIRCMD_PRN_SETFONT, font, size, width, height); -} - - -void hwapi::prn_setLetters(uint8_t bold, uint8_t invers, uint8_t underlined) const -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_PRN_SETLETT, bold, invers, underlined, 0); -} - -void hwapi::prn_cut(uint8_t kindof) const -{ - // kindof = 1: full cut 2: partial cut 3=eject (5xLF + full cut) - sendWRcmd_setSendCommand4(SENDDIRCMD_PRN_CUT, kindof,0,0,0); -} - -void hwapi::prn_newLine(uint8_t nrOfLines) const -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_PRN_LF, nrOfLines, 0, 0, 0); -} - -void hwapi::prn_printCompleteFontTable(void) const -{ - sendWRcmd_setSendCommand0(SENDDIRCMD_PRN_FONTTAB); -} - - -void hwapi::prn_printBarcode(uint8_t kindOf, uint8_t withText, uint8_t offset, uint8_t rotation, uint8_t dataLeng, uint8_t *data) const -{ - uint8_t buf[66], nn; - //uint16_t uitmp; - - if (dataLeng>58) - dataLeng=58; - - buf[0]=kindOf; - buf[1]=withText; - buf[2]=offset; - buf[3]=rotation; - buf[4]=dataLeng; - // rest: Barcode-data: - for (nn=0; nn1278) - return false; - ticketTemplate.append(text); - qDebug()<<"\nText added "<1266) - return false; - ticketTemplate.append(tmpStr); - return true; -} - -bool hwapi::pri_TD_addCommand(char group, char attribute, char p1, char p2, char p3, char p4, char p5) const -{ - // always add 8 byte to the ticket layout: ESC & group & attribute & parameter1...5 - /* complete list of possible commands: - group 50 : paper - attribute 10 : move forward - p1: wayInMm p2: direction - attribute 11 : cut - p1: kind of, 1=full 2=partial, 3=eject - attribute 12 : new line(s) - p1: nr of lines 1...100 - - group 51 : fonts - attribute 10 : kind of font see description above - p1: possible: 0...22, expedient: 5...11 - attribute 11 : font size - p1: 6...20 12=normal 6=tiny - attribute 12 : font width - p1: 0...4 - attribute 13 : font heigth - p1: 0...7 - attribute 14 : switch bold print on/off - p1: 0=off 1=on - attribute 15 : switch invers print on/off - p1: 0=off 1=on - attribute 16 : switch underlined print on/off - p1: 0=off 1=on - - group 52 : print graphics - attribute 10 : print barcode with dynamic data 6 and 7 - p1...p5 = kindOf, withText, offset, rotation, dataLeng, see description above - attribute 11 : print QRcode with preset data - - attribute 12 : print Logo - p1=nrOfLogo, p2=offset - - group 53 : print dynamics - attribute 10 : 1...8 = print dynData 0..7 at this place - -*/ - - - char tmpStr[10]; - - // command has always fixed length of 8 byte - if (ticketTemplate.length()>1270) - return false; - if (group<50 || group>59) - return false; - if (attribute<10 || attribute>30) - return false; - - tmpStr[0]=0x1B; // ESC - tmpStr[1]=group; - tmpStr[2]=attribute; - tmpStr[3]=p1; - tmpStr[4]=p2; - tmpStr[5]=p3; - tmpStr[6]=p4; - tmpStr[7]=p5; - - ticketTemplate.append(tmpStr, 8); - - - qDebug()<<"\ncmd added "<1277) - return false; - ticketTemplate.append("\n"); - return true; -} - -bool hwapi::pri_TD_addSign(char sign) const -{ - if (ticketTemplate.length()>1277) - return false; - ticketTemplate.append(sign); - return true; -} - - -char hwapi::prn_clearDocument(uint8_t documentNumber) const -{ - if (documentNumber>15) - return false; - sendWRcmd_setSendCommand4(SENDDIRCMD_PRN_CLEARDOC, documentNumber, 0, 0, 0); - return true; -} - - -bool hwapi::prn_store_Document(uint8_t documentNumber ) const -{ - // send to DC - // documentNumber=0...15, stored in Eeprom - // maximal 1280 bytes each - // allowed: 0x20...0xFF, 0x0A, 0x0C, 0x1B (LF, CR, Esc) - // 0x1B=start of embedded command (next 7bytes = command) - - if (documentNumber>15) - return false; - sub_storeSendingText(&ticketTemplate); - epi_storeUserOfSendingTextBuffer(3,documentNumber,0,0,0); // 3=store document - return true; -} - - -bool hwapi::prn_printDocument(uint8_t documentNumber, struct T_dynDat *dynTicketData) const -{ - if (documentNumber>15) - return false; - epi_store64ByteSendData(64, &(dynTicketData->licensePlate[0])); - sendWRcmd_setSendCommand4(SENDDIRCMD_PRN_DOC, documentNumber, 0, 0, 0); - return true; -} - - - - - - -// ---------------------------------------------------------------------------------------------------------- -// ------------------------------------------- MDB Bus ------------------------------------------------------ -// ---------------------------------------------------------------------------------------------------------- - - - -void hwapi::mdb_sendBusReset(void) const -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_MDB_RES, 0,0,0,0); - -} - -#define mdb_device_coinChk 0 -#define mdb_device_changer 1 -#define mdb_device_bill 2 -//#define mdb_device_credit 3 // obsolete - - -void hwapi::mdb_sendCommand(uint8_t toMdbDevice, uint8_t mdbCommand) const -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_MDB_SENDCMD, toMdbDevice, mdbCommand, 0,0); - -} - -void hwapi::mdb_sendMessage(uint8_t toMdbDevice, uint8_t mdbCommand, uint8_t nrOfData, uint8_t *dataBuffer) const -{ - // nrOfData = sizeOf(dataBuffer) maximal 34 byte according mdb specs - uint8_t myBuf[64], ii; - - tslib_strclr(myBuf, 0, 64); - myBuf[0]=toMdbDevice; - myBuf[1]=mdbCommand; - if (nrOfData>34) nrOfData=34; - myBuf[2]=nrOfData; - for (ii=0; ii>=8; - myBuf[1]=uint8_t (uitmp); - myBuf[2]=tokenChannel; - pp=3; - for (ii=0; ii<16; ii++) - { - uitmp=coinDenomination[ii]; - myBuf[pp]=uint8_t(uitmp); - uitmp>>=8; - myBuf[pp+1]=uint8_t(uitmp); - pp+=2; - } - - epi_store64ByteSendData(35, myBuf); - sendWRcmd_setSendCommand0(SENDDIRCMD_EMP_SETT); - -} - -void hwapi::emp_pollingOnOff(uint8_t on) const -{ - // on: 1=start polling the coin accepter 0=stop - sendWRcmd_setSendCommand4(SENDDIRCMD_EMP_POLL, on,0,0,0); - -} - -void hwapi::emp_startCoinAcceptance(void) const -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_EMP_STARPPAY, 0,0,0,0); - -} - -void hwapi::emp_stopCoinAcceptance(void) const -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_EMP_STOPPAY, 0,0,0,0); - -} - - - -void hwapi::emp_getAllParameters(struct T_emp *emp) const -{ - uint8_t leng, data[66], ii, pp; - epi_restoreEmpSettings(&leng, data); // expected length = 64 byte - - // get 64 bytes about EMP: see h-file - - emp->gotSetup = data[0]; - emp->state = data[1]; - emp->shaft = data[2]; - emp->countryCode= uchar2uint(data[4], data[3]); - emp->scale = data[5]; - emp->decimals = data[6]; - for (ii=0; ii<16; ii++) - emp->coinValues[ii] = data[7+ii]; - emp->coinAccept = uchar2uint(data[24], data[23]); - emp->tokenChannel = data[25]; - emp->pollingRunning = data[26]; - emp->paymentRunning = data[27]; - - pp=28; - for (ii=0; ii<16; ii++) - { - emp->denomination[ii] = uchar2uint(data[pp+1], data[pp]); - pp+=2; - } - emp->routing= uchar2uint(data[61], data[60]); - -} - -/* -static bool emp_newCoin; -static uint8_t emp_newCoinSignal; -static uint16_t emp_newCoinValue; -static uint8_t emp_newCoinError; - -uint8_t hwapi::emp_chkIfCoinInserted(void) -{ - // retval: 1=got coin 0xFF=emp reported an error 0=got nothing - // comes only one time after each coin, vaslues are stored - uint8_t leng, data[8]; - - epi_restoreEmpCoinSignal(&leng, data); - // 5 byte per inserted coin: - // data[0]: 1=got coin, data set valid - // data[1]: emp-signal of last inserted coin - // data[2]: emp-error or warning - // data[3,4]: emp-value of last inserted coin 3=low byte - - //epi_clearEmpCoinSignal(); - - if (data[0]>0) - { - emp_newCoin=data[0]; // anything came in, coin or error or both - - if (data[0] & 0x80) - { - emp_newCoinError=data[4]; - } - if (data[0] &0x0F) - { - emp_newCoinSignal=data[1]; - emp_newCoinValue=uchar2uint(data[3], data[2]); - } - return emp_newCoin; - } - return 0; - -} - -uint8_t hwapi::emp_getInsertedCoinSignal(void) -{ - uint8_t uctmp=emp_newCoinSignal; - emp_newCoinSignal=0; // return only once - return uctmp; - -} - - -uint16_t hwapi::emp_getInsertedCoinValue(void) -{ - uint16_t uitmp=emp_newCoinValue; - emp_newCoinValue=0; // return only once - return uitmp; -} - -uint8_t hwapi::emp_getCoinError(void) -{ - uint8_t uctmp=emp_newCoinError; - emp_newCoinError=0; // return only once - return uctmp; -} -*/ - -uint8_t hwapi::emp_chkIfCoinInserted(void) const -{ - // retval: 0...16 coins left in FIFO - return epi_isNewCoinLeft(); -} - - -void hwapi::emp_getNewCoinRecord(uint8_t *valid, uint8_t *signal, uint8_t *error, uint16_t *value) const -{ - - epi_restoreEmpCoinSignal(valid, signal, error, value); -} - -uint8_t hwapi::emp_giveLastCoin(uint16_t *value, uint8_t *signal) const -{ - // retval: 0: NO coin stored 1: valid coin 2: got wrong coin or coin denied - // value: if retval1: value of the coin if reval=2: error number - // signal: channel nr reported from checker - - uint8_t valid, chan, error; - uint16_t wert; - - epi_restoreEmpCoinSignal(&valid, &chan, &error, &wert); - - if (valid && error==0xFF ) - { - *value=wert; - *signal=chan; - return 1; - } - - if (valid && error<0xFF ) - { - *value=error; - *signal=chan; // normally 0, but sometimes we get both - return 2; - } - return 0; -} - -uint8_t hwapi::emp_returnLastCoin(uint16_t *value, uint8_t *signal) const -{ - // use this for coin changer - - uint8_t valid, chan, error; - uint16_t wert; - - epi_restoreEmpCoinSignal(&valid, &chan, &error, &wert); - - if (error) - { - *value=0; - *signal=error; - return 0; - } - *value=wert; - *signal=chan; - return valid; -} - -// ---------------------------------------------------------------------------------------------------------- -// --------------------------------------------- Bill Validator ----------------------------------- -// ---------------------------------------------------------------------------------------------------------- -/* -// Coin checker and changer mdb4.2 / section 5 -// Level 2 Commands (predefined device msg acc. mdb manual and auto-poll) -uint8_t hwapi::mdb_bill_startPolling(bool on) -{ - // send ether one command (from list below) - // or a poll command in the proper polling grid (e.g. every 100ms) - epi_storeConfig08(mdbPollBills,on); - //sendWRcmd_setSendCommand0(SENDDIRCMD_WR_CONF_08); - return 0; -} - -// the following functions tell the DC to send a mdb command to any mdb slave -// in opposite to mdb_sendData() the exact telegrams don't have to be formed here, DC does it. -uint8_t hwapi::mdb_bill_reset() -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_MDB_BillAll, 1, 0, 0, 0); - - return 0; -} - -uint8_t hwapi::mdb_bill_setup() -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_MDB_BillAll, 2, 0, 0, 0); - - return 0; -} - -uint8_t hwapi::mdb_bill_security(uint16_t secLevel) -{ - - sendWRcmd_setSendCommand4(SENDDIRCMD_MDB_BillAll, 3, uint8_t(secLevel), uint8_t(secLevel>>8), 0); - - return 0; -} - -uint8_t hwapi::mdb_bill_pollManually(void) -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_MDB_BillAll, 4, 0, 0, 0); - - return 0; -} - -uint8_t hwapi::mdb_bill_billType(uint16_t billEnable, uint16_t escrowEnable) -{ - - sendWRcmd_setSendCommand4(SENDDIRCMD_MDB_BillType, - uint8_t(billEnable), uint8_t(billEnable>>8), - uint8_t(escrowEnable), uint8_t(escrowEnable>>8)); - - return 0; -} - -uint8_t hwapi::mdb_bill_escrow(uint8_t action) -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_MDB_BillAll, 5, action, 0, 0); - - return 0; -} - -uint16_t hwapi::mdb_bill_stacker(void) -{ - sendWRcmd_setSendCommand4(SENDDIRCMD_MDB_BillAll, 6, 0, 0, 0); - - return 0; -} - -uint8_t hwapi::mdb_bill_expansion(uint8_t subCmd, uint8_t send[32]) -{ - uint8_t sendbuf[34], nn; - - // 1) insert subCmd into buffer - for (nn=0; nn<32; nn++) - sendbuf[nn+1]=send[nn]; - sendbuf[0]=subCmd; - sendbuf[33]=0; - epi_storeMdbSendData(34, sendbuf); - sendWRcmd_setSendCommand0(SENDDIRCMD_MDB_BillExp); - return 0; -} - - -uint8_t hwapi::mdb_bill_gotPollResponse(void) -{ - // 0: no response 1: got ACK 2: got NAK 3 got ACK with additional data - return epi_getMdbResponse(); // request only once, then epi_getMdbRecLength()==0 - -} - - -uint8_t hwapi::mdb_bill_getDataLen(void) -{ - // return nr of byte received from any mdb device - return epi_getMdbRecLength(); -} - -uint8_t hwapi::mdb_bill_getPollData(uint8_t *mdb_data, uint8_t maxBufferSize) -{ - uint8_t len, buf[64], LL; - len=epi_getMdbRecLength(); - epi_restoreMdbRecData(buf); // request only once, then epi_getMdbRecLength()==0 - (maxBufferSizepowerRdBk=epi_restoreReadDIs(DIBYTE0, RB_VGSM); - if (epi_cntchk_swRs1toModem()) - mod_hw_state->rsSwOk=1; - else - mod_hw_state->rsSwOk=0; - - mod_hw_state->rsDrvOk=epi_cntchk_enabDrv01(); // can never be false - mod_hw_state->HwState=false; - mod_hw_state->CommState=false; - mod_hw_state->gotAnswer=false; - - return 0; -} - - -uint8_t hwapi::mod_setCondition(uint16_t chgCmd) -{ - // e.g. change to state registered, sleep, open, off.... - return uint8_t(chgCmd); -} - -uint16_t hwapi::mod_getCondition(void) -{ - // e.g. now socket open - - return 0; -} - -bool hwapi::mod_sendBufferFree(void) -{ - // sending allowed (before writing) and sending finished (after writing) - - return 0; -} - -void hwapi::mod_wantReadData(uint16_t nrOfData) -{ - // start reading - nrOfData=0; - -} - -uint8_t hwapi::mod_sendDataBlk(uint16_t len, uint8_t *buf) -{ - len=buf[0]; - return uint8_t(len); -} - -uint16_t hwapi::mod_gotData(void) -{ - // return nr of received bytes - - return 0; -} - -uint8_t hwapi::mod_loadDataBlk(uint16_t len, uint8_t *buf) -{ - len=buf[0]; - return uint8_t(len); - - -} - -uint8_t hwapi::mod_setupSerial(struct TserialParams serialParameter) -{ - // Baudrate and so on... - return 0; -} - -uint8_t hwapi::mod_getCurrentSerialSettings(struct TserialParams *serialParameter) -{ - // Baudrate and so on... - - return 0; -} -*/ - - - - - - - - - - -// neu, 25.8.21 - - - - -QString hwapi::dc_getTxt4RsDiagWin(void) const -{ - return epi_getTxt4RsDiagWin(); -} - -void hwapi::dc_clrTxt4RsDiagWin(void) const -{ - epi_clrTxt4RsDiagWin(); -} - -QString hwapi::dc_get2ndTxt4RsDiagWin(void) const -{ - return epi_get2ndTxt4RsDiagWin(); -} - -void hwapi::dc_clr2ndTxt4RsDiagWin(void) const -{ - epi_clr2ndTxt4RsDiagWin(); -} - -QString hwapi::dc_getTxt4HsStateLine(void) const -{ - // Crash! - return epi_getTxt4HsStateLine(); -} - -void hwapi::dc_clrTxt4HsStateLine(void) const -{ - epi_clrTxt4HsStateLine(); -} - - -QString hwapi::dc_getTxt4masterStateLine(void) const -{ - return epi_getTxt4masterStateLine(); -} - -void hwapi::dc_clrTxt4masterStateLine(void) const -{ - epi_clrTxt4masterStateLine(); -} - -QString hwapi::dc_getTxt4resultStateLine(void) const -{ - return epi_getTxt4resultStateLine(); -} - -void hwapi::dc_clrTxt4resultStateLine(void) const -{ - epi_clrTxt4resultStateLine(); -} - -QString hwapi::dc_getdataStateLine(void) const -{ - return epi_getTxt4dataStateLine(); -} - -void hwapi::dc_clrTxt4dataStateLine(void) const -{ - epi_clrTxt4dataStateLine(); -} - - -QString hwapi::dc_getdatifLine(void) const -{ - return epi_getTxt4datifLine(); -} - -void hwapi::dc_clrTxt4datifLine(void) const -{ - epi_clrTxt4datifLine(); -} - - - - -// using DC2 Bootloader - -void hwapi::bl_iniChain(void) const -{ - dcBL_iniChain(); -} - - -bool hwapi::bl_importBinFile(QByteArray readBinFile, uint32_t fileSize, char withDispl) const -{ - return dcBL_importBinFile(readBinFile, fileSize, withDispl); -} - -uint8_t hwapi::bl_activatBootloader(uint8_t *sendData) const -{ - return dcBL_activatBootloader(sendData); -} - -uint8_t hwapi::bl_startChain(void) const -{ - return dcBL_startChain(); -} - -uint8_t hwapi::bl_readBLversion(uint8_t *sendData) const -{ - // minimum size of sendData-buffer: 5byte retval: length - - return dcBL_readBLversion(sendData); -} - -uint8_t hwapi::bl_readFWversion(uint8_t *sendData) const -{ - // minimum size of sendData-buffer: 5byte retval: length - return dcBL_readFWversion(sendData); - -} - -uint8_t hwapi::bl_prepareDC_BLcmd(uint8_t Cmd, uint8_t SendDataLength, uint8_t *sendData, uint8_t *outBuf) const -{ -// make BL protocol, retval = outbuf length (5...133) -// bring data in correct form: start always with 0x02 finish with 0x03 and append checksum -// 0x02 Cmd < ...sendData ..> CRC CRC 0x03 -// Data length = 0...64 -// special conversion: if data contain 2 or 3 (STX, ETX) then write two bytes: 0x1B (=ESC) and data|0x80 -// so maxlength = 5 + 2 x 64 (if all data are 2 or 3) without 2,3: maxlength = 5 + 64 - - return dcBL_prepareDC_BLcmd(Cmd, SendDataLength, sendData, outBuf); - -} - -uint8_t hwapi::bl_exitBL(uint8_t *sendData) const -{ - // minimum size of sendData-buffer: 5byte retval: length - return dcBL_exitBL(sendData); -} - -void hwapi::led_switchLedIllumination(uint8_t on) const -{ - if (on) - { - - } - -} - - - -// neu, 25.3.23 - -// ------------------------------------------------------------------------------------ -// 27.3.2023: Use Device-Controller's Bootloader to send hex-file -// ------------------------------------------------------------------------------------ - -void hwapi::bl_rebootDC(void) const -{ - uint8_t len, buf[20]; - - len=dcBL_restartDC(buf); - sendWRcmd_setSendBlock160(len, buf); -} - -void hwapi::bl_startBL(void) const { - uint8_t len, buf[20]; - memset(buf, 0x00, sizeof(buf)); - - len=dcBL_activatBootloader(buf); - sendWRcmd_setSendBlock160(len, buf); -} - -bool hwapi::bl_checkBL(void) const -{ - uint8_t len, buf[20]; - - //len=dcBL_readBLversion(buf); - len=dcBL_readFWversion(buf); - sendWRcmd_setSendBlock160(len, buf); - - return (len > 0); -} - -bool hwapi::bl_isUp(void) const -{ - uint8_t receivedData[160]; - uint8_t LL; - - memset(receivedData, 0x00, sizeof(receivedData)); - - LL=epi_getRawRecLength(); - if (LL>0) - { - epi_getRawReceivedData(receivedData); - //epi_clrRawReceivedString(); - - //qDebug() << " *** got " << LL << " data bytes from BL: " << - // receivedData[0] << " " << receivedData[1] << " " << receivedData[2] << " " << - // receivedData[3] << " " << receivedData[4] << " " << receivedData[5] << " "; - - // response to "readFWversion" - if (receivedData[0]==2 && receivedData[1]==146 && receivedData[2]==45 && - receivedData[3]==45 && receivedData[4] ==95 && receivedData[5]==176) - { - dcBL_iniLoading(); - return true; - } - // response to "start BL" - if (receivedData[0]==2 && receivedData[1]==101 && receivedData[2]==48 && - receivedData[3]==223 && receivedData[4] ==131 ) - { - dcBL_iniLoading(); - return true; - } - - } - return false; -} - - -void hwapi::bl_sendAddress(uint16_t blockNumber) const -{ - // send start address, nr of 64byte-block, start with 0 - // will be sent only for folling block-numbers: - // 0, 1024, 2048, 3072 and 4096, so basically every 64kByte - uint32_t dcBL_BlkCtr=(uint32_t)blockNumber; - uint8_t len, buf[20]; - - tslib_strclr(buf, 0, 20); - if (dcBL_BlkCtr==0 || dcBL_BlkCtr==1024 || dcBL_BlkCtr==2048 || dcBL_BlkCtr==3072 || dcBL_BlkCtr==4096) - { - dcBL_BlkCtr*=64; - len=dcBL_sendFlashStartAddr2BL(dcBL_BlkCtr, buf); // make command string - // uint8_t dcBL_sendFlashStartAddr2BL(uint32_t startAddr, uint8_t *sendData) - // minimum size of sendData-buffer: 13byte retval: length (9...13) - sendWRcmd_setSendBlock160(len, buf); // send command to BL - } -} - -uint8_t hwapi::bl_wasSendingAddOK(void) const -{ - // return val: 0: no response by now 1:error 10: OK - - return dcBL_sendSuccess(0x21); - // return val: 0: no response by now 1:error 10: OK - // lastCommand=0x21 for sendAddr or 0x22 for send data - -} - -void hwapi::bl_openBinary(void) const -{ - - dcBL_loadBinary(0); -} - -void hwapi::bl_sendDataBlock(uint8_t length, uint8_t *buffer) const -{ - // send 64 byte from bin file - uint8_t LL=length, sendBuf[80], sendLen; - if (LL>64) LL=64; - - tslib_strclr(sendBuf,0,80); -/* hier ist alles richtig - qDebug() << "bl_sendDataBlock "<rtc_hour; - temp[1]= DateTime->rtc_min; - temp[2]= DateTime->rtc_sec; - temp[3]= 20; - temp[4]= DateTime->rtc_year; - temp[5]= DateTime->rtc_month; - temp[6]= DateTime->rtc_dayOfMonth; - temp[7]= DateTime->rtc_dayOfWeek; - b_ret=longFDcmd_set(20,0,0,8,temp); - return b_ret; -} - -bool hwapi::rtc_getExtendedTime(uint8_t *leng, uint8_t *data) const -{ - epi_restoreExtendedTime(leng, data); - return true; - -/* - buf[0]=GlobTime.Hours; - buf[1]=GlobTime.Min; - buf[2]=GlobTime.Sec; - buf[3]=GlobTime.Year; - buf[4]=GlobTime.Month; - buf[5]=GlobTime.Day; - buf[6]=GlobTime.DOW; - buf[7]=' '; // immer auf 32bit auffüllen sonst Speicherproblem beim Master! - uitmp=GlobTime.MinOfDay; - buf[8]=swl_getOneByteFromUint(uitmp, 0); - buf[9]=swl_getOneByteFromUint(uitmp, 1); - buf[10]=' '; - buf[11]=' '; - ultmp=GlobTime.SecOfDay; - buf[12]=swl_getOneByteFromUlong(ultmp, 0); - buf[13]=swl_getOneByteFromUlong(ultmp, 1); - buf[14]=swl_getOneByteFromUlong(ultmp, 2); - buf[15]=swl_getOneByteFromUlong(ultmp, 3); - - buf[16]=swl_isLeap(GlobTime.Year); - buf[17]=swl_getNextLeapYear(GlobTime.Year); - buf[18]=swl_getLastLeapYear(GlobTime.Year); - buf[19]=swl_hoursOfThisWeek(GlobTime.DOW, GlobTime.Hours); - - uitmp=swl_minutesOfThisWeek(GlobTime.DOW, GlobTime.Hours, GlobTime.Min); - buf[20]=swl_getOneByteFromUint(uitmp, 0); // 0=low byte 1=high byte - buf[21]=swl_getOneByteFromUint(uitmp, 1); - - uitmp=swl_hoursOfThisMonth(GlobTime.Day, GlobTime.Hours); - buf[22]=swl_getOneByteFromUint(uitmp, 0); - buf[23]=swl_getOneByteFromUint(uitmp, 1); - - uitmp=swl_minutesOfThisMonth(GlobTime.Day, GlobTime.Hours, GlobTime.Min); - buf[24]=swl_getOneByteFromUint(uitmp, 0); - buf[25]=swl_getOneByteFromUint(uitmp, 1); - - uitmp=swl_GetDaysOfYear(GlobTime.Year, GlobTime.Month, GlobTime.Day); - buf[26]=swl_getOneByteFromUint(uitmp, 0); - buf[27]=swl_getOneByteFromUint(uitmp, 1); - - uitmp=swl_GetHoursOfYear(GlobTime.Year, GlobTime.Month, GlobTime.Day, GlobTime.Hours); - buf[28]=swl_getOneByteFromUint(uitmp, 0); - buf[29]=swl_getOneByteFromUint(uitmp, 1); - buf[30]=0; - buf[31]=0; - ultmp= swl_GetMinutesOfYear(GlobTime.Year, GlobTime.Month, GlobTime.Day, - GlobTime.Hours, GlobTime.Min); - buf[32]=swl_getOneByteFromUlong(ultmp, 0); - buf[33]=swl_getOneByteFromUlong(ultmp, 1); - buf[34]=swl_getOneByteFromUlong(ultmp, 2); - buf[35]=swl_getOneByteFromUlong(ultmp, 3); - - buf[36]=rtc_getSqwaveSettings(); - buf[37]=0; - buf[38]=0; - buf[39]=0; - - ultmp= 0; // Minutes of the Millenium - buf[40]=swl_getOneByteFromUlong(ultmp, 0); - buf[41]=swl_getOneByteFromUlong(ultmp, 1); - buf[42]=swl_getOneByteFromUlong(ultmp, 2); - buf[43]=swl_getOneByteFromUlong(ultmp, 3); - - dc2prot_setReadData(44, buf); - - */ - -} - -bool hwapi::rtc_getExtendedTime(struct T_extTime *exTime) const -{ - uint8_t len; - uint16_t LL, nn; - uint8_t *start; - uint8_t buf[66]; - - epi_restoreExtendedTime(&len, buf); - // Puffer in struct eintragen: - LL=sizeof(struct T_extTime); - start = &(exTime->Hours); - nn=0; - do - { - *start = buf[nn]; - start++; - } while(++nn800) dateiLang=800; - tslib_strcpy(content, inhaltOfJson, dateiLang); // enthaelt genaue Laenge, Rest =0 - nrOfBlocks=dateiLang/64; - if (dateiLang%64>0) - nrOfBlocks++; - dateiLang=nrOfBlocks; - dateiLang<<=6; // auf volle 64byte aufgerundet - - // check free memory - frei=check4freeFDlongCmd(); - // Command-Stack sollte 16 Commands fassen, je 64byte Nutzdaten = 1024byte - // frei gibt also die Anzahl freier 64byte Bloecke zurueck - // das Json-File hat max 800 byte = 13 bloecke - if (frei<16) // Puffer muss ganz leer sein! nicht dass was durcheinander kommt - return false; - - // Start- und Stop auch als langes Kommando schicken - // PROBLEM: wuerden sie in einem anderen Batch gespeichert (short command stack), - // dann kann die Reihenfolge nicht gewaehrleistet werden - // Das Startkommando muss sicher zuerst kommen - // Das Abschlusskommando muss sicher zuletzt kommen - - tslib_strclr(temp,0,65); - temp[0]=dateiArt; - temp[1]=NummDesTempl; - longFDcmd_set(30, 0,0, 2,temp); // sende "Starte-file-DL" - uitmp=0; bn=0; - do - { - biox_CopyBlock(inhaltOfJson, uitmp, temp, 0, 64); - longFDcmd_set(31,0, bn++, 64, temp); - //uitmp<<=6; // falsch - uitmp+=64; - } while(uitmp < dateiLang); - - longFDcmd_set(32, 0,0, 0,temp); // Abschluss - - return true; -} - -//char prn_dynPrnVal[8][8]; -bool hwapi::prn_sendDynamicPrnValues(uint8_t *dynPrnVal ) const -// dynPrnVal = array of 8 Variables with 8 byte each, come as ascii string -// like: char prn_dynPrnVal[8][8]; -// return true if sending, false if cmd-stack is full -{ - - uint8_t temp[66]; - - - tslib_strcpy(dynPrnVal, temp, 64); // Vorsicht, kann \0en enthalten - return longFDcmd_set(33,0,0, 64, temp); - -} - - -bool hwapi::prn_printTemplate(uint8_t nrOftemplate) const - // print one of the templates loaded by Json prior - // nr = 1..32 -{ - // return true if sending, false if cmd-stack is full - - // 3.5.23: die dynVals und alle templates sollen am stück gesendet - uint8_t data[64]; - data[0]=nrOftemplate; - return longFDcmd_set(152, 0,0, 1, data); -} - -void hwapi::log_getHoldAccountNumbers(uint8_t *nrOfVals, uint16_t *accNr ) const -{ - // returns all acc nrs of the backuped vault records - // use: uint16_t backupedAccNumbers[8] - - epi_restoreDCbackupAccNr(nrOfVals, accNr); -} - - - -bool hwapi::log_selectVaultRecord(uint16_t accountNr ) const -{ - // return true if sending, false if cmd-stack is full - // and trigger transfer - - uint8_t dat1, dat2; - bool ret; - - uint8_t frei=check4freeFDshortCmd(); - if (frei<8) - return false; - - epi_iniVRstorage(); - dat1=uint2uchar(accountNr, LOWBYTE); - dat2=uint2uchar(accountNr, HIGHBYTE); - ret=sendFDcmd_set(153, 0,0, dat1,dat2,0,0); // select this record - // true means "will be sent" - sendFDcmd_set(0,38,0, 0,0,0,0); // return VaultRecord block-Nr.0 - sendFDcmd_set(0,38,1, 0,0,0,0); // return VaultRecord block-Nr.1 - sendFDcmd_set(0,38,2, 0,0,0,0); // return VaultRecord block-Nr.2 - sendFDcmd_set(0,38,3, 0,0,0,0); // return VaultRecord block-Nr.3 - sendFDcmd_set(0,38,4, 0,0,0,0); // return VaultRecord block-Nr.4 - sendFDcmd_set(0,38,5, 0,0,0,0); // return VaultRecord block-Nr.4 - // 38: <100 to get long 64byte response - - return ret; -} - -bool hwapi::log_chkIfVaultRecordAvailable(void) const -{ - // return true if completly received - return epi_checkIfVaultRecordAvailable(); - return false; -} - -bool hwapi::log_getVaultRecord(struct T_vaultRecord *retVR) const - // which was selected by: log_selectVaultRecord() - // to be forwarded to Ismas - // return true if completly received -{ - - uint16_t LL, nn, len; - char *start; - uint8_t buf[400]; - bool ret; - - ret=epi_restoreVaultRecord(&len, buf); // true if completly received - if (ret==false) - return false; - // Puffer in struct eintragen: - LL=sizeof(struct T_vaultRecord); // =320 - start = &retVR->startbuffer[0]; - nn=0; - do - { - *start = buf[nn]; - start++; - } while(++nnram; - nn=0; - do - { - *start = buf[nn]; - start++; - } while(++nnallDoorsDebounced; - nn=0; - do - { - *start = buf[nn]; - start++; - } while(++nn0) - { - // print was started - lastState=res; - } - } else - { - if (lastState==0) - { - // result hat sich auf 1 oder 2 geändert, d.h. Druck ist fertig - if (res==1) - { - - //emit hwapi_templatePrintFinished_OK(); - } else - if (res==2) - { - - //emit hwapi_templatePrintFinished_Err(); - } - lastState=res; - } - } - return res; -} - -uint8_t hwapi::prn_getCurrentPrinterState() const -{ - // 0: printer OK - // bit0: near paper end bit1: no paper - // bit2: temperature error bit3: error head open - // bit4: paper jam in cutter - // bit6: no response bit7: serial rec. error - // bit5: printer not ready - - - uint8_t lastPrinterStatus; - uint8_t buf[70], leng; - - // 2nd way to get dyn.conditions: - epi_restoreDynMachineConditions(&leng, buf); - lastPrinterStatus=buf[53]; - - return lastPrinterStatus; -} - - -// 21.4.23TS: change function "sendDeviceSettings()" to use this struct: "struct T_devices" -void hwapi::sys_sendDeviceParameter(struct T_devices *deviceSettings) const -{ - // same as "sendDeviceSettings()" but with much more data - uint8_t buf[64]; - uint16_t LL, nn; - tslib_strclr(buf,0,64); - uint8_t *start; - - // den gesamten struct in einen Puffer kopieren - LL=sizeof(struct T_devices); - start = &deviceSettings->kindOfPrinter; - nn=0; - do - { - buf[nn] = *start; - start++; - } while(++nnkindOfPrinter; - nn=0; - do - { - *start = buf[nn]; - start++; - } while(++nn0 in case of error - // is inncluded in sys_superviseSystem - - struct T_moduleCondition *modCond=0; - sys_getDeviceConditions(modCond); - - struct T_dynamicCondition *dynMaCond=0; - sys_getDynMachineConditions(dynMaCond); - - struct T_devices *devPara=0; - sys_restoreDeviceParameter(devPara); - - if (modCond->rtc>=200) - return 1; - if (modCond->printer==200 || modCond->printer==201) // 200: not connected 201: printer-HW-error 202: no paper - return 2; - if (modCond->printer==202) - return 3; - - if (modCond->coinBlocker>=200) - return 4; - if (modCond->mdbBus>=200) - return 5; - if (modCond->intEe>=200) - return 6; - - if (devPara->kindOfCoinChecker==1 || devPara->kindOfCoinChecker==2) // 0: without 1=EMP820 2=EMP900 3=currenza c² (MW) - { - if (modCond->coinChecker>=200 || modCond->coinEscrow>=200) - { - // Fehler Münzver. - return 7; - } - if (modCond->coinSafe>200) // 200: kasse fehlt 201: voll 100:fast voll 1:ok - { - return 8; - } - } else - if (devPara->kindOfCoinChecker==3) - { - if (modCond->changer>=200) - { - // Fehler Münzver. - return 7; - } - if (modCond->coinSafe>200) // 200: kasse fehlt 201: voll 100:fast voll 1:ok - { - return 8; - } - } - - if ( modCond->billReader>=200 && devPara->BillAcceptor>0) - { - // Fehler BNA - return 9; - } - - if (dynMaCond->onAlarm>0) - return 10; - - if (dynMaCond->modeAbrech>0) - return 11; - - if (dynMaCond->nowCardTest>0) - return 12; - - if (dynMaCond->startupTestIsRunning>0) - return 13; - - if (modCond->voltage>=200) - return 14; - if (modCond->temper>=200) - return 15; - - return 0; -} - - -// retrigger System-Check with: -// bool hwapi::sys_runCompleteTest(void) const - - -uint8_t hwapi::sys_superviseSystem(void) const -{ - // this function proofs if vending is possible depending of doors state - - struct T_dynamicCondition *dynMaCond=0; - struct T_moduleCondition *modCond=0; - - if (!gpi_areDcDataValid()) - { - // es gibt keinerlei gültige Daten vom DC - return 0; - } - - // jetzt sind die DC-Daten aktuell, also reinholen: - sys_getDynMachineConditions(dynMaCond); - sys_getDeviceConditions(modCond); - - if (!modCond->allModulesChecked) - { - // noch keine Testergebnisse - if (dynMaCond->startupTestIsRunning) - return 2; // Starttest läuft gerade - else - return 1; // Starttest ist noch nicht gelaufen - } - - // all doors: 99: undefined 0:closed 1:open - if (dynMaCond->lowerDoor || dynMaCond->upperDoor) - return 3; - if (dynMaCond->middleDoor) - return 4; - - if (sys_componentAssessment() >0) - return 5; // errors found - - return 6; // everything fine -} - - - -uint8_t hwapi::sys_getSystemErrors(void) const -{ - - return sys_componentAssessment(); - - -} - - diff --git a/DCPlugin/src/prot.cpp b/DCPlugin/src/prot.cpp deleted file mode 100644 index 95a40aa..0000000 --- a/DCPlugin/src/prot.cpp +++ /dev/null @@ -1,764 +0,0 @@ -#include "prot.h" -#include -#include "controlBus.h" -#include "dcBL.h" - - -T_prot::T_prot() -{ - - mySerialPort = new T_com(); - connect(mySerialPort, SIGNAL(receivingFinished()), this, SLOT( analyseRecData() )); - //connect(mySerialPort, SIGNAL(sendingFinished()), this, SLOT(sendeFin())); - - for (int nn=0; nnisPortOpen(); -} - -bool T_prot::isSerialFree(void) -{ - return true; // ohne HS's kann er nicht blockiert sein -} - -void T_prot::setRecLen(uint16_t WriteCmd) -{ - if (WriteCmd<100) - { - RdDataLength=DATALEN_RECEIVE_LONG; // store here already because it's no longer - // returned from slave - mySerialPort->receiveFixLen(TELEGRAMLEN_RECEIVE_LONG); - } else - { - RdDataLength=DATALEN_RECEIVE_FAST; - mySerialPort->receiveFixLen(TELEGRAMLEN_RECEIVE_FAST); - } -} - -void T_prot::setUserWriteData(uint16_t WriteCmd, uint16_t WrAddr, uint8_t WrDatLen, uint8_t *data) -{ - WriteCommand=WriteCmd; - WriteAddr=WrAddr; - WrDataLength=WrDatLen; - if (WrDataLength>FRAME_DATALEN) - WrDataLength=FRAME_DATALEN; - - for (int nn=0; nnsetRecLen(WriteCmd); - -} - -void T_prot::setUserWriteData(uint16_t WriteCmd, uint16_t WrAddr) -{ - WriteCommand=WriteCmd; - WriteAddr=WrAddr; - WrDataLength=0; - for (int nn=0; nnsetRecLen(WriteCmd); - -} - -void T_prot::setUserWriteData(uint16_t WriteCmd) -{ - WriteCommand=WriteCmd; - WriteAddr=0; - WrDataLength=0; - for (int nn=0; nnsetRecLen(WriteCmd); - -} - -void T_prot::setUserWrite1DB(uint16_t WriteCmd, uint16_t WrAddr, uint8_t val) -{ - // wie oben, jedoch einfachere Datenübergabe - WriteCommand=WriteCmd; - WriteAddr=WrAddr; - WrDataLength=1; - ui8OutputData[0]=val; - SendDataValid=1; // always set WR first - kindOfData=0; // 0: binaries, 1:text - this->setRecLen(WriteCmd); - -} - -void T_prot::setUserWrite2DB(uint16_t WriteCmd, uint16_t WrAddr, uint8_t val0, uint8_t val1) -{ - WriteCommand=WriteCmd; - WriteAddr=WrAddr; - WrDataLength=2; - ui8OutputData[0]=val0; - ui8OutputData[1]=val1; - SendDataValid=1; // always set WR first - kindOfData=0; // 0: binaries, 1:text - this->setRecLen(WriteCmd); - -} - -void T_prot::setUserWriteText(uint16_t WriteCmd, uint16_t WrAddr, uint8_t WrDatLen, char *data) -{ - WriteCommand=WriteCmd; - WriteAddr=WrAddr; - WrDataLength=WrDatLen; - if (WrDataLength>FRAME_DATALEN) - WrDataLength=FRAME_DATALEN; - - for (int nn=0; nnsetRecLen(WriteCmd); - -} - -void T_prot::setUserReadData( uint16_t ReadCmd, uint16_t RdAddr, uint16_t reserv) -{ - ReadCommand=ReadCmd; - ReadAddr=RdAddr; - reserve=reserv; - SendDataValid |=2; - readAddress=RdAddr; // store here already because it's no longer returned from slave - readSource=ReadCmd; -} - -void T_prot::setUserReadData( uint16_t ReadCmd, uint16_t RdAddr) -{ - ReadCommand=ReadCmd; - ReadAddr=RdAddr; - reserve=0; - SendDataValid |=2; - readAddress=RdAddr; // store here already because it's no longer returned from slave - readSource=ReadCmd; -} - -void T_prot::setUserReadData( uint16_t ReadCmd) -{ - ReadCommand=ReadCmd; - ReadAddr=0; - reserve=0; - SendDataValid |=2; - readAddress=0; // store here already because it's no longer returned from slave - readSource=ReadCmd; -} - -void T_prot::setBLsendData( uint8_t len, uint8_t *buf) -{ - for (int nn=0; nnBL_DATA_LEN) BLsendDataLength=BL_DATA_LEN; - for (int nn=0; nnsetRecLen(100); // how many?? - //readAddress= // needed?? - - //qDebug()<<"prot: got BL data " << len << "bytes, "; - //for (int i=0; ireceiveFixLen(nrOfbytesToReceive); -} - -void T_prot::sendUserData(uint16_t slaveAdr) -{ - // man könnte hier noch "SendDataValid" abfragen, - // muss immer 3 sein, muss man aber nicht - - //qDebug() << "prot send user data "<writeToSerial(packBuf_2, BLsendDataLength); - - - } else - startFastPacking(); // quicker since 15.12.21TS - //startPacking(); -} - -void T_prot::startFastPacking(void) -{ - uint16_t mycrc; - uint16_t sendLen; - uint8_t uctmp, nn, pp, CrcLp; - char sendBuffer[FRAME_MAXLEN], ctmp; - - //qDebug() << "prot start fast packing "<9 && WriteCommand<100) - { - // long command 10...99 - // WriteCommand==0 if only read request, then use short sending - sendBuffer[0]=STARTSIGN_SEND_LONG; - WrDataLength=DATALEN_SEND_LONG; // immer - //qDebug() << "send long cmd, len: " << WrDataLength; - } else - { - // fast command - sendBuffer[0]=STARTSIGN_SEND_FAST; - WrDataLength=DATALEN_SEND_FAST; // immer - //qDebug() << "send fast cmd, len: " << WrDataLength; - } - sendBuffer[1]= uint8_t(WriteCommand); - sendBuffer[2]= uint8_t(ReadCommand); - if (WriteAddr>0) - sendBuffer[3]= char(WriteAddr); // bei fast nur EINE adresse, wr hat Vorrang - else - sendBuffer[3]= char(ReadAddr); - // beim Fast prot. ist das reserve dann ists egal was drin steht - - if (kindOfData) // 0: binaries, 1:text - { - for (nn=0; nn>=8; - sendBuffer[CrcLp+1]=char(mycrc); - sendLen=CrcLp+2; - - // send to VCP: - QByteArray packBuff; - packBuff.clear(); - packBuff.append(sendBuffer, sendLen); // ohne sendLen wird beim ersten \0 abgeschnitten!!! - mySerialPort->writeToSerial(packBuff, sendLen); - -} - -/* -void T_prot::startPacking(void) -{ - uint16_t mycrc; - uint16_t uitmp, sendLen; - uint8_t uctmp, nn, pp, CrcLp; - char sendBuffer[FRAME_MAXLEN], ctmp; - - //qDebug() << "prot start packing "<>=8; - sendBuffer[2]= char(uitmp); - - uitmp=WriteCommand; - sendBuffer[3]= char(uitmp); - uitmp>>=8; - sendBuffer[4]= char(uitmp); - - uitmp=WriteAddr; - sendBuffer[5]= char(uitmp); - uitmp>>=8; - sendBuffer[6]= char(uitmp); - - uitmp=ReadCommand; - sendBuffer[7]= char(uitmp); - uitmp>>=8; - sendBuffer[8]= char(uitmp); - - uitmp=ReadAddr; - sendBuffer[9]= char(uitmp); - uitmp>>=8; - sendBuffer[10]= char(uitmp); - - uitmp=reserve; - sendBuffer[11]= '-'; //char(uitmp); - uitmp>>=8; - sendBuffer[12]= '-'; //char(uitmp); - - sendBuffer[13]= char(WrDataLength); - CrcLp= 14 + WrDataLength; - - if (kindOfData) // 0: binaries, 1:text - { - for (nn=0; nn>=8; - sendBuffer[CrcLp+1]=char(mycrc); - sendLen=CrcLp+2; - - sendBuffer[CrcLp+2]=13; - sendBuffer[CrcLp+3]=10; - sendLen+=2; - - // send to VCP: - QByteArray packBuff; - packBuff.clear(); - packBuff.append(sendBuffer, sendLen); // ohne sendLen wird beim ersten \0 abgeschnitten!!! - mySerialPort->writeToSerial(packBuff, sendLen); - // void T_com::writeToSerial(const QByteArray &data, uint16_t sendLength) -} -*/ - -// --------------------------------------------------------------------------------------------------------- -// receiving..... -// --------------------------------------------------------------------------------------------------------- - - -void T_prot::analyseRecData(void) -{ - // Aufruf per connect aus serialcontrol wenn Daten empfangen wurden - // getRecData(QByteArray &data, uint16_t &sendLength); - - QByteArray Indata; - QString myString, tempStr; -//char recBuffer[FRAME_MAXLEN]; -uint8_t recBuffer[FRAME_MAXLEN]; - - uint16_t recLength; - - INdataValid=false; - gpi_setTxt4HsStateLine(""); - gpi_setTxt4masterStateLine(""); - gpi_setTxt4resultStateLine(""); - gpi_setTxt4dataStateLine(""); - gpi_setTxt4datifLine(""); - - // read from "VCP": - mySerialPort->readFromSerial(Indata, recLength); -//qDebug()<<"prot: got data " << recLength; - if (recLength>FRAME_MAXLEN) - recLength=FRAME_MAXLEN; - for (int nn=0; nn0) - { - // dann anzeige - switch (result) - { - case 1: gpi_setTxt4masterStateLine("wrong length received"); break; - case 2: gpi_setTxt4masterStateLine("wrong start sign received"); break; - case 3: gpi_setTxt4masterStateLine("received datalen too big"); break; - case 4: gpi_setTxt4masterStateLine("wrong data len received"); break; - case 5: gpi_setTxt4masterStateLine("wrong crc received"); break; - - } - myString.setNum(result); - - // Daten abspeichern, könnten vom BL sein: - gpi_storeRawReceivedData(uint8_t(recLength), recBuffer); - emit rawDataRecieved(); - - } else - { - //& result ==0 - gpi_setTxt4masterStateLine("slave response OK"); - // Daten OK, also prüfe Inhalt. - // Konnte der Slave das Master-Command verwenden oder hatte es Fehler? - // konnte der Slave die geforderten Daten ausgeben (DOs, AOs)? - // konnte der Slave die geforderten Daten einlesen (AIs, DIs)? - - //CheckInResult(recBuffer); // Ergebnisse des Slaves anzeigen - // stimmt nicht mehr bei FastProt - - ShowFastInData(recBuffer); // Eingangs-Daten des Slaves anzeigen - } - emit framerecieved(); - //qDebug() << "framereceived emitted"; -} - - -uint8_t T_prot::FastCheckInData(uint8_t *Inbuf, uint16_t LL) -{ - - uint16_t rawInLen=LL, crcL_Addr, recCrc, myCrc, nn, datalen, nxt; - - if (Inbuf[0]!=STARTSIGN_RECEIVE_FAST && Inbuf[0]!=STARTSIGN_RECEIVE_LONG) - { - //qDebug() << "prot: got wrong start sign: " << Inbuf[0]; - return 2; // wrong start sign - } - if ( (rawInLen FRAME_DATALEN) //[9]=reported data lenght - return 3; // reported datalen too big - - if ((datalen !=(rawInLen-12)) && (datalen !=(rawInLen-13)) && (datalen !=(rawInLen-14)) ) - { - // angehängtes CR und/oder LF tolerieren - qDebug() << "wrong data length, " << datalen << " " << rawInLen; - return 4; // data len does not match to complete length - - } - crcL_Addr=datalen+10; // weil im definierten protocol 10 bytes vor den Daten stehen - recCrc=0; - - recCrc=uchar2uint(uint8_t(Inbuf[crcL_Addr+1]), uint8_t(Inbuf[crcL_Addr])); - myCrc=0; - for (nn=0; nnSlave) - switch (slaveresult) - { -// received message (from master) analysis: -// 0: got valid request -// this errors can only come back from a single device (not bus) -// or from a bus slave in local mode -// 1: wrong start 2: wrong length -// 3: wrong crc 4: wrong addr - - case 1: gpi_setTxt4resultStateLine("slave got wrong start sign"); break; - case 2: gpi_setTxt4resultStateLine("slave got wrong length"); break; - case 3: gpi_setTxt4resultStateLine("slave got wrong crc"); break; - case 4: gpi_setTxt4resultStateLine("slave got wrong addr"); break; - - case 10: gpi_setTxt4resultStateLine("slave is in local mode"); break; - case 13: gpi_setTxt4resultStateLine("local mode with wrong crc"); break; - case 14: gpi_setTxt4resultStateLine("local mode with wrong addr"); break; - // wenn 1..4 dann konnte der Slave das Mastertelegramm gar nicht verwenden, also hier Stoppen - } - if (slaveresult>0 && slaveresult<10) - return 1; - - // Slave hat gültiges Kommando empfangen: - // 2.result auswerten: - // recBuffer[3]; // Write result, d.h. Ergebnis des Schreibvorganges (z.B. DOs) des Slaves - // recBuffer[4]; // Read result, d.h. Ergebnis des Lesevorganges (z.B. DIs) des Slaves - // bisher nicht bekannt welche Fehlercodes es gibt, also den code direkt ausgeben. - // bisher bekannt: 0=OK - - myString.clear(); - myString = "Slave OUT and IN Result: "; - tempStr.setNum(Inbuf[3],16); - myString.append(tempStr); - myString.append(" "); - tempStr.setNum(Inbuf[4],16); - myString.append(tempStr); - gpi_setTxt4resultStateLine(myString); - return 0; -} - - - -uint8_t T_prot::ShowFastInData(uint8_t *recBuffer) -{ - QString myString=nullptr, tempStr=nullptr; - uint8_t result; - - RecSlaveAddr=0; - result=recBuffer[1]; // total result - result &=0x60; // only read result (bit 5,6) - - if (result==0) // read result =OK, - // dann sind die Eingangsdaten gültig - { - myString.append("valid INdata: "); - INdataValid=true; - //readSource already set with sending - readAddress=0; - // RdDataLength already set with sending - if (RdDataLength>FRAME_DATALEN) - RdDataLength=FRAME_DATALEN; - for (int ii=0; iiFRAME_DATALEN) - RdDataLength=FRAME_DATALEN; - for (int ii=0; ii -#include -#include -#include "tslib.h" -#include "sendWRcmd.h" - - -void indat_PrnPwr(void); - - -void sendWRcmd_INI(void) -{ - - sendWRcmd_clrCmdStack(); - sendWRcmd_clrCmd4Stack(); - sendFDcmd_clrStack(); - longFDcmd_clrStack(); -} - -// Command Stack for commands without parameters - - -static uint16_t nextAsynchsendCmd0[CMDSTACKDEPTH]; -static uint8_t nrOfCmdsInQueue; -/* convention: use simple (not rotating) FIFO Stack: -Example: nrOfCmdsInQueue=4 then - nextAsynchsendCmd0[0]=cmd1 // was stored as first - nextAsynchsendCmd0[1]=cmd2 - nextAsynchsendCmd0[2]=cmd3 - nextAsynchsendCmd0[3]=cmd4 // came in as last - - Send: [0] first, then move buffer 1 down: - nextAsynchsendCmd0[0]=cmd2 - nextAsynchsendCmd0[1]=cmd3 - nextAsynchsendCmd0[2]=cmd4 - nextAsynchsendCmd0[3]=0; - nrOfCmdsInQueue=3 now -*/ - -void sendWRcmd_clrCmdStack(void) -{ - uint8_t nn; - for (nn=0; nn=CMDSTACKDEPTH) - { - qDebug() << "cannot save cmd because stack is full"; - return false; // not possible - } - nextAsynchsendCmd0[nrOfCmdsInQueue++]=nextCmd; - //qDebug() << "PI cmd queued:"<< nextCmd << ", saved, pp=" << nrOfCmdsInQueue; - return true; // ok, will be sent -} - -uint16_t sendWRcmd_getSendCommand0(void) -{ - uint16_t nxtAsynchCmd; - uint8_t nn, ll; - if (nrOfCmdsInQueue==0 || nrOfCmdsInQueue>CMDSTACKDEPTH) - return 0; // error - nxtAsynchCmd=nextAsynchsendCmd0[0]; - - // move Puffer down by one element - if (CMDSTACKDEPTH>0) - ll=CMDSTACKDEPTH-1; - else - ll=0; - for (nn=0; nn0) - nrOfCmdsInQueue--; - //qDebug() << "PI cmd queued:"<< nxtAsynchCmd << ", restored, pp now =" << nrOfCmdsInQueue; - return nxtAsynchCmd; -} - -//--------------------------------------------------------------------------------------------------------------------- -//--------------------------------------------------------------------------------------------------------------------- -// Command Stack for commands with 4 parameters - - - -static uint16_t nextAsynchsendCmd4[CMD4STACKDEPTH]; -static uint8_t nextCmd4para1[CMD4STACKDEPTH]; -static uint8_t nextCmd4para2[CMD4STACKDEPTH]; -static uint8_t nextCmd4para3[CMD4STACKDEPTH]; -static uint8_t nextCmd4para4[CMD4STACKDEPTH]; -static uint8_t nrOfCmds4InQueue; -/* convention: use simple (not rotating) FIFO Stack: -Example: nrOfCmdsInQueue=4 then - nextAsynchsendCmd0[0]=cmd1 // was stored as first - nextAsynchsendCmd0[1]=cmd2 - nextAsynchsendCmd0[2]=cmd3 - nextAsynchsendCmd0[3]=cmd4 // came in as last - - Send: [0] first, then move buffer 1 down: - nextAsynchsendCmd0[0]=cmd2 - nextAsynchsendCmd0[1]=cmd3 - nextAsynchsendCmd0[2]=cmd4 - nextAsynchsendCmd0[3]=0; - nrOfCmdsInQueue=3 now -*/ - - -void sendWRcmd_clrCmd4Stack(void) -{ - uint8_t nn; - for (nn=0; nn=CMD4STACKDEPTH) - { - qDebug() << "cannot save cmd because stack is full"; - return false; // not possible - } - nextAsynchsendCmd4[nrOfCmds4InQueue]=nextCmd; - nextCmd4para1[nrOfCmds4InQueue]=dat1; - nextCmd4para2[nrOfCmds4InQueue]=dat2; - nextCmd4para3[nrOfCmds4InQueue]=dat3; - nextCmd4para4[nrOfCmds4InQueue]=dat4; - //qDebug() << "data with 4 data byte saved, pp=" << nrOfCmds4InQueue; - //qDebug() << " dat1=" << nextCmd4para1[nrOfCmds4InQueue] << " dat2=" << nextCmd4para2[nrOfCmds4InQueue] - // << " dat3=" << nextCmd4para3[nrOfCmds4InQueue] << " dat4=" << nextCmd4para4[nrOfCmds4InQueue]; - nrOfCmds4InQueue++; - return true; // ok, will be sent -} - -uint16_t sendWRcmd_getSendCommand4(uint8_t *dat1, uint8_t *dat2, uint8_t *dat3, uint8_t *dat4) -{ - uint16_t nxtAsynchCmd; - uint8_t nn, ll; - - if (nrOfCmds4InQueue==0 || nrOfCmds4InQueue>CMD4STACKDEPTH) - return 0; // error - nxtAsynchCmd=nextAsynchsendCmd4[0]; - *dat1=nextCmd4para1[0]; - *dat2=nextCmd4para2[0]; - *dat3=nextCmd4para3[0]; - *dat4=nextCmd4para4[0]; - //qDebug() << "cmd4 restored to send from [0]; pp=" << nrOfCmds4InQueue; - //qDebug() << " data1: " << nextCmd4para1[0] << " data2: " << nextCmd4para2[0] << - // " data3: " << nextCmd4para3[0] << " data4: " << nextCmd4para4[0]; - - // move Puffer down by one element - if (CMD4STACKDEPTH>0) - ll=CMD4STACKDEPTH-1; - else - ll=0; - for (nn=0; nn0) - nrOfCmds4InQueue--; - //qDebug() << "cmd4 after push down: pp=" << nrOfCmds4InQueue; - return nxtAsynchCmd; -} - - - - - -static uint16_t nextAsynchsendCmd8[CMD8STACKDEPTH]; -static uint8_t nextCmd8para1[CMD8STACKDEPTH]; -static uint8_t nextCmd8para2[CMD8STACKDEPTH]; -static uint16_t nextCmd8para3[CMD8STACKDEPTH]; -static uint32_t nextCmd8para4[CMD8STACKDEPTH]; -static uint8_t nrOfCmds8InQueue; - -void sendWRcmd_clrCmd8Stack(void) -{ - uint8_t nn; - for (nn=0; nn=CMD8STACKDEPTH) - { - qDebug() << "cannot save cmd because stack is full"; - return false; // not possible - } - nextAsynchsendCmd8[nrOfCmds8InQueue]=nextCmd; - nextCmd8para1[nrOfCmds8InQueue]=dat1; - nextCmd8para2[nrOfCmds8InQueue]=dat2; - nextCmd8para3[nrOfCmds8InQueue]=dat3; - nextCmd8para4[nrOfCmds8InQueue]=dat4; - nrOfCmds8InQueue++; - return true; // ok, will be sent -} - -uint16_t sendWRcmd_getSendCommand8(uint8_t *dat1, uint8_t *dat2, uint16_t *dat3, uint32_t *dat4) -{ - uint16_t nxtAsynchCmd; - uint8_t nn, ll; - - if (nrOfCmds8InQueue==0 || nrOfCmds8InQueue>CMD8STACKDEPTH) - return 0; // error - nxtAsynchCmd=nextAsynchsendCmd8[0]; - *dat1=nextCmd8para1[0]; - *dat2=nextCmd8para2[0]; - *dat3=nextCmd8para3[0]; - *dat4=nextCmd8para4[0]; - - // move buffer down by one element - if (CMD8STACKDEPTH>0) - ll=CMD8STACKDEPTH-1; - else - ll=0; - for (nn=0; nn0) - nrOfCmds8InQueue--; - return nxtAsynchCmd; -} - - - - - - - -static uint8_t sendAsynchDataBuf[160]; // no stack, only ONE buffer -static uint8_t sendAsyDatLen; - -bool sendWRcmd_setSendBlock160(uint8_t leng, uint8_t *buf) -{ - //qDebug() << "pi epi: storing send data"; - if (leng>160) leng=160; - sendAsyDatLen=leng; - tslib_strclr(sendAsynchDataBuf, 0, 160); - for (uint8_t nn=0; nn=MAXNROF_PRNBLOCKS) - return 1; // not possible, no free mem - - //len=tslib_strlen(buf); // kennt keine Binärzeichen!!!!!! - len=leng; - if (len>MAXNROF_PRNBYTES) - len=MAXNROF_PRNBYTES; - - tslib_strclr(Sdata_PRN_TEXT[pp], 0, MAXNROF_PRNBYTES); - - for (nn=0; nn0) - pPrnDataBuff--; - pp=pPrnDataBuff; - // example: pp=4: then buffers [0...3] are still occupied, pp=0: all buffers empty - - // now clear highest copyed line (which got free now) - tslib_strclr(Sdata_PRN_TEXT[pp], 0, MAXNROF_PRNBYTES); - - // optionally: clear all remaining higher lines: - for (nn=(pp+1); nn0: nr of 64byte-blocks - return (pPrnDataBuff); -} - - - - - - - - - - -// --------------------------------------------------------------------------------- -// 11.4.23 neu, Kommando direkt an "FastDevice"-protokoll senden, nicht mehr umsetzen -// --------------------------------------------------------------------------------- - - -// short command, 4 data bytes -static uint8_t nextFDwrCmd[FDCMD_STACKDEPTH]; -static uint8_t nextFDrdCmd[FDCMD_STACKDEPTH]; -static uint8_t nextFDblkNr[FDCMD_STACKDEPTH]; - -static uint8_t nextFDpara1[FDCMD_STACKDEPTH]; -static uint8_t nextFDpara2[FDCMD_STACKDEPTH]; -static uint8_t nextFDpara3[FDCMD_STACKDEPTH]; -static uint8_t nextFDpara4[FDCMD_STACKDEPTH]; -static uint8_t p_nextFDcmdsInQueue; -/* convention: use simple (not rotating) FIFO Stack: -Example: nrOfCmdsInQueue=4 then - nextAsynchsendCmd0[0]=cmd1 // was stored as first - nextAsynchsendCmd0[1]=cmd2 - nextAsynchsendCmd0[2]=cmd3 - nextAsynchsendCmd0[3]=cmd4 // came in as last - - Send: [0] first, then move buffer 1 down: - nextAsynchsendCmd0[0]=cmd2 - nextAsynchsendCmd0[1]=cmd3 - nextAsynchsendCmd0[2]=cmd4 - nextAsynchsendCmd0[3]=0; - nrOfCmdsInQueue=3 now -*/ - - -void sendFDcmd_clrStack(void) -{ - uint8_t nn; - for (nn=0; nn=FDCMD_STACKDEPTH) - { - qDebug() << "cannot save cmd because stack is full"; - return false; // not possible - } - nextFDwrCmd[p_nextFDcmdsInQueue]=nextWrCmd; - nextFDrdCmd[p_nextFDcmdsInQueue]=nextRdCmd; - nextFDblkNr[p_nextFDcmdsInQueue]=blockNum; - nextFDpara1[p_nextFDcmdsInQueue]=dat1; - nextFDpara2[p_nextFDcmdsInQueue]=dat2; - nextFDpara3[p_nextFDcmdsInQueue]=dat3; - nextFDpara4[p_nextFDcmdsInQueue]=dat4; - //qDebug() << "data with 4 data byte saved, pp=" << nrOfCmds4InQueue; - //qDebug() << " dat1=" << nextCmd4para1[nrOfCmds4InQueue] << " dat2=" << nextCmd4para2[nrOfCmds4InQueue] - // << " dat3=" << nextCmd4para3[nrOfCmds4InQueue] << " dat4=" << nextCmd4para4[nrOfCmds4InQueue]; - p_nextFDcmdsInQueue++; - return true; // ok, will be sent -} - -bool sendFDcmd_get(uint8_t *nextWrCmd, uint8_t *nextRdCmd, uint8_t *blockNum, uint8_t *dat1, uint8_t *dat2, uint8_t *dat3, uint8_t *dat4) -{ - uint8_t nn, ll; - - if (p_nextFDcmdsInQueue==0 || p_nextFDcmdsInQueue>FDCMD_STACKDEPTH) - return false; // not possible - - *nextWrCmd=nextFDwrCmd[0]; - *nextRdCmd=nextFDrdCmd[0]; - *blockNum=nextFDblkNr[0]; - *dat1=nextFDpara1[0]; - *dat2=nextFDpara2[0]; - *dat3=nextFDpara3[0]; - *dat4=nextFDpara4[0]; - //qDebug() << "cmd4 restored to send from [0]; pp=" << nrOfCmds4InQueue; - //qDebug() << " data1: " << nextCmd4para1[0] << " data2: " << nextCmd4para2[0] << - // " data3: " << nextCmd4para3[0] << " data4: " << nextCmd4para4[0]; - - // move Puffer down by one element - if (FDCMD_STACKDEPTH>0) - ll=FDCMD_STACKDEPTH-1; - else - ll=0; - for (nn=0; nn0) - p_nextFDcmdsInQueue--; - //qDebug() << "cmd4 after push down: pp=" << nrOfCmds4InQueue; - return true; // ok, will be sent -} - -uint8_t check4FDshortCmd(void) -{ - // returns number of waiting command, max FDCMD_STACKDEPTH - return p_nextFDcmdsInQueue; -} - - -uint8_t check4freeFDshortCmd(void) -{ - // returns number of free places in short-command stack - return FDCMD_STACKDEPTH - p_nextFDcmdsInQueue; -} - - -// long command, 64 data bytes -static uint8_t longFDwrCmd[FDLONG_STACKDEPTH]; -static uint8_t longFDrdCmd[FDLONG_STACKDEPTH]; -static uint8_t longFDblkNr[FDLONG_STACKDEPTH]; -static uint8_t longFDlength[FDLONG_STACKDEPTH]; - -static uint8_t longFDpara[FDLONG_STACKDEPTH][64]; -static uint8_t p_longFDcmdsInQueue; - - -void longFDcmd_clrStack(void) -{ - uint8_t nn, mm; - for (nn=0; nn=FDLONG_STACKDEPTH) - { - qDebug() << "cannot save cmd because stack is full"; - return false; // not possible - } - longFDwrCmd[p_longFDcmdsInQueue]=nextWrCmd; - longFDrdCmd[p_longFDcmdsInQueue]=nextRdCmd; - longFDblkNr[p_longFDcmdsInQueue]=blockNum; - longFDlength[p_longFDcmdsInQueue]=length; - for (nn=0; nn<64; nn++) - longFDpara[p_longFDcmdsInQueue][nn]=data[nn]; - - p_longFDcmdsInQueue++; - return true; // ok, will be sent -} - -bool longFDcmd_get(uint8_t *nextWrCmd, uint8_t *nextRdCmd, uint8_t *blockNum, uint8_t *length, uint8_t *data) -{ - uint8_t nn, mm, ll; - - if (p_longFDcmdsInQueue==0 || p_longFDcmdsInQueue>FDLONG_STACKDEPTH) - return false; // not possible - - *nextWrCmd= longFDwrCmd[0]; - *nextRdCmd= longFDrdCmd[0]; - *blockNum = longFDblkNr[0]; - *length = longFDlength[0]; - for (mm=0; mm<64; mm++) - data[mm] = longFDpara[0][mm]; - - // move Puffer down by one element - if (FDLONG_STACKDEPTH>0) - ll=FDLONG_STACKDEPTH-1; - else - ll=0; - for (nn=0; nn0) - p_longFDcmdsInQueue--; - - return true; // ok, will be sent -} - -uint8_t check4FDlongCmd(void) -{ - // returns number of waiting command - return p_longFDcmdsInQueue; -} - -uint8_t check4freeFDlongCmd(void) -{ - // returns number of free places in command stack - return FDLONG_STACKDEPTH - p_longFDcmdsInQueue; -} - - - - -static uint8_t Sdata_DeviceParameter[64]; -static uint8_t Sdata_DevParaLen; - -uint8_t epi_store64BdevParameter(uint8_t length, uint8_t *buf) -{ - // HWapi writes data to be stored - uint8_t nn; - for (nn=0; nn -#include - -#ifdef QT_POSIX_IPC - // The POSIX backend can be explicitly selected using the -feature-ipc_posix - // option to the Qt configure script. If it is enabled, the QT_POSIX_IPC - // macro will be defined. -> we use SystemV shared memory -#error "QT_POSIX_IPC defined" -#else -#include // ftok -#endif - -// std::atomic_bool SharedMemBuffer::__sharedMemLocked{false}; - -QSharedMemory *SharedMemBuffer::getShm(std::size_t size) { - static QSharedMemory shMem; - if (size > 0) { - static const long nativeKey = ftok("/etc/os-release", 'H'); - static const QString fkey = std::to_string(nativeKey).c_str(); - shMem.setKey(fkey); - if (!shMem.isAttached()) { - if (shMem.create(size)) { - return &shMem; - } else { - if (shMem.error() == QSharedMemory::AlreadyExists) { - if (shMem.attach()) { - return &shMem; - } - } - } - qCritical() << shMem.nativeKey() << shMem.key() << shMem.data() - << shMem.error() << shMem.errorString(); - return nullptr; - } - } - return &shMem; -} diff --git a/DCPlugin/src/storeINdata.cpp b/DCPlugin/src/storeINdata.cpp deleted file mode 100644 index 4f4035b..0000000 --- a/DCPlugin/src/storeINdata.cpp +++ /dev/null @@ -1,1336 +0,0 @@ -#include -#include - -#include -#include -#include "storeINdata.h" -#include "tslib.h" -#include "shared_mem_buffer.h" - - -// 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) - - -// store power on/off condition of the devices to control the data request - -static bool indat_savePrnPwr; - -void indat_storePrinterPower(bool isOn) { - indat_savePrnPwr=isOn; -} - -bool indat_isPrinterOn() { - return indat_savePrnPwr; -} - -static bool indat_saveMifPwr; - -void indat_storeMifarePower(bool isOn) { - indat_saveMifPwr=isOn; -} - -bool indat_isMifareOn() { - return indat_saveMifPwr; -} - -static bool indat_MdbIsOn; - -void indat_storeMDBisOn(bool isOn) { - indat_MdbIsOn=isOn; -} - -bool indat_isMdbOn() { - return indat_MdbIsOn; -} - -void gpi_storeSlaveSerParams(uint8_t slaveBaudRate, uint8_t NrDataBits, - uint8_t parity, uint8_t NrStopBits) { - // store numbers - SharedMemBuffer::getData()->ndbs = NrDataBits; - SharedMemBuffer::getData()->pari = parity; - SharedMemBuffer::getData()->nsb = NrStopBits; - SharedMemBuffer::getData()->br = slaveBaudRate; -} - -void epi_getSlaveSerParams(uint8_t *slaveBaudRate, uint8_t *NrDataBits, - uint8_t *parity, uint8_t *NrStopBits) { - - *NrDataBits = SharedMemBuffer::getDataConst()->ndbs; - *parity = SharedMemBuffer::getDataConst()->pari; - *NrStopBits = SharedMemBuffer::getDataConst()->nsb; - *slaveBaudRate = SharedMemBuffer::getDataConst()->br; -} - -QString epi_getSlaveParamSTR() { - QString mySt; - - switch (SharedMemBuffer::getDataConst()->br) { - case 1: mySt="1200 ";break; - case 2: mySt="9600 ";break; - case 3: mySt="19200 ";break; - case 4: mySt="38400 ";break; - case 5: mySt="57600 ";break; - case 6: mySt="115200 ";break; - } - - char ctmp = SharedMemBuffer::getDataConst()->ndbs; - ctmp += 0x30; - mySt.append(ctmp); - ctmp = SharedMemBuffer::getDataConst()->pari; - mySt.append(ctmp); - ctmp = SharedMemBuffer::getDataConst()->nsb; - ctmp += 0x30; - mySt.append(ctmp); - return mySt; -} - -// static QString genStrings[MAXNROF_GENSTR]; - // 0=HW 1=SW 2=State - -void gpi_storeGenerals(uint8_t genNr, QString text) { - // 0=HW 1=SW 2=State - if (genNr < MAXNROF_GENSTR) { - strncpy(&SharedMemBuffer::getData()->genStrings[genNr][0], - text.toStdString().c_str(), - sizeof(SharedMemBuffer::getDataConst()->genStrings[0])); - } -} - -QString epi_loadGenerals(uint8_t genNr) { - if (genNr < MAXNROF_GENSTR) { - if (genNr==2) { // DC2 State is shorter (8byte, not 64) - //genStrings[2][8]=0; - SharedMemBuffer::getData()->genStrings[2][8] = '\0'; - } - return QString(SharedMemBuffer::getDataConst()->genStrings[genNr]); - } - return " "; -} - -// ------------------------------- - -void gpi_storeUID(uint8_t const *buf8byteUid) { - uint64_t udltmp=0; - - for (int ii=0; ii<8; ii++) { - SharedMemBuffer::getData()->Sdata.UIDstr[ii] = buf8byteUid[ii]; - udltmp |= buf8byteUid[ii]; - udltmp <<= 8; - } - SharedMemBuffer::getData()->Sdata.slaveUID = udltmp; -} - -void epi_getUIDdec(uint8_t *buf8byteUid) { - for (int ii=0; ii<8; ii++) { - buf8byteUid[ii] = SharedMemBuffer::getDataConst()->Sdata.UIDstr[ii]; - } -} - -QString epi_getUIDstr() { - // die UID besteht aus 8 bytes (8 dezimalzahlen) - // -> umformen in hexstring - - QString myStr; - for (int ii=0;ii<8; ii++) { - myStr += QString::number(SharedMemBuffer::getDataConst()->Sdata.UIDstr[ii], 16); - myStr += " "; - } - return myStr; -} - -void gpi_backupSquareMode(uint8_t squMode) { - SharedMemBuffer::getData()->getGlobalTime.squareOutMode = squMode; -} - -uint8_t epi_getSquareMode() { - return SharedMemBuffer::getDataConst()->getGlobalTime.squareOutMode; -} - -void gpi_backupTime(uint8_t *timeBuffer, uint8_t Leng) { - /* - // Daten kommen in gleicher Reihenfolge vom Slave - uint8_t *pTime; - pTime=&getGlobalTime.hour; - if (Leng>44) Leng=44; // mehr brauch ma ned - for (int nn=0; nngetGlobalTime.second = Leng; // nur damit CompilerWarnung weg ist - - SharedMemBuffer::getData()->getGlobalTime.DayOfWeek = timeBuffer[0]; - SharedMemBuffer::getData()->getGlobalTime.minute = timeBuffer[1]; - SharedMemBuffer::getData()->getGlobalTime.second = timeBuffer[2]; - SharedMemBuffer::getData()->getGlobalTime.hour = timeBuffer[3]; - SharedMemBuffer::getData()->getGlobalTime.Year = timeBuffer[4]; - SharedMemBuffer::getData()->getGlobalTime.Month = timeBuffer[5]; - SharedMemBuffer::getData()->getGlobalTime.DayOfMonth = timeBuffer[6]; -} - -void epi_getTime(uint8_t *hh, uint8_t *mm, uint8_t *ss) { - *hh = SharedMemBuffer::getDataConst()->getGlobalTime.hour; - *mm = SharedMemBuffer::getDataConst()->getGlobalTime.minute; - *ss = SharedMemBuffer::getDataConst()->getGlobalTime.second; -} - -void epi_getDate(uint8_t *yy, uint8_t *mm, uint8_t *dd) { - *yy = SharedMemBuffer::getDataConst()->getGlobalTime.Year; - *mm = SharedMemBuffer::getDataConst()->getGlobalTime.Month; - *dd = SharedMemBuffer::getDataConst()->getGlobalTime.DayOfMonth; -} - -void epi_getToday(uint8_t *dow, uint16_t *minOfToday, uint32_t *secOfToday) { - *dow = SharedMemBuffer::getDataConst()->getGlobalTime.DayOfWeek; - *minOfToday = SharedMemBuffer::getDataConst()->getGlobalTime.MinutesOfToday; - *secOfToday = SharedMemBuffer::getDataConst()->getGlobalTime.SecondsOfToday; -} - -bool epi_isLeapYear(uint8_t *lastLeapYear, uint8_t *NextLeapYear) { - *lastLeapYear = SharedMemBuffer::getDataConst()->getGlobalTime.lastLeap; - *NextLeapYear = SharedMemBuffer::getDataConst()->getGlobalTime.nextLeap; - return SharedMemBuffer::getDataConst()->getGlobalTime.IsLeapyear; -} - -bool epi_isLeapYear() { - return SharedMemBuffer::getDataConst()->getGlobalTime.IsLeapyear; -} - -void epi_getSpecialWeekTimeDate(uint8_t *DayOfWeek, - uint8_t *HoursOfWeek, - uint16_t *MinutesOfWeek) { - *DayOfWeek = SharedMemBuffer::getDataConst()->getGlobalTime.DayOfWeek; - *HoursOfWeek = SharedMemBuffer::getDataConst()->getGlobalTime.hoursOfWeek; - *MinutesOfWeek = SharedMemBuffer::getDataConst()->getGlobalTime.minOfWeek; -} - -void epi_getSpecialMonthTimeDate(uint8_t *DayOfMonth, - uint16_t *HoursOfMonth, - uint16_t *MinutesOfMonth) { - *DayOfMonth = SharedMemBuffer::getDataConst()->getGlobalTime.DayOfMonth; - *HoursOfMonth = SharedMemBuffer::getDataConst()->getGlobalTime.hoursOfMonth; - *MinutesOfMonth = SharedMemBuffer::getDataConst()->getGlobalTime.minOfMonth; -} - -void epi_getSpecialYearTimeDate(uint16_t *DayOfYear, - uint16_t *HoursOfYear, - uint32_t *MinutesOfYear) { - *DayOfYear = SharedMemBuffer::getDataConst()->getGlobalTime.dayOfYear; - *HoursOfYear = SharedMemBuffer::getDataConst()->getGlobalTime.hoursOfYear; - *MinutesOfYear = SharedMemBuffer::getDataConst()->getGlobalTime.minOfYear; -} - -QString epi_getRtcTimeStr(uint8_t timeStyle) { - // style: 0: hh:mm 1: hh:mm:ss - QString mystr=nullptr, tempStr=nullptr; - - tempStr.setNum(SharedMemBuffer::getDataConst()->getGlobalTime.hour, 10); - mystr=tempStr.rightJustified(2,'0',false); // macht feste Länge, 5->05 - mystr.append(':'); - tempStr.setNum(SharedMemBuffer::getDataConst()->getGlobalTime.minute, 10); - //mystr.append(tempStr); - mystr+=tempStr.rightJustified(2,'0',false); - //mystr.append(':'); // so - //mystr+=':'; // oder so, =gleich - - if (timeStyle==1) // hh:mm:ss - { - mystr.append(':'); - tempStr.setNum(SharedMemBuffer::getDataConst()->getGlobalTime.second, 10); - mystr.append(tempStr.rightJustified(2,'0',false)); // wie += - } - return mystr; -} - -QString epi_getRtcDateStr(uint8_t dateStyle) { - // 1=german dd.mm.yy 2=american yy/mm/dd 3=mm.dd.yy - QString tmpStr=nullptr, YYstr=nullptr, MMstr=nullptr, DDstr=nullptr, mystr=nullptr; - mystr.clear(); - - tmpStr.setNum(SharedMemBuffer::getDataConst()->getGlobalTime.Year, 10); - YYstr=tmpStr.rightJustified(4,'0',false); // immer vierstellig - YYstr[0]='2'; // 2000 dazu - - tmpStr.setNum(SharedMemBuffer::getDataConst()->getGlobalTime.Month, 10); - MMstr=tmpStr.rightJustified(2,'0',false); - - tmpStr.setNum(SharedMemBuffer::getDataConst()->getGlobalTime.DayOfMonth, 10); - DDstr=tmpStr.rightJustified(2,'0',false); - - if (dateStyle==1) // Germany dd.mm.yy - { - mystr=DDstr + '.' + MMstr + '.' + YYstr; - } else - if (dateStyle==2) // american yy/mm/dd - { - mystr=YYstr + '/' + MMstr + '/' + DDstr; - } else - // mm.dd.yy - { - mystr=MMstr + '.' + DDstr + '.' + YYstr; - } - return mystr; -} - - -QString epi_getSlaveTimeDateStr() { - QString myStr; - myStr=epi_getRtcTimeStr(1) + " " + epi_getRtcDateStr(1); - return myStr; - -} - -// /////////////////////////////////////////////////////////////////////////////////// -// analog values -// /////////////////////////////////////////////////////////////////////////////////// - - -uint8_t gpi_getMaxNrAIs() { - return MAXNROF_AI; -} - -void gpi_storeAIs(uint8_t aiNr, uint16_t val) { - if (aiNr < MAXNROF_AI) { - SharedMemBuffer::getData()->AI_val[aiNr] = val; - } -} - -uint16_t epi_loadAIs(uint8_t aiNr) { - if (aiNr < MAXNROF_AI) { - return SharedMemBuffer::getDataConst()->AI_val[aiNr]; - } - return 0; -} - - -//-------------- -// measurement values -// ADC0: temp -// 1: voltage -// 2: brightness - -uint32_t epi_loadMeasureValue(uint8_t ValueNr) { - // ValueNr 0=ADC0, 1=ADC1 aso... - if (ValueNr < MAXNROF_MEASURE) { - return SharedMemBuffer::getDataConst()->Sdata.measurement[ValueNr]; - } - return 0; -} - -void gpi_storeMeasureValue(uint8_t ValueNr, uint32_t val) { - // in mV, also bis 65,535V - if (ValueNr < MAXNROF_MEASURE) { - SharedMemBuffer::getData()->Sdata.measurement[ValueNr] = val; - } -} - -QString epi_getSlaveTemperatureStr() { - char myStr[8], halfDegree=0, Minus=0, oneChar; - int16_t val=0, pp, einer, zehner; - QString myqStr; - - //qDebug() << "AIN0: " << epi_loadAIs(0) << "AIN1: " << epi_loadAIs(1); - - uint32_t meas_temper=epi_loadMeasureValue(MEASCHAN_TEMPERATURE); - // im SaxFormat gespeichert, hier umwandeln in String - - //qDebug() << "meas_temper: " << meas_temper; - - - for (pp=0; pp<8; pp++) myStr[pp]=0; - if (meas_temper&1) // ungerade, also ,5°C - { - halfDegree=1; - meas_temper &=0xFFFE; // um 0,5°C abrunden - } - if (meas_temper<100) - { - Minus=1; - val=int16_t(meas_temper)/2; - val-=50; - } else - { - val=int16_t(meas_temper)-100; - val/=2; - } - pp=0; // pointer auf string - if (Minus) - myStr[pp++]='-'; - // val is now 0..150 for pos Temp or 0..49 for negativ temperature - if (val<10) - { - // only one digit, just change to ascii - oneChar = char(val)+0x30; - if (tslib_isDecAsciiNumber(oneChar)) - myStr[pp++]=oneChar; - else - myStr[pp++]='0'; - } else - if (val<100) - { - // 10...99 - einer=val%10; - zehner=val/10; - //myStr[pp++]=char(zehner); - //myStr[pp++]=char(einer); - - oneChar = char(zehner)+0x30; - if (tslib_isDecAsciiNumber(oneChar)) - myStr[pp++]=oneChar; - else - myStr[pp++]='0'; - - oneChar = char(einer)+0x30; - if (tslib_isDecAsciiNumber(oneChar)) - myStr[pp++]=oneChar; - else - myStr[pp++]='0'; - - } else - { - // 100...150 - myStr[pp++]='1'; // hunderter Stelle immer 1 - val-=100; - einer=val%10; - zehner=val/10; - //myStr[pp++]=char(zehner)+0x30; - //myStr[pp++]=char(einer)+0x30; - oneChar = char(zehner)+0x30; - if (tslib_isDecAsciiNumber(oneChar)) - myStr[pp++]=oneChar; - else - myStr[pp++]='0'; - - oneChar = char(einer)+0x30; - if (tslib_isDecAsciiNumber(oneChar)) - myStr[pp++]=oneChar; - else - myStr[pp++]='0'; - } - myStr[pp++]=','; - if (halfDegree) - myStr[pp++]='5'; - else - myStr[pp++]='0'; - myqStr.clear(); - myqStr.append(myStr); - myqStr.append("°C"); - return myqStr; -} - -QString epi_getSlaveVoltageStr() -{ - // value in "meas_volt" in mV, also bis 65,535V. Value range [6000...16000] (6V...16V) - QString myqStr; - uint32_t vor, nach, tmp32; - uint16_t pp; - char myStr[12], ke; //, kz, kh; - - uint32_t ultmp=epi_loadMeasureValue(MEASCHAN_VOLTAGE); - for (pp=0; pp<12; pp++) myStr[pp]=0; - - //qDebug() << ultmp << "mV"; - - myqStr.clear(); - vor=ultmp/1000; - //qDebug() << "vor: " << vor; - - nach=ultmp%1000; - //qDebug() << "nach: " << nach; - pp=0; - if (vor>9) - { - myStr[pp++]=char(vor/10)+0x30; - } - myStr[pp++]=char(vor%10)+0x30; - myStr[pp++]=','; - - ke=char(nach/100); - //qDebug() << "ke: " << ke; - myStr[pp++]=char(ke)+0x30; - - tmp32=nach%100; - ke=char(tmp32/10); - //qDebug() << "ke: " << ke; - myStr[pp++]=char(ke)+0x30; - - tmp32=nach%10; - ke=char(tmp32); - //qDebug() << "ke: " << ke; - myStr[pp++]=char(ke)+0x30; - - - myStr[pp++]='V'; - myqStr.append(myStr); - return myqStr; -} - - - -// /////////////////////////////////////////////////////////////////////////////////// -// digital inputs -// /////////////////////////////////////////////////////////////////////////////////// - -/* come all in with 0x1201: -D0: upper door D1: low door D2:vault door -D3: cash box D4: bill box in -D5: bit 0: upper lockbar up bit1:down -D6: bit 0: lower lockbar up bit1:down - -D7: 0 -D7: DI_contact Power Is On - -D8: OptoIn 1,2 -D9: Aux0...5 -D10:Wake from ptu -D11: DI Wake From Mdb -D12: Ready from printer -D13: Coin Shutter Input -D14: CoinEscrow switch -D15: Mifare IN -D16: Modem_Wake In - -D18: DI Mif Pwr is on -D19: DI MDB_TxD_rdBack -D20: DI Aux Pwr is on -D21: DI GSM Pwr from PO2 is ON -D22: DI Credit Pwr from PO2 is on - =DI RdBack Credit Wake -D23: DI Printer Pwr from PO2 is on -D24: DI MDB Pwr from PO2 is on - */ - -void gpi_storeDI_doorSwitches(uint8_t upperDoor, - uint8_t lowerDoor, - uint8_t vaultDoor) { - SharedMemBuffer::getData()->din.doorSwitch = 0; - if (upperDoor) SharedMemBuffer::getData()->din.doorSwitch |= 1; - if (lowerDoor) SharedMemBuffer::getData()->din.doorSwitch |= 2; - if (vaultDoor) SharedMemBuffer::getData()->din.doorSwitch |= 4; -} - -uint8_t epi_getDI_doorSwitches(void) { - // bit0: upper door 1: low door 2:vault door - return SharedMemBuffer::getDataConst()->din.doorSwitch; -} - -void gpi_storeDI_vaultSwitches(uint8_t CashBoxIn, uint8_t BillBoxIn) { - SharedMemBuffer::getData()->din.vaultSwitch = 0; - if (CashBoxIn) SharedMemBuffer::getData()->din.vaultSwitch |= 1; - if (BillBoxIn) SharedMemBuffer::getData()->din.vaultSwitch |= 2; -} - -uint8_t epi_getDI_vaultSwitches(void) { - // bit0: cash box 1: bill box in - return SharedMemBuffer::getData()->din.vaultSwitch; -} - -void gpi_storeDI_lockSwitches(uint8_t indatUL, uint8_t indatLL) { - // D5: bit 0: upper lockbar up bit1:down - // D6: bit 0: lower lockbar up bit1:down - SharedMemBuffer::getData()->din.lockSwitch = 0; - if (indatUL & 1) SharedMemBuffer::getData()->din.lockSwitch |= 1; - if (indatUL & 2) SharedMemBuffer::getData()->din.lockSwitch |= 2; - if (indatLL & 1) SharedMemBuffer::getData()->din.lockSwitch |= 4; - if (indatLL & 2) SharedMemBuffer::getData()->din.lockSwitch |= 8; -} - -uint8_t epi_getDI_lockSwitches(void) { - // retval: bit 0: upper lockbar up bit1: upper lockbar is down - // bit 2: lower lockbar up bit1: lower lockbar is down - return SharedMemBuffer::getData()->din.lockSwitch; -} - -void gpi_storeDI_optos(uint8_t indatOpto) { - // OptoIn bit 0,1: optoin 1,2 - SharedMemBuffer::getData()->din.opto = 0; - if (indatOpto & 1) SharedMemBuffer::getData()->din.opto |= 1; - if (indatOpto & 2) SharedMemBuffer::getData()->din.opto |= 2; -} - -uint8_t epi_getDI_optos(void) { - // bit0: opto in 1 1: opto in 2 - return SharedMemBuffer::getDataConst()->din.opto; -} - -uint8_t gpi_storeDI_auxIn(uint8_t aux) { // Aux0...5 - return SharedMemBuffer::getData()->din.aux = aux; -} - -uint8_t epi_getDI_auxIn(void) { // bit0: auxin 1 ... 5: auxin 6 - return SharedMemBuffer::getDataConst()->din.aux; -} - -bool gpi_storeDI_ptuWake(bool w) { - return SharedMemBuffer::getData()->din.wakeFromPtu = w; -} - -bool epi_getDI_ptuWake(void) { - return SharedMemBuffer::getDataConst()->din.wakeFromPtu; -} - -bool gpi_storeDI_mbdWake(bool w) { - return SharedMemBuffer::getData()->din.wakeFromMdb = w; -} - -bool epi_getDI_mdbWake(void) { - return SharedMemBuffer::getDataConst()->din.wakeFromMdb; -} - -bool gpi_storeDI_prnReady(bool ready) { - return SharedMemBuffer::getData()->din.PrnReady = ready; -} - -bool epi_getDI_prnReady(void) { - return SharedMemBuffer::getDataConst()->din.PrnReady; -} - -bool gpi_storeDI_CoinAttach(bool attach) { - return SharedMemBuffer::getData()->din.CoinAttach = attach; -} - -bool epi_getDI_CoinAttach(void) { - return SharedMemBuffer::getDataConst()->din.CoinAttach; -} - -bool gpi_storeDI_CoinEscrow(bool ce) { - return SharedMemBuffer::getData()->din.CoinEscrowOpen = ce; -} - -bool epi_getDI_CoinEscrow(void) { - return SharedMemBuffer::getDataConst()->din.CoinEscrowOpen; -} - -bool gpi_storeDI_mifareCardTapped(bool tapped) { - return SharedMemBuffer::getData()->din.mifCardTap = tapped; -} - -bool epi_getDI_mifareCardTapped(void) { - return SharedMemBuffer::getDataConst()->din.mifCardTap; -} - -bool gpi_storeDI_modemWake(bool w) { - return SharedMemBuffer::getData()->din.wakeFromModem = w; -} - -bool epi_getDI_modemWake(void) { - return SharedMemBuffer::getDataConst()->din.mifCardTap; -} - -bool gpi_storeDI_contactPowerIsOn(bool on) { - return SharedMemBuffer::getData()->din.contactPwrOn = on; -} - -bool epi_getDI_contactPwr(void) { // invertiert! - return !SharedMemBuffer::getDataConst()->din.contactPwrOn; -} - -bool gpi_storeDI_MifarePowerIsOn(bool on) { - return SharedMemBuffer::getData()->din.mifarePwrOn = on; -} - -bool epi_getDI_mifarePwr(void) { - return SharedMemBuffer::getDataConst()->din.mifarePwrOn; -} - -bool gpi_storeDI_readbackMdbTxD(bool rdbkMdbTxd) { - return SharedMemBuffer::getData()->din.rdbk_mdbTxd = rdbkMdbTxd; -} - -bool epi_getDI_mdbTxd(void) { - return SharedMemBuffer::getDataConst()->din.rdbk_mdbTxd; -} - -bool gpi_storeDI_AuxPowerIsOn(bool on) { - return SharedMemBuffer::getData()->din.AuxPwrOn = on; -} - -bool epi_getDI_auxPwr(void) { - return SharedMemBuffer::getDataConst()->din.AuxPwrOn; -} - -bool gpi_storeDI_GsmPowerIsOn(bool on) { - return SharedMemBuffer::getData()->din.gsmPwrOn = on; -} - -bool epi_getDI_gsmPwr(void) { - return SharedMemBuffer::getDataConst()->din.gsmPwrOn; -} - -bool gpi_storeDI_CreditPowerIsOn(bool on) { - // invertieren!!! - return SharedMemBuffer::getData()->din.creditPwrOn = !on; -} - -bool epi_getDI_creditPwr(void) { - return SharedMemBuffer::getDataConst()->din.creditPwrOn; -} - -bool gpi_storeDI_PrinterPowerIsOn(bool on) { - return SharedMemBuffer::getData()->din.printerPwrOn = on; -} - -bool epi_getDI_printerPwr(void) { - return SharedMemBuffer::getDataConst()->din.printerPwrOn; -} - -bool gpi_storeDI_MdbPowerIsOn(bool on) { - return SharedMemBuffer::getData()->din.mdbPwrOn = on; -} - -bool epi_getDI_mdbPwr(void) { - return SharedMemBuffer::getDataConst()->din.mdbPwrOn; -} - -bool gpi_storeDI_rejMot_home(bool reject) { - return SharedMemBuffer::getData()->din.rejMot_home = reject; -} - -bool epi_getDI_rejectMotor_homepos(void) { - return SharedMemBuffer::getDataConst()->din.rejMot_home; -} - -uint8_t gpi_storeDI_paperLow(uint8_t sensor) { - // 0: Sensor sees paper 1: no paper 99: off - return SharedMemBuffer::getData()->din.npe_sensor = sensor; -} - -uint8_t epi_getDI_npe_sensor(void) { - return SharedMemBuffer::getDataConst()->din.npe_sensor; -} - - - -// /////////////////////////////////////////////////////////////////////////////////// -// readaback digital outputs -// /////////////////////////////////////////////////////////////////////////////////// - - -/* -D0 bit0: MDB devices 0=off 1=on - bit1: MDB bus power - bit2: MDB WakeOut - -D1=Printer -D2=Credit -D3=Modem - -D5: serial drv on/off, Serial mux1, Serial mux2 -D6: Leds, Fan, -D7: Siren and relay -D8: PtuWakeOut -D9: Power Aux/Barcode -D10: AuxDir 1...6 -D11: AuxOut 1...6 -D12: Coin shutter output -D13: CoinEscrow Outputs -*/ - -uint8_t gpi_storeDO_mdbRxTst(uint8_t mdbRxTst) { - return SharedMemBuffer::getData()->dout.mbdRxTst = mdbRxTst; -} - -bool epi_getDO_mdbRxTestOut(void) { - return SharedMemBuffer::getData()->dout.mbdRxTst & 1; -} - -uint8_t gpi_storeDO_motorOutputs(uint8_t motorBits) { - //D1: motor outputs bit0: upper lock forw bit 1 backw - // Bit2: lowLock forw bit3: LL backw - return SharedMemBuffer::getData()->dout.motorBits = motorBits; -} - -uint8_t epi_getDO_motorOuts(void) { - // bit0: upper lock forward bit 1 backward - // bit2: lower lock forward bit 3 backward - return SharedMemBuffer::getDataConst()->dout.motorBits; -} - -uint8_t gpi_storeDO_serialSwitch(uint8_t serialSwitch) { // serial drv on/off, Serial mux1, Serial mux2 - return SharedMemBuffer::getData()->dout.serialSwitch = serialSwitch; -} - -uint8_t epi_getDO_serialSwitch(void) { - // serial drv on/off, Serial mux1, Serial mux2 - return SharedMemBuffer::getDataConst()->dout.serialSwitch; -} - -bool epi_getDO_serialDriverIsOn(void) { - return SharedMemBuffer::getDataConst()->dout.serialSwitch & 1; -} - -bool epi_getDO_serialMux1isSetToPrinter(void) { - // mux1 off: serial is switched to printer - return (SharedMemBuffer::getDataConst()->dout.serialSwitch & 2) == 0; -} - -bool epi_getDO_serialMux1isSetToModem(void) { - // mux1 on: serial is switched to modem - return (SharedMemBuffer::getDataConst()->dout.serialSwitch & 2) > 0; -} - -bool epi_getDO_serialMux2isSetToCredit(void) { - // mux2 off: serial is switched to credit card terminal - return (SharedMemBuffer::getDataConst()->dout.serialSwitch & 4) == 0; -} - -bool epi_getDO_serialMux2isSetToMifare(void) { - // mux2 on: serial is switched to mifare reader - return (SharedMemBuffer::getDataConst()->dout.serialSwitch & 4) > 0; -} - -uint8_t gpi_storeDO_ledsAndFan(uint8_t ledState) { - // bit0: coinled 1:front_illu 2: paper-led 3:pinpad-led 4:start-led 5:service-led 6:fan - return SharedMemBuffer::getData()->dout.ledsAndFan = ledState; -} - -bool epi_getDO_led_coin(void) { - return (SharedMemBuffer::getDataConst()->dout.ledsAndFan & 1); -} - -bool epi_getDO_led_front(void) { - return (SharedMemBuffer::getDataConst()->dout.ledsAndFan & 2); -} - -bool epi_getDO_led_ticket(void) { - return (SharedMemBuffer::getDataConst()->dout.ledsAndFan & 4); -} - -bool epi_getDO_led_pin(void) { - return (SharedMemBuffer::getDataConst()->dout.ledsAndFan & 8); -} - -bool epi_getDO_led_start(void) { - return (SharedMemBuffer::getDataConst()->dout.ledsAndFan & 16); -} - -bool epi_getDO_led_inside(void) { - return (SharedMemBuffer::getDataConst()->dout.ledsAndFan & 32); -} - -bool epi_getDO_fan(void) { - return (SharedMemBuffer::getDataConst()->dout.ledsAndFan & 64); -} - -uint8_t gpi_storeDO_sirenAndRelay(uint8_t sirenRelay) { - // bit0: siren 1:relay - return SharedMemBuffer::getData()->dout.laermUndRelay = sirenRelay; -} - -bool epi_getDO_sirene(void) { - return SharedMemBuffer::getDataConst()->dout.laermUndRelay & 1; -} - -bool epi_getDO_relay(void) { - return SharedMemBuffer::getDataConst()->dout.laermUndRelay & 2; -} - -uint8_t gpi_storeDO_ptuWake(uint8_t state) { - return SharedMemBuffer::getData()->dout.ptuWake = state; -} - -bool epi_getDO_ptuWake(void) { - return SharedMemBuffer::getDataConst()->dout.ptuWake > 0; -} - -uint8_t gpi_storeDO_auxPower(uint8_t pwr) { - return SharedMemBuffer::getData()->dout.auxPower = pwr; -} - -bool epi_getDO_auxPower(void) { - return SharedMemBuffer::getDataConst()->dout.auxPower > 0; -} - -uint8_t gpi_storeDO_coinShutter(uint8_t state) { - return SharedMemBuffer::getData()->dout.coinShutter = state; -} - -bool epi_getDO_coinShutterOpen(void) { - // bit0: Coin shutter output, bit1: input-test-output - return SharedMemBuffer::getDataConst()->dout.coinShutter & 1; -} - -bool epi_getDO_coinShutterTest(void) { - // bit0: Coin shutter output, bit1: input-test-output - return SharedMemBuffer::getDataConst()->dout.coinShutter & 2; -} - -uint8_t gpi_storeDO_coinEscrow(uint8_t state) { - return SharedMemBuffer::getData()->dout.coinEscrow = state; -} - -uint8_t epi_getDO_coinEscrow(void) { - // retval: 1:return flap is open 2:take flap is open 0:closed - if (SharedMemBuffer::getData()->dout.coinEscrow & 1) { - return 1; // return flap is open - } - if (SharedMemBuffer::getData()->dout.coinEscrow & 2) { - return 2; // take flap is open - } - return 0; -} - -uint8_t gpi_storeDO_printerPwrOn(uint8_t state) { - return SharedMemBuffer::getData()->dout.printerPower = state; -} - -uint8_t epi_getDO_printerPwr(void) { - return SharedMemBuffer::getDataConst()->dout.printerPower; -} - -//------------------------------------------------------------------------------------ -//------------------------------------------------------------------------------------ -//----------------------------- Mifare Card Reader ----------------------------------- -uint8_t gpi_storeMifReaderStateAndCardType(uint8_t const *buf) { - // retval 0=OK 1=error host buffer too small - memset(SharedMemBuffer::getData()->Sdata.MIF_STATE, 0x00, - sizeof(SharedMemBuffer::getData()->Sdata.MIF_STATE)); - memcpy(SharedMemBuffer::getData()->Sdata.MIF_STATE, buf, 8); - return 0; // OK -} - -/* data description: - -new fast version: -byte 0= still the same: current read state: - 0=power off 1=reader-fault 2=ready - 3=just reading 4=read complete - 5=read partial, removed too early - 6=state unknown - -byte 1: reader state 1=ok 0=nok -byte 2: card preent (0,1) -byte 3: card selected (0) -byte 4: card type: 0...5 -byte 5: card allowed (0=no 1=MifareClassic 1k or 4k) -byte 6: CardSize: 1 or 4 (kB) -byte 7: length of UID 4 or 7 (byte) - - -old long version -byte 0: current read state: 0=power off 1=reader-fault 2=ready - 3=just reading 4=read complete - 5=read partial, removed too early - 6=state unknown -byte 1,2: read data length from card -3: 1=reader is OK (reported serial nr is OK) 0=wrong or no reader -4...15: reader version, expected "SL025-1.8" -byte16: 1=card is present 0:not -17: 0 -18: card type reported from reader -19: 1=allowed card type 0=not -20: card size: 1 or 4 (dec) = card size -21: LengthOfUID: 4 or 7 (dec) (byte) -22: UID 8 byte in hex -byte 30: sector logged: 0 -byte 31: current sector: 0 -byte 32: result, always 0 -*/ - -uint8_t epi_restoreMifState(uint8_t *buf, uint8_t maxBufferSize) { - // HWapi can read States from DC - if (maxBufferSize<8) { - return 1; // error - } - memcpy(buf, SharedMemBuffer::getData()->Sdata.MIF_STATE, 8); - return 0; // OK -} - -// data come in blockwise, so safe them blockwise as well -bool gpi_storeMifCardData(uint8_t blkNr, uint8_t const *receivedData) { - if (blkNr<12) { - memcpy(&SharedMemBuffer::getData()->Sdata.MIF_DATA[blkNr][0], receivedData, 64); - return true; - } - return false; -} - -uint8_t epi_restoreMifData(uint8_t blkNr, uint8_t *buf, uint8_t maxBufferSize) { - if (blkNr>11 || maxBufferSize<64) { - return 1; // error - } - - memcpy(buf, &SharedMemBuffer::getDataConst()->Sdata.MIF_DATA[blkNr][0], 64); - return 0; // ois OK -} - -void gpi_storeNewMifareCard(uint8_t typ, uint8_t const *holder) { - SharedMemBuffer::getData()->mif_cardType = typ; - strncpy((char *)holder, (char *)SharedMemBuffer::getData()->mif_cardHolder, 7); - SharedMemBuffer::getData()->mif_cardHolder[7] = '\0'; -} - -uint8_t epi_mifGetCardType(uint8_t const *holder) { - //holder[8] = name of card holder - // retval Type of MifareCard, 1=upper door, 2=lower door 3=test printer 4=test coins - strncpy((char *)SharedMemBuffer::getData()->mif_cardHolder, (char *)holder, 7); - return SharedMemBuffer::getData()->mif_cardType; -} - -void epi_restorePrinterState(uint8_t *buf) { - memcpy((char *)buf, (char *)SharedMemBuffer::getData()->Sdata.PRN_STATE, - sizeof(SharedMemBuffer::getData()->Sdata.PRN_STATE)); -} - -void gpi_storePrinterState(uint8_t const *buf) { - memcpy((char *)SharedMemBuffer::getData()->Sdata.PRN_STATE, (char *)buf, - sizeof(SharedMemBuffer::getData()->Sdata.PRN_STATE)); -} - -void epi_restorePrinterFonts(uint8_t *buf) { - memcpy((char *)buf, (char *)SharedMemBuffer::getData()->Sdata.PRN_FONTS, - sizeof(SharedMemBuffer::getData()->Sdata.PRN_FONTS)); -} - -void gpi_storePrinterFonts(uint8_t const *buf) { - memcpy((char *)SharedMemBuffer::getData()->Sdata.PRN_FONTS, (char *)buf, - sizeof(SharedMemBuffer::getData()->Sdata.PRN_FONTS)); -} - -// DB0: mdb_bus_ready (switched on) -// DB1: rdBackV12devicePower -// DB2: rdBackV5busPwr -bool gpi_storeMdbState(bool busReady, bool V12on, bool V5on) { - SharedMemBuffer::getData()->Sdata.mdb_busRdy = busReady; - SharedMemBuffer::getData()->Sdata.mdb_V12on = V12on; - SharedMemBuffer::getData()->Sdata.mdb_V5on = V5on; - return true; -} - -bool epi_restoreMdbBusReady(void) { - return SharedMemBuffer::getDataConst()->Sdata.mdb_busRdy; -} - -bool epi_restoreMdbV12Ready(void) { - return SharedMemBuffer::getDataConst()->Sdata.mdb_V12on; -} - -bool epi_restoreMdbV5Ready(void) { - return SharedMemBuffer::getDataConst()->Sdata.mdb_V5on; -} - -// last received mdb answer (from mdb device) -// only needed if a special command was sent directly -// DB0: mdb Device-Nr -// DB1: last sent mdb command -// DB2: nr of received (payload) data bytes (apart from ACK, can be 0....34) -// DB3...DB38: rec.data (payload) -void gpi_storeMdbResponse(uint8_t leng, uint8_t const *data) { - memset(&SharedMemBuffer::getData()->Sdata.RecBuff[0], 0x00, - sizeof(SharedMemBuffer::getData()->Sdata.RecBuff)); - SharedMemBuffer::getData()->Sdata.mdbNrOfRecData = leng; - memcpy((char *)&SharedMemBuffer::getData()->Sdata.RecBuff[0], - (char const *)data, leng); -} - -void epi_restoreMdbResponse(uint8_t *leng, uint8_t *data) { - *leng = SharedMemBuffer::getDataConst()->Sdata.mdbNrOfRecData; - memcpy((char *)data, - (char *)&SharedMemBuffer::getDataConst()->Sdata.RecBuff[0], *leng); -} - -void gpi_storeEmpSettings(uint8_t leng, uint8_t const *data) { - leng = std::min(leng, (uint8_t)(64)); - memset(&SharedMemBuffer::getData()->Sdata.emp_settingsBuff[0], 0x00, - sizeof(SharedMemBuffer::getData()->Sdata.emp_settingsBuff)); - SharedMemBuffer::getData()->Sdata.empNrOfsettings = leng; - memcpy((char *)&SharedMemBuffer::getData()->Sdata.emp_settingsBuff[0], - (char const *)data, leng); -} - -void epi_restoreEmpSettings(uint8_t *leng, uint8_t *data) { - *leng = SharedMemBuffer::getDataConst()->Sdata.empNrOfsettings; - memcpy((char *)data, - (char *)&SharedMemBuffer::getData()->Sdata.emp_settingsBuff[0], - *leng); -} - -// ...................................................................... -// Münzbuffer[10]: Münze für Münze auslesen (LIFO) -// 4.5.21 - -static void sub_enterData(uint8_t valid, uint8_t signal, - uint8_t error, uint16_t value) { - if (SharedMemBuffer::getDataConst()->ctr_gotCoin < MEMDEPTH_GOTCOINS) { - uint8_t const gc = SharedMemBuffer::getDataConst()->ctr_gotCoin; - SharedMemBuffer::getData()->gotCoin[gc].valid = valid; - SharedMemBuffer::getData()->gotCoin[gc].signal = signal; - SharedMemBuffer::getData()->gotCoin[gc].error = error; - SharedMemBuffer::getData()->gotCoin[gc].value = value; - } - SharedMemBuffer::getData()->ctr_gotCoin += 1; -} - -void gpi_storeEmpCoinSignal(uint8_t leng, uint8_t const *data) { - // leng is number of coin record with 5 bytes each - uint8_t LL = leng; // nr of coin records - uint16_t vv, pp = 0; - - //while (LL>0) // with FastProtocol only one coin - { - vv=uchar2uint(data[pp+4], data[pp+3]); - sub_enterData(data[pp], data[pp+1], data[pp+2], vv ); - pp+=5; - LL--; - } -} - -uint8_t epi_isNewCoinLeft(void) { - // retval: 0...16 coins left in FIFO - return SharedMemBuffer::getDataConst()->ctr_gotCoin; -} - -void epi_restoreEmpCoinSignal(uint8_t *valid, uint8_t *signal, - uint8_t *error, uint16_t *value) { - SharedMemBuffer::getData()->ctr_gotCoin -= 1; - if (SharedMemBuffer::getDataConst()->ctr_gotCoin < MEMDEPTH_GOTCOINS) { - uint8_t const gc = SharedMemBuffer::getDataConst()->ctr_gotCoin; - *valid = SharedMemBuffer::getDataConst()->gotCoin[gc].valid; - *signal = SharedMemBuffer::getDataConst()->gotCoin[gc].signal; - *error = SharedMemBuffer::getDataConst()->gotCoin[gc].error; - *value = SharedMemBuffer::getDataConst()->gotCoin[gc].value; - } -} - -void gpi_storeRbDeviceSettings(uint8_t leng, uint8_t const *data) { // getestet am 12.4.23TS - leng = std::min(leng, (uint8_t)(64)); - SharedMemBuffer::getData()->Sdata.NrOfDeviceSetting = leng; - memset((char *)&SharedMemBuffer::getData()->Sdata.DeviceSettingBuff[0], - 0x00, sizeof(SharedMemBuffer::getData()->Sdata.DeviceSettingBuff)); - memcpy((char *)&SharedMemBuffer::getData()->Sdata.DeviceSettingBuff[0], - (char const *)data, leng); -} - -void epi_restoreRbDeviceSettings(uint8_t *leng, uint8_t *data) { // getestet am 12.4.23TS - *leng = SharedMemBuffer::getDataConst()->Sdata.NrOfDeviceSetting; - memcpy((char *)data, - (char const *)&SharedMemBuffer::getDataConst()->Sdata.DeviceSettingBuff[0], - *leng); -} - -void gpi_storeMachineIDsettings(uint8_t leng, uint8_t const *data) { - leng = std::min(leng, (uint8_t)(64)); - SharedMemBuffer::getData()->Sdata.NrOfMachineIDSetting = leng; - memset((char *)&SharedMemBuffer::getData()->Sdata.NrOfMachineIDBuff[0], - 0x00, sizeof(SharedMemBuffer::getData()->Sdata.NrOfMachineIDBuff)); - memcpy((char *)&SharedMemBuffer::getData()->Sdata.NrOfMachineIDBuff[0], - (char const *)data, leng); -} - -void epi_restoreMachineIDsettings(uint8_t *leng, uint8_t *data) { - *leng = SharedMemBuffer::getDataConst()->Sdata.NrOfMachineIDSetting; - memcpy((char *)data, - (char const *)&SharedMemBuffer::getDataConst()->Sdata.NrOfMachineIDBuff[0], - *leng); -} - - -static uint8_t p_lastCoin; - -void epi_clearCurrentPayment(void) { - // call at beginning of coin collection - SharedMemBuffer::getData()->store.insertedAmount = 0; - p_lastCoin = 0; -} - -void gpi_storeCurrentPayment(uint32_t insertedAmount, - uint16_t lastCoinType, uint16_t lastCoinValue) { - SharedMemBuffer::getData()->store.insertedAmount = insertedAmount; - SharedMemBuffer::getData()->store.lastCoinType[p_lastCoin] = lastCoinType; - SharedMemBuffer::getData()->store.lastCoinValue[p_lastCoin] = lastCoinValue; - p_lastCoin++; -} - -uint32_t epi_CurrentPaymentGetAmount(void) { - return SharedMemBuffer::getDataConst()->store.insertedAmount; -} - -uint16_t epi_CurrentPaymentGetLastCoin(void) { - uint8_t pp = p_lastCoin; - if (pp==0) { - return 0; // noch keine Münze erhalten - } - if (pp>0) { - pp--; - } - return SharedMemBuffer::getDataConst()->store.lastCoinValue[pp]; -} - -bool epi_CurrentPaymentGetAllCoins(uint16_t *types, uint16_t *values) { - // alle bei diesem Verkauf eingeworfenen Münzen sind gespeichert falls die jmd. braucht - if (p_lastCoin==0) { - return false; - } - for (int nn=0; nn<64; nn++) { - types[nn] = SharedMemBuffer::getDataConst()->store.lastCoinType[nn]; - values[nn] = SharedMemBuffer::getDataConst()->store.lastCoinValue[nn]; - } - return true; -} - -void gpi_storeWakeSources(uint8_t const *receivedData) { - SharedMemBuffer::getData()->store.wakeSrc = 0; - for (int nn=5; nn>=0; nn--) { - uint8_t const uctmp = receivedData[nn]; - SharedMemBuffer::getData()->store.wakeSrc |= uctmp; - SharedMemBuffer::getData()->store.wakeSrc <<= 8; - } - SharedMemBuffer::getData()->store.wakeReason = receivedData[6]; - -} - -uint64_t epi_getWakeSources(void) { - return SharedMemBuffer::getDataConst()->store.wakeSrc; -} - -uint8_t epi_getWakeReason(void) -{ - return SharedMemBuffer::getDataConst()->store.wakeReason; -} - - - -void gpi_storeExtendedTime(uint8_t leng, uint8_t const *data) { - leng = std::min(leng, (uint8_t)(64)); - SharedMemBuffer::getData()->store.rbDevParamLen = leng; - memset((char *)(&SharedMemBuffer::getData()->store.rbDevParams[0]), 0x00, - sizeof(SharedMemBuffer::getData()->store.rbDevParams)); - memcpy((char *)(&SharedMemBuffer::getData()->store.rbDevParams[0]), - (char const *)data, leng); -} - -void epi_restoreExtendedTime(uint8_t *leng, uint8_t *data) { - *leng = SharedMemBuffer::getDataConst()->store.rbDevParamLen; - memcpy((char *)data, - (char const *)(&SharedMemBuffer::getData()->store.rbDevParams[0]), - *leng); -} - -// store device conditions -void gpi_storeDeviceConditions(uint8_t leng, uint8_t const *data) { - leng = std::min(leng, (uint8_t)(64)); - SharedMemBuffer::getData()->store.deviceCondLen = leng; - memset((char *)(&SharedMemBuffer::getData()->store.deviceCond[0]), 0x00, - sizeof(SharedMemBuffer::getData()->store.deviceCond)); - memcpy((char *)(&SharedMemBuffer::getData()->store.deviceCond[0]), - (char const *)data, leng); -} - -void epi_restoreDeviceConditions(uint8_t *leng, uint8_t *data) { - *leng = SharedMemBuffer::getDataConst()->store.deviceCondLen; - memcpy((char *)data, - (char const *)(&SharedMemBuffer::getData()->store.deviceCond[0]), - *leng); -} - -// store dynamic machine conditions -void gpi_storeDynMachineConditions(uint8_t leng, uint8_t const *data) { - SharedMemBuffer::getData()->store.machCondLen = leng; - memset((char *)(&SharedMemBuffer::getData()->store.machCond[0]), 0x00, - sizeof(SharedMemBuffer::getData()->store.machCond)); - memcpy((char *)(&SharedMemBuffer::getData()->store.machCond[0]), - (char const *)data, leng); -} - -void epi_restoreDynMachineConditions(uint8_t *leng, uint8_t *data) { - *leng = SharedMemBuffer::getDataConst()->store.machCondLen; - memcpy((char *)data, - (char const *)(&SharedMemBuffer::getData()->store.machCond[0]), - *leng); -} - -void gpi_storeDCbackupAccNr(uint8_t /*leng*/, uint8_t const *data) { - // if (leng > 32) { - // leng = 32; - // } - SharedMemBuffer::getData()->store.DcBackupAccNr[0] = uchar2uint(data[1], data[0]); - SharedMemBuffer::getData()->store.DcBackupAccNr[1] = uchar2uint(data[3], data[2]); - SharedMemBuffer::getData()->store.DcBackupAccNr[2] = uchar2uint(data[5], data[4]); - SharedMemBuffer::getData()->store.DcBackupAccNr[3] = uchar2uint(data[7], data[6]); - SharedMemBuffer::getData()->store.DcBackupAccNr[4] = uchar2uint(data[9], data[8]); - SharedMemBuffer::getData()->store.DcBackupAccNr[5] = uchar2uint(data[11], data[10]); - SharedMemBuffer::getData()->store.DcBackupAccNr[6] = uchar2uint(data[13], data[12]); - SharedMemBuffer::getData()->store.DcBackupAccNr[7] = uchar2uint(data[15], data[14]); - SharedMemBuffer::getData()->store.DcBackupNrOfAccNr = 8; -} - -void epi_restoreDCbackupAccNr(uint8_t *leng, uint16_t *accNrs) { - // return accNrs[0..7] - *leng = SharedMemBuffer::getDataConst()->store.DcBackupNrOfAccNr; - for (int nn=0; nn<8; nn++) { - accNrs[nn] = SharedMemBuffer::getDataConst()->store.DcBackupAccNr[nn]; - } -} - -void epi_iniVRstorage(void) { - memset((char *)(&SharedMemBuffer::getData()->store.vaultrecord[0]), 0x00, - sizeof(SharedMemBuffer::getData()->store.vaultrecord)); - SharedMemBuffer::getData()->store.gotNrBlocksOfVaultRec = 0; -} - -void gpi_storeVaultRecord(uint8_t blkNr, uint8_t const *data) { - uint16_t start = blkNr; - - // setze pro Block ein bit, wir brauchen block 0...4 - // also muss store_gotNrBlocksOfVaultRec auf 0x1F stehen - SharedMemBuffer::getData()->store.gotNrBlocksOfVaultRec |= (1<store.vaultrecord[start+ii] = data[ii]; - } -} - -bool epi_checkIfVaultRecordAvailable(void) { - return SharedMemBuffer::getDataConst()->store.gotNrBlocksOfVaultRec == 0x1F; -} - -bool epi_restoreVaultRecord(uint16_t *length, uint8_t *buf) { - *length = 0; - if (SharedMemBuffer::getDataConst()->store.gotNrBlocksOfVaultRec == 0x1F) { - *length = 320; - memcpy((char *)buf, - (char const *)SharedMemBuffer::getDataConst()->store.vaultrecord, - *length); - return true; - } - return false; -} - -void gpi_storeCBlevel(uint32_t amount, uint16_t nrOfCoins) { - SharedMemBuffer::getData()->store.amount = amount; - SharedMemBuffer::getData()->store.nrOfCoins = nrOfCoins; -} - -uint32_t epi_getCashBoxContent(void) { - return SharedMemBuffer::getDataConst()->store.amount; -} - -uint16_t epi_getNrOfCoinsInCashBox(void) { - return SharedMemBuffer::getDataConst()->store.nrOfCoins; -} - - - - - -void gpi_storeDcDataValid(bool isVal) -{ - SharedMemBuffer::getData()->store.dcDataValid = isVal; -} - - -bool gpi_areDcDataValid() -{ - return SharedMemBuffer::getDataConst()->store.dcDataValid; -} - - - - - - - diff --git a/DCPlugin/src/tslib.cpp b/DCPlugin/src/tslib.cpp deleted file mode 100644 index a257256..0000000 --- a/DCPlugin/src/tslib.cpp +++ /dev/null @@ -1,598 +0,0 @@ -#include "tslib.h" -#include - -//tslib::tslib() -//{ - - -//} - - -/* -uint16_t tslib::uchar2uint(uint8_t Highbyte, uint8_t Lowbyte) -{ - uint16_t uitmp; - uitmp=0; - uitmp |= uint8_t(Highbyte); - uitmp<<=8; - uitmp |= uint8_t(Lowbyte); - return uitmp; -} - -uint8_t tslib::uint2uchar(uint16_t uival, bool getHighB) -{ - // getHighB: low=GetLowByte - uint16_t uitmp=uival; - if (getHighB==0) - return uint8_t(uitmp); - uitmp>>=8; - return uint8_t(uitmp); - -}*/ - -uint16_t uchar2uint(char Highbyte, char Lowbyte) -{ - uint16_t uitmp; - uitmp=0; - uitmp |= uint8_t(Highbyte); - uitmp<<=8; - uitmp |= uint8_t(Lowbyte); - return uitmp; -} - -uint16_t uchar2uint(uint8_t Highbyte, uint8_t Lowbyte) -{ - uint16_t uitmp; - uitmp=0; - uitmp |= uint8_t(Highbyte); - uitmp<<=8; - uitmp |= uint8_t(Lowbyte); - return uitmp; -} - -uint32_t uchar2ulong(uint8_t Highbyte, uint8_t MHbyte, uint8_t MLbyte, uint8_t Lowbyte) -{ - uint32_t ultmp=0; - - ultmp |= uint8_t(Highbyte); - ultmp<<=8; - ultmp |= uint8_t(MHbyte); - ultmp<<=8; - ultmp |= uint8_t(MLbyte); - ultmp<<=8; - ultmp |= uint8_t(Lowbyte); - return ultmp; -} - -uint8_t uint2uchar(uint16_t uival, bool getHighB) -{ - // getHighB: low=GetLowByte - uint16_t uitmp=uival; - if (getHighB==0) - return uint8_t(uitmp); - uitmp>>=8; - return uint8_t(uitmp); - -} - - -uint8_t ulong2uchar(uint32_t ulval, uint8_t getBytNr) -{ - // getBytNr: 0=LSB 3=MSB - uint32_t ultmp=ulval; - if (getBytNr==0) - return uint8_t(ultmp); - ultmp>>=8; - if (getBytNr==1) - return uint8_t(ultmp); - ultmp>>=8; - if (getBytNr==2) - return uint8_t(ultmp); - ultmp>>=8; - return uint8_t(ultmp); - -} - -void delay(uint16_t MilliSec) -{ - QThread::msleep(uint32_t(MilliSec)); -} - - -void GetTimeString(uint8_t hours, uint8_t minutes, uint8_t seconds, uint8_t System12h, uint8_t ShowSec, uint8_t *buf) -{ - // Zahlenwerte in String wandeln, 12/24h-Format // 12byte für buf! - uint8_t usa; - uint16_t jj; - uint8_t hh, mm, ss, with_sec; - - // buf[0]= ganz linkes Zeichen - hh=hours; - mm=minutes; - ss=seconds; - - // 15.10.12, Plausibilitätsprüfung -------------------------------------------------- - if (hh>23) hh=0; - if (mm>59) mm=0; - if (ss>59) ss=0; - - with_sec=ShowSec; - for (jj=0; jj<12; jj++) buf[jj]=0; - usa = System12h; // 1:12h 0:24h - - // Stunden: - if (usa) - { - // 12h System - if (hh==0 || hh==12) - { - // 12AM (Mitternacht) oder 12PM (Mittag) - buf[0]=0x31; - buf[1]=0x32; - } else - if (hh<12) - { - // 1..11AM - buf[0]=hh/10+0x30; - buf[1]=hh%10+0x30; - } else - { - //13:00 bis 23Uhr - buf[0]=(hh-12)/10+0x30; - buf[1]=(hh-12)%10+0x30; - } - } else - { - // 24h System - buf[0]=hh/10+0x30; - buf[1]=hh%10+0x30; - } - - // Minuten: - buf[2]=':'; - buf[3]=mm/10+0x30; - buf[4]=mm%10+0x30; - - jj=5; - if (with_sec) - { - buf[jj++]=':'; - buf[jj++]=ss/10+0x30; - buf[jj++]=ss%10+0x30; - } - if (usa) - { - buf[jj++]=' '; - if (hh<12) - buf[jj++]='A'; - else - buf[jj++]='P'; - buf[jj++]='M'; - } - -} - -// ------------------- ******************************************************************************** - -void GetDateString(uint8_t day, uint8_t month, uint8_t yearhigh, uint8_t yearlow, uint8_t format, uint8_t sep, uint8_t *buf) -{ - // generate date as ascii string from integers day/month/year - // yearhigh: 10..29, in europe always 20 (not in arabia!) comes as hex number, e.g. 0x20 - // format= 0: dd.mm.yyyy (deutsch) - // 1: mm.dd.yyyy (amerika) - // 2: yyyy.mm.dd (Iran, Dubai) - // 3: dd.yyyy.mm - // 4: mm.yyyy.dd - // 5: yyyy.dd.mm - // sep: 0: use . as seperator 1: use / as seperator - // return String in *buf // 11byte für buf! - - - uint8_t tag, mon, jahr, d10, d1, m10, m1, y1000, y100, y10, y1; - uint8_t slash; - - - y100= (yearhigh & 0x0F)+0x30; - y1000=((yearhigh & 0xF0)>>4)+0x30; -// if (yearhigh>=20) -// { -// y1000='2'; -// y100=28+yearhigh; // '0' + (yearhigh-20) -// } else -// if (yearhigh<20) -// { -// y1000='1'; -// y100=38-yearhigh; // '9' - (19-yearhigh) -// } - - tag=day; - mon=month; - jahr=yearlow; - - if (mon>12 || mon==0) mon=1; // 23.10.12 - if (tag>31 || tag==0) tag=1; - if (jahr>50 || jahr<11) jahr=1; - - if (sep==0) - slash='.'; // slash==0 - else if (sep==1) - slash='/'; - else - if (sep>=0x20) - slash=sep; - else - slash='.'; - - d10 =tag/10; - d1 =tag%10; - m10 =mon/10; - m1 =mon%10; - y10 =jahr/10; - y1 =jahr%10; - - d10 +=0x30; // in Asccii wandeln - d1 +=0x30; - m10 +=0x30; - m1 +=0x30; - y10 +=0x30; - y1 +=0x30; - - switch (format) - { - // 0: dd.mm.yyyy - case 0: buf[0]=d10; buf[1]=d1; buf[2]=slash; buf[3]=m10; buf[4]=m1; buf[5]=slash; - buf[6]=y1000; buf[7]=y100; buf[8]=y10; buf[9]=y1; break; - - // 1: mm.dd.yyyy - case 1: buf[0]=m10; buf[1]=m1; buf[2]=slash; buf[3]=d10; buf[4]=d1; buf[5]=slash; - buf[6]=y1000; buf[7]=y100; buf[8]=y10; buf[9]=y1; break; - - // 2: yyyy.mm.dd - case 2: buf[0]=y1000; buf[1]=y100; buf[2]=y10; buf[3]=y1; buf[4]=slash; buf[5]=m10; - buf[6]=m1; buf[7]=slash; buf[8]=d10; buf[9]=d1; break; - - // 3: dd.yyyy.mm - case 3: buf[0]=d10; buf[1]=d1; buf[2]=slash; buf[3]=y1000; buf[4]=y100; - buf[5]=y10; buf[6]=y1; buf[7]=slash; buf[8]=m10; buf[9]=m1; break; - - // 4: mm.yyyy.dd - case 4: buf[0]=m10; buf[1]=m1; buf[2]=slash; buf[3]=y1000; buf[4]=y100; - buf[5]=y10; buf[6]=y1; buf[7]=slash; buf[8]=d10; buf[9]=d1; break; - - // 5: yyyy.dd.mm - case 5: buf[0]=y1000; buf[1]=y100; buf[2]=y10; buf[3]=y1; buf[4]=slash; buf[5]=d10; - buf[6]=d1; buf[7]=slash; buf[8]=m10; buf[9]=m1; break; - - } - buf[10]=0; - - -} - -// ------------------- ******************************************************************************** - -void GetShortDateString(uint8_t day, uint8_t month, uint8_t yearlow, uint8_t format, uint8_t sep, uint8_t *buf) -{ - // generate date as ascii string from integers day/month/year - // format= 0: dd.mm.yy (deutsch) - // 1: mm.dd.yy (amerika) - // 2: yy.mm.dd (Iran, Dubai) - // 3: dd.yy.mm - // 4: mm.yy.dd - // 5: yy.dd.mm - // sep: 0: use . as seperator 1: use / as seperator - // return String in *buf // 11byte für buf! - - - uint8_t tag, mon, jahr, d10, d1, m10, m1, y10, y1; - uint8_t slash; - - - tag=day; - mon=month; - jahr=yearlow; - - if (mon>12 || mon==0) mon=1; // 23.10.12 - if (tag>31 || tag==0) tag=1; - if (jahr>50 || jahr<11) jahr=1; - - if (sep==0) - slash='.'; // slash==0 - else if (sep==1) - slash='/'; - else if (sep>=0x20) - slash=sep; - else - slash='.'; - - d10 =tag/10; - d1 =tag%10; - m10 =mon/10; - m1 =mon%10; - y10 =jahr/10; - y1 =jahr%10; - - d10 +=0x30; // in Asccii wandeln - d1 +=0x30; - m10 +=0x30; - m1 +=0x30; - y10 +=0x30; - y1 +=0x30; - - switch (format) - { - // 0: dd.mm.yyyy - case 0: buf[0]=d10; buf[1]=d1; buf[2]=slash; buf[3]=m10; buf[4]=m1; buf[5]=slash; - buf[6]=y10; buf[7]=y1; break; - - // 1: mm.dd.yyyy - case 1: buf[0]=m10; buf[1]=m1; buf[2]=slash; buf[3]=d10; buf[4]=d1; buf[5]=slash; - buf[6]=y10; buf[7]=y1; break; - - // 2: yyyy.mm.dd - case 2: buf[0]=y10; buf[1]=y1; buf[2]=slash; buf[3]=m10; - buf[4]=m1; buf[5]=slash; buf[6]=d10; buf[7]=d1; break; - - // 3: dd.yyyy.mm - case 3: buf[0]=d10; buf[1]=d1; buf[2]=slash; - buf[3]=y10; buf[4]=y1; buf[5]=slash; buf[6]=m10; buf[7]=m1; break; - - // 4: mm.yyyy.dd - case 4: buf[0]=m10; buf[1]=m1; buf[2]=slash; - buf[3]=y10; buf[4]=y1; buf[5]=slash; buf[6]=d10; buf[7]=d1; break; - - // 5: yyyy.dd.mm - case 5: buf[0]=y10; buf[1]=y1; buf[2]=slash; buf[3]=d10; - buf[4]=d1; buf[5]=slash; buf[6]=m10; buf[7]=m1; break; - - } - buf[8]=0; - - -} - -uint16_t tslib_strlen(char *buf) -{ - uint16_t nn; - - for (nn=0; nn<0xFFF0; nn++) - if (buf[nn]==0) - return nn; - return 0; -} - -uint16_t tslib_strlen(uint8_t *buf) -{ - uint16_t nn; - - for (nn=0; nn<0xFFF0; nn++) - if (buf[nn]==0) - return nn; - return 0; -} - -void tslib_strclr(char *buf, char clrsign, uint16_t len) -{ - uint16_t nn; - - for (nn=0; nn=0x30 && sign<=0x39) - return true; - return false; -} - -bool tslib_isHexAsciiNumber(char sign) -{ - if (sign>=0x30 && sign<=0x39) - return true; - if (sign>=0x61 && sign<=0x66) // a...f - return true; - if (sign>=0x41 && sign<=0x46) // A...F - return true; - return false; -} - -int tslib_getMinimum(int val1, int val2) -{ - if (val1maxArayLen) LL=maxArayLen; - for (ii=0; ii> (7 - nn)) & 0x01); - if (B15H) - { - crc ^= 0x1021; - } - } - } - - for (nn = 0; nn < 16; nn++) - { - B15H = 0; - if(crc & 0x8000) - B15H = 1; - crc = (crc << 1) | 0x00; - if (B15H) - { - crc ^= 0x1021; - } - } - return crc; - -} - -static uint8_t LastBLcmd; // stored the last sent cmd in order to analys response - // cmd echo'ed: error cmd or'ed with 0x80: OK - -uint8_t tslib_prepareDC_BLcmd(uint8_t Cmd, uint8_t SendDataLength, uint8_t *sendData, uint8_t *outBuf) -{ - // make BL protocol, retval = outbuf length (5...133) - // bring data in correct form: start always with 0x02 finish with 0x03 and append checksum - // 0x02 Cmd < ...sendData ..> CRC CRC 0x03 - // Data length = 0...64 - // special conversion: if data contain 2 or 3 (STX, ETX) then write two bytes: 0x1B (=ESC) and data|0x80 - // so maxlength = 5 + 2 x 64 (if all data are 2 or 3) without 2,3: maxlength = 5 + 64 - - uint8_t myBuf[140], pp=0, nn, uctmp, currLen=0; - uint16_t calcCrc; - - tslib_strclr(myBuf, 0, 140); - - myBuf[pp++]=2; // STX - myBuf[pp++]=Cmd; - LastBLcmd=Cmd; - - // append data: - for (nn=0; nn>8) & 0x00FF); - myBuf[pp++]=3; - currLen=pp; - - return currLen; -} - -// some special commands (right out of bootloader manual) -uint8_t tslib_readBLversion(uint8_t *sendData) -{ - // minimum size of sendData-buffer: 5byte retval: length - uint8_t myBuf[2]; - tslib_strclr(myBuf, 0, 2); - return tslib_prepareDC_BLcmd(0x11, 0, myBuf, sendData); -} - -uint8_t tslib_readFWversion(uint8_t *sendData) -{ - // minimum size of sendData-buffer: 5byte retval: length - uint8_t myBuf[2]; - tslib_strclr(myBuf, 0, 2); - return tslib_prepareDC_BLcmd(0x12, 0, myBuf, sendData); -} - -uint8_t tslib_exitBL(uint8_t *sendData) -{ - // minimum size of sendData-buffer: 5byte retval: length - uint8_t myBuf[2]; - tslib_strclr(myBuf, 0, 2); - return tslib_prepareDC_BLcmd(0x18, 0, myBuf, sendData); -} - -uint8_t tslib_sendFlashStartAddr2BL(uint32_t startAddr, uint8_t *sendData) -{ - // minimum size of sendData-buffer: 13byte retval: length (9...13) - uint8_t myBuf[2]; - tslib_strclr(myBuf, 0, 2); - return tslib_prepareDC_BLcmd(0x11, 0, myBuf, sendData); -} -*/ - -// ----------------------------------------------------------------------------------------------- - - -void biox_CopyBlock(uint8_t *src, uint16_t srcPos, uint8_t *dest, uint16_t destPos, uint16_t len) -{ - // both buffers starting from pos 0 - uint16_t xx,yy,zz,ii; - - xx = srcPos; - yy = destPos; - zz = len; - - for (ii = 0; ii < zz; ++ii) - { - dest[yy + ii] = src[xx + ii]; - } -} diff --git a/OnDemandUpdatePTU.pro b/OnDemandUpdatePTU.pro index f58cdce..3018e67 100644 --- a/OnDemandUpdatePTU.pro +++ b/OnDemandUpdatePTU.pro @@ -15,47 +15,129 @@ DEFINES += QT_DEPRECATED_WARNINGS # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -VERSION=1.3.4 + +# 1.3.6 : Do not update device-controller/json files, but have the library +# (in a later step) do that. +# Fixed sending messages to ISMAS. +# Always execute contents of opkg_commands-file (even if there are no +# changes). +# 1.3.7 : Wait forever for git-commands to finish in QProcess executing such +# a command. +# 1.3.8 : Remove accessing opkg_commands under file-system-path /etc/psa_update. +# Activate download of json-configuration files. +# 1.3.9 : Fix sendLastVersion: use configured branch and not master branch in +# git show origin/master -s --format="c=%h m=%s d=%cI" ==> +# git show origin/zg1/zone1 -s --format="c=%h m=%s d=%cI" +# Use dynamic values for os-release and apism-version when sending +# last version info. +# 1.3.10: Fix premature killing opkg-commands: detected timeout of 100s was +# too small when updating apism. +# Fix display of UPDATE_SUCCESS when opkg_command fails. Detected when +# updating apsim failed. +# 1.3.11: Integrate version of ATBUpdateTool in SendLastVersion-ISMAS-message. +# 1.3.12: Add command parameters for output of yocto-infos about ATBUpdateTool. +# Use 'git pull' instead of 'git fetch'. +# Use 'git clone --filter=blob:none' instead of 'git clone' to speed +# up cloning of customer repository. +# 1.3.13: Fix: if the customer repository is corrupted, remove it and re-clone +# the repository (without checking the ISMAS-trigger (WAIT-)button. +# 1.3.14: Add additional check for sanity of customer repository using +# "git fsck". +# Stream-lined code of update process: massive refactoring. +# Added functionality: If WAIT button is not active, then an existing +# customer repository will be repaired, or a not existing repository +# will be cloned. The process stops then. +# However, if the WAIT button is active, the at least the commands in +# opkg_commands will be executed. Changed files in the customer +# repository will be worked on: tariff-files will be synced with the +# local filesystem, json-files will be downloaded to firmware. +# The device-controller firmware will be handled in a later version. +# 1.3.15: Bug fixes found during testing. +# Don't disable Exit-button during update-process. +# Removed worker-thread with an own event-loop: only the GUI thread +# has an event loop. Tested JSON-downloads several times successfully +# (using the slave lib where the CA helper tool was active as master). +# Turned previous worker-object into its own thread, but without any +# own event-loop (so it cannot block anything inside the CA-plugin). +# 1.3.16: Bug fixes found during testing. +# 1.3.17: Add ATBUpdateTool.ini and custom command line parser. Settings +# given in ATBUpdateTool.ini can be overwritten on the command-line. +# 1.3.18: Bug fixes found during testing. +# 1.3.19: Bug fixes found during testing. +VERSION="1.3.20" +# 1.3.20: Bug fixes found during testing. + +# PLANNED TODOS: +# 1: Das Repository wird repariert bwz. neu geklont. Unabhaengig vom WAIT. +# 2: Wenn der WAIT-Button aktiv ist, dann wird ein Repository repariert (neu +# geklont), aber zusaetzlich werden alle verfuegbaren Dateien als neu +# angesehen und die entsprechenden Aktionen durchgefuehrt: tariff-files +# spiegeln, json-files laden und dc laden. Also VORSICHT: das repository +# muss in diesem fall wirklich in ordnung sein. +# 3: Wurde keine Datei geaendert, kein initiales Clone und der WAIT-button +# nicht aktiv, so (passiert natuerlich nichts) kann man davon ausgehen, +# dass es sich um ein automatisches Update handelt. Dann koennte man im +# ISMAS eine entsprechende Meldung anzeigen als Teil von SEND-LAST-VERSION. +# Wenn der WAIT-button aktiv ist, dann werden zumindest die opkg-commands +# ausgefuehrt. +# 4: rsync: immer alle Dateien soiegeln (bis auf opkg-commands) +# 5: Falls das Tool mal abstuerzt, dann einen Signal-Handler (fuer TERM) +# installieren, sodass zumnidest SEND-LAST-VERSION mit rausgeht. +# 6: rsync: explizites Binary, nicht das in busybox enthaltene. +# 7: Versionen der Json-Files lassen sich auslesen. +# Problem: Einstellungen in den Json-Files lassen sich auch mittels +# Funktionen in der CD-Library ueberschreiben. Damit ist dann wieder nicht +# mehr so klar, was jetzt eigentlich aktiv ist. +# 8: m_alwaysDownloadConfig und m_alwaysDownloadDC: vorbereitet: man koennte +# es so arrangieren, dass der DC plus die Json-files im Repository immer +# runtergeladen werden, obwohl sich im Repository gar nicts veraendert +# hat. Eeventuell nuetzlich beim initialen Setuo eines PSA. +# 9: Das Kunden-Repository sollte immer gezogen werden, unabhaengig von der +# Stellung des WAIT-Button. Grund: es koennte sein, dass andernfalls ein +# PSA weit hiter anderen steht, und dann ploetzlich einmal alle vorher- +# gehenden Aenderungen anzieht, die gar nicht fuer ihn gemeint waren. + + +win32 { + BUILD_DATE=$$system("date /t") + BUILD_TIME=$$system("time /t") +} 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}" INCLUDEPATH += plugins -CONFIG += c++17 console +CONFIG += c++17 # CONFIG -= app_bundle DEFINES+=APP_VERSION=\\\"$$VERSION\\\" +DEFINES+=APP_BUILD_DATE=\\\"$$BUILD_DATE\\\" +DEFINES+=APP_BUILD_TIME=\\\"$$BUILD_TIME\\\" +DEFINES+=APP_EXTENDED_VERSION=\\\"$$EXTENDED_VERSION\\\" +# keep comments, as /* fall through */ +QMAKE_CXXFLAGS += -C QMAKE_CXXFLAGS += -g QMAKE_CXXFLAGS += -Wno-deprecated-copy -# custom target for 'git subtree' -# subtree.target = subtree -# subtree.commands = git subtree add --prefix DCPlugin https://git.mimbach49.de/GerhardHoffmann/DCPlugin.git master --squash -# subtree.depends = -# QMAKE_EXTRA_UNIX_TARGETS += subtree - -# ! exists(DCPlugin) { -# $$system("git subtree add --prefix DCPlugin https://git.mimbach49.de/GerhardHoffmann/DCPlugin.git master --squash") -# } else { - # $$system("git subtree pull --prefix DCPlugin https://git.mimbach49.de/GerhardHoffmann/DCPlugin.git master --squash") -# } - -# You can make your code fail to compile if it uses deprecated APIs. -# In order to do so, uncomment the following line. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - contains( CONFIG, PTU5 ) { greaterThan(QT_MAJOR_VERSION, 4): QT += serialport CONFIG += link_pkgconfig lessThan(QT_MAJOR_VERSION, 5): PKGCONFIG += qextserialport - QMAKE_CXXFLAGS += -std=c++17 # for GCC >= 4.7 - QMAKE_CXXFLAGS += -Wno-deprecated-copy + QMAKE_CXXFLAGS += -O2 -std=c++17 # for GCC >= 4.7 + # QMAKE_CXXFLAGS += -Wno-deprecated-copy ARCH = PTU5 DEFINES+=PTU5 } contains( CONFIG, PTU5_YOCTO ) { greaterThan(QT_MAJOR_VERSION, 4): QT += serialport QMAKE_CXXFLAGS += -std=c++17 # for GCC >= 4.7 - QMAKE_CXXFLAGS += -Wno-deprecated-copy + # QMAKE_CXXFLAGS += -Wno-deprecated-copy PTU5BASEPATH = /opt/devel/ptu5 ARCH = PTU5 DEFINES+=PTU5 @@ -69,7 +151,7 @@ contains( CONFIG, DesktopLinux ) { # QMAKE_CC = ccache $$QMAKE_CC # QMAKE_CXX = ccache $$QMAKE_CXX QMAKE_CXXFLAGS += -std=c++17 - QMAKE_CXXFLAGS += -Wno-deprecated-copy + # QMAKE_CXXFLAGS += -Wno-deprecated-copy linux-clang { QMAKE_CXXFLAGS += -Qunused-arguments } ARCH = DesktopLinux DEFINES+=DesktopLinux @@ -87,7 +169,7 @@ SOURCES += \ process/command.cpp \ message_handler.cpp \ worker.cpp \ - worker_thread.cpp + commandline_parser.cpp HEADERS += \ update.h \ @@ -101,24 +183,15 @@ HEADERS += \ process/command.h \ message_handler.h \ worker.h \ - worker_thread.h \ + commandline_parser.h \ plugins/interfaces.h +OTHER_FILES += \ + ATBUpdateTool.ini + FORMS += \ mainwindow.ui -OTHER_FILES += \ - /opt/app/tools/atbupdate/update_log.csv \ - main.cpp.bck \ - main.cpp.bck2 \ - main.cpp.bck3 - -# https://blog.developer.atlassian.com/the-power-of-git-subtree/?_ga=2-71978451-1385799339-1568044055-1068396449-1567112770 -# git subtree add --prefix DCPlugin https://git.mimbach49.de/GerhardHoffmann/DCPlugin.git master --squash -# git subtree pull --prefix DCPlugin https://git.mimbach49.de/GerhardHoffmann/DCPlugin.git master --squash -# include(./DCPlugin/DCPlugin.pri) - - ########################################################################################## # for running program on target through QtCreator diff --git a/commandline_parser.cpp b/commandline_parser.cpp new file mode 100644 index 0000000..e60f71f --- /dev/null +++ b/commandline_parser.cpp @@ -0,0 +1,251 @@ +#include "commandline_parser.h" + +#include +#include +#include +#include + +CommandLineParser::CommandLineParser() + : m_repositoryUrl("https://git.mimbach49.de/GerhardHoffmann") + , m_plugInDir("/usr/lib/") + , m_plugInName("libCAslave.so") + , m_workingDir("/opt/app/tools/atbupdate/") + , m_dryRun("false") + , m_noUpdatePsaHardware("false") + , m_showYoctoVersion("false") + , m_showYoctoInstallStatus("false") + , m_showExtendedVersion("false") + , m_iniFileName("ATBUpdateTool.ini") + , m_alwaysDownloadConfig("false") + , m_alwaysDownloadDC("false") + , m_repositoryUrlOption( + QCommandLineOption( + QStringList() << "repository-url" << "repository-url", + QCoreApplication::translate("main", "Where to find a customer repository."), + QCoreApplication::translate("main", "directory"))) + , m_iniFileDirectoryOption( + QCommandLineOption( + QStringList() << "ini-directory" << "ini-directory", + QCoreApplication::translate("main", "Where to find an ini-file."), + QCoreApplication::translate("main", "directory"))) + , m_iniFileNameOption( + QCommandLineOption( + QStringList() << "ini-filename" << "ini-filename", + QCoreApplication::translate("main", "Name of ini-file."), + QCoreApplication::translate("main", "file"))) + , m_pluginDirectoryOption( + QCommandLineOption( + QStringList() << "plugin-directory" << "plugin-directory", + QCoreApplication::translate("main", "Where to find dc-plugin."), + QCoreApplication::translate("main", "directory"))) + , m_pluginNameOption( + QCommandLineOption( + QStringList() << "plugin-name" << "plugin-name", + QCoreApplication::translate("main", "Name of dc-plugin."), + QCoreApplication::translate("main", "directory"))) + , m_noDownloadOption( + QCommandLineOption( + "no-psa-hardware-update", + QCoreApplication::translate("main", "Do not update the PSA firmware (json, device-controller)."))) + , m_alwaysDownloadConfigOption( + QCommandLineOption( + "always-download-config", + QCoreApplication::translate("main", "Always download the (json-)configs to DC)."))) + , m_alwaysDownloadDCOption( + QCommandLineOption( + "always-download-dc", + QCoreApplication::translate("main", "Always download the dc-bin-file to DC)."))) + , m_workingDirectoryOption( + QCommandLineOption( + QStringList() << "working-directory" << "working-directory", + QCoreApplication::translate("main", "working directory of update-script."), + QCoreApplication::translate("main", "directory"))) + , m_dryRunOption( + QCommandLineOption( + QStringList() << "d" << "dry-run", + QCoreApplication::translate("main", "Start ATBUpdateTool in dry-run-mode. No actual actions."))) + , m_extendedVersionOption( + QCommandLineOption( + QStringList() << "V" << "extended-version", + QCoreApplication::translate("main", "Show extended version (including last git commit)."))) + , m_yoctoVersionOption( + QCommandLineOption( + QStringList() << "y" << "yocto-version", + QCoreApplication::translate("main", "Show yocto version of ATBUpdateTool."))) + , m_yoctoInstallStatusOption( + QCommandLineOption( + QStringList() << "Y" << "yocto-install", + QCoreApplication::translate("main", "Show yocto install status of ATBUpdateTool."))) { + configure(); +} + +void CommandLineParser::configure() { + m_parser.setApplicationDescription("Download tool for downloading device controller firmware, printer json-files and executing opkg-commands."); + m_parser.addHelpOption(); + m_parser.addVersionOption(); + + m_repositoryUrlOption.setDefaultValue("https://git.mimbach49.de/GerhardHoffmann"); + m_parser.addOption(m_repositoryUrlOption); + + m_iniFileDirectoryOption.setDefaultValue("."); + m_parser.addOption(m_iniFileDirectoryOption); + + m_iniFileNameOption.setDefaultValue("ATBUpdateTool.ini"); + m_parser.addOption(m_iniFileNameOption); + + m_pluginDirectoryOption.setDefaultValue("/usr/lib/"); + m_parser.addOption(m_pluginDirectoryOption); + + m_pluginNameOption.setDefaultValue("libCAslave.so"); + m_parser.addOption(m_pluginNameOption); + + m_alwaysDownloadConfigOption.setDefaultValue("false"); + m_parser.addOption(m_alwaysDownloadConfigOption); + + m_alwaysDownloadDCOption.setDefaultValue("false"); + m_parser.addOption(m_alwaysDownloadDCOption); + + m_noDownloadOption.setDefaultValue("false"); + m_parser.addOption(m_noDownloadOption); + + m_workingDirectoryOption.setDefaultValue("/opt/app/tools/atbupdate/"); + m_parser.addOption(m_workingDirectoryOption); + + m_dryRunOption.setDefaultValue("false"); + m_parser.addOption(m_dryRunOption); + + m_extendedVersionOption.setDefaultValue("false"); + m_parser.addOption(m_extendedVersionOption); + + m_yoctoVersionOption .setDefaultValue("false"); + m_parser.addOption(m_yoctoVersionOption); + + m_yoctoInstallStatusOption .setDefaultValue("false"); + m_parser.addOption(m_yoctoInstallStatusOption); +} + +void CommandLineParser::readSettings() { + QString const iniFileDir = m_parser.value(m_iniFileDirectoryOption); + QString const iniFileName = m_parser.value(m_iniFileNameOption); + m_iniFileName = QDir::cleanPath(iniFileDir + QDir::separator() + iniFileName); + + if (!m_iniFileName.isEmpty()) { + if (QFile(m_iniFileName).exists()) { + QSettings settings(m_iniFileName, QSettings::IniFormat); + QStringList keys = settings.allKeys(); + for (QString const &key: keys) { + QVariant v = settings.value(key); + if (key.contains("repository-url")) { + m_repositoryUrl = v.toString(); + } else + if (key.contains("plugin-directory")) { + m_plugInDir = v.toString(); + } else + if (key.contains("working-directory")) { + m_workingDir = v.toString(); + } else + if (key.contains("dry-run")) { + m_dryRun = (v.toBool() ? "true" : "false"); + } else + if (key.contains("extended-version")) { + m_showExtendedVersion = (v.toBool() ? "true" : "false"); + } else + if (key.contains("no-psa-hardware-update")) { + m_noUpdatePsaHardware = (v.toBool() ? "true" : "false"); + } else + if (key.contains("always-download-config")) { + m_alwaysDownloadConfig = (v.toBool() ? "true" : "false"); + } else + if (key.contains("always-download-dc")) { + m_alwaysDownloadDC = (v.toBool() ? "true" : "false"); + } else + if (key.contains("yocto-install")) { + m_showYoctoInstallStatus = (v.toBool() ? "true" : "false"); + } else + if (key.contains("yocto-version")) { + m_showYoctoVersion = (v.toBool() ? "true" : "false"); + } else + if (key.contains("plugin-name")) { + m_plugInName = v.toString(); + } + } + } + } +} + +QString CommandLineParser::repositoryUrl() { + if (m_parser.isSet(m_repositoryUrlOption)) { + m_repositoryUrl = m_parser.value(m_repositoryUrlOption); + } + return m_repositoryUrl; +} + +QString CommandLineParser::plugInDir() { + if (m_parser.isSet(m_pluginDirectoryOption)) { + m_plugInDir = m_parser.value(m_pluginDirectoryOption); + } + return m_plugInDir; +} + +QString CommandLineParser::plugInName() { + if (m_parser.isSet(m_pluginNameOption)) { + m_plugInName = m_parser.value(m_pluginNameOption); + } + return m_plugInName; +} + +QString CommandLineParser::workingDir() { + if (m_parser.isSet(m_workingDirectoryOption)) { + m_workingDir = m_parser.value(m_workingDirectoryOption); + } + return m_workingDir; +} + +bool CommandLineParser::dryRun() { + if (m_parser.isSet(m_dryRunOption)) { + m_dryRun = m_parser.value(m_dryRunOption); + } + return m_dryRun == "false" ? false : true; +} + +bool CommandLineParser::noUpdatePsaHardware() { + if (m_parser.isSet(m_noDownloadOption)) { + m_noUpdatePsaHardware = m_parser.value(m_noDownloadOption); + } + return m_noUpdatePsaHardware == "false" ? false : true; +} + +bool CommandLineParser::yoctoVersion() { + if (m_parser.isSet(m_yoctoVersionOption)) { + m_showYoctoVersion = m_parser.value(m_yoctoVersionOption); + } + return m_showYoctoVersion == "false" ? false : true; +} + +bool CommandLineParser::yoctoInstallStatus() { + if (m_parser.isSet(m_yoctoInstallStatusOption)) { + m_showYoctoInstallStatus = m_parser.value(m_yoctoInstallStatusOption); + } + return m_showYoctoInstallStatus == "false" ? false : true; +} + +bool CommandLineParser::extendedVersion() { + if (m_parser.isSet(m_extendedVersionOption)) { + m_showExtendedVersion = m_parser.value(m_extendedVersionOption); + } + return m_showExtendedVersion == "false" ? false : true; +} + +bool CommandLineParser::alwaysDownloadConfig() { + if (m_parser.isSet(m_alwaysDownloadConfigOption)) { + m_alwaysDownloadConfig = m_parser.value(m_alwaysDownloadConfigOption); + } + return m_alwaysDownloadConfig == "false" ? false : true; +} + +bool CommandLineParser::alwaysDownloadDC() { + if (m_parser.isSet(m_alwaysDownloadDCOption)) { + m_alwaysDownloadDC = m_parser.value(m_alwaysDownloadDCOption); + } + return m_alwaysDownloadDC == "false" ? false : true; +} diff --git a/commandline_parser.h b/commandline_parser.h new file mode 100644 index 0000000..62d6452 --- /dev/null +++ b/commandline_parser.h @@ -0,0 +1,63 @@ +#ifndef COMMAND_LINE_PARSER_H_INCLUDED +#define COMMAND_LINE_PARSER_H_INCLUDED + +#include +#include +#include +#include + +class CommandLineParser : public QCommandLineParser { + QString m_repositoryUrl; + QString m_plugInDir; + QString m_plugInName; + QString m_workingDir; + QString m_dryRun; + QString m_noUpdatePsaHardware; + QString m_showYoctoVersion; + QString m_showYoctoInstallStatus; + QString m_showExtendedVersion; + QString m_iniFileName; + QString m_alwaysDownloadConfig; + QString m_alwaysDownloadDC; + + QCommandLineOption m_repositoryUrlOption; + QCommandLineOption m_iniFileDirectoryOption; + QCommandLineOption m_iniFileNameOption; + QCommandLineOption m_pluginDirectoryOption; + QCommandLineOption m_pluginNameOption; + QCommandLineOption m_noDownloadOption; + QCommandLineOption m_alwaysDownloadConfigOption; + QCommandLineOption m_alwaysDownloadDCOption; + QCommandLineOption m_workingDirectoryOption; + QCommandLineOption m_dryRunOption; + QCommandLineOption m_extendedVersionOption; + QCommandLineOption m_yoctoVersionOption; + QCommandLineOption m_yoctoInstallStatusOption; + + QCommandLineParser m_parser; + + void configure(); + +public: + + explicit CommandLineParser(); + ~CommandLineParser() = default; + + QCommandLineParser &parser() { return m_parser; } + QCommandLineParser const &parser() const { return m_parser; } + void process(const QCoreApplication &app) { m_parser.process(app); } + QString const &iniFileName() const { return m_iniFileName; } + void readSettings(); + QString repositoryUrl(); + QString plugInDir(); + QString plugInName(); + QString workingDir(); + bool dryRun(); + bool noUpdatePsaHardware(); + bool yoctoVersion(); + bool yoctoInstallStatus(); + bool extendedVersion(); + bool alwaysDownloadConfig(); + bool alwaysDownloadDC(); +}; +#endif // COMMAND_LINE_PARSER_H_INCLUDED diff --git a/doc/ATBUpdateTool.drawio b/doc/ATBUpdateTool.drawio new file mode 100644 index 0000000..06019ca --- /dev/null +++ b/doc/ATBUpdateTool.drawio @@ -0,0 +1,230 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/ATBUpdateTool.drawio-3.pdf b/doc/ATBUpdateTool.drawio-3.pdf new file mode 100644 index 0000000..67082e9 Binary files /dev/null and b/doc/ATBUpdateTool.drawio-3.pdf differ diff --git a/git/git_client.cpp b/git/git_client.cpp index 88dbe1a..b23d7a3 100644 --- a/git/git_client.cpp +++ b/git/git_client.cpp @@ -26,29 +26,93 @@ GitClient::GitClient(QString const &customerNrStr, } bool GitClient::gitCloneCustomerRepository() { - QString gitCommand("git clone "); + /* Blobless clone + ============== + + When using the --filter=blob:none option, the initial git clone will + download all reachable commits and trees, and only download the blobs + for commits when you do a git checkout. This includes the first checkout + inside the git clone operation. + + The important thing to notice is that we have a copy of every blob at + HEAD but the blobs in the history are not present. If your repository + has a deep history full of large blobs, then this option can + significantly reduce your git clone times. The commit and tree data is + still present, so any subsequent git checkout only needs to download + the missing blobs. The Git client knows how to batch these requests to + ask the server only for the missing blobs. + + Further, when running git fetch in a blobless clone, the server only + sends the new commits and trees. The new blobs are downloaded only + after a git checkout. Note that git pull runs git fetch and then git + merge, so it will download the necessary blobs during the git merge + command. + + When using a blobless clone, you will trigger a blob download whenever + you need the contents of a file, but you will not need one if you only + need the OID (object-id) of a file. This means that git log can detect + which commits changed a given path without needing to download extra + data. + + This means that blobless clones can perform commands like git + merge-base, git log, or even git log -- with the same performance + as a full clone. + + Commands like git diff or git blame require the contents of the + paths to compute diffs, so these will trigger blob downloads the first + time they are run. However, the good news is that after that you will + have those blobs in your repository and do not need to download them a + second time. Most developers only need to run git blame on a small + number of files, so this tradeoff of a slightly slower git blame command + is worth the faster clone and fetch times. + + Note: git v2.18 does not support treeless clones: --filter=tree:0. + */ + + // Note: for some reason it is necessary to pass "--progress ---v", + // otherwise QProcess returns an error of 128 = 0x80 for the command. + + QString gitCommand("git clone --progress -vvv --filter=blob:none "); gitCommand += m_repositoryPath; Command c(gitCommand); qInfo() << "IN CURRENT WD" << m_workingDirectory - << "CLONE" << m_repositoryPath << "..."; + << "CLONE VIA COMMAND" << gitCommand; if (c.execute(m_workingDirectory)) { // execute the command in wd QString const result = c.getCommandResult(); if (!result.isEmpty()) { // Cloning into 'customer_281'...\n - static QRegularExpression re("(^\\s*Cloning\\s+into\\s+[']\\s*)(.*)(\\s*['].*$)"); - QRegularExpressionMatch match = re.match(result); - if (match.hasMatch()) { - if (re.captureCount() == 3) { // start with full match (0), then the other 3 matches - if (match.captured(2).trimmed() == m_customerNr) { - qInfo() << "CLONING" << m_repositoryPath << "OK"; - return true; + int customer = -1; + int cloning = result.indexOf("Cloning", 0, Qt::CaseInsensitive); + if (cloning != -1) { + customer = result.indexOf("customer_", cloning, Qt::CaseInsensitive); + if (customer != -1) { + QString customerNr = result.mid(customer); + static constexpr char const ch = '\''; + int i = customerNr.indexOf(QChar(ch)); + if (i != -1) { + if ((customerNr = customerNr.mid(0, i)) == m_customerNr) { + qInfo() << "CLONING" << m_repositoryPath << "OK"; + return true; + } + Utils::printCriticalErrorMsg( + QString("ERROR CLONE RESULT HAS WRONG CUSTOMER-NR. (%1 != %2) CLONE_RESULT=%3") + .arg(customerNr) + .arg(m_customerNr) + .arg(result)); + return false; } } } + Utils::printCriticalErrorMsg( + QString("ERROR CLONE RESULT HAS WRONG FORMAT. CLONING=%1 CUSTOMER=%2 CLONE_RESULT=%3") + .arg(cloning) + .arg(customer) + .arg(result)); + return false; } - Utils::printCriticalErrorMsg(QString("ERROR CLONE RESULT HAS WRONG FORMAT. CLONE_RESULT=") + result); + Utils::printCriticalErrorMsg("ERROR CLONE RESULT IS EMPTY"); } return false; } @@ -114,16 +178,14 @@ bool GitClient::gitCloneAndCheckoutBranch() { return false; } -QStringList GitClient::gitShowReason() { +QStringList GitClient::gitShowReason(QString branchName) { QStringList lst; if (QDir(m_customerRepository).exists()) { // %h: commit (short form) // %s: commit message // %cI: commit date, strict ISO 8601 format - // Note: use master branch. By convention, there is a ChangeLog file - // in the root of the repository, which has to be always the last file - // to be checked in when the customer repository somehow changed. - Command c("git show origin/master -s --format=\"c=%h m=%s d=%cI\""); + // Note: branch with branchName has to exist: format zg1/zone1 + Command c(QString("git show origin/%1 -s --format=\"c=%h m=%s d=%cI\"").arg(branchName)); if (c.execute(m_customerRepository)) { QString const s = c.getCommandResult().trimmed(); int const c = s.indexOf("c="); @@ -217,92 +279,88 @@ std::optional GitClient::gitDiff(QString const &commits) { return std::nullopt; } +bool GitClient::gitFsck() { + bool r = false; + if (QDir(m_customerRepository).exists()) { + Command c("git fsck"); + if ((r = c.execute(m_customerRepository)) == false) { + QString const &s = c.getCommandResult().trimmed(); + Utils::printCriticalErrorMsg(QString("GIT FSCK FAILED: %1").arg(s)); + } + } + return r; +} /* Hat sich nichts geaendert, so werden auch keine Commits <>..<> angezeigt */ -std::optional GitClient::gitFetch() { +std::optional GitClient::gitPull() { if (QDir(m_customerRepository).exists()) { qInfo() << "BRANCH NAME" << m_branchName; - Command c("git fetch"); + Command c("git pull"); if (c.execute(m_customerRepository)) { QString const s = c.getCommandResult().trimmed(); if (!s.isEmpty()) { QStringList lines = Update::split(s, '\n'); + worker()->CONSOLE(lines) << Worker::UPDATE_STEP::UPDATE_REPOSITORY; if (!lines.empty()) { - int zoneNr = Utils::read1stLineOfFile("/mnt/system_data/zone_nr"); - m_branchName = (zoneNr != 0) ? QString("zg1/zone%1").arg(zoneNr) : "master"; - // lines can look like this: - // From https://git.mimbach49.de/GerhardHoffmann/customer_281 - // 41ec581..5d25ac3 master -> origin/master - // ff10f57..43530a1 zg1/zone1 -> origin/zg1/zone1 - // 6ed893f..5d9882c zg1/zone2 -> origin/zg1/zone2 - // 4384d17..77045d8 zg1/zone3 -> origin/zg1/zone3 - // 89d2812..36a0d74 zg1/zone5 -> origin/zg1/zone5 - bool found = false; - for (int i=0; i < lines.size(); ++i) { - if (lines.at(i).contains(m_branchName)) { - found = true; - // 409f198..6c22726 zg1/zone1 -> origin/zg1/zone1 - static QRegularExpression re("(^\\s*)([0-9A-Fa-f]+..[0-9A-Fa-f]+)(.*$)"); - QRegularExpressionMatch match = re.match(lines.at(i)); - if (match.hasMatch()) { - if (re.captureCount() == 3) { // start with full match (0), then the other 3 matches - return match.captured(2); + static const QRegularExpression alreadyUpToDate("^\\s*Already\\s+up\\s+to\\s+date.*$"); + if (std::none_of(lines.cbegin(), lines.cend(), + [](QString const &s) { return s.contains(alreadyUpToDate); })) { + int zoneNr = Utils::read1stLineOfFile("/mnt/system_data/zone_nr"); + m_branchName = (zoneNr != 0) ? QString("zg1/zone%1").arg(zoneNr) : "master"; + // lines can look like this: + // From https://git.mimbach49.de/GerhardHoffmann/customer_281 + // 41ec581..5d25ac3 master -> origin/master + // ff10f57..43530a1 zg1/zone1 -> origin/zg1/zone1 + // 6ed893f..5d9882c zg1/zone2 -> origin/zg1/zone2 + // 4384d17..77045d8 zg1/zone3 -> origin/zg1/zone3 + // 89d2812..36a0d74 zg1/zone5 -> origin/zg1/zone5 + bool found = false; + for (int i=0; i < lines.size(); ++i) { + if (lines.at(i).contains(m_branchName)) { + found = true; + // 409f198..6c22726 zg1/zone1 -> origin/zg1/zone1 + static QRegularExpression re("(^\\s*)([0-9A-Fa-f]+..[0-9A-Fa-f]+)(.*$)"); + QRegularExpressionMatch match = re.match(lines.at(i)); + if (match.hasMatch()) { + if (re.captureCount() == 3) { // start with full match (0), then the other 3 matches + QString const matchCaptured = match.captured(2); + worker()->CONSOLE(QStringList(matchCaptured)) << Worker::UPDATE_STEP::UPDATE_REPOSITORY; + return matchCaptured; + } else { + QStringList lst(QString("(wrong capture count (%1)").arg(re.captureCount())); + worker()->GUI(lst) << (worker()->CONSOLE(lst) << Worker::UPDATE_STEP::UPDATE_REPOSITORY_FAILURE); + } } else { - emit m_worker->showErrorMessage("git fetch", - QString("(wrong cap-count (%1)").arg(re.captureCount())); + QStringList lst("no regex-match for commits"); + worker()->GUI(lst) << (worker()->CONSOLE(lst) << Worker::UPDATE_STEP::UPDATE_REPOSITORY_FAILURE); } - } else { - emit m_worker->showErrorMessage("git fetch", - "no regex-match for commits"); - Utils::printCriticalErrorMsg("NO REGEX MATCH FOR COMMITS"); } } - } - if (!found) { - emit m_worker->showErrorMessage("git fetch", - QString("unkown branch name ") + m_branchName); - Utils::printCriticalErrorMsg("UNKNOWN BRANCH NAME " + m_branchName); + if (!found) { + QStringList lst(QString("unknown branch name ") + m_branchName); + worker()->GUI(lst) << (worker()->CONSOLE(lst) << Worker::UPDATE_STEP::UPDATE_REPOSITORY_FAILURE); + } + } else { + return "Already up to date"; } } else { - emit m_worker->showErrorMessage("git fetch", - QString("wrong format for result of 'git fetch' ") + s); - Utils::printCriticalErrorMsg(QString("WRONG FORMAT FOR RESULT OF 'GIT FETCH' ") + s); + QStringList lst(QString("WRONG FORMAT FOR RESULT OF 'GIT PULL' ") + s); + worker()->GUI(lst) << (worker()->CONSOLE(lst) << Worker::UPDATE_STEP::UPDATE_REPOSITORY_FAILURE); } } else { - emit m_worker->showErrorMessage("git fetch", "empty result for 'git fetch'"); - Utils::printCriticalErrorMsg("EMPTY RESULT FOR 'GIT FETCH'"); + QStringList lst("EMPTY RESULT FOR 'GIT PULL'"); + worker()->GUI(lst) << (worker()->CONSOLE(lst) << Worker::UPDATE_STEP::UPDATE_REPOSITORY_FAILURE); } } } else { - emit m_worker->showErrorMessage("git fetch", QString("repository ") + m_customerRepository + " does not exist"); - Utils::printCriticalErrorMsg(QString("REPOSITORY ") + m_customerRepository + " DOES NOT EXIST"); + QStringList lst(QString("REPOSITORY ") + m_customerRepository + " DOES NOT EXIST"); + worker()->GUI(lst) << (worker()->CONSOLE(lst) << Worker::UPDATE_STEP::UPDATE_REPOSITORY_FAILURE); } return std::nullopt; } -bool GitClient::gitFetchAndDiff() { - if (gitFetch()) { - QString gitCommand("git diff --compact-summary HEAD..FETCH_HEAD"); - Command c(gitCommand); - return c.execute(m_workingDirectory); - } - return false; -} - -bool GitClient::gitPull() { - if (QDir(m_customerRepository).exists()) { - Command c("git pull"); - if (c.execute(m_customerRepository)) { - qInfo() << "PULLED INTO" << m_customerRepository; - return true; - } - Utils::printCriticalErrorMsg(QString("PULL INTO " + m_customerRepository + " FAILED")); - } - return false; -} - std::optional GitClient::gitMerge() { Command c("git merge"); if (c.execute(m_workingDirectory)) { diff --git a/git/git_client.h b/git/git_client.h index 63d83e4..f6ce89e 100644 --- a/git/git_client.h +++ b/git/git_client.h @@ -43,14 +43,17 @@ class GitClient : public QObject { bool gitCloneAndCheckoutBranch(); - std::optional gitFetch(); - bool gitFetchAndDiff(); - bool gitPull(); + Worker *worker() { return m_worker; } + Worker const *worker() const { return m_worker; } + + std::optional gitPull(); std::optional gitDiff(QString const &commit); std::optional gitMerge(); + bool gitFsck(); + QString gitLastCommit(QString fileName); - QStringList gitShowReason(); + QStringList gitShowReason(QString branchName); static QString gitBlob(QString fileName); QString gitCommitForBlob(QString blob); bool gitIsFileTracked(QString file2name); diff --git a/interfaces.h b/interfaces.h new file mode 100755 index 0000000..65a0f67 --- /dev/null +++ b/interfaces.h @@ -0,0 +1,2372 @@ +#ifndef INTERFACE_H +#define INTERFACE_H + +#include + + + +struct T_emp +{ + + // Fixdata from EMP: + uint8_t shaft; // = changer level + uint16_t countryCode; + uint8_t scale; + uint8_t decimals; + uint8_t coinValues[16]; + uint16_t routing; + + // Master specs: + uint8_t gotSetup; // 1: got specifications from master 0: no specs + uint16_t coinAccept; // bit 0 = coin1 bit H=accept + uint8_t tokenChannel; + uint16_t denomination[16]; + + // dynamic: + uint8_t state; // step counter of EMP (electronic coin checker) FSM (finite state machine): + // 0=start command + // 1=powered, do emp ini, send reset + // 2=delay + // 3=wait for response, requesting status after response + // 4,5 through, startup + // 6: wait for status + // 7: through, startup + // 8: IDLE state. EMP is up and ready, polling is running + // 9: polling on, payment not yet on + // 10: payment, check coins + // 11: through + // 12: wait 1s for last coin + // 90: stop all, 1s delay + // 99: off, all stopped + + + uint8_t pollingRunning; + uint8_t paymentRunning; + +}; + +struct Trtc_DateTime +{ + uint8_t rtc_hour; + uint8_t rtc_min; + uint8_t rtc_sec; + uint8_t rtc_dayOfMonth; + uint8_t rtc_month; + uint8_t rtc_year; + uint8_t rtc_dayOfWeek; +}; + +struct Tprn_hw_state +{ + // hardware (IO's) + bool powerRdBk; // prn pwr is on + bool rsSwOk; // serial switch (printer or modem) is set to printer + bool rsDrvOk; // RS232 converter for PTU, Printer and Modem in on + + bool ReadyLine; // HW signal from printer showing ready + bool inIdle; // powered and free from errors + bool paperNearEnd; // paper roll runs out + bool noPaper; + bool ErrorTemp; + bool HeadOpen; + bool cutterJam; + bool noResponse; // printer is not connected, cable broken, wrong baudrate + bool badResponse; +}; + + struct Tprn_currentSettings +{ + uint8_t currFont; + uint8_t currSize; + uint8_t currHeigth; + uint8_t currWidth; + bool nowBold; + bool nowInvers; + bool nowUnderlined; + uint8_t currDensity; + uint8_t currSpeed; + bool nowAligned; +}; + +// obsolete + struct T_dynDat +{ + uint8_t licensePlate[8]; + uint8_t vendingPrice[8]; + uint8_t parkingEnd[8]; + uint8_t currentTime[8]; + uint8_t currentDate[8]; + uint8_t dynDat5[8]; + uint8_t dynDat6[8]; + uint8_t dynDat7[8]; +}; + + +struct T_vaultRecord +{ + + // Kassenbeleg (Abrechnungsdatensatz = Kassenwechsel-Datensatz) + char startbuffer[4]; // Psa> // never move or change this 1st entry + uint16_t AccountingNumber; + uint16_t CUNU; + uint16_t MANU; + uint16_t resint1; + //uint16_t resint2; + + char label1buffer[4]; // tim> + uint8_t year; + uint8_t month; + uint8_t dom; + uint8_t hour; + uint8_t min; + uint8_t sec; + uint8_t DoW; + uint8_t reschar3; + + char label2buffer[4]; // abs> + uint32_t AbsIncome1; + uint32_t AbsReserve; + uint32_t AbsNrOfCuts; + + char label3buffer[4]; // mw > + + // Verkauf, Tuer zu: + uint32_t VKcoinsInserted[16]; // nur fuer Wechsler, soviel wurde eingeworfen + uint32_t VKcoinsReturned[6]; // nur fuer Wechsler, Anzahl Muenzen pro Typ, soviel wurde zurueckgegeben + + // Service, Tuer offen: + uint16_t ServCoinsInserted[16]; // nur fuer Wechsler, soviel wurde eingeworfen + uint16_t ServCoinsReturned[6]; // nur fuer Wechsler, Anzahl Muenzen pro Typ, soviel wurde zurueckgegeben + uint16_t resint3; + uint16_t resint4; + uint16_t currentTubeContent[6]; // nur fuer Wechsler, aktueller Fuellstand + uint16_t resint5; + uint16_t resint6; + + char label4buffer[4]; // box> + uint16_t coinsInVault[16]; + uint16_t billsInStacker[8]; + + char label5buffer[4]; // val> + // actually constant unless exchange rate is changed + uint16_t coinDenomination[16]; // 5..50000 (z.B. 2? sind in Ungarn 760Ft) + uint16_t billDenom[8]; + uint16_t tubeDenom[6]; + uint16_t exchangeRate; + uint16_t resint9; + + // new from 1.8.23 + uint32_t cutsSinceCBchange; + uint32_t CBcontent_cent; + uint32_t CBnrofCoins; + + char endofblock[4]; // end +// 332 bytes + + uint16_t CRC16; // Xmodem16 from startbuffer[0] to endofblock[3] + uint16_t resint11; + char endofRecord[4]; // ---- + +}; + +struct T_moduleCondition +{ + // store conditon of all system components, hold in RAM + // 0 means unknown, not yet tested/used + // 1 means OK + // 50..99 = HINT / Notification + // 100..150 = WARNING + // 200..250 = ERROR + + uint8_t ram; + uint8_t intEe; + uint8_t extEe; + + uint8_t rtc; // 1: time/date OK 100: time not plausible 200: hardware error + uint8_t boardHw; + uint8_t printer; + uint8_t modem; + + uint8_t signal; // 1...99 + uint8_t regist; // 100:not 1:reg 2:ping OK 3:gotTime + uint8_t mdbBus; + uint8_t coinChecker; // EMP, OMP or mei-cashflow + + uint8_t coinEscrow; + uint8_t mifareReader; // 0: unknown 1=OK 200=no response 201=wrong response 202: Reader reports HW-error + uint8_t creditTerm; + uint8_t coinReject; + + uint8_t coinSafe; + uint8_t billSafe; + uint8_t voltage; // 1:11..14V + uint8_t temper; + + uint8_t poweronTest; + uint8_t doorState; // 1: alles zu 200: tuer offen + bit1(S) +bit2(CB) + bit3(CB) + uint8_t doorWasOpened; // 1: all doors are closed 200: any door was just opened + uint8_t changer; // can only be tested by usage + + uint8_t coinBlocker; // can only be tested by usage + uint8_t billReader; // can only be tested by usage + uint8_t ResetReason; + uint8_t allModulesChecked; + + uint8_t alarmState; + uint8_t res11; + uint8_t res12; + uint8_t res13; +// 31 +}; + +struct T_dynamicCondition +{ + char allDoorsDebounced; + char openedAuthorized; + uint8_t CBinDebounced; // 0:fehlt 1:drin + char upperDoor; // 99: undefined 0:closed 1:open + char middleDoor; // 99: undefined 0:closed 1:open + char lowerDoor; // 99: undefined 0:closed 1:open + char reserve; + char billBox; + char modeAbrech; + char onAlarm; // 0:alarm aus 1:alarm 2:alarm mit Sirene 3: Sirenentest + char nowCardTest; + char nowPayment; // not used, always 0 + char lastMifCardType; + uint8_t lastSDoorState; + uint8_t lastVDoorState; + uint8_t lastCBstate; + char paymentInProgress; + // 0: stopped by timeout + // 1: running 2: wait4lastCoin + // 3: payment stopped manually, coins in Escrow + // 4: payment stopped autom, amount collected, coins in Escrow + // 5: payment stopped, escrow full, coins in Escrow + // 6: coins encashed 7:coins returned + // 8: CoinChecker or MDB on Error + + + char res1; + uint16_t U_Batt; + uint16_t Temperatur; + uint16_t nrCoinsInBox; + uint32_t amountInBox; + uint32_t totalTransVolume; + uint32_t totalNrOfVends; + char jsonValid_config; + char jsonValid_device; + char jsonValid_cash; + char jsonValid_print; + char jsonValid_serial; + char jsonValid_time; + char lastFileType; +// 44 + uint8_t MifCardHolder[8]; + uint8_t resultOfLastTemplPrint; + // 0: unknown or printing in progress + // 1: OK, doc was printed 2: error, doc was not printed + uint8_t lastPrinterStatus; + // 0: printer OK + // bit0: near paper end bit1: no paper + // bit2: temperature error bit3: error head open + // bit4: paper jam in cutter + // bit6: no response bit7: serial rec. error + // bit5: printer not ready + uint8_t startupTestIsRunning; + + //54 +}; + +struct T_extTime +{ + uint8_t Hours; + uint8_t Min; + uint8_t Sec; + uint8_t Year; + uint8_t Month; + uint8_t Day; + uint8_t DOW; + uint8_t res1; + uint16_t MinOfDay; + uint16_t res2; + uint32_t SecOfDay; + uint8_t isLeapYear; + uint8_t nxtLeapYear; + uint8_t lastLeapYear; + uint8_t hoursOfThisWeek; + uint16_t minutesOfThisWeek; + uint16_t hoursOfThisMonth; + uint16_t daysOfThisYear; + uint16_t GetHoursOfYear; + uint16_t res3; + uint32_t GetMinutesOfYear; + uint8_t getWakeIntvSec; + uint8_t res4; + uint16_t res5; + uint32_t MinutesOfMillenium; + +}; + + +typedef uint8_t UCHAR; +typedef uint16_t UINT; + +struct T_devices +{ + // set by master, used(1) or notused (0) or type 2....20 + + UCHAR kindOfPrinter; // 0:off 1:Gebe + UCHAR kindOfCoinChecker; // 0: without 1=EMP820 2=EMP900 3=currenza Csquare (MW) + UCHAR kindOfMifareReader; // by now only stronglink SL025 =1 + UCHAR solarPower; // 1:sleep allowed 0: no sleep + //UCHAR suppressSleepMode; // 0:sleep allowed 1: no sleep + + UCHAR kindOfModem; // 0:off 1:Sunlink + UCHAR kindOfCreditcard; // 0:off 1:Feig NFC + UCHAR CoinEscrow; + UCHAR CoinRejectUnit; + + UCHAR CoinShutter; + UCHAR BillAcceptor; + UCHAR usevaultLock; + UCHAR autoAlarm; // 1: switch on siren for 1min in doors opened unauthorized + + UCHAR autoOpen; // 1: open door covers after valid ATBcard + UCHAR printAccReceipt; // 0/1 + UCHAR printDoorReceipt; + UCHAR printTokenTicket; + + UINT VaultFullWarnLevel; + UINT VaultFullErrorLevel; + UINT BattEmptyWarnLevel; + UINT BattEmptyErrorLevel; + +}; + +struct T_chg_Tub +{ + + uint8_t tubeLevel[8]; // [0]=nr coins of lowest value + uint8_t tubeFull[8]; // 1=full 0 else + uint16_t tubeValues[8]; // in cent [0]=lowest value 5c or 10cent + uint16_t tubeFilled[8]; // nr of every coin inserted + uint16_t tubeDispens[8]; // nr of every coin dispensed + // 64 byte +}; + +struct T_changer +{ + // Fixdata from Coin Changer + uint8_t setup; // always 1 + uint8_t state; // step of state machine + // 0..12 like EMP, 13...30 for coin dispense + + uint8_t level; // mdb-level, always 3 + uint16_t countryCode; + uint8_t scale; + uint8_t decimals; + uint8_t coinSetup[16]; // [0]=lowest coin, multiply with scale + uint16_t intendedAcceptance; //bitwise 0,1 1=accept coin, came from master + uint8_t tokenChannel; + uint8_t pollingRunning; // 1: emp is polled 0:not + uint8_t paymentRunning; // 1: coins are accepted + uint16_t denomination[16]; + uint16_t availableTubes; //bitwise 0,1 1=av. bit0 = lowest coin value +}; + +struct T_bna +{ + // reported with STATUS: + uint8_t setup; // 0: not 1: got valid parameters from device + uint8_t FeatureLevel; + uint16_t countryCode; // programmed in EMP + uint16_t scalingFactor; // z.B. 5 + uint8_t decimalPlace; + uint8_t pad1; + uint16_t stackerCap; + uint16_t billSecureLevel; + uint8_t hasEscrow; + uint8_t accBillTypes[16]; // programmed in EMP z.B. (bit 0..7): 1 2 4 10 20 40 0 0 + uint16_t currentStackerLevel; // requested number of notes in billbox + + // settings from Master + uint16_t intendedAccept; // bit 0 =5€ + uint16_t pad2; + uint16_t billDenomination[16]; + +}; + +class hwinf +{ + +public: + virtual ~hwinf() {} + + + + // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ + // Use serial interface and protocol stack in Cashagent-Library + // Sending Output data to DeviceController DC2b + // Sending input requests to DC2 (single or auto-batch) + // Getting input data as receiver payload + // Furthermore the Cashagent-Library answers with status strings about sending and reading result + // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ + + + virtual bool dc_openSerial(int BaudNr, QString BaudStr, QString ComName, uint8_t connect) const { + Q_UNUSED(BaudNr); + Q_UNUSED(BaudStr); + Q_UNUSED(ComName); + Q_UNUSED(connect); + return false; + } + // Command: open serial interface + // BaudNr: 0:1200 1:9600 2:19200 3:38400 4:57600 5:115200 + // BaudStr: for exapmle "19200" + // ComName: for example "COM48" + // connect: 0, 1 + + virtual void dc_closeSerial(void) const {} + // Command: close serial interface in order to save power while power down + // or if another port must be used + + + virtual bool dc_isPortOpen(void) const { + return false; + } + // returns true if port open (don't send unless open. Sending to closed port will crash program) + + virtual void dc_autoRequest(bool on) const { + Q_UNUSED(on); + } + // on = true: select that all READ-Requests are sent automatically + // on = false: select that all READ-Requests are sent manually one by one + // Every input information from DC2 must be requested + // ( digital and analog sensors, get time/date, get status information ) + + virtual void dc_requTestResponse() const {} + // tell DC2 to send a test-string, useful to see if cable and baudrate is OK + + virtual bool dc_readAnswTestResponse() const { + return false; + } + // retval: true: test was successful, got right response + + virtual uint8_t dc_isRequestDone(void) const { + return 0; + } + // retval: 0: request is still in progress + // 1: answer from DC2 was OK + // 2: wrong answer from DC2 + + virtual uint16_t dc_getCompletePayLoad(uint16_t plBufSiz, uint8_t *payLoad) const { + Q_UNUSED(plBufSiz); + Q_UNUSED(payLoad); + return 0; + } + // get data back in "payLoad", max 64 byte, can be used for diagnosis + // retval = nr of bytes received. If host buffer too small then + // only plBufSiz bytes are copied to "payLoad" + // plBufSiz = size of host buffer + + virtual void dc_setWakeFrequency(uint8_t period) const { + Q_UNUSED(period); + } + // RTC wakes DC2 (and PTU) by hardware signal every 32seconds + // change wake signal period to 1...64s + + virtual void dc_OrderToReset(void) const {} + // want DC2 to reset (in order to start Bootloader) + + + virtual QString dc_getSerialState(void) const { + return QString(); + } + // get result of opening-command like "ttyS0 opened with 115200 8N1! + // or error messages like "comport not available..." + // was saved by last opening event, can be passed for 100ms + + virtual void dc_clrSerialStateText(void) const {} + // clear above text to avoid multiple repetive displaying + + + virtual void bl_sendDataDirectly(uint8_t length, uint8_t *buf) const { + Q_UNUSED(length); + Q_UNUSED(buf); + } + // send without protocol frame, needed for the DC bootloader + + virtual uint8_t getRawRecLength(void) const { + return 0; + } + // only needed if protocol stack in Cashagent-Library is bypassed + + virtual uint8_t getRawReceivedData(uint8_t *receivedData) const { + Q_UNUSED(receivedData); + return 0; + } + // only needed if protocol stack in Cashagent-Library is bypassed + + virtual QString dc_getSerialParams(void) const { + return QString(); + } + // get DC2 serial settings (not very meaningful as they will not come if different from master settings) + + virtual QString dc_getHWversion(void) const { + return QString(); + } + // get DC2 hardware version + + virtual QString dc_getSWversion(void) const { + return QString(); + } + // get DC2 software version + + virtual QString dc_getState(void) const { + return QString(); + } + // get DC2 status (every OK or any error/warning? ) + + +// ---------------------------------------------------------------------------------------------------------- +// Date and Time +// ---------------------------------------------------------------------------------------------------------- + + virtual uint8_t rtc_getDateTime(struct Trtc_DateTime *rtc_DateTime) const { + Q_UNUSED(rtc_DateTime); + return 0; + } + + virtual uint8_t rtc_setDateTime(void) const { + return 0; + } + // synch DC2 with PC or PTU system time and date + + virtual void rtc_getTime(uint8_t *hh, uint8_t *mm, uint8_t *ss) const { + Q_UNUSED(hh); + Q_UNUSED(mm); + Q_UNUSED(ss); + } + // get time directly + + virtual void rtc_getDate(uint8_t *yy, uint8_t *mm, uint8_t *dd) const { + Q_UNUSED(yy); + Q_UNUSED(mm); + Q_UNUSED(dd); + } + // get date directly + + virtual uint8_t rtc_getToday(uint8_t *dow, uint16_t *minOfToday, uint32_t *secOfToday) const { + Q_UNUSED(dow); + Q_UNUSED(minOfToday); + Q_UNUSED(secOfToday); + return 0; + } + // dow=day of week, 1=monday...7 + // minOfToday: 0=midnight...1439= 23:59 + // secOfToday: 0=midnight...86399= 23:59:59 + + virtual bool rtc_isLeapYear(uint8_t *lastLeapYear, uint8_t *NextLeapYear) const { + Q_UNUSED(lastLeapYear); + Q_UNUSED(NextLeapYear); + return false; + } + // retval true: this year is leap year + + virtual bool rtc_isLeapYear() const { + return false; + } + + virtual void rtc_getWeek(uint8_t *DayOfWeek, uint8_t *HoursOfWeek, uint16_t *MinutesOfWeek) const { + Q_UNUSED(DayOfWeek); + Q_UNUSED(HoursOfWeek); + Q_UNUSED(MinutesOfWeek); + } + // DayOfWeek: 1=monday...7 + // HoursOfWeek: 0=Monday 0:00 o'clock...167=Sunday 23:00 + // MinutesOfWeek: 0=Monday 0:00 o'clock...10079=Sunday 23:59 + + virtual void rtc_getMonth(uint8_t *DayOfMonth, uint16_t *HoursOfMonth, uint16_t *MinutesOfMonth) const { + Q_UNUSED(DayOfMonth); + Q_UNUSED(HoursOfMonth); + Q_UNUSED(MinutesOfMonth); + } + // DayOfMonth: 1...31 + // HoursOfMonth: 0 = 0:00o'clock of 1.day in month up to 743 + // MinutesOfMonth:0 = 0:00o'clock of 1.day in month up to 44639 + + virtual void rtc_getYear(uint16_t *DayOfYear, uint16_t *HoursOfYear, uint32_t *MinutesOfYear) const { + Q_UNUSED(DayOfYear); + Q_UNUSED(HoursOfYear); + Q_UNUSED(MinutesOfYear); + } + // DayOfYear: 1...366 1= 1.Jan of this current year + // HoursOfYear: 0=1.Jan 0:00o'clock ...8783=31.12 23 o'clock + // MinutesOfYear: 0=1.Jan 0:00o'clock ...527039=31.12 23:59 o'clock + + virtual QString rtc_getTimStr(void) const { + return QString(); + } + virtual QString rtc_getDatStr(void) const { + return QString(); + } + virtual QString rtc_getTimDatStr(void) const { + return QString(); + } + + + // UID - unique number, different in every DC + virtual void dc_getUID8byte(uint8_t *buf8byteUid) const { + Q_UNUSED(buf8byteUid); + } + // get 8 single bytes in buffer + + virtual QString dc_getUIDstr() const { + return QString(); + } + // get as string + + virtual uint64_t dc_getUIDnumber(void) const { + return 0; + } + // get UID as one long number + +// ---------------------------------------------------------------------------------------------------------- +// analogs +// ---------------------------------------------------------------------------------------------------------- + + // Analog values: + virtual uint32_t dc_getTemperature(void) const { + return 0; + } + // in Sax-Format 0...400 (0=-50,0degC 100=0,0degC 141=20,5degC 400=150,0degC) + + virtual QString dc_getTemperaturStr(void) const { + return QString(); + } + // as string like "-12,5degC" + + virtual uint32_t dc_getVoltage(void) const { + return 0; + } + // as value in mV, 0...65,535V + + virtual QString dc_getVoltagStr(void) const { + return QString(); + } + // as string in mV + + virtual bool dc_mainFuseIsOk(void) const { + return false; + } + // true if 12V fuse is OK + // false: fuse blown, DC will continue working but no 12V device can be used! + +// ------------------------------------------------------------------------------ +// digital outputs +// ------------------------------------------------------------------------------ + + virtual uint8_t lock_switchUpperLock(uint8_t dir) const { + Q_UNUSED(dir); + return 0; + } + // dir 0=off 1=up 2=down + // move lock until stop cmd (0) + + virtual uint8_t lock_switchLowerLock(uint8_t dir) const { + Q_UNUSED(dir); + return 0; + } + // dir 0=off 1=up 2=down + // move lock until stop cmd (0) + + virtual void lock_switchVaultDoor(void) const {} + + virtual void coin_switchRejectMotor(uint8_t dir) const { + Q_UNUSED(dir); + } + + virtual void coin_rejectCoins(void) const {} + + // LEDs + virtual void led_switchLedService(uint8_t on) const { + Q_UNUSED(on); + } + virtual void led_switchLedPaper(uint8_t on, uint8_t ton, uint8_t tof) const { + Q_UNUSED(on); + Q_UNUSED(ton); + Q_UNUSED(tof); + } + virtual void led_switchLedPinPad(uint8_t on, uint8_t ton, uint8_t tof) const { + Q_UNUSED(on); + Q_UNUSED(ton); + Q_UNUSED(tof); + } + virtual void led_switchLedStart(uint8_t on, uint8_t ton, uint8_t tof) const { + Q_UNUSED(on); + Q_UNUSED(ton); + Q_UNUSED(tof); + } + virtual void led_switchLedCoinbassin(uint8_t on, uint8_t ton, uint8_t tof) const { + Q_UNUSED(on); + Q_UNUSED(ton); + Q_UNUSED(tof); + } + + virtual void fan_switchFan(bool on) const { + Q_UNUSED(on); + } + virtual void alarm_switchSiren(bool on) const { + Q_UNUSED(on); + } + virtual void bar_OpenBarrier(bool open) const { + Q_UNUSED(open); + } + virtual void ptu_switchWake(bool WAKEACTIVE) const { + Q_UNUSED(WAKEACTIVE); + } + + virtual void aux_power(bool on) const { + Q_UNUSED(on); + } + virtual void aux_setUsage(uint8_t PinDirection) const { + Q_UNUSED(PinDirection); + } + virtual void aux_setOutputs(uint8_t PinIsHigh) const { + Q_UNUSED(PinIsHigh); + } + + virtual void lock_switchContactPower(bool on) const { + Q_UNUSED(on); + } + + virtual void prn_switchPower(bool on) const { + Q_UNUSED(on); + } + + virtual void mif_readerOn(bool on) const { + Q_UNUSED(on); + } + + virtual void mif_creatAtbCard(uint8_t cardType) const { + Q_UNUSED(cardType); + } + + virtual void mod_switchPower(bool on) const { + Q_UNUSED(on); + } + + virtual void mod_switchWake(bool WAKEACTIVE) const { + Q_UNUSED(WAKEACTIVE); + } + + virtual void mdb_switchPower(bool on) const { + Q_UNUSED(on); + } + + virtual void mdb_switchWake(bool WAKEACTIVE) const { + Q_UNUSED(WAKEACTIVE); + } + + virtual void credit_switchPower(bool on) const { + Q_UNUSED(on); + } + // the same as modem power + + virtual void credit_switchWake(bool WAKEACTIVE) const { + Q_UNUSED(WAKEACTIVE); + } + + virtual void shut_move(bool open) const { + Q_UNUSED(open); + } + + virtual void esc_moveFlaps(uint8_t flap ) const { + Q_UNUSED(flap); + } + // 0: close both 1: open take-flap 2: open return + + +// ------------------------------------------------------------------------------ +// door, cashbox and lock switches +// ------------------------------------------------------------------------------ + + virtual uint8_t door_getSwitches(void) const { + return 0; + } + // retval: bit0: upper door 1: low door 2:vault door + + virtual bool door_isUpperDoorOpen(void) const { + return false; + } + + virtual bool door_isLowerDoorOpen(void) const { + return false; + } + + virtual bool vault_isVaultDoorOpen(void) const { + return false; + } + + virtual uint8_t vault_getSwitches(void) const { + return 0; + } + // retval bit0: cash box, bit 1: bill box + + virtual bool vault_isCoinVaultIn(void) const { + return false; + } + + virtual bool vault_isBillVaultIn(void) const { + return false; + } + + virtual uint8_t door_getLocks(void) const { + return 0; + } + // retval bit0: upper lever is up (=open) + // bit1: upper lever is down (=locked) + // bit2: lower lever is up + // bit3: lower lever is down (=locked) + + virtual bool door_upperDoorIsLocked(void) const { + return false; + } + + virtual bool door_upperDoorIsUnlocked(void) const { + return false; + } + + virtual bool door_lowerDoorIsLocked(void) const { + return false; + } + + virtual bool door_lowerDoorIsUnlocked(void) const { + return false; + } + + virtual bool bar_optoIn1isOn(void) const { + return false; + } + + virtual bool bar_optoIn2isOn(void) const { + return false; + } + + virtual uint8_t aux_getAuxInputs(void) const { + return 0; + } + + virtual bool ptu_WakeINisActive(void) const { + return false; + } + + virtual bool mdb_WakeINisActive(void) const { + return false; + } + + virtual bool prn_readyINisActive(void) const { + return false; + } + + virtual bool coid_isAttached(void) const { + return false; + } + + virtual bool coin_escrowIsOpen(void) const { + return false; + } + + virtual bool mif_cardIsAttached(void) const { + return false; + } + +//bool hwapi::mod_WakeINisActive(void); + + virtual bool door_isContactPowerOn(void) const { + return false; + } + + virtual bool mif_isMifarePowerOn(void) const { + return false; + } + + virtual bool mdb_testIsmdbTxDon(void) const { + return false; + } + + virtual bool aux_isAuxPowerOn(void) const { + return false; + } + + virtual bool mod_isGsmPowerOn(void) const { + return false; + } + + virtual bool cred_isCreditPowerOn(void) const { + return false; + } + + virtual bool prn_isPrinterPowerOn(void) const { + return false; + } + + virtual uint8_t prn_PrnFuseIsOk(void) const { + return 0; + } + //retval: 0: fuse blown 1: fuse OK 2:unknown as printer power is off + + virtual bool mdb_isMdbPowerOn(void) const { + return false; + } + + virtual bool cash_getRejectMotorHomePos(void) const { + return false; + } + + virtual uint8_t cash_getLowPaperSensor(void) const { + return 0; + } + // 0: Sensor sees paper 1: no paper 99: off + + + // ------------------------------------------------------------------------------ + // request commands + // ------------------------------------------------------------------------------ + + // all read-requests can be sent manually by the following functions + // or automatically in background by: void hwapi::dc_autoRequest(bool on) + + + virtual void request_DC2serialConfig() const {} + // read-request can be sent manually by this function, not needed if auto-request is on + + virtual void request_DC2_HWversion() const {} + // read-request can be sent manually by this function, not needed if auto-request is on + virtual void request_DC2_SWversion() const {} + // read-request can be sent manually by this function, not needed if auto-request is on + virtual void request_DC2_condition() const {} + // read-request can be sent manually by this function, not needed if auto-request is on + virtual void request_DC2_UID() const {} + // read-request can be sent manually by this function, not needed if auto-request is on + virtual void request_DC2_TimeAndDate() const {} + // read-request can be sent manually by this function, not needed if auto-request is on + virtual void request_DC2_analogues() const {} + // read-request can be sent manually by this function, not needed if auto-request is on + virtual void request_DC2_digitalInputs() const {} + // read-request can be sent manually by this function, not needed if auto-request is on + virtual void request_DC2_digitalOutputs() const {} + // read-request can be sent manually by this function, not needed if auto-request is on + + // ------------------------------------------------------------------------------ + + // the following device state requests are deployed only if device is powered up: + virtual void request_PrinterHwState() const {} + virtual void request_PrinterCurrentFonts() const {} + virtual void request_PrinterStateComplete() const {} + + virtual void request_MifareReaderState() const {} + virtual void request_MifareCardType() const {} + virtual void request_MifareAtbType() const {} + virtual void request_MifareID() const {} + virtual void request_MifareData(uint8_t dataBlockNumber) const { + Q_UNUSED(dataBlockNumber); + } + //virtual void request_MifareData() const =0; + + virtual void request_MDB_Status() const {} + virtual void request_MDB_lastResponse() const {} + virtual void request_EMP_allParameters() const {} + virtual void request_EMP_lastCoin() const {} + + + // ------------------------------------------------------------------------------ + // readback digital outputs of connected devices + // these functions are not needed for normal operation + // but can be used to test and verify conditions + // ------------------------------------------------------------------------------ + + + virtual bool test_getDO_mdbRXtst(void) const { + return false; + } + // readback digital outputs of connected devices + // these functions are not needed for normal operation + // but can be used to test and verify conditions + + virtual uint8_t lock_getDO_motors(void) const { + return 0; + } + // bit0: upper lock forward bit 1 backward + // bit2: lower lock forward bit 3 backward + + virtual uint8_t test_serialState(void) const { + return 0; + } + // test on-board signals for the serials + // serial drv on/off, Serial mux1, Serial mux2 + + virtual bool test_serialIsOn(void) const { + return false; + } + + virtual bool test_serialMux1isSetToPrinter(void) const { + return false; + } + virtual bool test_serialMux1isSetToModem(void) const { + return false; + } + virtual bool test_serialMux2isSetToCredit(void) const { + return false; + } + virtual bool test_serialMux2isSetToMifare(void) const { + return false; + } + + virtual bool led_coinIsOn(void) const { + return false; + } + virtual bool led_frontIsOn(void) const { + return false; + } + virtual bool led_ticketIsOn(void) const { + return false; + } + virtual bool led_pinIsOn(void) const { + return false; + } + virtual bool led_StartIsOn(void) const { + return false; + } + virtual bool led_insideIsOn(void) const { + return false; + } + + virtual bool fan_isOn(void) const { + return false; + } + virtual bool siren_isOn(void) const { + return false; + } + virtual bool bar_relayIsOn(void) const { + return false; + } + virtual bool ptu_WakeOutIsOn(void) const { + return false; + } + + virtual bool aux_powerIsOn(void) const { + return false; + } + + virtual bool coin_shutterIsOpen(void) const { + return false; + } + virtual bool coin_shutterTestOutput(void) const { + return false; + } + + virtual uint8_t coin_escrowFlapOpened(void) const { + return 0; + } + // retval: 1:return flap is open 2:take flap is open 0:closed + + + +// ------------------------------------------------------------------------------ +// devices are operated by DC +// processes with more then one devices +// timer controlled or long term processes +// ------------------------------------------------------------------------------ + + + virtual void sendDeviceSettings(uint8_t kindOfPrinter, uint8_t kindOfCoinChecker, + uint8_t kindOfMifareReader, uint8_t suppressSleep, + uint8_t kindOfModem, uint8_t kindOfCredit ) const { + Q_UNUSED(kindOfPrinter); + Q_UNUSED(kindOfCoinChecker); + Q_UNUSED(kindOfMifareReader); + Q_UNUSED(suppressSleep); + Q_UNUSED(kindOfModem); + Q_UNUSED(kindOfCredit); + } + // enable hardware in device controller: + // kindOfPrinter: 0:off 1: GPT4672 (only this one implemented) + // kindOfCoinChecker: 0:off 1:EMP820 2:EMP900 3: Csquare_changer + // kindOfMifareReader: 0:off 1: SL025 (only this one implemented) + // suppressSleep: 0:sleep allowed 1: sleep surpressed for special reason + // kindOfModem: 0:off 1: ATB_Sunlink_LTE (not yet implemented) + // kindOfCredit: 0:off 1: cVendTopp 2:cVendPin (not yet implemented) + + virtual void request_ReadbackDeviceSettings() const {} + + virtual void readback_DeviceSettings(uint8_t *length, uint8_t *data) const { + Q_UNUSED(length); + Q_UNUSED(data); + } + // refer to DC2 manual for exact content + // state 5.5.21: byte[0]=kindOfPrinter byte[1]=kindOfCoinChecker + // byte[2]=kindOfMifarereadr byte[3]=suppress sleep mode + // byte[4]=kindOfModem byte[5]=kind of cc terminal + + virtual void sendMachineID(uint16_t customerNr, uint16_t machineNr, + uint16_t borough, uint16_t zone, + uint16_t alias, char *location) const { + Q_UNUSED(customerNr); + Q_UNUSED(machineNr); + Q_UNUSED(borough); + Q_UNUSED(zone); + Q_UNUSED(alias); + Q_UNUSED(location); + } + + virtual void request_ReadbackMachineID() const =0; + + virtual void readback_machineIDdata(uint8_t *length, uint8_t *data) const { + Q_UNUSED(length); + Q_UNUSED(data); + } + // state 5.5.21: byte[0,1]=customer number byte[2,3]=machine number + // byte[4,5]=borough byte[6,7]=zone byte[8,9]=alias name + // byte[10...41]=location + + // Locks stops automatically at end switch or by timeout + virtual uint8_t lock_openUpperDoor(void) const { + return 0; + } + virtual uint8_t lock_closeUpperDoor(void) const { + return 0; + } + + virtual uint8_t lock_openLowerDoor(void) const { + return 0; + } + virtual uint8_t lock_closeLowerDoor(void) const { + return 0; + } + + virtual void shut_openOnce(void) const {} + // and close automatic after shutter time + + virtual void shut_openForCoin(bool start) const { + Q_UNUSED(start); + } + // open flap if coin is attached + // once process is started it runs until stop command + + virtual void shut_sendOpeningTime(uint16_t timeIn_ms ) const { + Q_UNUSED(timeIn_ms); + } + // after this time without retrigger the flap is closed + + virtual void esc_takeMoney(void) const {} + // and close automatically after escrow time (1s) + + virtual void esc_returnMoney(void) const {} + // and close automatically after escrow time (1s) + + +// ---------------------------------------------------------------------------------------------------------- +// --------------------------------------------- MIFARE ----------------------------------------------------- +// ---------------------------------------------------------------------------------------------------------- + +// obsolete + virtual uint8_t mif_returnReaderStateAndCardType(uint8_t *buf, uint8_t maxBufferSize) const { + Q_UNUSED(buf); + Q_UNUSED(maxBufferSize); + return 0; + } + // retval 0=OK 1=error host buffer too small + /* data description, new fast version: + byte 0= still the same: current read state: + 0=power off 1=reader-fault 2=ready + 3=just reading 4=read complete + 5=read partial, removed too early + 6=state unknown + + byte 1: reader state 1=ok 0=nok + byte 2: card preent (0,1) + byte 3: card selected (0) + byte 4: card type: 0...5 + byte 5: card allowed (0=no 1=MifareClassic 1k or 4k) + byte 6: CardSize: 1 or 4 (kB) + byte 7: length of UID 4 or 7 (byte) + */ + + virtual bool mif_readerIsOK(void) const { + return false; + } + + virtual bool mif_cardAttached(void) const { + return false; + } + // not working! use mif_cardIsAttached() instead + + virtual uint8_t mif_readResult(void) const { + return 0; + } + // result: 0: unknown or still in progress + // 1: card read successful + // 2: reading error + // not working! + + virtual QString mif_cardUID(void) const { + return QString(); + } + // not working + + virtual uint8_t mif_getCardDataDec(uint8_t blkNr, uint8_t *buf, uint8_t maxBufferSize) const { + Q_UNUSED(blkNr); + Q_UNUSED(buf); + Q_UNUSED(maxBufferSize); + return 0; + } + + virtual QString mif_getCardDataStr(uint8_t blockNumber) const =0; + // with blockNumber=0...11 + + + + // ---------------------------------------------------------------------------------------------------------- + // --------------------------------------------- PRINTER ---------------------------------------------------- + // ---------------------------------------------------------------------------------------------------------- + + // read printer condition and settings + + virtual uint8_t prn_getHwState(struct Tprn_hw_state *prn_hw_state) const { + Q_UNUSED(prn_hw_state); + return 0; + } + // retval: status byte + // byte 0 = 0: prnter OK, >0: error + // bit0: paper low 1: no paper 2: temperature error + // 3: head open 4: paper jam in cutter + // 6: no response 7: bad response from printer + // and return struct "Tprn_hw_state" + + virtual bool prn_isUpAndReady(void) const { + return false; + } + // true: printer is powered, serial is ok, no error, printer is connected and resonding + + virtual void prn_getCurrentFontSetting(struct Tprn_currentSettings *prn_fonts) const { + Q_UNUSED(prn_fonts); + } + + + // send Commands to printer: + + virtual void prn_sendText(QByteArray *buf) const { + Q_UNUSED(buf); + } + // up to 1280 bytes + + virtual void prn_sendPrnSysCmd(uint8_t para1, uint8_t para2, uint32_t para3) const { + Q_UNUSED(para1); + Q_UNUSED(para2); + Q_UNUSED(para3); + } + // send three byte through to printer, see printers manual + + virtual void prn_sendPrnEscCmd(uint8_t para1, uint8_t para2, uint8_t para3, uint8_t para4) const { + Q_UNUSED(para1); + Q_UNUSED(para2); + Q_UNUSED(para3); + Q_UNUSED(para4); + } + // send four byte through to printer, see printers manual + + + virtual void prn_sendPrnSetup(uint16_t paperSpeed, uint8_t density, uint8_t alignment, uint8_t orientation) const { + Q_UNUSED(paperSpeed); + Q_UNUSED(density); + Q_UNUSED(alignment); + Q_UNUSED(orientation); + } + // send 5 byte: byte 0,1: speed 5...250 mm/s + // byte2: density 0....(25)....50 + // byte3: alignment 'l', 'c', 'r' = left, center, right + // byte4: orientation 0, 90, 180 = 0deg, 90deg, 180deg rotation (by now not supported!) + // not batched! don't use twice within 100ms + + virtual void prn_movePaper(uint8_t wayInMm, uint8_t direction) const { + Q_UNUSED(wayInMm); + Q_UNUSED(direction); + } + //direction: 1=forward 2=backward + // + virtual void prn_setFonts(uint8_t font, uint8_t size, uint8_t width, uint8_t height) const { + Q_UNUSED(font); + Q_UNUSED(size); + Q_UNUSED(width); + Q_UNUSED(height); + } + // font = kind of font 5...11 (0..22) + // size = 6...20, 9..9: too tiny 10: small ...12 = normal size ...20=huge + // width: 0...4 0=1x 1=2x 2=4x (huge!) 3=8x 4=16x (3,4 make no sense) + // heigth: 0...7 = 1x...8x only 0,1,2,(3) make sense + + virtual void prn_setLetters(uint8_t bold, uint8_t invers, uint8_t underlined) const { + Q_UNUSED(bold); + Q_UNUSED(invers); + Q_UNUSED(underlined); + } + // bold: 0/1 + // invers: 0/1 + // underlined: 0/1 + + virtual void prn_cut(uint8_t kindof) const { + Q_UNUSED(kindof); + } + // kindof: 1=full cut 2=partial cut 3=eject (5xLF + full cut) + + virtual void prn_newLine(uint8_t nrOfLines) const { + Q_UNUSED(nrOfLines); + } + + virtual void prn_printCompleteFontTable(void) const {} + + + virtual void prn_printBarcode(uint8_t kindOf, uint8_t withText, uint8_t offset, uint8_t rotation, uint8_t dataLeng, uint8_t *data) const { + Q_UNUSED(kindOf); + Q_UNUSED(withText); + Q_UNUSED(offset); + Q_UNUSED(rotation); + Q_UNUSED(dataLeng); + Q_UNUSED(data); + } + // kind of barcode: 0=Code39 1=Code128 2=EAN13 3= 2/5interleaved 4=UPC-A 5=EAN8 + // withText: print readable text below + // offset: move by pixel from left border + // rotation + // dataLeng in byte + + virtual void prn_sendQRdata(QByteArray *buf) const { + Q_UNUSED(buf); + } + // maximal 150 alphanummeric bytes + + virtual void prn_printQRcode(void) const {} + // QRcode may have 1...150 alphanummeric data, must be transfered in advance + + + virtual void prn_printLogo(uint8_t nrOfLogo, uint8_t offset ) const { + Q_UNUSED(nrOfLogo); + Q_UNUSED(offset); + } + // nrOfLogo: 1..4 in flash 5...8 in Ram + // offset: in mm form left border + + + // ......................................................... + // Parking Ticket (print-out document) designer TD - obsolete + // ......................................................... + + + + // ---------------------------------------------------------------------------------------------------------- + // --------------------------------------------- MDB Bus ---------------------------------------------------- + // ---------------------------------------------------------------------------------------------------------- + + virtual void mdb_sendBusReset(void) const {} + + virtual void mdb_sendCommand(uint8_t toMdbDevice, uint8_t mdbCommand) const { + Q_UNUSED(toMdbDevice); + Q_UNUSED(mdbCommand); + } + // send one bus command directly over mdb bus, refer to mdb manual for commands + // this command is not needed in normal operation, just for new or special things + + virtual void mdb_sendMessage(uint8_t toMdbDevice, uint8_t mdbCommand, uint8_t nrOfData, uint8_t *dataBuffer) const { + Q_UNUSED(toMdbDevice); + Q_UNUSED(mdbCommand); + Q_UNUSED(nrOfData); + Q_UNUSED(dataBuffer); + } + // nrOfData = sizeOf(dataBuffer) maximal 34 byte according mdb specs + // same as mdb_sendCommand, just with data + + virtual bool mdb_busIsReadyToWork() const { + return false; + } + + virtual bool mdb_deviceVoltageOK() const { + return false; + } + + virtual bool mdb_busVoltageOk() const { + return false; + } + + virtual uint8_t mdb_getLastDeviceResponse(uint8_t *fromDevice, uint8_t *lastRequest, + uint8_t *responseLength, uint8_t *responseBuffer) const { + Q_UNUSED(fromDevice); + Q_UNUSED(lastRequest); + Q_UNUSED(responseLength); + Q_UNUSED(responseBuffer); + return 0; + } + // fromDevice: device nr from which data was requested 0,1,2,3 + // lastRequest: sent mdb command + // responseLength: nr of payload data (after mdb-ack) 0...34 + // responseBuffer holds payload data (answer from mdb device) + // return val: mdb result of this request: 1=got ACK 2=got 3xNAK 3=no or bad response 4:got Data (after ACK) + + + // ---------------------------------------------------------------------------------------------------------- + // ---------------------------------- Electronic Coin Validator EMP ----------------------------------------- + // ---------------------------------------------------------------------------------------------------------- + + + virtual void emp_sendSettings(uint16_t coinAcceptance, uint8_t tokenChannel, uint16_t *coinDenomination ) const { + Q_UNUSED(coinAcceptance); + Q_UNUSED(tokenChannel); + Q_UNUSED(coinDenomination); + } + // coinAcceptance: bit0=coin1 (lowest donomination) bit15=coin16 bitH=accept bit L = deny coin (no validation) + // tokenChannel 0...31: if this signal comes from emp then a token was inserted + // coinDenomination = array of 16 coin values (e.g. 5, 10, 20...) + + virtual void emp_pollingOnOff(uint8_t on) const { + Q_UNUSED(on); + } + + virtual void emp_startCoinAcceptance() const {} + + virtual void emp_stopCoinAcceptance() const {} + + virtual void emp_getAllParameters(struct T_emp *emp) const { + Q_UNUSED(emp); + } + // see struct in hwapi.h + // usage example: + // hwapi *HWaccess const override; + // HWaccess = new hwapi() const override; + // struct T_emp myEmp const override; + // HWaccess->emp_getAllParameters(&myEmp) const override; + // readval=myEmp.pollingRunning const override; + + virtual uint8_t emp_chkIfCoinInserted(void) const { + return 0; + } + // retval: 0...16 coins left in FIFO + + virtual void emp_getNewCoinRecord(uint8_t *valid, uint8_t *signal, uint8_t *error, uint16_t *value) const { + Q_UNUSED(value); + Q_UNUSED(signal); + Q_UNUSED(error); + Q_UNUSED(valid); + } + // with every call ONE coin is taken out of FIFO and pointer decremented + // valid: should be 1 + // signal: comes right from coin checker, 0...15 (0=first programmed coin type) 0xFF=no signal + // error: was reported from EMP as dynamic signal right after coin insertion (instead of + // coin signal), example: 3=unknown coin 4=coin is blocked by host. 0xFF=no error + // value: of the coin. Depends on parameter "coinDenomination" in function "emp_sendSettings" + // if coinDenomination[coin 0..15] = 0 then the value programmed in coin checker is taken + // if coinDenomination > 0 then this value is taken. + // Useful in case of two currencies (adapt to local currency) or for token. + + // function gives more details as "emp getLastCoin()" but "emp getLastCoin()" is easier to use + + // alternativ to emp_getNewCoinRecord( ): + virtual uint8_t emp_giveLastCoin(uint16_t *value, uint8_t *signal) const { + Q_UNUSED(value); + Q_UNUSED(signal); + return 0; + } + // retval: 0: NO coin stored 1: valid coin 2: got wrong coin or coin denied + // value: if retval1: value of the coin if reval=2: error number + // 0xFF means NO error or NO signal (as 0 is a valid error/signal) + // signal: channel nr reported from checker 0...15 + + + virtual uint8_t emp_returnLastCoin(uint16_t *value, uint8_t *signal) const { + Q_UNUSED(value); + Q_UNUSED(signal); + return 0; + } + // use for changer + + + + virtual QString dc_getTxt4RsDiagWin(void) const { + return QString(); + } + virtual void dc_clrTxt4RsDiagWin(void) const {} + virtual QString dc_get2ndTxt4RsDiagWin(void) const { + return QString(); + } + virtual void dc_clr2ndTxt4RsDiagWin(void) const {} + virtual QString dc_getTxt4HsStateLine(void) const { + return QString(); + } + virtual void dc_clrTxt4HsStateLine(void) const {} + virtual QString dc_getTxt4masterStateLine(void) const { + return QString(); + } + virtual void dc_clrTxt4masterStateLine(void) const {} + virtual QString dc_getTxt4resultStateLine(void) const { + return QString(); + } + virtual void dc_clrTxt4resultStateLine(void) const {} + virtual QString dc_getdataStateLine(void) const { + return QString(); + } + virtual void dc_clrTxt4dataStateLine(void) const {} + virtual QString dc_getdatifLine(void) const { + return QString(); + } + virtual void dc_clrTxt4datifLine(void) const {} + + + +// ---------------------------------------------------------------------------------------------------------- +// -------- DC Bootloader 1.Version +// ---------------------------------------------------------------------------------------------------------- + + // using DC2 Bootloader + virtual void bl_iniChain() const {} + virtual bool bl_importBinFile(QByteArray readBinFile, uint32_t fileSize, char withDispl) const { + Q_UNUSED(readBinFile); + Q_UNUSED(fileSize); + Q_UNUSED(withDispl); + return false; + } + virtual uint8_t bl_activatBootloader(uint8_t *sendData) const { + Q_UNUSED(sendData); + return 0; + } + virtual uint8_t bl_startChain() const { + return 0; + } + virtual uint8_t bl_readBLversion(uint8_t *sendData) const { + Q_UNUSED(sendData); + return 0; + } + // minimum size of sendData-buffer: 5byte retval: length + virtual uint8_t bl_readFWversion(uint8_t *sendData) const { + Q_UNUSED(sendData); + return 0; + } + // minimum size of sendData-buffer: 5byte retval: length + + virtual uint8_t bl_prepareDC_BLcmd(uint8_t Cmd, uint8_t SendDataLength, uint8_t *sendData, uint8_t *outBuf) const { + Q_UNUSED(Cmd); + Q_UNUSED(SendDataLength); + Q_UNUSED(sendData); + Q_UNUSED(outBuf); + return 0; + } + // make BL protocol, retval = outbuf length (5...133) + // bring data in correct form: start always with 0x02 finish with 0x03 and append checksum + // 0x02 Cmd < ...sendData ..> CRC CRC 0x03 + // Data length = 0...64 + // special conversion: if data contain 2 or 3 (STX, ETX) then write two bytes: 0x1B (=ESC) and data|0x80 + // so maxlength = 5 + 2 x 64 (if all data are 2 or 3) without 2,3: maxlength = 5 + 64 + + virtual uint8_t bl_exitBL(uint8_t *sendData) const { + Q_UNUSED(sendData); + return 0; + } + // minimum size of sendData-buffer: 5byte retval: length + + virtual void led_switchLedIllumination(uint8_t on) const { + Q_UNUSED(on); + } + + + + +// ------------------------------------------------------------------------------------ +// 27.3.2023: Use Device-Controller's Bootloader to send hex-file +// ------------------------------------------------------------------------------------ + + virtual void bl_rebootDC(void) const {} + + virtual void bl_startBL() const {} + virtual void bl_checkBL() const {} + virtual bool bl_isUp() const { + return false; + } + // return true is bl is up and running + // also initializes "sendFile" + + virtual void bl_sendAddress(uint16_t blockNumber) const { + Q_UNUSED(blockNumber); + } + // send start address, nr of 64byte-block, start with 0 + // will be sent only for folling block-numbers: + // 0, 1024, 2048, 3072 and 4096, so basically every 64kByte + + virtual uint8_t bl_wasSendingAddOK() const { + return 0; + } + // return val: 0: no response by now 1:error 10: OK + + virtual void bl_openBinary() const {} + + virtual void bl_sendDataBlock(uint8_t length, uint8_t *buffer) const { + Q_UNUSED(length); + Q_UNUSED(buffer); + } + // send 64 byte from bin file + + virtual void bl_sendLastBlock() const {} + + virtual uint8_t bl_wasSendingDataOK() const { + return false; + } + // return val: 0: no response by now 1:error 10: OK + + virtual void bl_stopBL() const {} + + +// ------------------------------------------------------------------------------------ +// 6.4.2023: new functions for coin collection and printing +// some new system functions +// ------------------------------------------------------------------------------------ + + + virtual bool rtc_setTimeDateDirect(struct Trtc_DateTime *DateTime) const { + Q_UNUSED(DateTime); + return false; + } + // return true if successful. could fail if more the 8 commands are waiting + + virtual bool rtc_getExtendedTime(uint8_t *leng, uint8_t *data) const { + Q_UNUSED(leng); + Q_UNUSED(data); + return false; + } + + virtual bool rtc_getExtendedTime(struct T_extTime *exTime) const { + Q_UNUSED(exTime); + return false; + } + + virtual bool sys_runCompleteTest() const { + return false; + } + // warning: lasts 20s in one pace + + virtual bool sys_ready4sending() const { + return false; + } + // return true if a Json-file can be sent + + virtual bool sys_sendJsonFileToDc(uint8_t kindOfFile, uint8_t nrOfTemplate, uint8_t *content ) const { + Q_UNUSED(kindOfFile); + Q_UNUSED(nrOfTemplate); + Q_UNUSED(content); + return false; + } + // kindOfFile: 1=config, 2=device, 3=cash, 4=serial, 5=time, 6=printer + // nrOfTemplate=1...32 if kindOfFile==6 + // content = content of the Json file, max 800byte ascii signs + // file is 0-terminated! + // return false if sending is not possible, wait a second + + virtual bool prn_sendDynamicPrnValues(uint8_t *dynPrnVal ) const { + Q_UNUSED(dynPrnVal); + return false; + } + // dynPrnVal = array of 8 Variables with 8 byte each, come as ascii string + // like: char prn_dynPrnVal[8][8]; + // return true if sending, false if cmd-stack is full + + virtual bool prn_printTemplate(uint8_t nrOftemplate) const { + Q_UNUSED(nrOftemplate); + return false; + } + // print one of the templates loaded by Json prior + // nr = 1..32 + // return true if sending, false if cmd-stack is full + + virtual void log_getHoldAccountNumbers(uint8_t *nrOfVals, uint16_t *accNr ) const { + Q_UNUSED(nrOfVals); + Q_UNUSED(accNr); + } + // returns all acc nrs of the backuped vault records + // use: uint16_t backupedAccNumbers[8] + + virtual bool log_selectVaultRecord(uint16_t accountNr ) const { + Q_UNUSED(accountNr); + return false; + } + // return true if sending, false if cmd-stack is full + // and trigger transfer + + virtual bool log_chkIfVaultRecordAvailable() const { + return false; + } + // return true if completly received + + virtual bool log_getVaultRecord(struct T_vaultRecord *retVR) const =0; + // which was selected by: log_selectVaultRecord() + // to be forwarded to Ismas + + virtual bool prn_printAccountReceipt() const { + return false; + } + // print all 8 backuped accounting receipts + // return true if sending to DC OK, false if cmd-stack is full + + virtual bool prn_printTestTicket() const { + return false; + } + // return true if sending to DC OK, false if cmd-stack is full + + + virtual bool cash_startPayment(uint32_t amount) const { + Q_UNUSED(amount); + return false; + } + // 17.4.23TS: extended to 32bit + + virtual uint8_t cash_paymentProcessing() const { + return 0; + } + // run this function periodically while coin payment process to generate necessary signals + // return value: + // 0: stopped 1: starting up 2: coin collection + // 3: finished by User (Push button) 4: finished, Max-Value collected + // 5: finished by escrow + // 10,11: error cannot start + // 12: timeout while payment, coins returned + // 13: stopped by unexpected error + + virtual uint32_t getInsertedAmount() const { + return 0; + } + + virtual uint16_t getLastInsertedCoin(void) const { + return 0; + } + + virtual bool getAllInsertedCoins(uint16_t *types, uint16_t *values) const { + Q_UNUSED(types); + Q_UNUSED(values); + return false; + } + // alle bei diesem Verkauf eingeworfenen Muenzen sind gespeichert, max 64 + + + virtual bool cash_cancelPayment() const { + return false; + } + // and return coins + + virtual bool cash_stopPayment() const { + return false; + } + // and keep coins in escrow + + + // after ticket/goods issue: + virtual bool vend_success() const { + return false; + } + // conclude payment process, encash all inserted coins to vault. Printing was successful + // if possible return change + + virtual bool vend_failed() const { + return false; + } + // conclude payment process and return all inserted coins + + + + + + virtual uint8_t mif_getCardType(QString *cardholder) const { + Q_UNUSED(cardholder); + return 0; + } + // return 1,2,3,4 = upper, lower access card, printer test, coin test + // cardholder: 7byte Name-String + + virtual uint64_t sys_getWakeSource() const { + return 0; + } + // retval: 6 bytes, bit coded, 1=event keeps DC awake + + virtual uint8_t sys_getWakeReason() const { + return 0; + } + // Master was woken by following reason: + // 1: MDB Event + // 2: Coin Event + // ( 3: Master Event) - will not set the wake line + // ( 4: 32s pulse) - will not set the wake line + // 5: Door Event + // ( 6: Diag Event) - will not set the wake line + // 7: 30min-Pulse for HB + + virtual void sys_getDeviceConditions(uint8_t *leng, uint8_t *data) const { + Q_UNUSED(leng); + Q_UNUSED(data); + } + + virtual void sys_getDeviceConditions(struct T_moduleCondition *devCond) const { + Q_UNUSED(devCond); + } + + virtual void sys_getDynMachineConditions(uint8_t *leng, uint8_t *data) const { + Q_UNUSED(leng); + Q_UNUSED(data); + } + + virtual void sys_getDynMachineConditions(struct T_dynamicCondition *dynMachCond) const { + Q_UNUSED(dynMachCond); + } + + + virtual uint32_t cash_getAmountInVault() const { + return 0; + } + + virtual uint16_t cash_getNrCoinsInVault() const { + return 0; + } + + virtual uint8_t prn_getPrintResult() const { + return 0; + } + + + + virtual uint8_t prn_getCurrentPrinterState() const { + return 0; + } + // 0: printer OK + // bit0: near paper end bit1: no paper + // bit2: temperature error bit3: error head open + // bit4: paper jam in cutter + // bit6: no response bit7: serial rec. error + // bit5: printer not ready + + + virtual void sys_sendDeviceParameter(struct T_devices *deviceSettings) const { + Q_UNUSED(deviceSettings); + } + + virtual void sys_restoreDeviceParameter(struct T_devices *deviceSettings) const { + Q_UNUSED(deviceSettings); + } + // attention: only applies if function "sys_sendDeviceParameter()" was used to send this settings before + // cannot be used to see settings programmed by JsonFile + + virtual bool sys_areDCdataValid() const { + return false; + } + + virtual bool sys_sendingTest() const { + return false; + } + + virtual void prn_requestCurrentDynData() const {} + + virtual bool prn_getCurrentDynamicPrnValuesFromDC(uint8_t *dynPrnVal ) const { + Q_UNUSED(dynPrnVal); + return false; + } + // which was sent with: bool prn_sendDynamicPrnValues(uint8_t *dynPrnVal ) const =0; + + virtual bool prn_dynDataAreEqual(uint8_t *buf) const { + Q_UNUSED(buf); + return false; + } + + virtual bool prn_printKombiticket(uint8_t nrOfKombi) const { + Q_UNUSED(nrOfKombi); + return false; + } + // print four of the templates loaded by Json prior + // nr = 1..8 + + virtual void lock_triggerUpperSolenoid(void) const {} + + virtual void lock_triggerLowerSolenoid(void) const {} + + virtual bool doors_supervise() const { + return false; + } + + virtual bool dc_isAutoRequestOn() const { + return false; + } + + virtual uint16_t log_getLatestAccountNumber() const { + return 0; + } + // new function 27.6.2023 + // latest = highest of the backup's + + virtual uint8_t log_getAvailableVaultBlocks() const { + return 0; + } + // return 0x0011 1111 if all 6 blocks are loaded (one bit per block) + + virtual uint8_t log_getAnswerToLastSlaveRequest() const { + return 0; + } + // use only for ONE request/command + // return: 0xFF: result unknown by now as sending is ongoing + // 0=OK + // 1= wrong length 2=wrong start sign 5= wrong crc + // 6= slave: master cmd was wrong 7: slave: could not write/read data + // 8=timeout, got no response from slave + // 0,8 work, 1..6 not yet tested. 8 comes immed. and stays 8 until reconnect + + // use for important and extended commands (print several templates, print ticket...) + virtual void log_startSupervision() const {} + + virtual uint8_t log_getAnswerToLastCmdBatch() const { + return 0; + } + // 0xFF: no command sent by now + // 0: started, in progress + // 1: done and OK + // 2: done and error + // not working properly, always 0 + + virtual bool log_getVaultData(uint8_t *data) const { + Q_UNUSED(data); + return false; + } + // get vault record in linear 8bit buffer with 384 byte + + + + // new from 1.8.23 + virtual bool prn_printOneAccountReceipt(uint16_t accountNr) const { + Q_UNUSED(accountNr); + return false; + } + // print one out of eight stored last accounting receipts + // function log_getHoldAccountNumbers() gives a list of acc-Nr. of the stored receipts + + virtual bool prn_printAllAvailAccountReceipts() const { + return false; + } + // same as: prn_printAccountReceipt() from line 1153 + // return true if sending to DC OK, false if cmd-stack is full + + virtual bool log_verifyVaultRecordByCrc() const { + return false; + } + // return true if CRC16 is correct, data are 100% OK. Security level 1:65536 + // verification is strongly recommended before further processing + // in case of "false"-result please reload from DC + + + virtual uint16_t log_DC_getNextAccountNumber() const { + return 0; + } + // the current cash box content will be backuped with this number on next cashbox-change + + virtual void log_DC_setNextAccountNumber(uint16_t newAccountingNumber) const { + Q_UNUSED(newAccountingNumber); + } + // the current cash box content will be backuped with this number on next cashbox-change + // use only in case of hardware replacements or errors which derailed the number + + virtual void log_DC_deleteAllVaultrecordsInDc() const {} + // use only in case of hardware replacements or errors which derailed the number + + virtual void log_DC_deleteAllTotalCounters() const {} + // use only in case of hardware replacements or errors which derailed the number + + virtual void dc_setNewCustomerNumber(uint16_t newCustNr) const { + Q_UNUSED(newCustNr); + } + + virtual void dc_setNewMachineNumber(uint16_t newMachNr) const { + Q_UNUSED(newMachNr); + } + + virtual void dc_setNewBorough(uint16_t newBorough) const { + Q_UNUSED(newBorough); + } + + virtual void dc_setNewZone(uint16_t newZone) const { + Q_UNUSED(newZone); + } + + + + // new functions from 8.9.23 + virtual QString mif_getReaderType() const { + return QString(); + } + // return "SL025" if correct reader is connected + + virtual void mif_getCardSize(uint8_t *cardSize, uint8_t *idLeng) const { + Q_UNUSED(cardSize); + Q_UNUSED(idLeng); + } + // cardSize=1k or 4kByte + // idLeng =4Byte or 7 byte + + virtual char mif_getAtbCardData(uint8_t *buf, uint8_t maxBuffSiz) const { + Q_UNUSED(buf); + Q_UNUSED(maxBuffSiz); + return 0; + } + // return complete buffer binary, just for test purpose + + virtual bool mif_isValidAtbCard() const { + return false; + } + + virtual uint32_t mif_getAtbCardCuNu() const { + return 0; + } + + virtual uint8_t mif_getAtbCardTyp() const { + return 0; + } + // return 1=upper door card 1=lower door 3=printer-test 4=coin-test + // 0: not a valid atb2020 card + + virtual QString mif_getAtbCardPerso() const { + return QString(); + } + // e.g. "PNsax001" used for personal number, name shortcode, card number + // free to use, can be set in AtbMcw23.exe tool + + virtual void mif_getAtbCardExpire(uint8_t *year, uint8_t *month, uint8_t *day, uint8_t *hour, uint8_t *minute) const { + Q_UNUSED(year); + Q_UNUSED(month); + Q_UNUSED(day); + Q_UNUSED(hour); + Q_UNUSED(minute); + } + + + // ------------------------------------------------------------------------------------ + // Device-Controller-Bootloader convenient version 21.09.2023 + // ------------------------------------------------------------------------------------ + + // use this to jump to BL: + //void hwapi::bl_rebootDC(void) const + + // use this to start BL: + // void hwapi::bl_startBL(void) const + + // call this in order to get response from BL: + //void hwapi::bl_checkBL(void) const + + // evaluate BL response: + //bool hwapi::bl_isUp(void) const + + // 29.9.23: new: "completeStart" function, replaces bl_rebootDC(), bl_startBL() and bl_checkBL() + // result can be verified with bl_isUp() as before + virtual bool bl_completeStart() const { + return false; + } + // must be used in DC's normal operation + + // select binfile-name in GUI + + // send binfile-name to BL-processor: + virtual bool bl_storeFirmware(QString fileName) const { + Q_UNUSED(fileName); + return false; + } + // load binary file 3x and compare + // return true if loaded correctly + // return false: error, could not load correctly + + // request the number of blocks for this file + virtual uint16_t bl_getNrOfFirmwareBlocks() const { + return 0; + } + // size of the loaded bin file in 64byte blocks + // call after bl_storeFirmware() + + // call the next two function's repetitive with "blockNumber"=0,1,2,3....."bl_getNrOfFirmwareBlocks()" + + virtual bool bl_blockAutoLoad(uint16_t blockNumber) const { + Q_UNUSED(blockNumber); + return false; + } + // call in loop from block number 0 up to <= "dcBL_getNrOfBlocks()" + //the last block "bl_getNrOfFirmwareBlocks()" is sent as conclusion command (important!) + // but after every call WAIT (!) for response "bl_blockAutoResponse()" !!!! + // data will be sent to DC, if neccesary addr will be sent additionally + // if neccesary sending will automatically repeat up to 3times + // retval: false if blockNumber>4095, true else + + // check out this response after every block-sending, wait until >0!!! + virtual int8_t bl_blockAutoResponse() const { + return 0; + } + // after every "bl_blockAutoLoad()" call this until response + // retval 0: wait 1: OK, blk was sent 2: OK, transfer complete + // 3: error despite repeating, cancel. probably bin file corrupted + // Max duration: 3x no response from BL = 900ms + + + // finally call: + // void hwapi::bl_stopBL(void) const + // -------------- end of bootloader --------------------------------------------------- + + + + // new from 28.9.23 and earliest from DC version 4.45 + // get all versions of the DC-Jsons + virtual void sys_requestJsonVersions(uint8_t jsonNr) const { + Q_UNUSED(jsonNr); + } + // send one request for every single version + // jsonNr=1...36, 1=config file (cust.Nr) 2=devices 3=cash 4=res. + // 5=printer template 1 ..... 36= template 32 + + virtual void sys_getJsonVersions(uint8_t jsonNr, char *versionString) const { + Q_UNUSED(jsonNr); + Q_UNUSED(versionString); + } + // jsonNr=1...36, 1=config file (cust.Nr) 2=devices 3=cash 4=res. + // 5=printer template 1 ..... 36= template 32 + // length of buffer is always 16 byte + + // ------------------------------------------------------------------------------------ + // Coin Changer + // ------------------------------------------------------------------------------------ + + // find above (same as for coin checker (EMP)): + + // mdb_switchPower(true); // power on/off + // cash_startPayment(amount_cent); // start polling, enable coins, changer turns to green + + // getInsertedAmount() + // getLastInsertedCoin() + // getAllInsertedCoins(uint16_t *types, uint16_t *values) + // all inserted coins of this past transaction are stored, max 64 + + // cash_stopPayment(); // and wait for further command (changer blinks yellow) + // cash_cancelPayment(); // and return complete paid amount + + // after ticket/goods issue: + // vend_success() + // conclude payment process, keep all coins. Printing was successful + // return change (payment above start-amount), so it works only if + // Payment was started with real vending price (pre selection). + // if payment was started with maximum price (for direct coin insertion) + // then use "changer_returnCoins()", not vend_success() + + // vend_failed() + // conclude payment process and return complete paid amount + + // also valid for changer: + // emp_sendSettings(uint16_t coinAcceptance, uint8_t tokenChannel, uint16_t *coinDenomination ) const =0; + // coinAcceptance: bit0=coin1 (lowest donomination) bit15=coin16 bitH=accept bit L = deny coin (no validation) + // tokenChannel 0...31: if this signal comes from emp then a token was inserted + // coinDenomination = array of 16 coin values (e.g. 5, 10, 20...) + + virtual void changer_returnCoins(uint32_t amountInCent) const { + Q_UNUSED(amountInCent); + } + + virtual void changer_requestChangeResult() const {} + + virtual uint8_t changer_getChangeResult(uint32_t *returnedAmount) const { + Q_UNUSED(returnedAmount); + return 0; + } + // get result of coin dispensing + // receivedData[0]: 0: not yet started 1:amount returned + // 2:only partial return 3: no return possible + // receivedData[2,3,4,5]: returned amount + + virtual void changer_getAllParameters(struct T_changer *mw) const { + Q_UNUSED(mw); + } + // requested automatically with 23, same like EMP + + virtual void changer_requestTubelevel(void) const {} + + virtual void changer_getTubelevel(struct T_chg_Tub *tubLevel) const { + Q_UNUSED(tubLevel); + } + // don't use tubeDispens[], it's not yet correct! + + + + // ------------------------------------------------------------------------------------ + // bank note acceptor + // ------------------------------------------------------------------------------------ + + // already defiened functions applying for BNA as well: + // mdb_switchPower(true); // power on/off + + // bank notes are integrated in the normal transaction process, so use the usual functions to run a vending cycle: + // cash_startPayment(amount_cent); // start polling, enable bills, reader shows green + // getInsertedAmount() + // cash_stopPayment(); + // cash_cancelPayment(); + // vend_success() + // vend_failed() + + virtual void bna_sendSettings(uint16_t notesToAccept, uint16_t parameters, + uint16_t *billDenomination, + uint32_t acceptanceLimit) const { + Q_UNUSED(notesToAccept); + Q_UNUSED(parameters); + Q_UNUSED(billDenomination); + Q_UNUSED(acceptanceLimit); + + } + // notesToAccept: bit0=bill1 (lowest donomination) bitH=accept bit L = deny + // parameters: e.g. use escrow function for some notes + // billDenomination = array of 16 bill values (e.g. 5, 10, 20...) + // these can be set alternatively by Json-File DC2C_cash.json + // acceptanceLimit: device will stop acceptance once this amount is reached and + // optionally keep last bill in escrow until vend_success() + // is called (put bill to stacker) or vend_failed() is called (return bill) + + virtual void bna_setCurrentAcceptance(uint16_t notesToAccept) const { + Q_UNUSED(notesToAccept); + } + // can be used to block notes dynamically, example: from now only 5€ bills are allowed (if only 3€ are to be paid) + // only valid till next start-payment. Cannot add notes which are not activated in Json + + virtual void bna_requestParameters() const {} + // send command to DC in order to get static invariable device parameters like currency + // device must be powered and polled to get these + + virtual bool bna_getAllParameters(struct T_bna *bna) const { + Q_UNUSED(bna); + return false; + } + // get all constant data from reader (e.g. currency) + // and actual Host-Settings (sent with bna_sendSettings() or json) + // retval = true if data are valid + + 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 { + Q_UNUSED(latestBill); + Q_UNUSED(currentNotes); + return 0; + } + // returns number of collected bank notes since start-command (current transaction) + // latestBill: last accepted bank note, value in cent + // currentNotes an array with up to 16 (further) notes collected + + virtual void bna_requestStackerLevel() const {} + + virtual uint16_t bna_getStackerLevel(uint32_t *amountInStacker, uint16_t *countOfBills) const { + Q_UNUSED(amountInStacker); + Q_UNUSED(countOfBills); + return 0; + } + // return val: nr of bills in stacker + // countOfBills: array of up to 16 sums, countOfBills[0]=nr of 5€-bills in stacker + // countOfBills[1] for 10€ and so on + + + + +signals: + // NOTE: declaring a "pure virtual" "signal" should be an error and thus not valid. + void hwapi_templatePrintFinished_OK() const; + void hwapi_templatePrintFinished_Err() const; + + void hwapi_coinCollectionJustStarted() const; + void hwapi_coinCollectionAborted() const; + + void hwapi_gotNewCoin() const; + void hwapi_payStopByMax() const; + void hwapi_payStopByPushbutton() const; + + void hwapi_payStopByEscrow() const; + void hwapi_payStopByError() const; + void hwapi_payStopByTimeout() const; + void hwapi_payCancelled() const; + void hwapi_coinProcessJustStopped() const; + + void hwapi_doorServiceDoorOpened() const; + void hwapi_doorVaultDoorOpened() const; + void hwapi_doorCoinBoxRemoved() const; + void hwapi_doorCoinBoxInserted() const; + void hwapi_doorCBinAndAllDoorsClosed() const; + void hwapi_doorAllDoorsClosed() const; +}; + + +// History +// 11.10.2021: V1.0 222 functions +// 23.12.2021: V1.1 added block-parameter to function "read mifare data" +// 30.12.2021: V1.2 added function: mif_clearDataBuffer(), mif_isBlockAvailable(uint8_t blkNr) and mif_getAvailableDataBlocks() +// 1.1.2022: V1.3 Mifare extended. ( background: read 16 x 48byte from card to DC, read 12 x 64byte from DC to CA) +// new: read full card with 768bytes from HWapi without block borders +// added: mif_getNrOfAvailableDataBytes mif_getCardData768byteDec(uint8_t *buf, uint16_t bufferSize) +// mif_getCardDataDec(uint16_t fromAddr, uint16_t toAddr, uint8_t *buf, uint16_t bufferSize) +// mif_getCardDataStr(bool useHexFormat, char seperator) + +// 29.03.2023: V3.1 some extensions for PSA1256_ptu5, +// V3.2 Bootloader improvement +// 12.04.2023: V3.3 new features extended: loading and using Json-files, cash-collection, cash-data-logging +// 14.04.2023: V3.4 new features extended: sys_getDynMachineConditions, sys_getDeviceConditions and +// rtc_getExtendedTime return struct in addition. New function to select and get VaultRecord +// +// 19.04.2023: V3.5 new function: sys_getWakeReason(); +// 17.05.2023: V3.6 new function: cash_isCollectionActive(), cash_isPayProcessActive() +// new signals: hwapi_coinCollectionJustStopped, hwapi_coinCollectionJustStarted +// getAllInsertedCoins() fixed, also in datif and storeINdata + +// 15.06.2023 V4.2 bring into same order as hwapi in order to set the THIS_IS_CA_MASTER correct +// 19.06.2023 V4.3 added some qCriticals to see emits + +// 01.08.2023 V4.4 some new values at the end of struct T_vaultRecord +// two more values in struct T_devices +// 7 new functions at the end of the file + + +//#define HWINF_iid "Atb.Psa2020.software.HWapi/3.1" +//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/3.1" +//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/3.3" +//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/3.4" +//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/3.5" +//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/3.6" +//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.0" +//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.1" +//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.2" +//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.3" +//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.4" + // 8.9.2023 two new functions (end of file) for mifare test +//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.5" + // 18.9.2023 major improvements for DC data exchange + // verification of door and cash box signals + // intensive verification of Json-Programming Master-Slave (PTU to DC), 100% ok +//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.6" + // 20.9.2023: speeding up door and cash box signals +//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.7" + // 26.09.2023: added improved DC-bootloader files +//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.8" +// 28.09.2023: added version request of DC-Json-Files +//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/5.0" + // 10.10.2023: added coin changer + +//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/5.1" +// 20.10.2023: added bill validator + +// hier dazwischen: Umstellung ALLER Prototypen +// hier von =0 auf {} durch Gerhard + +#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/5.2" + // 7.11.2023: bna functions activated + + +Q_DECLARE_INTERFACE(hwinf, HWINF_iid) + + +#endif + + + diff --git a/ismas/ismas_client.cpp b/ismas/ismas_client.cpp index 0e5ba65..b637136 100644 --- a/ismas/ismas_client.cpp +++ b/ismas/ismas_client.cpp @@ -23,6 +23,15 @@ #include #if 0 +######################## +# Spec vom 27.10.2023: +# U0010 -> %-Werte +# U0001 -> 100% +# U0003 -> "FAIL" +# U0002 -> "" (OK -> WAIT state reset) +# ISMAS -> "WAIT" +######################## +# # $1: EVENT: U0001 update finished: 100% # U0002 reset TRG # U0003 error @@ -47,6 +56,12 @@ void IsmasClient::printDebugMessage(int port, QString const &clientIP, int clientPort, QString const &message) { +#if 0 + Q_UNUSED(port); + Q_UNUSED(clientIP); + Q_UNUSED(clientPort); + Q_UNUSED(message); +#else qDebug().noquote() << "\n" << "SEND-REQUEST-RECEIVE-RESPONSE ..." << "\n" @@ -55,12 +70,19 @@ void IsmasClient::printDebugMessage(int port, << "local address ..." << clientIP << "\n" << "local port ......" << clientPort << "\n" << message; +#endif } void IsmasClient::printInfoMessage(int port, QString const &clientIP, int clientPort, QString const &message) { +#if 0 + Q_UNUSED(port); + Q_UNUSED(clientIP); + Q_UNUSED(clientPort); + Q_UNUSED(message); +#else qInfo().noquote() << "\n" << "SEND-REQUEST-RECEIVE-RESPONSE ..." << "\n" @@ -69,6 +91,7 @@ void IsmasClient::printInfoMessage(int port, << "local address ..." << clientIP << "\n" << "local port ......" << clientPort << "\n" << message; +#endif } void IsmasClient::printErrorMessage(int port, @@ -292,7 +315,7 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) { } } - printInfoMessage(port, clientIP, clientPort, QString("MESSAGE RECEIVED ") + buf); + // printInfoMessage(port, clientIP, clientPort, QString("MESSAGE RECEIVED ") + buf); QString response(buf); if (int idx = response.indexOf("{\"error\":\"ISMAS is offline\"}")) { @@ -367,16 +390,18 @@ QString IsmasClient::errorBackendNotConnected(QString const &info, version.toStdString().c_str()); } -QString IsmasClient::errorGitClone(int percent, QString const &info, QString const &version) { +QString IsmasClient::errorGitClone(QString const &info, + QString const &version) { return updateNewsToIsmas("U0003", - percent, + m_progressInPercent, RESULT_CODE::INSTALL_ERROR, "CLONE CUSTOMER REPOSITORY FAILED", info.toStdString().c_str(), version.toStdString().c_str()); } -QString IsmasClient::backendConnected(QString const &info, QString const &version) { +QString IsmasClient::backendConnected(QString const &info, + QString const &version) { return updateNewsToIsmas("U0010", m_progressInPercent, RESULT_CODE::SUCCESS, @@ -385,7 +410,8 @@ QString IsmasClient::backendConnected(QString const &info, QString const &versio version.toStdString().c_str()); } -QString IsmasClient::execOpkgCommand(QString const &info, QString const &version) { +QString IsmasClient::execOpkgCommand(QString const &info, + QString const &version) { return updateNewsToIsmas("U0010", m_progressInPercent, RESULT_CODE::SUCCESS, @@ -622,6 +648,9 @@ QString IsmasClient::updateOfPSASendVersion(PSAInstalled const &psa) { "}," "\"ATBQT\" : {" "\"VERSION\" : \"%s\"" + "}," + "\"ATB-UPDATE-TOOL\" : {" + "\"VERSION\" : \"%s\"" "}" "}," "\"PLUGINS\" : {" @@ -749,6 +778,7 @@ QString IsmasClient::updateOfPSASendVersion(PSAInstalled const &psa) { psa.sw.apismVersion.toStdString().c_str(), psa.sw.atbQTVersion.toStdString().c_str(), + psa.sw.atbUpdateToolVersion.toStdString().c_str(), psa.pluginVersion.deviceController.toStdString().c_str(), psa.pluginVersion.ingenicoISelfCC.toStdString().c_str(), @@ -857,7 +887,14 @@ QString IsmasClient::jsonParseFailed(int resultCode, QString reason, QString con version.toStdString().c_str()); } -std::optional IsmasClient::finalResult(int resultCode, QString reason, QString const &version) { +std::optional IsmasClient::finalResult(int resultCode, + QString reason, + QString const &version) { + Q_UNUSED(resultCode); + Q_UNUSED(reason); + Q_UNUSED(version); + + /* m_progressInPercent = 100; if (resultCode == RESULT_CODE::SUCCESS) { return updateNewsToIsmas("U0002", @@ -875,6 +912,7 @@ std::optional IsmasClient::finalResult(int resultCode, QString reason, reason.toStdString().c_str(), version.toStdString().c_str()); } + */ return std::nullopt; } diff --git a/ismas/ismas_client.h b/ismas/ismas_client.h index a43fe1f..34b0d9f 100644 --- a/ismas/ismas_client.h +++ b/ismas/ismas_client.h @@ -48,6 +48,7 @@ struct PSAInstalled { struct SoftWare { QString apismVersion; QString atbQTVersion; + QString atbUpdateToolVersion; } sw; struct PluginVersion { @@ -98,6 +99,7 @@ struct PSAInstalled { sw.apismVersion = "N/A"; sw.atbQTVersion = "N/A"; + sw.atbUpdateToolVersion = "N/A"; pluginVersion.deviceController = "N/A"; pluginVersion.ingenicoISelfCC = "N/A"; @@ -175,7 +177,7 @@ public: QString cloneAndCheckoutCustomerRepository(QString const &info, QString const &version = QString()); // clone and checkout customer repository QString checkoutBranch(QString const &info, QString const &version = QString()); // checkout branch QString errorBackendNotConnected(QString const &info, QString const &version = QString()); // checkout branch - QString errorGitClone(int percent, QString const &info, QString const &version = QString()); + QString errorGitClone(QString const &info, QString const &version = QString()); QString backendConnected(QString const &info, QString const &version = QString()); QString updateTriggerSet(QString const &info, QString const &version = QString()); QString errorUpdateTrigger(QString const &info, QString const &version = QString()); diff --git a/main.cpp b/main.cpp index 877ebae..7b19f21 100644 --- a/main.cpp +++ b/main.cpp @@ -10,6 +10,7 @@ #include "message_handler.h" #include "plugins/interfaces.h" +#include "commandline_parser.h" #include #include @@ -21,6 +22,7 @@ #include #include #include +#include #include "update.h" #include "git/git_client.h" @@ -51,7 +53,7 @@ int main(int argc, char *argv[]) { if (value != "C") { qputenv("LC_ALL", "C"); } - // qputenv("XDG_RUNTIME_DIR", "/run/user/0"); + // qputenv("XDG_RUNTIME_DIR", "/var/run/user/0"); openlog("ATB-UPDATE", LOG_PERROR | LOG_PID | LOG_CONS, LOG_USER); @@ -64,74 +66,73 @@ int main(int argc, char *argv[]) { setDebugLevel(LOG_NOTICE); } -//#if defined (Q_OS_UNIX) || defined (Q_OS_LINUX) -//#ifdef _POSIX_THREAD_PROCESS_SHARED -// errno = 0; -// int res = 0; -// if ((res = sysconf(_SC_THREAD_PROCESS_SHARED)) < 0) { -// if (errno != 0) { -// qCritical() << "_POSIX_THREAD_PROCESS_SHARED NOT SUPPORTED" -// << strerror(errno); -// exit(-1); -// } -// } else { -// if (res == _POSIX_THREAD_PROCESS_SHARED) { -// Utils::printInfoMsg("_POSIX_THREAD_PROCESS_SHARED SUPPORTED"); -// } -// } -//#endif -//#endif - - QCommandLineParser parser; - parser.setApplicationDescription("Download tool for downloading device controller firmware, printer json-files and executing opkg-commands."); - parser.addHelpOption(); - parser.addVersionOption(); - - QCommandLineOption pluginDirectoryOption(QStringList() << "plugin-directory" << "plugin-directory", - QCoreApplication::translate("main", "Where to find dc-plugin."), - QCoreApplication::translate("main", "directory")); - QString const pluginDefault = "/usr/lib"; - pluginDirectoryOption.setDefaultValue(pluginDefault); - parser.addOption(pluginDirectoryOption); - - QCommandLineOption pluginNameOption(QStringList() << "plugin-name" << "plugin-name", - QCoreApplication::translate("main", "Name of dc-plugin."), - QCoreApplication::translate("main", "directory")); - QString const pluginNameDefault = "libCAslave.so"; - pluginNameOption.setDefaultValue(pluginNameDefault); - parser.addOption(pluginNameOption); - - QCommandLineOption workingDirectoryOption(QStringList() << "working-directory" << "working-directory", - QCoreApplication::translate("main", "working directory of update-script."), - QCoreApplication::translate("main", "directory")); - QString const workingDirectoryDefault = "/opt/app/tools/atbupdate"; - workingDirectoryOption.setDefaultValue(workingDirectoryDefault); - parser.addOption(workingDirectoryOption); - - QCommandLineOption dryRunOption(QStringList() << "d" << "dry-run", - QCoreApplication::translate("main", "Start ATBUpdateTool in dry-run-mode. No actual actions.")); - parser.addOption(dryRunOption); - - // Process the actual command line arguments given by the user + CommandLineParser parser; parser.process(a); - QString plugInDir = parser.value(pluginDirectoryOption); - QString plugInName = parser.value(pluginNameOption); - QString workingDir = parser.value(workingDirectoryOption); - bool dryRun = parser.isSet(dryRunOption); + parser.readSettings(); + + QString repositoryUrl = parser.repositoryUrl(); + QString plugInDir = parser.plugInDir(); + QString plugInName = parser.plugInName(); + QString workingDir = parser.workingDir(); + QString iniFileName = parser.iniFileName(); + bool const dryRun = parser.dryRun(); + bool const noUpdatePsaHardware = parser.noUpdatePsaHardware(); + bool const showYoctoVersion = parser.yoctoVersion(); + bool const showYoctoInstallStatus = parser.yoctoInstallStatus(); + bool const showExtendedVersion = parser.extendedVersion(); + bool const alwaysDownloadConfig = parser.alwaysDownloadConfig(); + bool const alwaysDownloadDC = parser.alwaysDownloadDC(); + QString const rtPath = QCoreApplication::applicationDirPath(); + int const machineNr = Utils::read1stLineOfFile("/mnt/system_data/machine_nr"); + int const customerNr = Utils::read1stLineOfFile("/mnt/system_data/cust_nr"); + int const zoneNr = Utils::read1stLineOfFile("/mnt/system_data/zone_nr"); + QString const branchName = (zoneNr != 0) + ? QString("zg1/zone%1").arg(zoneNr) : "master"; + + qInfo() << "pwd ......................" << rtPath; + qInfo() << "repositoryUrl ............" << repositoryUrl; + qInfo() << "plugInDir ................" << plugInDir; + qInfo() << "plugInName ..............." << plugInName; + qInfo() << "workingDir ..............." << workingDir; + qInfo() << "dryRun ..................." << dryRun; + qInfo() << "noUpdatePsaHardware ......" << noUpdatePsaHardware; + qInfo() << "alwaysDownloadConfig ....." << alwaysDownloadConfig; + qInfo() << "alwaysDownloadDC ........." << alwaysDownloadDC; + qInfo() << "showYoctoVersion ........." << showYoctoVersion; + qInfo() << "showYoctoInstallStatus ..." << showYoctoInstallStatus; + qInfo() << "showExtendedVersion ......" << showExtendedVersion; + qInfo() << "iniFileName .............." << iniFileName; + qInfo() << "extended-version ........." << APP_EXTENDED_VERSION; + qInfo() << "machineNr ................" << machineNr; + qInfo() << "customerNr ..............." << customerNr; + qInfo() << "zoneNr ..................." << zoneNr; + + if (showExtendedVersion) { + printf(APP_EXTENDED_VERSION"\n"); + return 0; + } + if (showYoctoVersion) { + printf("%s\n", Worker::getATBUpdateToolYoctoVersion().toStdString().c_str()); + return 0; + } + if (showYoctoInstallStatus) { + printf("%s\n", Worker::getATBUpdateToolYoctoInstallationStatus().toStdString().c_str()); + return 0; + } + + + QThread::currentThread()->setObjectName("main thread"); + qInfo() << "Main thread" << QThread::currentThreadId(); + + if (!QDir(plugInDir).exists()) { qCritical() << plugInDir << "does not exists, but has to contain dc-library"; exit(-1); } - qInfo() << "pwd ..............." << rtPath; - qInfo() << "plugInDir ........." << plugInDir; - qInfo() << "plugInName ........" << plugInName; - qInfo() << "workingDir ........" << workingDir; - qInfo() << "dryRun ............" << dryRun; - // before loading the library, delete all possible shared memory segments #if defined Q_OS_LINUX || defined Q_OS_UNIX // system("rm -rf /tmp/qipc*"); @@ -139,49 +140,24 @@ int main(int argc, char *argv[]) { #error "Only tested under UNIX/LINUX" #endif - hwinf *hw = Update::loadDCPlugin(QDir(plugInDir), plugInName); - hw->dc_autoRequest(true); - // hw->dc_openSerial(5, "115200", "ttymxc2", 1); - - int machineNr = Utils::read1stLineOfFile("/etc/machine_nr"); - int customerNr = Utils::read1stLineOfFile("/etc/cust_nr"); - int zoneNr = Utils::read1stLineOfFile("/etc/zone_nr"); - QString const branchName = (zoneNr != 0) - ? QString("zg1/zone%1").arg(zoneNr) : "master"; - - QThread::currentThread()->setObjectName("main thread"); - qInfo() << "Main thread" << QThread::currentThreadId(); - Worker worker(customerNr, machineNr, zoneNr, + repositoryUrl, branchName, + plugInDir, plugInName, workingDir, + noUpdatePsaHardware, + alwaysDownloadConfig, + alwaysDownloadDC, dryRun); - QString const customerNrStr( - QString("customer_") + QString::number(customerNr).rightJustified(3, '0')); - - QScopedPointer update( - new Update(hw, - &worker, - QDir::cleanPath(workingDir + QDir::separator() + customerNrStr), - customerNrStr, - branchName, - plugInName, - workingDir, - dryRun, - nullptr, - SERIAL_PORT, - "115200")); - - MainWindow mw(hw, &worker, update.get()); + MainWindow mw(&worker); worker.setMainWindow(&mw); mw.setWindowFlags(Qt::Window | Qt::FramelessWindowHint); - mw.setWindowState(Qt::WindowFullScreen); - mw.show(); + mw.showFullScreen(); return a.exec(); } diff --git a/mainwindow.cpp b/mainwindow.cpp index d1989cd..89f1e09 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -10,104 +10,17 @@ #include #include #include +#include - -#if EMERGENCY_LEAVE_BL==1 -static int step = 0; - -void MainWindow::emergencyLeaveBL() { - // - qCritical() << __func__ << step; - switch(step) { - case 0: - if (m_hw->dc_openSerial(5, "115200", "ttymxc2", 1)) { - qCritical() << __func__ << "open ok"; - step++; - QThread::msleep(2000); - m_hw->dc_autoRequest(false); - emit leaveBL(); - } - break; - case 1: - m_hw->bl_rebootDC(); - QThread::msleep(1000); - qCritical() << __func__ << "reboot ok" << QDateTime::currentDateTime().toString(Qt::ISODateWithMs); - step++; - emit leaveBL(); - break; - case 2: - case 3: - case 4: - case 5: - case 6: - m_hw->bl_startBL(); - QThread::msleep(1000); - qCritical() << __func__ << "start" << QDateTime::currentDateTime().toString(Qt::ISODateWithMs); - step++; - emit leaveBL(); - break; - case 7: - case 9: - case 11: - case 13: - case 15: - m_hw->bl_checkBL(); - qCritical() << __func__ << "check" << QDateTime::currentDateTime().toString(Qt::ISODateWithMs); - QThread::msleep(1500); - ++step; - emit leaveBL(); - break; - case 8: - case 10: - case 12: - case 14: - case 16: - qCritical() << __func__ << "is Up..." << QDateTime::currentDateTime().toString(Qt::ISODateWithMs); - if (m_hw->bl_isUp()) { - qCritical() << __func__ << "is Up...OK" << step << QDateTime::currentDateTime().toString(Qt::ISODateWithMs); - QThread::msleep(5000); - step = 16; - } else { - qCritical() << __func__ << "is Up...NO" << step << QDateTime::currentDateTime().toString(Qt::ISODateWithMs); - } - ++step; - emit leaveBL(); - break; - case 17: - case 18: - case 19: - qCritical() << __func__ << "stop" << QDateTime::currentDateTime().toString(Qt::ISODateWithMs); - m_hw->bl_stopBL(); - QThread::msleep(1000); - //m_hw->dc_closeSerial(); - ++step; - emit leaveBL(); - break; - } -} -#endif - -MainWindow::MainWindow(hwinf *hw, Worker *worker, Update *update, QWidget *parent) +MainWindow::MainWindow(Worker *worker, QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) - , m_hw(hw) , m_worker(worker) , m_width(70) , m_progressRunning(false) - , m_progressValue(0) - , m_update(update) , m_updateStep(UpdateDcEvent::UpdateStep::NONE) { -#if EMERGENCY_LEAVE_BL==1 - QTimer *t = new QTimer(this); - connect(t, SIGNAL(timeout()), this, SLOT(emergencyLeaveBL())); - connect(this, SIGNAL(leaveBL()), this, SLOT(emergencyLeaveBL()), Qt::QueuedConnection); - t->setSingleShot(true); - t->start(1000); - return; -#endif - this->setStatusBar(new QStatusBar(this)); QFont f; f.setStyleHint(QFont::Monospace); @@ -125,10 +38,11 @@ MainWindow::MainWindow(hwinf *hw, Worker *worker, Update *update, QWidget *paren QString start = QDateTime::currentDateTime().toString(Qt::ISODate); lst << QString("Start: ") + start.leftJustified(m_width-10); lst << QString("").leftJustified(m_width-3, '='); - lst << QString("Machine number : %1 ").arg(m_worker->machineNr()).leftJustified(m_width-3); - lst << QString("Customer number : %1 ").arg(m_worker->customerNr()).leftJustified(m_width-3); - lst << QString("Zone number : %1 (%2)").arg(m_worker->zoneNr()).arg(Utils::zoneName(m_worker->zoneNr())).leftJustified(m_width-3); - lst << QString("APISM version : %1").arg(m_worker->apismVersion()).leftJustified(m_width-3); + lst << QString("Update tool version: %1 - %2 %3").arg(APP_VERSION).arg(APP_BUILD_DATE).arg(APP_BUILD_TIME).leftJustified(m_width-3); + lst << QString("Machine number : %1 ").arg(m_worker->machineNr()).leftJustified(m_width-3); + lst << QString("Customer number : %1 ").arg(m_worker->customerNr()).leftJustified(m_width-3); + lst << QString("Zone number : %1 (%2)").arg(m_worker->zoneNr()).arg(Utils::zoneName(m_worker->zoneNr())).leftJustified(m_width-3); + lst << QString("APISM version : %1").arg(m_worker->apismVersion()).leftJustified(m_width-3); lst << QString("").leftJustified(m_width-3, '='); ui->updateStatus->setText(lst.join('\n')); @@ -136,7 +50,7 @@ MainWindow::MainWindow(hwinf *hw, Worker *worker, Update *update, QWidget *paren // ui->updateStatus->installEventFilter(this); m_startTimer = new QTimer(this); - connect(m_startTimer, SIGNAL(timeout()), m_worker, SLOT(update())); + connect(m_startTimer, SIGNAL(timeout()), m_worker, SLOT(start())); m_startTimer->setSingleShot(true); m_startTimer->start(1000); @@ -153,6 +67,8 @@ MainWindow::MainWindow(hwinf *hw, Worker *worker, Update *update, QWidget *paren connect(m_worker, SIGNAL(appendText(QString,QString)),this,SLOT(onAppendText(QString,QString))); connect(m_worker, SIGNAL(showErrorMessage(QString,QString)),this, SLOT(onShowErrorMessage(QString,QString))); connect(m_worker, SIGNAL(showStatusMessage(QString,QString)),this, SLOT(onShowStatusMessage(QString,QString))); + connect(m_worker, SIGNAL(showErrorMessage(QStringList)),this, SLOT(onShowErrorMessage(QStringList))); + connect(m_worker, SIGNAL(showStatusMessage(QString,QString)),this, SLOT(onShowStatusMessage(QString,QString))); connect(m_worker, SIGNAL(replaceLast(QString,QString)),this,SLOT(onReplaceLast(QString,QString))); connect(m_worker, SIGNAL(replaceLast(QStringList,QString)),this, SLOT(onReplaceLast(QStringList,QString))); } @@ -176,22 +92,22 @@ void MainWindow::customEvent(QEvent *event) { case START_PROGRESS_LOOP: { m_progressRunning = true; ui->updateProgress->reset(); - m_progressValue = 10; - QApplication::postEvent(this, new ProgressEvent(this, m_progressValue)); + // m_progressValue = 10; + QApplication::postEvent(this, new ProgressEvent(this, 1)); } break; case STOP_PROGRESS_LOOP: { m_progressRunning = false; - m_progressValue -= 10; - m_worker->setProgress(m_progressValue/10); + // m_progressValue -= 10; + // m_worker->setProgress(m_progressValue/10); } break; default: { - if (m_progressRunning) { - m_progressValue = progress; - ui->updateProgress->setValue(progress/10); - QApplication::postEvent(this, new ProgressEvent(this, progress+10)); - QThread::msleep(500); - } - } + if (m_progressRunning) { + // m_progressValue = progress; + ui->updateProgress->setValue(progress); + // ueberpruefen: hauptfenster schickt sich selber ein event + // QApplication::postEvent(this, new ProgressEvent(this, progress)); + // QThread::msleep(500); + }} } } else if (sender == m_worker) { @@ -211,86 +127,6 @@ void MainWindow::customEvent(QEvent *event) { } else { qCritical() << "!!! UNKNOWN SENDER !!!"; } - } else - if (event->type() == UpdateDcEvent::type()) { - UpdateDcEvent *pevent = (UpdateDcEvent *)event; - UpdateDcEvent::UpdateStep const updateStep = pevent->updateStep(); - QObject const *sender = pevent->sender(); - if (sender == m_worker) { - QDateTime const &recv = QDateTime::currentDateTime(); - QDateTime const &send = pevent->sendDateTime(); - qint64 const delay = recv.toMSecsSinceEpoch() - send.toMSecsSinceEpoch(); - switch(updateStep) { - case UpdateDcEvent::UpdateStep::NONE: - break; - case UpdateDcEvent::UpdateStep::DC_REBOOT: { - m_hw->bl_rebootDC(); - QString msg = QDateTime::currentDateTime().toString(Qt::ISODateWithMs) - + QString(": reset device controller (delay=%1ms").arg(delay); - emit m_worker->showStatusMessage("dc update", msg); - Utils::printInfoMsg(msg.toUpper()); - m_updateStep = UpdateDcEvent::UpdateStep::DC_REBOOT; - } break; - case UpdateDcEvent::UpdateStep::BL_START: { - QString const &msg = recv.toString(Qt::ISODateWithMs) - + QString(": start bootloader (%1, delay=%2ms)").arg(pevent->count()).arg(delay); - emit m_worker->showStatusMessage("dc update", msg); - Utils::printInfoMsg(msg.toUpper()); - m_hw->bl_startBL(); - if (pevent->count() == BL_START_COUNT) { - m_updateStep = UpdateDcEvent::UpdateStep::BL_START; - } - } break; - case UpdateDcEvent::UpdateStep::BL_CHECK: { - if (m_updateStep != UpdateDcEvent::UpdateStep::BL_IS_UP) { - QString const &msg = recv.toString(Qt::ISODateWithMs) - + QString(": request bootloader version (%1, delay=%2ms)").arg(pevent->count()).arg(delay); - emit m_worker->showStatusMessage("dc update", msg); - Utils::printInfoMsg(msg.toUpper()); - m_hw->bl_checkBL(); - //m_updateStep = UpdateDcEvent::UpdateStep::BL_CHECK; - } - } break; - case UpdateDcEvent::UpdateStep::BL_IS_UP: { - QString msg = recv.toString(Qt::ISODateWithMs) - + QString(": check running bootloader (%1, delay=%2ms)").arg(pevent->count()).arg(delay); - emit m_worker->showStatusMessage("dc update", msg); - Utils::printInfoMsg(msg.toUpper()); - if (m_updateStep != UpdateDcEvent::UpdateStep::BL_IS_UP) { - if (m_hw->bl_isUp()) { - msg = recv.toString(Qt::ISODateWithMs) - + QString(": bootloader running (%1, delay=%2ms)").arg(pevent->count()).arg(delay); - emit m_worker->showStatusMessage("dc update", msg); - Utils::printInfoMsg(msg.toUpper()); - m_updateStep = UpdateDcEvent::UpdateStep::BL_IS_UP; - } else { - msg = recv.toString(Qt::ISODateWithMs) - + QString(": bootloader stop requested (%1, delay=%2ms)").arg(pevent->count()).arg(delay); - emit m_worker->showStatusMessage("dc update", msg); - Utils::printInfoMsg(msg.toUpper()); - if (m_updateStep == UpdateDcEvent::UpdateStep::BL_STOP) { - msg = QDateTime::currentDateTime().toString(Qt::ISODateWithMs) - + QString(": bootloader down (%1, delay=%2ms)").arg(pevent->count()).arg(delay); - emit m_worker->showStatusMessage("dc update", msg); - Utils::printInfoMsg(msg.toUpper()); - m_updateStep = UpdateDcEvent::UpdateStep::BL_IS_DOWN; - } - } - } - } break; - case UpdateDcEvent::UpdateStep::BL_STOP: { - QString const &msg = QDateTime::currentDateTime().toString(Qt::ISODateWithMs) - + QString(": stop bootloader (%1, delay=%2ms)").arg(pevent->count()).arg(delay); - emit m_worker->showStatusMessage("dc update", msg); - Utils::printInfoMsg(msg.toUpper()); - //if (m_bootLoaderIsUp) { - m_hw->bl_stopBL(); - m_updateStep = UpdateDcEvent::UpdateStep::BL_STOP; - //} - } break; - default: ; - } - } } QThread::yieldCurrentThread(); @@ -308,29 +144,33 @@ void MainWindow::onEnableExit() { ui->exit->setEnabled(true); } -//bool MainWindow::eventFilter(QObject *obj, QEvent *ev) { -// if (obj == ui->updateStatus) { -// qCritical() << "REc. event for text edit" << ev->type(); -// } -// return QMainWindow::eventFilter(obj, ev); -//} - void MainWindow::onRestartExitTimer() { m_exitTimer->stop(); m_exitTimer->start(60 * 1000); - // ui->updateStatus->blockSignals(true); + scrollDownTextEdit(); + ui->updateStatus->setEnabled(false); } void MainWindow::onQuit() { m_exitTimer->stop(); - qCritical() << QString("ON QUIT: EXIT CODE %1").arg(m_worker->returnCode()); - qApp->exit(m_worker->returnCode()); + int errorCode = 0; + + qCritical() + << QString("ON QUIT: CURRENT STEP %1") + .arg(m_worker->getSmap()[m_worker->currentStep()]); + + // TODO: replace SEND_LAST_VERSION with UPDATE_SUCCEEDED + if (m_worker->currentStep() != Worker::UPDATE_STEP::SEND_LAST_VERSION) { + errorCode = -1; + } + qCritical() << QString("ON QUIT: EXIT CODE %1").arg(errorCode); + qApp->exit(errorCode); } void MainWindow::scrollDownTextEdit() { - Utils::printInfoMsg(QString("SCROLL-DOWN-TEXT_EDIT CALLED AT ") - + QDateTime::currentDateTime().toString(Qt::ISODateWithMs)); + // Utils::printInfoMsg(QString("SCROLL-DOWN-TEXT_EDIT CALLED AT ") + // + QDateTime::currentDateTime().toString(Qt::ISODateWithMs)); ui->updateStatus->setEnabled(true); @@ -341,10 +181,12 @@ void MainWindow::scrollDownTextEdit() { } void MainWindow::onAppendText(QString text, QString suffix) { - Utils::printInfoMsg(QString("ON APPEND CALLED AT ") - + QDateTime::currentDateTime().toString(Qt::ISODateWithMs)); + // Utils::printInfoMsg(QString("ON APPEND CALLED AT ") + // + QDateTime::currentDateTime().toString(Qt::ISODateWithMs)); QString editText = ui->updateStatus->toPlainText(); + scrollDownTextEdit(); + if (!suffix.isNull() && suffix.size() > 0) { //qInfo() << "TEXT" << text << "SUFFIX" << suffix; if (suffix == Worker::UPDATE_STEP_SUCCESS || suffix == Worker::UPDATE_STEP_FAIL) { @@ -370,9 +212,8 @@ void MainWindow::onAppendText(QString text, QString suffix) { } void MainWindow::onReplaceLast(QStringList newTextLines, QString suffix) { - Utils::printInfoMsg(QString("ON REPLACE LAST (LIST) CALLED AT ") - + QDateTime::currentDateTime().toString(Qt::ISODateWithMs)); - + // Utils::printInfoMsg(QString("ON REPLACE LAST (LIST) CALLED AT ") + // + QDateTime::currentDateTime().toString(Qt::ISODateWithMs)); int const s = newTextLines.size(); if (s > 0) { QString editText = ui->updateStatus->toPlainText(); @@ -405,13 +246,17 @@ void MainWindow::onReplaceLast(QStringList newTextLines, QString suffix) { } void MainWindow::onReplaceLast(QString text, QString suffix) { - Utils::printInfoMsg(QString("ON REPLACE LAST (TEXT) CALLED AT ") - + QDateTime::currentDateTime().toString(Qt::ISODateWithMs)); - + // Utils::printInfoMsg(QString("ON REPLACE LAST (TEXT) CALLED AT ") + // + QDateTime::currentDateTime().toString(Qt::ISODateWithMs)); QString editText = ui->updateStatus->toPlainText(); QStringList lines = editText.split('\n', QString::SplitBehavior::SkipEmptyParts); if (lines.size() > 0) { - lines.removeLast(); + // removing the last line is really meant for refreshing the last line + // with a string very similar than the original one, typically only + // followed by a suffix. + if (lines.last().contains(text)) { + lines.removeLast(); + } if (!suffix.isNull() && suffix.size() > 0 && suffix != "\n") { QString const add = text.leftJustified(m_width-10) + suffix; if (!add.isEmpty()) { @@ -443,3 +288,21 @@ void MainWindow::onShowErrorMessage(QString title, QString text) { void MainWindow::onShowStatusMessage(QString title, QString text) { onShowMessage(title, text); } + +void MainWindow::onShowErrorMessage(QStringList lst) { + if (lst.size() >= 2) { + onShowMessage(lst.at(0), lst.at(1)); + } + if (lst.size() == 1) { + onShowMessage(lst.at(0), ""); + } +} + +void MainWindow::onShowStatusMessage(QStringList lst) { + if (lst.size() >= 2) { + onShowMessage(lst.at(0), lst.at(1)); + } + if (lst.size() == 1) { + onShowMessage(lst.at(0), ""); + } +} diff --git a/mainwindow.h b/mainwindow.h index 88f6ca1..c6eac86 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -21,10 +21,9 @@ class MainWindow : public QMainWindow { protected: void customEvent(QEvent *event) override; - // bool eventFilter(QObject *obj, QEvent *ev) override; public: - MainWindow(hwinf *hw, Worker *worker, Update *update, QWidget *parent = nullptr); + MainWindow(Worker *worker, QWidget *parent = nullptr); ~MainWindow(); static const int START_PROGRESS_LOOP = -1; @@ -34,11 +33,6 @@ public: static const int BL_IS_UP_COUNT = 5; static const int BL_STOP_COUNT = 5; - int progressValue() const { return m_progressValue; } - hwinf *getPlugin() { return m_hw; } - hwinf const *getPlugin() const { return m_hw; } - Update *getUpdate() { return m_update; } - Update const *getUpdate() const { return m_update; } UpdateDcEvent::UpdateStep updateStep() const { return m_updateStep; } void setUpdateStep(UpdateDcEvent::UpdateStep updateStep) { m_updateStep = updateStep; } @@ -48,6 +42,8 @@ public slots: void onReplaceLast(QString, QString suffix = ""); void onShowErrorMessage(QString, QString); void onShowStatusMessage(QString, QString); + void onShowErrorMessage(QStringList); + void onShowStatusMessage(QStringList); void onStopStartTimer(); void onRestartExitTimer(); void onEnableExit(); @@ -70,14 +66,12 @@ private: void onShowMessage(QString, QString); Ui::MainWindow *ui; - hwinf *m_hw; Worker *m_worker; int const m_width; QTimer *m_startTimer; QTimer *m_exitTimer; bool m_progressRunning; - int m_progressValue; - Update *m_update; + //int m_progressValue; UpdateDcEvent::UpdateStep m_updateStep; }; #endif // MAINWINDOW_H diff --git a/plugins/interfaces.h b/plugins/interfaces.h old mode 100644 new mode 100755 index d9f31b6..65a0f67 --- a/plugins/interfaces.h +++ b/plugins/interfaces.h @@ -193,7 +193,7 @@ struct T_moduleCondition uint8_t coinChecker; // EMP, OMP or mei-cashflow uint8_t coinEscrow; - uint8_t mifareReader; + uint8_t mifareReader; // 0: unknown 1=OK 200=no response 201=wrong response 202: Reader reports HW-error uint8_t creditTerm; uint8_t coinReject; @@ -344,7 +344,58 @@ struct T_devices }; +struct T_chg_Tub +{ + uint8_t tubeLevel[8]; // [0]=nr coins of lowest value + uint8_t tubeFull[8]; // 1=full 0 else + uint16_t tubeValues[8]; // in cent [0]=lowest value 5c or 10cent + uint16_t tubeFilled[8]; // nr of every coin inserted + uint16_t tubeDispens[8]; // nr of every coin dispensed + // 64 byte +}; + +struct T_changer +{ + // Fixdata from Coin Changer + uint8_t setup; // always 1 + uint8_t state; // step of state machine + // 0..12 like EMP, 13...30 for coin dispense + + uint8_t level; // mdb-level, always 3 + uint16_t countryCode; + uint8_t scale; + uint8_t decimals; + uint8_t coinSetup[16]; // [0]=lowest coin, multiply with scale + uint16_t intendedAcceptance; //bitwise 0,1 1=accept coin, came from master + uint8_t tokenChannel; + uint8_t pollingRunning; // 1: emp is polled 0:not + uint8_t paymentRunning; // 1: coins are accepted + uint16_t denomination[16]; + uint16_t availableTubes; //bitwise 0,1 1=av. bit0 = lowest coin value +}; + +struct T_bna +{ + // reported with STATUS: + uint8_t setup; // 0: not 1: got valid parameters from device + uint8_t FeatureLevel; + uint16_t countryCode; // programmed in EMP + uint16_t scalingFactor; // z.B. 5 + uint8_t decimalPlace; + uint8_t pad1; + uint16_t stackerCap; + uint16_t billSecureLevel; + uint8_t hasEscrow; + uint8_t accBillTypes[16]; // programmed in EMP z.B. (bit 0..7): 1 2 4 10 20 40 0 0 + uint16_t currentStackerLevel; // requested number of notes in billbox + + // settings from Master + uint16_t intendedAccept; // bit 0 =5€ + uint16_t pad2; + uint16_t billDenomination[16]; + +}; class hwinf { @@ -363,80 +414,118 @@ public: // $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - virtual bool dc_openSerial(int BaudNr, QString BaudStr, QString ComName, uint8_t connect) const =0; + virtual bool dc_openSerial(int BaudNr, QString BaudStr, QString ComName, uint8_t connect) const { + Q_UNUSED(BaudNr); + Q_UNUSED(BaudStr); + Q_UNUSED(ComName); + Q_UNUSED(connect); + return false; + } // Command: open serial interface // BaudNr: 0:1200 1:9600 2:19200 3:38400 4:57600 5:115200 // BaudStr: for exapmle "19200" // ComName: for example "COM48" // connect: 0, 1 - virtual void dc_closeSerial(void) const =0; + virtual void dc_closeSerial(void) const {} // Command: close serial interface in order to save power while power down // or if another port must be used - virtual bool dc_isPortOpen(void) const =0; + virtual bool dc_isPortOpen(void) const { + return false; + } // returns true if port open (don't send unless open. Sending to closed port will crash program) - virtual void dc_autoRequest(bool on) const =0; + virtual void dc_autoRequest(bool on) const { + Q_UNUSED(on); + } // on = true: select that all READ-Requests are sent automatically // on = false: select that all READ-Requests are sent manually one by one // Every input information from DC2 must be requested // ( digital and analog sensors, get time/date, get status information ) - virtual void dc_requTestResponse() const =0; + virtual void dc_requTestResponse() const {} // tell DC2 to send a test-string, useful to see if cable and baudrate is OK - virtual bool dc_readAnswTestResponse() const =0; + virtual bool dc_readAnswTestResponse() const { + return false; + } // retval: true: test was successful, got right response - virtual uint8_t dc_isRequestDone(void) const =0; + virtual uint8_t dc_isRequestDone(void) const { + return 0; + } // retval: 0: request is still in progress // 1: answer from DC2 was OK // 2: wrong answer from DC2 - virtual uint16_t dc_getCompletePayLoad(uint16_t plBufSiz, uint8_t *payLoad) const =0; + virtual uint16_t dc_getCompletePayLoad(uint16_t plBufSiz, uint8_t *payLoad) const { + Q_UNUSED(plBufSiz); + Q_UNUSED(payLoad); + return 0; + } // get data back in "payLoad", max 64 byte, can be used for diagnosis // retval = nr of bytes received. If host buffer too small then // only plBufSiz bytes are copied to "payLoad" // plBufSiz = size of host buffer - virtual void dc_setWakeFrequency(uint8_t period) const =0; + virtual void dc_setWakeFrequency(uint8_t period) const { + Q_UNUSED(period); + } // RTC wakes DC2 (and PTU) by hardware signal every 32seconds // change wake signal period to 1...64s - virtual void dc_OrderToReset(void) const =0; + virtual void dc_OrderToReset(void) const {} // want DC2 to reset (in order to start Bootloader) - virtual QString dc_getSerialState(void) const =0; + virtual QString dc_getSerialState(void) const { + return QString(); + } // get result of opening-command like "ttyS0 opened with 115200 8N1! // or error messages like "comport not available..." // was saved by last opening event, can be passed for 100ms - virtual void dc_clrSerialStateText(void) const =0; + virtual void dc_clrSerialStateText(void) const {} // clear above text to avoid multiple repetive displaying - virtual void bl_sendDataDirectly(uint8_t length, uint8_t *buf) const =0; + virtual void bl_sendDataDirectly(uint8_t length, uint8_t *buf) const { + Q_UNUSED(length); + Q_UNUSED(buf); + } // send without protocol frame, needed for the DC bootloader - virtual uint8_t getRawRecLength(void) const =0; + virtual uint8_t getRawRecLength(void) const { + return 0; + } // only needed if protocol stack in Cashagent-Library is bypassed - virtual uint8_t getRawReceivedData(uint8_t *receivedData) const =0; + virtual uint8_t getRawReceivedData(uint8_t *receivedData) const { + Q_UNUSED(receivedData); + return 0; + } // only needed if protocol stack in Cashagent-Library is bypassed - virtual QString dc_getSerialParams(void) const =0; + virtual QString dc_getSerialParams(void) const { + return QString(); + } // get DC2 serial settings (not very meaningful as they will not come if different from master settings) - virtual QString dc_getHWversion(void) const =0; + virtual QString dc_getHWversion(void) const { + return QString(); + } // get DC2 hardware version - virtual QString dc_getSWversion(void) const =0; + virtual QString dc_getSWversion(void) const { + return QString(); + } // get DC2 software version - virtual QString dc_getState(void) const =0; + virtual QString dc_getState(void) const { + return QString(); + } // get DC2 status (every OK or any error/warning? ) @@ -444,55 +533,103 @@ public: // Date and Time // ---------------------------------------------------------------------------------------------------------- - virtual uint8_t rtc_getDateTime(struct Trtc_DateTime *rtc_DateTime) const =0; + virtual uint8_t rtc_getDateTime(struct Trtc_DateTime *rtc_DateTime) const { + Q_UNUSED(rtc_DateTime); + return 0; + } - virtual uint8_t rtc_setDateTime(void) const =0; + virtual uint8_t rtc_setDateTime(void) const { + return 0; + } // synch DC2 with PC or PTU system time and date - virtual void rtc_getTime(uint8_t *hh, uint8_t *mm, uint8_t *ss) const =0; + virtual void rtc_getTime(uint8_t *hh, uint8_t *mm, uint8_t *ss) const { + Q_UNUSED(hh); + Q_UNUSED(mm); + Q_UNUSED(ss); + } // get time directly - virtual void rtc_getDate(uint8_t *yy, uint8_t *mm, uint8_t *dd) const =0; + virtual void rtc_getDate(uint8_t *yy, uint8_t *mm, uint8_t *dd) const { + Q_UNUSED(yy); + Q_UNUSED(mm); + Q_UNUSED(dd); + } // get date directly - virtual uint8_t rtc_getToday(uint8_t *dow, uint16_t *minOfToday, uint32_t *secOfToday) const =0; + virtual uint8_t rtc_getToday(uint8_t *dow, uint16_t *minOfToday, uint32_t *secOfToday) const { + Q_UNUSED(dow); + Q_UNUSED(minOfToday); + Q_UNUSED(secOfToday); + return 0; + } // dow=day of week, 1=monday...7 // minOfToday: 0=midnight...1439= 23:59 // secOfToday: 0=midnight...86399= 23:59:59 - virtual bool rtc_isLeapYear(uint8_t *lastLeapYear, uint8_t *NextLeapYear) const =0; + virtual bool rtc_isLeapYear(uint8_t *lastLeapYear, uint8_t *NextLeapYear) const { + Q_UNUSED(lastLeapYear); + Q_UNUSED(NextLeapYear); + return false; + } // retval true: this year is leap year - virtual bool rtc_isLeapYear() const =0; + virtual bool rtc_isLeapYear() const { + return false; + } - virtual void rtc_getWeek(uint8_t *DayOfWeek, uint8_t *HoursOfWeek, uint16_t *MinutesOfWeek) const =0; + virtual void rtc_getWeek(uint8_t *DayOfWeek, uint8_t *HoursOfWeek, uint16_t *MinutesOfWeek) const { + Q_UNUSED(DayOfWeek); + Q_UNUSED(HoursOfWeek); + Q_UNUSED(MinutesOfWeek); + } // DayOfWeek: 1=monday...7 // HoursOfWeek: 0=Monday 0:00 o'clock...167=Sunday 23:00 // MinutesOfWeek: 0=Monday 0:00 o'clock...10079=Sunday 23:59 - virtual void rtc_getMonth(uint8_t *DayOfMonth, uint16_t *HoursOfMonth, uint16_t *MinutesOfMonth) const =0; + virtual void rtc_getMonth(uint8_t *DayOfMonth, uint16_t *HoursOfMonth, uint16_t *MinutesOfMonth) const { + Q_UNUSED(DayOfMonth); + Q_UNUSED(HoursOfMonth); + Q_UNUSED(MinutesOfMonth); + } // DayOfMonth: 1...31 // HoursOfMonth: 0 = 0:00o'clock of 1.day in month up to 743 // MinutesOfMonth:0 = 0:00o'clock of 1.day in month up to 44639 - virtual void rtc_getYear(uint16_t *DayOfYear, uint16_t *HoursOfYear, uint32_t *MinutesOfYear) const =0; + virtual void rtc_getYear(uint16_t *DayOfYear, uint16_t *HoursOfYear, uint32_t *MinutesOfYear) const { + Q_UNUSED(DayOfYear); + Q_UNUSED(HoursOfYear); + Q_UNUSED(MinutesOfYear); + } // DayOfYear: 1...366 1= 1.Jan of this current year // HoursOfYear: 0=1.Jan 0:00o'clock ...8783=31.12 23 o'clock // MinutesOfYear: 0=1.Jan 0:00o'clock ...527039=31.12 23:59 o'clock - virtual QString rtc_getTimStr(void) const =0; - virtual QString rtc_getDatStr(void) const =0; - virtual QString rtc_getTimDatStr(void) const =0; + virtual QString rtc_getTimStr(void) const { + return QString(); + } + virtual QString rtc_getDatStr(void) const { + return QString(); + } + virtual QString rtc_getTimDatStr(void) const { + return QString(); + } // UID - unique number, different in every DC - virtual void dc_getUID8byte(uint8_t *buf8byteUid) const =0; + virtual void dc_getUID8byte(uint8_t *buf8byteUid) const { + Q_UNUSED(buf8byteUid); + } // get 8 single bytes in buffer - virtual QString dc_getUIDstr() const =0; + virtual QString dc_getUIDstr() const { + return QString(); + } // get as string - virtual uint64_t dc_getUIDnumber(void) const =0; + virtual uint64_t dc_getUIDnumber(void) const { + return 0; + } // get UID as one long number // ---------------------------------------------------------------------------------------------------------- @@ -500,19 +637,29 @@ public: // ---------------------------------------------------------------------------------------------------------- // Analog values: - virtual uint32_t dc_getTemperature(void) const =0; + virtual uint32_t dc_getTemperature(void) const { + return 0; + } // in Sax-Format 0...400 (0=-50,0degC 100=0,0degC 141=20,5degC 400=150,0degC) - virtual QString dc_getTemperaturStr(void) const =0; + virtual QString dc_getTemperaturStr(void) const { + return QString(); + } // as string like "-12,5degC" - virtual uint32_t dc_getVoltage(void) const =0; + virtual uint32_t dc_getVoltage(void) const { + return 0; + } // as value in mV, 0...65,535V - virtual QString dc_getVoltagStr(void) const =0; + virtual QString dc_getVoltagStr(void) const { + return QString(); + } // as string in mV - virtual bool dc_mainFuseIsOk(void) const=0; + virtual bool dc_mainFuseIsOk(void) const { + return false; + } // true if 12V fuse is OK // false: fuse blown, DC will continue working but no 12V device can be used! @@ -520,60 +667,124 @@ public: // digital outputs // ------------------------------------------------------------------------------ - virtual uint8_t lock_switchUpperLock(uint8_t dir) const =0; + virtual uint8_t lock_switchUpperLock(uint8_t dir) const { + Q_UNUSED(dir); + return 0; + } // dir 0=off 1=up 2=down // move lock until stop cmd (0) - virtual uint8_t lock_switchLowerLock(uint8_t dir) const =0; + virtual uint8_t lock_switchLowerLock(uint8_t dir) const { + Q_UNUSED(dir); + return 0; + } // dir 0=off 1=up 2=down // move lock until stop cmd (0) - virtual void lock_switchVaultDoor(void) const =0; + virtual void lock_switchVaultDoor(void) const {} - virtual void coin_switchRejectMotor(uint8_t dir) const =0; + virtual void coin_switchRejectMotor(uint8_t dir) const { + Q_UNUSED(dir); + } - virtual void coin_rejectCoins(void) const =0; + virtual void coin_rejectCoins(void) const {} // LEDs - virtual void led_switchLedService(uint8_t on) const =0; - virtual void led_switchLedPaper(uint8_t on, uint8_t ton, uint8_t tof) const =0; - virtual void led_switchLedPinPad(uint8_t on, uint8_t ton, uint8_t tof) const =0; - virtual void led_switchLedStart(uint8_t on, uint8_t ton, uint8_t tof) const =0; - virtual void led_switchLedCoinbassin(uint8_t on, uint8_t ton, uint8_t tof) const =0; + virtual void led_switchLedService(uint8_t on) const { + Q_UNUSED(on); + } + virtual void led_switchLedPaper(uint8_t on, uint8_t ton, uint8_t tof) const { + Q_UNUSED(on); + Q_UNUSED(ton); + Q_UNUSED(tof); + } + virtual void led_switchLedPinPad(uint8_t on, uint8_t ton, uint8_t tof) const { + Q_UNUSED(on); + Q_UNUSED(ton); + Q_UNUSED(tof); + } + virtual void led_switchLedStart(uint8_t on, uint8_t ton, uint8_t tof) const { + Q_UNUSED(on); + Q_UNUSED(ton); + Q_UNUSED(tof); + } + virtual void led_switchLedCoinbassin(uint8_t on, uint8_t ton, uint8_t tof) const { + Q_UNUSED(on); + Q_UNUSED(ton); + Q_UNUSED(tof); + } - virtual void fan_switchFan(bool on) const =0; - virtual void alarm_switchSiren(bool on) const =0; - virtual void bar_OpenBarrier(bool open) const =0; - virtual void ptu_switchWake(bool WAKEACTIVE) const =0; + virtual void fan_switchFan(bool on) const { + Q_UNUSED(on); + } + virtual void alarm_switchSiren(bool on) const { + Q_UNUSED(on); + } + virtual void bar_OpenBarrier(bool open) const { + Q_UNUSED(open); + } + virtual void ptu_switchWake(bool WAKEACTIVE) const { + Q_UNUSED(WAKEACTIVE); + } - virtual void aux_power(bool on) const =0; - virtual void aux_setUsage(uint8_t PinDirection) const =0; - virtual void aux_setOutputs(uint8_t PinIsHigh) const =0; + virtual void aux_power(bool on) const { + Q_UNUSED(on); + } + virtual void aux_setUsage(uint8_t PinDirection) const { + Q_UNUSED(PinDirection); + } + virtual void aux_setOutputs(uint8_t PinIsHigh) const { + Q_UNUSED(PinIsHigh); + } - virtual void lock_switchContactPower(bool on) const =0; + virtual void lock_switchContactPower(bool on) const { + Q_UNUSED(on); + } - virtual void prn_switchPower(bool on) const =0; + virtual void prn_switchPower(bool on) const { + Q_UNUSED(on); + } - virtual void mif_readerOn(bool on) const =0; + virtual void mif_readerOn(bool on) const { + Q_UNUSED(on); + } - virtual void mif_creatAtbCard(uint8_t cardType) const =0; + virtual void mif_creatAtbCard(uint8_t cardType) const { + Q_UNUSED(cardType); + } - virtual void mod_switchPower(bool on) const=0; + virtual void mod_switchPower(bool on) const { + Q_UNUSED(on); + } - virtual void mod_switchWake(bool WAKEACTIVE) const=0; + virtual void mod_switchWake(bool WAKEACTIVE) const { + Q_UNUSED(WAKEACTIVE); + } - virtual void mdb_switchPower(bool on) const =0; + virtual void mdb_switchPower(bool on) const { + Q_UNUSED(on); + } - virtual void mdb_switchWake(bool WAKEACTIVE) const =0; + virtual void mdb_switchWake(bool WAKEACTIVE) const { + Q_UNUSED(WAKEACTIVE); + } - virtual void credit_switchPower(bool on) const =0; + virtual void credit_switchPower(bool on) const { + Q_UNUSED(on); + } // the same as modem power - virtual void credit_switchWake(bool WAKEACTIVE) const =0; + virtual void credit_switchWake(bool WAKEACTIVE) const { + Q_UNUSED(WAKEACTIVE); + } - virtual void shut_move(bool open) const =0; + virtual void shut_move(bool open) const { + Q_UNUSED(open); + } - virtual void esc_moveFlaps(uint8_t flap ) const =0; + virtual void esc_moveFlaps(uint8_t flap ) const { + Q_UNUSED(flap); + } // 0: close both 1: open take-flap 2: open return @@ -581,78 +792,142 @@ public: // door, cashbox and lock switches // ------------------------------------------------------------------------------ - virtual uint8_t door_getSwitches(void) const =0; + virtual uint8_t door_getSwitches(void) const { + return 0; + } // retval: bit0: upper door 1: low door 2:vault door - virtual bool door_isUpperDoorOpen(void) const =0; + virtual bool door_isUpperDoorOpen(void) const { + return false; + } - virtual bool door_isLowerDoorOpen(void) const =0; + virtual bool door_isLowerDoorOpen(void) const { + return false; + } - virtual bool vault_isVaultDoorOpen(void) const =0; + virtual bool vault_isVaultDoorOpen(void) const { + return false; + } - virtual uint8_t vault_getSwitches(void) const =0; + virtual uint8_t vault_getSwitches(void) const { + return 0; + } // retval bit0: cash box, bit 1: bill box - virtual bool vault_isCoinVaultIn(void) const =0; + virtual bool vault_isCoinVaultIn(void) const { + return false; + } - virtual bool vault_isBillVaultIn(void) const =0; + virtual bool vault_isBillVaultIn(void) const { + return false; + } - virtual uint8_t door_getLocks(void) const =0; + virtual uint8_t door_getLocks(void) const { + return 0; + } // retval bit0: upper lever is up (=open) // bit1: upper lever is down (=locked) // bit2: lower lever is up // bit3: lower lever is down (=locked) - virtual bool door_upperDoorIsLocked(void) const =0; + virtual bool door_upperDoorIsLocked(void) const { + return false; + } - virtual bool door_upperDoorIsUnlocked(void) const =0; + virtual bool door_upperDoorIsUnlocked(void) const { + return false; + } - virtual bool door_lowerDoorIsLocked(void) const =0; + virtual bool door_lowerDoorIsLocked(void) const { + return false; + } - virtual bool door_lowerDoorIsUnlocked(void) const =0; + virtual bool door_lowerDoorIsUnlocked(void) const { + return false; + } - virtual bool bar_optoIn1isOn(void) const =0; + virtual bool bar_optoIn1isOn(void) const { + return false; + } - virtual bool bar_optoIn2isOn(void) const =0; + virtual bool bar_optoIn2isOn(void) const { + return false; + } - virtual uint8_t aux_getAuxInputs(void) const =0; + virtual uint8_t aux_getAuxInputs(void) const { + return 0; + } - virtual bool ptu_WakeINisActive(void) const =0; + virtual bool ptu_WakeINisActive(void) const { + return false; + } - virtual bool mdb_WakeINisActive(void) const =0; + virtual bool mdb_WakeINisActive(void) const { + return false; + } - virtual bool prn_readyINisActive(void) const =0; + virtual bool prn_readyINisActive(void) const { + return false; + } - virtual bool coid_isAttached(void) const =0; + virtual bool coid_isAttached(void) const { + return false; + } - virtual bool coin_escrowIsOpen(void) const =0; + virtual bool coin_escrowIsOpen(void) const { + return false; + } - virtual bool mif_cardIsAttached(void) const =0; + virtual bool mif_cardIsAttached(void) const { + return false; + } //bool hwapi::mod_WakeINisActive(void); - virtual bool door_isContactPowerOn(void) const =0; + virtual bool door_isContactPowerOn(void) const { + return false; + } - virtual bool mif_isMifarePowerOn(void) const =0; + virtual bool mif_isMifarePowerOn(void) const { + return false; + } - virtual bool mdb_testIsmdbTxDon(void) const =0; + virtual bool mdb_testIsmdbTxDon(void) const { + return false; + } - virtual bool aux_isAuxPowerOn(void) const =0; + virtual bool aux_isAuxPowerOn(void) const { + return false; + } - virtual bool mod_isGsmPowerOn(void) const =0; + virtual bool mod_isGsmPowerOn(void) const { + return false; + } - virtual bool cred_isCreditPowerOn(void) const =0; + virtual bool cred_isCreditPowerOn(void) const { + return false; + } - virtual bool prn_isPrinterPowerOn(void) const =0; + virtual bool prn_isPrinterPowerOn(void) const { + return false; + } - virtual uint8_t prn_PrnFuseIsOk(void) const=0; + virtual uint8_t prn_PrnFuseIsOk(void) const { + return 0; + } //retval: 0: fuse blown 1: fuse OK 2:unknown as printer power is off - virtual bool mdb_isMdbPowerOn(void) const =0; + virtual bool mdb_isMdbPowerOn(void) const { + return false; + } - virtual bool cash_getRejectMotorHomePos(void) const=0; + virtual bool cash_getRejectMotorHomePos(void) const { + return false; + } - virtual uint8_t cash_getLowPaperSensor(void) const=0; + virtual uint8_t cash_getLowPaperSensor(void) const { + return 0; + } // 0: Sensor sees paper 1: no paper 99: off @@ -664,44 +939,46 @@ public: // or automatically in background by: void hwapi::dc_autoRequest(bool on) - virtual void request_DC2serialConfig() const =0; + virtual void request_DC2serialConfig() const {} // read-request can be sent manually by this function, not needed if auto-request is on - virtual void request_DC2_HWversion() const =0; + virtual void request_DC2_HWversion() const {} // read-request can be sent manually by this function, not needed if auto-request is on - virtual void request_DC2_SWversion() const =0; + virtual void request_DC2_SWversion() const {} // read-request can be sent manually by this function, not needed if auto-request is on - virtual void request_DC2_condition() const =0; + virtual void request_DC2_condition() const {} // read-request can be sent manually by this function, not needed if auto-request is on - virtual void request_DC2_UID() const =0; + virtual void request_DC2_UID() const {} // read-request can be sent manually by this function, not needed if auto-request is on - virtual void request_DC2_TimeAndDate() const =0; + virtual void request_DC2_TimeAndDate() const {} // read-request can be sent manually by this function, not needed if auto-request is on - virtual void request_DC2_analogues() const =0; + virtual void request_DC2_analogues() const {} // read-request can be sent manually by this function, not needed if auto-request is on - virtual void request_DC2_digitalInputs() const =0; + virtual void request_DC2_digitalInputs() const {} // read-request can be sent manually by this function, not needed if auto-request is on - virtual void request_DC2_digitalOutputs() const =0; + virtual void request_DC2_digitalOutputs() const {} // read-request can be sent manually by this function, not needed if auto-request is on // ------------------------------------------------------------------------------ // the following device state requests are deployed only if device is powered up: - virtual void request_PrinterHwState() const =0; - virtual void request_PrinterCurrentFonts() const =0; - virtual void request_PrinterStateComplete() const =0; + virtual void request_PrinterHwState() const {} + virtual void request_PrinterCurrentFonts() const {} + virtual void request_PrinterStateComplete() const {} - virtual void request_MifareReaderState() const =0; - virtual void request_MifareCardType() const =0; - virtual void request_MifareAtbType() const =0; - virtual void request_MifareID() const =0; - virtual void request_MifareData(uint8_t dataBlockNumber) const =0; + virtual void request_MifareReaderState() const {} + virtual void request_MifareCardType() const {} + virtual void request_MifareAtbType() const {} + virtual void request_MifareID() const {} + virtual void request_MifareData(uint8_t dataBlockNumber) const { + Q_UNUSED(dataBlockNumber); + } //virtual void request_MifareData() const =0; - virtual void request_MDB_Status() const =0; - virtual void request_MDB_lastResponse() const =0; - virtual void request_EMP_allParameters() const =0; - virtual void request_EMP_lastCoin() const =0; + virtual void request_MDB_Status() const {} + virtual void request_MDB_lastResponse() const {} + virtual void request_EMP_allParameters() const {} + virtual void request_EMP_lastCoin() const {} // ------------------------------------------------------------------------------ @@ -711,44 +988,88 @@ public: // ------------------------------------------------------------------------------ - virtual bool test_getDO_mdbRXtst(void) const =0; + virtual bool test_getDO_mdbRXtst(void) const { + return false; + } // readback digital outputs of connected devices // these functions are not needed for normal operation // but can be used to test and verify conditions - virtual uint8_t lock_getDO_motors(void) const =0; + virtual uint8_t lock_getDO_motors(void) const { + return 0; + } // bit0: upper lock forward bit 1 backward // bit2: lower lock forward bit 3 backward - virtual uint8_t test_serialState(void) const =0; + virtual uint8_t test_serialState(void) const { + return 0; + } // test on-board signals for the serials // serial drv on/off, Serial mux1, Serial mux2 - virtual bool test_serialIsOn(void) const =0; + virtual bool test_serialIsOn(void) const { + return false; + } - virtual bool test_serialMux1isSetToPrinter(void) const =0; - virtual bool test_serialMux1isSetToModem(void) const =0; - virtual bool test_serialMux2isSetToCredit(void) const =0; - virtual bool test_serialMux2isSetToMifare(void) const =0; + virtual bool test_serialMux1isSetToPrinter(void) const { + return false; + } + virtual bool test_serialMux1isSetToModem(void) const { + return false; + } + virtual bool test_serialMux2isSetToCredit(void) const { + return false; + } + virtual bool test_serialMux2isSetToMifare(void) const { + return false; + } - virtual bool led_coinIsOn(void) const =0; - virtual bool led_frontIsOn(void) const =0; - virtual bool led_ticketIsOn(void) const =0; - virtual bool led_pinIsOn(void) const =0; - virtual bool led_StartIsOn(void) const =0; - virtual bool led_insideIsOn(void) const =0; + virtual bool led_coinIsOn(void) const { + return false; + } + virtual bool led_frontIsOn(void) const { + return false; + } + virtual bool led_ticketIsOn(void) const { + return false; + } + virtual bool led_pinIsOn(void) const { + return false; + } + virtual bool led_StartIsOn(void) const { + return false; + } + virtual bool led_insideIsOn(void) const { + return false; + } - virtual bool fan_isOn(void) const =0; - virtual bool siren_isOn(void) const =0; - virtual bool bar_relayIsOn(void) const =0; - virtual bool ptu_WakeOutIsOn(void) const =0; + virtual bool fan_isOn(void) const { + return false; + } + virtual bool siren_isOn(void) const { + return false; + } + virtual bool bar_relayIsOn(void) const { + return false; + } + virtual bool ptu_WakeOutIsOn(void) const { + return false; + } - virtual bool aux_powerIsOn(void) const =0; + virtual bool aux_powerIsOn(void) const { + return false; + } - virtual bool coin_shutterIsOpen(void) const =0; - virtual bool coin_shutterTestOutput(void) const =0; + virtual bool coin_shutterIsOpen(void) const { + return false; + } + virtual bool coin_shutterTestOutput(void) const { + return false; + } - virtual uint8_t coin_escrowFlapOpened(void) const =0; + virtual uint8_t coin_escrowFlapOpened(void) const { + return 0; + } // retval: 1:return flap is open 2:take flap is open 0:closed @@ -762,7 +1083,14 @@ public: virtual void sendDeviceSettings(uint8_t kindOfPrinter, uint8_t kindOfCoinChecker, uint8_t kindOfMifareReader, uint8_t suppressSleep, - uint8_t kindOfModem, uint8_t kindOfCredit ) const =0; + uint8_t kindOfModem, uint8_t kindOfCredit ) const { + Q_UNUSED(kindOfPrinter); + Q_UNUSED(kindOfCoinChecker); + Q_UNUSED(kindOfMifareReader); + Q_UNUSED(suppressSleep); + Q_UNUSED(kindOfModem); + Q_UNUSED(kindOfCredit); + } // enable hardware in device controller: // kindOfPrinter: 0:off 1: GPT4672 (only this one implemented) // kindOfCoinChecker: 0:off 1:EMP820 2:EMP900 3: Csquare_changer @@ -771,9 +1099,12 @@ public: // kindOfModem: 0:off 1: ATB_Sunlink_LTE (not yet implemented) // kindOfCredit: 0:off 1: cVendTopp 2:cVendPin (not yet implemented) - virtual void request_ReadbackDeviceSettings() const =0; + virtual void request_ReadbackDeviceSettings() const {} - virtual void readback_DeviceSettings(uint8_t *length, uint8_t *data) const =0; + virtual void readback_DeviceSettings(uint8_t *length, uint8_t *data) const { + Q_UNUSED(length); + Q_UNUSED(data); + } // refer to DC2 manual for exact content // state 5.5.21: byte[0]=kindOfPrinter byte[1]=kindOfCoinChecker // byte[2]=kindOfMifarereadr byte[3]=suppress sleep mode @@ -781,36 +1112,58 @@ public: virtual void sendMachineID(uint16_t customerNr, uint16_t machineNr, uint16_t borough, uint16_t zone, - uint16_t alias, char *location) const =0; + uint16_t alias, char *location) const { + Q_UNUSED(customerNr); + Q_UNUSED(machineNr); + Q_UNUSED(borough); + Q_UNUSED(zone); + Q_UNUSED(alias); + Q_UNUSED(location); + } virtual void request_ReadbackMachineID() const =0; - virtual void readback_machineIDdata(uint8_t *length, uint8_t *data) const =0; + virtual void readback_machineIDdata(uint8_t *length, uint8_t *data) const { + Q_UNUSED(length); + Q_UNUSED(data); + } // state 5.5.21: byte[0,1]=customer number byte[2,3]=machine number // byte[4,5]=borough byte[6,7]=zone byte[8,9]=alias name // byte[10...41]=location // Locks stops automatically at end switch or by timeout - virtual uint8_t lock_openUpperDoor(void) const =0; - virtual uint8_t lock_closeUpperDoor(void) const =0; + virtual uint8_t lock_openUpperDoor(void) const { + return 0; + } + virtual uint8_t lock_closeUpperDoor(void) const { + return 0; + } - virtual uint8_t lock_openLowerDoor(void) const =0; - virtual uint8_t lock_closeLowerDoor(void) const =0; + virtual uint8_t lock_openLowerDoor(void) const { + return 0; + } + virtual uint8_t lock_closeLowerDoor(void) const { + return 0; + } - virtual void shut_openOnce(void) const =0; + virtual void shut_openOnce(void) const {} // and close automatic after shutter time - virtual void shut_openForCoin(bool start) const =0; + virtual void shut_openForCoin(bool start) const { + Q_UNUSED(start); + } // open flap if coin is attached // once process is started it runs until stop command - virtual void shut_sendOpeningTime(uint16_t timeIn_ms ) const =0; + virtual void shut_sendOpeningTime(uint16_t timeIn_ms ) const { + Q_UNUSED(timeIn_ms); + } // after this time without retrigger the flap is closed - virtual void esc_takeMoney(void) const =0; + virtual void esc_takeMoney(void) const {} // and close automatically after escrow time (1s) - virtual void esc_returnMoney(void) const =0; + virtual void esc_returnMoney(void) const {} // and close automatically after escrow time (1s) @@ -818,8 +1171,12 @@ public: // --------------------------------------------- MIFARE ----------------------------------------------------- // ---------------------------------------------------------------------------------------------------------- - - virtual uint8_t mif_returnReaderStateAndCardType(uint8_t *buf, uint8_t maxBufferSize) const =0; +// obsolete + virtual uint8_t mif_returnReaderStateAndCardType(uint8_t *buf, uint8_t maxBufferSize) const { + Q_UNUSED(buf); + Q_UNUSED(maxBufferSize); + return 0; + } // retval 0=OK 1=error host buffer too small /* data description, new fast version: byte 0= still the same: current read state: @@ -837,18 +1194,34 @@ public: byte 7: length of UID 4 or 7 (byte) */ - virtual bool mif_readerIsOK(void) const =0; + virtual bool mif_readerIsOK(void) const { + return false; + } - virtual bool mif_cardAttached(void) const =0; + virtual bool mif_cardAttached(void) const { + return false; + } + // not working! use mif_cardIsAttached() instead - virtual uint8_t mif_readResult(void) const =0; + virtual uint8_t mif_readResult(void) const { + return 0; + } // result: 0: unknown or still in progress // 1: card read successful // 2: reading error + // not working! - virtual QString mif_cardUID(void) const =0; + virtual QString mif_cardUID(void) const { + return QString(); + } + // not working - virtual uint8_t mif_getCardDataDec(uint8_t blkNr, uint8_t *buf, uint8_t maxBufferSize) const =0; + virtual uint8_t mif_getCardDataDec(uint8_t blkNr, uint8_t *buf, uint8_t maxBufferSize) const { + Q_UNUSED(blkNr); + Q_UNUSED(buf); + Q_UNUSED(maxBufferSize); + return 0; + } virtual QString mif_getCardDataStr(uint8_t blockNumber) const =0; // with blockNumber=0...11 @@ -861,7 +1234,10 @@ public: // read printer condition and settings - virtual uint8_t prn_getHwState(struct Tprn_hw_state *prn_hw_state) const =0; + virtual uint8_t prn_getHwState(struct Tprn_hw_state *prn_hw_state) const { + Q_UNUSED(prn_hw_state); + return 0; + } // retval: status byte // byte 0 = 0: prnter OK, >0: error // bit0: paper low 1: no paper 2: temperature error @@ -869,68 +1245,116 @@ public: // 6: no response 7: bad response from printer // and return struct "Tprn_hw_state" - virtual bool prn_isUpAndReady(void) const =0; + virtual bool prn_isUpAndReady(void) const { + return false; + } // true: printer is powered, serial is ok, no error, printer is connected and resonding - virtual void prn_getCurrentFontSetting(struct Tprn_currentSettings *prn_fonts) const =0; + virtual void prn_getCurrentFontSetting(struct Tprn_currentSettings *prn_fonts) const { + Q_UNUSED(prn_fonts); + } // send Commands to printer: - virtual void prn_sendText(QByteArray *buf) const =0; + virtual void prn_sendText(QByteArray *buf) const { + Q_UNUSED(buf); + } // up to 1280 bytes - virtual void prn_sendPrnSysCmd(uint8_t para1, uint8_t para2, uint32_t para3) const =0; + virtual void prn_sendPrnSysCmd(uint8_t para1, uint8_t para2, uint32_t para3) const { + Q_UNUSED(para1); + Q_UNUSED(para2); + Q_UNUSED(para3); + } // send three byte through to printer, see printers manual - virtual void prn_sendPrnEscCmd(uint8_t para1, uint8_t para2, uint8_t para3, uint8_t para4) const =0; + virtual void prn_sendPrnEscCmd(uint8_t para1, uint8_t para2, uint8_t para3, uint8_t para4) const { + Q_UNUSED(para1); + Q_UNUSED(para2); + Q_UNUSED(para3); + Q_UNUSED(para4); + } // send four byte through to printer, see printers manual - virtual void prn_sendPrnSetup(uint16_t paperSpeed, uint8_t density, uint8_t alignment, uint8_t orientation) const =0; + virtual void prn_sendPrnSetup(uint16_t paperSpeed, uint8_t density, uint8_t alignment, uint8_t orientation) const { + Q_UNUSED(paperSpeed); + Q_UNUSED(density); + Q_UNUSED(alignment); + Q_UNUSED(orientation); + } // send 5 byte: byte 0,1: speed 5...250 mm/s // byte2: density 0....(25)....50 // byte3: alignment 'l', 'c', 'r' = left, center, right // byte4: orientation 0, 90, 180 = 0deg, 90deg, 180deg rotation (by now not supported!) // not batched! don't use twice within 100ms - virtual void prn_movePaper(uint8_t wayInMm, uint8_t direction) const =0; + virtual void prn_movePaper(uint8_t wayInMm, uint8_t direction) const { + Q_UNUSED(wayInMm); + Q_UNUSED(direction); + } //direction: 1=forward 2=backward // - virtual void prn_setFonts(uint8_t font, uint8_t size, uint8_t width, uint8_t height) const =0; + virtual void prn_setFonts(uint8_t font, uint8_t size, uint8_t width, uint8_t height) const { + Q_UNUSED(font); + Q_UNUSED(size); + Q_UNUSED(width); + Q_UNUSED(height); + } // font = kind of font 5...11 (0..22) // size = 6...20, 9..9: too tiny 10: small ...12 = normal size ...20=huge // width: 0...4 0=1x 1=2x 2=4x (huge!) 3=8x 4=16x (3,4 make no sense) // heigth: 0...7 = 1x...8x only 0,1,2,(3) make sense - virtual void prn_setLetters(uint8_t bold, uint8_t invers, uint8_t underlined) const =0; + virtual void prn_setLetters(uint8_t bold, uint8_t invers, uint8_t underlined) const { + Q_UNUSED(bold); + Q_UNUSED(invers); + Q_UNUSED(underlined); + } // bold: 0/1 // invers: 0/1 // underlined: 0/1 - virtual void prn_cut(uint8_t kindof) const =0; + virtual void prn_cut(uint8_t kindof) const { + Q_UNUSED(kindof); + } // kindof: 1=full cut 2=partial cut 3=eject (5xLF + full cut) - virtual void prn_newLine(uint8_t nrOfLines) const =0; + virtual void prn_newLine(uint8_t nrOfLines) const { + Q_UNUSED(nrOfLines); + } - virtual void prn_printCompleteFontTable(void) const =0; + virtual void prn_printCompleteFontTable(void) const {} - virtual void prn_printBarcode(uint8_t kindOf, uint8_t withText, uint8_t offset, uint8_t rotation, uint8_t dataLeng, uint8_t *data) const =0; + virtual void prn_printBarcode(uint8_t kindOf, uint8_t withText, uint8_t offset, uint8_t rotation, uint8_t dataLeng, uint8_t *data) const { + Q_UNUSED(kindOf); + Q_UNUSED(withText); + Q_UNUSED(offset); + Q_UNUSED(rotation); + Q_UNUSED(dataLeng); + Q_UNUSED(data); + } // kind of barcode: 0=Code39 1=Code128 2=EAN13 3= 2/5interleaved 4=UPC-A 5=EAN8 // withText: print readable text below // offset: move by pixel from left border // rotation // dataLeng in byte - virtual void prn_sendQRdata(QByteArray *buf) const =0; + virtual void prn_sendQRdata(QByteArray *buf) const { + Q_UNUSED(buf); + } // maximal 150 alphanummeric bytes - virtual void prn_printQRcode(void) const =0; + virtual void prn_printQRcode(void) const {} // QRcode may have 1...150 alphanummeric data, must be transfered in advance - virtual void prn_printLogo(uint8_t nrOfLogo, uint8_t offset ) const =0; + virtual void prn_printLogo(uint8_t nrOfLogo, uint8_t offset ) const { + Q_UNUSED(nrOfLogo); + Q_UNUSED(offset); + } // nrOfLogo: 1..4 in flash 5...8 in Ram // offset: in mm form left border @@ -945,24 +1369,44 @@ public: // --------------------------------------------- MDB Bus ---------------------------------------------------- // ---------------------------------------------------------------------------------------------------------- - virtual void mdb_sendBusReset(void) const =0; + virtual void mdb_sendBusReset(void) const {} - virtual void mdb_sendCommand(uint8_t toMdbDevice, uint8_t mdbCommand) const =0; + virtual void mdb_sendCommand(uint8_t toMdbDevice, uint8_t mdbCommand) const { + Q_UNUSED(toMdbDevice); + Q_UNUSED(mdbCommand); + } // send one bus command directly over mdb bus, refer to mdb manual for commands // this command is not needed in normal operation, just for new or special things - virtual void mdb_sendMessage(uint8_t toMdbDevice, uint8_t mdbCommand, uint8_t nrOfData, uint8_t *dataBuffer) const =0; + virtual void mdb_sendMessage(uint8_t toMdbDevice, uint8_t mdbCommand, uint8_t nrOfData, uint8_t *dataBuffer) const { + Q_UNUSED(toMdbDevice); + Q_UNUSED(mdbCommand); + Q_UNUSED(nrOfData); + Q_UNUSED(dataBuffer); + } // nrOfData = sizeOf(dataBuffer) maximal 34 byte according mdb specs // same as mdb_sendCommand, just with data - virtual bool mdb_busIsReadyToWork() const =0; + virtual bool mdb_busIsReadyToWork() const { + return false; + } - virtual bool mdb_deviceVoltageOK() const =0; + virtual bool mdb_deviceVoltageOK() const { + return false; + } - virtual bool mdb_busVoltageOk() const =0; + virtual bool mdb_busVoltageOk() const { + return false; + } virtual uint8_t mdb_getLastDeviceResponse(uint8_t *fromDevice, uint8_t *lastRequest, - uint8_t *responseLength, uint8_t *responseBuffer) const =0; + uint8_t *responseLength, uint8_t *responseBuffer) const { + Q_UNUSED(fromDevice); + Q_UNUSED(lastRequest); + Q_UNUSED(responseLength); + Q_UNUSED(responseBuffer); + return 0; + } // fromDevice: device nr from which data was requested 0,1,2,3 // lastRequest: sent mdb command // responseLength: nr of payload data (after mdb-ack) 0...34 @@ -975,69 +1419,106 @@ public: // ---------------------------------------------------------------------------------------------------------- - virtual void emp_sendSettings(uint16_t coinAcceptance, uint8_t tokenChannel, uint16_t *coinDenomination ) const =0; - // coinAcceptance: bit0=coin1 (lowest donomination) bit15=coin16 bitH=accept bit L = deny coin (no validation) - // tokenChannel 0...31: if this signal comes from emp then a token was inserted - // coinDenomination = array of 16 coin values (e.g. 5, 10, 20...) + virtual void emp_sendSettings(uint16_t coinAcceptance, uint8_t tokenChannel, uint16_t *coinDenomination ) const { + Q_UNUSED(coinAcceptance); + Q_UNUSED(tokenChannel); + Q_UNUSED(coinDenomination); + } + // coinAcceptance: bit0=coin1 (lowest donomination) bit15=coin16 bitH=accept bit L = deny coin (no validation) + // tokenChannel 0...31: if this signal comes from emp then a token was inserted + // coinDenomination = array of 16 coin values (e.g. 5, 10, 20...) - virtual void emp_pollingOnOff(uint8_t on) const =0; + virtual void emp_pollingOnOff(uint8_t on) const { + Q_UNUSED(on); + } - virtual void emp_startCoinAcceptance(void) const =0; + virtual void emp_startCoinAcceptance() const {} - virtual void emp_stopCoinAcceptance(void) const =0; + virtual void emp_stopCoinAcceptance() const {} - virtual void emp_getAllParameters(struct T_emp *emp) const =0; - // see struct in hwapi.h - // usage example: - // hwapi *HWaccess const override; - // HWaccess = new hwapi() const override; - // struct T_emp myEmp const override; - // HWaccess->emp_getAllParameters(&myEmp) const override; - // readval=myEmp.pollingRunning const override; + virtual void emp_getAllParameters(struct T_emp *emp) const { + Q_UNUSED(emp); + } + // see struct in hwapi.h + // usage example: + // hwapi *HWaccess const override; + // HWaccess = new hwapi() const override; + // struct T_emp myEmp const override; + // HWaccess->emp_getAllParameters(&myEmp) const override; + // readval=myEmp.pollingRunning const override; - virtual uint8_t emp_chkIfCoinInserted(void) const =0; - // retval: 0...16 coins left in FIFO + virtual uint8_t emp_chkIfCoinInserted(void) const { + return 0; + } + // retval: 0...16 coins left in FIFO - virtual void emp_getNewCoinRecord(uint8_t *valid, uint8_t *signal, uint8_t *error, uint16_t *value) const =0; - // with every call ONE coin is taken out of FIFO and pointer decremented - // valid: should be 1 - // signal: comes right from coin checker, 0...15 (0=first programmed coin type) 0xFF=no signal - // error: was reported from EMP as dynamic signal right after coin insertion (instead of - // coin signal), example: 3=unknown coin 4=coin is blocked by host. 0xFF=no error - // value: of the coin. Depends on parameter "coinDenomination" in function "emp_sendSettings" - // if coinDenomination[coin 0..15] = 0 then the value programmed in coin checker is taken - // if coinDenomination > 0 then this value is taken. - // Useful in case of two currencies (adapt to local currency) or for token. + virtual void emp_getNewCoinRecord(uint8_t *valid, uint8_t *signal, uint8_t *error, uint16_t *value) const { + Q_UNUSED(value); + Q_UNUSED(signal); + Q_UNUSED(error); + Q_UNUSED(valid); + } + // with every call ONE coin is taken out of FIFO and pointer decremented + // valid: should be 1 + // signal: comes right from coin checker, 0...15 (0=first programmed coin type) 0xFF=no signal + // error: was reported from EMP as dynamic signal right after coin insertion (instead of + // coin signal), example: 3=unknown coin 4=coin is blocked by host. 0xFF=no error + // value: of the coin. Depends on parameter "coinDenomination" in function "emp_sendSettings" + // if coinDenomination[coin 0..15] = 0 then the value programmed in coin checker is taken + // if coinDenomination > 0 then this value is taken. + // Useful in case of two currencies (adapt to local currency) or for token. // function gives more details as "emp getLastCoin()" but "emp getLastCoin()" is easier to use // alternativ to emp_getNewCoinRecord( ): - virtual uint8_t emp_giveLastCoin(uint16_t *value, uint8_t *signal) const =0; - // retval: 0: NO coin stored 1: valid coin 2: got wrong coin or coin denied - // value: if retval1: value of the coin if reval=2: error number - // 0xFF means NO error or NO signal (as 0 is a valid error/signal) - // signal: channel nr reported from checker 0...15 + virtual uint8_t emp_giveLastCoin(uint16_t *value, uint8_t *signal) const { + Q_UNUSED(value); + Q_UNUSED(signal); + return 0; + } + // retval: 0: NO coin stored 1: valid coin 2: got wrong coin or coin denied + // value: if retval1: value of the coin if reval=2: error number + // 0xFF means NO error or NO signal (as 0 is a valid error/signal) + // signal: channel nr reported from checker 0...15 - virtual uint8_t emp_returnLastCoin(uint16_t *value, uint8_t *signal) const =0; - // use for changer + virtual uint8_t emp_returnLastCoin(uint16_t *value, uint8_t *signal) const { + Q_UNUSED(value); + Q_UNUSED(signal); + return 0; + } + // use for changer - virtual QString dc_getTxt4RsDiagWin(void) const =0; - virtual void dc_clrTxt4RsDiagWin(void) const =0; - virtual QString dc_get2ndTxt4RsDiagWin(void) const =0; - virtual void dc_clr2ndTxt4RsDiagWin(void) const =0; - virtual QString dc_getTxt4HsStateLine(void) const =0; - virtual void dc_clrTxt4HsStateLine(void) const =0; - virtual QString dc_getTxt4masterStateLine(void) const =0; - virtual void dc_clrTxt4masterStateLine(void) const =0; - virtual QString dc_getTxt4resultStateLine(void) const =0; - virtual void dc_clrTxt4resultStateLine(void) const =0; - virtual QString dc_getdataStateLine(void) const =0; - virtual void dc_clrTxt4dataStateLine(void) const =0; - virtual QString dc_getdatifLine(void) const =0; - virtual void dc_clrTxt4datifLine(void) const =0; + virtual QString dc_getTxt4RsDiagWin(void) const { + return QString(); + } + virtual void dc_clrTxt4RsDiagWin(void) const {} + virtual QString dc_get2ndTxt4RsDiagWin(void) const { + return QString(); + } + virtual void dc_clr2ndTxt4RsDiagWin(void) const {} + virtual QString dc_getTxt4HsStateLine(void) const { + return QString(); + } + virtual void dc_clrTxt4HsStateLine(void) const {} + virtual QString dc_getTxt4masterStateLine(void) const { + return QString(); + } + virtual void dc_clrTxt4masterStateLine(void) const {} + virtual QString dc_getTxt4resultStateLine(void) const { + return QString(); + } + virtual void dc_clrTxt4resultStateLine(void) const {} + virtual QString dc_getdataStateLine(void) const { + return QString(); + } + virtual void dc_clrTxt4dataStateLine(void) const {} + virtual QString dc_getdatifLine(void) const { + return QString(); + } + virtual void dc_clrTxt4datifLine(void) const {} @@ -1046,27 +1527,54 @@ public: // ---------------------------------------------------------------------------------------------------------- // using DC2 Bootloader - virtual void bl_iniChain(void) const =0; - virtual bool bl_importBinFile(QByteArray readBinFile, uint32_t fileSize, char withDispl) const =0; - virtual uint8_t bl_activatBootloader(uint8_t *sendData) const =0; - virtual uint8_t bl_startChain(void) const =0; - virtual uint8_t bl_readBLversion(uint8_t *sendData) const =0; - // minimum size of sendData-buffer: 5byte retval: length - virtual uint8_t bl_readFWversion(uint8_t *sendData) const =0; - // minimum size of sendData-buffer: 5byte retval: length + virtual void bl_iniChain() const {} + virtual bool bl_importBinFile(QByteArray readBinFile, uint32_t fileSize, char withDispl) const { + Q_UNUSED(readBinFile); + Q_UNUSED(fileSize); + Q_UNUSED(withDispl); + return false; + } + virtual uint8_t bl_activatBootloader(uint8_t *sendData) const { + Q_UNUSED(sendData); + return 0; + } + virtual uint8_t bl_startChain() const { + return 0; + } + virtual uint8_t bl_readBLversion(uint8_t *sendData) const { + Q_UNUSED(sendData); + return 0; + } + // minimum size of sendData-buffer: 5byte retval: length + virtual uint8_t bl_readFWversion(uint8_t *sendData) const { + Q_UNUSED(sendData); + return 0; + } + // minimum size of sendData-buffer: 5byte retval: length - virtual uint8_t bl_prepareDC_BLcmd(uint8_t Cmd, uint8_t SendDataLength, uint8_t *sendData, uint8_t *outBuf) const =0; - // make BL protocol, retval = outbuf length (5...133) - // bring data in correct form: start always with 0x02 finish with 0x03 and append checksum - // 0x02 Cmd < ...sendData ..> CRC CRC 0x03 - // Data length = 0...64 - // special conversion: if data contain 2 or 3 (STX, ETX) then write two bytes: 0x1B (=ESC) and data|0x80 - // so maxlength = 5 + 2 x 64 (if all data are 2 or 3) without 2,3: maxlength = 5 + 64 + virtual uint8_t bl_prepareDC_BLcmd(uint8_t Cmd, uint8_t SendDataLength, uint8_t *sendData, uint8_t *outBuf) const { + Q_UNUSED(Cmd); + Q_UNUSED(SendDataLength); + Q_UNUSED(sendData); + Q_UNUSED(outBuf); + return 0; + } + // make BL protocol, retval = outbuf length (5...133) + // bring data in correct form: start always with 0x02 finish with 0x03 and append checksum + // 0x02 Cmd < ...sendData ..> CRC CRC 0x03 + // Data length = 0...64 + // special conversion: if data contain 2 or 3 (STX, ETX) then write two bytes: 0x1B (=ESC) and data|0x80 + // so maxlength = 5 + 2 x 64 (if all data are 2 or 3) without 2,3: maxlength = 5 + 64 - virtual uint8_t bl_exitBL(uint8_t *sendData) const =0; - // minimum size of sendData-buffer: 5byte retval: length + virtual uint8_t bl_exitBL(uint8_t *sendData) const { + Q_UNUSED(sendData); + return 0; + } + // minimum size of sendData-buffer: 5byte retval: length - virtual void led_switchLedIllumination(uint8_t on) const =0; + virtual void led_switchLedIllumination(uint8_t on) const { + Q_UNUSED(on); + } @@ -1075,33 +1583,44 @@ public: // 27.3.2023: Use Device-Controller's Bootloader to send hex-file // ------------------------------------------------------------------------------------ - virtual void bl_rebootDC(void) const =0; + virtual void bl_rebootDC(void) const {} - virtual void bl_startBL(void) const =0; - virtual void bl_checkBL(void) const =0; - virtual bool bl_isUp(void) const =0; - // return true is bl is up and running - // also initializes "sendFile" + virtual void bl_startBL() const {} + virtual void bl_checkBL() const {} + virtual bool bl_isUp() const { + return false; + } + // return true is bl is up and running + // also initializes "sendFile" - virtual void bl_sendAddress(uint16_t blockNumber) const =0; - // send start address, nr of 64byte-block, start with 0 - // will be sent only for folling block-numbers: - // 0, 1024, 2048, 3072 and 4096, so basically every 64kByte + virtual void bl_sendAddress(uint16_t blockNumber) const { + Q_UNUSED(blockNumber); + } + // send start address, nr of 64byte-block, start with 0 + // will be sent only for folling block-numbers: + // 0, 1024, 2048, 3072 and 4096, so basically every 64kByte - virtual uint8_t bl_wasSendingAddOK(void) const =0; + virtual uint8_t bl_wasSendingAddOK() const { + return 0; + } // return val: 0: no response by now 1:error 10: OK - virtual void bl_openBinary(void) const =0; + virtual void bl_openBinary() const {} - virtual void bl_sendDataBlock(uint8_t length, uint8_t *buffer) const =0; + virtual void bl_sendDataBlock(uint8_t length, uint8_t *buffer) const { + Q_UNUSED(length); + Q_UNUSED(buffer); + } // send 64 byte from bin file - virtual void bl_sendLastBlock(void) const =0; + virtual void bl_sendLastBlock() const {} - virtual uint8_t bl_wasSendingDataOK(void) const =0; + virtual uint8_t bl_wasSendingDataOK() const { + return false; + } // return val: 0: no response by now 1:error 10: OK - virtual void bl_stopBL(void) const =0; + virtual void bl_stopBL() const {} // ------------------------------------------------------------------------------------ @@ -1110,267 +1629,673 @@ public: // ------------------------------------------------------------------------------------ - virtual bool rtc_setTimeDateDirect(struct Trtc_DateTime *DateTime) const =0; - // return true if successful. could fail if more the 8 commands are waiting + virtual bool rtc_setTimeDateDirect(struct Trtc_DateTime *DateTime) const { + Q_UNUSED(DateTime); + return false; + } + // return true if successful. could fail if more the 8 commands are waiting - virtual bool rtc_getExtendedTime(uint8_t *leng, uint8_t *data) const =0; + virtual bool rtc_getExtendedTime(uint8_t *leng, uint8_t *data) const { + Q_UNUSED(leng); + Q_UNUSED(data); + return false; + } - virtual bool rtc_getExtendedTime(struct T_extTime *exTime) const =0; + virtual bool rtc_getExtendedTime(struct T_extTime *exTime) const { + Q_UNUSED(exTime); + return false; + } - virtual bool sys_runCompleteTest(void) const =0; - // warning: lasts 20s in one pace + virtual bool sys_runCompleteTest() const { + return false; + } + // warning: lasts 20s in one pace - virtual bool sys_ready4sending(void) const =0; + virtual bool sys_ready4sending() const { + return false; + } // return true if a Json-file can be sent - virtual bool sys_sendJsonFileToDc(uint8_t kindOfFile, uint8_t nrOfTemplate, uint8_t *content ) const =0; - // kindOfFile: 1=config, 2=device, 3=cash, 4=serial, 5=time, 6=printer - // nrOfTemplate=1...32 if kindOfFile==6 - // content = content of the Json file, max 800byte ascii signs - // file is 0-terminated! - // return false if sending is not possible, wait a second + virtual bool sys_sendJsonFileToDc(uint8_t kindOfFile, uint8_t nrOfTemplate, uint8_t *content ) const { + Q_UNUSED(kindOfFile); + Q_UNUSED(nrOfTemplate); + Q_UNUSED(content); + return false; + } + // kindOfFile: 1=config, 2=device, 3=cash, 4=serial, 5=time, 6=printer + // nrOfTemplate=1...32 if kindOfFile==6 + // content = content of the Json file, max 800byte ascii signs + // file is 0-terminated! + // return false if sending is not possible, wait a second - virtual bool prn_sendDynamicPrnValues(uint8_t *dynPrnVal ) const =0; + virtual bool prn_sendDynamicPrnValues(uint8_t *dynPrnVal ) const { + Q_UNUSED(dynPrnVal); + return false; + } // dynPrnVal = array of 8 Variables with 8 byte each, come as ascii string // like: char prn_dynPrnVal[8][8]; // return true if sending, false if cmd-stack is full - virtual bool prn_printTemplate(uint8_t nrOftemplate) const =0; - // print one of the templates loaded by Json prior - // nr = 1..32 - // return true if sending, false if cmd-stack is full + virtual bool prn_printTemplate(uint8_t nrOftemplate) const { + Q_UNUSED(nrOftemplate); + return false; + } + // print one of the templates loaded by Json prior + // nr = 1..32 + // return true if sending, false if cmd-stack is full - virtual void log_getHoldAccountNumbers(uint8_t *nrOfVals, uint16_t *accNr ) const =0; + virtual void log_getHoldAccountNumbers(uint8_t *nrOfVals, uint16_t *accNr ) const { + Q_UNUSED(nrOfVals); + Q_UNUSED(accNr); + } // returns all acc nrs of the backuped vault records // use: uint16_t backupedAccNumbers[8] - virtual bool log_selectVaultRecord(uint16_t accountNr ) const =0; - // return true if sending, false if cmd-stack is full - // and trigger transfer + virtual bool log_selectVaultRecord(uint16_t accountNr ) const { + Q_UNUSED(accountNr); + return false; + } + // return true if sending, false if cmd-stack is full + // and trigger transfer - virtual bool log_chkIfVaultRecordAvailable(void) const =0; - // return true if completly received + virtual bool log_chkIfVaultRecordAvailable() const { + return false; + } + // return true if completly received virtual bool log_getVaultRecord(struct T_vaultRecord *retVR) const =0; - // which was selected by: log_selectVaultRecord() - // to be forwarded to Ismas + // which was selected by: log_selectVaultRecord() + // to be forwarded to Ismas - virtual bool prn_printAccountReceipt(void) const =0; - // print all 8 backuped accounting receipts - // return true if sending to DC OK, false if cmd-stack is full + virtual bool prn_printAccountReceipt() const { + return false; + } + // print all 8 backuped accounting receipts + // return true if sending to DC OK, false if cmd-stack is full - virtual bool prn_printTestTicket(void) const =0; - // return true if sending to DC OK, false if cmd-stack is full + virtual bool prn_printTestTicket() const { + return false; + } + // return true if sending to DC OK, false if cmd-stack is full - virtual bool cash_startPayment(uint32_t amount) const =0; - // 17.4.23TS: extended to 32bit + virtual bool cash_startPayment(uint32_t amount) const { + Q_UNUSED(amount); + return false; + } + // 17.4.23TS: extended to 32bit - virtual uint8_t cash_paymentProcessing(void) const =0; - // run this function periodically while coin payment process to generate necessary signals - // return value: - // 0: stopped 1: starting up 2: coin collection - // 3: finished by User (Push button) 4: finished, Max-Value collected - // 5: finished by escrow - // 10,11: error cannot start - // 12: timeout while payment, coins returned - // 13: stopped by unexpected error + virtual uint8_t cash_paymentProcessing() const { + return 0; + } + // run this function periodically while coin payment process to generate necessary signals + // return value: + // 0: stopped 1: starting up 2: coin collection + // 3: finished by User (Push button) 4: finished, Max-Value collected + // 5: finished by escrow + // 10,11: error cannot start + // 12: timeout while payment, coins returned + // 13: stopped by unexpected error - virtual uint32_t getInsertedAmount(void) const =0; + virtual uint32_t getInsertedAmount() const { + return 0; + } - virtual uint16_t getLastInsertedCoin(void) const =0; + virtual uint16_t getLastInsertedCoin(void) const { + return 0; + } - virtual bool getAllInsertedCoins(uint16_t *types, uint16_t *values) const =0; - // alle bei diesem Verkauf eingeworfenen Muenzen sind gespeichert, max 64 + virtual bool getAllInsertedCoins(uint16_t *types, uint16_t *values) const { + Q_UNUSED(types); + Q_UNUSED(values); + return false; + } + // alle bei diesem Verkauf eingeworfenen Muenzen sind gespeichert, max 64 - virtual bool cash_cancelPayment(void) const =0; - // and return coins + virtual bool cash_cancelPayment() const { + return false; + } + // and return coins - virtual bool cash_stopPayment(void) const =0; - // and keep coins in escrow + virtual bool cash_stopPayment() const { + return false; + } + // and keep coins in escrow // after ticket/goods issue: - virtual bool vend_success(void) const =0; - // conclude payment process, encash all inserted coins to vault. Printing was successful - // if possible return change + virtual bool vend_success() const { + return false; + } + // conclude payment process, encash all inserted coins to vault. Printing was successful + // if possible return change - virtual bool vend_failed(void) const =0; - // conclude payment process and return all inserted coins + virtual bool vend_failed() const { + return false; + } + // conclude payment process and return all inserted coins - virtual uint8_t mif_getCardType(QString *cardholder) const =0; - // return 1,2,3,4 = upper, lower access card, printer test, coin test - // cardholder: 7byte Name-String + virtual uint8_t mif_getCardType(QString *cardholder) const { + Q_UNUSED(cardholder); + return 0; + } + // return 1,2,3,4 = upper, lower access card, printer test, coin test + // cardholder: 7byte Name-String - virtual uint64_t sys_getWakeSource(void) const =0; - // retval: 6 bytes, bit coded, 1=event keeps DC awake + virtual uint64_t sys_getWakeSource() const { + return 0; + } + // retval: 6 bytes, bit coded, 1=event keeps DC awake - virtual uint8_t sys_getWakeReason(void) const =0; - // Master was woken by following reason: - // 1: MDB Event - // 2: Coin Event - // ( 3: Master Event) - will not set the wake line - // ( 4: 32s pulse) - will not set the wake line - // 5: Door Event - // ( 6: Diag Event) - will not set the wake line - // 7: 30min-Pulse for HB + virtual uint8_t sys_getWakeReason() const { + return 0; + } + // Master was woken by following reason: + // 1: MDB Event + // 2: Coin Event + // ( 3: Master Event) - will not set the wake line + // ( 4: 32s pulse) - will not set the wake line + // 5: Door Event + // ( 6: Diag Event) - will not set the wake line + // 7: 30min-Pulse for HB - virtual void sys_getDeviceConditions(uint8_t *leng, uint8_t *data) const =0; + virtual void sys_getDeviceConditions(uint8_t *leng, uint8_t *data) const { + Q_UNUSED(leng); + Q_UNUSED(data); + } - virtual void sys_getDeviceConditions(struct T_moduleCondition *devCond) const =0; + virtual void sys_getDeviceConditions(struct T_moduleCondition *devCond) const { + Q_UNUSED(devCond); + } - virtual void sys_getDynMachineConditions(uint8_t *leng, uint8_t *data) const =0; + virtual void sys_getDynMachineConditions(uint8_t *leng, uint8_t *data) const { + Q_UNUSED(leng); + Q_UNUSED(data); + } - virtual void sys_getDynMachineConditions(struct T_dynamicCondition *dynMachCond) const =0; + virtual void sys_getDynMachineConditions(struct T_dynamicCondition *dynMachCond) const { + Q_UNUSED(dynMachCond); + } - virtual uint32_t cash_getAmountInVault(void) const =0; + virtual uint32_t cash_getAmountInVault() const { + return 0; + } - virtual uint16_t cash_getNrCoinsInVault(void) const =0; + virtual uint16_t cash_getNrCoinsInVault() const { + return 0; + } - virtual uint8_t prn_getPrintResult() const =0; + virtual uint8_t prn_getPrintResult() const { + return 0; + } - virtual uint8_t prn_getCurrentPrinterState() const =0; - // 0: printer OK - // bit0: near paper end bit1: no paper - // bit2: temperature error bit3: error head open - // bit4: paper jam in cutter - // bit6: no response bit7: serial rec. error - // bit5: printer not ready + virtual uint8_t prn_getCurrentPrinterState() const { + return 0; + } + // 0: printer OK + // bit0: near paper end bit1: no paper + // bit2: temperature error bit3: error head open + // bit4: paper jam in cutter + // bit6: no response bit7: serial rec. error + // bit5: printer not ready - virtual void sys_sendDeviceParameter(struct T_devices *deviceSettings) const =0; + virtual void sys_sendDeviceParameter(struct T_devices *deviceSettings) const { + Q_UNUSED(deviceSettings); + } - virtual void sys_restoreDeviceParameter(struct T_devices *deviceSettings) const =0; - // attention: only applies if function "sys_sendDeviceParameter()" was used to send this settings before - // cannot be used to see settings programmed by JsonFile + virtual void sys_restoreDeviceParameter(struct T_devices *deviceSettings) const { + Q_UNUSED(deviceSettings); + } + // attention: only applies if function "sys_sendDeviceParameter()" was used to send this settings before + // cannot be used to see settings programmed by JsonFile - virtual bool sys_areDCdataValid(void) const =0; + virtual bool sys_areDCdataValid() const { + return false; + } - virtual bool sys_sendingTest(void) const =0; + virtual bool sys_sendingTest() const { + return false; + } - virtual void prn_requestCurrentDynData(void) const =0; + virtual void prn_requestCurrentDynData() const {} - virtual bool prn_getCurrentDynamicPrnValuesFromDC(uint8_t *dynPrnVal ) const =0; + virtual bool prn_getCurrentDynamicPrnValuesFromDC(uint8_t *dynPrnVal ) const { + Q_UNUSED(dynPrnVal); + return false; + } // which was sent with: bool prn_sendDynamicPrnValues(uint8_t *dynPrnVal ) const =0; - virtual bool prn_dynDataAreEqual(uint8_t *buf) const =0; + virtual bool prn_dynDataAreEqual(uint8_t *buf) const { + Q_UNUSED(buf); + return false; + } - virtual bool prn_printKombiticket(uint8_t nrOfKombi) const =0; - // print four of the templates loaded by Json prior - // nr = 1..8 + virtual bool prn_printKombiticket(uint8_t nrOfKombi) const { + Q_UNUSED(nrOfKombi); + return false; + } + // print four of the templates loaded by Json prior + // nr = 1..8 - virtual void lock_triggerUpperSolenoid(void) const =0; + virtual void lock_triggerUpperSolenoid(void) const {} - virtual void lock_triggerLowerSolenoid(void) const =0; + virtual void lock_triggerLowerSolenoid(void) const {} - virtual bool doors_supervise(void) const =0; + virtual bool doors_supervise() const { + return false; + } - virtual bool dc_isAutoRequestOn(void) const =0; + virtual bool dc_isAutoRequestOn() const { + return false; + } - virtual uint16_t log_getLatestAccountNumber(void) const=0; + virtual uint16_t log_getLatestAccountNumber() const { + return 0; + } // new function 27.6.2023 // latest = highest of the backup's - virtual uint8_t log_getAvailableVaultBlocks(void) const=0; - // return 0x0011 1111 if all 6 blocks are loaded (one bit per block) - - virtual uint8_t log_getAnswerToLastSlaveRequest(void) const =0; - // use only for ONE request/command - // return: 0xFF: result unknown by now as sending is ongoing - // 0=OK - // 1= wrong length 2=wrong start sign 5= wrong crc - // 6= slave: master cmd was wrong 7: slave: could not write/read data - // 8=timeout, got no response from slave + virtual uint8_t log_getAvailableVaultBlocks() const { + return 0; + } + // return 0x0011 1111 if all 6 blocks are loaded (one bit per block) + virtual uint8_t log_getAnswerToLastSlaveRequest() const { + return 0; + } + // use only for ONE request/command + // return: 0xFF: result unknown by now as sending is ongoing + // 0=OK + // 1= wrong length 2=wrong start sign 5= wrong crc + // 6= slave: master cmd was wrong 7: slave: could not write/read data + // 8=timeout, got no response from slave + // 0,8 work, 1..6 not yet tested. 8 comes immed. and stays 8 until reconnect // use for important and extended commands (print several templates, print ticket...) - virtual void log_startSupervision(void) const =0; + virtual void log_startSupervision() const {} - virtual uint8_t log_getAnswerToLastCmdBatch(void) const =0; - // 0xFF: no command sent by now - // 0: started, in progress - // 1: done and OK - // 2: done and error + virtual uint8_t log_getAnswerToLastCmdBatch() const { + return 0; + } + // 0xFF: no command sent by now + // 0: started, in progress + // 1: done and OK + // 2: done and error + // not working properly, always 0 - virtual bool log_getVaultData(uint8_t *data) const =0; - // get vault record in linear 8bit buffer with 384 byte + virtual bool log_getVaultData(uint8_t *data) const { + Q_UNUSED(data); + return false; + } + // get vault record in linear 8bit buffer with 384 byte // new from 1.8.23 - virtual bool prn_printOneAccountReceipt(uint16_t accountNr) const =0; - // print one out of eight stored last accounting receipts - // function log_getHoldAccountNumbers() gives a list of acc-Nr. of the stored receipts + virtual bool prn_printOneAccountReceipt(uint16_t accountNr) const { + Q_UNUSED(accountNr); + return false; + } + // print one out of eight stored last accounting receipts + // function log_getHoldAccountNumbers() gives a list of acc-Nr. of the stored receipts - virtual bool prn_printAllAvailAccountReceipts(void) const =0; - // same as: prn_printAccountReceipt() from line 1153 - // return true if sending to DC OK, false if cmd-stack is full + virtual bool prn_printAllAvailAccountReceipts() const { + return false; + } + // same as: prn_printAccountReceipt() from line 1153 + // return true if sending to DC OK, false if cmd-stack is full - virtual bool log_verifyVaultRecordByCrc(void) const =0; - // return true if CRC16 is correct, data are 100% OK. Security level 1:65536 - // verification is strongly recommended before further processing - // in case of "false"-result please reload from DC + virtual bool log_verifyVaultRecordByCrc() const { + return false; + } + // return true if CRC16 is correct, data are 100% OK. Security level 1:65536 + // verification is strongly recommended before further processing + // in case of "false"-result please reload from DC - virtual uint16_t log_DC_getNextAccountNumber(void) const=0; - // the current cash box content will be backuped with this number on next cashbox-change + virtual uint16_t log_DC_getNextAccountNumber() const { + return 0; + } + // the current cash box content will be backuped with this number on next cashbox-change - virtual void log_DC_setNextAccountNumber(uint16_t newAccountingNumber) const=0; - // the current cash box content will be backuped with this number on next cashbox-change - // use only in case of hardware replacements or errors which derailed the number + virtual void log_DC_setNextAccountNumber(uint16_t newAccountingNumber) const { + Q_UNUSED(newAccountingNumber); + } + // the current cash box content will be backuped with this number on next cashbox-change + // use only in case of hardware replacements or errors which derailed the number - virtual void log_DC_deleteAllVaultrecordsInDc(void) const=0; - // use only in case of hardware replacements or errors which derailed the number + virtual void log_DC_deleteAllVaultrecordsInDc() const {} + // use only in case of hardware replacements or errors which derailed the number - virtual void log_DC_deleteAllTotalCounters(void) const=0; - // use only in case of hardware replacements or errors which derailed the number + virtual void log_DC_deleteAllTotalCounters() const {} + // use only in case of hardware replacements or errors which derailed the number - virtual void dc_setNewCustomerNumber(uint16_t newCustNr) const =0; + virtual void dc_setNewCustomerNumber(uint16_t newCustNr) const { + Q_UNUSED(newCustNr); + } - virtual void dc_setNewMachineNumber(uint16_t newMachNr) const =0; + virtual void dc_setNewMachineNumber(uint16_t newMachNr) const { + Q_UNUSED(newMachNr); + } - virtual void dc_setNewBorough(uint16_t newBorough) const =0; + virtual void dc_setNewBorough(uint16_t newBorough) const { + Q_UNUSED(newBorough); + } + + virtual void dc_setNewZone(uint16_t newZone) const { + Q_UNUSED(newZone); + } + + + + // new functions from 8.9.23 + virtual QString mif_getReaderType() const { + return QString(); + } + // return "SL025" if correct reader is connected + + virtual void mif_getCardSize(uint8_t *cardSize, uint8_t *idLeng) const { + Q_UNUSED(cardSize); + Q_UNUSED(idLeng); + } + // cardSize=1k or 4kByte + // idLeng =4Byte or 7 byte + + virtual char mif_getAtbCardData(uint8_t *buf, uint8_t maxBuffSiz) const { + Q_UNUSED(buf); + Q_UNUSED(maxBuffSiz); + return 0; + } + // return complete buffer binary, just for test purpose + + virtual bool mif_isValidAtbCard() const { + return false; + } + + virtual uint32_t mif_getAtbCardCuNu() const { + return 0; + } + + virtual uint8_t mif_getAtbCardTyp() const { + return 0; + } + // return 1=upper door card 1=lower door 3=printer-test 4=coin-test + // 0: not a valid atb2020 card + + virtual QString mif_getAtbCardPerso() const { + return QString(); + } + // e.g. "PNsax001" used for personal number, name shortcode, card number + // free to use, can be set in AtbMcw23.exe tool + + virtual void mif_getAtbCardExpire(uint8_t *year, uint8_t *month, uint8_t *day, uint8_t *hour, uint8_t *minute) const { + Q_UNUSED(year); + Q_UNUSED(month); + Q_UNUSED(day); + Q_UNUSED(hour); + Q_UNUSED(minute); + } + + + // ------------------------------------------------------------------------------------ + // Device-Controller-Bootloader convenient version 21.09.2023 + // ------------------------------------------------------------------------------------ + + // use this to jump to BL: + //void hwapi::bl_rebootDC(void) const + + // use this to start BL: + // void hwapi::bl_startBL(void) const + + // call this in order to get response from BL: + //void hwapi::bl_checkBL(void) const + + // evaluate BL response: + //bool hwapi::bl_isUp(void) const + + // 29.9.23: new: "completeStart" function, replaces bl_rebootDC(), bl_startBL() and bl_checkBL() + // result can be verified with bl_isUp() as before + virtual bool bl_completeStart() const { + return false; + } + // must be used in DC's normal operation + + // select binfile-name in GUI + + // send binfile-name to BL-processor: + virtual bool bl_storeFirmware(QString fileName) const { + Q_UNUSED(fileName); + return false; + } + // load binary file 3x and compare + // return true if loaded correctly + // return false: error, could not load correctly + + // request the number of blocks for this file + virtual uint16_t bl_getNrOfFirmwareBlocks() const { + return 0; + } + // size of the loaded bin file in 64byte blocks + // call after bl_storeFirmware() + + // call the next two function's repetitive with "blockNumber"=0,1,2,3....."bl_getNrOfFirmwareBlocks()" + + virtual bool bl_blockAutoLoad(uint16_t blockNumber) const { + Q_UNUSED(blockNumber); + return false; + } + // call in loop from block number 0 up to <= "dcBL_getNrOfBlocks()" + //the last block "bl_getNrOfFirmwareBlocks()" is sent as conclusion command (important!) + // but after every call WAIT (!) for response "bl_blockAutoResponse()" !!!! + // data will be sent to DC, if neccesary addr will be sent additionally + // if neccesary sending will automatically repeat up to 3times + // retval: false if blockNumber>4095, true else + + // check out this response after every block-sending, wait until >0!!! + virtual int8_t bl_blockAutoResponse() const { + return 0; + } + // after every "bl_blockAutoLoad()" call this until response + // retval 0: wait 1: OK, blk was sent 2: OK, transfer complete + // 3: error despite repeating, cancel. probably bin file corrupted + // Max duration: 3x no response from BL = 900ms + + + // finally call: + // void hwapi::bl_stopBL(void) const + // -------------- end of bootloader --------------------------------------------------- + + + + // new from 28.9.23 and earliest from DC version 4.45 + // get all versions of the DC-Jsons + virtual void sys_requestJsonVersions(uint8_t jsonNr) const { + Q_UNUSED(jsonNr); + } + // send one request for every single version + // jsonNr=1...36, 1=config file (cust.Nr) 2=devices 3=cash 4=res. + // 5=printer template 1 ..... 36= template 32 + + virtual void sys_getJsonVersions(uint8_t jsonNr, char *versionString) const { + Q_UNUSED(jsonNr); + Q_UNUSED(versionString); + } + // jsonNr=1...36, 1=config file (cust.Nr) 2=devices 3=cash 4=res. + // 5=printer template 1 ..... 36= template 32 + // length of buffer is always 16 byte + + // ------------------------------------------------------------------------------------ + // Coin Changer + // ------------------------------------------------------------------------------------ + + // find above (same as for coin checker (EMP)): + + // mdb_switchPower(true); // power on/off + // cash_startPayment(amount_cent); // start polling, enable coins, changer turns to green + + // getInsertedAmount() + // getLastInsertedCoin() + // getAllInsertedCoins(uint16_t *types, uint16_t *values) + // all inserted coins of this past transaction are stored, max 64 + + // cash_stopPayment(); // and wait for further command (changer blinks yellow) + // cash_cancelPayment(); // and return complete paid amount + + // after ticket/goods issue: + // vend_success() + // conclude payment process, keep all coins. Printing was successful + // return change (payment above start-amount), so it works only if + // Payment was started with real vending price (pre selection). + // if payment was started with maximum price (for direct coin insertion) + // then use "changer_returnCoins()", not vend_success() + + // vend_failed() + // conclude payment process and return complete paid amount + + // also valid for changer: + // emp_sendSettings(uint16_t coinAcceptance, uint8_t tokenChannel, uint16_t *coinDenomination ) const =0; + // coinAcceptance: bit0=coin1 (lowest donomination) bit15=coin16 bitH=accept bit L = deny coin (no validation) + // tokenChannel 0...31: if this signal comes from emp then a token was inserted + // coinDenomination = array of 16 coin values (e.g. 5, 10, 20...) + + virtual void changer_returnCoins(uint32_t amountInCent) const { + Q_UNUSED(amountInCent); + } + + virtual void changer_requestChangeResult() const {} + + virtual uint8_t changer_getChangeResult(uint32_t *returnedAmount) const { + Q_UNUSED(returnedAmount); + return 0; + } + // get result of coin dispensing + // receivedData[0]: 0: not yet started 1:amount returned + // 2:only partial return 3: no return possible + // receivedData[2,3,4,5]: returned amount + + virtual void changer_getAllParameters(struct T_changer *mw) const { + Q_UNUSED(mw); + } + // requested automatically with 23, same like EMP + + virtual void changer_requestTubelevel(void) const {} + + virtual void changer_getTubelevel(struct T_chg_Tub *tubLevel) const { + Q_UNUSED(tubLevel); + } + // don't use tubeDispens[], it's not yet correct! + + + + // ------------------------------------------------------------------------------------ + // bank note acceptor + // ------------------------------------------------------------------------------------ + + // already defiened functions applying for BNA as well: + // mdb_switchPower(true); // power on/off + + // bank notes are integrated in the normal transaction process, so use the usual functions to run a vending cycle: + // cash_startPayment(amount_cent); // start polling, enable bills, reader shows green + // getInsertedAmount() + // cash_stopPayment(); + // cash_cancelPayment(); + // vend_success() + // vend_failed() + + virtual void bna_sendSettings(uint16_t notesToAccept, uint16_t parameters, + uint16_t *billDenomination, + uint32_t acceptanceLimit) const { + Q_UNUSED(notesToAccept); + Q_UNUSED(parameters); + Q_UNUSED(billDenomination); + Q_UNUSED(acceptanceLimit); + + } + // notesToAccept: bit0=bill1 (lowest donomination) bitH=accept bit L = deny + // parameters: e.g. use escrow function for some notes + // billDenomination = array of 16 bill values (e.g. 5, 10, 20...) + // these can be set alternatively by Json-File DC2C_cash.json + // acceptanceLimit: device will stop acceptance once this amount is reached and + // optionally keep last bill in escrow until vend_success() + // is called (put bill to stacker) or vend_failed() is called (return bill) + + virtual void bna_setCurrentAcceptance(uint16_t notesToAccept) const { + Q_UNUSED(notesToAccept); + } + // can be used to block notes dynamically, example: from now only 5€ bills are allowed (if only 3€ are to be paid) + // only valid till next start-payment. Cannot add notes which are not activated in Json + + virtual void bna_requestParameters() const {} + // send command to DC in order to get static invariable device parameters like currency + // device must be powered and polled to get these + + virtual bool bna_getAllParameters(struct T_bna *bna) const { + Q_UNUSED(bna); + return false; + } + // get all constant data from reader (e.g. currency) + // and actual Host-Settings (sent with bna_sendSettings() or json) + // retval = true if data are valid + + 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 { + Q_UNUSED(latestBill); + Q_UNUSED(currentNotes); + return 0; + } + // returns number of collected bank notes since start-command (current transaction) + // latestBill: last accepted bank note, value in cent + // currentNotes an array with up to 16 (further) notes collected + + virtual void bna_requestStackerLevel() const {} + + virtual uint16_t bna_getStackerLevel(uint32_t *amountInStacker, uint16_t *countOfBills) const { + Q_UNUSED(amountInStacker); + Q_UNUSED(countOfBills); + return 0; + } + // return val: nr of bills in stacker + // countOfBills: array of up to 16 sums, countOfBills[0]=nr of 5€-bills in stacker + // countOfBills[1] for 10€ and so on - virtual void dc_setNewZone(uint16_t newZone) const =0; signals: - virtual void hwapi_templatePrintFinished_OK(void) const=0; - virtual void hwapi_templatePrintFinished_Err(void) const=0; + // NOTE: declaring a "pure virtual" "signal" should be an error and thus not valid. + void hwapi_templatePrintFinished_OK() const; + void hwapi_templatePrintFinished_Err() const; - 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; - - - // new from 2023.06.12 - 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; + void hwapi_coinCollectionJustStarted() const; + void hwapi_coinCollectionAborted() const; + void hwapi_gotNewCoin() const; + void hwapi_payStopByMax() const; + void hwapi_payStopByPushbutton() const; + void hwapi_payStopByEscrow() const; + void hwapi_payStopByError() const; + void hwapi_payStopByTimeout() const; + void hwapi_payCancelled() const; + void hwapi_coinProcessJustStopped() const; + void hwapi_doorServiceDoorOpened() const; + void hwapi_doorVaultDoorOpened() const; + void hwapi_doorCoinBoxRemoved() const; + void hwapi_doorCoinBoxInserted() const; + void hwapi_doorCBinAndAllDoorsClosed() const; + void hwapi_doorAllDoorsClosed() const; }; @@ -1413,9 +2338,29 @@ signals: //#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.1" //#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.2" //#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.3" -#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.4" +//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.4" + // 8.9.2023 two new functions (end of file) for mifare test +//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.5" + // 18.9.2023 major improvements for DC data exchange + // verification of door and cash box signals + // intensive verification of Json-Programming Master-Slave (PTU to DC), 100% ok +//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.6" + // 20.9.2023: speeding up door and cash box signals +//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.7" + // 26.09.2023: added improved DC-bootloader files +//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/4.8" +// 28.09.2023: added version request of DC-Json-Files +//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/5.0" + // 10.10.2023: added coin changer +//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/5.1" +// 20.10.2023: added bill validator +// hier dazwischen: Umstellung ALLER Prototypen +// hier von =0 auf {} durch Gerhard + +#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/5.2" + // 7.11.2023: bna functions activated Q_DECLARE_INTERFACE(hwinf, HWINF_iid) diff --git a/plugins/libCAmaster.so b/plugins/libCAmaster.so index eafb659..39e1557 100755 Binary files a/plugins/libCAmaster.so and b/plugins/libCAmaster.so differ diff --git a/plugins/libCAslave.so b/plugins/libCAslave.so new file mode 100755 index 0000000..74a1fc9 Binary files /dev/null and b/plugins/libCAslave.so differ diff --git a/plugins/libCashAgentLib.so b/plugins/libCashAgentLib.so deleted file mode 100755 index 791a182..0000000 Binary files a/plugins/libCashAgentLib.so and /dev/null differ diff --git a/process/command.cpp b/process/command.cpp index 22b03a4..c85c8ac 100644 --- a/process/command.cpp +++ b/process/command.cpp @@ -4,6 +4,7 @@ #include #include #include +#include Command::Command(QString const &command, int start_timeout, int finish_timeout) : m_command(command.trimmed()) @@ -65,39 +66,58 @@ bool Command::execute(QString workingDirectory, QStringList args) { p->start(m_command); } + qint64 const start = QDateTime::currentDateTime().toMSecsSinceEpoch(); + if (p->waitForStarted(m_waitForStartTimeout)) { qDebug() << "PROCESS" << m_command << "STARTED IN" << p->workingDirectory(); if (p->state() == QProcess::ProcessState::Running) { qDebug() << "PROCESS" << m_command << "RUNNING IN" << p->workingDirectory(); - if (p->waitForFinished(m_waitForFinishTimeout)) { + // wait forever for git/opkg-commands to finish + int wait = m_waitForFinishTimeout; + if (m_command.trimmed().startsWith("git", Qt::CaseInsensitive) || + m_command.trimmed().startsWith("opkg", Qt::CaseInsensitive)) { + wait = -1; + } + bool const no_timeout = p->waitForFinished(wait); + if (no_timeout) { qDebug() << "PROCESS" << m_command << "FINISHED IN" << p->workingDirectory(); if (p->exitStatus() == QProcess::NormalExit) { if ((m_exitCode = p->exitCode()) == 0) { + qint64 const end = QDateTime::currentDateTime().toMSecsSinceEpoch(); qDebug() << "EXECUTED" << m_command + << QString("(runtime %1ms)").arg(end-start) << "with code" << m_exitCode << "IN" << p->workingDirectory(); return true; } else { + qint64 const end = QDateTime::currentDateTime().toMSecsSinceEpoch(); qCritical() << "EXECUTED" << m_command + << QString("(runtime %1ms)").arg(end-start) << "with code" << m_exitCode << "IN" << p->workingDirectory(); } } else { + qint64 const end = QDateTime::currentDateTime().toMSecsSinceEpoch(); qCritical() << "PROCESS" << m_command << "CRASHED with code" << p->exitCode() + << QString("(after %1ms)").arg(end-start) << "IN" << p->workingDirectory(); } } else { + qint64 const end = QDateTime::currentDateTime().toMSecsSinceEpoch(); qCritical() << "PROCESS" << m_command - << "DID NOT FINISH" - << "IN" << p->workingDirectory(); + << "DID NOT FINISH WITH" << wait + << "MS IN" << p->workingDirectory() + << QString("(runtime %1ms)").arg(end-start); } } else { qCritical() << "WRONG PROCESS STATE" << p->state() << "IN" << p->workingDirectory(); } } else { + qint64 const end = QDateTime::currentDateTime().toMSecsSinceEpoch(); qCritical() << "PROCESS" << m_command << "TIMEOUT AT START" + << QString("(runtime %1ms)").arg(end-start) << "IN" << p->workingDirectory(); } return false; diff --git a/update.cpp b/update.cpp index 66d9770..551d912 100644 --- a/update.cpp +++ b/update.cpp @@ -29,11 +29,7 @@ #include #define UPDATE_OPKG (1) -#define UPDATE_DC (1) -#define UPDATE_PRINTER_TEMPLATES (1) -#define UPDATE_CASH_TEMPLATE (1) -#define UPDATE_CONF_TEMPLATE (1) -#define UPDATE_DEVICE_TEMPLATE (1) +#define UPDATE_DC (0) static const QMap baudrateMap = { {"1200" , 0}, {"9600" , 1}, {"19200" , 2}, {"38400" , 3}, @@ -98,11 +94,11 @@ bool Update::unloadDCPlugin() { return false; } -Update::Update(hwinf *hw, - Worker *worker, +Update::Update(Worker *worker, QString customerRepository, QString customerNrStr, QString branchName, + QString plugInDir, QString pluginName, QString workingDir, bool dryRun, @@ -110,7 +106,7 @@ Update::Update(hwinf *hw, char const *serialInterface, char const *baudrate) : QObject(parent) - , m_hw(hw) + , m_hw(loadDCPlugin(QDir(plugInDir), pluginName)) , m_worker(worker) , m_serialInterface(serialInterface) , m_baudrate(baudrate) @@ -119,214 +115,33 @@ Update::Update(hwinf *hw, , m_branchName(branchName) , m_pluginName(pluginName) , m_workingDir(workingDir) - , m_dryRun(dryRun) { + , m_dryRun(dryRun) + , m_sys_areDCdataValid(false) { - qInfo() << "UPDATE: m_serialInterface ..." << m_serialInterface; - qInfo() << "UPDATE: m_baudrate ..." << m_baudrate; - qInfo() << "UPDATE: m_customerRepository ..." << m_customerRepository; - qInfo() << "UPDATE: m_customerNr ..........." << m_customerNrStr; - qInfo() << "UPDATE: m_branchName ..........." << m_branchName; - qInfo() << "UPDATE: m_pluginName ..........." << m_pluginName; - qInfo() << "UPDATE: m_workingDirectory ....." << m_workingDir; + int tries = 20; + while ((m_sys_areDCdataValid = m_hw->sys_areDCdataValid()) == false) { + // must deliver 'true', only then are all data from hwapi valid + if (--tries < 0) { + qCritical() << "ERROR!!! DC DATA NOT VALID -> CA-MASTER-PLUGIN NOT CONNECTED"; + } + m_hw->dc_autoRequest(true); + QThread::msleep(500); + } + + qCritical() << "UPDATE: m_sys_areDCDataValid ..." << m_sys_areDCdataValid; + + //qInfo() << "UPDATE: m_serialInterface ..." << m_serialInterface; + //qInfo() << "UPDATE: m_baudrate ..." << m_baudrate; + //qInfo() << "UPDATE: m_customerRepository ..." << m_customerRepository; + //qInfo() << "UPDATE: m_customerNr ..........." << m_customerNrStr; + //qInfo() << "UPDATE: m_branchName ..........." << m_branchName; + //qInfo() << "UPDATE: m_pluginName ..........." << m_pluginName; + //qInfo() << "UPDATE: m_workingDirectory ....." << m_workingDir; } Update::~Update() { } -Update::DownloadResult Update::sendStatus(int ret) const { - switch (ret) { // return values of dc are: - case 0: // 0: no answer by now - return DownloadResult::NOP; // 1: error - case 10: // 10: success - return DownloadResult::OK; - default:; - } - return DownloadResult::ERROR; -} - -Update::DownloadResult Update::sendNextAddress(int bNum) const { - // sends address only if blockNumber is one of 0, 1024, 2048, 3072, 4096 - int noAnswerCount = 0; - int errorCount = 0; - if ( bNum==0 || bNum==1024 || bNum==2048 || bNum==3072 || bNum==4096 ) { - // qDebug() << "addr-block" << bNum << "..."; - while (noAnswerCount <= 250) { - m_hw->bl_sendAddress(bNum); - QThread::msleep(100); - DownloadResult const res = sendStatus(m_hw->bl_wasSendingAddOK()); - if (res != DownloadResult::NOP) { - if (res == DownloadResult::ERROR) { - if (++errorCount >= 10) { - qCritical() << "addr-block" << bNum << "...FAILED"; - return res; - } - } else { // res == DownloadResult::OK - // qInfo() << "addr-block" << bNum << "...OK"; - return res; - } - } else { - noAnswerCount += 1; // no answer by now - } - } - // wait max. about 3 seconds - return DownloadResult::TIMEOUT; - } - // blockNumber is not one of 0, 1024, 2048, 3072, 4096 -> do nothing - return DownloadResult::NOP; -} - -Update::DownloadResult Update::sendNextDataBlock(QByteArray const &binary, - int bNum) const { - uint8_t local[66]; - int const bAddr = bNum * 64; - int noAnswerCount = 0; - int errorCount = 0; - - memcpy(local, binary.constData() + bAddr, 64); - local[64] = local[65] = 0x00; - - // QByteArray b((const char *)(&local[0]), 64); - // qCritical() << "SNDB" << bNum << b.size() << b.toHex(); - - while (noAnswerCount <= 250) { - m_hw->bl_sendDataBlock(64, local); - QThread::msleep(10); - DownloadResult const res = sendStatus(m_hw->bl_wasSendingDataOK()); - if (res != DownloadResult::NOP) { - if (res == DownloadResult::ERROR) { - if (++errorCount >= 10) { - qCritical() << "data for block" << bNum << "...FAILED"; - return res; - } - } else { - // qInfo() << "data for block" << bNum << "OK"; - return res; - } - } else { - noAnswerCount += 1; // no answer by now - } - } - // wait max. about 3 seconds - return DownloadResult::TIMEOUT; -} - -Update::DownloadResult Update::dc_downloadBinary(QByteArray const &b) const { - int const nBlocks = (((b.size())%64)==0) ? (b.size()/64) : (b.size()/64)+1; - - // fill lst block of data to be sent with 0xFF - QByteArray ba = b.leftJustified(nBlocks*64, (char)(0xFF)); - - qInfo() << "total number of bytes to send to dc" << ba.size(); - qInfo() << "total number of blocks to send to dc" << nBlocks; - - int bNum = 0; - DownloadResult res = DownloadResult::OK; - fprintf(stderr, "\n64-byte block %04d ", bNum); - while (res != DownloadResult::ERROR && bNum < nBlocks) { - if ((res = sendNextAddress(bNum)) != DownloadResult::ERROR) { - if ((res = sendNextDataBlock(ba, bNum)) != DownloadResult::ERROR) { - bNum += 1; - fprintf(stderr, "."); - if ((bNum % 80) == 0) { - fprintf(stderr, "\n64-byte block %04d ", bNum); - } - } - } - } - fprintf(stderr, "\nlast 64-byte block %04d\n", bNum); - - 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() << "ERROR SEND REMAINING" << rest << "BYTES"; - m_hw->bl_sendDataBlock(64, local); - } - - m_hw->bl_sendLastBlock(); - qInfo() << "last result" << (int)sendStatus(m_hw->bl_wasSendingDataOK()); - return res; -} - -bool Update::startBootloader() const { // deprecated - return false; -#if 0 - int nStartTry = 5; - while (--nStartTry >= 0) { - m_hw->bl_startBL(); - QThread::msleep(500); - int nCheckTry = 10; - while (--nCheckTry >= 0) { - m_hw->bl_checkBL(); - QThread::msleep(500); - if (m_hw->bl_isUp()) { - qInfo() << "starting bootloader...OK"; - return true; - } else { - qCritical() << "bootloader not up (" - << nStartTry << "," << nCheckTry << ")" << QThread::currentThread(); - } - } - } - qCritical() << "starting bootloader...FAILED" << QThread::currentThread(); - return false; -#endif -} - -bool Update::stopBootloader() const { - // stop bootloader: this MUST work -> otherwise the PSA has to be restarted - // manually - emit m_worker->showErrorMessage("dc update", "stopping bootloader..."); - - int nTryFinalize = 1; // could do this in an endless loop - - do { - // in principle, any value except BL_STOP will do, as we want to detect - // change to BL_STOP - m_worker->mainWindow()->setUpdateStep(UpdateDcEvent::UpdateStep::BL_CHECK); - - QApplication::postEvent( - m_worker->mainWindow(), - new UpdateDcEvent(m_worker, UpdateDcEvent::UpdateStep::BL_STOP, nTryFinalize)); - - QThread::sleep(1); - - int const cntLimit = 20; - int cnt = 0; - while (++cnt < cntLimit && - m_worker->mainWindow()->updateStep() != UpdateDcEvent::UpdateStep::BL_STOP) { - // wait until bl_stopBL() has been sent - QThread::msleep(500); - } - - QApplication::postEvent( - m_worker->mainWindow(), - new UpdateDcEvent(m_worker, UpdateDcEvent::UpdateStep::BL_CHECK, nTryFinalize)); - QThread::sleep(1); - - QApplication::postEvent( - m_worker->mainWindow(), - new UpdateDcEvent(m_worker, UpdateDcEvent::UpdateStep::BL_IS_UP, nTryFinalize)); - QThread::sleep(1); - - cnt = 0; - while (++cnt < cntLimit && - m_worker->mainWindow()->updateStep() != UpdateDcEvent::UpdateStep::BL_IS_DOWN) { - // wait until done - QThread::msleep(200); - } - - } while (++nTryFinalize <= MainWindow::BL_STOP_COUNT && - m_worker->mainWindow()->updateStep() != UpdateDcEvent::UpdateStep::BL_IS_DOWN); - - return (m_worker->mainWindow()->updateStep() == UpdateDcEvent::UpdateStep::BL_IS_DOWN); -} - // br is a index into a table, used for historical reasons. bool Update::openSerial(int br, QString baudrate, QString comPort) const { qDebug() << "opening serial" << br << baudrate << comPort << "..."; @@ -358,51 +173,6 @@ bool Update::isSerialOpen() const { return m_hw->dc_isPortOpen(); } -bool Update::resetDeviceController() const { // deprecated - return false; -#if 0 - qDebug() << "resetting device controller..."; - m_hw->bl_rebootDC(); - // wait maximally 3 seconds, before starting bootloader - qInfo() << "resetting device controller...OK"; - return true; -#endif -} - -QByteArray Update::loadBinaryDCFile(QString filename) const { - qDebug() << "loading dc binary" << filename << "..."; - - QFile file(filename); // closed in destructor call - if (!file.exists()) { - qCritical() << file.fileName() << "does not exist"; - return QByteArray(); - } - if (!file.open(QIODevice::ReadOnly)) { - qCritical() << "cannot open file" << file.fileName(); - return QByteArray(); - } - qInfo() << "loading dc binary" << filename << "...OK"; - return file.readAll(); -} - -bool Update::downloadBinaryToDC(QString const &bFile) const { - qDebug() << "sending" << bFile << "to dc..."; - QByteArray const dcBinary = loadBinaryDCFile(bFile); - if (dcBinary.size() > 0) { - if (dc_downloadBinary(dcBinary) != DownloadResult::OK) { - qCritical() << "sending" << bFile << "to dc...FAILED"; - return false; - } else { - qInfo() << "sending" << bFile << "to dc...OK"; - } - } else { - qCritical() << "sending" << bFile << "to dc...FAILED"; - qCritical() << "loading binary" << bFile << "FAILED"; - return false; - } - return true; -} - /* /////////////////////////////////////////////////////////////////////////////// @@ -486,111 +256,78 @@ bool Update::downloadBinaryToDC(QString const &bFile) const { // There is no problem to repeat this command until the // bootloader is really not running anymore. */ -bool Update::updateBinary(char const *fileToSendToDC) { +bool Update::updateBinary(QString const &fileToSendToDC) { qInfo() << "UPDATING DEVICE CONTROLLER FIRMWARE BINARY" << fileToSendToDC; + + return false; + QFile fn(fileToSendToDC); - bool r; - if ((r = fn.exists()) == true) { - QFileInfo fi(fn); - if ((r = updateDC(fileToSendToDC)) == true) { - Utils::printInfoMsg( - QString(" UPDATING BINARY ") + fi.fileName() - + QString(" (size=%1").arg(fi.size()) + ") DONE"); - } else { - Utils::printCriticalErrorMsg( - QString(" UPDATING BINARY ") + fi.fileName() - + QString(" (size=%1").arg(fi.size()) + ") FAILED"); + if (!fn.exists()) { + // output via CONSOLE() etc + return false; + } + + bool bl_isUp = false; + if (m_hw->bl_completeStart()) { + int cnt = 5; + while (--cnt > 0) { + if (m_hw->bl_isUp()) { + bl_isUp = true; + break; + } } - } else { - Utils::printCriticalErrorMsg( - QString(fileToSendToDC) + " DOES NOT EXIST -> NO UPDATE OF DC FIRMWARE"); - } - return r; -} - -bool Update::updateDC(QString bFile) const { - qDebug() << "IN UPDATEDC: UPDATING DC: FILE TO SEND" << bFile; - - m_worker->mainWindow()->setUpdateStep(UpdateDcEvent::UpdateStep::NONE); - - QApplication::postEvent( // step 1: reset device controller - m_worker->mainWindow(), - new UpdateDcEvent(m_worker, UpdateDcEvent::UpdateStep::DC_REBOOT, 1)); - QThread::sleep(1); - - for (int i=1; i <= MainWindow::BL_START_COUNT; ++i) { - QApplication::postEvent( // step 2: start bootloader (5x) - m_worker->mainWindow(), - new UpdateDcEvent(m_worker, UpdateDcEvent::UpdateStep::BL_START, i)); - QThread::sleep(1); } - int const cntLimit = 100; // wait until its for sure that bl_startBL() - int cnt = 0; // has been excuted - while (++cnt < cntLimit && - m_worker->mainWindow()->updateStep() != UpdateDcEvent::UpdateStep::BL_START) { - // wait until all bl_startBL() are done - QThread::msleep(200); - } - - if (cnt == cntLimit) { - // start events not received ??? - Utils::printCriticalErrorMsg("BL_START EVENT NOT RECEIVED AFTER 20 SECS"); + if (!bl_isUp) { return false; } - m_worker->mainWindow()->setUpdateStep(UpdateDcEvent::UpdateStep::BL_CHECK); + if (!m_hw->bl_storeFirmware(fileToSendToDC)) { + m_hw->bl_stopBL(); + return false; + } - for (int i=1; i <= MainWindow::BL_IS_UP_COUNT; ++i) { - QApplication::postEvent(m_worker->mainWindow(), new UpdateDcEvent(m_worker, UpdateDcEvent::UpdateStep::BL_CHECK, i)); - QThread::sleep(1); - QApplication::postEvent(m_worker->mainWindow(), new UpdateDcEvent(m_worker, UpdateDcEvent::UpdateStep::BL_IS_UP, i)); - if (m_worker->mainWindow()->updateStep() == UpdateDcEvent::UpdateStep::BL_IS_UP) { - break; + uint16_t const nrOfFirmwareBlocks = m_hw->bl_getNrOfFirmwareBlocks(); + + for (uint16_t blockNr = 0; blockNr <= nrOfFirmwareBlocks; ++blockNr) { + m_hw->bl_blockAutoLoad(blockNr); + + int sleepTime = 0; + while (1) { + if (sleepTime > 1500) { + m_hw->bl_stopBL(); + return false; + } + + int8_t const r = m_hw->bl_blockAutoResponse(); + + // after every "bl_blockAutoLoad()" call this until response + // retval 0: wait 1: OK, blk was sent 2: OK, transfer complete + // 3: error despite repeating, cancel. probably bin file corrupted + // Max duration: 3x no response from BL = 900ms + + switch(r) { + case 1: + /* fall through */ + case 2: + sleepTime = 0; + break; + case 0: { + QThread::msleep(100); + sleepTime += 100; + } break; + case 3: + m_hw->bl_stopBL(); + return false; + default: + m_hw->bl_stopBL(); + return false; // unknown error code + } } - QThread::sleep(1); + + m_hw->bl_stopBL(); } - cnt = 0; - while (++cnt < cntLimit && - m_worker->mainWindow()->updateStep() != UpdateDcEvent::UpdateStep::BL_IS_UP) { - // wait until all bl_startBL() are done - QThread::msleep(200); - } - - if (cnt == cntLimit) { - // really not up - Utils::printCriticalErrorMsg("BL_IS_UP EVENT NOT RECEIVED AFTER 20 SECS"); - stopBootloader(); // try to stop bootloader whichhas been already started - return false; - } - - if (m_worker->mainWindow()->updateStep() == UpdateDcEvent::UpdateStep::BL_IS_UP) { - // bootloader MUST be running to download device-controller -#if 0 - if (!downloadBinaryToDC(bFile)) { - Utils::printCriticalErrorMsg( - QString("UPDATING DC: ") + bFile + " ...DOWNLOAD FAILED"); - } -#endif - - } else { - Utils::printCriticalErrorMsg( - QString("UPDATING DC: ") + bFile + " BOOT LOADER NOT RUNNING -> NO DOWNLOAD (" - + QThread::currentThread()->objectName() + ")"); - return false; - } - - // do this unconditionally, even if bootloader is not running at all -> - // the controller possibly tells us nonsense. - if (!stopBootloader()) { - Utils::printCriticalErrorMsg( - QString("UPDATING DC: ") + bFile + " BOOT LOADER STILL RUNNING (" - + QThread::currentThread()->objectName() + ")"); - return false; - } - - Utils::printInfoMsg(QString("UPDATING DC: ") + bFile + " ...OK"); return true; } @@ -610,10 +347,6 @@ bool Update::downloadJson(enum FileTypeJson type, int templateIdx, QString jsFileToSendToDC) const { - qDebug() << "updating json-file:" << jsFileToSendToDC << "..."; - qDebug() << " template-index:" << templateIdx; - qDebug() << " json-type:" << jsonType(type); - m_hw->dc_autoRequest(true); // downloading Json needs the AutoEmission flag qDebug() << "SET AUTO-REQUEST=TRUE"; QThread::sleep(1); // make sure the auto-request flag is acknowledged @@ -623,7 +356,7 @@ bool Update::downloadJson(enum FileTypeJson type, while ((ready = m_hw->sys_ready4sending()) == false) { QThread::msleep(200); if (--nTry <= 0) { - qCritical() << "SYS NOT READY FOR SENDING AFTER 5 SECONDS"; + Utils::printCriticalErrorMsg("SYS NOT READY FOR SENDING AFTER 5 SECONDS"); break; } } @@ -636,22 +369,46 @@ bool Update::downloadJson(enum FileTypeJson type, if (file.open(QIODevice::ReadOnly)) { if (fi.size() <= 800) { QByteArray ba = file.readAll(); + // kindOfFile: 1=config, 2=device, 3=cash, 4=serial, 5=time, 6=printer + // nrOfTemplate=1...32 if kindOfFile==6 + // content = content of the Json file, max 800byte ascii signs if (m_hw->sys_sendJsonFileToDc((uint8_t)(type), templateIdx, (uint8_t *)ba.data())) { - QThread::sleep(1); - qDebug() << "SENT" << jsFileToSendToDC; + + m_hw->dc_autoRequest(true); + QThread::msleep(500); + + // testing + m_hw->request_ReadbackMachineID(); + QThread::msleep(500); + + uint8_t data[64]; + memset(data, 0x00, sizeof(data)); + uint8_t length = 0; + + m_hw->readback_machineIDdata(&length, data); + + QThread::msleep(500); + + QByteArray ba((const char*)data, length); + + qCritical() << length << "MACHINE ID =" << ba.toHex(':'); + ret = true; } } else { - qCritical() << "SIZE OF" << jsFileToSendToDC - << "TOO BIG (" << fi.size() << "BYTES)"; + Utils::printCriticalErrorMsg( + QString("SIZE OF %1 TOO BIG (%2 BYTES)") + .arg(jsFileToSendToDC).arg(fi.size())); } } else { - qCritical() << "CANNOT OPEN" << jsFileToSendToDC << "FOR READING"; + Utils::printCriticalErrorMsg( + QString("CAN NOT OPEN ") + jsFileToSendToDC + " FOR READING"); } } else { - qCritical() << jsFileToSendToDC << "DOES NOT EXIST"; + Utils::printCriticalErrorMsg( + QString(jsFileToSendToDC) + " DOES NOT EXIST"); } } @@ -738,112 +495,56 @@ QStringList Update::getDcSoftAndHardWareVersion() { } bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) { - bool serialOpened = false; - - QString const &parentName = Utils::getParentName(); - - Utils::printInfoMsg( - QString("PARENT OF ATB-UPDATE-TOOL (ppid=%1) ").arg(getppid()) + parentName); - - if (parentName == "ATBQT" || parentName == "systemd") { - // the tool was not called during 'service' ot during an automatic - // update procedure. and it was called explicitly with libCAmaster.so - if (m_pluginName.contains("master", Qt::CaseInsensitive)) { - Utils::printCriticalErrorMsg(parentName - + " IS MASTER, BUT ATB-UPDATE-TOOL CALLED WITH libCAmaster.so"); - return false; - } - Utils::printInfoMsg( - QString("ATB-UPDATE-TOOL STARTED AS SLAVE OF ") + parentName); - } else - if (Utils::isATBQTRunning()) { // manual testing - if (m_pluginName.contains("master", Qt::CaseInsensitive)) { - Utils::printCriticalErrorMsg( - "ATBQT IS MASTER, BUT ATB-UPDATE-TOOL CALLED WITH libCAmaster.so"); - return false; - } - Utils::printInfoMsg( - "ATB-UPDATE-TOOL STARTED AS SLAVE-SIBLING OF ATBQT-MASTER"); - } else { - if (m_pluginName.contains("slave", Qt::CaseInsensitive)) { - Utils::printCriticalErrorMsg( - "ATB-UPDATE-TOOL CALLED WITH libCAslave.so ALTHOUGH MASTER"); - return false; - } - Utils::printInfoMsg("ATB-UPDATE-TOOL STARTED AS MASTER"); - - if ((serialOpened = openSerial(baudrateMap.value(m_baudrate), - m_baudrate, - m_serialInterface)) == false) { - Utils::printCriticalErrorMsg( - QString("CANNOT OPEN ") - + m_serialInterface - + "( BAUDRATE=" + m_baudrate + ")"); - return false; - } - - m_hw->dc_autoRequest(false); - - Utils::printInfoMsg( - QString("SERIAL OPEN ") + m_serialInterface - + " (BAUDRATE=" + m_baudrate + ")"); + if (m_sys_areDCdataValid == false) { + qCritical() << "ERROR!!! DC DATA NOT VALID -> CA-MASTER-PLUGIN NOT CONNECTED"; + return false; } bool res = false; QList::const_iterator it; for (it = filesToWorkOn.cbegin(); it != filesToWorkOn.cend(); ++it) { m_worker->startProgressLoop(); - QString fToWorkOn = (*it).trimmed(); - fToWorkOn = QDir::cleanPath(m_customerRepository + QDir::separator() + fToWorkOn); - + QString const &fToWorkOn = QDir::cleanPath(m_customerRepository + QDir::separator() + it->trimmed()); static const QRegularExpression version("^.*dc2c[.][0-9]{1,2}[.][0-9]{1,2}[.]bin.*$"); if (fToWorkOn.contains(version)) { - Utils::printInfoMsg("DO-UPDATE FILE-TO-WORK-ON " + fToWorkOn); + bool updateBinaryRes = true; - QFile fn(fToWorkOn); - QFileInfo finfo(fn); - if (!fn.exists()) { // check for broken link - Utils::printCriticalErrorMsg("DO-UPDATE FILE-TO-WORK-ON " - + fToWorkOn + " DOES NOT EXIST"); - res = false; - } else { - bool updateBinaryRes = true; + // CONSOLE() - qInfo() << "DOWNLOADING" << finfo.completeBaseName() << "TO DC"; -#if UPDATE_DC == 1 - m_hw->dc_autoRequest(false);// default: turn auto-request setting off - QThread::sleep(1); // wait to be sure that there are no more - // commands sent to dc-hardware - qInfo() << "SET AUTO-REQUEST=FALSE"; + m_hw->dc_autoRequest(false);// default: turn auto-request setting off + QThread::sleep(1); // wait to be sure that there are no more + // commands sent to dc-hardware - if ((updateBinaryRes = updateBinary(fToWorkOn.toStdString().c_str())) == true) { - qCritical() << "downloaded binary" << fToWorkOn; - ++displayIndex; - emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(2, ' ') + QString(")") - + QString(" Update ") + QFileInfo(fToWorkOn).fileName(), - Worker::UPDATE_STEP_DONE); - } + if ((updateBinaryRes = updateBinary(fToWorkOn)) == true) { - m_hw->dc_autoRequest(true); // turn auto-request setting on - qInfo() << "SET AUTO-REQUEST=TRUE"; + // qCritical() << "downloaded binary" << fToWorkOn; - QStringList const &versions = Update::getDcSoftAndHardWareVersion(); - if (versions.size() >= 2) { - if (updateBinaryRes == true) { - qInfo() << "dc-hardware-version (UPDATED)" << versions[0]; - qInfo() << "dc-firmware-version (UPDATED)" << versions[1]; - } else { - qInfo() << "dc-hardware-version (NOT UPDATED)" << versions[0]; - qInfo() << "dc-firmware-version (NOT UPDATED)" << versions[1]; - } - } -#endif - res = updateBinaryRes; + ++displayIndex; + emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(2, ' ') + QString(")") + + QString(" Update ") + QFileInfo(fToWorkOn).fileName(), + Worker::UPDATE_STEP_DONE); } + + m_hw->dc_autoRequest(true); // turn auto-request setting on + + // qInfo() << "SET AUTO-REQUEST=TRUE"; + + QStringList const &versions = Update::getDcSoftAndHardWareVersion(); + if (versions.size() >= 2) { + if (updateBinaryRes == true) { + qInfo() << "dc-hardware-version (UPDATED)" << versions[0]; + qInfo() << "dc-firmware-version (UPDATED)" << versions[1]; + } else { + qInfo() << "dc-hardware-version (NOT UPDATED)" << versions[0]; + qInfo() << "dc-firmware-version (NOT UPDATED)" << versions[1]; + } + } + + res = updateBinaryRes; + } else if (fToWorkOn.contains("DC2C_print", Qt::CaseInsensitive) && fToWorkOn.endsWith(".json", Qt::CaseInsensitive)) { res = true; -#if UPDATE_PRINTER_TEMPLATES == 1 int i = fToWorkOn.indexOf("DC2C_print", Qt::CaseInsensitive); int const templateIdx = fToWorkOn.mid(i).midRef(10, 2).toInt(); if ((templateIdx < 1) || (templateIdx > 32)) { @@ -851,68 +552,60 @@ bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) { res = false; } else { if ((res = updatePrinterTemplate(templateIdx, fToWorkOn))) { - qInfo() << "downloaded printer template"<< fToWorkOn; + Utils::printInfoMsg( + QString("DOWNLOADED PRINTER TEMPLATE %1 WITH INDEX=%2") + .arg(fToWorkOn) + .arg(templateIdx)); ++displayIndex; - emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(2, ' ') + QString(")") + emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(3, ' ') + QString(")") + QString(" Update ") + QFileInfo(fToWorkOn).fileName(), Worker::UPDATE_STEP_DONE); } } -#endif } else if (fToWorkOn.contains("DC2C_cash", Qt::CaseInsensitive) && fToWorkOn.endsWith(".json", Qt::CaseInsensitive)) { res = true; -#if UPDATE_CASH_TEMPLATE == 1 if ((res = updateCashConf(fToWorkOn))) { - qInfo() << "downloaded cash template"<< fToWorkOn; + Utils::printInfoMsg(QString("DOWNLOADED CASH TEMPLATE %1").arg(fToWorkOn)); ++displayIndex; - emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(2, ' ') + QString(")") + emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(3, ' ') + QString(")") + QString(" Update ") + QFileInfo(fToWorkOn).fileName(), Worker::UPDATE_STEP_DONE); } -#endif } else if (fToWorkOn.contains("DC2C_conf", Qt::CaseInsensitive) && fToWorkOn.endsWith(".json", Qt::CaseInsensitive)) { res = true; -#if UPDATE_CONF_TEMPLATE == 1 if ((res= updateConfig(fToWorkOn))) { - qInfo() << "downloaded config template"<< fToWorkOn; + Utils::printInfoMsg(QString("DOWNLOADED CONFIG TEMPLATE %1").arg(fToWorkOn)); ++displayIndex; - emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(2, ' ') + QString(")") + emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(3, ' ') + QString(")") + QString(" Update ") + QFileInfo(fToWorkOn).fileName(), Worker::UPDATE_STEP_DONE); } -#endif } else if (fToWorkOn.contains("DC2C_device", Qt::CaseInsensitive) && fToWorkOn.endsWith(".json", Qt::CaseInsensitive)) { res = true; -#if UPDATE_DEVICE_TEMPLATE == 1 if ((res = updateDeviceConf(fToWorkOn))) { - qInfo() << "downloaded device template"<< fToWorkOn; + Utils::printInfoMsg(QString("DOWNLOADED DEVICE TEMPLATE %1").arg(fToWorkOn)); ++displayIndex; - emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(2, ' ') + QString(")") + emit m_worker->appendText(QString("\n(") + QString("%1").arg(displayIndex).rightJustified(3, ' ') + QString(")") + QString(" Update ") + QFileInfo(fToWorkOn).fileName(), Worker::UPDATE_STEP_DONE); } -#endif } else { qCritical() << "UNKNOWN JSON FILE NAME" << fToWorkOn; res = false; } - m_worker->stopProgressLoop(); - m_worker->setProgress(100); + // m_worker->stopProgressLoop(); + // m_worker->setProgress(100); if (res == false) { break; } } // for (it = openLines.cbegin(); it != openLines.end(); ++it) { - //m_hw->dc_autoRequest(true); // ALWAYS turn autoRequest ON - //qDebug() << "SET AUTO-REQUEST=TRUE"; - - if (serialOpened) { - m_hw->dc_closeSerial(); - } + m_hw->dc_autoRequest(true); // ALWAYS turn autoRequest ON + qDebug() << "SET AUTO-REQUEST=TRUE"; return res; } diff --git a/update.h b/update.h index f56cdc7..cb1d01a 100644 --- a/update.h +++ b/update.h @@ -21,8 +21,8 @@ class Worker; class Update : public QObject { Q_OBJECT - hwinf *m_hw; - Worker *m_worker; + hwinf *m_hw = nullptr; + Worker *m_worker = nullptr; char const *m_serialInterface; char const *m_baudrate; QString m_customerRepository; @@ -32,6 +32,7 @@ class Update : public QObject { QString m_workingDir; bool m_maintenanceMode; bool m_dryRun; + bool m_sys_areDCdataValid; static QPluginLoader pluginLoader; @@ -44,11 +45,11 @@ public: static QStringList split(QString line, QChar sep = ','); - explicit Update(hwinf *hw, - Worker *worker, + explicit Update(Worker *worker, QString customerRepository, QString customerNrStr, QString branchName, + QString plugInDir, QString pluginName, QString workingDir, bool dryRun = false, @@ -58,6 +59,9 @@ public: virtual ~Update() override; bool doUpdate(int &displayIndex, QStringList const &linesToWorkOn); + hwinf *hw() { return m_hw; } + hwinf const *hw() const { return m_hw; } + //QString customerId() { return m_customerId; } //QString const customerId() const { return m_customerId; } @@ -69,23 +73,14 @@ public: private: static QString jsonType(enum FileTypeJson type); - - DownloadResult sendStatus(int ret) const; - DownloadResult sendNextAddress(int bNum) const; - DownloadResult sendNextDataBlock(QByteArray const &b, int bNum) const; - DownloadResult dc_downloadBinary(QByteArray const &binary) const; - - bool startBootloader() const; - bool stopBootloader() const; bool openSerial(int br, QString baudrate, QString comPort) const; void closeSerial() const; bool isSerialOpen() const; bool resetDeviceController() const; QByteArray loadBinaryDCFile(QString filename) const; bool downloadBinaryToDC(QString const &bFile) const; - bool updateDC(QString bFile) const; bool updatePrinterTemplate(int templateIdx, QString fname) const; - bool updateBinary(char const *fileToSendToDC); + bool updateBinary(QString const &fileToSendToDC); bool updateConfig(QString jsFileToSendToDC); bool updateCashConf(QString jsFileToSendToDC); bool updateDeviceConf(QString jsFileToSendToDC); diff --git a/utils.cpp b/utils.cpp index 284c95e..870af4e 100644 --- a/utils.cpp +++ b/utils.cpp @@ -46,17 +46,90 @@ QString Utils::zoneName(quint8 i) { return "N/A"; } -void Utils::printCriticalErrorMsg(QString const &errorMsg) { - qCritical() << QString(80, '!'); +void Utils::printCriticalErrorMsg(QString const &errorMsg, bool upper, bool lower) { + if (upper) qCritical() << QString(80, 'E'); + qCritical() << errorMsg; - qCritical() << QString(80, '!'); + + if (lower) qCritical() << QString(80, 'E'); } -void Utils::printInfoMsg(QString const &infoMsg) { - qCritical() << QString(80, '='); - qCritical() << infoMsg; - qCritical() << QString(80, '='); +void Utils::printCriticalErrorMsg(QStringList const &errorMsg) { + qCritical() << QString(80, 'E'); + for (int i = 0; i < errorMsg.size(); ++i) { + qCritical() << errorMsg.at(i); + } + qCritical() << QString(80, 'E'); +} +void Utils::printUpdateStatusMsg(QDebug debug, QStringList const &updateMsg) { + //if (updateMsg.size() > 1) { + // qCritical() << QString(80, 'U'); + //} + + Q_UNUSED(debug); + + for (int i = 0; i < updateMsg.size(); ++i) { + qInfo() << updateMsg.at(i); + } + + //if (updateMsg.size() > 1) { + // qCritical() << QString(80, 'U'); + //} +} + +void Utils::printUpdateStatusMsg(QStringList const &updateMsg) { + //if (updateMsg.size() > 1) { + // qCritical() << QString(80, 'U'); + //} + + for (int i = 0; i < updateMsg.size(); ++i) { + qCritical() << updateMsg.at(i); + } + + //if (updateMsg.size() > 1) { + // qCritical() << QString(80, 'U'); + //} +} + +void Utils::printUpdateStatusMsg(QString const &updateMsg, bool upper, bool lower) { + if (upper) qCritical() << QString(80, 'U'); + + qCritical() << updateMsg; + + if (lower) qCritical() << QString(80, 'U'); +} + +void Utils::printUpdateStatusMsg(QDebug debug, QString const &updateMsg, + bool upper, bool lower) { + if (upper) debug << QString(80, 'U'); + + qInfo() << updateMsg; + + if (lower) debug << QString(80, 'U'); + +} + +void Utils::printInfoMsg(QString const &infoMsg, bool upper, bool lower) { + if (upper) qCritical() << QString(80, 'I'); + + qCritical() << infoMsg; + + if (lower) qCritical() << QString(80, 'I'); +} + +void Utils::printInfoMsg(QStringList const &infoMsg) { + //if (infoMsg.size() > 1) { + // qCritical() << QString(80, 'I'); + //} + + for (int i = 0; i < infoMsg.size(); ++i) { + qCritical() << infoMsg.at(i); + } + + //if (infoMsg.size() > 1) { + // qCritical() << QString(80, 'I'); + //} } void Utils::printLineEditInfo(QStringList const &lines) { diff --git a/utils.h b/utils.h index 6dd7dd7..1e77a17 100644 --- a/utils.h +++ b/utils.h @@ -8,12 +8,19 @@ #include #include #include +#include namespace Utils { int read1stLineOfFile(QString fileName); QString zoneName(quint8 i); - void printCriticalErrorMsg(QString const &errorMsg); - void printInfoMsg(QString const &infoMsg); + void printCriticalErrorMsg(QString const &errorMsg, bool upper=false, bool lower=false); + void printCriticalErrorMsg(QStringList const &errorMsg); + void printInfoMsg(QString const &infoMsg, bool upper=false, bool lower=false); + void printInfoMsg(QStringList const &infoMsg); + void printUpdateStatusMsg(QDebug debug, QStringList const &updateMsg); + void printUpdateStatusMsg(QStringList const &updateMsg); + void printUpdateStatusMsg(QString const &updateMsg, bool upper=false, bool lower=false); + void printUpdateStatusMsg(QDebug debug, QString const &updateMsg, bool upper=false, bool lower=false); void printLineEditInfo(QStringList const &lines); QString getTariffLoadTime(QString fileName); QString rstrip(QString const &str); diff --git a/worker.cpp b/worker.cpp index c787c05..c8dd4ce 100644 --- a/worker.cpp +++ b/worker.cpp @@ -16,8 +16,7 @@ #include #include #include - -#include +#include #include "message_handler.h" #include "plugins/interfaces.h" @@ -26,31 +25,116 @@ #include "mainwindow.h" #include "utils.h" -QString const Worker::UPDATE_STEP_OK(" [ ok]"); -QString const Worker::UPDATE_STEP_DONE(" [done]"); -QString const Worker::UPDATE_STEP_FAIL(" [FAIL]"); +QString const Worker::UPDATE_STEP_OK ( " [ ok]"); +QString const Worker::UPDATE_STEP_DONE ( " [done]"); +QString const Worker::UPDATE_STEP_WRONG ( "[WRONG]"); +QString const Worker::UPDATE_STEP_FAIL ( " [FAIL]"); QString const Worker::UPDATE_STEP_SUCCESS(" [SUCCESS]"); +using UPDATE_STEP = Worker::UPDATE_STEP; +const QMap Worker::smap ( + std::initializer_list>{ +#define INSERT_ELEMENT(p) std::pair(p, #p) + INSERT_ELEMENT(UPDATE_STEP::STARTED), + INSERT_ELEMENT(UPDATE_STEP::CHECK_REPOSITORY), + INSERT_ELEMENT(UPDATE_STEP::CHECK_REPOSITORY_SUCCESS), + INSERT_ELEMENT(UPDATE_STEP::CHECK_REPOSITORY_FAILURE), + INSERT_ELEMENT(UPDATE_STEP::CHECK_SANITY), + INSERT_ELEMENT(UPDATE_STEP::CHECK_SANITY_SUCCESS), + INSERT_ELEMENT(UPDATE_STEP::CHECK_SANITY_FAILURE), + INSERT_ELEMENT(UPDATE_STEP::REPOSITORY_RECOVERED_SUCCESS), + INSERT_ELEMENT(UPDATE_STEP::REPOSITORY_RECOVERED_FAILURE), + INSERT_ELEMENT(UPDATE_STEP::CLONE_REPOSITORY), + INSERT_ELEMENT(UPDATE_STEP::CLONE_REPOSITORY_SUCCESS), + INSERT_ELEMENT(UPDATE_STEP::CLONE_REPOSITORY_FAILURE), + INSERT_ELEMENT(UPDATE_STEP::CHECKOUT_REPOSITORY), + INSERT_ELEMENT(UPDATE_STEP::CHECKOUT_REPOSITORY_SUCCESS), + INSERT_ELEMENT(UPDATE_STEP::CHECKOUT_REPOSITORY_FAILURE), + INSERT_ELEMENT(UPDATE_STEP::CHECK_ISMAS_TRIGGER), + INSERT_ELEMENT(UPDATE_STEP::CHECK_ISMAS_TRIGGER_WRONG_VALUE), + INSERT_ELEMENT(UPDATE_STEP::CHECK_ISMAS_TRIGGER_SUCCESS), + INSERT_ELEMENT(UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE), + INSERT_ELEMENT(UPDATE_STEP::INITIAL_CLONE_WITHOUT_ACTIVE_ISMAS_TRIGGER), + INSERT_ELEMENT(UPDATE_STEP::INITIAL_CLONE_WITH_ACTIVE_ISMAS_TRIGGER), + INSERT_ELEMENT(UPDATE_STEP::CHECKOUT_BRANCH), + INSERT_ELEMENT(UPDATE_STEP::CHECKOUT_BRANCH_SUCCESS), + INSERT_ELEMENT(UPDATE_STEP::CHECKOUT_BRANCH_FAILURE), + INSERT_ELEMENT(UPDATE_STEP::UPDATE_REPOSITORY), + INSERT_ELEMENT(UPDATE_STEP::UPDATE_REPOSITORY_SUCCESS), + INSERT_ELEMENT(UPDATE_STEP::UPDATE_REPOSITORY_FAILURE), + INSERT_ELEMENT(UPDATE_STEP::CHECK_FOR_REPOSITORY_CHANGES), + INSERT_ELEMENT(UPDATE_STEP::CHECK_FOR_REPOSITORY_CHANGES_SUCCESS), + INSERT_ELEMENT(UPDATE_STEP::CHECK_FOR_REPOSITORY_CHANGES_FAILURE), + INSERT_ELEMENT(UPDATE_STEP::FILES_TO_UPDATE), + INSERT_ELEMENT(UPDATE_STEP::FILES_TO_DOWNLOAD), + INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMANDS), + INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMAND_1), + INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMAND_2), + INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMAND_3), + INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMAND_4), + INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMAND_5), + INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMAND_6), + INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMAND_7), + INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMAND_8), + INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMAND_9), + INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMAND_LAST), + INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMAND_SUCCESS), + INSERT_ELEMENT(UPDATE_STEP::EXEC_OPKG_COMMAND_FAILURE), + INSERT_ELEMENT(UPDATE_STEP::DOWNLOAD_CONFIG_FILE), + INSERT_ELEMENT(UPDATE_STEP::DOWNLOAD_CONFIG_FILE_SUCCESS), + INSERT_ELEMENT(UPDATE_STEP::DOWNLOAD_CONFIG_FILE_FAILURE), + INSERT_ELEMENT(UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER), + INSERT_ELEMENT(UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER_SUCCESS), + INSERT_ELEMENT(UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER_FAILURE), + INSERT_ELEMENT(UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE), + INSERT_ELEMENT(UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE_SUCCESS), + INSERT_ELEMENT(UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE_FAILURE), + INSERT_ELEMENT(UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY), + INSERT_ELEMENT(UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_SUCCESS), + INSERT_ELEMENT(UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_FAILURE), + INSERT_ELEMENT(UPDATE_STEP::SAVE_LOGS), + INSERT_ELEMENT(UPDATE_STEP::SAVE_LOGS_SUCCESS), + INSERT_ELEMENT(UPDATE_STEP::SAVE_LOGS_FAILURE), + INSERT_ELEMENT(UPDATE_STEP::SEND_LAST_VERSION), + INSERT_ELEMENT(UPDATE_STEP::UPDATE_SUCCEEDED), + INSERT_ELEMENT(UPDATE_STEP::UPDATE_FAILED), + INSERT_ELEMENT(UPDATE_STEP::UPDATE_ACTIVATED), + INSERT_ELEMENT(UPDATE_STEP::FINISHED), + INSERT_ELEMENT(UPDATE_STEP::DEBUG), + INSERT_ELEMENT(UPDATE_STEP::ERROR) +#undef INSERT_ELEMENT +}); + +Worker *Worker::instance = nullptr; + Worker::Worker(int customerNr, int machineNr, int zoneNr, + QString repositoryUrl, QString branchName, + QString pluginDir, QString pluginName, QString workingDirectory, + bool noUpdatePsaHardware, + bool alwaysDownloadConfig, + bool alwaysDownloadDC, bool dryRun, QObject *parent, char const *serialInterface, char const *baudrate) - : m_workerThread("workerThread") - , m_customerNr(customerNr) + : m_customerNr(customerNr) , m_customerNrStr(QString("customer_") + QString::number(m_customerNr).rightJustified(3, '0')) , m_machineNr(machineNr) , m_zoneNr(zoneNr) + , m_pluginDir(pluginDir) , m_pluginName(pluginName) , m_workingDirectory(workingDirectory) , m_branchName(branchName) - , m_customerRepositoryPath(QString("https://git.mimbach49.de/GerhardHoffmann/%1.git").arg(m_customerNrStr)) + , m_customerRepositoryPath(QString("%1/%2.git").arg(repositoryUrl).arg(m_customerNrStr)) , m_customerRepository(QDir::cleanPath(m_workingDirectory + QDir::separator() + m_customerNrStr)) + , m_noUpdatePsaHardware(noUpdatePsaHardware) + , m_alwaysDownloadConfig(alwaysDownloadConfig) + , m_alwaysDownloadDC(alwaysDownloadDC) , m_dryRun(dryRun) , m_parent(parent) , m_serialInterface(serialInterface) @@ -58,6 +142,7 @@ Worker::Worker(int customerNr, , m_gc(m_customerNrStr, m_customerRepository, m_workingDirectory, m_branchName, this) , m_osVersion(getOsVersion()) , m_atbqtVersion(getATBQTVersion()) + , m_atbUpdateToolVersion(getATBUpdateToolVersion()) , m_cpuSerial(getCPUSerial()) , m_pluginVersionATBDeciceController(getPluginVersion("/opt/app/ATBAPP/plugins/libATBDeviceControllerPlugin.so")) , m_pluginVersionIngenicoISelf(getPluginVersion("/opt/app/ATBAPP/plugins/libIngenicoISelf_CCPlugin.so")) @@ -70,439 +155,360 @@ Worker::Worker(int customerNr, , m_waitForNewUpdates(this) , m_filesToUpdate() , m_updateProcessRunning(true) - , m_returnCode(0) - , m_progressValue(0) + , m_mainWindow(nullptr) /* contains plugin */ //, m_withoutIsmasDirectPort(true) /* useful for testing */ { , m_withoutIsmasDirectPort(false) /* useful for testing */ { + // TODO: turn object into singleton + instance = this; + this->setObjectName("worker-object"); QDir::setCurrent(m_workingDirectory); - // restart apism to make sure it is running ? - // Command c("systemctl restart apism"); - // if (c.execute("/tmp")) { - // QThread::sleep(10); // give APISM some time to reconnect - // } - - if (std::optional v = getApismVersion()) { - m_apismVersion = v.value(); - } - - qInfo() << "CURRENT TIME ..............." << QDateTime::currentDateTime().toString(Qt::ISODate); - qInfo() << "OS VERSION ................." << m_osVersion; - qInfo() << "ATBQT VERSION .............." << m_atbqtVersion; - qInfo() << "CPU SERIAL ................." << m_cpuSerial; - qInfo() << "CUSTOMER_NR ................" << m_customerNr; - qInfo() << "CUSTOMER_NR_STR ............" << m_customerNrStr; - qInfo() << "CUSTOMER_REPOSITORY_PATH ..." << m_customerRepositoryPath; - qInfo() << "CUSTOMER_REPOSITORY ........" << m_customerRepository; - qInfo() << "MACHINE_NR ................." << m_machineNr; - qInfo() << "ZONE_NR ...................." << m_zoneNr; - qInfo() << "BRANCH_NAME ................" << m_branchName; - qInfo() << "PLUGIN_NAME ................" << m_pluginName; - qInfo() << "WORKING_DIRECTORY .........." << m_workingDirectory; - qInfo() << "APISM VERSION .............." << m_apismVersion; - - this->moveToThread(&m_workerThread); - m_workerThread.start(); - - int cnt = 0; - while (!m_workerThread.isRunning()) { - if (++cnt > 5) { - Utils::printCriticalErrorMsg("starting worker thread FAILED"); - return; - } - QThread::sleep(1); - } + m_apismVersion = getAPISMYoctoVersion(); } Worker::~Worker() { - int cnt = 0; - m_workerThread.quit(); - while (!m_workerThread.isFinished()) { - if (!m_workerThread.wait(1000)) { - if (++cnt > 5) { - Utils::printCriticalErrorMsg("stopping worker thread FAILED"); - return; - } - } +} + +void Worker::displayProgressInMainWindow(int progress) { + if (m_mainWindow) { + QApplication::postEvent(m_mainWindow, + new ProgressEvent(this, progress)); } } void Worker::setProgress(int progress) { - if (m_mainWindow) { - m_progressValue = progress; - QApplication::postEvent(m_mainWindow, new ProgressEvent(this, progress)); - } + m_ismasClient.setProgressInPercent(progress); + displayProgressInMainWindow(progress); } + void Worker::startProgressLoop() { - QApplication::postEvent(m_mainWindow, new ProgressEvent(this, MainWindow::START_PROGRESS_LOOP)); + displayProgressInMainWindow(MainWindow::START_PROGRESS_LOOP); } void Worker::stopProgressLoop() { - QApplication::postEvent(m_mainWindow, new ProgressEvent(this, MainWindow::STOP_PROGRESS_LOOP)); + displayProgressInMainWindow(MainWindow::STOP_PROGRESS_LOOP); } static std::once_flag once; -void Worker::update() { +void Worker::run() { // user should not start the update process several times std::call_once(once, &Worker::privateUpdate, this); } +bool Worker::isRepositoryCorrupted() { + QDir customerRepository(m_customerRepository); + if (customerRepository.exists()) { + QDir customerRepositoryGit(QDir::cleanPath(m_customerRepository + QDir::separator() + ".git/")); + if (!m_gc.gitFsck()) { + // should never happen + Utils::printCriticalErrorMsg("CORRUPTED CUSTOMER REPOSITORY: GIT_FSCK FAILED"); + return true; + } + // .git-directory inside git-repository does not exist, which means the + // git-repository is corrupted -> remove it and start from scratch + if (!customerRepositoryGit.exists()) { + // should never happen + Utils::printCriticalErrorMsg("CORRUPTED CUSTOMER REPOSITORY .GIT DOES NOT EXIST"); + return true; + } + } + return false; +} + +bool Worker::repairCorruptedRepository() { + QDir customerRepository(m_customerRepository); + if (!customerRepository.removeRecursively()) { + + Utils::printCriticalErrorMsg("ERROR REMOVING CORR. CUST-REPOSITORY"); + + //m_updateStatus = UpdateStatus(UPDATE_STATUS::REMOVE_GIT_REPOSITORY_FAILED, + // QString("REMOVAL OF GIT-REPOSITORY %1 FAILED").arg(m_customerRepository)); + //IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, + // QString("#M=APISM#C=CMD_EVENT#J=") + + // m_ismasClient.sanityCheckFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, + // m_updateStatus.m_statusDescription)); + //emit showErrorMessage("apism sanity check", m_updateStatus.m_statusDescription); + + return false; + } + return true; +} + void Worker::privateUpdate() { if (!m_mainWindow) { Utils::printCriticalErrorMsg("m_mainWindow NOT SET"); return; } - m_updateProcessRunning = true; - bool sentIsmasLastVersionNotification = false; + QString func(__PRETTY_FUNCTION__); - emit disableExit(); + GUI() << (ISMAS() << (CONSOLE() << UPDATE_STEP::STARTED)); + + QScopedPointer upr(new UpdateProcessRunning(this)); - m_returnCode = -1; QDir customerRepository(m_customerRepository); - if (!customerRepository.exists()) { - emit appendText("\nInitializing customer environment ..."); - startProgressLoop(); - if (m_gc.gitCloneAndCheckoutBranch()) { - stopProgressLoop(); - emit replaceLast("Initializing customer environment", UPDATE_STEP_DONE); + QDir customerRepositoryEtc(QDir::cleanPath(m_customerRepository + QDir::separator() + "etc/")); - int progress = (m_mainWindow->progressValue()/10) + 10; - setProgress(progress); + CONSOLE() << UPDATE_STEP::CHECK_SANITY; - m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CLONE_AND_CHECKOUT_SUCCESS, - QString("CLONED AND CHECKED OUT: ") + m_customerRepository); + m_clone = false; + m_repairClone = false; + m_initialClone = false; + // the customer repository is cloned or + // repaired/re-cloned without checking the + // ISMAS-trigger (WAIT-)button. - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.cloneAndCheckoutCustomerRepository( - m_updateStatus.m_statusDescription)); + // Case 1: no existing repository: - setProgress(progress + 10); + // if there was a sane repository + // available, then the trigger-button is + // checked: + // 1: trigger == WAIT: then + // have been activated in ISMAS. - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.updateOfPSASucceeded("")); + bool continueUpdate = true; // check if git-clone command has timed-out, + // resulting in a corrupted git-repository, which + // does not contain an ./etc-directory - setProgress(100); - m_ismasClient.setProgressInPercent(100); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + m_ismasClient.updateOfPSAActivated()); - - m_returnCode = 0; + if (isRepositoryCorrupted()) { // a not-existing repository is not meant + // to be corrupted + CONSOLE() << UPDATE_STEP::CHECK_SANITY_FAILURE; + if ((continueUpdate = repairCorruptedRepository()) == true) { + m_repairClone = true; + CONSOLE() << UPDATE_STEP::REPOSITORY_RECOVERED_SUCCESS; } else { - stopProgressLoop(); - - int progress = (m_mainWindow->progressValue()/10) + 10; - setProgress(progress); - - emit replaceLast("Initializing customer environment", UPDATE_STEP_FAIL); - - m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CLONE_AND_CHECKOUT_FAILURE, - QString("CLONE OR CHECKOUT FAILED: ") + m_customerRepository); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.errorGitClone(100, m_updateStatus.m_statusDescription)); - - m_returnCode = -3; + ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::REPOSITORY_RECOVERED_FAILURE)); + return; } - } else { - m_ismasClient.setProgressInPercent(10); - if (updateTriggerSet()) { - m_ismasClient.setProgressInPercent(20); - if (customerEnvironment()) { - m_ismasClient.setProgressInPercent(30); - if (filesToUpdate()) { - // send message to ISMAS about files which have been - // checked in into git repository - m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CHECK_FILES_TO_UPDATE_SUCCESS, - QString("Files to update: ") + m_filesToUpdate.join(',')); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.updateOfPSAContinues("CHECK-FILES-TO-UPDATE", - m_updateStatus.m_statusDescription)); - m_ismasClient.setProgressInPercent(40); - if (updateFiles(50)) { - m_ismasClient.setProgressInPercent(50); - if (syncCustomerRepositoryAndFS()) { - m_ismasClient.setProgressInPercent(60); - if (sendIsmasLastVersionNotification()) { - m_ismasClient.setProgressInPercent(70); - sentIsmasLastVersionNotification = true; - if (saveLogFile()) { - m_ismasClient.setProgressInPercent(80); + } - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.updateOfPSASucceeded("")); + CONSOLE() << UPDATE_STEP::CHECK_SANITY_SUCCESS; - // mark update as activated -> this resets the WAIT button - m_ismasClient.setProgressInPercent(95); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.updateOfPSAActivated()); - - m_returnCode = 0; - } else { - m_updateStatus = UpdateStatus(UPDATE_STATUS::SAVE_LOG_FILES_FAILED, - QString("Saving log files failed")); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, - "SAVE-LOG-FILES", - m_updateStatus.m_statusDescription)); - m_returnCode = -11; - } - } else { - m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_SEND_LAST_VERSION_FAILED, - QString("Sending ISMAS last version failed")); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, - "ISMAS-SEND-LAST-VERSION", - m_updateStatus.m_statusDescription)); - m_returnCode = -10; - } - } else { - m_updateStatus = UpdateStatus(UPDATE_STATUS::RSYNC_UPDATES_FAILURE, - QString("Syncing files to update failed")); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, - "RSYNC-UPDATE-FILES", - m_updateStatus.m_statusDescription)); - m_returnCode = -9; - } - } else { - m_updateStatus = UpdateStatus(UPDATE_STATUS::PSA_UPDATE_FILES_FAILED, - QString("Updating files failed")); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, - "UPDATE-FILES", - m_updateStatus.m_statusDescription)); - m_returnCode = -8; + if (continueUpdate) { + if ((continueUpdate = customerRepository.exists()) == false) { + m_initialClone = (m_repairClone == false); + GUI() << (CONSOLE() << UPDATE_STEP::CLONE_REPOSITORY); + for (int i = 0; i < 5; ++i) { // try to checkout git repository + setProgress(i); // and switch to branch + if (m_gc.gitCloneAndCheckoutBranch()) { + if (!isRepositoryCorrupted()) { + GUI() << (ISMAS() << (CONSOLE() << UPDATE_STEP::CLONE_REPOSITORY_SUCCESS)); + continueUpdate = true; + m_clone = true; + break; } - } else { - m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_FAILURE, - QString("No files to update")); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, - "FETCH-FILES-TO-UPDATE", - m_updateStatus.m_statusDescription)); - m_returnCode = -7; } - } else { - m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CHECKOUT_BRANCH_FAILURE, - QString("Configuring customer environment failed")); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, - "GIT-CHECKOUT-BRANCH", - m_updateStatus.m_statusDescription)); - m_returnCode = -6; + QThread::sleep(1); // maybe git needs more time } + + if (continueUpdate == false) { + GUI() << (ISMAS() << (CONSOLE() << UPDATE_STEP::CLONE_REPOSITORY_FAILURE)); + return; + } + + Q_ASSERT_X(m_clone, (func + QString(":%1").arg(__LINE__)).toStdString().c_str(), "clone failed"); + } else { - m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_UPDATE_TRIGGER_SET_FAILURE, - QString("ISMAS update trigger wrong")); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, - "CHECK-UPDATE-TRIGGER", - m_updateStatus.m_statusDescription)); - m_returnCode = -5; + + Q_ASSERT_X(!m_clone, (func + QString(":%1").arg(__LINE__)).toStdString().c_str(), "m_clone not false"); + Q_ASSERT_X(!m_initialClone, (func + QString(":%1").arg(__LINE__)).toStdString().c_str(), "m_initialClone not false"); + Q_ASSERT_X(!m_repairClone, (func + QString(":%1").arg(__LINE__)).toStdString().c_str(), "m_repairClone not false"); + + CONSOLE() << UPDATE_STEP::CHECK_REPOSITORY; + if (isRepositoryCorrupted()) { + ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::CHECK_REPOSITORY_FAILURE)); + return; + } } } + CONSOLE() << UPDATE_STEP::CHECK_REPOSITORY_SUCCESS; + setProgress(_CHECKOUT_REPOSITORY_SUCCESS); - m_ismasClient.setProgressInPercent(100); - setProgress(100); - if (m_returnCode != 0) { - stopProgressLoop(); - emit appendText(QString("UPDATE "), UPDATE_STEP_FAIL); - - m_updateStatus = UpdateStatus(UPDATE_STATUS::UPDATE_PROCESS_FAILURE, - QString("Update process failed")); - if (std::optional s = m_ismasClient.finalResult(IsmasClient::RESULT_CODE::INSTALL_ERROR, - m_updateStatus.m_statusDescription)) { - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + s.value()); + //////////////////////////////////////////////////////////////////////////// + // + // CHECK UPDATE TRIGGER + // + //////////////////////////////////////////////////////////////////////////// + m_ismasTriggerActive = false; + if ((continueUpdate = updateTriggerSet()) == false) { + if (m_initialClone) { + GUI() << (ISMAS() << (CONSOLE() << UPDATE_STEP::INITIAL_CLONE_WITHOUT_ACTIVE_ISMAS_TRIGGER)); } + return; } else { - emit appendText(QString("UPDATE "), UPDATE_STEP_SUCCESS); - - m_updateStatus = UpdateStatus(UPDATE_STATUS::UPDATE_PROCESS_SUCCESS, - QString("Update process succeeded. Reset WAIT.")); - if (std::optional s = m_ismasClient.finalResult(IsmasClient::RESULT_CODE::SUCCESS, - m_updateStatus.m_statusDescription)) { - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + s.value()); - } + GUI() << (ISMAS() << (CONSOLE() << UPDATE_STEP::INITIAL_CLONE_WITH_ACTIVE_ISMAS_TRIGGER)); } - - if (!sentIsmasLastVersionNotification) { - // try even if the backend is not connected - sendIsmasLastVersionNotification(); + if (m_ismasTriggerActive == false) {// make it explicit again: only if the + // ismas trigger is active ('WAIT'), + // then proceed + return; } + GUI() << (ISMAS() << (CONSOLE() << UPDATE_STEP::CHECK_ISMAS_TRIGGER_SUCCESS)); + setProgress(_CHECK_ISMAS_TRIGGER_SUCCESS); - m_updateProcessRunning = false; - emit enableExit(); - emit restartExitTimer(); + + //////////////////////////////////////////////////////////////////////////// + // + // CHECK-OUT BRANCH + // + //////////////////////////////////////////////////////////////////////////// + if ((continueUpdate = customerEnvironment()) == false) { + return; + } + CONSOLE() << UPDATE_STEP::CHECKOUT_BRANCH_SUCCESS; + setProgress(_CHECKOUT_BRANCH_SUCCESS); + + + //////////////////////////////////////////////////////////////////////////// + // + // COMPUTE CHANGED FILES OF CUSTOMER REPOSITORY + // + //////////////////////////////////////////////////////////////////////////// + if ((continueUpdate = filesToUpdate()) == false) { + return; + } + ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::UPDATE_REPOSITORY_SUCCESS)); + setProgress(_UPDATE_REPOSITORY_SUCCESS); + + + //////////////////////////////////////////////////////////////////////////// + // + // EXECUTE OPKG COMMANDS + // + //////////////////////////////////////////////////////////////////////////// + if ((continueUpdate = execOpkgCommands()) == false) { + return; + } + GUI() << (CONSOLE() << UPDATE_STEP::EXEC_OPKG_COMMAND_SUCCESS); + setProgress(_EXEC_OPKG_COMMAND_SUCCESS); + + + //////////////////////////////////////////////////////////////////////////// + // + // UPDATE THE PSA USING THE CHANGED FILES + // + //////////////////////////////////////////////////////////////////////////// + if ((continueUpdate = downloadFilesToPSAHardware()) == false) { + return; + } + GUI() << (CONSOLE() << UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE_SUCCESS); + setProgress(_DOWNLOAD_FILES_TO_PSA_HARDWARE_SUCCESS); + + + //////////////////////////////////////////////////////////////////////////// + // + // (R)SYNC THE REPOSITORY WITH THE LOCAL FILEYSTEM + // + //////////////////////////////////////////////////////////////////////////// + if ((continueUpdate = syncCustomerRepositoryAndFS()) == false) { + return; + } + ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_SUCCESS)); + setProgress(_SYNC_CUSTOMER_REPOSITORY_SUCCESS); + + + //////////////////////////////////////////////////////////////////////////// + // + // FUTURE: SAVE LOG FILES + // + //////////////////////////////////////////////////////////////////////////// + if ((continueUpdate = saveLogFile()) == false) { + return; + } + // ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::SAVE_LOGS_SUCCESS)); + setProgress(_SAVE_LOGS_SUCCESS); + + + //////////////////////////////////////////////////////////////////////////// + // + // FINAL MESSAGES (PART 1) + // + //////////////////////////////////////////////////////////////////////////// + ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::UPDATE_SUCCEEDED)); + setProgress(_UPDATE_SUCCEEDED); + + ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::UPDATE_ACTIVATED)); + setProgress(_UPDATE_ACTIVATED); + + ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::FINISHED)); + setProgress(_FINISHED); + + + //////////////////////////////////////////////////////////////////////////// + // + // FINAL MESSAGES (PART 2): SEND-LAST-VERSION + // (destructor of struct UpdateProcessRunning) + // + //////////////////////////////////////////////////////////////////////////// } -std::optional Worker::getApismVersion() { - for (int repeat = 0; repeat < 10; ++repeat) { - qInfo() << "REPEAT" << repeat << "In getApismVersion() -> #M=APISM#C=REQ_SELF#J={}"; - std::optional result - = IsmasClient::sendRequestReceiveResponse( - IsmasClient::APISM::DIRECT_PORT, "#M=APISM#C=REQ_SELF#J={}"); - if (result) { - QString msg = result.value(); - qInfo() << "In getApismVersion() -> APISM response" << msg; - QJsonParseError parseError; - QJsonDocument document(QJsonDocument::fromJson(msg.toUtf8(), &parseError)); - if (parseError.error != QJsonParseError::NoError) { - qCritical() << "(1) INVALID JSON MSG: PARSING FAILED (msg=" << msg << "):" - << parseError.error << parseError.errorString(); - m_updateStatus = UpdateStatus(UPDATE_STATUS::JSON_PARSE_FAILURE, - QString("(2) INVALID JSON %1 %2 %3") - .arg(msg) - .arg(parseError.error) - .arg(parseError.errorString())); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.jsonParseFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, - m_updateStatus.m_statusDescription)); - return std::nullopt; - } - if (!document.isObject()) { - qCritical() << "FILE IS NOT A JSON OBJECT!"; - m_updateStatus = UpdateStatus(UPDATE_STATUS::JSON_PARSE_FAILURE, - QString("NOT A JSON-OBJECT %1").arg(msg)); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.jsonParseFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, - m_updateStatus.m_statusDescription)); - return std::nullopt; - } - QJsonObject obj = document.object(); - QStringList keys = obj.keys().filter("CMD_GET_APISMSTATUS_RESPONSE"); - if (keys.size() != 1) { - m_updateStatus = UpdateStatus(UPDATE_STATUS::BACKEND_CHECK_FAILURE, - "CMD_GET_APISMSTATUS_RESPONSE KEY NOT AVAILABLE"); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.sanityCheckFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, - m_updateStatus.m_statusDescription)); - emit showErrorMessage("apism response", m_updateStatus.m_statusDescription); - return std::nullopt; - } else { - QString const key = keys.at(0); - QJsonValue v = obj.value(key); - return v.toObject().value("Version").toString(); - } - } else { - QThread::sleep(1); - } - } - return std::nullopt; -} - -#define CHECK_UPDATE_TRIGGER_SET "Check update trigger ..." - bool Worker::updateTriggerSet() { + // repository is existent and not corrupted. check now if the ISMAS-trigger + // (WAIT-button) is activated even in case of initial checkout + static const QString func = "UPDATE-TRIGGER-SET"; + if (m_withoutIsmasDirectPort) { // useful for testing return true; } - emit appendText("\n" CHECK_UPDATE_TRIGGER_SET); - QString triggerValue(""); - int const startMs = QTime::currentTime().msecsSinceStartOfDay(); + GUI() << (ISMAS() << (CONSOLE() << UPDATE_STEP::CHECK_ISMAS_TRIGGER)); + + QString triggerValue("NOT CHECKED YET"); for (int repeat = 1; repeat <= 100; ++repeat) { - qInfo() << "UPDATE TRIGGER SET -> REPEAT" << repeat; - if (repeat > 1) { + int const startMs = QTime::currentTime().msecsSinceStartOfDay(); int const durationMs = QTime::currentTime().msecsSinceStartOfDay() - startMs; - QString const &msg = QString("elapsed: %1.%2s").arg(durationMs / 1000).arg(durationMs % 1000); - qInfo() << "REPEAT" << msg; - emit showErrorMessage("check update trigger", msg); + QString const &s = QString("elapsed: %1.%2s").arg(durationMs / 1000).arg(durationMs % 1000); + CONSOLE(QStringList(func) << s) << UPDATE_STEP::DEBUG; } else { - emit showErrorMessage("check update trigger", ""); + CONSOLE(QStringList(func) << QString("-> REPEAT=%1").arg(repeat)) << UPDATE_STEP::DEBUG; } if ((repeat % 10) == 0) { - qInfo() << "CHECK UPDATE TRIGGER. RESTART APISM ..."; + CONSOLE(QStringList(func) << "RESTART APISM") << UPDATE_STEP::DEBUG; Command c("systemctl restart apism"); if (c.execute("/tmp")) { QThread::sleep(20); // give APISM some time to reconnect - qInfo() << "CHECK UPDATE TRIGGER. RESTARTING APISM DONE"; + CONSOLE(QStringList(func) << "RESTART APISM DONE") << UPDATE_STEP::DEBUG; } } - startProgressLoop(); if (std::optional result = IsmasClient::sendRequestReceiveResponse( IsmasClient::APISM::DIRECT_PORT, "#M=APISM#C=REQ_ISMASPARAMETER#J={}")) { - stopProgressLoop(); - int progress = (m_mainWindow->progressValue()/10) + 10; - setProgress(progress); - QString msg = result.value(); - - qInfo() << "REPEAT" << repeat << "APISM RESPONSE (" << msg << ")"; + QString const &msg = QString("APISM RESPONSE(%1)=(").arg(repeat) + result.value() + ")"; + CONSOLE(QStringList(func) << msg) << UPDATE_STEP::DEBUG; QJsonParseError parseError; - QJsonDocument document(QJsonDocument::fromJson(msg.toUtf8(), &parseError)); + QJsonDocument document(QJsonDocument::fromJson(result.value().toUtf8(), &parseError)); if (parseError.error != QJsonParseError::NoError) { - qCritical() << "(2) INVALID JSON MSG: PARSING FAILED (msg=" << msg << "):" - << parseError.error << parseError.errorString(); - setProgress(100); - m_updateStatus = UpdateStatus(UPDATE_STATUS::JSON_PARSE_FAILURE, - QString("(2) INVALID JSON %1 %2 %3") - .arg(msg) - .arg(parseError.error) - .arg(parseError.errorString())); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.jsonParseFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, - m_updateStatus.m_statusDescription)); - emit showErrorMessage("check update trigger", - QString("invalid json ") + msg.mid(0, 20)); - emit replaceLast(CHECK_UPDATE_TRIGGER_SET, UPDATE_STEP_FAIL); - return false; + QStringList lst(QString("INVALID JSON MSG: PARSING FAILED (json=%1 error=[%2] str=[%3] offset=[%4])") + .arg(msg) + .arg(parseError.error) + .arg(parseError.errorString()) + .arg(parseError.offset)); + GUI(lst) << (CONSOLE(lst) << UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE); + break; } if (!document.isObject()) { - qCritical() << "FILE IS NOT A JSON OBJECT!"; - setProgress(100); - m_updateStatus = UpdateStatus(UPDATE_STATUS::JSON_PARSE_FAILURE, - QString("NOT A JSON-OBJECT %1").arg(msg)); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.jsonParseFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, - m_updateStatus.m_statusDescription)); - emit showErrorMessage("check update trigger", QString("not a json object") + msg); - emit replaceLast(CHECK_UPDATE_TRIGGER_SET, UPDATE_STEP_FAIL); - return false; + QStringList lst(QString("not a json-object %1").arg(result.value())); + GUI(lst) << (CONSOLE(lst) << UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE); + break; } - progress += 1; - setProgress(progress); QJsonObject obj = document.object(); // always look for an 'error' first if (obj.contains("error")) { - progress += 1; - setProgress(progress); - QString value = obj.value("error").toString(); - emit showErrorMessage("check update trigger", QString("REPEAT %1 error=<").arg(repeat) + value + ">"); - qInfo() << "REPEAT" << repeat << "In updateTriggerSet() error=<" - << value << ">"; + QStringList lst(obj.value("error").toString()); + CONSOLE(QStringList(lst)) << UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE; QThread::sleep(6); continue; } @@ -514,379 +520,333 @@ bool Worker::updateTriggerSet() { if (v.isObject()) { QJsonObject obj = v.toObject(); if (obj.contains("Custom_ID") && obj.contains("Device_ID")) { - QJsonValue const c = obj.value("Custom_ID"); - QJsonValue const m = obj.value("Device_ID"); - int customerNr = c.toInt(-1); - int machineNr = m.toInt(-1); + int const customerNr = obj.value("Custom_ID").toInt(-1); + int const machineNr = obj.value("Device_ID").toInt(-1); if (customerNr != m_customerNr) { - setProgress(100); - m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE, - QString("CUSTOMER-NR (%1) != LOCAL CUSTOMER-NR (%2)") - .arg(customerNr).arg(m_customerNr)); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.sanityCheckFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, - m_updateStatus.m_statusDescription)); - emit showErrorMessage("check update trigger", m_updateStatus.m_statusDescription); - emit replaceLast(CHECK_UPDATE_TRIGGER_SET, UPDATE_STEP_FAIL); - return false; + QStringList lst(QString("CUSTOMER-NR (%1) != LOCAL CUSTOMER-NR (%2)") + .arg(customerNr).arg(m_customerNr)); + GUI(lst) << (CONSOLE(lst) << UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE); + break; } if (machineNr != m_machineNr) { - setProgress(100); - m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE, - QString("MACHINE-NR (%1) != LOCAL MACHINE-NR (%2)") - .arg(machineNr).arg(m_machineNr)); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.sanityCheckFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, - m_updateStatus.m_statusDescription)); - emit showErrorMessage("check update trigger", m_updateStatus.m_statusDescription); - emit replaceLast(CHECK_UPDATE_TRIGGER_SET, UPDATE_STEP_FAIL); - return false; + QStringList lst(QString("MACHINE-NR (%1) != LOCAL MACHINE-NR (%2)") + .arg(machineNr).arg(m_machineNr)); + GUI(lst) << (CONSOLE(lst) << UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE); + break; } - - qInfo() << "MACHINE-AND-CUSTOMER-CHECK" << m_updateStatus.m_statusDescription; - } else { - setProgress(100); - m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE, - "Dev_ID DOES NOT CONTAIN Custom_ID AND/OR Device_ID"); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.sanityCheckFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, - m_updateStatus.m_statusDescription)); - emit showErrorMessage("check update trigger", m_updateStatus.m_statusDescription); - emit replaceLast(CHECK_UPDATE_TRIGGER_SET, UPDATE_STEP_FAIL); - return false; + QStringList lst("Dev_ID DOES NOT CONTAIN Custom_ID AND/OR Device_ID"); + GUI(lst) << (CONSOLE(lst) << UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE); + break; } } else { - setProgress(100); - m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE, - "Dev_ID KEY NOT A JSON-OBJECT"); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.sanityCheckFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, - m_updateStatus.m_statusDescription)); - emit showErrorMessage("check update trigger", m_updateStatus.m_statusDescription); - emit replaceLast(CHECK_UPDATE_TRIGGER_SET, UPDATE_STEP_FAIL); - return false; + QStringList lst("Dev_ID KEY NOT A JSON-OBJECT"); + GUI(lst) << (CONSOLE(lst) << UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE); + break; } } else { - setProgress(100); - m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE, - "Dev_ID KEY NOT AVAILABLE"); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.sanityCheckFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, - m_updateStatus.m_statusDescription)); - emit showErrorMessage("check update trigger", m_updateStatus.m_statusDescription); - emit replaceLast(CHECK_UPDATE_TRIGGER_SET, UPDATE_STEP_FAIL); - return false; + QStringList lst("Dev_ID KEY NOT AVAILABLE"); + GUI(lst) << (CONSOLE(lst) << UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE); + break; } - progress += 1; - setProgress(progress); if (obj.contains("Fileupload")) { QJsonValue v = obj.value("Fileupload"); if (v.isObject()) { obj = v.toObject(); if (obj.contains("TRG")) { - triggerValue = obj.value("TRG").toString(); - - qInfo() << "REPEAT" << repeat - << "In updateTriggerSet() TRG value=<" - << triggerValue << ">"; - - if (triggerValue == "WAIT") { - setProgress(100); - m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_SANITY_CHECK_OK, - QString("MACHINE-NR (%1) AND CUST-NR (%2) OK") - .arg(m_machineNr).arg(m_customerNr)); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.updateOfPSAContinues("MACHINE-AND-CUSTOMER-CHECK", - m_updateStatus.m_statusDescription)); - - m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_UPDATE_TRIGGER_SET, - QString("UPDATE TRIGGER SET. CONTINUE. ")); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.updateTriggerSet(m_updateStatus.m_statusDescription, "")); - - emit replaceLast(CHECK_UPDATE_TRIGGER_SET, UPDATE_STEP_DONE); - return true; + if ((triggerValue = obj.value("TRG").toString()) == "WAIT") { + m_ismasTriggerActive = true; + return m_ismasTriggerActive; } else if (QRegExp("\\s*").exactMatch(triggerValue)) { // check for whitespace - stopProgressLoop(); - int progress = (m_mainWindow->progressValue()/10) + 10; - progress += 1; - setProgress(progress); - emit showErrorMessage("check update trigger", "empty update-trigger"); + QStringList lst("empty update trigger"); + if (m_clone) { + GUI(lst) << (CONSOLE(lst) << UPDATE_STEP::CHECK_ISMAS_TRIGGER_WRONG_VALUE); + // if the customer repository has just been cloned + break; // it is OK the ISMAS trigger might not be 'WAIT' + } else { + GUI(lst) << (CONSOLE(lst) << UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE); + } QThread::sleep(6); continue; } else { // if the download-button once has the wrong value, it will never recover - setProgress(100); - m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE, - QString("TRIGGER-VALUE=<") + triggerValue + "> NOT 'WAIT'"); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.sanityCheckFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, - m_updateStatus.m_statusDescription)); - emit showErrorMessage("check update trigger", m_updateStatus.m_statusDescription); - emit replaceLast(CHECK_UPDATE_TRIGGER_SET, UPDATE_STEP_FAIL); - return false; + if (m_clone) { + GUI() << (CONSOLE() << UPDATE_STEP::CHECK_ISMAS_TRIGGER_WRONG_VALUE); + } else { + QStringList lst(QString("TRIGGER-VALUE=<%1> NOT 'WAIT'").arg(triggerValue)); + GUI(lst) << (CONSOLE(lst) << UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE); + } + break; } } else { - setProgress(100); - m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE, - "TRG KEY NOT AVAILABLE"); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.sanityCheckFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, - m_updateStatus.m_statusDescription)); - emit replaceLast(CHECK_UPDATE_TRIGGER_SET, UPDATE_STEP_FAIL); - emit showErrorMessage("check update trigger", m_updateStatus.m_statusDescription); - return false; + QStringList lst("TRG key not available"); + GUI(lst) << (CONSOLE(lst) << UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE); + break; } } else { - setProgress(100); - m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE, - "Fileupload NOT A JSON-OBJECT"); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.sanityCheckFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, - m_updateStatus.m_statusDescription)); - emit replaceLast(CHECK_UPDATE_TRIGGER_SET, UPDATE_STEP_FAIL); - emit showErrorMessage("check update trigger", m_updateStatus.m_statusDescription); - return false; + QStringList lst("Fileupload not a json-object"); + GUI(lst) << (CONSOLE(lst) << UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE); + break; } } else { - setProgress(100); - m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE, - "Fileupload KEY NOT AVAILABLE"); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.sanityCheckFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, - m_updateStatus.m_statusDescription)); - emit replaceLast(CHECK_UPDATE_TRIGGER_SET, UPDATE_STEP_FAIL); - emit showErrorMessage("check update trigger", m_updateStatus.m_statusDescription); - return false; + QStringList lst(QString("Fileupload not available")); + GUI(lst) << (CONSOLE(lst) << UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE); + break; } } else { - stopProgressLoop(); - int progress = (m_mainWindow->progressValue()/10) + 10; - progress += 1; - setProgress(progress); - emit showErrorMessage("check update trigger", "no ISMAS response"); + QStringList lst = QStringList(QString("no ISMAS response")); + GUI(lst) << (CONSOLE(lst) << UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE); QThread::sleep(6); } } - setProgress(100); - m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_UPDATE_TRIGGER_NOT_SET_OR_WRONG, - QString("ISMAS_UPDATE-TRIGGER-NOT-SET-OR-WRONG: VALUE=(") + - triggerValue + ")"); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.errorUpdateTrigger(m_updateStatus.m_statusDescription, "")); + if (m_initialClone == false) { + if (!triggerValue.contains("WAIT", Qt::CaseInsensitive)) { + QStringList lst(QString("ISMAS_UPDATE-TRIGGER-NOT-SET-OR-WRONG: VALUE=(") + triggerValue + ")"); + ISMAS(lst) << (GUI(lst) << (CONSOLE(lst) << UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE)); + } + } - emit replaceLast(CHECK_UPDATE_TRIGGER_SET, UPDATE_STEP_FAIL); return false; } bool Worker::customerEnvironment() { - emit appendText("\nPrepare customer environment ..."); + // configure customer environment -> checkout branch in case someone has + // changed the zone_nr + + ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::CHECKOUT_BRANCH)); + if (QDir(m_customerRepository).exists()) { - startProgressLoop(); if (m_gc.gitCheckoutBranch()) { - stopProgressLoop(); - int progress = (m_mainWindow->progressValue()/10) + 10; - setProgress(progress); - - m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CHECKOUT_BRANCH, - QString("CHECKED-OUT BRANCH ") + m_gc.branchName()); - - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.checkoutBranch(m_updateStatus.m_statusDescription, "")); - - setProgress(100); - emit replaceLast("Prepare customer environment ...", UPDATE_STEP_DONE); - qInfo() << "PREPARE CUSTOMER ENVIRONMENT DONE"; return true; } else { - stopProgressLoop(); - int progress = (m_mainWindow->progressValue()/10) + 10; - setProgress(progress); - emit showErrorMessage("cust-env", - QString("Checkout ") + m_customerRepository + " failed"); - Utils::printCriticalErrorMsg(QString("CHECKOUT OF " + m_customerRepository + "FAILED")); + QStringList lst(QString("CHECKOUT OF " + m_customerRepository + "FAILED")); + ISMAS(lst) << (GUI(lst) << (CONSOLE(lst) << UPDATE_STEP::CHECKOUT_BRANCH_FAILURE)); } - } else { - emit showErrorMessage("cust-env", m_customerRepository + " does not exist"); - Utils::printCriticalErrorMsg(m_customerRepository + " DOES NOT EXIST"); + } else {// cannot happen + QStringList lst(QString(m_customerRepository + " DOES NOT EXIST")); + ISMAS(lst) << (GUI(lst) << (CONSOLE(lst) << UPDATE_STEP::CHECKOUT_BRANCH_FAILURE)); } - setProgress(100); - emit replaceLast("Prepare customer environment ...", UPDATE_STEP_FAIL); return false; } bool Worker::filesToUpdate() { - emit appendText("\nFetch changes files ..."); - startProgressLoop(); - if (std::optional changes = m_gc.gitFetch()) { - stopProgressLoop(); - int progress = (m_mainWindow->progressValue()/10) + 10; - setProgress(progress); + // determine which files has to be updated: either sent to the hardware or + // rsynced with the filesystem in case of tariff-files - m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES, - QString("FETCHING OF ") + m_customerRepositoryPath + - QString(" INTO ") + m_customerRepository); + ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::UPDATE_REPOSITORY)); - setProgress(progress + 10); - if (std::optional changedFileNames = m_gc.gitDiff(changes.value())) { - setProgress(progress + 20); - if (m_gc.gitPull()) { - emit replaceLast(QString("Fetch changes files ..."), UPDATE_STEP_DONE); - m_filesToUpdate = changedFileNames.value(); + // always execute contents of opkg_commands-file + m_filesToUpdate << "etc/psa_update/opkg_commands"; - Utils::printInfoMsg("FILES-TO-UPDATE " + m_filesToUpdate.join(',')); - - int const size = m_filesToUpdate.size(); - if (size > 1) { - emit appendText(QString("Found %1 files to update :").arg(size), UPDATE_STEP_DONE); - for (int i = 0; i < size; ++i) { - emit appendText(QString("\n ") + m_filesToUpdate.at(i)); - } - } else { - emit appendText("Found 1 file to update :", UPDATE_STEP_DONE); - emit appendText(QString("\n ") + m_filesToUpdate.at(0)); - } - return true; + if (m_alwaysDownloadConfig) { +#if 0 + QStringList lst(QString("m_alwaysDownloadConfig NOT TESTED")); + CONSOLE(lst) << UPDATE_STEP::UPDATE_REPOSITORY; + // always download all json-config files, even if none of them have been + // changed in the git repository. useful for first installation. + QDir dir(QDir::cleanPath(m_customerRepository + QDir::separator() + "etc/psa_config")); + if (dir.exists()) { + QStringList jsons = dir.entryList(QStringList() << "DC2C*.json", QDir::Files); + if (!jsons.isEmpty()) { + m_filesToUpdate << jsons; } - emit showErrorMessage("files to update", "pulling files failed"); - Utils::printCriticalErrorMsg("PULLING FILES FAILED"); - - } else { - emit showErrorMessage("files to update", "no files to update (checked-in any files?)"); - Utils::printCriticalErrorMsg("NO FILES TO UPDATE (CHECKED IN ANY FILES?)"); } - setProgress(progress + 30); - } else { - stopProgressLoop(); - int progress = (m_mainWindow->progressValue()/10) + 10; - setProgress(progress + 30); - - emit showErrorMessage("files to update", - QString("no changes in ") + m_customerRepository + - " (checked-in any files?)"); - - Utils::printCriticalErrorMsg("NO CHANGES IN " - + m_customerRepository - + " (CHECKED IN ANY FILES?)"); +#endif } - emit replaceLast(QString("Fetch changes files ..."), UPDATE_STEP_FAIL); - setProgress(100); - return false; + if (m_alwaysDownloadDC) { +#if 0 + QStringList lst(QString("m_alwaysDownloadDC NOT TESTED")); + CONSOLE(lst) << UPDATE_STEP::UPDATE_REPOSITORY; + // always download the last dc-binary, even if not changed in the + // git repository. useful for first installation. + QDir dir(QDir::cleanPath(m_customerRepository + QDir::separator() + "etc/psa_update")); + if (dir.exists()) { + QStringList dc = dir.entryList(QStringList() << "dc2c*.bin", QDir::Files, + QDir::SortFlag::Time | QDir::SortFlag::Reversed); + if (!dc.isEmpty()) { + m_filesToUpdate << dc.first(); + } + } +#endif + } + + if (std::optional changes = m_gc.gitPull()) { + if (!changes.value().contains("Already up to date")) { + if (std::optional changedFileNames = m_gc.gitDiff(changes.value())) { + m_filesToUpdate << changedFileNames.value(); + } + } + m_filesToUpdate.removeDuplicates(); + + qCritical() << __PRETTY_FUNCTION__ << "FILES-TO-UPDATE" << m_filesToUpdate; + + GUI(m_filesToUpdate) << (CONSOLE(m_filesToUpdate) << UPDATE_STEP::FILES_TO_UPDATE); + setProgress(_FILES_TO_UPDATE); + } else { + ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::UPDATE_REPOSITORY_FAILURE)); + return false; + } + + return true; } -bool Worker::updateFiles(quint8 percent) { - QStringList filesToDownload; - m_displayIndex = 0; - startProgressLoop(); +bool Worker::computeFilesToDownload() { + m_filesToDownload.clear(); for (int i = 0; i < m_filesToUpdate.size(); ++i) { QString const fName = m_filesToUpdate.at(i); - Utils::printInfoMsg(QString("FNAME ") + fName); + if (fName.contains("DC2C_print", Qt::CaseInsensitive) || + fName.contains("DC2C_device", Qt::CaseInsensitive) || + fName.contains("DC2C_conf", Qt::CaseInsensitive) || + fName.contains("DC2C_cash", Qt::CaseInsensitive)) { + m_filesToDownload << fName; // download printer-config-files + } else { + static const QRegularExpression version("^.*dc2c[.][0-9]{1,2}[.][0-9]{1,2}[.]bin.*$"); + if (fName.contains(version)) { + m_filesToDownload << fName; // download device controller + } + } + } + return (m_filesToDownload.size() > 0); +} + +bool Worker::execOpkgCommands() { + for (int i = 0; i < m_filesToUpdate.size(); ++i) { + QString const fName = m_filesToUpdate.at(i); if (fName.contains("opkg_commands", Qt::CaseInsensitive)) { - emit appendText("\n( ) Update opkg pakets ..."); + GUI() << (CONSOLE() << UPDATE_STEP::EXEC_OPKG_COMMANDS); // execute opkg commands if (QDir::setCurrent(m_customerRepository)) { QFile f(fName); if (f.exists()) { if (f.open(QIODevice::ReadOnly)) { QTextStream in(&f); - int cmdCount = 0; - QStringList opkgCommands; + m_opkgCommands.clear(); + bool executeOpkgCommandFailed = false; while (!in.atEnd()) { QString line = in.readLine(); static const QRegularExpression comment("^\\s*#.*$"); if (line.indexOf(comment, 0) == -1) { // found opkg command QString opkgCommand = line.trimmed(); - ++cmdCount; - executeOpkgCommand(opkgCommand); - QString cmd = "\n " + opkgCommand; - emit appendText(cmd); - opkgCommands << cmd; + if (!executeOpkgCommand(opkgCommand)) { + executeOpkgCommandFailed = true; + } else { + QString cmd = "\n " + opkgCommand; + emit appendText(cmd); + m_opkgCommands << cmd; - m_ismasClient.setProgressInPercent(++percent); - m_updateStatus = UpdateStatus(UPDATE_STATUS::EXEC_OPKG_COMMAND, - QString("EXEC OPKG-COMMAND ") + opkgCommand); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.execOpkgCommand(m_updateStatus.m_statusDescription, "")); + QStringList const opkgLst(opkgCommand); + QStringList const cmdLst(cmd); + + switch(m_opkgCommands.size()) { + case 1: + ISMAS(opkgLst) << (GUI(cmdLst) << (CONSOLE() << UPDATE_STEP::EXEC_OPKG_COMMAND_1)); + setProgress(_EXEC_OPKG_COMMAND_1); + break; + case 2: + ISMAS(opkgLst) << (GUI(cmdLst) << (CONSOLE() << UPDATE_STEP::EXEC_OPKG_COMMAND_2)); + setProgress(_EXEC_OPKG_COMMAND_2); + break; + case 3: + ISMAS(opkgLst) << (GUI(cmdLst) << (CONSOLE() << UPDATE_STEP::EXEC_OPKG_COMMAND_3)); + setProgress(_EXEC_OPKG_COMMAND_3); + break; + case 4: + ISMAS(opkgLst) << (GUI(cmdLst) << (CONSOLE() << UPDATE_STEP::EXEC_OPKG_COMMAND_4)); + setProgress(_EXEC_OPKG_COMMAND_4); + break; + case 5: + ISMAS(opkgLst) << (GUI(cmdLst) << (CONSOLE() << UPDATE_STEP::EXEC_OPKG_COMMAND_5)); + setProgress(_EXEC_OPKG_COMMAND_5); + break; + case 6: + ISMAS(opkgLst) << (GUI(cmdLst) << (CONSOLE() << UPDATE_STEP::EXEC_OPKG_COMMAND_6)); + setProgress(_EXEC_OPKG_COMMAND_6); + break; + case 7: + ISMAS(opkgLst) << (GUI(cmdLst) << (CONSOLE() << UPDATE_STEP::EXEC_OPKG_COMMAND_7)); + setProgress(_EXEC_OPKG_COMMAND_7); + break; + case 8: + ISMAS(opkgLst) << (GUI(cmdLst) << (CONSOLE() << UPDATE_STEP::EXEC_OPKG_COMMAND_8)); + setProgress(_EXEC_OPKG_COMMAND_8); + break; + case 9: + ISMAS(opkgLst) << (GUI(cmdLst) << (CONSOLE() << UPDATE_STEP::EXEC_OPKG_COMMAND_9)); + setProgress(_EXEC_OPKG_COMMAND_9); + break; + default: + ISMAS(opkgLst) << (GUI(cmdLst) << (CONSOLE() << UPDATE_STEP::EXEC_OPKG_COMMAND_LAST)); + setProgress(_EXEC_OPKG_COMMAND_LAST); + } + } } } f.close(); - if (cmdCount > 0) { - m_displayIndex = 1; - QString prepend = QString("(") + QString("%1").arg(m_displayIndex).rightJustified(2, ' ') + QString(")") - + QString(" Update opkg pakets ... "); - opkgCommands.prepend(prepend); - emit replaceLast(opkgCommands, UPDATE_STEP_DONE); + if (!executeOpkgCommandFailed) { + if (m_opkgCommands.size() > 0) { + m_displayIndex = 1; + GUI() << UPDATE_STEP::EXEC_OPKG_COMMAND_SUCCESS; + setProgress(_EXEC_OPKG_COMMAND_SUCCESS); + } } else { m_displayIndex = 1; - emit replaceLast(QString("(") + QString("%1").arg(m_displayIndex).rightJustified(2, ' ') + QString(")") - + QString(" Update opkg pakets ... "), UPDATE_STEP_FAIL); + GUI() << UPDATE_STEP::EXEC_OPKG_COMMAND_FAILURE; + setProgress(_EXEC_OPKG_COMMAND_FAILURE); + return false; } } } } - } else - if (fName.contains("print", Qt::CaseInsensitive)) { - filesToDownload << fName; // download printer-config-files - } else { - static const QRegularExpression version("^.*dc2c[.][0-9]{1,2}[.][0-9]{1,2}[.]bin.*$"); - if (fName.contains(version)) { - filesToDownload << fName; // download device controller - } } } + return true; +} - stopProgressLoop(); - setProgress(100); +bool Worker::downloadFilesToPSAHardware() { + m_displayIndex = 0; - if (filesToDownload.size() > 0) { - Utils::printInfoMsg(QString("FILES_TO_DOWNLOAD_TO_PSA_HW ") + filesToDownload.join(',')); + GUI(m_filesToDownload) << (CONSOLE(m_filesToDownload) << UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE); + setProgress(_DOWNLOAD_FILES_TO_PSA_HARDWARE); - Update *update = m_mainWindow->getUpdate(); - if (update) { - return update->doUpdate(m_displayIndex, filesToDownload); + if (m_noUpdatePsaHardware == false) { + if (computeFilesToDownload()) { + CONSOLE(m_filesToDownload) << UPDATE_STEP::FILES_TO_DOWNLOAD; + + Update update(this, + QDir::cleanPath(m_workingDirectory + QDir::separator() + m_customerNrStr), + m_customerNrStr, + m_branchName, + m_pluginDir, + m_pluginName, + m_workingDirectory); + + return update.doUpdate(m_displayIndex, m_filesToDownload); + } else { + CONSOLE(QStringList("NO FILES TO DOWNLOAD TO PSA-HW")) << UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE_FAILURE; + setProgress(_DOWNLOAD_FILES_TO_PSA_HARDWARE_FAILURE); } - } else { - Utils::printCriticalErrorMsg("NO FILES_TO_DOWNLOAD_TO_PSA_HW"); } return true; } bool Worker::syncCustomerRepositoryAndFS() { - // this step is currently needed only for updating tariff-files - setProgress(0); - emit appendText("\nSync customer environment with filesystem ..."); + ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY)); + if (QDir(m_customerRepository).exists()) { if (QDir::setCurrent(m_customerRepository)) { Command md("bash"); if (!md.execute(m_customerRepository, - QStringList() << "-c" << "mkdir -p /etc/psa_config /etc/psa_update /etc/dc /etc/psa_tariff")) { + QStringList() << "-c" << "mkdir -p /etc/psa_config /etc/dc /etc/psa_tariff")) { qCritical() << "COULD NOT EXECUTE '" << md.command() << "' exitCode=(" << md.exitCode() << ")"; } - int progress = 10; - setProgress(progress); QString const params("-vvv " "--recursive " "--progress " @@ -894,24 +854,30 @@ bool Worker::syncCustomerRepositoryAndFS() { "--exclude=.* " "--include=*.bin " "--include=*.json " - "--include=opkg_commands " "--include=*.ini"); QStringList cmds; - cmds << QString("rsync ") + params.simplified() + " etc/ /etc"; - cmds << QString("rsync ") + params.simplified() + " opt/ /opt"; + + if (QDir(QDir::cleanPath(m_customerRepository + QDir::separator() + "etc/")).exists()) { + cmds << QString("rsync ") + params.simplified() + " etc/ /etc"; + Utils::printInfoMsg(QString("CONFIGURED SYNCING TO /ETC")); + } + if (QDir(QDir::cleanPath(m_customerRepository + QDir::separator() + "opt/")).exists()) { + cmds << QString("rsync ") + params.simplified() + " opt/ /opt"; + Utils::printInfoMsg(QString("CONFIGURED SYNCING TO /OPT")); + } QString cmd; bool error = false; foreach (cmd, cmds) { - progress += 5; - setProgress(progress); if (!error) { Command c("bash"); qInfo() << "EXECUTING CMD..." << cmd; + Utils::printInfoMsg(QString("EXECUTING CMD %1...").arg(cmd)); if (c.execute(m_customerRepository, QStringList() << "-c" << cmd)) { QStringList result = c.getCommandResult().split('\n'); QString const &p1 = "send_files mapped "; QString const &p2 = "of size"; + for (int i = 0; i < result.size(); ++i) { QString line = result.at(i); qInfo() << line; @@ -922,14 +888,16 @@ bool Worker::syncCustomerRepositoryAndFS() { if (sendFilesAtPos != -1 && ofSizeAtPos != -1) { sendFilesAtPos += p1.length(); QString const &s = line.mid(sendFilesAtPos, ofSizeAtPos - sendFilesAtPos).trimmed(); - m_updateStatus = UpdateStatus(UPDATE_STATUS::RSYNC_FILE_SUCCESS, - QString("RSYNC FILE ") + s.split("/").last() + - " LAST-COMMIT: " + m_gc.gitLastCommit(s)); - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_EVENT#J=") + - m_ismasClient.rsyncFile(m_updateStatus.m_statusDescription, "")); + + //m_updateStatus = UpdateStatus(UPDATE_STATUS::RSYNC_FILE_SUCCESS, + // QString("RSYNC FILE ") + s.split("/").last() + + // " LAST-COMMIT: " + m_gc.gitLastCommit(s)); + //IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, + // QString("#M=APISM#C=CMD_EVENT#J=") + + // m_ismasClient.rsyncFile(m_updateStatus.m_statusDescription, "")); } } + } else { Utils::printCriticalErrorMsg(QString("CMD ") + cmd + " FAILED: " + c.getCommandResult() + QString(" EXIT_CODE=(%1)").arg(c.exitCode())); @@ -937,38 +905,29 @@ bool Worker::syncCustomerRepositoryAndFS() { } } } - progress += 5; - setProgress(progress); if (!error) { // now check tariff-files in etc and /etc/psa_tariff QDir dir1(QDir::cleanPath(m_customerRepository + QDir::separator() + "etc/psa_tariff")); QDir dir2("/etc/psa_tariff"); if (Utils::sameFilesInDirs(dir1, dir2)) { - setProgress(100); - emit replaceLast(QString("Sync customer environment with filesystem ..."), UPDATE_STEP_DONE); + ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_SUCCESS)); + setProgress(_SYNC_CUSTOMER_REPOSITORY_SUCCESS); return true; - } else { - // TODO: send message to ISMAS } } } } - setProgress(100); - emit replaceLast(QString("Sync customer environment with filesystem ..."), UPDATE_STEP_FAIL); + ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_FAILURE)); + setProgress(_SYNC_CUSTOMER_REPOSITORY_FAILURE); return false; } -bool Worker::sendIsmasLastVersionNotification() { - IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, - QString("#M=APISM#C=CMD_SENDVERSION#J=") + - m_ismasClient.updateOfPSASendVersion(getPSAInstalled())); - emit appendText(QString("Send last version info "), UPDATE_STEP_DONE); +bool Worker::saveLogFile() { + // ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::SAVE_LOGS)); + // ISMAS() << (GUI() << (CONSOLE() << UPDATE_STEP::SAVE_LOGS_FAILURE)); return true; } -bool Worker::saveLogFile() { - return true; -} QString Worker::getOsVersion() const { QString const cmd = QString("echo -n $(cat /etc/os-release | head -n 1 | cut -d'\"' -f2 | tr -d '\"')"); Command c("bash"); @@ -978,6 +937,51 @@ QString Worker::getOsVersion() const { return "N/A"; } +QString Worker::getATBUpdateToolYoctoVersion() { + if (QFile::exists("/var/lib/opkg/status")) { + QString const cmd = QString("echo -n $(cat /var/lib/opkg/status | grep -A1 atbupdatetool | tail -n 1 | cut -d':' -f2 | cut -d' ' -f2)"); + Command c("bash"); + if (c.execute("/tmp", QStringList() << "-c" << cmd)) { + return c.getCommandResult(); // 1.3.9+git0+226553a8ab-r0 + } + } + return "N/A"; +} + +QString Worker::getAPISMYoctoVersion() { + if (QFile::exists("/var/lib/opkg/status")) { + QString const cmd = QString("echo -n $(cat /var/lib/opkg/status | grep -A1 apism | tail -n 1 | cut -d':' -f2 | cut -d' ' -f2)"); + Command c("bash"); + if (c.execute("/tmp", QStringList() << "-c" << cmd)) { + return c.getCommandResult(); // 1.4.1.0-r4 + } + } + return "N/A"; +} + +QString Worker::getATBUpdateToolYoctoInstallationStatus() { + if (QFile::exists("/var/lib/opkg/status")) { + QString const cmd = QString("echo -n $(cat /var/lib/opkg/status | grep -A3 atbupdatetool | tail -n 1 | cut -d':' -f2 | cut -d' ' -f2,3,4)"); + Command c("bash"); + if (c.execute("/tmp", QStringList() << "-c" << cmd)) { + return c.getCommandResult(); // 1.3.9+git0+226553a8ab-r0 + } + } + return "N/A"; +} + +QString Worker::getAPISMYoctoInstallationStatus() { + if (QFile::exists("/var/lib/opkg/status")) { + QString const cmd = QString("echo -n $(cat /var/lib/opkg/status | grep -A3 apism | tail -n 1 | cut -d':' -f2 | cut -d' ' -f2,3,4)"); + Command c("bash"); + if (c.execute("/tmp", QStringList() << "-c" << cmd)) { + return c.getCommandResult(); // 1.3.9+git0+226553a8ab-r0 + } + } + return "N/A"; +} + + QString Worker::getATBQTVersion() const { QString const cmd = QString("echo -n $(/opt/app/ATBAPP/ATBQT -v | head -n 2 | cut -d':' -f2)"); Command c("bash"); @@ -987,6 +991,10 @@ QString Worker::getATBQTVersion() const { return "N/A"; } +QString Worker::getATBUpdateToolVersion() const { + return APP_EXTENDED_VERSION; +} + QString Worker::getCPUSerial() const { QString const cmd = QString("echo -n $(cat /proc/cpuinfo | grep -i Serial | cut -d':' -f2)"); Command c("bash"); @@ -1025,22 +1033,25 @@ QString Worker::getPluginVersion(QString const &pluginFileName) const { QStringList Worker::getDCVersion() const { QStringList lst = (QStringList() << "N/A" << "N/A"); - hwinf *hwi = m_mainWindow->getPlugin(); - if (hwi) { - hwi->dc_autoRequest(true); // turn auto-request setting on + Update const *up = update(); + if (up) { + hwinf const *caPlugin = up->hw(); + if (caPlugin) { + caPlugin->dc_autoRequest(true); // turn auto-request setting on - QByteArray const cmp(8, char(0)); - QByteArray hw(""), sw(""); - for (int i=0; i<5; ++i) { - hw = hwi->dc_getHWversion().toUtf8(); - sw = hwi->dc_getSWversion().toUtf8(); - if (!hw.startsWith(cmp)) { - lst.clear(); - qInfo() << hw << sw; - lst << hw << sw; - break; + QByteArray const cmp(8, char(0)); + QByteArray hw(""), sw(""); + for (int i=0; i<5; ++i) { + hw = caPlugin->dc_getHWversion().toUtf8(); + sw = caPlugin->dc_getSWversion().toUtf8(); + if (!hw.startsWith(cmp)) { + lst.clear(); + qInfo() << hw << sw; + lst << hw << sw; + break; + } + QThread::sleep(1); } - QThread::sleep(1); } } return lst; @@ -1082,9 +1093,7 @@ PSAInstalled Worker::getPSAInstalled() { QString printSysDir("/etc/psa_config"); QString tariffSysDir("/etc/psa_tariff"); QString tariffRepoDir("etc/psa_tariff"); - QString opkgSysDir("/etc/psa_update"); QString opkgRepoDir("etc/psa_update"); - QString const &absPathNameOpkg = QDir::cleanPath(opkgSysDir + QDir::separator() + "opkg_commands"); QString const &absPathNameRepositoryOpkg = QDir::cleanPath(opkgRepoDir + QDir::separator() + "opkg_commands"); QString absPathName; QString absPathNameRepository; @@ -1093,7 +1102,7 @@ PSAInstalled Worker::getPSAInstalled() { psaInstalled.versionInfo.reason = ""; psaInstalled.versionInfo.created = ""; - QStringList versionInfo = m_gc.gitShowReason(); + QStringList versionInfo = m_gc.gitShowReason(m_branchName); if (versionInfo.size() == 3) { psaInstalled.versionInfo.lastCommit = versionInfo.at(0); psaInstalled.versionInfo.reason = versionInfo.at(1); @@ -1115,12 +1124,12 @@ PSAInstalled Worker::getPSAInstalled() { psaInstalled.tariff.info = "N/A"; psaInstalled.tariff.version = "N/A"; - psaInstalled.hw.linuxVersion = m_osVersion; + psaInstalled.hw.linuxVersion = getOsVersion(); psaInstalled.hw.cpuSerial = m_cpuSerial; - psaInstalled.opkg.blob = m_gc.gitBlob(absPathNameOpkg); - psaInstalled.opkg.size = getFileSize(absPathNameOpkg); - psaInstalled.opkg.loadTime = Utils::getTariffLoadTime(absPathNameOpkg); + psaInstalled.opkg.blob = m_gc.gitBlob(absPathNameRepositoryOpkg); + // psaInstalled.opkg.size = getFileSize(absPathNameRepositoryOpkg); + // psaInstalled.opkg.loadTime = Utils::getTariffLoadTime(absPathNameRepositoryOpkg); psaInstalled.opkg.lastCommit = m_gc.gitLastCommit(absPathNameRepositoryOpkg); psaInstalled.dc.versionHW = deviceControllerVersionHW; @@ -1129,8 +1138,9 @@ PSAInstalled Worker::getPSAInstalled() { psaInstalled.dc.gitLastCommit = "N/A"; psaInstalled.dc.size = -1; - psaInstalled.sw.apismVersion = m_apismVersion; - psaInstalled.sw.atbQTVersion = m_atbqtVersion; + psaInstalled.sw.apismVersion = getAPISMYoctoVersion(); + psaInstalled.sw.atbQTVersion = getATBQTVersion(); + psaInstalled.sw.atbUpdateToolVersion = m_atbUpdateToolVersion; psaInstalled.pluginVersion.deviceController = m_pluginVersionATBDeciceController; psaInstalled.pluginVersion.ingenicoISelfCC = m_pluginVersionIngenicoISelf; @@ -1165,260 +1175,3 @@ PSAInstalled Worker::getPSAInstalled() { return psaInstalled; } - -hwinf *Worker::getPlugin() { - return m_mainWindow ? m_mainWindow->getPlugin() : nullptr; -} - -hwinf const *Worker::getPlugin() const { - return m_mainWindow ? m_mainWindow->getPlugin() : nullptr; -} - -/************************************************************************************************ - * operators - */ -QDebug operator<< (QDebug debug, UpdateStatus status) { - switch(status.m_updateStatus) { - case UPDATE_STATUS::ISMAS_SEND_LAST_VERSION_FAILED: - debug << QString("UPDATE_STATUS::ISMAS_SEND_LAST_VERSION_FAILED: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::SAVE_LOG_FILES_FAILED: - debug << QString("UPDATE_STATUS::SAVE_LOG_FILES_FAILED: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::GIT_CHECK_FILES_TO_UPDATE_SUCCESS: - debug << QString("UPDATE_STATUS::GIT_CHECK_FILES_TO_UPDATE_SUCCESS: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::PSA_UPDATE_FILES_FAILED: - debug << QString("UPDATE_STATUS::PSA_UPDATE_FILES_FAILED: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::RSYNC_UPDATES_SUCCESS: - debug << QString("UPDATE_STATUS::RSYNC_UPDATES_SUCCESS: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::RSYNC_UPDATES_FAILURE: - debug << QString("UPDATE_STATUS::RSYNC_UPDATES_FAILURE: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::EXEC_OPKG_COMMAND: - debug << QString("UPDATE_STATUS::EXEC_OPKG_COMMAND: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::GIT_CLONE_AND_CHECKOUT_SUCCESS: - debug << QString("UPDATE_STATUS::GIT_CLONE_AND_CHECKOUT_SUCCESS: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::GIT_CLONE_AND_CHECKOUT_FAILURE: - debug << QString("UPDATE_STATUS::GIT_CLONE_AND_CHECKOUT_FAILURE: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::NOT_DEFINED: - debug << QString("UPDATE_STATUS::NOT_DEFINED: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::UPDATE_PROCESS_FAILURE: - debug << QString("UPDATE_STATUS::UPDATE_PROCESS_FAILURE: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::ISMAS_UPDATE_TRIGGER_SET_FAILURE: - debug << QString("UPDATE_STATUS::ISMAS_UPDATE_TRIGGER_FAILURE: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::GIT_CHECKOUT_BRANCH_FAILURE: - debug << QString("UPDATE_STATUS::GIT_CHECKOUT_BRANCH_FAILURE: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::GIT_CHECKOUT_BRANCH: - debug << QString("UPDATE_STATUS::GIT_CHECKOUT_BRANCH: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::ISMAS_UPDATE_TRIGGER_NOT_SET_OR_WRONG: - debug << QString("UPDATE_STATUS::ISMAS_UPDATE_TRIGGER_NOT_SET_OR_WRONG: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::ISMAS_UPDATE_TRIGGER_SET: - debug << QString("UPDATE_STATUS::ISMAS_UPDATE_TRIGGER_SET: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::ISMAS_SANITY_CHECK_OK: - debug << QString("UPDATE_STATUS::ISMAS_SANITY_CHECK_OK: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::JSON_PARSE_FAILURE: - debug << QString("UPDATE_STATUS::JSON_PARSE_FAILURE: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::BACKEND_CHECK: - debug << QString("UPDATE_STATUS::BACKEND_CHECK: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::BACKEND_CHECK_FAILURE: - debug << QString("UPDATE_STATUS::BACKEND_CHECK_FAILURE: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::BACKEND_NOT_CONNECTED: - debug << QString("UPDATE_STATUS::BACKEND_NOT_CONNECTED: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::UPDATE_PROCESS_SUCCESS: - debug << QString("UPDATE_STATUS::UPDATE_PROCESS_SUCCESS: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_PENDING: - debug << QString("UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_PENDING: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE: - debug << QString("UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::GIT_FETCH_UPDATES: - debug << QString("UPDATE_STATUS::GIT_FETCH_UPDATES: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_FAILURE: - debug << QString("UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_FAILURE: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::ISMAS_RESPONSE_RECEIVED: - debug << QString("UPDATE_STATUS::ISMAS_RESPONSE_RECEIVED: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::RSYNC_FILE_SUCCESS: - debug << QString("UPDATE_STATUS::RSYNC_FILE_SUCCESS: ") - << status.m_statusDescription; - break; - case UPDATE_STATUS::EXEC_OPKG_COMMANDS: - debug << QString("UPDATE_STATUS::EXEC_OPKG_COMMANDS: ") - << status.m_statusDescription; - break; - // default:; - } - return debug; -} - -QString& operator<< (QString& str, UpdateStatus status) { - switch(status.m_updateStatus) { - case UPDATE_STATUS::ISMAS_SEND_LAST_VERSION_FAILED: - str = QString("UPDATE_STATUS::ISMAS_SEND_LAST_VERSION_FAILED: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::SAVE_LOG_FILES_FAILED: - str = QString("UPDATE_STATUS::SAVE_LOG_FILES_FAILED: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::GIT_CHECK_FILES_TO_UPDATE_SUCCESS: - str = QString("UPDATE_STATUS::GIT_CHECK_FILES_TO_UPDATE_SUCCESS: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::PSA_UPDATE_FILES_FAILED: - str = QString("UPDATE_STATUS::PSA_UPDATE_FILES_FAILED: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::RSYNC_UPDATES_SUCCESS: - str = QString("UPDATE_STATUS::RSYNC_UPDATES_SUCCESS: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::RSYNC_UPDATES_FAILURE: - str = QString("UPDATE_STATUS::RSYNC_UPDATES_FAILURE: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::EXEC_OPKG_COMMAND: - str = QString("UPDATE_STATUS::EXEC_OPKG_COMMAND: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::GIT_CLONE_AND_CHECKOUT_SUCCESS: - str = QString("UPDATE_STATUS::GIT_CLONE_AND_CHECKOUT_SUCCESS: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::GIT_CLONE_AND_CHECKOUT_FAILURE: - str = QString("UPDATE_STATUS::GIT_CLONE_AND_CHECKOUT_FAILURE: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::NOT_DEFINED: - str = QString("UPDATE_STATUS::NOT_DEFINED: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::UPDATE_PROCESS_FAILURE: - str = QString("UPDATE_STATUS::UPDATE_PROCESS_FAILURE: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::ISMAS_UPDATE_TRIGGER_SET_FAILURE: - str = QString("UPDATE_STATUS::ISMAS_UPDATE_TRIGGER_FAILURE: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::GIT_CHECKOUT_BRANCH_FAILURE: - str = QString("UPDATE_STATUS::GIT_CHECKOUT_BRANCH_FAILURE: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::GIT_CHECKOUT_BRANCH: - str = QString("UPDATE_STATUS::GIT_CHECKOUT_BRANCH: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::ISMAS_UPDATE_TRIGGER_NOT_SET_OR_WRONG: - str = QString("UPDATE_STATUS::ISMAS_UPDATE_TRIGGER_NOT_SET_OR_WRONG: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE: - str = QString("UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_FAILURE: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::ISMAS_UPDATE_TRIGGER_SET: - str = QString("UPDATE_STATUS::ISMAS_UPDATE_TRIGGER_SET: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::ISMAS_SANITY_CHECK_OK: - str = QString("UPDATE_STATUS::ISMAS_SANITY_CHECK_OK: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::JSON_PARSE_FAILURE: - str = QString("UPDATE_STATUS::JSON_PARSE_FAILURE: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::BACKEND_CHECK: - str = QString("UPDATE_STATUS::BACKEND_CHECK: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::BACKEND_CHECK_FAILURE: - str = QString("UPDATE_STATUS::BACKEND_CHECK_FAILURE: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::BACKEND_NOT_CONNECTED: - str = QString("UPDATE_STATUS::BACKEND_NOT_CONNECTED: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::UPDATE_PROCESS_SUCCESS: - str = QString("UPDATE_STATUS::UPDATE_PROCESS_SUCCESS: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_PENDING: - str = QString("UPDATE_STATUS::ISMAS_WAIT_STATE_CHECK_PENDING: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::GIT_FETCH_UPDATES: - str = QString("UPDATE_STATUS::GIT_FETCH_UPDATES: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_FAILURE: - str = QString("UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_FAILURE: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::ISMAS_RESPONSE_RECEIVED: - str = QString("UPDATE_STATUS::ISMAS_RESPONSE_RECEIVED: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::EXEC_OPKG_COMMANDS: - str = QString("UPDATE_STATUS::EXEC_OPKG_COMMANDS: "); - str += status.m_statusDescription; - break; - case UPDATE_STATUS::RSYNC_FILE_SUCCESS: - str = QString("UPDATE_STATUS::RSYNC_FILE_SUCCESS: "); - str += status.m_statusDescription; - break; - //default:; - } - return str; -} diff --git a/worker.h b/worker.h index 2ecadfb..394b944 100644 --- a/worker.h +++ b/worker.h @@ -8,13 +8,17 @@ #include #include #include +#include +#include +#include #include +#include -#include "worker_thread.h" #include "update.h" #include "git/git_client.h" #include "ismas/ismas_client.h" +#include "utils.h" #ifdef PTU5 #define SERIAL_PORT "ttymxc2" @@ -22,68 +26,106 @@ #define SERIAL_PORT "ttyUSB0" #endif +#define _ISMAS_DONE "U0001" // 100% +#define _ISMAS_SET_WAIT_OK "U0002" // empty WAIT-button ("") +#define _ISMAS_FAILURE "U0003" // FAIL +#define _ISMAS_CONTINUE "U0010" // %-values +#define _ISMAS_RESET_WAIT "ISMAS" // reset WAIT-button to "WAIT" -enum class UPDATE_STATUS : quint8 { - NOT_DEFINED, - ISMAS_WAIT_STATE_CHECK_PENDING, - ISMAS_WAIT_STATE_CHECK_FAILURE, - ISMAS_RESPONSE_RECEIVED, - BACKEND_CHECK, - BACKEND_CHECK_FAILURE, - BACKEND_NOT_CONNECTED, - ISMAS_UPDATE_TRIGGER_SET, - ISMAS_UPDATE_TRIGGER_NOT_SET_OR_WRONG, - GIT_CLONE_AND_CHECKOUT_SUCCESS, - GIT_CLONE_AND_CHECKOUT_FAILURE, - GIT_CHECKOUT_BRANCH, - GIT_CHECKOUT_BRANCH_FAILURE, - GIT_FETCH_UPDATES, - GIT_FETCH_UPDATES_REQUEST_FAILURE, - EXEC_OPKG_COMMAND, - EXEC_OPKG_COMMANDS, - RSYNC_UPDATES_FAILURE, - RSYNC_UPDATES_SUCCESS, - RSYNC_FILE_SUCCESS, - JSON_PARSE_FAILURE, - UPDATE_PROCESS_SUCCESS, - UPDATE_PROCESS_FAILURE, - ISMAS_SANITY_CHECK_OK, - ISMAS_UPDATE_TRIGGER_SET_FAILURE, - PSA_UPDATE_FILES_FAILED, - GIT_CHECK_FILES_TO_UPDATE_SUCCESS, - ISMAS_SEND_LAST_VERSION_FAILED, - SAVE_LOG_FILES_FAILED -}; +#define _STARTED (1) +#define _CHECK_SANITY (2) +#define _CHECK_SANITY_FAILURE (3) +#define _CHECK_SANITY_SUCCESS (4) +#define _REPOSITORY_RECOVERED_FAILURE (5) +#define _REPOSITORY_RECOVERED_SUCCESS (6) +#define _CHECK_REPOSITORY (7) +#define _CHECK_REPOSITORY_FAILURE (8) +#define _CHECK_REPOSITORY_SUCCESS (9) +#define _CLONE_REPOSITORY (10) +#define _CLONE_REPOSITORY_FAILURE (11) +#define _CLONE_REPOSITORY_SUCCESS (12) +#define _CHECKOUT_REPOSITORY (13) +#define _CHECKOUT_REPOSITORY_FAILURE (14) +#define _CHECKOUT_REPOSITORY_SUCCESS (15) +#define _INITIAL_CLONE_WITHOUT_ACTIVE_ISMAS_TRIGGER (16) +#define _INITIAL_CLONE_WITH_ACTIVE_ISMAS_TRIGGER (17) +#define _CHECK_ISMAS_TRIGGER (19) +#define _CHECK_ISMAS_TRIGGER_WRONG_VALUE (20) +#define _CHECK_ISMAS_TRIGGER_SUCCESS (21) +#define _CHECK_ISMAS_TRIGGER_FAILURE (22) +#define _CHECKOUT_BRANCH (23) +#define _CHECKOUT_BRANCH_FAILURE (24) +#define _CHECKOUT_BRANCH_SUCCESS (25) +#define _UPDATE_REPOSITORY (26) +#define _UPDATE_REPOSITORY_FAILURE (28) +#define _UPDATE_REPOSITORY_SUCCESS (29) +#define _CHECK_FOR_REPOSITORY_CHANGES (30) +#define _CHECK_FOR_REPOSITORY_CHANGES_SUCCESS (36) +#define _FILES_TO_UPDATE (37) +#define _CHECK_FOR_REPOSITORY_CHANGES_FAILURE (38) +#define _FILES_TO_DOWNLOAD (39) +#define _EXEC_OPKG_COMMANDS (41) +#define _EXEC_OPKG_COMMAND_1 (42) +#define _EXEC_OPKG_COMMAND_2 (43) +#define _EXEC_OPKG_COMMAND_3 (44) +#define _EXEC_OPKG_COMMAND_4 (45) +#define _EXEC_OPKG_COMMAND_5 (46) +#define _EXEC_OPKG_COMMAND_6 (47) +#define _EXEC_OPKG_COMMAND_7 (48) +#define _EXEC_OPKG_COMMAND_8 (49) +#define _EXEC_OPKG_COMMAND_9 (50) +#define _EXEC_OPKG_COMMAND_LAST (51) +#define _EXEC_OPKG_COMMAND_FAILURE (52) +#define _EXEC_OPKG_COMMAND_SUCCESS (53) +#define _DOWNLOAD_FILES_TO_PSA_HARDWARE (54) +#define _DOWNLOAD_CONFIG_FILE (55) +#define _DOWNLOAD_CONFIG_FILE_SUCCESS (56) +#define _DOWNLOAD_CONFIG_FILE_FAILURE (57) +#define _DOWNLOAD_DEVICE_CONTROLLER (65) +#define _DOWNLOAD_DEVICE_CONTROLLER_SUCCESS (86) +#define _DOWNLOAD_DEVICE_CONTROLLER_FAILURE (87) +#define _DOWNLOAD_FILES_TO_PSA_HARDWARE_FAILURE (88) +#define _DOWNLOAD_FILES_TO_PSA_HARDWARE_SUCCESS (89) +#define _SYNC_CUSTOMER_REPOSITORY (90) +#define _SYNC_CUSTOMER_REPOSITORY_FAILURE (91) +#define _SYNC_CUSTOMER_REPOSITORY_SUCCESS (92) +#define _SAVE_LOGS (93) +#define _SAVE_LOGS_FAILURE (94) +#define _SAVE_LOGS_SUCCESS (95) +#define _SEND_LAST_VERSION (96) +#define _UPDATE_SUCCEEDED (97) +#define _UPDATE_FAILED (98) +#define _UPDATE_ACTIVATED (99) +#define _FINISHED (100) +#define _DEBUG (1000) +#define _ERROR (1001) -struct UpdateStatus { - UPDATE_STATUS m_updateStatus; - QString m_statusDescription; +#define _SEND_LAST_VERSION_CORRECTION (4) +#define _UPDATE_SUCCEEDED_CORRECTION (3) +#define _UPDATE_FAILED_CORRECTION (2) +#define _UPDATE_ACTIVATED_CORRECTION (1) - explicit UpdateStatus(UPDATE_STATUS s = UPDATE_STATUS::NOT_DEFINED, - QString const &d = QString("")) - : m_updateStatus(s), m_statusDescription(d) {} -}; - -QDebug operator<<(QDebug debug, UpdateStatus status); -QString& operator<<(QString &str, UpdateStatus status); - -#define ISMAS_UPDATE_REQUESTS (10) +#define ISMAS_UPDATE_REQUESTS (10) +#define CHECK_UPDATE_TRIGGER_SET "Check update trigger ..." class MainWindow; class hwinf; -class Worker : public QObject { +class Worker : public QThread{ Q_OBJECT - WorkerThread m_workerThread; int const m_customerNr; QString const m_customerNrStr; int const m_machineNr; int const m_zoneNr; + QString const m_pluginDir; QString const m_pluginName; QString const m_workingDirectory; QString const m_branchName; QString const m_customerRepositoryPath; QString const m_customerRepository; + bool const m_noUpdatePsaHardware; + bool const m_alwaysDownloadConfig; + bool const m_alwaysDownloadDC; bool const m_dryRun; QObject *m_parent; QString const m_serialInterface; @@ -92,6 +134,7 @@ class Worker : public QObject { GitClient m_gc; QString const m_osVersion; QString const m_atbqtVersion; + QString const m_atbUpdateToolVersion; QString const m_cpuSerial; QString const m_pluginVersionATBDeciceController; QString const m_pluginVersionIngenicoISelf; @@ -104,21 +147,23 @@ class Worker : public QObject { int m_ismasUpdateRequests; QTimer m_waitForNewUpdates; - UpdateStatus m_updateStatus; - QStringList m_filesToUpdate; + QStringList m_filesToDownload; bool m_updateProcessRunning; int m_displayIndex; - int m_returnCode; + bool m_clone = false; + bool m_initialClone = false; + bool m_repairClone = false; + bool m_ismasTriggerActive = false; MainWindow *m_mainWindow; - int m_progressValue; bool m_withoutIsmasDirectPort; QString m_apismVersion; bool executeOpkgCommand(QString opkgCommand); QString getOsVersion() const; QString getATBQTVersion() const; + QString getATBUpdateToolVersion() const; QString getCPUSerial() const; QString getRaucVersion() const; QString getOpkgVersion() const; @@ -126,19 +171,170 @@ class Worker : public QObject { QStringList getDCVersion() const; qint64 getFileSize(QString const &fileName) const; + bool isRepositoryCorrupted(); + bool repairCorruptedRepository(); + + int sendCloneAndCheckoutSuccess(); + int sendCloneAndCheckoutFailure(); + int sendIsmasTriggerFailure(); + int sendPullFailure(); + int sendFileUpdateFailure(); + int sendRsyncFailure(); + int sendLastVersionFailure(); + int sendSaveLogFilesFailure(); + int sendCustomerEnvironmentConfigurationFailed(); + int sendFoundFilesToUpdateSuccess(); + int sendUpdateSucceededAndActivated(); + int sendFinalResult(); + + struct UpdateProcessRunning { + Worker *m_worker; + + explicit UpdateProcessRunning(Worker *worker) : m_worker(worker) { + m_worker->m_updateProcessRunning = true; + // emit m_worker->disableExit(); + emit m_worker->enableExit(); + m_worker->startProgressLoop(); + } + + virtual ~UpdateProcessRunning() { + m_worker->ISMAS() << (m_worker->GUI() << (m_worker->CONSOLE() + << UPDATE_STEP::SEND_LAST_VERSION)); + m_worker->stopProgressLoop(); + + m_worker->m_updateProcessRunning = false; + emit m_worker->enableExit(); + emit m_worker->restartExitTimer(); + } + }; + + friend struct UpdateProcessRunning; public: + enum class UPDATE_STEP { + STARTED = _STARTED, + CHECK_REPOSITORY = _CHECK_REPOSITORY, + CHECK_REPOSITORY_SUCCESS = _CHECK_REPOSITORY_SUCCESS, + CHECK_REPOSITORY_FAILURE = _CHECK_REPOSITORY_FAILURE, + CHECK_SANITY = _CHECK_SANITY, + CHECK_SANITY_SUCCESS = _CHECK_SANITY_SUCCESS, + CHECK_SANITY_FAILURE = _CHECK_SANITY_FAILURE, + REPOSITORY_RECOVERED_SUCCESS = _REPOSITORY_RECOVERED_SUCCESS, + REPOSITORY_RECOVERED_FAILURE = _REPOSITORY_RECOVERED_FAILURE, + CLONE_REPOSITORY = _CLONE_REPOSITORY, + CLONE_REPOSITORY_SUCCESS = _CLONE_REPOSITORY_SUCCESS, + CLONE_REPOSITORY_FAILURE = _CLONE_REPOSITORY_FAILURE, + CHECKOUT_REPOSITORY = _CHECKOUT_REPOSITORY, + CHECKOUT_REPOSITORY_SUCCESS = _CHECKOUT_REPOSITORY_SUCCESS, + CHECKOUT_REPOSITORY_FAILURE = _CHECKOUT_REPOSITORY_FAILURE, + CHECK_ISMAS_TRIGGER = _CHECK_ISMAS_TRIGGER, + CHECK_ISMAS_TRIGGER_WRONG_VALUE = _CHECK_ISMAS_TRIGGER_WRONG_VALUE, + CHECK_ISMAS_TRIGGER_SUCCESS = _CHECK_ISMAS_TRIGGER_SUCCESS, + CHECK_ISMAS_TRIGGER_FAILURE = _CHECK_ISMAS_TRIGGER_FAILURE, + INITIAL_CLONE_WITHOUT_ACTIVE_ISMAS_TRIGGER = _INITIAL_CLONE_WITHOUT_ACTIVE_ISMAS_TRIGGER, + INITIAL_CLONE_WITH_ACTIVE_ISMAS_TRIGGER = _INITIAL_CLONE_WITH_ACTIVE_ISMAS_TRIGGER, + CHECKOUT_BRANCH = _CHECKOUT_BRANCH, + CHECKOUT_BRANCH_SUCCESS = _CHECKOUT_BRANCH_SUCCESS, + CHECKOUT_BRANCH_FAILURE = _CHECKOUT_BRANCH_FAILURE, + UPDATE_REPOSITORY = _UPDATE_REPOSITORY, + UPDATE_REPOSITORY_SUCCESS = _UPDATE_REPOSITORY_SUCCESS, + UPDATE_REPOSITORY_FAILURE = _UPDATE_REPOSITORY_FAILURE, + CHECK_FOR_REPOSITORY_CHANGES = _CHECK_FOR_REPOSITORY_CHANGES, + CHECK_FOR_REPOSITORY_CHANGES_SUCCESS = _CHECK_FOR_REPOSITORY_CHANGES_SUCCESS, + CHECK_FOR_REPOSITORY_CHANGES_FAILURE = _CHECK_FOR_REPOSITORY_CHANGES_FAILURE, + FILES_TO_UPDATE = _FILES_TO_UPDATE, + DOWNLOAD_FILES_TO_PSA_HARDWARE = _DOWNLOAD_FILES_TO_PSA_HARDWARE, + FILES_TO_DOWNLOAD = _FILES_TO_DOWNLOAD, + EXEC_OPKG_COMMANDS = _EXEC_OPKG_COMMANDS, + EXEC_OPKG_COMMAND_1 = _EXEC_OPKG_COMMAND_1, + EXEC_OPKG_COMMAND_2 = _EXEC_OPKG_COMMAND_2, + EXEC_OPKG_COMMAND_3 = _EXEC_OPKG_COMMAND_3, + EXEC_OPKG_COMMAND_4 = _EXEC_OPKG_COMMAND_4, + EXEC_OPKG_COMMAND_5 = _EXEC_OPKG_COMMAND_5, + EXEC_OPKG_COMMAND_6 = _EXEC_OPKG_COMMAND_6, + EXEC_OPKG_COMMAND_7 = _EXEC_OPKG_COMMAND_7, + EXEC_OPKG_COMMAND_8 = _EXEC_OPKG_COMMAND_8, + EXEC_OPKG_COMMAND_9 = _EXEC_OPKG_COMMAND_9, + EXEC_OPKG_COMMAND_LAST = _EXEC_OPKG_COMMAND_LAST, + EXEC_OPKG_COMMAND_SUCCESS = _EXEC_OPKG_COMMAND_SUCCESS, + EXEC_OPKG_COMMAND_FAILURE = _EXEC_OPKG_COMMAND_FAILURE, + DOWNLOAD_CONFIG_FILE = _DOWNLOAD_CONFIG_FILE, + DOWNLOAD_CONFIG_FILE_SUCCESS = _DOWNLOAD_CONFIG_FILE_SUCCESS, + DOWNLOAD_CONFIG_FILE_FAILURE = _DOWNLOAD_CONFIG_FILE_FAILURE, + DOWNLOAD_DEVICE_CONTROLLER = _DOWNLOAD_DEVICE_CONTROLLER, + DOWNLOAD_DEVICE_CONTROLLER_SUCCESS = _DOWNLOAD_DEVICE_CONTROLLER_SUCCESS, + DOWNLOAD_DEVICE_CONTROLLER_FAILURE = _DOWNLOAD_DEVICE_CONTROLLER_FAILURE, + DOWNLOAD_FILES_TO_PSA_HARDWARE_SUCCESS = _DOWNLOAD_FILES_TO_PSA_HARDWARE_SUCCESS, + DOWNLOAD_FILES_TO_PSA_HARDWARE_FAILURE = _DOWNLOAD_FILES_TO_PSA_HARDWARE_FAILURE, + SYNC_CUSTOMER_REPOSITORY = _SYNC_CUSTOMER_REPOSITORY, + SYNC_CUSTOMER_REPOSITORY_SUCCESS = _SYNC_CUSTOMER_REPOSITORY_SUCCESS, + SYNC_CUSTOMER_REPOSITORY_FAILURE = _SYNC_CUSTOMER_REPOSITORY_FAILURE, + SAVE_LOGS = _SAVE_LOGS, + SAVE_LOGS_SUCCESS = _SAVE_LOGS_SUCCESS, + SAVE_LOGS_FAILURE = _SAVE_LOGS_FAILURE, + SEND_LAST_VERSION = _SEND_LAST_VERSION, + UPDATE_SUCCEEDED = _UPDATE_SUCCEEDED, + UPDATE_ACTIVATED = _UPDATE_ACTIVATED, + UPDATE_FAILED = _UPDATE_FAILED, + FINISHED = _FINISHED, + DEBUG = _DEBUG, + ERROR = _ERROR + }; + +private: + QStringList m_debugMsg; + QStringList m_guiMsg; + QStringList m_ismasMsg; + UPDATE_STEP m_currentStep; + static Worker *instance; + QStringList m_opkgCommands; + Update *m_update = nullptr; + +protected: + virtual void run(); + +public: + QDebug CONSOLE(QStringList const &lst = QStringList()) { + m_debugMsg = lst; + return QDebug(QtMsgType::QtInfoMsg); + } + + IsmasClient &ISMAS(QStringList const &lst = QStringList()) { + m_ismasMsg = lst; + return m_ismasClient; + } + + Worker *GUI(QStringList const &lst = QStringList()) { + m_guiMsg = lst; + return this; + } + + static QMap const &getSmap() { + return smap; + } + + static QString getATBUpdateToolYoctoVersion(); + static QString getATBUpdateToolYoctoInstallationStatus(); + static QString getAPISMYoctoVersion(); + static QString getAPISMYoctoInstallationStatus(); + static const QString UPDATE_STEP_OK; static const QString UPDATE_STEP_DONE; static const QString UPDATE_STEP_FAIL; + static const QString UPDATE_STEP_WRONG; static const QString UPDATE_STEP_SUCCESS; explicit Worker(int customerNr, // 281 int machineNr, int zoneNr, + QString repositoryUrl, QString branchName, + QString pluginDir, QString pluginName, QString workingDir = ".", + bool noUpdatePsaHardware = false, + bool alwaysDownloadConfig = false, + bool alwaysDownloadDC = false, bool dryRun = false, QObject *parent = nullptr, char const *serialInterface = SERIAL_PORT, @@ -146,9 +342,8 @@ public: ~Worker(); void setMainWindow(MainWindow *mainWindow) { m_mainWindow = mainWindow; } - hwinf *getPlugin(); - hwinf const *getPlugin() const; void setProgress(int progress); + void displayProgressInMainWindow(int progress); void startProgressLoop(); void stopProgressLoop(); @@ -156,24 +351,19 @@ public: IsmasClient const &getIsmasClient() const { return m_ismasClient; } bool updateProcessRunning() const { return m_updateProcessRunning; } - int returnCode() const { return m_returnCode; } + UPDATE_STEP currentStep() const { return m_currentStep; } int machineNr() const { return m_machineNr; } int customerNr() const { return m_customerNr; } int zoneNr() const { return m_zoneNr; } QString apismVersion() const { return m_apismVersion; } + QString atbUpdateToolVersion() const { return m_atbUpdateToolVersion; } MainWindow *mainWindow() { return m_mainWindow; } MainWindow const *mainWindow() const { return m_mainWindow; } - //friend QDebug operator<<(QDebug debug, Worker const &w) { - // Q_UNUSED(w); - // return debug; - //} - //friend QString& operator<<(QString &str, Worker const &w) { - // Q_UNUSED(w); - // return str; - //} + Update *update() { return m_update; } + Update const *update() const { return m_update; } signals: void appendText(QString, QString suffix = ""); @@ -181,27 +371,910 @@ signals: void replaceLast(QStringList, QString); void showErrorMessage(QString title, QString description); void showStatusMessage(QString title, QString description); + void showErrorMessage(QStringList titleAndDesc); + void showStatusMessage(QStringList titleAndDesc); void stopStartTimer(); void restartExitTimer(); void enableExit(); void disableExit(); -public slots: - void update(); - private slots: bool updateTriggerSet(); bool customerEnvironment(); bool filesToUpdate(); - bool updateFiles(quint8 percent); + bool downloadFilesToPSAHardware(); bool syncCustomerRepositoryAndFS(); - bool sendIsmasLastVersionNotification(); + // bool sendIsmasLastVersionNotification(int progress); bool saveLogFile(); private: PSAInstalled getPSAInstalled(); void privateUpdate(); - std::optional getApismVersion(); + bool computeFilesToDownload(); + bool execOpkgCommands(); + + static const QMap smap; + + // CONSOLE() + friend UPDATE_STEP operator<<(QDebug debug, UPDATE_STEP step) { + if (!Worker::instance) { + return step; + } + + Worker::instance->m_currentStep = step; + QStringList lst = QStringList(smap[step]); + + switch (step) { + case UPDATE_STEP::STARTED: { + Utils::printUpdateStatusMsg( + debug, + QStringList(smap[step]) + << QString("CURRENT TIME ...............%1").arg(QDateTime::currentDateTime().toString(Qt::ISODate)) + << QString("OS VERSION .................%1").arg(instance->m_osVersion) + << QString("ATBQT VERSION ..............%1").arg(instance->m_atbqtVersion) + << QString("CPU SERIAL .................%1").arg(instance->m_cpuSerial) + << QString("CUSTOMER_NR ................%1").arg(instance->m_customerNr) + << QString("CUSTOMER_NR_STR ............%1").arg(instance->m_customerNrStr) + << QString("CUSTOMER_REPOSITORY_PATH ...%1").arg(instance->m_customerRepositoryPath) + << QString("CUSTOMER_REPOSITORY ........%1").arg(instance->m_customerRepository) + << QString("MACHINE_NR .................%1").arg(instance->m_machineNr) + << QString("ZONE_NR ....................%1").arg(instance->m_zoneNr) + << QString("BRANCH_NAME ................%1").arg(instance->m_branchName) + << QString("PLUGIN_NAME ................%1").arg(instance->m_pluginName) + << QString("WORKING_DIRECTORY ..........%1").arg(instance->m_workingDirectory) + << QString("APISM VERSION ..............%1").arg(instance->m_apismVersion) + << QString("ATB UPDATE TOOL VERSION ....%1").arg(instance->m_atbUpdateToolVersion)); + } break; + case UPDATE_STEP::CHECK_REPOSITORY: + break; + case UPDATE_STEP::CHECK_SANITY: + Utils::printUpdateStatusMsg( + debug, + QStringList(smap[step]) + << QString("CHECK SANITY OF CUSTOMER REPOSITORY %1") + .arg(instance->m_customerRepository)); + break; + case UPDATE_STEP::CHECK_SANITY_SUCCESS: + Utils::printUpdateStatusMsg( + debug, + QStringList(smap[step]) + << QString("SANITY OF CUSTOMER REPOSITORY %1 OK") + .arg(instance->m_customerRepository)); + break; + case UPDATE_STEP::CHECK_SANITY_FAILURE: + Utils::printUpdateStatusMsg( + debug, + QStringList(smap[step]) + << QString("CORRUPTED CUSTOMER REPOSITORY %1. REPAIRING...") + .arg(instance->m_customerRepository)); + break; + case UPDATE_STEP::REPOSITORY_RECOVERED_SUCCESS: + Utils::printUpdateStatusMsg( + debug, + QStringList(smap[step]) + << QString("CORRUPTED CUSTOMER REPOSITORY %1. REPAIRING DONE") + .arg(instance->m_customerRepository)); + break; + case UPDATE_STEP::REPOSITORY_RECOVERED_FAILURE: + Utils::printUpdateStatusMsg( + debug, + QStringList(smap[step]) + << QString("CORRUPTED CUSTOMER REPOSITORY %1. REPAIRING FAILED") + .arg(instance->m_customerRepository)); + break; + case UPDATE_STEP::CHECK_REPOSITORY_SUCCESS: + break; + case UPDATE_STEP::CHECK_REPOSITORY_FAILURE: + break; + case UPDATE_STEP::CLONE_REPOSITORY: + break; + case UPDATE_STEP::CLONE_REPOSITORY_SUCCESS: + break; + case UPDATE_STEP::CLONE_REPOSITORY_FAILURE: + break; + case UPDATE_STEP::CHECKOUT_REPOSITORY: + break; + case UPDATE_STEP::CHECKOUT_REPOSITORY_SUCCESS: + break; + case UPDATE_STEP::CHECKOUT_REPOSITORY_FAILURE: + break; + case UPDATE_STEP::CHECK_ISMAS_TRIGGER: + lst << instance->m_debugMsg; + Utils::printUpdateStatusMsg(debug, lst); + break; + case UPDATE_STEP::CHECK_ISMAS_TRIGGER_SUCCESS: + break; + case UPDATE_STEP::CHECK_ISMAS_TRIGGER_WRONG_VALUE: + lst << instance->m_debugMsg; + Utils::printUpdateStatusMsg(debug, lst); + break; + case UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE: { + lst << instance->m_debugMsg; + Utils::printUpdateStatusMsg(debug, lst); + } break; + case UPDATE_STEP::INITIAL_CLONE_WITHOUT_ACTIVE_ISMAS_TRIGGER: + break; + case UPDATE_STEP::INITIAL_CLONE_WITH_ACTIVE_ISMAS_TRIGGER: + break; + case UPDATE_STEP::CHECKOUT_BRANCH: + lst << instance->m_debugMsg; + Utils::printUpdateStatusMsg(debug, lst); + break; + case UPDATE_STEP::CHECKOUT_BRANCH_SUCCESS: + lst << instance->m_debugMsg; + Utils::printUpdateStatusMsg(debug, lst); + break; + case UPDATE_STEP::CHECKOUT_BRANCH_FAILURE: + lst << instance->m_debugMsg; + Utils::printUpdateStatusMsg(debug, lst); + break; + case UPDATE_STEP::UPDATE_REPOSITORY: + break; + case UPDATE_STEP::UPDATE_REPOSITORY_SUCCESS: + break; + case UPDATE_STEP::UPDATE_REPOSITORY_FAILURE: + break; + case UPDATE_STEP::CHECK_FOR_REPOSITORY_CHANGES: + break; + case UPDATE_STEP::CHECK_FOR_REPOSITORY_CHANGES_SUCCESS: + break; + case UPDATE_STEP::CHECK_FOR_REPOSITORY_CHANGES_FAILURE: + break; + case UPDATE_STEP::FILES_TO_UPDATE: { + lst << instance->m_debugMsg; + Utils::printUpdateStatusMsg(debug, lst); + } break; + case UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE: { + lst << instance->m_debugMsg; + Utils::printUpdateStatusMsg(debug, lst); + } break; + case UPDATE_STEP::FILES_TO_DOWNLOAD: + break; + case UPDATE_STEP::EXEC_OPKG_COMMANDS: + break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_1: + __attribute__((fallthrough)); + // [[fallthrough]] -> c++17 -> unknown for clang + case UPDATE_STEP::EXEC_OPKG_COMMAND_2: + __attribute__((fallthrough)); + case UPDATE_STEP::EXEC_OPKG_COMMAND_3: + __attribute__((fallthrough)); + case UPDATE_STEP::EXEC_OPKG_COMMAND_4: + __attribute__((fallthrough)); + case UPDATE_STEP::EXEC_OPKG_COMMAND_5: + __attribute__((fallthrough)); + case UPDATE_STEP::EXEC_OPKG_COMMAND_6: + __attribute__((fallthrough)); + case UPDATE_STEP::EXEC_OPKG_COMMAND_7: + __attribute__((fallthrough)); + case UPDATE_STEP::EXEC_OPKG_COMMAND_8: + __attribute__((fallthrough)); + case UPDATE_STEP::EXEC_OPKG_COMMAND_9: + __attribute__((fallthrough)); + case UPDATE_STEP::EXEC_OPKG_COMMAND_LAST: + lst << instance->m_debugMsg; + Utils::printUpdateStatusMsg(debug, lst); + break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_SUCCESS: + break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_FAILURE: + break; + case UPDATE_STEP::DOWNLOAD_CONFIG_FILE: + break; + case UPDATE_STEP::DOWNLOAD_CONFIG_FILE_SUCCESS: + break; + case UPDATE_STEP::DOWNLOAD_CONFIG_FILE_FAILURE: + break; + case UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER: + lst << instance->m_debugMsg; + Utils::printUpdateStatusMsg(debug, lst); + break; + case UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER_SUCCESS: + lst << instance->m_debugMsg; + Utils::printUpdateStatusMsg(debug, lst); + break; + case UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER_FAILURE: + lst << instance->m_debugMsg; + Utils::printUpdateStatusMsg(debug, lst); + break; + case UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE_SUCCESS: + lst << instance->m_debugMsg; + Utils::printUpdateStatusMsg(debug, lst); + break; + case UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE_FAILURE: + break; + case UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY: + break; + case UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_SUCCESS: + lst << instance->m_debugMsg; + Utils::printUpdateStatusMsg(debug, lst); + break; + case UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_FAILURE: + break; + case UPDATE_STEP::SAVE_LOGS: + break; + case UPDATE_STEP::SAVE_LOGS_SUCCESS: + lst << instance->m_debugMsg; + Utils::printUpdateStatusMsg(debug, lst); + break; + case UPDATE_STEP::SAVE_LOGS_FAILURE: + break; + case UPDATE_STEP::SEND_LAST_VERSION: + // SEND_LAST_VERSION_CORRECTION + break; + case UPDATE_STEP::UPDATE_SUCCEEDED: + lst << instance->m_debugMsg; + Utils::printUpdateStatusMsg(debug, lst); + break; + case UPDATE_STEP::UPDATE_ACTIVATED: + lst << instance->m_debugMsg; + Utils::printUpdateStatusMsg(debug, lst); + break; + case UPDATE_STEP::UPDATE_FAILED: + break; + case UPDATE_STEP::FINISHED: + lst << instance->m_debugMsg; + Utils::printUpdateStatusMsg(debug, lst); + break; + case UPDATE_STEP::DEBUG: { + lst << instance->m_debugMsg; + qCritical() << __LINE__ << lst; + Utils::printUpdateStatusMsg(debug, lst); + } break; + case UPDATE_STEP::ERROR: + //Utils::printUpdateStatusMsg( + // debug, QStringList(smap[step]) << instance->m_errorMsg); + break; + } + + instance->m_debugMsg.clear(); + + return step; + } + + // ISMAS() + friend UPDATE_STEP operator<<(IsmasClient &ismasClient, UPDATE_STEP step) { + + if (!Worker::instance) { + return step; + } + + Worker::instance->m_currentStep = step; + QStringList lst = QStringList(smap[step]); + + switch (step) { + case UPDATE_STEP::STARTED: { + ismasClient.setProgressInPercent(_STARTED); + } break; + case UPDATE_STEP::CHECK_REPOSITORY: + ismasClient.setProgressInPercent(_CHECK_REPOSITORY); + break; + case UPDATE_STEP::CHECK_REPOSITORY_SUCCESS: + break; + case UPDATE_STEP::CHECK_REPOSITORY_FAILURE: + break; + case UPDATE_STEP::CHECK_SANITY: + ismasClient.setProgressInPercent(_CHECK_SANITY); + break; + case UPDATE_STEP::CHECK_SANITY_SUCCESS: + ismasClient.setProgressInPercent(_CHECK_SANITY_SUCCESS); + break; + case UPDATE_STEP::CHECK_SANITY_FAILURE: + ismasClient.setProgressInPercent(_CHECK_SANITY_FAILURE); + break; + case UPDATE_STEP::REPOSITORY_RECOVERED_SUCCESS: + break; + case UPDATE_STEP::REPOSITORY_RECOVERED_FAILURE: + break; + case UPDATE_STEP::CLONE_REPOSITORY: + ismasClient.setProgressInPercent(_CLONE_REPOSITORY); + break; + case UPDATE_STEP::CLONE_REPOSITORY_SUCCESS: { + ismasClient.setProgressInPercent(_CLONE_REPOSITORY_SUCCESS); + QString const &ismasUpdateNews = + QString("#M=APISM#C=CMD_EVENT#J=") + + ismasClient.updateNewsToIsmas( + "U0010", + _CLONE_REPOSITORY_SUCCESS, + IsmasClient::RESULT_CODE::SUCCESS, + smap[step], + QString("CLONED REPOSITORY %1 AND CHECKED OUT BRANCH %2") + .arg(instance->m_customerRepository) + .arg(instance->m_gc.branchName()).toStdString().c_str(), + ""); + ismasClient.sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, + ismasUpdateNews); + } break; + case UPDATE_STEP::CLONE_REPOSITORY_FAILURE: { + ismasClient.setProgressInPercent(_CLONE_REPOSITORY_FAILURE); + QString const &ismasUpdateNews = + QString("#M=APISM#C=CMD_EVENT#J=") + + ismasClient.updateNewsToIsmas( + "U0003", + _CLONE_REPOSITORY_FAILURE, + IsmasClient::RESULT_CODE::INSTALL_ERROR, + smap[step], + QString("CLONING REPOSITORY %1 OR CHECKING OUT BRANCH %2 FAILED") + .arg(instance->m_customerRepository) + .arg(instance->m_gc.branchName()).toStdString().c_str(), + ""); + ismasClient.sendRequestReceiveResponse( + IsmasClient::APISM::DB_PORT, ismasUpdateNews); + } break; + case UPDATE_STEP::CHECKOUT_REPOSITORY: + ismasClient.setProgressInPercent(_CHECKOUT_REPOSITORY); + break; + case UPDATE_STEP::CHECKOUT_REPOSITORY_SUCCESS: + ismasClient.setProgressInPercent(_CHECKOUT_REPOSITORY_SUCCESS); + ismasClient.sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, + QString("#M=APISM#C=CMD_EVENT#J=") + + ismasClient.cloneAndCheckoutCustomerRepository( + QString("CHECKED OUT REPOSITORY %1 AND CHECKED OUT BRANCH %2") + .arg(instance->m_customerRepository) + .arg(instance->m_gc.branchName()))); + break; + case UPDATE_STEP::CHECKOUT_REPOSITORY_FAILURE: + ismasClient.setProgressInPercent(_CHECKOUT_REPOSITORY_FAILURE); + break; + case UPDATE_STEP::CHECK_ISMAS_TRIGGER: + ismasClient.setProgressInPercent(_CHECK_ISMAS_TRIGGER); + break; + case UPDATE_STEP::CHECK_ISMAS_TRIGGER_SUCCESS: + ismasClient.setProgressInPercent(_CHECK_ISMAS_TRIGGER_SUCCESS); + ismasClient.sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, + QString("#M=APISM#C=CMD_EVENT#J=") + + ismasClient.updateTriggerSet("ISMAS TRIGGER SET", "")); + break; + case UPDATE_STEP::CHECK_ISMAS_TRIGGER_WRONG_VALUE: + ismasClient.setProgressInPercent(_CHECK_ISMAS_TRIGGER_WRONG_VALUE); + break; + case UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE: { + ismasClient.setProgressInPercent(_CHECK_ISMAS_TRIGGER_FAILURE); + QString const &ismasUpdateNews = + QString("#M=APISM#C=CMD_EVENT#J=") + + ismasClient.updateNewsToIsmas( + "U0003", + _CHECK_ISMAS_TRIGGER_FAILURE, + IsmasClient::RESULT_CODE::INSTALL_ERROR, + smap[step], + instance->m_ismasMsg.join(' ').toStdString().c_str(), + ""); + ismasClient.sendRequestReceiveResponse( + IsmasClient::APISM::DB_PORT, ismasUpdateNews); + } break; + case UPDATE_STEP::INITIAL_CLONE_WITHOUT_ACTIVE_ISMAS_TRIGGER: + ismasClient.setProgressInPercent(_INITIAL_CLONE_WITHOUT_ACTIVE_ISMAS_TRIGGER); + break; + case UPDATE_STEP::INITIAL_CLONE_WITH_ACTIVE_ISMAS_TRIGGER: + ismasClient.setProgressInPercent(_INITIAL_CLONE_WITH_ACTIVE_ISMAS_TRIGGER); + break; + case UPDATE_STEP::CHECKOUT_BRANCH: + ismasClient.setProgressInPercent(_CHECKOUT_BRANCH); + break; + case UPDATE_STEP::CHECKOUT_BRANCH_SUCCESS: { + ismasClient.setProgressInPercent(_CHECKOUT_BRANCH_SUCCESS); + QString const &ismasUpdateNews = + QString("#M=APISM#C=CMD_EVENT#J=") + + ismasClient.updateNewsToIsmas( + "U0010", + _CHECKOUT_BRANCH_SUCCESS, + IsmasClient::RESULT_CODE::SUCCESS, + smap[step], + instance->m_ismasMsg.join(' ').toStdString().c_str(), + ""); + ismasClient.sendRequestReceiveResponse( + IsmasClient::APISM::DB_PORT, ismasUpdateNews); + } break; + case UPDATE_STEP::CHECKOUT_BRANCH_FAILURE: { + ismasClient.setProgressInPercent(_CHECKOUT_BRANCH_FAILURE); + QString const &ismasUpdateNews = + QString("#M=APISM#C=CMD_EVENT#J=") + + ismasClient.updateNewsToIsmas( + "U0003", + _CHECKOUT_BRANCH_FAILURE, + IsmasClient::RESULT_CODE::INSTALL_ERROR, + smap[step], + instance->m_ismasMsg.join(' ').toStdString().c_str(), + ""); + ismasClient.sendRequestReceiveResponse( + IsmasClient::APISM::DB_PORT, ismasUpdateNews); + } break; + case UPDATE_STEP::UPDATE_REPOSITORY: + ismasClient.setProgressInPercent(_UPDATE_REPOSITORY); + break; + case UPDATE_STEP::UPDATE_REPOSITORY_SUCCESS: + ismasClient.setProgressInPercent(_UPDATE_REPOSITORY_SUCCESS); + break; + case UPDATE_STEP::UPDATE_REPOSITORY_FAILURE: + ismasClient.setProgressInPercent(_UPDATE_REPOSITORY_FAILURE); + break; + case UPDATE_STEP::CHECK_FOR_REPOSITORY_CHANGES: + ismasClient.setProgressInPercent(_CHECK_FOR_REPOSITORY_CHANGES); + break; + case UPDATE_STEP::CHECK_FOR_REPOSITORY_CHANGES_SUCCESS: + ismasClient.setProgressInPercent(_CHECK_FOR_REPOSITORY_CHANGES_SUCCESS); + break; + case UPDATE_STEP::CHECK_FOR_REPOSITORY_CHANGES_FAILURE: + ismasClient.setProgressInPercent(_CHECK_FOR_REPOSITORY_CHANGES_FAILURE); + break; + case UPDATE_STEP::FILES_TO_UPDATE: + ismasClient.setProgressInPercent(_FILES_TO_UPDATE); + break; + case UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE: + ismasClient.setProgressInPercent(_DOWNLOAD_FILES_TO_PSA_HARDWARE); + break; + case UPDATE_STEP::FILES_TO_DOWNLOAD: + ismasClient.setProgressInPercent(_FILES_TO_DOWNLOAD); + break; + case UPDATE_STEP::EXEC_OPKG_COMMANDS: + ismasClient.setProgressInPercent(_EXEC_OPKG_COMMANDS); + break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_1: + ismasClient.setProgressInPercent(_EXEC_OPKG_COMMAND_1); + __attribute__((fallthrough)); // [[fallthrough]]; -> c++17, unknown to clang + case UPDATE_STEP::EXEC_OPKG_COMMAND_2: { + switch(step) { + case UPDATE_STEP::EXEC_OPKG_COMMAND_1: break; + default: ismasClient.setProgressInPercent(_EXEC_OPKG_COMMAND_2); + } __attribute__((fallthrough)); + } + case UPDATE_STEP::EXEC_OPKG_COMMAND_3: { + switch(step) { + case UPDATE_STEP::EXEC_OPKG_COMMAND_1: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_2: break; + default: ismasClient.setProgressInPercent(_EXEC_OPKG_COMMAND_3); + } __attribute__((fallthrough)); + } + case UPDATE_STEP::EXEC_OPKG_COMMAND_4: { + switch(step) { + case UPDATE_STEP::EXEC_OPKG_COMMAND_1: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_2: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_3: break; + default: ismasClient.setProgressInPercent(_EXEC_OPKG_COMMAND_4); + } __attribute__((fallthrough)); + } + case UPDATE_STEP::EXEC_OPKG_COMMAND_5: { + switch(step) { + case UPDATE_STEP::EXEC_OPKG_COMMAND_1: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_2: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_3: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_4: break; + default: ismasClient.setProgressInPercent(_EXEC_OPKG_COMMAND_5); + } __attribute__((fallthrough)); + } + case UPDATE_STEP::EXEC_OPKG_COMMAND_6: { + switch(step) { + case UPDATE_STEP::EXEC_OPKG_COMMAND_1: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_2: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_3: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_4: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_5: break; + default: ismasClient.setProgressInPercent(_EXEC_OPKG_COMMAND_6); + } __attribute__((fallthrough)); + } + case UPDATE_STEP::EXEC_OPKG_COMMAND_7: { + switch(step) { + case UPDATE_STEP::EXEC_OPKG_COMMAND_1: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_2: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_3: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_4: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_5: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_6: break; + default: ismasClient.setProgressInPercent(_EXEC_OPKG_COMMAND_7); + } __attribute__((fallthrough)); + } + case UPDATE_STEP::EXEC_OPKG_COMMAND_8: { + switch(step) { + case UPDATE_STEP::EXEC_OPKG_COMMAND_1: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_2: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_3: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_4: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_5: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_6: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_7: break; + default: ismasClient.setProgressInPercent(_EXEC_OPKG_COMMAND_8); + } __attribute__((fallthrough)); + } + case UPDATE_STEP::EXEC_OPKG_COMMAND_9: { + switch(step) { + case UPDATE_STEP::EXEC_OPKG_COMMAND_1: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_2: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_3: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_4: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_5: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_6: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_7: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_8: break; + default: ismasClient.setProgressInPercent(_EXEC_OPKG_COMMAND_9); + } __attribute__((fallthrough)); + } + case UPDATE_STEP::EXEC_OPKG_COMMAND_LAST: { + switch(step) { + case UPDATE_STEP::EXEC_OPKG_COMMAND_1: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_2: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_3: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_4: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_5: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_6: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_7: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_8: break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_9: break; + default: ismasClient.setProgressInPercent(_EXEC_OPKG_COMMAND_LAST); + } + QString const &ismasUpdateNews = + QString("#M=APISM#C=CMD_EVENT#J=") + + ismasClient.updateNewsToIsmas( + _ISMAS_CONTINUE, + ismasClient.getProgressInPercent(), + IsmasClient::RESULT_CODE::SUCCESS, + smap[step], + instance->m_ismasMsg.join(' ').toStdString().c_str(), + ""); + ismasClient.sendRequestReceiveResponse( + IsmasClient::APISM::DB_PORT, ismasUpdateNews); + } break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_SUCCESS: { + ismasClient.setProgressInPercent(_EXEC_OPKG_COMMAND_SUCCESS); + } break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_FAILURE: { + ismasClient.setProgressInPercent(_EXEC_OPKG_COMMAND_FAILURE); + QString const &ismasUpdateNews = + QString("#M=APISM#C=CMD_EVENT#J=") + + ismasClient.updateNewsToIsmas( + _ISMAS_FAILURE, + ismasClient.getProgressInPercent(), + IsmasClient::RESULT_CODE::INSTALL_ERROR, + smap[step], + instance->m_ismasMsg.join(' ').toStdString().c_str(), + ""); + ismasClient.sendRequestReceiveResponse( + IsmasClient::APISM::DB_PORT, ismasUpdateNews); + } break; + case UPDATE_STEP::DOWNLOAD_CONFIG_FILE: + ismasClient.setProgressInPercent(_DOWNLOAD_CONFIG_FILE); + break; + case UPDATE_STEP::DOWNLOAD_CONFIG_FILE_SUCCESS: + ismasClient.setProgressInPercent(_DOWNLOAD_CONFIG_FILE_SUCCESS); + break; + case UPDATE_STEP::DOWNLOAD_CONFIG_FILE_FAILURE: + ismasClient.setProgressInPercent(_DOWNLOAD_CONFIG_FILE_FAILURE); + break; + case UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER: + ismasClient.setProgressInPercent(_DOWNLOAD_DEVICE_CONTROLLER); + break; + case UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER_SUCCESS: { + ismasClient.setProgressInPercent(_DOWNLOAD_DEVICE_CONTROLLER_SUCCESS); + QString const &ismasUpdateNews = + QString("#M=APISM#C=CMD_EVENT#J=") + + ismasClient.updateNewsToIsmas( + _ISMAS_CONTINUE, + ismasClient.getProgressInPercent(), + IsmasClient::RESULT_CODE::SUCCESS, + smap[step], + instance->m_ismasMsg.join(' ').toStdString().c_str(), + ""); + ismasClient.sendRequestReceiveResponse( + IsmasClient::APISM::DB_PORT, ismasUpdateNews); + } break; + case UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER_FAILURE: + ismasClient.setProgressInPercent(_DOWNLOAD_DEVICE_CONTROLLER_FAILURE); + break; + case UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE_SUCCESS: { + ismasClient.setProgressInPercent(_DOWNLOAD_FILES_TO_PSA_HARDWARE_SUCCESS); + QString const &ismasUpdateNews = + QString("#M=APISM#C=CMD_EVENT#J=") + + ismasClient.updateNewsToIsmas( + _ISMAS_CONTINUE, + ismasClient.getProgressInPercent(), + IsmasClient::RESULT_CODE::SUCCESS, + smap[step], + instance->m_ismasMsg.join(' ').toStdString().c_str(), + ""); + ismasClient.sendRequestReceiveResponse( + IsmasClient::APISM::DB_PORT, ismasUpdateNews); + } break; + case UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE_FAILURE: + ismasClient.setProgressInPercent(_DOWNLOAD_FILES_TO_PSA_HARDWARE_FAILURE); + break; + case UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY: + ismasClient.setProgressInPercent(_SYNC_CUSTOMER_REPOSITORY); + break; + case UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_SUCCESS: { + ismasClient.setProgressInPercent(_SYNC_CUSTOMER_REPOSITORY_SUCCESS); + QString const &ismasUpdateNews = + QString("#M=APISM#C=CMD_EVENT#J=") + + ismasClient.updateNewsToIsmas( + _ISMAS_CONTINUE, + ismasClient.getProgressInPercent(), + IsmasClient::RESULT_CODE::SUCCESS, + smap[step], + instance->m_ismasMsg.join(' ').toStdString().c_str(), + ""); + ismasClient.sendRequestReceiveResponse( + IsmasClient::APISM::DB_PORT, ismasUpdateNews); + } break; + case UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_FAILURE: + ismasClient.setProgressInPercent(_SYNC_CUSTOMER_REPOSITORY_FAILURE); + break; + case UPDATE_STEP::SAVE_LOGS: + ismasClient.setProgressInPercent(_SAVE_LOGS); + break; + case UPDATE_STEP::SAVE_LOGS_SUCCESS: { + ismasClient.setProgressInPercent(_SAVE_LOGS_SUCCESS); + QString const &ismasUpdateNews = + QString("#M=APISM#C=CMD_EVENT#J=") + + ismasClient.updateNewsToIsmas( + _ISMAS_CONTINUE, + ismasClient.getProgressInPercent(), + IsmasClient::RESULT_CODE::SUCCESS, + smap[step], + instance->m_ismasMsg.join(' ').toStdString().c_str(), + ""); + ismasClient.sendRequestReceiveResponse( + IsmasClient::APISM::DB_PORT, ismasUpdateNews); + } break; + case UPDATE_STEP::SAVE_LOGS_FAILURE: + ismasClient.setProgressInPercent(_SAVE_LOGS_FAILURE); + break; + case UPDATE_STEP::SEND_LAST_VERSION: { + ismasClient.setProgressInPercent(_SEND_LAST_VERSION + _SEND_LAST_VERSION_CORRECTION); + ismasClient.sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, + QString("#M=APISM#C=CMD_SENDVERSION#J=") + + ismasClient.updateOfPSASendVersion(instance->getPSAInstalled())); + } break; + case UPDATE_STEP::UPDATE_SUCCEEDED: { + ismasClient.setProgressInPercent(_UPDATE_SUCCEEDED + _UPDATE_SUCCEEDED_CORRECTION); + QString const &ismasUpdateNews = + QString("#M=APISM#C=CMD_EVENT#J=") + + ismasClient.updateNewsToIsmas( + "U0001", // WAIT-button set to 100% + ismasClient.getProgressInPercent(), + IsmasClient::RESULT_CODE::SUCCESS, + smap[step], + instance->m_ismasMsg.join(' ').toStdString().c_str(), + ""); + ismasClient.sendRequestReceiveResponse( + IsmasClient::APISM::DB_PORT, ismasUpdateNews); + } break; + case UPDATE_STEP::UPDATE_ACTIVATED: { + ismasClient.setProgressInPercent(_UPDATE_ACTIVATED + _UPDATE_ACTIVATED_CORRECTION); + QString const &ismasUpdateNews = + QString("#M=APISM#C=CMD_EVENT#J=") + + ismasClient.updateNewsToIsmas( + "U0002", // reset WAIT-button to "" (empty string) + ismasClient.getProgressInPercent(), + IsmasClient::RESULT_CODE::SUCCESS, + smap[step], + instance->m_ismasMsg.join(' ').toStdString().c_str(), + ""); + ismasClient.sendRequestReceiveResponse( + IsmasClient::APISM::DB_PORT, ismasUpdateNews); + } break; + case UPDATE_STEP::UPDATE_FAILED: { + ismasClient.setProgressInPercent(_UPDATE_FAILED); + QString const &ismasUpdateNews = + QString("#M=APISM#C=CMD_EVENT#J=") + + ismasClient.updateNewsToIsmas( + "U0003", + ismasClient.getProgressInPercent(), + IsmasClient::RESULT_CODE::INSTALL_ERROR, + smap[step], + instance->m_ismasMsg.join(' ').toStdString().c_str(), + ""); + ismasClient.sendRequestReceiveResponse( + IsmasClient::APISM::DB_PORT, ismasUpdateNews); + } break; + case UPDATE_STEP::FINISHED: + ismasClient.setProgressInPercent(_FINISHED); + break; + case UPDATE_STEP::DEBUG: + break; + case UPDATE_STEP::ERROR: + break; + } + + instance->m_ismasMsg.clear(); + + return step; + } + + // GUI() + friend UPDATE_STEP operator<<(Worker *worker, UPDATE_STEP step) { + if (!Worker::instance) { + return step; + } + + Worker::instance->m_currentStep = step; + + switch (step) { + case UPDATE_STEP::STARTED: + break; + case UPDATE_STEP::CHECK_REPOSITORY: + emit worker->appendText("\nInitializing customer environment ..."); + break; + case UPDATE_STEP::CHECK_SANITY: + break; + case UPDATE_STEP::CHECK_SANITY_SUCCESS: + break; + case UPDATE_STEP::CHECK_SANITY_FAILURE: + break; + case UPDATE_STEP::REPOSITORY_RECOVERED_SUCCESS: + break; + case UPDATE_STEP::REPOSITORY_RECOVERED_FAILURE: + break; + case UPDATE_STEP::CHECK_REPOSITORY_SUCCESS: + break; + case UPDATE_STEP::CHECK_REPOSITORY_FAILURE: + break; + case UPDATE_STEP::CLONE_REPOSITORY: + emit worker->appendText("\nInitializing customer environment ..."); + break; + case UPDATE_STEP::CLONE_REPOSITORY_SUCCESS: + emit worker->replaceLast("Initializing customer environment", + Worker::UPDATE_STEP_DONE); + break; + case UPDATE_STEP::CLONE_REPOSITORY_FAILURE: + emit worker->replaceLast("Initializing customer environment", + Worker::UPDATE_STEP_FAIL); + break; + case UPDATE_STEP::CHECKOUT_REPOSITORY: + break; + case UPDATE_STEP::CHECKOUT_REPOSITORY_SUCCESS: + break; + case UPDATE_STEP::CHECKOUT_REPOSITORY_FAILURE: + break; + case UPDATE_STEP::CHECK_ISMAS_TRIGGER: + emit worker->appendText("\n" CHECK_UPDATE_TRIGGER_SET); + break; + case UPDATE_STEP::CHECK_ISMAS_TRIGGER_SUCCESS: + break; + case UPDATE_STEP::CHECK_ISMAS_TRIGGER_WRONG_VALUE: + emit worker->replaceLast(CHECK_UPDATE_TRIGGER_SET, UPDATE_STEP_WRONG); + emit worker->showErrorMessage(worker->m_guiMsg); + break; + case UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE: + emit worker->replaceLast(CHECK_UPDATE_TRIGGER_SET, UPDATE_STEP_FAIL); + emit worker->showErrorMessage(worker->m_guiMsg); + break; + case UPDATE_STEP::INITIAL_CLONE_WITHOUT_ACTIVE_ISMAS_TRIGGER: + break; + case UPDATE_STEP::INITIAL_CLONE_WITH_ACTIVE_ISMAS_TRIGGER: + break; + case UPDATE_STEP::CHECKOUT_BRANCH: + emit worker->appendText("\nPrepare customer environment ..."); + break; + case UPDATE_STEP::CHECKOUT_BRANCH_SUCCESS: + emit worker->replaceLast("Prepare customer environment ...", UPDATE_STEP_DONE); + break; + case UPDATE_STEP::CHECKOUT_BRANCH_FAILURE: + emit worker->replaceLast("Prepare customer environment ...", UPDATE_STEP_FAIL); + emit worker->showErrorMessage(worker->m_guiMsg); + break; + case UPDATE_STEP::UPDATE_REPOSITORY: + emit worker->appendText("\nUpdate repository..."); + break; + case UPDATE_STEP::UPDATE_REPOSITORY_SUCCESS: + emit worker->replaceLast(QString("Update repository ..."), UPDATE_STEP_DONE); + break; + case UPDATE_STEP::UPDATE_REPOSITORY_FAILURE: + emit worker->replaceLast(QString("Update repository ..."), UPDATE_STEP_FAIL); + break; + case UPDATE_STEP::CHECK_FOR_REPOSITORY_CHANGES: + break; + case UPDATE_STEP::CHECK_FOR_REPOSITORY_CHANGES_SUCCESS: + break; + case UPDATE_STEP::CHECK_FOR_REPOSITORY_CHANGES_FAILURE: + break; + case UPDATE_STEP::FILES_TO_UPDATE: { + + qCritical() << "FILES_TO_UPDATE" << worker->m_filesToUpdate; + + int const size = worker->m_filesToUpdate.size(); + if (size > 1) { + emit worker->appendText(QString("Found %1 files to update :").arg(size), UPDATE_STEP_DONE); + for (int i = 0; i < size; ++i) { + emit worker->appendText(QString("\n ") + worker->m_filesToUpdate.at(i)); + } + } + if (size == 1) { + emit worker->appendText("Found 1 file to update :", UPDATE_STEP_DONE); + emit worker->appendText(QString("\n ") + worker->m_filesToUpdate.at(0)); + } + } break; + case UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE: + break; + case UPDATE_STEP::FILES_TO_DOWNLOAD: + break; + case UPDATE_STEP::EXEC_OPKG_COMMANDS: + emit worker->appendText("\n( ) Update opkg pakets ..."); + break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_1: + __attribute__((fallthrough)); + // [[fallthrough]] -> c++17 -> unknown for clang + case UPDATE_STEP::EXEC_OPKG_COMMAND_2: + __attribute__((fallthrough)); + case UPDATE_STEP::EXEC_OPKG_COMMAND_3: + __attribute__((fallthrough)); + case UPDATE_STEP::EXEC_OPKG_COMMAND_4: + __attribute__((fallthrough)); + case UPDATE_STEP::EXEC_OPKG_COMMAND_5: + __attribute__((fallthrough)); + case UPDATE_STEP::EXEC_OPKG_COMMAND_6: + __attribute__((fallthrough)); + case UPDATE_STEP::EXEC_OPKG_COMMAND_7: + __attribute__((fallthrough)); + case UPDATE_STEP::EXEC_OPKG_COMMAND_8: + __attribute__((fallthrough)); + case UPDATE_STEP::EXEC_OPKG_COMMAND_9: + __attribute__((fallthrough)); + case UPDATE_STEP::EXEC_OPKG_COMMAND_LAST: + break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_SUCCESS: { + QString prepend = QString("(") + QString("%1").arg(worker->m_displayIndex).rightJustified(3, ' ') + QString(")") + + QString(" Update opkg pakets ... "); + worker->m_opkgCommands.prepend(prepend); + emit worker->replaceLast(worker->m_opkgCommands, UPDATE_STEP_DONE); + } break; + case UPDATE_STEP::EXEC_OPKG_COMMAND_FAILURE: { + emit worker->replaceLast(QString("(") + QString("%1").arg(worker->m_displayIndex).rightJustified(3, ' ') + QString(")") + + QString(" Update opkg pakets ... "), UPDATE_STEP_FAIL); + } break; + case UPDATE_STEP::DOWNLOAD_CONFIG_FILE: + break; + case UPDATE_STEP::DOWNLOAD_CONFIG_FILE_SUCCESS: + break; + case UPDATE_STEP::DOWNLOAD_CONFIG_FILE_FAILURE: + break; + case UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER: + break; + case UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER_SUCCESS: + break; + case UPDATE_STEP::DOWNLOAD_DEVICE_CONTROLLER_FAILURE: + break; + case UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE_SUCCESS: + break; + case UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE_FAILURE: + break; + case UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY: + emit worker->appendText("\nSync customer environment with filesystem ..."); + break; + case UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_SUCCESS: + emit worker->replaceLast(QString("Sync customer environment with filesystem ..."), UPDATE_STEP_DONE); + break; + case UPDATE_STEP::SYNC_CUSTOMER_REPOSITORY_FAILURE: + emit worker->replaceLast(QString("Sync customer environment with filesystem ..."), UPDATE_STEP_FAIL); + break; + case UPDATE_STEP::SAVE_LOGS: + break; + case UPDATE_STEP::SAVE_LOGS_SUCCESS: + break; + case UPDATE_STEP::SAVE_LOGS_FAILURE: + break; + case UPDATE_STEP::SEND_LAST_VERSION: + emit worker->appendText(QString("Send last version info "), UPDATE_STEP_DONE); + break; + case UPDATE_STEP::UPDATE_SUCCEEDED: + emit worker->appendText(QString("UPDATE "), UPDATE_STEP_SUCCESS); + break; + case UPDATE_STEP::UPDATE_ACTIVATED: + break; + case UPDATE_STEP::UPDATE_FAILED: + emit worker->appendText(QString("UPDATE "), UPDATE_STEP_FAIL); + break; + case UPDATE_STEP::FINISHED: + break; + case UPDATE_STEP::DEBUG: + emit worker->showStatusMessage(worker->m_guiMsg); + break; + case UPDATE_STEP::ERROR: + emit worker->showErrorMessage(worker->m_guiMsg); + break; + } + + worker->m_guiMsg.clear(); + + return step; + } }; #endif // WORKER_H_INCLUDED