Index: firmware/App/Controllers/FlowSensors.c =================================================================== diff -u -r256d5cb05f1ef09e19e2f2733a111f600c73a7ee -r2e21405574597474db0ebae86cdd7fa2d517f71c --- firmware/App/Controllers/FlowSensors.c (.../FlowSensors.c) (revision 256d5cb05f1ef09e19e2f2733a111f600c73a7ee) +++ firmware/App/Controllers/FlowSensors.c (.../FlowSensors.c) (revision 2e21405574597474db0ebae86cdd7fa2d517f71c) @@ -33,30 +33,30 @@ // ********** private definitions ********** -#define FLOW_SENSORS_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Interval (ms/task time) at which the Dialysate flow data is published on the CAN bus. -#define FLOW_SENSORS_EDGES_BUFFER_LENGTH 100 -#define FLOW_SENSORS_PULSES_PER_LITER 110000 // TODO calibration record +#define FLOW_SENSORS_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Interval (ms/task time) at which the Dialysate flow data is published on the CAN bus. +#define FLOW_SENSORS_EDGES_BUFFER_LENGTH 100 ///< Flow sensors edges buffer length. +#define FLOW_SENSORS_PULSES_PER_LITER 110000 ///< Flow sensors pulses per liter +#define FLOW_OUT_OF_RANGE_PERSISTENT_INTERVAL ( 12 * MS_PER_SECOND ) ///< Flow out of range time out in counts. +#define DATA_PUBLISH_COUNTER_START_COUNT 20 ///< Data publish counter start count. -#define FLOW_OUT_OF_RANGE_PERSISTENT_INTERVAL ( 12 * MS_PER_SECOND ) // Why is this so long? ///< Flow out of range time out in counts. -#define DATA_PUBLISH_COUNTER_START_COUNT 20 ///< Data publish counter start count. +static const F32 FLOW_SENSORS_LITERS_PER_PULSES = ( 1.0 / (F32)FLOW_SENSORS_PULSES_PER_LITER ); ///< Flow sensors liters/pulses coefficient. -static const F32 FLOW_SENSORS_LITERS_PER_PULSES = ( 1.0 / (F32)FLOW_SENSORS_PULSES_PER_LITER ); - // ********** private data ********** +/// Flow sensors data structure typedef struct { - U08 edgeCountsIndex; - U16 edgeCountsBuffer[ FLOW_SENSORS_EDGES_BUFFER_LENGTH ]; - OVERRIDE_F32_T measuredFlowLPM; - OVERRIDE_F32_T measuredROFlowWithCPsLPM; + U08 edgeCountsIndex; ///< Edge counts index. + U16 edgeCountsBuffer[ FLOW_SENSORS_EDGES_BUFFER_LENGTH ]; ///< Edge counts buffer array. + OVERRIDE_F32_T measuredFlowLPM; ///< Measured flow in L/min. + OVERRIDE_F32_T measuredROFlowWithCPsLPM; ///< Measured RO flow with concentrate pumps in L/min. } FLOW_SENSOR_STATUS_T; -static U32 dataPublicationCounter; ///< Used to schedule Dialysate flow data publication to CAN bus. +static U32 dataPublicationCounter; ///< Used to schedule Dialysate flow data publication to CAN bus. static OVERRIDE_U32_T flowSensorsDataPublishInterval = { FLOW_SENSORS_DATA_PUB_INTERVAL, FLOW_SENSORS_DATA_PUB_INTERVAL, - 0, 0 }; ///< Interval (in ms) at which to publish Dialysate flow data to CAN bus. -static FLOW_SENSOR_STATUS_T flowSensorStatus[ NUM_OF_FLOW_SENSORS ]; + 0, 0 }; ///< Interval (in ms) at which to publish Dialysate flow data to CAN bus. +static FLOW_SENSOR_STATUS_T flowSensorStatus[ NUM_OF_FLOW_SENSORS ]; ///< Flow sensors status. static DG_FLOW_SENSORS_CAL_RECORD_T flowSensorsCalRecord; ///< Flow sensors calibration record. // ********** private function prototypes ********** @@ -97,20 +97,21 @@ { SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; BOOL calStatus = getNVRecord2Driver( GET_CAL_FLOW_SENSORS, (U08*)&flowSensorsCalRecord, sizeof( DG_FLOW_SENSORS_CAL_RECORD_T ), - NUM_OF_CAL_DATA_FLOW_SENSORS, ALARM_ID_DG_DIALYSATE_FLOW_SENSOR_INVALID_CAL_RECORD ); - result = ( TRUE == calStatus ? SELF_TEST_STATUS_PASSED : SELF_TEST_STATUS_FAILED ); + NUM_OF_CAL_DATA_FLOW_SENSORS, ALARM_ID_DG_FLOW_SENSORS_INVALID_CAL_RECORD ); + result = ( TRUE == calStatus ? SELF_TEST_STATUS_PASSED : SELF_TEST_STATUS_FAILED ); + return result; } /*********************************************************************//** * @brief - * The execFlowSesnorsMonitor function executes the flow sensors monitor. + * The execFlowSensorsMonitor function executes the flow sensors monitor. * @details Inputs: none * @details Outputs: flowSensorStatus, flowSensorsCalRecord * @return none *************************************************************************/ -void execFlowSesnorsMonitor( void ) +void execFlowSensorsMonitor( void ) { U08 i; U08 countsIndex; @@ -122,7 +123,7 @@ if ( TRUE == isNewCalibrationRecordAvailable() ) { getNVRecord2Driver( GET_CAL_FLOW_SENSORS, (U08*)&flowSensorsCalRecord, sizeof( DG_FLOW_SENSORS_CAL_RECORD_T ), - NUM_OF_CAL_DATA_FLOW_SENSORS, ALARM_ID_DG_DIALYSATE_FLOW_SENSOR_INVALID_CAL_RECORD ); + NUM_OF_CAL_DATA_FLOW_SENSORS, ALARM_ID_DG_FLOW_SENSORS_INVALID_CAL_RECORD ); } for ( i = 0; i < NUM_OF_FLOW_SENSORS; i++ ) @@ -153,17 +154,16 @@ #ifndef _VECTORCAST_ default: - // TODO software fault + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_FLOW_SENSOR_SELECTED, i ); break; #endif } - flowSensorStatus[ i ].edgeCountsIndex = INC_WRAP( countsIndex, 0, FLOW_SENSORS_EDGES_BUFFER_LENGTH ); + flowSensorStatus[ i ].edgeCountsIndex = INC_WRAP( countsIndex, 0, ( FLOW_SENSORS_EDGES_BUFFER_LENGTH - 1 ) ); } - // TODO dialysate flow alarm. Is it needed? - //currentFlow = getMeasuredDialysateFlowRate(); + //currentFlow = getMeasuredFlowRateLPM( DIALYSATE_FLOW_SENSOR ); //isFlowOutOfUpperRange = ( currentFlow > MAX_DIALYSATE_FLOWRATE_LPM ? TRUE : FALSE ); //checkPersistentAlarm( ALARM_ID_DIALYSATE_FLOW_RATE_OUT_OF_RANGE, isFlowOutOfUpperRange, currentFlow, MAX_DIALYSATE_FLOWRATE_LPM ); @@ -180,11 +180,28 @@ *************************************************************************/ F32 getMeasuredFlowRateLPM( FLOW_SENSORS_T sensorId ) { - return getF32OverrideValue( &flowSensorStatus[ sensorId ].measuredFlowLPM ); + F32 flow = getF32OverrideValue( &flowSensorStatus[ sensorId ].measuredFlowLPM ); + + return flow; } /*********************************************************************//** * @brief + * The getMeasuredROFlowRateWithConcPumpsLPM function gets the measured flow + * rate of a flow sensor in L/min. + * @details Inputs: flowSensorStatus + * @details Outputs: flowSensorStatus + * @return the current flow rate (in L/min). + *************************************************************************/ +F32 getMeasuredROFlowRateWithConcPumpsLPM( void ) +{ + F32 flow = getF32OverrideValue( &flowSensorStatus[ RO_FLOW_SENSOR ].measuredROFlowWithCPsLPM ); + + return flow; +} + +/*********************************************************************//** + * @brief * The publishFlowSensorsData function publishes flow sensors data at * the set interval. * @details Inputs: flowSensorsDataPublicationCounter, @@ -198,13 +215,13 @@ if ( ++dataPublicationCounter >= getU32OverrideValue( &flowSensorsDataPublishInterval ) ) { FLOW_SENSORS_DATA_T data; + data.ROFlowRateLPM = getMeasuredFlowRateLPM( RO_FLOW_SENSOR ); data.dialysateFlowRateLPM = getMeasuredFlowRateLPM( DIALYSATE_FLOW_SENSOR ); - data.ROFlowRateWithCPsLPM = getF32OverrideValue( &flowSensorStatus[ RO_FLOW_SENSOR ].measuredROFlowWithCPsLPM ); + data.ROFlowRateWithCPsLPM = getMeasuredROFlowRateWithConcPumpsLPM(); dataPublicationCounter = 0; broadcastData( MSG_ID_DG_FLOW_SENSORS_DATA, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&data, sizeof( FLOW_SENSORS_DATA_T ) ); - } }