1197 lines
41 KiB
C++
1197 lines
41 KiB
C++
#include "src/ATBAPP/ATBDeviceControllerPlugin.h"
|
|
#include "src/ATBAPP/ATBHealthEvent.h"
|
|
#include "src/ATBAPP/ATBMachineEvent.h"
|
|
#include "src/ATBAPP/Utils.h"
|
|
#include "src/ATBAPP/support/JSON.h"
|
|
#include "src/ATBAPP/support/DBusControllerInterface.h"
|
|
#include "src/ATBAPP/support/PTUSystem.h"
|
|
#include "src/ATBAPP/support/CashUtils.h"
|
|
|
|
#include <QTimer>
|
|
#include <QThread>
|
|
#include <QTextCodec>
|
|
#include <QDebug>
|
|
|
|
#include <QPluginLoader>
|
|
#include <QDateTime>
|
|
#include <QFileInfo>
|
|
#include <QCoreApplication>
|
|
#include <QUuid>
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
ATBDeviceControllerPlugin::ATBDeviceControllerPlugin(QObject *parent)
|
|
: isMaster(false)
|
|
, pluginState(PLUGIN_STATE::NOT_INITIALIZED)
|
|
, eventReceiver(nullptr)
|
|
{
|
|
this->setParent(parent);
|
|
|
|
this->pluginInfo = QString::fromUtf8(pluginInfoString.c_str());
|
|
|
|
if (!this->private_loadCashAgentLib("")) {
|
|
return;
|
|
}
|
|
|
|
this->init_sc_dbus();
|
|
|
|
|
|
//connect(dynamic_cast<QObject*>(hw), SIGNAL(hwapi_templatePrintFinished_OK()), this, SLOT(onPrintFinishedOK()), Qt::QueuedConnection);
|
|
//connect(dynamic_cast<QObject*>(hw), SIGNAL(hwapi_templatePrintFinished_Err()), this, SLOT(onPrintFinishedERR()), Qt::QueuedConnection);
|
|
|
|
connect(dynamic_cast<QObject*>(hw), SIGNAL(hwapi_gotNewCoin()), this, SLOT(onCashGotCoin()), Qt::QueuedConnection);
|
|
connect(dynamic_cast<QObject*>(hw), SIGNAL(hwapi_payStopByMax()), this, SLOT(onCashPayStopByMax()), Qt::QueuedConnection);
|
|
connect(dynamic_cast<QObject*>(hw), SIGNAL(hwapi_payStopByPushbutton()), this, SLOT(onCashPayStopByPushbutton()), Qt::QueuedConnection);
|
|
connect(dynamic_cast<QObject*>(hw), SIGNAL(hwapi_payStopByEscrow()), this, SLOT(onCashPayStopByEscrow()), Qt::QueuedConnection);
|
|
connect(dynamic_cast<QObject*>(hw), SIGNAL(hwapi_payStopByError()), this, SLOT(onCashPayStopByError()), Qt::QueuedConnection);
|
|
connect(dynamic_cast<QObject*>(hw), SIGNAL(hwapi_payStopByTimeout()), this, SLOT(onCashPayStopByTimeout()), Qt::QueuedConnection);
|
|
|
|
connect(dynamic_cast<QObject*>(hw), SIGNAL(hwapi_doorServiceDoorOpened()), this, SLOT(onServiceDoorOpened()), Qt::QueuedConnection); // switch to ModeSERVICE
|
|
connect(dynamic_cast<QObject*>(hw), SIGNAL(hwapi_doorVaultDoorOpened()), this, SLOT(onVaultDoorOpened()), Qt::QueuedConnection); // Screen?? with message
|
|
connect(dynamic_cast<QObject*>(hw), SIGNAL(hwapi_doorCoinBoxRemoved()), this, SLOT(onCoinBoxRemoved()), Qt::QueuedConnection); // Create/Send Account
|
|
connect(dynamic_cast<QObject*>(hw), SIGNAL(hwapi_doorCoinBoxInserted()), this, SLOT(onCoinBoxInserted()), Qt::QueuedConnection);
|
|
connect(dynamic_cast<QObject*>(hw), SIGNAL(hwapi_doorCBinAndAllDoorsClosed()), this, SLOT(onCBinAndAllDoorsClosed()), Qt::QueuedConnection);
|
|
connect(dynamic_cast<QObject*>(hw), SIGNAL(hwapi_doorAllDoorsClosed()), this, SLOT(onAllDoorsClosed()), Qt::QueuedConnection); // check for errors, switch to mode IDLE
|
|
|
|
// move hw object to separate thread:
|
|
auto hwThread = new QThread;
|
|
dynamic_cast<QObject*>(hw)->moveToThread(hwThread);
|
|
hwThread->start();
|
|
|
|
|
|
this->diag = new DeviceControllerDiag(this);
|
|
connect(this->diag, &DeviceControllerDiag::newVoltage, this, &ATBDeviceControllerPlugin::onNewVoltage);
|
|
|
|
|
|
this->currentSelectedTicketType = 0;
|
|
this->currentCashState = CASH_STATE::CACHE_EMPTY;
|
|
}
|
|
|
|
ATBDeviceControllerPlugin::~ATBDeviceControllerPlugin() {}
|
|
|
|
PLUGIN_STATE ATBDeviceControllerPlugin::initDCPlugin(QObject *eventReceiver, const QSettings & settings)
|
|
{
|
|
this->eventReceiver = eventReceiver;
|
|
|
|
// read variables from setting
|
|
this->serialPortName = settings.value("ATBDeviceControllerPlugin/serialPort", "ttymxc2").toString();
|
|
QByteArray printerEncoding = settings.value("ATBDeviceControllerPlugin/printerEncoding", "ISO 8859-2").toString().toLatin1();
|
|
|
|
if (this->isMaster) {
|
|
// open serial port
|
|
hw->dc_openSerial(5, "115200", this->serialPortName, 1);
|
|
hw->dc_autoRequest(true);
|
|
}
|
|
|
|
hw->dc_setNewCustomerNumber(PTUSystem::readCustomerNumber());
|
|
hw->dc_setNewMachineNumber(PTUSystem::readMachineNumber());
|
|
hw->dc_setNewZone(PTUSystem::readZoneNumber());
|
|
hw->dc_setNewBorough(PTUSystem::readGroupNumber());
|
|
|
|
hw->rtc_setDateTime();
|
|
|
|
// this is necessary to init the CashAgentLib (!)
|
|
hw->vend_failed();
|
|
|
|
|
|
// text encoding for printer
|
|
this->codec = QTextCodec::codecForName(printerEncoding);
|
|
|
|
if (this->codec == nullptr) {
|
|
printerEncoding = "ISO 8859-1";
|
|
qCritical() << "ATBDeviceControllerPlugin: ERROR: printer encoding \"" << printerEncoding << "\" is not supported!";
|
|
qCritical() << " ... use default encoding: " << printerEncoding;
|
|
this->codec = QTextCodec::codecForName(printerEncoding);
|
|
}
|
|
else {
|
|
qCritical() << "ATBDeviceControllerPlugin: Set printer encoding to " << printerEncoding;
|
|
}
|
|
|
|
this->diag->init(this->hw, this->eventReceiver);
|
|
|
|
this->pluginState = PLUGIN_STATE::INITIALIZED;
|
|
|
|
return pluginState;
|
|
}
|
|
|
|
|
|
void ATBDeviceControllerPlugin::startPhysicalLayer()
|
|
{
|
|
if (!this->isMaster) return;
|
|
|
|
if (this->pluginState == PLUGIN_STATE::NOT_INITIALIZED)
|
|
{
|
|
qCritical() << "ATBDeviceControllerPlugin::startPhysicalLayer(): plugin is not initialized";
|
|
return;
|
|
}
|
|
|
|
// open serial port
|
|
hw->dc_openSerial(5, "115200", this->serialPortName, 1);
|
|
|
|
hw->dc_autoRequest(true);
|
|
}
|
|
|
|
void ATBDeviceControllerPlugin::stopPhysicalLayer()
|
|
{
|
|
if (!this->isMaster) return;
|
|
|
|
if (this->pluginState == PLUGIN_STATE::NOT_INITIALIZED)
|
|
{
|
|
qCritical() << "ATBDeviceControllerPlugin::startPhysicalLayer(): plugin is not initialized";
|
|
return;
|
|
}
|
|
|
|
hw->dc_autoRequest(false);
|
|
|
|
hw->dc_closeSerial();
|
|
}
|
|
|
|
|
|
void ATBDeviceControllerPlugin::reboot()
|
|
{
|
|
// note:
|
|
// - dc reset lasts about ~5s !
|
|
// - makes a power cycle to certain components, e.g. card terminal
|
|
hw->bl_rebootDC();
|
|
}
|
|
|
|
void ATBDeviceControllerPlugin::reset()
|
|
{
|
|
// note:
|
|
// - dc reset lasts about ~5s !
|
|
// - makes a power cycle to certain components, e.g. card terminal
|
|
hw->dc_OrderToReset();
|
|
}
|
|
|
|
|
|
|
|
// Handle Mode-Changes --------------------------------------------------------
|
|
|
|
void ATBDeviceControllerPlugin::onChangedProgramModeToSELL()
|
|
{
|
|
hw->rtc_setDateTime();
|
|
hw->mdb_switchWake(0); // wakeup MDB components
|
|
}
|
|
|
|
void ATBDeviceControllerPlugin::onChangedProgramModeToSERVICE()
|
|
{
|
|
//hw->dc_autoRequest(true);
|
|
hw->mdb_switchWake(0); // wakeup MDB components
|
|
}
|
|
|
|
void ATBDeviceControllerPlugin::onChangedProgramModeToIDLE()
|
|
{
|
|
//hw->dc_autoRequest(false); // <-- TODO: ???
|
|
|
|
this->diag->diagRequest();
|
|
hw->mdb_switchWake(1);
|
|
|
|
}
|
|
|
|
void ATBDeviceControllerPlugin::onChangedProgramModeToOOO()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
// TASKS: Cash handling -------------------------------------------------------
|
|
void ATBDeviceControllerPlugin::requestStartCashInput(const QString & amount)
|
|
{
|
|
qCritical() << "Start Cash vending with amount = " << amount;
|
|
|
|
uint32_t amountInt = static_cast<uint32_t>(amount.toUInt());
|
|
|
|
if (amountInt == 0) amountInt = UINT_MAX;
|
|
|
|
hw->cash_startPayment(amountInt);
|
|
}
|
|
|
|
void ATBDeviceControllerPlugin::requestStopCashInput()
|
|
{
|
|
hw->cash_stopPayment();
|
|
|
|
// we need new cash value in application...
|
|
QTimer::singleShot(2500, this, SLOT(onCashPayStopedSuccess()));
|
|
}
|
|
|
|
void ATBDeviceControllerPlugin::cashCollect()
|
|
{
|
|
hw->vend_success();
|
|
this->currentCashState = CASH_STATE::CACHE_EMPTY;
|
|
}
|
|
|
|
void ATBDeviceControllerPlugin::cashAbort()
|
|
{
|
|
hw->vend_failed();
|
|
this->currentCashState = CASH_STATE::CACHE_EMPTY;
|
|
}
|
|
|
|
// Coin/Cash processing variants ----------------------------------------------
|
|
|
|
nsDeviceControllerInterface::COIN_PROCESSOR ATBDeviceControllerPlugin::coinProcessor()
|
|
{
|
|
return this->diag->coinProcessorType;
|
|
}
|
|
|
|
nsDeviceControllerInterface::BILL_ACCEPTOR ATBDeviceControllerPlugin::billAcceptor()
|
|
{
|
|
return this->diag->billAcceptor;
|
|
}
|
|
|
|
|
|
// TASKS: Account -------------------------------------------------------------
|
|
|
|
// for an external account request, e.g. by an ui-button:
|
|
void ATBDeviceControllerPlugin::requestAccount()
|
|
{
|
|
qCritical() << "ATBDeviceControllerPlugin::requestAccount()";
|
|
|
|
this->private_startAccount();
|
|
}
|
|
|
|
void ATBDeviceControllerPlugin::private_startAccount()
|
|
{
|
|
uint16_t backupedAccNumbers[8]; // array of account numbers
|
|
uint8_t nrOfVals; // number of saved accounts
|
|
|
|
// it is not defined which one is the latest account
|
|
hw->log_getHoldAccountNumbers(&nrOfVals, backupedAccNumbers);
|
|
|
|
// DEBUG
|
|
qCritical() << "Start account: ";
|
|
qCritical() << " nrOfVals = " << nrOfVals;
|
|
for (int i=0; i<nrOfVals; ++i) {
|
|
qCritical() << " backupedAccNumbers[" << i << "] = " << backupedAccNumbers[i];
|
|
}
|
|
|
|
qsort( backupedAccNumbers, nrOfVals, sizeof (uint16_t), Utils::compare );
|
|
|
|
uint16_t latestAccountNumber = backupedAccNumbers[nrOfVals-1];
|
|
|
|
|
|
// DEBUG
|
|
qCritical() << " latestAccountNumber = " << latestAccountNumber;
|
|
|
|
hw->log_selectVaultRecord(latestAccountNumber);
|
|
|
|
this->accountCheckCounter = 0;
|
|
QTimer::singleShot(500, this, SLOT(private_checkAccountData()));
|
|
}
|
|
|
|
void ATBDeviceControllerPlugin::private_checkAccountData()
|
|
{
|
|
// DEBUG
|
|
qCritical() << " --> private_checkAccountData()";
|
|
|
|
if (hw->log_chkIfVaultRecordAvailable()) {
|
|
this->private_getAccountData();
|
|
}
|
|
else {
|
|
if (this->accountCheckCounter < 10) {
|
|
this->accountCheckCounter++;
|
|
QTimer::singleShot(500, this, SLOT(private_checkAccountData()));
|
|
}
|
|
else {
|
|
// cannot get accountData within ~10*500ms
|
|
qCritical() << "checkAccountData() failed";
|
|
|
|
// simulate:
|
|
this->private_getAccountData();
|
|
|
|
|
|
// TODO: create and send an HealthEvent...
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void ATBDeviceControllerPlugin::private_getAccountData()
|
|
{
|
|
// DEBUG
|
|
qCritical() << " --> private_getAccountData()";
|
|
|
|
struct T_vaultRecord retVR;
|
|
|
|
hw->log_getVaultRecord(&retVR);
|
|
|
|
QHash<QString, QVariant> accountData;
|
|
|
|
accountData.insert("AccountingNumber", QString::number(retVR.AccountingNumber));
|
|
|
|
|
|
// build dateTime: -------------------------------------------------------
|
|
// Example: "2023-07-19T18:24:01.063+02:00"
|
|
QString startDateTimeString;
|
|
QString formatString = "yyyy-MM-ddThh:mm:ss";
|
|
uint year = retVR.year + 2000;
|
|
startDateTimeString.append(QString::number(year)).append("-");
|
|
uint month = retVR.month;
|
|
startDateTimeString.append(QString::number(month).rightJustified(2, '0')).append("-");
|
|
uint day = retVR.dom;
|
|
startDateTimeString.append(QString::number(day).rightJustified(2, '0')).append("T");
|
|
uint hour = retVR.hour;
|
|
startDateTimeString.append(QString::number(hour).rightJustified(2, '0')).append(":");
|
|
uint minute = retVR.min;
|
|
startDateTimeString.append(QString::number(minute).rightJustified(2, '0')).append(":");
|
|
uint seconds = retVR.sec;
|
|
startDateTimeString.append(QString::number(seconds).rightJustified(2, '0'));
|
|
|
|
qCritical() << " startDateTimeString = " << startDateTimeString;
|
|
|
|
QDateTime startDateTime = QDateTime::fromString(startDateTimeString, formatString);
|
|
accountData.insert("accountStartTime", startDateTime);
|
|
//-------------------------------------------------------------------------
|
|
|
|
// COINS in Vault: --------------------------------------------------------
|
|
|
|
int numberOfCoinVariants = sizeof(retVR.coinsInVault)/sizeof(retVR.coinsInVault[0]);
|
|
|
|
// DEBUG
|
|
qCritical() << " NumberOfCoinVariants = " << numberOfCoinVariants;
|
|
|
|
// limit numberOfCoinVariants:
|
|
if (numberOfCoinVariants > 16) { numberOfCoinVariants = 16; }
|
|
|
|
accountData.insert("NumberOfCoinVariants", numberOfCoinVariants);
|
|
for (int i = 0; i < numberOfCoinVariants; ++i) {
|
|
accountData.insert("COIN_" + QString::number(i+1) + "_Quantity", retVR.coinsInVault[i]);
|
|
accountData.insert("COIN_" + QString::number(i+1) + "_Value", retVR.coinDenomination[i]);
|
|
|
|
// DEBUG
|
|
qCritical() << "COIN_" + QString::number(i+1) + "_Quantity = " << accountData["COIN_" + QString::number(i) + "_Quantity"];
|
|
qCritical() << "COIN_" + QString::number(i+1) + "_Value = " << accountData["COIN_" + QString::number(i) + "_Value"];
|
|
}
|
|
|
|
// NOTES in stacker: --------------------------------------------------------
|
|
|
|
int numberOfBillVariants = sizeof(retVR.billsInStacker)/sizeof(retVR.billsInStacker[0]);
|
|
|
|
// DEBUG
|
|
qCritical() << " numberOfBillVariants = " << numberOfBillVariants;
|
|
|
|
// limit numberOfBillVariants:
|
|
if (numberOfBillVariants > 16) { numberOfBillVariants = 16; }
|
|
|
|
accountData.insert("NumberOfBillVariants", numberOfBillVariants);
|
|
for (int i = 0; i < numberOfBillVariants; ++i) {
|
|
accountData.insert("NOTE_" + QString::number(i+1) + "_Quantity", retVR.billsInStacker[i]);
|
|
accountData.insert("NOTE_" + QString::number(i+1) + "_Value", retVR.billDenom[i]);
|
|
|
|
// DEBUG
|
|
qCritical() << "NOTE_" + QString::number(i+1) + "_Quantity = " << accountData["NOTE_" + QString::number(i+1) + "_Quantity"];
|
|
qCritical() << "NOTE_" + QString::number(i+1) + "_Value = " << accountData["NOTE_" + QString::number(i+1) + "_Value"];
|
|
}
|
|
|
|
|
|
|
|
emit requestAccountResponse(accountData);
|
|
}
|
|
|
|
|
|
// Door Events / Hardware contacts --------------------------------------------
|
|
void ATBDeviceControllerPlugin::onServiceDoorOpened()
|
|
{
|
|
qCritical() << "ATBDeviceControllerPlugin::onServiceDoorOpened()";
|
|
|
|
// ... to detect alarm etc.
|
|
this->diag->diagRequest();
|
|
|
|
// switch to mode service
|
|
emit this->requestModeSERVICE();
|
|
|
|
// TODO:
|
|
// - create an HealthEvent (-> ISMAS-Event)
|
|
}
|
|
|
|
void ATBDeviceControllerPlugin::onVaultDoorOpened()
|
|
{
|
|
// TODO:
|
|
// - show special screen / message on screen
|
|
// - create an HealthEvent (-> ISMAS-Event)
|
|
qCritical() << "ATBDeviceControllerPlugin::onVaultDoorOpened()";
|
|
|
|
// ... to detect alarm etc.
|
|
this->diag->diagRequest();
|
|
|
|
// this is started here because we want to keep ptu awake in order to get
|
|
// coin box removed / inserted etc.
|
|
// BackgroundTask("ACCOUNT") is finished, if account message is sent to ISMAS!
|
|
this->dbus->startBackgroundTask("DOOR_OPEN");
|
|
|
|
// do not: emit this->requestModeSERVICE();
|
|
}
|
|
|
|
void ATBDeviceControllerPlugin::onCoinBoxRemoved()
|
|
{
|
|
qCritical() << "ATBDeviceControllerPlugin::onCoinBoxRemoved()";
|
|
|
|
// BackgroundTask("ACCOUNT") is finished, if account message is sent to ISMAS!
|
|
this->dbus->startBackgroundTask("ACCOUNT");
|
|
|
|
QTimer::singleShot(4000, this, SLOT(private_startAccount()));
|
|
}
|
|
|
|
void ATBDeviceControllerPlugin::onCoinBoxInserted()
|
|
{
|
|
qCritical() << "ATBDeviceControllerPlugin::onCoinBoxInserted()";
|
|
}
|
|
|
|
/**
|
|
* This is called, when all CoinBox is inserted and all doors
|
|
* are closed.
|
|
*/
|
|
void ATBDeviceControllerPlugin::onCBinAndAllDoorsClosed()
|
|
{
|
|
qCritical() << "ATBDeviceControllerPlugin::onCBinAndAllDoorsClosed()";
|
|
|
|
QTimer::singleShot(2000, this, SIGNAL(requestModeIDLE()));
|
|
|
|
this->dbus->finishedBackgroundTask("DOOR_OPEN");
|
|
}
|
|
|
|
/**
|
|
* This is called, when all no coinbox is inserted and all doors are
|
|
* closed.
|
|
*/
|
|
void ATBDeviceControllerPlugin::onAllDoorsClosed()
|
|
{
|
|
qCritical() << "ATBDeviceControllerPlugin::onAllDoorsClosed()";
|
|
|
|
emit this->requestModeIDLE();
|
|
this->dbus->finishedBackgroundTask("DOOR_OPEN");
|
|
|
|
// TODO: check for errors and create a machine event
|
|
}
|
|
|
|
void ATBDeviceControllerPlugin::onNewVoltage(uint32_t voltage)
|
|
{
|
|
qCritical() << "ATBDeviceControllerPlugin::onNewVoltage() = " << voltage;
|
|
|
|
QString voltageString = QString::number(voltage);
|
|
|
|
JSON::setPrettySerialize(true);
|
|
JSON::JsonObject json;
|
|
|
|
json = JSON::objectBuilder()
|
|
->set("Name", "batt")
|
|
->set("Value", voltageString)
|
|
->set("Unit", "V")
|
|
->create();
|
|
|
|
|
|
ATBHealthEvent *healthEvent = new ATBHealthEvent(
|
|
ATB_HEALTH_MODE::STATE,
|
|
"VOLTAGE",
|
|
JSON::serialize(json)
|
|
);
|
|
|
|
QCoreApplication::postEvent(eventReceiver, healthEvent);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
QString parkingEndDateString = QLocale().toString(parkingEndDateTime.date(), QLocale::ShortFormat);
|
|
QString currentDateString = QLocale().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();
|
|
|
|
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 =0; 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::requestPrintReceipt(const QString & printingString)
|
|
{
|
|
QByteArray ba = printingString.toUtf8();
|
|
hw->prn_switchPower(true);
|
|
hw->prn_sendText(&ba);
|
|
QTimer::singleShot(4000, this, SLOT(onPrinterWaitForPrintingReceipt()));
|
|
|
|
//QTimer::singleShot(2000, this, [this](){ hw->prn_cut(3); } );
|
|
}
|
|
|
|
void ATBDeviceControllerPlugin::onPrinterWaitForPrintingReceipt()
|
|
{
|
|
quint8 printerResult = this->hw->prn_getPrintResult();
|
|
|
|
switch (printerResult) {
|
|
case 0: // still printing
|
|
qCritical() << "--> printer: WaitForPrintingReceipt";
|
|
QTimer::singleShot(2000, this, SLOT(onPrinterWaitForPrintingReceipt()));
|
|
break;
|
|
case 1: // printing finished, Ok
|
|
qCritical() << "DC Finished printing receipt";
|
|
emit this->printReceiptFinished(nsDeviceControllerInterface::RESULT_STATE::SUCCESS,
|
|
// TODO: TicketNumber
|
|
"",
|
|
"");
|
|
hw->prn_switchPower(true);
|
|
hw->prn_cut(3);
|
|
break;
|
|
case 2: // printing finished, Error
|
|
qCritical() << "DC Error: wait for printing receipt";
|
|
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->printReceiptFinished(nsDeviceControllerInterface::RESULT_STATE::ERROR_BACKEND,
|
|
this->errorCode,
|
|
this->errorDescription);
|
|
break;
|
|
default:
|
|
qCritical() << "DC Error: wait for printing receipt";
|
|
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->printReceiptFinished(nsDeviceControllerInterface::RESULT_STATE::ERROR_BACKEND,
|
|
this->errorCode,
|
|
this->errorDescription);
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
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
|
|
<< " amount = " << printingData["amount"] << endl
|
|
<< " parkingEnd = " << printingData["parkingEnd"] << endl
|
|
<< " currentDateTime = " << printingData["currentDateTime"] << endl;
|
|
|
|
QDateTime parkingEndDateTime = QDateTime::fromString(printingData["parkingEnd"].toString(), Qt::ISODate);
|
|
QDateTime currentDateTime = QDateTime::fromString(printingData["currentDateTime"].toString(), Qt::ISODate);
|
|
|
|
QString parkingEndDateString = QLocale().toString(parkingEndDateTime.date(), QLocale::ShortFormat);
|
|
QString currentDateString = QLocale().toString(currentDateTime.date(), QLocale::ShortFormat);
|
|
|
|
/* -----------------------------------------------------------------------------------------
|
|
* note: the following highly depends on printer template files!
|
|
* -----------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
// 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));
|
|
|
|
|
|
// DEBUG
|
|
/*
|
|
uint8_t* buf = dynTicketData->licensePlate;
|
|
int length = 64;
|
|
for (int i = 0; i < length; ++i) {
|
|
fprintf(stderr, "%d %02x %c\n", i, buf[i], buf[i]);
|
|
}
|
|
fprintf(stderr, "\n");
|
|
*/
|
|
|
|
// DEBUG
|
|
qCritical() << "ATBDeviceControllerPlugin::requestPrintTicket()";
|
|
|
|
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;
|
|
|
|
|
|
this->onPrintFinishedERR();
|
|
return;
|
|
}
|
|
|
|
// set ticket type:
|
|
// 00281 - Szeged:
|
|
// 1 - Cash / ShortTimeParking
|
|
// 2 - Card / ShortTimeParking
|
|
// 3 - Cash / DayTicket
|
|
// 4 - Card / DayTicket
|
|
QString paymentType = printingData["paymentType"].toString(); // must be "CASH" | "CARD"
|
|
QString productName = printingData["product"].toString(); // must be "ShortTimeParking" | "DayTicket"
|
|
|
|
if ( (paymentType == "CASH") && (productName == "ShortTimeParking") ) {
|
|
this->currentSelectedTicketType = 1;
|
|
}
|
|
else
|
|
if ( (paymentType == "CARD") && (productName == "ShortTimeParking") ) {
|
|
this->currentSelectedTicketType = 2;
|
|
}
|
|
else
|
|
if ( (paymentType == "CASH") && (productName == "DayTicket") ) {
|
|
this->currentSelectedTicketType = 3;
|
|
}
|
|
else
|
|
if ( (paymentType == "CARD") && (productName == "DayTicket") ) {
|
|
this->currentSelectedTicketType = 4;
|
|
}
|
|
else {
|
|
qCritical() << "ERROR: requestPrintTicket(): invalid payment data:";
|
|
qCritical() << " paymentType = " << paymentType << endl
|
|
<< " productName = " << productName << endl;
|
|
this->onPrintFinishedERR();
|
|
return;
|
|
}
|
|
|
|
QTimer::singleShot(3000, this, SLOT(onPrinterDataPrepared()));
|
|
}
|
|
|
|
|
|
void ATBDeviceControllerPlugin::onPrinterDataPreparedForTemplates()
|
|
{
|
|
if (this->templateList.isEmpty()) return;
|
|
|
|
this->onPrinterPrintNextTemplate();
|
|
}
|
|
|
|
void ATBDeviceControllerPlugin::onPrinterDataPrepared()
|
|
{
|
|
this->hw->prn_printKombiticket(this->currentSelectedTicketType);
|
|
|
|
// note: calling prn_getPrintResult() immediately may result in wrong answer!
|
|
// We have to wait "about some seconds" until calling this function!
|
|
QTimer::singleShot(4000, this, SLOT(onPrinterWaitForPrintingTicket()));
|
|
|
|
// old: use printer templates:
|
|
// this->currentTemplate = 1;
|
|
// this->onPrinterPrintNextTemplate();
|
|
}
|
|
|
|
void ATBDeviceControllerPlugin::onPrinterWaitForPrintingTicket()
|
|
{
|
|
quint8 printerResult = this->hw->prn_getPrintResult();
|
|
|
|
switch (printerResult) {
|
|
case 0: // still printing
|
|
qCritical() << "--> printer: WaitForPrintingTicket";
|
|
QTimer::singleShot(2000, this, SLOT(onPrinterWaitForPrintingTicket()));
|
|
break;
|
|
case 1: // printing finished, Ok
|
|
this->onPrintFinishedOK();
|
|
break;
|
|
case 2: // printing finished, Error
|
|
this->onPrintFinishedERR();
|
|
break;
|
|
default:
|
|
qCritical() << "DC Error: wait for printing";
|
|
this->onPrintFinishedERR();
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
void ATBDeviceControllerPlugin::onPrinterPrintNextTemplate()
|
|
{
|
|
// template list must not be empty
|
|
if (this->templateList.isEmpty()) {
|
|
this->onPrintFinishedERR();
|
|
return;
|
|
}
|
|
|
|
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
|
|
QTimer::singleShot(2000, this, SLOT(onPrinterWaitForPrintingTicket()));
|
|
}
|
|
else {
|
|
// print next template
|
|
QTimer::singleShot(2000, this, SLOT(onPrinterPrintNextTemplate()));
|
|
}
|
|
|
|
}
|
|
|
|
/************************************************************************************************
|
|
* private slots, interface to low level hwapi
|
|
*
|
|
*/
|
|
void ATBDeviceControllerPlugin::onPrintFinishedOK()
|
|
{
|
|
// DEBUG
|
|
qCritical() << "ATBDeviceControllerPlugin::onPrintFinishedOK()";
|
|
|
|
emit this->printTicketFinished(nsDeviceControllerInterface::RESULT_STATE::SUCCESS,
|
|
// TODO: TicketNumber
|
|
"",
|
|
"");
|
|
}
|
|
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
|
|
|
|
emit this->printTicketFinished(nsDeviceControllerInterface::RESULT_STATE::ERROR_BACKEND,
|
|
this->errorCode,
|
|
this->errorDescription);
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************************************
|
|
* cash payment
|
|
*/
|
|
void ATBDeviceControllerPlugin::onCashGotCoin()
|
|
{
|
|
// DEBUG
|
|
qCritical() << "ATBDeviceControllerPlugin::onGotCoin()";
|
|
|
|
this->currentCashState = CASH_STATE::CACHE_INPUT;
|
|
|
|
uint32_t amountInt = this->hw->getInsertedAmount();
|
|
|
|
QString amountString = QString::number(amountInt);
|
|
|
|
|
|
emit this->cashInputEvent(nsDeviceControllerInterface::RESULT_STATE::SUCCESS,
|
|
nsDeviceControllerInterface::CASH_STATE::CACHE_INPUT,
|
|
amountString,
|
|
"",
|
|
"");
|
|
}
|
|
|
|
void ATBDeviceControllerPlugin::onCashPayStopByPushbutton()
|
|
{
|
|
// DEBUG
|
|
qCritical() << "ATBDeviceControllerPlugin::onCashPayStopByPushbutton()";
|
|
|
|
// we need new cash value in application...
|
|
QTimer::singleShot(500, this, SLOT(onCashPayStopedSuccess()));
|
|
|
|
}
|
|
|
|
void ATBDeviceControllerPlugin::onCashPayStopByMax()
|
|
{
|
|
// DEBUG
|
|
qCritical() << "ATBDeviceControllerPlugin::onCashVendStopByMax()";
|
|
|
|
// we need new cash value in application...
|
|
QTimer::singleShot(500, this, SLOT(onCashPayStopedSuccess()));
|
|
|
|
}
|
|
|
|
void ATBDeviceControllerPlugin::onCashPayStopByEscrow()
|
|
{
|
|
// DEBUG
|
|
qCritical() << "ATBDeviceControllerPlugin::onCashPayStopByEscrow()";
|
|
|
|
uint32_t amountInt = this->hw->getInsertedAmount();
|
|
|
|
QString amountString = QString::number(amountInt);
|
|
|
|
emit this->cashInputFinished(nsDeviceControllerInterface::RESULT_STATE::ERROR_BACKEND,
|
|
amountString,
|
|
"",
|
|
"",
|
|
"",
|
|
"",
|
|
"");
|
|
}
|
|
|
|
void ATBDeviceControllerPlugin::onCashPayStopByError()
|
|
{
|
|
// DEBUG
|
|
qCritical() << "ATBDeviceControllerPlugin::onCashPayStopByError()";
|
|
|
|
uint32_t amountInt = this->hw->getInsertedAmount();
|
|
|
|
QString amountString = QString::number(amountInt);
|
|
|
|
emit this->cashInputFinished(nsDeviceControllerInterface::RESULT_STATE::ERROR_BACKEND,
|
|
amountString,
|
|
"",
|
|
"",
|
|
"",
|
|
"",
|
|
"");
|
|
}
|
|
|
|
void ATBDeviceControllerPlugin::onCashPayStopByTimeout()
|
|
{
|
|
// DEBUG
|
|
qCritical() << "ATBDeviceControllerPlugin::onCashPayStopByTimeout()";
|
|
|
|
uint32_t amountInt = this->hw->getInsertedAmount();
|
|
|
|
QString amountString = QString::number(amountInt);
|
|
|
|
emit this->cashInputFinished(nsDeviceControllerInterface::RESULT_STATE::ERROR_BACKEND,
|
|
amountString,
|
|
"",
|
|
"",
|
|
"",
|
|
"",
|
|
"");
|
|
}
|
|
|
|
void ATBDeviceControllerPlugin::onCashPayStopedSuccess()
|
|
{
|
|
// DEBUG
|
|
qCritical() << "ATBDeviceControllerPlugin::onCashPayStopedSuccess()";
|
|
|
|
uint32_t amountInt = this->hw->getInsertedAmount();
|
|
|
|
QString amountString = QString::number(amountInt);
|
|
|
|
qCritical() << " insertedAmount (int) = " << amountInt;
|
|
qCritical() << " insertedAmount = " << amountString;
|
|
|
|
emit this->cashInputFinished(nsDeviceControllerInterface::RESULT_STATE::SUCCESS,
|
|
amountString,
|
|
"", // coins
|
|
"", // notes
|
|
"", // change
|
|
"",
|
|
"");
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Load CashAgentLib
|
|
* @brief ATBDeviceControllerPlugin::private_loadCashAgentLib
|
|
* @param pluginName
|
|
* @return
|
|
*/
|
|
bool ATBDeviceControllerPlugin::private_loadCashAgentLib(QString pluginName)
|
|
{
|
|
if (pluginName == "") {
|
|
|
|
// search list for plugin (.so) file:
|
|
QStringList pluginNameList;
|
|
pluginNameList << "/usr/lib/libCAslave.so"
|
|
<< "/usr/lib/libCAmaster.so"
|
|
<< "/usr/lib/libCashAgentLib.so";
|
|
// using C++11 range based loop:
|
|
for (const auto& filename : pluginNameList) {
|
|
if (QFileInfo(filename).isReadable()) {
|
|
pluginName = filename;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (pluginName == "") {
|
|
qCritical() << "ATBDeviceControllerPlugin: CashAgentLib not installed!";
|
|
this->errorCode = "CashAgentLib::NOT_FOUND";
|
|
this->errorDescription = "ERROR: no CashAgentLib: ";
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
if (!QLibrary::isLibrary(pluginName)) {
|
|
qCritical() << "ATBDeviceControllerPlugin: can not load CashAgentLib: " << pluginName;
|
|
this->errorCode = "CashAgentLib::NO_LIBRARY";
|
|
this->errorDescription = "ERROR: can not load CashAgentLib: " + pluginName;
|
|
return false;
|
|
}
|
|
|
|
if (pluginName.contains("slave", Qt::CaseInsensitive)) {
|
|
this->isMaster = false;
|
|
}
|
|
else
|
|
if (pluginName.contains("master", Qt::CaseInsensitive)) {
|
|
this->isMaster = true;
|
|
}
|
|
|
|
QPluginLoader* pluginLoader = new QPluginLoader();
|
|
pluginLoader->setFileName(pluginName);
|
|
|
|
QObject* plugin = pluginLoader->instance();
|
|
if (!pluginLoader->isLoaded()) {
|
|
qCritical() << "ATBDeviceControllerPlugin: can not instantiate CashAgentLib: " << pluginName;
|
|
qCritical() << " error: " << pluginLoader->errorString();
|
|
this->errorCode = "CashAgentLib::NO_INSTANCE";
|
|
this->errorDescription = "ERROR: can not instantiate CashAgentLib: " + pluginName;
|
|
return false;
|
|
}
|
|
|
|
if (plugin == nullptr) {
|
|
qCritical() << "ATBDeviceControllerPlugin: plugin is NULL";
|
|
this->errorCode = "CashAgentLib::INSTANCE_IS_NULL";
|
|
this->errorDescription = "ERROR: CashAgentLib instance is NULL: " + pluginName;
|
|
}
|
|
|
|
qCritical() << "ATBDeviceControllerPlugin: instantiate CashAgentLib: " << pluginName;
|
|
|
|
this->hw = qobject_cast<hwinf*>(plugin);
|
|
|
|
if (this->hw == nullptr) {
|
|
qCritical() << "ATBDeviceControllerPlugin: hw is NULL";
|
|
this->errorCode = "CashAgentLib::HW_IS_NULL";
|
|
this->errorDescription = "ERROR: CashAgentLib object_cast is NULL: " + pluginName;
|
|
return false;
|
|
}
|
|
|
|
qCritical() << "ATBDeviceControllerPlugin: loaded CashAgentLib";
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************************************
|
|
* dbus
|
|
*/
|
|
int ATBDeviceControllerPlugin::init_sc_dbus()
|
|
{
|
|
#if defined (ARCH_PTU4)
|
|
this->dbus = new DBusControllerInterface("eu.atb.ptu", "/systemcontrol", QDBusConnection::systemBus(), 0);
|
|
#elif defined (ARCH_PTU5)
|
|
this->dbus = new DBusControllerInterface("eu.atb.ptu.systemcontrol", "/systemcontrol", QDBusConnection::systemBus(), 0);
|
|
#else
|
|
this->dbus = new DBusControllerInterface("eu.atb.ptu", "/systemcontrol", QDBusConnection::sessionBus(), 0);
|
|
#endif
|
|
if (!dbus->isValid()) {
|
|
QString errorString = QDBusError::errorString(dbus->lastError().type());
|
|
qCritical() << errorString;
|
|
|
|
if (dbus->lastError().isValid()){
|
|
qCritical() << "last error is valid.";
|
|
}
|
|
|
|
qCritical() << "message: " << dbus->lastError().message();
|
|
qCritical() << "SystemController is not valid.";
|
|
return 0;
|
|
}
|
|
|
|
if (!dbus->connection().isConnected()) {
|
|
qCritical() << "SystemController is not connected.";
|
|
return 0;
|
|
}
|
|
|
|
connect(this->dbus, SIGNAL(wokeUpFrom(uchar)), this, SLOT(onWokeUp(uchar)));
|
|
|
|
return 1;
|
|
}
|
|
|
|
void ATBDeviceControllerPlugin::onWokeUp(uchar source)
|
|
{
|
|
if (source == 0x01) {
|
|
// woke up from device controller
|
|
this->diag->diagRequest();
|
|
}
|
|
}
|
|
|
|
|
|
/************************************************************************************************
|
|
* Mandatory plugin methods
|
|
*
|
|
*/
|
|
|
|
PLUGIN_STATE ATBDeviceControllerPlugin::getState()
|
|
{
|
|
return this->pluginState;
|
|
}
|
|
|
|
QString & ATBDeviceControllerPlugin::getLastError()
|
|
{
|
|
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
|