Index: firmware/App/Monitors/Temperature.c =================================================================== diff -u -r60db0506b1a90ed00b0e83159f6e7510ab6e4b7b -r1bea59c13158a871b80e76d75a2a1a579ae67434 --- firmware/App/Monitors/Temperature.c (.../Temperature.c) (revision 60db0506b1a90ed00b0e83159f6e7510ab6e4b7b) +++ firmware/App/Monitors/Temperature.c (.../Temperature.c) (revision 1bea59c13158a871b80e76d75a2a1a579ae67434) @@ -45,10 +45,7 @@ #define TEMP_SENSORS_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Temperature sensors publish data time interval. #define TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Temperature sensors FPGA error timeout in milliseconds. -#define D4_TEMP_MOVING_AVG_NUM_OF_SAMPLES 50 ///< D4 temperature sensor moving average number of samples. -#define D50_TEMP_MOVING_AVG_NUM_OF_SAMPLES 50 ///< D50 temperature sensor moving average number of samples. -#define D99_TEMP_MOVING_AVG_NUM_OF_SAMPLES 50 ///< D99 temperature sensor moving average number of samples -#define D78_TEMP_MOVING_AVG_NUM_OF_SAMPLES 50 ///< D99 temperature sensor moving average number of samples +#define TEMP_MOVING_AVG_NUM_OF_SAMPLES 50 ///< temperature sensor moving average number of samples. #define DATA_PUBLISH_COUNTER_START_COUNT 30 ///< Data publish counter start count. #define DIAL_TEMP_MOVING_AVG_NUM_OF_SAMPLES 30 ///< Dialysate temperature sensors moving average number of samples. #define D28_D30_DATA_COLLECTION_TIME_MS ( 1 * MS_PER_SECOND ) ///< Dialysate temperature sensors data collection time in milliseconds. @@ -73,6 +70,15 @@ NUM_OF_TEMPSENSORS_EXEC_STATES, ///< Total number of exec states } TEMPSENSORS_EXEC_STATES_T; +/// Filter temperature readings record. +typedef struct +{ + F32 temperatureReadings[ TEMP_MOVING_AVG_NUM_OF_SAMPLES ]; ///< Holds temperature sample rolling average. + U32 temperatureReadingsIdx; ///< Index for next sample in rolling average array. + F32 temperatureReadingsTotal; ///< Rolling total - used to calc average. + U32 temperatureReadingsCount; ///< Number of samples in rolling average buffer +} FILTER_TEMPERATURE_READINGS_T; + /// Dialysate temperature moving average structure typedef struct { @@ -91,35 +97,11 @@ static BOOL tempDriftEventCheck; ///< Temperature sensor drift event boolean. static DIAL_TEMP_MOVING_AVG_DATA_T dialTempMovingAvgData[ NUM_OF_DIAL_TEMPS ]; ///< Dialysate temperature moving average data. -static F32 d4TempAvgC; ///< D4 temperature average in C. -static F32 d4TempRunningSumC; ///< D4 temperature running sum in C. -static F32 d4TempSamplesC[ D4_TEMP_MOVING_AVG_NUM_OF_SAMPLES ]; ///< D4 temperature samples array in C. -static U32 d4TempSamplesNextIndex; ///< D4 temperature sample next index number. -static U32 d4TempCount; ///< D4 Number of samples in average buffer. +static FILTER_TEMPERATURE_READINGS_T filteredTemperatureReadings[NUM_OF_TEMPERATURE_SENSORS]; ///< Filtered temperature reading for temperature sensors. +static OVERRIDE_F32_T filteredcurrentTemperatureReadings[ NUM_OF_TEMPERATURE_SENSORS ]; ///< filtered current temperature sensor temperature readings (overrideable). static U32 tempDataCollectionTimeInterval; ///< Temperature data collection time interval in milliseconds. -static U32 d4TempSampleIntervalCounter; ///< D4 temperature sensor sample collection timer counter. -static U32 d50TempSampleIntervalCounter; ///< D50 temperature sensor sample collection timer counter. +static U32 TempSampleIntervalCounter; ///< temperature sensor sample collection timer counter. -static F32 d50TempAvgC; ///< D50 temperature average in C. -static F32 d50TempRunningSumC; ///< D50 temperature running sum in C. -static F32 d50TempSamplesC[ D50_TEMP_MOVING_AVG_NUM_OF_SAMPLES ]; ///< D50 temperature samples array in C. -static U32 d50TempSamplesNextIndex; ///< D50 temperature sample next index number. -static U32 d50TempCount; ///< D50 Number of samples in average buffer. - -static F32 d99TempAvgC; ///< D99 temperature average in C. -static F32 d99TempRunningSumC; ///< D99 temperature running sum in C. -static F32 d99TempSamplesC[ D99_TEMP_MOVING_AVG_NUM_OF_SAMPLES ]; ///< D99 temperature samples array in C. -static U32 d99TempSamplesNextIndex; ///< D99 temperature sample next index number. -static U32 d99TempCount; ///< D99 Number of samples in average buffer. -static U32 d99TempSampleIntervalCounter; ///< D99 temperature sensor sample collection timer counter. - -static F32 d78TempAvgC; ///< D78 temperature average in C. -static F32 d78TempRunningSumC; ///< D78 temperature running sum in C. -static F32 d78TempSamplesC[ D99_TEMP_MOVING_AVG_NUM_OF_SAMPLES ]; ///< D78 temperature samples array in C. -static U32 d78TempSamplesNextIndex; ///< D78 temperature sample next index number. -static U32 d78TempCount; ///< D78 Number of samples in average buffer. -static U32 d78TempSampleIntervalCounter; ///< D78 temperature sensor sample collection timer counter. - static U32 ddTempDataPublicationTimerCounter; ///< DD Temperature sensors data publish timer counter. static U32 fpTempDataPublicationTimerCounter; ///< FP Temperature sensors data publish timer counter. static OVERRIDE_U32_T ddTempSensorsPublishInterval; ///< DD Temperature sensors publish time interval override. @@ -143,33 +125,30 @@ *************************************************************************/ void initTemperature( void ) { + TEMPERATURE_SENSORS_T sensor; + startTime = 0; tempSensorsExecState = TEMPSENSORS_EXEC_STATE_START; ddTempDataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; fpTempDataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; - d4TempRunningSumC = 0.0F; - d4TempAvgC = 0.0F; - d4TempSamplesNextIndex = 0; - d4TempCount = 0; - d50TempRunningSumC = 0.0F; - d50TempAvgC = 0.0F; - d50TempSamplesNextIndex = 0; - d50TempCount = 0; - d99TempRunningSumC = 0.0F; - d99TempAvgC = 0.0F; - d99TempSamplesNextIndex = 0; - d99TempCount = 0; - d78TempRunningSumC = 0.0F; - d78TempAvgC = 0.0F; - d78TempSamplesNextIndex = 0; - d78TempCount = 0; - d4TempSampleIntervalCounter = 0; - d50TempSampleIntervalCounter = 0; - d99TempSampleIntervalCounter = 0; - d78TempSampleIntervalCounter = 0; + + TempSampleIntervalCounter = 0; tempDataCollectionTimeInterval = 0; tempDriftEventCheck = FALSE; + // Initialize override structures for each temperature sensor + for ( sensor = TEMPSENSORS_FIRST; sensor < NUM_OF_TEMPERATURE_SENSORS; sensor++ ) + { + filteredcurrentTemperatureReadings[ sensor ].data = 0.0F; + filteredcurrentTemperatureReadings[ sensor ].ovData = 0.0F; + filteredcurrentTemperatureReadings[ sensor ].ovInitData = 0.0F; + filteredcurrentTemperatureReadings[ sensor ].override = OVERRIDE_RESET; + + filteredTemperatureReadings[ sensor ].temperatureReadingsIdx = 0; + filteredTemperatureReadings[ sensor ].temperatureReadingsTotal = 0.0F; + filteredTemperatureReadings[ sensor ].temperatureReadingsCount = 0; + } + dialTempMovingAvgData[ DIAL_TEMP_D28 ].dialTempColHasTimerBeenSet = FALSE; dialTempMovingAvgData[ DIAL_TEMP_D30 ].dialTempColHasTimerBeenSet = FALSE; @@ -323,83 +302,28 @@ *************************************************************************/ static void filterTemperatureReadings( void ) { - F32 d4Temp = 0.0F; - F32 d50Temp = 0.0F; - F32 d99Temp = 0.0F; - F32 d78Temp = 0.0F; + TEMPERATURE_SENSORS_T sensor; + F32 rawTemp = 0.0F; - // Moving average sample collection interval varies based on the dialysate flow rate - if ( ++d4TempSampleIntervalCounter >= tempDataCollectionTimeInterval ) + if ( ++TempSampleIntervalCounter >= tempDataCollectionTimeInterval ) { - // Filter D4 Temperature for AC heater - if ( d4TempCount >= D4_TEMP_MOVING_AVG_NUM_OF_SAMPLES ) + for ( sensor = TEMPSENSORS_FIRST; sensor < NUM_OF_TEMPERATURE_SENSORS; sensor++ ) { - d4TempRunningSumC -= d4TempSamplesC[ d4TempSamplesNextIndex ]; - } + rawTemp = getTemperatureValue ( sensor ); - d4Temp = getTemperatureValue( D4_TEMP ); - d4TempSamplesC[ d4TempSamplesNextIndex ] = d4Temp; - d4TempRunningSumC += d4Temp; - d4TempSamplesNextIndex = INC_WRAP( d4TempSamplesNextIndex, 0, D4_TEMP_MOVING_AVG_NUM_OF_SAMPLES - 1 ); - d4TempCount = INC_CAP( d4TempCount, D4_TEMP_MOVING_AVG_NUM_OF_SAMPLES ); - d4TempAvgC = d4TempRunningSumC / (F32)d4TempCount; - d4TempSampleIntervalCounter = 0; - } - - // Moving average sample collection interval varies based on the dialysate flow rate - if ( ++d50TempSampleIntervalCounter >= tempDataCollectionTimeInterval ) - { - if ( d50TempCount >= D50_TEMP_MOVING_AVG_NUM_OF_SAMPLES ) - { - d50TempRunningSumC -= d50TempSamplesC[ d50TempSamplesNextIndex ]; + if ( filteredTemperatureReadings[ sensor ].temperatureReadingsCount >= TEMP_MOVING_AVG_NUM_OF_SAMPLES ) + { + filteredTemperatureReadings[ sensor ].temperatureReadingsTotal -= filteredTemperatureReadings[ sensor ].temperatureReadings[ filteredTemperatureReadings[ sensor ].temperatureReadingsIdx ]; + } + filteredTemperatureReadings[ sensor ].temperatureReadings[ filteredTemperatureReadings[ sensor ].temperatureReadingsIdx ] = rawTemp; + filteredTemperatureReadings[ sensor ].temperatureReadingsTotal += rawTemp; + filteredTemperatureReadings[ sensor ].temperatureReadingsIdx = INC_WRAP( filteredTemperatureReadings[ sensor ].temperatureReadingsIdx, 0, TEMP_MOVING_AVG_NUM_OF_SAMPLES - 1 ); + filteredTemperatureReadings[ sensor ].temperatureReadingsCount = INC_CAP( filteredTemperatureReadings[ sensor ].temperatureReadingsCount, TEMP_MOVING_AVG_NUM_OF_SAMPLES ); + filteredcurrentTemperatureReadings[ sensor ].data = filteredTemperatureReadings[ sensor ].temperatureReadingsTotal / (F32)filteredTemperatureReadings[ sensor ].temperatureReadingsCount; } - - d50Temp = getTemperatureValue( D50_TEMP ); - d50TempSamplesC[ d50TempSamplesNextIndex ] = d50Temp; - d50TempRunningSumC += d50Temp; - d50TempSamplesNextIndex = INC_WRAP( d50TempSamplesNextIndex, 0, D50_TEMP_MOVING_AVG_NUM_OF_SAMPLES - 1 ); - d50TempCount = INC_CAP( d50TempCount, D50_TEMP_MOVING_AVG_NUM_OF_SAMPLES ); - d50TempAvgC = d50TempRunningSumC / (F32)d50TempCount; - d50TempSampleIntervalCounter = 0; + TempSampleIntervalCounter = 0; } - - // Moving average sample collection interval varies based on the dialysate flow rate - if ( ++d99TempSampleIntervalCounter >= tempDataCollectionTimeInterval ) - { - - // Filter D99 Temperature for fresh dialysate temperature - if ( d99TempCount >= D99_TEMP_MOVING_AVG_NUM_OF_SAMPLES ) - { - d99TempRunningSumC -= d99TempSamplesC[ d99TempSamplesNextIndex ]; - } - - d99Temp = getTemperatureValue( D99_TEMP ); - d99TempSamplesC[ d99TempSamplesNextIndex ] = d99Temp; - d99TempRunningSumC += d99Temp; - d99TempSamplesNextIndex = INC_WRAP( d99TempSamplesNextIndex, 0, D99_TEMP_MOVING_AVG_NUM_OF_SAMPLES - 1 ); - d99TempCount = INC_CAP( d99TempCount, D99_TEMP_MOVING_AVG_NUM_OF_SAMPLES ); - d99TempAvgC = d99TempRunningSumC / (F32)d99TempCount; - } - - // Moving average sample collection interval varies based on the dialysate flow rate - if ( ++d78TempSampleIntervalCounter >= tempDataCollectionTimeInterval ) - { - - // Filter D78 Temperature for fresh dialysate temperature - if ( d78TempCount >= D78_TEMP_MOVING_AVG_NUM_OF_SAMPLES ) - { - d78TempRunningSumC -= d78TempSamplesC[ d78TempSamplesNextIndex ]; - } - - d78Temp = getTemperatureValue( D78_TEMP ); - d78TempSamplesC[ d78TempSamplesNextIndex ] = d78Temp; - d78TempRunningSumC += d78Temp; - d78TempSamplesNextIndex = INC_WRAP( d78TempSamplesNextIndex, 0, D78_TEMP_MOVING_AVG_NUM_OF_SAMPLES - 1 ); - d78TempCount = INC_CAP( d78TempCount, D78_TEMP_MOVING_AVG_NUM_OF_SAMPLES ); - d78TempAvgC = d78TempRunningSumC / (F32)d78TempCount; - } - // dailysate temperature moving average filterDialTemperatureReadings(); } @@ -500,7 +424,9 @@ *************************************************************************/ F32 getD4AverageTemperature( void ) { - return d4TempAvgC; + F32 temperature = getF32OverrideValue( &filteredcurrentTemperatureReadings[ D4_TEMP ] ); + + return temperature; } /*********************************************************************//** @@ -513,7 +439,9 @@ *************************************************************************/ F32 getD50AverageTemperature( void ) { - return d50TempAvgC; + F32 temperature = getF32OverrideValue( &filteredcurrentTemperatureReadings[ D50_TEMP ] ); + + return temperature; } /*********************************************************************//** @@ -526,7 +454,9 @@ *************************************************************************/ F32 getD99AverageTemperature( void ) { - return d99TempAvgC; + F32 temperature = getF32OverrideValue( &filteredcurrentTemperatureReadings[ D99_TEMP ] ); + + return temperature; } /*********************************************************************//** @@ -539,7 +469,9 @@ *************************************************************************/ F32 getD78AverageTemperature( void ) { - return d78TempAvgC; + F32 temperature = getF32OverrideValue( &filteredcurrentTemperatureReadings[ D78_TEMP ] ); + + return temperature; } /*********************************************************************//** @@ -555,7 +487,7 @@ { F32 period = (F32)SEC_PER_MIN / ( getTDDialysateFlowrate() / BAL_CHAMBER_FILL_VOLUME_ML ) ; - U32 sampleInterval = (U32)( ( period / (F32)D4_TEMP_MOVING_AVG_NUM_OF_SAMPLES ) * MS_PER_SECOND ); + U32 sampleInterval = (U32)( ( period / (F32)TEMP_MOVING_AVG_NUM_OF_SAMPLES ) * MS_PER_SECOND ); tempDataCollectionTimeInterval = (U32) ( sampleInterval / TASK_PRIORITY_INTERVAL ); } @@ -660,6 +592,30 @@ /*********************************************************************//** * @brief + * The testDDTemperatureSensorFilteredReadingsOverride function overrides the + * filtered value of the specified DD temperature sensor with a given value. + * @details \b Inputs: none + * @details \b Outputs: filteredcurrentTemperatureReadings[] + * @param message Override message from Dialin which includes a sensor + * ID and override value of the temperature value for that sensor. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testDDTemperatureSensorFilteredReadingsOverride( MESSAGE_T *message ) +{ + BOOL result = FALSE; + TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; + OVERRIDE_TYPE_T ovType = getOverrideArrayPayloadFromMessage( message, &payload ); + + if ( payload.index <= NUM_OF_TEMPERATURE_SENSORS ) + { + result = f32ArrayOverride( message, &filteredcurrentTemperatureReadings[0], NUM_OF_TEMPERATURE_SENSORS - 1 ); + } + + return result; +} + +/*********************************************************************//** + * @brief * The testIOFPTemperatureSensorsDataPublishIntervalOverride function * overrides the IOFP temperature sensors data publish interval. * @details \b Inputs: none