Index: firmware/App/Controllers/BloodLeak.c =================================================================== diff -u -r656e6c800f80af3f5fc318051356f87832219689 -r32309398e7ef59471bd624e34ab6b91cdaaf9d24 --- firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 656e6c800f80af3f5fc318051356f87832219689) +++ firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 32309398e7ef59471bd624e34ab6b91cdaaf9d24) @@ -96,6 +96,7 @@ // ***************** zeroing status *************** // #define BLD_NOMINAL_INTENSITY 930 ///< Blood leak nominal intensity. +#define BLD_MAX_INTENSITY_DRIFT_AFTER_ZEROING ( BLD_NOMINAL_INTENSITY * 0.01F ) ///< Blood leak max intensity drift after zeroing. #define BLD_MAX_INTENSITY_OUT_OF_RANGE 0.40F ///< Blood leak maximum allowed intensity. #define BLD_MIN_INTENSITY_OUT_OF_RANGE 0.35F ///< Blood leak minimum allowed intensity. #define BLD_ZERO_MIN_INTERVAL_MS ( 30 * SEC_PER_MIN * MS_PER_SECOND ) ///< Blood leak zeroing minimum interval in milliseconds. @@ -231,7 +232,6 @@ static BLOOD_LEAK_STATUS_T getFPGABloodDetectProcessedStatus( void ); static BOOL isDialysateLineInBypass( void ); static void processBloodLeakIntensityData( void ); -static void checkBloodLeakDrift( void ); static void signalEmbModeCmdRespConsumed( U08 cmd ); /*********************************************************************//** @@ -401,7 +401,7 @@ *************************************************************************/ BOOL zeroBloodLeak( void ) { - BOOL status = TRUE; + BOOL status = FALSE; if ( getAvailableEmbModeQueueCount() >= BLOOD_LEAK_EMB_MODE_ZERO_CMD_RQRD_Q ) { @@ -462,6 +462,21 @@ return status; } +BLOOD_LEAK_INTENSITY_CHECK_T getBloodLeakIntensityStatusAfterZeroing( void ) +{ + BLOOD_LEAK_INTENSITY_CHECK_T status = BLOOD_LEAK_INTENSITY_WAIT_FOR_FRESH_DATA; + + if ( TRUE == bloodLeakEmbModeCmd[ I_EMB_MODE_CMD ].isCmdRespRdy ) + { + U32 intensity = bloodLeakEmbModeCmd[ I_EMB_MODE_CMD ].commandResp; + + status = ( abs( BLD_NOMINAL_INTENSITY - intensity ) <= BLD_MAX_INTENSITY_DRIFT_AFTER_ZEROING ? BLOOD_LEAK_INTENSITY_IN_RANGE : + BLOOD_LEAK_INTENSITY_OUT_OF_RANGE ); + } + + return status; +} + /*********************************************************************//** * @brief * The exitBloodLeakNormalState requests that the blood leak sensor to exit @@ -726,8 +741,6 @@ bloodLeakPersistenceCtr = 0; } - checkBloodLeakDrift(); - switch ( getCurrentOperationMode() ) { case MODE_TREA: @@ -868,6 +881,39 @@ /*********************************************************************//** * @brief + * The isBloodLeakZeroingNeeded function checks whether blood leak zeroing + * is needed in terms of drift. + * @details Inputs: bloodLeakZeroingStatus + * @details Outputs: bloodLeakZeroingStatus + * @return TRUE if blood leak zeroing is needed otherwise, FALSE + *************************************************************************/ +BOOL isBloodLeakZeroingNeeded( void ) +{ + BOOL status = FALSE; + BOOL isZeroingNeeded = TRUE; + U32 setPoint = bloodLeakEmbModeCmd[ SP_EMB_MODE_CMD ].commandResp; + F32 driftMinFromTop = BLD_NOMINAL_INTENSITY - ( setPoint * BLD_MAX_INTENSITY_OUT_OF_RANGE ); + F32 driftMaxFromTop = BLD_NOMINAL_INTENSITY - ( setPoint * BLD_MIN_INTENSITY_OUT_OF_RANGE ); + BOOL isZeroingAllowed = didTimeout( bloodLeakZeroingStatus.lastZeroingStartTimeMS, BLD_ZERO_MIN_INTERVAL_MS ); + + isZeroingNeeded &= ( bloodLeakZeroingStatus.intensityMovingAverage >= driftMinFromTop ? TRUE : FALSE ); + isZeroingNeeded &= ( bloodLeakZeroingStatus.intensityMovingAverage <= driftMaxFromTop ? TRUE : FALSE ); + + if ( FALSE == isZeroingNeeded ) + { + bloodLeakZeroingStatus.driftInRangeStartTimeMS = getMSTimerCount(); + } + + if ( ( TRUE == isZeroingAllowed ) && ( TRUE == didTimeout( bloodLeakZeroingStatus.driftInRangeStartTimeMS, BLD_ZERO_IN_RANGE_DRIFT_TIMEOUT_MS ) ) ) + { + status = TRUE; + } + + return status; +} + +/*********************************************************************//** + * @brief * The handleBloodLeakEmbModeWaitForCommandState function handles the wait for * command state. The state prepares the message to be sent to the blood leak * sensor. @@ -1607,10 +1653,6 @@ { enqueueEmbModeCmd( V_EMB_MODE_CMD ); } - //else if ( 2 == bloodLeakEmbModeInfoCmdCounter ) - //{ - // enqueueEmbModeCmd( D_EMB_MODE_CMD ); - //} // Set the timer for the next time out to enqueue // Reset the counter. The counter starts from 0 @@ -1690,39 +1732,8 @@ signalEmbModeCmdRespConsumed( I_EMB_MODE_CMD ); } } - /*********************************************************************//** * @brief - * The checkBloodLeakDrift function checks for blood leak drift and if the - * conditions are met, it proceeds with requesting the zero sequence again. - * @details Inputs: bloodLeakZeroingStatus - * @details Outputs: bloodLeakZeroingStatus - * @return none - *************************************************************************/ -static void checkBloodLeakDrift( void ) -{ - BOOL isZeroingNeeded = TRUE; - U32 setPoint = bloodLeakEmbModeCmd[ SP_EMB_MODE_CMD ].commandResp; - F32 driftMinFromTop = BLD_NOMINAL_INTENSITY - ( setPoint * BLD_MAX_INTENSITY_OUT_OF_RANGE ); - F32 driftMaxFromTop = BLD_NOMINAL_INTENSITY - ( setPoint * BLD_MIN_INTENSITY_OUT_OF_RANGE ); - BOOL isZeroingAllowed = didTimeout( bloodLeakZeroingStatus.lastZeroingStartTimeMS, BLD_ZERO_MIN_INTERVAL_MS ); - - isZeroingNeeded &= ( bloodLeakZeroingStatus.intensityMovingAverage >= driftMinFromTop ? TRUE : FALSE ); - isZeroingNeeded &= ( bloodLeakZeroingStatus.intensityMovingAverage <= driftMaxFromTop ? TRUE : FALSE ); - - if ( FALSE == isZeroingNeeded ) - { - bloodLeakZeroingStatus.driftInRangeStartTimeMS = getMSTimerCount(); - } - - if ( ( TRUE == isZeroingAllowed ) && ( TRUE == didTimeout( bloodLeakZeroingStatus.driftInRangeStartTimeMS, BLD_ZERO_IN_RANGE_DRIFT_TIMEOUT_MS ) ) ) - { - zeroBloodLeak(); - } -} - -/*********************************************************************//** - * @brief * The signalEmbModeCmdRespConsumed function sets the cmd response ready flag * to false its flag that fresh data is ready. * @details Inputs: none