Index: firmware/App/Controllers/HemoDiaFiltration.c =================================================================== diff -u -rfff7eb3560421130e0cd4788f84bce0a8ee7ff44 -r8acb1d02ac39d202a47338091b249ff2f30f5ea7 --- firmware/App/Controllers/HemoDiaFiltration.c (.../HemoDiaFiltration.c) (revision fff7eb3560421130e0cd4788f84bce0a8ee7ff44) +++ firmware/App/Controllers/HemoDiaFiltration.c (.../HemoDiaFiltration.c) (revision 8acb1d02ac39d202a47338091b249ff2f30f5ea7) @@ -34,20 +34,21 @@ #define HDF_DATA_PUBLISH_INTERVAL ( 1000 / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the hemodiafiltration data published. #define SECONDS_PER_MINUTE 60 ///< seconds per minute -#define HDF_CONTROL_PERIOD_SECONDS 2 ///< Interval at which the hemodiafiltration flow rate adjustment is executed in seconds +#define HDF_CONTROL_PERIOD_SECONDS 4 ///< Interval at which the hemodiafiltration flow rate adjustment is executed in seconds #define HDF_CONTROL_PERIOD_MS ( HDF_CONTROL_PERIOD_SECONDS * MS_PER_SECOND ) ///< Interval at which the hemodiafiltration flow rate adjustment is executed in milliseconds #define HDF_CONTROL_INTERVAL ( HDF_CONTROL_PERIOD_MS / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the peroidic hemodiafiltration flow rate is calculated. #define ZERO_RATE 0.0F ///< Zero value. #define SUB_PUMP_PRESSURE_CONTROL_P_COEFFICIENT 0.5F ///< P term for Sub pump pressure control. #define SUB_PUMP_PRESSURE_CONTROL_I_COEFFICIENT 5.0F ///< I term for Sub pump pressure control. +#define HDF_TMP_TARGET 250.0F ///< TMP pressure that the controller will target to once volume has been set. // ********** private data ********** static HDF_EXEC_STATE_T hdfExecState; ///< Current hemodiafiltration executive state. static BOOL isHemodiafiltrationRequested; ///< Flag indicating hemodiafiltration request. static U32 hdfControlTimerCounter; ///< Counter (in task interval) to initiate the periodic hemodiafiltration rate recalculation. -static F32 hdfCurrentRate; ///< current HDF rate in ml/min -static F32 hdfTMPTarget; ///< HDF target TMP +static OVERRIDE_F32_T hdfCurrentRate; ///< current HDF rate in ml/min +static OVERRIDE_F32_T hdfTMPTarget; ///< HDF target TMP static F32 hdfManualRate; ///< Manually set HDF rate static F32 hdfMaximumVolume; ///< Maximum HDF volume setting static F32 hdfCurrentVolume; ///< current HDF delivered substitution volume @@ -85,10 +86,16 @@ hdfDataPublishInterval.ovInitData = 0; hdfDataPublishInterval.override = OVERRIDE_RESET; isHemodiafiltrationRequested = FALSE; - hdfTMPTarget = 0.0; + hdfTMPTarget.data = 0.0; + hdfTMPTarget.ovData = 0.0; + hdfTMPTarget.ovInitData = 0.0; + hdfTMPTarget.override = OVERRIDE_RESET; hdfManualRate = 0.0; hdfControlTimerCounter = 0; - hdfCurrentRate = 0.0; + hdfCurrentRate.data = 0.0; + hdfCurrentRate.ovData = 0.0; + hdfCurrentRate.ovInitData = 0.0; + hdfCurrentRate.override = OVERRIDE_RESET; hdfLastActiveRate = HDF_MAX_RATE; hdfMaximumVolume = 0.0; hdfCurrentVolume = 0.0; @@ -127,7 +134,7 @@ if ( TRUE == isHDFRateUpdated ) { // Update HDF rate - cmdChangeQhdf( hdfCurrentRate ); // this results in a message to DD to change the hdf pump rate + cmdChangeQhdf( getCurrentHDFRate() ); // this results in a message to DD to change the hdf pump rate isHDFRateUpdated = FALSE; } @@ -171,16 +178,16 @@ // manual rate set, use that as the proposed rate if ( hdfManualRate > ZERO_RATE ) { - hdfCurrentRate = CheckHDFRate( hdfManualRate ); + hdfCurrentRate.data = CheckHDFRate( hdfManualRate ); } else { // TMP control, resume with previous HDF rate // TODO: make sure that hdfCurrentRate is not 0 if HDF is actually wanted (volume not > max) - hdfCurrentRate = CheckHDFRate( hdfCurrentRate ); - if ( hdfCurrentRate > ZERO_RATE ) + hdfCurrentRate.data = CheckHDFRate( hdfCurrentRate.data ); + if ( getCurrentHDFRate() > ZERO_RATE ) { - resetPIDController( PID_CONTROLLER_ID_SUB_PUMP_PRES, hdfCurrentRate, 0.0F ); + resetPIDController( PID_CONTROLLER_ID_SUB_PUMP_PRES, getCurrentHDFRate(), 0.0F ); hdfControlTimerCounter = 0; } } @@ -206,7 +213,7 @@ if ( TRUE != isHemodiafiltrationRequested ) { - hdfCurrentRate = 0.0; + hdfCurrentRate.data = 0.0; isHDFRateUpdated = TRUE; state = TD_HDF_PAUSED; } @@ -227,7 +234,7 @@ *************************************************************************/ void setHemodiafiltrationParameters( F32 setHDFTMPTarget, F32 setHDFMaximumVolume ) { - hdfTMPTarget = setHDFTMPTarget; // mmHg + hdfTMPTarget.data = setHDFTMPTarget; // mmHg hdfMaximumVolume = setHDFMaximumVolume; // ml } @@ -256,7 +263,7 @@ void StartHemodiafiltration( void ) { isHemodiafiltrationRequested = TRUE; - hdfCurrentRate = hdfLastActiveRate; + hdfCurrentRate.data = hdfLastActiveRate; } /*********************************************************************//** @@ -269,7 +276,7 @@ void StopHemodiafiltration( void ) { isHemodiafiltrationRequested = FALSE; - hdfLastActiveRate = hdfCurrentRate; + hdfLastActiveRate = hdfCurrentRate.data; } /*********************************************************************//** @@ -302,7 +309,7 @@ /*********************************************************************//** * @brief - * The UpdateHDFCompensation function updates the hemodiafiltration rate + * The UpdateHDFRateAndVolume function updates the hemodiafiltration rate * based on the trans-membrane-pressure * @details \b Inputs: D41 and H14 temperature * @details \b Outputs: updated HDF rate @@ -318,17 +325,17 @@ // get new rate from PI controller if ( ZERO_RATE == hdfManualRate ) { - new_rate = runPIDController( PID_CONTROLLER_ID_SUB_PUMP_PRES, hdfTMPTarget, getLongFilteredTMPPressure() ); - hdfCurrentRate = CheckHDFRate( new_rate ); + new_rate = runPIDController( PID_CONTROLLER_ID_SUB_PUMP_PRES, getCurrentHDFTMPTarget(), getLongFilteredTMPPressure() ); + hdfCurrentRate.data = CheckHDFRate( new_rate ); } // update and check volume - hdfCurrentVolume += ((F32) HDF_CONTROL_PERIOD_SECONDS / (F32) SECONDS_PER_MINUTE) * hdfCurrentRate; //ml + hdfCurrentVolume += ((F32) HDF_CONTROL_PERIOD_SECONDS / (F32) SECONDS_PER_MINUTE) * hdfCurrentRate.data; //ml if ( hdfCurrentVolume > hdfMaximumVolume ) { reachedMaximumHDFVolume = TRUE; // Done delivering HDF, turn off pump and go to pause state - hdfCurrentRate = ZERO_RATE; + hdfCurrentRate.data = ZERO_RATE; hdfExecState = TD_HDF_PAUSED; } hdfControlTimerCounter = 0; @@ -351,6 +358,19 @@ /*********************************************************************//** * @brief + * The getCurrentHDFTMPTarget function returns the current TMP Target + * of the hemodiafiltration. + * @details \b Inputs: hdfTMPTarget + * @details \b Outputs: none + * @return the current state of HDF TMP Target. + *************************************************************************/ +F32 getCurrentHDFTMPTarget( void ) +{ + return getF32OverrideValue( &hdfTMPTarget ); +} + +/*********************************************************************//** + * @brief * The getCurrentHDFRate function returns the current rate * of the hemodiafiltration. * @details \b Inputs: hdfCurrentRate @@ -359,7 +379,7 @@ *************************************************************************/ F32 getCurrentHDFRate( void ) { - return hdfCurrentRate; + return getF32OverrideValue( &hdfCurrentRate ); } /*********************************************************************//** @@ -380,8 +400,8 @@ data.hdfExecState = (U32)hdfExecState; data.hdfRequestedRate = hdfManualRate; - data.hdfTargetTMP = hdfTMPTarget; - data.hdfCurrentRate = hdfCurrentRate; + data.hdfTargetTMP = getCurrentHDFTMPTarget(); + data.hdfCurrentRate = getCurrentHDFRate(); data.hdfCurrentTMP = getLongFilteredTMPPressure(); data.isHDFRequested = (U32)isHemodiafiltrationRequested; data.hdfRequestedVolume = hdfMaximumVolume; @@ -400,7 +420,7 @@ /*********************************************************************//** * @brief * The testTDHDFDataPublishIntervalOverride function overrides the - * DD hemodiafiltration data publish interval. + * TD hemodiafiltration data publish interval. * @details \b Inputs: hdfDataPublishInterval * @details \b Outputs: hdfDataPublishInterval * @param Override message from Dialin which includes the interval @@ -414,6 +434,50 @@ return result; } +/*********************************************************************//** + * @brief + * The testTDHDFCurrentRateOverride function overrides the + * HDF current rate. + * @details \b Inputs: none + * @details \b Outputs: hdfCurrentRate + * @param: message Override message from Dialin which includes + * HDF current rate (in mL/hour) + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testTDHDFCurrentRateOverride( MESSAGE_T *message ) +{ + BOOL result = f32Override( message, &hdfCurrentRate ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testTDHDFTargetTMPOverride function overrides the + * TMP target. + * @details \b Inputs: none + * @details \b Outputs: hdfTMPTarget + * @param: message Override message from Dialin which includes + * tmp target that HDF controls to in mm/hg. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testTDHDFTargetTMPOverride( MESSAGE_T *message ) +{ + BOOL result = f32Override( message, &hdfTMPTarget ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testTDHDFStartStopHDFOverride function starts the HDF Controller + * at mentioned TMP target, flow rate, and total volume. + * @details \b Inputs: tester logged in + * @details \b Outputs: hdfTMPTarget, hdfCurrentRate, hdfVolume + * @param message set message from Dialin which includes the data to set + * and the state to set the sub pump to. + * @return TRUE if set request is successful, FALSE if not + *************************************************************************/ BOOL testTDHDFStartStopHDFOverride( MESSAGE_T *message ) { BOOL result = FALSE;