/**********************************************************************//** * * Copyright (c) 2019-2020 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 DGInterface.c * * @date 08-Apr-2020 * @author S. Nash * * @brief Interfaces with and monitors the DG sub-system. * **************************************************************************/ #include "AlarmMgmt.h" #include "OperationModes.h" #include "SystemCommMessages.h" #include "DGInterface.h" /** * @addtogroup DGInterface * @{ */ // ********** private definitions ********** #define START_DG_CMD TRUE #define STOP_DG_CMD FALSE // ********** private data ********** // DG status static DG_OP_MODE_T dgCurrentOpMode = DG_MODE_INIT; static BOOL dgStarted = FALSE; static BOOL dgStartetSet = FALSE; static BOOL dgWaterSampled = FALSE; static BOOL dgWaterSampledSet = FALSE; // DG sensor data static F32 dgPressures[ NUM_OF_DG_PRESSURE_SENSORS ]; static F32 dgPrimaryTempSet = 0.0; static F32 dgPrimaryTemp = 0.0; static F32 dgTrimmerTempSet = 0.0; static F32 dgTrimmerTemp = 0.0; // DG pumps data static F32 dgROPumpFlowRateMlMin = 0.0; static U32 dgROPumpPressureSetPtPSI = 0; static U32 dgDrainPumpSpeedSetPtRPM = 0; // reservoir data static DG_RESERVOIR_ID_T dgActiveReservoir = DG_RESERVOIR_2; static DG_RESERVOIR_ID_T dgActiveReservoirSet = DG_RESERVOIR_2; static U32 dgReservoirFillVolumeTarget = 0; static U32 dgReservoirFillVolumeTargetSet = 0; static U32 dgReservoirDrainVolumeTarget = 0; static U32 dgReservoirDrainVolumeTargetSet = 0; // ********** private function prototypes ********** /*********************************************************************//** * @brief * The initDGInterface function initializes the DGInterface module. * @details * Inputs : none * Outputs : DGInterface module initialized. * @return none *************************************************************************/ void initDGInterface( void ) { // TODO - anything to initialize? } /*********************************************************************//** * @brief * The getDGOpMode function gets the current DG operating mode. * @details * Inputs : dgCurrentOpMode * Outputs : none * @return Current DG operating mode. *************************************************************************/ DG_OP_MODE_T getDGOpMode( void ) { DG_OP_MODE_T result = dgCurrentOpMode; return result; } /*********************************************************************//** * @brief * The getDGPressure function gets the latest pressure reported by the DG \n * for a given pressure sensor. * @details * Inputs : dgPressures[] * Outputs : none * @param sensorID : pressure sensor we are getting reading for. * @return Latest pressure reading reported by DG for the given sensor. *************************************************************************/ F32 getDGPressure( DG_PRESSURE_SENSORS_T sensorID ) { F32 result = 0.0; if ( sensorID < NUM_OF_DG_PRESSURE_SENSORS ) { result = dgPressures[ sensorID ]; } else { // TODO - s/w fault } return result; } /*********************************************************************//** * @brief * The getDGROPumpPressureSetPt function gets the latest RO pump \n * pressure set point reported by the DG. * @details * Inputs : dgROPumpPressureSetPtPSI * Outputs : none * @return Latest RO pump pressure set point reported by DG. *************************************************************************/ U32 getDGROPumpPressureSetPt( void ) { U32 result = dgROPumpPressureSetPtPSI; return result; } /*********************************************************************//** * @brief * The getDGROPumpFlowRateMlMin function gets the latest RO pump flow \n * rate reported by the DG. * @details * Inputs : dgROPumpFlowRateMlMin * Outputs : none * @return Latest RO pump flow rate reported by DG. *************************************************************************/ F32 getDGROPumpFlowRateMlMin( void ) { F32 result = dgROPumpFlowRateMlMin; return result; } /*********************************************************************//** * @brief * The getDGDrainPumpRPMSetPt function gets the latest drain pump RPM \n * set point reported by the DG. * @details * Inputs : dgDrainPumpSpeedSetPtRPM * Outputs : none * @return Latest drain pump RPM set point reported by DG. *************************************************************************/ U32 getDGDrainPumpRPMSetPt( void ) { U32 result = dgDrainPumpSpeedSetPtRPM; return result; } /*********************************************************************//** * @brief * The setDGOpMode function sets the latest DG operating mode reported by \n * the DG. * @details * Inputs : none * Outputs : dgCurrentOpMode * @param opMode : operating mode reported by DG. * @return none *************************************************************************/ void setDGOpMode( U32 opMode ) { if ( opMode < NUM_OF_DG_MODES ) { dgCurrentOpMode = (DG_OP_MODE_T)opMode; } } /*********************************************************************//** * @brief * The setDGDialysateTemperatures function sets the latest temperature data \n * reported by the DG. * @details * Inputs : none * Outputs : dgPrimaryTemp, dgTrimmerTemp * @param primaryHtrTemp : Primary heater temperature reported by DG. * @param trimmerHtrTemp : Trimmer heater temperature reported by DG. * @return none *************************************************************************/ void setDGDialysateTemperatures( F32 primaryHtrTemp, F32 trimmerHtrTemp ) { dgPrimaryTemp = primaryHtrTemp; dgTrimmerTemp = trimmerHtrTemp; } /*********************************************************************//** * @brief * The setDGReservoirsData function sets the latest reservoir data \n * reported by the DG. * @details * Inputs : none * Outputs : dgActiveReservoir, dgReservoirFillVolumeTarget, dgReservoirDrainVolumeTarget * @param resID : ID of active reservoir. * @param fillVol : Reservoir fill to volume reported by DG. * @param drainVol : Reservoir drain to volume reported by DG. * @return none *************************************************************************/ void setDGReservoirsData( DG_RESERVOIR_ID_T resID, U32 fillVol, U32 drainVol ) { if ( resID < NUM_OF_DG_RESERVOIRS ) { dgActiveReservoir = resID; dgReservoirFillVolumeTarget = fillVol; dgReservoirDrainVolumeTarget = drainVol; } } /*********************************************************************//** * @brief * The setDGPressures function sets the latest pressures reported by the DG. * @details * Inputs : none * Outputs : dgPressures[] * @param roIn : latest RO pump inlet pressure reported by DG. * @param roOut : latest RO pump outlet pressure reported by DG. * @param drainIn : latest drain pump inlet pressure reported by DG. * @param drainOut : latest drain pump outlet pressure reported by DG. * @return none *************************************************************************/ void setDGPressures( F32 roIn, F32 roOut, F32 drainIn, F32 drainOut ) { dgPressures[ DG_PRESSURE_SENSOR_RO_PUMP_INLET ] = roIn; dgPressures[ DG_PRESSURE_SENSOR_RO_PUMP_OUTLET ] = roOut; dgPressures[ DG_PRESSURE_SENSOR_DRAIN_PUMP_INLET ] = drainIn; dgPressures[ DG_PRESSURE_SENSOR_DRAIN_PUMP_OUTLET ] = drainOut; } /*********************************************************************//** * @brief * The setDGROPumpData function sets the latest RO pump data reported by the DG. * @details * Inputs : none * Outputs : dgROPumpPressureSetPtPSI, dgROPumpFlowRateMlMin * @param presSetPt : latest RO pump pressure set point reported by DG. * @param flowRate : latest RO pump flow rate reported by DG. * @return none *************************************************************************/ void setDGROPumpData( U32 presSetPt, F32 flowRate ) { dgROPumpPressureSetPtPSI = presSetPt; dgROPumpFlowRateMlMin = flowRate; } /*********************************************************************//** * @brief * The setDGDrainPumpData function sets the latest drain pump data reported by the DG. * @details * Inputs : none * Outputs : dgDrainPumpSpeedSetPtRPM * @param rpmSetPt : latest drain pump RPM set point reported by DG. * @return none *************************************************************************/ void setDGDrainPumpData( U32 rpmSetPt ) { dgDrainPumpSpeedSetPtRPM = rpmSetPt; } /*********************************************************************//** * @brief * The cmdSetDGDialysateTargetTemps function sends a target dialysate \n * temperature command message to the DG. * @details * Inputs : none * Outputs : dgPrimaryTempSet, dgTrimmerTempSet * @param primaryHtrTemp : commanded target dialysate temperature for the primary heater. * @param trimmerHtrTemp : commanded target dialysate temperature for the trimmer heater. * @return none *************************************************************************/ void cmdSetDGDialysateTargetTemps( F32 primaryHtrTemp, F32 trimmerHtrTemp ) { dgPrimaryTempSet = primaryHtrTemp; dgTrimmerTempSet = trimmerHtrTemp; sendDialysateTempTargetsToDG( primaryHtrTemp, trimmerHtrTemp ); } /*********************************************************************//** * @brief * The cmdStartDG function sends a start command to the DG. DG will transition \n * from standby to re-circulate mode and start producing warm, pure water. * @details * Inputs : none * Outputs : start DG command sent * @return none *************************************************************************/ void cmdStartDG( void ) { dgStarted = TRUE; sendDGStartStopCommand( START_DG_CMD ); } /*********************************************************************//** * @brief * The cmdStopDG function sends a stop command to the DG. DG will transition \n * from re-circulate mode to standby mode. Pumps and heater go off. * @details * Inputs : none * Outputs : stop DG command sent * @return none *************************************************************************/ void cmdStopDG( void ) { dgStarted = FALSE; sendDGStartStopCommand( STOP_DG_CMD ); } /*********************************************************************//** * @brief * The cmdSetDGActiveReservoir function sends a set active reservoir command \n * message to the DG. * @details * Inputs : none * Outputs : set active reservoir command sent to DG. * @param resID : ID of reservoir to set as active (reservoir for HD to draw from). * @return none *************************************************************************/ void cmdSetDGActiveReservoir( DG_RESERVOIR_ID_T resID ) { if ( resID < NUM_OF_DG_RESERVOIRS ) { dgActiveReservoirSet = resID; sendDGSwitchReservoirCommand( resID ); } else { // TODO - s/w fault } } /*********************************************************************//** * @brief * The cmdStartDGFill function sends a fill command message to the DG. * @details * Inputs : none * Outputs : fill command sent to DG. * @param fillToVolMl : volume (in mL) to fill inactive reservoir to. * @return none *************************************************************************/ void cmdStartDGFill( U32 fillToVolMl ) { dgReservoirFillVolumeTargetSet = fillToVolMl; sendDGFillCommand( fillToVolMl ); } /*********************************************************************//** * @brief * The cmdStartDGDrain function sends a drain command message to the DG. * @details * Inputs : none * Outputs : drain command sent to DG. * @param drainToVolMl : volume (in mL) to drain inactive reservoir to. * @return none *************************************************************************/ void cmdStartDGDrain( U32 drainToVolMl ) { dgReservoirDrainVolumeTargetSet = drainToVolMl; sendDGDrainCommand( drainToVolMl ); } /*********************************************************************//** * @brief * The cmdDGSampleWater function sends a sample water command message to the DG. * @details * Inputs : none * Outputs : sample water command sent to DG. * @return none *************************************************************************/ void cmdDGSampleWater( void ) { dgWaterSampled = TRUE; sendDGSampleWaterCommand(); } /**@}*/