Index: firmware/App/Services/FPInterface.c =================================================================== diff -u -r5479efc61e81eb9e133d529afe805b006797a572 -r6f961c6e113a4076ba9d5f97e078a398a8976d7c --- firmware/App/Services/FPInterface.c (.../FPInterface.c) (revision 5479efc61e81eb9e133d529afe805b006797a572) +++ firmware/App/Services/FPInterface.c (.../FPInterface.c) (revision 6f961c6e113a4076ba9d5f97e078a398a8976d7c) @@ -16,9 +16,14 @@ ***************************************************************************/ #include "FPInterface.h" +#include "FPOperationModes.h" #include "Messaging.h" #include "MessagePayloads.h" #include "ModeInitPOST.h" +#include "ModeGenPermeate.h" +#include "ModeGenPermeateDefeatured.h" +#include "ModePreGenPermeate.h" +#include "ModePreGenPermeateDefeatured.h" #include "ModeStandby.h" #include "OperationModes.h" #include "PersistentAlarm.h" @@ -33,19 +38,16 @@ // ********** private definitions ********** -#define FP_DATA_FRESHNESS_TIMEOUT_MS ( 3 * MS_PER_SECOND ) ///< FP data freshness timeout (in ms). #define MAX_FP_FLOW_RATE ( 700.0F ) ///< Max FP pump flow rate // ********** private data ********** -static FP_OP_MODE_T fpCurrentOpMode; ///< Current TD operation mode. -static U32 fpSubMode; ///< Current state (sub-mode) of current TD operation mode. static F32 fpFlowRate; ///< FP flow rate -static BOOL fpOpModeDataFreshFlag = FALSE; ///< Flag to signal/process fresh FP op mode data // ********** private function prototypes ********** -static void checkFPDataFreshness( ALARM_ID_T alarmID, BOOL *fpFreshDataFlag ); +static BOOL handlePreGenCmd( BOOL start ); +static BOOL handleGenWaterCmd( BOOL start ); /*********************************************************************//** * @brief @@ -56,94 +58,11 @@ *************************************************************************/ void initFPInterface( void ) { - // Initialize unit variables - fpCurrentOpMode = FP_MODE_INIT; - fpSubMode = 0; - fpFlowRate = MAX_FP_FLOW_RATE; + fpFlowRate = MAX_FP_FLOW_RATE; } -/**********************************************************************//** - * @brief - * The checkFPDataFreshness function checks the freshness of data coming from - * the FP sub-system. - * @details \b Alarm: Given alarm is triggered if FP is communicating but has - * not published new data for too long. - * @details \b Inputs: FP communicating flag - * @details \b Outputs: none - * @param alarm ID of alarm to check - * @param fpFreshDataFlag Pointer to flag indicating whether new data has been - * received since last time this function has seen it. - * @return None - *************************************************************************/ -static void checkFPDataFreshness( ALARM_ID_T alarmID, BOOL *fpFreshDataFlag ) -{ - if ( TRUE == *fpFreshDataFlag ) - { - *fpFreshDataFlag = FALSE; - checkPersistentAlarm( alarmID, FALSE, 0.0, 0.0 ); - } - else - { // Alarm if not receiving FP fresh data message in timely manner - if ( TRUE == isFPCommunicating() ) - { - checkPersistentAlarm( alarmID, TRUE, 0.0, 0.0 ); - } - else - { - checkPersistentAlarm( alarmID, FALSE, 0.0, 0.0 ); - } - } -} - /*********************************************************************//** * @brief - * The execFPInterfaceMonitor function executes the FP Interface monitoring - * function. Ensures FP is sending fresh data in a timely manner. - * @details \b Inputs: none - * @details \b Outputs: none - * @return none - *************************************************************************/ -void execFPInterfaceMonitor( void ) -{ - -} - -/*********************************************************************//** - * @brief - * The cmdFPStartStop function sends a start/stop command to FP for mode - * transition and generate water with commanded flow rate. - * @details Inputs: none - * @details Outputs: start/stop command along with flow rate if applicable. - * @param startStop To start/stop the FP delivery. - * @return TRUE if msg successfully queued for transmit, FALSE if not - *************************************************************************/ -BOOL cmdFPStartStop( BOOL startStop, RO_CMD_ID cmdMode) -{ - FP_WATER_REQ_PAYLOAD_T fpStartRequest; - BOOL result; - MESSAGE_T msg; - U08 *payloadPtr = msg.payload; - - // Populate FP start message - fpStartRequest.cmdID = (U32)cmdMode; - fpStartRequest.start = startStop; - fpStartRequest.roRate = getFPFlowRate(); - - // Create a message record - blankMessage( &msg ); - msg.hdr.msgID = MSG_ID_DD_FP_START_STOP_CMD_REQUEST; - msg.hdr.payloadLen = sizeof( FP_WATER_REQ_PAYLOAD_T ); - - memcpy( payloadPtr, &fpStartRequest, sizeof( FP_WATER_REQ_PAYLOAD_T ) ); - - // Serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer - result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_DD_2_RO, ACK_REQUIRED ); - - return result; -} - -/*********************************************************************//** - * @brief * The setFPFlowRate function sets the FP pump flow rate to deliver purified * water. * @details \b Inputs: none @@ -169,53 +88,110 @@ /*********************************************************************//** * @brief - * The getFPOpMode function gets the current latest reported FP operating mode. - * @details \b Inputs: fpCurrentOpMode - * @details \b Outputs: none - * @return Latest reported FP operating mode. + * The requestFPGeneratePermeate function handles a FP permeate + * request from DD. + * @details Inputs: none + * @details Outputs: message handled + * @param cmdID the ID of the command + * @param start the TRUE FALSE bool to determine start or stop + * @return TRUE if message is sucessfully parsed, FALSE if not. *************************************************************************/ -FP_OP_MODE_T getFPOpMode( void ) +BOOL requestFPGeneratePermeate( RO_CMD_ID cmdID, BOOL start ) { - return fpCurrentOpMode; + BOOL result = FALSE; + F32 flow = getFPFlowRate(); + + switch ( cmdID ) + { + case RO_PRE_GEN: + result = handlePreGenCmd( start ); + break; + case RO_GEN_WATER: + result = handleGenWaterCmd( start ); + break; + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_FP_SOFTWARE_FAULT, FP_FAULT_ID_FP_INVALID_FP_CMD, cmdID ) + break; + } + + return result; } /*********************************************************************//** * @brief - * The getFPSubMode function gets the latest reported FP operating sub-mode. - * @details \b Inputs: fpSubMode - * @details \b Outputs: none - * @return Latest reported FP operating sub-mode. + * The handlePreGenCmd function handles a FP pre generate water + * request from DD and updates permeate flow rate. + * @details Inputs: none + * @details Outputs: message handled + * @param start the TRUE FALSE bool to determine start or stop + * @return TRUE if message is sucessfully parsed, FALSE if not. *************************************************************************/ -U32 getFPSubMode( void ) +static BOOL handlePreGenCmd( BOOL start ) { - return fpSubMode; + BOOL result = FALSE; + FP_OP_MODE_T fpMode = getCurrentFPOperationMode(); + + if ( ( FP_MODE_STAN == fpMode ) && ( TRUE == start ) ) + { + if ( TRUE == isFPDefeatured() ) + { + result = requestPreGenDefStart(); + } + else + { + result = requestPreGenStart(); + } + } + else if ( FP_MODE_PGEN == fpMode ) + { + if ( FALSE == start ) + { + result = requestPreGenStop(); + } + else + { + result = TRUE; + } + } + else if ( FP_MODE_DPGP == fpMode ) + { + result = requestPreGenDefStop(); + } + + return result; } /*********************************************************************//** * @brief - * The setFPOpMode function sets the latest FP operating mode reported by - * the FP (called by FP published message handler). - * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT if reported FP mode is invalid. - * @details \b Inputs: none - * @details \b Outputs: fpCurrentOpMode, fpSubMode, fpOpModeDataFreshFlag - * @param opMode The operating mode reported by FP - * @param subMode The sub-mode of operating mode reported by FP - * @return none + * The handleGenWaterCmd function handles a generate water + * request from DD and updates permeate flow rate. + * @details Inputs: none + * @details Outputs: message handled + * @param start the TRUE FALSE bool to determine start or stop + * @return TRUE if message is sucessfully parsed, FALSE if not. *************************************************************************/ -void setFPOpMode( U32 opMode, U32 subMode ) +static BOOL handleGenWaterCmd( BOOL start ) { - if ( opMode < NUM_OF_FP_MODES ) + BOOL result = FALSE; + + if ( TRUE == start ) { - // update FP op mode and sub-mode - fpCurrentOpMode = (FP_OP_MODE_T)opMode; - fpSubMode = subMode; + if ( TRUE == isFPDefeatured() ) + { + result = requestGenWaterDefStart(); + } + else + { + result = requestGenWaterStart(); + } } else { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_FP_OPERATING_MODE, opMode ); + result = requestGenWaterStop(); + result = TRUE; } - fpOpModeDataFreshFlag = TRUE; + return result; }