Index: firmware/App/Modes/ModeGenDialysate.c =================================================================== diff -u -re6415d33321e7990c3b5e82b0c8a87c64cc3a2c8 -ra711f7995e555b503ed8c295f98fbe7bb9e5abf5 --- firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision e6415d33321e7990c3b5e82b0c8a87c64cc3a2c8) +++ firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision a711f7995e555b503ed8c295f98fbe7bb9e5abf5) @@ -75,6 +75,8 @@ static OVERRIDE_F32_T targetHydChamberFluidTemp; ///< Target hydraulics chamber fluid temperature. static OVERRIDE_U32_T isDialDeliveryInProgress; ///< To indicate dialysate started delivering to dialyzer for treatment (overrideable) static OVERRIDE_U32_T isDialysateGoodtoDeliver; ///< Flag indicating whether ready to deliver dialysate or not. +static BOOL pendingSpentChamberFill; ///< Flag indicating spent chamber fill process to be initiated. +static BOOL pendingBicarbChamberFill; ///< Flag indicating bicarb chamber fill process to be initiated. static BOOL pendingStopDDGenDialRequest; ///< Flag indicating TD has requested DD stop the generate dialysate. static U32 genDialysateDataPublicationTimerCounter; ///< Used to schedule generate dialysate data publication to CAN bus. static OVERRIDE_U32_T genDialysateDataPublishInterval; ///< Generate dialysate mode data publish interval. @@ -96,6 +98,7 @@ static F32 getGenDialysateTargetTemperature( void ); static void calculateTargetDialysateTemp( void ); static void checkDialysateTemperature( void ); +static void monitorChamberLevelStatus( void ); static void publishGenDialysateModeData( void ); /*********************************************************************//** @@ -128,6 +131,8 @@ genDialysateDataPublicationTimerCounter = 0; isTreatmentParamUpdated = FALSE; bicarbFillStartTimeMS = 0; + pendingSpentChamberFill = FALSE; + pendingBicarbChamberFill = FALSE; //Testing bypassStateDelayStartTimeMS = 0; delayBypassStateFlag = TRUE; @@ -201,13 +206,13 @@ break; case DD_GEND_DIALYSATE_BYPASS_STATE: - //Close all balancing chamber valves - valveControlForBCClosedState(); setValveState( DD_M4_VALV, VALVE_STATE_OPEN ); setValveState( D14_VALV, VALVE_STATE_OPEN ); setValveState( D53_VALV, VALVE_STATE_OPEN ); // Drain valve setValveState( D35_VALV, VALVE_STATE_CLOSED ); // VDI setValveState( D40_VALV, VALVE_STATE_CLOSED ); // VDO + setValveState( D47_VALV, VALVE_STATE_CLOSED ); // spent chamber purge valve + setValveState( D64_VALV, VALVE_STATE_CLOSED ); setValveState( D34_VALV, VALVE_STATE_OPEN ); // Bypass valve // Turn on the primary heater @@ -231,6 +236,8 @@ case DD_GEND_DIALYSATE_DELIVERY_STATE: //Previous state + setValveState( D47_VALV, VALVE_STATE_CLOSED ); // spent chamber purge valve + setValveState( D64_VALV, VALVE_STATE_CLOSED ); setValveState( DD_M4_VALV, VALVE_STATE_OPEN ); setValveState( D14_VALV, VALVE_STATE_OPEN ); setValveState( D53_VALV, VALVE_STATE_OPEN ); // Drain valve @@ -253,8 +260,6 @@ break; case DD_GEND_SPENT_CHAMBER_FILL_STATE: - //Close all balancing chamber valves - valveControlForBCClosedState(); //Set valves and actuators setValveState( D35_VALV, VALVE_STATE_CLOSED ); // VDI setValveState( D40_VALV, VALVE_STATE_CLOSED ); // VDO @@ -283,14 +288,12 @@ break; case DD_GEND_BICARB_CHAMBER_FILL_STATE: - //Close all balancing chamber valves - valveControlForBCClosedState(); requestConcentratePumpOff( D11_PUMP, FALSE ); requestConcentratePumpOff( D10_PUMP, FALSE ); requestConcentratePumpOff( D76_PUMP, FALSE ); //Set valves and actuators - setValveState( D47_VALV, VALVE_STATE_CLOSED ); // Spent chamber purge valve + setValveState( D47_VALV, VALVE_STATE_CLOSED ); // spent chamber purge valve setValveState( D35_VALV, VALVE_STATE_CLOSED ); // VDI setValveState( D40_VALV, VALVE_STATE_CLOSED ); // VDO setValveState( D14_VALV, VALVE_STATE_CLOSED ); @@ -363,6 +366,9 @@ //Check temperature drift between D30 and D28 checkDialysateTemperatureSensors(); + //Monitor spent and bicarb chamber level + monitorChamberLevelStatus(); + //TODO: Transition to post gen dialysate then standby. if ( TRUE == pendingStopDDGenDialRequest ) { @@ -453,6 +459,30 @@ /*********************************************************************//** * @brief + * The monitorChamberLevelStatus function checks the spent chamber and bicarb + * chamber level status and updates the corrosponding flags. + * @details \b Inputs: Spent and bicarb chamber levels. + * @details \b Outputs: none + * @return none + *************************************************************************/ +static void monitorChamberLevelStatus( void ) +{ + LEVEL_STATE_T spentChamberLevel = getLevelStatus( D46_LEVL ); + LEVEL_STATE_T bicarbChamberLevel = getLevelStatus( D63_LEVL ); + + if ( LEVEL_STATE_LOW == spentChamberLevel ) + { + pendingSpentChamberFill = TRUE; + } + + if ( LEVEL_STATE_LOW == bicarbChamberLevel ) + { + pendingBicarbChamberFill = TRUE; + } +} + +/*********************************************************************//** + * @brief * The calculateTargetDialysateTemp function calculate the delta temperature * required for dialysate temperature to meet the set temperature at dialyzer. * @details \b Inputs: Qd and target temperature. @@ -510,9 +540,8 @@ *************************************************************************/ static DD_GEND_MODE_STATE_T handleGenDDialysateBypassState( void ) { - DD_GEND_MODE_STATE_T state = DD_GEND_DIALYSATE_BYPASS_STATE; - LEVEL_STATE_T spentChamberLevel = getLevelStatus( D46_LEVL ); - LEVEL_STATE_T bicarbChamberLevel = getLevelStatus( D63_LEVL ); + DD_GEND_MODE_STATE_T state = DD_GEND_DIALYSATE_BYPASS_STATE; + BOOL balancingChambFillInProgress = getBalancingChamberFillinProgressStatus(); //Testing if ( TRUE == delayBypassStateFlag ) @@ -529,17 +558,19 @@ } #ifdef __SPENT_CHAMBER_FILL__ - if ( LEVEL_STATE_LOW == spentChamberLevel ) + if ( ( TRUE == pendingSpentChamberFill ) && ( FALSE == balancingChambFillInProgress ) ) { setModeGenDStateTransition( DD_GEND_SPENT_CHAMBER_FILL_STATE ); + pendingSpentChamberFill = FALSE; isDialDeliveryInProgress.data = FALSE; state = DD_GEND_SPENT_CHAMBER_FILL_STATE; } #endif #ifdef __BICARB_CHAMBER_FILL__ - if ( LEVEL_STATE_LOW == bicarbChamberLevel ) + if ( ( TRUE == pendingBicarbChamberFill ) && ( FALSE == balancingChambFillInProgress ) ) { setModeGenDStateTransition( DD_GEND_BICARB_CHAMBER_FILL_STATE ); + pendingBicarbChamberFill = FALSE; isDialDeliveryInProgress.data = FALSE; state = DD_GEND_BICARB_CHAMBER_FILL_STATE; } @@ -579,17 +610,19 @@ state = DD_GEND_DIALYSATE_BYPASS_STATE; } #ifdef __SPENT_CHAMBER_FILL__ - else if ( LEVEL_STATE_LOW == spentChamberLevel ) + else if ( ( TRUE == pendingSpentChamberFill ) && ( FALSE == balancingChambFillInProgress ) ) { setModeGenDStateTransition( DD_GEND_SPENT_CHAMBER_FILL_STATE ); + pendingSpentChamberFill = FALSE; isDialDeliveryInProgress.data = FALSE; state = DD_GEND_SPENT_CHAMBER_FILL_STATE; } #endif #ifdef __BICARB_CHAMBER_FILL__ - else if ( LEVEL_STATE_LOW == bicarbChamberLevel ) + else if ( ( TRUE == pendingBicarbChamberFill ) && ( FALSE == balancingChambFillInProgress ) ) { setModeGenDStateTransition( DD_GEND_BICARB_CHAMBER_FILL_STATE ); + pendingBicarbChamberFill = FALSE; isDialDeliveryInProgress.data = FALSE; state = DD_GEND_BICARB_CHAMBER_FILL_STATE; }