/************************************************************************** * * 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 TDInterface.c * * @author (last) Vinayakam Mani * @date (last) 28-Oct-2024 * * @author (original) Vinayakam Mani * @date (original) 28-Oct-2024 * ***************************************************************************/ #include "TDInterface.h" #include "Messaging.h" #include "ModeInitPOST.h" #include "OperationModes.h" #include "PersistentAlarm.h" #include "SystemCommDD.h" #include "TaskGeneral.h" #include "Timers.h" /** * @addtogroup TDInterface * @{ */ // ********** private definitions ********** #define TD_DATA_FRESHNESS_TIMEOUT_MS ( 3 * MS_PER_SECOND ) ///< TD data freshness timeout (in ms). #define TD_MAX_DIALYSIS_FLOW_RATE ( 600.0F ) ///< TD Max dialysis flow rate // ********** private data ********** // TD status static TD_OP_MODE_T tdCurrentOpMode; ///< Current TD operation mode. static U32 tdSubMode; ///< Current state (sub-mode) of current TD operation mode. static F32 tdDialysisFlowrate; ///< TD dialysis flow rate static F32 tdUFRate; ///< TD ultrafilteration rate static F32 tdTargetDialysateTemp; ///< TD target dialysate temperature static BOOL tdDialyzerBypass; ///< TD dialyzer bypass static U32 tdAcidType; ///< TD Acid type static U32 tdBiCarbType; ///< TD Bicarb type static BOOL tdOpModeDataFreshFlag = FALSE; ///< Flag to signal/process fresh TD op mode data // ********** private function prototypes ********** static void checkTDDataFreshness( ALARM_ID_T alarmID, BOOL *tdFreshDataFlag ); /*********************************************************************//** * @brief * The initTDInterface function initializes the TDInterface unit. * @details \b Inputs: none * @details \b Outputs: TDInterface unit initialized. * @return none *************************************************************************/ void initTDInterface( void ) { // Initialize unit variables tdCurrentOpMode = MODE_INIT; tdSubMode = 0; tdDialysisFlowrate = TD_MAX_DIALYSIS_FLOW_RATE; // Will update later based on the TD value tdUFRate = 0.0F; tdTargetDialysateTemp = 0.0F; tdDialyzerBypass = FALSE; tdAcidType = 0; tdBiCarbType = 0; } /**********************************************************************//** * @brief * The checkTDDataFreshness function checks the freshness of data coming from * the TD sub-system. * @details \b Alarm: Given alarm is triggered if TD is communicating but has * not published new data for too long. * @details \b Inputs: TD communicating flag * @details \b Outputs: none * @param alarm ID of alarm to check * @param tdFreshDataFlag Pointer to flag indicating whether new data has been * received since last time this function has seen it. * @return None *************************************************************************/ static void checkTDDataFreshness( ALARM_ID_T alarmID, BOOL *tdFreshDataFlag ) { if ( TRUE == *tdFreshDataFlag ) { *tdFreshDataFlag = FALSE; checkPersistentAlarm( alarmID, FALSE, 0.0, 0.0 ); } else { // Alarm if not receiving TD fresh data message in timely manner if ( TRUE == isTDCommunicating() ) { checkPersistentAlarm( alarmID, TRUE, 0.0, 0.0 ); } else { checkPersistentAlarm( alarmID, FALSE, 0.0, 0.0 ); } } } /*********************************************************************//** * @brief * The execTDInterfaceMonitor function executes the TD Interface monitoring * function. Ensures TD is sending fresh data in a timely manner. * @details \b Inputs: none * @details \b Outputs: none * @return none *************************************************************************/ void execTDInterfaceMonitor( void ) { } /*********************************************************************//** * @brief * The getTDOpMode function gets the current latest reported TD operating mode. * @details \b Inputs: tdCurrentOpMode * @details \b Outputs: none * @return Latest reported TD operating mode. *************************************************************************/ TD_OP_MODE_T getTDOpMode( void ) { return tdCurrentOpMode; } /*********************************************************************//** * @brief * The getTDSubMode function gets the latest reported TD operating sub-mode. * @details \b Inputs: tdSubMode * @details \b Outputs: none * @return Latest reported TD operating sub-mode. *************************************************************************/ U32 getTDSubMode( void ) { return tdSubMode; } /*********************************************************************//** * @brief * The setTDOpMode function sets the latest TD operating mode reported by * the TD (called by TD published message handler). * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT if reported TD mode is invalid. * @details \b Inputs: none * @details \b Outputs: tdCurrentOpMode, ddSubMode, tdOpModeDataFreshFlag * @param opMode The operating mode reported by DD * @param subMode The sub-mode of operating mode reported by TD * @return none *************************************************************************/ void setTDOpMode( U32 opMode, U32 subMode ) { if ( opMode < NUM_OF_MODES ) { // update TD op mode and sub-mode tdCurrentOpMode = (TD_OP_MODE_T)opMode; tdSubMode = subMode; } else { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_TD_OPERATING_MODE, opMode ); } tdOpModeDataFreshFlag = TRUE; } /*********************************************************************//** * @brief * The getTDDialysateFlowrate function gets the latest TD dialysis flow * rate. * @details \b Inputs: tdDialysisFlowrate * @details \b Outputs: none * @return Latest TD dialysis flow rate. *************************************************************************/ F32 getTDDialysateFlowrate( void ) { return tdDialysisFlowrate; } /*********************************************************************//** * @brief * The getTDUFrate function gets the latest TD ultrafilteration flow * rate. * @details \b Inputs: tdUFRate * @details \b Outputs: none * @return Latest UF rate. *************************************************************************/ F32 getTDUFRate( void ) { return tdUFRate; } /*********************************************************************//** * @brief * The getTDTargetDialysateTemperature function gets the latest TD * target dialysate temperature rate. * @details \b Inputs: tdTargetDialysateTemp * @details \b Outputs: none * @return Latest target dialysate temperature. *************************************************************************/ F32 getTDTargetDialysateTemperature( void ) { return tdTargetDialysateTemp; } /*********************************************************************//** * @brief * The getTDDialyzerBypass function gets the latest TD * dailyzer bypass valve enable flag. * @details \b Inputs: tdDialyzerBypass * @details \b Outputs: none * @return Latest dialyzer bypass valve enable. *************************************************************************/ BOOL getTDDialyzerBypass( void ) { return tdDialyzerBypass; } /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ /**@}*/