Add/Implemnt additional printer methods (using templates)

This commit is contained in:
Siegfried Siegert 2023-06-26 19:47:01 +02:00
parent 04e2da390c
commit 6e9b1018e5
Signed by: SiegfriedSiegert
GPG Key ID: 68371E015E8F0B03
2 changed files with 138 additions and 11 deletions

View File

@ -301,6 +301,120 @@ void ATBDeviceControllerPlugin::onAllDoorsClosed()
// TASKS: printing ------------------------------------------------------------
void ATBDeviceControllerPlugin::requestPrintTicket(nsDeviceControllerInterface::TICKET_VARIANT ticketVariant, const QHash<QString, QVariant> & printingData)
{
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);
// 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));
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(parkingEndDateTime.toString("dd.MM.yy"));
memcpy((char*)dynTicketData->currentTime, ba_parkingEndDate.data(), std::min(ba_parkingEndDate.size(),8));
// ! and yes... 'ParkingEndDate' is 'currentTime'
QByteArray ba_currentDate = codec->fromUnicode(currentDateTime.toString("dd.MM.yy"));
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();
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->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->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;
}
// DEBUG
qCritical() << "ATBDeviceControllerPlugin::requestPrintTicket()";
for (int i; i < this->templateList.size(); ++i) {
qCritical() << " template: " << this->templateList.at(i);
}
if (!this->hw->dc_isPortOpen()) {
qCritical() << " ... serial port is not open!";
this->onPrintFinishedERR();
return;
}
// 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()));
}
void ATBDeviceControllerPlugin::requestPrintReceipt(const QHash<QString, QVariant> & printingData)
{
Q_UNUSED(printingData)
qCritical() << "ATBDeviceControllerPlugin::requestPrintReceipt() is currently not implemented";
}
void ATBDeviceControllerPlugin::requestPrintTicket(const QHash<QString, QVariant> & printingData)
{
struct T_dynDat *dynTicketData = new T_dynDat;
@ -412,6 +526,12 @@ void ATBDeviceControllerPlugin::requestPrintTicket(const QHash<QString, QVariant
}
void ATBDeviceControllerPlugin::onPrinterDataPreparedForTemplates()
{
if (this->templateList.isEmpty()) return;
this->onPrinterPrintNextTemplate();
}
void ATBDeviceControllerPlugin::onPrinterDataPrepared()
{
@ -452,31 +572,35 @@ void ATBDeviceControllerPlugin::onPrinterWaitForPrinting()
void ATBDeviceControllerPlugin::onPrinterPrintNextTemplate()
{
qCritical() << " ... print template " << this->currentTemplate;
if (!this->hw->prn_printTemplate(this->currentTemplate)) {
this->errorCode = "hwapi::prn_printTemplate";
this->errorDescription = QString("hwapi method 'hwapi::onPrinterPrintNextTemplate(%1)' result is false").arg(this->currentTemplate);
// template list must not be empty
if (this->templateList.isEmpty()) {
this->onPrintFinishedERR();
return;
}
if (this->currentTemplate >= 3) {
qCritical() << " ... print template " << this->templateList.first();
if (!this->hw->prn_printTemplate(this->templateList.first())) {
this->errorCode = "hwapi::prn_printTemplate";
this->errorDescription = QString("hwapi method 'hwapi::onPrinterPrintNextTemplate(%1)' result is false").arg(this->templateList.first());
this->onPrintFinishedERR();
return;
}
this->templateList.removeFirst();
if (templateList.isEmpty()) {
// all templates are printed
this->currentTemplate = 0;
// FAKE SIGNAL:
QTimer::singleShot(500, this, SLOT(onPrintFinishedOK()));
QTimer::singleShot(2000, this, SLOT(onPrintFinishedOK()));
}
else {
// print next template
this->currentTemplate++;
QTimer::singleShot(2000, this, SLOT(onPrinterPrintNextTemplate()));
}
}
/************************************************************************************************
* private slots, interface to low level hwapi
*

View File

@ -49,6 +49,8 @@ public:
// TASKS: printing ------------------------------------------------------------
void requestPrintTicket(const QHash<QString, QVariant> & printingData);
void requestPrintTicket(nsDeviceControllerInterface::TICKET_VARIANT ticketVariant, const QHash<QString, QVariant> & printingData);
void requestPrintReceipt(const QHash<QString, QVariant> & printingData);
// TASKS: Account -------------------------------------------------------------
void requestAccount();
@ -82,7 +84,7 @@ private:
QString errorDescription;
QString pluginInfo;
int currentTemplate;
QList<int> templateList;
bool useDebug;
@ -112,6 +114,7 @@ private slots:
// printer
void onPrinterDataPrepared();
void onPrinterDataPreparedForTemplates();
void onPrinterPrintNextTemplate();
void onPrinterWaitForPrinting();