Index: firmware/App/Modes/Dialysis.c =================================================================== diff -u -ra673b3fdaed36dc1e30bce51c8d90218cc96fccb -r2e6c750c202b7361d79488ce383e34f380e75413 --- firmware/App/Modes/Dialysis.c (.../Dialysis.c) (revision a673b3fdaed36dc1e30bce51c8d90218cc96fccb) +++ firmware/App/Modes/Dialysis.c (.../Dialysis.c) (revision 2e6c750c202b7361d79488ce383e34f380e75413) @@ -20,6 +20,7 @@ #include "DialInFlow.h" #include "DialOutFlow.h" #include "OperationModes.h" +#include "TaskGeneral.h" #include "Timers.h" #include "ModeTreatment.h" @@ -30,6 +31,10 @@ // ********** private definitions ********** +#define MAX_UF_ACCURACY_ERROR_ML 250 ///< Maximum ultrafiltration accuracy error in mL over the entire treatment. +#define MAX_UF_ACCURACY_ERROR_ML_PER_HR 100 ///< Maximum ultrafiltration accuracy error in mL/hr. +#define UF_ACCURACY_CHECK_INTERVAL ((1 * MIN_PER_HOUR * SEC_PER_MIN * MS_PER_SECOND) / TASK_GENERAL_INTERVAL) ///< Ultrafiltration rate accuracy check interval count + /// Enumeration of dialysis sub-mode states. typedef enum Dialysis_States { @@ -67,6 +72,9 @@ static F32 maxUFVolumeML; ///< Currently set total ultrafiltration volume for treatment (from prescription). static F32 setUFRate; ///< Currently set ultrafiltration rate (from prescription). +static U32 uFAccuracyCheckTimerCtr; ///< Timer counter to determine when next to check ultrafiltration accuracy. +static F32 lastUFVolumeChecked; ///< Starting ultrafiltration volume for accuracy check. + // ********** private function prototypes ********** static DIALYSIS_STATE_T handleDialysisUltrafiltrationState( void ); @@ -77,6 +85,7 @@ static UF_STATE_T handleUFRunningState( void ); static UF_STATE_T handleUFCompletedOrOffState( void ); +static void checkUFAccuracy( void ); static void updateUFVolumes( void ); /*********************************************************************//** @@ -106,6 +115,9 @@ setDialysateFlowRate = 0; maxUFVolumeML = 0.0; setUFRate = 0.0; + + uFAccuracyCheckTimerCtr = 0; + lastUFVolumeChecked = 0.0; } /*********************************************************************//** @@ -349,6 +361,12 @@ // calculate UF volumes and provide to dialysate outlet pump controller updateUFVolumes(); + // if we've reached target UF volume, UF is complete + if ( measUFVolume >= maxUFVolumeML ) + { + result = UF_COMPLETED_OR_OFF_STATE; + } + // TODO - test code - remove later if ( TRUE == isStopButtonPressed() ) { @@ -385,6 +403,41 @@ /*********************************************************************//** * @brief + * The checkUFAccuracy function checks ultrafiltration accuracy for the last \n + * minute and triggers an alarm if out of spec. + * @details + * Inputs : uFAccuracyCheckTimerCtr, lastUFVolumeChecked, measUFVolume + * Outputs : uFAccuracyCheckTimerCtr, lastUFVolumeChecked + * @return none + *************************************************************************/ +static void checkUFAccuracy( void ) +{ + // check UF accuracy at 1 hour intervals + if ( ++uFAccuracyCheckTimerCtr >= UF_ACCURACY_CHECK_INTERVAL ) + { + F32 uFMeasRatePerHr = measUFVolume - lastUFVolumeChecked; + F32 uFSetRatePerHr = ( setUFRate * (F32)MIN_PER_HOUR ); + F32 uFRateError = uFSetRatePerHr - uFMeasRatePerHr; + + // check UF accuracy + if ( uFRateError > (F32)MAX_UF_ACCURACY_ERROR_ML_PER_HR ) + { + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_UF_RATE_ACCURACY_ERROR, uFSetRatePerHr, uFMeasRatePerHr ); + } + // reset for next check + lastUFVolumeChecked = measUFVolume; + uFAccuracyCheckTimerCtr = 0; + } + + // check total UF volume error + if ( ( FABS( refUFVolume - measUFVolume ) ) >= (F32)MAX_UF_ACCURACY_ERROR_ML ) + { + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_UF_VOLUME_ACCURACY_ERROR, refUFVolume, measUFVolume ); + } +} + +/*********************************************************************//** + * @brief * The updateUFVolumes function updates the ultrafiltration volumes based on \n * set UF rate, latest UF elapsed time, and the latest load cell weight for the \n * currently used reservoir. Updated UF volumes are then sent to the dialysate \n