Index: firmware/App/Modes/TreatmentRecirc.c =================================================================== diff -u -r13b15c23c5065a9967bd8776b0cea2f71cd1a240 -rcd5be724d5a3ba7457e761191d82f278654d7f5c --- firmware/App/Modes/TreatmentRecirc.c (.../TreatmentRecirc.c) (revision 13b15c23c5065a9967bd8776b0cea2f71cd1a240) +++ firmware/App/Modes/TreatmentRecirc.c (.../TreatmentRecirc.c) (revision cd5be724d5a3ba7457e761191d82f278654d7f5c) @@ -1,14 +1,14 @@ /************************************************************************** * -* Copyright (c) 2021-2023 Diality Inc. - All Rights Reserved. +* Copyright (c) 2021-2024 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 TreatmentRecirc.c * -* @author (last) Michael Garthwaite -* @date (last) 01-Mar-2023 +* @author (last) Sean Nash +* @date (last) 31-Jul-2023 * * @author (original) Sean Nash * @date (original) 20-Jan-2021 @@ -46,6 +46,7 @@ static U32 recircTimerCtr; ///< Timer counter (in GP task intervals) counts time spent in re-circulation sub-mode. static U32 recircPublishTimerCtr; ///< Timer counter (in GP task intervals) counts time to next status broadcast. +static BOOL recircStartRecircRequested; ///< Flag indicates user requesting to start recirculating (confirming disconnected). static BOOL recircReconnectRequested; ///< Flag indicates user requesting re-circulate stop so they can re-connect. static BOOL recircBackToTreatmenRequested; ///< Flag indicates user requesting to go back to treatment (confirming re-connected). static BOOL recircResumeRequested; ///< Flag indicates user requesting resumption of re-circulating. @@ -58,13 +59,15 @@ static void setupForRecirculationState( void ); static void setupForRecirculationStopState( void ); +static TREATMENT_RECIRC_STATE_T handleRecircDisconnectPatientState( void ); static TREATMENT_RECIRC_STATE_T handleRecircRecircState( void ); static TREATMENT_RECIRC_STATE_T handleRecircStoppedState( void ); +static TREATMENT_RECIRC_STATE_T handleRecircReconnectPatientState( void ); static BOOL handleRecircReconnectUserAction( REQUEST_REJECT_REASON_CODE_T *rejReason ); static BOOL handleRecicConfirmReconnectUserAction( REQUEST_REJECT_REASON_CODE_T *rejReason ); static BOOL handleRecircResumeUserAction( REQUEST_REJECT_REASON_CODE_T *rejReason ); -static BOOL handleRecircEndTreatmentUserAction( REQUEST_REJECT_REASON_CODE_T *rejReason ); +static BOOL handleRecircConfirmDisconnectUserAction( REQUEST_REJECT_REASON_CODE_T *rejReason ); static void publishTreatmentRecircData( void ); @@ -78,7 +81,7 @@ *************************************************************************/ void initTreatmentRecirc( void ) { - treatmentRecircState = TREATMENT_RECIRC_RECIRC_STATE; + treatmentRecircState = TREATMENT_RECIRC_DISCONNECT_PATIENT_STATE; recircTimerCtr = 0; recircPublishTimerCtr = 0; resetTreatmentRecircFlags(); @@ -93,6 +96,7 @@ *************************************************************************/ static void resetTreatmentRecircFlags( void ) { + recircStartRecircRequested = FALSE; recircReconnectRequested = FALSE; recircBackToTreatmenRequested = FALSE; recircResumeRequested = FALSE; @@ -110,22 +114,24 @@ void transitionToTreatmentRecirc( void ) { initTreatmentRecirc(); - + setCurrentSubState( (U32)treatmentRecircState ); doorClosedRequired( TRUE, TRUE ); // Set valves to safe state setValvePosition( VDI, VALVE_POSITION_C_CLOSE ); setValvePosition( VDO, VALVE_POSITION_C_CLOSE ); - setValvePosition( VBA, VALVE_POSITION_B_OPEN ); - setValvePosition( VBV, VALVE_POSITION_B_OPEN ); + setupForRecirculationStopState(); - // Start blood pump at re-circulate flow rate - setBloodPumpTargetFlowRate( RECIRC_BP_FLOW_RATE_ML_MIN, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); + // Enable venous bubble detection while recirculating + setVenousBubbleDetectionEnabled( TRUE ); + // Ensure syringe pump is stopped stopSyringePump(); - // Start air trap control - startAirTrapControl(); - // *Note - Dialysate pump should already be re-circulating from rinseback sub-mode + // Stop air trap leveling control + endAirTrapControl(); + // Re-circulate dialysate side of dialyzer w/ heating to maintain temperature + setDialInPumpTargetFlowRate( DIALYSATE_FLOW_RATE_FOR_RECIRC, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); + cmdStartDGTrimmerHeater(); // Set user alarm recovery actions allowed in this sub-mode setAlarmUserActionEnabled( ALARM_USER_ACTION_RESUME, FALSE ); @@ -149,8 +155,6 @@ setValvePosition( VBV, VALVE_POSITION_B_OPEN ); // Start blood pump at re-circulate flow rate setBloodPumpTargetFlowRate( RECIRC_BP_FLOW_RATE_ML_MIN, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); - // Start air trap leveling control - startAirTrapControl(); } /*********************************************************************//** @@ -169,16 +173,14 @@ // Close arterial and venous lines setValvePosition( VBA, VALVE_POSITION_C_CLOSE ); setValvePosition( VBV, VALVE_POSITION_C_CLOSE ); - // Stop air trap leveling control - endAirTrapControl(); } /*********************************************************************//** * @brief * The execTreatmentRecirc function executes the Treatment circulate sub-mode * state machine. * @details Inputs: treatmentRecircState - * @details Outputs: treatmentRecircState, recircTimerCtr + * @details Outputs: treatmentRecircState, recircTimerCtr, recircEndTreatmentRequested * @return none *************************************************************************/ void execTreatmentRecirc( void ) @@ -190,6 +192,10 @@ switch ( treatmentRecircState ) { + case TREATMENT_RECIRC_DISCONNECT_PATIENT_STATE: + treatmentRecircState = handleRecircDisconnectPatientState(); + break; + case TREATMENT_RECIRC_RECIRC_STATE: treatmentRecircState = handleRecircRecircState(); break; @@ -198,13 +204,18 @@ treatmentRecircState = handleRecircStoppedState(); break; + case TREATMENT_RECIRC_RECONNECT_PATIENT_STATE: + treatmentRecircState = handleRecircReconnectPatientState(); + break; + default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_TREATMENT_RECIRC_INVALID_STATE, treatmentRecircState ); break; } if ( priorSubState != treatmentRecircState ) { + setCurrentSubState( (U32)treatmentRecircState ); SEND_EVENT_WITH_2_U32_DATA( HD_EVENT_SUB_STATE_CHANGE, priorSubState, treatmentRecircState ); } // Re-circulate flags should be handled by now - reset in case not handled by current state @@ -216,6 +227,27 @@ /*********************************************************************//** * @brief + * The handleRecircDisconnectPatientState function handles the re-circulation + * disconnect patient state operations. + * @details Inputs: flags + * @details Outputs: flags handled + * @return next Treatment re-circulation state + *************************************************************************/ +static TREATMENT_RECIRC_STATE_T handleRecircDisconnectPatientState( void ) +{ + TREATMENT_RECIRC_STATE_T result = TREATMENT_RECIRC_DISCONNECT_PATIENT_STATE; + + if ( TRUE == recircStartRecircRequested ) + { + setupForRecirculationState(); + result = TREATMENT_RECIRC_RECIRC_STATE; + } + + return result; +} + +/*********************************************************************//** + * @brief * The handleRecircRecircState function handles the re-circulating state * operations. * @details Inputs: flags @@ -226,12 +258,18 @@ { TREATMENT_RECIRC_STATE_T result = TREATMENT_RECIRC_RECIRC_STATE; - // Is alarm stop or user reconnect requested? - if ( ( TRUE == recircReconnectRequested ) || ( TRUE == doesAlarmStatusIndicateStop() ) ) + // Is alarm stop? + if ( TRUE == doesAlarmStatusIndicateStop() ) { setupForRecirculationStopState(); result = TREATMENT_RECIRC_STOPPED_STATE; } + // Is user reconnect requested? + else if ( TRUE == recircReconnectRequested ) + { + setupForRecirculationStopState(); + result = TREATMENT_RECIRC_RECONNECT_PATIENT_STATE; + } // Is end treatment requested? else if ( TRUE == recircEndTreatmentRequested ) { @@ -254,6 +292,33 @@ { TREATMENT_RECIRC_STATE_T result = TREATMENT_RECIRC_STOPPED_STATE; + // Is end treatment requested? + if ( TRUE == recircEndTreatmentRequested ) + { + signalEndTreatment(); + } + // Is re-circ resume requested? + else if ( TRUE == recircResumeRequested ) + { + setupForRecirculationState(); + result = TREATMENT_RECIRC_RECIRC_STATE; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The handleRecircReconnectPatientState function handles the re-circulation + * reconnect patient state operations. + * @details Inputs: flags + * @details Outputs: flags handled + * @return next Treatment re-circulation state + *************************************************************************/ +static TREATMENT_RECIRC_STATE_T handleRecircReconnectPatientState( void ) +{ + TREATMENT_RECIRC_STATE_T result = TREATMENT_RECIRC_RECONNECT_PATIENT_STATE; + // Is back to treatment requested? if ( TRUE == recircBackToTreatmenRequested ) { @@ -262,7 +327,8 @@ // Is end treatment requested? else if ( TRUE == recircEndTreatmentRequested ) { - signalEndTreatment(); + setupForRecirculationStopState(); + signalEndTreatment(); // signal end Tx sub-mode } // Is re-circ resume requested? else if ( TRUE == recircResumeRequested ) @@ -306,9 +372,15 @@ break; case REQUESTED_USER_ACTION_TX_RECIRC_END_TREATMENT: - accepted = handleRecircEndTreatmentUserAction( &rejReason ); + // Send message to UI to get user confirmation to end treatment - action initiated only upon receipt of user confirmation from UI + addConfirmationRequest( GENERIC_CONFIRM_ID_TREATMENT_END, GENERIC_CONFIRM_CMD_REQUEST_OPEN, 0 ); + accepted = TRUE; break; + case REQUESTED_USER_ACTION_TX_RECIRC_CONFIRM_DISCONNECT: + accepted = handleRecircConfirmDisconnectUserAction( &rejReason ); + break; + default: rejReason = REQUEST_REJECT_REASON_INVALID_COMMAND; break; @@ -337,14 +409,18 @@ { BOOL result = FALSE; - if ( TREATMENT_RECIRC_RECIRC_STATE == treatmentRecircState ) + if ( treatmentRecircState != TREATMENT_RECIRC_RECIRC_STATE ) { - result = TRUE; - recircReconnectRequested = TRUE; + *rejReason = REQUEST_REJECT_REASON_ACTION_DISABLED_IN_CURRENT_STATE; } + else if ( TRUE == isTreatmentResumeBlocked() ) + { + *rejReason = REQUEST_REJECT_REASON_TREATMENT_CANNOT_BE_RESUMED; + } else { - *rejReason = REQUEST_REJECT_REASON_ACTION_DISABLED_IN_CURRENT_STATE; + result = TRUE; + recircReconnectRequested = TRUE; } return result; @@ -364,7 +440,7 @@ { BOOL result = FALSE; - if ( TREATMENT_RECIRC_STOPPED_STATE == treatmentRecircState ) + if ( TREATMENT_RECIRC_RECONNECT_PATIENT_STATE == treatmentRecircState ) { result = TRUE; recircBackToTreatmenRequested = TRUE; @@ -391,7 +467,7 @@ { BOOL result = FALSE; - if ( TREATMENT_RECIRC_STOPPED_STATE == treatmentRecircState ) + if ( ( TREATMENT_RECIRC_STOPPED_STATE == treatmentRecircState ) || ( TREATMENT_RECIRC_RECONNECT_PATIENT_STATE == treatmentRecircState ) ) { result = TRUE; recircResumeRequested = TRUE; @@ -406,22 +482,22 @@ /*********************************************************************//** * @brief - * The handleRecircEndTreatmentUserAction function handles an e reatment - * user action request. It is assumed that the calling function will set - * the reject reason parameter to None beforehand. + * The handleRecircConfirmDisconnectUserAction function handles a confirm + * patient disconnect user action request. It is assumed that the calling + * function will set the reject reason parameter to None beforehand. * @details Inputs: treatmentRecircState - * @details Outputs: ending of treatment action handled + * @details Outputs: confirming patient disconnect action handled * @param rejReason Code indicating reason for rejection * @return TRUE if user action accepted, FALSE if not *************************************************************************/ -static BOOL handleRecircEndTreatmentUserAction( REQUEST_REJECT_REASON_CODE_T *rejReason ) +static BOOL handleRecircConfirmDisconnectUserAction( REQUEST_REJECT_REASON_CODE_T *rejReason ) { BOOL result = FALSE; - if ( ( TREATMENT_RECIRC_RECIRC_STATE == treatmentRecircState ) || ( TREATMENT_RECIRC_STOPPED_STATE == treatmentRecircState ) ) + if ( TREATMENT_RECIRC_DISCONNECT_PATIENT_STATE == treatmentRecircState ) { result = TRUE; - recircEndTreatmentRequested = TRUE; + recircStartRecircRequested = TRUE; } else {