Index: firmware/App/Controllers/DialysateFlow.c =================================================================== diff -u -ra069eb423b26296eb95214e18383c81adae07497 -r87ebf31788a90216c65e0264e2b8cb21d25e5b9b --- firmware/App/Controllers/DialysateFlow.c (.../DialysateFlow.c) (revision a069eb423b26296eb95214e18383c81adae07497) +++ firmware/App/Controllers/DialysateFlow.c (.../DialysateFlow.c) (revision 87ebf31788a90216c65e0264e2b8cb21d25e5b9b) @@ -1,14 +1,14 @@ /************************************************************************** * -* Copyright (c) 2019-2021 Diality Inc. - All Rights Reserved. +* Copyright (c) 2021-2022 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 DialysateFlow.c * -* @author (last) Sean Nash -* @date (last) 15-Nov-2021 +* @author (last) Dara Navaei +* @date (last) 15-Jul-2022 * * @author (original) Hung Nguyen * @date (original) 20-Oct-2021 @@ -36,23 +36,24 @@ #define FLOW_SENSOR_ZERO_READING 0xFFFF ///< Flow sensor reading indicates zero flow (or flow lower than can be detected by sensor). #define FLOW_SAMPLES_TO_AVERAGE ( 1000 / TASK_PRIORITY_INTERVAL ) ///< Averaging flow data over 1000 ms intervals. -#define FLOW_AVERAGE_MULTIPLIER ( 1.0 / (F32)FLOW_SAMPLES_TO_AVERAGE ) ///< Optimization - multiplying is faster than dividing. +#define FLOW_AVERAGE_MULTIPLIER ( 1.0F / (F32)FLOW_SAMPLES_TO_AVERAGE ) ///< Optimization - multiplying is faster than dividing. -#define DIALYSATE_FLOW_ADC_TO_LPM_FACTOR 300 ///< Conversion factor from pulse period (2us units) to flow rate (L/min) for dialysate flow rate (divide this by pulse period). +#define DIALYSATE_FLOW_ADC_TO_LPM_FACTOR 272.72F ///< Conversion factor from pulse period (2us units) to flow rate (L/min) for dialysate flow rate (divide this by pulse period). #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. // ********** private data ********** -static U32 dialysateFlowDataPublicationTimerCounter = 0; ///< Used to schedule Dialysate flow data publication to CAN bus. +static U32 dialysateFlowDataPublicationTimerCounter; ///< Used to schedule Dialysate flow data publication to CAN bus. static OVERRIDE_U32_T dialysateFlowDataPublishInterval = { DIALYSATE_FLOW_DATA_PUB_INTERVAL, DIALYSATE_FLOW_DATA_PUB_INTERVAL, 0, 0 }; ///< Interval (in ms) at which to publish Dialysate flow data to CAN bus. static OVERRIDE_F32_T measuredDialysateFlowRateLPM = { 0.0, 0.0, 0.0, 0 }; ///< Measured Dialysate flow rate (in L/min). -static S32 measuredFlowReadingsSum = 0; ///< Raw flow reading sums for averaging. -static U32 flowFilterCounter = 0; ///< Flow filtering counter. +static S32 measuredFlowReadingsSum; ///< Raw flow reading sums for averaging. +static U32 flowFilterCounter; ///< Flow filtering counter. static DG_FLOW_SENSORS_CAL_RECORD_T flowSensorsCalRecord; ///< Flow sensors calibration record. // ********** private function prototypes ********** @@ -74,7 +75,7 @@ // Initialize the variables measuredFlowReadingsSum = 0; flowFilterCounter = 0; - dialysateFlowDataPublicationTimerCounter = 0; + dialysateFlowDataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; } /*********************************************************************//** @@ -88,19 +89,10 @@ SELF_TEST_STATUS_T execDialysateFlowMeterSelfTest( void ) { 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 ); - 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_FLOW_SENSORS_INVALID_CAL_RECORD ); - - if ( TRUE == calStatus ) - { - result = SELF_TEST_STATUS_PASSED; - } - else - { - result = SELF_TEST_STATUS_FAILED; - } - return result; } @@ -117,6 +109,7 @@ void execDialysateFlowMeterMonitor( void ) { U16 dialysateFlowReading = getFPGADialysateFlowRate(); + dialysateFlowReading = ( 0 == dialysateFlowReading ? FLOW_SENSOR_ZERO_READING : dialysateFlowReading ); F32 currentFlow; BOOL isFlowOutOfUpperRange; @@ -127,7 +120,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_FLOW_SENSORS_INVALID_CAL_RECORD ); + NUM_OF_CAL_DATA_FLOW_SENSORS, ALARM_ID_DG_RO_FLOW_SENSOR_INVALID_CAL_RECORD ); } // Read flow at the control set @@ -139,7 +132,7 @@ measuredDialysateFlowRateLPM.data = pow(flow, 4) * flowSensorsCalRecord.flowSensors[ CAL_DATA_DIALYSATE_FLOW_SENSOR ].fourthOrderCoeff + pow(flow, 3) * flowSensorsCalRecord.flowSensors[ CAL_DATA_DIALYSATE_FLOW_SENSOR ].thirdOrderCoeff + pow(flow, 2) * flowSensorsCalRecord.flowSensors[ CAL_DATA_DIALYSATE_FLOW_SENSOR ].secondOrderCoeff + - flow * flowSensorsCalRecord.flowSensors[ CAL_DATA_DIALYSATE_FLOW_SENSOR ].gain + + flow * flowSensorsCalRecord.flowSensors[ CAL_DATA_DIALYSATE_FLOW_SENSOR ].gain + flowSensorsCalRecord.flowSensors[ CAL_DATA_DIALYSATE_FLOW_SENSOR ].offset; // If the flow is less than a certain value, FPGA will return 0xFFFF meaning that the flow is 0. @@ -149,11 +142,11 @@ } measuredFlowReadingsSum = 0; - flowFilterCounter = 0; + flowFilterCounter = 0; } - currentFlow = getMeasuredDialysateFlowRate(); - isFlowOutOfUpperRange = currentFlow > MAX_DIALYSATE_FLOWRATE_LPM; + currentFlow = getMeasuredDialysateFlowRate(); + isFlowOutOfUpperRange = ( currentFlow > MAX_DIALYSATE_FLOWRATE_LPM ? TRUE : FALSE ); checkPersistentAlarm( ALARM_ID_DIALYSATE_FLOW_RATE_OUT_OF_RANGE, isFlowOutOfUpperRange, currentFlow, MAX_DIALYSATE_FLOWRATE_LPM ); // Publish dialysate flow meter data on the CAN bus according to the specified interval @@ -175,8 +168,7 @@ DIALYSATE_FLOW_METER_DATA_T dialysateFlowData; dialysateFlowData.measuredDialysateFlowRate = getMeasuredDialysateFlowRate(); - broadcastData( MSG_ID_DG_DIALYSATE_FLOW_METER_DATA, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&dialysateFlowData, - sizeof( DIALYSATE_FLOW_METER_DATA_T ) ); + broadcastData( MSG_ID_DG_DIALYSATE_FLOW_METER_DATA, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&dialysateFlowData, sizeof( DIALYSATE_FLOW_METER_DATA_T ) ); dialysateFlowDataPublicationTimerCounter = 0; } } @@ -198,6 +190,7 @@ * TEST SUPPORT FUNCTIONS *************************************************************************/ + /*********************************************************************//** * @brief * The testSetDialysateFlowDataPublishIntervalOverride function overrides the