#include #include "StateController.h" #include "ApplicationController.h" #include "types.h" StateController::StateController(QObject *parent) : QObject(parent) {} void StateController::init() { startTimer(QOBJECT_TIMER_TIMEOUT_MS); connect(&_ApplicationController, SIGNAL(didUnhandledMsgAppController(const QVariantList &)), this , SLOT(doStateControllerUnhandledMsgReceived(const QVariantList &))); _dryDemo.connectToState("Idle" , this, &StateController::onIdleStateChange ); _dryDemo.connectToState("Tx_Params" , this, &StateController::onTreatmentParamsStateChange ); _dryDemo.connectToState("Water_Sample" , this, &StateController::onWaterSampleStateChange ); _dryDemo.connectToState("Consumables" , this, &StateController::onConsumablesStateChange ); _dryDemo.connectToState("Disposables" , this, &StateController::onDisposablesStateChange ); _dryDemo.connectToState("System_Prime" , this, &StateController::onSystemPrimeStateChange ); _dryDemo.connectToState("BP_HR" , this, &StateController::onBPHRStateChange ); _dryDemo.connectToState("Ultrafiltraion" , this, &StateController::onUltrafiltrationStateChange ); _dryDemo.connectToState("Connection" , this, &StateController::onConnectionStateChange ); _dryDemo.connectToState("Start_Tx" , this, &StateController::onStartTreatmentStateChange ); _dryDemo.connectToState("Blood_Prime" , this, &StateController::onTreatmentBloodPrimeStateChange); _dryDemo.connectToState("Treatment" , this, &StateController::onTreatmentTreatmentStateChange ); _dryDemo.connectToState("End_Tx" , this, &StateController::onEndTreatmentStateChange ); _dryDemo.connectToState("Disinfect" , this, &StateController::onDisinfectStateChange ); _dryDemoCurrentCmd = CMD_NONE; // Start with uninitialized treatment params _treatmentParams.hasTxParamsBeenInitialized = false; resetVariables(); initMessagesHashTable(); // Todo remove this once the state machine is finished. } void StateController::quit() { // TODo fill up } void StateController::doStateControllerUnhandledMsgReceived(const QVariantList &msg) { if (!_dryDemo.isRunning()) { _dryDemo.start(); // TODO why cannot start the state machine somewhere else? } MessageID receivedMsgID = static_cast(msg[0].toUInt()); QVariantList msgBack; switch(receivedMsgID) { case ID_UI_RQST_TX: _dryDemoCurrentCmd = CMD_TX_PARAMS; break; case ID_UI_TX_PARAMS_RQST: _treatmentRcvdMessages[receivedMsgID] = msg[1]; break; case ID_UI_CONFIRM_RESP: _treatmentRcvdMessages[receivedMsgID] = msg[1]; break; case ID_UI_CONFIRM_TX_PARAMS: _hasUserConfirmedToProceed = true; break; case ID_SAMPLE_WATER_RESULT: _treatmentRcvdMessages[receivedMsgID] = msg[1]; break; case ID_UI_CONSUMABLES_INSTALL: _hasUserConfirmedToProceed = true; break; case ID_UI_INTALLATION_CONFIRM: _hasUserConfirmedToProceed = true; break; case ID_UI_PATIENT_CONNECTION_RQST: _hasUserConfirmedToProceed = true; _dryDemoCurrentCmd = CMD_BP_HR; break; case ID_UI_SET_UF_VOLUME_RQST: msgBack.clear(); msgBack.append(static_cast(ID_HD_SET_UF_VOLUME_RESP)); msgBack.append(Can_Id::eChlid_HD_UI); msgBack.append(1); msgBack.append(0); msgBack.append(1.8); emit _ApplicationController.didActionTransmit(msgBack); _dryDemoCurrentCmd = CMD_CONNECTION; break; case ID_UI_PATIENT_CONNECTION_CONF_RQST: msgBack.clear(); msgBack.append(static_cast(ID_HD_PATINET_CONNECTION_CONF_RESP)); msgBack.append(Can_Id::eChlid_HD_UI); msgBack.append(1); msgBack.append(0); emit _ApplicationController.didActionTransmit(msgBack); _dryDemoCurrentCmd = CMD_START_TX; break; case ID_UI_START_TX_RQST: _hasUserConfirmedToProceed = true; break; case ID_USER_TX_TIME_CHANGES_RQST: _treatmentRcvdMessages[receivedMsgID] = msg[1]; break; case ID_NONE: case ID_HD_BLOOD_FLOW_DATA_BC: case ID_HD_DIALYSATE_FLOW_DATA_BC: case ID_PRESSURE_OCCLUSION_DATA_BC: case ID_DIALYSATE_OUT_FLOW_DATA_BC: case ID_TX_TIME_BC: case ID_HD_TX_PARAMS_RANGES_DATA: case ID_HD_TX_STATES_BC: case ID_HD_OP_MODE: case ID_FILTER_FLUSH_TIME_BC: case ID_HD_UI_CONFIRM_RQST: case ID_PRE_TX_STATES_BC: case ID_HD_NEW_PARAMS_RESP: case ID_HD_SYS_SELF_TEST_TIME_BC: case ID_HD_DRY_SELF_TEST_TIME_BC: case ID_HD_PRIMING_TIME_BC: case ID_HD_SET_UF_VOLUME_RESP: case ID_HD_PATINET_CONNECTION_CONF_RESP: case ID_USER_TX_TIME_CHANGES_RESP: case ID_HD_BLOOD_PRIME_BC: // Do nothing break; } } void StateController::timerEvent(QTimerEvent *) { _dryDemo.submitEvent("TimeoutEvent"); if (_isBroadcastListReady) { sendMessages(true); } if (_isSendListReady) { sendMessages(false); } } // ---------------------- Private methods ------------------ // void StateController::initMessagesHashTable() { QVariantList temp; temp.append("Transition_2_Tx_Parms"); temp.append(false); // wait for a trigger temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_HD_OP_MODE)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(MODE_TPAR); temp.append(0); _dryDemoCmds[CMD_TX_PARAMS].append(temp); temp.clear(); temp.append("Transition_2_Water_Sample"); temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_HD_OP_MODE)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(MODE_PRET); temp.append(0); _dryDemoCmds[CMD_WATER_SAMPLE].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_WATER_SAMPLE].append(temp); temp.clear(); temp.append(static_cast(COUNTER_PRE_TX_TIMERS)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_FILTER_FLUSH_TIME_BC)); temp.append(Can_Id::eChlid_DG_Sync); temp.append(DEFAULT_TIMEOUT_S); temp.append(DEFAULT_TIMEOUT_S); _dryDemoCmds[CMD_WATER_SAMPLE].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(0); temp.append(1); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_WATER_SAMPLE].append(temp); temp.clear(); temp.append("Transition_2_Consumables"); temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_HD_OP_MODE)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(MODE_PRET); temp.append(0); _dryDemoCmds[CMD_CONSUMABLES].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(true); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(1); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_CONSUMABLES].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(1); temp.append(0); temp.append(1); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_CONSUMABLES].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(1); temp.append(0); temp.append(2); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_CONSUMABLES].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(1); temp.append(0); temp.append(3); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_CONSUMABLES].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_DISPOSABLES)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(1); temp.append(0); temp.append(4); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_CONSUMABLES].append(temp); temp.clear(); temp.append("Transition_2_Disposables"); temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_HD_OP_MODE)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(MODE_PRET); temp.append(0); _dryDemoCmds[CMD_DISPOSABLES].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(2); temp.append(0); temp.append(0); temp.append(1); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_DISPOSABLES].append(temp); temp.clear(); temp.append(static_cast(COUNTER_PRE_TX_TIMERS)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_HD_SYS_SELF_TEST_TIME_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(DEFAULT_TIMEOUT_S); temp.append(DEFAULT_TIMEOUT_S); _dryDemoCmds[CMD_DISPOSABLES].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); // wait for the user temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(3); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_DISPOSABLES].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(true); // wait for the user temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(3); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_DISPOSABLES].append(temp); temp.clear(); temp.append("Transition_2_Sys_Prime"); temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_HD_OP_MODE)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(MODE_PRET); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(4); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_PRE_TX_TIMERS)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_HD_DRY_SELF_TEST_TIME_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(DEFAULT_TIMEOUT_S); temp.append(DEFAULT_TIMEOUT_S); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(4); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(1); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(4); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(2); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); //(false); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(4); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(3); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(4); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(4); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(4); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(5); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(4); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(6); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(4); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(7); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(4); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(8); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(4); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(9); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(4); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(10); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(4); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(11); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(4); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(12); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(4); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(13); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(4); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(14); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(4); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(15); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(4); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(16); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(5); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_PRE_TX_TIMERS)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_HD_PRIMING_TIME_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(DEFAULT_TIMEOUT_S); temp.append(DEFAULT_TIMEOUT_S); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(5); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(1); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(5); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(2); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(5); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(3); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(5); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(4); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(5); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(5); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(5); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(6); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(5); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(7); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(5); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(8); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(5); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(9); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(5); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(10); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(5); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(11); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(5); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(12); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(true); // wait temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(6); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_SYSTEM_PRIME].append(temp); temp.clear(); temp.append("Transition_2_BP_HR"); temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_HD_OP_MODE)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(MODE_PRET); temp.append(0); _dryDemoCmds[CMD_BP_HR].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); // wait temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(7); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_BP_HR].append(temp); temp.clear(); temp.append("Transition_2_Ultrafiltraion"); temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_HD_OP_MODE)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(MODE_PRET); temp.append(0); _dryDemoCmds[CMD_ULTRAFILTRATION].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); // wait temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(7); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(1); temp.append(0); temp.append(0); _dryDemoCmds[CMD_ULTRAFILTRATION].append(temp); temp.clear(); temp.append("Transition_2_Patient_Connection"); temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_HD_OP_MODE)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(MODE_PRET); temp.append(0); _dryDemoCmds[CMD_CONNECTION].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(true); // wait temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(7); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(2); temp.append(0); temp.append(0); _dryDemoCmds[CMD_CONNECTION].append(temp); temp.clear(); /* temp.append("Transition_2_Start_Tx"); temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_HD_OP_MODE)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(MODE_PRET); temp.append(0); _dryDemoCmds[CMD_START_TX].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(true); // wait temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_PRE_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(7); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(3); temp.append(0); temp.append(0); _dryDemoCmds[CMD_START_TX].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // Transition to Tx. This is empty because there is no event temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_HD_OP_MODE)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(MODE_TREA); temp.append(0); _dryDemoCmds[CMD_START_TX].append(temp); temp.clear(); // NOTE: Tx param ranges are broadcast in firmware but it is sent here only once temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); // wait temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_HD_TX_PARAMS_RANGES_DATA)); temp.append(Can_Id::eChlid_HD_UI); temp.append(0); temp.append(DEFAULT_TX_PRESCRIBED_DUR_S / 60); temp.append(0.0); temp.append(DEFAULT_UF_VOLUME_L); temp.append(100); temp.append(600); _dryDemoCmds[CMD_START_TX].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); // wait temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_HD_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(1); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_START_TX].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); // wait temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_HD_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(2); temp.append(1); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_START_TX].append(temp); temp.clear(); temp.append(static_cast(COUNTER_TX_TIMER)); // this is the timer temp.append(false); // wait temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_TX_TIME_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(DEFAULT_TX_PRESCRIBED_DUR_S); temp.append(DEFAULT_TX_ELAPSED_TIME_S); temp.append(DEFAULT_TX_PRESCRIBED_DUR_S - DEFAULT_TX_ELAPSED_TIME_S); _dryDemoCmds[CMD_START_TX].append(temp); temp.clear(); */ temp.append("Transition_2_End_Tx"); temp.append(static_cast(COUNTER_NONE)); // Transition to Tx. This is empty because there is no event temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_HD_OP_MODE)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(MODE_TREA); temp.append(0); _dryDemoCmds[CMD_END_TX].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); // wait temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_HD_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(1); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_END_TX].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(true); // wait temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_HD_TX_STATES_BC)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(6); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); temp.append(0); _dryDemoCmds[CMD_END_TX].append(temp); temp.clear(); temp.append("Transition_2_Disinfect"); temp.append(false); temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_HD_OP_MODE)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(MODE_STAN); temp.append(0); _dryDemoCmds[CMD_DISINFECTION].append(temp); temp.clear(); temp.append(static_cast(COUNTER_NONE)); // this is the timer temp.append(false); // wait temp.append(static_cast(CMD_NONE)); // auto transition temp.append(static_cast(ID_HD_OP_MODE)); temp.append(Can_Id::eChlid_HD_Sync); temp.append(MODE_STAN); temp.append(2); _dryDemoCmds[CMD_DISINFECTION].append(temp); temp.clear(); } void StateController::resetVariables() { _index = 0; _broadcastMsgCount = 0; _timerBroadcastCount = 0; _hasUserConfirmedToProceed = false; _currentCounterValue = COUNTER_VAR_DEFAULT_VALUE; _prescribedTreatmentTimeS = PRESC_TIME_DEFAULT_VALUE; _stateStatus = STATE_ON_ENTRY; _isBroadcastListReady = false; _isSendListReady = false; _treatmentVars.accumulatedVolumeML = 0.0; _treatmentVars.broadcastIntervalCount = 0; _treatmentVars.broadcastIntervalCount = 0; _broadcastMessages.clear(); _sendMessages.clear(); } void StateController::sendMessages(bool isBroadcast) { QList msgList = _broadcastMessages; if (isBroadcast) { _broadcastMessages.clear(); } else { msgList = _sendMessages; _sendMessages.clear(); } for (auto item: msgList) { emit _ApplicationController.didActionTransmit(item); } } void StateController::setTreatmentParams(bool isFromUI, const QVariant &payload) { if (isFromUI) { QVariantList resp; resp.append(static_cast(ID_HD_NEW_PARAMS_RESP)); resp.append(Can_Id::eChlid_HD_UI); resp.append(ACCEPT_VALUE); resp.append(0); qint32 index = 0; Types::U32 u32Var; Types::F32 f32Var; Types::S32 s32Var; GetValue(payload.toByteArray(), index, u32Var); _treatmentParams.bloodFlowRateMLPM = u32Var.value; resp.append(u32Var.value); GetValue(payload.toByteArray(), index, u32Var); _treatmentParams.dialysateFlowRateMLPM = u32Var.value; resp.append(u32Var.value); GetValue(payload.toByteArray(), index, u32Var); _treatmentParams.txDurationMins = u32Var.value; resp.append(u32Var.value); GetValue(payload.toByteArray(), index, u32Var); _treatmentParams.salineBolusVolML = u32Var.value; resp.append(u32Var.value); GetValue(payload.toByteArray(), index, u32Var); _treatmentParams.acidConc = u32Var.value; resp.append(u32Var.value); GetValue(payload.toByteArray(), index, u32Var); _treatmentParams.bicarbConc = u32Var.value; resp.append(u32Var.value); GetValue(payload.toByteArray(), index, u32Var); _treatmentParams.dialyzerType = u32Var.value; resp.append(u32Var.value); GetValue(payload.toByteArray(), index, u32Var); _treatmentParams.heparinType = u32Var.value; resp.append(u32Var.value); GetValue(payload.toByteArray(), index, u32Var); _treatmentParams.bloodMeasurementInveralMin = u32Var.value; resp.append(u32Var.value); GetValue(payload.toByteArray(), index, u32Var); _treatmentParams.rinsebackFlowRateMLPM = u32Var.value; resp.append(u32Var.value); GetValue(payload.toByteArray(), index, s32Var); _treatmentParams.areterialPresLimitWindowMMHG = s32Var.value; resp.append(s32Var.value); GetValue(payload.toByteArray(), index, s32Var); _treatmentParams.venousPresLimitWindowMMHG = s32Var.value; resp.append(s32Var.value); GetValue(payload.toByteArray(), index, s32Var); _treatmentParams.venousPresLimitAsymWindowMMHG = s32Var.value; resp.append(s32Var.value); GetValue(payload.toByteArray(), index, f32Var); _treatmentParams.heparinDispenseRateMLHR = f32Var.value; resp.append(f32Var.value); GetValue(payload.toByteArray(), index, f32Var); _treatmentParams.heparinBolusVolML = f32Var.value; resp.append(f32Var.value); GetValue(payload.toByteArray(), index, f32Var); _treatmentParams.dialysateTemperatureC = f32Var.value; resp.append(f32Var.value); _treatmentParams.hasTxParamsBeenInitialized = true; _isSendListReady = false; _sendMessages.append(resp); _isSendListReady = true; qDebug() << "Treatment params from TPAR" << _treatmentParams.bloodFlowRateMLPM << _treatmentParams.dialysateFlowRateMLPM << _treatmentParams.txDurationMins << _treatmentParams.dialysateTemperatureC; } else if (!_treatmentParams.hasTxParamsBeenInitialized) { _treatmentParams.bloodFlowRateMLPM = DEF_TX_PARAM_BLOOD_FLOW_RATE_MLPM; _treatmentParams.dialysateFlowRateMLPM = DEF_TX_PARAM_DIAL_FLOW_RATE_MLPM; _treatmentParams.txDurationMins = DEF_TX_PARAM_PRESCRIBED_DUR_S / SECONDS_PER_MINUTE; _treatmentParams.salineBolusVolML = DEF_TX_PARAM_SALINE_BOLUS_VOL_ML; _treatmentParams.acidConc = 0; _treatmentParams.bicarbConc = 0; _treatmentParams.dialyzerType = 0; _treatmentParams.heparinType = 0; _treatmentParams.bloodMeasurementInveralMin = 0; _treatmentParams.rinsebackFlowRateMLPM = DEF_TX_PARAM_RINSEBACK_FLOW_RATE_MLPM; _treatmentParams.areterialPresLimitWindowMMHG = DEF_TX_PARAM_ART_PRES_LIMIT_WIN_MMHG; _treatmentParams.venousPresLimitWindowMMHG = DEF_TX_PARAM_VEN_PRES_LIMIT_WIN_MMHG; _treatmentParams.venousPresLimitAsymWindowMMHG = DEF_TX_PARAM_VEN_PRES_LIMIT_ASYM_WIN_MMHG; _treatmentParams.heparinDispenseRateMLHR = 0; _treatmentParams.heparinBolusVolML = 0; _treatmentParams.dialysateTemperatureC = DEF_TX_PARAM_DIA_TEMPERATURE_C; _treatmentParams.hasTxParamsBeenInitialized = true; } qDebug() << "Treatment params" << _treatmentParams.hasTxParamsBeenInitialized; } void StateController::prepareOcclusionBroadcastData() { // TODO a random variation here QVariantList msg; msg.append(static_cast(ID_PRESSURE_OCCLUSION_DATA_BC)); msg.append(Can_Id::eChlid_HD_Sync); msg.append(10.2); msg.append(12.3); msg.append(0); msg.append(0); msg.append(0); msg.append(0); msg.append(0); msg.append(0); msg.append(0); msg.append(0); msg.append(0); msg.append(0); _isBroadcastListReady = false; _broadcastMessages.append(msg); _isBroadcastListReady = true; } void StateController::prepareTreatmentTimeBroadcastData() { _treatmentVars.treatmentElapsedTimeS++; _treatmentVars.remainingTreatmentTimeS = _treatmentVars.prescribedTreatmentTimeS - _treatmentVars.treatmentElapsedTimeS; if (_treatmentVars.remainingTreatmentTimeS <= 0 ) { _treatmentVars.remainingTreatmentTimeS = 0; } //qDebug() << " Treatment time" << QTime::currentTime() << _treatmentVars._broadcastIntervalCount << _treatmentVars._treatmentElapsedTimeS << _treatmentVars._remainingTreatmentTimeS; QVariantList msg; msg.append(static_cast(ID_TX_TIME_BC)); msg.append(Can_Id::eChlid_HD_Sync); msg.append(_treatmentVars.prescribedTreatmentTimeS); msg.append(_treatmentVars.treatmentElapsedTimeS); msg.append(_treatmentVars.remainingTreatmentTimeS); _isBroadcastListReady = false; _broadcastMessages.append(msg); _isBroadcastListReady = true; } void StateController::prepareTreatmentStatesBroadcastData(const QVariantList &payload) { QVariantList msg; msg.append(static_cast(ID_HD_TX_STATES_BC)); msg.append(Can_Id::eChlid_HD_Sync); for (auto item: payload) { msg.append(item); } _isBroadcastListReady = false; _broadcastMessages.append(msg); _isBroadcastListReady = true; } void StateController::prepareBloodFlowBroadcastData() { QVariantList msg; msg.append(static_cast(ID_HD_BLOOD_FLOW_DATA_BC)); msg.append(Can_Id::eChlid_HD_Sync); msg.append(_treatmentParams.bloodFlowRateMLPM); msg.append(_treatmentParams.bloodFlowRateMLPM - 0.1); msg.append(0.0); msg.append(0.0); msg.append(0.0); msg.append(0.0); msg.append(0.0); msg.append(0); msg.append(_treatmentParams.bloodFlowRateMLPM); msg.append(0); _isBroadcastListReady = false; _broadcastMessages.append(msg); _isBroadcastListReady = true; } void StateController::prepareDialysateFlowBroadcastData() { QVariantList msg; msg.append(static_cast(ID_HD_DIALYSATE_FLOW_DATA_BC)); msg.append(Can_Id::eChlid_HD_Sync); msg.append(_treatmentParams.dialysateFlowRateMLPM); msg.append(_treatmentParams.dialysateFlowRateMLPM - 0.1); msg.append(0.0); msg.append(0.0); msg.append(0.0); msg.append(0.0); msg.append(0.0); msg.append(0); msg.append(_treatmentParams.dialysateFlowRateMLPM); msg.append(0); _isBroadcastListReady = false; _broadcastMessages.append(msg); _isBroadcastListReady = true; } void StateController::prepareDialysateOutFlowBroadcastData() { QVariantList msg; msg.append(static_cast(ID_DIALYSATE_OUT_FLOW_DATA_BC)); msg.append(Can_Id::eChlid_HD_Sync); msg.append(_treatmentVars.refUFVolumeML); msg.append(_treatmentVars.measUFVolumeML); msg.append(0.0); msg.append(0.0); msg.append(0.0); msg.append(0.0); msg.append(0.0); msg.append(0.0); msg.append(0.0); msg.append(0.0); msg.append(0); msg.append(0.0); msg.append(0); _isBroadcastListReady = false; _broadcastMessages.append(msg); _isBroadcastListReady = true; } void StateController::prepareTreatmentParamsRangesBroadcastData() { // Calculations are from broadcastTreatmentSettingsRanges in the HD quint32 elapsedTimeMins = _treatmentVars.treatmentElapsedTimeS / SECONDS_PER_MINUTE; float dialVolumeSoFarML = _treatmentParams.dialysateFlowRateMLPM * (_treatmentVars.treatmentElapsedTimeS / SECONDS_PER_MINUTE); float maxQdMLPM = 0.0; if (_treatmentVars.treatmentElapsedTimeS > 0) { maxQdMLPM = (MAX_DIALYSATE_VOLUME_ML - dialVolumeSoFarML) / (_treatmentVars.remainingTreatmentTimeS / SECONDS_PER_MINUTE); } quint32 minTimeMins = qMax(elapsedTimeMins + 2, (quint32)MIN_TX_TIME_MINS); float prescribedUF = (_treatmentVars.prescribedUFRate > 0.0 ? _treatmentVars.prescribedUFRate : 1); quint32 maxTimeRemMins = (MAX_UF_VOL_ML - _treatmentVars.refUFVolumeML) / prescribedUF; quint32 maxTime1 = minTimeMins + maxTimeRemMins; quint32 maxTime2 = MAX_DIAL_RATE_MLPM / _treatmentParams.dialysateFlowRateMLPM; quint32 maxTimeMins = qMax(maxTime1, maxTime2); //qDebug() << "Time Ranges Values" << minTimeMins << maxTimeRemMins << maxTime2 << maxTimeMins << _treatmentVars.prescribedUFRate; float minUFVolML = _treatmentVars.refUFVolumeML + _treatmentVars.prescribedUFRate; float maxUFVol1 = minUFVolML + ((_treatmentParams.txDurationMins - elapsedTimeMins) * MAX_UF_RATE_MLPM); float maxUFVol2 = minUFVolML; if (_treatmentVars.prescribedUFRate > 0.0 ) { maxUFVol2 = minUFVolML + (MAX_TX_TIME_MINS - elapsedTimeMins - 1) * _treatmentVars.prescribedUFRate; } float maxUFVol = qMax(maxUFVol1, maxUFVol2); quint32 minDialFlowRateMLPM = MIN_DIAL_RATE_MLPM; quint32 maxDialFlowRateMLPM = (maxQdMLPM > MIN_DIAL_RATE_MLPM ? maxQdMLPM : minDialFlowRateMLPM); maxTimeMins = qMin(maxTimeMins, (quint32)MAX_TX_TIME_MINS) ; maxUFVol = qMin(maxUFVol, (float)MAX_UF_VOL_ML); maxDialFlowRateMLPM = qMin(maxDialFlowRateMLPM, (quint32)MAX_DIAL_RATE_MLPM); //qDebug() << "New UF" << minUFVolML << maxUFVol1 << maxUFVol2 << maxUFVol << maxDialFlowRateMLPM; QVariantList msg; msg.append(static_cast(ID_HD_TX_PARAMS_RANGES_DATA)); msg.append(Can_Id::eChlid_HD_Sync); msg.append(minTimeMins); msg.append(maxTimeMins); msg.append(minUFVolML); msg.append(maxUFVol); msg.append(minDialFlowRateMLPM); msg.append(maxDialFlowRateMLPM); _isBroadcastListReady = false; _broadcastMessages.append(msg); _isBroadcastListReady = true; } void StateController::prepareHDModeTransitionBroadcastData(HD_OP_MODE mode) { QVariantList msg; msg.append(static_cast(ID_HD_OP_MODE)); msg.append(Can_Id::eChlid_HD_Sync); msg.append(mode); msg.append(0); _isBroadcastListReady = false; _broadcastMessages.append(msg); _isBroadcastListReady = true; //qDebug() << "MOde" << msg; } void StateController::preparePreTreatmentStatesBroadcastData(const QList &preTxStates) { QVariantList msg; msg.append(static_cast(ID_PRE_TX_STATES_BC)); msg.append(Can_Id::eChlid_HD_Sync); for (auto item: preTxStates) { msg.append(item); } _isBroadcastListReady = false; _broadcastMessages.append(msg); _isBroadcastListReady = true; } void StateController::handleTreatmentReceivedMessages() { // TODO mutex here? for (auto i = _treatmentRcvdMessages.begin(), end = _treatmentRcvdMessages.end(); i != end; ++i) { if (!i.value().isNull()) { if (i.key() == ID_UI_TX_PARAMS_RQST) { setTreatmentParams(true, i.value()); _treatmentRcvdMessages[i.key()].clear(); } if (i.key() == ID_USER_TX_TIME_CHANGES_RQST) { handleTreatmentTimeChangeRequest(i.value()); _treatmentRcvdMessages[i.key()].clear(); } } } } void StateController::handleTreatmentTimeChangeRequest(const QVariant &payload) { quint32 accept = REJECT_VALUE; qint32 IDIndex = 0; Types::U32 txDurMinType; GetValue(payload.toByteArray(), IDIndex, txDurMinType); quint32 txDurMin = txDurMinType.value; quint32 elapsedTimeMins = _treatmentVars.treatmentElapsedTimeS / SECONDS_PER_MINUTE; if ((txDurMin > elapsedTimeMins) && (txDurMin >= MIN_TX_TIME_MINS)) { float UFVolumeL = ((txDurMin - elapsedTimeMins) * _treatmentVars.prescribedUFRate) + _treatmentVars.refUFVolumeML; UFVolumeL /= MILLILITERS_PER_LITER; // Upper and lower range values are from #defines quint32 dialVolume = _treatmentParams.dialysateFlowRateMLPM * txDurMin; bool isMinTxTimeValid = (txDurMin >= MIN_TX_TIME_MINS ? true : false); bool isTxTimeValid = (txDurMin <= MAX_TX_TIME_MINS ? true : false); bool isMinUFVolValid = ((UFVolumeL >= MIN_UF_VOL_L) || (UFVolumeL <= 0.0) ? true : false); // TODO fix the UF Vol bool isUFVolValid = (UFVolumeL <= MAX_UF_VOL_L ? true : false); qDebug() << "Test of tx" << _treatmentVars.prescribedUFRate << elapsedTimeMins << UFVolumeL << isUFVolValid; if (isMinTxTimeValid && isTxTimeValid && isMinUFVolValid && isUFVolValid && (dialVolume <= MAX_DIALYSATE_VOLUME_ML)) { _treatmentVars.prescribedTreatmentTimeS = txDurMin * SECONDS_PER_MINUTE; _treatmentVars.prescribedMaxUFVolML = UFVolumeL * MILLILITERS_PER_LITER; accept = ACCEPT_VALUE; qDebug() << "New tx time" << txDurMin * SECONDS_PER_MINUTE << accept; } } QVariantList resp; resp.append(static_cast(ID_USER_TX_TIME_CHANGES_RESP)); resp.append(Can_Id::eChlid_HD_UI); resp.append(accept); resp.append(0); resp.append(_treatmentVars.prescribedTreatmentTimeS /SECONDS_PER_MINUTE); resp.append(_treatmentVars.prescribedMaxUFVolML); _isSendListReady = false; _sendMessages.append(resp); _isSendListReady = true; } qint32 StateController::handleMsgBBPayload(const QVariant &payload) { qint32 cmd = CMD_NONE; qint32 IDIndex = 0; Types::U32 param; GetValue(payload.toByteArray(), IDIndex, param); if (param.value == UI_MSG_BB_PAYLOAD_ID) { IDIndex = UI_MSG_BB_STATUS_INDEX; GetValue(payload.toByteArray(), IDIndex, param); cmd = param.value; } QVariantList msg; msg.append(static_cast(ID_HD_UI_CONFIRM_RQST)); msg.append(Can_Id::eChlid_HD_UI); msg.append(UI_MSG_BB_PAYLOAD_ID); msg.append(ACCEPT_VALUE); msg.append(0); _isSendListReady = false; _sendMessages.append(msg); _isSendListReady = true; return cmd; } // ----------- State transition methods ---------------- // void StateController::onIdleStateChange(bool active) { static State_Status status = STATE_ON_ENTRY; auto inEntry = [=](){ resetVariables(); prepareHDModeTransitionBroadcastData(MODE_STAN); _transitionEventsFromIdle.clear(); _transitionEventsFromIdle[CMD_TX_PARAMS ] = "Transition_2_Tx_Parms"; _transitionEventsFromIdle[CMD_WATER_SAMPLE ] = "Transition_2_Water_Sample"; _transitionEventsFromIdle[CMD_CONSUMABLES ] = "Transition_2_Consumables"; _transitionEventsFromIdle[CMD_DISPOSABLES ] = "Transition_2_Disposables"; _transitionEventsFromIdle[CMD_SYSTEM_PRIME ] = "Transition_2_Sys_Prime"; _transitionEventsFromIdle[CMD_BP_HR ] = "Transition_2_BP_HR"; _transitionEventsFromIdle[CMD_ULTRAFILTRATION ] = "Transition_2_Ultrafiltraion"; _transitionEventsFromIdle[CMD_CONNECTION ] = "Transition_2_Patient_Connection"; _transitionEventsFromIdle[CMD_START_TX ] = "Transition_2_Start_Tx"; _transitionEventsFromIdle[CMD_END_TX ] = "Transition_2_End_Tx"; _transitionEventsFromIdle[CMD_DISINFECTION ] = "Transition_2_Disinfect"; status = STATE_ON_ACTION; qDebug() << "Idle on entry"; }; auto inAction = [=](){ if (!_treatmentRcvdMessages[ID_UI_CONFIRM_RESP].isNull()) { qint32 cmd = handleMsgBBPayload(_treatmentRcvdMessages[ID_UI_CONFIRM_RESP]); User_Command_ID cmdIDEnum = static_cast(cmd); _treatmentRcvdMessages[ID_UI_CONFIRM_RESP].clear(); if ((cmdIDEnum > CMD_STAND_BY) && (cmdIDEnum < NUM_OF_USER_CMDS)) { qDebug() << "Submit event" << _transitionEventsFromIdle[cmdIDEnum]; _dryDemo.submitEvent(_transitionEventsFromIdle[cmdIDEnum]); status = STATE_ON_ENTRY; } qDebug() << "Idle in action" << cmdIDEnum; } }; auto inExit = [=](){ status = STATE_ON_ENTRY; }; switch (status) { // TODO macro it later case STATE_ON_ENTRY : if (active) inEntry (); break; case STATE_ON_ACTION: if (active) inAction(); break; case STATE_ON_EXIT : if (active) inExit (); break; } } void StateController::onTreatmentParamsStateChange(bool active) { static State_Status status = STATE_ON_ENTRY; auto inEntry = [=](){ prepareHDModeTransitionBroadcastData(MODE_TPAR); qDebug() << "In treatment params on entry"; status = STATE_ON_ACTION; _treatmentParams.hasTxParamsBeenInitialized = false; _hasUserConfirmedToProceed = false; }; auto inAction = [=]() { //qDebug() << "In treatment params on action"; handleTreatmentReceivedMessages(); if ((_treatmentParams.hasTxParamsBeenInitialized) && (_hasUserConfirmedToProceed)) { status = STATE_ON_EXIT; } if (!_treatmentRcvdMessages[ID_UI_CONFIRM_RESP].isNull()) { _dryDemo.submitEvent("Transition_back_2_idle"); status = STATE_ON_ENTRY; } }; auto inExit = [=](){ qDebug() << "In treatment params on exit"; status = STATE_ON_ENTRY; _dryDemo.submitEvent("T_2_Water_Sample"); }; switch (status) { // TODO macro it later case STATE_ON_ENTRY : if (active) inEntry (); break; case STATE_ON_ACTION: if (active) inAction(); break; case STATE_ON_EXIT : if (active) inExit (); break; } } void StateController::onWaterSampleStateChange(bool active) { static State_Status status = STATE_ON_ENTRY; static quint32 timerCountDownS = DEFAULT_TIMEOUT_S; auto inEntry = [=](){ qDebug() << "Water sample on entry"; QList preTxStates({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); prepareHDModeTransitionBroadcastData(MODE_PRET); preparePreTreatmentStatesBroadcastData(preTxStates); status = STATE_ON_ACTION; timerCountDownS = DEFAULT_TIMEOUT_S; _treatmentVars.broadcastIntervalCount = 0; }; auto inAction = [=]() { handleTreatmentReceivedMessages(); if (timerCountDownS != 0) { _treatmentVars.broadcastIntervalCount++; if (_treatmentVars.broadcastIntervalCount % NUM_OF_COUNTS_TIMER_BC_EMIT == 0) { timerCountDownS--; QVariantList msg; msg.append(static_cast(ID_FILTER_FLUSH_TIME_BC)); msg.append(Can_Id::eChlid_DG_Sync); msg.append(DEFAULT_TIMEOUT_S); msg.append(timerCountDownS); _isBroadcastListReady = false; _broadcastMessages.append(msg); _isBroadcastListReady = true; } } else { QList preTxStates({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); quint32 state = 1; quint32 stateIndex = 1; preTxStates[stateIndex] = state; preparePreTreatmentStatesBroadcastData(preTxStates); } if (!_treatmentRcvdMessages[ID_UI_CONFIRM_RESP].isNull()) { status = STATE_ON_ENTRY; _dryDemo.submitEvent("Transition_back_2_idle"); } if (timerCountDownS == 0) { if (!_treatmentRcvdMessages[ID_SAMPLE_WATER_RESULT].isNull()) { qint32 resultIndex = 0; Types::U32 param; GetValue(_treatmentRcvdMessages[ID_SAMPLE_WATER_RESULT].toByteArray(), resultIndex, param); if (param.value == ACCEPT_VALUE) { status = STATE_ON_EXIT; } else { status = STATE_ON_ENTRY; _dryDemo.submitEvent("Transition_back_2_idle"); } _treatmentRcvdMessages[ID_SAMPLE_WATER_RESULT].clear(); } } }; auto inExit = [=](){ qDebug() << "In treatment params on exit"; status = STATE_ON_ENTRY; _dryDemo.submitEvent("T_2_Consumables"); }; switch (status) { // TODO macro it later case STATE_ON_ENTRY : if (active) inEntry (); break; case STATE_ON_ACTION: if (active) inAction(); break; case STATE_ON_EXIT : if (active) inExit (); break; } } void StateController::onConsumablesStateChange(bool active) { static State_Status status = STATE_ON_ENTRY; static quint32 state = 0; static quint32 stateIndex = 2; auto inEntry = [=](){ qDebug() << "Consumables on entry"; state = 0; QList preTxStates({1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); preTxStates[stateIndex] = state; prepareHDModeTransitionBroadcastData(MODE_PRET); preparePreTreatmentStatesBroadcastData(preTxStates); status = STATE_ON_ACTION; _hasUserConfirmedToProceed = false; }; auto inAction = [=]() { if (_hasUserConfirmedToProceed) { qDebug() << " State " << state; if (state < 4) { state++; QList preTxStates({1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); preTxStates[stateIndex] = state; preparePreTreatmentStatesBroadcastData(preTxStates); } else { status = STATE_ON_EXIT; } } if (!_treatmentRcvdMessages[ID_UI_CONFIRM_RESP].isNull()) { status = STATE_ON_ENTRY; _dryDemo.submitEvent("Transition_back_2_idle"); } }; auto inExit = [=](){ qDebug() << "In consumables on exit"; status = STATE_ON_ENTRY; _dryDemo.submitEvent("T_2_Disposables"); }; switch (status) { // TODO macro it later case STATE_ON_ENTRY : if (active) inEntry (); break; case STATE_ON_ACTION: if (active) inAction(); break; case STATE_ON_EXIT : if (active) inExit (); break; } } void StateController::onDisposablesStateChange(bool active) { static State_Status status = STATE_ON_ENTRY; static quint32 timerCountDownS = DEFAULT_TIMEOUT_S; static quint32 stateNum = 0; static quint32 stateIndex = 3; auto inEntry = [=](){ qDebug() << "Disposables on entry"; stateNum = 0; QList preTxStates({2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); preTxStates[stateIndex] = stateNum; prepareHDModeTransitionBroadcastData(MODE_PRET); preparePreTreatmentStatesBroadcastData(preTxStates); status = STATE_ON_ACTION; _hasUserConfirmedToProceed = false; _treatmentVars.broadcastIntervalCount = 0; timerCountDownS = DEFAULT_TIMEOUT_S; }; auto inAction = [=]() { if (timerCountDownS != 0) { _treatmentVars.broadcastIntervalCount++; if (_treatmentVars.broadcastIntervalCount % NUM_OF_COUNTS_TIMER_BC_EMIT == 0) { timerCountDownS--; QVariantList msg; msg.append(static_cast(ID_HD_SYS_SELF_TEST_TIME_BC)); msg.append(Can_Id::eChlid_HD_Sync); msg.append(DEFAULT_TIMEOUT_S); msg.append(timerCountDownS); _isBroadcastListReady = false; _broadcastMessages.append(msg); _isBroadcastListReady = true; } } if (stateNum < 12) { stateNum++; QList preTxStates({2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); preTxStates[stateIndex] = stateNum; preparePreTreatmentStatesBroadcastData(preTxStates); } else if (timerCountDownS == 0) { QList preTxStates({3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); preparePreTreatmentStatesBroadcastData(preTxStates); if (_hasUserConfirmedToProceed) { qDebug() << "Disposables done"; status = STATE_ON_EXIT; } } if (!_treatmentRcvdMessages[ID_UI_CONFIRM_RESP].isNull()) { status = STATE_ON_ENTRY; _dryDemo.submitEvent("Transition_back_2_idle"); } }; auto inExit = [=](){ qDebug() << "In disposables on exit"; status = STATE_ON_ENTRY; _dryDemo.submitEvent("T_2_System_Prime"); }; switch (status) { // TODO macro it later case STATE_ON_ENTRY : if (active) inEntry (); break; case STATE_ON_ACTION: if (active) inAction(); break; case STATE_ON_EXIT : if (active) inExit (); break; } } void StateController::onSystemPrimeStateChange(bool active) { qDebug() << active; //switch (status) { // TODO macro it later //case STATE_ON_ENTRY : if (active) inEntry (); break; //case STATE_ON_ACTION: if (active) inAction(); break; //case STATE_ON_EXIT : if (active) inExit (); break; //} } void StateController::onBPHRStateChange(bool active) { if (active) { qDebug() << "BP/HR active"; //QVariantList msg = _dryDemoCmds[_dryDemoCurrentCmd][_index].mid(RESP_MSG_START_INDEX); //emit _ApplicationController.didActionTransmit(msg); } } void StateController::onUltrafiltrationStateChange(bool active) { if (active) { qDebug() << "Ultrafiltraion active"; } } void StateController::onConnectionStateChange(bool active) { if(active) { qDebug() << "Connection active"; //QVariantList msg = _dryDemoCmds[_dryDemoCurrentCmd][_index].mid(RESP_MSG_START_INDEX); //emit _ApplicationController.didActionTransmit(msg); } } void StateController::onStartTreatmentStateChange(bool active) { static State_Status status = STATE_ON_ENTRY; auto inEntry = [=](){ qDebug() << "Start Treatment active"; resetVariables(); QVariantList msg; msg.append(static_cast(ID_HD_OP_MODE)); msg.append(Can_Id::eChlid_HD_Sync); msg.append(MODE_TREA); msg.append(0); _isBroadcastListReady = false; _broadcastMessages.append(msg); _isBroadcastListReady = true; msg.clear(); msg.append(1); msg.append(0); msg.append(0); msg.append(0); msg.append(0); msg.append(0); msg.append(0); msg.append(0); msg.append(0); msg.append(0); msg.append(0); prepareTreatmentStatesBroadcastData(msg); QVariant emptyVariantList; setTreatmentParams(false, emptyVariantList); status = STATE_ON_EXIT; }; auto inAction = [](){}; auto inExit = [=](){ status = STATE_ON_ENTRY; _dryDemo.submitEvent("Start_Tx_2_Blood_Prime"); }; switch (status) { // TODO macro it later case STATE_ON_ENTRY : if (active) inEntry (); break; case STATE_ON_ACTION: if (active) inAction(); break; case STATE_ON_EXIT : if (active) inExit (); break; } } void StateController::onTreatmentBloodPrimeStateChange(bool active) { static State_Status status = STATE_ON_ENTRY; auto inEntry = [=](){ resetVariables(); qDebug() << "Blood prime entry"; status = STATE_ON_ACTION; }; auto inAction = [=](){ _treatmentVars.broadcastIntervalCount++; _treatmentVars.accumulatedVolumeML += (DEF_TX_PARAM_BLOOD_FLOW_RATE_MLPM * BLOOD_FLOW_INTEGRATOR); if (_treatmentVars.broadcastIntervalCount % NUM_OF_COUNTS_TIMER_BC_EMIT == 0) { QVariantList msg; msg.append(static_cast(ID_HD_BLOOD_PRIME_BC)); msg.append(Can_Id::eChlid_HD_Sync); msg.append(BLOOD_PRIME_VOLUME_ML); msg.append(_treatmentVars.accumulatedVolumeML); _isBroadcastListReady = false; _broadcastMessages.append(msg); _isBroadcastListReady = true; prepareOcclusionBroadcastData(); prepareTreatmentParamsRangesBroadcastData(); } if (_treatmentVars.accumulatedVolumeML > BLOOD_PRIME_VOLUME_ML) { // send blood prime value on last time QVariantList msg; msg.append(static_cast(ID_HD_BLOOD_PRIME_BC)); msg.append(Can_Id::eChlid_HD_Sync); msg.append(BLOOD_PRIME_VOLUME_ML); msg.append(_treatmentVars.accumulatedVolumeML); _isBroadcastListReady = false; _broadcastMessages.append(msg); _isBroadcastListReady = true; status = STATE_ON_EXIT; } if (!_treatmentRcvdMessages[ID_UI_CONFIRM_RESP].isNull()) { status = STATE_ON_ENTRY; _dryDemo.submitEvent("Transition_back_2_idle"); } }; auto inExit = [=](){ qDebug() << "Blood prime exit"; status = STATE_ON_ENTRY; _dryDemo.submitEvent("Blood_Prime_2_Treatment"); }; switch (status) { // TODO macro it later case STATE_ON_ENTRY : if (active) inEntry (); break; case STATE_ON_ACTION: if (active) inAction(); break; case STATE_ON_EXIT : if (active) inExit (); break; } } void StateController::onTreatmentTreatmentStateChange(bool active) { static State_Status status = STATE_ON_ENTRY; handleTreatmentReceivedMessages(); auto inEntry = [=](){ resetVariables(); qDebug() << "Treatment Treatment state"; _treatmentVars.prescribedTreatmentTimeS = _treatmentParams.txDurationMins * SECONDS_PER_MINUTE; _treatmentVars.treatmentElapsedTimeS = DEF_TX_ELAPSED_TIME_S; _treatmentVars.remainingTreatmentTimeS = _treatmentVars.prescribedTreatmentTimeS - _treatmentVars.treatmentElapsedTimeS; _treatmentVars.prescribedMaxUFVolML = DEF_TX_PARAM_UF_VOLUME_L * MILLILITERS_PER_LITER; // TODO from tx params _treatmentVars.prescribedUFRate = _treatmentVars.prescribedMaxUFVolML / _treatmentParams.txDurationMins; _treatmentVars.refUFVolumeML = (_treatmentVars.treatmentElapsedTimeS / SECONDS_PER_MINUTE) * _treatmentVars.prescribedUFRate; status = STATE_ON_ACTION; }; auto inAction = [=](){ _treatmentVars.broadcastIntervalCount++; float timeSinceLastCallMS = static_cast(QOBJECT_TIMER_TIMEOUT_MS) / static_cast(MILLISECONDS_PER_SECOND); _treatmentVars.refUFVolumeML += (timeSinceLastCallMS / SECONDS_PER_MINUTE) * _treatmentVars.prescribedUFRate; _treatmentVars.measUFVolumeML = _treatmentVars.refUFVolumeML; //qDebug() << "UF Va;ue" << QTime::currentTime() << _treatmentVars.refUFVolumeML << _treatmentVars.prescribedUFRate; if (_treatmentVars.broadcastIntervalCount % NUM_OF_COUNTS_TIMER_BC_EMIT == 0) { QVariantList msg; msg.append(2); msg.append(1); msg.append(0); msg.append(0); msg.append(0); msg.append(0); msg.append(0); msg.append(0); msg.append(0); msg.append(0); msg.append(0); prepareTreatmentStatesBroadcastData(msg); prepareOcclusionBroadcastData(); prepareTreatmentTimeBroadcastData(); prepareBloodFlowBroadcastData(); prepareDialysateFlowBroadcastData(); prepareDialysateOutFlowBroadcastData(); prepareTreatmentParamsRangesBroadcastData(); } //qDebug() << "Target treatment" << _treatmentVars.prescribedTreatmentTimeS; if (_treatmentVars.remainingTreatmentTimeS <= 0 ) { status = STATE_ON_EXIT; } if (!_treatmentRcvdMessages[ID_UI_CONFIRM_RESP].isNull()) { status = STATE_ON_ENTRY; _dryDemo.submitEvent("Transition_back_2_idle"); } }; auto inExit = [=](){ qDebug() << "Treat Treatment exit"; status = STATE_ON_ENTRY; _dryDemo.submitEvent("Treatment_2_End_Treatment"); // TODO bring back }; switch (status) { // TODO macro it later case STATE_ON_ENTRY : if (active) inEntry (); break; case STATE_ON_ACTION: if (active) inAction(); break; case STATE_ON_EXIT : if (active) inExit (); break; } } void StateController::onEndTreatmentStateChange(bool active) { if (active) { qDebug() << "Treatment end active"; //QVariantList msg = _dryDemoCmds[_dryDemoCurrentCmd][_index].mid(RESP_MSG_START_INDEX); //emit _ApplicationController.didActionTransmit(msg); } } void StateController::onDisinfectStateChange(bool active) { if (active) { qDebug() << "Disinfect active"; QVariantList msg = _dryDemoCmds[_dryDemoCurrentCmd][_index].mid(RESP_MSG_START_INDEX); emit _ApplicationController.didActionTransmit(msg); } else { qDebug() << "Disinfect exit"; } }