/************************************************************************** * * Copyright (c) 2021-2023 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 ConsumableSelfTest.c * * @author (last) Michael Garthwaite * @date (last) 01-Jun-2023 * * @author (original) Quang Nguyen * @date (original) 06-Mar-2021 * ***************************************************************************/ #include "BloodFlow.h" #include "ConsumableSelfTest.h" #include "DGInterface.h" #include "DialInFlow.h" #include "DialOutFlow.h" #include "ModePreTreat.h" #include "NVDataMgmt.h" #include "Reservoirs.h" #include "SelfTests.h" #include "SyringePump.h" #include "SystemCommMessages.h" #include "Valves.h" /** * @addtogroup ConsumableSelfTest * @{ */ // ********** private definitions ********** // ********** private data ********** static CONSUMABLE_SELF_TESTS_STATE_T currentConsumableSelfTestState; ///< Current state of the consumable self-tests state machine. static BOOL consumableInstallConfirmed; ///< Flag indicates user has confirmed the installation of consumables. // ********** private function prototypes ********** static void handleConsumableSelfTestStopRequest( void ); /*********************************************************************//** * @brief * The initConsumableSelfTest function initializes the ConsumableSelfTest module. * @details Inputs: none * @details Outputs: ConsumableSelfTest module initialized. * @return none *************************************************************************/ void initConsumableSelfTest( void ) { currentConsumableSelfTestState = CONSUMABLE_SELF_TESTS_INSTALL_STATE; consumableInstallConfirmed = FALSE; } /*********************************************************************//** * @brief * The transitionToConsumableSelfTest function resets anything required before * the start of consumable self-test. * @details Inputs: none * @details Outputs: Consumable self-tests re-initialized. * @return none *************************************************************************/ void transitionToConsumableSelfTest( void ) { // Pumps should be off signalBloodPumpHardStop(); signalDialInPumpHardStop(); signalDialOutPumpHardStop(); stopSyringePump(); setCurrentSubState( (U32)CONSUMABLE_SELF_TESTS_INSTALL_STATE ); // Set valves to default positions setValveAirTrap( STATE_CLOSED ); setValvePosition( VDI, VALVE_POSITION_A_INSERT_EJECT ); setValvePosition( VDO, VALVE_POSITION_A_INSERT_EJECT ); setValvePosition( VBA, VALVE_POSITION_A_INSERT_EJECT ); setValvePosition( VBV, VALVE_POSITION_A_INSERT_EJECT ); } /*********************************************************************//** * @brief * The execConsumableSelfTest function executes the consumable self-test * state machine. * @details Inputs: currentConsumableSelfTestState * @details Outputs: currentConsumableSelfTestState * @return none *************************************************************************/ void execConsumableSelfTest( void ) { CONSUMABLE_SELF_TESTS_STATE_T priorSubState = currentConsumableSelfTestState; switch( currentConsumableSelfTestState ) { case CONSUMABLE_SELF_TESTS_INSTALL_STATE: #ifndef _RELEASE_ if ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_DISABLE_UI_INTERACTION ) ) { consumableInstallConfirmed = TRUE; } #endif // TODO: Check for DG straw door status to be open once DG door driver implemented if ( TRUE == consumableInstallConfirmed ) // TODO - should we check that concentrate cap is off too? { consumableInstallConfirmed = FALSE; #ifndef _RELEASE_ if ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_DISABLE_CONSUMABLES_TESTS ) ) { currentConsumableSelfTestState = CONSUMABLE_SELF_TESTS_COMPLETE_STATE; } else #endif { if ( ( DG_MODE_GENE == getDGOpMode() ) && ( DG_GEN_IDLE_MODE_STATE_FLUSH_WATER == getDGSubMode() ) ) { cmdStartDGFill( FILL_RESERVOIR_TO_VOLUME_ML, DEFAULT_TARGET_FILL_FLOW_RATE_LPM ); currentConsumableSelfTestState = CONSUMABLE_SELF_TESTS_PRIME_STATE; } } } break; case CONSUMABLE_SELF_TESTS_PRIME_STATE: if ( ( DG_MODE_FILL == getDGOpMode() ) && ( getDGSubMode() >= DG_FILL_MODE_STATE_TEST_BICARB_CONDUCTIVITY ) ) { currentConsumableSelfTestState = CONSUMABLE_SELF_TESTS_BICARB_PUMP_CHECK_STATE; } break; case CONSUMABLE_SELF_TESTS_BICARB_PUMP_CHECK_STATE: if ( ( DG_MODE_FILL == getDGOpMode() ) && ( getDGSubMode() >= DG_FILL_MODE_STATE_TEST_ACID_CONDUCTIVITY ) ) { currentConsumableSelfTestState = CONSUMABLE_SELF_TESTS_ACID_PUMP_CHECK_STATE; } break; case CONSUMABLE_SELF_TESTS_ACID_PUMP_CHECK_STATE: if ( ( DG_MODE_FILL == getDGOpMode() ) && ( getDGSubMode() >= DG_FILL_MODE_STATE_PRODUCE_DIALYSATE ) ) { currentConsumableSelfTestState = CONSUMABLE_SELF_TESTS_COMPLETE_STATE; cmdStopDGFill(); } break; case CONSUMABLE_SELF_TESTS_COMPLETE_STATE: break; default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_CONSUMABLE_SELF_TEST_STATE, currentConsumableSelfTestState ); break; } if ( priorSubState != currentConsumableSelfTestState ) { setCurrentSubState( (U32)currentConsumableSelfTestState ); SEND_EVENT_WITH_2_U32_DATA( HD_EVENT_SUB_STATE_CHANGE, priorSubState, currentConsumableSelfTestState ); } // Handle triggered alarm with stop property handleConsumableSelfTestStopRequest(); } /*********************************************************************//** * @brief * The getConsumableSelfTestState function returns the current state of * consumable self-tests sub-mode. * @details Inputs: currentConsumableSelfTestState * @details Outputs: none * @return current consumable self-tests state *************************************************************************/ U32 getConsumableSelfTestState( void ) { return (U32)currentConsumableSelfTestState; } /*********************************************************************//** * @brief * The signalUserConfirmConsumableInstall function handles user confirmation of * consumable installation. * @details Inputs: none * @details Outputs: confirmConsumableInstallRequested * @return TRUE if signal accepted, FALSE if not *************************************************************************/ void signalUserConfirmConsumableInstall( void ) { consumableInstallConfirmed = TRUE; } /*********************************************************************//** * @brief * The handleConsumableSelfTestStopRequest function handles stop request from * alarm and transition to consumable install state. * @details Inputs: none * @details Outputs: none * @return the next state of consumable self-tests state machine *************************************************************************/ static void handleConsumableSelfTestStopRequest( void ) { if ( TRUE == doesAlarmStatusIndicateStop() ) { currentConsumableSelfTestState = CONSUMABLE_SELF_TESTS_INSTALL_STATE; cmdStopDGFill(); } } /**@}*/