Index: firmware/App/Controllers/FlowSensors.c =================================================================== diff -u -r4e11c80367b5ae522aa34fb137079e516c98831b -rcb4d35cc50df2d3cc9e828cd92e53cf456ca9b9d --- firmware/App/Controllers/FlowSensors.c (.../FlowSensors.c) (revision 4e11c80367b5ae522aa34fb137079e516c98831b) +++ firmware/App/Controllers/FlowSensors.c (.../FlowSensors.c) (revision cb4d35cc50df2d3cc9e828cd92e53cf456ca9b9d) @@ -17,30 +17,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 ********** @@ -142,10 +142,9 @@ #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(); //isFlowOutOfUpperRange = ( currentFlow > MAX_DIALYSATE_FLOWRATE_LPM ? TRUE : FALSE );