Index: firmware/App/Modes/ModeFlush.c =================================================================== diff -u -r654c5598765bb862c00a0175bdac95604c6c9b24 -ra89d6b091874136d75a9bfbdbbc1ff00f42467b3 --- firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision 654c5598765bb862c00a0175bdac95604c6c9b24) +++ firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision a89d6b091874136d75a9bfbdbbc1ff00f42467b3) @@ -1,23 +1,25 @@ /************************************************************************** * -* Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. +* Copyright (c) 2019-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 ModeFlush.c +* @file ModeFlush.c * -* @author (last) Quang Nguyen -* @date (last) 01-Sep-2020 +* @author (last) Dara Navaei +* @date (last) 13-Jun-2022 * -* @author (original) Leonardo Baloa -* @date (original) 20-Dec-2019 +* @author (original) Leonardo Baloa +* @date (original) 20-Dec-2019 * ***************************************************************************/ +#include "ConcentratePumps.h" #include "DrainPump.h" #include "Heaters.h" #include "LoadCell.h" +#include "MessageSupport.h" #include "ModeFault.h" #include "ModeFlush.h" #include "OperationModes.h" @@ -39,55 +41,60 @@ // General defines #define FLUSH_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Mode flush data publish interval in counts. -#define RO_PUMP_TARGET_FLOW_RATE_LPM 0.8 ///< RO pump target flow rate during flush/fill in L/min. TODO original flow was 0.8 -#define RO_PUMP_MAX_PRESSURE_PSI 130 ///< Maximum RO pump pressure during flush/fill states in psi. -#define DRAIN_PUMP_TARGET_RPM 2200 ///< Drain pump target RPM during drain. +#define RO_PUMP_TARGET_FLOW_RATE_LPM 0.8F ///< RO pump target flow rate during flush/fill in L/min. +#define RO_PUMP_MAX_PRESSURE_PSI 130 ///< Maximum RO pump pressure during flush/fill states in psi. +#define DRAIN_PUMP_TARGET_RPM 2400 ///< Drain pump target RPM during drain. // Drain R1 & R2 states defines -#define DRAIN_WEIGHT_UNCHANGE_TIMEOUT ( 6 * MS_PER_SECOND ) ///< Time period of unchanged weight during draining before timeout. +#define DRAIN_WEIGHT_UNCHANGE_TIMEOUT ( 6 * MS_PER_SECOND ) ///< Time period of unchanged weight during draining before timeout. // Flush drain path state defines -#define FLUSH_DRAIN_WAIT_TIME_MS ( 1 * 60 * MS_PER_SECOND ) ///< Flush Drain path wait time in milliseconds. TODo original time is 2 minutes +#define FLUSH_DRAIN_WAIT_TIME_MS ( 2 * MS_PER_SECOND ) ///< Flush Drain path wait time in milliseconds. TODo it was 2 minutes // Flush dialysate state defines -#define FLUSH_DIALYSATE_WAIT_TIME_MS ( 0.5 * 60 * MS_PER_SECOND ) ///< Flush dialysate wait time in milliseconds. +#define FLUSH_DIALYSATE_WAIT_TIME_MS ( 0.5F * 60 * MS_PER_SECOND ) ///< Flush dialysate wait time in milliseconds. // Flush concentrate straws state defines -#define FLUSH_CONCENTRATE_STRAWS_TIME_MS ( 0.5 * 60 * MS_PER_SECOND ) ///< Flush concentrate straws wait time in milliseconds. TODO original time is 3 minutes +#define FLUSH_CONCENTRATE_STRAWS_TIME_MS ( 0.5F * 60 * MS_PER_SECOND ) ///< Flush concentrate straws wait time in milliseconds. todo was 3 minutes +#define ACID_PUMP_SPEED_ML_PER_MIN -30.0F ///< Acid pump speed in mL/min. +// The bicarb pump is 2% faster than the acid pump to create a flow from acid to bicarb line during flush +#define BICARB_PUMP_SPEED_ML_PER_MIN 30.6F ///< Bicarb pump speed in mL/min. // Flush and drain R1 and R2 state defines -#define RSRVRS_FULL_VOL_ML 1650.0 ///< Reservoirs 1 & 2 full volume in mL. TODo original value was 1900 -#define RSRVRS_PARTIAL_FILL_VOL_ML 500.0 ///< Reservoirs 1 & 2 partial volume in mL. +#define RSRVRS_FULL_VOL_ML 1800.0F ///< Reservoirs 1 & 2 full volume in mL. TODo original value was 1900 +#define RSRVRS_PARTIAL_FILL_VOL_ML 500.0F ///< Reservoirs 1 & 2 partial volume in mL. #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 * 60 * MS_PER_SECOND ) ///< Reservoirs 1 & 2 full fill up timeout in ms. TODO original value was 5 minutes +#define RSRVRS_FILL_UP_TIMEOUT_MS ( 5 * 60 * MS_PER_SECOND ) ///< Reservoirs 1 & 2 full fill up timeout in ms. #define RSRVRS_PARTIAL_FILL_TIMEOUT_MS ( 2 * 60 * MS_PER_SECOND ) ///< Reservoirs 1 & 2 partial fill up timeout in ms. -#define RSRVRS_DRAIN_TIMEOUT_MS ( 3 * 60 * MS_PER_SECOND ) ///< Reservoirs 1 & 2 drain timeout in ms. TODO original value was 2 minutes -#define FINAL_DRAIN_RO_PUMP_FLOW_LPM 0.6 ///< Final drain RO pump flow rate in L/min. This is used to flush the drain line during drain. +#define RSRVRS_DRAIN_TIMEOUT_MS ( 2 * 60 * MS_PER_SECOND ) ///< Reservoirs 1 & 2 drain timeout in ms. +#define FINAL_DRAIN_RO_PUMP_FLOW_LPM 0.6F ///< Final drain RO pump flow rate in L/min. This is used to flush the drain line during drain. // Flush drain line state defines -#define FLUSH_DRAIN_LINE_VOLUME_L 0.1 ///< Water volume to flush in liters. +#define FLUSH_DRAIN_LINE_VOLUME_L 0.1F ///< Water volume to flush in liters. #define FLUSH_DRAIN_LINE_TIMEOUT_MS ( 1 * 60 * MS_PER_SECOND ) ///< Flush drain lines timeout in milliseconds. // Flush circulation state defines -#define FLUSH_CIRCULATION_WAIT_TIME_MS ( 0.5 * 60 * MS_PER_SECOND ) ///< Flush circulation wait time in milliseconds. +#define FLUSH_CIRCULATION_WAIT_TIME_MS ( 0.5F * 60 * MS_PER_SECOND ) ///< Flush circulation wait time in milliseconds. // Flush with fresh water state defines -#define FLUSH_WITH_FRESH_WATER_WAIT_TIME_MS ( 0.5 * 60 * MS_PER_SECOND ) ///< Flush with fresh water wait time in milliseconds. +#define FLUSH_WITH_FRESH_WATER_WAIT_TIME_MS ( 0.5F * 60 * MS_PER_SECOND ) ///< Flush with fresh water wait time in milliseconds. // ********** private data ********** -static DG_FLUSH_STATE_T flushState = DG_FLUSH_STATE_START; ///< Current active flush state. -static DG_FLUSH_STATE_T prevFlushState = DG_FLUSH_STATE_START; ///< Previous flush state. -static U32 rsrvrFillStableTimeCounter = 0; ///< Reservoirs fill stable time counter. -static U32 overallFlushElapsedTimeStart = 0; ///< Overall flush mode elapsed time start. -static U32 stateTimerStart = 0; ///< State timer start. +static DG_FLUSH_STATE_T flushState; ///< Current active flush state. +static DG_FLUSH_STATE_T prevFlushState; ///< Previous flush state. +static DG_FLUSH_UI_STATE_T flushUIState; ///< Current UI flush state. +static U32 rsrvrFillStableTimeCounter; ///< Reservoirs fill stable time counter. +static U32 overallFlushElapsedTimeStart; ///< Overall flush mode elapsed time start. +static U32 stateTimerStart; ///< State timer start. static ALARM_ID_T alarmDetectedPendingTrigger; ///< Alarm ID that is detected and is pending to be triggered. -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 BOOL isThisInitialDrain = TRUE; ///< Initial drain boolean flag. -static U32 dataPublishCounter = 0; ///< Flush data publish counter. -static BOOL hasWaterCancellationBeenSet = FALSE; ///< Water cancellation set/not set boolean flag. -static F32 flushLinesVolumeL = 0.0; ///< Volume of water pumped by RO pump during flush lines state. +static DG_RESERVOIR_STATUS_T rsrvr1Status; ///< Reservoir 1 status. +static DG_RESERVOIR_STATUS_T rsrvr2Status; ///< Reservoir 2 status. +static BOOL isThisInitialDrain; ///< Initial drain boolean flag. +static U32 dataPublishCounter; ///< Flush data publish counter. +static BOOL hasWaterCancellationBeenSet; ///< Water cancellation set/not set boolean flag. +static F32 flushLinesVolumeL; ///< Volume of water pumped by RO pump during flush lines state. +static BOOL haveDrainParamsBeenInit; ///< Boolean flag to indicate whether the drain parameters have been reset or not. // ********** private function prototypes ********** @@ -110,6 +117,7 @@ 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 void publishFlushData( void ); +static void monitorModeFlush( void ); /*********************************************************************//** * @brief @@ -118,14 +126,15 @@ * @details Outputs: flushState, prevFlushState, rsrvrFillStableTimeCounter, * overallFlushElapsedTime, isThisInitialDrain, dataPublishCounter, * rsrvr1Status, rsrvr2Status, hasWaterCancellationBeenSet, - * flushLinesVolumeL + * flushLinesVolumeL, haveDrainParamsBeenInit, stateTimerStart * @return none *************************************************************************/ void initFlushMode( void ) { // Initialize the variables flushState = DG_FLUSH_STATE_START; prevFlushState = DG_FLUSH_STATE_START; + flushUIState = FLUSH_UI_STATE_NOT_RUNNING; rsrvrFillStableTimeCounter = 0; overallFlushElapsedTimeStart = 0; isThisInitialDrain = TRUE; @@ -134,21 +143,25 @@ rsrvr2Status = NUM_OF_DG_RESERVOIR_STATUS; hasWaterCancellationBeenSet = FALSE; flushLinesVolumeL = 0.0; + haveDrainParamsBeenInit = FALSE; + stateTimerStart = 0; } /*********************************************************************//** * @brief * The transitionToFlushMode function prepares for transition to flush mode. * @details Inputs: none * @details Outputs: Prepares for transition to flush mode - * @return none + * @return initial flush state *************************************************************************/ -void transitionToFlushMode( void ) +U32 transitionToFlushMode( void ) { // Reset all the actuators deenergizeActuators(); initFlushMode(); + + return flushState; } /*********************************************************************//** @@ -160,6 +173,8 @@ *************************************************************************/ U32 execFlushMode( void ) { + monitorModeFlush(); + // Execute current flush state switch ( flushState ) { @@ -286,28 +301,17 @@ { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_START; - // Reset the load cells lowest weight prior to starting the run - resetReservoirsLowestWeight(); - // Start overall flush timer overallFlushElapsedTimeStart = getMSTimerCount(); // Close VPi to prevent wasting water setValveState( VPI, VALVE_STATE_CLOSED ); - - // Request a tare for reservoir 1 - tareReservoir(); - -#ifndef V_2_SYSTEM // Set the actuators to drain R1 setValveState( VRD1, VALVE_STATE_OPEN ); -#else - // Set the actuators to drain R1 - setValveState( VRD, VALVE_STATE_R1_C_TO_NC ); -#endif setDrainPumpTargetRPM( DRAIN_PUMP_TARGET_RPM ); + flushUIState = FLUSH_UI_STATE_DRAIN_DEVICE; stateTimerStart = getMSTimerCount(); rsrvr1Status = DG_RESERVOIR_ABOVE_TARGET; state = DG_FLUSH_STATE_DRAIN_R1; @@ -336,21 +340,16 @@ { if ( TRUE == isThisInitialDrain ) { - // Request a tare for reservoir 2 - tareReservoir(); + // Request a tare for reservoir 1 + tareLoadCell( LOAD_CELL_RESERVOIR_1_PRIMARY ); + tareLoadCell( LOAD_CELL_RESERVOIR_1_BACKUP ); } -#ifndef V_2_SYSTEM // Close reservoir 1 drain setValveState( VRD1, VALVE_STATE_CLOSED ); // Set the actuators to drain R2 // NOTE: Drain pump is already on and VDr is already on drain state setValveState( VRD2, VALVE_STATE_OPEN ); -#else - // Set the actuators to drain R2 - // NOTE: Drain pump is already on and VDr is already on drain state - setValveState( VRD, VALVE_STATE_R2_C_TO_NO ); -#endif stateTimerStart = getMSTimerCount(); rsrvr2Status = DG_RESERVOIR_ABOVE_TARGET; @@ -388,31 +387,32 @@ if ( TRUE == isThisInitialDrain ) { + tareLoadCell( LOAD_CELL_RESERVOIR_2_PRIMARY ); + tareLoadCell( LOAD_CELL_RESERVOIR_2_BACKUP ); + // Set the actuators to flush drain setValveState( VPI, VALVE_STATE_OPEN ); -#ifndef V_2_SYSTEM setValveState( VPD, VALVE_STATE_DRAIN_C_TO_NO ); setValveState( VRD2, VALVE_STATE_CLOSED ); -#else - setValveState( VPD, VALVE_STATE_DRAIN_C_TO_NC ); -#endif state = DG_FLUSH_STATE_FLUSH_DRAIN; } else { // Set the actuators to pull fresh water in to drain the circulation line setValveState( VPI, VALVE_STATE_OPEN ); -#ifndef V_2_SYSTEM setValveState( VPD, VALVE_STATE_OPEN_C_TO_NC ); setValveState( VRD2, VALVE_STATE_CLOSED ); -#else - setValveState( VPD, VALVE_STATE_OPEN_C_TO_NO ); -#endif + setValveState( VPO, VALVE_STATE_NOFILL_C_TO_NO ); setValveState( VRC, VALVE_STATE_DRAIN_C_TO_NO ); setValveState( VDR, VALVE_STATE_DRAIN_C_TO_NO ); - setROPumpTargetFlowRate( FINAL_DRAIN_RO_PUMP_FLOW_LPM, RO_PUMP_MAX_PRESSURE_PSI ); + setROPumpTargetFlowRateLPM( FINAL_DRAIN_RO_PUMP_FLOW_LPM, RO_PUMP_MAX_PRESSURE_PSI ); + // Turn on the UV reactors + turnOnUVReactor( INLET_UV_REACTOR ); + turnOnUVReactor( OUTLET_UV_REACTOR ); + + flushUIState = FLUSH_UI_STATE_FLUSH_RECIRCULATION_PATH; state = DG_FLUSH_STATE_FLUSH_CIRCULATION_DRAIN_LINE; } @@ -440,12 +440,8 @@ if ( TRUE == didTimeout( stateTimerStart, FLUSH_DRAIN_WAIT_TIME_MS ) ) { -#ifndef V_2_SYSTEM setValveState( VPD, VALVE_STATE_OPEN_C_TO_NC ); -#else - setValveState( VPD, VALVE_STATE_OPEN_C_TO_NO ); -#endif - setROPumpTargetFlowRate( RO_PUMP_TARGET_FLOW_RATE_LPM, RO_PUMP_MAX_PRESSURE_PSI ); + setROPumpTargetFlowRateLPM( RO_PUMP_TARGET_FLOW_RATE_LPM, RO_PUMP_MAX_PRESSURE_PSI ); // Turn on the UV reactors turnOnUVReactor( INLET_UV_REACTOR ); @@ -474,7 +470,14 @@ if ( TRUE == didTimeout( stateTimerStart, FLUSH_DIALYSATE_WAIT_TIME_MS ) ) { - // TODO turn on the concentrate pumps + // Turn the pumps on in reverse + setConcentratePumpTargetSpeed( CONCENTRATEPUMPS_CP1_ACID, ACID_PUMP_SPEED_ML_PER_MIN ); + setConcentratePumpTargetSpeed( CONCENTRATEPUMPS_CP2_BICARB, BICARB_PUMP_SPEED_ML_PER_MIN ); + + // Turn on the concentrate pumps + requestConcentratePumpOn( CONCENTRATEPUMPS_CP1_ACID ); + requestConcentratePumpOn( CONCENTRATEPUMPS_CP2_BICARB ); + stateTimerStart = getMSTimerCount(); state = DG_FLUSH_STATE_FLUSH_CONCENTRATE_STRAWS; @@ -498,14 +501,18 @@ if ( TRUE == didTimeout( stateTimerStart, FLUSH_CONCENTRATE_STRAWS_TIME_MS ) ) { - // TODO turn off the concentrate pumps + // Done with flushing the concentrate pumps line + requestConcentratePumpOff( CONCENTRATEPUMPS_CP1_ACID ); + requestConcentratePumpOff( CONCENTRATEPUMPS_CP2_BICARB ); + setValveState( VPO, VALVE_STATE_FILL_C_TO_NC ); setValveState( VRF, VALVE_STATE_R1_C_TO_NC ); setValveState( VRI, VALVE_STATE_R2_C_TO_NC ); stateTimerStart = getMSTimerCount(); rsrvr1Status = DG_RESERVOIR_BELOW_TARGET; rsrvr2Status = DG_RESERVOIR_BELOW_TARGET; + flushUIState = FLUSH_UI_STATE_FLUSH_RESERVOIRS; state = DG_FLUSH_STATE_FLUSH_R1_TO_R2; } @@ -557,11 +564,8 @@ setValveState( VRF, VALVE_STATE_R2_C_TO_NO ); setValveState( VRI, VALVE_STATE_R1_C_TO_NO ); setValveState( VRO, VALVE_STATE_R2_C_TO_NC ); -#ifndef V_2_SYSTEM setValveState( VRD1, VALVE_STATE_OPEN ); -#else - setValveState( VRD, VALVE_STATE_R1_C_TO_NC ); -#endif + setDrainPumpTargetRPM( DRAIN_PUMP_TARGET_RPM ); stateTimerStart = getMSTimerCount(); @@ -611,22 +615,20 @@ { // Done with draining R1 signalDrainPumpHardStop(); -#ifndef V_2_SYSTEM setValveState( VRD1, VALVE_STATE_CLOSED ); -#endif } // Reservoir 1 drain time out else if ( DG_RESERVOIR_NOT_REACHED_TARGET == rsrvr1Status ) { state = DG_FLUSH_STATE_CANCEL_BASIC_PATH; } - // First reservoir 2 must be completely full + // First reservoir 2 must be completely full but if reservoir 1 is filled before reservoir 2 is full, alarm if ( DG_RESERVOIR_BELOW_TARGET == rsrvr2Status ) { rsrvr2Status = getRsrvrFillStatus( DG_RESERVOIR_2, RSRVRS_FULL_VOL_ML, RSRVRS_FILL_UP_TIMEOUT_MS ); - U32 drainPumpRPM = getTargetDrainPumpRPM(); + U32 drainPumpRPM = getDrainPumpTargetRPM(); // Keep monitoring the status of reservoir 1 as the same time F32 volume = getLoadCellSmallFilteredWeight( LOAD_CELL_RESERVOIR_1_PRIMARY ); // Reservoir 1 cannot be filled before reservoir 2 is filled and is overflowing to reservoir 1. If reservoir 1 has already @@ -642,24 +644,27 @@ } } // Once reservoir 2 is full, reservoir 1 must be partially full - else if( DG_RESERVOIR_REACHED_TARGET == rsrvr2Status ) + else if ( DG_RESERVOIR_REACHED_TARGET == rsrvr2Status ) { rsrvr1Status = getRsrvrFillStatus( DG_RESERVOIR_1, RSRVRS_PARTIAL_FILL_VOL_ML, RSRVRS_PARTIAL_FILL_TIMEOUT_MS ); // Once R1 is partially full, transition to the next state if ( DG_RESERVOIR_REACHED_TARGET == rsrvr1Status ) { signalROPumpHardStop(); -#ifndef V_2_SYSTEM setValveState( VRD1, VALVE_STATE_OPEN ); -#else - setValveState( VRD, VALVE_STATE_R1_C_TO_NC ); -#endif + setValveState( VRO, VALVE_STATE_R1_C_TO_NO ); setDrainPumpTargetRPM( DRAIN_PUMP_TARGET_RPM ); + // Turn off the UV reactors prior to transitioning to drain states. + // In the drain states, there is not fluid flowing in the RO section so the reactors are turned off + turnOffUVReactor( INLET_UV_REACTOR ); + turnOffUVReactor( OUTLET_UV_REACTOR ); + stateTimerStart = getMSTimerCount(); isThisInitialDrain = FALSE; rsrvr1Status = DG_RESERVOIR_ABOVE_TARGET; + flushUIState = FLUSH_UI_STATE_DRAIN_RESERVOIRS; state = DG_FLUSH_STATE_DRAIN_R1; } // Check if reservoir 1 fill timed out @@ -669,7 +674,7 @@ } } // Check if reservoir 2 fill time out - else if( DG_RESERVOIR_NOT_REACHED_TARGET == rsrvr2Status ) + else if ( DG_RESERVOIR_NOT_REACHED_TARGET == rsrvr2Status ) { state = DG_FLUSH_STATE_CANCEL_WATER_PATH; } @@ -692,7 +697,7 @@ { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_FLUSH_CIRCULATION_DRAIN_LINE; - F32 waterFlowRate = getMeasuredROFlowRate(); + F32 waterFlowRate = getMeasuredROFlowRateLPM(); F32 waterVolume = ( ( waterFlowRate / SEC_PER_MIN ) / ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ); // Integrate volume of water moved through line @@ -703,15 +708,10 @@ { // Set the actuators to transition to flush circulation // The valves are set to do flush drain and flush circulation -#ifndef V_2_SYSTEM setValveState( VPD, VALVE_STATE_DRAIN_C_TO_NO ); -#else - setValveState( VPD, VALVE_STATE_DRAIN_C_TO_NC ); -#endif setValveState( VRC, VALVE_STATE_RECIRC_C_TO_NC ); setValveState( VDR, VALVE_STATE_RECIRC_C_TO_NC ); - setValveState( VPO, VALVE_STATE_NOFILL_C_TO_NO ); - setROPumpTargetFlowRate( RO_PUMP_TARGET_FLOW_RATE_LPM, RO_PUMP_MAX_PRESSURE_PSI ); + setROPumpTargetFlowRateLPM( RO_PUMP_TARGET_FLOW_RATE_LPM, RO_PUMP_MAX_PRESSURE_PSI ); stateTimerStart = getMSTimerCount(); @@ -742,11 +742,7 @@ if ( TRUE == didTimeout( stateTimerStart, FLUSH_CIRCULATION_WAIT_TIME_MS ) ) { -#ifndef V_2_SYSTEM setValveState( VPD, VALVE_STATE_OPEN_C_TO_NC ); -#else - setValveState( VPD, VALVE_STATE_OPEN_C_TO_NO ); -#endif setValveState( VRC, VALVE_STATE_DRAIN_C_TO_NO ); setValveState( VDR, VALVE_STATE_DRAIN_C_TO_NO ); @@ -774,7 +770,7 @@ if ( TRUE == didTimeout( stateTimerStart, FLUSH_WITH_FRESH_WATER_WAIT_TIME_MS ) ) { deenergizeActuators(); - + flushUIState = FLUSH_UI_STATE_COMPLETE; state = DG_FLUSH_STATE_COMPLETE; } @@ -798,6 +794,8 @@ // deenergize all the actuators failFlushMode(); + flushUIState = FLUSH_UI_STATE_CANCEL_FLUSH; + return state; } @@ -823,12 +821,8 @@ // Set the actuators setValveState( VPI, VALVE_STATE_CLOSED ); -#ifndef V_2_SYSTEM setValveState( VPD, VALVE_STATE_DRAIN_C_TO_NO ); setValveState( VRD2, VALVE_STATE_OPEN ); -#else - setValveState( VPD, VALVE_STATE_DRAIN_C_TO_NC ); -#endif // Set both reservoirs to be considered as full rsrvr1Status = DG_RESERVOIR_ABOVE_TARGET; @@ -841,6 +835,8 @@ // Start the drain pump setDrainPumpTargetRPM( DRAIN_PUMP_TARGET_RPM ); + flushUIState = FLUSH_UI_STATE_CANCEL_FLUSH; + // Start the timer for drain timeout stateTimerStart = getMSTimerCount(); } @@ -853,13 +849,8 @@ if ( DG_RESERVOIR_REACHED_TARGET == rsrvr2Status ) { -#ifndef V_2_SYSTEM setValveState( VRD1, VALVE_STATE_OPEN ); setValveState( VRD2, VALVE_STATE_CLOSED ); -#else - // Set the drain valve to reservoir 1 - setValveState( VRD, VALVE_STATE_R1_C_TO_NC ); -#endif } } else if ( DG_RESERVOIR_NOT_REACHED_TARGET == rsrvr2Status ) @@ -875,9 +866,7 @@ if ( DG_RESERVOIR_REACHED_TARGET == rsrvr1Status ) { -#ifndef V_2_SYSTEM setValveState( VRD2, VALVE_STATE_CLOSED ); -#endif // Done with draining signalDrainPumpHardStop(); @@ -989,20 +978,29 @@ { DG_RESERVOIR_STATUS_T status = DG_RESERVOIR_ABOVE_TARGET; + // If the drain parameters of the reservoir is not initialized, initialize them + if ( FALSE == haveDrainParamsBeenInit ) + { + initDrainParameters( r ); + haveDrainParamsBeenInit = TRUE; + } + BOOL isDrainComplete = hasTargetDrainVolumeBeenReached( r, drainSteadyStateTimeout ); if ( TRUE == isDrainComplete ) { // Set the state timer in case it needs to be used for another timeout check - stateTimerStart = getMSTimerCount(); - status = DG_RESERVOIR_REACHED_TARGET; + stateTimerStart = getMSTimerCount(); + haveDrainParamsBeenInit = FALSE; + status = DG_RESERVOIR_REACHED_TARGET; } else if ( TRUE == didTimeout( stateTimerStart, timeout ) ) { // Failed to drain on time - prevFlushState = flushState; + prevFlushState = flushState; + haveDrainParamsBeenInit = FALSE; alarmDetectedPendingTrigger = ALARM_ID_DG_RESERVOIR_DRAIN_TIMEOUT; - status = DG_RESERVOIR_NOT_REACHED_TARGET; + status = DG_RESERVOIR_NOT_REACHED_TARGET; } return status; @@ -1026,11 +1024,39 @@ data.overallElapsedTime = calcTimeSince( overallFlushElapsedTimeStart ); data.stateElapsedTime = calcTimeSince( stateTimerStart ); data.drainLineVolume = flushLinesVolumeL; + data.flushUIState = (U32)flushUIState; - broadcastFlushData( &data ); + broadcastData( MSG_ID_DG_FLUSH_DATA, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&data, sizeof( MODE_FLUSH_DATA_T ) ); dataPublishCounter = 0; } } +/*********************************************************************//** + * @brief + * The monitorModeFlush function monitors the status of the caps and sets the + * state of the state machine to water cancellation path if the caps are not + * closed during the run. + * @details Inputs: none + * @details Outputs: prevFlushState, flushState, alarmDetectedPendingTrigger + * @return: none + *************************************************************************/ +static void monitorModeFlush( void ) +{ +#ifndef _RELEASE_ + if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_CAPS_MONITOR ) != SW_CONFIG_ENABLE_VALUE ) +#endif + { + if ( ( STATE_OPEN == getSwitchStatus( CONCENTRATE_CAP ) ) || ( STATE_OPEN == getSwitchStatus( DIALYSATE_CAP ) ) ) + { + // Set the variables to fail and go to cancel water path. Set the pending alarm to no alarm so the cancel water path + // will not be raising the alarm at end of the cancel water path. The recoverable alarm is raised here in this function + U32 cap = (U32)( STATE_OPEN == getSwitchStatus( CONCENTRATE_CAP ) ? CONCENTRATE_CAP : DIALYSATE_CAP ); + prevFlushState = flushState; + flushState = DG_FLUSH_STATE_CANCEL_WATER_PATH; + alarmDetectedPendingTrigger = ALARM_ID_DG_DIALYSATE_OR_CONC_CAP_NOT_IN_PROPER_POSITION; + } + } +} + /**@}*/