Clean up. Adding SEXTEN.

This commit is contained in:
Gerhard Hoffmann 2024-07-16 16:42:39 +02:00
parent a849f953bd
commit 2ecaa0545f

View File

@ -35,9 +35,6 @@ extern "C" char* strptime(const char* s,
#include <sstream> #include <sstream>
#include "calculator_functions.h" #include "calculator_functions.h"
#include "calculate_price.h" #include "calculate_price.h"
#include "aes128.h"
#include "cc_iuc_asynchpos.h"
#include "MessageHelper.h"
#include <stdlib.h> #include <stdlib.h>
#define SZEGED (0) #define SZEGED (0)
@ -50,7 +47,8 @@ extern "C" char* strptime(const char* s,
#define NEUHAUSER_CHRISTOPH_REISEN (0) #define NEUHAUSER_CHRISTOPH_REISEN (0)
#define NEUHAUSER_PERNEGG_AN_DER_MUR (0) #define NEUHAUSER_PERNEGG_AN_DER_MUR (0)
#define NEUHAUSER_STOCKERAU (0) #define NEUHAUSER_STOCKERAU (0)
#define KLEIPEDA_LITAUEN (1) #define KLEIPEDA_LITAUEN (0)
#define SEXTEN (1)
#if NEUHAUSER_KIRCHDORF==1 #if NEUHAUSER_KIRCHDORF==1
static bool test_neuhauser_kirchdorf(int step, double cost) { static bool test_neuhauser_kirchdorf(int step, double cost) {
@ -210,720 +208,6 @@ static bool test_neuhauser_kirchdorf(int step, double cost) {
*/ */
//https://lxp32.github.io/docs/a-simple-example-crc32-calculation/
uint32_t crc32(const char *s, size_t n) {
uint32_t crc=0xFFFFFFFF;
for(size_t i=0;i<n;i++) {
char ch=s[i];
for(size_t j=0;j<8;j++) {
uint32_t b=(ch^crc)&1;
crc>>=1;
if(b) crc=crc^0xEDB88320;
ch>>=1;
}
}
return ~crc;
}
#define UINT unsigned int
#define UCHAR unsigned char
static struct billAsynchData asynchBill;
void iuc_asynchpos_sub_initArray(unsigned char* pArray, int length) {
unsigned int uitemp = 0;
for (uitemp = 0; uitemp < length; ++uitemp)
pArray[uitemp] = 0x00;
}
unsigned int biox_StrLen(unsigned char *str) {
unsigned int zz;
for (zz=0; zz<0xF000; zz++)
if (str[zz]==0)
return(zz);
return(0);
}
void biox_CopyBlock(unsigned char *src, UINT srcPos, UCHAR *dest, UINT destPos, UINT len) {
UINT xx,yy,zz,ii;
xx = srcPos;
yy = destPos;
zz = len;
for (ii = 0; ii < zz; ++ii) {
dest[yy + ii] = src[xx + ii];
}
}
void iuc_asynchpos_sub_synchTime() {
QDateTime current = QDateTime::currentDateTime();
current.setTime(QTime(12, 0, 0));
current.setDate(QDate(2024, 6, 18));
QString const &s = current.toString(Qt::ISODate);
QByteArray time(s.toStdString().c_str());
time[10] = ' ';
strncpy((char *)asynchBill.time, time.toStdString().c_str(), sizeof(asynchBill.time));
}
uint32_t iuc_asynchpos_sub_updateCRC(uint32_t crc, unsigned char* pData, size_t len) {
// berechne CRC32 nach Polynom x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1
QByteArray a((char *)pData, len);
qCritical() << "updateCRC" << a.toHex(' ');
qCritical() << "updateCRC" << len << hex << crc;
int i = 0;
int j = 0;
// unsigned long rem;
// unsigned char octet;
// UCHAR *p, *q;
unsigned char ucCarry = 0x00;
crc = ~crc;
while (len > 0) {
crc ^= (uint32_t)pData[i];
++i;
for (j = 0; j < 8; ++j) {
ucCarry = crc & 1;
crc >>= 1;
if (ucCarry) {
crc ^= IUC_ASYNCHPOS_POLYNOME;
}
}
--len;
}
return ~crc;
}
unsigned char biox_ah2ui_char(unsigned char AscString)
{
// change hex ascii string ( of ascii numbers '0'..'9', 'A' or 'a' ...'F','f') to number
unsigned char uctmp1;
unsigned char uitmp;
uitmp = 0;
uctmp1=AscString;//[zz];
if (uctmp1>=0x30 && uctmp1<=0x39)
{
//uitmp<<=4; // nur wenn eine neue Ziffer dazukommt und vor der addition!
uctmp1-=0x30;
uitmp+=/*(UINT)*/uctmp1;
} else
if (uctmp1>='A' && uctmp1<='F')
{
//uitmp<<=4;
uctmp1-=0x37;
uitmp+=/*(UINT)*/uctmp1;
} else
if (uctmp1>='a' && uctmp1<='f')
{
//uitmp<<=4;
uctmp1-=0x57;
uitmp+=/*(UINT)*/uctmp1;
}
return(uitmp);
}
unsigned char iuc_asynchpos_send_serial(unsigned char* pData, unsigned int length, unsigned char needRTS, unsigned char overrideACK) {
unsigned int uitmp = 0;
unsigned int uitmp2 = 0;
unsigned int uitmp3 = 0;
unsigned int txCounter = 0;
unsigned int dxCounter = 0;
unsigned char uctmp = 0x00;
// unsigned char uctmp2 =0x00;
unsigned char chksum = 0x00;
//unsigned char dataContext = 0x00;
unsigned int retryCount = 0;
unsigned long lastRetry = 0;
unsigned int dxLength;
// unsigned int dx = biox_StrLen(pData) + 1;
unsigned char rxBuf[8];
//unsigned char pData_[IUC_ASYNCHPOS_MAX_ARRAY_SIZE];
// unsigned int loopCount = 1000;
// unsigned char retVal = 0x01;
//preparing to send
//if (needRTS) {
//brd_SendDiagStr("->IUC ASYNCHPOS sending 0x04 (EOT).",1);
// uctmp = iuc_asynchpos_rts();
//}
//sending data
if (!uctmp) {
//brd_SendDiagStr("----->IUC ASYNCHPOS",1);
iuc_asynchpos_sub_initArray(txAsynchData, IUC_ASYNCHPOS_MAX_ARRAY_SIZE);
//iuc_asynchpos_sub_initArray(pData_, IUC_ASYNCHPOS_MAX_ARRAY_SIZE);
//biox_CopyBlock(pData,0,pData_,0,IUC_ASYNCHPOS_MAX_ARRAY_SIZE);
/*dxCounter = 0;
for (uitmp = 0; uitmp < dx + dxCounter; ++uitmp) {
if ((pData[uitmp] >= STX && pData[uitmp] <= ACK2)
|| (pData[uitmp] == DLE) || (pData[uitmp] == NAK)) {
pData[uitmp] = (pData[uitmp] + 0x30);
for (uitmp2 = uitmp; uitmp2 < dx + dxCounter; ++uitmp2) {
pData[uitmp2 + 1] = pData[uitmp2];
}
pData[uitmp] = DLE;
++dxCounter;
}
}
dxCounter = 0;*/
for (uitmp = 0; uitmp < length; uitmp += IUC_ASYNCHPOS_MIN_PACKET_SIZE) {
//if (dxCounter > 0)
//uitmp -= dxCounter;
uctmp = 0x00;
dxCounter = 0;
chksum = 0x00;
dxLength = IUC_ASYNCHPOS_MIN_PACKET_SIZE;
if (length - uitmp <= IUC_ASYNCHPOS_MIN_PACKET_SIZE)
dxLength = 2 + length - uitmp;
iuc_asynchpos_sub_initArray(txAsynchData, 3 + IUC_ASYNCHPOS_MIN_PACKET_SIZE);
//Packet structure is STX <packet_data> ETX1|ETX2 {LRC}
txAsynchData[0] = STX;
for (txCounter = 0; (txCounter/* + dxCounter*/) < dxLength; ++txCounter) {
//for (txCounter = 0; txCounter < dxLength; ++txCounter) {
/*if ((pData[uitmp + txCounter] >= STX && pData[uitmp + txCounter] <= ACK2)
|| (pData[uitmp + txCounter] == DLE) || (pData[uitmp + txCounter] == NAK)) {
txAsynchData[1 + txCounter + dxCounter] = DLE;
uctmp = (pData[uitmp + txCounter] + 0x30);
++dxCounter;
txAsynchData[1 + txCounter + dxCounter] = uctmp; //(pData[uitmp + txCounter] + 0x30);
} else {*/
txAsynchData[1 + txCounter/* + dxCounter*/] = pData[uitmp + txCounter];
if ((pData[uitmp + txCounter] >= STX && pData[uitmp + txCounter] <= ACK2)
|| (pData[uitmp + txCounter] == DLE) || (pData[uitmp + txCounter] == NAK)) {
++dxCounter;
}
}
for (uitmp2 = 1; uitmp2 < dxLength + dxCounter; ++uitmp2) {
if ((txAsynchData[uitmp2] >= STX && txAsynchData[uitmp2] <= ACK2)
|| (txAsynchData[uitmp2] == DLE) || (txAsynchData[uitmp2] == NAK)) {
for (uitmp3 = dxLength + dxCounter; uitmp3 > uitmp2; --uitmp3) {
txAsynchData[uitmp3] = txAsynchData[uitmp3 - 1];
}
txAsynchData[uitmp2 + 1] = (txAsynchData[uitmp2 + 1] + 0x30);
txAsynchData[uitmp2] = DLE;
}
}
/*if (dxLength < IUC_ASYNCHPOS_MIN_PACKET_SIZE && txAsynchData[txCounter + dxCounter] != 0x00) {
++dxCounter;
}*/
for (uitmp2 = 1; uitmp2 <= (txCounter + dxCounter); ++uitmp2) {
chksum ^= txAsynchData[uitmp2];
}
if (!iucAsynchpoxDataContext) {
txAsynchData[1 + txCounter + dxCounter] = ETX1;
chksum ^= ETX1;
} else {
txAsynchData[1 + txCounter + dxCounter] = ETX2;
chksum ^= ETX2;
}
txAsynchData[2 + txCounter + dxCounter] = chksum;
QByteArray c((char*)txAsynchData, 2 + txCounter + dxCounter + 1);
qCritical() << "txCounter" << txCounter;
qCritical() << "dxCounter" << dxCounter;
qCritical() << "check" << chksum;
qCritical() << "txAsyncData" << c.toHex(' ');
}
}
return 0;
}
unsigned int iuc_asynchpos_send(unsigned char packetType,
unsigned char* pData,
unsigned int length,
unsigned char needRTS) {
unsigned char txData_[IUC_ASYNCHPOS_MAX_ARRAY_SIZE];
unsigned char tempID [IUC_ASYNCHPOS_MIN_BASE_BYTE_DATA_SIZE];
unsigned char tempID_ [IUC_ASYNCHPOS_MIN_BASE_BYTE_DATA_SIZE];
unsigned char tempAPAK [IUC_ASYNCHPOS_MIN_BASE_BYTE_DATA_SIZE];
unsigned long uitmp = 0;
unsigned int posID = 0;
unsigned long chksum = 0;
unsigned int messageLength = length + 1;
unsigned int length_ = length + 1;
unsigned char pData_[IUC_ASYNCHPOS_MAX_ARRAY_SIZE];
unsigned char uctemp = 0;
// unsigned char retries = 4;
unsigned char rxBuf[8];
iuc_asynchpos_crc_old = 0;
iuc_asynchpos_sub_initArray(rxBuf, 8);
iuc_asynchpos_sub_initArray(pData_, IUC_ASYNCHPOS_MAX_ARRAY_SIZE);
biox_CopyBlock(pData,0,pData_,0,length_);
iuc_asynchpos_sub_initArray(txData_, IUC_ASYNCHPOS_MAX_ARRAY_SIZE);
iuc_asynchpos_sub_initArray(tempID, IUC_ASYNCHPOS_MIN_BASE_BYTE_DATA_SIZE);
iuc_asynchpos_sub_initArray(tempID_, IUC_ASYNCHPOS_MIN_BASE_BYTE_DATA_SIZE);
iuc_asynchpos_sub_initArray(tempAPAK, IUC_ASYNCHPOS_MIN_BASE_BYTE_DATA_SIZE);
//header
/*
The header of the message is composed of:
? 1 byte packet Type, which indicates the type of the packet;
? 8 bytes Packet ID, a unique ID to achieve maximum security (for information on forming
Packet ID see chapter 3.4 Communication security);
? 1 byte P.O.S. ID length;
? ASCII encoded P.O.S. ID (up to 255 bytes); ((gemeint ist Terminal ID)
*/
txData_[2] = packetType;
//1 byte P.O.S. ID length
/*for (uitmp = 0; uitmp < 32 && terminalID[uitmp] != 0x00; ++uitmp) {
++posID; // -= uitmp;
}*/
posID = biox_StrLen(terminalID)/* + 1*/;
//++posID;
txData_[11] = (UCHAR) posID;
messageLength += (10 + posID); //Added header
txData_[0] = (messageLength) & 0xFF00; //high byte
txData_[1] = (messageLength) & 0x00FF; //low byte
//8 byte Packet ID
/*
Apak: 9D547268976ADE1BBB39DE90F3A449E5
Terminal id: T-LT-OPT-01
*/
//calculate CRC32
uctemp = (UCHAR) posID;
fprintf(stderr, "POSID=%0X\n", uctemp);
chksum = IUC_ASYNCHPOS_POLYNOME_INITIAL;
chksum = iuc_asynchpos_sub_updateCRC(chksum,&uctemp,1);
fprintf(stderr, "%d CRC32=%04X\n", __LINE__, chksum);
chksum = iuc_asynchpos_sub_updateCRC(chksum,terminalID,posID);
fprintf(stderr, "%d CRC32=%04X\n", __LINE__, chksum);
//for (uitmp = 0; uitmp < length_; ++uitmp) {
chksum = iuc_asynchpos_sub_updateCRC(chksum,pData_/*[uitmp]*/,length_);
fprintf(stderr, "%d CRC32=%04X\n", __LINE__, chksum);
//}
//XOR crc value with APAK
//chksum = 2502456899; //HACK FOR TESTING, REMOVE LATER!
for(uitmp = 0; uitmp < IUC_ASYNCHPOS_MIN_BASE_BYTE_DATA_SIZE; ++uitmp) {
tempAPAK[uitmp] |= biox_ah2ui_char(terminalAPAK[uitmp * 2]) << 4;
tempAPAK[uitmp] |= biox_ah2ui_char(terminalAPAK[(uitmp * 2) + 1]);
//tempAPAK[uitmp] = (terminalAPAK[uitmp * 2] << 8) | (terminalAPAK[(uitmp * 2) + 1]);
}
tempID[0] = (chksum >> 24) & 0xFF;
tempID[1] = (chksum >> 16) & 0xFF;
tempID[2] = (chksum >> 8) & 0xFF;
tempID[3] = chksum & 0xFF;
for (uitmp = 0; uitmp < 4; ++uitmp) {
tempID[uitmp] ^= tempAPAK[uitmp]; //terminalAPAK[uitmp];
}
for (uitmp = 4; uitmp < IUC_ASYNCHPOS_MIN_BASE_BYTE_DATA_SIZE; ++uitmp) {
tempID[uitmp] = tempAPAK[uitmp]; //terminalAPAK[uitmp];
}
//Eyncrypt result with APAK, according to AES128
QByteArray x((char *)tempID, IUC_ASYNCHPOS_MIN_BASE_BYTE_DATA_SIZE);
QByteArray z((char *)tempAPAK, IUC_ASYNCHPOS_MIN_BASE_BYTE_DATA_SIZE);
qCritical() << "AES-INPUT" << x.toHex();
qCritical() << "APAK" << z.toHex();
aes_encrypt(tempID,tempID_,tempAPAK);
QByteArray y((char *)tempID_, IUC_ASYNCHPOS_MIN_BASE_BYTE_DATA_SIZE);
qCritical() << "AES-OUTPUT" << y.toHex();
//get the leftmost 8 byte of that value and set then as Packet ID
for (uitmp = 0; uitmp < 8; ++uitmp) {
txData_[3 + uitmp] = tempID_[uitmp];
fprintf(stderr, "%0X", txData_[3 + uitmp]);
} fprintf(stderr, "\n");
//P.O.S.ID
for (uitmp = 0; uitmp < posID; ++uitmp) {
txData_[12 + uitmp] = terminalID[uitmp];
}
//Message
//1 byte - marker
//0 . 7F bytes - tag name
//2 + N bytes - data
for (uitmp = 0; uitmp < length_; ++uitmp) {
txData_[12 + posID + uitmp] = pData_[uitmp];
}
QByteArray a((char *)(&txData_[0]), messageLength+1);
qCritical() << "MESSAGE" << a.toHex(' ');
iuc_asynchpos_send_serial(txData_, (messageLength/* + 1*/),needRTS,0x00);
//QByteArray b((char *)(&txAsynchData[0]), IUC_ASYNCHPOS_MAX_ARRAY_SIZE);
//qCritical() << "EXPANDED MESSAGE" << b.toHex(' ');
#if 0
brd_SendDiagStr("->IUC ASYNCHPOS send message: ",0);
brd_SendDiagBlock(txData_,1,messageLength);
//Message compiled, now send it via serial
uitmp = 1;
//while (retries > 0 && uitmp > 0) {
//uitmp = iuc_asynchpos_send_serial(txData_, (messageLength + 1));
//--retries;
if (iuc_asynchpos_send_serial(txData_, (messageLength/* + 1*/),needRTS,0x00)) {
//brd_SendDiagStr("->IUC ASYNCHPOS Message failed!",1);
//TODO Message sending failed -> Error handling here
//return 1;
uitmp = 0x00;
//brd_SendDiagStr("->IUC ASYNCHPOS Message NOT send",1);
} else {
//brd_SendDiagStr("->IUC ASYNCHPOS Message send",1);
} /*else {
--retries;
}
}*/
//if (!uitmp)
//return 1;
/*if (retries == 0) {
brd_SendDiagStr("->IUC ASYNCHPOS Message failed!",1);
rxBuf[0] = 0x45;
rxBuf[1] = 0x00;
rxBuf[2] = 0xFF;
vmc_SendWithBuffer(rxBuf,20,0x69,0);
return 1;
}
rxBuf[0] = 0x45;
rxBuf[1] = 0x00;
rxBuf[2] = 0x00;
vmc_SendWithBuffer(rxBuf,20,0x69,0);*/
//brd_SendDiagStr("->IUC ASYNCHPOS Message send",1);
//while(iuc_asynchpos_recieve_serial());
#endif
return 0;
}
void iuc_asynchpos_command_Login() { //Kasse registrieren
unsigned char message[IUC_ASYNCHPOS_MAX_TX_MESSAGE_SIZE];
unsigned char packetType = 0x00;
unsigned int uitemp = 0;
unsigned char command[] = "Login";
unsigned char tagName[] = "Time";
//unsigned char tag2Name[] = "IdleText";
unsigned char tag3Name[] = "Flags";
unsigned char tag3Value[] = "AP3|LR";
//Constructing the message
iuc_asynchpos_sub_initArray(message,IUC_ASYNCHPOS_MAX_TX_MESSAGE_SIZE);
uitemp = (unsigned char) biox_StrLen(command);
message[0] = (unsigned char) uitemp + 0x80; //constructed element, tag name length
biox_CopyBlock(command,0,message,1,uitemp); //tag name
++uitemp;
message[uitemp] = (unsigned char) biox_StrLen(tagName);//data element, tag name length
++uitemp;
biox_CopyBlock(tagName,0,message,uitemp, biox_StrLen(tagName));// tag name
uitemp += (1 + biox_StrLen(tagName));
//Time
iuc_asynchpos_sub_synchTime();
message[uitemp] = (unsigned char) biox_StrLen(asynchBill.time);//value length
++uitemp;
biox_CopyBlock(asynchBill.time,0,message,uitemp, biox_StrLen(asynchBill.time));//value
uitemp += biox_StrLen(asynchBill.time);
//Flags
message[uitemp] = (unsigned char) biox_StrLen(tag3Name);//data element, tag name length
++uitemp;
biox_CopyBlock(tag3Name,0,message,uitemp, biox_StrLen(tag3Name));// tag name
uitemp += (1 + biox_StrLen(tag3Name));
message[uitemp] = (unsigned char) biox_StrLen(tag3Value);//value length
++uitemp;
biox_CopyBlock(tag3Value,0,message,uitemp, biox_StrLen(tag3Value));//value
uitemp += biox_StrLen(tag3Value)/* + 1*/;
iuc_asynchpos_send(packetType,message,uitemp,0x01);
}
void biox_ClearMem(UCHAR *targ, UCHAR FillByte, UINT Len)
{
// fill buffer and terminate
UINT zz=0;
for (zz=0; zz<Len; zz++)
targ[zz]=FillByte;
}
void biox_ultoa(unsigned long n, char *str)
{
UCHAR 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 biox_MemCpPos(UCHAR *src, UCHAR *dest, UINT pos)
{
// copy src to destination, start from position "pos".
// 1=start from beginning
// terminierung nicht eintragen, dest Puffer wird extern abgeschlossen
// dest must be long enough !!!!
UINT zz, len, pp;
UCHAR uctmp;
pp=pos; // unbedingt Zwischenspeichern, geht sonst verloren!!!!!!!
len=biox_StrLen(src);
zz=0;
do
{
uctmp=src[zz];
if (uctmp>0) // terminierung
dest[zz+pp]=uctmp;
zz++;
} while(uctmp>0 && zz<len);
}
typedef uint32_t ULONG;
void generate_UniqueTransNr(UCHAR *buf)
{
// TODO: wieder entfernen
QDateTime dt(QDateTime::fromString("2024-06-12T12:00:00", Qt::ISODate));
ULONG transID = MessageHelper::secsSinceJan2017(dt);
QByteArray unique(QByteArray(std::to_string(transID).c_str(), 9).rightJustified(10, '0'));
unique = unique.append(QByteArray("1000").rightJustified(5, '0'));
unique = unique.append(QByteArray("100").rightJustified(4, '0'));
memcpy(buf, unique.toStdString().c_str(), 19);
// qCritical() << "XX" << QByteArray((char *)buf, 19).toHex(':');
return;
// buf>=20 bytes!
UCHAR tmp12[12];
ULONG ultmp = 0;
// a) Transaction ID, max 19 chars
// ab April 2017: TID muss über alle Automaten und über alle Zeiten eindeutig sein,
// sonst gibt SessionBase keine Antwort.
//uitmp=VKdata.TransID; sub_BufferNummEntry(ultmp); // einfache Version bis März 2017
biox_ClearMem(buf, '0', 19);
biox_ClearMem(tmp12, 0, 12);
//VdKdata.TransID = com_totalSecSince1jan2017();
//biox_ultoa(VKdata.TransID, tmp12);
biox_ultoa(transID, (char *)tmp12);
biox_MemCpPos(tmp12, buf, 1);
qCritical() << "TransID 222" << hex << QByteArray((char *)buf, 20).toHex(':');
// Automaten-nr auch rein, sonst können versch. Automaten die gleiche Nummer haben!
biox_ClearMem(tmp12, 0, 12);
//ultmp=(ULONG) Conf.MachNr; //.MachineID;
ultmp=1000; //.MachineID;
biox_ultoa(ultmp, (char *)tmp12);
biox_MemCpPos(tmp12, buf, 11);
qCritical() << "TransID 333" << hex << QByteArray((char *)buf, 20).toHex(':');
biox_ClearMem(tmp12, 0, 12);
//ultmp=(ULONG)Conf.CustomNr; //.CustID;
ultmp=100; //.CustID;
biox_ultoa(ultmp, (char *)tmp12);
biox_MemCpPos(tmp12, buf, 16);
qCritical() << "TransID 444" << hex << QByteArray((char *)buf, 20).toHex(':');
buf[19]=0;
}
void iuc_asynchpos_command_authorize(unsigned int vkPreis) {
UCHAR message[IUC_ASYNCHPOS_MAX_ARRAY_SIZE];
UCHAR packetType = 0x00;
UINT uitemp = 0;
UCHAR command[] = "Authorize";
UCHAR tag1Name[] = "Amount";
UCHAR tag2Name[] = "Cash";
UCHAR tag3Name[] = "Currency";
UCHAR tag4Name[] = "DocNr";
UCHAR tag5Name[] = "Time";
UCHAR tag6Name[] = "Lang";
//UCHAR tag1Value[10];
UCHAR tag2Value[] = "0";
UCHAR tag3Value[] = "978";
UCHAR tag6Value[] = "lt";
UINT vkPreis_ = vkPreis;
qCritical() << "START" << __func__;
iuc_asynch_PRNrecieved = 0;
//Constructing the message
iuc_asynchpos_sub_initArray(message,IUC_ASYNCHPOS_MAX_ARRAY_SIZE);
//iuc_asynchpos_sub_initArray(tag1Value,10);
uitemp = (UCHAR) biox_StrLen(command);
message[0] = (UCHAR) uitemp + 0x80; //constructed element, tag name length
biox_CopyBlock(command,0,message,1,uitemp); //tag name
++uitemp;
//Amount
message[uitemp] = (UCHAR) biox_StrLen(tag1Name);//data element, tag name length
++uitemp;
biox_CopyBlock(tag1Name,0,message,uitemp, biox_StrLen(tag1Name));// tag name
uitemp += (1 + biox_StrLen(tag1Name));
std::string tag1Value = std::to_string(vkPreis_);
message[uitemp] = (UCHAR) biox_StrLen((uint8_t *)tag1Value.c_str());//value length
++uitemp;
biox_CopyBlock((uint8_t *)tag1Value.c_str(),0,message,uitemp, biox_StrLen((uint8_t *)tag1Value.c_str()));//value
uitemp += (/*1 + */biox_StrLen((uint8_t *)tag1Value.c_str()));
//Cash
message[uitemp] = (UCHAR) biox_StrLen(tag2Name);//data element, tag name length
++uitemp;
biox_CopyBlock(tag2Name,0,message,uitemp, biox_StrLen(tag2Name));// tag name
uitemp += (1 + biox_StrLen(tag2Name));
message[uitemp] = (UCHAR) biox_StrLen(tag2Value);//value length
++uitemp;
biox_CopyBlock(tag2Value,0,message,uitemp, biox_StrLen(tag2Value));//value
uitemp += (/*1 + */biox_StrLen(tag2Value));
//Currency
message[uitemp] = (UCHAR) biox_StrLen(tag3Name);//data element, tag name length
++uitemp;
biox_CopyBlock(tag3Name,0,message,uitemp, biox_StrLen(tag3Name));// tag name
uitemp += (1 + biox_StrLen(tag3Name));
message[uitemp] = (UCHAR) biox_StrLen(tag3Value);//value length
++uitemp;
biox_CopyBlock(tag3Value,0,message,uitemp, biox_StrLen(tag3Value));//value
uitemp += (/*1 + */biox_StrLen(tag3Value));
//DocNr
message[uitemp] = (UCHAR) biox_StrLen(tag4Name);//data element, tag name length
++uitemp;
biox_CopyBlock(tag4Name,0,message,uitemp, biox_StrLen(tag4Name));// tag name
uitemp += (1 + biox_StrLen(tag4Name));
//biox_ltoa(asynchBill.docuNr,asynchBill.docNr);
//++asynchBill.docuNr;
generate_UniqueTransNr(asynchBill.docNr);
message[uitemp] = (UCHAR) biox_StrLen(asynchBill.docNr);//value length
++uitemp;
biox_CopyBlock(asynchBill.docNr,0,message,uitemp, biox_StrLen(asynchBill.docNr));//value
uitemp += biox_StrLen(asynchBill.docNr)/* + 1*/;
//Time
message[uitemp] = (UCHAR) biox_StrLen(tag5Name);//data element, tag name length
++uitemp;
biox_CopyBlock(tag5Name,0,message,uitemp, biox_StrLen(tag5Name));// tag name
uitemp += (1 + biox_StrLen(tag5Name));
iuc_asynchpos_sub_synchTime();
message[uitemp] = (UCHAR) biox_StrLen(asynchBill.time);//value length
++uitemp;
biox_CopyBlock(asynchBill.time,0,message,uitemp, biox_StrLen(asynchBill.time));//value
uitemp += biox_StrLen(asynchBill.time)/* + 1*/;
//Language
message[uitemp] = (UCHAR) biox_StrLen(tag6Name);//data element, tag name length
++uitemp;
biox_CopyBlock(tag6Name,0,message,uitemp, biox_StrLen(tag6Name));// tag name
uitemp += (1 + biox_StrLen(tag6Name));
message[uitemp] = (UCHAR) biox_StrLen(tag6Value);//value length
++uitemp;
biox_CopyBlock(tag6Value,0,message,uitemp, biox_StrLen(tag6Value));//value
uitemp += biox_StrLen(tag6Value)/* + 1*/;
iuc_asynchpos_send(packetType,message,uitemp,0x00);
}
int main() { int main() {
#if 0 #if 0
@ -1171,6 +455,171 @@ int main() {
} }
#endif #endif
#if SEXTEN==1
std::ifstream input;
int pop_min_time;
int pop_max_time;
int pop_min_price;
int pop_max_price;
int pop_daily_card_price;
input.open("/opt/ptu5/opt/customer_501/etc/psa_tariff/tariff01.json");
std::stringstream sstr;
while(input >> sstr.rdbuf());
std::string json(sstr.str());
Configuration cfg;
bool isParsed = cfg.ParseJson(&cfg, json.c_str());
cout << endl;
if (isParsed) {
pop_min_time = get_minimal_parkingtime(&cfg);
pop_max_time = get_maximal_parkingtime(&cfg);
pop_min_price = get_minimal_parkingprice(&cfg);
pop_max_price = get_maximal_parkingprice(&cfg);
pop_daily_card_price = cfg.getPaymentOptions().pop_daily_card_price;
qCritical() << " pop_min_time: " << pop_min_time;
qCritical() << " pop_max_time: " << pop_max_time;
qCritical() << " pop_min_price: " << pop_min_price;
qCritical() << " pop_max_price: " << pop_max_price;
QList<int> timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg);
qCritical() << "TimeSteps" << timeSteps;
// return 0;
CalcState cs;
double cost;
int durationInMinutes = 0;
int offsetInMinutes = 0;
// for (int day = Qt::Monday; day <= Qt::Sunday; ++day) {
for (int day = Qt::Monday; day <= Qt::Monday; ++day) {
QDateTime s(QDate(2024, 7, 14 + day), QTime()); // 20: (whit) monday,..., 26: sunday
QDateTime end;
switch (day) {
case (int)Qt::Monday:
qCritical() << "Monday";
break;
case (int)Qt::Tuesday:
qCritical() << "Tuesday";
break;
case (int)Qt::Wednesday:
qCritical() << "Wednesday";
break;
case (int)Qt::Thursday:
qCritical() << "Thursday";
break;
case (int)Qt::Friday:
qCritical() << "Friday";
break;
case (int)Qt::Saturday:
qCritical() << "Saturday";
break;
case (int)Qt::Sunday:
qCritical() << "Sunday";
break;
}
/*
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
parking_tariff_t *tariff,
QDateTime &start_parking_time,
int netto_parking_time,
QDateTime &end_parking_time, // return value
struct price_t *price, // return value
bool prepaid = true);
*/
//for (int minutes = 0; minutes < 1440; ++minutes) {
for (int minutes = 480; minutes < 481; minutes += 1) {
QDateTime start = s.addSecs(minutes * 60);
qCritical() << "start" << start.toString(Qt::ISODate);
QDateTime effectiveStart = start;
if (start.time() < QTime(8, 0, 0)) {
effectiveStart.setTime(QTime(8, 0, 0));
} else
if (start.time() <= QTime(19, 0, 0)) {
effectiveStart = start;
} else {
effectiveStart = start.addDays(1);
effectiveStart.setTime(QTime(8, 0, 0)); // next day
}
for (int i = 100; i <= 100; i += 10) {
//for (int i = 2100; i <= 2100; i += 10) {
cost = i;
if ((cs = compute_duration_for_parking_ticket(&cfg, start, cost, end))) { // return value
qCritical() << "end" << end.toString(Qt::ISODate);
durationInMinutes = pop_min_time;
if (i > 0) {
durationInMinutes += (i/10) * 4;
}
offsetInMinutes = 0;
if (effectiveStart.time() >= QTime(8, 0, 0) && effectiveStart.time() <= QTime(19, 0, 0)) {
if (effectiveStart.time().secsTo(QTime(19, 0, 0)) < (durationInMinutes * 60)) {
offsetInMinutes = 780; // 19:00 -> 8:00
}
}
if (i == 0) {
i += 20;
}
#if 0
if ((durationInMinutes + offsetInMinutes) == (effectiveStart.secsTo(end) / 60)) {
if (day == Qt::Monday && minutes >= 480 && minutes <= 1140) {
qCritical() << "| start ............................" << start.toString(Qt::ISODate);
qCritical() << "| cost ............................." << cost;
qCritical() << "| durationInMinutes ................" << durationInMinutes
<< "(" << (durationInMinutes - 60) << "+ 60 )";
qCritical() << "| offsetInMinutes .................." << offsetInMinutes;
qCritical() << "| end .............................." << end.toString(Qt::ISODate) << endl;
}
continue;
}
#endif
}
if (!cs) {
qCritical() << "ERROR CalcState" << cs.toString() << endl;
} else {
qCritical() << cs.toString();
}
#if 0
qCritical() << __LINE__ << "start ............................" << start.toString(Qt::ISODate);
qCritical() << __LINE__ << "effectiveStart ..................." << effectiveStart.toString(Qt::ISODate);
qCritical() << __LINE__ << "cost ............................." << cost;
qCritical() << __LINE__ << "durationInMinutes ................" << durationInMinutes;
qCritical() << __LINE__ << "offsetInMinutes .................." << offsetInMinutes;
qCritical() << __LINE__ << "effectiveStart.secsTo(end) / 60 .." << effectiveStart.secsTo(end) / 60;
qCritical() << __LINE__ << "end .............................." << end.toString(Qt::ISODate) << endl;
exit(-1);
#endif
}
}
}
}
#endif
#if NEUHAUSER_STOCKERAU==1 #if NEUHAUSER_STOCKERAU==1
std::ifstream input; std::ifstream input;
int pop_min_time; int pop_min_time;