diff --git a/DCPlugin.pro b/DCPlugin.pro index f07f685..4379416 100644 --- a/DCPlugin.pro +++ b/DCPlugin.pro @@ -78,7 +78,8 @@ HEADERS += \ src/ATBAPP/ATBDeviceControllerPlugin.h \ src/ATBAPP/Utils.h \ src/ATBAPP/support/DBusControllerInterface.h \ - src/ATBAPP/support/JSON.h + src/ATBAPP/support/JSON.h \ + src/ATBAPP/support/PTUSystem.h SOURCES += \ src/ATBAPP/ATBHealthEvent.cpp \ @@ -87,7 +88,8 @@ SOURCES += \ src/ATBAPP/DeviceControllerDiag.cpp \ src/ATBAPP/Utils.cpp \ src/ATBAPP/support/DBusControllerInterface.cpp \ - src/ATBAPP/support/JSON.cpp + src/ATBAPP/support/JSON.cpp \ + src/ATBAPP/support/PTUSystem.cpp DISTFILES += \ generate-version.sh diff --git a/src/ATBAPP/support/PTUSystem.cpp b/src/ATBAPP/support/PTUSystem.cpp new file mode 100644 index 0000000..200e4ad --- /dev/null +++ b/src/ATBAPP/support/PTUSystem.cpp @@ -0,0 +1,109 @@ +#include "PTUSystem.h" + +#include +#include +#include + + +PTUSystem::PTUSystem(QObject *parent) : QObject(parent) +{ + +} + + + + +quint16 PTUSystem::readCustomerNumber() +{ + QString resultFilename; + QStringList fileNameList; + fileNameList << "/mnt/system_data/cust_nr" + << "/etc/cust_nr"; + for (const auto& filename : fileNameList) { + if (QFileInfo(filename).isReadable()) { + resultFilename = filename; + break; + } + } + + QString resultString = PTUSystem::readConfigString(resultFilename); + return static_cast(resultString.toInt()); +} + +quint16 PTUSystem::readMachineNumber() +{ + QString resultFilename; + QStringList fileNameList; + fileNameList << "/mnt/system_data/machine_nr" + << "/etc/machine_nr"; + for (const auto& filename : fileNameList) { + if (QFileInfo(filename).isReadable()) { + resultFilename = filename; + break; + } + } + + QString resultString = PTUSystem::readConfigString(resultFilename); + return static_cast(resultString.toInt()); +} + +quint16 PTUSystem::readZoneNumber() +{ + QString resultFilename; + QStringList fileNameList; + fileNameList << "/mnt/system_data/zone_nr" + << "/etc/zone_nr"; + for (const auto& filename : fileNameList) { + if (QFileInfo(filename).isReadable()) { + resultFilename = filename; + break; + } + } + + QString resultString = PTUSystem::readConfigString(resultFilename); + return static_cast(resultString.toInt()); +} + +quint16 PTUSystem::readGroupNumber() +{ + QString resultFilename; + QStringList fileNameList; + fileNameList << "/mnt/system_data/group_nr" + << "/etc/group_nr"; + for (const auto& filename : fileNameList) { + if (QFileInfo(filename).isReadable()) { + resultFilename = filename; + break; + } + } + + QString resultString = PTUSystem::readConfigString(resultFilename); + return static_cast(resultString.toInt()); +} + + +QString PTUSystem::readConfigString(const QString & filename) +{ + QFileInfo fileinfo(filename); + + if (! fileinfo.isReadable() ) { + qDebug() << "PTUSystem::readConfigString(): \"" << filename << "\" is not readable"; + return ""; + } + + QFile file(filename); + + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + qDebug() << "PTUSystem::readConfigString() cannot open file: " << filename; + return ""; + } + + QTextStream in(&file); + + QString stringValue = in.readLine(100); + qDebug() << "PTUSystem::readConfigString() stringValue = " << stringValue; + + file.close(); + + return stringValue; +} diff --git a/src/ATBAPP/support/PTUSystem.h b/src/ATBAPP/support/PTUSystem.h new file mode 100644 index 0000000..336eec1 --- /dev/null +++ b/src/ATBAPP/support/PTUSystem.h @@ -0,0 +1,24 @@ +#ifndef PTUSYSTEM_H +#define PTUSYSTEM_H + +#include + +class PTUSystem : public QObject +{ + Q_OBJECT +public: + explicit PTUSystem(QObject *parent = nullptr); + + static quint16 readCustomerNumber(); + static quint16 readMachineNumber(); + static quint16 readZoneNumber(); + static quint16 readGroupNumber(); + +private: + static QString readConfigString(const QString & filename); + +signals: + +}; + +#endif // PTUSYSTEM_H