/************************************************************************** * * Copyright (c) 2019-2020 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 PreTreatmentRecirc.c * * @author (last) Quang Nguyen * @date (last) 08-Feb-2021 * * @author (original) Quang Nguyen * @date (original) 08-Feb-2021 * ***************************************************************************/ #include "DialInFlow.h" #include "DialOutFlow.h" #include "BloodFlow.h" #include "DGInterface.h" #include "PreTreatmentRecirc.h" #include "Valves.h" /** * @addtogroup PreTreatmentRecirc * @{ */ // ********** private definitions ********** #define BLOOD_PUMP_RECIRC_FLOW_RATE 100 ///< Blood pump flow rate during recirculation in mL/min. #define DIALYSATE_PUMP_RECIRC_FLOW_RATE 100 ///< Dialysate pump flow rate during recirculation in mL/min. /// Wet self-tests state machine. typedef enum Pre_Treatment_Recirc_State { PRE_TREATMENT_RECIRC_START_STATE = 0, ///< Pre-treatment recirculate start state. PRE_TREATMENT_RECIRC_STATE, ///< Pre-treatment recirculate state. NUM_OF_PRE_TREATMENT_RECIRC_STATES ///< Number of pre-treatment recirculate states. } PRE_TREATMENT_RECIRC_STATE_T; // ********** private data ********** static PRE_TREATMENT_RECIRC_STATE_T currentPreTreatmentRecircState; ///< Current state of the pre-treatment recirculate state machine. // ********** private function prototypes ********** static PRE_TREATMENT_RECIRC_STATE_T handlePreTreatmentRecirculateStartState( void ); static PRE_TREATMENT_RECIRC_STATE_T handlePreTreatmentRecirculateState( void ); /*********************************************************************//** * @brief * The initPreTreatmentRecirc function initializes the PreTreatmentRecirc module. * @details Inputs: none * @details Outputs: PreTreatmentRecirc module initialized. * @return none *************************************************************************/ void initPreTreatmentRecirc( void ) { currentPreTreatmentRecircState = PRE_TREATMENT_RECIRC_START_STATE; } /*********************************************************************//** * @brief * The transitionToPreTreatmentRecirc function resets anything required before * the start of pre-treatment recirculate sub-mode. * @details Inputs: none * @details Outputs: PreTreatmentRecirc module re-initialized. * @return none *************************************************************************/ void transitionToPreTreatmentRecirc( void ) { initPreTreatmentRecirc(); } /*********************************************************************//** * @brief * The execPreTreatmentRecirc function executes the pre-treatment recirculate state machine. * @details Inputs: currentPreTreatmentRecircState * @details Outputs: currentPreTreatmentRecircState * @return none *************************************************************************/ void execPreTreatmentRecirc( void ) { // execute pre-treatment recirculate state machine switch ( currentPreTreatmentRecircState ) { case PRE_TREATMENT_RECIRC_START_STATE: currentPreTreatmentRecircState = handlePreTreatmentRecirculateStartState(); break; case PRE_TREATMENT_RECIRC_STATE: currentPreTreatmentRecircState = handlePreTreatmentRecirculateState(); break; default: currentPreTreatmentRecircState = PRE_TREATMENT_RECIRC_START_STATE; SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_HD_INVALID_NO_CARTRIDGE_SELF_TEST_STATE, (U32)currentPreTreatmentRecircState ); break; } } /*********************************************************************//** * @brief * The isPatientConnectionRequested function returns the status of patient connection request. * @details Inputs: none * @details Outputs: none * @return TRUE if patient connection requested, otherwise FALSE *************************************************************************/ BOOL isPatientConnectionRequested( void ) { // TODO Add handler to UI interaction return TRUE; } /*********************************************************************//** * @brief * The handlePreTreatmentRecirculateStartState function changes valves and * heater settings for pre-treatment recirculate sub-mode. * @details Inputs: none * @details Outputs: controlled valves and pumps * @return current state (sub-mode) *************************************************************************/ static PRE_TREATMENT_RECIRC_STATE_T handlePreTreatmentRecirculateStartState( void ) { setValvePosition( VDI, VALVE_POSITION_C_CLOSE ); setValvePosition( VDO, VALVE_POSITION_C_CLOSE ); setValvePosition( VBA, VALVE_POSITION_B_OPEN ); setValvePosition( VBV, VALVE_POSITION_B_OPEN ); setValveAirTrap( STATE_CLOSED ); cmdSetDGActiveReservoir( DG_RESERVOIR_1 ); cmdStartDGTrimmerHeater(); setBloodPumpTargetFlowRate( BLOOD_PUMP_RECIRC_FLOW_RATE, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); setDialInPumpTargetFlowRate( DIALYSATE_PUMP_RECIRC_FLOW_RATE, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); signalDialOutPumpHardStop(); return PRE_TREATMENT_RECIRC_STATE; } /*********************************************************************//** * @brief * The handleRecirculateState function handles blood and dialysate circuits * recirculation state during pre-treatment recirculate sub-mode. * @details Inputs: none * @details Outputs: controlled valves and pumps * @return current state (sub-mode) *************************************************************************/ static PRE_TREATMENT_RECIRC_STATE_T handlePreTreatmentRecirculateState( void ) { PRE_TREATMENT_RECIRC_STATE_T state = PRE_TREATMENT_RECIRC_STATE; // if ( TRUE == alarmActionStopReceived ) // { // signalDialOutPumpHardStop(); // signalDialInPumpHardStop(); // signalBloodPumpHardStop(); // cmdStopDGTrimmerHeater(); // // state = HD_PRE_TREATMENT_PAUSE_STATE; // resumePreTreatmentState = HD_PRE_TREATMENT_RECIRCULATE_START_STATE; // } return state; } /**@}*/