Compare commits

...

10 Commits

Author SHA1 Message Date
1897e8237a
Add watcher for switching on/off modem 2024-11-13 15:02:14 +01:00
d5693cb2b1
Merge branch 'master' into palanga-switch-terminal-on-off 2024-11-13 14:18:45 +01:00
d3b1046a9f onCCWakeGpioChanged():
Use commands credit_switchWake/switchPower to reboot cc-terminal.
2024-11-13 13:28:04 +01:00
a98ddbdb85 Changed file name to check for cc-terminal rebbot to /run/powerctrl_cc. 2024-11-13 13:27:13 +01:00
91a0f88cd9 hwapi::onCCWakeGpioChanged():
when switching cc-terminal off, send 0 to watch-file (watched by a
	filesystem watcher).
	when switching cc-terminal on, send 1 to watch-file (watched by a
	filesystem watcher).
2024-11-11 16:20:15 +01:00
c31b38917a Use QSettings to get watch.txt file path.
onCCWakeGpioChanged():

	remove obsolete code.
2024-11-08 12:06:19 +01:00
fe1351fcca switching on/off modem seems to be enough 2024-11-07 16:09:20 +01:00
c337b6e50e hwapi::onCCWakeGpioChanged():
start implementation of slot for fileSystemWatcher.
	Seems to be enough to start only the modem, as the cc-terminal
	is connected to the modem.
2024-11-07 14:14:58 +01:00
821a6e63bf Connect fileSystemWatcher. 2024-11-07 14:14:25 +01:00
73b2dec85e Added fileSystemWatcher to check if cc-terminal has to switched on/off. 2024-11-07 14:12:02 +01:00
2 changed files with 88 additions and 4 deletions

View File

@ -63,7 +63,8 @@ V4.0 6.9.2023: activating DC-Bootloader in slve-lib (SM)
#include "shared_mem_buffer.h"
#include "runProc.h"
#include "interfaces.h"
#include <QScopedPointer>
#include <QFileSystemWatcher>
/*
* select Plugin Type here
@ -98,7 +99,7 @@ V4.0 6.9.2023: activating DC-Bootloader in slve-lib (SM)
//#define THIS_IS_CA_MASTER
class QFileSystemWatcher;
class QSharedMemory;
class DownloadThread;
class ReportingThread;
@ -115,7 +116,13 @@ private:
QSharedMemory *m_sharedMem;
ReportingThread *m_reportingThread;
DownloadThread *m_downloadThread;
//QTimer *hwapi_triggerBL;
QScopedPointer<QFileSystemWatcher> m_fileSystemWatcher;
QString m_powerctrl_cc;
QString m_powerctrl_modem;
private slots:
void onCCWakeGpioChanged(QString const &file);
public:
explicit hwapi(QObject *parent = nullptr);

View File

@ -15,6 +15,8 @@
#include <cstring>
#include <QThread>
#include <QDebug>
#include <QFileSystemWatcher>
#include <QSettings>
static uint32_t hwapi_lastStartAmount;
@ -35,6 +37,7 @@ hwapi::hwapi(QObject *parent) : QObject(parent)
qCritical() << " hwapi::hwapi() APP_EXTENDED_VERSION:" << APP_EXTENDED_VERSION;
qCritical() << "hwapi::hwapi() APP_EXTENDED_VERSION_LIB:" << APP_EXTENDED_VERSION_LIB;
m_fileSystemWatcher.reset();
// create or attach shared memory segment
m_sharedMem = SharedMem::getShm(sizeof(SharedMem));
@ -56,8 +59,26 @@ hwapi::hwapi(QObject *parent) : QObject(parent)
#error "SLAVE LIB COMPILED INTO MASTER"
#endif
myDatif = new T_datif(this); // für die CAslave-Lib auskommentieren!
QSettings settings("/opt/app/ATBAPP/ATBQT.ini", QSettings::IniFormat);
m_powerctrl_cc = settings.value("AsyncPOS_CCPlugin/terminal_watch_file",
"/run/powerctrl_cc").toString();
m_fileSystemWatcher.reset(new QFileSystemWatcher());
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_powerctrl_cc;
}
}
myDatif = new T_datif(this); // für die CAslave-Lib auskommentieren!
#endif
#ifdef THIS_IS_CA_SLAVE
@ -120,6 +141,62 @@ hwapi::hwapi(QObject *parent) : QObject(parent)
connect(runProcess, SIGNAL(runProc_coinAttached()), this, SLOT(coinAttached()));
}
void hwapi::onCCWakeGpioChanged(QString const &fileName) {
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();
if (content.startsWith("0")) {
qCritical() << __func__ << ":" << __LINE__ << "switching cc-terminal off...";
credit_switchWake(false);
credit_switchPower(false);
} else
if (content.startsWith("1")) {
qCritical() << __func__ << ":" << __LINE__ << "switching cc-terminal on...";
credit_switchPower(true);
credit_switchWake(true);
} else
if (content.startsWith("2")) {
qCritical() << __func__ << ":" << __LINE__ << "switching cc-terminal off and on...";
credit_switchWake(false);
credit_switchPower(false);
QThread::sleep(1);
credit_switchPower(true);
credit_switchWake(true);
} else {
qCritical() << "switching cc-terminal watched file contained" << content;
QFile::resize(m_powerctrl_cc, 0); // empty file
}
}
}
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;
}
}
void hwapi::hwapi_slotPayProc(void)
{