Hotwheels-Cluster 1.2
Creation of Cluster APP for SEA:ME project.
 
Loading...
Searching...
No Matches
SystemInfoProvider.cpp
Go to the documentation of this file.
1
14
16#include <QDebug>
18
26 : m_executor(executor ? executor : new SystemCommandExecutor())
27 , m_ownExecutor(executor == nullptr)
28{}
29
30
39
49QString SystemInfoProvider::getWifiStatus(QString &wifiName) const
50{
51 QString output = m_executor->executeCommand("nmcli -t -f DEVICE,STATE,CONNECTION dev");
52 QStringList lines = output.split('\n');
53
54 for (const QString &line : lines) {
55 if (line.startsWith("wlan")) {
56 QStringList parts = line.split(':');
57 if (parts.size() >= 3) {
58 wifiName = parts[2];
59 return (parts[1] == "connected") ? "Connected" : "Disconnected";
60 }
61 }
62 }
63 wifiName.clear();
64 return "No interface detected";
65}
66
67
74{
75 QString tempStr = m_executor->readFile("/sys/class/hwmon/hwmon0/temp1_input").trimmed();
76
77 bool ok;
78 double tempMillidegrees = tempStr.toDouble(&ok);
79 return ok ? QString("%1°C").arg(tempMillidegrees / 1000.0, 0, 'f', 1) : "N/A";
80}
81
86
88{
89 QString output = m_executor->executeCommand(
90 "sh -c \"ip -4 addr show wlan0 | grep -oP '(?<=inet\\s)\\d+\\.\\d+\\.\\d+\\.\\d+'\"");
91
92 return output.trimmed().isEmpty() ? "No IP address" : output.trimmed();
93}
Definition of the SystemCommandExecutor class.
Definition of the SystemInfoProvider class.
Interface for executing system commands and reading files.
Class that executes system commands and reads files.
~SystemInfoProvider() override
Destructor for the SystemInfoProvider class.
QString getWifiStatus(QString &wifiName) const override
Gets the current WiFi status.
ISystemCommandExecutor * m_executor
QString getIpAddress() const override
Gets the current IP address of the WiFi interface.
SystemInfoProvider(ISystemCommandExecutor *executor=nullptr)
Constructor for the SystemInfoProvider class.
QString getTemperature() const override
Gets the current temperature in degrees Celsius.