Index: firmware/App/Modes/TreatmentStop.c =================================================================== diff -u -rd608769332d4ffe19f39a18caca14d6155f13e0a -re21e33dc6ae05c705bab8639a3d05a9376b26c25 --- firmware/App/Modes/TreatmentStop.c (.../TreatmentStop.c) (revision d608769332d4ffe19f39a18caca14d6155f13e0a) +++ firmware/App/Modes/TreatmentStop.c (.../TreatmentStop.c) (revision e21e33dc6ae05c705bab8639a3d05a9376b26c25) @@ -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 ); @@ -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.