Compare commits

..

8 Commits

10 changed files with 222 additions and 146 deletions

View File

@ -1,7 +1,7 @@
#include "CArun.h"
#include "datei.h"
#include "CCWakelineAbstraction.h"
#include "DigitalOutputAbstraction.h"
CArun::CArun(QObject *parent)
@ -20,7 +20,11 @@ CArun::CArun(QObject *parent)
this->timerChainCtrl->start();
this->ccWakelineAbstraction = new CCWakelineAbstraction(this->HWaccess, this);
this->digitalOutputAbstraction = new DigitalOutputAbstraction(this->HWaccess, this);
this->digitalOutputAbstraction->addCCWake("/sys/class/leds/wakeupctrl_cc/brightness");
this->digitalOutputAbstraction->addCCPower("/run/powerctrl_cc");
this->digitalOutputAbstraction->addCCModem("/run/powerctrl_modem");
}

View File

@ -22,7 +22,7 @@ enum class SETUP_STEP {
};
class CCWakelineAbstraction;
class DigitalOutputAbstraction;
class CArun : public QObject
{
@ -45,7 +45,7 @@ private:
void openSerialPort();
CCWakelineAbstraction* ccWakelineAbstraction;
DigitalOutputAbstraction* digitalOutputAbstraction;
signals:

View File

@ -1,51 +0,0 @@
#include <QFileSystemWatcher>
#include <QFile>
#include <QDebug>
#include "CCWakelineAbstraction.h"
#include "plugin.h"
/**
* this is based on a solution from:
* https://embeddeduse.com/2018/09/18/monitoring-sys-files-qfilesystemwatcher/
*
*/
CCWakelineAbstraction::CCWakelineAbstraction(hwinf *dc, QObject *parent)
: QObject(parent)
, dc(dc)
{
auto ccWakeMonitor = new QFileSystemWatcher(this);
ccWakeMonitor->addPath("/sys/class/leds/wakeupctrl_cc/brightness");
connect(ccWakeMonitor, &QFileSystemWatcher::fileChanged,
this, &CCWakelineAbstraction::ccWakeChanged);
qCritical() << "... init CCWakelineAbstraction";
}
void CCWakelineAbstraction::ccWakeChanged(const QString &path)
{
QFile ccWakeFile(path);
if (!ccWakeFile.open(QIODevice::ReadOnly)) {
qWarning() << "ERROR: Could not open ccWakeFile file.";
return;
}
auto ccWake = ccWakeFile.readAll();
if (!ccWake.isEmpty()) {
int state = ccWake.at(0);
//qCritical() << "INFO: ccWake = " << state;
switch (state) {
case 0x30: // '1'
qCritical() << "INFO: ccWake -> sleep";
this->dc->credit_switchWake(true); // switch 'sleep'
break;
case 0x31: // '0'
qCritical() << "INFO: ccWake -> wake";
this->dc->credit_switchWake(false); // switch 'wake'
break;
}
}
}

View File

@ -1,25 +0,0 @@
#ifndef CCWAKELINEABSTRACTION_H
#define CCWAKELINEABSTRACTION_H
#include <QObject>
class hwinf;
class QFileSystemWatcher;
class CCWakelineAbstraction : public QObject
{
Q_OBJECT
public:
CCWakelineAbstraction(hwinf *dc, QObject *parent = nullptr);
private:
hwinf *dc;
QFileSystemWatcher *ccWakeMonitor;
void ccWakeChanged(const QString &path);
};
#endif // CCWAKELINEABSTRACTION_H

View File

@ -0,0 +1,170 @@
#include <QFileSystemWatcher>
#include <QFile>
#include <QFileInfo>
#include <QTimer>
#include <QDebug>
#include "DigitalOutputAbstraction.h"
#include "plugin.h"
/**
* this is based on a solution from:
* https://embeddeduse.com/2018/09/18/monitoring-sys-files-qfilesystemwatcher/
*
*/
DigitalOutputAbstraction::DigitalOutputAbstraction(hwinf *dc, QObject *parent)
: QObject(parent)
, dc(dc)
{
this->fileMonitor = new QFileSystemWatcher(this);
connect(this->fileMonitor, &QFileSystemWatcher::fileChanged,
this, &DigitalOutputAbstraction::fileChanged);
qCritical() << "... init DigitalOutputAbstraction";
}
bool DigitalOutputAbstraction::addCCWake(const QString file)
{
// on PTU5: "/sys/class/leds/wakeupctrl_cc/brightness"
if (!QFileInfo::exists(file)) {
qCritical() << " ... create file: " << file;
QFile(file).open(QIODevice::ReadWrite | QIODevice::Text);
}
qCritical() << " ... add file: " << file;
this->ccWakePath = file;
return this->fileMonitor->addPath(file);
}
bool DigitalOutputAbstraction::addCCPower(const QString file)
{
if (!QFileInfo::exists(file)) {
qCritical() << " ... create file: " << file;
QFile(file).open(QIODevice::ReadWrite | QIODevice::Text);
}
qCritical() << " ... add file: " << file;
this->ccPowerPath = file;
return this->fileMonitor->addPath(file);
}
bool DigitalOutputAbstraction::addCCModem(const QString file)
{
if (!QFileInfo::exists(file)) {
qCritical() << " ... create file: " << file;
QFile(file).open(QIODevice::ReadWrite | QIODevice::Text);
}
qCritical() << " ... add file: " << file;
this->modemPowerPath = file;
return this->fileMonitor->addPath(file);
}
void DigitalOutputAbstraction::fileChanged(const QString &path)
{
if (path == this->ccPowerPath) this->private_ccPowerChanged();
if (path == this->ccWakePath) this->private_ccWakeChanged();
if (path == this->modemPowerPath) this->private_modemPowerChanged();
}
void DigitalOutputAbstraction::private_modemPowerChanged()
{
QFile modemPowerFile(this->modemPowerPath);
if (!modemPowerFile.open(QIODevice::ReadOnly)) {
qWarning() << "ERROR: Could not open modemPowerFile " << this->modemPowerPath;
return;
}
auto modemPower = modemPowerFile.readAll();
if (!modemPower.isEmpty()) {
int state = modemPower.at(0);
// qCritical() << "INFO: modemPower = " << state;
switch (state) {
case 0x30: // '0'
qCritical() << "INFO: modemPower -> off";
this->dc->mod_switchWake(false);
this->dc->mod_switchPower(false);
break;
case 0x31: // '1'
qCritical() << "INFO: modemPower -> on";
this->dc->mod_switchWake(true);
this->dc->mod_switchPower(true);
break;
}
}
}
void DigitalOutputAbstraction::private_ccPowerChanged()
{
QFile ccPowerFile(this->ccPowerPath);
if (!ccPowerFile.open(QIODevice::ReadOnly)) {
qWarning() << "ERROR: Could not open ccPowerFile file.";
return;
}
auto ccPower = ccPowerFile.readAll();
if (!ccPower.isEmpty()) {
int state = ccPower.at(0);
auto lambdaOn = [this]() -> void
{
this->dc->credit_switchPower(true);
this->dc->credit_switchWake(true);
};
auto lambdaOff = [this]() -> void
{
this->dc->credit_switchPower(false);
this->dc->credit_switchWake(false);
};
//qCritical() << "INFO: ccPower = " << state;
switch (state) {
case 0x30: // '0'
qCritical() << "INFO: ccPower -> off";
lambdaOff();
break;
case 0x31: // '1'
qCritical() << "INFO: ccPower -> on";
lambdaOn();
break;
case 0x32: // '2'
qCritical() << "INFO: ccPower -> on / off";
lambdaOff();
QTimer::singleShot(500, this, lambdaOn);
break;
}
}
}
void DigitalOutputAbstraction::private_ccWakeChanged()
{
QFile ccWakeFile(this->ccWakePath);
if (!ccWakeFile.open(QIODevice::ReadOnly)) {
qWarning() << "ERROR: Could not open ccWakeFile " << this->ccWakePath;
return;
}
auto ccWake = ccWakeFile.readAll();
if (!ccWake.isEmpty()) {
int state = ccWake.at(0);
//qCritical() << "INFO: ccWake = " << state;
switch (state) {
case 0x30: // '0'
qCritical() << "INFO: ccWake -> sleep";
this->dc->credit_switchWake(true); // switch 'sleep'
break;
case 0x31: // '1'
qCritical() << "INFO: ccWake -> wake";
this->dc->credit_switchWake(false); // switch 'wake'
break;
}
}
}

View File

@ -0,0 +1,37 @@
#ifndef DIGITALOUTPUTABSTRACTION_H
#define DIGITALOUTPUTABSTRACTION_H
#include <QObject>
class hwinf;
class QFileSystemWatcher;
class DigitalOutputAbstraction : public QObject
{
Q_OBJECT
public:
DigitalOutputAbstraction(hwinf *dc, QObject *parent = nullptr);
bool addCCWake(const QString file);
bool addCCPower(const QString file);
bool addCCModem(const QString file);
private:
hwinf *dc;
QFileSystemWatcher *fileMonitor;
QString modemPowerPath;
QString ccPowerPath;
QString ccWakePath;
void fileChanged(const QString &path);
void private_modemPowerChanged();
void private_ccPowerChanged();
void private_ccWakeChanged();
};
#endif // DIGITALOUTPUTABSTRACTION_H

View File

@ -40,14 +40,14 @@ DEFINES+=APP_EXTENDED_VERSION=\\\"$$EXTENDED_VERSION\\\"
SOURCES += \
CArun.cpp \
CCWakelineAbstraction.cpp \
DigitalOutputAbstraction.cpp \
main.cpp \
tslib.cpp \
datei.cpp
HEADERS += \
CArun.h \
CCWakelineAbstraction.h \
DigitalOutputAbstraction.h \
guidefs.h \
tslib.h \
versionHistory.txt \

View File

@ -63,8 +63,7 @@ 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
@ -99,7 +98,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;
@ -116,11 +115,7 @@ private:
QSharedMemory *m_sharedMem;
ReportingThread *m_reportingThread;
DownloadThread *m_downloadThread;
QScopedPointer<QFileSystemWatcher> m_fileSystemWatcher;
QString m_watchedFile;
private slots:
void onCCWakeGpioChanged(QString const &file);
//QTimer *hwapi_triggerBL;
public:
explicit hwapi(QObject *parent = nullptr);

View File

@ -1205,7 +1205,7 @@ char T_datif::loadRecDataFromFrame()
uit2=0;
}
if (uit2==3 || uit2==5 || uit2==10 || uit2==20 || uit2==50 || uit2==100 || uit2==200 || uit2==500)
if (uit2==3 || uit2==5 || uit2==10 || uit2==20 || uit2==40 || uit2==50 || uit2==100 || uit2==200 || uit2==500)
{
// valid coin
if ((newInsertedAmount != lastInsertedAmount) || uit2>0 )

View File

@ -15,8 +15,6 @@
#include <cstring>
#include <QThread>
#include <QDebug>
#include <QFileSystemWatcher>
#include <QSettings>
static uint32_t hwapi_lastStartAmount;
@ -37,7 +35,6 @@ 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));
@ -59,21 +56,8 @@ hwapi::hwapi(QObject *parent) : QObject(parent)
#error "SLAVE LIB COMPILED INTO MASTER"
#endif
QSettings settings("/opt/app/ATBAPP/ATBQT.ini", QSettings::IniFormat);
m_watchedFile = settings.value("AsyncPOS_CCPlugin/terminal_watch_file",
"/opt/app/ATBAPP/watch.txt").toString();
m_fileSystemWatcher.reset(new QFileSystemWatcher());
if (!m_fileSystemWatcher->addPath(m_watchedFile)) {
qCritical() << "cannot add path for" << m_watchedFile;
} else {
if (connect(m_fileSystemWatcher.get(), SIGNAL(fileChanged(QString const&)),
this, SLOT(onCCWakeGpioChanged(QString const&)))) {
qCritical() << "connected file watcher with" << m_watchedFile;
}
}
myDatif = new T_datif(this); // für die CAslave-Lib auskommentieren!
#endif
#ifdef THIS_IS_CA_SLAVE
@ -136,44 +120,6 @@ hwapi::hwapi(QObject *parent) : QObject(parent)
connect(runProcess, SIGNAL(runProc_coinAttached()), this, SLOT(coinAttached()));
}
void hwapi::onCCWakeGpioChanged(QString const &fileName) {
if (fileName == m_watchedFile) {
QFile f(m_watchedFile);
if (f.open(QFile::ReadOnly | QFile::Text)) {
QTextStream stream(&f);
QString const &content = stream.readAll();
if (content.startsWith("0")) {
qCritical() << __func__ << ":" << __LINE__ << "switching terminal off...";
mod_switchWake(false);
mod_switchPower(false);
f.close();
f.setFileName(m_watchedFile);
// to turn off cc-terminal, the content must be "0"
if (f.open(QFile::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
QTextStream s(&f);
s << "switching terminal off";
}
} else
if (content.startsWith("1")) {
qCritical() << __func__ << ":" << __LINE__ << "switching terminal on...";
mod_switchPower(true);
mod_switchWake(true);
f.close();
f.setFileName(m_watchedFile);
// to turn on cc-terminal, the content must be "1"
if (f.open(QFile::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
QTextStream s(&f);
s << "switching terminal on";
}
} else {
qCritical() << "watched file contained" << content;
}
}
} else {
qCritical() << "ERROR watching the wrong file" << fileName;
}
}
void hwapi::hwapi_slotPayProc(void)
{