#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; resetVariables(); initMessagesHashTable(); // Todo move this? } 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()); bool isCmdValid = false; QVariantList msgBack; switch(receivedMsgID) { case ID_UI_RQST_TX: isCmdValid = true; _dryDemoCurrentCmd = CMD_TX_PARAMS; break; case ID_UI_TX_PARAMS_RQST: msgBack.clear(); msgBack.append(static_cast(ID_HD_NEW_PARAMS_RESP)); msgBack.append(Can_Id::eChlid_HD_UI); msgBack.append(1); msgBack.append(0); msgBack.append(275); msgBack.append(250); msgBack.append(60); msgBack.append(0); msgBack.append(100); msgBack.append(0); msgBack.append(0); msgBack.append(0); msgBack.append(0); msgBack.append(0); msgBack.append(250); msgBack.append(120); msgBack.append(100); msgBack.append(20); msgBack.append(0.000); msgBack.append(0.000); msgBack.append(36.00); emit _ApplicationController.didActionTransmit(msgBack); break; case ID_UI_CONFIRM_RESP: { int IDIndex = 0; Types::U32 IDParam; GetValue(msg[1].toByteArray(), IDIndex, IDParam); if (IDParam.value == UI_MSG_BB_PAYLOAD_ID) { int cmdIndex = UI_MSG_DD_STATUS_INDEX; Types::U32 cmdParam; GetValue(msg[1].toByteArray(), cmdIndex, cmdParam); User_Command_ID cmdIDEnum = static_cast(cmdParam.value); if ((cmdIDEnum > CMD_NONE) && (cmdIDEnum < NUM_OF_USER_CMDS)) { _dryDemoCurrentCmd = cmdIDEnum; isCmdValid = true; qDebug() << "Msg Case 2" << receivedMsgID << cmdParam.value << _dryDemoCurrentCmd <(ID_HD_UI_CONFIRM_RQST)); msgBack.append(Can_Id::eChlid_HD_UI); msgBack.append(UI_MSG_BB_PAYLOAD_ID); msgBack.append(1); msgBack.append(0); emit _ApplicationController.didActionTransmit(msgBack); } } } break; case ID_UI_CONFIRM_TX_PARAMS: isCmdValid = true; _dryDemoCurrentCmd = CMD_WATER_SAMPLE; break; case ID_SAMPLE_WATER_RESULT: { isCmdValid = true; int resultIndex = 0; Types::U32 resultParam; GetValue(msg[1].toByteArray(), resultIndex, resultParam); if ( resultParam.value == 1 ) { _dryDemoCurrentCmd = CMD_CONSUMABLES; } else { _dryDemoCurrentCmd = CMD_NONE; transitionApplicationToStandBy(); } } break; case ID_UI_CONSUMABLES_INSTALL: _hasUserConfirmedToProceed = true; break; case ID_UI_INTALLATION_CONFIRM: _hasUserConfirmedToProceed = true; _dryDemoCurrentCmd = CMD_SYSTEM_PRIME; isCmdValid = true; break; case ID_UI_PATIENT_CONNECTION_RQST: _hasUserConfirmedToProceed = true; _dryDemoCurrentCmd = CMD_BP_HR; isCmdValid = 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; isCmdValid = true; 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; isCmdValid = true; 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_PRESSURE_OCCLUSION_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; } if ((isCmdValid) && (_dryDemo.isRunning())) { isCmdValid = false; _dryDemo.submitEvent("Transition_back_2_idle"); } } void StateController::timerEvent(QTimerEvent *) { _dryDemo.submitEvent("TimeoutEvent"); //qDebug() << "Index" << _index << listSize; if (_isBoradcastListReady) { sendMessages(true); } if (_isSendListReady) { sendMessages(false); } quint16 listSize = _dryDemoCmds[_dryDemoCurrentCmd].size(); if (_dryDemoCurrentCmd != CMD_START_TX) { if ((listSize > 1) && (_index < listSize)) { int counterType = _dryDemoCmds[_dryDemoCurrentCmd][_index][IS_TIMER_INDEX].toInt(); Counter_Type counterTypeEnum = static_cast(counterType); //qDebug() << "Counter Type" << _dryDemoCurrentCmd << _index << counterTypeEnum; //if (_dryDemoCmds[_dryDemoCurrentCmd][_index][IS_TIMER_INDEX].toBool()) { if (counterTypeEnum != COUNTER_NONE) { if (_timerBroadcastCount >= NUM_OF_COUNTS_TIMER_BC_EMIT) { QVariant tempVar; QVariantList msg; switch ( counterTypeEnum) { case COUNTER_NONE: // Do nothing break; case COUNTER_PRE_TX_TIMERS: if (_currentCounterValue < 0) { _currentCounterValue = _dryDemoCmds[_dryDemoCurrentCmd][_index][COUNT_DOWN_TIMER_INDEX].toUInt(); } _currentCounterValue--; _timerBroadcastCount = 0; tempVar = _dryDemoCmds[_dryDemoCurrentCmd][_index].mid(RESP_MSG_START_INDEX); msg = tempVar.toList(); msg[COUNT_DOWN_TIMER_INDEX - RESP_MSG_START_INDEX] = _currentCounterValue; //qDebug() << "Counters Pre Tx" << _currentCounterValue << _dryDemoCmds[_dryDemoCurrentCmd][_index][COUNT_DOWN_TIMER_INDEX].toUInt(); emit _ApplicationController.didActionTransmit(msg); break; case COUNTER_TX_TIMER: /* if ((_currentCounterValue < 0) && (_prescribedTreatmentTimeS < 0)) { _prescribedTreatmentTimeS = _dryDemoCmds[_dryDemoCurrentCmd][_index][TIME_PRESCRIBED_S_INDEX].toUInt(); quint32 elapsedTimeS = _dryDemoCmds[_dryDemoCurrentCmd][_index][TIME_ELAPSED_S_INDEX].toUInt(); _currentCounterValue = _prescribedTreatmentTimeS - elapsedTimeS; } _currentCounterValue--; _timerBroadcastCount = 0; tempVar = _dryDemoCmds[_dryDemoCurrentCmd][_index].mid(RESP_MSG_START_INDEX); msg = tempVar.toList(); msg[TIME_PRESCRIBED_S_INDEX - RESP_MSG_START_INDEX] = _prescribedTreatmentTimeS; msg[TIME_REMAINING_S_INDEX - RESP_MSG_START_INDEX] = _currentCounterValue; qDebug() << "Counters Tx" << _currentCounterValue << _dryDemoCmds[_dryDemoCurrentCmd][_index]; emit _ApplicationController.didActionTransmit(msg); */ break; case COUNTER_RINSEBACK_TIMER: break; } if (_currentCounterValue == 0) { _index++; _currentCounterValue = COUNTER_VAR_DEFAULT_VALUE; } } else { _timerBroadcastCount++; } } else { if (_broadcastMsgCount <= NUM_OF_COUNTS_TO_BC_MSG) { emit _ApplicationController.didActionTransmit(_dryDemoCmds[_dryDemoCurrentCmd][_index].mid(RESP_MSG_START_INDEX)); _broadcastMsgCount++; } bool isWaitNeeded = _dryDemoCmds[_dryDemoCurrentCmd][_index][IS_WAIT_NEEDED_INDEX].toBool(); if ((!isWaitNeeded) || (isWaitNeeded && _hasUserConfirmedToProceed)) { //qDebug() << "Nex Inedx" << _dryDemoCmds[_dryDemoCurrentCmd][_index]; if (_broadcastMsgCount > NUM_OF_COUNTS_TO_BC_MSG) { int nextCmd = _dryDemoCmds[_dryDemoCurrentCmd][_index][NEXT_AUTO_TRANSITION_INDEX].toInt(); User_Command_ID nextCmdEnum = static_cast(nextCmd); qDebug() << "NONE" << nextCmd << nextCmdEnum; if (nextCmdEnum != CMD_NONE) { qDebug() << "Current Enum" << _dryDemoCurrentCmd; _dryDemoCurrentCmd = nextCmdEnum; qDebug() << "New transition" << nextCmdEnum << _dryDemoCurrentCmd << _index; _dryDemo.submitEvent("Transition_back_2_idle"); } _index++; _broadcastMsgCount = 0; _hasUserConfirmedToProceed = 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::transitionApplicationToStandBy() { resetVariables(); QVariantList list; list.append(static_cast(ID_HD_OP_MODE)); list.append(Can_Id::eChlid_HD_Sync); list.append(MODE_STAN); list.append(0); emit _ApplicationController.didActionTransmit(list); } 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; _isBoradcastListReady = false; _isSendListReady = false; _treatmentVars.accumulatedVolumeML = 0.0; _treatmentVars.broadcastIntervalCount = 0; _treatmentVars.treatmentElapsedTimeS = 0; _treatmentVars.treatmentElapsedTimeS = 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::prepareOcclusionBroadcastData() { 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); _broadcastMessages.append(msg); } void StateController::prepareTreatmentTimeBroadcastData() { _treatmentVars.treatmentElapsedTimeS++; _treatmentVars.remainingTreatmentTimeS = _treatmentVars.prescribedTreatmentTimeS - _treatmentVars.treatmentElapsedTimeS; //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); _broadcastMessages.append(msg); } 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); } _broadcastMessages.append(msg); } void StateController::handleTreatmentReceivedMessages() { for (auto i = _treatmentRcvdMessages.begin(), end = _treatmentRcvdMessages.end(); i != end; ++i) { //qDebug() << "Hash Message" << i.key() << i.value(); if (i.key() == ID_USER_TX_TIME_CHANGES_RQST) { handleTreatmentTimeChangeRequest(i.value()); } } _treatmentRcvdMessages.clear(); } void StateController::handleTreatmentTimeChangeRequest(const QVariant &payload) { quint32 accept = REJECT_VALUE; int 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; // TODO from treatment params quint32 dialVolume = 600 * txDurMin; // TODO treatment params bool isMinTxTimeValid = (txDurMin >= MIN_TX_TIME_MINS ? true : false); bool isTxTimeValid = (txDurMin <= TX_PARAM_PRESCRIBED_DUR_S ? true : false); bool isMinUFVolValid = ((UFVolumeL >= 0.0) || (UFVolumeL <= 0.0) ? true : false); // TODO fix the UF Vol bool isUFVolValid = (UFVolumeL <= TX_PARAM_UF_VOLUME_L ? true : false); qDebug() << "Test of tx" << _treatmentVars.prescribedUFRate << elapsedTimeMins << UFVolumeL << isUFVolValid; if (isMinTxTimeValid && isTxTimeValid && isMinUFVolValid && isUFVolValid && (dialVolume <= MAX_DIALYSATE_VOLUME_ML)) { // TODO set UF values _treatmentVars.prescribedTreatmentTimeS = txDurMin * SECONDS_PER_MINUTE; _treatmentVars.prescribedMaxUFVolML = UFVolumeL * MILLILITERS_PER_LITER; accept = ACCEPT_VALUE; qDebug() << "New tx time" << txDurMin * SECONDS_PER_MINUTE << accept; } } _isSendListReady = false; 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); resp.append(_treatmentVars.prescribedMaxUFVolML); _sendMessages.append(resp); _isSendListReady = true; } // ----------- State transition methods ---------------- // void StateController::onIdleStateChange(bool active) { if (active) { qDebug() << "Idle on entry" << _dryDemoCurrentCmd; // TODO remove if (_dryDemoCurrentCmd == CMD_START_TX) { qDebug() << "Treatment event stareted"; _dryDemo.submitEvent("Transition_2_Start_Tx"); } else if ((_dryDemoCmds.contains(_dryDemoCurrentCmd)) && (_dryDemoCurrentCmd != CMD_NONE)) { transitionApplicationToStandBy(); QString transitionEvent = _dryDemoCmds[_dryDemoCurrentCmd][_index][TRANSITION_EVENT_INDEX].toString(); qDebug() << "Event" << transitionEvent <<_dryDemoCurrentCmd << _index; _dryDemo.submitEvent(transitionEvent); } } else { if (_dryDemoCurrentCmd != CMD_START_TX) { qDebug() << "Idle on exit!"; QVariantList msg = _dryDemoCmds[_dryDemoCurrentCmd][_index].mid(RESP_MSG_START_INDEX); emit _ApplicationController.didActionTransmit(msg); _index++; } } } void StateController::onTreatmentParamsStateChange(bool active) { if (active) { qDebug() << "In treatment params on entry"; } } void StateController::onWaterSampleStateChange(bool active) { if(active) { qDebug() << "Sample" << _index; QVariantList msg = _dryDemoCmds[_dryDemoCurrentCmd][_index].mid(RESP_MSG_START_INDEX); emit _ApplicationController.didActionTransmit(msg); } else { qDebug() << "Sample inactive"; } } void StateController::onConsumablesStateChange(bool active) { if(active) { qDebug() << "Consumables" << _index; QVariantList msg = _dryDemoCmds[_dryDemoCurrentCmd][_index].mid(RESP_MSG_START_INDEX); emit _ApplicationController.didActionTransmit(msg); } } void StateController::onDisposablesStateChange(bool active) { if(active) { qDebug() << "Disposables" << _index; QVariantList msg = _dryDemoCmds[_dryDemoCurrentCmd][_index].mid(RESP_MSG_START_INDEX); emit _ApplicationController.didActionTransmit(msg); } } void StateController::onSystemPrimeStateChange(bool active) { if (active) { qDebug() << "Prime active"; QVariantList msg = _dryDemoCmds[_dryDemoCurrentCmd][_index].mid(RESP_MSG_START_INDEX); emit _ApplicationController.didActionTransmit(msg); } } 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 ) { if (_stateStatus == STATE_ON_ENTRY) { 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); _broadcastMessages.append(msg); msg.clear(); msg.append(static_cast(ID_HD_TX_PARAMS_RANGES_DATA)); msg.append(Can_Id::eChlid_HD_Sync); msg.append(0); msg.append(TX_PARAM_PRESCRIBED_DUR_S / SECONDS_PER_MINUTE); msg.append(0.0); msg.append(TX_PARAM_UF_VOLUME_L); msg.append(MIN_DIAL_RATE_MLPM); msg.append(MAX_DIAL_RATE_MLPM); _broadcastMessages.append(msg); 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); _treatmentVars.prescribedMaxUFVolML = TX_PARAM_UF_VOLUME_L * MILLILITERS_PER_LITER; _treatmentVars.prescribedUFRate = _treatmentVars.prescribedMaxUFVolML / (TX_PARAM_PRESCRIBED_DUR_S / SECONDS_PER_MINUTE); _treatmentVars.refUFVolumeML = 0.0; _isBoradcastListReady = true; _stateStatus = STATE_ON_EXIT; } else if (_stateStatus == STATE_ON_EXIT) { _stateStatus = STATE_ON_ENTRY; _dryDemo.submitEvent("Start_Tx_2_Blood_Prime"); } } void StateController::onTreatmentBloodPrimeStateChange(bool) { _treatmentVars.broadcastIntervalCount++; if (_treatmentVars.accumulatedVolumeML > BLOOD_PRIME_VOLUME_ML) { _stateStatus = STATE_ON_EXIT; } if (_stateStatus == STATE_ON_ENTRY) { resetVariables(); qDebug() << "Blood prime enty"; _stateStatus = STATE_ON_ACTION; } else if (_stateStatus == STATE_ON_EXIT) { qDebug() << "Blood prime exit"; _stateStatus = STATE_ON_ENTRY; _dryDemo.submitEvent("Blood_Prime_2_Treatment"); } _treatmentVars.accumulatedVolumeML += (TX_PARAM_BLOOD_FLOW_RATE_MLPM * BLOOD_FLOW_INTEGRATOR); if (_treatmentVars.broadcastIntervalCount % NUM_OF_BC_COUNTS_ADJUSTED == 0) { _isBoradcastListReady = false; 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); _broadcastMessages.append(msg); prepareOcclusionBroadcastData(); _isBoradcastListReady = true; } } void StateController::onTreatmentTreatmentStateChange(bool) { _treatmentVars.broadcastIntervalCount++; handleTreatmentReceivedMessages(); if (_stateStatus == STATE_ON_ENTRY) { resetVariables(); qDebug() << "Treatment Treatment state"; _treatmentVars.prescribedTreatmentTimeS = TX_PARAM_PRESCRIBED_DUR_S; _treatmentVars.treatmentElapsedTimeS = DEFAULT_TX_ELAPSED_TIME_S; _stateStatus = STATE_ON_ACTION; } else if (_stateStatus == STATE_ON_EXIT) { qDebug() << "Treat Treatment exit"; // _dryDemo.submitEvent("Treatment_2_End_Treatment"); } if (_treatmentVars.broadcastIntervalCount % NUM_OF_BC_COUNTS_ADJUSTED == 0) { _isBoradcastListReady = false; 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(); _isBoradcastListReady = true; } if (_treatmentVars.remainingTreatmentTimeS <= 0 ) { _stateStatus = STATE_ON_EXIT; } } 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"; } }