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

148
src/datIf.cpp Normal file → Executable file
View File

@@ -88,7 +88,7 @@ T_datif::T_datif(QObject *parent) : QObject(parent)
dif_scanStep=0;
selectedSlaveAddr=FIX_SLAVE_ADDR;
cycl_running=0;
epi_resetDcDataValid(); // data are not yet valid, no response from DC by now
epi_resetDcDataValid(1); // data are not yet valid, no response from DC by now
datif_noResponseCtr=0;
@@ -129,6 +129,11 @@ void T_datif::resetChain(void)
dif_scanStep=0;
}
#define RESPONSEWAITTIME 10
// ab 5 keine timeouts mehr
#define GOTRESP_SENDGAP 20
// Wert egal, muss nur > RESPONSEWAITTIME und <255 sein
char T_datif::datif_cycleSend()
{
// cyclic transmission of INPUT-Requests
@@ -145,14 +150,14 @@ char T_datif::datif_cycleSend()
if ( !myDCIF->isPortOpen())
{
//qDebug() << "com port not available"; // wird ununterbrochen ausgegeben
epi_resetDcDataValid(); // DC data not valid
epi_resetDcDataValid(2); // DC data not valid
return 0;
}
// supervise if DC data are valid
datif_noResponseCtr++; // inc every 20ms
if (datif_noResponseCtr>250) // no life sign from device controller (DC) for about 3s
epi_resetDcDataValid(); // DC data has not updated for >=5s -> no longer valid!
epi_resetDcDataValid(3); // DC data has not updated for >=5s -> no longer valid!
// Ueberwachung ob ein oder mehrere Commands am Stueck erfolgreich waren
if (gpi_wantToResetSupervision())
@@ -171,8 +176,7 @@ char T_datif::datif_cycleSend()
// c) gar keine Antwort, Timeout nach 100ms -> 2x wiederholen (nach einer Luecke von 10ms )
// cycl_running=0: nichts zu tun 1: Mitteilung: Kommando wurde soeben abgesendet, 2,3,4 = Wiederholung
if (cycl_running) // 21.9.23 doRepeat hier raus sonst gehts warten auch nicht mehr (BL)
// if (cycl_running && doRepeat)
if (cycl_running)
{
// request is still running, wait for response before next sending
//qDebug()<< "datif wait for response";
@@ -180,28 +184,35 @@ char T_datif::datif_cycleSend()
datif_trigger->start(20); // ruft "this" (datif_cycleSend) erneut in 20ms auf
// mit 10 kein Unterscheid weil Zykluszeit grösser
cycl_running++; // inc every 20...30ms // warte max 100ms auf Antwort
if (cycl_running >80 && cycl_running <95) // neu 13.9.23 mind. 40 damit Templates
// in Folge gedruckt werden koennen
// 95: muss nur kleiner sein als die 100 fuer die Luecke
// 17.10.23: 50--> 80
cycl_running++; // inc every 20ms, warte auf Antwort
if (cycl_running >= GOTRESP_SENDGAP)
{
// 100ms vergangen, bisher keine Antwort, also Kommando wiederholen
qDebug()<< "datif timeout no response for wr/rd cmd "<< keepLastWrCmd << " " << keepLastRdCmd;
// got response, wait just one (this) cycle before next sending
cycl_running=0;
return 0;
}
if (cycl_running >=RESPONSEWAITTIME )
{
// bisher keine Antwort, also Kommando wiederholen
qDebug()<< "datif timeout no response for wr/rd cmd "<< keepLastWrCmd << " " << keepLastRdCmd;
cycl_running = 0; // gleich wiederholen weil ja schon ewig nichts mehr reinkam
datif_cmdWasPerformed=2; // NO :((
gpi_storeLastResult(8);
return 0;
}
if (cycl_running>=101) // 100 + 1
/*
* Unsinn, wird nie durchlaufen
if (cycl_running>=(RESPONSEWAITTIME+6)) // 3.7.24: 101-->110
{
// Antwort ist gekommen, also nach kurzer Luecke naechstes (datif_cmdWasPerformed==1)
// oder nochmal gleiches (datif_cmdWasPerformed==2) Kommando senden
//qDebug()<< "datif got any response";
cycl_running=0;
}
*/
// hier stoppen, weil Antwort des letzten Cmds noch nicht da
return 0;
}
@@ -223,6 +234,7 @@ char T_datif::datif_cycleSend()
datif_kindOfCmd=0;
cycl_running=0;
gpi_storeOverallResult(2);
qCritical()<<"datif, error no response to wr/rd "<<keepLastWrCmd<<" "<<keepLastRdCmd;
return 0;
}
@@ -249,7 +261,7 @@ char T_datif::datif_cycleSend()
datif_cmdWasPerformed=0;
} else
{
qDebug() << "datif: unknown cmd, stop repeating wr/rd:" << keepLastWrCmd << " " << keepLastRdCmd;
qCritical() << "datif: unknown cmd, stop repeating wr/rd:" << keepLastWrCmd << " " << keepLastRdCmd;
datif_cmdWasPerformed=0;
cycl_running=0;
datif_kindOfCmd=0;
@@ -280,8 +292,10 @@ char T_datif::datif_cycleSend()
myDCIF->setUserReadData(nextRdCmd);
myDCIF->sendUserData(selectedSlaveAddr);
//qDebug()<<"Datif send long FD cmd (wr/rd): "<<nextWrCmd<< " / " << nextRdCmd
// << " " << data[0]<< " " << data[1]<< " " << data[2]<< " " << data[3];
qDebug()<<"Datif send long FD cmd (wr/rd): "<<nextWrCmd<< " / " << nextRdCmd << "Dlen:" << length;
// << " data:" << data[0]<< " " << data[1]<< " " << data[2]<< " " << data[3]
// << " " << data[4]<< " " << data[5]<< " " << data[6]<< " " << data[7]
// << " " << data[8]<< " " << data[9]<< " " << data[10]<< " " << data[11];
cycl_running=1; // 1: start transmission
datif_kindOfCmd=2;
@@ -308,8 +322,8 @@ char T_datif::datif_cycleSend()
myDCIF->setUserReadData(nextRdCmd);
myDCIF->sendUserData(selectedSlaveAddr);
//qDebug()<<"Datif send short FD cmd (wr/rd): "<<nextWrCmd<< " / " << nextRdCmd << " "
// << blockNum << " " << dat1 << " " << dat2<< " " << dat3<< " " << dat4;
qDebug()<<"Datif send short FD cmd (wr/rd): "<<nextWrCmd<< " / " << nextRdCmd << " ";
// << blockNum << " " << dat1 << " " << dat2<< " " << dat3<< " " << dat4;
cycl_running=1; // 1: start transmission
datif_kindOfCmd=1;
@@ -345,7 +359,7 @@ char T_datif::datif_cycleSend()
else
{
dif_scanStep=0; // always start from beginning
epi_resetDcDataValid();
epi_resetDcDataValid(4);
}
datif_cmdWasPerformed=0; // 0: no response by now
@@ -363,10 +377,10 @@ char T_datif::sendINrequestsAutomatic(void)
// 114,0,0,0,0,0,0,0,0,0};
// extension 6.12.23, complete list:
uint8_t datif_autoRequCommandList[40]={11, 12, 13, 14, 17, 18, 19, 21, 22, 23,
24, 25, 27, 30, 31, 32, 33, 35, 39, 40,
uint8_t datif_autoRequCommandList[40]={11, 12, 14, 17, 18, 19, 21, 22, 23, 24,
25, 27, 30, 31, 32, 33, 34, 35, 39, 40,
41, 42, 102,103,104,106,107,108,109,110,
112,113,114,115,116,0, 0, 0, 0, 0};
112,113,114,115,116,0, 0, 0, 0, 0};
uint8_t datif_maxNrCommands=35, datif_sendNow;
// send quicker while transaction is ongoing:
@@ -380,7 +394,8 @@ char T_datif::sendINrequestsAutomatic(void)
// 19: get time and date and Extra values. poll occasionally and if needed
// 107, 22: MDB: poll if needed
doRepeat=true; // 20.9.23 15uhr (after release)
//doRepeat=true; // 20.9.23 15uhr (after release)
doRepeat=false; // 3.7.24 off, is repeated cyclic anyway
if (gpi_getNowCoinPay())
{
@@ -478,7 +493,7 @@ char T_datif::loadRecDataFromFrame()
if (gpi_getNowIsBootload())
{
datif_cmdWasPerformed=1;
cycl_running=100; // stop waiting for response and wait 1cycle till next sending
cycl_running=GOTRESP_SENDGAP; // stop waiting for response and wait 1cycle till next sending
return 0;
}
@@ -504,11 +519,11 @@ char T_datif::loadRecDataFromFrame()
receivedData[12], receivedData[13], receivedData[14], receivedData[15]);
*/
datif_cmdWasPerformed=2; // NO :((
cycl_running=100; // stop waiting for response and wait 1cycle till next sending
cycl_running=GOTRESP_SENDGAP; // stop waiting for response and wait 1cycle till next sending
return 0;
}
datif_cmdWasPerformed=1; // YES :), stop repeating
cycl_running=100; // stop waiting for response
cycl_running=GOTRESP_SENDGAP; // stop waiting for response
//qDebug() << "datif: got valid response ";
@@ -546,6 +561,9 @@ char T_datif::loadRecDataFromFrame()
localStr.append(ctmp);
}
if (readSource==0)
return 0; // done
//qDebug() << "got HW version: " << localStr;
switch (readSource) // = request command
{
@@ -924,22 +942,6 @@ char T_datif::loadRecDataFromFrame()
break;
// ab hier neu: 12.4.23
case CMD2DC_RDBK_DEV_PARA: //14
/*
buf66[0]=devPara.kindOfPrinter;
@@ -990,8 +992,8 @@ char T_datif::loadRecDataFromFrame()
case 112: // get inserted amount in cent in sum
// byte 0..3: amount just paid 4,5:last coin type 6,7: last coin value
newInsertedAmount=uchar2ulong(receivedData[3],receivedData[2],receivedData[1],receivedData[0]);
uitmp=uchar2uint(receivedData[5],receivedData[4]); // last coin type
uit2=uchar2uint(receivedData[7],receivedData[6]); // last coin value
uitmp=uchar2uint(receivedData[5],receivedData[4]); // type of last coin
uit2=uchar2uint(receivedData[7],receivedData[6]); // value of last coin
//if (uitmp>0) // nur 1x bei neuer Münze 6.10.23 aendern:
// beim Wechsler hat die kleinste Muenze immer coin type 0!
if (uitmp>10000 || uit2>10000)
@@ -999,7 +1001,7 @@ char T_datif::loadRecDataFromFrame()
uitmp=0;
uit2=0;
}
if ((newInsertedAmount != lastInsertedAmount) || uit2>0) // 22.5.2024
if ((newInsertedAmount != lastInsertedAmount) || uit2>0 )
{
gpi_storeCurrentPayment(newInsertedAmount, uitmp, uit2);
emit datif_gotNewCoin(); // OR BILL if (uitmp & 0x8000)>0
@@ -1037,7 +1039,9 @@ char T_datif::loadRecDataFromFrame()
break;
case 31: // Get dynamic machine conditions (doors, voltage, alarm….)
if (RdDleng>50)
// first 64 bytes, rest comes with cmd 34
if (RdDleng>60)
{
epi_setDcDataValid(); // DC-Data are valid as DC responded.
// Could be set to every response but this (31)
@@ -1046,23 +1050,8 @@ char T_datif::loadRecDataFromFrame()
gpi_storeDI_CoinAttach(receivedData[6]); // new, 14.2.24 needed for direct coin insertion
}
/* funktioniert, ist aber nicht nötig. Signal wird nach dem shared memory erzeugt
prnResult=receivedData[52];
if (prnResult != lastResult)
{
// new result
if (prnResult==1)
{
emit datif_templatePrintFinished_OK();
} else
if (prnResult==2)
{
emit datif_templatePrintFinished_Err();
}
lastResult=prnResult;
}*/
} else
qDebug()<<"datif received cmd31 with "<<RdDleng<<" bytes only";
break;
@@ -1078,24 +1067,22 @@ char T_datif::loadRecDataFromFrame()
gpi_storeDCbackupAccNr(RdDleng, receivedData);
break;
case 34: // Get dynamic machine conditions part 2
if (RdDleng>5)
{
gpi_storeDynMachCond2(RdDleng, receivedData);
//qDebug()<<"datif rec. cmd34: ";
//for (int nn=0; nn<64; nn++)
// qDebug() << nn << " : " << receivedData[nn] << " ";
}
break;
case 35:
gpi_storeMifCardType(RdDleng, receivedData);
break;
case 38: // Get stored account record backup
// readAddress, &RdDleng, receivedData
//if (RdDleng>50) // 1.8.23 nach Verlängerung des Datensatzes um 20byte falsch!!!
//{
gpi_storeVaultRecord(readAddress, receivedData ); // always/max 64byte
/*
qDebug()<<"datif cmd38 got vault data. blockNr: "<<readAddress;
if (readAddress==0)
for (nn=0; nn<64; nn+=8)
{
qDebug()<<receivedData[nn]<<" "<<receivedData[nn+1]<<" "<<receivedData[nn+2]<<" "<<receivedData[nn+3]<<" "
<<receivedData[nn+4]<<" "<<receivedData[nn+5]<<" "<<receivedData[nn+6]<<" "<<receivedData[nn+7];
}
*/
//}
break;
case 39:
@@ -1141,6 +1128,9 @@ char T_datif::loadRecDataFromFrame()
}
break;
default:
qCritical()<<"datif, error received unknown cmd "<< readSource;
}
readSource=0; // 17.05.2023: to avoid multiple recording

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
}

10
src/prot.cpp Normal file → Executable file
View File

@@ -97,14 +97,22 @@ void T_prot::setRecLen(uint16_t ReadCmd)
void T_prot::setUserWriteData(uint16_t WriteCmd, uint16_t WrAddr, uint8_t WrDatLen, uint8_t *data)
{
int nn;
WriteCommand=WriteCmd;
WriteAddr=WrAddr;
WrDataLength=WrDatLen;
if (WrDataLength>FRAME_DATALEN)
WrDataLength=FRAME_DATALEN;
for (int nn=0; nn<WrDataLength; nn++)
// ui8BLsendData[BL_DATA_LEN];
for (nn=0; nn<WrDataLength; nn++)
ui8OutputData[nn]=data[nn];
// clear the rest. added at 26.6.2024TS. important for printer text
for (nn=WrDataLength; nn<FRAME_DATALEN; nn++)
ui8OutputData[nn]=0;
SendDataValid=1; // always set WR first
kindOfData=0; // 0: binaries, 1:text
this->setRecLen(100); // default: short response

1727
src/runProc.cpp Normal file → Executable file

File diff suppressed because it is too large Load Diff

6
src/sendWRcmd.cpp Normal file → Executable file
View File

@@ -19,7 +19,11 @@ void sendWRcmd_INI(void)
}
// Command Stack for commands without parameters
uint8_t sendWRcmd_getStackSize(void)
{
return CMDSTACKDEPTH; // defined in shared_mem_buffer.h
}
//static uint16_t nextAsynchsendCmd0[CMDSTACKDEPTH];

67
src/storeINdata.cpp Normal file → Executable file
View File

@@ -9,7 +9,7 @@
// 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)
// Change log: 8.5.24TS: clear all oversize buffers (if only 32 of 64bytes are used then fill the rest with 0)
@@ -1002,6 +1002,8 @@ bool epi_getDI_auxPwr(void)
void gpi_storeDI_GsmPowerIsOn(bool di_gsm_PwrOn)
{
SharedMem::write()->di_gsmPwrOn=di_gsm_PwrOn;
//qDebug()<<"store In Data Gsm Pwr = "<< di_gsm_PwrOn;
}
bool epi_getDI_gsmPwr(void)
@@ -1541,6 +1543,8 @@ void gpi_storeMdbResponse(uint8_t leng, uint8_t *data)
//tslib_strcpy(data, SharedMem::write()->Sdata_RecBuff, uint16_t(Sdata_mdbNrOfRecData));
for (nn=0; nn<leng; nn++)
SharedMem::write()->Sdata_RecBuff[nn] = data[nn];
for (nn=leng; nn<40; nn++)
SharedMem::write()->Sdata_RecBuff[nn] = 0;
}
@@ -1567,6 +1571,8 @@ void gpi_storeEmpSettings(uint8_t leng, uint8_t *data)
//tslib_strcpy(data, SharedMem::write()->Sdata_emp_settingsBuff, leng);
for (nn=0; nn<leng; nn++)
SharedMem::write()->Sdata_emp_settingsBuff[nn] = data[nn];
for (nn=leng; nn<64; nn++)
SharedMem::write()->Sdata_emp_settingsBuff[nn] = 0;
}
@@ -1672,6 +1678,9 @@ void gpi_storeRbDeviceSettings(uint8_t leng, uint8_t *data) // getestet am
//tslib_strcpy(data, SharedMem::write()->Sdata_DeviceSettingBuff, leng);
for (nn=0; nn<leng; nn++)
SharedMem::write()->Sdata_DeviceSettingBuff[nn] = data[nn];
for (nn=leng; nn<64; nn++)
SharedMem::write()->Sdata_DeviceSettingBuff[nn] = 0;
}
@@ -1912,6 +1921,10 @@ void gpi_storeDeviceConditions(uint8_t leng, uint8_t *data)
//tslib_strcpy(data, SharedMem::write()->store_deviceCond, leng);
for (nn=0; nn<leng; nn++)
SharedMem::write()->store_deviceCond[nn]=data[nn];
// clear the rest
for (nn=leng; nn<64; nn++)
SharedMem::write()->store_deviceCond[nn]=0;
}
void epi_restoreDeviceConditions(uint8_t *leng, uint8_t *data)
@@ -1947,6 +1960,8 @@ void gpi_storeDynMachineConditions(uint8_t leng, uint8_t *data)
// tslib_strcpy(data, SharedMem::write()->store_machCond, leng);
for (nn=0; nn<leng; nn++)
SharedMem::write()->store_machCond[nn] = data[nn];
for (nn=leng; nn<64; nn++)
SharedMem::write()->store_machCond[nn] = 0;
}
@@ -2098,16 +2113,26 @@ void epi_setDcDataValid(void)
}
}
void epi_resetDcDataValid(void)
void epi_resetDcDataValid(char reason)
{
bool now=SharedMem::read()->store_DcDataAreValid;
if (now==true)
{
SharedMem::write()->store_DcDataAreValid = false;
#ifdef THIS_IS_CA_MASTER
qDebug()<<"master lib RESET DcDataValid";
switch (reason)
{
case 1: qDebug()<<"master lib RESET DcDataValid startup"; break;
case 2: qDebug()<<"master lib RESET DcDataValid port closed"; break;
case 3: qDebug()<<"master lib RESET DcDataValid no more data"; break;
case 4: qDebug()<<"master lib RESET DcDataValid manuell"; break;
default: qDebug()<<"master lib RESET DcDataValid ---"; break;
}
#else
qDebug()<<"slave lib RESET DcDataValid";
Q_UNUSED(reason);
#endif
}
}
@@ -2346,6 +2371,7 @@ void epi_getJsonVersion(uint8_t jsonNr, char *versionString)
versionString[nn] = SharedMem::read()->store_jsonVersion[nn][lrd];
}
// korrektur 8.5.24: printer versionen auf 6...37 (nicht 5..36)
}
@@ -2452,7 +2478,40 @@ void epi_restoreBnaContent(uint8_t *data)
// new, 8.5.24
//uint8_t store_machCon2len;
//uint8_t store_machCon2[66];
void epi_clearDynMachCond2(void)
{
uint8_t nn;
SharedMem::write()->store_machCon2len=0;
for (nn=0; nn<64; nn++)
SharedMem::write()->store_machCon2[nn] = 0;
}
void gpi_storeDynMachCond2(uint8_t leng, uint8_t *data)
{
uint8_t nn;
if (leng>64) leng=64;
SharedMem::write()->store_machCon2len=leng;
for (nn=0; nn<leng; nn++)
SharedMem::write()->store_machCon2[nn] = data[nn];
for (nn=leng; nn<64; nn++)
SharedMem::write()->store_machCon2[nn] = 0;
}
void epi_restoreDynMachCond2(uint8_t *leng, uint8_t *data)
{
uint8_t nn, LL;
LL=SharedMem::read()->store_machCon2len;
*leng=LL;
for (nn=0; nn<LL; nn++)
data[nn] = SharedMem::read()->store_machCon2[nn];
}

371
src/tslib.cpp Normal file → Executable file
View File

@@ -610,3 +610,374 @@ bool tslib_strComp(uint8_t *buf, char *compStr)
return true;
}
char biox_StrComp(char *S1, char *S2, int len)
{
// retval=1 wenn gleich; ? in S2 =Jokerzeichen
int ii;
for (ii=0; ii<len; ii++)
{
if ((S1[ii] != S2[ii]) && (S2[ii] != '?') )
return (0);
}
return(1);
}
// *****************************************************************************************
uint16_t tslib_StrLen(char *str)
{
uint16_t zz;
for (zz=0; zz<0xF000; zz++)
if (str[zz]==0)
return(zz);
return(0);
}
// *****************************************************************************************
uint16_t biox_StrLenInt(uint16_t *str)
{
uint16_t zz;
for (zz=0; zz<0xF000; zz++)
if (str[zz]==0)
return(zz);
return(0);
}
// *****************************************************************************************
void biox_MemCpy(uint8_t *src, uint8_t *dest, uint16_t Len)
{
// copy "Len" bytes from target to destination
// if Len==0 then copy until first NULL in targ
uint16_t zz=0;
if (Len==0)
{
while(src[zz]>0)
{
dest[zz]=src[zz];
zz++;
}
dest[zz]=0; // termination
} else
{
// Len>0 --> copy "Len" bytes
for (zz=0; zz<Len; zz++)
dest[zz]=src[zz];
dest[zz]=0; // termination
}
}
void tslib_itoa(int n, char *str)
{
// -23456 -> str[0]='-' str[1]='2' ...[5]='6' str[6]=0
// 5 -> str[0]='5' str[1..6]=0
uint8_t pp, zi[7];
int itmp, pi=0;
for (pp=0;pp<7;pp++)
{
str[pp]=0;
zi[pp]=0;
}
itmp=n;
pp=0;
if (itmp==0)
str[pp++]=0x30;
if (itmp<0)
{
str[pp++]='-';
itmp*=-1;
}
while(itmp>0)
{
zi[pi++]=itmp%10;
itmp/=10;
}
// now: zi[0]=6 zi[1]=5 zi[2]=4 zi[3]=3 zi[4]=2 zi[5]=0 zi[6]=0 pi=4
while (pi>0)
str[pp++]=zi[--pi]+0x30;
//str[0]='-'; str[1]='1'; str[3]='3'; // Test
}
// ***********************************************************************************************
void tslib_uitoa(unsigned int n, char *str)
{
uint8_t pp, zi[6];
unsigned int itmp;
int pi=0;
for (pp=0;pp<6;pp++)
{
str[pp]=0;
zi[pp]=0;
}
itmp=n;
pp=0;
if (itmp==0)
str[pp++]=0x30;
while(itmp>0)
{
zi[pi++]=itmp%10;
itmp/=10;
}
// now: zi[0]=6 zi[1]=5 zi[2]=4 zi[3]=3 zi[4]=2 zi[5]=0 pi=4
while (pi>0)
str[pp++]=zi[--pi]+0x30;
//str[0]='-'; str[1]='1'; str[3]='3'; // Test
}
// ***********************************************************************************************
void tslib_ltoa(long n, char *str)
{
// -2147483647 -> str[0]='-' str[1]='2' ...[10]='6' str[11]=0
uint8_t pp, zi[12];
int pi=0;
long ltmp;
for (pp=0;pp<12;pp++)
{
str[pp]=0;
zi[pp]=0;
}
ltmp=n;
pp=0;
if (ltmp==0)
str[pp++]=0x30;
if (ltmp<0)
{
str[pp++]='-';
ltmp*=-1;
}
while(ltmp>0)
{
zi[pi++]=ltmp%10;
ltmp/=10;
}
while (pi>0)
str[pp++]=zi[--pi]+0x30;
}
// ***********************************************************************************************
void tslib_ultoa(unsigned long n, char *str)
{
// 0... ->4294967296 str[0]='4' str[1]='2' ...[9]='6' str[10]=0 str[11]=0
uint8_t pp, zi[12];
int pi=0;
unsigned long ltmp;
for (pp=0;pp<12;pp++)
{
str[pp]=0;
zi[pp]=0;
}
ltmp=n;
pp=0;
if (ltmp==0)
str[pp++]=0x30;
while(ltmp>0)
{
zi[pi++]=ltmp%10;
ltmp/=10;
}
while (pi>0)
str[pp++]=zi[--pi]+0x30;
}
// ***********************************************************************************************
void tslib_uitobin(unsigned int decval, char *str)
{
uint16_t dv, bb;
int ll;
dv=decval;
ll=8; // show 8 bit
if (dv>255) ll=16; // show 16 bit
str[ll--]=0; // terminierung
bb=0;
do
{
if (dv & (1<<bb) ) str[ll]=0x31; else str[ll]=0x30;
bb++; ll--;
} while(ll>=0);
}
// ***********************************************************************************************
long tslib_atol( char *AscString)
{
// change ascii string ( of ascii numbers '0'..'9') to number
// AscString must be 0-terminated!
// a leading '-' is ignored, a'.' or a ',' stops calculation
//aufruf mit ("1234")
// aus IDE: ucatmp[0]='1' ucatmp[3]='4' ucatmp[4]='0' sl=4
unsigned long ultmp;
unsigned char uctmp1, minus=0;
unsigned int sl, zz;
sl=tslib_StrLen(AscString);
if (sl>10) sl=10; // mehr passt im ULONG nicht rein!
ultmp=0;
for (zz=0; zz<sl; zz++)
{
uctmp1=AscString[zz];
if (zz==0 && uctmp1=='-')
minus=1;
else
if (uctmp1>0x2F && uctmp1<0x3A)
{
ultmp*=10; // nur wenn eine neue Ziffer dazukommt und vor der addition!
uctmp1-=0x30;
ultmp+=(uint32_t)uctmp1;
} else
if (uctmp1=='.' || uctmp1==',' || uctmp1==0 )
{
if (minus)
ultmp*=(-1);
return(ultmp);
}
}
if (minus)
ultmp*=(-1);
return(ultmp);
}
// *****************************************************************************************
unsigned long tslib_atoul( char *AscString)
{
// change ascii string ( of ascii numbers '0'..'9') to number
// AscString must be 0-terminated!
// a leading '-' is ignored, a'.' or a ',' stops calculation
//aufruf mit ("1234")
// aus IDE: ucatmp[0]='1' ucatmp[3]='4' ucatmp[4]='0' sl=4
unsigned long ultmp;
unsigned char uctmp1;
unsigned int sl, zz;
sl=tslib_StrLen(AscString);
if (sl>10) sl=10; // mehr passt im ULONG nicht rein!
ultmp=0;
for (zz=0; zz<sl; zz++)
{
uctmp1=AscString[zz];
if (uctmp1>0x2F && uctmp1<0x3A)
{
ultmp*=10; // nur wenn eine neue Ziffer dazukommt und vor der addition!
uctmp1-=0x30;
ultmp+=(uint32_t)uctmp1;
} else
if (uctmp1=='.' || uctmp1==',' || uctmp1==0 )
return(ultmp);
}
return(ultmp);
}
// *****************************************************************************************
unsigned int tslib_ah2ui( char *AscString)
{
// change hex ascii string ( of ascii numbers '0'..'9', 'A' or 'a' ...'F','f') to number
// AscString must be 0-terminated!
// Example: "1A0C" = 6668
//unsigned long ultmp;
unsigned char uctmp1;
unsigned int sl, zz, uitmp;
sl=tslib_StrLen(AscString);
if (sl>4) sl=4;
uitmp=0;
for (zz=0; zz<sl; zz++)
{
uctmp1=AscString[zz];
if (uctmp1>=0x30 && uctmp1<=0x39)
{
uitmp<<=4; // nur wenn eine neue Ziffer dazukommt und vor der addition!
uctmp1-=0x30;
uitmp+=(uint16_t)uctmp1;
} else
if (uctmp1>='A' && uctmp1<='F')
{
uitmp<<=4;
uctmp1-=0x37;
uitmp+=(uint16_t)uctmp1;
} else
if (uctmp1>='a' && uctmp1<='f')
{
uitmp<<=4;
uctmp1-=0x57;
uitmp+=(uint16_t)uctmp1;
}
}
return(uitmp);
}