Index: firmware/App/Modes/TreatmentStop.c =================================================================== diff -u -r1a36e9bd718b40ceaee21dd12eca2da353828e30 -r86dc010eacfdaad879327202bf03336e0c77ead3 --- firmware/App/Modes/TreatmentStop.c (.../TreatmentStop.c) (revision 1a36e9bd718b40ceaee21dd12eca2da353828e30) +++ firmware/App/Modes/TreatmentStop.c (.../TreatmentStop.c) (revision 86dc010eacfdaad879327202bf03336e0c77ead3) @@ -45,6 +45,8 @@ static TREATMENT_STOP_STATE_T currentTxStopState; ///< Current treatment stop state. static U32 bloodSittingTimerCtr; ///< Timer counter tracks time in this mode while blood is sitting. static U32 stopPublishTimerCtr; ///< Timer counter (in GP task intervals) counts time to next status broadcast. +static BOOL airTrapFillInProgress; ///< Flag indicates an air trap fill is in progress. + /// Interval (in task intervals) at which to publish treatment stop sub-mode data to CAN bus. static OVERRIDE_U32_T treatmentStopPublishInterval = { TREATMENT_STOP_DATA_PUBLISH_INTERVAL, TREATMENT_STOP_DATA_PUBLISH_INTERVAL, TREATMENT_STOP_DATA_PUBLISH_INTERVAL, 0 }; @@ -76,6 +78,7 @@ { currentTxStopState = TREATMENT_STOP_RECIRC_STATE; // Assume blood and dialysate will recirculate initially - will stop pump(s) as appropriate in state machine bloodSittingTimerCtr = 0; + airTrapFillInProgress = FALSE; stopPublishTimerCtr = TREATMENT_STOP_DATA_PUBLISH_INTERVAL; } @@ -112,7 +115,6 @@ setValvePosition( VDO, VALVE_POSITION_C_CLOSE ); setupForBloodRecirculationState(); - setupForDialysateRecirculationState(); signalInitiatePressureStabilization( USE_NORMAL_STABILIZATION_PERIOD ); @@ -182,9 +184,20 @@ doorClosedRequired( TRUE, TRUE ); // Open VBA and VBV valves to patient for blood recirculation setValvePosition( VBA, VALVE_POSITION_B_OPEN ); - setValvePosition( VBV, VALVE_POSITION_B_OPEN ); - // Start blood pump at prescribed flow rate - setBloodPumpTargetFlowRate( getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ), MOTOR_DIR_FORWARD, mode ); + if ( TRUE == isAirTrapFillInProgress() ) + { + // set BP to air trap fill rate if air trap fill has been initiated + setBloodPumpTargetFlowRate( AIR_TRAP_FILL_BLOOD_FLOW_RATE, MOTOR_DIR_FORWARD, mode ); + // close VBV for fill + setValvePosition( VBV, VALVE_POSITION_C_CLOSE ); + } + else + { + // Start blood pump at prescribed flow rate + setBloodPumpTargetFlowRate( getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ), MOTOR_DIR_FORWARD, mode ); + // re-open VBV for blood recirculation + setValvePosition( VBV, VALVE_POSITION_B_OPEN ); + } // Start Heparin pump as appropriate startHeparinPump(); // Start air trap leveling control @@ -290,6 +303,8 @@ break; } + airTrapFillInProgress = isAirTrapFillInProgress(); + if ( priorSubState != currentTxStopState ) { setCurrentSubState( (U32)currentTxStopState ); @@ -307,6 +322,8 @@ * operations to set new states. * @details Inputs: state, flags * @details Outputs: flags handled + * @param state The Tx stop state that we're in now. An invalid state will + * force a re-evaluation of actuator settings based on current status. * @return next treatment re-circulation state *************************************************************************/ static TREATMENT_STOP_STATE_T handleTreatmentStopAlarmsAndSignals( TREATMENT_STOP_STATE_T state ) @@ -317,6 +334,21 @@ BOOL bldAlarmsStatus = ( ( TRUE == isAlarmActive( ALARM_ID_HD_BLOOD_LEAK_RECOVERING_PLEASE_WAIT ) ) && ( FALSE == isAlarmActive( ALARM_ID_HD_BLOOD_LEAK_DETECTED ) ? TRUE : FALSE ) ); + // if an air trap fill has started, set BP rate and VBV state accordingly + if ( ( airTrapFillInProgress != TRUE ) && ( TRUE == isAirTrapFillInProgress() ) ) + { + // set BP to air trap fill rate if air trap fill has been initiated + setBloodPumpTargetFlowRate( AIR_TRAP_FILL_BLOOD_FLOW_RATE, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); + // close VBV for fill + setValvePosition( VBV, VALVE_POSITION_C_CLOSE ); + } + // if an air trap fill has completed, force re-evaluation of state to restore BP and VBV appropriately + else if ( ( TRUE == airTrapFillInProgress ) && ( isAirTrapFillInProgress() != TRUE ) ) + { + state = NUM_OF_TREATMENT_STOP_STATES; // make it look like we're changing states to force re-evaluation + } + + // recovering from blood leak alarm? if ( TRUE == bldAlarmsStatus ) { if ( ( TREATMENT_STOP_RECOVER_BLOOD_DETECT_STATE != state ) && ( dialysateRecircBlocked != TRUE ) ) @@ -325,6 +357,7 @@ result = TREATMENT_STOP_RECOVER_BLOOD_DETECT_STATE; } } + // handling a saline bolus? else if ( ( TRUE == isSalineBolusStartRequested() ) || ( getSalineBolusState() != SALINE_BOLUS_STATE_IDLE ) ) { // No need for setup function since the saline bolus exec function starts from Idle and sets the actuators @@ -333,40 +366,39 @@ if ( SALINE_BOLUS_STATE_IDLE == (U32)getSalineBolusState() ) { // Send the first 4th level state here only when we are in idle - setCurrent4thLevelState( (U32)getSalineBolusState() ); + setCurrent4thLevelState( (U32)SALINE_BOLUS_STATE_IDLE ); } } - else + // Both unblocked and not in recirculate both state + else if ( ( TREATMENT_STOP_RECIRC_STATE != state ) && ( FALSE == dialysateRecircBlocked ) && ( FALSE == bloodRecircBlocked ) ) { - // Both unblocked and not in recirculate both state - if ( ( TREATMENT_STOP_RECIRC_STATE != state ) && ( FALSE == dialysateRecircBlocked ) && ( FALSE == bloodRecircBlocked ) ) - { - setupForBloodRecirculationState(); - setupForDialysateRecirculationState(); - result = TREATMENT_STOP_RECIRC_STATE; - } - // Both blocked and not in stopped state - 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 - 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 - else if ( ( TREATMENT_STOP_RECIRC_DIALYSATE_ONLY_STATE != state ) && ( TRUE == bloodRecircBlocked ) && - ( FALSE == dialysateRecircBlocked ) ) - { - setupForBloodRecirculationStopState(); - result = TREATMENT_STOP_RECIRC_DIALYSATE_ONLY_STATE; - } + setupForBloodRecirculationState(); + setupForDialysateRecirculationState(); + result = TREATMENT_STOP_RECIRC_STATE; } + // Both blocked and not in stopped state + 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 + else if ( ( TREATMENT_STOP_RECIRC_BLOOD_ONLY_STATE != state ) && ( TRUE == dialysateRecircBlocked ) && + ( FALSE == bloodRecircBlocked ) ) + { + setupForBloodRecirculationState(); + setupForDialysateRecirculationStopState(); + result = TREATMENT_STOP_RECIRC_BLOOD_ONLY_STATE; + } + // Blood recirculation blocked and not in dialysate recirc state + else if ( ( TREATMENT_STOP_RECIRC_DIALYSATE_ONLY_STATE != state ) && ( TRUE == bloodRecircBlocked ) && + ( FALSE == dialysateRecircBlocked ) ) + { + setupForBloodRecirculationStopState(); + setupForDialysateRecirculationState(); + result = TREATMENT_STOP_RECIRC_DIALYSATE_ONLY_STATE; + } return result; }