2023-04-19 16:26:12 +02:00
|
|
|
#include "src/ATBAPP/ATBDeviceControllerPlugin.h"
|
|
|
|
#include "src/ATBAPP/ATBHealthEvent.h"
|
|
|
|
|
2023-05-03 11:56:36 +02:00
|
|
|
#include <QTimer>
|
|
|
|
|
2023-04-19 16:26:12 +02:00
|
|
|
|
|
|
|
ATBDeviceControllerPlugin::ATBDeviceControllerPlugin(QObject *parent) : QObject(parent),
|
|
|
|
pluginState(PLUGIN_STATE::NOT_INITIALIZED)
|
|
|
|
{
|
|
|
|
this->pluginInfo = QString::fromUtf8(pluginInfoString.c_str());
|
|
|
|
|
|
|
|
this->hw = new hwapi();
|
2023-05-02 17:10:17 +02:00
|
|
|
|
|
|
|
connect(dynamic_cast<QObject*>(hw), SIGNAL(hwapi_templatePrintFinished_OK()), this, SLOT(onPrintFinishedOK()));
|
|
|
|
connect(dynamic_cast<QObject*>(hw), SIGNAL(hwapi_templatePrintFinished_Err()), this, SLOT(onPrintFinishedERR()));
|
|
|
|
connect(dynamic_cast<QObject*>(hw), SIGNAL(hwapi_gotNewCoin()), this, SLOT(onGotCoin()));
|
2023-04-19 16:26:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ATBDeviceControllerPlugin::~ATBDeviceControllerPlugin() {}
|
|
|
|
|
|
|
|
PLUGIN_STATE ATBDeviceControllerPlugin::initDCPlugin(QObject *healthEventReceiver, const QSettings & settings)
|
|
|
|
{
|
|
|
|
this->healthEventReceiver = healthEventReceiver;
|
|
|
|
|
2023-05-02 17:39:38 +02:00
|
|
|
// read variables from setting
|
|
|
|
QString serialPort = settings.value("DEVICE_CONTROLLER/serialPort", "ttymxc2").toString();
|
2023-04-19 16:26:12 +02:00
|
|
|
|
2023-05-02 17:39:38 +02:00
|
|
|
hw->dc_openSerial(5, "115200", serialPort, 1);
|
2023-05-02 17:10:17 +02:00
|
|
|
|
2023-04-19 16:26:12 +02:00
|
|
|
this->pluginState = PLUGIN_STATE::INITIALIZED;
|
|
|
|
|
|
|
|
return pluginState;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TASKS: Cash handling -------------------------------------------------------
|
|
|
|
void ATBDeviceControllerPlugin::requestStartCashInput(const QString & amount)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ATBDeviceControllerPlugin::requestStopCashInput()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ATBDeviceControllerPlugin::cashCollect()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ATBDeviceControllerPlugin::cashAbort()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TASKS: printing ------------------------------------------------------------
|
|
|
|
void ATBDeviceControllerPlugin::requestPrintTicket(const QHash<QString, QVariant> & printingData)
|
|
|
|
{
|
|
|
|
struct T_dynDat *dynTicketData = new T_dynDat;
|
|
|
|
|
2023-05-03 11:56:36 +02:00
|
|
|
qCritical() << "ATBDeviceControllerPlugin::requestPrintTicket( " << endl
|
|
|
|
<< " licenseplate = " << printingData["licenseplate"] << endl
|
|
|
|
<< " amount = " << printingData["amount"] << endl
|
|
|
|
<< " parkingEnd = " << printingData["parkingEnd"] << endl
|
|
|
|
<< " currentTime = " << printingData["currentTime"] << endl
|
|
|
|
<< " currentDate = " << printingData["currentDate"] << endl;
|
|
|
|
|
|
|
|
|
2023-04-19 16:26:12 +02:00
|
|
|
strncpy((char*)dynTicketData->licensePlate, printingData["licenseplate"].toByteArray().data(), 7);
|
|
|
|
strncpy((char*)dynTicketData->vendingPrice, printingData["amount"].toByteArray().data(), 7);
|
2023-05-02 17:10:17 +02:00
|
|
|
strncpy((char*)dynTicketData->parkingEnd, printingData["parkingEnd"].toByteArray().data(), 7);
|
2023-04-19 16:26:12 +02:00
|
|
|
strncpy((char*)dynTicketData->currentTime, printingData["currentTime"].toByteArray().data(), 7);
|
|
|
|
strncpy((char*)dynTicketData->currentDate, printingData["currentDate"].toByteArray().data(), 7);
|
|
|
|
|
2023-05-02 17:10:17 +02:00
|
|
|
// DEBUG
|
|
|
|
qCritical() << "ATBDeviceControllerPlugin::requestPrintTicket()";
|
|
|
|
if (!this->hw->dc_isPortOpen()) {
|
|
|
|
qCritical() << " ... serial port is not open!";
|
|
|
|
emit this->onPrintFinishedERR();
|
|
|
|
}
|
|
|
|
|
2023-05-03 11:56:36 +02:00
|
|
|
|
|
|
|
// 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";
|
2023-05-02 17:10:17 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
emit this->onPrintFinishedERR();
|
2023-05-03 11:56:36 +02:00
|
|
|
return;
|
2023-05-02 17:10:17 +02:00
|
|
|
}
|
2023-05-03 11:56:36 +02:00
|
|
|
|
|
|
|
QTimer::singleShot(1000, this, SLOT(onPrinterDataPrepared()));
|
2023-04-19 16:26:12 +02:00
|
|
|
}
|
|
|
|
|
2023-05-03 11:56:36 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-04-19 16:26:12 +02:00
|
|
|
|
2023-05-02 17:10:17 +02:00
|
|
|
/************************************************************************************************
|
|
|
|
* private slots, interface to low level hwapi
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void ATBDeviceControllerPlugin::onPrintFinishedOK()
|
|
|
|
{
|
|
|
|
emit this->printTicketFinished(nsDeviceControllerInterface::RESULT_STATE::SUCCESS,
|
|
|
|
"",
|
|
|
|
"");
|
|
|
|
}
|
|
|
|
void 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
|
|
|
|
|
|
|
|
emit this->printTicketFinished(nsDeviceControllerInterface::RESULT_STATE::ERROR_BACKEND,
|
|
|
|
this->errorCode,
|
|
|
|
this->errorDescription);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ATBDeviceControllerPlugin::onGotCoin()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-04-19 16:26:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************************************
|
|
|
|
* Mandatory plugin methods
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
PLUGIN_STATE ATBDeviceControllerPlugin::getState()
|
|
|
|
{
|
|
|
|
return this->pluginState;
|
|
|
|
}
|
|
|
|
|
2023-05-02 17:07:48 +02:00
|
|
|
QString & ATBDeviceControllerPlugin::getLastError()
|
2023-04-19 16:26:12 +02:00
|
|
|
{
|
|
|
|
return this->errorCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString & ATBDeviceControllerPlugin::getLastErrorDescription()
|
|
|
|
{
|
|
|
|
return this->errorDescription;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString & ATBDeviceControllerPlugin::getPluginInfo()
|
|
|
|
{
|
|
|
|
return this->pluginInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const QString ATBDeviceControllerPlugin::getString(nsDeviceControllerInterface::RESULT_STATE resultState)
|
|
|
|
{
|
|
|
|
QString str;
|
|
|
|
|
|
|
|
switch (resultState) {
|
|
|
|
case nsDeviceControllerInterface::RESULT_STATE::SUCCESS:
|
|
|
|
str = QString("RESULT_STATE::SUCCESS");
|
|
|
|
break;
|
|
|
|
case nsDeviceControllerInterface::RESULT_STATE::ERROR_BACKEND:
|
|
|
|
str = QString("RESULT_STATE::ERROR_BACKEND");
|
|
|
|
break;
|
|
|
|
case nsDeviceControllerInterface::RESULT_STATE::ERROR_TIMEOUT:
|
|
|
|
str = QString("RESULT_STATE::ERROR_TIMEOUT");
|
|
|
|
break;
|
|
|
|
case nsDeviceControllerInterface::RESULT_STATE::ERROR_PROCESS:
|
|
|
|
str = QString("RESULT_STATE::ERROR_PROCESS");
|
|
|
|
break;
|
|
|
|
case nsDeviceControllerInterface::RESULT_STATE::ERROR_RETRY:
|
|
|
|
str = QString("RESULT_STATE::ERROR_RETRY");
|
|
|
|
break;
|
|
|
|
case nsDeviceControllerInterface::RESULT_STATE::INFO:
|
|
|
|
str = QString("RESULT_STATE::INFO");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************************************
|
|
|
|
* ... end
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if QT_VERSION < 0x050000
|
|
|
|
Q_EXPORT_PLUGIN2( ATBDeviceControllerPlugin, ATBDeviceControllerPlugin )
|
|
|
|
#endif
|