From ef7932102fdfe659cb4ab25318d2bd54aa087683 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Tue, 18 Apr 2023 12:19:08 +0200 Subject: [PATCH] Massive change: using shared memory containing most device controller realted variables. --- src/storeINdata.cpp | 1542 ++++++++++++++++--------------------------- 1 file changed, 581 insertions(+), 961 deletions(-) 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; +}