Index: firmware/App/Modes/ModeGenIdle.c =================================================================== diff -u -rc4f3105da2ed8a7c40950588b54b79067185a3ad -re5713fcc4511a625434a4748f7dded3d237acdf8 --- firmware/App/Modes/ModeGenIdle.c (.../ModeGenIdle.c) (revision c4f3105da2ed8a7c40950588b54b79067185a3ad) +++ firmware/App/Modes/ModeGenIdle.c (.../ModeGenIdle.c) (revision e5713fcc4511a625434a4748f7dded3d237acdf8) @@ -8,8 +8,8 @@ * * @file ModeGenIdle.c * -* @author (last) Dara Navaei -* @date (last) 11-May-2023 +* @author (last) Michael Garthwaite +* @date (last) 16-May-2023 * * @author (original) Quang Nguyen * @date (original) 06-Aug-2021 @@ -46,8 +46,7 @@ // ********** private definitions ********** #define TARGET_RO_PRESSURE_PSI 130 ///< Target pressure for RO pump. -#define TARGET_RO_FLOW_RATE_L 0.4F ///< Target flow rate for RO pump. -#define BAD_FLUSH_FILL_TARGET_VOLUME_ML 1000 ///< Target fill volume in the bad flush fill state. +#define TARGET_RO_FLOW_RATE_L 0.8F ///< Target flow rate for RO pump. #define HD_LOST_COMM_TIMEOUT_MS (5 * SEC_PER_MIN * MS_PER_SECOND ) ///< The time of HD lost comm before DG transition back to standby. #define BAD_FILL_SUBSTATES_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the bad fill sub-states is published on the CAN bus. #define DATA_PUBLISH_COUNTER_START_COUNT 61 ///< Data publish counter start count. @@ -60,7 +59,6 @@ // several times to drain and fill and handle a bad fill. static DG_GEN_IDLE_MODE_BAD_FILL_STATE_T badFillState = DG_HANDLE_BAD_FILL_STATE_START; ///< Initialize bad fill sub-state. static U32 hdLostCommStartTime_ms; ///< Lost communication with HD start time in ms. -static U32 targetFillVolumeML; ///< Save the target fill volume before calling startFillCmd(). static BOOL handleBadFillFlag; ///< Internal signal flag to handle bad fill. static OVERRIDE_U32_T genIdleDataPublicationInterval = { BAD_FILL_SUBSTATES_PUB_INTERVAL, BAD_FILL_SUBSTATES_PUB_INTERVAL, @@ -104,7 +102,7 @@ { // Re-initialize each time we transition to generation idle mode initGenIdleMode(); - + setCurrentSubState( NO_SUB_STATE ); // Set initial actuator states setValveState( VSP, VALVE_STATE_CLOSED ); setValveState( VPI, VALVE_STATE_OPEN ); @@ -157,6 +155,19 @@ /*********************************************************************//** * @brief + * The getCurrentGenIdleBadFillState function returns the current state of the + * generation idle mode bad fill. + * @details Inputs: badFillState + * @details Outputs: none + * @return the current state of generation idle mode bad fill + *************************************************************************/ +DG_GEN_IDLE_MODE_BAD_FILL_STATE_T getCurrentGenIdleBadFillState( void ) +{ + return badFillState; +} + +/*********************************************************************//** + * @brief * The requestDGStop function handles an HD request to stop (return to standby mode). * @details Inputs: none * @details Outputs: DG standby mode requested @@ -182,7 +193,7 @@ void setBadAvgConductivityDetectedFlag( BOOL badAvgConducitivyflag ) { handleBadFillFlag = badAvgConducitivyflag; - badFillState = DG_HANDLE_BAD_FILL_STATE_START; // Reset bad fill state too so we start at beginning + badFillState = DG_HANDLE_BAD_FILL_STATE_START; // Reset bad fill state too so we start at beginning } /*********************************************************************//** @@ -289,6 +300,7 @@ static DG_GEN_IDLE_MODE_STATE_T handleBadFillState( void ) { DG_GEN_IDLE_MODE_STATE_T result = DG_GEN_IDLE_MODE_STATE_HANDLE_BAD_FILL; + U32 priorSubState = badFillState; // Execute current bad fill state switch ( badFillState ) @@ -319,6 +331,10 @@ break; } + if ( priorSubState != badFillState ) + { + setCurrentSubState( badFillState ); + } return result; } @@ -355,13 +371,13 @@ // Check if the alarm has been cleared by the user and if yes, continue with the fill if ( FALSE == isAlarmActive( ALARM_ID_DG_FILL_CONDUCTIVITY_OUT_OF_RANGE ) ) { - // Save the HD target fill volume before command 1000 mL fill volume - targetFillVolumeML = getTargetFillVolumeML(); + state = DG_HANDLE_BAD_FILL_STATE_FLUSH_FILL; - state = DG_HANDLE_BAD_FILL_STATE_FLUSH_FILL; - - // Start the flush fill - startFillCmd( BAD_FLUSH_FILL_TARGET_VOLUME_ML, getTargetFillFlowRateLPM() ); + // Start the flush fill. + // NOTE: the actual target fill from HD is sent here but at this stage the fill target is 1000 mL. + // The other functions that check against the fill target know to check for 1000 mL. This is to make sure + // the actual fill target from HD is not overridden in case multiple bad fills occurred back to back. + startFillCmd( getTargetFillVolumeML(), getTargetFillFlowRateLPM() ); } return state; @@ -397,7 +413,7 @@ DG_GEN_IDLE_MODE_BAD_FILL_STATE_T state = DG_HANDLE_BAD_FILL_STATE_REFILL; // Refill to the saved target fill volume (~1500 mL) - startFillCmd( targetFillVolumeML, getTargetFillFlowRateLPM() ); + startFillCmd( getTargetFillVolumeML(), getTargetFillFlowRateLPM() ); return state; } @@ -444,7 +460,7 @@ data.badFillSignal = (U32)handleBadFillFlag; data.badFillState = (U32)badFillState; data.genIdleState = (U32)getCurrentGenIdleState(); - data.targetFillVolumemL = targetFillVolumeML; + data.targetFillVolumemL = getTargetFillVolumeML(); broadcastData( MSG_ID_DG_GEN_IDLE_DATA, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&data, sizeof( DG_GEN_IDLE_DATA_T ) );