Index: firmware/App/Monitors/Pressures.c =================================================================== diff -u -rfe9b77e60850fe37da225d4348f0a6a8defc28db -rf979c391268b595e44fb6747d43487e4d2294e68 --- firmware/App/Monitors/Pressures.c (.../Pressures.c) (revision fe9b77e60850fe37da225d4348f0a6a8defc28db) +++ firmware/App/Monitors/Pressures.c (.../Pressures.c) (revision f979c391268b595e44fb6747d43487e4d2294e68) @@ -101,6 +101,8 @@ #define DATA_PUBLISH_COUNTER_START_COUNT 5 ///< Data publish counter start count. +#define BARO_MOVING_AVG_NUM_OF_SAMPLES 10 ///< Barometric pressure sensor moving average number of samples. + /// Defined states for the pressure monitor state machine. typedef enum Pressure_States { @@ -118,6 +120,15 @@ NUM_OF_PRESSURE_SELF_TEST_STATES ///< Number of pressure/occlusion self-test states. } PRESSURE_SELF_TEST_STATE_T; +/// Barometric pressure sensor moving average structure +typedef struct +{ + F32 baroRunningSumPSI; ///< Baro pressure sensor running sum in psi. + OVERRIDE_F32_T baroAvgPSI; ///< Baro pressure sensor average in psi. + F32 baroSamplesPSI[ BARO_MOVING_AVG_NUM_OF_SAMPLES ]; ///< Baro pressure sensor samples array in psi. + U32 baroSamplesNextIndex; ///< Baro pressure sensor sample next index number. +} BARO_MOVING_AVG_DATA_T; + // ********** private data ********** static PRESSURE_STATE_T pressureState; ///< Current state of pressure monitor state machine. @@ -168,6 +179,7 @@ static U32 venPressureReadingsShortIdx; ///< Index for next sample in rolling average array. static F32 venPressureReadingsShortTotal; ///< Rolling total - used to calc average. static U32 venPressureReadingsShortCount; ///< Number of samples in flow rolling average buffer. +static BARO_MOVING_AVG_DATA_T baroMovingAvg; ///< Barometric sensor moving average. static PRESSURE_SELF_TEST_STATE_T pressurePostState; ///< Pressure self test post state. //static HD_PRESSURE_SENSORS_CAL_RECORD_T pressureSensorsCalRecord; ///< Pressure sensors calibration record. @@ -182,6 +194,7 @@ static void publishPressureData( void ); static void determineArtVenPressureLimits( void ); static void filterInlinePressureReadings( F32 artPres, F32 venPres ); +static void filterBaroPressureReadings( F32 baroPresPSI ); /*********************************************************************//** * @brief @@ -258,6 +271,14 @@ venPressureReadingsShortIdx = 0; venPressureReadingsShortTotal = 0.0F; venPressureReadingsShortCount = 0; + + baroMovingAvg.baroAvgPSI.data = 0.0F; + baroMovingAvg.baroAvgPSI.ovData = 0.0F; + baroMovingAvg.baroAvgPSI.ovInitData = 0.0F; + baroMovingAvg.baroAvgPSI.override = OVERRIDE_RESET; + baroMovingAvg.baroRunningSumPSI = 0.0F; + baroMovingAvg.baroSamplesNextIndex = 0; + memset( baroMovingAvg.baroSamplesPSI, 0.0F, BARO_MOVING_AVG_NUM_OF_SAMPLES ); } /*********************************************************************//** @@ -526,11 +547,14 @@ static PRESSURE_STATE_T handlePressureContReadState( void ) { PRESSURE_STATE_T result = PRESSURE_CONTINUOUS_READ_STATE; - F32 fpgaArtPres = getPressure( H2_PRES ) - arterialPressureOffset; - F32 fpgaVenPres = getPressure( H14_PRES ) - venousPressureOffset; + F32 fpgaArtPres = getPressure( H2_PRES ) - arterialPressureOffset; + F32 fpgaVenPres = getPressure( H14_PRES ) - venousPressureOffset; + F32 fpgaBaroPresPSI = getPressure( H23_PRES ); // Filter inline pressure readings filterInlinePressureReadings( fpgaArtPres, fpgaVenPres ); + // Filter the baro pressure + filterBaroPressureReadings( fpgaBaroPresPSI ); // Get latest dialysate pressure so we can calculate TMP tmpPressure.data = getLongFilteredVenousPressure() - getDialysatePressure(); @@ -914,6 +938,18 @@ /*********************************************************************//** * @brief + * The getBaroPressurePSI function gets the averaged barometric pressure in psi. + * @details \b Inputs: baroMovingAvg.baroAvgPS + * @details \b Outputs: none + * @return the current average barometric pressure in psi. + *************************************************************************/ +F32 getBaroPressurePSI( void ) +{ + return getF32OverrideValue( &baroMovingAvg.baroAvgPSI ); +} + +/*********************************************************************//** + * @brief * The filterInlinePressureReadings function adds a new arterial and venous * pressure sample to the filters. * @details \b Inputs: none @@ -974,6 +1010,26 @@ /*********************************************************************//** * @brief + * The filterBaroPressureReadings function calculates the barometric pressure + * in psi. + * @details \b Inputs: none + * @details \b Outputs: baroMovingAvg + * @param baroPresPSI newest barometric pressure from FPGA + * @return none + *************************************************************************/ +static void filterBaroPressureReadings( F32 baroPresPSI ) +{ + U32 currentIndex = baroMovingAvg.baroSamplesNextIndex; + F32 prevSampleToRemovePSI = baroMovingAvg.baroSamplesPSI[ currentIndex ]; + + baroMovingAvg.baroSamplesPSI[ currentIndex ] = baroPresPSI; + baroMovingAvg.baroRunningSumPSI = baroMovingAvg.baroRunningSumPSI + baroPresPSI - prevSampleToRemovePSI; + baroMovingAvg.baroSamplesNextIndex = INC_WRAP( currentIndex, 0, BARO_MOVING_AVG_NUM_OF_SAMPLES - 1 ); + baroMovingAvg.baroAvgPSI.data = baroMovingAvg.baroRunningSumPSI / (F32)BARO_MOVING_AVG_NUM_OF_SAMPLES; +} + +/*********************************************************************//** + * @brief * The publishPressureData function publishes pressure data at the set * interval. * @details \b Message \b Sent: MSG_ID_TD_PRESSURE_DATA @@ -1003,6 +1059,7 @@ data.tmpPressure = getTMPPressure(); data.tmpMinLimit = -400.0F; // TODO - use windowed min/max values based on user set params when implemented data.tmpMaxLimit = 100.0F; + data.h23Pressure = getBaroPressurePSI(); broadcastData( MSG_ID_TD_PRESSURE_DATA, COMM_BUFFER_OUT_CAN_TD_BROADCAST, (U08*)&data, sizeof( PRESSURE_DATA_T ) ); pressureDataPublicationTimerCounter = 0; @@ -1117,4 +1174,20 @@ return result; } +/*********************************************************************//** + * @brief + * The testBaroPressureOverride function overrides baro sensor pressure. + * @details \b Inputs: none + * @details \b Outputs: baroMovingAvg.baroAvgPSI + * @param message Override message from Dialin which includes the value to + * override the baro pressure to. + * @return TRUE if override request is successful, FALSE if not + *************************************************************************/ +BOOL testBaroPressureOverride( MESSAGE_T * message ) +{ + BOOL result = f32Override( message, &baroMovingAvg.baroAvgPSI ); + + return result; +} + /**@}*/