Index: firmware/App/Modes/ModePostTreat.c =================================================================== diff -u -raa7b1f5f68aae23c1c52b32658fcb625c29accfb -r269317d07ab6ccbff5294953d2ecc1cbc43336ab --- firmware/App/Modes/ModePostTreat.c (.../ModePostTreat.c) (revision aa7b1f5f68aae23c1c52b32658fcb625c29accfb) +++ firmware/App/Modes/ModePostTreat.c (.../ModePostTreat.c) (revision 269317d07ab6ccbff5294953d2ecc1cbc43336ab) @@ -62,6 +62,7 @@ static BOOL disposableRemovalConfirmed; ///< Flag indicates user confirms disposable removal. static BOOL rinseConcentrateLines; ///< FLag indicates to rinse concentrate lines. static BOOL isThisFirstDrain; ///< Flag to indicate whether this is the first time the reservoir is drained. +static BOOL dgCommandSent; ///< Flag indicates whether a DG command has been already sent. static HD_POST_TREATMENT_STATE_T currentPostTreatmentState; ///< Current state of post-treatment mode state machine. static DRAIN_STATE_T currentDrainReservoirState; ///< Current drain reservoir state. static U32 postTreatmentPublishTimerCounter; ///< Timer counter used to schedule post-treatment data broadcast. @@ -88,7 +89,8 @@ * @details Inputs: none * @details Outputs: patientDisconnectionConfirmed, disposableRemovalConfirmed, * rinseConcentrateLines, isThisFirstDrain, currentPostTreatmentState, - * currentDrainReservoirState, postTreatmentPublishTimerCounter, treatmentLogData + * currentDrainReservoirState, postTreatmentPublishTimerCounter, treatmentLogData, + * dgCommandSent * @return none *************************************************************************/ void initPostTreatmentMode( void ) @@ -97,6 +99,7 @@ disposableRemovalConfirmed = FALSE; rinseConcentrateLines = FALSE; isThisFirstDrain = TRUE; + dgCommandSent = FALSE; currentPostTreatmentState = HD_POST_TREATMENT_DRAIN_RESERVOIRS_STATE; currentDrainReservoirState = DRAIN_RESERVOIR_SWITCH_STATE; postTreatmentPublishTimerCounter = 0; @@ -528,8 +531,8 @@ * @brief * The handleDrainReservoirSwitchState function waits for DG to complete * reservoir switch. - * @details Inputs: isThisFirstDrain - * @details Outputs: rinseConcentrateLines + * @details Inputs: isThisFirstDrain, dgCommandSent + * @details Outputs: rinseConcentrateLines, dgCommandSent * @return next state *************************************************************************/ static DRAIN_STATE_T handleDrainReservoirSwitchState( void ) @@ -538,20 +541,36 @@ if ( ( DG_MODE_GENE == getDGOpMode() ) && ( DG_GEN_IDLE_MODE_STATE_FLUSH_WATER == getDGSubMode() ) ) { - DG_SWITCH_RSRVRS_CMD_T rsrvrCmd; + DG_CMD_RESPONSE_T dgCmdResp; - // The first drain starts with setting the reservoir 2 as active and then the first reservoir is drained - rsrvrCmd.reservoirID = (U32)( TRUE == isThisFirstDrain ? DG_RESERVOIR_2 : DG_RESERVOIR_1 ); - rsrvrCmd.useLastTrimmerHeaterDC = FALSE; + if ( FALSE == dgCommandSent ) + { + DG_SWITCH_RSRVRS_CMD_T rsrvrCmd; - cmdSetDGActiveReservoir( &rsrvrCmd ); + // The first drain starts with setting the reservoir 2 as active and then the first reservoir is drained + rsrvrCmd.reservoirID = (U32)( TRUE == isThisFirstDrain ? DG_RESERVOIR_2 : DG_RESERVOIR_1 ); + rsrvrCmd.useLastTrimmerHeaterDC = FALSE; + dgCommandSent = TRUE; - if ( TRUE == hasDGCompletedReservoirSwitch() ) + cmdSetDGActiveReservoir( &rsrvrCmd ); + } + else if ( TRUE == getDGCommandResponse( DG_CMD_SWITCH_RESERVOIR, &dgCmdResp ) ) { - // Check if the reservoir switch has been completed - // If this is the first drain, rinse the concentrate lines too - rinseConcentrateLines = ( TRUE == isThisFirstDrain ? TRUE : FALSE ); - state = DRAIN_RESERVOIR_START_DRAIN_STATE; + if ( DG_CMD_REQUEST_REJECT_REASON_NONE == dgCmdResp.rejectCode ) + { + if ( TRUE == hasDGCompletedReservoirSwitch() ) + { + // Check if the reservoir switch has been completed + // If this is the first drain, rinse the concentrate lines too + rinseConcentrateLines = ( TRUE == isThisFirstDrain ? TRUE : FALSE ); + dgCommandSent = FALSE; + state = DRAIN_RESERVOIR_START_DRAIN_STATE; + } + } + else + { + dgCommandSent = FALSE; + } } } @@ -562,8 +581,8 @@ * @brief * The handleDrainReservoirStartDrainState function sends command to DG to * send the drain command to DG. - * @details Inputs: rinseConcentrateLines - * @details Outputs: none + * @details Inputs: rinseConcentrateLines, dgCommandSent + * @details Outputs: dgCommandSent * @return next state *************************************************************************/ static DRAIN_STATE_T handleDrainReservoirStartDrainState( void ) @@ -575,16 +594,28 @@ DG_CMD_RESPONSE_T dgCmdResp; // If DG is still in the Idle mode in the flush water state and the drain command has not been sent, send the drain command - if ( FALSE == getDGCommandResponse( DG_CMD_START_DRAIN, &dgCmdResp ) ) + if ( FALSE == dgCommandSent ) { cmdStartDGDrain( DRAIN_RESERVOIR_TO_VOLUME_ML, TRUE, rinseConcentrateLines, TRUE ); + dgCommandSent = TRUE; } + else if ( TRUE == getDGCommandResponse( DG_CMD_START_DRAIN, &dgCmdResp ) ) + { + if ( DG_CMD_REQUEST_REJECT_REASON_NONE == dgCmdResp.rejectCode ) + { + if ( DG_MODE_DRAI == getDGOpMode() ) + { + // If the drain has started, transition to drain state + dgCommandSent = FALSE; + state = DRAIN_RESERVOIR_DRAIN_STATE; + } + } + else + { + dgCommandSent = FALSE; + } + } } - else if ( DG_MODE_DRAI == getDGOpMode() ) - { - // If the drain has started, transition to drain state - state = DRAIN_RESERVOIR_DRAIN_STATE; - } return state; }