Implement printing ticket
This commit is contained in:
parent
6478eda581
commit
f611e07dcf
@ -2,6 +2,7 @@
|
||||
#include "src/ATBAPP/ATBHealthEvent.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include <QTextCodec>
|
||||
|
||||
|
||||
ATBDeviceControllerPlugin::ATBDeviceControllerPlugin(QObject *parent) : QObject(parent),
|
||||
@ -24,9 +25,19 @@ PLUGIN_STATE ATBDeviceControllerPlugin::initDCPlugin(QObject *healthEventReceive
|
||||
|
||||
// read variables from setting
|
||||
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);
|
||||
|
||||
|
||||
// text encoding for printer
|
||||
this->codec = QTextCodec::codecForName(printerEncoding);
|
||||
|
||||
|
||||
|
||||
this->pluginState = PLUGIN_STATE::INITIALIZED;
|
||||
|
||||
return pluginState;
|
||||
@ -59,6 +70,7 @@ void ATBDeviceControllerPlugin::cashAbort()
|
||||
void ATBDeviceControllerPlugin::requestPrintTicket(const QHash<QString, QVariant> & printingData)
|
||||
{
|
||||
struct T_dynDat *dynTicketData = new T_dynDat;
|
||||
memset(dynTicketData, 0, sizeof(*dynTicketData));
|
||||
|
||||
qCritical() << "ATBDeviceControllerPlugin::requestPrintTicket( " << endl
|
||||
<< " licenseplate = " << printingData["licenseplate"] << endl
|
||||
@ -68,17 +80,24 @@ void ATBDeviceControllerPlugin::requestPrintTicket(const QHash<QString, QVariant
|
||||
<< " currentDate = " << printingData["currentDate"] << endl;
|
||||
|
||||
|
||||
strncpy((char*)dynTicketData->licensePlate, printingData["licenseplate"].toByteArray().data(), 7);
|
||||
strncpy((char*)dynTicketData->vendingPrice, printingData["amount"].toByteArray().data(), 7);
|
||||
strncpy((char*)dynTicketData->parkingEnd, printingData["parkingEnd"].toByteArray().data(), 7);
|
||||
strncpy((char*)dynTicketData->currentTime, printingData["currentTime"].toByteArray().data(), 7);
|
||||
strncpy((char*)dynTicketData->currentDate, printingData["currentDate"].toByteArray().data(), 7);
|
||||
// set dynamic printer data:
|
||||
memcpy((char*)dynTicketData->licensePlate, codec->fromUnicode(printingData["licenseplate"].toString()).data(), 8);
|
||||
memcpy((char*)dynTicketData->vendingPrice, codec->fromUnicode(printingData["amount"].toString()).data(), 8);
|
||||
|
||||
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
|
||||
qCritical() << "ATBDeviceControllerPlugin::requestPrintTicket()";
|
||||
|
||||
if (!this->hw->dc_isPortOpen()) {
|
||||
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;
|
||||
|
||||
|
||||
emit this->onPrintFinishedERR();
|
||||
this->onPrintFinishedERR();
|
||||
return;
|
||||
}
|
||||
|
||||
QTimer::singleShot(1000, this, SLOT(onPrinterDataPrepared()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ATBDeviceControllerPlugin::onPrinterDataPrepared()
|
||||
{
|
||||
for (int i = 1; i <= 3; ++i) {
|
||||
|
||||
qCritical() << " ... print template " << i;
|
||||
|
||||
if (!this->hw->prn_printTemplate(i)) {
|
||||
this->errorCode = "hwapi::prn_printTemplate";
|
||||
this->errorDescription = QString("hwapi method 'hwapi::prn_printTemplate(%1)' result is false").arg(i);
|
||||
emit this->onPrintFinishedERR();
|
||||
return;
|
||||
}
|
||||
}
|
||||
this->currentTemplate = 1;
|
||||
this->onPrinterPrintNextTemplate();
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
this->onPrintFinishedERR();
|
||||
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()
|
||||
{
|
||||
// DEBUG
|
||||
qCritical() << "ATBDeviceControllerPlugin::onPrintFinishedOK()";
|
||||
|
||||
emit this->printTicketFinished(nsDeviceControllerInterface::RESULT_STATE::SUCCESS,
|
||||
"",
|
||||
"");
|
||||
}
|
||||
void ATBDeviceControllerPlugin::onPrintFinishedERR()
|
||||
{
|
||||
// DEBUG
|
||||
qCritical() << "ATBDeviceControllerPlugin::onPrintFinishedERR()";
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
@ -17,6 +17,8 @@
|
||||
#include <QSharedMemory>
|
||||
|
||||
|
||||
class QTextCodec;
|
||||
|
||||
|
||||
using namespace nsDeviceControllerInterface;
|
||||
|
||||
@ -93,6 +95,9 @@ private:
|
||||
QString errorDescription;
|
||||
QString pluginInfo;
|
||||
|
||||
int currentTemplate;
|
||||
|
||||
|
||||
bool useDebug;
|
||||
|
||||
PLUGIN_STATE pluginState;
|
||||
@ -101,11 +106,18 @@ private:
|
||||
|
||||
hwinf* hw;
|
||||
|
||||
QTextCodec *codec;
|
||||
|
||||
private slots:
|
||||
// printer
|
||||
|
||||
void onPrinterDataPrepared();
|
||||
void onPrinterPrintNextTemplate();
|
||||
|
||||
void onPrintFinishedOK();
|
||||
void onPrintFinishedERR();
|
||||
|
||||
// cash payment
|
||||
void onGotCoin();
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user