Index: firmware/App/Modes/ModeDrain.c =================================================================== diff -u -r2c08db070a6e09306caf461e7aceeb53097fd995 -r45ceca1780ca1256252828ead6bf6112303ae79f --- firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision 2c08db070a6e09306caf461e7aceeb53097fd995) +++ firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision 45ceca1780ca1256252828ead6bf6112303ae79f) @@ -8,7 +8,7 @@ * @file ModeDrain.c * * @author (last) Dara Navaei -* @date (last) 21-Dec-2022 +* @date (last) 20-Jul-2023 * * @author (original) Leonardo Baloa * @date (original) 20-Dec-2019 @@ -20,13 +20,15 @@ #include "CPLD.h" #include "DrainPump.h" #include "Heaters.h" -#include "ModeFill.h" #include "ModeDrain.h" +#include "ModeFill.h" +#include "ModeGenIdle.h" #include "OperationModes.h" #include "Pressures.h" #include "Reservoirs.h" #include "ROPump.h" #include "SystemComm.h" +#include "SystemCommMessages.h" #include "TaskGeneral.h" #include "TemperatureSensors.h" #include "Timers.h" @@ -39,8 +41,8 @@ // ********** private definitions ********** -#define TARGET_DRAIN_PUMP_RPM 2400 ///< Target drain pump speed (in RPM). -#define DRAIN_WEIGHT_UNCHANGE_TIMEOUT ( 2 * MS_PER_SECOND ) ///< Time period of unchanged weight during draining before timeout. +#define TARGET_DRAIN_PUMP_RPM 2200 ///< Target drain pump speed (in RPM). +#define DRAIN_WEIGHT_UNCHANGE_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Time period of unchanged weight during draining before timeout. #define DRAIN_EMPTY_TARE_WAIT ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) /// Time period to wait after drain complete and before taring load cells. @@ -55,8 +57,21 @@ #define RINSE_CONCENTRATE_LINES_WAIT ( 25 * MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Time period to wait for concentrate lines to rinse. #define RINSE_SPEED ( ( CONCENTRATE_PUMP_MAX_SPEED - 3.0F ) * -1.0F ) ///< Reserver the concentrate speed to rinse out concentrate lines. -#define CONCENTRATION_BOTTLE_LOW_VOLUME_ML 100.0F ///< Concentration bottle low volume in mL. +#define CONCENTRATE_BOTTLE_PRIMING_VOL_ML 73.0F ///< Concentrate bottle priming volume in mL. +#define CONCENTRATE_BOTTLE_RESERVOIOR_VOL_ML 1500.0F ///< Concentrate bottle reservoir volume in mL +#define CONCENTRATE_BOTTLE_RESERVOIOR_FILLS 3 ///< Concentrate bottle reservoir vlls. +#define BICARB_PERCENT_FILL 0.03514F ///< Bicarb volume percentage of reservoir volume. +#define ACID_PERCENT_FILL 0.02222F ///< Acid volume percentage of reservoir volume. + +///< Concentrate bottle acid low volume in mL. +static const F32 CONCENTRATE_BOTTLE_ACID_LOW_VOLUME_ML = ( CONCENTRATE_BOTTLE_PRIMING_VOL_ML + + ( CONCENTRATE_BOTTLE_RESERVOIOR_VOL_ML * CONCENTRATE_BOTTLE_RESERVOIOR_FILLS * ACID_PERCENT_FILL) ); + +///< Concentrate bottle bicarb low volume in mL. +static const F32 CONCENTRATE_BOTTLE_BICARB_LOW_VOLUME_ML = ( CONCENTRATE_BOTTLE_PRIMING_VOL_ML + + ( CONCENTRATE_BOTTLE_RESERVOIOR_VOL_ML * CONCENTRATE_BOTTLE_RESERVOIOR_FILLS * BICARB_PERCENT_FILL) ); + // ********** private data ********** static DG_DRAIN_STATE_T drainState; ///< Currently active drain state. @@ -98,11 +113,24 @@ *************************************************************************/ U32 transitionToDrainMode( void ) { - // re-initialize each time we transition to drain mode - initDrainMode(); - DG_RESERVOIR_ID_T inactiveReservoir = getInactiveReservoir(); + if ( ( getTestConfigStatus( TEST_CONFIG_RECOVER_TREATMENT ) != TRUE ) || ( getPreviousOperationMode() != DG_MODE_FAUL ) ) + { + // re-initialize each time we transition to drain mode + initDrainMode(); + initDrainParameters( inactiveReservoir ); + } + else + { + setValveState( VPI, VALVE_STATE_OPEN ); + setValveState( VPD, VALVE_STATE_OPEN_C_TO_NC ); + } + + setCurrentSubState( NO_SUB_STATE ); + + SEND_EVENT_WITH_2_U32_DATA( DG_EVENT_INACTIVE_RESERVOIR_TEMP_REMOVE, (U32)inactiveReservoir, 0 ) // TODO remove + if ( DG_RESERVOIR_1 == inactiveReservoir ) { setValveStateDelayed( VRD1, VALVE_STATE_OPEN, DELAY_RES_DRAIN_VALVE_MS ); @@ -112,8 +140,6 @@ setValveStateDelayed( VRD2, VALVE_STATE_OPEN, DELAY_RES_DRAIN_VALVE_MS ); } - initDrainParameters( inactiveReservoir ); - // set initial actuator states setValveState( VDR, VALVE_STATE_DRAIN_C_TO_NO ); setDrainPumpTargetRPMDelayed( TARGET_DRAIN_PUMP_RPM, DELAY_DRAIN_PUMP_MS ); @@ -122,9 +148,13 @@ // because the initial guess in the heaters driver needs the target flow to calculate // the new PWMs for the main and small primary heaters setROPumpTargetFlowRateLPM( TARGET_RO_FLOW_RATE_L, TARGET_RO_PRESSURE_PSI ); - setHeaterTargetTemperature( DG_PRIMARY_HEATER, getPrimaryHeaterTargetTemperature() ); - startHeater( DG_PRIMARY_HEATER ); + if ( FALSE == isHeaterOn( DG_PRIMARY_HEATER ) ) + { + setHeaterTargetTemperature( DG_PRIMARY_HEATER, getPrimaryHeaterTargetTemperature() ); + startHeater( DG_PRIMARY_HEATER ); + } + setCPLDCleanLEDColor( CPLD_CLEAN_LED_OFF ); return drainState; @@ -230,9 +260,20 @@ { DG_DRAIN_STATE_T result = DG_DRAIN_STATE_DRAIN; DG_RESERVOIR_ID_T inactiveReservoir = getInactiveReservoir(); + U32 targetVolumeML = getTargetDrainVolumeML(); + BOOL drainStatus = FALSE; + if ( 0 == targetVolumeML ) + { + drainStatus = hasTargetDrainToZeroBeenReached( inactiveReservoir, DRAIN_WEIGHT_UNCHANGE_TIMEOUT_MS ); + } + else + { + drainStatus = hasTargetDrainToVolumeBeenReached( inactiveReservoir, targetVolumeML, DRAIN_WEIGHT_UNCHANGE_TIMEOUT_MS ); + } + // if we have reached our target drain to volume (by weight) or cannot drain anymore, we are done draining - go back to generation idle mode - if ( TRUE == hasTargetDrainVolumeBeenReached( inactiveReservoir, DRAIN_WEIGHT_UNCHANGE_TIMEOUT ) ) + if ( TRUE == drainStatus ) { DG_ACID_CONCENTRATES_RECORD_T acid; F32 acidBottleVolML; @@ -246,6 +287,7 @@ acidBottleVolML = acid.acidConcentrate[ CAL_DATA_ACID_CONCENTRATE_1 ].acidFullBottleVolumeML; bicarbBottleVolML = bicarb.bicarbConcentrate[ CAL_DATA_BICARB_CONCENTRATE_1 ].bicarbStartVolumeML; + SEND_EVENT_WITH_2_U32_DATA( DG_EVENT_INACTIVE_RESERVOIR_TEMP_REMOVE, (U32)inactiveReservoir, 0 ) // TODO remove if ( DG_RESERVOIR_1 == inactiveReservoir ) { @@ -261,18 +303,20 @@ #endif { // Detect empty bottles using integrated volumes - if ( ( acidBottleVolML - getChemicalUsedVolumeML( ACID ) ) <= CONCENTRATION_BOTTLE_LOW_VOLUME_ML ) // || // SRSDG 437 + if ( ( acidBottleVolML - getChemicalUsedVolumeML( ACID ) ) <= CONCENTRATE_BOTTLE_ACID_LOW_VOLUME_ML ) // SRSDG 836 { resetChemicalUsedVolumeML( ACID ); setThisFisrtFillFlag( TRUE ); // indicates bottles need prime activateAlarmNoData( ALARM_ID_DG_ACID_BOTTLE_LOW_VOLUME ); + activateAlarmNoData ( ALARM_ID_DG_CREATING_DIALYSATE_PLEASE_WAIT ); } - if ( ( bicarbBottleVolML - getChemicalUsedVolumeML( BICARB ) ) <= CONCENTRATION_BOTTLE_LOW_VOLUME_ML ) // || // SRSDG 438 + if ( ( bicarbBottleVolML - getChemicalUsedVolumeML( BICARB ) ) <= CONCENTRATE_BOTTLE_BICARB_LOW_VOLUME_ML ) // SRSDG 837 { resetChemicalUsedVolumeML( BICARB ); setThisFisrtFillFlag( TRUE ); activateAlarmNoData( ALARM_ID_DG_BICARB_BOTTLE_LOW_VOLUME ); + activateAlarmNoData ( ALARM_ID_DG_CREATING_DIALYSATE_PLEASE_WAIT ); } } @@ -298,7 +342,7 @@ * The handleDrainStateTare function handles the tare state of the drain mode * state machine. * @details Inputs: drainEmptyTareTimerCtr - * @details Outputs: drainEmptyTareTimerCtr + * @details Outputs: drainEmptyTareTimerCtr, rinseConcentrateLines * @return the next state *************************************************************************/ static DG_DRAIN_STATE_T handleDrainStateTare( void ) @@ -308,6 +352,8 @@ if ( ++drainEmptyTareTimerCtr > DRAIN_EMPTY_TARE_WAIT ) { + SEND_EVENT_WITH_2_U32_DATA( DG_EVENT_INACTIVE_RESERVOIR_TEMP_REMOVE, (U32)inactiveReservoir, 0 ) // TODO remove + drainEmptyTareTimerCtr = 0; tareLoadCellsAtEmpty( inactiveReservoir ); @@ -332,8 +378,8 @@ * @brief * The handleRinseState function handles the tare state of the drain mode * state machine. - * @details Inputs: drainEmptyTareTimerCtr - * @details Outputs: drainEmptyTareTimerCtr + * @details Inputs: drainEmptyTareTimerCtr, rinseConcentrateLines + * @details Outputs: drainEmptyTareTimerCtr, rinseConcentrateLines * @return the next state *************************************************************************/ static DG_DRAIN_STATE_T handleRinseState( void ) @@ -345,6 +391,7 @@ if ( ++rinseConcentrateLinesTimerCtr > RINSE_CONCENTRATE_LINES_WAIT ) { rinseConcentrateLinesTimerCtr = 0; + rinseConcentrateLines = FALSE; requestConcentratePumpOff( CONCENTRATEPUMPS_CP1_ACID, NO_PARK_CONC_PUMPS ); requestConcentratePumpOff( CONCENTRATEPUMPS_CP2_BICARB, NO_PARK_CONC_PUMPS ); requestNewOperationMode( DG_MODE_GENE );