/************************************************************************** * * Copyright (c) 2019-2021 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 SampleWater.c * * @author (last) Quang Nguyen * @date (last) 19-Feb-2021 * * @author (original) Quang Nguyen * @date (original) 19-Feb-2021 * ***************************************************************************/ #include "AlarmMgmt.h" #include "DGInterface.h" #include "SampleWater.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" /** * @addtogroup SampleWater * @{ */ // ********** private definitions ********** // ********** private data ********** static BOOL sampleWaterStartRequested; ///< Flag indicates user has requested to start sample water. static BOOL sampleWaterStopRequested; ///< Flag indicates user has requested to stop sample water. static BOOL sampleWaterResultEntered; ///< Flag indicates user has entered sample water result. static SAMPLE_WATER_STATE_T currentSampleWaterState; ///< Current state of sample water sub-mode. static BOOL sampleWaterResult; ///< The result entered by user after testing water sample. // ********** private function prototypes ********** static SAMPLE_WATER_STATE_T handleWaterSampleSetupState( void ); static SAMPLE_WATER_STATE_T handleWaterSampleState( void ); /*********************************************************************//** * @brief * The initSampleWater function initializes the Pre-Treatment SampleWater module. * @details Inputs: none * @details Outputs: SampleWater module initialized. * @return none *************************************************************************/ void initSampleWater( void ) { sampleWaterStartRequested = FALSE; sampleWaterStopRequested = FALSE; sampleWaterResultEntered = FALSE; currentSampleWaterState = SAMPLE_WATER_SETUP_STATE; sampleWaterResult = FALSE; } /*********************************************************************//** * @brief * The transitionToSampleWater function prepares for transition to sample water mode. * @details Inputs: none * @details Outputs: Commanded DG to flush filters and re-initializes SampleWater module * @return none *************************************************************************/ void transitionToSampleWater( void ) { cmdDGSampleWater( SAMPLE_WATER_CMD_FLUSH ); initSampleWater(); } /*********************************************************************//** * @brief * The execSampleWater function executes the Sample Water state machine. * @details Inputs: currentSampleWaterState * @details Outputs: currentSampleWaterState * @return none *************************************************************************/ void execSampleWater( void ) { switch ( currentSampleWaterState ) { case SAMPLE_WATER_SETUP_STATE: currentSampleWaterState = handleWaterSampleSetupState(); break; case SAMPLE_WATER_STATE: currentSampleWaterState = handleWaterSampleState(); break; case SAMPLE_WATER_COMPLETE_STATE: break; default: // TODO: alarm break; } } /*********************************************************************//** * @brief * The getSampleWaterState function returns the current state of sample water sub-mode. * @details Inputs: currentSampleWaterState * @details Outputs: none * @return current sample water state *************************************************************************/ U32 getSampleWaterState( void ) { return (U32)currentSampleWaterState; } /*********************************************************************//** * @brief * The getSampleWaterResult function returns the result from sample water testing. * @details Inputs: sampleWaterResult * @details Outputs: none * @return water sample self-test status *************************************************************************/ SELF_TEST_STATUS_T getSampleWaterResult( void ) { SELF_TEST_STATUS_T result = SELF_TEST_STATUS_FAILED; #ifndef SKIP_SAMPLE_WATER if ( TRUE == sampleWaterResult ) #endif { result = SELF_TEST_STATUS_PASSED; } return result; } /*********************************************************************//** * @brief * The signalSampleWaterUserAction function signals a sample water user action * has been requested. The request is handled and responded to. * @details Inputs: none * @details Outputs: action handled, request responded to * @param action User action requested * @return none *************************************************************************/ void signalSampleWaterUserAction( REQUESTED_SAMPLE_WATER_USER_ACTIONS_T action ) { BOOL accepted = FALSE; REQUEST_REJECT_REASON_CODE_T rejReason = REQUEST_REJECT_REASON_ACTION_DISABLED_IN_CURRENT_STATE; // Reject user action requests if any alarm is currently active. User must clear alarm first. if ( FALSE == isAnyAlarmActive() ) { switch ( action ) { case REQUESTED_USER_ACTION_SAMPLE_WATER_STOP: if ( SAMPLE_WATER_STATE == currentSampleWaterState ) { sampleWaterStopRequested = TRUE; accepted = TRUE; rejReason = REQUEST_REJECT_REASON_NONE; } break; case REQUESTED_USER_ACTION_SAMPLE_WATER_START: if ( SAMPLE_WATER_STATE == currentSampleWaterState ) { sampleWaterStartRequested = TRUE; accepted = TRUE; rejReason = REQUEST_REJECT_REASON_NONE; } break; default: rejReason = REQUEST_REJECT_REASON_INVALID_COMMAND; break; } } else { rejReason = REQUEST_REJECT_REASON_ALARM_IS_ACTIVE; } sendSampleWaterCmdResponse( accepted, (U32)rejReason ); } /*********************************************************************//** * @brief * The setSampleWaterResult function sets the sample water test result * provided by the user. * @details Inputs: none * @details Outputs: action handled, request responded to * @param result sample water test result * @return none *************************************************************************/ void setSampleWaterResult( BOOL result ) { sampleWaterResultEntered = TRUE; sampleWaterResult = result; } /*********************************************************************//** * @brief * The handleWaterSampleSetupState function waits for filter flush period elapsed. * @details Inputs: flushTimerCounter * @details Outputs: none * @return current state *************************************************************************/ static SAMPLE_WATER_STATE_T handleWaterSampleSetupState( void ) { SAMPLE_WATER_STATE_T state = SAMPLE_WATER_SETUP_STATE; DG_OP_MODE_T dgOpMode = getDGOpMode(); U32 dgSubMode = getDGSubMode(); if ( ( DG_MODE_STAN == dgOpMode ) && ( DG_STANDBY_MODE_STATE_FLUSH_FILTER_IDLE == dgSubMode ) ) { state = SAMPLE_WATER_STATE; } return state; } /*********************************************************************//** * @brief * The handleWaterSampleState function processes sample water commands from user. * @details Inputs: sampleWaterFailed, sampleWaterStartRequested, sampleWaterStopRequested * @details Outputs: Processed commands from user * @return current state *************************************************************************/ static SAMPLE_WATER_STATE_T handleWaterSampleState( void ) { SAMPLE_WATER_STATE_T state = SAMPLE_WATER_STATE; if ( TRUE == sampleWaterResultEntered ) { state = SAMPLE_WATER_COMPLETE_STATE; sampleWaterResultEntered = FALSE; } if ( TRUE == sampleWaterStartRequested ) { sampleWaterStartRequested = FALSE; cmdDGSampleWater( SAMPLE_WATER_CMD_START ); } if ( TRUE == sampleWaterStopRequested ) { sampleWaterStopRequested = FALSE; cmdDGSampleWater( SAMPLE_WATER_CMD_STOP ); } return state; } /**@}*/