/************************************************************************** * * Copyright (c) 2024-2024 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 ROInterface.c * * @author (last) Vinayakam Mani * @date (last) 19-Nov-2024 * * @author (original) Vinayakam Mani * @date (original) 19-Nov-2024 * ***************************************************************************/ #include "Messaging.h" #include "MessagePayloads.h" #include "ModeInitPOST.h" #include "ModeStandby.h" #include "OperationModes.h" #include "PersistentAlarm.h" #include "ROInterface.h" #include "SystemCommDD.h" #include "TaskGeneral.h" #include "Timers.h" /** * @addtogroup ROInterface * @{ */ // ********** 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 ); /*********************************************************************//** * @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 ) { // Initialize unit variables fpCurrentOpMode = FP_MODE_INIT; fpSubMode = 0; 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 * @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 getFPOpMode function gets the current latest reported FP operating mode. * @details \b Inputs: fpCurrentOpMode * @details \b Outputs: none * @return Latest reported FP operating mode. *************************************************************************/ FP_OP_MODE_T getFPOpMode( void ) { return fpCurrentOpMode; } /*********************************************************************//** * @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. *************************************************************************/ U32 getFPSubMode( void ) { return fpSubMode; } /*********************************************************************//** * @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 *************************************************************************/ void setFPOpMode( U32 opMode, U32 subMode ) { if ( opMode < NUM_OF_FP_MODES ) { // update FP op mode and sub-mode fpCurrentOpMode = (FP_OP_MODE_T)opMode; fpSubMode = subMode; } else { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_FP_OPERATING_MODE, opMode ); } fpOpModeDataFreshFlag = TRUE; } /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ /**@}*/