Index: firmware/App/Controllers/BloodLeak.c =================================================================== diff -u -rc27b1788cee92bcb143d6c4f09d4b278ddded36f -rfae38745527912b9b64e618096556ae7ff263cb8 --- firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision c27b1788cee92bcb143d6c4f09d4b278ddded36f) +++ firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision fae38745527912b9b64e618096556ae7ff263cb8) @@ -1871,7 +1871,6 @@ if ( ( TRUE == isZeroingAllowed ) && ( TRUE == didTimeout( bloodLeakZeroingStatus.driftInRangeStartTimeMS, BLD_ZERO_IN_RANGE_DRIFT_TIMEOUT_MS ) ) ) { - SEND_EVENT_WITH_2_F32_DATA( HD_EVENT_BLOOD_LEAK_ZEROING_REQUIRED, driftMinFromTop, driftMaxFromTop ) status = TRUE; } @@ -1901,13 +1900,13 @@ if ( ( TRUE == isZeroingAllowed ) && ( TRUE == didTimeout( bloodLeakZeroingStatus.driftUpperRangeStartTimeMS, BLD_ZERO_UPPER_RANGE_DRIFT_TIMEOUT_MS ) ) ) { - SEND_EVENT_WITH_2_F32_DATA( HD_EVENT_BLOOD_LEAK_ZEROING_REQUIRED, intensityMvgAvg, 0.0 ) status = TRUE; } return status; } + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ Index: firmware/App/Modes/Dialysis.c =================================================================== diff -u -r00ff72e0b1cf3002e660d850346e26e1209e2b24 -rfae38745527912b9b64e618096556ae7ff263cb8 --- firmware/App/Modes/Dialysis.c (.../Dialysis.c) (revision 00ff72e0b1cf3002e660d850346e26e1209e2b24) +++ firmware/App/Modes/Dialysis.c (.../Dialysis.c) (revision fae38745527912b9b64e618096556ae7ff263cb8) @@ -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 ) { @@ -1155,35 +1155,72 @@ if ( TRUE == bloodLeakZeroingStatus.hasBloodLeakZeroingBeenRequested ) { bloodLeakZeroingStatus.hasBloodLeakZeroingBeenRequested = FALSE; - bloodLeakZeroingStatus.DPiToBLDFlushedVolML = 0.0F; + state = BLD_ZEROING_FLUSH_RSRVR_2_DPI_STATE; + if ( TRUE == bloodLeakZeroingStatus.isZeroingRequestedFromTreatmentStop ) + { + // 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_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; } @@ -1296,10 +1333,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; } @@ -1492,10 +1531,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; @@ -1540,6 +1583,8 @@ { signalInitiatePressureStabilization( USE_NORMAL_STABILIZATION_PERIOD ); } + + SEND_EVENT_WITH_2_F32_DATA( HD_EVENT_BLOOD_LEAK_ZEROING_REQUIRED, 0, 0 ) } /*********************************************************************//** @@ -1552,7 +1597,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; @@ -1619,24 +1665,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; -} - /**@}*/ Index: firmware/App/Modes/Dialysis.h =================================================================== diff -u -rbac52336ea9e23fc2dfb4a802afe49401dfb7057 -rfae38745527912b9b64e618096556ae7ff263cb8 --- firmware/App/Modes/Dialysis.h (.../Dialysis.h) (revision bac52336ea9e23fc2dfb4a802afe49401dfb7057) +++ firmware/App/Modes/Dialysis.h (.../Dialysis.h) (revision fae38745527912b9b64e618096556ae7ff263cb8) @@ -45,6 +45,7 @@ F32 cumSalineVolumeMl; ///< Cumulative saline volume in mL. F32 bolSalineVolumeMl; ///< Bolus saline volume in mL. F32 bloodLeakZeroingDPi2BLDFlushVolumeML; ///< Blood leak zeroing DPi to BLD flush volume in mL. + F32 bloodLeakZeroingRsrvr2DPiFlushVolumeML; ///< Blood leak zeroing reservoir to DPi flush volume in mL. } SALINE_BOLUS_DATA_PAYLOAD_T; #pragma pack(pop) Index: firmware/App/Services/Reservoirs.c =================================================================== diff -u -r00ff72e0b1cf3002e660d850346e26e1209e2b24 -rfae38745527912b9b64e618096556ae7ff263cb8 --- firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 00ff72e0b1cf3002e660d850346e26e1209e2b24) +++ firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision fae38745527912b9b64e618096556ae7ff263cb8) @@ -274,28 +274,19 @@ /*********************************************************************//** * @brief - * The checkReservoirHasBeenSwitched function returns the reservoir has been + * The checkHasReservoirBeenSwitched function returns the reservoir has been * switched flag. - * @details Inputs: none + * @details Inputs: hasReservoirBeenSwitched * @details Outputs: hasReservoirBeenSwitched * @return reservoir has been switched flag *************************************************************************/ -BOOL checkReservoirHasBeenSwitched( void ) +BOOL checkHasReservoirBeenSwitched( void ) { - return hasReservoirBeenSwitched; -} + BOOL status = hasReservoirBeenSwitched; -/*********************************************************************//** - * @brief - * The resetReservoirSwitchFlag function resets the reservoir has been - * switched flag. - * @details Inputs: none - * @details Outputs: hasReservoirBeenSwitched - * @return none - *************************************************************************/ -void resetReservoirSwitchFlag( void ) -{ hasReservoirBeenSwitched = FALSE; + + return status; } // ********** private functions ********** Index: firmware/App/Services/Reservoirs.h =================================================================== diff -u -r00ff72e0b1cf3002e660d850346e26e1209e2b24 -rfae38745527912b9b64e618096556ae7ff263cb8 --- firmware/App/Services/Reservoirs.h (.../Reservoirs.h) (revision 00ff72e0b1cf3002e660d850346e26e1209e2b24) +++ firmware/App/Services/Reservoirs.h (.../Reservoirs.h) (revision fae38745527912b9b64e618096556ae7ff263cb8) @@ -56,8 +56,7 @@ void updateReservoirUFTime( void ); // Update time spent doing ultrafiltration for currently active reservoir U32 getLastReservoirUFTimeInMs( void ); // Get the time spent doing ultrafiltration on the previously active reservoir -BOOL checkReservoirHasBeenSwitched( void ); -void resetReservoirSwitchFlag( void ); +BOOL checkHasReservoirBeenSwitched( void ); BOOL testSetRecirculationLevelPctOverride( F32 value ); // Set override for reciruclation percentage BOOL testResetRecirculationLevelPctOverride( void ); // Reset override for recirulation percentage