/************************************************************************** * * Copyright (c) 2025-2025 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file StateTxPaused.c * * @author (last) Sean * @date (last) 18-Apr-2025 * * @author (original) Sean * @date (original) 18-Apr-2025 * ***************************************************************************/ #include "AirTrap.h" #include "BloodFlow.h" #include "Buttons.h" #include "DDInterface.h" #include "Messaging.h" //#include "NVDataMgmt.h" #include "OperationModes.h" #include "StateTxPaused.h" //#include "Switches.h" #include "TaskGeneral.h" #include "Valves.h" /** * @addtogroup StateTxPaused * @{ */ // ********** private definitions ********** /// Treatment paused status broadcast interval. #define TREATMENT_PAUSED_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) // ********** private data ********** static TREATMENT_PAUSED_STATE_T currentTxPausedState; ///< Current treatment paused state. static U32 bloodSittingTimerCtr; ///< Timer counter tracks time in this mode while blood is sitting. static U32 pausedPublishTimerCtr; ///< Timer counter (in GP task intervals) counts time to next treatment paused status broadcast. static OVERRIDE_U32_T treatmentPausedPublishInterval; ///< Interval (in task intervals) at which to publish treatment paused state data to CAN bus. // ********** private function prototypes ********** /*********************************************************************//** * @brief * The initTreatmentPaused function initializes the Treatment Paused State unit. * @details \b Inputs: none * @details \b Outputs: Treatment Paused State unit initialized. * @return none *************************************************************************/ void initTreatmentPaused( void ) { currentTxPausedState = TREATMENT_PAUSED_RECIRC_STATE; // Assume blood and dialysate will recirculate initially - will stop pump(s) as appropriate in state machine bloodSittingTimerCtr = 0; pausedPublishTimerCtr = TREATMENT_PAUSED_DATA_PUBLISH_INTERVAL; treatmentPausedPublishInterval.data = TREATMENT_PAUSED_DATA_PUBLISH_INTERVAL; treatmentPausedPublishInterval.ovData = TREATMENT_PAUSED_DATA_PUBLISH_INTERVAL; treatmentPausedPublishInterval.ovInitData = TREATMENT_PAUSED_DATA_PUBLISH_INTERVAL; treatmentPausedPublishInterval.override = OVERRIDE_RESET; } /*********************************************************************//** * @brief * The transitionToTreatmentPaused function prepares for transition to * Treatment Paused state. * @details \b Inputs: currentTxPausedState * @details \b Outputs: none * @return none *************************************************************************/ void transitionToTreatmentPaused( void ) { initTreatmentPaused(); setCurrentSubState( (U32)currentTxPausedState ); setCurrent4thLevelState( NO_SUB_STATE ); // Set user alarm recovery actions allowed in this sub-mode setAlarmUserActionEnabled( ALARM_USER_ACTION_RESUME, TRUE ); if ( FALSE ) // TODO ( TRUE == getRinsebackCompleted() ) { // block rinseback action if already done setAlarmUserActionEnabled( ALARM_USER_ACTION_RINSEBACK, FALSE ); } else { setAlarmUserActionEnabled( ALARM_USER_ACTION_RINSEBACK, TRUE ); } setAlarmUserActionEnabled( ALARM_USER_ACTION_END_TREATMENT, TRUE ); // setupForBloodRecirculationState(); // setupForDialysateRecirculationState(); // temporary actuator setup until setup functions implemented TODO signalBloodPumpHardStop(); setValvePosition( H1_VALV, VALVE_POSITION_C_CLOSE ); setValvePosition( H19_VALV, VALVE_POSITION_C_CLOSE ); cmdBypassDialyzer( TRUE ); cmdChangeQuf( 0.0F ); startAirTrapControl(); // signalInitiatePressureStabilization( USE_NORMAL_STABILIZATION_PERIOD ); // Reset saline bolus state in case alarm interrupted one // resetSalineBolus(); // Reset blood leak zeroing params // resetBloodLeakZeroingVariables(); // Should always have an alarm active in treatment stop sub-mode so that user can take action if ( FALSE == isAnyAlarmActive() ) { // if ( TRUE == getRinsebackCompleted() ) // { // activateAlarmNoData( ALARM_ID_TD_TREATMENT_STOPPED_AFTER_RINSEBACK ); // No escalation after rinseback because no blood in blood line // } // else { activateAlarmNoData( ALARM_ID_TD_TREATMENT_STOPPED_BY_USER ); } // coming back to stop state via non-alarm path, so no audio - just want alarm for its options signalAlarmSilence( ALARM_SILENCE_CMD_CANCEL ); } } /*********************************************************************//** * @brief * The execTreatmentPaused function executes the Treatment Paused state machine. * @details \b Alarm: ALARM_ID_HD_SOFTWARE_FAULT if state is invalid * @details \b Message \b Sent: TD_EVENT_SUB_STATE_CHANGE when state changes * @details \b Inputs: currentTxPausedState * @details \b Outputs: currentTxPausedState * @return none *************************************************************************/ void execTreatmentPaused( void ) { TREATMENT_PAUSED_STATE_T priorSubState = currentTxPausedState; // switch ( currentTxPausedState ) // { // case TREATMENT_PAUSED_RECIRC_STATE: // currentTxPausedState = handleTreatmentStopRecircState(); // break; // // case TREATMENT_PAUSED_RECIRC_DIALYSATE_ONLY_STATE: // currentTxPausedState = handleTreatmentStopDialysateRecircState(); // break; // // case TREATMENT_PAUSED_RECIRC_BLOOD_ONLY_STATE: // currentTxPausedState = handleTreatmentStopBloodRecircState(); // break; // // case TREATMENT_PAUSED_NO_RECIRC_STATE: // currentTxPausedState = handleTreatmentStopNoRecircState(); // break; // // case TREATMENT_PAUSED_RECOVER_BLOOD_DETECT_STATE: // currentTxPausedState = handleTreatmentStopRecoverBloodDetectState(); // break; // // default: // SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_TREATMENT_STOP_INVALID_STATE, currentTxStopState ); // break; // } if ( priorSubState != currentTxPausedState ) { setCurrentSubState( (U32)currentTxPausedState ); SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_SUB_STATE_CHANGE, priorSubState, currentTxPausedState ); } // Broadcast treatment stop status // publishTreatmentStopData(); } /*********************************************************************//** * @brief * The getCurrentTreatmentPausedState function returns the current state of the * treatment paused sub-mode. * @details \b Inputs: currentTxPausedState * @details \b Outputs: none * @return currentTxPausedState *************************************************************************/ TREATMENT_PAUSED_STATE_T getCurrentTreatmentPausedState( void ) { return currentTxPausedState; } /**@}*/