From ba7d801330423305dd8ec2b2f560a096137a008e Mon Sep 17 00:00:00 2001 From: Siegfried Siegert Date: Fri, 8 Mar 2024 10:50:07 +0100 Subject: [PATCH 1/7] Update DeviceController Interface 1.1.3 (TICKET_VARIANT::FOOD_STAMP) --- src/ATBAPP/DeviceControllerInterface.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ATBAPP/DeviceControllerInterface.h b/src/ATBAPP/DeviceControllerInterface.h index 3416dec..c195860 100644 --- a/src/ATBAPP/DeviceControllerInterface.h +++ b/src/ATBAPP/DeviceControllerInterface.h @@ -196,7 +196,7 @@ signals: Q_DECLARE_INTERFACE(DeviceControllerInterface, - "eu.atb.ptu.plugin.DeviceControllerInterface/1.1.2") + "eu.atb.ptu.plugin.DeviceControllerInterface/1.1.3") namespace nsDeviceControllerInterface { @@ -229,6 +229,7 @@ namespace nsDeviceControllerInterface { ERROR_RECEIPT, START_RECEIPT, // e.g. Szeged Start STOP_RECEIPT, // e.g. Szeged Stop + FOOD_STAMP }; enum class COIN_PROCESSOR : quint8 { From d5786aa5ab6ae142f35769f749ec2571fd42fe81 Mon Sep 17 00:00:00 2001 From: Siegfried Siegert Date: Fri, 8 Mar 2024 12:44:41 +0100 Subject: [PATCH 2/7] Add COIN_PROCESSER::NONE (machine without coin processing) --- src/ATBAPP/DeviceControllerDiag.cpp | 3 +++ src/ATBAPP/DeviceControllerInterface.h | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ATBAPP/DeviceControllerDiag.cpp b/src/ATBAPP/DeviceControllerDiag.cpp index 2a5f89f..7ca3742 100644 --- a/src/ATBAPP/DeviceControllerDiag.cpp +++ b/src/ATBAPP/DeviceControllerDiag.cpp @@ -230,6 +230,9 @@ void DeviceControllerDiag::sub_componentAssessment() // ----------------------------------------------------------------------------------------------- switch (devPara.kindOfCoinChecker) { + case 0: + this->coinProcessorType = nsDeviceControllerInterface::COIN_PROCESSOR::NONE; + break; case 1: case 2: this->coinProcessorType = nsDeviceControllerInterface::COIN_PROCESSOR::ESCROW; diff --git a/src/ATBAPP/DeviceControllerInterface.h b/src/ATBAPP/DeviceControllerInterface.h index c195860..f5ed5ba 100644 --- a/src/ATBAPP/DeviceControllerInterface.h +++ b/src/ATBAPP/DeviceControllerInterface.h @@ -234,7 +234,8 @@ namespace nsDeviceControllerInterface { enum class COIN_PROCESSOR : quint8 { CHANGER, - ESCROW + ESCROW, + NONE }; enum class BILL_ACCEPTOR : quint8 { From 8659627171c4d0082657cbfe74538dcc6eb09edc Mon Sep 17 00:00:00 2001 From: Siegfried Siegert Date: Fri, 8 Mar 2024 13:04:28 +0100 Subject: [PATCH 3/7] Add object variable currentTicketType --- src/ATBAPP/ATBDeviceControllerPlugin.cpp | 6 ++++++ src/ATBAPP/ATBDeviceControllerPlugin.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/ATBAPP/ATBDeviceControllerPlugin.cpp b/src/ATBAPP/ATBDeviceControllerPlugin.cpp index e2698ec..7744872 100644 --- a/src/ATBAPP/ATBDeviceControllerPlugin.cpp +++ b/src/ATBAPP/ATBDeviceControllerPlugin.cpp @@ -67,7 +67,11 @@ ATBDeviceControllerPlugin::ATBDeviceControllerPlugin(QObject *parent) this->diag = new DeviceControllerDiag(this->persistentData, this); connect(this->diag, &DeviceControllerDiag::newVoltage, this, &ATBDeviceControllerPlugin::onNewVoltage); + + // currentSelectedTicketType - number of used "Kombiticket" (deprecated) use TICKET_VARIANT in future this->currentSelectedTicketType = 0; + this->currentTicketVariant = TICKET_VARIANT::PARKING_TICKET; + this->currentCashState = CASH_STATE::CACHE_EMPTY; this->cashStartAmountInt = 0; @@ -606,6 +610,8 @@ void ATBDeviceControllerPlugin::requestPrintTicket(nsDeviceControllerInterface:: this->templateList.clear(); + this->currentTicketVariant = ticketVariant; + switch (ticketVariant) { case nsDeviceControllerInterface::TICKET_VARIANT::START_RECEIPT: qCritical() << " -> TICKET_VARIANT::START_RECEIPT"; diff --git a/src/ATBAPP/ATBDeviceControllerPlugin.h b/src/ATBAPP/ATBDeviceControllerPlugin.h index 07d5b3d..caba403 100644 --- a/src/ATBAPP/ATBDeviceControllerPlugin.h +++ b/src/ATBAPP/ATBDeviceControllerPlugin.h @@ -131,6 +131,8 @@ private: // dbus int init_sc_dbus(); + // printer privates + TICKET_VARIANT currentTicketVariant; QLocale printerLocale; private slots: From 6072970bf08898d9c10edbc1def333cdc6f255f6 Mon Sep 17 00:00:00 2001 From: Siegfried Siegert Date: Fri, 8 Mar 2024 13:06:53 +0100 Subject: [PATCH 4/7] Rework Printing: add private methods depending on TICKET_VARIANT --- src/ATBAPP/ATBDeviceControllerPlugin.cpp | 137 +++++++++++++++-------- src/ATBAPP/ATBDeviceControllerPlugin.h | 4 + 2 files changed, 93 insertions(+), 48 deletions(-) diff --git a/src/ATBAPP/ATBDeviceControllerPlugin.cpp b/src/ATBAPP/ATBDeviceControllerPlugin.cpp index 7744872..fa27e87 100644 --- a/src/ATBAPP/ATBDeviceControllerPlugin.cpp +++ b/src/ATBAPP/ATBDeviceControllerPlugin.cpp @@ -564,50 +564,6 @@ void ATBDeviceControllerPlugin::requestPrintTicket(nsDeviceControllerInterface:: struct T_dynDat *dynTicketData = new T_dynDat; memset(dynTicketData, 0, sizeof(*dynTicketData)); - QDateTime parkingEndDateTime = QDateTime::fromString(printingData["parkingEnd"].toString(), Qt::ISODate); - QDateTime currentDateTime = QDateTime::fromString(printingData["currentDateTime"].toString(), Qt::ISODate); - - QString parkingEndDateString = this->printerLocale.toString(parkingEndDateTime.date(), QLocale::ShortFormat); - QString currentDateString = this->printerLocale.toString(currentDateTime.date(), QLocale::ShortFormat); - - - // set dynamic printer data: - QByteArray ba_licenseplate = codec->fromUnicode(printingData["licenseplate"].toString()); - memcpy((char*)dynTicketData->licensePlate, ba_licenseplate.data(), std::min(ba_licenseplate.size(),8)); - - QByteArray ba_amount = codec->fromUnicode(printingData["amount"].toString()); - memcpy((char*)dynTicketData->vendingPrice, ba_amount.data(), std::min(ba_amount.size(),8)); // Szeged - memcpy((char*)dynTicketData->dynDat6, ba_amount.data(), std::min(ba_amount.size(),8)); // Schoenau - - QByteArray ba_parkingEndTime = codec->fromUnicode(parkingEndDateTime.toString("hh:mm")); - memcpy((char*)dynTicketData->parkingEnd, ba_parkingEndTime.data(), std::min(ba_parkingEndTime.size(),8)); - - QByteArray ba_parkingEndDate = codec->fromUnicode(parkingEndDateString); - memcpy((char*)dynTicketData->currentTime, ba_parkingEndDate.data(), std::min(ba_parkingEndDate.size(),8)); - // ! and yes... 'ParkingEndDate' is 'currentTime' - - QByteArray ba_currentDate = codec->fromUnicode(currentDateString); - memcpy((char*)dynTicketData->currentDate, ba_currentDate.data(), std::min(ba_currentDate.size(),8)); - - // STAN for Szeged Start/Stop: must be 9 digits - // -------------------------------------------------------------------------------------- - QString stan = codec->fromUnicode(printingData["STAN"].toString()); - qCritical() << " requestPrintTicket() STAN = " << stan; - QString stan1; - QString stan2; - if (stan.length() == 9) { - stan1 = " " + stan.mid(0,3); - stan2 = stan.mid(3,3) + " " + stan.mid(6,3); - } - else { - qCritical() << "ASSERT: ATBDeviceControllerPlugin::requestPrintTicket() invalid STAN: " << stan; - stan1 = " 000"; - stan2 = "000 000"; - } - QByteArray ba_stan1 = codec->fromUnicode(stan1); - QByteArray ba_stan2 = codec->fromUnicode(stan2); - // -------------------------------------------------------------------------------------- - this->templateList.clear(); this->currentTicketVariant = ticketVariant; @@ -615,14 +571,12 @@ void ATBDeviceControllerPlugin::requestPrintTicket(nsDeviceControllerInterface:: switch (ticketVariant) { case nsDeviceControllerInterface::TICKET_VARIANT::START_RECEIPT: qCritical() << " -> TICKET_VARIANT::START_RECEIPT"; - memcpy((char*)dynTicketData->dynDat6, ba_stan1.data(), std::min(ba_stan1.size(),8)); - memcpy((char*)dynTicketData->dynDat7, ba_stan2.data(), std::min(ba_stan2.size(),8)); + this->private_setupDynTicketData_START_RECEIPT(dynTicketData, printingData); this->templateList << 21 << 22 << 23; break; case nsDeviceControllerInterface::TICKET_VARIANT::STOP_RECEIPT: qCritical() << " -> TICKET_VARIANT::STOP_RECEIPT"; - memcpy((char*)dynTicketData->dynDat6, ba_stan1.data(), std::min(ba_stan1.size(),8)); - memcpy((char*)dynTicketData->dynDat7, ba_stan2.data(), std::min(ba_stan2.size(),8)); + this->private_setupDynTicketData_STOP_RECEIPT(dynTicketData, printingData); this->templateList << 24 << 25 << 26; break; case nsDeviceControllerInterface::TICKET_VARIANT::RECEIPT: @@ -631,10 +585,16 @@ void ATBDeviceControllerPlugin::requestPrintTicket(nsDeviceControllerInterface:: break; case nsDeviceControllerInterface::TICKET_VARIANT::PARKING_TICKET: break; + case nsDeviceControllerInterface::TICKET_VARIANT::FOOD_STAMP: + qCritical() << " -> TICKET_VARIANT::FOOD_STAMP"; + this->private_setupDynTicketData_FOOD_STAMP(dynTicketData, printingData); + this->private_setupTemplateList_FOOD_STAMP(printingData); + break; } // DEBUG qCritical() << "ATBDeviceControllerPlugin::requestPrintTicket()"; + for (int i =0; i < this->templateList.size(); ++i) { qCritical() << " template: " << this->templateList.at(i); } @@ -962,6 +922,87 @@ void ATBDeviceControllerPlugin::onPrintFinishedERR() +// private printer data setups +void ATBDeviceControllerPlugin::private_setupDynTicketData_START_RECEIPT(struct T_dynDat *dynTicketData, const QHash & printingData) +{ + QDateTime parkingEndDateTime = QDateTime::fromString(printingData["parkingEnd"].toString(), Qt::ISODate); + QDateTime currentDateTime = QDateTime::fromString(printingData["currentDateTime"].toString(), Qt::ISODate); + + QString parkingEndDateString = this->printerLocale.toString(parkingEndDateTime.date(), QLocale::ShortFormat); + QString currentDateString = this->printerLocale.toString(currentDateTime.date(), QLocale::ShortFormat); + + + // set dynamic printer data: + QByteArray ba_licenseplate = codec->fromUnicode(printingData["licenseplate"].toString()); + memcpy((char*)dynTicketData->licensePlate, ba_licenseplate.data(), std::min(ba_licenseplate.size(),8)); + + QByteArray ba_amount = codec->fromUnicode(printingData["amount"].toString()); + memcpy((char*)dynTicketData->vendingPrice, ba_amount.data(), std::min(ba_amount.size(),8)); // Szeged + memcpy((char*)dynTicketData->dynDat6, ba_amount.data(), std::min(ba_amount.size(),8)); // Schoenau + + QByteArray ba_parkingEndTime = codec->fromUnicode(parkingEndDateTime.toString("hh:mm")); + memcpy((char*)dynTicketData->parkingEnd, ba_parkingEndTime.data(), std::min(ba_parkingEndTime.size(),8)); + + QByteArray ba_parkingEndDate = codec->fromUnicode(parkingEndDateString); + memcpy((char*)dynTicketData->currentTime, ba_parkingEndDate.data(), std::min(ba_parkingEndDate.size(),8)); + // ! and yes... 'ParkingEndDate' is 'currentTime' + + QByteArray ba_currentDate = codec->fromUnicode(currentDateString); + memcpy((char*)dynTicketData->currentDate, ba_currentDate.data(), std::min(ba_currentDate.size(),8)); + // STAN for Szeged Start/Stop: must be 9 digits + // -------------------------------------------------------------------------------------- + QString stan = codec->fromUnicode(printingData["STAN"].toString()); + qCritical() << " requestPrintTicket() STAN = " << stan; + QString stan1; + QString stan2; + if (stan.length() == 9) { + stan1 = " " + stan.mid(0,3); + stan2 = stan.mid(3,3) + " " + stan.mid(6,3); + } + else { + qCritical() << "ASSERT: ATBDeviceControllerPlugin::requestPrintTicket() invalid STAN: " << stan; + stan1 = " 000"; + stan2 = "000 000"; + } + QByteArray ba_stan1 = codec->fromUnicode(stan1); + QByteArray ba_stan2 = codec->fromUnicode(stan2); + + + // -------------------------------------------------------------------------------------- + + memcpy((char*)dynTicketData->dynDat6, ba_stan1.data(), std::min(ba_stan1.size(),8)); + memcpy((char*)dynTicketData->dynDat7, ba_stan2.data(), std::min(ba_stan2.size(),8)); + + +} + +void ATBDeviceControllerPlugin::private_setupDynTicketData_STOP_RECEIPT(struct T_dynDat *dynTicketData, const QHash & printingData) +{ + // same as START_RECEIPT + this->private_setupDynTicketData_START_RECEIPT(dynTicketData, printingData); +} + + + +void ATBDeviceControllerPlugin::private_setupDynTicketData_FOOD_STAMP(struct T_dynDat *dynTicketData, const QHash & printingData) +{ + // set dynamic printer data: + QByteArray ba_licenseplate = codec->fromUnicode(printingData["employeeNr"].toString()); + memcpy((char*)dynTicketData->licensePlate, ba_licenseplate.data(), std::min(ba_licenseplate.size(),8)); + + +} + +// print 'multiplicator' x template 1 +void ATBDeviceControllerPlugin::private_setupTemplateList_FOOD_STAMP(const QHash & printingData) +{ + int multiplicatorInt = printingData["multiplicator"].toInt(); + + qCritical() << "printingData[\"multiplicator\"]" << multiplicatorInt; + +} + + /************************************************************************************************ * cash payment */ diff --git a/src/ATBAPP/ATBDeviceControllerPlugin.h b/src/ATBAPP/ATBDeviceControllerPlugin.h index caba403..3e11134 100644 --- a/src/ATBAPP/ATBDeviceControllerPlugin.h +++ b/src/ATBAPP/ATBDeviceControllerPlugin.h @@ -134,6 +134,10 @@ private: // printer privates TICKET_VARIANT currentTicketVariant; QLocale printerLocale; + void private_setupDynTicketData_START_RECEIPT(struct T_dynDat *dynTicketData, const QHash & printingData); + void private_setupDynTicketData_STOP_RECEIPT(struct T_dynDat *dynTicketData, const QHash & printingData); + void private_setupDynTicketData_FOOD_STAMP(struct T_dynDat *dynTicketData, const QHash & printingData); + void private_setupTemplateList_FOOD_STAMP(const QHash & printingData); private slots: // printer From f81369944c50dc9fa81e7fed1acc7e60457b5e0a Mon Sep 17 00:00:00 2001 From: Siegfried Siegert Date: Fri, 8 Mar 2024 13:09:19 +0100 Subject: [PATCH 5/7] FOOD_STAMP: build template list ... Ths last template printed is different (this includes e.g. a full cut whereas the other templates have only a semi-cut. --- src/ATBAPP/ATBDeviceControllerPlugin.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ATBAPP/ATBDeviceControllerPlugin.cpp b/src/ATBAPP/ATBDeviceControllerPlugin.cpp index fa27e87..85fd127 100644 --- a/src/ATBAPP/ATBDeviceControllerPlugin.cpp +++ b/src/ATBAPP/ATBDeviceControllerPlugin.cpp @@ -1000,6 +1000,11 @@ void ATBDeviceControllerPlugin::private_setupTemplateList_FOOD_STAMP(const QHash qCritical() << "printingData[\"multiplicator\"]" << multiplicatorInt; + for (int i = 1; i < multiplicatorInt; i++) { + this->templateList << 1; + } + // last template: + this->templateList << 2; } From b7cedf54446f9d398cd45bb229234ab54cb25ba2 Mon Sep 17 00:00:00 2001 From: Siegfried Siegert Date: Mon, 11 Mar 2024 13:31:51 +0100 Subject: [PATCH 6/7] Add class Ticket --- DCPlugin.pro | 6 +- src/ATBAPP/support/Ticket.cpp | 166 ++++++++++++++++++++++++++++++++++ src/ATBAPP/support/Ticket.h | 88 ++++++++++++++++++ 3 files changed, 258 insertions(+), 2 deletions(-) create mode 100644 src/ATBAPP/support/Ticket.cpp create mode 100644 src/ATBAPP/support/Ticket.h diff --git a/DCPlugin.pro b/DCPlugin.pro index 190ec8d..2615d7a 100644 --- a/DCPlugin.pro +++ b/DCPlugin.pro @@ -87,7 +87,8 @@ HEADERS += \ src/ATBAPP/support/DBusControllerInterface.h \ src/ATBAPP/support/JSON.h \ src/ATBAPP/support/PTUSystem.h \ - src/ATBAPP/support/PersistentData.h + src/ATBAPP/support/PersistentData.h \ + src/ATBAPP/support/Ticket.h SOURCES += \ src/ATBAPP/ATBHealthEvent.cpp \ @@ -99,7 +100,8 @@ SOURCES += \ src/ATBAPP/support/DBusControllerInterface.cpp \ src/ATBAPP/support/JSON.cpp \ src/ATBAPP/support/PTUSystem.cpp \ - src/ATBAPP/support/PersistentData.cpp + src/ATBAPP/support/PersistentData.cpp \ + src/ATBAPP/support/Ticket.cpp DISTFILES += \ generate-version.sh diff --git a/src/ATBAPP/support/Ticket.cpp b/src/ATBAPP/support/Ticket.cpp new file mode 100644 index 0000000..0d6bf0e --- /dev/null +++ b/src/ATBAPP/support/Ticket.cpp @@ -0,0 +1,166 @@ +#include "Ticket.h" + +#include + +Ticket::Ticket(TICKET_VARIANT ticketVariant, QObject *parent ) + : QObject(parent) + , ticketVariant(ticketVariant) + , _hasTemplateDynData(false) +{ + +} + +TICKET_VARIANT Ticket::variant() +{ + return this->ticketVariant; +} + +QList * Ticket::templateList() +{ + return &(this->_templateList); +} + +bool Ticket::hasTemplateDynData() +{ + return this->_hasTemplateDynData; +} + +quint8 Ticket::getCurrentProcessedTemplateNumber() +{ + return this->currentProcessedTemplateNumber; +} + +void Ticket::setCurrentTemplateProcessed() +{ + this->currentProcessedTemplateNumber++; +} + + +bool Ticket::initNew(TICKET_VARIANT ticketVariant, const QList & templateList, const QHash & printingData) +{ + this->clear(); + + this->ticketVariant = ticketVariant; + this->printingData = printingData; + this->_templateList = templateList; + this->currentProcessedTemplateNumber = 0; + + // DEBUG + qCritical() << "Ticket::initNew():"; + qCritical() << " -> " << ticketVariant; + + int multiplicatorInt; + + switch (this->ticketVariant) { + case TICKET_VARIANT::PARKING_TICKET: + break; + case TICKET_VARIANT::RECEIPT: + break; + case TICKET_VARIANT::ERROR_RECEIPT: + break; + case TICKET_VARIANT::START_RECEIPT: + this->_templateList << 21 << 22 << 23; + break; + case TICKET_VARIANT::STOP_RECEIPT: + this->_templateList << 24 << 25 << 26; + break; + case TICKET_VARIANT::FOOD_STAMP: + if (printingData.contains("dyn1_list")) { + this->_hasTemplateDynData = true; + + this->dyn1List = printingData["dyn1_list"].toStringList(); + this->dyn2List = printingData["dyn2_list"].toStringList(); + } + + if (printingData.contains("multiplicator")) { + multiplicatorInt = printingData["multiplicator"].toInt(); + for (int i = 1; i < multiplicatorInt; i++) { + this->_templateList << 1; + } + // last template: + this->_templateList << 2; + } + + // DEBUG FOOD_STAMP: + qCritical() << " --> printingData[\"multiplicator\"]" << multiplicatorInt; + + break; + } + + + // DEBUG + QString templateListString; + for (int i =0; i < this->_templateList.size(); ++i) { + templateListString.append(QString(" %1").arg(this->_templateList.at(i))); + } + qCritical() << " -> templates: " << templateListString; + + + return true; +} + +void Ticket::clear() +{ + this->ticketVariant = TICKET_VARIANT::PARKING_TICKET; + this->printingData.clear(); + this->_templateList.clear(); + this->errorCode.clear(); + this->errorDescription.clear(); + + this->_hasTemplateDynData = false; + this->dyn1List.clear(); + this->dyn1List.clear(); +} + +QString Ticket::getErrorCode() { return this->errorCode; } +QString Ticket::getErrorDescription() { return this->errorDescription; } + + + + +/** + */ +QStringList Ticket::getDyn1List() +{ + return this->dyn1List; +} + +QStringList Ticket::getDyn2List() +{ + return this->dyn2List; +} + + + + + + +/************************************************************************************************ + * operator + * + */ +QDebug operator<<(QDebug debug, TICKET_VARIANT ticketVariant) +{ + switch (ticketVariant) { + case TICKET_VARIANT::PARKING_TICKET: + debug << "TICKET_VARIANT::PARKING_TICKET"; + break; + case TICKET_VARIANT::RECEIPT: + debug << "TICKET_VARIANT::RECEIPT"; + break; + case TICKET_VARIANT::ERROR_RECEIPT: + debug << "TICKET_VARIANT::ERROR_RECEIPT"; + break; + case TICKET_VARIANT::START_RECEIPT: + debug << "TICKET_VARIANT::START_RECEIPT"; + break; + case TICKET_VARIANT::STOP_RECEIPT: + debug << "TICKET_VARIANT::STOP_RECEIPT"; + break; + case TICKET_VARIANT::FOOD_STAMP: + debug << "TICKET_VARIANT::FOOD_STAMP"; + break; + } + + return debug; +} diff --git a/src/ATBAPP/support/Ticket.h b/src/ATBAPP/support/Ticket.h new file mode 100644 index 0000000..25c8382 --- /dev/null +++ b/src/ATBAPP/support/Ticket.h @@ -0,0 +1,88 @@ +#ifndef TICKET_H +#define TICKET_H + +#include +#include + +#include "../DeviceControllerInterface.h" + +using namespace nsDeviceControllerInterface; + +QDebug operator<<(QDebug debug, TICKET_VARIANT ticketVariant); + + + +class Ticket : public QObject +{ + Q_OBJECT + +public: + Ticket(TICKET_VARIANT ticketVariant, QObject *parent = nullptr); + + bool initNew(TICKET_VARIANT ticketVariant, const QList & templateList, const QHash & printingData); + void clear(); + + TICKET_VARIANT variant(); + + QList * templateList(); + + /** + * @brief getPrintingData - generic getter for printingData + * Used mainly for simple tickets (single tickets e.g. ParkingTicket) + * @return + */ + QHash & getPrintingData(); + + /** + * @brief hasTemplateDynData + * @return true, if ticket has dynamic data for each template. + * + * This depends on TICKET_VARIANT and printingData + */ + bool hasTemplateDynData(); + + /** + * @brief getDyn1List + * contains dynamic template data + * The size of the lists must be exactly the same as the number of templates. + */ + QStringList getDyn1List(); + QStringList getDyn2List(); + + quint8 getCurrentProcessedTemplateNumber(); + + /** + * Mark current template as processed + */ + void setCurrentTemplateProcessed(); + + + // error handling + QString getErrorCode(); + QString getErrorDescription(); + + + + +private: + TICKET_VARIANT ticketVariant; + + // printingData from application + QHash printingData; + + // templateList, from .ini or created by ticketVariant... + QList _templateList; + + bool _hasTemplateDynData; + + quint8 currentProcessedTemplateNumber; + + QStringList dyn1List; + QStringList dyn2List; + + // error handling + QString errorCode; + QString errorDescription; +}; + +#endif // TICKET_H From f94f33862fc66ed4ecc63be667319337d6e1aec8 Mon Sep 17 00:00:00 2001 From: Siegfried Siegert Date: Mon, 11 Mar 2024 14:06:05 +0100 Subject: [PATCH 7/7] Printing: dynamically set template dyn-data using Ticket-class See DC_printer_interface.graphml/pdf --- src/ATBAPP/ATBDeviceControllerPlugin.cpp | 213 +++++++++++++---------- src/ATBAPP/ATBDeviceControllerPlugin.h | 22 ++- 2 files changed, 134 insertions(+), 101 deletions(-) diff --git a/src/ATBAPP/ATBDeviceControllerPlugin.cpp b/src/ATBAPP/ATBDeviceControllerPlugin.cpp index 85fd127..d7a8126 100644 --- a/src/ATBAPP/ATBDeviceControllerPlugin.cpp +++ b/src/ATBAPP/ATBDeviceControllerPlugin.cpp @@ -70,7 +70,7 @@ ATBDeviceControllerPlugin::ATBDeviceControllerPlugin(QObject *parent) // currentSelectedTicketType - number of used "Kombiticket" (deprecated) use TICKET_VARIANT in future this->currentSelectedTicketType = 0; - this->currentTicketVariant = TICKET_VARIANT::PARKING_TICKET; + this->currentTicket = new Ticket(TICKET_VARIANT::PARKING_TICKET, this); this->currentCashState = CASH_STATE::CACHE_EMPTY; @@ -558,48 +558,40 @@ void ATBDeviceControllerPlugin::onNewVoltage(uint32_t voltage) - +/** + * @brief ATBDeviceControllerPlugin::requestPrintTicket + * @param ticketVariant + * @param printingData + * + * Setup (initNew()) Ticket-Object + * + */ void ATBDeviceControllerPlugin::requestPrintTicket(nsDeviceControllerInterface::TICKET_VARIANT ticketVariant, const QHash & printingData) { - struct T_dynDat *dynTicketData = new T_dynDat; - memset(dynTicketData, 0, sizeof(*dynTicketData)); + QList templateList; - this->templateList.clear(); + // TODO: read template list from .ini - this->currentTicketVariant = ticketVariant; - - switch (ticketVariant) { - case nsDeviceControllerInterface::TICKET_VARIANT::START_RECEIPT: - qCritical() << " -> TICKET_VARIANT::START_RECEIPT"; - this->private_setupDynTicketData_START_RECEIPT(dynTicketData, printingData); - this->templateList << 21 << 22 << 23; - break; - case nsDeviceControllerInterface::TICKET_VARIANT::STOP_RECEIPT: - qCritical() << " -> TICKET_VARIANT::STOP_RECEIPT"; - this->private_setupDynTicketData_STOP_RECEIPT(dynTicketData, printingData); - this->templateList << 24 << 25 << 26; - break; - case nsDeviceControllerInterface::TICKET_VARIANT::RECEIPT: - break; - case nsDeviceControllerInterface::TICKET_VARIANT::ERROR_RECEIPT: - break; - case nsDeviceControllerInterface::TICKET_VARIANT::PARKING_TICKET: - break; - case nsDeviceControllerInterface::TICKET_VARIANT::FOOD_STAMP: - qCritical() << " -> TICKET_VARIANT::FOOD_STAMP"; - this->private_setupDynTicketData_FOOD_STAMP(dynTicketData, printingData); - this->private_setupTemplateList_FOOD_STAMP(printingData); - break; - } // DEBUG + qCritical() << "------------------------------------------------------------------------"; qCritical() << "ATBDeviceControllerPlugin::requestPrintTicket()"; + qCritical() << " TICKET_VARIANT: " << ticketVariant; + qCritical() << " dyn1_list: " << printingData["dyn1_list"].toStringList(); + qCritical() << " dyn2_list: " << printingData["dyn2_list"].toStringList(); + qCritical() << "------------------------------------------------------------------------"; - for (int i =0; i < this->templateList.size(); ++i) { - qCritical() << " template: " << this->templateList.at(i); + + if (!this->currentTicket->initNew(ticketVariant, templateList, printingData)) { + this->errorCode = this->currentTicket->getErrorCode(); + this->errorDescription = this->currentTicket->getErrorCode(); + + qCritical() << "ERROR: ticket->initNew: " << ticketVariant; + + this->onPrintFinishedERR(); + return; } - /* if (!this->hw->dc_isPortOpen()) { qCritical() << " ... serial port is not open!"; @@ -608,26 +600,7 @@ void ATBDeviceControllerPlugin::requestPrintTicket(nsDeviceControllerInterface:: } */ - // TODO: wird hier nur 'licensePlate' gedruckt? - if (!this->hw->prn_sendDynamicPrnValues(dynTicketData->licensePlate)) { - this->errorCode = "hwapi::prn_sendDynamicPrnValues"; - this->errorDescription = "hwapi method 'hwapi::prn_sendDynamicPrnValues' result is false"; - - qCritical() << "ERROR:"; - qCritical() << "ATBDeviceControllerPlugin::requestPrintTicket( " << endl - << " licenseplate = " << printingData["licenseplate"] << endl - << " amount = " << printingData["amount"] << endl - << " parkingEnd = " << printingData["parkingEnd"] << endl - << " currentTime = " << printingData["currentTime"] << endl - << " currentDate = " << printingData["currentDate"] << endl - << " stan = " << printingData["STAN"] << endl; - - this->onPrintFinishedERR(); - return; - } - - QTimer::singleShot(1000, this, SLOT(onPrinterDataPreparedForTemplates())); - + this->prepareDynTemplateData(); } void ATBDeviceControllerPlugin::requestPrintReceipt(const QHash & printingData) @@ -821,7 +794,7 @@ void ATBDeviceControllerPlugin::requestPrintTicket(const QHashtemplateList.isEmpty()) return; + if (this->currentTicket->templateList()->isEmpty()) return; this->onPrinterPrintNextTemplate(); } @@ -866,30 +839,37 @@ void ATBDeviceControllerPlugin::onPrinterWaitForPrintingTicket() void ATBDeviceControllerPlugin::onPrinterPrintNextTemplate() { // template list must not be empty - if (this->templateList.isEmpty()) { + if (this->currentTicket->templateList()->isEmpty()) { this->onPrintFinishedERR(); return; } - qCritical() << " ... print template " << this->templateList.first(); + qCritical() << " ... print template " << this->currentTicket->templateList()->first(); - if (!this->hw->prn_printTemplate(this->templateList.first())) { + if (!this->hw->prn_printTemplate(this->currentTicket->templateList()->first())) { this->errorCode = "hwapi::prn_printTemplate"; - this->errorDescription = QString("hwapi method 'hwapi::onPrinterPrintNextTemplate(%1)' result is false").arg(this->templateList.first()); + this->errorDescription = QString("hwapi method 'hwapi::onPrinterPrintNextTemplate(%1)' result is false").arg(this->currentTicket->templateList()->first()); this->onPrintFinishedERR(); return; } - this->templateList.removeFirst(); + this->currentTicket->templateList()->removeFirst(); + this->currentTicket->setCurrentTemplateProcessed(); - if (templateList.isEmpty()) { + if (this->currentTicket->templateList()->isEmpty()) { // all templates are printed QTimer::singleShot(2000, this, SLOT(onPrinterWaitForPrintingTicket())); } else { - // print next template - QTimer::singleShot(2000, this, SLOT(onPrinterPrintNextTemplate())); - } + if (this->currentTicket->hasTemplateDynData()) { + // set new dyn data: + QTimer::singleShot(2000, this, SLOT(onPrinterPrepareDynTemplateData())); + } + else { + // print next template + QTimer::singleShot(2000, this, SLOT(onPrinterPrintNextTemplate())); + } + } } /************************************************************************************************ @@ -922,21 +902,71 @@ void ATBDeviceControllerPlugin::onPrintFinishedERR() -// private printer data setups -void ATBDeviceControllerPlugin::private_setupDynTicketData_START_RECEIPT(struct T_dynDat *dynTicketData, const QHash & printingData) +void ATBDeviceControllerPlugin::onPrinterPrepareDynTemplateData() { - QDateTime parkingEndDateTime = QDateTime::fromString(printingData["parkingEnd"].toString(), Qt::ISODate); - QDateTime currentDateTime = QDateTime::fromString(printingData["currentDateTime"].toString(), Qt::ISODate); + this->prepareDynTemplateData(); +} +void ATBDeviceControllerPlugin::prepareDynTemplateData() +{ + struct T_dynDat *dynTicketData = new T_dynDat; + memset(dynTicketData, 0, sizeof(*dynTicketData)); + + // setup dynTicketData dependent on currentTicket + + // DEBUG: + qCritical() << "---------------------------------------------------"; + qCritical() << "ATBDeviceControllerPlugin::prepareDynTemplateData():"; + qCritical() << " -> currentProcessedTemplateNumber: " << this->currentTicket->getCurrentProcessedTemplateNumber(); + qCritical() << " -> this->currentTicket->variant(): " << this->currentTicket->variant(); + qCritical() << "---------------------------------------------------"; + + switch (this->currentTicket->variant()) { + case nsDeviceControllerInterface::TICKET_VARIANT::START_RECEIPT: + private_setupDynTemplateData_START_RECEIPT(dynTicketData, this->currentTicket); + break; + case nsDeviceControllerInterface::TICKET_VARIANT::STOP_RECEIPT: + private_setupDynTemplatData_STOP_RECEIPT(dynTicketData, this->currentTicket); + break; + case nsDeviceControllerInterface::TICKET_VARIANT::RECEIPT: + break; + case nsDeviceControllerInterface::TICKET_VARIANT::ERROR_RECEIPT: + break; + case nsDeviceControllerInterface::TICKET_VARIANT::PARKING_TICKET: + break; + case nsDeviceControllerInterface::TICKET_VARIANT::FOOD_STAMP: + private_setupDynTemplatData_FOOD_STAMP(dynTicketData, this->currentTicket); + break; + } + + // C-Programmierung: wird hier nur 'licensePlate' gedruckt? + if (!this->hw->prn_sendDynamicPrnValues(dynTicketData->licensePlate)) { + this->errorCode = "hwapi::prn_sendDynamicPrnValues"; + this->errorDescription = "hwapi method 'hwapi::prn_sendDynamicPrnValues' result is false"; + + qCritical() << "ERROR: hw->prn_sendDynamicPrnValues"; + + this->onPrintFinishedERR(); + return; + } + + QTimer::singleShot(1000, this, SLOT(onPrinterDataPreparedForTemplates())); +} + + +void ATBDeviceControllerPlugin::private_setupDynTemplateData_START_RECEIPT(struct T_dynDat *dynTicketData, Ticket *ticket) +{ + QDateTime parkingEndDateTime = QDateTime::fromString(ticket->getPrintingData()["parkingEnd"].toString(), Qt::ISODate); + QDateTime currentDateTime = QDateTime::fromString(ticket->getPrintingData()["currentDateTime"].toString(), Qt::ISODate); QString parkingEndDateString = this->printerLocale.toString(parkingEndDateTime.date(), QLocale::ShortFormat); QString currentDateString = this->printerLocale.toString(currentDateTime.date(), QLocale::ShortFormat); // set dynamic printer data: - QByteArray ba_licenseplate = codec->fromUnicode(printingData["licenseplate"].toString()); + QByteArray ba_licenseplate = codec->fromUnicode(ticket->getPrintingData()["licenseplate"].toString()); memcpy((char*)dynTicketData->licensePlate, ba_licenseplate.data(), std::min(ba_licenseplate.size(),8)); - QByteArray ba_amount = codec->fromUnicode(printingData["amount"].toString()); + QByteArray ba_amount = codec->fromUnicode(ticket->getPrintingData()["amount"].toString()); memcpy((char*)dynTicketData->vendingPrice, ba_amount.data(), std::min(ba_amount.size(),8)); // Szeged memcpy((char*)dynTicketData->dynDat6, ba_amount.data(), std::min(ba_amount.size(),8)); // Schoenau @@ -951,7 +981,7 @@ void ATBDeviceControllerPlugin::private_setupDynTicketData_START_RECEIPT(struct memcpy((char*)dynTicketData->currentDate, ba_currentDate.data(), std::min(ba_currentDate.size(),8)); // STAN for Szeged Start/Stop: must be 9 digits // -------------------------------------------------------------------------------------- - QString stan = codec->fromUnicode(printingData["STAN"].toString()); + QString stan = codec->fromUnicode(ticket->getPrintingData()["STAN"].toString()); qCritical() << " requestPrintTicket() STAN = " << stan; QString stan1; QString stan2; @@ -972,40 +1002,39 @@ void ATBDeviceControllerPlugin::private_setupDynTicketData_START_RECEIPT(struct memcpy((char*)dynTicketData->dynDat6, ba_stan1.data(), std::min(ba_stan1.size(),8)); memcpy((char*)dynTicketData->dynDat7, ba_stan2.data(), std::min(ba_stan2.size(),8)); - - } -void ATBDeviceControllerPlugin::private_setupDynTicketData_STOP_RECEIPT(struct T_dynDat *dynTicketData, const QHash & printingData) +void ATBDeviceControllerPlugin::private_setupDynTemplatData_STOP_RECEIPT(struct T_dynDat *dynTicketData, Ticket *ticket) { // same as START_RECEIPT - this->private_setupDynTicketData_START_RECEIPT(dynTicketData, printingData); + this->private_setupDynTemplateData_START_RECEIPT(dynTicketData, ticket); } - - -void ATBDeviceControllerPlugin::private_setupDynTicketData_FOOD_STAMP(struct T_dynDat *dynTicketData, const QHash & printingData) +void ATBDeviceControllerPlugin::private_setupDynTemplatData_FOOD_STAMP(struct T_dynDat *dynTicketData, Ticket *ticket) { - // set dynamic printer data: - QByteArray ba_licenseplate = codec->fromUnicode(printingData["employeeNr"].toString()); + quint8 currentProcessedTemplateNumber = ticket->getCurrentProcessedTemplateNumber(); + + // TODO: check DynXList size / or ensure that DynXList has value + + // "Mitarbeiter-Nummer": dynPr1 -> licenceplate + QString currentEMP_Nr = ticket->getDyn1List().at(currentProcessedTemplateNumber); + QByteArray ba_licenseplate = codec->fromUnicode(currentEMP_Nr); memcpy((char*)dynTicketData->licensePlate, ba_licenseplate.data(), std::min(ba_licenseplate.size(),8)); + // "Lauf.Nr": dynPr2 -> vendingPrice + QString currentStampNumber = ticket->getDyn2List().at(currentProcessedTemplateNumber); + QByteArray ba_amount = codec->fromUnicode(currentStampNumber); + memcpy((char*)dynTicketData->vendingPrice, ba_amount.data(), std::min(ba_amount.size(),8)); + // DEBUG + qCritical() << "-------------------------------------------------------"; + qCritical() << "private_setupDynTemplatData_FOOD_STAMP()"; + qCritical() << " currentProcessedTemplateNumber: " << currentProcessedTemplateNumber; + qCritical() << " currentEMP_Nr: " << currentEMP_Nr; + qCritical() << " currentStampNumber: " << currentStampNumber; + qCritical() << "-------------------------------------------------------"; } -// print 'multiplicator' x template 1 -void ATBDeviceControllerPlugin::private_setupTemplateList_FOOD_STAMP(const QHash & printingData) -{ - int multiplicatorInt = printingData["multiplicator"].toInt(); - - qCritical() << "printingData[\"multiplicator\"]" << multiplicatorInt; - - for (int i = 1; i < multiplicatorInt; i++) { - this->templateList << 1; - } - // last template: - this->templateList << 2; -} /************************************************************************************************ diff --git a/src/ATBAPP/ATBDeviceControllerPlugin.h b/src/ATBAPP/ATBDeviceControllerPlugin.h index 3e11134..dbf3f8d 100644 --- a/src/ATBAPP/ATBDeviceControllerPlugin.h +++ b/src/ATBAPP/ATBDeviceControllerPlugin.h @@ -7,6 +7,7 @@ #include "src/ATBAPP/DeviceControllerInterface.h" #include "src/ATBAPP/ATBAPPplugin.h" #include "src/ATBAPP/DeviceControllerDiag.h" +#include "src/ATBAPP/support/Ticket.h" #include "version.h" @@ -20,11 +21,11 @@ class DBusControllerInterface; class QTextCodec; - using namespace nsDeviceControllerInterface; class QSettings; + class ATBDeviceControllerPlugin : public DeviceControllerInterface { @@ -94,8 +95,6 @@ private: QString errorDescription; QString pluginInfo; - QList templateList; - QString serialPortName; bool useDebug; @@ -131,13 +130,16 @@ private: // dbus int init_sc_dbus(); - // printer privates - TICKET_VARIANT currentTicketVariant; + // printer privates ---------------------------------------------------------------------------- + Ticket * currentTicket; QLocale printerLocale; - void private_setupDynTicketData_START_RECEIPT(struct T_dynDat *dynTicketData, const QHash & printingData); - void private_setupDynTicketData_STOP_RECEIPT(struct T_dynDat *dynTicketData, const QHash & printingData); - void private_setupDynTicketData_FOOD_STAMP(struct T_dynDat *dynTicketData, const QHash & printingData); - void private_setupTemplateList_FOOD_STAMP(const QHash & printingData); + + void prepareDynTemplateData(); + + void private_setupDynTemplateData_START_RECEIPT(struct T_dynDat *dynTicketData, Ticket *ticket); + void private_setupDynTemplatData_STOP_RECEIPT(struct T_dynDat *dynTicketData, Ticket *ticket); + void private_setupDynTemplatData_FOOD_STAMP(struct T_dynDat *dynTicketData, Ticket *ticket); + // --------------------------------------------------------------------------------------------- private slots: // printer @@ -148,6 +150,8 @@ private slots: void onPrinterWaitForPrintingTicket(); void onPrinterWaitForPrintingReceipt(); + void onPrinterPrepareDynTemplateData(); + void onPrintFinishedOK(); void onPrintFinishedERR();