Index: firmware/App/Modes/Dialysis.c =================================================================== diff -u -r7abbb238d02b3dfa1d60940e557d0ade0f1b53cc -r8ab3c94988c1381c3e4f0d8fb68fd86a995d5285 --- firmware/App/Modes/Dialysis.c (.../Dialysis.c) (revision 7abbb238d02b3dfa1d60940e557d0ade0f1b53cc) +++ firmware/App/Modes/Dialysis.c (.../Dialysis.c) (revision 8ab3c94988c1381c3e4f0d8fb68fd86a995d5285) @@ -53,7 +53,8 @@ #define MAX_ACTIVE_LOAD_CELL_CHANGE_G 50.0F ///< Maximum delta between new and previous measured UF volume. // 3.07 + 12.28 has been received from the mechanical team and extra volume as margin has been added for safety -#define DPI_TO_BLD_VOLUME_ML ( 3.07F + 12.28F + 8.0F ) ///< Dialysate inlet pump to blood detect sensor volume in milliliters. +#define DPI_2_BLD_VOLUME_ML ( 3.07F + 12.28F + 8.0F ) ///< Dialysate inlet pump to blood detect sensor volume in milliliters. +#define RSRVR_2_DPI_VOLUME_ML ( 70.0 + 5.0F ) ///< Reservoir to dialysate inlet pump volume in milliliters. /// Defined states for the Load Cell cycles. typedef enum Reservoir_Steady_Cycle @@ -68,7 +69,8 @@ /// Blood leak treatment zeroing data structure typedef struct { - F32 DPiToBLDFlushedVolML; ///< Dialysate inlet pump to blood leak flushed volume in milliliters. + F32 DPi2BLDFlushedVolML; ///< Dialysate inlet pump to blood leak flushed volume in milliliters. + F32 rsrvr2DPiFlushedVolML; ///< Active reservoir to dialysate inlet pump flushed volume in milliliters. BOOL hasBloodLeakZeroingBeenRequested; ///< Flag to indicate blood leak zeroing has been requested. BOOL isZeroingRequestedFromTreatmentStop; ///< Flag to indicate blood leak zeroing has been requested from treatment stop. BOOL isZeroingNeededAfterRsrvrSwitch; ///< Flag to indicate blood leak zeroing is needed after reservoir switch. @@ -121,7 +123,8 @@ static SALINE_BOLUS_STATE_T handleSalineBolusMaxDeliveredState( DIALYSIS_STATE_T *dialysisState ); static BLOOD_LEAK_ZEROING_STATE_T handleBloodLeakZeroingIdleState( void ); -static BLOOD_LEAK_ZEROING_STATE_T handleBloodLeakZeroingFlushState( void ); +static BLOOD_LEAK_ZEROING_STATE_T handleBloodLeakZeroingFlushReservoir2DPiState( void ); +static BLOOD_LEAK_ZEROING_STATE_T handleBloodLeakZeroingFlushDPi2BLDState( void ); static BLOOD_LEAK_ZEROING_STATE_T handleBloodLeakZeroingZeroState( void ); static BLOOD_LEAK_ZEROING_STATE_T handleBloodLeakZeroingVerifyZeroingState( void ); static BLOOD_LEAK_ZEROING_STATE_T handleBloodLeakZeroingCompleteState( DIALYSIS_STATE_T *dialysisState ); @@ -131,7 +134,6 @@ static void publishSalineBolusData( void ); static void checkLoadCellsStablePrimaryBackupDriftOutOfRange( DG_RESERVOIR_ID_T reservoirID, RESERVOIR_STEADY_CYCLE_T cycle ); -static BOOL hasDPiToBLDVolumeBeenFlushed( void ); /*********************************************************************//** * @brief @@ -702,16 +704,14 @@ if ( ( TRUE == bloodLeakZeroingStatus.isZeroingNeededAfterRsrvrSwitch ) && ( DIALYSIS_UF_STATE == currentDialysisState ) ) { - if ( TRUE == checkReservoirHasBeenSwitched() ) + if ( TRUE == checkHasReservoirBeenSwitched() ) { // Reset the blood leak zeroing variables resetBloodLeakZeroing(); requestBloodLeakZeroing( FALSE ); } } - resetReservoirSwitchFlag(); - // Dialysis state machine switch ( currentDialysisState ) { @@ -1154,35 +1154,71 @@ if ( TRUE == bloodLeakZeroingStatus.hasBloodLeakZeroingBeenRequested ) { bloodLeakZeroingStatus.hasBloodLeakZeroingBeenRequested = FALSE; - bloodLeakZeroingStatus.DPiToBLDFlushedVolML = 0.0F; + state = BLD_ZEROING_FLUSH_RSRVR_2_DPI_STATE; + if ( TRUE == bloodLeakZeroingStatus.isZeroingRequestedFromTreatmentStop ) + { + // Cmd DPo to stop + setDialOutPumpTargetRate( 0, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); + + setValvePosition( VDI, VALVE_POSITION_C_CLOSE ); + setValvePosition( VDO, VALVE_POSITION_C_CLOSE ); + + state = BLD_ZEROING_FLUSH_DPI_2_BLD_STATE; + } + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleBloodLeakZeroingFlushReservoir2DPiState function handles the + * blood leak zeroing flush reservoir to dialysate inlet pump state. + * @details Inputs: bloodLeakZeroingStatus + * @details Outputs: bloodLeakZeroingStatus + * @return next state of the blood leak zeroing state + *************************************************************************/ +static BLOOD_LEAK_ZEROING_STATE_T handleBloodLeakZeroingFlushReservoir2DPiState( void ) +{ + BLOOD_LEAK_ZEROING_STATE_T state = BLD_ZEROING_FLUSH_RSRVR_2_DPI_STATE; + F32 measuredDPiMLPM = getMeasuredDialInFlowRate(); + + bloodLeakZeroingStatus.rsrvr2DPiFlushedVolML += ( (F32)( measuredDPiMLPM * TASK_GENERAL_INTERVAL ) / (F32)( SEC_PER_MIN * MS_PER_SECOND ) ); + + if ( bloodLeakZeroingStatus.rsrvr2DPiFlushedVolML > RSRVR_2_DPI_VOLUME_ML ) + { // Cmd all pumps to stop setDialOutPumpTargetRate( 0, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); stopSyringePump(); setValvePosition( VDI, VALVE_POSITION_C_CLOSE ); setValvePosition( VDO, VALVE_POSITION_C_CLOSE ); - state = BLD_ZEROING_FLUSH_STATE; + state = BLD_ZEROING_FLUSH_DPI_2_BLD_STATE; } return state; } /*********************************************************************//** * @brief - * The handleBloodLeakZeroingFlushState function handles the blood leak zeroing + * The handleBloodLeakZeroingFlushDPi2BLDState function handles the blood + * leak zeroing * flush state. In this state, the line in between the dialysate inlet pump * to blood leak detector is flushed with new dialysate. - * @details Inputs: none - * @details Outputs: none + * @details Inputs: bloodLeakZeroingStatus + * @details Outputs: bloodLeakZeroingStatus * @return next state of the blood leak zeroing state *************************************************************************/ -static BLOOD_LEAK_ZEROING_STATE_T handleBloodLeakZeroingFlushState( void ) +static BLOOD_LEAK_ZEROING_STATE_T handleBloodLeakZeroingFlushDPi2BLDState( void ) { - BLOOD_LEAK_ZEROING_STATE_T state = BLD_ZEROING_FLUSH_STATE; + BLOOD_LEAK_ZEROING_STATE_T state = BLD_ZEROING_FLUSH_DPI_2_BLD_STATE; + F32 measuredDPiMLPM = getMeasuredDialInFlowRate(); - if ( TRUE == hasDPiToBLDVolumeBeenFlushed() ) + bloodLeakZeroingStatus.DPi2BLDFlushedVolML += ( (F32)( measuredDPiMLPM * TASK_GENERAL_INTERVAL ) / (F32)( SEC_PER_MIN * MS_PER_SECOND ) ); + + if ( bloodLeakZeroingStatus.DPi2BLDFlushedVolML > DPI_2_BLD_VOLUME_ML ) { state = BLD_ZEROING_ZERO_STATE; } @@ -1295,10 +1331,12 @@ { SALINE_BOLUS_DATA_PAYLOAD_T data; - data.tgtSalineVolumeMl = getTreatmentParameterU32( TREATMENT_PARAM_SALINE_BOLUS_VOLUME ); - data.cumSalineVolumeMl = totalSalineVolumeDelivered_mL; - data.bolSalineVolumeMl = bolusSalineVolumeDelivered_mL; - data.bloodLeakZeroingDPi2BLDFlushVolumeML = bloodLeakZeroingStatus.DPiToBLDFlushedVolML; + data.tgtSalineVolumeMl = getTreatmentParameterU32( TREATMENT_PARAM_SALINE_BOLUS_VOLUME ); + data.cumSalineVolumeMl = totalSalineVolumeDelivered_mL; + data.bolSalineVolumeMl = bolusSalineVolumeDelivered_mL; + data.bloodLeakZeroingDPi2BLDFlushVolumeML = bloodLeakZeroingStatus.DPi2BLDFlushedVolML; + data.bloodLeakZeroingRsrvr2DPiFlushVolumeML = bloodLeakZeroingStatus.rsrvr2DPiFlushedVolML; + broadcastData( MSG_ID_SALINE_BOLUS_DATA, COMM_BUFFER_OUT_CAN_HD_BROADCAST, (U08*)&data, sizeof( SALINE_BOLUS_DATA_PAYLOAD_T ) ); salineBolusBroadcastTimerCtr = 0; } @@ -1491,10 +1529,14 @@ bloodLeakZeroingStatus.bloodLeakZeroingState = handleBloodLeakZeroingIdleState(); break; - case BLD_ZEROING_FLUSH_STATE: - bloodLeakZeroingStatus.bloodLeakZeroingState = handleBloodLeakZeroingFlushState(); + case BLD_ZEROING_FLUSH_RSRVR_2_DPI_STATE: + bloodLeakZeroingStatus.bloodLeakZeroingState = handleBloodLeakZeroingFlushReservoir2DPiState(); break; + case BLD_ZEROING_FLUSH_DPI_2_BLD_STATE: + bloodLeakZeroingStatus.bloodLeakZeroingState = handleBloodLeakZeroingFlushDPi2BLDState(); + break; + case BLD_ZEROING_ZERO_STATE: bloodLeakZeroingStatus.bloodLeakZeroingState = handleBloodLeakZeroingZeroState(); break; @@ -1539,6 +1581,8 @@ { signalInitiatePressureStabilization( USE_NORMAL_STABILIZATION_PERIOD ); } + + SEND_EVENT_WITH_2_F32_DATA( HD_EVENT_BLOOD_LEAK_ZEROING_REQUIRED, 0, 0 ) } /*********************************************************************//** @@ -1551,7 +1595,8 @@ *************************************************************************/ void resetBloodLeakZeroing( void ) { - bloodLeakZeroingStatus.DPiToBLDFlushedVolML = 0.0F; + bloodLeakZeroingStatus.DPi2BLDFlushedVolML = 0.0F; + bloodLeakZeroingStatus.rsrvr2DPiFlushedVolML = 0.0F; bloodLeakZeroingStatus.bloodLeakZeroingState = BLD_ZEROING_IDLE_STATE; bloodLeakZeroingStatus.hasBloodLeakZeroingBeenRequested = FALSE; bloodLeakZeroingStatus.isZeroingRequestedFromTreatmentStop = FALSE; @@ -1618,24 +1663,4 @@ } } -/*********************************************************************//** - * @brief - * The hasDPiToBLDVolumeBeenFlushed function checks whether the line in - * between dialysate inlet pump to the blood leak detector has been flushed - * with fresh fluid or not. - * @details Inputs: bloodLeakZeroing - * @details Outputs: bloodLeakZeroing - * @return TRUE if the line has been flushed otherwise, FALSE - *************************************************************************/ -static BOOL hasDPiToBLDVolumeBeenFlushed( void ) -{ - BOOL status = FALSE; - F32 measuredDPiMLPM = getMeasuredDialInFlowRate(); - - bloodLeakZeroingStatus.DPiToBLDFlushedVolML += ( (F32)( measuredDPiMLPM * TASK_GENERAL_INTERVAL ) / (F32)( SEC_PER_MIN * MS_PER_SECOND ) ); - status = ( bloodLeakZeroingStatus.DPiToBLDFlushedVolML > DPI_TO_BLD_VOLUME_ML ? TRUE : FALSE ); - - return status; -} - /**@}*/