Index: sources/StateController.cpp =================================================================== diff -u -r584874a724b2d3e8c98247d3b0e42d6a34ce9478 -r1cfa9a2d55e3bf954e5d02f12b73d3a8deda9e5c --- sources/StateController.cpp (.../StateController.cpp) (revision 584874a724b2d3e8c98247d3b0e42d6a34ce9478) +++ sources/StateController.cpp (.../StateController.cpp) (revision 1cfa9a2d55e3bf954e5d02f12b73d3a8deda9e5c) @@ -7,7 +7,12 @@ void StateController::init() { connect(&_ApplicationController, SIGNAL(didUnhandledMsgAppController(const QVariantList &)), - this , SLOT(onStateControllerUnhandledMsgReceived(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() @@ -20,28 +25,77 @@ { 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? } - switch(msg[0].toUInt()) + qDebug() << "Active states" << _dryDemo.activeStateNames(); + + switch(receivedMsgID) { - case 2500: // TODO enum for this - qDebug() << "Right here"; - _dryDemo.connectToState("Idle", _dryDemo.onEntry([&]() { - qDebug() << "In onEntry" << _dryDemo.activeStateNames();})); + case 0x2500: // TODO enum for this + //qDebug() << "Right here"; + //_dryDemo.connectToState("Idle", _dryDemo.onEntry([&]() { + // qDebug() << "In onEntry" << _dryDemo.activeStateNames();})); + //qDebug() << "New state" << _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"); + } - 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; + 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; + //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"; + } +} +