Add watcher for switching on/off modem

This commit is contained in:
Siegfried Siegert 2024-11-13 15:02:14 +01:00
parent d5693cb2b1
commit 1897e8237a
Signed by untrusted user: SiegfriedSiegert
GPG Key ID: 68371E015E8F0B03
2 changed files with 40 additions and 11 deletions

View File

@ -117,7 +117,9 @@ private:
ReportingThread *m_reportingThread;
DownloadThread *m_downloadThread;
QScopedPointer<QFileSystemWatcher> m_fileSystemWatcher;
QString m_watchedFile;
QString m_powerctrl_cc;
QString m_powerctrl_modem;
private slots:
void onCCWakeGpioChanged(QString const &file);

View File

@ -60,16 +60,21 @@ hwapi::hwapi(QObject *parent) : QObject(parent)
#endif
QSettings settings("/opt/app/ATBAPP/ATBQT.ini", QSettings::IniFormat);
m_watchedFile = settings.value("AsyncPOS_CCPlugin/terminal_watch_file",
m_powerctrl_cc = settings.value("AsyncPOS_CCPlugin/terminal_watch_file",
"/run/powerctrl_cc").toString();
m_fileSystemWatcher.reset(new QFileSystemWatcher());
if (!m_fileSystemWatcher->addPath(m_watchedFile)) {
qCritical() << "cannot add path for" << m_watchedFile;
m_powerctrl_modem = "/run/powerctrl_modem";
m_fileSystemWatcher->addPath(m_powerctrl_modem);
if (!m_fileSystemWatcher->addPath(m_powerctrl_cc)) {
qCritical() << "cannot add path for" << m_powerctrl_cc;
} else {
if (connect(m_fileSystemWatcher.get(), SIGNAL(fileChanged(QString const&)),
this, SLOT(onCCWakeGpioChanged(QString const&)))) {
qCritical() << "connected file watcher with" << m_watchedFile;
qCritical() << "connected file watcher with" << m_powerctrl_cc;
}
}
@ -137,9 +142,12 @@ hwapi::hwapi(QObject *parent) : QObject(parent)
}
void hwapi::onCCWakeGpioChanged(QString const &fileName) {
if (fileName == m_watchedFile) {
qCritical() << __func__ << ":" << __LINE__ << " " << m_watchedFile;
QFile f(m_watchedFile);
qCritical() << __func__ << ":" << __LINE__ << fileName;
if (fileName == m_powerctrl_cc) {
QFile f(m_powerctrl_cc);
if (f.exists() && f.open(QFile::ReadOnly | QFile::Text)) {
QTextStream stream(&f);
QString const &content = stream.readAll();
@ -162,11 +170,30 @@ void hwapi::onCCWakeGpioChanged(QString const &fileName) {
credit_switchWake(true);
} else {
qCritical() << "switching cc-terminal watched file contained" << content;
QFile::resize(m_watchedFile, 0); // empty file
QFile::resize(m_powerctrl_cc, 0); // empty file
}
}
} else {
qCritical() << "ERROR watching the wrong file" << fileName << m_watchedFile;
}
else if (fileName == m_powerctrl_modem) {
QFile f(m_powerctrl_modem);
if (f.exists() && f.open(QFile::ReadOnly | QFile::Text)) {
QTextStream stream(&f);
QString const &content = stream.readAll();
if (content.startsWith("0")) {
qCritical() << __func__ << ":" << __LINE__ << "switching modem off...";
mod_switchWake(false);
mod_switchPower(false);
} else
if (content.startsWith("1")) {
qCritical() << __func__ << ":" << __LINE__ << "switching modem on...";
mod_switchWake(true);
mod_switchPower(true);
}
}
}
else {
qCritical() << "ERROR watching the wrong file" << fileName << m_powerctrl_cc;
}
}