#include "StateController.h" #include "ApplicationController.h" StateController::StateController(QObject *parent) : QObject(parent) {} void StateController::init() { connect(&_ApplicationController, SIGNAL(didUnhandledMsgAppController(const QVariantList &)), this , SLOT(onStateControllerUnhandledMsgReceived(const QVariantList &))); _dryDemo.connectToState("Idle" , this, &StateController::onIdleStateChange ); _dryDemo.connectToState("Treatment" , this, &StateController::onTreatmentStateChange ); _dryDemo.connectToState("Disinfect" , this, &StateController::onDisinfectStateChange ); } void StateController::quit() { // TODo fill up } void StateController::onStateControllerUnhandledMsgReceived(const QVariantList &msg) { qDebug() << "Message With new" << msg[0]; quint16 receivedMsgID = msg[0].toUInt(); if (!_dryDemo.isRunning()) { _dryDemo.start(); // TODO why cannot start the state machine somewhere else? } qDebug() << "Active states" << _dryDemo.activeStateNames(); switch(receivedMsgID) { case 0x2500: // TODO enum for this //qDebug() << "Right here"; //_dryDemo.connectToState("Idle", _dryDemo.onEntry([&]() { // qDebug() << "In onEntry" << _dryDemo.activeStateNames();})); //qDebug() << "New state" << _dryDemo.activeStateNames(); //QVariantList list; //list.append(static_cast(0x2A00)); //list.append(Can_Id::eChlid_HD_UI); //list.append(68); //list.append(34.56); //emit _ApplicationController.didActionTransmit(list); break; case 0x2700: if ( _dryDemo.activeStateNames()[0] == "Idle" ) { qDebug() << "Current active"; _dryDemo.submitEvent("Tx_Start_Rqst"); } qDebug() << "Active state in 0x2700" << _dryDemo.activeStateNames()[0]; if (_dryDemo.activeStateNames()[0] == "Treatment") { qDebug() << "Active state in treatment" << _dryDemo.activeStateNames()[0]; _dryDemo.submitEvent("Transition_back_2_idle"); } break; } //qDebug() << "Msg Received" << msg; // TODO remove } // ---------------------- Private methods ------------------ // void StateController::onIdleStateChange(bool active) { if (active) { REMOVE_THIS++; qDebug() << "Idle from function" << REMOVE_THIS << active; if (REMOVE_THIS == 2) { _dryDemo.submitEvent("Disinfect_Rqst"); } } } void StateController::onTreatmentStateChange(bool active) { qDebug() << "Calling treatment function"; if (active) { qDebug() << "Treatment active"; } else { qDebug() << "Treatment inactive"; } } void StateController::onDisinfectStateChange(bool active) { if (active) { qDebug() << "Disinfect active"; } }