Implement printing ticket
This commit is contained in:
parent
6478eda581
commit
f611e07dcf
@ -2,6 +2,7 @@
|
|||||||
#include "src/ATBAPP/ATBHealthEvent.h"
|
#include "src/ATBAPP/ATBHealthEvent.h"
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QTextCodec>
|
||||||
|
|
||||||
|
|
||||||
ATBDeviceControllerPlugin::ATBDeviceControllerPlugin(QObject *parent) : QObject(parent),
|
ATBDeviceControllerPlugin::ATBDeviceControllerPlugin(QObject *parent) : QObject(parent),
|
||||||
@ -24,9 +25,19 @@ PLUGIN_STATE ATBDeviceControllerPlugin::initDCPlugin(QObject *healthEventReceive
|
|||||||
|
|
||||||
// read variables from setting
|
// read variables from setting
|
||||||
QString serialPort = settings.value("DEVICE_CONTROLLER/serialPort", "ttymxc2").toString();
|
QString serialPort = settings.value("DEVICE_CONTROLLER/serialPort", "ttymxc2").toString();
|
||||||
|
QByteArray printerEncoding = settings.value("DEVICE_CONTROLLER/printerEnconding", "ISO 8859-2").toString().toLatin1();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// open serial port
|
||||||
hw->dc_openSerial(5, "115200", serialPort, 1);
|
hw->dc_openSerial(5, "115200", serialPort, 1);
|
||||||
|
|
||||||
|
|
||||||
|
// text encoding for printer
|
||||||
|
this->codec = QTextCodec::codecForName(printerEncoding);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
this->pluginState = PLUGIN_STATE::INITIALIZED;
|
this->pluginState = PLUGIN_STATE::INITIALIZED;
|
||||||
|
|
||||||
return pluginState;
|
return pluginState;
|
||||||
@ -59,6 +70,7 @@ void ATBDeviceControllerPlugin::cashAbort()
|
|||||||
void ATBDeviceControllerPlugin::requestPrintTicket(const QHash<QString, QVariant> & printingData)
|
void ATBDeviceControllerPlugin::requestPrintTicket(const QHash<QString, QVariant> & printingData)
|
||||||
{
|
{
|
||||||
struct T_dynDat *dynTicketData = new T_dynDat;
|
struct T_dynDat *dynTicketData = new T_dynDat;
|
||||||
|
memset(dynTicketData, 0, sizeof(*dynTicketData));
|
||||||
|
|
||||||
qCritical() << "ATBDeviceControllerPlugin::requestPrintTicket( " << endl
|
qCritical() << "ATBDeviceControllerPlugin::requestPrintTicket( " << endl
|
||||||
<< " licenseplate = " << printingData["licenseplate"] << endl
|
<< " licenseplate = " << printingData["licenseplate"] << endl
|
||||||
@ -68,17 +80,24 @@ void ATBDeviceControllerPlugin::requestPrintTicket(const QHash<QString, QVariant
|
|||||||
<< " currentDate = " << printingData["currentDate"] << endl;
|
<< " currentDate = " << printingData["currentDate"] << endl;
|
||||||
|
|
||||||
|
|
||||||
strncpy((char*)dynTicketData->licensePlate, printingData["licenseplate"].toByteArray().data(), 7);
|
// set dynamic printer data:
|
||||||
strncpy((char*)dynTicketData->vendingPrice, printingData["amount"].toByteArray().data(), 7);
|
memcpy((char*)dynTicketData->licensePlate, codec->fromUnicode(printingData["licenseplate"].toString()).data(), 8);
|
||||||
strncpy((char*)dynTicketData->parkingEnd, printingData["parkingEnd"].toByteArray().data(), 7);
|
memcpy((char*)dynTicketData->vendingPrice, codec->fromUnicode(printingData["amount"].toString()).data(), 8);
|
||||||
strncpy((char*)dynTicketData->currentTime, printingData["currentTime"].toByteArray().data(), 7);
|
|
||||||
strncpy((char*)dynTicketData->currentDate, printingData["currentDate"].toByteArray().data(), 7);
|
QDateTime parkingEndQDateTime = QDateTime::fromString(printingData["parkingEnd"].toString(), Qt::ISODate);
|
||||||
|
QDateTime currentDateTime = QDateTime::fromString(printingData["currentTime"].toString(), Qt::ISODate);
|
||||||
|
|
||||||
|
memcpy((char*)dynTicketData->parkingEnd, codec->fromUnicode(parkingEndQDateTime.toString("hh:mm")).data(), 8);
|
||||||
|
memcpy((char*)dynTicketData->currentTime, codec->fromUnicode(currentDateTime.toString("hh:mm")).data(), 8);
|
||||||
|
memcpy((char*)dynTicketData->currentDate, codec->fromUnicode(currentDateTime.toString("dd.MM.yy")).data(), 8);
|
||||||
|
|
||||||
// DEBUG
|
// DEBUG
|
||||||
qCritical() << "ATBDeviceControllerPlugin::requestPrintTicket()";
|
qCritical() << "ATBDeviceControllerPlugin::requestPrintTicket()";
|
||||||
|
|
||||||
if (!this->hw->dc_isPortOpen()) {
|
if (!this->hw->dc_isPortOpen()) {
|
||||||
qCritical() << " ... serial port is not open!";
|
qCritical() << " ... serial port is not open!";
|
||||||
emit this->onPrintFinishedERR();
|
this->onPrintFinishedERR();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -96,29 +115,47 @@ void ATBDeviceControllerPlugin::requestPrintTicket(const QHash<QString, QVariant
|
|||||||
<< " currentDate = " << printingData["currentDate"] << endl;
|
<< " currentDate = " << printingData["currentDate"] << endl;
|
||||||
|
|
||||||
|
|
||||||
emit this->onPrintFinishedERR();
|
this->onPrintFinishedERR();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTimer::singleShot(1000, this, SLOT(onPrinterDataPrepared()));
|
QTimer::singleShot(1000, this, SLOT(onPrinterDataPrepared()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ATBDeviceControllerPlugin::onPrinterDataPrepared()
|
void ATBDeviceControllerPlugin::onPrinterDataPrepared()
|
||||||
{
|
{
|
||||||
for (int i = 1; i <= 3; ++i) {
|
this->currentTemplate = 1;
|
||||||
|
this->onPrinterPrintNextTemplate();
|
||||||
|
}
|
||||||
|
|
||||||
qCritical() << " ... print template " << i;
|
|
||||||
|
|
||||||
if (!this->hw->prn_printTemplate(i)) {
|
void ATBDeviceControllerPlugin::onPrinterPrintNextTemplate()
|
||||||
|
{
|
||||||
|
qCritical() << " ... print template " << this->currentTemplate;
|
||||||
|
|
||||||
|
if (!this->hw->prn_printTemplate(this->currentTemplate)) {
|
||||||
this->errorCode = "hwapi::prn_printTemplate";
|
this->errorCode = "hwapi::prn_printTemplate";
|
||||||
this->errorDescription = QString("hwapi method 'hwapi::prn_printTemplate(%1)' result is false").arg(i);
|
this->errorDescription = QString("hwapi method 'hwapi::onPrinterPrintNextTemplate(%1)' result is false").arg(this->currentTemplate);
|
||||||
emit this->onPrintFinishedERR();
|
this->onPrintFinishedERR();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this->currentTemplate >= 3) {
|
||||||
|
// all templates are printed
|
||||||
|
this->currentTemplate = 0;
|
||||||
|
|
||||||
|
// FAKE SIGNAL:
|
||||||
|
QTimer::singleShot(1000, this, SLOT(onPrintFinishedOK()));
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
// print next template
|
||||||
|
this->currentTemplate++;
|
||||||
|
QTimer::singleShot(3000, this, SLOT(onPrinterPrintNextTemplate()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************************************
|
/************************************************************************************************
|
||||||
@ -127,12 +164,19 @@ void ATBDeviceControllerPlugin::onPrinterDataPrepared()
|
|||||||
*/
|
*/
|
||||||
void ATBDeviceControllerPlugin::onPrintFinishedOK()
|
void ATBDeviceControllerPlugin::onPrintFinishedOK()
|
||||||
{
|
{
|
||||||
|
// DEBUG
|
||||||
|
qCritical() << "ATBDeviceControllerPlugin::onPrintFinishedOK()";
|
||||||
|
|
||||||
emit this->printTicketFinished(nsDeviceControllerInterface::RESULT_STATE::SUCCESS,
|
emit this->printTicketFinished(nsDeviceControllerInterface::RESULT_STATE::SUCCESS,
|
||||||
"",
|
"",
|
||||||
"");
|
"");
|
||||||
}
|
}
|
||||||
void ATBDeviceControllerPlugin::onPrintFinishedERR()
|
void ATBDeviceControllerPlugin::onPrintFinishedERR()
|
||||||
{
|
{
|
||||||
|
// DEBUG
|
||||||
|
qCritical() << "ATBDeviceControllerPlugin::onPrintFinishedERR()";
|
||||||
|
|
||||||
|
|
||||||
this->errorCode = "PRINTER"; // TODO: get more detailed error code from low level API
|
this->errorCode = "PRINTER"; // TODO: get more detailed error code from low level API
|
||||||
this->errorDescription = "Printer error"; // TODO: get more detailed error description from low level API
|
this->errorDescription = "Printer error"; // TODO: get more detailed error description from low level API
|
||||||
|
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
#include <QSharedMemory>
|
#include <QSharedMemory>
|
||||||
|
|
||||||
|
|
||||||
|
class QTextCodec;
|
||||||
|
|
||||||
|
|
||||||
using namespace nsDeviceControllerInterface;
|
using namespace nsDeviceControllerInterface;
|
||||||
|
|
||||||
@ -93,6 +95,9 @@ private:
|
|||||||
QString errorDescription;
|
QString errorDescription;
|
||||||
QString pluginInfo;
|
QString pluginInfo;
|
||||||
|
|
||||||
|
int currentTemplate;
|
||||||
|
|
||||||
|
|
||||||
bool useDebug;
|
bool useDebug;
|
||||||
|
|
||||||
PLUGIN_STATE pluginState;
|
PLUGIN_STATE pluginState;
|
||||||
@ -101,11 +106,18 @@ private:
|
|||||||
|
|
||||||
hwinf* hw;
|
hwinf* hw;
|
||||||
|
|
||||||
|
QTextCodec *codec;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
// printer
|
||||||
|
|
||||||
void onPrinterDataPrepared();
|
void onPrinterDataPrepared();
|
||||||
|
void onPrinterPrintNextTemplate();
|
||||||
|
|
||||||
void onPrintFinishedOK();
|
void onPrintFinishedOK();
|
||||||
void onPrintFinishedERR();
|
void onPrintFinishedERR();
|
||||||
|
|
||||||
|
// cash payment
|
||||||
void onGotCoin();
|
void onGotCoin();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user