Add use of shared memory.
Add changes for version 3.4. of library.
This commit is contained in:
		
							
								
								
									
										273
									
								
								src/hwapi.cpp
									
									
									
									
									
								
							
							
						
						
									
										273
									
								
								src/hwapi.cpp
									
									
									
									
									
								
							@@ -21,8 +21,11 @@
 | 
			
		||||
#include "controlBus.h"
 | 
			
		||||
#include "storeINdata.h"
 | 
			
		||||
#include "dcBL.h"
 | 
			
		||||
#include "shared_mem_buffer.h"
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
#include <../plugins/interfaces.h>
 | 
			
		||||
#include <QSharedMemory>
 | 
			
		||||
 | 
			
		||||
#include "interfaces.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static const QMap<QString, int> baudrateMap = {
 | 
			
		||||
@@ -30,20 +33,29 @@ static const QMap<QString, int> baudrateMap = {
 | 
			
		||||
  {"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();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
hwapi::~hwapi() {
 | 
			
		||||
    if (m_sharedMem && m_sharedMem->isAttached()) {
 | 
			
		||||
        m_sharedMem->detach();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void hwapi::sub_storeSendingText(QByteArray *buf) const
 | 
			
		||||
{
 | 
			
		||||
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 +751,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 +768,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 +2239,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 +3090,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 +3125,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 +3156,7 @@ void hwapi::bl_sendLastBlock(void) const
 | 
			
		||||
 | 
			
		||||
    len=dcBL_writeLastPage(buf);
 | 
			
		||||
    sendWRcmd_setSendBlock160(len, buf);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint8_t hwapi::bl_wasSendingDataOK(void) const
 | 
			
		||||
@@ -3309,6 +3329,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(++nn<LL);
 | 
			
		||||
 | 
			
		||||
    return true;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
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;
 | 
			
		||||
};
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool hwapi::sys_runCompleteTest(void) const
 | 
			
		||||
{
 | 
			
		||||
    // warning: lasts 20s in one pace
 | 
			
		||||
@@ -3320,9 +3394,8 @@ bool hwapi::sys_ready4sending(void) const
 | 
			
		||||
    // return true if a Json-file can be sent
 | 
			
		||||
 | 
			
		||||
    // check free memory
 | 
			
		||||
    uint8_t frei=FDLONG_STACKDEPTH - check4FDlongCmd();
 | 
			
		||||
    uint8_t frei=check4freeFDlongCmd();
 | 
			
		||||
        // Command-Stack sollte 16 Commands fassen, je 64byte Nutzdaten = 1024byte
 | 
			
		||||
        // in check4FDlongCmd() steht wieviele Plaetze bereits belegt sind
 | 
			
		||||
        // frei gibt also die Anzahl freier 64byte Bloecke zurueck
 | 
			
		||||
        // das Json-File hat max 800 byte = 13 bloecke
 | 
			
		||||
    if (frei<16)        // Puffer muss ganz leer sein! nicht dass was durcheinander kommt
 | 
			
		||||
@@ -3357,9 +3430,8 @@ bool hwapi::sys_sendJsonFileToDc(uint8_t kindOfFile, uint8_t nrOfTemplate, uint8
 | 
			
		||||
    dateiLang<<=6;  // auf volle 64byte aufgerundet
 | 
			
		||||
 | 
			
		||||
    // check free memory
 | 
			
		||||
    frei=FDLONG_STACKDEPTH - check4FDlongCmd();
 | 
			
		||||
    frei=check4freeFDlongCmd();
 | 
			
		||||
        // Command-Stack sollte 16 Commands fassen, je 64byte Nutzdaten = 1024byte
 | 
			
		||||
        // in check4FDlongCmd() steht wieviele Plaetze bereits belegt sind
 | 
			
		||||
        // frei gibt also die Anzahl freier 64byte Bloecke zurueck
 | 
			
		||||
        // das Json-File hat max 800 byte = 13 bloecke
 | 
			
		||||
    if (frei<16)        // Puffer muss ganz leer sein! nicht dass was durcheinander kommt
 | 
			
		||||
@@ -3380,8 +3452,8 @@ bool hwapi::sys_sendJsonFileToDc(uint8_t kindOfFile, uint8_t nrOfTemplate, uint8
 | 
			
		||||
    {
 | 
			
		||||
        biox_CopyBlock(inhaltOfJson, uitmp, temp, 0, 64);
 | 
			
		||||
        longFDcmd_set(31,0, bn++, 64, temp);
 | 
			
		||||
        uitmp += 64;
 | 
			
		||||
        // uitmp<<=6;
 | 
			
		||||
        //uitmp<<=6;  // falsch
 | 
			
		||||
        uitmp+=64;
 | 
			
		||||
    } while(uitmp < dateiLang);
 | 
			
		||||
 | 
			
		||||
    longFDcmd_set(32, 0,0, 0,temp);       // Abschluss
 | 
			
		||||
@@ -3412,11 +3484,12 @@ bool hwapi::prn_printTemplate(uint8_t nrOftemplate) const
 | 
			
		||||
    return sendFDcmd_set(152, 0,0, nrOftemplate,0,0,0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void hwapi::log_getHoldAccountNumbers(uint32_t *accNr ) const
 | 
			
		||||
    // returns all acc nrs of the backuped vault records
 | 
			
		||||
    // use: uint32_t backupedAccNumbers[8]
 | 
			
		||||
void hwapi::log_getHoldAccountNumbers(uint8_t *nrOfVals, uint16_t *accNr ) const
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(accNr);
 | 
			
		||||
    // returns all acc nrs of the backuped vault records
 | 
			
		||||
    // use: uint16_t backupedAccNumbers[8]
 | 
			
		||||
 | 
			
		||||
    epi_restoreDCbackupAccNr(nrOfVals, accNr);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -3424,21 +3497,62 @@ void hwapi::log_getHoldAccountNumbers(uint32_t *accNr ) const
 | 
			
		||||
bool hwapi::log_selectVaultRecord(uint16_t accountNr ) const
 | 
			
		||||
{
 | 
			
		||||
    // return true if sending, false if cmd-stack is full
 | 
			
		||||
    uint8_t dat1, dat2;
 | 
			
		||||
    // and trigger transfer
 | 
			
		||||
 | 
			
		||||
    uint8_t dat1, dat2;
 | 
			
		||||
    bool ret;
 | 
			
		||||
 | 
			
		||||
    uint8_t frei=check4freeFDshortCmd();
 | 
			
		||||
    if (frei<8)
 | 
			
		||||
        return false;
 | 
			
		||||
 | 
			
		||||
    epi_iniVRstorage();
 | 
			
		||||
    dat1=uint2uchar(accountNr, LOWBYTE);
 | 
			
		||||
    dat2=uint2uchar(accountNr, HIGHBYTE);
 | 
			
		||||
    return sendFDcmd_set(153, 0,0, dat1,dat2,0,0);
 | 
			
		||||
    ret=sendFDcmd_set(153, 0,0, dat1,dat2,0,0); // select this record
 | 
			
		||||
        // true means "will be sent"
 | 
			
		||||
    sendFDcmd_set(0,38,0, 0,0,0,0);    // return VaultRecord block-Nr.0
 | 
			
		||||
    sendFDcmd_set(0,38,1, 0,0,0,0);    // return VaultRecord block-Nr.1
 | 
			
		||||
    sendFDcmd_set(0,38,2, 0,0,0,0);    // return VaultRecord block-Nr.2
 | 
			
		||||
    sendFDcmd_set(0,38,3, 0,0,0,0);    // return VaultRecord block-Nr.3
 | 
			
		||||
    sendFDcmd_set(0,38,4, 0,0,0,0);    // return VaultRecord block-Nr.4
 | 
			
		||||
    sendFDcmd_set(0,38,5, 0,0,0,0);    // return VaultRecord block-Nr.4
 | 
			
		||||
        // 38: <100 to get long 64byte response
 | 
			
		||||
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool hwapi::log_chkIfVaultRecordAvailable(void) const
 | 
			
		||||
{
 | 
			
		||||
    // return true if completly received
 | 
			
		||||
    return epi_checkIfVaultRecordAvailable();
 | 
			
		||||
        return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//request, isAvailable
 | 
			
		||||
void hwapi::log_getVaultRecord(struct T_vaultRecord *retVR) const
 | 
			
		||||
bool hwapi::log_getVaultRecord(struct T_vaultRecord *retVR) const
 | 
			
		||||
    // which was selected by: log_selectVaultRecord()
 | 
			
		||||
    // to be forwarded to Ismas
 | 
			
		||||
    // return true if completly received
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(retVR);
 | 
			
		||||
 | 
			
		||||
    uint16_t LL, nn, len;
 | 
			
		||||
    char   *start;
 | 
			
		||||
    uint8_t  buf[400];
 | 
			
		||||
    bool ret;
 | 
			
		||||
 | 
			
		||||
    ret=epi_restoreVaultRecord(&len, buf);   // true if completly received
 | 
			
		||||
    if (ret==false)
 | 
			
		||||
        return false;
 | 
			
		||||
        // Puffer in struct eintragen:
 | 
			
		||||
    LL=sizeof(struct T_vaultRecord);		// =320
 | 
			
		||||
    start = &retVR->startbuffer[0];
 | 
			
		||||
    nn=0;
 | 
			
		||||
    do
 | 
			
		||||
    {
 | 
			
		||||
        *start = buf[nn];
 | 
			
		||||
        start++;
 | 
			
		||||
    } while(++nn<LL);
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool hwapi::prn_printAccountReceipt(void) const
 | 
			
		||||
@@ -3516,36 +3630,95 @@ bool hwapi::vend_failed(void) const
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint8_t hwapi::mif_getCardType(QString cardholder) const
 | 
			
		||||
uint8_t hwapi::mif_getCardType(QString *cardholder) const
 | 
			
		||||
    // return 1,2,3,4 = upper, lower access card, printer test, coin test
 | 
			
		||||
    // cardholder: 7byte Name-String
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(cardholder);
 | 
			
		||||
    return 0; // to satisfy compiler
 | 
			
		||||
    uint8_t type, buf[8], nn;
 | 
			
		||||
    char ctmp;
 | 
			
		||||
 | 
			
		||||
    memset(buf, 0x00, sizeof(buf));
 | 
			
		||||
 | 
			
		||||
    type=epi_mifGetCardType(&buf[0]);
 | 
			
		||||
        //holder[8] = name of card holder
 | 
			
		||||
        // retval Type of MifareCard, 1=upper door, 2=lower door 3=test printer 4=test coins
 | 
			
		||||
    for (nn=0;nn<8; nn++) {
 | 
			
		||||
        ctmp=buf[nn];
 | 
			
		||||
        cardholder[nn]=ctmp;
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
    return type;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint64_t hwapi::sys_getWakeSource(void) const
 | 
			
		||||
{
 | 
			
		||||
uint64_t hwapi::sys_getWakeSource(void) const {
 | 
			
		||||
    // retval: 6 bytes, bit coded, 1=event keeps DC awake
 | 
			
		||||
     return epi_getWakeSources();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//void hwapi::sys_getDeviceConditions(struct T_moduleCondition *devCond) const
 | 
			
		||||
void hwapi::sys_getDeviceConditions(uint8_t *leng, uint8_t *data) const
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
void hwapi::sys_getDeviceConditions(uint8_t *leng, uint8_t *data) const {
 | 
			
		||||
    //uint8_t leng, data[66];
 | 
			
		||||
    epi_restoreDeviceConditions(leng, data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//void hwapi::sys_getDynMachineConditions(struct T_dynamicCondition *dynMachCond) const
 | 
			
		||||
void hwapi::sys_getDynMachineConditions(uint8_t *leng, uint8_t *data) const
 | 
			
		||||
{
 | 
			
		||||
    epi_restoreDeviceConditions(leng, data);
 | 
			
		||||
void hwapi::sys_getDeviceConditions(struct T_moduleCondition *devCond) const {
 | 
			
		||||
    uint16_t LL, nn;
 | 
			
		||||
    uint8_t *start;
 | 
			
		||||
    uint8_t  buf[70], leng;
 | 
			
		||||
 | 
			
		||||
    epi_restoreDeviceConditions(&leng, buf);
 | 
			
		||||
 | 
			
		||||
        // Puffer in struct eintragen:
 | 
			
		||||
    LL=sizeof(struct T_moduleCondition);
 | 
			
		||||
    start = &devCond->ram;
 | 
			
		||||
    nn=0;
 | 
			
		||||
    do
 | 
			
		||||
    {
 | 
			
		||||
        *start = buf[nn];
 | 
			
		||||
        start++;
 | 
			
		||||
    } while(++nn<LL);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void hwapi::sys_getDynMachineConditions(uint8_t *leng, uint8_t *data) const
 | 
			
		||||
{
 | 
			
		||||
    epi_restoreDynMachineConditions(leng, data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void hwapi::sys_getDynMachineConditions(struct T_dynamicCondition *dynMachCond) const
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    uint16_t LL, nn;
 | 
			
		||||
    char *start;
 | 
			
		||||
    uint8_t  buf[70], leng;
 | 
			
		||||
 | 
			
		||||
    epi_restoreDynMachineConditions(&leng, buf);
 | 
			
		||||
        // Puffer in struct eintragen:
 | 
			
		||||
    LL=sizeof(struct T_dynamicCondition);
 | 
			
		||||
    start = &dynMachCond->allDoorsDebounced;
 | 
			
		||||
    nn=0;
 | 
			
		||||
    do
 | 
			
		||||
    {
 | 
			
		||||
        *start = buf[nn];
 | 
			
		||||
        start++;
 | 
			
		||||
    } while(++nn<LL);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint32_t hwapi::cash_getAmountInVault(void) const
 | 
			
		||||
{
 | 
			
		||||
    return epi_getCashBoxContent();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint16_t hwapi::cash_getNrCoinsInVault(void) const
 | 
			
		||||
{
 | 
			
		||||
    return epi_getNrOfCoinsInCashBox();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user