diff --git a/DCPlugin.pro b/DCPlugin.pro index 412637f..e97d14f 100644 --- a/DCPlugin.pro +++ b/DCPlugin.pro @@ -80,7 +80,8 @@ HEADERS += \ src/ATBAPP/support/CashUtils.h \ src/ATBAPP/support/DBusControllerInterface.h \ src/ATBAPP/support/JSON.h \ - src/ATBAPP/support/PTUSystem.h + src/ATBAPP/support/PTUSystem.h \ + src/ATBAPP/support/PersistentData.h SOURCES += \ src/ATBAPP/ATBHealthEvent.cpp \ @@ -91,7 +92,8 @@ SOURCES += \ src/ATBAPP/support/CashUtils.cpp \ src/ATBAPP/support/DBusControllerInterface.cpp \ src/ATBAPP/support/JSON.cpp \ - src/ATBAPP/support/PTUSystem.cpp + src/ATBAPP/support/PTUSystem.cpp \ + src/ATBAPP/support/PersistentData.cpp DISTFILES += \ generate-version.sh diff --git a/src/ATBAPP/ATBDeviceControllerPlugin.cpp b/src/ATBAPP/ATBDeviceControllerPlugin.cpp index 706b984..6e0fcc8 100644 --- a/src/ATBAPP/ATBDeviceControllerPlugin.cpp +++ b/src/ATBAPP/ATBDeviceControllerPlugin.cpp @@ -60,11 +60,12 @@ ATBDeviceControllerPlugin::ATBDeviceControllerPlugin(QObject *parent) dynamic_cast(hw)->moveToThread(hwThread); hwThread->start(); + QString persistentDataFile = "/mnt/system_data/dc_persistentData.dat"; + this->persistentData = new PersistentData(persistentDataFile); - this->diag = new DeviceControllerDiag(this); + this->diag = new DeviceControllerDiag(this->persistentData, this); connect(this->diag, &DeviceControllerDiag::newVoltage, this, &ATBDeviceControllerPlugin::onNewVoltage); - this->currentSelectedTicketType = 0; this->currentCashState = CASH_STATE::CACHE_EMPTY; @@ -101,6 +102,11 @@ PLUGIN_STATE ATBDeviceControllerPlugin::initDCPlugin(QObject *eventReceiver, con // this is necessary to init the CashAgentLib (!) hw->vend_failed(); + // read sw-version and store it in persistentData, if changed + QString dc_fw_version = hw->dc_getSWversion(); + qCritical() << "ATBDeviceControllerPlugin: DC firmware version: " << dc_fw_version; + this->persistentData->setDCFirmwareVersion(dc_fw_version); + this->persistentData->serializeToFile(); // text encoding for printer this->codec = QTextCodec::codecForName(printerEncoding); @@ -141,6 +147,10 @@ void ATBDeviceControllerPlugin::startPhysicalLayer() void ATBDeviceControllerPlugin::stopPhysicalLayer() { + // store persistent data + this->persistentData->serializeToFile(); + + // skip, if we use slave lib if (!this->isMaster) return; if (this->pluginState == PLUGIN_STATE::NOT_INITIALIZED) diff --git a/src/ATBAPP/ATBDeviceControllerPlugin.h b/src/ATBAPP/ATBDeviceControllerPlugin.h index e3f39f6..34c7a70 100644 --- a/src/ATBAPP/ATBDeviceControllerPlugin.h +++ b/src/ATBAPP/ATBDeviceControllerPlugin.h @@ -10,7 +10,7 @@ #include "version.h" - +#include "support/PersistentData.h" #include "interfaces.h" @@ -112,6 +112,8 @@ private: DeviceControllerDiag* diag; + PersistentData *persistentData; + uint32_t cashStartAmountInt; diff --git a/src/ATBAPP/DeviceControllerDiag.cpp b/src/ATBAPP/DeviceControllerDiag.cpp index 3d801db..c94f691 100644 --- a/src/ATBAPP/DeviceControllerDiag.cpp +++ b/src/ATBAPP/DeviceControllerDiag.cpp @@ -5,13 +5,14 @@ #include #include -DeviceControllerDiag::DeviceControllerDiag(QObject *parent) +DeviceControllerDiag::DeviceControllerDiag(PersistentData *pData, QObject *parent) : QObject(parent) , coinProcessorType(nsDeviceControllerInterface::COIN_PROCESSOR::ESCROW) , billAcceptor(nsDeviceControllerInterface::BILL_ACCEPTOR::NO) , eventReceiver(nullptr) , isRequestRunning(false) , flagInterruptDiag(false) + , pData(pData) { diagRequestTimeoutTimer = new QTimer(this); diagRequestTimeoutTimer->setInterval(1000*20); // 20s @@ -42,6 +43,12 @@ void DeviceControllerDiag::diagRequest() this->diagRequestTimeoutTimer->start(); this->private_startDiag(); + + // read dc-fw-version: + QString dc_fw_version = hw->dc_getSWversion(); + qCritical() << "ATBDeviceControllerPlugin: DC firmware version: " << dc_fw_version; + this->pData->setDCFirmwareVersion(dc_fw_version); + this->pData->serializeToFile(); } diff --git a/src/ATBAPP/DeviceControllerDiag.h b/src/ATBAPP/DeviceControllerDiag.h index cf9ad69..ca75983 100644 --- a/src/ATBAPP/DeviceControllerDiag.h +++ b/src/ATBAPP/DeviceControllerDiag.h @@ -9,6 +9,8 @@ #include "interfaces.h" #include "DeviceControllerInterface.h" +#include "support/PersistentData.h" + namespace DeviceController { Q_NAMESPACE @@ -60,7 +62,7 @@ class DeviceControllerDiag : public QObject Q_OBJECT public: - DeviceControllerDiag(QObject *parent = nullptr); + DeviceControllerDiag(PersistentData *pData, QObject *parent = nullptr); void init(hwinf* hw, QObject* eventReceiver); @@ -90,7 +92,7 @@ private: QSet machineEventSet; - + PersistentData* pData; private slots: void onDiagRequestTimeoutTimerTimeout(); diff --git a/src/ATBAPP/support/PersistentData.cpp b/src/ATBAPP/support/PersistentData.cpp new file mode 100644 index 0000000..05f2a67 --- /dev/null +++ b/src/ATBAPP/support/PersistentData.cpp @@ -0,0 +1,137 @@ +#include "PersistentData.h" + +#include +#include +#include +#include +#include +#include + +PersistentData::PersistentData(const QString &datafileName, QObject *parent) + : QObject(parent) + , isChangedFlag(false) +{ + // load persistant data, if available + this->filename = datafileName; + + QFileInfo dataFileInfo(this->filename); + QString dataFilePath = dataFileInfo.path(); + + QDir dir; + if ( ! dir.exists(dataFilePath)) { + qCritical() << "Persistent data file does not exist!"; + qCritical() << " --> create new: " << this->filename; + dir.mkpath(dataFilePath); + } + + this->read(); +} + + +void PersistentData::serializeToFile() +{ + this->save(); +} + +void PersistentData::save() +{ + QFile fileOut(this->filename); + if (fileOut.open(QIODevice::WriteOnly)) + { + QDataStream out(&fileOut); + out.setVersion(QDataStream::Qt_4_6); + + out << this->hash; + fileOut.flush(); + fileOut.close(); + } +} + +void PersistentData::read() +{ + QFile fileIn(this->filename); + if (fileIn.open(QIODevice::ReadOnly)) + { + QDataStream in(&fileIn); + in.setVersion(QDataStream::Qt_4_6); + + in >> hash; + + fileIn.close(); + } +} + + + +QVariant PersistentData::getParameter(const QString & key) const { +#if defined (ARCH_DesktopLinux) + // note: QVariant.toString() returns empty string for custom types + qDebug() << "VendingData::getParameter() key = " << key << " value = " << hash.value(key).toString(); +#endif + return hash.value(key); +} + +QVariant PersistentData::getParameter(const QString & key) +{ + #if defined (ARCH_DesktopLinux) + // note: QVariant.toString() returns empty string for custom types + qDebug() << "VendingData::getParameter() key = " << key << " value = " << hash.value(key).toString(); + #endif + + return hash.value(key); +} + +void PersistentData::setParameter(const QString & key, QVariant value) +{ + this->isChangedFlag = true; + + #if defined (ARCH_DesktopLinux) + // note: QVariant.toString() returns empty string for custom types + qDebug() << "VendingData::setParameter() key = " << key << " value = " << value.toString(); + #endif + + this->hash.insert(key, value); +} + +void PersistentData::clearParameter(const QString & key) +{ + this->isChangedFlag = true; + this->hash.remove(key); +} + +bool PersistentData::hasParameter(const QString & key) const +{ + return hash.contains(key); +} + + +uint PersistentData::getUintParameter(const QString & key) const +{ + qDebug() << "PersistentData::getUintParameter() key = " << key << " value = " << hash.value(key).toString(); + + uint returnValue = 0; + bool ok; + + returnValue = hash.value(key).toString().toUInt(&ok); + if (!ok) returnValue = 0; + + return returnValue; +} + +QList PersistentData::uniqueKeys() const { + return hash.uniqueKeys(); +} + + +void PersistentData::setDCFirmwareVersion(const QString & fw_version) +{ + if (this->hash["dc_fw_version"].toString() != fw_version) { + this->isChangedFlag = true; + this->hash.insert("dc_fw_version", fw_version); + } +} + +QString PersistentData::getDCFirmwareVersion() +{ + return this->hash["dc_fw_version"].toString(); +} diff --git a/src/ATBAPP/support/PersistentData.h b/src/ATBAPP/support/PersistentData.h new file mode 100644 index 0000000..a2ed769 --- /dev/null +++ b/src/ATBAPP/support/PersistentData.h @@ -0,0 +1,49 @@ +#ifndef PERSISTENTDATA_H +#define PERSISTENTDATA_H + +#include +#include +#include +#include +#include + +class PersistentData : public QObject +{ + Q_OBJECT +public: + explicit PersistentData(const QString &datafileName, QObject *parent = nullptr); + + void setDCFirmwareVersion(const QString & fw_version); + QString getDCFirmwareVersion(); + + + QVariant getParameter(const QString & key); + QVariant getParameter(const QString & key) const; + void setParameter(const QString & key, QVariant value); + void clearParameter(const QString & key); + bool hasParameter(const QString & key) const; + + uint getUintParameter(const QString & key) const; + QList uniqueKeys() const; + + +public slots: + void serializeToFile(); + +signals: + + +private: + QHash hash; + + QString dc_fw_version; + + QString filename; + + void save(); + void read(); + + bool isChangedFlag; +}; + +#endif // PERSISTENTDATA_H