Index: firmware/App/DGCommon.h =================================================================== diff -u -r667b78a4ba1b948d4977b9b55234acf8d670f2d9 -r3728ad1f09658c3495a11c6ba8e784bcfdfe3794 --- firmware/App/DGCommon.h (.../DGCommon.h) (revision 667b78a4ba1b948d4977b9b55234acf8d670f2d9) +++ firmware/App/DGCommon.h (.../DGCommon.h) (revision 3728ad1f09658c3495a11c6ba8e784bcfdfe3794) @@ -25,7 +25,7 @@ #define DG_VERSION_MAJOR 0 #define DG_VERSION_MINOR 6 #define DG_VERSION_MICRO 0 -#define DG_VERSION_BUILD 14 +#define DG_VERSION_BUILD 49 // ********** build switches ********** @@ -58,6 +58,7 @@ // Turn these flags on to disable dialysate mixing #define DISABLE_DIALYSATE_CHECK 1 #define DISABLE_MIXING 1 + #define USE_SMALL_FLOW_SENSOR_K_FACTOR 1 #include #include Index: firmware/App/Modes/ModeFill.c =================================================================== diff -u -r667b78a4ba1b948d4977b9b55234acf8d670f2d9 -r3728ad1f09658c3495a11c6ba8e784bcfdfe3794 --- firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision 667b78a4ba1b948d4977b9b55234acf8d670f2d9) +++ firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision 3728ad1f09658c3495a11c6ba8e784bcfdfe3794) @@ -66,15 +66,23 @@ // ********** private data ********** +typedef struct +{ + F32 fillFlowRunningSum; ///< Fill flow running sum. + U32 fillFlowSampleCounter; ///< Fill flow sample counter. + F32 fillFlowAverage; ///< Fill flow average value. +} FILL_FLOW_RATE_STATUS_T; + static DG_FILL_MODE_STATE_T fillState; ///< Currently active fill state. static U32 dialysateFillStartTime; ///< Current time when starting to fill dialysate. static F32 reservoirBaseWeight; ///< Fill reservoir base weight. +static FILL_FLOW_RATE_STATUS_T fillFlowRate; ///< Fill flow rate status. static U32 waterQualityCheckStartTime; ///< Starting time for inlet water quality check. static U32 concentrateTestStartTime; ///< Starting time for concentrate test. static U32 concentratePumpPrimeCount; ///< Interval count for concentrate pump prime. -static F32 totalROFlowRate_mL_min; ///< Total RO flow rate over period of time. +static F32 totalROFlowRate_mL_min; ///< Total RO flow rate over period of time. static F32 acidConductivityTotal; ///< Total of acid conductivity during fill. static F32 dialysateConductivityTotal; ///< Total of dialysate conductivity during fill. static U32 conductivitySampleCount; ///< Sample count of conductivity during fill. @@ -94,6 +102,7 @@ static BOOL isWaterQualityGood( void ); static BOOL checkDialysateTemperature( void ); static void handleDialysateMixing( F32 measuredROFlowRate_mL_min ); +static void calculateFillAverage( void ); /*********************************************************************//** * @brief @@ -104,15 +113,18 @@ *************************************************************************/ void initFillMode( void ) { - fillState = DG_FILL_MODE_STATE_START; - dialysateFillStartTime = 0; - reservoirBaseWeight = 0.0; - totalROFlowRate_mL_min = 0.0; - concentrateTestStartTime = 0; - acidConductivityTotal = 0.0; - dialysateConductivityTotal = 0.0; - conductivitySampleCount = 0; - concentratePumpPrimeCount = 0; + fillState = DG_FILL_MODE_STATE_START; + dialysateFillStartTime = 0; + reservoirBaseWeight = 0.0; + totalROFlowRate_mL_min = 0.0; + concentrateTestStartTime = 0; + acidConductivityTotal = 0.0; + dialysateConductivityTotal = 0.0; + conductivitySampleCount = 0; + concentratePumpPrimeCount = 0; + fillFlowRate.fillFlowAverage = 0.79; // TODO get this value from NV RAM at the beginning of the fill + fillFlowRate.fillFlowRunningSum = 0.0; + fillFlowRate.fillFlowSampleCounter = 0; initPersistentAlarm( ALARM_ID_ACID_CONDUCTIVITY_OUT_OF_RANGE, 0, EMPTY_BOTTLE_DETECT_PERSISTENT_PERIOD_MS ); initPersistentAlarm( ALARM_ID_BICARB_CONDUCTIVITY_OUT_OF_RANGE, 0, EMPTY_BOTTLE_DETECT_PERSISTENT_PERIOD_MS ); @@ -143,8 +155,8 @@ // NOTE: The target flow rate should be set prior to setting the start primary heater // because the initial guess in the heaters driver needs the target flow to calculate // the new PWMs for the main and small primary heaters - setROPumpTargetFlowRate( TARGET_RO_FLOW_RATE_L, TARGET_RO_PRESSURE_PSI ); - startPrimaryHeater(); + //setROPumpTargetFlowRate( TARGET_RO_FLOW_RATE_L, TARGET_RO_PRESSURE_PSI ); + startHeater( DG_PRIMARY_HEATER ); } /*********************************************************************//** @@ -213,6 +225,19 @@ /*********************************************************************//** * @brief + * The getAverageFillFlowRate function returns the moving average fill + * flow rate. + * @details Inputs: none + * @details Outputs: averageFillFlowRate + * @return the moving average of the fill flow rate + *************************************************************************/ +F32 getAverageFillFlowRate( void ) +{ + return fillFlowRate.fillFlowAverage; +} + +/*********************************************************************//** + * @brief * The handleCheckInletWaterState function checks for inlet water quality * before jumping to dialysate production state. * @details Inputs: Temperature and conductivity alarms @@ -313,8 +338,8 @@ { DG_FILL_MODE_STATE_T result = DG_FILL_MODE_STATE_ACID_PUMP_CHECK; DG_ACID_CONCENTRATES_RECORD_T acid = getAcidConcentrateCalRecord(); - F32 const measuredROFlowRate_mL_min = getMeasuredROFlowRate() * ML_PER_LITER; - F32 acidPumpFlowRate_mL_min = measuredROFlowRate_mL_min * acid.acidConcentrate[ CAL_DATA_ACID_CONCENTRATE_1 ].acidConcMixRatio + + F32 measuredROFlowRate_mL_min = getMeasuredROFlowRate() * ML_PER_LITER; + F32 acidPumpFlowRate_mL_min = measuredROFlowRate_mL_min * acid.acidConcentrate[ CAL_DATA_ACID_CONCENTRATE_1 ].acidConcMixRatio + CONCENTRATE_PUMP_PRIME_EXTRA_SPEED_ML_MIN; #ifndef DISABLE_DIALYSATE_CHECK F32 const acidConductivity = getConductivityValue( CONDUCTIVITYSENSORS_CD1_SENSOR ); @@ -362,8 +387,8 @@ *************************************************************************/ static DG_FILL_MODE_STATE_T handleDialysateProductionState( void ) { - DG_FILL_MODE_STATE_T result = DG_FILL_MODE_STATE_DIALYSATE_PRODUCTION; - F32 const measuredROFlowRate_mL_min = getMeasuredROFlowRate() * ML_PER_LITER; + DG_FILL_MODE_STATE_T result = DG_FILL_MODE_STATE_DIALYSATE_PRODUCTION; + F32 measuredROFlowRate_mL_min = getMeasuredROFlowRate() * ML_PER_LITER; #ifndef DISABLE_DIALYSATE_CHECK if ( ( TRUE == isWaterQualityGood() ) && ( TRUE == checkDialysateTemperature() ) ) @@ -426,6 +451,10 @@ dialysateConductivityTotal += dialysateConductivity; conductivitySampleCount++; + // DG is delivering dialysate keep collecting the sample counter and the measured flow + fillFlowRate.fillFlowSampleCounter += 1; + fillFlowRate.fillFlowRunningSum += getMeasuredROFlowRate(); + #ifndef DISABLE_DIALYSATE_CHECK if ( ( isWaterQualityGood() != TRUE ) || ( checkDialysateTemperature() != TRUE ) ) { @@ -486,6 +515,12 @@ } #endif + // Done with this fill. Calculate the average fill flow rate + fillFlowRate.fillFlowAverage = fillFlowRate.fillFlowRunningSum / (F32)fillFlowRate.fillFlowSampleCounter; + // Reset the variables for the next fill + fillFlowRate.fillFlowRunningSum = 0.0; + fillFlowRate.fillFlowSampleCounter = 0; + setValveState( VPO, VALVE_STATE_NOFILL_C_TO_NO ); requestNewOperationMode( DG_MODE_GENE ); } @@ -542,7 +577,7 @@ static BOOL checkDialysateTemperature( void ) { F32 const dialysateTemp = getTemperatureValue( TEMPSENSORS_OUTLET_PRIMARY_HEATER ); - F32 const targetTemp = getPrimaryHeaterTargetTemperature(); + F32 const targetTemp = getHeaterTargetTemperature( DG_PRIMARY_HEATER ); return ( ( fabs( dialysateTemp - targetTemp ) <= DIALYSATE_TEMPERATURE_TOLERANCE_C ) ? TRUE : FALSE ); } @@ -572,7 +607,12 @@ #endif } +static void calculateFillAverage( void ) +{ +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r667b78a4ba1b948d4977b9b55234acf8d670f2d9 -r3728ad1f09658c3495a11c6ba8e784bcfdfe3794 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 667b78a4ba1b948d4977b9b55234acf8d670f2d9) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 3728ad1f09658c3495a11c6ba8e784bcfdfe3794) @@ -500,33 +500,6 @@ return result; } -/*********************************************************************//** - * @brief - * The broadcastHeatersData function sends out DG heaters data - * @details Inputs: none - * @details Outputs: heaters data msg constructed and queued - * @param heatersData which is the heaters data structure pointer - * @return TRUE if msg successfully queued for transmit, FALSE if not - *************************************************************************/ -BOOL broadcastHeatersData ( HEATERS_DATA_T *heatersData ) -{ - BOOL result; - MESSAGE_T msg; - U08 *payloadPtr = msg.payload; - - // create a message record - blankMessage( &msg ); - msg.hdr.msgID = MSG_ID_DG_HEATERS_DATA; - msg.hdr.payloadLen = sizeof( HEATERS_DATA_T ); - - memcpy( payloadPtr, heatersData, sizeof( HEATERS_DATA_T ) ); - - // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer - result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_DG_BROADCAST, ACK_NOT_REQUIRED ); - - return result; -} - /*********************************************************************//** * @brief * The broadcastDrainPumpData function sends out the drain pump data. @@ -616,35 +589,6 @@ /*********************************************************************//** * @brief - * The broadcastConcentratePumpData function sends out concentrate pumps' data. - * @details Inputs: none - * @details Outputs: concentrate pump data msg constructed and queued - * @param cp1TgtSpeed target speed for concentrate pump CP1 - * @param measuredCP1Speed measured speed for concentrate pump CP1 using hall sense - * @param cp2TgtSpeed target speed for concentrate pump CP2 - * @param measuredCP2Speed measured speed for concentrate pump CP2 using hall sense - * @return TRUE if msg successfully queued for transmit, FALSE if not - *************************************************************************/ -BOOL broadcastConcentratePumpData( void * concentratePumpDataPtr ) -{ - BOOL result; - MESSAGE_T msg; - - // create a message record - blankMessage( &msg ); - msg.hdr.msgID = MSG_ID_DG_CONCENTRATE_PUMP_DATA; - msg.hdr.payloadLen = sizeof( CONCENTRATE_PUMP_DATA_T ); - - memcpy( &msg.payload, concentratePumpDataPtr, sizeof( CONCENTRATE_PUMP_DATA_T ) ); - - // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer - result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_DG_BROADCAST, ACK_NOT_REQUIRED ); - - return result; -} - -/*********************************************************************//** - * @brief * The broadcastPressureSensorsData function sends out DG pressure data. * @details Inputs: none * @details Outputs: Pressure data msg constructed and queued @@ -860,8 +804,8 @@ result = TRUE; memcpy( &payload, message->payload, sizeof( TARGET_TEMPS_PAYLOAD_T ) ); - setPrimaryHeaterTargetTemperature( payload.targetPrimaryHeaterTemp ); - setTrimmerHeaterTargetTemperature( payload.targetTrimmerHeaterTemp ); + setHeaterTargetTemperature( DG_PRIMARY_HEATER, payload.targetPrimaryHeaterTemp ); + setHeaterTargetTemperature( DG_TRIMMER_HEATER, payload.targetTrimmerHeaterTemp ); } sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_DG_2_HD, result ); } @@ -1588,7 +1532,7 @@ } else { - stopFillCmd(); + //stopFillCmd(); } } @@ -1645,7 +1589,7 @@ } else if ( ( DG_MODE_GENE == getCurrentOperationMode() ) && ( FALSE == startingTreatment ) ) { - result = requestDGStop(); + //result = requestDGStop(); TODO uncomment this only for testing If DG by itself is run, a stop request is sent since HD is may not be available } } @@ -1748,11 +1692,11 @@ if ( TRUE == startingHeater ) { - result = startPrimaryHeater(); + result = startHeater( DG_PRIMARY_HEATER ); } else { - stopPrimaryHeater(); + stopHeater( DG_PRIMARY_HEATER ); result = TRUE; } } @@ -2472,7 +2416,7 @@ } else { - result = testResetSwitchesDataPublishIntervalOverrid(); + result = testResetSwitchesDataPublishIntervalOverride(); } } @@ -3081,38 +3025,6 @@ /*********************************************************************//** * @brief -* The handleTestROFlowRateOverride function handles a request to override -* the RO flow rate. -* @details Inputs: none -* @details Outputs: message handled -* @param message a pointer to the message to handle -* @return none -*******************************************************************/ -void handleTestMeasuredROFlowRateOverride( MESSAGE_T *message ) -{ - TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; - BOOL result = FALSE; - - // verify payload length - if ( sizeof( TEST_OVERRIDE_ARRAY_PAYLOAD_T ) == message->hdr.payloadLen ) - { - memcpy( &payload, message->payload, sizeof( TEST_OVERRIDE_ARRAY_PAYLOAD_T ) ); - if ( FALSE == payload.reset ) - { - result = testSetMeasuredROFlowRateOverride( payload.state.f32 ); - } - else - { - result = testResetMeasuredROFlowRateOverride(); - } - } - - // respond to request - sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); -} - -/*********************************************************************//** -* @brief * The handleTestThermistorsValueOverride function handles a request to * override a thermistor's value. * @details Inputs: none