DCLibraries/dCArun/CArun.cpp

175 lines
5.3 KiB
C++
Raw Normal View History

2024-03-02 08:36:06 +01:00
#include "CArun.h"
#include "datei.h"
2024-06-10 11:50:34 +02:00
#include "CCWakelineAbstraction.h"
2024-03-02 08:36:06 +01:00
CArun::CArun(QObject *parent)
: QObject(parent)
, setupStep(SETUP_STEP::INIT)
2024-03-02 08:36:06 +01:00
{
this->timerChainCtrl = new QTimer(this);
this->connect(timerChainCtrl, SIGNAL(timeout()), this, SLOT(chainControl()));
this->timerChainCtrl->setSingleShot(true);
this->timerChainCtrl->setInterval(100);
2024-03-02 08:36:06 +01:00
loadPlugIn(1);
// Start setup-steps:
qCritical() << "CArun: start setup...";
this->timerChainCtrl->start();
2024-06-10 11:50:34 +02:00
this->ccWakelineAbstraction = new CCWakelineAbstraction(this->HWaccess, this);
2024-03-02 08:36:06 +01:00
}
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())
{
qCritical() << "CArun: cannot load plugin";
2024-03-02 08:36:06 +01:00
} else
qCritical() << "CArun: plugin loaded: " << pluginLoader->fileName();
2024-03-02 08:36:06 +01:00
if (!pluginLoader->isLoaded())
{
qCritical() << "CArun: ERROR loading plugin: " << pluginLoader->errorString();;
2024-03-02 08:36:06 +01:00
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
qCritical() << "CArun: ERROR cannot start instance";
2024-03-02 08:36:06 +01:00
return 0;
}
this->HWaccess = qobject_cast<hwinf *>(plugin);
2024-03-02 08:36:06 +01:00
// make instance to class "hwinf" in dll_HWapi.h over "interfaces.h"
return 0;
}
void CArun::openSerialPort()
2024-03-02 08:36:06 +01:00
{
#define FILENAME_COMPORT "../comport.csv" // TODO: use absolute path
// use settings (ini-file)
// comport.csv wird mit installiert in: /opt/app/
// k.A., ob "../comport.csv" gefunden wird.
2024-03-02 08:36:06 +01:00
qCritical() << "CArun: open serial port...";
2024-03-02 08:36:06 +01:00
QString bs, cn;
int br, ci;
2024-03-02 08:36:06 +01:00
// 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
this->HWaccess->dc_openSerial(br,bs,cn,1);
} else
{
// vermutlich wird dies hier ausgeführt?
2024-03-02 08:36:06 +01:00
// open with default settings
qCritical() << "CArun: open serial with default values";
2024-03-02 08:36:06 +01:00
bs="115200";
br=5;
//cn="COM14"; // Windows
cn="ttymxc2"; // PTU5
ci=2;
HWaccess->dc_openSerial(br,bs,cn,1);
}
}
2024-03-02 08:36:06 +01:00
void CArun::chainControl(void)
{
switch (this->setupStep) {
case SETUP_STEP::INIT:
qCritical() << "CArun: SETUP_STEP::INIT";
this->setupStep = SETUP_STEP::OPEN_SERIAL_PORT;
this->timerChainCtrl->start();
break;
case SETUP_STEP::OPEN_SERIAL_PORT:
qCritical() << "CArun: SETUP_STEP::OPEN_SERIAL_PORT";
this->openSerialPort();
2024-07-25 15:34:47 +02:00
this->setupStep = SETUP_STEP::TEST_OPEN_PORT;
this->timerChainCtrl->start();
break;
case SETUP_STEP::TEST_OPEN_PORT:
qCritical() << "CArun: SETUP_STEP::TEST_OPEN_PORT";
if (this->HWaccess->dc_isPortOpen()) {
this->setupStep = SETUP_STEP::TEST_RESPONSE_REQUEST;
}
else {
qCritical() << "CArun: port is still closed, restarting..";
this->setupStep = SETUP_STEP::INIT;
}
this->timerChainCtrl->start();
break;
case SETUP_STEP::TEST_RESPONSE_REQUEST:
qCritical() << "CArun: SETUP_STEP::TEST_RESPONSE_REQUEST";
this->HWaccess->dc_requTestResponse();
this->setupStep = SETUP_STEP::TEST_RESPONSE_CHECK;
this->timerChainCtrl->start();
break;
case SETUP_STEP::TEST_RESPONSE_CHECK:
qCritical() << "CArun: SETUP_STEP::TEST_RESPONSE_CHECK";
if (this->HWaccess->dc_readAnswTestResponse()) {
// response was correct
this->setupStep = SETUP_STEP::SETUP_AUTOREQEUST;
}
else {
qCritical() << "CArun: got no answer from DC, retry..";
this->setupStep = SETUP_STEP::INIT;
}
this->timerChainCtrl->start();
break;
case SETUP_STEP::SETUP_AUTOREQEUST:
qCritical() << "CArun: SETUP_STEP::SETUP_AUTOREQEUST";
this->HWaccess->dc_autoRequest(1);
this->setupStep = SETUP_STEP::CHECK_VALID_DATA;
2024-07-25 15:34:47 +02:00
this->timerChainCtrl->start(2000);
break;
case SETUP_STEP::CHECK_VALID_DATA:
qCritical() << "CArun: SETUP_STEP::CHECK_VALID_DATA";
if (this->HWaccess->sys_areDCdataValid()) {
qCritical() << "CArun: DC is connected";
// do not start timer again
}
else {
qCritical() << "CArun: auto request is not running, retry...";
this->setupStep = SETUP_STEP::INIT;
this->timerChainCtrl->start();
}
break;
default:
qCritical() << "CArun: invalid setup step";
break;
}
2024-03-02 08:36:06 +01:00
}