Index: firmware/App/Modes/ModeChemicalDisinfectFlush.c =================================================================== diff -u -r6127d594f1673bd75ffe7be22eec69a2f39e025d -refc7f297febee73bf520b4c5646e49c8f53caf41 --- firmware/App/Modes/ModeChemicalDisinfectFlush.c (.../ModeChemicalDisinfectFlush.c) (revision 6127d594f1673bd75ffe7be22eec69a2f39e025d) +++ firmware/App/Modes/ModeChemicalDisinfectFlush.c (.../ModeChemicalDisinfectFlush.c) (revision efc7f297febee73bf520b4c5646e49c8f53caf41) @@ -47,39 +47,46 @@ // ********** private definitions ********** // General defines -#define MAX_ALLOWED_STATE_TRIALS 1 ///< Max allowed trials on a state. This is general among all the states. #define CHEM_DISINFECT_FLUSH_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Mode chem disinfect data publish interval in counts. -// Start state defines -#define MIN_INLET_PRESSURE_PSI 10.0F ///< Minimum water inlet pressure in psi. - // Drain R1 & R2 states defines #define DRAIN_PUMP_TARGET_RPM 2400 ///< Drain pump target RPM during drain. #define RSRVRS_INITIAL_FINAL_DRAIN_TIME_OUT_MS ( 2 * SEC_PER_MIN * MS_PER_SECOND ) ///< Reservoirs 1 & 2 initial drain time out in milliseconds. #define RSRVRS_INITIAL_DRAIN_TIME_OUT_MS ( 2 * SEC_PER_MIN * MS_PER_SECOND ) ///< Reservoirs 1 & 2 initial drain time out in milliseconds. #define DRAIN_WEIGHT_UNCHANGE_TIMEOUT ( 6 * MS_PER_SECOND ) ///< Time period of unchanged weight during draining before timeout. +// Inlet water checks defines +#define MIN_INLET_TEMPERATURE_C 24.0F ///< Minimum water inlet temperature in C. +#define MAX_INLET_TEMPERATURE_C 37.0F ///< Maximum water inlet temperature in C. +#define MAX_INLET_CONDUCTIVITY_US_PER_CM 2000.0F ///< Maximum water inlet conductivity in us/cm +#define MIN_INLET_CONDUCTIVITY_US_PER_CM 100.0F ///< Minimum water inlet conductivity in us/cm +#define MIN_INLET_PRESSURE_PSI 10.0F ///< Minimum water inlet pressure in psi. +#define MAX_INLET_PRESSURE_PSI 80.0F ///< Maximum water inlet pressure in psi. + // Flush drain path state defines -#define FLUSH_DRAIN_WAIT_TIME_MS ( 1 * SEC_PER_MIN * MS_PER_SECOND ) ///< Flush Drain path wait time in milliseconds. +#define FLUSH_DRAIN_WAIT_TIME_MS ( 1 * SEC_PER_MIN * MS_PER_SECOND ) ///< Flush Drain path wait time in milliseconds. #define MAX_ALLOWED_FLUSH_DRAIN_PERIODS 2 ///< Number of flush drain periods to wait for inlet water to come in range -#define MIN_INLET_TEMPERATURE_C 10.0F ///< Minimum water inlet temperature in C. TODO original temperature was 25 C -#define MAX_INLET_CONDUCTIVITY_US_PER_CM 2000.0F ///< Maximum water inlet conductivity in us/cm -#define MIN_INLET_CONDUCTIVITY_US_PER_CM 0.0F ///< Minimum water inlet conductivity in us/cm // Flush circulation path state defines #define RO_PUMP_TARGET_FLUSH_FILL_FLOW_RATE_LPM 0.8F ///< RO pump target flow rate during flush/fill in L/min. #define MAX_RO_PUMP_FLUSH_FILL_PRESSURE_PSI 130 ///< Maximum RO pump pressure during flush/fill states in psi. #define FLUSH_CICRCULATION_WAIT_TIME_MS ( 30 * MS_PER_SECOND ) ///< Flush/rinse circulation path wait time in milliseconds. -// Flush and drain R1 and R2 -#define RSRVRS_FULL_VOL_ML 1700.0F ///< Reservoirs 1 & 2 full volume in mL. TODo original value was 1900 +// Flush and drain R1 and R2 defines #define RSRVRS_FULL_STABLE_TIME_COUNT ( ( 4 * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ) ///< Reservoirs 1 & 2 full stable time in counts. #define RSRVRS_FILL_UP_TIMEOUT_MS ( 5 * SEC_PER_MIN * MS_PER_SECOND ) ///< Reservoirs 1 & 2 full fill up timeout in ms. #define RSRVRS_FLUSH_DRAIN_TIMEOUT_MS ( 2 * SEC_PER_MIN * MS_PER_SECOND ) ///< Reservoirs 1 & 2 drain timeout in ms. +#define RSRVRS_DRAIN_TARGET_VOLUME_ML 200.0F ///< While filling and draining at the same time, look for a volume that indicates draining is working, ml. #define FLUSH_ADDITIONAL_TIME_MS ( 38 * MS_PER_SECOND ) ///< Additional time to flush after reservoir full #define NUM_OF_RINSE_CYCLES 2 ///< Number of rinse cycles -#define CHEM_DISINFECT_FLUSH_TIME_MS ( 12 * SEC_PER_MIN * MS_PER_SECOND ) ///< Chemical disinfect flush time in ms. TODO: get the correct time for the mode +#define CHEM_DISINFECT_FLUSH_TIME_MS ( 12 * SEC_PER_MIN * MS_PER_SECOND ) ///< Chemical disinfect flush time in ms. TODO: get the correct time for the mode or not used? +// Fill reservoirs to full defines +#define RESERVOIR_FULL_VOLUME_CHANGE_LIMIT_ML 5.0F ///< The maximum difference between the short-term and long-term filtered reservoir volumes in ml that determines the tank is full. +#define RESERVOIR_MINIMUM_FULL_VOLUME_ML 1700.0F ///< When filling the reservoir, the volume reading must be at least this value before checking for the volume to level off. +#define RSRVRS_FILL_TO_FULL_STABLE_TASK_INT ( ( 2 * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ) ///< Reservoirs 1 & 2 full stable time in task intervals. + +// Flush disinfectant lines and flush UF defines #define CONC_PUMP_CP1_FLUSH_SPEED_ML_PER_MIN 40.0 ///< Concentrate pump CP1 speed for flush #define CONC_PUMP_CP2_FLUSH_SPEED_ML_PER_MIN 40.8 ///< Concentrate pump CP2 speed for flush #define FLUSH_DISINFECTANT_LINE_WAIT_TIME_MS ( 2.5 * SEC_PER_MIN * MS_PER_SECOND ) ///< Time to flush disinfectant line in milliseconds. @@ -109,29 +116,18 @@ static U32 overallChemDisinfectFlushTimer = 0; ///< Chemical disinfect flush cycle total timer. static U32 stateTimer = 0; ///< Chemical disinfect flush state timer to be used in different states. static U32 stateTrialCounter = 0; ///< Chemical disinfect flush state trial counter to be used for retries in different states. -static BOOL areTempSensorsInRange = FALSE; ///< Chemical disinfect flush temperature sensors in/out range flag. static BOOL haveInletWaterChecksPassed = TRUE; ///< Inlet water pressure, temperature, and pressure in range flag -/// Boolean flag to check whether draining R1 and R2 is at the end of the chemical disinfect flush cycle or in the beginning. So the drain states can be reused. -static BOOL isThisLastDrain = FALSE; +static BOOL isThisLastDrain = FALSE; /// Boolean flag to check whether draining R1 and R2 is at the end of the chemical disinfect flush cycle or in the beginning. static DG_RESERVOIR_STATUS_T rsrvr1Status = NUM_OF_DG_RESERVOIR_STATUS; ///< Reservoir 1 status. static DG_RESERVOIR_STATUS_T rsrvr2Status = NUM_OF_DG_RESERVOIR_STATUS; ///< Reservoir 2 status. -static F32 R1ChemDisinfectFlushVol = 0.0; ///< Reservoir 1 full volume during chemical disinfect flush. -static F32 R2ChemDisinfectFlushVol = 0.0; ///< Reservoir 2 full volume during chemical disinfect flush. -static BOOL rsrvr2Empty = FALSE; -//static BOOL rsrvr1Full = FALSE; -//static BOOL rsrvr1Empty = FALSE; -//static BOOL rsrvr2Full = FALSE; -//static U32 chemDisinfectFlushTimer = 0; ///< Chemical disinfect flush timer. -static U32 waitTimer = 0; -static U32 rinseCycleCounter = 0; ///< Counter for rinse fill and drain cycles -static U32 rsrvrsVolMonitorTimer = 0; ///< Reservoir 1 & 2 volume monitor timers during chemical disinfect flush. -static BOOL areRsrvrsLeaking = FALSE; ///< Reservoir 1 & 2 leak check flag during chemical disinfect flush. +static U32 waitTimer = 0; ///< Wait timer for reservoir flushing. +static U32 drainTimer = 0; ///< Timer for reservoir draining during flush states static U32 dataPublishCounter = 0; ///< Chemical disinfect flush data publish counter. static CANCELLATION_MODE_T cancellationMode = CANCELLATION_MODE_NONE; ///< Cancellation mode. static U32 rsrvrFillStableTimeCounter; ///< Reservoirs fill stable time counter. +static U32 rsrvrFillToFullStableTimeCounter = 0; ///< Task interval counter for determining if reservoir is full static ALARM_ID_T alarmDetectedPendingTrigger; ///< Chemical disinfect flush alarm to raise. static U32 numberOfPostDisinfectRinses; ///< Number of times to rinse the fluid path after chemical disinfect flush. -static BOOL haveDrainParamsBeenInit[ NUM_OF_DG_RESERVOIRS ]; ///< Boolean flag to indicate whether the drain parameters have been reset or not. static DISINFECT_FLUSH_NV_OPS_T disinfectFlushNVOps; ///< Disinfect flush non-volatile memory operations. // ********** private function prototypes ********** @@ -150,8 +146,8 @@ static DG_CHEM_DISINFECT_FLUSH_STATE_T handleChemicalDisinfectFlushCompleteState( void ); static void failChemicalDisinfectFlush( void ); -static DG_RESERVOIR_STATUS_T getRsrvrFillStatus( DG_RESERVOIR_ID_T r, F32 targetVol, U32 timeout ); static DG_RESERVOIR_STATUS_T getRsrvrDrainStatus( DG_RESERVOIR_ID_T r, U32 drainSteadyStateTimeout, U32 timeout ); +static DG_RESERVOIR_STATUS_T getRsrvrFillToFullStatus( DG_RESERVOIR_ID_T r, U32 timeout ); static void publishChemicalDisinfectFlushData( void ); static void monitorModeChemicalDisinfectFlush( void ); static void writeDisinfectFlushDataToNV( void ); @@ -162,11 +158,11 @@ * disinfect flush mode module. * @details Inputs: none * @details Outputs: chemDisinfectFlushState, stateTimer, isThisLastDrain, - * stateTrialCounter, areTempSensorsInRange, rsrvr1Status, rsrvr2Status, + * stateTrialCounter, rsrvr1Status, rsrvr2Status, haveInletWaterChecksPassed, * overallChemDisinfectFlushTimer, * cancellationMode, rsrvrFillStableTimeCounter, prevChemDisinfectFlushState * numberOfPostDisinfectRinses, - * chemDisinfectFlushUIState, haveDrainParamsBeenInit, + * chemDisinfectFlushUIState, * disinfectFlushNVOps * @return none *************************************************************************/ @@ -177,22 +173,16 @@ stateTimer = 0; isThisLastDrain = FALSE; stateTrialCounter = 0; - areTempSensorsInRange = FALSE; haveInletWaterChecksPassed = TRUE; rsrvr1Status = NUM_OF_DG_RESERVOIR_STATUS; rsrvr2Status = NUM_OF_DG_RESERVOIR_STATUS; overallChemDisinfectFlushTimer = 0; cancellationMode = CANCELLATION_MODE_NONE; rsrvrFillStableTimeCounter = 0; - rinseCycleCounter = 0; numberOfPostDisinfectRinses = 0; - R1ChemDisinfectFlushVol = 0.0; - R2ChemDisinfectFlushVol = 0.0; chemDisinfectFlushUIState = CHEM_DISINFECT_FLUSH_UI_STATE_NOT_RUNNING; - haveDrainParamsBeenInit[ DG_RESERVOIR_1 ] = FALSE; - haveDrainParamsBeenInit[ DG_RESERVOIR_2 ] = FALSE; - //disinfectFlushNVOps.hasFlushCompleteDateBeenWrittenToNV = FALSE; - //disinfectFlushNVOps.hasFlushStatusBeenWrittenToNV = FALSE; + disinfectFlushNVOps.hasDisFlushCompleteDateBeenWrittenToNV = FALSE; + disinfectFlushNVOps.hasDisFlushStatusBeenWrittenToNV = FALSE; } /*********************************************************************//** @@ -325,22 +315,19 @@ /*********************************************************************//** * @brief * The handleChemicalDisinfectFlushStartState function handles the chemical - * disinfect flush start state. The state checks the inlet pressure and the - * difference in between TDi and TRo sensors and if they are not in - * range, it transitions to basic cancellation path. Otherwise, it + * disinfect flush start state. The state prepares for the next state and * transitions to the next state. - * @details Inputs: alarm, rsrvrFillStableTimeCounter, rsrvr1Status, - * stateTimer - * @details Outputs: alarm, rsrvrFillStableTimeCounter, rsrvr1Status, + * @details Inputs: none + * @details Outputs: rsrvrFillStableTimeCounter, rsrvr1Status, * stateTimer, chemDisinfectFlushUIState * @return next state of the chemical disinfect flush state machine *************************************************************************/ static DG_CHEM_DISINFECT_FLUSH_STATE_T handleChemicalDisinfectFlushStartState( void ) { DG_CHEM_DISINFECT_FLUSH_STATE_T state = DG_CHEM_DISINFECT_FLUSH_STATE_DRAIN_R1; - // Set the chemical disinfect that is published on the UI - chemDisinfectFlushUIState = CHEM_DISINFECT_FLUSH_UI_STATE_NOT_RUNNING; + // Set the chemical disinfect flush state that is published on the UI + chemDisinfectFlushUIState = CHEM_DISINFECT_FLUSH_UI_STATE_FLUSH_AFTER_DISINFECT; // Start overall chemical disinfect timer overallChemDisinfectFlushTimer = getMSTimerCount(); @@ -355,12 +342,11 @@ setValveState( VPO, VALVE_STATE_FILL_C_TO_NC ); setValveState( VRD1, VALVE_STATE_OPEN ); setDrainPumpTargetRPM( DRAIN_PUMP_TARGET_RPM ); - rsrvrFillStableTimeCounter = 0; - // Assume reservoir 1 is full and drain it - rsrvr1Status = DG_RESERVOIR_ABOVE_TARGET; - stateTimer = getMSTimerCount(); + rsrvr1Status = DG_RESERVOIR_ABOVE_TARGET; + stateTimer = getMSTimerCount(); + return state; } @@ -370,37 +356,31 @@ * disinfect flush drain R1 state. The state drains reservoir 1. If the * transition is finished within the time, it transitions to the next state, * otherwise, it transitions to basic cancellation path. - * @details Inputs: stateTimer, rsrvr1Status, rsrvr2Status, isThisLastDrain + * @details Inputs: stateTimer, rsrvr1Status, rsrvr2Status * @details Outputs: stateTimer, rsrvr1Status, rsrvr2Status, * ChemDisinfectFlushUIState - * @return next state of the chemical disinfect state machine + * @return next state of the chemical disinfect flush state machine *************************************************************************/ static DG_CHEM_DISINFECT_FLUSH_STATE_T handleChemicalDisinfectFlushDrainR1State( void ) { DG_CHEM_DISINFECT_FLUSH_STATE_T state = DG_CHEM_DISINFECT_FLUSH_STATE_DRAIN_R1; - // Set the chemical disinfect that is published on the UI - chemDisinfectFlushUIState = CHEM_DISINFECT_FLUSH_UI_STATE_FLUSH_AFTER_DISINFECT; - if ( DG_RESERVOIR_ABOVE_TARGET == rsrvr1Status ) { rsrvr1Status = getRsrvrDrainStatus( DG_RESERVOIR_1, DRAIN_WEIGHT_UNCHANGE_TIMEOUT, RSRVRS_INITIAL_FINAL_DRAIN_TIME_OUT_MS ); } else if ( DG_RESERVOIR_REACHED_TARGET == rsrvr1Status ) - { - // Assume reservoir 2 is full and drain it - rsrvr2Status = DG_RESERVOIR_ABOVE_TARGET; - - tareLoadCell( LOAD_CELL_RESERVOIR_1_PRIMARY ); - tareLoadCell( LOAD_CELL_RESERVOIR_1_BACKUP ); - - // Done with draining R1 + { // Done with draining R1 + if ( FALSE == isThisLastDrain ) + { + tareLoadCell( LOAD_CELL_RESERVOIR_1_PRIMARY ); + tareLoadCell( LOAD_CELL_RESERVOIR_1_BACKUP ); + } setValveState( VRD1, VALVE_STATE_CLOSED ); setValveState( VRD2, VALVE_STATE_OPEN ); rsrvr2Status = DG_RESERVOIR_ABOVE_TARGET; - state = DG_CHEM_DISINFECT_FLUSH_STATE_DRAIN_R2; - // Start the timer + state = DG_CHEM_DISINFECT_FLUSH_STATE_DRAIN_R2; stateTimer = getMSTimerCount(); } else if ( DG_RESERVOIR_NOT_REACHED_TARGET == rsrvr1Status ) @@ -419,10 +399,8 @@ * transition is finished within the time, it transitions to the next * state, otherwise, it transitions to basic cancellation path. * @details Inputs: stateTimer, rsrvr2Status, isThisLastDrain, - * stateTrialCounter - * @details Outputs: stateTimer, rsrvr2Status, stateTrialCounter, - * chemDisinfectFlushUIState - * @return next state of the chemical disinfect state machine + * @details Outputs: stateTimer, rsrvr2Status, chemDisinfectFlushUIState + * @return next state of the chemical disinfect flush state machine *************************************************************************/ static DG_CHEM_DISINFECT_FLUSH_STATE_T handleChemicalDisinfectFlushDrainR2State( void ) { @@ -443,8 +421,7 @@ { tareLoadCell( LOAD_CELL_RESERVOIR_2_PRIMARY ); tareLoadCell( LOAD_CELL_RESERVOIR_2_BACKUP ); - // ??? make sure load cell check is done in tareLoadCell or add that here? - + // Set valves for next state, flush drain setValveState( VPO, VALVE_STATE_NOFILL_C_TO_NO ); setValveState( VRD2, VALVE_STATE_CLOSED ); @@ -467,34 +444,33 @@ /*********************************************************************//** * @brief * The handleChemicalDisinfectFlushFlushDrainState function handles the chemical - * disinfect flush drain state. The state flushes the drain line for a - * period of time and then measures the temperature and conductivity of + * disinfect flush flush drain state. The state flushes the drain line for a + * period of time and then measures the temperature and conductivity of the * water. If they are not within the range after the specified number of tries, * it transitions to basic cancellation path, otherwise it transitions to the next state. - * @details Inputs: stateTimer, stateTrialCounter, alarm, - * prevChemDisinfectFlushState + * @details Inputs: stateTimer, stateTrialCounter, prevChemDisinfectFlushState * @details Outputs: stateTimer, stateTrialCounter, alarm, * prevChemDisinfectFlushState - * @return next state of the chemical disinfect state machine + * @return next state of the chemical disinfect flush state machine *************************************************************************/ static DG_CHEM_DISINFECT_FLUSH_STATE_T handleChemicalDisinfectFlushFlushDrainState( void ) { DG_CHEM_DISINFECT_FLUSH_STATE_T state = DG_CHEM_DISINFECT_FLUSH_STATE_FLUSH_DRAIN; // TODO: check whether flush has already been completed within some time period, skip this state if it has - + // Check if flush time has elapsed if ( TRUE == didTimeout( stateTimer, FLUSH_DRAIN_WAIT_TIME_MS ) ) { - if (haveInletWaterChecksPassed) - { + if (haveInletWaterChecksPassed) + { // set pumps and valves for next state, flush disinfectant line setValveState( VPD, VALVE_STATE_OPEN_C_TO_NC ); setROPumpTargetFlowRateLPM( RO_PUMP_TARGET_FLUSH_FILL_FLOW_RATE_LPM, MAX_RO_PUMP_FLUSH_FILL_PRESSURE_PSI ); // Set the concentrate pump to run at a constant speed during flushing in reverse setConcentratePumpTargetSpeed( CONCENTRATEPUMPS_CP1_ACID, -1.0 * CONC_PUMP_CP1_FLUSH_SPEED_ML_PER_MIN ); requestConcentratePumpOn( CONCENTRATEPUMPS_CP1_ACID ); - // Turn on the bicarb line with forward direction, to dispense the chemical and mix + // Turn on the bicarb line with forward direction, to flush the line that contains acid from the disinfect setConcentratePumpTargetSpeed( CONCENTRATEPUMPS_CP2_BICARB, CONC_PUMP_CP2_FLUSH_SPEED_ML_PER_MIN ); requestConcentratePumpOn( CONCENTRATEPUMPS_CP2_BICARB ); turnOnUVReactor( INLET_UV_REACTOR ); @@ -504,22 +480,19 @@ state = DG_CHEM_DISINFECT_FLUSH_STATE_FLUSH_DISINFECTANT_LINE; } else - { - // If the number of failures have not exceeded the limit, try again. - stateTrialCounter++; - if ( stateTrialCounter < MAX_ALLOWED_FLUSH_DRAIN_PERIODS ) + { // If the number of failures have not exceeded the limit, try again. + if ( ++stateTrialCounter < MAX_ALLOWED_FLUSH_DRAIN_PERIODS ) { - stateTimer = getMSTimerCount(); + stateTimer = getMSTimerCount(); } - // Couldn't get a good water sample after a couple of trials and the disinfect flush cycle failed + else - { - alarmDetectedPendingTrigger = ALARM_ID_INLET_WATER_TEMPERATURE_IN_LOW_RANGE; //ALARM_ID_DG_NEW_WAT; + { // Couldn't get a good water sample after a couple of trials and the disinfect flush cycle failed + alarmDetectedPendingTrigger = ALARM_ID_INLET_WATER_TEMPERATURE_IN_LOW_RANGE; //TODO: ALARM_ID_DG_NEW_WAT; prevChemDisinfectFlushState = state; state = DG_CHEM_DISINFECT_FLUSH_STATE_CANCEL_BASIC_PATH; } } - } return state; @@ -529,24 +502,19 @@ * @brief * The handleChemicalDisinfectFlushFlushDisinfectantLineState function handles the * chemical disinfect flush flush disinfectant line state. The state flushes the - * disinfectant line for a period of time. After the flush if the temperature - * sensors are not within a certain degrees from each other, the state - * transitions to basic cancellation path, otherwise, it transitions to the + * disinfectant line for a period of time. After the flush it transitions to the * next state. - * @details Inputs: stateTimer, stateTrialCounter, prevChemDisinfectFlushState - * alarm, areTempSensorsInRange, rsrvr1Status, rsrvr2Status - * @details Outputs: stateTimer, stateTrialCounter, prevChemDisinfectFlushState, - * alarm, areTempSensorsInRange, rsrvr1Status, rsrvr2Status - * @return next state of the chemical disinfect state machine + * @details Inputs: stateTimer, prevChemDisinfectFlushState + * @details Outputs: stateTimer + * @return next state of the chemical disinfect flush state machine ************************************************************************/ static DG_CHEM_DISINFECT_FLUSH_STATE_T handleChemicalDisinfectFlushFlushDisinfectantLineState( void ) { DG_CHEM_DISINFECT_FLUSH_STATE_T state = DG_CHEM_DISINFECT_FLUSH_STATE_FLUSH_DISINFECTANT_LINE; - + // Check if the flush disinfectant line time has elapsed if ( TRUE == didTimeout( stateTimer, FLUSH_DISINFECTANT_LINE_WAIT_TIME_MS ) ) { - // set the pumps and valves for the next state, flush UF setValveState( VPO, VALVE_STATE_FILL_C_TO_NC ); setValveState( VRD2, VALVE_STATE_OPEN ); @@ -562,12 +530,12 @@ /*********************************************************************//** * @brief * The handleChemicalDisinfectFlushFlushUFState function handles the - * chemical disinfect flush flush UF state. - * @details Inputs: stateTimer, rsrvr1Status, rsrvr2Status, - * prevChemDisinfectFlushState - * @details Outputs: stateTimer, rsrvr1Status, rsrvr2Status, - * prevChemDisinfectFlushState - * @return next state of the chemical disinfect state machine + * chemical disinfect flush flush UF state. The state flushes the + * UF filter for a period of time. After the flush it transitions to the + * next state. + * @details Inputs: stateTimer, + * @details Outputs: stateTimer, + * @return next state of the chemical disinfect flush state machine *************************************************************************/ static DG_CHEM_DISINFECT_FLUSH_STATE_T handleChemicalDisinfectFlushFlushUFState( void ) { @@ -582,12 +550,13 @@ setValveState( VRD1, VALVE_STATE_OPEN ); setValveState( VRF, VALVE_STATE_R2_C_TO_NO ); setValveState( VRI, VALVE_STATE_R1_C_TO_NO ); - rsrvr1Status = DG_RESERVOIR_ABOVE_TARGET; rsrvr2Status = DG_RESERVOIR_BELOW_TARGET; - rinseCycleCounter = 0; - stateTimer = getMSTimerCount(); - state = DG_CHEM_DISINFECT_FLUSH_STATE_FLUSH_R2_TO_R1_DRAIN_R1; + drainTimer = getMSTimerCount(); + numberOfPostDisinfectRinses = 0; + + stateTimer = getMSTimerCount(); + state = DG_CHEM_DISINFECT_FLUSH_STATE_FLUSH_R2_TO_R1_DRAIN_R1; } return state; @@ -596,120 +565,112 @@ /*********************************************************************//** * @brief - * The handleChemicalDisinfectFlushRinseR2ToR1AndDrainR1State function handles - * the chemical disinfect rinse R2 to R1 and drain R1 state. The state + * The handleChemicalDisinfectFlushFlushR2ToR1DrainR1State function handles + * the chemical disinfect flush R2 to R1 and drain R1 state. The state * rinses reservoir 2 and drains reservoir 1 at the same time. If the drain - * process times out, it transitions to basic cancellation state, and - * if the rinse times out, it transitions to water cancellation state. + * process times out, it transitions to water cancellation state, and + * if the fill times out, it transitions to water cancellation state. * If the drain and rinse are completed within the defined time, it * transitions to the next state. * @details Inputs: rsrvr1Status, rsrvr2Status * @details Outputs: stateTimer, rsrvr1Status, rsrvr2Status, * prevChemDisinfectFlushState, alarmDetectedPendingTrigger - * @return next state of the chemical disinfect state machine + * @return next state of the chemical disinfect flush state machine *************************************************************************/ static DG_CHEM_DISINFECT_FLUSH_STATE_T handleChemicalDisinfectFlushFlushR2ToR1DrainR1State( void ) { DG_CHEM_DISINFECT_FLUSH_STATE_T state = DG_CHEM_DISINFECT_FLUSH_STATE_FLUSH_R2_TO_R1_DRAIN_R1; + // Check whether draining R1 has timed out if ( DG_RESERVOIR_ABOVE_TARGET == rsrvr1Status ) - { - rsrvr1Status = getRsrvrDrainStatus( DG_RESERVOIR_1, DRAIN_WEIGHT_UNCHANGE_TIMEOUT, RSRVRS_FLUSH_DRAIN_TIMEOUT_MS ); - - if ( DG_RESERVOIR_REACHED_TARGET == rsrvr1Status ) + { // Do not use the standard drain status function because we are filling and draining at the same time + if ( getLoadCellSmallFilteredWeight( LOAD_CELL_RESERVOIR_1_PRIMARY ) < RSRVRS_DRAIN_TARGET_VOLUME_ML ) { - // Done with draining R1 - signalDrainPumpHardStop(); - setValveState( VRD1, VALVE_STATE_CLOSED ); + rsrvr1Status = DG_RESERVOIR_REACHED_TARGET; } - else if ( DG_RESERVOIR_NOT_REACHED_TARGET == rsrvr1Status ) + else if ( TRUE == didTimeout( drainTimer, RSRVRS_FLUSH_DRAIN_TIMEOUT_MS ) ) { // reservoir 1 drain timeout prevChemDisinfectFlushState = state; - state = DG_CHEM_DISINFECT_FLUSH_STATE_CANCEL_WATER_PATH; + alarmDetectedPendingTrigger = ALARM_ID_DG_RESERVOIR_DRAIN_TIMEOUT; + state = DG_CHEM_DISINFECT_FLUSH_STATE_CANCEL_WATER_PATH; } } - // Reservoir 2 must be completely full + // Check whether R2 fill has timed out if ( DG_RESERVOIR_BELOW_TARGET == rsrvr2Status ) { - rsrvr2Status = getRsrvrFillStatus( DG_RESERVOIR_2, RSRVRS_FULL_VOL_ML, RSRVRS_FILL_UP_TIMEOUT_MS ); - + rsrvr2Status = getRsrvrFillToFullStatus( DG_RESERVOIR_2, RSRVRS_FILL_UP_TIMEOUT_MS ); if ( DG_RESERVOIR_REACHED_TARGET == rsrvr2Status ) { waitTimer = getMSTimerCount(); } else if ( DG_RESERVOIR_NOT_REACHED_TARGET == rsrvr2Status ) { prevChemDisinfectFlushState = state; - state = DG_CHEM_DISINFECT_FLUSH_STATE_CANCEL_WATER_PATH; + state = DG_CHEM_DISINFECT_FLUSH_STATE_CANCEL_WATER_PATH; } } - if ( ( DG_RESERVOIR_REACHED_TARGET == rsrvr2Status ) && ( DG_RESERVOIR_REACHED_TARGET == rsrvr1Status ) && - ( TRUE == didTimeout( waitTimer, FLUSH_ADDITIONAL_TIME_MS ) ) ) + // Overflow R2 to R1 for an additional period + if ( ( DG_RESERVOIR_REACHED_TARGET == rsrvr2Status ) && ( TRUE == didTimeout( waitTimer, FLUSH_ADDITIONAL_TIME_MS ) ) ) { - // Set the valves to rinse R1 to R2 and drain R2 + // Set the valves to flush R1 to R2 and drain R2 setValveState( VRD2, VALVE_STATE_OPEN ); setValveState( VRD1, VALVE_STATE_CLOSED ); setValveState( VRO, VALVE_STATE_R1_C_TO_NO ); setValveState( VRI, VALVE_STATE_R2_C_TO_NC ); setValveState( VRF, VALVE_STATE_R1_C_TO_NC ); - // Turn on the drain pump to drain R2 - setDrainPumpTargetRPM( DRAIN_PUMP_TARGET_RPM ); - - // Set the reservoir status rsrvr1Status = DG_RESERVOIR_BELOW_TARGET; rsrvr2Status = DG_RESERVOIR_ABOVE_TARGET; + drainTimer = getMSTimerCount(); + stateTimer = getMSTimerCount(); state = DG_CHEM_DISINFECT_FLUSH_STATE_FLUSH_R1_TO_R2_DRAIN_R2; - } + return state; } /*********************************************************************//** * @brief - * The handleChemicalDisinfectFlushRinseR1ToR2AndDrainR2State function handles - * the chemical disinfect flush rinse R1 to R2 and drain R2 state. The state - * rinses reservoir 1 and drains reservoir 2 at the same time. If the drain - * process times out, it transitions to basic cancellation state, and + * The handleChemicalDisinfectFlushFlushR1ToR2DrainR2State function handles + * the chemical disinfect flush flush R1 to R2 and drain R2 state. The state + * fills reservoir 1 and drains reservoir 2 at the same time. If the drain + * process times out, it transitions to water cancellation state, and * if the rinse times out, it transitions to water cancellation state. * If the drain and rinse are completed within the defined time, it * transitions to the next state. - * @details Inputs: rsrvr1Status, rsrvr2Status, rinseCycleCounter + * @details Inputs: rsrvr1Status, rsrvr2Status, numberOfPostDisinfectRinses * @details Outputs: stateTimer, rsrvr1Status, rsrvr2Status, * prevChemDisinfectFlushState, alarmDetectedPendingTrigger, isThisLastDrain * numberOfPostDisinfectRinses - * @return next state of the chemical disinfect state machine + * @return next state of the chemical disinfect flush state machine *************************************************************************/ static DG_CHEM_DISINFECT_FLUSH_STATE_T handleChemicalDisinfectFlushFlushR1ToR2DrainR2State( void ) { DG_CHEM_DISINFECT_FLUSH_STATE_T state = DG_CHEM_DISINFECT_FLUSH_STATE_FLUSH_R1_TO_R2_DRAIN_R2; - + // Check whether draining R2 has timed out if ( DG_RESERVOIR_ABOVE_TARGET == rsrvr2Status ) - { - rsrvr2Status = getRsrvrDrainStatus( DG_RESERVOIR_2, DRAIN_WEIGHT_UNCHANGE_TIMEOUT, RSRVRS_FLUSH_DRAIN_TIMEOUT_MS ); - - if ( DG_RESERVOIR_REACHED_TARGET == rsrvr2Status ) + { // Do not use the standard drain status function because we are filling and draining at the same time + if ( getLoadCellSmallFilteredWeight( LOAD_CELL_RESERVOIR_2_PRIMARY ) < RSRVRS_DRAIN_TARGET_VOLUME_ML ) { - // Done with draining R2 - signalDrainPumpHardStop(); - setValveState( VRD2, VALVE_STATE_CLOSED ); + rsrvr2Status = DG_RESERVOIR_REACHED_TARGET; } - else if ( DG_RESERVOIR_NOT_REACHED_TARGET == rsrvr2Status ) + else if ( TRUE == didTimeout( drainTimer, RSRVRS_FLUSH_DRAIN_TIMEOUT_MS ) ) { - // reservoir 2 drain timeout + // reservoir 2 drain timeout prevChemDisinfectFlushState = state; + alarmDetectedPendingTrigger = ALARM_ID_DG_RESERVOIR_DRAIN_TIMEOUT; state = DG_CHEM_DISINFECT_FLUSH_STATE_CANCEL_WATER_PATH; } } - // Reservoir 1 must be completely full + // Check whether R1 fill has timed out if ( DG_RESERVOIR_BELOW_TARGET == rsrvr1Status ) { - rsrvr1Status = getRsrvrFillStatus( DG_RESERVOIR_1, RSRVRS_FULL_VOL_ML, RSRVRS_FILL_UP_TIMEOUT_MS ); + rsrvr1Status = getRsrvrFillToFullStatus( DG_RESERVOIR_1, RSRVRS_FILL_UP_TIMEOUT_MS ); if ( DG_RESERVOIR_REACHED_TARGET == rsrvr1Status ) { @@ -718,29 +679,24 @@ else if ( DG_RESERVOIR_NOT_REACHED_TARGET == rsrvr1Status ) { prevChemDisinfectFlushState = state; - state = DG_CHEM_DISINFECT_FLUSH_STATE_CANCEL_WATER_PATH; + state = DG_CHEM_DISINFECT_FLUSH_STATE_CANCEL_WATER_PATH; } } - if ( ( DG_RESERVOIR_REACHED_TARGET == rsrvr2Status ) && ( DG_RESERVOIR_REACHED_TARGET == rsrvr1Status ) && - ( TRUE == didTimeout( waitTimer, FLUSH_ADDITIONAL_TIME_MS ) ) ) + // Overflow R2 to R1 for an additional period + if ( ( DG_RESERVOIR_REACHED_TARGET == rsrvr1Status ) && ( TRUE == didTimeout( waitTimer, FLUSH_ADDITIONAL_TIME_MS ) ) ) { - ++rinseCycleCounter; - if ( rinseCycleCounter < NUM_OF_RINSE_CYCLES ) + if ( ++numberOfPostDisinfectRinses < NUM_OF_RINSE_CYCLES ) { // Set the valves to flush R2 to R1 and drain R1 setValveState( VRO, VALVE_STATE_R2_C_TO_NC ); setValveState( VRD1, VALVE_STATE_OPEN ); setValveState( VRD2, VALVE_STATE_CLOSED ); setValveState( VRF, VALVE_STATE_R2_C_TO_NO ); setValveState( VRI, VALVE_STATE_R1_C_TO_NO ); - - // Turn on the drain pump to drain R2 - setDrainPumpTargetRPM( DRAIN_PUMP_TARGET_RPM ); - - // Set the reservoir status rsrvr2Status = DG_RESERVOIR_BELOW_TARGET; rsrvr1Status = DG_RESERVOIR_ABOVE_TARGET; + drainTimer = getMSTimerCount(); stateTimer = getMSTimerCount(); state = DG_CHEM_DISINFECT_FLUSH_STATE_FLUSH_R2_TO_R1_DRAIN_R1; @@ -752,50 +708,47 @@ setValveState( VRF, VALVE_STATE_R2_C_TO_NO ); setValveState( VPD, VALVE_STATE_DRAIN_C_TO_NO ); setValveState( VRI, VALVE_STATE_R1_C_TO_NO ); + setValveState( VPO, VALVE_STATE_FILL_C_TO_NC ); setValveState( VRD1, VALVE_STATE_OPEN ); setValveState( VRD2, VALVE_STATE_CLOSED ); - - // Turn on the drain pump to drain R2 setDrainPumpTargetRPM( DRAIN_PUMP_TARGET_RPM ); - + // Because this is the second reservoir drain in this mode, the drain parameters must be reset + initDrainParameters( DG_RESERVOIR_1 ); + initDrainParameters( DG_RESERVOIR_2 ); + rsrvr2Status = DG_RESERVOIR_ABOVE_TARGET; + rsrvr1Status = DG_RESERVOIR_ABOVE_TARGET; // Turn off CP1 and CP2 and ROP signalROPumpHardStop(); requestConcentratePumpOff( CONCENTRATEPUMPS_CP1_ACID ); requestConcentratePumpOff( CONCENTRATEPUMPS_CP2_BICARB ); - //Turn off UV reactors turnOffUVReactor( INLET_UV_REACTOR ); turnOffUVReactor( OUTLET_UV_REACTOR ); - // Set the reservoir status - rsrvr2Status = DG_RESERVOIR_ABOVE_TARGET; - rsrvr1Status = DG_RESERVOIR_ABOVE_TARGET; - isThisLastDrain = TRUE; + stateTimer = getMSTimerCount(); state = DG_CHEM_DISINFECT_FLUSH_STATE_DRAIN_R1; } } return state; - } /*********************************************************************//** * @brief * The handleChemicalDisinfectFlushCancelModeBasicPathState function handles the - * chemical disinfect cancel mode basic path state. The state sets the state + * chemical disinfect flush cancel mode basic path state. The state sets the state * to complete and raises an alarm. * @details Inputs: none * @details Outputs: cancellationMode, ChemDisinfectFlushUIState - * @return next state of the heat disinfect state machine + * @return next state of the chemical disinfect flush state machine *************************************************************************/ static DG_CHEM_DISINFECT_FLUSH_STATE_T handleChemicalDisinfectFlushCancelModeBasicPathState( void ) { DG_CHEM_DISINFECT_FLUSH_STATE_T state = DG_CHEM_DISINFECT_FLUSH_STATE_CANCEL_BASIC_PATH; - - // Set the chemical disinfect that is published on the UI + // Set the chemical disinfect flush that is published on the UI chemDisinfectFlushUIState = CHEM_DISINFECT_FLUSH_UI_STATE_CANCEL_FLUSH; // Set the cancellation mode @@ -809,17 +762,17 @@ /*********************************************************************//** * @brief * The handleChemicalDisinfectFlushCancelModeWaterPathState function handles the - * chemical disinfect flush cancel mode cold water path state. + * chemical disinfect flush cancel mode water path state. * @details Inputs: rsrvr1Status, rsrvr2Status, cancellationMode, stateTimer * @details Outputs: rsrvr1Status, rsrvr2Status, cancellationMode, stateTimer, * ChemDisinfectFlushUIState - * @return next state of the chemical disinfect state machine + * @return next state of the chemical disinfect flush state machine *************************************************************************/ static DG_CHEM_DISINFECT_FLUSH_STATE_T handleChemicalDisinfectFlushCancelModeWaterPathState( void ) { DG_CHEM_DISINFECT_FLUSH_STATE_T state = DG_CHEM_DISINFECT_FLUSH_STATE_CANCEL_WATER_PATH; - // Set the chemical disinfect that is published on the UI + // Set the chemical disinfect flush state that is published on the UI chemDisinfectFlushUIState = CHEM_DISINFECT_FLUSH_UI_STATE_CANCEL_FLUSH; if ( CANCELLATION_MODE_NONE == cancellationMode ) @@ -883,19 +836,21 @@ /*********************************************************************//** * @brief * The handleChemicalDisinfectFlushCompleteState function handles the chemical - * disinfect complete state. The state stops chemical disinfect and + * disinfect flush complete state. The state stops chemical disinfect flush and * requests transition to mode standby. * @details Inputs: none * @details Outputs: ChemDisinfectFlushUIState - * @return next state of the chemical disinfect state machine + * @return next state of the chemical disinfect flush state machine *************************************************************************/ static DG_CHEM_DISINFECT_FLUSH_STATE_T handleChemicalDisinfectFlushCompleteState( void ) { DG_CHEM_DISINFECT_FLUSH_STATE_T state = DG_CHEM_DISINFECT_FLUSH_STATE_COMPLETE; - // Set the chemical disinfect that is published on the UI + // Set the chemical disinfect flush state that is published on the UI chemDisinfectFlushUIState = CHEM_DISINFECT_FLUSH_UI_STATE_COMPLETE; + writeDisinfectFlushDataToNV(); //TODO: is this needed? + stopChemicalDisinfectFlush(); return state; @@ -916,103 +871,97 @@ /*********************************************************************//** * @brief - * The getRsrvrFillStatus function checks whether the target reservoir - * is full or not. If the fill times out, it sets the state machine to - * complete and exits the chemical disinfect mode. - * @details Inputs: rsrvrFillStableTimeCounter, alarm, stateTimer, chemDisinfectFlushState - * @details Outputs: prevChemDisinfectFlushState + * The getRsrvrDrainStatus function returns the status of draining a + * reservoir. If the drain times out, an alarm is set. + * @details Inputs: stateTimer + * @details Outputs: reservoir drain status, stateTimer, prevChemDisinfectFlushState, alarm * @param r is DG_RESERVOIR_1 or DG_RESERVOIR_2 - * @param targetVol is the target fill volume + * @param drainSteadyStateTimeout which is the time the reservoir's level + * does not change and is steady state + * @param timeout which is the timeout that a reservoir must be drained by + * then + * @return the status of the reservoirs during draining + *************************************************************************/ +static DG_RESERVOIR_STATUS_T getRsrvrDrainStatus( DG_RESERVOIR_ID_T r, U32 drainSteadyStateTimeout, U32 timeout ) +{ + DG_RESERVOIR_STATUS_T status = DG_RESERVOIR_ABOVE_TARGET; + + BOOL isDrainComplete = hasTargetDrainVolumeBeenReached( r, drainSteadyStateTimeout ); + + if ( TRUE == isDrainComplete ) + { + // Set the state timer in case it needs to be used for another timeout check + stateTimer = getMSTimerCount(); + status = DG_RESERVOIR_REACHED_TARGET; + } + else if ( TRUE == didTimeout( stateTimer, timeout ) ) + { + // Failed to drain on time. Update the previous chemical disinfect state + prevChemDisinfectFlushState = chemDisinfectFlushState; + alarmDetectedPendingTrigger = ALARM_ID_DG_RESERVOIR_DRAIN_TIMEOUT; + status = DG_RESERVOIR_NOT_REACHED_TARGET; + } + + return status; +} + +/*********************************************************************//** + * @brief + * The getRsrvrFillToFullStatus function checks whether the target reservoir + * is full or not based on a plateau in the tank readings. + * If the fill times out, it sets an alarm. + * @details Inputs: rsrvrFillToFullStableTimeCounter, stateTimer + * @details Outputs: alarm, reservoir fill status, + * @param r is DG_RESERVOIR_1 or DG_RESERVOIR_2 * @param timeout is the fill up timeout * @return the status of the reservoirs during filling *************************************************************************/ -static DG_RESERVOIR_STATUS_T getRsrvrFillStatus( DG_RESERVOIR_ID_T r, F32 targetVol, U32 timeout ) +static DG_RESERVOIR_STATUS_T getRsrvrFillToFullStatus( DG_RESERVOIR_ID_T r, U32 timeout ) { DG_RESERVOIR_STATUS_T status = DG_RESERVOIR_BELOW_TARGET; - F32 volume = 0.0; + F32 currentVolume = 0.0; + F32 filteredVolume = 0.0; if ( DG_RESERVOIR_1 == r ) { - volume = getLoadCellSmallFilteredWeight( LOAD_CELL_RESERVOIR_1_PRIMARY ); + currentVolume = getLoadCellSmallFilteredWeight( LOAD_CELL_RESERVOIR_1_PRIMARY ); + filteredVolume = getLoadCellLargeFilteredWeight( LOAD_CELL_RESERVOIR_1_PRIMARY ); } else if ( DG_RESERVOIR_2 == r ) { - volume = getLoadCellSmallFilteredWeight( LOAD_CELL_RESERVOIR_2_PRIMARY ); + currentVolume = getLoadCellSmallFilteredWeight( LOAD_CELL_RESERVOIR_2_PRIMARY ); + filteredVolume = getLoadCellLargeFilteredWeight( LOAD_CELL_RESERVOIR_2_PRIMARY ); } else { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_DG_RESERVOIR_SELECTED, r ) } - // Check the volume of the reservoir against the target volume - if ( volume >= targetVol ) + // Check the volume of the reservoir against the previous volume + if ( ( currentVolume > RESERVOIR_MINIMUM_FULL_VOLUME_ML ) && ( fabs( currentVolume - filteredVolume ) < RESERVOIR_FULL_VOLUME_CHANGE_LIMIT_ML ) ) { - if ( ++rsrvrFillStableTimeCounter >= RSRVRS_FULL_STABLE_TIME_COUNT ) + if ( ++rsrvrFillToFullStableTimeCounter >= RSRVRS_FILL_TO_FULL_STABLE_TASK_INT ) { - status = DG_RESERVOIR_REACHED_TARGET; - rsrvrFillStableTimeCounter = 0; + status = DG_RESERVOIR_REACHED_TARGET; + rsrvrFillToFullStableTimeCounter = 0; // Set the state timer in case it needs to be used for another timeout check - stateTimer = getMSTimerCount(); + stateTimer = getMSTimerCount(); } } else if ( TRUE == didTimeout( stateTimer, timeout ) ) { // Failed to fill ontime. Update the previous chemical disinfect state and transition to basic cancellation - prevChemDisinfectFlushState = chemDisinfectFlushState; - alarmDetectedPendingTrigger = ALARM_ID_DG_RESERVOIR_FILL_TIMEOUT; - status = DG_RESERVOIR_NOT_REACHED_TARGET; + prevChemDisinfectFlushState = chemDisinfectFlushState; + alarmDetectedPendingTrigger = ALARM_ID_DG_RESERVOIR_FILL_TIMEOUT; + status = DG_RESERVOIR_NOT_REACHED_TARGET; } - - return status; -} - -/*********************************************************************//** - * @brief - * The getRsrvrDrainStatus function returns the status of draining a - * reservoir. - * @details Inputs: stateTimer, chemDisinfectFlushState - * alarm - * @details Outputs: stateTimer, prevChemDisinfectFlushState, alarm - * @param r is DG_RESERVOIR_1 or DG_RESERVOIR_2 - * @param drainSteadyStateTimeout which is the time the reservoir's level - * does not change and is steady state - * @param timeout which is the timeout that a reservoir must be drained by - * then - * @return the status of the reservoirs during draining - *************************************************************************/ -static DG_RESERVOIR_STATUS_T getRsrvrDrainStatus( DG_RESERVOIR_ID_T r, U32 drainSteadyStateTimeout, U32 timeout ) -{ - DG_RESERVOIR_STATUS_T status = DG_RESERVOIR_ABOVE_TARGET; - - // If the drain parameters of the reservoir is not initialized, initialize them - if ( FALSE == haveDrainParamsBeenInit[ r ] ) + else { - initDrainParameters( r ); - haveDrainParamsBeenInit[ r ] = TRUE; + rsrvrFillToFullStableTimeCounter = 0; } - - BOOL isDrainComplete = hasTargetDrainVolumeBeenReached( r, drainSteadyStateTimeout ); - - if ( TRUE == isDrainComplete ) - { - // Set the state timer in case it needs to be used for another timeout check - stateTimer = getMSTimerCount(); - haveDrainParamsBeenInit[ r ] = FALSE; - status = DG_RESERVOIR_REACHED_TARGET; - } - else if ( TRUE == didTimeout( stateTimer, timeout ) ) - { - // Failed to drain on time. Update the previous chemical disinfect state - prevChemDisinfectFlushState = chemDisinfectFlushState; - haveDrainParamsBeenInit[ r ] = FALSE; - alarmDetectedPendingTrigger = ALARM_ID_DG_RESERVOIR_DRAIN_TIMEOUT; - status = DG_RESERVOIR_NOT_REACHED_TARGET; - } - return status; } - /*********************************************************************//** * @brief * The publishChemicalDisinfectFlushData function publishes chemical disinfect @@ -1021,9 +970,9 @@ * @details Outputs: dataPublishCounter * @return: none *************************************************************************/ - static void publishChemicalDisinfectFlushData( void ) { + // TODO: decide what data to publish if ( ++dataPublishCounter >= CHEM_DISINFECT_FLUSH_DATA_PUB_INTERVAL ) { MODE_CHEMICAL_DISINFECT_FLUSH_DATA_T data; @@ -1032,8 +981,7 @@ data.chemDisinfectFlushState = (U32)chemDisinfectFlushState; data.stateElapsedTime = calcTimeSince( stateTimer ); data.overallElapsedTime = calcTimeSince( overallChemDisinfectFlushTimer ); - data.postDisinfectTargetRinseCount = (U32) NUM_OF_RINSE_CYCLES; - data.postDisinfectCurrentRinseCount = rinseCycleCounter; + data.postDisinfectCurrentRinseCount = numberOfPostDisinfectRinses; data.cancellationMode = (U32)cancellationMode; uiData.chemDisinfectFlushTargetTime = CHEM_DISINFECT_FLUSH_TIME_MS; uiData.chemDisinfectFlushCountdownTime = calcTimeSince( overallChemDisinfectFlushTimer ); @@ -1048,7 +996,6 @@ } } - /*********************************************************************//** * @brief * The monitorModeChemicalDisinfectFlush function monitors the status of the caps and @@ -1061,8 +1008,6 @@ *************************************************************************/ static void monitorModeChemicalDisinfectFlush( void ) { - BOOL hasConductivityFailed = TRUE; - #ifndef _RELEASE_ if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_CAPS_MONITOR ) != SW_CONFIG_ENABLE_VALUE ) #endif @@ -1080,52 +1025,57 @@ alarmDetectedPendingTrigger = ALARM_ID_DG_DIALYSATE_OR_CONC_CAP_NOT_IN_PROPER_POSITION; } } - - // In all states, check inlet temperature, inlet pressure, and inlet conductivity. + + // In some states, check inlet temperature, inlet pressure, and inlet conductivity. + BOOL hasConductivityFailed = TRUE; + BOOL hasInletPressureFailed = TRUE; + BOOL hasInletTemperatureFailed = TRUE; haveInletWaterChecksPassed= TRUE; - hasConductivityFailed = ( ( getConductivityValue( CONDUCTIVITYSENSORS_CPI_SENSOR ) >= MAX_INLET_CONDUCTIVITY_US_PER_CM ) || - ( getConductivityValue( CONDUCTIVITYSENSORS_CPI_SENSOR ) <= MIN_INLET_CONDUCTIVITY_US_PER_CM ) ); + + hasConductivityFailed = ( ( getConductivityValue( CONDUCTIVITYSENSORS_CPI_SENSOR ) > MAX_INLET_CONDUCTIVITY_US_PER_CM ) || + ( getConductivityValue( CONDUCTIVITYSENSORS_CPI_SENSOR ) < MIN_INLET_CONDUCTIVITY_US_PER_CM ) ); + hasInletPressureFailed = ( ( getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_INLET ) < MIN_INLET_PRESSURE_PSI ) || + ( getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_INLET ) > MAX_INLET_PRESSURE_PSI ) ); + hasInletTemperatureFailed = ( ( getTemperatureValue( TEMPSENSORS_INLET_PRIMARY_HEATER ) < MIN_INLET_TEMPERATURE_C ) || + ( getTemperatureValue( TEMPSENSORS_INLET_PRIMARY_HEATER ) > MAX_INLET_TEMPERATURE_C ) ); #ifndef _RELEASE_ - if ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_DISABLE_DISINFECT_CONDUCTIVITY_CHECK ) ) + if ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_DISABLE_WATER_QUALITY_CHECK ) ) { hasConductivityFailed = FALSE; } #endif - if ( getTemperatureValue( TEMPSENSORS_INLET_PRIMARY_HEATER ) < MIN_INLET_TEMPERATURE_C || - hasConductivityFailed || - getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_INLET ) < MIN_INLET_PRESSURE_PSI) - { - // Inlet check failed, alarm unless in the start, drain, or flush drain states - haveInletWaterChecksPassed= FALSE; // set flag for flush drain state - switch( chemDisinfectFlushState ) + if ( hasInletTemperatureFailed || hasConductivityFailed || hasInletPressureFailed ) + { // Inlet check failed, alarm unless in the start, drain, or flush drain states + haveInletWaterChecksPassed= FALSE; // set flag for flush drain state + switch( chemDisinfectFlushState ) { case DG_CHEM_DISINFECT_FLUSH_STATE_START: case DG_CHEM_DISINFECT_FLUSH_STATE_DRAIN_R1: case DG_CHEM_DISINFECT_FLUSH_STATE_DRAIN_R2: case DG_CHEM_DISINFECT_FLUSH_STATE_FLUSH_DRAIN: - break; + break; - case DG_CHEM_DISINFECT_FLUSH_STATE_FLUSH_DISINFECTANT_LINE: - case DG_CHEM_DISINFECT_FLUSH_STATE_FLUSH_UF: - case DG_CHEM_DISINFECT_FLUSH_STATE_FLUSH_R2_TO_R1_DRAIN_R1: - case DG_CHEM_DISINFECT_FLUSH_STATE_FLUSH_R1_TO_R2_DRAIN_R2: + case DG_CHEM_DISINFECT_FLUSH_STATE_FLUSH_DISINFECTANT_LINE: + case DG_CHEM_DISINFECT_FLUSH_STATE_FLUSH_UF: + case DG_CHEM_DISINFECT_FLUSH_STATE_FLUSH_R2_TO_R1_DRAIN_R1: + case DG_CHEM_DISINFECT_FLUSH_STATE_FLUSH_R1_TO_R2_DRAIN_R2: prevChemDisinfectFlushState = chemDisinfectFlushState; - alarmDetectedPendingTrigger = ALARM_ID_INLET_WATER_TEMPERATURE_IN_LOW_RANGE; //ALARM_ID_NEW_WAT; + alarmDetectedPendingTrigger = ALARM_ID_INLET_WATER_TEMPERATURE_IN_LOW_RANGE; //TODO: ALARM_ID_NEW_WAT; chemDisinfectFlushState = DG_CHEM_DISINFECT_FLUSH_STATE_CANCEL_WATER_PATH; - break; + break; } } - } /*********************************************************************//** * @brief - * The writeDisinfectDataToNV function writes the disinfection data to the + * The writeDisinfectDataToNV function writes the disinfect flush data to the * non-volatile memory. - * @details Inputs: disinfectNVOps - * @details Outputs: disinfectNVOps + * @details Inputs: disinfectFlushNVOps + * @details Outputs: disinfectFlushNVOps * @return: none *************************************************************************/ +// TODO: is this necessary? static void writeDisinfectFlushDataToNV( void ) { if ( FALSE == disinfectFlushNVOps.hasDisFlushCompleteDateBeenWrittenToNV )