Index: firmware/App/Monitors/Pressures.c =================================================================== diff -u -r4fd2b355f467baa04535272f58589e2a60443201 -r9f3f6f601dba9f278440bba6beba5ea19cadb3a9 --- firmware/App/Monitors/Pressures.c (.../Pressures.c) (revision 4fd2b355f467baa04535272f58589e2a60443201) +++ firmware/App/Monitors/Pressures.c (.../Pressures.c) (revision 9f3f6f601dba9f278440bba6beba5ea19cadb3a9) @@ -101,10 +101,12 @@ #define SIZE_OF_LONG_ART_ROLLING_AVG ( ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) * 10 ) /// Measured arterial pressure is filtered w/ 1 second moving average for inline pressure. #define SIZE_OF_SHORT_ART_ROLLING_AVG ( ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) * 1 ) -/// Measured arterial pressure is filtered w/ 10 second moving average for pressure compensation of flow. +/// Measured venous pressure is filtered w/ 10 second moving average for pressure compensation of flow. #define SIZE_OF_LONG_VEN_ROLLING_AVG ( ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) * 10 ) /// Measured venous pressure is filtered w/ 1 second moving average for inline pressure and unfiltered for occlusion detection. #define SIZE_OF_SHORT_VEN_ROLLING_AVG ( ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) * 1 ) +/// Measured trans-membrane pressure is filtered w/ 10 second moving average for pressure compensation of flow. +#define SIZE_OF_LONG_TMP_ROLLING_AVG ( ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) * 10 ) #define DATA_PUBLISH_COUNTER_START_COUNT 5 ///< Data publish counter start count. @@ -160,6 +162,7 @@ static OVERRIDE_F32_T shortFilteredArterialPressure; ///< Measured arterial pressure after short (1 s) filter (in mmHg). static F32 longFilteredVenousPressure; ///< Measured venous pressure after long (10 s) filter (in mmHg). static OVERRIDE_F32_T shortFilteredVenousPressure; ///< Measured venous pressure after short (1 s) filter (in mmHg). +static F32 longFilteredTmpPressure; ///< Measured trans-membrane pressure after long (10 s) filter (in mmHg). static OVERRIDE_F32_T tmpPressure; ///< Calculated trans-membrane pressure (in mmHg). static STABILIZATION_PERIODS_T pressureStabilizeTime; ///< Pressure stabilization time based on system events such as airpump, treatment param changes etc., static BOOL resetFillExemptPeriod; ///< Flag to reset the exempt period after defined time expire. @@ -191,6 +194,11 @@ static U32 venPressureReadingsShortCount; ///< Number of samples in flow rolling average buffer. static BARO_MOVING_AVG_DATA_T baroMovingAvg; ///< Barometric sensor moving average. +static F32 tmpPressureReadingsLong[ SIZE_OF_LONG_TMP_ROLLING_AVG ]; ///< Holds flow samples for long trans-membrane pressure rolling average. +static U32 tmpPressureReadingsLongIdx; ///< Index for next sample in rolling average array. +static F32 tmpPressureReadingsLongTotal; ///< Rolling total - used to calc average. +static U32 tmpPressureReadingsLongCount; ///< Number of samples in flow rolling average buffer. + static PRESSURE_SELF_TEST_STATE_T pressurePostState; ///< Pressure self test post state. //static HD_PRESSURE_SENSORS_CAL_RECORD_T pressureSensorsCalRecord; ///< Pressure sensors calibration record. @@ -204,7 +212,7 @@ static void checkTmpPressureInRange( void ); static void publishPressureData( void ); static void determineArtVenPressureLimits( void ); -static void filterInlinePressureReadings( F32 artPres, F32 venPres ); +static void filterInlinePressureReadings( F32 artPres, F32 venPres, F32 tmpPres ); static void filterBaroPressureReadings( F32 baroPresPSI ); /*********************************************************************//** @@ -286,6 +294,10 @@ venPressureReadingsShortTotal = 0.0F; venPressureReadingsShortCount = 0; + tmpPressureReadingsLongIdx = 0; + tmpPressureReadingsLongTotal = 0.0F; + tmpPressureReadingsLongCount = 0; + baroMovingAvg.baroAvgPSI.data = 0.0F; baroMovingAvg.baroAvgPSI.ovData = 0.0F; baroMovingAvg.baroAvgPSI.ovInitData = 0.0F; @@ -418,8 +430,8 @@ filtVen = getLongFilteredVenousPressure(); } - // TMP uses the same venous filter selection as the pressure stabilization and the latest dialysate pressure. - filtTmp = filtVen - ( getDialysatePressure() * PSI_TO_MMHG ); + // Using final TMP value for override. + filtTmp = getTMPPressure(); curArtPres = FLOAT_TO_INT_WITH_ROUND( filtArt ); curVenPres = FLOAT_TO_INT_WITH_ROUND( filtVen ); @@ -575,10 +587,11 @@ PRESSURE_STATE_T result = PRESSURE_CONTINUOUS_READ_STATE; F32 fpgaArtPres = getPressure( H2_PRES ) - arterialPressureOffset; F32 fpgaVenPres = getPressure( H14_PRES ) - venousPressureOffset; + F32 tmpPres = getTMPPressure(); F32 fpgaBaroPresPSI = getPressure( H23_PRES ); // Filter inline pressure readings - filterInlinePressureReadings( fpgaArtPres, fpgaVenPres ); + filterInlinePressureReadings( fpgaArtPres, fpgaVenPres, tmpPres); // Filter the baro pressure filterBaroPressureReadings( fpgaBaroPresPSI ); @@ -595,6 +608,7 @@ #ifndef TEST_NO_PRESSURE_CHECKS checkArterialPressureInRange(); checkVenousPressureInRange(); + checkTMPPressureInRange(); #endif return result; @@ -977,6 +991,19 @@ /*********************************************************************//** * @brief + * The getLongFilteredTMPPressure function gets the current long filtered + * trans-membrane pressure. + * @details \b Inputs: longFilteredTmpPressure + * @details \b Outputs: none + * @return the current long filtered trans-membrane pressure (in mmHg). + *************************************************************************/ +F32 getLongFilteredTMPPressure( void ) +{ + return longFilteredTmpPressure; +} + +/*********************************************************************//** + * @brief * The getBaroPressurePSI function gets the averaged barometric pressure in psi. * @details \b Inputs: baroMovingAvg.baroAvgPS * @details \b Outputs: none @@ -989,18 +1016,20 @@ /*********************************************************************//** * @brief - * The filterInlinePressureReadings function adds a new arterial and venous - * pressure sample to the filters. + * The filterInlinePressureReadings function adds a new arterial, venous and + * trans-membrane pressure sample to the filters. * @details \b Inputs: none * @details \b Outputs: artPressureReadingsLong[], artPressureReadingsLongIdx, artPressureReadingsLongTotal, artPressureReadingsLongCount, * artPressureReadingsShort, artPressureReadingsShortIdx, artPressureReadingsShortTotal, artPressureReadingsShortCount, * venPressureReadingsShort, venPressureReadingsShortIdx, venPressureReadingsShortTotal, venPressureReadingsShortCount, - * longFilteredArterialPressure, shortFilteredArterialPressure, shortFilteredVenousPressure + * longFilteredArterialPressure, shortFilteredArterialPressure, shortFilteredVenousPressure, + * tmpPressureReadingsLong[], tmpPressureReadingsLongIdx, tmpPressureReadingsLongTotal, tmpPressureReadingsLongCount * @param artPres newest arterial pressure sample to add to filters * @param venPres newest venous pressure sample to add to filter + * @param tmpPres newest trans-membrane pressure sample to add to filter * @return none *************************************************************************/ -static void filterInlinePressureReadings( F32 artPres, F32 venPres ) +static void filterInlinePressureReadings( F32 artPres, F32 venPres, F32 tmpPres ) { // Long filter for arterial pressure. if ( artPressureReadingsLongCount >= SIZE_OF_LONG_ART_ROLLING_AVG ) @@ -1045,6 +1074,18 @@ venPressureReadingsShortIdx = INC_WRAP( venPressureReadingsShortIdx, 0, SIZE_OF_SHORT_VEN_ROLLING_AVG - 1 ); venPressureReadingsShortCount = INC_CAP( artPressureReadingsShortCount, SIZE_OF_SHORT_VEN_ROLLING_AVG ); shortFilteredVenousPressure.data = venPressureReadingsShortTotal / (F32)venPressureReadingsShortCount; + + // Long filter for trans-membrane pressure + if ( tmpPressureReadingsLongCount >= SIZE_OF_LONG_TMP_ROLLING_AVG ) + { + tmpPressureReadingsLongTotal -= tmpPressureReadingsLong[ tmpPressureReadingsLongIdx ]; + } + tmpPressureReadingsLong[ tmpPressureReadingsLongIdx ] = tmpPres; + tmpPressureReadingsLongTotal += tmpPres; + tmpPressureReadingsLongIdx = INC_WRAP( tmpPressureReadingsLongIdx, 0, SIZE_OF_LONG_TMP_ROLLING_AVG - 1 ); + tmpPressureReadingsLongCount = INC_CAP( tmpPressureReadingsLongCount, SIZE_OF_LONG_TMP_ROLLING_AVG ); + longFilteredTmpPressure = tmpPressureReadingsLongTotal / (F32)tmpPressureReadingsLongCount; + tmpPressure.data = tmpPres; } /*********************************************************************//** @@ -1096,6 +1137,7 @@ data.h2LongFilterPres = longFilteredArterialPressure; data.h14LongFilterPres = longFilteredVenousPressure; data.tmpPressure = getTMPPressure(); + data.tmpLongFilterPres = longFilteredTmpPressure; data.tmpMinLimit = (F32)currentTmpMinLimit; data.tmpMaxLimit = (F32)currentTmpMaxLimit; data.h23Pressure = getBaroPressurePSI(); Index: firmware/App/Monitors/Pressures.h =================================================================== diff -u -r4fd2b355f467baa04535272f58589e2a60443201 -r9f3f6f601dba9f278440bba6beba5ea19cadb3a9 --- firmware/App/Monitors/Pressures.h (.../Pressures.h) (revision 4fd2b355f467baa04535272f58589e2a60443201) +++ firmware/App/Monitors/Pressures.h (.../Pressures.h) (revision 9f3f6f601dba9f278440bba6beba5ea19cadb3a9) @@ -53,6 +53,7 @@ NUM_OF_PRESSURE_LIMITS_STATES ///< Number of pressure limits states } PRESSURE_LIMITS_STATES_T; +#pragma pack(push, 1) /// Payload record structure for the pressure data message. typedef struct { @@ -66,10 +67,12 @@ F32 h2LongFilterPres; ///< Latest long filtered arterial pressure (mmHg) F32 h14LongFilterPres; ///< Latest long filtered venous pressure (mmHg) F32 tmpPressure; ///< Latest trans-membrane pressure (mmHg) + F32 tmpLongFilterPres; ///< Latest long filtered tmp pressure (mmHg) F32 tmpMinLimit; ///< Current TMP minimum pressure limit (mmHg) F32 tmpMaxLimit; ///< Current TMP maximum pressure limit (mmHg) F32 h23Pressure; ///< Current barometric pressure (psi) } PRESSURE_DATA_T; +#pragma pack(pop) // ********** public function prototypes ********** @@ -92,6 +95,7 @@ F32 getFilteredVenousPressure( void ); F32 getLongFilteredVenousPressure( void ); F32 getTMPPressure( void ); +F32 getLongFilteredTMPPressure( void ); F32 getBaroPressurePSI( void ); BOOL pressureLimitHandleWidenRequest( MESSAGE_T *message );