forked from GerhardHoffmann/DCLibraries
Proposal: final version for new CArun class
This commit is contained in:
parent
c902bd9a54
commit
3bbd3e4e19
255
dCArun/CArun.cpp
255
dCArun/CArun.cpp
@ -1,24 +1,22 @@
|
|||||||
#include "CArun.h"
|
#include "CArun.h"
|
||||||
|
|
||||||
#include "datei.h"
|
#include "datei.h"
|
||||||
|
|
||||||
|
|
||||||
#define UPDATE_PERIOD_MS 100
|
|
||||||
// period to call chain steps
|
|
||||||
|
|
||||||
#define VENDINGTIMEOUT_MS 30000
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CArun::CArun(QObject *parent)
|
CArun::CArun(QObject *parent)
|
||||||
: QObject{parent}
|
: QObject(parent)
|
||||||
|
, setupStep(SETUP_STEP::INIT)
|
||||||
{
|
{
|
||||||
|
this->timerChainCtrl = new QTimer(this);
|
||||||
|
this->connect(timerChainCtrl, SIGNAL(timeout()), this, SLOT(chainControl()));
|
||||||
|
this->timerChainCtrl->setSingleShot(true);
|
||||||
|
this->timerChainCtrl->setInterval(100);
|
||||||
|
|
||||||
loadPlugIn(1);
|
loadPlugIn(1);
|
||||||
|
|
||||||
timerChainCtrl = new QTimer(this);
|
// Start setup-steps:
|
||||||
connect(timerChainCtrl, SIGNAL(timeout()), this, SLOT(chainControl()));
|
qCritical() << "CArun: start setup...";
|
||||||
timerChainCtrl->setSingleShot(0);
|
|
||||||
timerChainCtrl->start(UPDATE_PERIOD_MS); // 1000: call every 1000ms
|
this->timerChainCtrl->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -37,13 +35,13 @@ char CArun::loadPlugIn(char lade1_entlade2)
|
|||||||
|
|
||||||
if (!pluginLoader->load())
|
if (!pluginLoader->load())
|
||||||
{
|
{
|
||||||
qDebug()<<"cannot load plugin";
|
qCritical() << "CArun: cannot load plugin";
|
||||||
} else
|
} else
|
||||||
qDebug() <<"loaded plugin: " << pluginLoader->fileName();
|
qCritical() << "CArun: plugin loaded: " << pluginLoader->fileName();
|
||||||
|
|
||||||
if (!pluginLoader->isLoaded())
|
if (!pluginLoader->isLoaded())
|
||||||
{
|
{
|
||||||
qDebug()<<pluginLoader->errorString();
|
qCritical() << "CArun: ERROR loading plugin: " << pluginLoader->errorString();;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,148 +50,121 @@ char CArun::loadPlugIn(char lade1_entlade2)
|
|||||||
{
|
{
|
||||||
// make instance of the root component (which can hold more then one clases)
|
// make instance of the root component (which can hold more then one clases)
|
||||||
// also loads the lib if not yet done
|
// also loads the lib if not yet done
|
||||||
qDebug()<<"cannot start instance";
|
qCritical() << "CArun: ERROR cannot start instance";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
HWaccess= qobject_cast<hwinf *>(plugin);
|
this->HWaccess = qobject_cast<hwinf *>(plugin);
|
||||||
// make instance to class "hwinf" in dll_HWapi.h over "interfaces.h"
|
// make instance to class "hwinf" in dll_HWapi.h over "interfaces.h"
|
||||||
|
|
||||||
qDebug()<<"loadPlugIn, HWAccess: " << HWaccess;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CArun::openSerialPort()
|
||||||
|
{
|
||||||
|
#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.
|
||||||
|
|
||||||
|
qCritical() << "CArun: open serial port...";
|
||||||
|
|
||||||
|
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
|
||||||
|
this->HWaccess->dc_openSerial(br,bs,cn,1);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
// vermutlich wird dies hier ausgeführt?
|
||||||
|
|
||||||
|
// open with default settings
|
||||||
|
qCritical() << "CArun: open serial with default values";
|
||||||
|
|
||||||
|
bs="115200";
|
||||||
|
br=5;
|
||||||
|
//cn="COM14"; // Windows
|
||||||
|
cn="ttymxc2"; // PTU5
|
||||||
|
ci=2;
|
||||||
|
HWaccess->dc_openSerial(br,bs,cn,1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CArun::chainControl(void)
|
void CArun::chainControl(void)
|
||||||
{
|
{
|
||||||
#define FILENAME_COMPORT "../comport.csv" // TODO: use absolute path
|
switch (this->setupStep) {
|
||||||
// use settings (ini-file)
|
case SETUP_STEP::INIT:
|
||||||
|
qCritical() << "CArun: SETUP_STEP::INIT";
|
||||||
QString bs, cn;
|
this->setupStep = SETUP_STEP::OPEN_SERIAL_PORT;
|
||||||
int br, ci;
|
this->timerChainCtrl->start();
|
||||||
|
break;
|
||||||
|
case SETUP_STEP::OPEN_SERIAL_PORT:
|
||||||
// load and use last settings: --------------------
|
qCritical() << "CArun: SETUP_STEP::OPEN_SERIAL_PORT";
|
||||||
QByteArray myBA;
|
this->openSerialPort();
|
||||||
myBA=datei_readFromFile(FILENAME_COMPORT);
|
this->setupStep = SETUP_STEP::CHECK_VALID_DATA;
|
||||||
if (myBA.length()>0)
|
this->timerChainCtrl->start();
|
||||||
{
|
break;
|
||||||
bs=csv_getEntryAsString(myBA,0); // read the 's' war 2!??
|
case SETUP_STEP::TEST_OPEN_PORT:
|
||||||
br=csv_getEntryAsInt(myBA,1); // z.B. 5 (5.Eintrag in der Baud-Liste)
|
qCritical() << "CArun: SETUP_STEP::TEST_OPEN_PORT";
|
||||||
bs=csv_getEntryAsString(myBA,2); // z.B 115200
|
if (this->HWaccess->dc_isPortOpen()) {
|
||||||
cn=csv_getEntryAsString(myBA,3); // z.B. COM9
|
this->setupStep = SETUP_STEP::TEST_RESPONSE_REQUEST;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
// TIMER myTO: hat keinen timeout-slot!
|
qCritical() << "CArun: port is still closed, restarting..";
|
||||||
// wird nur verwendet, um isActive() abzufragen, d.h. ~x zu warten
|
this->setupStep = SETUP_STEP::INIT;
|
||||||
|
|
||||||
// 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
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
this->timerChainCtrl->start();
|
||||||
if (myNextStep)
|
break;
|
||||||
{
|
case SETUP_STEP::TEST_RESPONSE_REQUEST:
|
||||||
*nextScreen=myNextStep;
|
qCritical() << "CArun: SETUP_STEP::TEST_RESPONSE_REQUEST";
|
||||||
myNextStep=0;
|
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;
|
||||||
}
|
}
|
||||||
return false;
|
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;
|
||||||
|
this->timerChainCtrl->start();
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,8 +9,19 @@
|
|||||||
#include <QPluginLoader>
|
#include <QPluginLoader>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include "plugin.h"
|
#include "plugin.h"
|
||||||
#include "stepList.h"
|
|
||||||
//#include "stepList.h" // define all working chain steps here
|
|
||||||
|
enum class SETUP_STEP {
|
||||||
|
INIT,
|
||||||
|
OPEN_SERIAL_PORT,
|
||||||
|
TEST_OPEN_PORT,
|
||||||
|
TEST_RESPONSE_REQUEST,
|
||||||
|
TEST_RESPONSE_CHECK,
|
||||||
|
SETUP_AUTOREQEUST,
|
||||||
|
CHECK_VALID_DATA
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CArun : public QObject
|
class CArun : public QObject
|
||||||
@ -20,8 +31,7 @@ class CArun : public QObject
|
|||||||
public:
|
public:
|
||||||
explicit CArun(QObject *parent = nullptr);
|
explicit CArun(QObject *parent = nullptr);
|
||||||
|
|
||||||
QTimer *timerChainCtrl;
|
QTimer *timerChainCtrl;
|
||||||
QTimer *timerVendingTimeout;
|
|
||||||
|
|
||||||
char loadPlugIn(char lade1_entlade2);
|
char loadPlugIn(char lade1_entlade2);
|
||||||
|
|
||||||
@ -31,11 +41,15 @@ private:
|
|||||||
|
|
||||||
hwinf *HWaccess=nullptr; // global pointer to plugin-class
|
hwinf *HWaccess=nullptr; // global pointer to plugin-class
|
||||||
|
|
||||||
|
SETUP_STEP setupStep;
|
||||||
|
|
||||||
|
void openSerialPort();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
|
||||||
|
private slots:
|
||||||
void chainControl();
|
void chainControl();
|
||||||
void vendingTimeout();
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user