/************************************************************************** * * Copyright (c) 2025-2025 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 FPInterface.c * * @author (last) Sean Nash * @date (last) 12-Sep-2025 * * @author (original) Vinayakam Mani * @date (original) 08-Aug-2025 * ***************************************************************************/ #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" #include "SystemCommDD.h" #include "TaskGeneral.h" #include "Timers.h" /** * @addtogroup FPInterface * @{ */ // ********** private definitions ********** #define MAX_FP_FLOW_RATE ( 700.0F ) ///< Max FP pump flow rate // ********** private data ********** static F32 fpFlowRate; ///< FP flow rate // ********** private function prototypes ********** static BOOL handlePreGenCmd( BOOL start ); static BOOL handleGenWaterCmd( BOOL start ); /*********************************************************************//** * @brief * The initFPInterface function initializes the FP Interface unit. * @details \b Inputs: none * @details \b Outputs: FP Interface unit initialized. * @return none *************************************************************************/ void initFPInterface( void ) { fpFlowRate = MAX_FP_FLOW_RATE; } /*********************************************************************//** * @brief * The setFPFlowRate function sets the FP pump flow rate to deliver purified * water. * @details \b Inputs: none * @details \b Outputs: fpFlowRate * @return none. *************************************************************************/ void setFPFlowRate( F32 fpFlow ) { fpFlowRate = fpFlow; } /*********************************************************************//** * @brief * The getFPFlowRate function gets the FP flow rate. * @details \b Inputs: Ro flow rate * @details \b Outputs: none * @return latest FP pump flow rate. *************************************************************************/ F32 getFPFlowRate( void ) { return fpFlowRate; } /*********************************************************************//** * @brief * 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. *************************************************************************/ BOOL requestFPGeneratePermeate( RO_CMD_ID cmdID, BOOL start ) { 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 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. *************************************************************************/ static BOOL handlePreGenCmd( BOOL start ) { 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 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. *************************************************************************/ static BOOL handleGenWaterCmd( BOOL start ) { BOOL result = FALSE; if ( TRUE == start ) { if ( TRUE == isFPDefeatured() ) { result = requestGenWaterDefStart(); } else { result = requestGenWaterStart(); } } else { result = requestGenWaterStop(); result = TRUE; } return result; } /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ /**@}*/