From c902bd9a54f9a8bd8ce9bb3de5f3ee81aae86cdf Mon Sep 17 00:00:00 2001 From: Siegfried Siegert Date: Sat, 2 Mar 2024 08:36:06 +0100 Subject: [PATCH] Proposal: remove Widgets --- dCArun/CArun.cpp | 199 ++++++++++++++++++++++++++++++++++++++++++++++ dCArun/CArun.h | 42 ++++++++++ dCArun/dCArun.pro | 2 + dCArun/main.cpp | 24 +++--- 4 files changed, 252 insertions(+), 15 deletions(-) create mode 100644 dCArun/CArun.cpp create mode 100644 dCArun/CArun.h diff --git a/dCArun/CArun.cpp b/dCArun/CArun.cpp new file mode 100644 index 0000000..1d6287c --- /dev/null +++ b/dCArun/CArun.cpp @@ -0,0 +1,199 @@ +#include "CArun.h" + +#include "datei.h" + + +#define UPDATE_PERIOD_MS 100 + // period to call chain steps + +#define VENDINGTIMEOUT_MS 30000 + + + +CArun::CArun(QObject *parent) + : QObject{parent} +{ + loadPlugIn(1); + + timerChainCtrl = new QTimer(this); + connect(timerChainCtrl, SIGNAL(timeout()), this, SLOT(chainControl())); + timerChainCtrl->setSingleShot(0); + timerChainCtrl->start(UPDATE_PERIOD_MS); // 1000: call every 1000ms +} + + +char CArun::loadPlugIn(char lade1_entlade2) +{ + plugInDir.cd("plugins"); + QPluginLoader *pluginLoader = new QPluginLoader(); + + pluginLoader->setFileName("/usr/lib/libCAmaster.so"); // for ptu5 + + if (lade1_entlade2==2) + { + pluginLoader->unload(); + return 0; + } + + if (!pluginLoader->load()) + { + qDebug()<<"cannot load plugin"; + } else + qDebug() <<"loaded plugin: " << pluginLoader->fileName(); + + if (!pluginLoader->isLoaded()) + { + qDebug()<errorString(); + return 0; + } + + QObject *plugin = pluginLoader->instance(); + if ( plugin == nullptr) + { + // make instance of the root component (which can hold more then one clases) + // also loads the lib if not yet done + qDebug()<<"cannot start instance"; + return 0; + } + + HWaccess= qobject_cast(plugin); + // make instance to class "hwinf" in dll_HWapi.h over "interfaces.h" + + qDebug()<<"loadPlugIn, HWAccess: " << HWaccess; + return 0; +} + + + +void CArun::chainControl(void) +{ + #define FILENAME_COMPORT "../comport.csv" // TODO: use absolute path + // use settings (ini-file) + + QString bs, cn; + int br, ci; + + + // load and use last settings: -------------------- + QByteArray myBA; + myBA=datei_readFromFile(FILENAME_COMPORT); + if (myBA.length()>0) + { + bs=csv_getEntryAsString(myBA,0); // read the 's' war 2!?? + br=csv_getEntryAsInt(myBA,1); // z.B. 5 (5.Eintrag in der Baud-Liste) + bs=csv_getEntryAsString(myBA,2); // z.B 115200 + cn=csv_getEntryAsString(myBA,3); // z.B. COM9 + ci=csv_getEntryAsInt(myBA,4); // Eintragsnummer in COM-Fenster + HWaccess->dc_openSerial(br,bs,cn,1); + } else + { + // vermutlich wird dies hier ausgeführt, weil eine csv-Datei wird nicht installiert + + // open with default settings + qDebug()<<"CArunGui: open serial with default values"; + + bs="115200"; + br=5; + //cn="COM14"; // Windows + cn="ttymxc2"; // PTU5 + ci=2; + HWaccess->dc_openSerial(br,bs,cn,1); + } + + // TIMER myTO: hat keinen timeout-slot! + // wird nur verwendet, um isActive() abzufragen, d.h. ~x zu warten + + // pruefen, of Port nach x s open: + if (HWaccess->dc_isPortOpen()) + { + + } else + { + // wenn nicht: step 6 + } + myTO->start(100); + } + } else + + if (myStep==2) + { + if (!myTO->isActive()) + { + HWaccess->dc_requTestResponse(); + myStep++; + myTO->start(100); + } + } else + + if (myStep==3) + { + if (!myTO->isActive()) + { + if (HWaccess->dc_readAnswTestResponse()) + myStep++; // response was correct + else + { + myStep=6; // 13.12.23: start Autoconnect cycle + qDebug()<<"CArunGui: got no answer from DC, retry.."; + } + myTO->start(100); + } + + } else + + if (myStep==4) + { + HWaccess->dc_autoRequest(1); + AutSendButton->setChecked(true); // taste "druecken" + myStep++; + myTO->start(2000); + } else + + if (myStep==5) + { + if (!myTO->isActive()) + { + if (HWaccess->sys_areDCdataValid()) + { + qDebug()<<"CArunGui: DC is connected"; + myStep=7; // OK, connection is up and running + } else + { + qDebug()<<"CArunGui: auto request is not running, retry..."; + myStep++; + myTO->start(100); + } + } + + } else + + if (myStep==6) + { + // restart autoconnect cycle + myTO->start(100); // restart + myStep=0; + } else + + if (myStep==7) + { + // stay here, DC connection is up and running + + + } else + { + + } + + if (myNextStep) + { + *nextScreen=myNextStep; + myNextStep=0; + } + return false; + + + + +} + + diff --git a/dCArun/CArun.h b/dCArun/CArun.h new file mode 100644 index 0000000..f9d031e --- /dev/null +++ b/dCArun/CArun.h @@ -0,0 +1,42 @@ +#ifndef CARUN_H +#define CARUN_H + +#include +#include +#include +#include + +#include +#include +#include "plugin.h" +#include "stepList.h" +//#include "stepList.h" // define all working chain steps here + + +class CArun : public QObject +{ + Q_OBJECT + +public: + explicit CArun(QObject *parent = nullptr); + + QTimer *timerChainCtrl; + QTimer *timerVendingTimeout; + + char loadPlugIn(char lade1_entlade2); + + QDir plugInDir; + +private: + + hwinf *HWaccess=nullptr; // global pointer to plugin-class + + + +signals: + void chainControl(); + void vendingTimeout(); + +}; + +#endif // CARUN_H diff --git a/dCArun/dCArun.pro b/dCArun/dCArun.pro index c2f8967..85f723b 100644 --- a/dCArun/dCArun.pro +++ b/dCArun/dCArun.pro @@ -41,6 +41,7 @@ DEFINES+=APP_BUILD_TIME=\\\"$$BUILD_TIME\\\" DEFINES+=APP_EXTENDED_VERSION=\\\"$$EXTENDED_VERSION\\\" SOURCES += \ + CArun.cpp \ main.cpp \ mainwindow.cpp \ tslib.cpp \ @@ -48,6 +49,7 @@ SOURCES += \ datei.cpp HEADERS += \ + CArun.h \ guidefs.h \ mainwindow.h \ stepList.h \ diff --git a/dCArun/main.cpp b/dCArun/main.cpp index 16bfb77..a2ea4a0 100755 --- a/dCArun/main.cpp +++ b/dCArun/main.cpp @@ -1,13 +1,14 @@ -#include "mainwindow.h" +#include "CArun.h" //#include "message_handler.h" -#include +#include int main(int argc, char *argv[]) { - int ret; - QApplication myapp(argc, argv); - QApplication::setApplicationName("CArunGui"); - QApplication::setApplicationVersion(APP_VERSION); + QCoreApplication myapp(argc, argv); + + QCoreApplication::setOrganizationName("ATB"); + QCoreApplication::setApplicationName("CArun"); + QCoreApplication::setApplicationVersion(APP_VERSION); /* if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling @@ -16,16 +17,9 @@ int main(int argc, char *argv[]) //setDebugLevel(QtMsgType::QtDebugMsg); } */ - MainWindow myMainWin; - QSize myMainSize={800, 480}; // breite, höhe, PTU: 800x440 - myMainWin.setMinimumSize(myMainSize); - myMainWin.setMaximumSize(myMainSize); - myMainWin.setWindowTitle("CArun_V4.2 run cash agent master lib"); - //myMainWin.show(); + CArun carun; - ret=myapp.exec(); - - return ret; + return myapp.exec(); }