Index: firmware/App/Modes/ModePostTreat.c =================================================================== diff -u -r648d1d3e60202ed80569a701df6666a143f5d0e8 -r44e745e602377ae878e1d31f0469cdcc47248ace --- firmware/App/Modes/ModePostTreat.c (.../ModePostTreat.c) (revision 648d1d3e60202ed80569a701df6666a143f5d0e8) +++ firmware/App/Modes/ModePostTreat.c (.../ModePostTreat.c) (revision 44e745e602377ae878e1d31f0469cdcc47248ace) @@ -8,7 +8,7 @@ * @file ModePostTreat.c * * @author (last) Dara Navaei -* @date (last) 03-Nov-2022 +* @date (last) 08-Dec-2022 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 @@ -67,6 +67,7 @@ static BOOL isThisFirstDrain; ///< Flag to indicate whether this is the first time the reservoir is drained. static BOOL drainDGDePrimeActive; ///< FLag to indicate DePrime DG Dialysate lines active static U32 drainDGDePrimeStarttime; ///< DG DePrime start time +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. @@ -94,7 +95,8 @@ * @details Inputs: none * @details Outputs: patientDisconnectionConfirmed, disposableRemovalConfirmed, * rinseConcentrateLines, isThisFirstDrain, currentPostTreatmentState, - * currentDrainReservoirState, postTreatmentPublishTimerCounter, treatmentLogData + * currentDrainReservoirState, postTreatmentPublishTimerCounter, treatmentLogData, + * dgCommandSent * @return none *************************************************************************/ void initPostTreatmentMode( void ) @@ -103,6 +105,7 @@ disposableRemovalConfirmed = FALSE; rinseConcentrateLines = FALSE; isThisFirstDrain = TRUE; + dgCommandSent = FALSE; currentPostTreatmentState = HD_POST_TREATMENT_DRAIN_RESERVOIRS_STATE; currentDrainReservoirState = DRAIN_DG_DEPRIME_STATE; postTreatmentPublishTimerCounter = 0; @@ -576,8 +579,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 ) @@ -586,20 +589,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; + } } } @@ -610,8 +629,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 ) @@ -623,15 +642,21 @@ 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 ) ) && ( dgCmdResp.rejectCode != DG_CMD_REQUEST_REJECT_REASON_NONE ) ) + { + dgCommandSent = FALSE; + } } else if ( DG_MODE_DRAI == getDGOpMode() ) { // If the drain has started, transition to drain state - state = DRAIN_RESERVOIR_DRAIN_STATE; + dgCommandSent = FALSE; + state = DRAIN_RESERVOIR_DRAIN_STATE; } return state;