Index: firmware/App/Modes/ModeStandby.c =================================================================== diff -u -rf43eb1e9e0803776ec7420b16e1db8760b020bd9 -rc48a99d2d1c852adcc986253b6c420a90dab7bfe --- firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision f43eb1e9e0803776ec7420b16e1db8760b020bd9) +++ firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision c48a99d2d1c852adcc986253b6c420a90dab7bfe) @@ -14,9 +14,11 @@ * **************************************************************************/ +#include "CPLD.h" #include "OperationModes.h" +#include "SystemComm.h" +#include "Timers.h" #include "ModeStandby.h" -#include "CPLD.h" /** * @addtogroup StandbyMode @@ -25,57 +27,67 @@ // ********** private definitions ********** +#define WATER_SAMPLE_TIME_MS ( 10 * MS_PER_SECOND ) ///< Duration of water sample state (in ms). + /// Enumeration of standby mode states. typedef enum Standby_Mode_States { STANDBY_MODE_STATE_START = 0, ///< Start standby mode state. STANDBY_MODE_STATE_IDLE, ///< Idle standby mode state. + STANDBY_MODE_STATE_SAMPLE_WATER, ///< Sample water standby mode state. NUM_OF_STANDBY_MODE_STATES ///< Number of standby mode states. } STANDBY_MODE_STATE_T; // ********** private data ********** static STANDBY_MODE_STATE_T standbyState = STANDBY_MODE_STATE_START; ///< Currently active standby state. +static BOOL pendingSampleWaterRequest = FALSE; ///< Flag indicating HD has requested a water sample. +static BOOL pendingStartDGRequest = FALSE; ///< Flag indicating HD has requested DG start (go to re-circulate mode). +static U32 waterSampleStartTime = 0; ///< Time stamp for start of water sample state. // ********** private function prototypes ********** -STANDBY_MODE_STATE_T handleStandbyIdleState( void ); +static STANDBY_MODE_STATE_T handleStandbyIdleState( void ); +static STANDBY_MODE_STATE_T handleStandbySampleWaterState( void ); /*********************************************************************//** - * @brief initStandbyMode + * @brief * The initStandbyMode function initializes the Standby Mode module. * @details * Inputs : none * Outputs : Standby Mode module initialized. - * @param none * @return none *************************************************************************/ void initStandbyMode( void ) { + standbyState = STANDBY_MODE_STATE_START; + pendingSampleWaterRequest = FALSE; + pendingStartDGRequest = FALSE; + waterSampleStartTime = 0; } /*********************************************************************//** - * @brief transitionToStandbyMode + * @brief * The transitionToStandbyMode function prepares for transition to standby mode. * @details * Inputs : none * Outputs : - * @param none * @return none *************************************************************************/ void transitionToStandbyMode( void ) { // reset to start state each time we transition to standby mode standbyState = STANDBY_MODE_STATE_START; + + // TODO - set initial actuator states } /*********************************************************************//** - * @brief execStandbyMode + * @brief * The execStandbyMode function executes the Standby Mode state machine. * @details * Inputs : none * Outputs : - * @param none * @return none *************************************************************************/ void execStandbyMode( void ) @@ -91,6 +103,10 @@ standbyState = handleStandbyIdleState(); break; + case STANDBY_MODE_STATE_SAMPLE_WATER: + standbyState = handleStandbySampleWaterState(); + break; + default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, 0, standbyState ) // TODO - add s/w fault enum to 1st data param standbyState = STANDBY_MODE_STATE_START; @@ -103,24 +119,99 @@ * The handleStandbyIdleState function executes the Idle state of the \n * Standby Mode state machine. * @details + * Inputs : pendingSampleWaterRequest, pendingStartDGRequest + * Outputs : possibly op mode + * @return the next state + *************************************************************************/ +static STANDBY_MODE_STATE_T handleStandbyIdleState( void ) +{ + STANDBY_MODE_STATE_T result = STANDBY_MODE_STATE_IDLE; + + // go to standby solo mode if HD is turned off or stops communicating. + if ( FALSE == isHDCommunicating() ) + { // TODO if HD comm loss, should we wait an hour or so before going to solo standby? + requestNewOperationMode( MODE_SOLO ); + } + // if HD requests water sample, go to water sample state + else if ( TRUE == pendingSampleWaterRequest ) + { + pendingSampleWaterRequest = FALSE; + waterSampleStartTime = getMSTimerCount(); + // TODO - open VPi and VSP valves + result = STANDBY_MODE_STATE_SAMPLE_WATER; + } + else if ( TRUE == pendingStartDGRequest ) + { + pendingStartDGRequest = FALSE; + requestNewOperationMode( MODE_CIRC ); + } + + return result; +} + +/*********************************************************************//** + * @brief + * The handleStandbySampleWaterState function executes the sample water state \n + * of the Standby Mode state machine. + * @details * Inputs : none * Outputs : - * @param none * @return the next state *************************************************************************/ -STANDBY_MODE_STATE_T handleStandbyIdleState( void ) +static STANDBY_MODE_STATE_T handleStandbySampleWaterState( void ) { - STANDBY_MODE_STATE_T result = STANDBY_MODE_STATE_IDLE; + STANDBY_MODE_STATE_T result = STANDBY_MODE_STATE_SAMPLE_WATER; - // go to standby or standby solo mode depending on whether HD is connected -// if ( FALSE == isHDCommunicating() ) // TODO - handle switching between standby and standby-solo modes -// { -// requestNewOperationMode( MODE_SOLO ); -// } + // VPi and VSP valves open for 10 seconds, then close and return to idle state + if ( TRUE == didTimeout( waterSampleStartTime, WATER_SAMPLE_TIME_MS ) ) + { + // TODO - close VPi and VSP valves. + result = STANDBY_MODE_STATE_IDLE; + } - // TODO - what is DG supposed to be doing while in standby mode? + return result; +} +/*********************************************************************//** + * @brief + * The requestWaterSample function handles an HD request to sample water. + * @details + * Inputs : standbyState + * Outputs : pendingSampleWaterRequest + * @return TRUE if request accepted, FALSE if not. + *************************************************************************/ +BOOL requestWaterSample( void ) +{ + BOOL result = FALSE; + + if ( STANDBY_MODE_STATE_IDLE == standbyState ) + { + result = TRUE; + pendingSampleWaterRequest = TRUE; + } + return result; } +/*********************************************************************//** + * @brief + * The requestDGStart function handles an HD request to start (go to re-circulate mode). + * @details + * Inputs : standbyState + * Outputs : pendingSampleWaterRequest + * @return TRUE if request accepted, FALSE if not. + *************************************************************************/ +BOOL requestDGStart( void ) +{ + BOOL result = FALSE; + + if ( STANDBY_MODE_STATE_IDLE == standbyState ) + { + result = TRUE; + pendingStartDGRequest = TRUE; + } + + return result; +} + /**@}*/