/************************************************************************** * * Copyright (c) 2021-2022 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) Dara Navaei * @date (last) 22-Mar-2022 * * @author (original) Quang Nguyen * @date (original) 06-Mar-2021 * ***************************************************************************/ #include "ConsumableSelfTest.h" #include "DGInterface.h" #include "ModePreTreat.h" #include "NVDataMgmt.h" #include "Reservoirs.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 ) { initConsumableSelfTest(); } /*********************************************************************//** * @brief * The execConsumableSelfTest function executes the consumable self-test * state machine. * @details Inputs: currentConsumableSelfTestState * @details Outputs: currentConsumableSelfTestState * @return none *************************************************************************/ void execConsumableSelfTest( void ) { switch( currentConsumableSelfTestState ) { case CONSUMABLE_SELF_TESTS_INSTALL_STATE: if ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_DISABLE_UI_INTERACTION ) ) { consumableInstallConfirmed = TRUE; } // TODO: Check for DG straw door status to be open once DG door driver implemented if ( TRUE == consumableInstallConfirmed ) { consumableInstallConfirmed = FALSE; if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_CONSUMABLES_TESTS ) != SW_CONFIG_ENABLE_VALUE ) { currentConsumableSelfTestState = CONSUMABLE_SELF_TESTS_FILL_CMD_STATE; } else { currentConsumableSelfTestState = CONSUMABLE_SELF_TESTS_COMPLETE_STATE; } } break; case CONSUMABLE_SELF_TESTS_FILL_CMD_STATE: if ( ( DG_MODE_GENE == getDGOpMode() ) && ( DG_GEN_IDLE_MODE_STATE_FLUSH_WATER == getDGSubMode() ) ) { currentConsumableSelfTestState = CONSUMABLE_SELF_TESTS_WATER_QUALITY_CHECK_STATE; cmdStartDGFill( FILL_RESERVOIR_TO_VOLUME_ML, DEFAULT_TARGET_FILL_FLOW_RATE_LPM ); } break; case CONSUMABLE_SELF_TESTS_WATER_QUALITY_CHECK_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 = DG_FILL_MODE_STATE_TEST_ACID_CONDUCTIVITY; } 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; } // 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(); } } /**@}*/