Index: sources/StateController.cpp =================================================================== diff -u -rac917f2cc891cabeae3edbd353b72d00c3637fcd -rbf25cc43f3a623f45cadd0c3449838bfe24688c2 --- sources/StateController.cpp (.../StateController.cpp) (revision ac917f2cc891cabeae3edbd353b72d00c3637fcd) +++ sources/StateController.cpp (.../StateController.cpp) (revision bf25cc43f3a623f45cadd0c3449838bfe24688c2) @@ -31,12 +31,9 @@ _dryDemo.connectToState("Disinfect" , this, &StateController::onDisinfectStateChange ); - _dryDemoCurrentCmd = CMD_NONE; - // Start with uninitialized treatment params - _treatmentParams.hasTxParamsBeenInitialized = false; + _treatmentParams.hasTxParamsBeenInitialized = false; // TODO remove resetVariables(); - initMessagesHashTable(); // Todo remove this once the state machine is finished. } void StateController::quit() @@ -52,12 +49,11 @@ } MessageID receivedMsgID = static_cast(msg[0].toUInt()); - QVariantList msgBack; switch(receivedMsgID) { case ID_UI_RQST_TX: - _dryDemoCurrentCmd = CMD_TX_PARAMS; + // TODO fix this to start break; case ID_UI_TX_PARAMS_RQST: @@ -85,38 +81,24 @@ break; case ID_UI_PATIENT_CONNECTION_RQST: - _hasUserConfirmedToProceed = true; - _dryDemoCurrentCmd = CMD_BP_HR; - break; + _hasUserConfirmedToProceed = true; + 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; + _treatmentRcvdMessages[receivedMsgID] = msg[1]; + 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; + _hasUserConfirmedToProceed = true; + break; case ID_UI_START_TX_RQST: - _hasUserConfirmedToProceed = true; - break; + _hasUserConfirmedToProceed = true; + break; case ID_USER_TX_TIME_CHANGES_RQST: - _treatmentRcvdMessages[receivedMsgID] = msg[1]; - break; + _treatmentRcvdMessages[receivedMsgID] = msg[1]; + break; case ID_NONE: case ID_HD_BLOOD_FLOW_DATA_BC: @@ -157,689 +139,6 @@ } // ---------------------- 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; @@ -849,7 +148,6 @@ _currentCounterValue = COUNTER_VAR_DEFAULT_VALUE; _prescribedTreatmentTimeS = PRESC_TIME_DEFAULT_VALUE; - _stateStatus = STATE_ON_ENTRY; _isBroadcastListReady = false; _isSendListReady = false; @@ -1163,11 +461,6 @@ // 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(); @@ -1245,6 +538,94 @@ return cmd; } +bool StateController::hasPreTxTimerElapsed(Can::Message_ID_Enum msgID, Can::Can_Id canChan, + quint32 &timerCountDownS, quint32 defaultTimeoutS) +{ + bool hasTimeElapsed = false; + + QVariantList msg; + msg.append(static_cast(msgID)); + msg.append(canChan); + + if ((_treatmentVars.broadcastIntervalCount % NUM_OF_COUNTS_TIMER_BC_EMIT == 0) && + (timerCountDownS != 0)) { + timerCountDownS--; + + msg.append(defaultTimeoutS); + msg.append(timerCountDownS); + _isBroadcastListReady = false; + _broadcastMessages.append(msg); + _isBroadcastListReady = true; + } + + if (timerCountDownS == defaultTimeoutS) { + // Send a start broadcast to start from a known value + msg.append(defaultTimeoutS); + msg.append(timerCountDownS); + _isBroadcastListReady = false; + _broadcastMessages.append(msg); + _isBroadcastListReady = true; + } + + if (timerCountDownS == 0) { + hasTimeElapsed = true; + } + + return hasTimeElapsed; +} + +void StateController::handleUltrafiltrationValidation(const QVariant &payload) +{ + // From validateAndSetUFVolume function in HD + quint32 accept = REJECT_VALUE; + qint32 ufIndex = 0; + Types::F32 param; + GetValue(payload.toByteArray(), ufIndex, param); + + float ufVolL = param.value / MILLILITERS_PER_LITER; + + if ((ufVolL >= MIN_UF_VOL_L) && (ufVolL <= MAX_UF_VOL_L)) { + accept = ACCEPT_VALUE; + _treatmentVars.txParamsUFVolL = ufVolL; + } + + if (accept == ACCEPT_VALUE) { + /* + * Before checking for the UF rate, treatment duration is needed. + * The user might select UF from dry demo without going to treatment params + * So setTreatmentParams is called first. If the treatment params have been set already + * then nothing is updated we can continue with verifying the UF + */ + QVariant emptyList; + setTreatmentParams(false, emptyList); + + if (_treatmentParams.txDurationMins > 0) { + float ufRate = param.value / _treatmentParams.txDurationMins; + qDebug() << "UF rate" << ufRate; + if ((ufRate > MAX_UF_RATE_MLPM) || (ufRate < MIN_UF_RATE_MLPM)) { + accept = REJECT_VALUE; + } + } + else + { + accept = REJECT_VALUE; + } + } + + QVariantList msg; + msg.clear(); + msg.append(static_cast(ID_HD_SET_UF_VOLUME_RESP)); + msg.append(Can_Id::eChlid_HD_UI); + msg.append(accept); + msg.append(0); + msg.append(_treatmentVars.txParamsUFVolL * MILLILITERS_PER_LITER); + _isSendListReady = false; + _sendMessages.append(msg); + _isSendListReady = true; +} + + + // ----------- State transition methods ---------------- // void StateController::onIdleStateChange(bool active) { @@ -1314,8 +695,12 @@ auto inAction = [=]() { //qDebug() << "In treatment params on action"; - handleTreatmentReceivedMessages(); + if (!_treatmentRcvdMessages[ID_UI_TX_PARAMS_RQST].isNull()) { + setTreatmentParams(true, _treatmentRcvdMessages[ID_UI_TX_PARAMS_RQST]); + _treatmentRcvdMessages[ID_UI_TX_PARAMS_RQST].clear(); + } + if ((_treatmentParams.hasTxParamsBeenInitialized) && (_hasUserConfirmedToProceed)) { status = STATE_ON_EXIT; } @@ -1355,24 +740,13 @@ }; auto inAction = [=]() { - handleTreatmentReceivedMessages(); + _treatmentVars.broadcastIntervalCount++; - if (timerCountDownS != 0) { - _treatmentVars.broadcastIntervalCount++; - if (_treatmentVars.broadcastIntervalCount % NUM_OF_COUNTS_TIMER_BC_EMIT == 0) { - timerCountDownS--; + bool hasTimeElapsed = hasPreTxTimerElapsed(ID_FILTER_FLUSH_TIME_BC, eChlid_DG_Sync, + timerCountDownS, DEFAULT_TIMEOUT_S); - 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 { + if (hasTimeElapsed) { + QList preTxStates({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); quint32 state = 1; quint32 stateIndex = 1; @@ -1385,12 +759,13 @@ _dryDemo.submitEvent("Transition_back_2_idle"); } - if (timerCountDownS == 0) { + if (hasTimeElapsed) { if (!_treatmentRcvdMessages[ID_SAMPLE_WATER_RESULT].isNull()) { qint32 resultIndex = 0; Types::U32 param; GetValue(_treatmentRcvdMessages[ID_SAMPLE_WATER_RESULT].toByteArray(), resultIndex, param); + qDebug() << "Counter" << timerCountDownS << param.value; if (param.value == ACCEPT_VALUE) { status = STATE_ON_EXIT; } @@ -1437,7 +812,7 @@ auto inAction = [=]() { if (_hasUserConfirmedToProceed) { qDebug() << " State " << state; - if (state < 4) { + if (state < 4) { // TODO #define for this state++; QList preTxStates({1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); preTxStates[stateIndex] = state; @@ -1488,30 +863,17 @@ }; auto inAction = [=]() { + _treatmentVars.broadcastIntervalCount++; - 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; - } - } - + bool hasTimeElapsed = hasPreTxTimerElapsed(ID_HD_SYS_SELF_TEST_TIME_BC, eChlid_HD_Sync, + timerCountDownS, DEFAULT_TIMEOUT_S); 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) { + else if (hasTimeElapsed) { QList preTxStates({3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); preparePreTreatmentStatesBroadcastData(preTxStates); @@ -1542,39 +904,217 @@ void StateController::onSystemPrimeStateChange(bool active) { + static State_Status status = STATE_ON_ENTRY; + static quint32 timerCountDownS = DEFAULT_TIMEOUT_S; + static quint32 stateNum = 0; + static quint32 stateIndex = 5; + static bool hasPrimeCompleted = false; - qDebug() << active; + auto inEntry = [=](){ + qDebug() << "Prime on entry"; + stateNum = 0; + stateIndex = 5; + QList preTxStates({4, 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; + hasPrimeCompleted = false; + }; + auto inAction = [=](){ + _treatmentVars.broadcastIntervalCount++; - //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; - //} + bool hasTimeElapsed = false; + + // First we do the prime section, then priming + if (!hasPrimeCompleted) { + hasTimeElapsed = hasPreTxTimerElapsed(ID_HD_DRY_SELF_TEST_TIME_BC, eChlid_HD_Sync, + timerCountDownS, DEFAULT_TIMEOUT_S); + if (stateNum < 15) { + stateNum++; + QList preTxStates({4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); + preTxStates[stateIndex] = stateNum; + preparePreTreatmentStatesBroadcastData(preTxStates); + } + else if (hasTimeElapsed) { + hasPrimeCompleted = true; + stateNum = 0; + timerCountDownS = DEFAULT_TIMEOUT_S; + QList preTxStates({5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); + preparePreTreatmentStatesBroadcastData(preTxStates); + } + } + else { + hasTimeElapsed = hasPreTxTimerElapsed(ID_HD_PRIMING_TIME_BC, eChlid_HD_Sync, + timerCountDownS, DEFAULT_TIMEOUT_S); + + if (stateNum < 12) { + stateNum++; + stateIndex = 6; + QList preTxStates({5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); + preTxStates[stateIndex] = stateNum; + preparePreTreatmentStatesBroadcastData(preTxStates); + } + else if (hasTimeElapsed) { + QList preTxStates({6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); + preparePreTreatmentStatesBroadcastData(preTxStates); + + if (_hasUserConfirmedToProceed) { + 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_BP_HR"); + }; + + 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); + static State_Status status = STATE_ON_ENTRY; + + auto inEntry = [=](){ + qDebug() << "BP/HR on entry"; + QList preTxStates({7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); + prepareHDModeTransitionBroadcastData(MODE_PRET); + preparePreTreatmentStatesBroadcastData(preTxStates); + status = STATE_ON_ACTION; + _hasUserConfirmedToProceed = false; + }; + + auto inAction = [=](){ + 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 BP/HR on exit"; + status = STATE_ON_ENTRY; + _dryDemo.submitEvent("T_2_Ultrafiltration"); + }; + + 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::onUltrafiltrationStateChange(bool active) { - if (active) { - qDebug() << "Ultrafiltraion active"; + static State_Status status = STATE_ON_ENTRY; + + auto inEntry = [=](){ + qDebug() << "UF on entry"; + QList preTxStates({7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); + prepareHDModeTransitionBroadcastData(MODE_PRET); + preparePreTreatmentStatesBroadcastData(preTxStates); + status = STATE_ON_ACTION; + _hasUserConfirmedToProceed = false; + }; + + auto inAction = [=](){ + if (!_treatmentRcvdMessages[ID_UI_SET_UF_VOLUME_RQST].isNull()) { + handleUltrafiltrationValidation(_treatmentRcvdMessages[ID_UI_SET_UF_VOLUME_RQST]); + _treatmentRcvdMessages[ID_UI_SET_UF_VOLUME_RQST].clear(); + 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 UF on exit"; + status = STATE_ON_ENTRY; + _dryDemo.submitEvent("T_2_Connection"); + }; + + 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::onConnectionStateChange(bool active) { - if(active) { - qDebug() << "Connection active"; - //QVariantList msg = _dryDemoCmds[_dryDemoCurrentCmd][_index].mid(RESP_MSG_START_INDEX); - //emit _ApplicationController.didActionTransmit(msg); + static State_Status status = STATE_ON_ENTRY; + static bool isConnectionDone = false; + + auto inEntry = [=](){ + qDebug() << "Connection on entry"; + QList preTxStates({7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); + prepareHDModeTransitionBroadcastData(MODE_PRET); + preparePreTreatmentStatesBroadcastData(preTxStates); + status = STATE_ON_ACTION; + isConnectionDone = false; + _hasUserConfirmedToProceed = false; + }; + + auto inAction = [=](){ + + if(_hasUserConfirmedToProceed) { + if (!isConnectionDone) { + _hasUserConfirmedToProceed = false; + isConnectionDone = true; + + QVariantList msg; + msg.clear(); + msg.append(static_cast(ID_HD_PATINET_CONNECTION_CONF_RESP)); + msg.append(Can_Id::eChlid_HD_UI); + msg.append(ACCEPT_VALUE); + msg.append(0); + _isSendListReady = false; + _sendMessages.append(msg); + _isSendListReady = true; + } + 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 Connection on exit"; + status = STATE_ON_ENTRY; + _dryDemo.submitEvent("T_2_Start_Tx"); + }; + + 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; } } @@ -1628,6 +1168,17 @@ auto inEntry = [=](){ resetVariables(); qDebug() << "Blood prime entry"; + + 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(0.0); + _isBroadcastListReady = false; + _broadcastMessages.append(msg); + _isBroadcastListReady = true; + prepareOcclusionBroadcastData(); + status = STATE_ON_ACTION; }; @@ -1693,7 +1244,7 @@ _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.prescribedMaxUFVolML = _treatmentVars.txParamsUFVolL * MILLILITERS_PER_LITER; _treatmentVars.prescribedUFRate = _treatmentVars.prescribedMaxUFVolML / _treatmentParams.txDurationMins; _treatmentVars.refUFVolumeML = (_treatmentVars.treatmentElapsedTimeS / SECONDS_PER_MINUTE) * _treatmentVars.prescribedUFRate;