/************************************************************************** * * Copyright (c) 2024-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 DDInterface.c * * @author (last) Michael Garthwaite * @date (last) 03-Mar-2025 * * @author (original) Michael Garthwaite * @date (original) 03-Mar-2025 * ***************************************************************************/ #include "ROPump.h" #include "DDInterface.h" #include "Messaging.h" #include "MessagePayloads.h" #include "ModeGenPermeate.h" #include "ModeStandby.h" #include "OperationModes.h" #include "PersistentAlarm.h" #include "SystemCommRO.h" #include "TaskGeneral.h" #include "Timers.h" /** * @addtogroup DDInterface * @{ */ // ********** private definitions ********** // ********** private data ********** static DD_OP_MODE_T ddCurrentOpMode; ///< Current DD operation mode. static U32 ddSubMode; ///< Current state (sub-mode) of current DD operation mode. static F32 ddPermeateFlowRate; ///< DD RO Permeate flow rate. // ********** private function prototypes ********** static void setDDOpMode( U32 opMode, U32 subMode ); static void setDDPermeateFlowRate( F32 flowRate ); /*********************************************************************//** * @brief * The initDDInterface function initializes the DD Interface unit. * @details \b Inputs: none * @details \b Outputs: DD Interface unit initialized. * @return none *************************************************************************/ void initDDInterface( void ) { // Initialize unit variables ddCurrentOpMode = DD_MODE_INIT; ddSubMode = 0; ddPermeateFlowRate = 0.0; } /*********************************************************************//** * @brief * The execDDInterfaceMonitor function executes the DD Interface monitoring * function. Ensures DD is sending fresh data in a timely manner. * @details \b Inputs: none * @details \b Outputs: none * @return none *************************************************************************/ void execDDInterfaceMonitor( void ) { // TODO: DD interface monitor. Ensure DD is sending fresh data in a timely manner. } /*********************************************************************//** * @brief * The getDDOpMode function gets the current latest reported DD operating mode. * @details \b Inputs: ddCurrentOpMode * @details \b Outputs: none * @return Latest reported DD operating mode. *************************************************************************/ DD_OP_MODE_T getDDOpMode( void ) { return ddCurrentOpMode; } /*********************************************************************//** * @brief * The getDDSubMode function gets the latest reported DD operating sub-mode. * @details \b Inputs: tdSubMode * @details \b Outputs: none * @return Latest reported DD operating sub-mode. *************************************************************************/ U32 getDDSubMode( void ) { return ddSubMode; } /*********************************************************************//** * @brief * The setDDPermeateFlowRate function sets the latest DD Permeate flow * rate. * @details \b Inputs: none * @details \b Outputs: ddPermeateFlowRate * @param flowRate. * @return none. *************************************************************************/ void setDDPermeateFlowRate( F32 flowRate ) { ddPermeateFlowRate = flowRate; } /*********************************************************************//** * @brief * The getDDPermeateFlowRate function sets the latest DD Permeate flow * rate. * @details \b Inputs: none * @details \b Outputs: ddPermeateFlowRate * @param Dialyzer Bypass enable. * @return latest DD Permeate Flow Rate. *************************************************************************/ F32 getDDPermeateFlowRate( void ) { return ddPermeateFlowRate; } /*********************************************************************//** * @brief * The handleGeneratePermeateRequestMsg function handles a RO permeate * request from DD and updates permeate flow rate. * @details Inputs: none * @details Outputs: message handled * @param message a pointer to the message to handle * @return TRUE if message is sucessfully parsed, FALSE if not. *************************************************************************/ BOOL handleGeneratePermeateRequestMsg( MESSAGE_T *message ) { BOOL result = FALSE; if ( message->hdr.payloadLen == sizeof( RO_WATER_REQ_PAYLOAD_T ) ) { RO_WATER_REQ_PAYLOAD_T startRORequest; RO_OP_MODE_T roMode = getCurrentOperationMode(); memcpy( &startRORequest, message->payload, sizeof( RO_WATER_REQ_PAYLOAD_T ) ); if ( ( RO_MODE_STAN == roMode ) && ( TRUE == startRORequest.start ) ) { setDDPermeateFlowRate( startRORequest.roRate ); setBoostPumpPWMDutyCycle( P12_PUMP,startRORequest.roRate ); result = requestROStart(); } else if ( RO_MODE_GENP == roMode ) { if ( FALSE == startRORequest.start ) { // stop Permeate Generation by transitioning to standby mode signalROPumpStop( P12_PUMP ); requestNewOperationMode( RO_MODE_STAN ); } else { // Set flow rate and delivery. setDDPermeateFlowRate( startRORequest.roRate ); } result = TRUE; } } return result; } /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ /**@}*/