Add collected changes from T.Sax

This commit is contained in:
2024-07-04 14:01:43 +02:00
parent ab5a343ab2
commit b0e55d8ea4
16 changed files with 2623 additions and 338 deletions

182
src/hwapi.cpp Normal file → Executable file
View File

@@ -5,21 +5,7 @@
* This api uses stored data and returns them in the following functions
* created: Q1/2020 TS until Q2/21
14.7.23TS: patch for correct printer state in line 3364 in sys_getDeviceConditions(struct T_moduleCondition *devCond) const
8.9.2023 two new functions (end of file) for mifare test. Interface version 4.4 DC4.40...4.43
14.09.2023: Verriegelung eingebaut, nur noch gültige Abr.Daten zurückgeben, Suchbegriff: <epi_restoreVaultRecord>
alle Mifare-Funktionen ueberprueft und ggf verbessert
18.09.2023: Signal "Kasse entnommen" und Signale "Tuer auf/zu" ueberprueft
20.9.2023: in datif die Abfrage der DynMachineData massiv beschleunigt
und hier in hwapi die entprellten Werte fuer Tueren und Kasse verwenden.
Problem war: Signal "Kasse entnommen" war zu langsam -> manchmal abr nicht gesendet
14.3.24 new function bool hwapi::cash_isCollectionStarted(void) const
padding three struct to 64 byte to avoid stack overflow when using
see history in hwapi.h
*/
#include "hwapi.h"
@@ -1770,8 +1756,10 @@ QString hwapi::mif_getCardDataStr(uint8_t blockNumber) const
uint8_t hwapi::prn_getHwState(struct Tprn_hw_state *prn_hw_state) const
{
// return printer hardware state: power is on? rs-driver on? rs_switch ok? hw-ready-line ok?
// printer on error or ok?
// return value:
// 0: unknown 1: printer OK
// 100: printer OK but paper near end
// 200: not connected 201: printer on error 202: no paper
return runProcess->prn_getHwState(prn_hw_state);
@@ -1779,13 +1767,8 @@ uint8_t hwapi::prn_getHwState(struct Tprn_hw_state *prn_hw_state) const
bool hwapi::prn_isUpAndReady(void) const
{
// 25.5.2023: geht nicht richtig :( bringt immer false obwohl Drucker OK
struct Tprn_hw_state prnHwNow;
prn_getHwState(&prnHwNow);
if (prnHwNow.inIdle && prnHwNow.rsSwOk && prnHwNow.rsDrvOk && prnHwNow.powerRdBk )
return true;
return false;
// gefixt am 24.5.2024
return runProcess->prn_isUpAndReady();
}
void hwapi::prn_getCurrentFontSetting(struct Tprn_currentSettings *prn_fonts) const
@@ -1809,46 +1792,10 @@ void hwapi::prn_getCurrentFontSetting(struct Tprn_currentSettings *prn_fonts) co
void hwapi::prn_sendText(QByteArray *buf) const
{
uint16_t nn, pp, mm, leng_byt, leng_blk, llb, freeStak;
uint8_t tmp66[66];
qCritical() << __PRETTY_FUNCTION__ << "RESET DC DATA VALID";
epi_clearDynMachineConditions(); // 24.6.23
gpi_storeDcDataValid(0);
// komplett aendern 11.9.23
memset(tmp66,0,66);
leng_byt=buf->size();
freeStak=check4freeFDstack();
freeStak<<=6;
if ( leng_byt > freeStak)
{
leng_byt=freeStak; // shorten the buffer as we cannot return an error (void function)
}
llb=leng_byt % 64; // length of last block, >0 if not dividable by 64
leng_blk=leng_byt / 64;
pp=0;
for (nn=0; nn<leng_blk; nn++)
{
for (mm=0; mm<64; mm++)
tmp66[mm]=buf->at(pp++);
longFDcmd_set(CMD2DC_PRI_PRINT_TXT, 0,0,64, tmp66);
}
if (llb>0)
{
//leng_blk++; // z.B. 200 = 3 volle blocks und ein block mit nur 8byte
memset(tmp66,0,66);
for (mm=0; mm<llb; mm++)
tmp66[mm]=buf->at(pp++);
for (mm=llb; mm<64; mm++)
tmp66[mm]=0;
longFDcmd_set(CMD2DC_PRI_PRINT_TXT, 0,0,64, tmp66);
}
runProcess->prn_sendText(buf);
// 23.5.2024TS: moved function down to runProc in order to have it available there.
// here in hwapi only a wrapper left
// ( this also supports the idea to keep hwapi short :)
}
@@ -1857,6 +1804,8 @@ void hwapi::prn_sendPrnSysCmd(uint8_t para1, uint8_t para2, uint32_t para3) cons
// send three byte through to printer, see printers manual
//sendWRcmd _setSendCommand8(SENDDIRCMD_PRN_SYS_CMD, para1, para2, 0, para3); hat gar nicht funktioniert
runProcess->prn_sendPrnSysCmd(para1, para2, para3);
/*
uint8_t data[64];
uint32_t ultmp=para3;
memset(data, 0,64);
@@ -1870,6 +1819,7 @@ void hwapi::prn_sendPrnSysCmd(uint8_t para1, uint8_t para2, uint32_t para3) cons
data[7]=uint8_t(ultmp);
longFDcmd_set(CMD2DC_PRI_SYS_CMD, 0, 0, 8, data);
*/
// getestet auf richtige uebertragung am 11.9.23TS
}
@@ -1887,7 +1837,7 @@ void hwapi::prn_sendPrnSetup(uint16_t paperSpeed, uint8_t density, uint8_t alig
// byte3: alignment 'l', 'c', 'r' = left, center, right
// byte4: orientation 0, 90, 180 = 0°, 90°, 180° rotation (by now not supported!)
// not batched! don't use twice within 100ms
/*
uint8_t buf[10];
uint16_t uitmp;
@@ -1900,7 +1850,8 @@ void hwapi::prn_sendPrnSetup(uint16_t paperSpeed, uint8_t density, uint8_t alig
buf[4]=orientation;
buf[5]=0;
longFDcmd_set(CMD2DC_PRI_SETUP,0,0,5, buf);
*/
runProcess->prn_sendPrnSetup(paperSpeed, density, alignment, orientation);
}
void hwapi::prn_movePaper(uint8_t wayInMm, uint8_t direction) const
@@ -2806,6 +2757,7 @@ bool hwapi::rtc_getExtendedTime(struct T_extTime *exTime) const
epi_restoreExtendedTime(&len, buf);
// Puffer in struct eintragen:
LL=sizeof(struct T_extTime);
if (LL>64) LL=64;
start = &(exTime->Hours);
nn=0;
do
@@ -3186,10 +3138,11 @@ void hwapi::sys_getDeviceConditions(struct T_moduleCondition *devCond) const
uint8_t *start;
uint8_t buf[70], leng;
epi_restoreDeviceConditions(&leng, buf);
epi_restoreDeviceConditions(&leng, buf); // leng is less then 64
// Puffer in struct eintragen:
LL=sizeof(struct T_moduleCondition);
if (LL>64) LL=64;
start = &devCond->ram;
nn=0;
do
@@ -3231,26 +3184,27 @@ void hwapi::sys_getDeviceConditions(struct T_moduleCondition *devCond) const
void hwapi::sys_getDynMachineConditions(uint8_t *leng, uint8_t *data) const
{
// not complete anymore
epi_restoreDynMachineConditions(leng, data);
}
void hwapi::sys_getDynMachineConditions(struct T_dynamicCondition *dynMachCond) const
{
uint16_t LL, nn;
char *start;
uint8_t buf[70], leng;
uint8_t buf[130], 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);
memcpy(dynMachCond, buf, sizeof(*dynMachCond)); // copy 64byte to the struct
// 3.7.24: stimmt nicht mehr weil struct im Ram die word grenzen einhaelt
// also ab hier einzeln uebertragen
dynMachCond->totalNrOfCuts = uchar2ulong(buf[57],buf[56],buf[55],buf[54]);
dynMachCond->nextAccountNumber = uchar2uint(buf[59], buf[58]);
dynMachCond->nrOfBillsInBox = uchar2uint(buf[61], buf[60]);
// 8.5.24TS, as the DC struct is >64byte now, it comes in two parts:
epi_restoreDynMachCond2(&leng, buf);
dynMachCond->amountInBillbox = uchar2ulong(buf[3], buf[2],buf[1],buf[0]);
dynMachCond->UbatAtLastPrint = uchar2uint(buf[5], buf[4]);
memcpy(&dynMachCond->reserve01, &buf[8], 56); // rest reserve
}
@@ -3334,14 +3288,11 @@ void hwapi::sys_sendDeviceParameter(struct T_devices *deviceSettings) const
void hwapi::sys_restoreDeviceParameter(struct T_devices *deviceSettings) const
{
// attention: only applies if function "sys_sendDeviceParameter()" was used to send this settings before
// cannot be used to see settings programmed by JsonFile
uint8_t buf[64];
uint8_t LL;
tslib_strclr(buf,0,64);
//runProcess->epi_restore64BdevParameter(&LL, buf); // wozu die???
epi_restoreRbDeviceSettings(&LL, buf); // viel besser, stimmt immer
epi_restoreRbDeviceSettings(&LL, buf);
Q_STATIC_ASSERT(sizeof(*deviceSettings) <= sizeof(buf));
@@ -3416,6 +3367,7 @@ void hwapi::prn_requestCurrentDynData(void) const
{
sendFDcmd_set(0,39,0,0,0,0,0); // rd data dynData
epi_clearDynData();
epi_clearDynMachCond2();
}
bool hwapi::prn_getCurrentDynamicPrnValuesFromDC(uint8_t *dynPrnVal ) const
@@ -4095,8 +4047,8 @@ int8_t hwapi::bl_blockAutoResponse(void) const
void hwapi::sys_requestJsonVersions(uint8_t jsonNr) const
{
// send one request for every single version
// jsonNr=1...36, 1=config file (cust.Nr) 2=devices 3=cash 4=res.
// 5=printer template 1 ..... 36= template 32
// jsonNr=1...36, 1=config file (cust.Nr) 2=devices 3=cash 4,5=empty
// 6=printer template 1 ..... 37= template 32
sendFDcmd_set(0, 21, jsonNr,0,0,0,0);
}
@@ -4301,7 +4253,7 @@ bool hwapi::bna_getAllParameters(struct T_bna *bna) const
bna->intendedAccept = uchar2uint(buf[31], buf[30]);
bna->pad2=0;
pp=32;
for (nn=0; nn<16; nn++)
for (nn=0; nn<8; nn++) // was 16!!! // 8.5.24 reduced
{
bna->billDenomination[nn] = uchar2uint(buf[pp+1], buf[pp]);
pp+=2;
@@ -4672,7 +4624,61 @@ bool hwapi::dcDownloadGetRunning() const {
return data ? data->m_downLoadDC.m_running.load() : 0;
}
bool hwapi::dcDownloadGetFinished() const {
bool hwapi::dcDownloadGetFinished() const
{
SharedMem const *data = SharedMem::getDataConst();
return data ? data->m_downLoadDC.m_running.load() : 0;
}
//uint16_t dcDownloadGetTotalBlockNumber() const override;
//uint16_t dcDownloadGetCurrentBlockNumber() const override;
//virtual QObject const *getAPI() override;
void hwapi::mod_switchResetline(void)
{
sendFDcmd_set(171,0,0, 2,0,0,0);
}
// new from 22.5.2024, print Json-Printer-Template which
// is stored locally here in PTU memory,
// rather then loading several jsons to DC and tell it to print (until now)
// the local printer-json can have any length using predefined commands
// printing a local printer-json happens like this:
// 1) select a file to be printed from memory
// 2) load, parse, translate and save the file with following function
// 3) set dynamics (values from current transaction)
// 4) send saved file to printer one or several times
// hint: dynamics can be changed at any time without reloading the ticket, just repeat 3) and 4)
void hwapi::prn_translateLocalPrinterJson(QByteArray jsonFile2print) const
{
runProcess->sys_parseFile( jsonFile2print);
runProcess->sys_translateKeys();
}
void hwapi::prnStoreDynamics(char *bufferDynPrintVars[], uint8_t nrOfDyns) const
{
runProcess->prnStoreDynamics(bufferDynPrintVars, nrOfDyns);
// store nrOfDyns (up to 16) dynamics before printing
// max length = 16 byte per dynamic
}
void hwapi::prn_printTranslatedTicket(void) const
{
runProcess->prnStartDirectPrinting();
}
uint8_t hwapi::prn_waitForDirectTicket(void) const
{
return runProcess->prn_getDirectPrintResult();
// return: 0: just printing, wait
// 1: OK - last print was succesful
// 2: error - not printed
// 2: printer error 3: no connection to DC
}