just save tests
This commit is contained in:
265
main/main.cpp
265
main/main.cpp
@@ -38,6 +38,7 @@ extern "C" char* strptime(const char* s,
|
||||
#include "aes128.h"
|
||||
#include "cc_iuc_asynchpos.h"
|
||||
#include "MessageHelper.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#define SZEGED (0)
|
||||
#define SCHOENAU_KOENIGSEE (0)
|
||||
@@ -48,8 +49,8 @@ extern "C" char* strptime(const char* s,
|
||||
#define BAD_NEUENAHR_AHRWEILER (0)
|
||||
#define NEUHAUSER_CHRISTOPH_REISEN (0)
|
||||
#define NEUHAUSER_PERNEGG_AN_DER_MUR (0)
|
||||
#define NEUHAUSER_STOCKERAU (1)
|
||||
#define KLEIPEDA_LITAUEN (0)
|
||||
#define NEUHAUSER_STOCKERAU (0)
|
||||
#define KLEIPEDA_LITAUEN (1)
|
||||
|
||||
#if NEUHAUSER_KIRCHDORF==1
|
||||
static bool test_neuhauser_kirchdorf(int step, double cost) {
|
||||
@@ -266,7 +267,7 @@ void iuc_asynchpos_sub_synchTime() {
|
||||
QDateTime current = QDateTime::currentDateTime();
|
||||
|
||||
current.setTime(QTime(12, 0, 0));
|
||||
current.setDate(QDate(2024, 6, 12));
|
||||
current.setDate(QDate(2024, 6, 18));
|
||||
|
||||
QString const &s = current.toString(Qt::ISODate);
|
||||
|
||||
@@ -572,16 +573,17 @@ unsigned int iuc_asynchpos_send(unsigned char packetType,
|
||||
//Eyncrypt result with APAK, according to AES128
|
||||
|
||||
QByteArray x((char *)tempID, IUC_ASYNCHPOS_MIN_BASE_BYTE_DATA_SIZE);
|
||||
QByteArray y((char *)tempID_, IUC_ASYNCHPOS_MIN_BASE_BYTE_DATA_SIZE);
|
||||
QByteArray z((char *)tempAPAK, IUC_ASYNCHPOS_MIN_BASE_BYTE_DATA_SIZE);
|
||||
|
||||
qCritical() << "X" << x.toHex();
|
||||
qCritical() << "Y" << y.toHex();
|
||||
qCritical() << "Z" << z.toHex();
|
||||
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];
|
||||
@@ -697,24 +699,250 @@ void iuc_asynchpos_command_Login() { //Kasse registrieren
|
||||
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() {
|
||||
#if 1
|
||||
#if 0
|
||||
|
||||
MessageHelper msgHelp;
|
||||
|
||||
|
||||
msgHelp.createLoginMessageChunksToSend(0x02);
|
||||
// msgHelp.createLoginMessageChunksToSend(0x02);
|
||||
msgHelp.createAuthorizeMessageChunksToSend(0x02);
|
||||
|
||||
|
||||
qCritical() << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" << endl;
|
||||
// return 0;
|
||||
|
||||
// unsigned static char terminalID[IUC_ASYNCHPOS_MIN_BASE_DATA_SIZE];
|
||||
// unsigned static char terminalAPAK[IUC_ASYNCHPOS_MIN_BASE_DATA_SIZE];
|
||||
strncpy((char *)&terminalID[0], "T-TPS-SELF2002in", IUC_ASYNCHPOS_MIN_BASE_DATA_SIZE);
|
||||
strncpy((char *)&terminalAPAK[0], "8AC304380E0E476BA2558B75DB9E2516", IUC_ASYNCHPOS_MIN_BASE_DATA_SIZE);
|
||||
|
||||
iuc_asynchpos_command_Login();
|
||||
//iuc_asynchpos_command_Login();
|
||||
iuc_asynchpos_command_authorize(1000);
|
||||
|
||||
qCritical() << "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy";
|
||||
return 0;
|
||||
|
||||
// test aes
|
||||
@@ -829,7 +1057,6 @@ int main() {
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
CalcState cs;
|
||||
double cost;
|
||||
int durationInMinutes = 0;
|
||||
@@ -865,6 +1092,16 @@ int main() {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
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) {
|
||||
QDateTime start = s.addSecs(minutes * 60);
|
||||
QDateTime effectiveStart = start;
|
||||
|
||||
Reference in New Issue
Block a user