Index: firmware/App/Modes/TreatmentStop.c =================================================================== diff -u -r6624b2257367f346202eeca3024ef2aae44e4c96 -r03f5d100a81e31a02bdf549e0150ae71b9a5d5e5 --- firmware/App/Modes/TreatmentStop.c (.../TreatmentStop.c) (revision 6624b2257367f346202eeca3024ef2aae44e4c96) +++ firmware/App/Modes/TreatmentStop.c (.../TreatmentStop.c) (revision 03f5d100a81e31a02bdf549e0150ae71b9a5d5e5) @@ -8,7 +8,7 @@ * @file TreatmentStop.c * * @author (last) Sean Nash -* @date (last) 12-Jun-2023 +* @date (last) 11-Jul-2023 * * @author (original) Sean * @date (original) 15-Jan-2020 @@ -36,7 +36,8 @@ // ********** private definitions ********** /// Treatment stop status broadcast interval. -#define TREATMENT_STOP_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) +#define TREATMENT_STOP_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) +#define DIALYSATE_FLOW_RATE_FOR_BLOOD_DETECT_RECOVERY_MLPM 600 ///< Dialysate flow rate for blood detect recovery in mL/min. // ********** private data ********** @@ -52,9 +53,11 @@ static TREATMENT_STOP_STATE_T handleTreatmentStopNoRecircState( void ); static void setupForDialysateRecirculationState( void ); static void setupForBloodRecirculationState( void ); +static void setupForRecoverBloodDetectState( void ); static TREATMENT_STOP_STATE_T handleTreatmentStopAlarmsAndSignals( TREATMENT_STOP_STATE_T state ); static TREATMENT_STOP_STATE_T handleTreatmentStopDialysateRecircState( void ); static TREATMENT_STOP_STATE_T handleTreatmentStopBloodRecircState( void ); +static TREATMENT_STOP_STATE_T handleTreatmentStopRecoverBloodDetectState( void ); static void handleTreatmentStopBloodSittingTimer( void ); static void publishTreatmentStopData( void ); @@ -109,7 +112,7 @@ setupForDialysateRecirculationState(); - signalUserRateChange(); // so pressure limits re-stabilize + signalInitiatePressureStabilization(); // Reset saline bolus state in case alarm interrupted one resetSalineBolus(); @@ -186,6 +189,21 @@ /*********************************************************************//** * @brief + * The setupForRecoverBloodDetectState function handles the setup for + * recovering blood detection state. + * @details Inputs: none + * @details Outputs: none + * @return none + *************************************************************************/ +static void setupForRecoverBloodDetectState( void ) +{ + doorClosedRequired( TRUE, TRUE ); + cmdStartDGTrimmerHeater(); + setDialInPumpTargetFlowRate( DIALYSATE_FLOW_RATE_FOR_BLOOD_DETECT_RECOVERY_MLPM, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); +} + +/*********************************************************************//** + * @brief * The setupForDialysateRecirculationStopState function sets actuators appropriately * for dialysate re-circulation stopped state. * @details Inputs: none @@ -252,6 +270,10 @@ currentTxStopState = handleTreatmentStopNoRecircState(); break; + case TREATMENT_STOP_RECOVER_BLOOD_DETECT_STATE: + currentTxStopState = handleTreatmentStopRecoverBloodDetectState(); + break; + default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_TREATMENT_STOP_INVALID_STATE, currentTxStopState ); break; @@ -277,38 +299,39 @@ static TREATMENT_STOP_STATE_T handleTreatmentStopAlarmsAndSignals( TREATMENT_STOP_STATE_T state ) { TREATMENT_STOP_STATE_T result = state; - BOOL bloodRecircBlocked = isBloodRecircBlocked(); - BOOL dialysateRecircBlocked = isDialysateRecircBlocked(); + BOOL bloodRecircBlocked = isBloodRecircBlocked(); + BOOL dialysateRecircBlocked = isDialysateRecircBlocked(); + if ( ( TREATMENT_STOP_RECOVER_BLOOD_DETECT_STATE != state ) && ( dialysateRecircBlocked != TRUE ) && + ( TRUE == isAlarmActive( ALARM_ID_HD_BLOOD_LEAK_RECOVERING_PLEASE_WAIT ) ) && ( FALSE == isAlarmActive( ALARM_ID_HD_BLOOD_LEAK_DETECTED ) ) ) + { + setupForRecoverBloodDetectState(); + result = TREATMENT_STOP_RECOVER_BLOOD_DETECT_STATE; + } // Both unblocked and not in recirculate both state - if ( ( TREATMENT_STOP_RECIRC_STATE != state ) && ( FALSE == dialysateRecircBlocked ) && ( FALSE == bloodRecircBlocked ) ) + else if ( ( TREATMENT_STOP_RECIRC_STATE != state ) && ( FALSE == dialysateRecircBlocked ) && ( FALSE == bloodRecircBlocked ) ) { setupForBloodRecirculationState(); setupForDialysateRecirculationState(); result = TREATMENT_STOP_RECIRC_STATE; } - // Both blocked and not in stopped state - if ( ( TREATMENT_STOP_NO_RECIRC_STATE != state ) && ( TRUE == dialysateRecircBlocked ) && ( TRUE == bloodRecircBlocked ) ) + else if ( ( TREATMENT_STOP_NO_RECIRC_STATE != state ) && ( TRUE == dialysateRecircBlocked ) && ( TRUE == bloodRecircBlocked ) ) { setupForBloodRecirculationStopState(); setupForDialysateRecirculationStopState(); result = TREATMENT_STOP_NO_RECIRC_STATE; } - // Dialysate recirculation blocked and not in blood recirc state - if ( ( TREATMENT_STOP_RECIRC_BLOOD_ONLY_STATE != state ) && - ( TRUE == dialysateRecircBlocked ) && - ( FALSE == bloodRecircBlocked ) ) + else if ( ( TREATMENT_STOP_RECIRC_BLOOD_ONLY_STATE != state ) && ( TRUE == dialysateRecircBlocked ) && + ( FALSE == bloodRecircBlocked ) ) { setupForDialysateRecirculationStopState(); result = TREATMENT_STOP_RECIRC_BLOOD_ONLY_STATE; } - // Blood recirculation blocked and not in dialysate recirc state - if ( ( TREATMENT_STOP_RECIRC_DIALYSATE_ONLY_STATE != state ) && - ( TRUE == bloodRecircBlocked ) && - ( FALSE == dialysateRecircBlocked ) ) + else if ( ( TREATMENT_STOP_RECIRC_DIALYSATE_ONLY_STATE != state ) && ( TRUE == bloodRecircBlocked ) && + ( FALSE == dialysateRecircBlocked ) ) { setupForBloodRecirculationStopState(); result = TREATMENT_STOP_RECIRC_DIALYSATE_ONLY_STATE; @@ -393,6 +416,25 @@ /*********************************************************************//** * @brief + * The handleTreatmentStopRecoverBloodDetectState function handles the recovering + * for blood detect state in treatment stop. + * @details Inputs: none + * @details Outputs: none + * @return next treatment stop state + *************************************************************************/ +static TREATMENT_STOP_STATE_T handleTreatmentStopRecoverBloodDetectState( void ) +{ + TREATMENT_STOP_STATE_T result = TREATMENT_STOP_RECOVER_BLOOD_DETECT_STATE; + + // Keep reseting the blood sitting timer + handleTreatmentStopBloodSittingTimer(); + result = handleTreatmentStopAlarmsAndSignals( result ); + + return result; +} + +/*********************************************************************//** + * @brief * The handleTreatmentStopBloodSittingTimer function handles the no re-circ * blood timer. It should only be called when Blood is NOT circulating. * Increments and checks for warning and alarm timeouts. @@ -405,15 +447,19 @@ // Ensure we do not sit in stopped state for too long (if blood in line) if ( getRinsebackCompleted() != TRUE ) { - if ( ++bloodSittingTimerCtr > WARN_TIME_BLOOD_SITTING ) + bloodSittingTimerCtr++; + if ( FALSE == doesAlarmStatusIndicateEndTxOnly() ) // Alarms appropriate only if we are not already at an alarm stop, end Tx only { - activateAlarmNoData( ALARM_ID_HD_BLOOD_SITTING_WARNING ); + if ( bloodSittingTimerCtr > WARN_TIME_BLOOD_SITTING ) + { + activateAlarmNoData( ALARM_ID_HD_BLOOD_SITTING_WARNING ); + } + if ( bloodSittingTimerCtr > MAX_TIME_BLOOD_SITTING ) + { + // Activate the alarm + activateAlarmNoData( ALARM_ID_HD_TREATMENT_STOPPED_NO_RINSEBACK ); + } } - if ( bloodSittingTimerCtr > MAX_TIME_BLOOD_SITTING ) - { - // Activate the alarm - activateAlarmNoData( ALARM_ID_HD_TREATMENT_STOPPED_NO_RINSEBACK ); - } } else {