Add class PTUSystem
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										109
									
								
								src/ATBAPP/support/PTUSystem.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										109
									
								
								src/ATBAPP/support/PTUSystem.cpp
									
									
									
									
									
										Normal 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;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										24
									
								
								src/ATBAPP/support/PTUSystem.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								src/ATBAPP/support/PTUSystem.h
									
									
									
									
									
										Normal 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
 | 
			
		||||
		Reference in New Issue
	
	Block a user