Add class PTUSystem

This commit is contained in:
Siegfried Siegert 2023-08-03 09:09:42 +02:00
parent acb1941d94
commit 8c2d764698
Signed by: SiegfriedSiegert
GPG Key ID: 68371E015E8F0B03
3 changed files with 137 additions and 2 deletions

View File

@ -78,7 +78,8 @@ HEADERS += \
src/ATBAPP/ATBDeviceControllerPlugin.h \ src/ATBAPP/ATBDeviceControllerPlugin.h \
src/ATBAPP/Utils.h \ src/ATBAPP/Utils.h \
src/ATBAPP/support/DBusControllerInterface.h \ src/ATBAPP/support/DBusControllerInterface.h \
src/ATBAPP/support/JSON.h src/ATBAPP/support/JSON.h \
src/ATBAPP/support/PTUSystem.h
SOURCES += \ SOURCES += \
src/ATBAPP/ATBHealthEvent.cpp \ src/ATBAPP/ATBHealthEvent.cpp \
@ -87,7 +88,8 @@ SOURCES += \
src/ATBAPP/DeviceControllerDiag.cpp \ src/ATBAPP/DeviceControllerDiag.cpp \
src/ATBAPP/Utils.cpp \ src/ATBAPP/Utils.cpp \
src/ATBAPP/support/DBusControllerInterface.cpp \ src/ATBAPP/support/DBusControllerInterface.cpp \
src/ATBAPP/support/JSON.cpp src/ATBAPP/support/JSON.cpp \
src/ATBAPP/support/PTUSystem.cpp
DISTFILES += \ DISTFILES += \
generate-version.sh generate-version.sh

View File

@ -0,0 +1,109 @@
#include "PTUSystem.h"
#include <QDebug>
#include <QDir>
#include <QFileInfo>
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<quint16>(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<quint16>(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<quint16>(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<quint16>(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;
}

View File

@ -0,0 +1,24 @@
#ifndef PTUSYSTEM_H
#define PTUSYSTEM_H
#include <QObject>
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