/************************************************************************** * * 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 RO_DATA_FRESHNESS_TIMEOUT_MS ( 3 * MS_PER_SECOND ) ///< RO data freshness timeout (in ms). #define MAX_RO_FLOW_RATE ( 700.0F ) ///< Max RO pump flow rate // ********** private data ********** static RO_OP_MODE_T roCurrentOpMode; ///< Current TD operation mode. static U32 roSubMode; ///< Current state (sub-mode) of current TD operation mode. static F32 roFlowRate; ///< RO flow rate static BOOL roOpModeDataFreshFlag = FALSE; ///< Flag to signal/process fresh RO op mode data // ********** private function prototypes ********** static void checkRODataFreshness( ALARM_ID_T alarmID, BOOL *roFreshDataFlag ); /*********************************************************************//** * @brief * The initROInterface function initializes the RO Interface unit. * @details \b Inputs: none * @details \b Outputs: RO Interface unit initialized. * @return none *************************************************************************/ void initROInterface( void ) { // Initialize unit variables roCurrentOpMode = RO_MODE_INIT; roSubMode = 0; roFlowRate = MAX_RO_FLOW_RATE; } /**********************************************************************//** * @brief * The checkRODataFreshness function checks the freshness of data coming from * the RO sub-system. * @details \b Alarm: Given alarm is triggered if RO is communicating but has * not published new data for too long. * @details \b Inputs: RO communicating flag * @details \b Outputs: none * @param alarm ID of alarm to check * @param roFreshDataFlag Pointer to flag indicating whether new data has been * received since last time this function has seen it. * @return None *************************************************************************/ static void checkRODataFreshness( ALARM_ID_T alarmID, BOOL *roFreshDataFlag ) { if ( TRUE == *roFreshDataFlag ) { *roFreshDataFlag = FALSE; checkPersistentAlarm( alarmID, FALSE, 0.0, 0.0 ); } else { // Alarm if not receiving RO fresh data message in timely manner if ( TRUE == isROCommunicating() ) { checkPersistentAlarm( alarmID, TRUE, 0.0, 0.0 ); } else { checkPersistentAlarm( alarmID, FALSE, 0.0, 0.0 ); } } } /*********************************************************************//** * @brief * The execROInterfaceMonitor function executes the RO Interface monitoring * function. Ensures RO is sending fresh data in a timely manner. * @details \b Inputs: none * @details \b Outputs: none * @return none *************************************************************************/ void execROInterfaceMonitor( void ) { } /*********************************************************************//** * @brief * The cmdROStartStop function sends a start/stop command to RO to deliver * purified water and required flow rate. * @details Inputs: none * @details Outputs: start/stop command along with flow rate if applicable. * @param startStop To start/stop the RO delivery. * @return TRUE if msg successfully queued for transmit, FALSE if not *************************************************************************/ BOOL cmdROStartStop( BOOL startStop) { RO_WATER_REQ_PAYLOAD_T roStartRequest; BOOL result; MESSAGE_T msg; U08 *payloadPtr = msg.payload; // Populate RO start message roStartRequest.start = startStop; roStartRequest.roRate = getROFlowRate(); // Create a message record blankMessage( &msg ); msg.hdr.msgID = MSG_ID_DD_RO_START_STOP_CMD_REQUEST; msg.hdr.payloadLen = sizeof( RO_WATER_REQ_PAYLOAD_T ); memcpy( payloadPtr, &roStartRequest, sizeof( RO_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 setROFlowRate function sets the RO pump flow rate to deliver purified * water. * @details \b Inputs: none * @details \b Outputs: roFlowRate * @return none. *************************************************************************/ void setROFlowRate( F32 roFlow ) { roFlowRate = roFlow; } /*********************************************************************//** * @brief * The getROFlowRate function gets the RO flow rate. * @details \b Inputs: Ro flow rate * @details \b Outputs: none * @return latest RO pump flow rate. *************************************************************************/ F32 getROFlowRate( void ) { return roFlowRate; } /*********************************************************************//** * @brief * The getROOpMode function gets the current latest reported RO operating mode. * @details \b Inputs: roCurrentOpMode * @details \b Outputs: none * @return Latest reported RO operating mode. *************************************************************************/ RO_OP_MODE_T getROOpMode( void ) { return roCurrentOpMode; } /*********************************************************************//** * @brief * The getROSubMode function gets the latest reported RO operating sub-mode. * @details \b Inputs: roSubMode * @details \b Outputs: none * @return Latest reported RO operating sub-mode. *************************************************************************/ U32 getROSubMode( void ) { return roSubMode; } /*********************************************************************//** * @brief * The setROOpMode function sets the latest RO operating mode reported by * the RO (called by RO published message handler). * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT if reported RO mode is invalid. * @details \b Inputs: none * @details \b Outputs: roCurrentOpMode, roSubMode, roOpModeDataFreshFlag * @param opMode The operating mode reported by RO * @param subMode The sub-mode of operating mode reported by RO * @return none *************************************************************************/ void setROOpMode( U32 opMode, U32 subMode ) { if ( opMode < NUM_OF_RO_MODES ) { // update RO op mode and sub-mode roCurrentOpMode = (RO_OP_MODE_T)opMode; roSubMode = subMode; } else { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_RO_OPERATING_MODE, opMode ); } roOpModeDataFreshFlag = TRUE; } /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ /**@}*/