Add use of shared memory.

Add changes for version 3.4. of library.
This commit is contained in:
Gerhard Hoffmann 2023-04-18 12:23:18 +02:00
parent cb4412779f
commit 86311de486

View File

@ -21,8 +21,11 @@
#include "controlBus.h" #include "controlBus.h"
#include "storeINdata.h" #include "storeINdata.h"
#include "dcBL.h" #include "dcBL.h"
#include "shared_mem_buffer.h"
#include <QDebug> #include <QDebug>
#include <../plugins/interfaces.h> #include <QSharedMemory>
#include "interfaces.h"
static const QMap<QString, int> baudrateMap = { static const QMap<QString, int> baudrateMap = {
@ -30,20 +33,29 @@ static const QMap<QString, int> baudrateMap = {
{"57600" , 4}, {"115200" , 5} {"57600" , 4}, {"115200" , 5}
}; };
hwapi::hwapi(QWidget *parent) : QObject(parent) hwapi::hwapi(QWidget *parent) : QObject(parent) {
{ // create or attach shared memory segment
// constructor // !!! The compoment creating the shared memory MUST be ATBQT !!!
//epi_resetAllDOs(); m_sharedMem = SharedMemBuffer::getShm(sizeof(SharedMemBuffer));
//PI_INI(); 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(); sendWRcmd_INI();
myDatif = new T_datif(); 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! char local[70], copie[1350]; // 64byte more then max buffer size!
int LL, nn, len, maxruns=20; int LL, nn, len, maxruns=20;
@ -739,13 +751,16 @@ QString hwapi::rtc_getTimStr() const
{ {
uint8_t hh, mm, ss, buf[20], nn; uint8_t hh, mm, ss, buf[20], nn;
QString qbuf; QString qbuf;
char ctmp;
qbuf.clear(); qbuf.clear();
for (nn=0; nn<20; nn++) buf[nn]=0; for (nn=0; nn<20; nn++) buf[nn]=0;
epi_getTime(&hh, &mm, &ss); epi_getTime(&hh, &mm, &ss);
GetTimeString(hh, mm, ss, HourSys24h, MITSEK, buf); // about 12byte long 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; return qbuf;
} }
@ -753,14 +768,17 @@ QString hwapi::rtc_getDatStr() const
{ {
uint8_t day, month, year, buf[20], nn; uint8_t day, month, year, buf[20], nn;
QString qbuf; QString qbuf;
char ctmp;
qbuf.clear(); qbuf.clear();
for (nn=0; nn<20; nn++) buf[nn]=0; for (nn=0; nn<20; nn++) buf[nn]=0;
epi_getDate(&year, &month, &day); epi_getDate(&year, &month, &day);
GetDateString(day, month, 0x20, year, DateFormatDeutsch, 0, buf); GetDateString(day, month, 0x20, year, DateFormatDeutsch, 0, buf);
for (nn=0; nn<20; nn++) for (nn=0; nn<20; nn++)
qbuf[nn]=buf[nn]; {
ctmp= buf[nn];
qbuf[nn]=ctmp;
}
return qbuf; return qbuf;
} }
@ -2221,7 +2239,8 @@ bool hwapi::pri_TD_addText(QByteArray text) const
bool hwapi::pri_TD_addValue(int val) const bool hwapi::pri_TD_addValue(int val) const
{ {
QString tmpStr; // QString tmpStr;
QByteArray tmpStr;
tmpStr.setNum(val,10); // up to 12 chars tmpStr.setNum(val,10); // up to 12 chars
if (ticketTemplate.length()>1266) if (ticketTemplate.length()>1266)
return false; 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 // send start address, nr of 64byte-block, start with 0
// will be sent only for folling block-numbers: // will be sent only for folling block-numbers:
@ -3106,7 +3125,7 @@ void hwapi::bl_openBinary(void) const
dcBL_loadBinary(0); 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 // send 64 byte from bin file
uint8_t LL=length, sendBuf[80], sendLen; uint8_t LL=length, sendBuf[80], sendLen;
@ -3137,6 +3156,7 @@ void hwapi::bl_sendLastBlock(void) const
len=dcBL_writeLastPage(buf); len=dcBL_writeLastPage(buf);
sendWRcmd_setSendBlock160(len, buf); sendWRcmd_setSendBlock160(len, buf);
} }
uint8_t hwapi::bl_wasSendingDataOK(void) const 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 bool hwapi::sys_runCompleteTest(void) const
{ {
// warning: lasts 20s in one pace // 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 // return true if a Json-file can be sent
// check free memory // check free memory
uint8_t frei=FDLONG_STACKDEPTH - check4FDlongCmd(); uint8_t frei=check4freeFDlongCmd();
// Command-Stack sollte 16 Commands fassen, je 64byte Nutzdaten = 1024byte // 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 // frei gibt also die Anzahl freier 64byte Bloecke zurueck
// das Json-File hat max 800 byte = 13 bloecke // das Json-File hat max 800 byte = 13 bloecke
if (frei<16) // Puffer muss ganz leer sein! nicht dass was durcheinander kommt 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 dateiLang<<=6; // auf volle 64byte aufgerundet
// check free memory // check free memory
frei=FDLONG_STACKDEPTH - check4FDlongCmd(); frei=check4freeFDlongCmd();
// Command-Stack sollte 16 Commands fassen, je 64byte Nutzdaten = 1024byte // 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 // frei gibt also die Anzahl freier 64byte Bloecke zurueck
// das Json-File hat max 800 byte = 13 bloecke // das Json-File hat max 800 byte = 13 bloecke
if (frei<16) // Puffer muss ganz leer sein! nicht dass was durcheinander kommt 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); biox_CopyBlock(inhaltOfJson, uitmp, temp, 0, 64);
longFDcmd_set(31,0, bn++, 64, temp); longFDcmd_set(31,0, bn++, 64, temp);
//uitmp<<=6; // falsch
uitmp+=64; uitmp+=64;
// uitmp<<=6;
} while(uitmp < dateiLang); } while(uitmp < dateiLang);
longFDcmd_set(32, 0,0, 0,temp); // Abschluss 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); return sendFDcmd_set(152, 0,0, nrOftemplate,0,0,0);
} }
void hwapi::log_getHoldAccountNumbers(uint32_t *accNr ) const void hwapi::log_getHoldAccountNumbers(uint8_t *nrOfVals, uint16_t *accNr ) const
// returns all acc nrs of the backuped vault records
// use: uint32_t backupedAccNumbers[8]
{ {
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 bool hwapi::log_selectVaultRecord(uint16_t accountNr ) const
{ {
// return true if sending, false if cmd-stack is full // 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); dat1=uint2uchar(accountNr, LOWBYTE);
dat2=uint2uchar(accountNr, HIGHBYTE); 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 bool hwapi::log_getVaultRecord(struct T_vaultRecord *retVR) const
void hwapi::log_getVaultRecord(struct T_vaultRecord *retVR) const
// which was selected by: log_selectVaultRecord() // which was selected by: log_selectVaultRecord()
// to be forwarded to Ismas // 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 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 // return 1,2,3,4 = upper, lower access card, printer test, coin test
// cardholder: 7byte Name-String // cardholder: 7byte Name-String
{ {
Q_UNUSED(cardholder); uint8_t type, buf[8], nn;
return 0; // to satisfy compiler 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 // retval: 6 bytes, bit coded, 1=event keeps DC awake
return epi_getWakeSources(); 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]; //uint8_t leng, data[66];
epi_restoreDeviceConditions(leng, data); epi_restoreDeviceConditions(leng, data);
} }
//void hwapi::sys_getDynMachineConditions(struct T_dynamicCondition *dynMachCond) const void hwapi::sys_getDeviceConditions(struct T_moduleCondition *devCond) const {
void hwapi::sys_getDynMachineConditions(uint8_t *leng, uint8_t *data) 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
{ {
epi_restoreDeviceConditions(leng, data); *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();
}