From 8b301a91dc0d4ae7a4ddd5f470016b4cd68b85c4 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Tue, 18 Apr 2023 13:43:37 +0200 Subject: [PATCH] Squashed 'DCPlugin/' changes from 3e3e1ef..652ad9b 652ad9b Included changes of TS for version 3.5. c85b090 Added ulong2uchar (version 3.5). 87a6ed0 Include changes of Thomas for version 3.5. 99c88c7 Included changes of Thomas for version 3.5. prn_getPrintResult(), 712ea0f Included changes of Thomas for version 3.5 of library: datif_templatePrintFinished_OK(), datif_templatePrintFinished_Err(), datif_gotNewCoin(). 86311de Add use of shared memory. Add changes for version 3.4. of library. cb44127 Added check4freeFDshortCmd. a95e174 Included some changes of Thomas. c724b5b Shift several device controller related variables to shared memory. ef79321 Massive change: using shared memory containing most device controller realted variables. a7aa75a Massive change: using shared memory containing devcie controller variables. dc00c69 Added check4freeFDlongCmd. eeb3519 Adding shared memory containing all variables necessary to check device controller related variables. 30338e2 Changed struct T_moduleCondition. Changed struct T_dynamicCondition. Added struct T_extTime. Added log_chkIfVaultRecordAvailable(). Added sys_getDeviceConditions(). set version to 3.4. 58fdea4 Added m_sharedMem. Added cash_getAmountInVault. Added cash_getNrCoinsInVault. Added sys_getDynMachineConditions() with new interface. Added sys_getDeviceConditions() with new interface. Added log_chkIfVaultRecordAvailable(). df760f1 Added shared_mem_buffer.h/.cpp. git-subtree-dir: DCPlugin git-subtree-split: 652ad9b43d24bddbc3c2636c4ff4b5d74e081e46 --- DCPlugin.pri | 6 +- include/datIf.h | 5 + include/hwapi.h | 75 +- include/interfaces.h | 170 ++-- include/sendWRcmd.h | 8 +- include/shared_mem_buffer.h | 289 +++++++ include/storeINdata.h | 232 ++---- include/tslib.h | 3 + src/controlBus.cpp | 126 ++- src/datIf.cpp | 60 +- src/hwapi.cpp | 370 +++++++-- src/sendWRcmd.cpp | 16 +- src/shared_mem_buffer.cpp | 39 + src/storeINdata.cpp | 1542 +++++++++++++---------------------- src/tslib.cpp | 17 + 15 files changed, 1598 insertions(+), 1360 deletions(-) create mode 100644 include/shared_mem_buffer.h create mode 100644 src/shared_mem_buffer.cpp diff --git a/DCPlugin.pri b/DCPlugin.pri index ee140f9..1f6add0 100644 --- a/DCPlugin.pri +++ b/DCPlugin.pri @@ -10,7 +10,8 @@ HEADERS += $${PWD}/include/com.h \ $${PWD}/include/prot.h \ $${PWD}/include/sendWRcmd.h \ $${PWD}/include/storeINdata.h \ - $${PWD}/include/tslib.h + $${PWD}/include/tslib.h \ + $${PWD}/include/shared_mem_buffer.h SOURCES += $${PWD}/src/com.cpp \ $${PWD}/src/controlBus.cpp \ @@ -20,4 +21,5 @@ SOURCES += $${PWD}/src/com.cpp \ $${PWD}/src/prot.cpp \ $${PWD}/src/sendWRcmd.cpp \ $${PWD}/src/storeINdata.cpp \ - $${PWD}/src/tslib.cpp + $${PWD}/src/tslib.cpp \ + $${PWD}/src/shared_mem_buffer.cpp diff --git a/include/datIf.h b/include/datIf.h index 9a20cb5..f858aec 100644 --- a/include/datIf.h +++ b/include/datIf.h @@ -330,6 +330,11 @@ signals: //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/include/hwapi.h b/include/hwapi.h index 03b6135..9175d84 100644 --- a/include/hwapi.h +++ b/include/hwapi.h @@ -93,14 +93,15 @@ Level 3): send command: "start payment process" #include "interfaces.h" #include "datIf.h" - - +class QSharedMemory; class hwapi : public QObject, public hwinf { Q_OBJECT Q_PLUGIN_METADATA(IID "Atb.Psa2020.software.HWapi/1.0" ) //FILE "HWapi.json") Q_INTERFACES(hwinf) +private: + void sub_storeSendingText(QByteArray *buf) const; DownloadResult sendNextAddress(int bNum) const; DownloadResult sendNextDataBlock(QByteArray const &b, int bNum) const; @@ -114,8 +115,11 @@ class hwapi : public QObject, bool resetDeviceController() const; QByteArray loadBinaryDCFile(QString filename) const; bool downloadBinaryToDC(QString const &bFile) const; + + QSharedMemory *m_sharedMem; public: explicit hwapi(QWidget *parent = nullptr); + virtual ~hwapi(); T_datif *myDatif; @@ -990,24 +994,12 @@ public: // uint16_t borough, uint16_t zone, // uint16_t alias, char *location) const override; - /* - uint8_t emp_getInsertedCoinSignal(void) const override; - // can be called one time after each coin - // emp_chkIfCoinInserted() must be called before! - - uint16_t emp_getInsertedCoinValue(void) const override; - // can be called one time after each coin - // emp_chkIfCoinInserted() must be called before! - - uint8_t emp_getCoinError(void) const override; - // can be called one time after each coin - // emp_chkIfCoinInserted() must be called before! - */ 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 @@ -1032,15 +1024,18 @@ public: // nr = 1..32 // return true if sending, false if cmd-stack is full - void log_getHoldAccountNumbers(uint32_t *accNr ) const override; - // returns all acc nrs of the backuped vault records - // use: uint32_t backupedAccNumbers[8] + 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 -//request, isAvailable - void log_getVaultRecord(struct T_vaultRecord *retVR) const override; + 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 @@ -1050,7 +1045,8 @@ public: bool prn_printTestTicket(void) const override; // return true if sending to DC OK, false if cmd-stack is full - bool cash_startPayment(uint16_t amount) const override; + bool cash_startPayment(uint32_t amount) const override; + // 17.4.23TS: extended to 32bit bool cash_cancelPayment(void) const override; // and return coins @@ -1078,30 +1074,47 @@ public: - uint8_t mif_getCardType(QString cardholder) const override; + 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 - //void sys_getDeviceConditions(struct T_moduleCondition *devCond) const override; void sys_getDeviceConditions(uint8_t *leng, uint8_t *data) const override; - //void sys_getDynMachineConditions(struct T_dynamicCondition *dynMachCond) 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 +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: - void sub_storeSendingText(QByteArray *buf) const; - - - - - + private slots: + void hwapi_slotPrintFinished_OK(void); + void hwapi_slotPrintFinished_Err(void); + void hwapi_slotGotCoin(void); }; diff --git a/include/interfaces.h b/include/interfaces.h index 0358f16..774d3d6 100644 --- a/include/interfaces.h +++ b/include/interfaces.h @@ -167,30 +167,29 @@ struct T_moduleCondition // 100..150 = WARNING // 200..250 = ERROR - uint8_t structStart; // always first!!! - uint8_t ram; // v - uint8_t intEe; // v - uint8_t extEe; // v + 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; // v - uint8_t printer; // v - uint8_t modem; // v + 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; // v - uint8_t mifareReader; // v - uint8_t creditTerm; // not available - uint8_t coinReject; // v + uint8_t coinEscrow; + uint8_t mifareReader; + uint8_t creditTerm; + uint8_t coinReject; - uint8_t coinSafe; // v - uint8_t billSafe; // v - uint8_t voltage; // v // 1:11..14V - uint8_t temper; // v + 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) @@ -211,54 +210,81 @@ struct T_moduleCondition struct T_dynamicCondition { - // dynamic conditions, change rapidly and frequently - // these are values for the Heartbeat - - // T?rschalter entprellt: + char allDoorsDebounced; + char openedAuthorized; + uint8_t CBinDebounced; char upperDoor; // 0:fehlt 1:drin char middleDoor; char lowerDoor; char coinBox; - char billBox; char modeAbrech; char onAlarm; char nowCardTest; - char nowPayment; char lastMifCardType; - char openedAuthorized; - char allDoorsDebounced; - uint8_t lastSDoorState; uint8_t lastVDoorState; - uint8_t CBinDebounced; uint8_t lastCBstate; - - char paymentInProgress; - char res1; - char res2; - char res3; - - uint16_t U_Batt; + char paymentInProgress; + char res1; + uint16_t U_Batt; uint16_t Temperatur; - - uint16_t cash_storedaccNumbers[8]; // List all stored accounting numbers in ext. eeprom - uint16_t nrCoinsInBox; - uint16_t resui1; - uint32_t amountInBox; - uint32_t amountJustPaid; - - uint16_t lastInsCoinType; // wahrscheinlich uchar - uint16_t resui2; - 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 +//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; + +}; class hwinf { @@ -1371,6 +1397,8 @@ public: */ + 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 @@ -1395,15 +1423,18 @@ public: // nr = 1..32 // return true if sending, false if cmd-stack is full - virtual void log_getHoldAccountNumbers(uint32_t *accNr ) const=0; + virtual void log_getHoldAccountNumbers(uint8_t *nrOfVals, uint16_t *accNr ) const=0; // returns all acc nrs of the backuped vault records - // use: uint32_t backupedAccNumbers[8] + // 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 -//request, isAvailable -virtual void log_getVaultRecord(struct T_vaultRecord *retVR) const=0; + 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 @@ -1413,7 +1444,8 @@ virtual void log_getVaultRecord(struct T_vaultRecord *retVR) const=0; virtual bool prn_printTestTicket(void) const=0; // return true if sending to DC OK, false if cmd-stack is full - virtual bool cash_startPayment(uint16_t amount) const=0; + virtual bool cash_startPayment(uint32_t amount) const=0; + // 17.4.23TS: extended to 32bit virtual uint32_t getInsertedAmount(void) const=0; @@ -1437,18 +1469,13 @@ virtual void log_getVaultRecord(struct T_vaultRecord *retVR) const=0; // conclude payment process and return all inserted coins - - - - - virtual uint8_t mif_getCardType(QString cardholder) const=0; + 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 void sys_getDeviceConditions(struct T_moduleCondition *devCond) const=0; virtual void sys_getDeviceConditions(uint8_t *leng, uint8_t *data) const=0; /* @@ -1485,8 +1512,7 @@ virtual void log_getVaultRecord(struct T_vaultRecord *retVR) const=0; */ - - //virtual void sys_getDynMachineConditions(struct T_dynamicCondition *dynMachCond) const=0; + virtual void sys_getDeviceConditions(struct T_moduleCondition *devCond) const=0; virtual void sys_getDynMachineConditions(uint8_t *leng, uint8_t *data) const=0; /* @@ -1552,6 +1578,31 @@ virtual void log_getVaultRecord(struct T_vaultRecord *retVR) const=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 + +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; }; @@ -1569,10 +1620,15 @@ virtual void log_getVaultRecord(struct T_vaultRecord *retVR) const=0; // 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.3" +//#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/3.4" +#define HWINF_iid "Atb.Psa1256ptu5.software.HWapi/3.5" diff --git a/include/sendWRcmd.h b/include/sendWRcmd.h index fb92d2f..dd37064 100644 --- a/include/sendWRcmd.h +++ b/include/sendWRcmd.h @@ -218,7 +218,10 @@ bool sendFDcmd_set(uint8_t nextWrCmd, uint8_t nextRdCmd, uint8_t blockNum, uint8 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 + // 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); @@ -230,6 +233,9 @@ bool longFDcmd_get(uint8_t *nextWrCmd, uint8_t *nextRdCmd, uint8_t *blockNum, ui uint8_t check4FDlongCmd(void); // returns number of waiting command +uint8_t check4freeFDlongCmd(void); + // returns number of free places in long-command stack + #endif diff --git a/include/shared_mem_buffer.h b/include/shared_mem_buffer.h new file mode 100644 index 0000000..4311ae7 --- /dev/null +++ b/include/shared_mem_buffer.h @@ -0,0 +1,289 @@ +#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]; + } 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; + } 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/include/storeINdata.h b/include/storeINdata.h index 6de5ccf..ac7bad3 100644 --- a/include/storeINdata.h +++ b/include/storeINdata.h @@ -8,7 +8,7 @@ #define MAXNROF_AO 3 -#define MAXNROF_GENSTR 16 +//#define MAXNROF_GENSTR 16 #define MAXNROF_CONTR_PORTS 11 #define MAXNROF_DIports 2 #define MAXNROF_DOports 2 @@ -32,9 +32,6 @@ 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); @@ -43,23 +40,16 @@ void epi_getSlaveSerParams(uint8_t *slaveBaudRate, uint8_t *NrDataBits, 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 *buf8byteUid); +void gpi_storeUID(uint8_t const *buf8byteUid); // buffer size: 8 byte - void epi_getUIDdec(uint8_t *buf8byteUid); // buffer size: 8 byte - QString epi_getUIDstr(); @@ -89,7 +79,7 @@ void epi_getSpecialYearTimeDate(uint16_t *DayOfYear, uint16_t *HoursOfYear, uint // /////////////////////////////////////////////////////////////////////////////////// -#define MAXNROF_AI 4 +// #define MAXNROF_AI 4 void gpi_storeAIs(uint8_t aiNr, uint16_t val); // rs -> Sdata @@ -138,185 +128,119 @@ void gpi_storeDI_optos(uint8_t indatOpto); uint8_t epi_getDI_optos(void); // bit0: opto in 1 1: opto in 2 -void gpi_storeDI_auxIn(uint8_t indatAuxIn); - // Aux0...5 - -uint8_t epi_getDI_auxIn(void); - // bit0: auxin 1 ... 5: auxin 6 - -void gpi_storeDI_ptuWake(uint8_t indat); +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); -void gpi_storeDI_mbdWake(uint8_t indat); - +bool gpi_storeDI_mbdWake(bool w); bool epi_getDI_mdbWake(void); -void gpi_storeDI_prnReady(uint8_t indat); - +bool gpi_storeDI_prnReady(bool ready); bool epi_getDI_prnReady(void); -void gpi_storeDI_CoinAttach(uint8_t indat); - +bool gpi_storeDI_CoinAttach(bool attach); bool epi_getDI_CoinAttach(void); -void gpi_storeDI_CoinEscrow(uint8_t indat); - +bool gpi_storeDI_CoinEscrow(bool ce); bool epi_getDI_CoinEscrow(void); -void gpi_storeDI_mifareCardTapped(uint8_t indat); - +bool gpi_storeDI_mifareCardTapped(bool tapped); bool epi_getDI_mifareCardTapped(void); -void gpi_storeDI_modemWake(uint8_t indat); - +bool gpi_storeDI_modemWake(bool w); bool epi_getDI_modemWake(void); - -void gpi_storeDI_contactPowerIsOn(bool di_contact_PwrOn); - +bool gpi_storeDI_contactPowerIsOn(bool on); bool epi_getDI_contactPwr(void); -void gpi_storeDI_MifarePowerIsOn(bool di_mifare_PwrOn); - +bool gpi_storeDI_MifarePowerIsOn(bool on); bool epi_getDI_mifarePwr(void); -void gpi_storeDI_readbackMdbTxD(bool di_rdbkMdbTxd); - +bool gpi_storeDI_readbackMdbTxD(bool rdbkMdbTxd); bool epi_getDI_mdbTxd(void); -void gpi_storeDI_AuxPowerIsOn(bool di_Aux_PwrOn); - +bool gpi_storeDI_AuxPowerIsOn(bool on); bool epi_getDI_auxPwr(void); -void gpi_storeDI_GsmPowerIsOn(bool di_gsm_PwrOn); - +bool gpi_storeDI_GsmPowerIsOn(bool on); bool epi_getDI_gsmPwr(void); -void gpi_storeDI_CreditPowerIsOn(bool di_credit_PwrOn); - +bool gpi_storeDI_CreditPowerIsOn(bool on); bool epi_getDI_creditPwr(void); -void gpi_storeDI_PrinterPowerIsOn(bool di_printer_PwrOn); - +bool gpi_storeDI_PrinterPowerIsOn(bool on); bool epi_getDI_printerPwr(void); -void gpi_storeDI_MdbPowerIsOn(bool di_mdb_PwrOn); - +bool gpi_storeDI_MdbPowerIsOn(bool on); bool epi_getDI_mdbPwr(void); - -void gpi_storeDI_rejMot_home(bool di); - +bool gpi_storeDI_rejMot_home(bool reject); bool epi_getDI_rejectMotor_homepos(void); -void gpi_storeDI_paperLow(uint8_t di); - +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 // /////////////////////////////////////////////////////////////////////////////////// -void gpi_storeDO_mdbRxTst(uint8_t do_mbdRxTst); - +uint8_t gpi_storeDO_mdbRxTst(uint8_t do_mbdRxTst); bool epi_getDO_mdbRxTestOut(void); - -void gpi_storeDO_motorOutputs(uint8_t Pwr); - +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 - -void gpi_storeDO_serialSwitch(uint8_t state); +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 - -void gpi_storeDO_ledsAndFan(uint8_t ledState); - +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); -void gpi_storeDO_sirenAndRelay(uint8_t sirenRelay); - +uint8_t gpi_storeDO_sirenAndRelay(uint8_t sirenRelay); bool epi_getDO_sirene(void); - bool epi_getDO_relay(void); -void gpi_storeDO_ptuWake(uint8_t state); - +uint8_t gpi_storeDO_ptuWake(uint8_t state); bool epi_getDO_ptuWake(void); -void gpi_storeDO_auxPower(uint8_t pwr); - +uint8_t gpi_storeDO_auxPower(uint8_t pwr); bool epi_getDO_auxPower(void); - -void gpi_storeDO_coinShutter(uint8_t state); - +uint8_t gpi_storeDO_coinShutter(uint8_t state); bool epi_getDO_coinShutterOpen(void); - bool epi_getDO_coinShutterTest(void); - -void gpi_storeDO_coinEscrow(uint8_t state); - +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 - -void gpi_storeDO_printerPwrOn(uint8_t state); - +uint8_t gpi_storeDO_printerPwrOn(uint8_t state); uint8_t epi_getDO_printerPwr(void); - - // --------------------------------------------------------------------------------------------- // counterchecks, make sure that DC-outputs are correct @@ -363,21 +287,14 @@ bool epi_cntchk_Mot2Fon(void); 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 *buf); +uint8_t gpi_storeMifReaderStateAndCardType(uint8_t const *buf); /* data description: byte 0: current read state: 0=power off 1=reader-fault 2=ready @@ -401,41 +318,24 @@ byte 32: result, always 0 uint8_t epi_restoreMifState(uint8_t *buf, uint8_t maxBufferSize); // retval 0=OK 1=error host buffer too small - -void gpi_storeMifCardData(uint8_t blkNr, uint8_t *receivedData); +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 - - -#define pi_prnStateArraySize 20 -#define pi_prnFontArraySize 20 - void epi_restorePrinterState(uint8_t *buf); - -void gpi_storePrinterState(uint8_t *buf); +void gpi_storePrinterState(uint8_t const *buf); void epi_restorePrinterFonts(uint8_t *buf); +void gpi_storePrinterFonts(uint8_t const *buf); -void gpi_storePrinterFonts(uint8_t *buf); - - - - -void gpi_storeMdbState(uint8_t busReady, uint8_t V12on, uint8_t V5on ); - +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 *data); - +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 @@ -444,12 +344,9 @@ void epi_restoreMdbResponse(uint8_t *leng, uint8_t *data); // 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 *data); - +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); @@ -463,67 +360,60 @@ void epi_restoreEmpCoinSignal(uint8_t *leng, uint8_t *data); void epi_clearEmpCoinSignal(); */ -#define MEMDEPTH_GOTCOINS 16 -void gpi_storeEmpCoinSignal(uint8_t leng, uint8_t *data); +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 *data); - +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 *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 *receivedData); - +void gpi_storeWakeSources(uint8_t const *receivedData); uint64_t epi_getWakeSources(void); - - -void gpi_storeExtendedTime(uint8_t leng, uint8_t *data); - +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 *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 *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 #endif diff --git a/include/tslib.h b/include/tslib.h index 7d2733e..bc38ade 100644 --- a/include/tslib.h +++ b/include/tslib.h @@ -13,6 +13,9 @@ uint32_t uchar2ulong(uint8_t Highbyte, uint8_t MHbyte, uint8_t MLbyte, uint8_t L 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); diff --git a/src/controlBus.cpp b/src/controlBus.cpp index e7a500f..5793ba1 100644 --- a/src/controlBus.cpp +++ b/src/controlBus.cpp @@ -2,129 +2,107 @@ #include #include #include "tslib.h" +#include "shared_mem_buffer.h" //#include "controlBus.h" // /////////////////////////////////////////////////////////////////////////////////// // control serial interface gui <--> serial // /////////////////////////////////////////////////////////////////////////////////// -static QString rs_comportName; // z.B. "COM48" -static QString rs_baudStr; // z.B. "19200" -static int rs_baudNr; //0...5 oder -1 -static uint8_t rs_connect; // 0,1 +//static QString rs_comportName; // z.B. "COM48" +//static QString rs_baudStr; // z.B. "19200" +//static int rs_baudNr; //0...5 oder -1 +//static uint8_t rs_connect; // 0,1 -void epi_setSerial(int BaudNr, QString BaudStr, QString ComName, uint8_t connect) -{ -// qDebug() << "ENTER" << BaudNr << BaudStr << ComName << connect; +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); - rs_comportName = ComName; - rs_baudStr = BaudStr; - rs_baudNr = BaudNr; // 0=1200 1=9600 2=19200 3=38400 4=57600 5=115200 oder -1 - rs_connect = connect; // 0/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); -// qDebug() << "LEAVE" << rs_baudNr << rs_baudStr << rs_comportName << rs_connect; + SharedMemBuffer::getData()->rs.baudNr = BaudNr; + SharedMemBuffer::getData()->rs.connect = connect; } -void epi_closeSerial(void) -{ - rs_connect=0; -// qDebug() << "ENTER/LEAVE rc_connect=0"; +void epi_closeSerial(void) { + SharedMemBuffer::getData()->rs.connect = 0; } -void gpi_serialChanged(void) -{ +void gpi_serialChanged(void) { // serial confirms that port was closed or opened - rs_connect=2; // Flanke, nur 1x öffnen/schließen - //qDebug() << "ENTER/LEAVE rc_connect=2"; + // rs_connect=2; // Flanke, nur 1x öffnen/schließen + SharedMemBuffer::getData()->rs.connect = 2; } -uint8_t gpi_getSerialConn(void) -{ - return rs_connect; +uint8_t gpi_getSerialConn(void) { + return SharedMemBuffer::getDataConst()->rs.connect; } -int gpi_getBaudNr(void) -{ - return rs_baudNr; +int gpi_getBaudNr(void) { + return SharedMemBuffer::getDataConst()->rs.baudNr; } -QString gpi_getComPortName(void) -{ - return rs_comportName; +QString gpi_getComPortName(void) { + return SharedMemBuffer::getDataConst()->rs.comportName; } -static bool rs_portIsOpen; - -void gpi_serialIsOpen(bool offen) -{ - //qDebug() << "ENTER/LEAVE offen=" << offen; - rs_portIsOpen=offen; +void gpi_serialIsOpen(bool offen) { + SharedMemBuffer::getData()->rs.portIsOpen = offen; } -bool epi_isSerialPortOpen() -{ +bool epi_isSerialPortOpen() { // true: port is open false: port is closed - //qDebug() << "ENTER/LEAVE offen=" << rs_portIsOpen; - return rs_portIsOpen; + return SharedMemBuffer::getDataConst()->rs.portIsOpen; } // /////////////////////////////////////////////////////////////////////////////////// // Control transfer gui <--> serial // /////////////////////////////////////////////////////////////////////////////////// - -static char AutoEmissionOn; // 1: zyklisch Anfragen zum Slave senden - -void epi_startEmmision(char start) -{ - AutoEmissionOn=start; +void epi_startEmmision(char start) { + SharedMemBuffer::getData()->AutoEmissionOn = start; } -bool gpi_isEmmisionOn(void) -{ - return AutoEmissionOn; +bool gpi_isEmmisionOn(void) { + return SharedMemBuffer::getDataConst()->AutoEmissionOn; } -//----------------------------------------------------- - -static uint16_t datif_sendingPeriod; -static bool datif_sendingPer_changed; - -uint16_t gpi_getPeriodicSendTimeVal() -{ - datif_sendingPer_changed=0; - if (datif_sendingPeriod<3 || datif_sendingPeriod>10000) +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 - else - return datif_sendingPeriod; + } + return SharedMemBuffer::getDataConst()->datif.sendingPeriod; } -void epi_setPeriodicSendTimeVal(uint16_t val) -{ - if (val>=3 && val<10000) - { - datif_sendingPer_changed=1; - datif_sendingPeriod=val; +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 datif_sendingPer_changed; +bool gpi_PeriodicSendTimeHasChanged() { + return SharedMemBuffer::getDataConst()->datif.sendingPer_changed; } -//----------------------------------------------------- - - -//----------------------------------------------------- - // /////////////////////////////////////////////////////////////////////////////////// // Status Display gui <--> serial // /////////////////////////////////////////////////////////////////////////////////// - // linke Spalte, über Connect Button static QString txt4comStateLine; diff --git a/src/datIf.cpp b/src/datIf.cpp index befbc9c..60e76d3 100644 --- a/src/datIf.cpp +++ b/src/datIf.cpp @@ -863,6 +863,11 @@ char T_datif::loadRecDataFromFrame() //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 @@ -902,7 +907,8 @@ char T_datif::loadRecDataFromFrame() for (int ii=0; ii // 316 byte Block im Speicher */ - + // readAddress, &RdDleng, receivedData + gpi_storeVaultRecord(readAddress, receivedData ); // always 64byte break; } @@ -1644,11 +1677,15 @@ 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++) - if (myStr[nn] !=receivedData[nn]) + { + ctmp=receivedData[nn]; + if (myStr[nn] != ctmp) { //qDebug() << " datif cmd 10: got wrong string "; //qDebug() << myStr; @@ -1656,6 +1693,7 @@ bool T_datif::verifyLineTestresponse(uint8_t RdDlen, uint8_t *receivedData) //qDebug() << nn; return false; } + } return true; } diff --git a/src/hwapi.cpp b/src/hwapi.cpp index ca0ad84..325b0c7 100644 --- a/src/hwapi.cpp +++ b/src/hwapi.cpp @@ -21,29 +21,65 @@ #include "controlBus.h" #include "storeINdata.h" #include "dcBL.h" +#include "shared_mem_buffer.h" #include -#include <../plugins/interfaces.h> +#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(QWidget *parent) : QObject(parent) -{ - // constructor - //epi_resetAllDOs(); - //PI_INI(); +hwapi::hwapi(QWidget *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::sub_storeSendingText(QByteArray *buf) const -{ +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; @@ -739,13 +775,16 @@ 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++) qbuf[nn]=buf[nn]; - + for (nn=0; nn<20; nn++) + { + ctmp=buf[nn]; + qbuf[nn]=ctmp; + } return qbuf; } @@ -753,14 +792,17 @@ 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++) - qbuf[nn]=buf[nn]; - + { + ctmp= buf[nn]; + qbuf[nn]=ctmp; + } return qbuf; } @@ -2221,7 +2263,8 @@ bool hwapi::pri_TD_addText(QByteArray text) const bool hwapi::pri_TD_addValue(int val) const { - QString tmpStr; +// QString tmpStr; + QByteArray tmpStr; tmpStr.setNum(val,10); // up to 12 chars if (ticketTemplate.length()>1266) return false; @@ -3071,7 +3114,7 @@ bool hwapi::bl_isUp(void) const } -void hwapi::bl_sendAddress(u_int16_t blockNumber) const +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: @@ -3106,7 +3149,7 @@ void hwapi::bl_openBinary(void) const dcBL_loadBinary(0); } -void hwapi::bl_sendDataBlock(uint8_t length, u_int8_t *buffer) const +void hwapi::bl_sendDataBlock(uint8_t length, uint8_t *buffer) const { // send 64 byte from bin file uint8_t LL=length, sendBuf[80], sendLen; @@ -3137,6 +3180,7 @@ void hwapi::bl_sendLastBlock(void) const len=dcBL_writeLastPage(buf); sendWRcmd_setSendBlock160(len, buf); + } uint8_t hwapi::bl_wasSendingDataOK(void) const @@ -3309,6 +3353,60 @@ bool hwapi::rtc_getExtendedTime(uint8_t *leng, uint8_t *data) const } +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(++nnstartbuffer[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; } diff --git a/src/sendWRcmd.cpp b/src/sendWRcmd.cpp index 1106652..afca5a6 100644 --- a/src/sendWRcmd.cpp +++ b/src/sendWRcmd.cpp @@ -563,11 +563,17 @@ bool sendFDcmd_get(uint8_t *nextWrCmd, uint8_t *nextRdCmd, uint8_t *blockNum, ui uint8_t check4FDshortCmd(void) { - // returns number of waiting command + // 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]; @@ -602,7 +608,7 @@ bool longFDcmd_set(uint8_t nextWrCmd, uint8_t nextRdCmd, uint8_t blockNum, uint8 uint8_t nn; if (p_longFDcmdsInQueue>=FDLONG_STACKDEPTH) { - qCritical() << "cannot save cmd because stack is full"; + qDebug() << "cannot save cmd because stack is full"; return false; // not possible } longFDwrCmd[p_longFDcmdsInQueue]=nextWrCmd; @@ -613,7 +619,6 @@ bool longFDcmd_set(uint8_t nextWrCmd, uint8_t nextRdCmd, uint8_t blockNum, uint8 longFDpara[p_longFDcmdsInQueue][nn]=data[nn]; p_longFDcmdsInQueue++; - return true; // ok, will be sent } @@ -659,5 +664,10 @@ uint8_t check4FDlongCmd(void) return p_longFDcmdsInQueue; } +uint8_t check4freeFDlongCmd(void) +{ + // returns number of free places in command stack + return FDLONG_STACKDEPTH - p_longFDcmdsInQueue; +} diff --git a/src/shared_mem_buffer.cpp b/src/shared_mem_buffer.cpp new file mode 100644 index 0000000..8026c19 --- /dev/null +++ b/src/shared_mem_buffer.cpp @@ -0,0 +1,39 @@ +#include "shared_mem_buffer.h" + +#include +#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/src/storeINdata.cpp b/src/storeINdata.cpp index c82f54f..007a51c 100644 --- a/src/storeINdata.cpp +++ b/src/storeINdata.cpp @@ -3,6 +3,8 @@ #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) @@ -12,75 +14,56 @@ static bool indat_savePrnPwr; -void indat_storePrinterPower(bool isOn) -{ +void indat_storePrinterPower(bool isOn) { indat_savePrnPwr=isOn; } -bool indat_isPrinterOn() -{ +bool indat_isPrinterOn() { return indat_savePrnPwr; } - static bool indat_saveMifPwr; -void indat_storeMifarePower(bool isOn) -{ +void indat_storeMifarePower(bool isOn) { indat_saveMifPwr=isOn; } -bool indat_isMifareOn() -{ +bool indat_isMifareOn() { return indat_saveMifPwr; } - static bool indat_MdbIsOn; -void indat_storeMDBisOn(bool isOn) -{ +void indat_storeMDBisOn(bool isOn) { indat_MdbIsOn=isOn; } -bool indat_isMdbOn() -{ +bool indat_isMdbOn() { return indat_MdbIsOn; } - -// ////////////////////////////////////////////////////////////////////////// - - - -static uint8_t ndbs, pari, nsb, br; - void gpi_storeSlaveSerParams(uint8_t slaveBaudRate, uint8_t NrDataBits, - uint8_t parity, uint8_t NrStopBits) -{ + uint8_t parity, uint8_t NrStopBits) { // store numbers - ndbs=NrDataBits; - pari=parity; - nsb=NrStopBits; - br=slaveBaudRate; + 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=ndbs; - *parity=pari; - *NrStopBits=nsb; - *slaveBaudRate=br; + 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 epi_getSlaveParamSTR() { QString mySt; - mySt.clear(); - switch (br) - { + + switch (SharedMemBuffer::getDataConst()->br) { case 1: mySt="1200 ";break; case 2: mySt="9600 ";break; case 3: mySt="19200 ";break; @@ -88,166 +71,81 @@ QString epi_getSlaveParamSTR() case 5: mySt="57600 ";break; case 6: mySt="115200 ";break; } - mySt.append(ndbs+0x30); - mySt.append(pari); - mySt.append(nsb+0x30); -//mySt="Hallo"; + 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]; +// static QString genStrings[MAXNROF_GENSTR]; // 0=HW 1=SW 2=State -void gpi_storeGenerals(uint8_t genNr, QString text) -{ +void gpi_storeGenerals(uint8_t genNr, QString text) { // 0=HW 1=SW 2=State - if (genNrgenStrings[genNr][0], + text.toStdString().c_str(), + sizeof(SharedMemBuffer::getDataConst()->genStrings[0])); } - } -QString epi_loadGenerals(uint8_t genNr) -{ - if (genNrgenStrings[2][8] = '\0'; + } + return QString(SharedMemBuffer::getDataConst()->genStrings[genNr]); } return " "; } - - - // ------------------------------- -static uint64_t Sdata_slaveUID; -static uint8_t Sdata_UIDstr[8]; - -void gpi_storeUID(uint8_t *buf8byteUid) -{ +void gpi_storeUID(uint8_t const *buf8byteUid) { uint64_t udltmp=0; - //qDebug()<< "store UID "; - - for (int ii=0; ii<8; ii++) - { - //qDebug()<< buf8byteUid[ii] << " "; - - Sdata_UIDstr[ii]=buf8byteUid[ii]; - udltmp|=buf8byteUid[ii]; - udltmp<<=8; + for (int ii=0; ii<8; ii++) { + SharedMemBuffer::getData()->Sdata.UIDstr[ii] = buf8byteUid[ii]; + udltmp |= buf8byteUid[ii]; + udltmp <<= 8; } - Sdata_slaveUID=udltmp; + SharedMemBuffer::getData()->Sdata.slaveUID = udltmp; } -void epi_getUIDdec(uint8_t *buf8byteUid) -{ -//qDebug()<< "get UID "; - for (int ii=0; ii<8; ii++) - { - //qDebug()<Sdata.UIDstr[ii]; } } -QString epi_getUIDstr() -{ +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(Sdata_UIDstr[ii],16); - myStr+=" "; + for (int ii=0;ii<8; ii++) { + myStr += QString::number(SharedMemBuffer::getDataConst()->Sdata.UIDstr[ii], 16); + myStr += " "; } - return myStr; + return myStr; } - - - - - - - - - - - -// /////////////////////////////////////////////////////////////////////////////////// -// Time and Date -// /////////////////////////////////////////////////////////////////////////////////// - -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; - -}; -static T_globTime getGlobalTime; - - -void gpi_backupSquareMode(uint8_t squMode) -{ - getGlobalTime.squareOutMode=squMode; +void gpi_backupSquareMode(uint8_t squMode) { + SharedMemBuffer::getData()->getGlobalTime.squareOutMode = squMode; } -uint8_t epi_getSquareMode() -{ - return getGlobalTime.squareOutMode; +uint8_t epi_getSquareMode() { + return SharedMemBuffer::getDataConst()->getGlobalTime.squareOutMode; } - -void gpi_backupTime(uint8_t *timeBuffer, uint8_t Leng) -{ +void gpi_backupTime(uint8_t *timeBuffer, uint8_t Leng) { /* // Daten kommen in gleicher Reihenfolge vom Slave uint8_t *pTime; @@ -259,87 +157,77 @@ void gpi_backupTime(uint8_t *timeBuffer, uint8_t Leng) }*/ // new, FastProt: 0=dayOfWeek 1=min 2=sec 3=hours 4=year 5=month 6=dayOfMonth - getGlobalTime.second=Leng; // nur damit CompilerWarnung weg ist - - getGlobalTime.DayOfWeek=timeBuffer[0]; - getGlobalTime.minute=timeBuffer[1]; - getGlobalTime.second=timeBuffer[2]; - getGlobalTime.hour=timeBuffer[3]; - getGlobalTime.Year=timeBuffer[4]; - getGlobalTime.Month=timeBuffer[5]; - getGlobalTime.DayOfMonth=timeBuffer[6]; - + SharedMemBuffer::getData()->getGlobalTime.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=getGlobalTime.hour; - *mm=getGlobalTime.minute; - *ss=getGlobalTime.second; +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=getGlobalTime.Year; - *mm=getGlobalTime.Month; - *dd=getGlobalTime.DayOfMonth; +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=getGlobalTime.DayOfWeek; - *minOfToday=getGlobalTime.MinutesOfToday; - *secOfToday=getGlobalTime.SecondsOfToday; +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=getGlobalTime.lastLeap; - *NextLeapYear=getGlobalTime.nextLeap; - if (getGlobalTime.IsLeapyear) - return true; - return false; +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() -{ - if (getGlobalTime.IsLeapyear) - return true; - return false; +bool epi_isLeapYear() { + return SharedMemBuffer::getDataConst()->getGlobalTime.IsLeapyear; } -void epi_getSpecialWeekTimeDate(uint8_t *DayOfWeek, uint8_t *HoursOfWeek, uint16_t *MinutesOfWeek) -{ - *DayOfWeek=getGlobalTime.DayOfWeek; - *HoursOfWeek=getGlobalTime.hoursOfWeek; - *MinutesOfWeek=getGlobalTime.minOfWeek; +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=getGlobalTime.DayOfMonth; - *HoursOfMonth=getGlobalTime.hoursOfMonth; - *MinutesOfMonth=getGlobalTime.minOfMonth; +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=getGlobalTime.dayOfYear; - *HoursOfYear=getGlobalTime.hoursOfYear; - *MinutesOfYear=getGlobalTime.minOfYear; +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) -{ +QString epi_getRtcTimeStr(uint8_t timeStyle) { // style: 0: hh:mm 1: hh:mm:ss QString mystr=nullptr, tempStr=nullptr; - tempStr.setNum(getGlobalTime.hour,10); + tempStr.setNum(SharedMemBuffer::getDataConst()->getGlobalTime.hour, 10); mystr=tempStr.rightJustified(2,'0',false); // macht feste Länge, 5->05 mystr.append(':'); - //tempStr.clear(); - tempStr.setNum(getGlobalTime.minute,10); // mit 16 statt 10 wirds in HEX angezeigt + tempStr.setNum(SharedMemBuffer::getDataConst()->getGlobalTime.minute, 10); //mystr.append(tempStr); mystr+=tempStr.rightJustified(2,'0',false); //mystr.append(':'); // so @@ -348,27 +236,25 @@ QString epi_getRtcTimeStr(uint8_t timeStyle) if (timeStyle==1) // hh:mm:ss { mystr.append(':'); - tempStr.setNum(getGlobalTime.second,10); + tempStr.setNum(SharedMemBuffer::getDataConst()->getGlobalTime.second, 10); mystr.append(tempStr.rightJustified(2,'0',false)); // wie += } return mystr; } - -QString epi_getRtcDateStr(uint8_t dateStyle) -{ +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(getGlobalTime.Year,10); // itoa decimal + tmpStr.setNum(SharedMemBuffer::getDataConst()->getGlobalTime.Year, 10); YYstr=tmpStr.rightJustified(4,'0',false); // immer vierstellig YYstr[0]='2'; // 2000 dazu - tmpStr.setNum(getGlobalTime.Month,10); + tmpStr.setNum(SharedMemBuffer::getDataConst()->getGlobalTime.Month, 10); MMstr=tmpStr.rightJustified(2,'0',false); - tmpStr.setNum(getGlobalTime.DayOfMonth,10); + tmpStr.setNum(SharedMemBuffer::getDataConst()->getGlobalTime.DayOfMonth, 10); DDstr=tmpStr.rightJustified(2,'0',false); if (dateStyle==1) // Germany dd.mm.yy @@ -387,37 +273,32 @@ QString epi_getRtcDateStr(uint8_t dateStyle) } -QString epi_getSlaveTimeDateStr() -{ +QString epi_getSlaveTimeDateStr() { QString myStr; myStr=epi_getRtcTimeStr(1) + " " + epi_getRtcDateStr(1); return myStr; } - // /////////////////////////////////////////////////////////////////////////////////// // analog values // /////////////////////////////////////////////////////////////////////////////////// -static uint16_t AI_val[MAXNROF_AI]; - -uint8_t gpi_getMaxNrAIs() -{ +uint8_t gpi_getMaxNrAIs() { return MAXNROF_AI; } -void gpi_storeAIs(uint8_t aiNr, uint16_t val) -{ - if (aiNrAI_val[aiNr] = val; + } } -uint16_t epi_loadAIs(uint8_t aiNr) -{ - if (aiNrAI_val[aiNr]; + } return 0; } @@ -427,29 +308,23 @@ uint16_t epi_loadAIs(uint8_t aiNr) // ADC0: temp // 1: voltage // 2: brightness -#define MAXNROF_MEASURE 4 -static uint32_t Sdata_measurement[MAXNROF_MEASURE]; - - -uint32_t epi_loadMeasureValue(uint8_t ValueNr) -{ +uint32_t epi_loadMeasureValue(uint8_t ValueNr) { // ValueNr 0=ADC0, 1=ADC1 aso... - if (ValueNrSdata.measurement[ValueNr]; + } return 0; } -void gpi_storeMeasureValue(uint8_t ValueNr, uint32_t val) -{ +void gpi_storeMeasureValue(uint8_t ValueNr, uint32_t val) { // in mV, also bis 65,535V - if (ValueNrSdata.measurement[ValueNr] = val; + } } -QString epi_getSlaveTemperatureStr() -{ +QString epi_getSlaveTemperatureStr() { char myStr[8], halfDegree=0, Minus=0, oneChar; int16_t val=0, pp, einer, zehner; QString myqStr; @@ -625,322 +500,203 @@ D23: DI Printer Pwr from PO2 is on D24: DI MDB Pwr from PO2 is on */ -static uint8_t di_doorSwitch; -void gpi_storeDI_doorSwitches(uint8_t upperDoor, uint8_t lowerDoor, uint8_t vaultDoor) -{ - - di_doorSwitch=0; - if (upperDoor) di_doorSwitch |=1; - if (lowerDoor) di_doorSwitch |=2; - if (vaultDoor) di_doorSwitch |=4; - -// qDebug()<<"storeINdata: "<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) -{ +uint8_t epi_getDI_doorSwitches(void) { // bit0: upper door 1: low door 2:vault door - return di_doorSwitch; + return SharedMemBuffer::getDataConst()->din.doorSwitch; } -static uint8_t di_vaultSwitch; -void gpi_storeDI_vaultSwitches(uint8_t CashBoxIn, uint8_t BillBoxIn) -{ - di_vaultSwitch=0; - if (CashBoxIn) di_vaultSwitch |=1; - if (BillBoxIn) di_vaultSwitch |=2; +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) -{ +uint8_t epi_getDI_vaultSwitches(void) { // bit0: cash box 1: bill box in - return di_vaultSwitch; + return SharedMemBuffer::getData()->din.vaultSwitch; } -static uint8_t di_lockSwitch; -void gpi_storeDI_lockSwitches(uint8_t indatUL, uint8_t indatLL) -{ +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 - di_lockSwitch=0; - if (indatUL & 1) di_lockSwitch |=1; - if (indatUL & 2) di_lockSwitch |=2; - if (indatLL & 1) di_lockSwitch |=4; - if (indatLL & 2) di_lockSwitch |=8; + 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) -{ +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 di_lockSwitch; + return SharedMemBuffer::getData()->din.lockSwitch; } -static uint8_t di_opto; -void gpi_storeDI_optos(uint8_t indatOpto) -{ +void gpi_storeDI_optos(uint8_t indatOpto) { // OptoIn bit 0,1: optoin 1,2 - di_opto=0; - if (indatOpto & 1) di_opto |=1; - if (indatOpto & 2) di_opto |=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) -{ +uint8_t epi_getDI_optos(void) { // bit0: opto in 1 1: opto in 2 - return di_opto; + return SharedMemBuffer::getDataConst()->din.opto; } - -static uint8_t di_aux; -void gpi_storeDI_auxIn(uint8_t indatAuxIn) -{ - // Aux0...5 - di_aux=indatAuxIn; +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 di_aux; +uint8_t epi_getDI_auxIn(void) { // bit0: auxin 1 ... 5: auxin 6 + return SharedMemBuffer::getDataConst()->din.aux; } - -static bool di_wakeFromPtu; -void gpi_storeDI_ptuWake(uint8_t indat) -{ - if (indat) - di_wakeFromPtu=true; - else - di_wakeFromPtu=false; +bool gpi_storeDI_ptuWake(bool w) { + return SharedMemBuffer::getData()->din.wakeFromPtu = w; } -bool epi_getDI_ptuWake(void) -{ - return di_wakeFromPtu; +bool epi_getDI_ptuWake(void) { + return SharedMemBuffer::getDataConst()->din.wakeFromPtu; } - -static bool di_wakeFromMdb; -void gpi_storeDI_mbdWake(uint8_t indat) -{ - if (indat) - di_wakeFromMdb=true; - else - di_wakeFromMdb=false; +bool gpi_storeDI_mbdWake(bool w) { + return SharedMemBuffer::getData()->din.wakeFromMdb = w; } -bool epi_getDI_mdbWake(void) -{ - return di_wakeFromMdb; +bool epi_getDI_mdbWake(void) { + return SharedMemBuffer::getDataConst()->din.wakeFromMdb; } - -static bool di_PrnReady; -void gpi_storeDI_prnReady(uint8_t indat) -{ - if (indat) - di_PrnReady=true; - else - di_PrnReady=false; +bool gpi_storeDI_prnReady(bool ready) { + return SharedMemBuffer::getData()->din.PrnReady = ready; } -bool epi_getDI_prnReady(void) -{ - return di_PrnReady; +bool epi_getDI_prnReady(void) { + return SharedMemBuffer::getDataConst()->din.PrnReady; } - -static bool di_CoinAttach; -void gpi_storeDI_CoinAttach(uint8_t indat) -{ - if (indat) - di_CoinAttach=true; - else - di_CoinAttach=false; +bool gpi_storeDI_CoinAttach(bool attach) { + return SharedMemBuffer::getData()->din.CoinAttach = attach; } -bool epi_getDI_CoinAttach(void) -{ - return di_CoinAttach; +bool epi_getDI_CoinAttach(void) { + return SharedMemBuffer::getDataConst()->din.CoinAttach; } -static bool di_CoinEscrowOpen; -void gpi_storeDI_CoinEscrow(uint8_t indat) -{ - if (indat) - di_CoinEscrowOpen=true; - else - di_CoinEscrowOpen=false; +bool gpi_storeDI_CoinEscrow(bool ce) { + return SharedMemBuffer::getData()->din.CoinEscrowOpen = ce; } -bool epi_getDI_CoinEscrow(void) -{ - return di_CoinEscrowOpen; +bool epi_getDI_CoinEscrow(void) { + return SharedMemBuffer::getDataConst()->din.CoinEscrowOpen; } - -static bool di_mifCardTap; -void gpi_storeDI_mifareCardTapped(uint8_t indat) -{ - if (indat) - di_mifCardTap=true; - else - di_mifCardTap=false; +bool gpi_storeDI_mifareCardTapped(uint8_t tapped) { + return SharedMemBuffer::getData()->din.mifCardTap = tapped; } -bool epi_getDI_mifareCardTapped(void) -{ - return di_mifCardTap; +bool epi_getDI_mifareCardTapped(void) { + return SharedMemBuffer::getDataConst()->din.mifCardTap; } - -static bool di_wakeFromModem; -void gpi_storeDI_modemWake(uint8_t indat) -{ - if (indat) - di_wakeFromModem=true; - else - di_wakeFromModem=false; +bool gpi_storeDI_modemWake(bool w) { + return SharedMemBuffer::getData()->din.wakeFromModem = w; } -bool epi_getDI_modemWake(void) -{ - return di_wakeFromModem; +bool epi_getDI_modemWake(void) { + return SharedMemBuffer::getDataConst()->din.mifCardTap; } - - -static bool di_contactPwrOn; - -void gpi_storeDI_contactPowerIsOn(bool di_contact_PwrOn) -{ - di_contactPwrOn=di_contact_PwrOn; +bool gpi_storeDI_contactPowerIsOn(bool on) { + return SharedMemBuffer::getData()->din.contactPwrOn = on; } -bool epi_getDI_contactPwr(void) -{ - // invertiert! - if (di_contactPwrOn) - return false; - return true; +bool epi_getDI_contactPwr(void) { // invertiert! + return !SharedMemBuffer::getDataConst()->din.contactPwrOn; } -static bool di_mifarePwrOn; - -void gpi_storeDI_MifarePowerIsOn(bool di_mifare_PwrOn) -{ - di_mifarePwrOn=di_mifare_PwrOn; +bool gpi_storeDI_MifarePowerIsOn(bool on) { + return SharedMemBuffer::getData()->din.mifarePwrOn = on; } -bool epi_getDI_mifarePwr(void) -{ - return di_mifarePwrOn; +bool epi_getDI_mifarePwr(void) { + return SharedMemBuffer::getDataConst()->din.mifarePwrOn; } -static bool di_rdbk_mdbTxd; - -void gpi_storeDI_readbackMdbTxD(bool di_rdbkMdbTxd) -{ - di_rdbk_mdbTxd=di_rdbkMdbTxd; +bool gpi_storeDI_readbackMdbTxD(bool rdbkMdbTxd) { + return SharedMemBuffer::getData()->din.rdbk_mdbTxd = rdbkMdbTxd; } -bool epi_getDI_mdbTxd(void) -{ - return di_rdbk_mdbTxd; +bool epi_getDI_mdbTxd(void) { + return SharedMemBuffer::getDataConst()->din.rdbk_mdbTxd; } -static bool di_AuxPwrOn; - -void gpi_storeDI_AuxPowerIsOn(bool di_Aux_PwrOn) -{ - di_AuxPwrOn=di_Aux_PwrOn; +bool gpi_storeDI_AuxPowerIsOn(bool on) { + return SharedMemBuffer::getData()->din.AuxPwrOn = on; } -bool epi_getDI_auxPwr(void) -{ - return di_AuxPwrOn; +bool epi_getDI_auxPwr(void) { + return SharedMemBuffer::getDataConst()->din.AuxPwrOn; } -static bool di_gsmPwrOn; - -void gpi_storeDI_GsmPowerIsOn(bool di_gsm_PwrOn) -{ - di_gsmPwrOn=di_gsm_PwrOn; +bool gpi_storeDI_GsmPowerIsOn(bool on) { + return SharedMemBuffer::getData()->din.gsmPwrOn = on; } -bool epi_getDI_gsmPwr(void) -{ - return di_gsmPwrOn; +bool epi_getDI_gsmPwr(void) { + return SharedMemBuffer::getDataConst()->din.gsmPwrOn; } -static bool di_creditPwrOn; - -void gpi_storeDI_CreditPowerIsOn(bool di_credit_PwrOn) -{ +bool gpi_storeDI_CreditPowerIsOn(bool on) { // invertieren!!! - if (di_credit_PwrOn) - di_creditPwrOn=0; - else - di_creditPwrOn=1; + return SharedMemBuffer::getData()->din.creditPwrOn = !on; } -bool epi_getDI_creditPwr(void) -{ - return di_creditPwrOn; +bool epi_getDI_creditPwr(void) { + return SharedMemBuffer::getDataConst()->din.creditPwrOn; } -static bool di_printerPwrOn; - -void gpi_storeDI_PrinterPowerIsOn(bool di_printer_PwrOn) -{ - di_printerPwrOn=di_printer_PwrOn; +bool gpi_storeDI_PrinterPowerIsOn(bool on) { + return SharedMemBuffer::getData()->din.printerPwrOn = on; } -bool epi_getDI_printerPwr(void) -{ - return di_printerPwrOn; +bool epi_getDI_printerPwr(void) { + return SharedMemBuffer::getDataConst()->din.printerPwrOn; } -static bool di_mdbPwrOn; - -void gpi_storeDI_MdbPowerIsOn(bool di_mdb_PwrOn) -{ - di_mdbPwrOn=di_mdb_PwrOn; +bool gpi_storeDI_MdbPowerIsOn(bool on) { + return SharedMemBuffer::getData()->din.mdbPwrOn = on; } -bool epi_getDI_mdbPwr(void) -{ - return di_mdbPwrOn; +bool epi_getDI_mdbPwr(void) { + return SharedMemBuffer::getDataConst()->din.mdbPwrOn; } -static bool di_rejMot_home; - -void gpi_storeDI_rejMot_home(bool di) -{ - di_rejMot_home=di; +bool gpi_storeDI_rejMot_home(bool reject) { + return SharedMemBuffer::getData()->din.rejMot_home = reject; } -bool epi_getDI_rejectMotor_homepos(void) -{ - return di_rejMot_home; +bool epi_getDI_rejectMotor_homepos(void) { + return SharedMemBuffer::getDataConst()->din.rejMot_home; } -static uint8_t di_npe_sensor; - -void gpi_storeDI_paperLow(uint8_t di) -{ +uint8_t gpi_storeDI_paperLow(uint8_t sensor) { // 0: Sensor sees paper 1: no paper 99: off - di_npe_sensor=di; + return SharedMemBuffer::getData()->din.npe_sensor = sensor; } -uint8_t epi_getDI_npe_sensor(void) -{ - return di_npe_sensor; +uint8_t epi_getDI_npe_sensor(void) { + return SharedMemBuffer::getDataConst()->din.npe_sensor; } @@ -970,265 +726,166 @@ D12: Coin shutter output D13: CoinEscrow Outputs */ -static uint8_t do_mbdRxTst; -void gpi_storeDO_mdbRxTst(uint8_t mdbRxTst) -{ - do_mbdRxTst=mdbRxTst; +uint8_t gpi_storeDO_mdbRxTst(uint8_t mdbRxTst) { + return SharedMemBuffer::getData()->dout.mbdRxTst = mdbRxTst; } -bool epi_getDO_mdbRxTestOut(void) -{ - if (do_mbdRxTst & 1) - return true; - return false; +bool epi_getDO_mdbRxTestOut(void) { + return SharedMemBuffer::getData()->dout.mbdRxTst & 1; } -static uint8_t do_motorBits; -void gpi_storeDO_motorOutputs(uint8_t Pwr) -{ +uint8_t gpi_storeDO_motorOutputs(uint8_t motorBits) { //D1: motor outputs bit0: upper lock forw bit 1 backw // Bit2: lowLock forw bit3: LL backw - do_motorBits=Pwr; + return SharedMemBuffer::getData()->dout.motorBits = motorBits; } -uint8_t epi_getDO_motorOuts(void) -{ +uint8_t epi_getDO_motorOuts(void) { // bit0: upper lock forward bit 1 backward // bit2: lower lock forward bit 3 backward - return do_motorBits; + return SharedMemBuffer::getDataConst()->dout.motorBits; } - - -static uint8_t do_serialSwitch; // serial drv on/off, Serial mux1, Serial mux2 -void gpi_storeDO_serialSwitch(uint8_t state) // serial drv on/off, Serial mux1, Serial mux2 -{ - do_serialSwitch=state; +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) -{ +uint8_t epi_getDO_serialSwitch(void) { // serial drv on/off, Serial mux1, Serial mux2 - return do_serialSwitch; + return SharedMemBuffer::getDataConst()->dout.serialSwitch; } -bool epi_getDO_serialDriverIsOn(void) -{ - - if ( do_serialSwitch & 1) - return true; - return false; +bool epi_getDO_serialDriverIsOn(void) { + return SharedMemBuffer::getDataConst()->dout.serialSwitch & 1; } -bool epi_getDO_serialMux1isSetToPrinter(void) -{ +bool epi_getDO_serialMux1isSetToPrinter(void) { // mux1 off: serial is switched to printer - if ((do_serialSwitch & 2)==0) - return true; - return false; + return (SharedMemBuffer::getDataConst()->dout.serialSwitch & 2) == 0; } -bool epi_getDO_serialMux1isSetToModem(void) -{ +bool epi_getDO_serialMux1isSetToModem(void) { // mux1 on: serial is switched to modem - if ((do_serialSwitch & 2)>0) - return true; - return false; + return (SharedMemBuffer::getDataConst()->dout.serialSwitch & 2) > 0; } -bool epi_getDO_serialMux2isSetToCredit(void) -{ +bool epi_getDO_serialMux2isSetToCredit(void) { // mux2 off: serial is switched to credit card terminal - if ((do_serialSwitch & 4)==0) - return true; - return false; + return (SharedMemBuffer::getDataConst()->dout.serialSwitch & 4) == 0; } -bool epi_getDO_serialMux2isSetToMifare(void) -{ +bool epi_getDO_serialMux2isSetToMifare(void) { // mux2 on: serial is switched to mifare reader - if ((do_serialSwitch & 4)>0) - return true; - return false; + return (SharedMemBuffer::getDataConst()->dout.serialSwitch & 4) > 0; } - - - - - -static uint8_t do_ledsAndFan; -void gpi_storeDO_ledsAndFan(uint8_t ledState) -{ +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 - do_ledsAndFan=ledState; + return SharedMemBuffer::getData()->dout.ledsAndFan = ledState; } -bool epi_getDO_led_coin(void) -{ - if (do_ledsAndFan & 1) - return true; - return false; +bool epi_getDO_led_coin(void) { + return (SharedMemBuffer::getDataConst()->dout.ledsAndFan & 1); } -bool epi_getDO_led_front(void) -{ - if (do_ledsAndFan & 2) - return true; - return false; +bool epi_getDO_led_front(void) { + return (SharedMemBuffer::getDataConst()->dout.ledsAndFan & 2); } -bool epi_getDO_led_ticket(void) -{ - if (do_ledsAndFan & 4) - return true; - return false; +bool epi_getDO_led_ticket(void) { + return (SharedMemBuffer::getDataConst()->dout.ledsAndFan & 4); } -bool epi_getDO_led_pin(void) -{ - if (do_ledsAndFan & 8) - return true; - return false; +bool epi_getDO_led_pin(void) { + return (SharedMemBuffer::getDataConst()->dout.ledsAndFan & 8); } -bool epi_getDO_led_start(void) -{ - if (do_ledsAndFan & 16) - return true; - return false; +bool epi_getDO_led_start(void) { + return (SharedMemBuffer::getDataConst()->dout.ledsAndFan & 16); } -bool epi_getDO_led_inside(void) -{ - if (do_ledsAndFan & 32) - return true; - return false; +bool epi_getDO_led_inside(void) { + return (SharedMemBuffer::getDataConst()->dout.ledsAndFan & 32); } -bool epi_getDO_fan(void) -{ - if (do_ledsAndFan & 64) - return true; - return false; +bool epi_getDO_fan(void) { + return (SharedMemBuffer::getDataConst()->dout.ledsAndFan & 64); } - - -static uint8_t do_laermUndRelay; -void gpi_storeDO_sirenAndRelay(uint8_t sirenRelay) -{ +uint8_t gpi_storeDO_sirenAndRelay(uint8_t sirenRelay) { // bit0: siren 1:relay - do_laermUndRelay=sirenRelay; + return SharedMemBuffer::getData()->dout.laermUndRelay = sirenRelay; } -bool epi_getDO_sirene(void) -{ - if (do_laermUndRelay & 1) - return true; - return false; +bool epi_getDO_sirene(void) { + return SharedMemBuffer::getDataConst()->dout.laermUndRelay & 1; } -bool epi_getDO_relay(void) -{ - if (do_laermUndRelay & 2) - return true; - return false; +bool epi_getDO_relay(void) { + return SharedMemBuffer::getDataConst()->dout.laermUndRelay & 2; } -static uint8_t do_ptuWake; -void gpi_storeDO_ptuWake(uint8_t state) -{ - do_ptuWake=state; +uint8_t gpi_storeDO_ptuWake(uint8_t state) { + return SharedMemBuffer::getData()->dout.ptuWake = state; } -bool epi_getDO_ptuWake(void) -{ - if (do_ptuWake>0) - return true; - return false; +bool epi_getDO_ptuWake(void) { + return SharedMemBuffer::getDataConst()->dout.ptuWake > 0; } -static uint8_t do_auxPower; -void gpi_storeDO_auxPower(uint8_t pwr) -{ - do_auxPower=pwr; +uint8_t gpi_storeDO_auxPower(uint8_t pwr) { + return SharedMemBuffer::getData()->dout.auxPower = pwr; } -bool epi_getDO_auxPower(void) -{ - if (do_auxPower>0) - return true; - return false; +bool epi_getDO_auxPower(void) { + return SharedMemBuffer::getDataConst()->dout.auxPower > 0; } - - -static uint8_t do_coinShutter; -void gpi_storeDO_coinShutter(uint8_t state) -{ - do_coinShutter=state; +uint8_t gpi_storeDO_coinShutter(uint8_t state) { + return SharedMemBuffer::getData()->dout.coinShutter = state; } -bool epi_getDO_coinShutterOpen(void) -{ +bool epi_getDO_coinShutterOpen(void) { // bit0: Coin shutter output, bit1: input-test-output - if (do_coinShutter & 1) - return true; - return false; + return SharedMemBuffer::getDataConst()->dout.coinShutter & 1; } -bool epi_getDO_coinShutterTest(void) -{ +bool epi_getDO_coinShutterTest(void) { // bit0: Coin shutter output, bit1: input-test-output - if (do_coinShutter & 2) - return true; - return false; + return SharedMemBuffer::getDataConst()->dout.coinShutter & 2; } -static uint8_t do_coinEscrow; - -void gpi_storeDO_coinEscrow(uint8_t state) -{ - do_coinEscrow=state; +uint8_t gpi_storeDO_coinEscrow(uint8_t state) { + return SharedMemBuffer::getData()->dout.coinEscrow = state; } -uint8_t epi_getDO_coinEscrow(void) -{ +uint8_t epi_getDO_coinEscrow(void) { // retval: 1:return flap is open 2:take flap is open 0:closed - if (do_coinEscrow &1) - return 1; // return flap is open - if (do_coinEscrow &2) + 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; } -static uint8_t do_printerPower; - -void gpi_storeDO_printerPwrOn(uint8_t state) -{ - do_printerPower=state; +uint8_t gpi_storeDO_printerPwrOn(uint8_t state) { + return SharedMemBuffer::getData()->dout.printerPower = state; } -uint8_t epi_getDO_printerPwr(void) -{ - return do_printerPower; +uint8_t epi_getDO_printerPwr(void) { + return SharedMemBuffer::getDataConst()->dout.printerPower; } //------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------ //----------------------------- Mifare Card Reader ----------------------------------- - -#define NROFMIFSTATEBYTES 40 -static uint8_t Sdata_MIF_STATE[NROFMIFSTATEBYTES]; - -uint8_t gpi_storeMifReaderStateAndCardType(uint8_t *buf) -{ +uint8_t gpi_storeMifReaderStateAndCardType(uint8_t const *buf) { // retval 0=OK 1=error host buffer too small - for (uint8_t nn=0; nnSdata.MIF_STATE, 0x00, + sizeof(SharedMemBuffer::getData()->Sdata.MIF_STATE)); + memcpy(SharedMemBuffer::getData()->Sdata.MIF_STATE, buf, 8); return 0; // OK } @@ -1270,424 +927,387 @@ byte 31: current sector: 0 byte 32: result, always 0 */ -uint8_t epi_restoreMifState(uint8_t *buf, uint8_t maxBufferSize) -{ +uint8_t epi_restoreMifState(uint8_t *buf, uint8_t maxBufferSize) { // HWapi can read States from DC - if (maxBufferSize<8) + if (maxBufferSize<8) { return 1; // error - - for (uint8_t nn=0; nn<8; nn++) - buf[nn]=Sdata_MIF_STATE[nn]; + } + memcpy(buf, SharedMemBuffer::getData()->Sdata.MIF_STATE, 8); return 0; // OK - } - - -static uint8_t Sdata_MIF_DATA[12][64]; // data come in blockwise, so safe them blockwise as well -void gpi_storeMifCardData(uint8_t blkNr, uint8_t *receivedData) -{ - if (blkNr<12) - { - for (uint8_t nn=0; nn<64; nn++) - Sdata_MIF_DATA[blkNr][nn]=receivedData[nn]; +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 } -} - -uint8_t epi_restoreMifData(uint8_t blkNr, uint8_t *buf, uint8_t maxBufferSize) -{ - if (blkNr>11 || maxBufferSize<64) - return 1; // error - - for (uint8_t nn=0; nn<64; nn++) - buf[nn]=Sdata_MIF_DATA[blkNr][nn]; - + memcpy(buf, &SharedMemBuffer::getDataConst()->Sdata.MIF_DATA[blkNr][0], 64); return 0; // ois OK } -//------------------------------------------------------------------------------------ -//------------------------------------------------------------------------------------ - - -static uint8_t Sdata_PRN_STATE[pi_prnStateArraySize]; - -void epi_restorePrinterState(uint8_t *buf) -{ - uint8_t nn; - - for (nn=0; nnmif_cardType = typ; + strncpy((char *)holder, (char *)SharedMemBuffer::getData()->mif_cardHolder, 7); + SharedMemBuffer::getData()->mif_cardHolder[7] = '\0'; } -void gpi_storePrinterState(uint8_t *buf) -{ - uint8_t nn; - - for (nn=0; nnmif_cardHolder, (char *)holder, 7); + return SharedMemBuffer::getData()->mif_cardType; } -static uint8_t Sdata_PRN_FONTS[pi_prnFontArraySize]; - -void epi_restorePrinterFonts(uint8_t *buf) -{ - uint8_t nn; - - for (nn=0; nnSdata.PRN_STATE, + sizeof(SharedMemBuffer::getData()->Sdata.PRN_STATE)); } -void gpi_storePrinterFonts(uint8_t *buf) -{ - uint8_t nn; - - for (nn=0; nnSdata.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)); +} - - -static bool Sdata_mdb_busRdy; -static bool Sdata_mdb_V12on; -static bool Sdata_mdb_V5on; +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 -void gpi_storeMdbState(uint8_t busReady, uint8_t V12on, uint8_t V5on ) -{ - Sdata_mdb_busRdy=bool(busReady); - Sdata_mdb_V12on=bool(V12on); - Sdata_mdb_V5on=bool(V5on); +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 Sdata_mdb_busRdy; +bool epi_restoreMdbBusReady(void) { + return SharedMemBuffer::getDataConst()->Sdata.mdb_busRdy; } -bool epi_restoreMdbV12Ready(void) -{ - return Sdata_mdb_V12on; +bool epi_restoreMdbV12Ready(void) { + return SharedMemBuffer::getDataConst()->Sdata.mdb_V12on; } -bool epi_restoreMdbV5Ready(void) -{ - return Sdata_mdb_V5on; +bool epi_restoreMdbV5Ready(void) { + return SharedMemBuffer::getDataConst()->Sdata.mdb_V5on; } - - -static uint8_t Sdata_mdbNrOfRecData; -static uint8_t Sdata_RecBuff[40]; - // 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 *data) -{ - - tslib_strclr(Sdata_RecBuff,0,40); - Sdata_mdbNrOfRecData=leng; - tslib_strcpy(data, Sdata_RecBuff, uint16_t(Sdata_mdbNrOfRecData)); +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=Sdata_mdbNrOfRecData; - tslib_strcpy(Sdata_RecBuff, data, Sdata_mdbNrOfRecData); - *leng = Sdata_mdbNrOfRecData; - +void epi_restoreMdbResponse(uint8_t *leng, uint8_t *data) { + *leng = SharedMemBuffer::getDataConst()->Sdata.mdbNrOfRecData; + memcpy((char *)data, + (char *)&SharedMemBuffer::getDataConst()->Sdata.RecBuff[0], *leng); } - - - - - - - - -static uint8_t Sdata_empNrOfsettings; -static uint8_t Sdata_emp_settingsBuff[66]; - -void gpi_storeEmpSettings(uint8_t leng, uint8_t *data) -{ - if (leng>64) leng=64; - Sdata_empNrOfsettings=leng; - tslib_strcpy(data, Sdata_emp_settingsBuff, leng); +void gpi_storeEmpSettings(uint8_t leng, uint8_t const *data) { + if (leng > 64) { + leng = 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=Sdata_empNrOfsettings; - tslib_strcpy(Sdata_emp_settingsBuff, data, Sdata_empNrOfsettings); +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 - - -struct T_coin -{ - uint8_t valid; - uint8_t signal; - uint8_t error; - uint8_t pad; - uint16_t value; -}; - -static struct T_coin gotCoin[MEMDEPTH_GOTCOINS]; -static uint8_t ctr_gotCoin; - - -void sub_enterData(uint8_t valid, uint8_t signal, uint8_t error, uint16_t value ) -{ - if (ctr_gotCoinctr_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; } - ctr_gotCoin++; - + SharedMemBuffer::getData()->ctr_gotCoin += 1; } -void gpi_storeEmpCoinSignal(uint8_t leng, uint8_t *data) -{ +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; - -//qDebug()<<"store emp data, len: "<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 ); - -//qDebug()<< "emp IN data: " << data[pp] << " " << data[pp+1] -// << " " <ctr_gotCoin; } -void epi_restoreEmpCoinSignal(uint8_t *valid, uint8_t *signal, uint8_t *error, uint16_t *value) -{ - ctr_gotCoin--; - if (ctr_gotCoinctr_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; } -/* -qDebug()<<"read emp data, nr "< 64) { + leng = 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) { + if (leng > 64) { + leng = 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 Sdata_NrOfDeviceSetting; -static uint8_t Sdata_DeviceSettingBuff[66]; - -void gpi_storeRbDeviceSettings(uint8_t leng, uint8_t *data) // getestet am 12.4.23TS -{ - if (leng>64) leng=64; - Sdata_NrOfDeviceSetting=leng; - tslib_strcpy(data, Sdata_DeviceSettingBuff, leng); // getestet am 12.4.23TS -} - -void epi_restoreRbDeviceSettings(uint8_t *leng, uint8_t *data) // getestet am 12.4.23TS -{ - - *leng=Sdata_NrOfDeviceSetting; - tslib_strcpy(Sdata_DeviceSettingBuff, data, Sdata_NrOfDeviceSetting); -} - - - - -static uint8_t Sdata_NrOfMachineIDSetting; -static uint8_t Sdata_NrOfMachineIDBuff[66]; - -void gpi_storeMachineIDsettings(uint8_t leng, uint8_t *data) -{ - if (leng>64) leng=64; - Sdata_NrOfMachineIDSetting=leng; - tslib_strcpy(data, Sdata_NrOfMachineIDBuff, leng); -} - -void epi_restoreMachineIDsettings(uint8_t *leng, uint8_t *data) -{ - - *leng=Sdata_NrOfMachineIDSetting; - tslib_strcpy(Sdata_NrOfMachineIDBuff, data, Sdata_NrOfMachineIDSetting); -} - - -static uint32_t store_insertedAmount; -static uint16_t store_lastCoinType[64]; -static uint16_t store_lastCoinValue[64]; static uint8_t p_lastCoin; -void epi_clearCurrentPayment(void) -{ +void epi_clearCurrentPayment(void) { // call at beginning of coin collection - store_insertedAmount=0; - p_lastCoin=0; + SharedMemBuffer::getData()->store.insertedAmount = 0; + p_lastCoin = 0; } -void gpi_storeCurrentPayment(uint32_t insertedAmount, uint16_t lastCoinType, uint16_t lastCoinValue) -{ - store_insertedAmount=insertedAmount; - store_lastCoinType[p_lastCoin]=lastCoinType; - store_lastCoinValue[p_lastCoin]=lastCoinValue; +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 store_insertedAmount; +uint32_t epi_CurrentPaymentGetAmount(void) { + return SharedMemBuffer::getDataConst()->store.insertedAmount; } -uint16_t epi_CurrentPaymentGetLastCoin(void) -{ - uint8_t pp; - pp=p_lastCoin; - if (pp==0) +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 store_lastCoinValue[pp]; + } + if (pp>0) { + pp--; + } + return SharedMemBuffer::getDataConst()->store.lastCoinValue[pp]; } -bool epi_CurrentPaymentGetAllCoins(uint16_t *types, uint16_t *values) -{ +bool epi_CurrentPaymentGetAllCoins(uint16_t *types, uint16_t *values) { // alle bei diesem Verkauf eingeworfenen Münzen sind gespeichert falls die jmd. braucht - uint8_t nn; - if (p_lastCoin==0) + if (p_lastCoin==0) { return false; - for (nn=0; nn<64; nn++) - { - types[nn]=store_lastCoinType[nn]; - values[nn]=store_lastCoinValue[nn]; } - + for (int nn=0; nn<64; nn++) { + types[nn] = SharedMemBuffer::getDataConst()->store.lastCoinType[nn]; + values[nn] = SharedMemBuffer::getDataConst()->store.lastCoinValue[nn]; + } return true; } - -uint64_t stor_wakSrc; - -void gpi_storeWakeSources(uint8_t *receivedData) -{ - uint8_t uctmp; - int nn; - stor_wakSrc=0; - for (nn=7; nn>=0; nn--) - { - uctmp=receivedData[nn]; - stor_wakSrc |=uctmp; - stor_wakSrc<<=8; +void gpi_storeWakeSources(uint8_t const *receivedData) { + SharedMemBuffer::getData()->store.wakeSrc = 0; + for (int nn=7; nn>=0; nn--) { + uint8_t const uctmp = receivedData[nn]; + SharedMemBuffer::getData()->store.wakeSrc |= uctmp; + SharedMemBuffer::getData()->store.wakeSrc <<= 8; } } -uint64_t epi_getWakeSources(void) -{ - return stor_wakSrc; +uint64_t epi_getWakeSources(void) { + return SharedMemBuffer::getDataConst()->store.wakeSrc; } - - - -static uint8_t store_rbDevParamLen; -static uint8_t store_rbDevParams[66]; - -void gpi_storeExtendedTime(uint8_t leng, uint8_t *data) -{ - if (leng>64) leng=64; - store_rbDevParamLen=leng; - tslib_strcpy(data, store_rbDevParams, leng); +void gpi_storeExtendedTime(uint8_t leng, uint8_t const *data) { + if (leng > 64) { + leng = 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=store_rbDevParamLen; - tslib_strcpy(store_rbDevParams, data, store_rbDevParamLen); +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 -static uint8_t store_deviceCondLen; -static uint8_t store_deviceCond[66]; - -void gpi_storeDeviceConditions(uint8_t leng, uint8_t *data) -{ - if (leng>64) leng=64; - store_deviceCondLen=leng; - tslib_strcpy(data, store_deviceCond, leng); +void gpi_storeDeviceConditions(uint8_t leng, uint8_t const *data) { + if (leng > 64) { + leng = 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=store_deviceCondLen; - tslib_strcpy(store_deviceCond, data, store_deviceCondLen); +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 -static uint8_t store_machCondLen; -static uint8_t store_machCond[66]; - -void gpi_storeDynMachineConditions(uint8_t leng, uint8_t *data) -{ - if (leng>64) leng=64; - store_machCondLen=leng; - tslib_strcpy(data, store_machCond, leng); +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=store_machCondLen; - tslib_strcpy(store_machCond, data, store_machCondLen); +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; +} diff --git a/src/tslib.cpp b/src/tslib.cpp index 4afd7e9..a257256 100644 --- a/src/tslib.cpp +++ b/src/tslib.cpp @@ -76,6 +76,23 @@ uint8_t uint2uchar(uint16_t uival, bool getHighB) } +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));