Add ATBMachineEvent class (QEvent)

This commit is contained in:
Siegfried Siegert 2023-06-21 10:55:12 +02:00
parent b39bbcfad5
commit 8fc88662d3
Signed by: SiegfriedSiegert
GPG Key ID: 68371E015E8F0B03
6 changed files with 126 additions and 4 deletions

View File

@ -73,11 +73,13 @@ HEADERS += \
src/ATBAPP/ATBAPPplugin.h \
src/ATBAPP/DeviceControllerInterface.h \
src/ATBAPP/ATBHealthEvent.h \
src/ATBAPP/ATBMachineEvent.h \
src/ATBAPP/ATBDeviceControllerPlugin.h \
src/ATBAPP/Utils.h
SOURCES += \
src/ATBAPP/ATBHealthEvent.cpp \
src/ATBAPP/ATBMachineEvent.cpp \
src/ATBAPP/ATBDeviceControllerPlugin.cpp \
src/ATBAPP/Utils.cpp

View File

@ -1,5 +1,6 @@
#include "src/ATBAPP/ATBDeviceControllerPlugin.h"
#include "src/ATBAPP/ATBHealthEvent.h"
#include "src/ATBAPP/ATBMachineEvent.h"
#include "src/ATBAPP/Utils.h"
#include <QTimer>
@ -51,9 +52,9 @@ ATBDeviceControllerPlugin::ATBDeviceControllerPlugin(QObject *parent) :
ATBDeviceControllerPlugin::~ATBDeviceControllerPlugin() {}
PLUGIN_STATE ATBDeviceControllerPlugin::initDCPlugin(QObject *healthEventReceiver, const QSettings & settings)
PLUGIN_STATE ATBDeviceControllerPlugin::initDCPlugin(QObject *eventReceiver, const QSettings & settings)
{
this->healthEventReceiver = healthEventReceiver;
this->eventReceiver = eventReceiver;
// read variables from setting
QString serialPort = settings.value("DEVICE_CONTROLLER/serialPort", "ttymxc2").toString();

View File

@ -90,7 +90,7 @@ private:
PLUGIN_STATE pluginState;
QObject* healthEventReceiver;
QObject* eventReceiver;
hwinf* hw;

View File

@ -0,0 +1,66 @@
/* Machine Event
*
* Used e.g. to send events to ISMAS
*
* Note: It's an Event, not a State!
* -> An Event may cause a transition to a different state, depending on the current state.
* -> Compare to edge/level trigger: Event is an "edge", State is a "level"
* => Do not mix both
*
*/
#include <QDateTime>
#include "ATBMachineEvent.h"
ATBMachineEvent::ATBMachineEvent(
const QString & id,
const QString & deviceName, // PTU/PRINTER/DC/...
EVENT_CLASS eventClass, // reason of event: Error/Warning/Alarm
const QString & name, // 'Event': "E001", "W003"
const int state,
const QString & parameter,
const QString & secondLevelInfo)
: QEvent(ATB_MACHINE_EVENT)
, eventId(id)
, deviceName(deviceName)
, machineEventClass(eventClass)
, eventName(name)
, eventState(state)
// timestamp including timezone offset
, timestamString(QDateTime::currentDateTime().toOffsetFromUtc(
QDateTime::currentDateTime().offsetFromUtc()).toString(Qt::ISODate)
)
, parameterString(parameter)
, secondLevelInfoString(secondLevelInfo)
{
}
QString ATBMachineEvent::getEventClassString(EVENT_CLASS eventClass)
{
switch (eventClass) {
case EVENT_CLASS::WARNING:
return "WARNING";
break;
case EVENT_CLASS::ERROR:
return "ERROR";
break;
case EVENT_CLASS::ALARM:
return "ALARM";
break;
case EVENT_CLASS::DEBUG:
return "DEBUG";
break;
case EVENT_CLASS::STATE:
return "STATE";
break;
case EVENT_CLASS::NOT_DEFINED:
return "NOT_DEFINED";
break;
}
return "NOT_DEFINED";
}

View File

@ -0,0 +1,47 @@
#ifndef ATBMACHINECONDITIONEVENT_H
#define ATBMACHINECONDITIONEVENT_H
#include <QEvent>
#include <QString>
enum class EVENT_CLASS : quint8;
const QEvent::Type ATB_MACHINE_EVENT = static_cast<QEvent::Type>(QEvent::User + 2);
class ATBMachineEvent : public QEvent
{
public:
explicit ATBMachineEvent(const QString & id,
const QString & deviceName, // PTU/PRINTER/DC/...
EVENT_CLASS eventClass, // reason of event: Error/Warning/Alarm
const QString & name, // 'Event': "E001", "W003"
const int state,
const QString & parameter,
const QString & secondLevelInfo
);
QString eventId;
QString deviceName;
EVENT_CLASS machineEventClass;
QString eventName;
int eventState;
QString timestamString;
QString parameterString;
QString secondLevelInfoString;
static QString getEventClassString(EVENT_CLASS eventClass);
};
enum class EVENT_CLASS : quint8 {
WARNING,
ERROR,
ALARM,
DEBUG,
STATE,
NOT_DEFINED
};
#endif // ATBMACHINEEVENT_H

View File

@ -24,7 +24,13 @@ class DeviceControllerInterface : public QObject
public:
virtual ~DeviceControllerInterface() {}
virtual nsDeviceControllerInterface::PLUGIN_STATE initDCPlugin(QObject *healthEventReceiver,
/**
* @brief initDCPlugin
* @param eventReceiver - QObject to receive ATBMachineEvents or HealthEvents
* @param settings
* @return
*/
virtual nsDeviceControllerInterface::PLUGIN_STATE initDCPlugin(QObject *eventReceiver,
const QSettings & settings) = 0;
// TASKS: Cash handling -------------------------------------------------------