Index: firmware/App/Monitors/Flow.c =================================================================== diff -u -r5aaed18e3cd460c091c36c95c81635273bad61c6 -r340b6bedc5aac2ad47364ade48a842f00b12b8fe --- firmware/App/Monitors/Flow.c (.../Flow.c) (revision 5aaed18e3cd460c091c36c95c81635273bad61c6) +++ firmware/App/Monitors/Flow.c (.../Flow.c) (revision 340b6bedc5aac2ad47364ade48a842f00b12b8fe) @@ -15,19 +15,19 @@ * ***************************************************************************/ -#include "AlarmMgmtRO.h" +#include "AlarmMgmtRO.h" #include "Flow.h" #include "Messaging.h" #include "PersistentAlarm.h" #include "TaskPriority.h" - -/** - * @addtogroup Flow - * @{ - */ - -// ********** private definitions ********** +/** + * @addtogroup Flow + * @{ + */ + +// ********** private definitions ********** + #define FLOWS_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Interval (ms/task time) at which the flows data is published on the CAN bus. #define DATA_PUBLISH_COUNTER_START_COUNT ( 5 ) ///< Data publish counter start count. #define FLOW_SAMPLE_FILTER_MS ( 500 ) ///< Filter flow data for given time @@ -60,9 +60,9 @@ F32 flowTempReadingsTotal; ///< Rolling total - used to calc average. U32 flowTempReadingsCount; ///< Number of samples in rolling average buffer } FILTER_FLOW_TEMPERATURE_READINGS_T; - -// ********** private data ********** +// ********** private data ********** + static OVERRIDE_F32_T filteredcurrentFlowReadings[ NUM_OF_FLOW_SENSORS ]; ///< filtered current flow sensor flow readings (overrideable). static OVERRIDE_F32_T filteredcurrentFlowTempReadings[ NUM_OF_FLOW_SENSORS ]; ///< filtered current flow sensor temperature readings (overrideable). //static RO_PRES_SENSORS_CAL_RECORD_T flowsCalRecord; ///< Flows calibration record. @@ -71,10 +71,10 @@ static FILTER_FLOW_TEMPERATURE_READINGS_T filteredFlowTempReadings[NUM_OF_FLOW_SENSORS]; ///< Filtered temperature reading for flow sensors. static FLOW_STATE_T flowsState; ///< current state of flow monitor state machine. static U32 flowsDataPublicationTimerCounter; ///< used to schedule flow data publication to CAN bus. -static OVERRIDE_U32_T flowsDataPublishInterval; ///< Flow data publish interval. - -// ********** private function prototypes ********** +static OVERRIDE_U32_T flowsDataPublishInterval; ///< Flow data publish interval. +// ********** private function prototypes ********** + static void filterFlowSensors( void ); static void filterFlowSensorReadings( void ); static void filterFlowSensorTemperatureReadings( void ); @@ -205,38 +205,38 @@ return result; } -/*********************************************************************//** - * @brief +/*********************************************************************//** + * @brief * The execFlowMonitor function executes the flow monitor state machine - * and publishes flow data. + * and publishes flow data. * @note This function should be called periodically to maintain monitoring * of the flow sensors. - * @details \b Inputs: flowsState + * @details \b Inputs: flowsState * @details \b Outputs: flowsState - * @details \b Alarm: ALARM_ID_RO_SOFTWARE_FAULT if in invalid flow state - * @return none - *************************************************************************/ -void execFlowMonitor( void ) -{ - // state machine - switch ( flowsState ) - { - case FLOW_INIT_STATE: - flowsState = handleFlowsInitState(); - break; - - case FLOW_CONTINUOUS_READ_STATE: - flowsState = handleFlowsContReadState(); - break; - - default: + * @details \b Alarm: ALARM_ID_RO_SOFTWARE_FAULT if in invalid flow state + * @return none + *************************************************************************/ +void execFlowMonitor( void ) +{ + // state machine + switch ( flowsState ) + { + case FLOW_INIT_STATE: + flowsState = handleFlowsInitState(); + break; + + case FLOW_CONTINUOUS_READ_STATE: + flowsState = handleFlowsContReadState(); + break; + + default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_RO_SOFTWARE_FAULT, SW_FAULT_ID_FLOW_INVALID_EXEC_STATE, (U32)flowsState ) - flowsState = FLOW_INIT_STATE; - break; - } - - // publish flow data on interval - publishFlowsData(); + flowsState = FLOW_INIT_STATE; + break; + } + + // publish flow data on interval + publishFlowsData(); } /*********************************************************************//** @@ -318,73 +318,73 @@ // flowsCalRecord.flowSensors[ (FLOW_SENSORS_T)sensorId ].offset; // return calFlow; //} - -/*********************************************************************//** - * @brief - * The handleFlowsInitState function handles the flows initialize state - * of the flow monitor state machine. - * @details \b Inputs: none - * @details \b Outputs: none - * @return next state - *************************************************************************/ -static FLOW_STATE_T handleFlowsInitState( void ) -{ - return FLOW_CONTINUOUS_READ_STATE; -} - -/*********************************************************************//** - * @brief - * The handleFlowsContReadState function handles the continuous read state + +/*********************************************************************//** + * @brief + * The handleFlowsInitState function handles the flows initialize state + * of the flow monitor state machine. + * @details \b Inputs: none + * @details \b Outputs: none + * @return next state + *************************************************************************/ +static FLOW_STATE_T handleFlowsInitState( void ) +{ + return FLOW_CONTINUOUS_READ_STATE; +} + +/*********************************************************************//** + * @brief + * The handleFlowsContReadState function handles the continuous read state * of the flows monitor state machine. Raw readings are read from driver - * and then filtered via moving average and calibrated. - * @details \b Inputs: raw readings from flow sensor driver - * @details \b Outputs: flow sensors are sampled, filtered and calibrated. - * @return next state - *************************************************************************/ -static FLOW_STATE_T handleFlowsContReadState( void ) + * and then filtered via moving average and calibrated. + * @details \b Inputs: raw readings from flow sensor driver + * @details \b Outputs: flow sensors are sampled, filtered and calibrated. + * @return next state + *************************************************************************/ +static FLOW_STATE_T handleFlowsContReadState( void ) { FLOW_STATE_T result = FLOW_CONTINUOUS_READ_STATE; // Get raw flow readings readFlowSensors(); // filter raw flow readings - filterFlowSensors(); - - return result; + filterFlowSensors(); + + return result; } -/*********************************************************************//** - * @brief - * The publishFlowsData function publishes RO flow data at a set interval. - * @details \b Inputs: flowsDataPublicationTimerCounter +/*********************************************************************//** + * @brief + * The publishFlowsData function publishes RO flow data at a set interval. + * @details \b Inputs: flowsDataPublicationTimerCounter * @details \b Outputs: flowsDataPublicationTimerCounter - * @details \b Message \b Sent: MSG_ID_RO_FLOW_DATA to publish flow data. - * @return none - *************************************************************************/ -static void publishFlowsData( void ) -{ - // publish pressure/occlusion data on interval - if ( ++flowsDataPublicationTimerCounter >= getU32OverrideValue( &flowsDataPublishInterval ) ) + * @details \b Message \b Sent: MSG_ID_RO_FLOW_DATA to publish flow data. + * @return none + *************************************************************************/ +static void publishFlowsData( void ) +{ + // publish pressure/occlusion data on interval + if ( ++flowsDataPublicationTimerCounter >= getU32OverrideValue( &flowsDataPublishInterval ) ) { FLOW_TEMP_DATA_T data; data.FlowFMS = getFilteredFlow( FLOW_SENSOR_WATER_INLET ); - data.FlowFMP = getFilteredFlow( FLOW_SENSOR_RO_OUTLET ); - + data.FlowFMP = getFilteredFlow( FLOW_SENSOR_RO_OUTLET ); + data.TempFMS = getFilteredFlowSensorTemperature( FLOW_SENSOR_WATER_INLET ); data.TempFMP = getFilteredFlowSensorTemperature( FLOW_SENSOR_RO_OUTLET ); - broadcastData( MSG_ID_RO_FLOW_DATA, COMM_BUFFER_OUT_CAN_RO_BROADCAST, (U08*)&data, sizeof( FLOW_TEMP_DATA_T ) ); + broadcastData( MSG_ID_RO_FLOW_DATA, COMM_BUFFER_OUT_CAN_RO_BROADCAST, (U08*)&data, sizeof( FLOW_TEMP_DATA_T ) ); flowsDataPublicationTimerCounter = 0; - } -} - - -/************************************************************************* - * TEST SUPPORT FUNCTIONS - *************************************************************************/ + } +} +/************************************************************************* + * TEST SUPPORT FUNCTIONS + *************************************************************************/ + + /*********************************************************************//** * @brief * The testFlowSensorDataPublishIntervalOverride function overrides the @@ -412,13 +412,13 @@ * ID and override value of the flow rate for that sensor. * @return TRUE if override successful, FALSE if not *************************************************************************/ -//BOOL testFlowSensorFilteredReadingsOverride( MESSAGE_T *message ) -//{ -// BOOL result = f32ArrayOverride( message, &filteredcurrentFlowReadings[0], NUM_OF_FLOW_SENSORS - 1 ); -// -// return result; -//} +BOOL testFlowSensorFilteredReadingsOverride( MESSAGE_T *message ) +{ + BOOL result = f32ArrayOverride( message, &filteredcurrentFlowReadings[0], NUM_OF_FLOW_SENSORS - 1 ); + return result; +} + /*********************************************************************//** * @brief * The testFlowSensorFilteredTemperatureReadingsOverride function overrides the @@ -429,11 +429,11 @@ * ID and override value of the flow sensor temperature. * @return TRUE if override successful, FALSE if not *************************************************************************/ -//BOOL testFlowSensorFilteredTemperatureReadingsOverride( MESSAGE_T *message ) -//{ -// BOOL result = f32ArrayOverride( message, &filteredcurrentFlowTempReadings[0], NUM_OF_FLOW_SENSORS - 1 ); -// -// return result; -//} - -/**@}*/ +BOOL testFlowSensorFilteredTemperatureReadingsOverride( MESSAGE_T *message ) +{ + BOOL result = f32ArrayOverride( message, &filteredcurrentFlowTempReadings[0], NUM_OF_FLOW_SENSORS - 1 ); + + return result; +} + +/**@}*/