Index: firmware/App/Controllers/DryBiCart.c =================================================================== diff -u -r351b1f34070149cea5342ce7b45ba97a4b99dab3 -r8752be6dad093564d924e5572ee8756699de0071 --- firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision 351b1f34070149cea5342ce7b45ba97a4b99dab3) +++ firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision 8752be6dad093564d924e5572ee8756699de0071) @@ -56,13 +56,16 @@ // Bicarb chamber fill/Supply #define DRY_BICART_SUPPLY_VALVE_D80_OPEN_TIME_MS ( 3 * MS_PER_SECOND ) ///< Max time allowed for supply (opening D80 valve) during bicarb chamber (F) fill. +#define DRY_BICART_SUPPLY_VENT_TIME_MS ( 1 * MS_PER_SECOND ) ///< Wait time to vent dry bicart gas before actuating Bicarb chamber(F) venting. +#define DRY_BICART_SUPPLY_VENT_MAX_TIME_MS ( 3 * MS_PER_SECOND ) ///< Max time to vent both dry bicart and Chamber F. // Dry Bicart Drain -#define DRY_BICART_MAX_DRAIN_TIME_MS ( 8 * SEC_PER_MIN * MS_PER_SECOND ) ///< Max drain time for dry bicart in ms. +#define LARGE_DRY_BICART_MAX_DRAIN_TIME_MS ( 8 * SEC_PER_MIN * MS_PER_SECOND ) ///< Max drain time for large dry bicart in ms. +#define SMALL_DRY_BICART_MAX_DRAIN_TIME_MS ( 4 * SEC_PER_MIN * MS_PER_SECOND ) ///< Max drain time for small dry bicart in ms. #define DRY_BICART_DRAIN_FLUID_PHASE_TIME_MS ( 3 * MS_PER_SECOND ) ///< Time to stay in fluid drain per cycle #define DRY_BICART_DRAIN_VENT_PHASE_TIME_MS ( 8 * MS_PER_SECOND ) ///< Time to keep D64 open per vent cycle #define DRY_BICART_DRAIN_COND_SAMPLE_PERIOD_MS 500 ///< Conductivity sample period -#define DRY_BICART_DRAIN_COND_ZERO_THRESH 0.05F ///< "Zero" conductivity threshold +#define DRY_BICART_DRAIN_COND_ZERO_THRESH 0.05F ///< Zero conductivity threshold #define DRY_BICART_DRAIN_COND_STABLE_SAMPLES 10U ///< Debounce samples (10*50ms=500ms) /// Payload record structure for dry bicart fill request @@ -76,42 +79,54 @@ static DRY_BICART_FILL_EXEC_STATE_T dryBiCartFillExecState; ///< Current state of dry bicart fill executive state machine. static BICARB_CHAMBER_FILL_EXEC_STATE_T bicarbChamberFillExecState; ///< Current state of bicarb chamber fill executive state machine. static DRY_BICART_DRAIN_EXEC_STATE_T dryBiCartDrainExecState; ///< Current state of dry bicart drain executive state machine +// fill static U32 dryBiCartFillStartTime; ///< Dry bicart fill start time. static U32 biCartFillCycleCounter; ///< Number of drybicart fill cycle -static OVERRIDE_U32_T biCartMaxFillCycleCount; ///< Maximum number of drybicart fill cycle ( overrideable) static U32 lastFillDurationInMS; ///< Previous time duration to fill the bicart fill. static U32 currentFillDurationInMS; ///< Current time duration to fill the bicart fill. -static OVERRIDE_U32_T dryBiCartFillRequested; ///< Start/stop Dry bicart fill. -static OVERRIDE_U32_T dryBiCartDrainRequested; ///< Start/stop Dry bicart drain. -static OVERRIDE_U32_T dryBiCartFillRequested; ///< Start/stop Dry bicart fill. +static OVERRIDE_U32_T biCartMaxFillCycleCount; ///< Maximum number of drybicart fill cycle ( overrideable) +// initiate the fill/supply/drain +static OVERRIDE_U32_T dryBiCartFillRequested; ///< Start/stop dry bicart fill. +static OVERRIDE_U32_T bicarbChamberFillRequested; ///< Start/stop bicarb chamber fill. +static OVERRIDE_U32_T dryBiCartDrainRequested; ///< Start/stop dry bicart drain. +// publish static OVERRIDE_U32_T dryBiCartDataPublishInterval; ///< Dry bicart data publish interval. static U32 dryBiCartDataPublicationTimerCounter; ///< Used to schedule drybicart data publication to CAN bus. +// cart selection for draining +static OVERRIDE_U32_T dryBiCartType; ///< Dry bicart size(small/large) +// supply static U32 dryBiCarbSupplyStartTime; ///< Bicarb supply start time from bicart to Chamber F. -static OVERRIDE_U32_T bicarbChamberFillRequested; ///< Start/stop Bicarb chamber fill. +// vent +static U32 dryBiCarbSypplyVentStartTime; ///< Bicarb supply vent start time for both bicart & Chamber F. +// drain static U32 dryBiCartDrainStartTime; ///< Drain overall start time (for max timeout) -static U32 dryBiCartDrainPhaseStartTime; ///< Phase start time (fluid/vent cycling) static U32 dryBiCartDrainLastCondSampleTime; ///< Last time conductivity was sampled static U32 dryBiCartDrainCondStableCount; ///< Debounce counter for "zero" conductivity +static U32 dryBiCartDrainTimePeriod; ///< Dry bicart drain time period // ********** private function prototypes ********** +// Fill static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillWaterStartState( void ); static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillWaterEndState( void ); static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartDegasStartState( void ); static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartDegasEndState( void ); static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillDurationCheckState( void ); static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillCompleteState( void ); - +// Supply & Vent +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberCartridgeFillWaterStartState( void ); +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberCartridgeFillWaterEndState( void ); static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberCheckLevelState( void ); static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberFillState( void ); static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberPressureCheckState( void ); - +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberSupplyVentStartState(void); +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberSupplyVentEndState(void); +// Drain static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartDrainStartState( void ); static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartFluidDrainState( void ); -static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartPressureEquillibriumState( void ); static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartFluidDrainDurationCheckState( void ); static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartFluidDrainEndState( void ); - +// publish the status static void publishDryBicartData( void ); static U32 getDryBicartFillDataPublishInterval( void ); @@ -154,25 +169,30 @@ bicarbChamberFillRequested.ovInitData = FALSE; bicarbChamberFillRequested.override = OVERRIDE_RESET; + dryBiCartType.data = FALSE; + dryBiCartType.ovData = FALSE; + dryBiCartType.ovInitData = 0; + dryBiCartType.override = OVERRIDE_RESET; + dryBiCartFillStartTime = 0; lastFillDurationInMS = 0; currentFillDurationInMS = 0; dryBiCartDataPublicationTimerCounter = 0; biCartFillCycleCounter = 0; dryBiCarbSupplyStartTime = 0; + dryBiCarbSypplyVentStartTime = 0; dryBiCartDrainStartTime = 0; - dryBiCartDrainPhaseStartTime = 0; dryBiCartDrainLastCondSampleTime = 0; dryBiCartDrainCondStableCount = 0; + dryBiCartDrainTimePeriod = 0; } /*********************************************************************//** * @brief * The transitionToDryBicart function prepares for transition to * dry bicart fill/degas operations. * @details \b Inputs: none - * @details \b Outputs: dryBiCartFillExecState,dryBiCartDataPublishInterval, - * biCartFillCycleCounter, dryBiCartFillStartTime + * @details \b Outputs: none * @return none *************************************************************************/ void transitionToDryBicart( void ) @@ -267,11 +287,158 @@ /*********************************************************************//** * @brief + * The execBicarbChamberFillMode function executes the bicarb chamber fill + * (delivering bicarbonate from Bicart assembly to chamber F)state machine. + * @details \b Inputs: bicarbChamberFillExecState + * @details \b Outputs: bicarbChamberFillExecState + * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT when wrong bicarb chamber + * fill state invoked. + * @return current state. + *************************************************************************/ +U32 execBicarbChamberFillMode( void ) +{ + // execute bicarb chamber fill state machine + switch ( bicarbChamberFillExecState ) + { + case BICARB_CHAMBER_START_STATE: + if ( TRUE == getU32OverrideValue( &bicarbChamberFillRequested ) ) + { + bicarbChamberFillExecState = BICARB_CARTRIDGE_FILL_WATER_START_STATE; + bicarbChamberFillRequested.data = FALSE; + } + break; + + case BICARB_CARTRIDGE_FILL_WATER_START_STATE: + bicarbChamberFillExecState = handleBicarbChamberCartridgeFillWaterStartState(); + break; + + case BICARB_CARTRIDGE_FILL_WATER_END_STATE: + bicarbChamberFillExecState = handleBicarbChamberCartridgeFillWaterEndState(); + break; + + case BICARB_CHAMBER_CHECK_LEVEL_STATE: + bicarbChamberFillExecState = handleBicarbChamberCheckLevelState(); + break; + + case BICARB_CHAMBER_FILL_STATE: + bicarbChamberFillExecState = handleBicarbChamberFillState(); + break; + + case BICARB_CHAMBER_PRESSURE_CHECK_STATE: + bicarbChamberFillExecState = handleBicarbChamberPressureCheckState(); + break; + + case BICARB_SUPPLY_VENT_START_STATE: + bicarbChamberFillExecState = handleBicarbChamberSupplyVentStartState(); + break; + + case BICARB_SUPPLY_VENT_END_STATE: + bicarbChamberFillExecState = handleBicarbChamberSupplyVentEndState(); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_BICARB_CHAMBER_FILL_INVALID_EXEC_STATE, bicarbChamberFillExecState ); + break; + } + + return bicarbChamberFillExecState; +} + +/*********************************************************************//** + * @brief + * The execDryBicartDrainMode function executes the dry bicart drain state machine. + * @details \b Inputs: dryBiCartDrainExecState + * @details \b Outputs: dryBiCartDrainExecState + * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT when wrong dry bicart drain state + * invoked. + * @return current state. + *************************************************************************/ +U32 execDryBicartDrainMode( void ) +{ + // execute drybicart drain state machine + switch ( dryBiCartDrainExecState ) + { + case DRY_BICART_DRAIN_START_STATE: + if ( TRUE == getU32OverrideValue( &dryBiCartDrainRequested ) ) + { + if ( TRUE == getU32OverrideValue( &dryBiCartType ) ) + { + dryBiCartDrainTimePeriod = LARGE_DRY_BICART_MAX_DRAIN_TIME_MS; + } + else + { + dryBiCartDrainTimePeriod = SMALL_DRY_BICART_MAX_DRAIN_TIME_MS; + } + dryBiCartDrainExecState = handleDryBicartDrainStartState(); + } + break; + + case DRY_BICART_FLUID_DRAIN_STATE: + dryBiCartDrainExecState = handleDryBicartFluidDrainState(); + break; + + case DRY_BICART_FLUID_DRAIN_DURATION_CHECK_STATE: + dryBiCartDrainExecState = handleDryBicartFluidDrainDurationCheckState(); + break; + + case DRY_BICART_FLUID_DRAIN_END_STATE: + dryBiCartDrainExecState = handleDryBicartFluidDrainEndState(); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_DRY_BICART_DRAIN_INVALID_EXEC_STATE, dryBiCartDrainExecState ); + break; + } + + return dryBiCartDrainExecState; +} + +/*********************************************************************//** + * @brief + * The setBicarbChamberFillRequested function sets the chmaberFillRequest + * flag value to be True. + * @details \b Inputs: none + * @details \b Outputs: bicarbChamberFillRequested + * @return none. + *************************************************************************/ +void setBicarbChamberFillRequested( void ) +{ + bicarbChamberFillRequested.data = TRUE; +} + +/*********************************************************************//** + * @brief + * The setBicartFillRequested function sets the bicart fill request + * flag value to be True. + * @details \b Inputs: none + * @details \b Outputs: dryBiCartFillRequested + * @return none. + *************************************************************************/ +void setBicartFillRequested( void ) +{ + dryBiCartFillRequested.data = TRUE; +} + +/*********************************************************************//** + * @brief + * The setBicartDrainRequested function sets the bicart drain request + * flag value to be True. + * @details \b Inputs: none + * @details \b Outputs: dryBiCartDrainRequested + * @return none. + *************************************************************************/ +void setBicartDrainRequested( void ) +{ + dryBiCartDrainRequested.data = TRUE; +} + +/*********************************************************************//** + * @brief * The handleDryBicartFillWaterStartState function initiates the water fill * into dry bicarbonate cartridge. * @details \b Inputs: none * @details \b Outputs: valve states - * @return the next drybicart fill state. + * @return the next drybicart fill water end state. *************************************************************************/ static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillWaterStartState( void ) { @@ -301,7 +468,7 @@ * for Dry bicart fill. * @details \b Inputs: D66 pressure sensor reading * @details \b Outputs: valve states - * @return the next drybicart fill state. + * @return the next drybicart degas start state. *************************************************************************/ static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillWaterEndState( void ) { @@ -330,7 +497,7 @@ * present in the Bicart assembly. * @details \b Inputs: none * @details \b Outputs: valve states - * @return the next drybicart fill state. + * @return the next drybicart degas end state. *************************************************************************/ static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartDegasStartState( void ) { @@ -353,9 +520,9 @@ * @brief * The handleDryBicartDegasEndState function open vent valve present in * the F Chamber (Bicarb) and closes the vent valve once pressure is met. - * @details \b Inputs: D66 pressure sensor reading + * @details \b Inputs: D66 pressure sensor reading, dryBiCartFillStartTime * @details \b Outputs: valve states - * @return the next drybicart fill state. + * @return the next drybicart fill duration check state. *************************************************************************/ static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartDegasEndState( void ) { @@ -387,7 +554,8 @@ * The handleDryBicartFillDurationCheckState function checks the fill duration * between last and current fill and exits if the duration is reduced over period * or number of fill cycle done. - * @details \b Inputs: none + * @details \b Inputs: currentFillDurationInMS, lastFillDurationInMS, biCartMaxFillCycleCount + * D66 pressure, biCartFillCycleCounter, dryBiCartFillRequested * @details \b Outputs: valve states * @return the next drybicart fill state. *************************************************************************/ @@ -432,9 +600,9 @@ * @brief * The handleDryBicartFillCompleteState function terminal for the dry bicart * fill states. - * @details \b Inputs: none + * @details \b Inputs: dryBiCartFillRequested * @details \b Outputs: valve states - * @return the next drybicart fill state. + * @return the next drybicart start state. *************************************************************************/ static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillCompleteState( void ) { @@ -456,7 +624,7 @@ * of the dry bicart fill state. * @details \b Inputs: dryBiCartFillExecState * @details \b Outputs: none - * @return the current state of dry bicart fill states. + * @return the current state of dry bicart fill exec state. *************************************************************************/ DRY_BICART_FILL_EXEC_STATE_T getCurrentDryBiCartFillExecState( void ) { @@ -469,7 +637,7 @@ * fill data publish interval. * @details \b Inputs: dryBiCartDataPublishInterval * @details \b Outputs: none - * @return the interval at dry bicart fill data being published. + * @return the interval at dry bicart fill/supply/drain data being published. *************************************************************************/ static U32 getDryBicartFillDataPublishInterval( void ) { @@ -480,74 +648,75 @@ /*********************************************************************//** * @brief - * The execBicarbChamberFillMode function executes the bicarb chamber fill - * (delivering bicarbonate from Bicart assembly to chamber F)state machine. - * @details \b Inputs: bicarbChamberFillExecState - * @details \b Outputs: bicarbChamberFillExecState - * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT when wrong bicarb chamber - * fill state invoked. - * @return current state. + * The handleBicarbChamberCartridgeFillWaterStartState function fill water in the dry bicart + * @details \b Inputs: none + * @details \b Outputs: valve states + * @return the next bicarb cartridge fill water end state. *************************************************************************/ -U32 execBicarbChamberFillMode( void ) +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberCartridgeFillWaterStartState( void ) { - // execute bicarb chamber fill state machine - switch ( bicarbChamberFillExecState ) - { - case BICARB_CHAMBER_START_STATE: - if ( TRUE == getU32OverrideValue( &bicarbChamberFillRequested ) ) - { - bicarbChamberFillExecState = BICARB_CHAMBER_CHECK_LEVEL_STATE; - bicarbChamberFillRequested.data = FALSE; - } - break; + BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CARTRIDGE_FILL_WATER_END_STATE; - case BICARB_CHAMBER_CHECK_LEVEL_STATE: - bicarbChamberFillExecState = handleBicarbChamberCheckLevelState(); - break; + // Close vent valves and descaling valve + setValveState( D81_VALV, VALVE_STATE_CLOSED ); + setValveState( D64_VALV, VALVE_STATE_CLOSED ); + setValveState( D85_VALV, VALVE_STATE_CLOSED ); - case BICARB_CHAMBER_FILL_STATE: - bicarbChamberFillExecState = handleBicarbChamberFillState(); - break; + // open inlet water to bicart + setValveState( D65_VALV, VALVE_STATE_OPEN ); - case BICARB_CHAMBER_PRESSURE_CHECK_STATE: - bicarbChamberFillExecState = handleBicarbChamberPressureCheckState(); - break; + return state; +} - default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_BICARB_CHAMBER_FILL_INVALID_EXEC_STATE, bicarbChamberFillExecState ); - break; +/*********************************************************************//** + * @brief + * The handleBicarbChamberCartridgeFillWaterStartState function stop water in the dry bicart + * @details \b Inputs: D66 pressure + * @details \b Outputs: valve states + * @return the next bicarb chamber check level state. + *************************************************************************/ +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberCartridgeFillWaterEndState( void ) +{ + BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CARTRIDGE_FILL_WATER_END_STATE; + F32 d66Pressure = getFilteredPressure( D66_PRES ); + + if ( d66Pressure >= DRY_BICART_FILL_COMPLETE_PRESSURE ) + { + // Close water inlet valve as D66 pressure reaches 15 PSI. + setValveState( D65_VALV, VALVE_STATE_CLOSED ); + state = BICARB_CHAMBER_CHECK_LEVEL_STATE; } - return bicarbChamberFillExecState; + return state; } /*********************************************************************//** * @brief * The handleBicarbChamberCheckLevelState function checks the bicarb level(D63) * in the chamber F and decides to open the bicarb inlet valve (D80). * @details \b Inputs: D63 level - * @details \b Outputs: valve states + * @details \b Outputs: valve states, dryBiCarbSupplyStartTime * @return the next bicarb chamber fill state. *************************************************************************/ static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberCheckLevelState( void ) { BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CHAMBER_CHECK_LEVEL_STATE; LEVEL_STATE_T bicarbChamberLevel = getLevelStatus( D63_LEVL ); - // Close vent valves and descaling valve - setValveState( D81_VALV, VALVE_STATE_CLOSED ); - setValveState( D64_VALV, VALVE_STATE_CLOSED ); - setValveState( D85_VALV, VALVE_STATE_CLOSED ); - // TODO: Confirm D80 open on chamber low or end of balancing chamber switching? // TODO: Enable the below code once level sensor is working //if ( LEVEL_STATE_LOW == bicarbChamberLevel ) //{ - // Open the Bicarb chamber inlet valve - setValveState( D80_VALV, VALVE_STATE_OPEN ); - // Start a timer when bicarb supply started to chamber F - dryBiCarbSupplyStartTime = getMSTimerCount(); - state = BICARB_CHAMBER_FILL_STATE; + if ( getBalancingChamberFillinProgressStatus() == FALSE ) + { + // Open the Bicarb chamber inlet valve + setValveState( D80_VALV, VALVE_STATE_OPEN ); + + // Start a timer when bicarb supply started to chamber F + dryBiCarbSupplyStartTime = getMSTimerCount(); + + state = BICARB_CHAMBER_FILL_STATE; + } //} return state; @@ -557,9 +726,9 @@ * @brief * The handleBicarbChamberFillState function checks the D66 pressure & * decides to open D65 and Close the inlet valve (D80) once level reached - * @details \b Inputs: D66 pressure sensor reading + * @details \b Inputs: D66 pressure sensor reading, D63 level * @details \b Outputs: valve states - * @return the next bicarb chamber fill state. + * @return the next bicarb chamber pressure check state. *************************************************************************/ static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberFillState( void ) { @@ -571,7 +740,7 @@ if ( LEVEL_STATE_HIGH == bicarbChamberLevel ) { setValveState( D80_VALV, VALVE_STATE_CLOSED ); - state = BICARB_CHAMBER_START_STATE; + state = BICARB_CHAMBER_PRESSURE_CHECK_STATE; } // Open water inlet valve to fill the bicart else if ( d66Pressure <= DRY_BICART_FILL_INITIATE_PRESSURE ) @@ -587,9 +756,9 @@ * @brief * The handleBicarbChamberPressureCheckStartState function actuates the vent valve * present in the Bicart assembly. - * @details \b Inputs: D66 Pressure, D63 level - * @details \b Outputs: none - * @return the next bicarb chamber fill state. + * @details \b Inputs: D66 Pressure, D63 level, dryBiCarbSupplyStartTime + * @details \b Outputs: dryBiCarbSypplyVentStartTime + * @return the next bicarb chamber Supply Vent Start state. *************************************************************************/ static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberPressureCheckState( void ) { @@ -603,7 +772,9 @@ { setValveState( D65_VALV, VALVE_STATE_CLOSED ); setValveState( D80_VALV, VALVE_STATE_CLOSED ); - state = BICARB_CHAMBER_START_STATE; + + dryBiCarbSypplyVentStartTime = getMSTimerCount(); + state = BICARB_SUPPLY_VENT_START_STATE; } // Close water inlet valve as fill is complete. @@ -617,57 +788,66 @@ /*********************************************************************//** * @brief - * The execDryBicartDrainMode function executes the dry bicart drain state machine. - * @details \b Inputs: dryBiCartDrainExecState - * @details \b Outputs: dryBiCartDrainExecState - * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT when wrong dry bicart drain state - * invoked. - * @return current state. + * The handleBicarbChamberSupplyVentStartState function actuates the vent valve + * present in the Bicart assembly. + * @details \b Inputs: dryBiCarbSypplyVentStartTime + * @details \b Outputs: dryBiCarbSypplyVentStartTime + * @return the next bicarb chamber Supply Vent End state. *************************************************************************/ -U32 execDryBicartDrainMode( void ) +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberSupplyVentStartState(void) { - // execute drybicart drain state machine - switch ( dryBiCartDrainExecState ) + BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_SUPPLY_VENT_START_STATE; + + if ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_SUPPLY_VENT_TIME_MS ) ) { - case DRY_BICART_DRAIN_START_STATE: - if ( TRUE == getU32OverrideValue( &dryBiCartDrainRequested ) ) - { - dryBiCartDrainExecState = handleDryBicartDrainStartState(); - } - break; + //Vent bicart after 1 sec + setValveState( D85_VALV, VALVE_STATE_OPEN ); + } - case DRY_BICART_FLUID_DRAIN_STATE: - dryBiCartDrainExecState = handleDryBicartFluidDrainState(); - break; + if ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_SUPPLY_VENT_MAX_TIME_MS ) ) + { + //Vent chamber F after 3 sec + setValveState( D64_VALV, VALVE_STATE_OPEN ); + dryBiCarbSypplyVentStartTime = getMSTimerCount(); + state = BICARB_SUPPLY_VENT_END_STATE; + } - case DRY_BICART_PRESSURE_EQUILLIBRIUM_STATE: - dryBiCartDrainExecState = handleDryBicartPressureEquillibriumState(); - break; + return state; +} - case DRY_BICART_FLUID_DRAIN_DURATION_CHECK_STATE: - dryBiCartDrainExecState = handleDryBicartFluidDrainDurationCheckState(); - break; +/*********************************************************************//** + * @brief + * The handleBicarbChamberSupplyVentEndState function actuates the vent valve + * present in the Bicart assembly. + * @details \b Inputs: dryBiCarbSypplyVentStartTime + * @details \b Outputs: none + * @return the next bicarb chamber start state. + *************************************************************************/ +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberSupplyVentEndState(void) +{ + BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_SUPPLY_VENT_END_STATE; - case DRY_BICART_FLUID_DRAIN_END_STATE: - dryBiCartDrainExecState = handleDryBicartFluidDrainEndState(); - break; + // close bicart vent and chamber f vent after 3 sec + if ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_SUPPLY_VENT_MAX_TIME_MS ) ) + { + setValveState( D85_VALV, VALVE_STATE_CLOSED ); + setValveState( D64_VALV, VALVE_STATE_CLOSED); - default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_DRY_BICART_DRAIN_INVALID_EXEC_STATE, dryBiCartDrainExecState ); - break; + state = BICARB_CHAMBER_START_STATE; } - return dryBiCartDrainExecState; + return state; } /*********************************************************************//** * @brief - * The handleDryBicartDrainStartState function set the one time actuation for bicarb drain request - * from dry bicarbonate cartridge. + * The handleDryBicartDrainStartState function set the one time actuation + * for bicarb drain request. * @details \b Inputs: none - * @details \b Outputs: valve states, dryBiCartDrainStartTime, dryBiCartDrainPhaseStartTime, dryBiCartDrainLastCondSampleTime, + * @details \b Outputs: valve states, dryBiCartDrainStartTime, + * dryBiCartDrainLastCondSampleTime, * dryBiCartDrainCondStableCount - * @return the next drybicart drain state. + * @return the next drybicart fluid drain state. *************************************************************************/ static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartDrainStartState( void ) { @@ -692,11 +872,10 @@ setConcentratePumpTargetSpeed( D10_PUMP, DRAIN_BICART_PUMP_SPEED, DOSING_CONT_VOLUME ); requestConcentratePumpOn( D10_PUMP ); - // Run D48 at 2300 rpm - setDialysatePumpTargetRPM( D48_PUMP, SPENT_DIAL_PUMP_INITIAL_RPM, TRUE ); + // Run D48 at 1000 rpm,There is no improvement over above 1000 rpm for drain duration. + setDialysatePumpTargetRPM( D48_PUMP, DIAL_PUMP_DRAIN_RPM, TRUE ); dryBiCartDrainStartTime = getMSTimerCount(); - dryBiCartDrainPhaseStartTime = dryBiCartDrainStartTime; dryBiCartDrainLastCondSampleTime = dryBiCartDrainStartTime; dryBiCartDrainCondStableCount = 0; @@ -707,9 +886,9 @@ * @brief * The handleDryBicartFluidDrainState function initiates the water drain * from dry bicarbonate cartridge. - * @details \b Inputs: dryBiCartDrainPhaseStartTime - * @details \b Outputs: dryBiCartDrainPhaseStartTime - * @return the next drybicart drain state. + * @details \b Inputs: none + * @details \b Outputs: none + * @return the next drybicart drain duration check state. *************************************************************************/ static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartFluidDrainState( void ) { @@ -720,62 +899,31 @@ setValveState( D81_VALV, VALVE_STATE_CLOSED ); setValveState( D85_VALV, VALVE_STATE_OPEN ); - // After a fluid drain window, go to duration/condition check (which alternates phases) - if ( TRUE == didTimeout( dryBiCartDrainPhaseStartTime, DRY_BICART_DRAIN_FLUID_PHASE_TIME_MS ) ) - { - // Open D64 valve (vent/equilibrium) - setValveState( D64_VALV, VALVE_STATE_OPEN ); - dryBiCartDrainPhaseStartTime = getMSTimerCount(); - state = DRY_BICART_PRESSURE_EQUILLIBRIUM_STATE; - } + // Open D64 valve (vent for equilibrium) + setValveState( D64_VALV, VALVE_STATE_OPEN ); + state = DRY_BICART_FLUID_DRAIN_DURATION_CHECK_STATE; return state; } /*********************************************************************//** * @brief - * The handleDryBicartPressureEquillibriumState function performs pressure - * equilibration by opening D64 while D80/D85 are open. - * @details \b Inputs: none - * @details \b Outputs: dryBiCartDrainPhaseStartTime - * @return the next drybicart drain state. - *************************************************************************/ -static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartPressureEquillibriumState( void ) -{ - DRY_BICART_DRAIN_EXEC_STATE_T state = DRY_BICART_PRESSURE_EQUILLIBRIUM_STATE; - - // After vent window, close and go to duration/condition check - if ( TRUE == didTimeout( dryBiCartDrainPhaseStartTime, DRY_BICART_DRAIN_VENT_PHASE_TIME_MS ) ) - { - setValveState( D64_VALV, VALVE_STATE_CLOSED ); - setValveState( D80_VALV, VALVE_STATE_CLOSED ); - setValveState( D85_VALV, VALVE_STATE_CLOSED ); - - dryBiCartDrainPhaseStartTime = getMSTimerCount(); - - state = DRY_BICART_FLUID_DRAIN_DURATION_CHECK_STATE; - } - - return state; -} - -/*********************************************************************//** - * @brief * The handleDryBicartFluidDrainDurationCheckState function monitors conductivity - * through D17 and D74 and determines drain completion, otherwise switch back and forth between - * DRY_BICART_FLUID_DRAIN_STATE and DRY_BICART_PRESSURE_EQUILLIBRIUM_STATE - * @details \b Inputs: P17_COND, P74_COND, dryBiCartDrainCondStableCount - * @details \b Outputs: dryBiCartDrainPhaseStartTime, dryBiCartDrainLastCondSampleTime - * @return the next drybicart drain state. + * through D17 and D74 and determines drain completion or drain complete by max timeout + * @details \b Inputs: P17_COND, P74_COND, dryBiCartDrainCondStableCount, dryBiCartDrainStartTime + * @details \b Outputs: dryBiCartDrainLastCondSampleTime + * @return the next drybicart drain end state. *************************************************************************/ static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartFluidDrainDurationCheckState( void ) { // switch back to DRY_BICART_FLUID_DRAIN_STATE if not fully drained or not timeout - DRY_BICART_DRAIN_EXEC_STATE_T state = DRY_BICART_FLUID_DRAIN_STATE; + DRY_BICART_DRAIN_EXEC_STATE_T state = DRY_BICART_FLUID_DRAIN_DURATION_CHECK_STATE; - // Max drain time fallback, it would be different for small and large bicart, + // Max drain time fall back, it is different for small and large bicart, // 4 minutes for small bicart with full of water and 8 minutes for large bicart - if ( TRUE == didTimeout( dryBiCartDrainStartTime, DRY_BICART_MAX_DRAIN_TIME_MS ) ) + // TODO: user settings should be derived for large and small dry bicart for drain time out + // right now dialin override is provided. + if ( TRUE == didTimeout( dryBiCartDrainStartTime, dryBiCartDrainTimePeriod ) ) { state = DRY_BICART_FLUID_DRAIN_END_STATE; @@ -826,18 +974,16 @@ #endif } - dryBiCartDrainPhaseStartTime = getMSTimerCount(); - return state; } /*********************************************************************//** * @brief * The handleDryBicartFluidDrainEndState function handles the end state for * draining of the fluid. - * @details \b Inputs: none + * @details \b Inputs: dryBiCartDrainRequested * @details \b Outputs: dryBiCartDrainRequested - * @return the next drybicart drain state. + * @return the next drybicart drain start state. *************************************************************************/ static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartFluidDrainEndState( void ) { @@ -855,45 +1001,6 @@ /*********************************************************************//** * @brief - * The setBicarbChamberFillRequested function sets the chmaberFillRequest - * flag value to be True. - * @details \b Inputs: none - * @details \b Outputs: bicarbChamberFillRequested - * @return none. - *************************************************************************/ -void setBicarbChamberFillRequested( void ) -{ - bicarbChamberFillRequested.data = TRUE; -} - -/*********************************************************************//** - * @brief - * The setBicartFillRequested function sets the bicart fill request - * flag value to be True. - * @details \b Inputs: none - * @details \b Outputs: dryBiCartFillRequested - * @return none. - *************************************************************************/ -void setBicartFillRequested( void ) -{ - dryBiCartFillRequested.data = TRUE; -} - -/*********************************************************************//** - * @brief - * The setBicartDrainRequested function sets the bicart drain request - * flag value to be True. - * @details \b Inputs: none - * @details \b Outputs: dryBiCartDrainRequested - * @return none. - *************************************************************************/ -void setBicartDrainRequested( void ) -{ - dryBiCartDrainRequested.data = TRUE; -} - -/*********************************************************************//** - * @brief * The publishDryBicartData function broadcasts the dry bicart * data at defined interval. * @details \b Inputs: dryBiCartDataPublicationTimerCounter @@ -918,6 +1025,8 @@ data.dryBiCartDrainRequested = getU32OverrideValue( &dryBiCartDrainRequested ); data.dryBiCartLastFillTime = lastFillDurationInMS; data.dryBiCartCurrentFillTime = currentFillDurationInMS; + data.dryBiCartType = getU32OverrideValue( &dryBiCartType ); + data.dryBiCartDrainTimePeriod = dryBiCartDrainTimePeriod; broadcastData( MSG_ID_DD_DRY_BICART_DATA, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&data, sizeof( DRY_BICART_DATA_T ) ); @@ -1003,8 +1112,8 @@ * @brief * The testDryBiCartDrainRequestOverride function starts/stops the bicart * drain request - * @details \b Inputs: bicarbChamberFillRequested - * @details \b Outputs: bicarbChamberFillRequested + * @details \b Inputs: dryBiCartDrainRequested + * @details \b Outputs: dryBiCartDrainRequested * @param message set message from Dialin which includes the bicart * drain request start/stop. * @return TRUE if set request is successful, FALSE if not @@ -1016,4 +1125,19 @@ return result; } +/*********************************************************************//** + * @brief + * The testDryBiCartTypeOverride function selects small/large cartridge type + * @details \b Inputs: dryBiCartType + * @details \b Outputs: dryBiCartType + * @param message set message from Dialin for small/large bicart type + * @return TRUE if set request is successful, FALSE if not + *************************************************************************/ +BOOL testDryBiCartTypeOverride( MESSAGE_T *message ) +{ + BOOL result = u32Override( message, &dryBiCartType, FALSE, TRUE ); + + return result; +} + /**@}*/