Index: firmware/App/Modes/ModePostTreat.c =================================================================== diff -u -r29b362c485f28f45ef367342ac895e1c1907ac45 -rcd21cbb4e733bfdf52f83bdca7a905645022c572 --- firmware/App/Modes/ModePostTreat.c (.../ModePostTreat.c) (revision 29b362c485f28f45ef367342ac895e1c1907ac45) +++ firmware/App/Modes/ModePostTreat.c (.../ModePostTreat.c) (revision cd21cbb4e733bfdf52f83bdca7a905645022c572) @@ -8,7 +8,7 @@ * @file ModePostTreat.c * * @author (last) Dara Navaei -* @date (last) 31-Mar-2022 +* @date (last) 08-Dec-2022 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 @@ -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; @@ -120,11 +123,15 @@ // Stop any DG fill that may be in progress from an aborted treatment cmdStopDGFill(); + syringeDetectionRequired( FALSE ); + // Set user alarm recovery actions allowed in this mode setAlarmUserActionEnabled( ALARM_USER_ACTION_RESUME, FALSE ); setAlarmUserActionEnabled( ALARM_USER_ACTION_RINSEBACK, FALSE ); setAlarmUserActionEnabled( ALARM_USER_ACTION_END_TREATMENT, FALSE ); + doorClosedRequired( FALSE, FALSE ); + cmdStopDGTrimmerHeater(); setValvePosition( VDI, VALVE_POSITION_C_CLOSE ); @@ -324,7 +331,7 @@ *************************************************************************/ void signalAlarmActionToPostTreatmentMode( ALARM_ACTION_T action ) { - + // Do nothing for now } /*********************************************************************//** @@ -345,6 +352,7 @@ { // Done with draining the reservoirs state = HD_POST_TREATMENT_PATIENT_DISCONNECTION_STATE; + doorClosedRequired( TRUE, TRUE ); } return state; @@ -368,14 +376,6 @@ OPN_CLS_STATE_T frontDoor = getSwitchStatus( FRONT_DOOR ); OPN_CLS_STATE_T pumpTrack = getSwitchStatus( PUMP_TRACK_SWITCH ); -#ifndef _RELEASE_ - if ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_DISABLE_SWITCHES_MONITOR ) ) - { - frontDoor = STATE_CLOSED; - pumpTrack = STATE_CLOSED; - } -#endif - if ( ( STATE_CLOSED == frontDoor ) && ( STATE_CLOSED == pumpTrack ) ) { #ifndef _RELEASE_ @@ -399,25 +399,15 @@ homeDialInPump(); homeDialOutPump(); + doorClosedRequired( FALSE, FALSE ); + if ( ( bolusVol > 0.0 ) || ( hepRate > 0.0 ) ) { retractSyringePump(); } } } - else - { - if ( STATE_OPEN == frontDoor ) - { - activateAlarmNoData( ALARM_ID_CARTRIDGE_DOOR_OPENED ); - } - if ( STATE_OPEN == pumpTrack ) - { - activateAlarmNoData( ALARM_ID_PUMP_TRACK_LATCH_OPENED ); - } - } - return state; } @@ -482,29 +472,18 @@ if ( TRUE == isSyringeDetected() ) { #ifndef _RELEASE_ - if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_SYRINGE_PUMP ) != SW_CONFIG_ENABLE_VALUE ) + if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_SYRINGE_PUMP_ALARMS ) != SW_CONFIG_ENABLE_VALUE ) #endif { activateAlarmNoData( ALARM_ID_HD_SYRINGE_DETECTED ); } } - else - { - clearAlarmCondition( ALARM_ID_HD_SYRINGE_DETECTED ); - } // Wait for cartridge and syringe to be removed and for DG to finish any drains/fills. if ( TRUE == isCartridgeRemoved ) { BOOL isSyringePumpDetected = isSyringeDetected(); -#ifndef _RELEASE_ - if ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_DISABLE_SYRINGE_PUMP ) ) - { - isSyringePumpDetected = FALSE; - } -#endif - if ( FALSE == isSyringePumpDetected ) { cmdStopDG(); @@ -552,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 ) @@ -562,17 +541,36 @@ if ( ( DG_MODE_GENE == getDGOpMode() ) && ( DG_GEN_IDLE_MODE_STATE_FLUSH_WATER == getDGSubMode() ) ) { - // The first drain starts with setting the reservoir 2 as active and then the first reservoir is drained - DG_RESERVOIR_ID_T id = ( TRUE == isThisFirstDrain ? DG_RESERVOIR_2 : DG_RESERVOIR_1 ); + DG_CMD_RESPONSE_T dgCmdResp; - cmdSetDGActiveReservoir( id ); + if ( FALSE == dgCommandSent ) + { + DG_SWITCH_RSRVRS_CMD_T rsrvrCmd; - if ( TRUE == hasDGCompletedReservoirSwitch() ) + // 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; + + 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; + } } } @@ -583,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 ) @@ -596,15 +594,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;