Index: firmware/App/Controllers/Ultrafiltration.c =================================================================== diff -u -r7278aeac8fdd894067a05c3bd3a177d38c0b0803 -r3f88f2878bfb58d9b67e05ed0717f6fbff136232 --- firmware/App/Controllers/Ultrafiltration.c (.../Ultrafiltration.c) (revision 7278aeac8fdd894067a05c3bd3a177d38c0b0803) +++ firmware/App/Controllers/Ultrafiltration.c (.../Ultrafiltration.c) (revision 3f88f2878bfb58d9b67e05ed0717f6fbff136232) @@ -18,6 +18,7 @@ #include "BalancingChamber.h" #include "ConcentratePumps.h" #include "Messaging.h" +#include "ModeGenDialysate.h" #include "OperationModes.h" #include "TaskGeneral.h" #include "Temperature.h" @@ -36,6 +37,7 @@ #define UF_COMPENSATION_PERIOD ( 2 * SEC_PER_MIN * MS_PER_SECOND ) ///< Interval at which the ultrafiltration compenstaion executed. #define UF_COMP_INTERVAL ( UF_COMPENSATION_PERIOD / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the peroidic ultrafiltration compensation calculated. #define ZERO_RATE 0.0F ///< Zero value. +#define UF_VOL_ML_PER_TASK_INTERVAL ( (F32)TASK_GENERAL_INTERVAL / ( (F32)MS_PER_SECOND * (F32)SEC_PER_MIN ) ) ///< UF volume (mL) delivered per task interval at 1 mL/min. // ********** private data ********** @@ -45,6 +47,7 @@ static U32 ufDataPublicationTimerCounter; ///< Used to schedule ultrafiltration data publication to CAN bus. static BOOL isUFRateUpdated; ///< flag indicating to update UF rate needed. static OVERRIDE_U32_T ufDataPublishInterval; ///< Ultrafiltration data publish interval. +static F32 ufVolumeDeliveredMl; ///< Accumulated UF volume since last reset (mL); shared by delivery and isolated UF. // ********** private function prototypes ********** @@ -69,6 +72,7 @@ compUFrate = getTDUFRate(); ufDataPublicationTimerCounter = 0; isUFRateUpdated = TRUE; + ufVolumeDeliveredMl = 0.0F; } /*********************************************************************//** @@ -127,6 +131,7 @@ { setConcentratePumpTargetSpeed( D76_PUMP, compUFrate, DOSING_CONT_VOLUME ); requestConcentratePumpOn( D76_PUMP ); + ufVolumeDeliveredMl += ( compUFrate * UF_VOL_ML_PER_TASK_INTERVAL ); } else { @@ -139,6 +144,27 @@ /*********************************************************************//** * @brief + * The stopUltrafiltration function stops the UF pump and clears the run + * request flag. + * @details \b Inputs: isUltrafiltrationRequested + * @details \b Outputs: isUltrafiltrationRequested, D76 pump off + * @return none + *************************************************************************/ +void stopUltrafiltration( void ) +{ + BOOL prevUFState = isUltrafiltrationRequested; + + isUltrafiltrationRequested = FALSE; + requestConcentratePumpOff( D76_PUMP, FALSE ); + + if ( prevUFState != isUltrafiltrationRequested ) + { + SEND_EVENT_WITH_2_U32_DATA( DD_EVENT_UF_PUMP_ON_OFF, prevUFState, isUltrafiltrationRequested ); + } +} + +/*********************************************************************//** + * @brief * The updateUFRequest function updates the ultrafiltration requested * flag to true or false based on the compensated UF rate. * @details \b Inputs: compensated UF @@ -148,13 +174,21 @@ static void updateUFRequest( void ) { F32 qd = getTDDialysateFlowrate(); - BOOL bypass = getTDDialyzerBypass(); BOOL prevUFState = isUltrafiltrationRequested; + BOOL allowUF = FALSE; - // update latest UF run/pause request - // if qd is zero or dialyzer is bypassed, UF pump should be turn off - if ( ( compUFrate > ZERO_RATE ) && ( qd > ZERO_RATE ) && ( FALSE == bypass ) ) + // Isolated UF may run with Qd = 0; delivery UF requires Qd > 0 + if ( DD_GEND_ISOLATED_UF_STATE == getCurrentGenDialysateState() ) { + allowUF = TRUE; + } + else if ( qd > ZERO_RATE ) + { + allowUF = TRUE; + } + + if ( ( compUFrate > ZERO_RATE ) && ( TRUE == allowUF ) ) + { isUltrafiltrationRequested = TRUE; } else @@ -184,6 +218,31 @@ /*********************************************************************//** * @brief + * The resetUFVolumeDelivered function clears the accumulated UF volume. + * @details \b Inputs: none + * @details \b Outputs: ufVolumeDeliveredMl + * @return none + *************************************************************************/ +void resetUFVolumeDelivered( void ) +{ + ufVolumeDeliveredMl = 0.0F; +} + +/*********************************************************************//** + * @brief + * The getUFVolumeDeliveredLiters function returns the accumulated UF volume + * delivered in liters. + * @details \b Inputs: ufVolumeDeliveredMl + * @details \b Outputs: none + * @return Accumulated UF volume delivered in L. + *************************************************************************/ +F32 getUFVolumeDeliveredLiters( void ) +{ + return ( ufVolumeDeliveredMl / (F32)ML_PER_LITER ); +} + +/*********************************************************************//** + * @brief * The publishUltrafiltrationData function broadcasts the ultrafiltration * data at defined interval. * @details \b Inputs: ufDataPublicationTimerCounter @@ -201,6 +260,7 @@ data.ufRate = getTDUFRate(); data.compUFrate = compUFrate; data.isUFRequested = (U32)isUltrafiltrationRequested; + data.ufVolumeDeliveredMl = ufVolumeDeliveredMl; broadcastData( MSG_ID_DD_UF_DATA, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&data, sizeof( UF_DATA_T ) );