Index: firmware/App/Monitors/Conductivity.c =================================================================== diff -u -rdc3647b737971d298748796d2455b3e021325d8a -rbc7dad193df69c64cf213db463e5115b1ba8a5f0 --- firmware/App/Monitors/Conductivity.c (.../Conductivity.c) (revision dc3647b737971d298748796d2455b3e021325d8a) +++ firmware/App/Monitors/Conductivity.c (.../Conductivity.c) (revision bc7dad193df69c64cf213db463e5115b1ba8a5f0) @@ -1,17 +1,17 @@ /************************************************************************** * -* Copyright (c) 2024-2024 Diality Inc. - All Rights Reserved. +* Copyright (c) 2024-2026 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file Conductivity.c * -* @author (last) Vinayakam Mani -* @date (last) 10-Sep-2024 +* @author (last) Michael Garthwaite +* @date (last) 06-Mar-2026 * * @author (original) Vinayakam Mani -* @date (original) 10-Sep-2024 +* @date (original) 13-Sep-2024 * ***************************************************************************/ #include // Used for calculating the polynomial calibration equation. @@ -20,6 +20,7 @@ #include "Conductivity.h" #include "MessageSupport.h" #include "Messaging.h" +#include "ModeGenPermeate.h" #include "OperationModes.h" #include "TaskPriority.h" #include "Utilities.h" @@ -31,18 +32,64 @@ // ********** private definitions ********** -#define COND_SENSOR_REPORT_PERIOD ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Broadcast conductivity values message every second. -#define DATA_PUBLISH_COUNTER_START_COUNT 40 ///< Data publish counter start count. +#define COND_SENSOR_REPORT_PERIOD ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Broadcast conductivity values message every second. +#define DATA_PUBLISH_COUNTER_START_COUNT 40 ///< Data publish counter start count. +#define CONDUCTIVITY_SAMPLE_FILTER_MS ( 500 ) ///< Filter conductivity data for given time +#define CONDUCTIVITY_TEMP_SAMPLE_FILTER_MS ( 500 ) ///< Filter conductivity temperature data for given time +#define SIZE_OF_FLOW_ROLLING_AVG ( CONDUCTIVITY_SAMPLE_FILTER_MS / TASK_PRIORITY_INTERVAL ) ///< Filtered conductivity moving average sample count. +#define SIZE_OF_FLOW_TEMP_ROLLING_AVG ( CONDUCTIVITY_TEMP_SAMPLE_FILTER_MS / TASK_PRIORITY_INTERVAL ) ///< Filtered conductivity temprature moving average sample count. +#define RO_RR_MOVING_AVG_NUM_OF_SAMPLES 30 ///< RO rejection ratio moving average number of samples. +#define FRACTION_TO_PERCENT_CONVERSION_FACTOR 100.0F ///< RO rejection ratio factor to percentage conversion factor value +#define RO_RR_SAMPLE_COLLECTION_INTERVAL 10 ///< Collect RO rejection ratio sample for every 10th time in priority task +/// Filter conductivity readings record. +typedef struct +{ + F32 conductivityReadings[ SIZE_OF_FLOW_ROLLING_AVG ]; ///< Holds conductivity sample rolling average. + U32 conductivityReadingsIdx; ///< Index for next sample in rolling average array. + F32 conductivityReadingsTotal; ///< Rolling total - used to calc average. + U32 conductivityReadingsCount; ///< Number of samples in rolling average buffer +} FILTER_CONDUCTIVITY_READINGS_T; + +/// Filter conductivity sensor temperature readings record. +typedef struct +{ + F32 conductivityTempReadings[ SIZE_OF_FLOW_ROLLING_AVG ]; ///< Holds conductivity sample rolling average. + U32 conductivityTempReadingsIdx; ///< Index for next sample in rolling average array. + F32 conductivityTempReadingsTotal; ///< Rolling total - used to calc average. + U32 conductivityTempReadingsCount; ///< Number of samples in rolling average buffer +} FILTER_CONDUCTIVITY_TEMPERATURE_READINGS_T; + // ********** private data ********** -static U32 conductivityPublishTimerCounter; -static OVERRIDE_U32_T conductivityDataPublishInterval = { COND_SENSOR_REPORT_PERIOD, - COND_SENSOR_REPORT_PERIOD, 0, 0 }; ///< Conductivity sensors publish time interval override. +static FILTER_CONDUCTIVITY_READINGS_T filteredConductivityReadings[NUM_OF_CONDUCTIVITY_SENSORS]; ///< Filtered conductivity reading for conductivity sensors. +static OVERRIDE_F32_T filteredcurrentConductivityReadings[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< filtered current conductivity sensor conductivity readings (overrideable). +static FILTER_CONDUCTIVITY_TEMPERATURE_READINGS_T filteredConductivityTemperatureReadings[NUM_OF_CONDUCTIVITY_SENSORS]; ///< Filtered temperature reading for conductivity sensors. +static OVERRIDE_F32_T filteredcurrentTemperatureReadings[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< filtered current conductivity sensor temperature readings (overrideable). +static U32 ddConductivityPublishTimerCounter; ///< DD Conductivity data publication counter. +static OVERRIDE_U32_T ddConductivityDataPublishInterval; ///< DD Conductivity sensors publish time interval override. +static U32 fpConductivityPublishTimerCounter; ///< FP Conductivity data publication counter. +static OVERRIDE_U32_T fpConductivityDataPublishInterval; ///< FP Conductivity sensors publish time interval override. +static F32 roRejectionRatio; ///< All time RO rejection ratio. +static F32 roRejectionRatioTankFill; ///< RO rejection ratio during permeate tank fill state. +static U32 roRRPublishTimerCounter; ///< RO rejection ratio publication counter. +static OVERRIDE_U32_T roRRDataPublishInterval; ///< RO rejection ratio publish time interval override. +static OVERRIDE_F32_T roRRAvg; ///< Average RO rejection ratio. +static F32 roRRRunningSum; ///< RO rejection ratio running sum. +static F32 roRRSamples[ RO_RR_MOVING_AVG_NUM_OF_SAMPLES ]; ///< RO rejection ratio samples array. +static U32 roRRSamplesNextIndex; ///< RO rejection ratio sample next index number. +static U32 roRRCount; ///< RO rejection ratio Number of samples in average buffer. +static F32 roRRTankFillAvg; ///< Average RO rejection ratio during permeate tank fill state. +static U32 roRRSampleIntervalCounter; ///< RO rejection ratio sample collection timer counter. // ********** private function prototypes ********** static void publishConductivitySensorsData( void ); +static void filterConductivitySensors( void ); +static void filterConductivitySensorReadings( void ); +static void filterConductivitySensorTemperatureReadings( void ); +static void calcRORejectionRatio( void ); +static void filterRORejectionRatioReadings( void ); /*********************************************************************//** * @brief @@ -53,9 +100,64 @@ *************************************************************************/ void initConductivity( void ) { - conductivityPublishTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; + CONDUCTIVITY_SENSORS_T sensor; + initConductivityTeensy(); initConductivitySensors(); + + ddConductivityPublishTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; + fpConductivityPublishTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; + roRRPublishTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; + roRejectionRatio = 0.0F; + roRejectionRatioTankFill = 0.0F; + roRRRunningSum = 0.0F; + roRRSamplesNextIndex = 0; + roRRCount = 0; + roRRTankFillAvg = 0.0F; + roRRAvg.data = 0.0F; + roRRAvg.ovData = 0.0F; + roRRAvg.ovInitData = 0.0F; + roRRAvg.override = OVERRIDE_RESET; + roRRSampleIntervalCounter = 0; + + memset( &roRRSamples, 0, sizeof( roRRSamples ) ); + + // Initialize override structures for each conductivity sensor + for ( sensor = FIRST_DD_COND_SENSOR; sensor < NUM_OF_CONDUCTIVITY_SENSORS; sensor++ ) + { + filteredcurrentConductivityReadings[ sensor ].data = 0.0F; + filteredcurrentConductivityReadings[ sensor ].ovData = 0.0F; + filteredcurrentConductivityReadings[ sensor ].ovInitData = 0.0F; + filteredcurrentConductivityReadings[ sensor ].override = OVERRIDE_RESET; + + filteredConductivityReadings[ sensor ].conductivityReadingsIdx = 0; + filteredConductivityReadings[ sensor ].conductivityReadingsTotal = 0.0F; + filteredConductivityReadings[ sensor ].conductivityReadingsCount = 0; + + filteredcurrentTemperatureReadings[ sensor ].data = 0.0F; + filteredcurrentTemperatureReadings[ sensor ].ovData = 0.0F; + filteredcurrentTemperatureReadings[ sensor ].ovInitData = 0.0F; + filteredcurrentTemperatureReadings[ sensor ].override = OVERRIDE_RESET; + + filteredConductivityTemperatureReadings[ sensor ].conductivityTempReadingsIdx = 0; + filteredConductivityTemperatureReadings[ sensor ].conductivityTempReadingsTotal = 0.0F; + filteredConductivityTemperatureReadings[ sensor ].conductivityTempReadingsCount = 0; + } + + ddConductivityDataPublishInterval.data = COND_SENSOR_REPORT_PERIOD; + ddConductivityDataPublishInterval.ovData = COND_SENSOR_REPORT_PERIOD; + ddConductivityDataPublishInterval.ovInitData = 0; + ddConductivityDataPublishInterval.override = OVERRIDE_RESET; + + fpConductivityDataPublishInterval.data = COND_SENSOR_REPORT_PERIOD; + fpConductivityDataPublishInterval.ovData = COND_SENSOR_REPORT_PERIOD; + fpConductivityDataPublishInterval.ovInitData = 0; + fpConductivityDataPublishInterval.override = OVERRIDE_RESET; + + roRRDataPublishInterval.data = COND_SENSOR_REPORT_PERIOD; + roRRDataPublishInterval.ovData = COND_SENSOR_REPORT_PERIOD; + roRRDataPublishInterval.ovInitData = 0; + roRRDataPublishInterval.override = OVERRIDE_RESET; } /*********************************************************************//** @@ -70,45 +172,335 @@ void execConductivity( void ) { //read conductivity sensors raw value - readConductivitySensors(); + execConductivityTeensy(); + execConductivitySensors(); - //control conductivity sensor - // TODO : need more clarity on why and when to execute following control. -#if 0 - handleConductivitySensorsReset(); - handleConductivitySensorsInitProcedure(); - execConductivitySensorWrite(); - execConductivitySensorRead(); -#endif + filterConductivitySensors(); + calcRORejectionRatio(); // TODO: should this be called here or inside filter function + filterRORejectionRatioReadings(); // publish conductivity sensors publishConductivitySensorsData(); } /*********************************************************************//** * @brief + * The filterConductivitySensors function gets averages the raw conductivity + * and temperature from the conductivity sensor. + * @details \b Inputs: conductivity readings from FPGA + * @details \b Outputs: filteredConductivityReadings[], filterConductivitySensorTemperatureReadings[] + * @return none + *************************************************************************/ +static void filterConductivitySensors( void ) +{ + //Filter conductivity sensor reading + filterConductivitySensorReadings(); + //Filter conductivity sensor temperature + filterConductivitySensorTemperatureReadings(); +} + +/*********************************************************************//** + * @brief + * The getFilteredConductivity function gets the filtered current conductivity (in uS/cm) + * for a given conductivity sensor. + * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT if given sensor is invalid. + * @details \b Inputs: filteredcurrentConductivityReadings[] + * @details \b Outputs: none + * @param sensor ID of conductivity sensor to get filtered conductivity reading for. + * @return The filtered current conductivity (in uS/cm) for the given conductivity sensor + *************************************************************************/ +F32 getFilteredConductivity( CONDUCTIVITY_SENSORS_T sensor ) +{ + F32 result = 0.0F; + + if ( sensor < NUM_OF_CONDUCTIVITY_SENSORS ) + { + result = filteredcurrentConductivityReadings[ sensor ].data; + if ( OVERRIDE_KEY == filteredcurrentConductivityReadings[ sensor ].override ) + { + result = filteredcurrentConductivityReadings[ sensor ].ovData; + } + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_FILTERED_CONDUCTIVITY_SENSOR_ID, (U32)sensor ) + } + + return result; +} + +/*********************************************************************//** + * @brief + * The filterConductivitySensorReadings function filters the conductivity rates for + * defined interval to get average conductivity rates. + * @details \b Inputs: filteredConductivityReadings[] + * @details \b Outputs: filteredConductivityReadings[], filteredcurrentConductivityReadings[] + * @return none + *************************************************************************/ +static void filterConductivitySensorReadings( void ) +{ + CONDUCTIVITY_SENSORS_T sensor; + F32 calculatedConductivity = 0.0F; + + for ( sensor = FIRST_DD_COND_SENSOR; sensor < NUM_OF_CONDUCTIVITY_SENSORS; sensor++ ) + { + + if ( getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_2_0_HW ) != TRUE ) + { + calculatedConductivity = getTeensyConductivityValue( sensor ); + } + else + { + calculatedConductivity = getConductivity( sensor ); + } + + // TODO - calibrate + + if ( filteredConductivityReadings[ sensor ].conductivityReadingsCount >= SIZE_OF_FLOW_ROLLING_AVG ) + { + filteredConductivityReadings[ sensor ].conductivityReadingsTotal -= filteredConductivityReadings[ sensor ].conductivityReadings[ filteredConductivityReadings[ sensor ].conductivityReadingsIdx ]; + } + filteredConductivityReadings[ sensor ].conductivityReadings[ filteredConductivityReadings[ sensor ].conductivityReadingsIdx ] = calculatedConductivity; + filteredConductivityReadings[ sensor ].conductivityReadingsTotal += calculatedConductivity; + filteredConductivityReadings[ sensor ].conductivityReadingsIdx = INC_WRAP( filteredConductivityReadings[ sensor ].conductivityReadingsIdx, 0, SIZE_OF_FLOW_ROLLING_AVG - 1 ); + filteredConductivityReadings[ sensor ].conductivityReadingsCount = INC_CAP( filteredConductivityReadings[ sensor ].conductivityReadingsCount, SIZE_OF_FLOW_ROLLING_AVG ); + filteredcurrentConductivityReadings[ sensor ].data = filteredConductivityReadings[ sensor ].conductivityReadingsTotal / (F32)filteredConductivityReadings[ sensor ].conductivityReadingsCount; + } +} + +/*********************************************************************//** + * @brief + * The getFilteredConductivitySensorTemperature function gets the filtered + * temperature (in C) for a given conductivity sensor. + * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT if given sensor is invalid. + * @details \b Inputs: filteredConductivityTemperatureReadings[] + * @details \b Outputs: none + * @param sensor ID of conductivity sensor to get filtered conductivity reading for. + * @return The filtered current temperature (in C) for the given conductivity sensor + *************************************************************************/ +F32 getFilteredConductivitySensorTemperature( CONDUCTIVITY_SENSORS_T sensor ) +{ + F32 result = 0.0F; + + if ( sensor < NUM_OF_CONDUCTIVITY_SENSORS ) + { + result = filteredcurrentTemperatureReadings[ sensor ].data; + if ( OVERRIDE_KEY == filteredcurrentTemperatureReadings[ sensor ].override ) + { + result = filteredcurrentTemperatureReadings[ sensor ].ovData; + } + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_FILTERED_CONDUCTIVITY_SENSOR_ID, (U32)sensor ) + } + + return result; +} + +/*********************************************************************//** + * @brief + * The filterConductivitySensorTemperatureReadings function filters the temperature + * rates for defined interval to get average conductivity rates. + * @details \b Inputs: filteredConductivityTemperatureReadings[] + * @details \b Outputs: filteredConductivityTemperatureReadings[], filteredcurrentTemperatureReadings[] + * @return none + *************************************************************************/ +static void filterConductivitySensorTemperatureReadings( void ) +{ + CONDUCTIVITY_SENSORS_T sensor; + F32 calculatedTemperature = 0.0F; + + for ( sensor = FIRST_DD_COND_SENSOR; sensor < NUM_OF_CONDUCTIVITY_SENSORS; sensor++ ) + { + if ( getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_2_0_HW ) != TRUE ) + { + calculatedTemperature = getTeensyConductivityTemperatureValue( sensor ); + } + else + { + calculatedTemperature = getConductivityTemperature( sensor ); + } + + // TODO - calibrate + + if ( filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsCount >= SIZE_OF_FLOW_ROLLING_AVG ) + { + filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsTotal -= filteredConductivityTemperatureReadings[sensor].conductivityTempReadings[ filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsIdx ]; + } + filteredConductivityTemperatureReadings[sensor].conductivityTempReadings[ filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsIdx ] = calculatedTemperature; + filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsTotal += calculatedTemperature; + filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsIdx = INC_WRAP( filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsIdx, 0, SIZE_OF_FLOW_ROLLING_AVG - 1 ); + filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsCount = INC_CAP( filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsCount, SIZE_OF_FLOW_ROLLING_AVG ); + filteredcurrentTemperatureReadings[sensor].data = filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsTotal / (F32)filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsCount; + } +} + +/*********************************************************************//** + * @brief + * The calcRORejectionRatio function calculates the RO rejection ratio using + * the P9 sensor conductivity value and P18 sensor conductivity value. + * @details Inputs: P9 sensor conductivity, P18 sensor conductivity + * @details Outputs: RO rejection ratio, Tank fill RO rejection ratio + * @return none + *************************************************************************/ +static void calcRORejectionRatio( void ) +{ + F32 feedConductivity = getFilteredConductivity( P9_COND ); + F32 permeateConductivity = getFilteredConductivity( P18_COND ); + + roRejectionRatio = RO_REJECTION_RATIO_OUT_OF_RANGE_VALUE; + + if ( fabs(feedConductivity) >= NEARLY_ZERO ) + { + roRejectionRatio = FRACTION_TO_PERCENT_CONVERSION_FACTOR * ( ( feedConductivity - permeateConductivity ) / feedConductivity ); + } + if ( getCurrentGenPermeateState() == FP_GENP_TANK_FILL_STATE ) + { + roRejectionRatioTankFill = roRejectionRatio; + } +} + +/*********************************************************************//** + * @brief + * The filterRORejectionRatioReadings function adds a new ro rejection ratio + * sample to the filters. + * @details \b Inputs: RO rejection ratio all time and during tank fill state + * @details \b Outputs: roRRRunningSumC, roRRSamples[], roRRSamplesNextIndex, + * roRRCount, roRRAvg, roRRTankFillAvg + * @return none + *************************************************************************/ +static void filterRORejectionRatioReadings( void ) +{ + F32 roRR = 0.0F; + + // Moving average samples are collected for every 100 msec + if ( ++roRRSampleIntervalCounter >= RO_RR_SAMPLE_COLLECTION_INTERVAL ) + { + // Filter RO rejection ratio + roRRRunningSum -= roRRSamples[ roRRSamplesNextIndex ]; + roRR = getRORejectonRatio(); + roRRSamples[ roRRSamplesNextIndex ] = roRR; + roRRRunningSum += roRR; + roRRSamplesNextIndex = INC_WRAP( roRRSamplesNextIndex, 0, RO_RR_MOVING_AVG_NUM_OF_SAMPLES - 1 ); + roRRCount = INC_CAP( roRRCount, RO_RR_MOVING_AVG_NUM_OF_SAMPLES ); + roRRAvg.data = roRRRunningSum / (F32)roRRCount; + roRRSampleIntervalCounter = 0; + + // Update the Filter RO rejection ratio during tank fill if the tank is filling + if ( getCurrentGenPermeateState() == FP_GENP_TANK_FILL_STATE ) + { + roRRTankFillAvg = roRRAvg.data; + } + } +} + +/*********************************************************************//** + * @brief + * The getRORejectonRatio function returns the RO rejection ratio + * @details \b Inputs: roRejectionRatio + * @details \b Outputs: none + * @return the RO rejection ratio in percentage + *************************************************************************/ +F32 getRORejectonRatio( void ) +{ + return roRejectionRatio; +} + +/*********************************************************************//** + * @brief + * The getTankFillRORejectionRatio function returns the RO rejection ratio + * during tank fill state + * @details \b Inputs: roRejectionRatioTankFill + * @details \b Outputs: none + * @return the tank fill RO rejection ratio in percentage + *************************************************************************/ +F32 getTankFillRORejectionRatio( void ) +{ + return roRejectionRatioTankFill; +} + +/*********************************************************************//** + * @brief + * The getRORRAverage function returns the average RO rejection ratio + * @details \b Inputs: roRRAvg + * @details \b Outputs: none + * @return the average RO rejection ratio in percentage + *************************************************************************/ +F32 getRORRAverage( void ) +{ + F32 avgRORR = getF32OverrideValue( &roRRAvg ); + + return avgRORR; +} + +/*********************************************************************//** + * @brief + * The getTankFillRORRAverage function returns the average RO rejection ratio + * during tank fill state + * @details \b Inputs: roRRTankFillAvg + * @details \b Outputs: none + * @return the average tank fill RO rejection ratio in percentage + *************************************************************************/ +F32 getTankFillRORRAverage( void ) +{ + return roRRTankFillAvg; +} + +/*********************************************************************//** + * @brief * The publishConductivitySensorsData function publishes DD conductivity data * at a set interval. - * @details \b Inputs: conductivityPublishTimerCounter - * @details \b Outputs: conductivityPublishTimerCounter - * @details \b Message \b Sent: MSG_ID_DD_CONDUCTIVITY_DATA to publish conductivity data. + * @details \b Inputs: ddconductivityPublishTimerCounter, fpConductivityPublishTimerCounter, + * roRRPublishTimerCounter + * @details \b Outputs: ddconductivityPublishTimerCounter, fpConductivityPublishTimerCounter, + * roRRPublishTimerCounter, DD, FP, RO data broadcast message sent + * @details \b Message \b Sent: MSG_ID_DD_CONDUCTIVITY_DATA to publish DD conductivity data. + * @details \b Message \b Sent: MSG_ID_FP_CONDUCTIVITY_DATA to publish FP conductivity data. * @return none *************************************************************************/ static void publishConductivitySensorsData( void ) { - // publish pressure/occlusion data on interval - if ( ++conductivityPublishTimerCounter >= getU32OverrideValue( &conductivityDataPublishInterval ) ) + // publish DD conductivity data on interval + if ( ++ddConductivityPublishTimerCounter >= getU32OverrideValue( &ddConductivityDataPublishInterval ) ) { - CONDUCTIVITY_DATA_T data; + DD_CONDUCTIVITY_DATA_T data; - data.d17Cond = getConductivityValue( D17_COND ); - data.d27Cond = getConductivityValue( D27_COND ); - data.d29Cond = getConductivityValue( D29_COND ); - data.d43Cond = getConductivityValue( D43_COND ); - data.d74Cond = getConductivityValue( D74_COND ); - conductivityPublishTimerCounter = 0; + data.d17Cond = getFilteredConductivity( D17_COND ); + data.d27Cond = getFilteredConductivity( D27_COND ); + data.d29Cond = getFilteredConductivity( D29_COND ); + data.d43Cond = getFilteredConductivity( D43_COND ); + data.d74Cond = getFilteredConductivity( D74_COND ); + ddConductivityPublishTimerCounter = 0; - broadcastData( MSG_ID_DD_CONDUCTIVITY_DATA, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&data, sizeof( CONDUCTIVITY_DATA_T ) ); + broadcastData( MSG_ID_DD_CONDUCTIVITY_DATA, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&data, sizeof( DD_CONDUCTIVITY_DATA_T ) ); } + + // publish FP Conductivity data on interval + if ( ++fpConductivityPublishTimerCounter >= getU32OverrideValue( &fpConductivityDataPublishInterval ) ) + { + FP_CONDUCTIVITY_DATA_T data; + + data.p9Conductivity = getFilteredConductivity( P9_COND ); + data.p18Conductivity = getFilteredConductivity( P18_COND ); + fpConductivityPublishTimerCounter = 0; + + broadcastData( MSG_ID_FP_CONDUCTIVITY_DATA, COMM_BUFFER_OUT_CAN_FP_BROADCAST, (U08*)&data, sizeof( FP_CONDUCTIVITY_DATA_T ) ); + } + + // publish ro rejection ratio data on interval + if ( ++roRRPublishTimerCounter >= getU32OverrideValue( &roRRDataPublishInterval ) ) + { + RO_REJECTION_RATIO_DATA_T data; + + data.rawRORejectionRatio = getRORejectonRatio(); + data.rawRORejectionRatioTankFill = getTankFillRORejectionRatio(); + data.avgRORejectionRatio = getRORRAverage(); + data.avgRORejectionRatioTankFill = getTankFillRORRAverage(); + data.genPermeateState = (U32)getCurrentGenPermeateState(); + roRRPublishTimerCounter = 0; + + broadcastData( MSG_ID_FP_RO_REJECTION_RATIO_DATA, COMM_BUFFER_OUT_CAN_FP_BROADCAST, (U08*)&data, sizeof( RO_REJECTION_RATIO_DATA_T ) ); + } } @@ -127,11 +519,233 @@ * that override valves states publish interval with (in ms) * @return TRUE if override successful, FALSE if not *************************************************************************/ -BOOL testConductivitySensorDataPublishIntervalOverride( MESSAGE_T *message ) +BOOL testDDConductivitySensorDataPublishIntervalOverride( MESSAGE_T *message ) { - BOOL result = u32BroadcastIntervalOverride( message, &conductivityDataPublishInterval, TASK_PRIORITY_INTERVAL ); + BOOL result = u32BroadcastIntervalOverride( message, &ddConductivityDataPublishInterval, TASK_PRIORITY_INTERVAL ); return result; } +/*********************************************************************//** + * @brief + * The testDDConductivitySensorFilteredReadingsOverride function overrides the + * filtered value of the specified DD conductivity sensor with a given value. + * @details \b Inputs: none + * @details \b Outputs: filteredcurrentConductivityReadings[] + * @param message Override message from Dialin which includes a sensor + * ID and override value of the conductivity rate for that sensor. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testDDConductivitySensorFilteredReadingsOverride( MESSAGE_T *message ) +{ + BOOL result = FALSE; + TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; + OVERRIDE_TYPE_T ovType = getOverrideArrayPayloadFromMessage( message, &payload ); + + if ( payload.index <= LAST_DD_COND_SENSOR ) + { + result = f32ArrayOverride( message, &filteredcurrentConductivityReadings[0], NUM_OF_CONDUCTIVITY_SENSORS - 1 );; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testDDConductivitySensorFilteredTemperatureReadingsOverride function + * overrides the filtered value of the specified DD conductivity 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 conductivity rate for that sensor. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testDDConductivitySensorFilteredTemperatureReadingsOverride( MESSAGE_T *message ) +{ + BOOL result = FALSE; + TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; + OVERRIDE_TYPE_T ovType = getOverrideArrayPayloadFromMessage( message, &payload ); + + if ( payload.index <= LAST_DD_COND_SENSOR ) + { + result = f32ArrayOverride( message, &filteredcurrentTemperatureReadings[0], NUM_OF_CONDUCTIVITY_SENSORS - 1 );; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testConductivitySensorDataPublishIntervalOverride function overrides the + * conductivity sensor data publish interval. + * @details \b Inputs: none + * @details \b Outputs: conductivityDataPublishInterval + * @param message Override message from Dialin which includes the value + * that override valves states publish interval with (in ms) + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testFPConductivitySensorDataPublishIntervalOverride( MESSAGE_T *message ) +{ + BOOL result = u32BroadcastIntervalOverride( message, &fpConductivityDataPublishInterval, TASK_PRIORITY_INTERVAL ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testFPConductivitySensorFilteredReadingsOverride function overrides the + * filtered value of the specified FP conductivity sensor with a given value. + * @details \b Inputs: none + * @details \b Outputs: filteredcurrentConductivityReadings[] + * @param message Override message from Dialin which includes a sensor + * ID and override value of the conductivity rate for that sensor. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testFPConductivitySensorFilteredReadingsOverride( MESSAGE_T *message ) +{ + BOOL result = FALSE; + TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; + OVERRIDE_TYPE_T ovType = getOverrideArrayPayloadFromMessage( message, &payload ); + + if ( ( payload.index >= FIRST_FP_COND_SENSOR ) && ( payload.index <= LAST_FP_COND_SENSOR ) ) + { + result = f32ArrayOverride( message, &filteredcurrentConductivityReadings[0], NUM_OF_CONDUCTIVITY_SENSORS - 1 );; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testFPConductivitySensorFilteredTemperatureReadingsOverride function + * overrides the filtered value of the specified FP conductivity 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 conductivity rate for that sensor. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testFPConductivitySensorFilteredTemperatureReadingsOverride( MESSAGE_T *message ) +{ + BOOL result = FALSE; + TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; + OVERRIDE_TYPE_T ovType = getOverrideArrayPayloadFromMessage( message, &payload ); + + if ( ( payload.index >= FIRST_FP_COND_SENSOR ) && ( payload.index <= LAST_FP_COND_SENSOR ) ) + { + result = f32ArrayOverride( message, &filteredcurrentTemperatureReadings[0], NUM_OF_CONDUCTIVITY_SENSORS - 1 );; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testRORejectionRatioDataPublishIntervalOverride function overrides the + * RO Rejection ratio data publish interval. + * @details \b Inputs: none + * @details \b Outputs: roRRDataPublishInterval + * @param message Override message from Dialin which includes the value + * that override valves states publish interval with (in ms) + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testRORejectionRatioDataPublishIntervalOverride( MESSAGE_T *message ) +{ + BOOL result = u32BroadcastIntervalOverride( message, &roRRDataPublishInterval, TASK_PRIORITY_INTERVAL ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testRORejectionRatioFilteredOverride function + * overrides the filtered RO rejection value with a given value. + * @details \b Inputs: none + * @details \b Outputs: roRRAvg + * @param message Override message from Dialin which includes override value + * of the RO rejection ratio. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testRORejectionRatioFilteredOverride( MESSAGE_T *message ) +{ + BOOL result = f32Override( message, &roRRAvg ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testConductivitySensorReadingsOverride function overrides the value of the + * specified conductivity sensor with a given value and determines which driver + * override. + * @details \b Inputs: testConfig + * @details \b Outputs: none + * @param message Override message from Dialin which includes an sensor + * ID and override value of the conductivity sensor. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testConductivitySensorReadingsOverride( MESSAGE_T *message ) +{ + BOOL result = FALSE; + TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; + OVERRIDE_TYPE_T ovType = getOverrideArrayPayloadFromMessage( message, &payload ); + + if ( getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_2_0_HW ) != TRUE ) + { + + if ( payload.index != D74_COND ) + { + result = testTeensyConductivitySensorReadingsOverride( message ); + } + else + { + result = testConductivitySensorReadingsOverride( message ); + } + } + else + { + result = testConductivitySensorConductivityReadingsOverride( message ); + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testConductivitySensorTemperatureOverride function overrides the value of the + * specified conductivity sensor with a given value and determines which driver + * override. + * @details \b Inputs: testConfig + * @details \b Outputs: none + * @param message Override message from Dialin which includes an sensor + * ID and override value of the conductivity sensor. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testConductivitySensorTemperatureOverride( MESSAGE_T *message ) +{ + BOOL result = FALSE; + TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; + OVERRIDE_TYPE_T ovType = getOverrideArrayPayloadFromMessage( message, &payload ); + + if ( getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_2_0_HW ) != TRUE ) + { + + if ( payload.index != D74_COND ) + { + result = testTeensyConductivitySensorTemperatureReadingsOverride( message ); + } + else + { + result = testConductivitySensorTemperatureReadingsOverride( message ); + } + } + else + { + result = testConductivitySensorTemperatureReadingsOverride( message ); + } + + return result; +} /**@}*/