Index: firmware/App/Modes/ModeGenIdle.c =================================================================== diff -u -ra6dff99e22bb6f646adfe3acf4f461cb43aec979 -rab14e70c7bac24b0c3ebd02c6763285cdd3951ce --- firmware/App/Modes/ModeGenIdle.c (.../ModeGenIdle.c) (revision a6dff99e22bb6f646adfe3acf4f461cb43aec979) +++ firmware/App/Modes/ModeGenIdle.c (.../ModeGenIdle.c) (revision ab14e70c7bac24b0c3ebd02c6763285cdd3951ce) @@ -58,7 +58,6 @@ // several times to drain and fill and handle a bad fill. static DG_GEN_IDLE_MODE_BAD_FILL_STATE_T badFillState = DG_HANDLE_BAD_FILL_STATE_START; ///< Initialize bad fill sub-state. static U32 hdLostCommStartTime_ms; ///< Lost communication with HD start time in ms. -static U32 genIdlePublicationTimerCounter; ///< Used to schedule bad fill sub-states publication to CAN bus. static U32 targetFillVolumeML; ///< Save the target fill volume before calling startFillCmd(). static BOOL handleBadFillFlag; ///< Internal signal flag to handle bad fill. static HD_OP_MODE_T hdMode; ///< HD operations mode. @@ -70,15 +69,15 @@ static DG_GEN_IDLE_MODE_STATE_T handleIdleStartState( void ); static DG_GEN_IDLE_MODE_STATE_T handleFlushWaterState( void ); -static DG_GEN_IDLE_MODE_STATE_T handleBadFillState( void ); // This state has sub-states 1.0 to 1.4 +static DG_GEN_IDLE_MODE_STATE_T handleBadFillState( void ); -static DG_GEN_IDLE_MODE_BAD_FILL_STATE_T handleFirstDrainState( void ); // idle 1.0 -static DG_GEN_IDLE_MODE_BAD_FILL_STATE_T handleFlushFillState( void ); // idle 1.1 -static DG_GEN_IDLE_MODE_BAD_FILL_STATE_T handleSecondDrainState( void ); // idle 1.2 -static DG_GEN_IDLE_MODE_BAD_FILL_STATE_T handleRefillState( void ); // idle 1.3 -static DG_GEN_IDLE_MODE_BAD_FILL_STATE_T handleClearAlarmState( void ); // idle 1.4 +static DG_GEN_IDLE_MODE_BAD_FILL_STATE_T handleStartState( void ); +static DG_GEN_IDLE_MODE_BAD_FILL_STATE_T handleFirstDrainState( void ); +static DG_GEN_IDLE_MODE_BAD_FILL_STATE_T handleFlushFillState( void ); +static DG_GEN_IDLE_MODE_BAD_FILL_STATE_T handleSecondDrainState( void ); +static DG_GEN_IDLE_MODE_BAD_FILL_STATE_T handleRefillState( void ); -static void publishBadFillSubstates( void ); +static void publishBadFillSubstates( U32 badFill ); /*********************************************************************//** * @brief @@ -91,7 +90,6 @@ { genIdleState = DG_GEN_IDLE_MODE_STATE_START; hdLostCommStartTime_ms = 0; - genIdlePublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; } /*********************************************************************//** @@ -243,8 +241,6 @@ break; } - publishBadFillSubstates(); - return (U32)genIdleState; } @@ -304,30 +300,25 @@ switch ( badFillState ) { case DG_HANDLE_BAD_FILL_STATE_START: - badFillState = DG_HANDLE_BAD_FILL_STATE_FIRST_DRAIN; - requestNewOperationMode( DG_MODE_DRAI ); // go to drain mode to empty bad dialysate because this is a bad fill + badFillState = handleStartState(); break; - case DG_HANDLE_BAD_FILL_STATE_FIRST_DRAIN: // idle 1.0 + case DG_HANDLE_BAD_FILL_STATE_FIRST_DRAIN: badFillState = handleFirstDrainState(); break; - case DG_HANDLE_BAD_FILL_STATE_FLUSH_FILL: // idle 1.1 + case DG_HANDLE_BAD_FILL_STATE_FLUSH_FILL: badFillState = handleFlushFillState(); break; - case DG_HANDLE_BAD_FILL_STATE_SECOND_DRAIN: // idle 1.2. + case DG_HANDLE_BAD_FILL_STATE_SECOND_DRAIN: badFillState = handleSecondDrainState(); break; case DG_HANDLE_BAD_FILL_STATE_REFILL: - badFillState = handleRefillState(); // idle 1.3 + badFillState = handleRefillState(); break; - case DG_HANDLE_BAD_FILL_STATE_CLEAR_ALARM: - badFillState = handleClearAlarmState(); // idle 1.4 - break; - default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_GEN_IDLE_MODE_INVALID_EXEC_STATE, genIdleState ) badFillState = DG_HANDLE_BAD_FILL_STATE_START; @@ -339,6 +330,27 @@ /*********************************************************************//** * @brief + * The handleStartState function executes the start state of the handle bad + * fill state machine. + * @details Inputs: none + * @details Outputs: none + * @return the next state + *************************************************************************/ +static DG_GEN_IDLE_MODE_BAD_FILL_STATE_T handleStartState( void ) +{ + DG_GEN_IDLE_MODE_BAD_FILL_STATE_T state = DG_HANDLE_BAD_FILL_STATE_FIRST_DRAIN; + + // Publish the state prior to requesting a drain and transitioning to drain mode + publishBadFillSubstates( state ); + + // Drain the bad filled reservoir first + requestNewOperationMode( DG_MODE_DRAI ); + + return state; +} + +/*********************************************************************//** + * @brief * The handleFirstDrainState function executes the first drain state of the * handle bad fill state machine. * @details Inputs: none @@ -347,15 +359,26 @@ *************************************************************************/ static DG_GEN_IDLE_MODE_BAD_FILL_STATE_T handleFirstDrainState( void ) { - DG_GEN_IDLE_MODE_BAD_FILL_STATE_T state = DG_HANDLE_BAD_FILL_STATE_FIRST_DRAIN; // after first drain is completed, go to next bad fill sub-state + DG_GEN_IDLE_MODE_BAD_FILL_STATE_T state = DG_HANDLE_BAD_FILL_STATE_FIRST_DRAIN; - if ( FALSE == isAlarmActive( ALARM_ID_FILL_CONDUCTIVITY_OUT_OF_RANGE ) ) // alarm is no longer active - cleared by user + // Check if the alarm has been cleared by the user and if yes, continue with the fill + if ( FALSE == isAlarmActive( ALARM_ID_FILL_CONDUCTIVITY_OUT_OF_RANGE ) ) { - targetFillVolumeML = getTargetFillVolumeML(); // save the HD target fill volume before command 1000 mL fill volume - startFillCmd( BAD_FLUSH_FILL_TARGET_VOLUME_ML, getTargetFillFlowRateLPM() ); + // Save the HD target fill volume before command 1000 mL fill volume + targetFillVolumeML = getTargetFillVolumeML(); state = DG_HANDLE_BAD_FILL_STATE_FLUSH_FILL; + + // Publish the state prior to transitioning to fill mode + publishBadFillSubstates( state ); + + // Start the flush fill + startFillCmd( BAD_FLUSH_FILL_TARGET_VOLUME_ML, getTargetFillFlowRateLPM() ); } + else + { + publishBadFillSubstates( state ); + } return state; } @@ -372,23 +395,11 @@ { DG_GEN_IDLE_MODE_BAD_FILL_STATE_T state = DG_HANDLE_BAD_FILL_STATE_SECOND_DRAIN; - requestNewOperationMode( DG_MODE_DRAI ); // go to drain mode to empty bad dialysate because this is a bad fill + // Publish the state prior to transitioning to drain mode + publishBadFillSubstates( state ); - /*if ( FALSE == isAlarmActive( ALARM_ID_FILL_CONDUCTIVITY_OUT_OF_RANGE ) ) // alarm is no longer active - cleared by user - { - targetFillVolumeML = getTargetFillVolumeML(); // save the HD target fill volume before command 1000 mL fill volume - startFillCmd( BAD_FLUSH_FILL_TARGET_VOLUME_ML, getTargetFillFlowRateLPM() ); + requestNewOperationMode( DG_MODE_DRAI ); - if ( TRUE == handleBadFillFlag ) - { - result = DG_HANDLE_BAD_FILL_STATE_FIRST_DRAIN; // (idle 1.0) - } - else - { - result = DG_HANDLE_BAD_FILL_STATE_SECOND_DRAIN; // (idle 1.2) - } - }*/ - return state; } @@ -402,11 +413,13 @@ *************************************************************************/ static DG_GEN_IDLE_MODE_BAD_FILL_STATE_T handleSecondDrainState( void ) { - DG_GEN_IDLE_MODE_BAD_FILL_STATE_T state = DG_HANDLE_BAD_FILL_STATE_CLEAR_ALARM; // after second drain completed, go to refill sub-state (idle 1.3) + DG_GEN_IDLE_MODE_BAD_FILL_STATE_T state = DG_HANDLE_BAD_FILL_STATE_REFILL; - //requestNewOperationMode( DG_MODE_DRAI ); // go to drain mode to empty bad dialysate because this is a bad fill + // Publish the state prior to transitioning to fill mode + publishBadFillSubstates( state ); - startFillCmd( targetFillVolumeML, getTargetFillFlowRateLPM() ); // refill to the saved target fill volume (~1500 mL) + // Refill to the saved target fill volume (~1500 mL) + startFillCmd( targetFillVolumeML, getTargetFillFlowRateLPM() ); return state; } @@ -421,53 +434,34 @@ *************************************************************************/ static DG_GEN_IDLE_MODE_BAD_FILL_STATE_T handleRefillState( void ) { - DG_GEN_IDLE_MODE_BAD_FILL_STATE_T result = DG_HANDLE_BAD_FILL_STATE_CLEAR_ALARM; // (idle 1.4) + DG_GEN_IDLE_MODE_BAD_FILL_STATE_T state = DG_HANDLE_BAD_FILL_STATE_START; - startFillCmd( targetFillVolumeML, getTargetFillFlowRateLPM() ); // refill to the saved target fill volume (~1500 mL) + publishBadFillSubstates( state ); - return result; -} - -/*********************************************************************//** - * @brief - * The handleClearAlarmState function executes the clear alarm state of the - * handle bad fill state machine. - * @details Inputs: none - * @details Outputs: none - * @return the next state - *************************************************************************/ -static DG_GEN_IDLE_MODE_BAD_FILL_STATE_T handleClearAlarmState( void ) -{ - DG_GEN_IDLE_MODE_BAD_FILL_STATE_T result = DG_HANDLE_BAD_FILL_STATE_START; - - // clear wait for dialysate alarm condition to allow resume + // Clear wait for dialysate alarm condition to allow resume clearAlarmCondition( ALARM_ID_CREATING_DIALYSATE_PLEASE_WAIT ); // resume option will appear - handleBadFillFlag = FALSE; // set flag to FALSE here so next call to idle exec will move to normal flush water state - genIdleState = DG_GEN_IDLE_MODE_STATE_START; + // Set flag to FALSE here so next call to idle exec will move to normal flush water state + handleBadFillFlag = FALSE; - return result; + return state; } /*********************************************************************//** * @brief * The publishBadFillSubstates function publishes idle mode bad fill * sub-states at the set interval. - * @details Inputs: genIdlePublicationTimerCounter - * @details Outputs: genIdlePublicationTimerCounter + * @details Inputs: none + * @details Outputs: none + * @param badFill the bad fill state that has to be published * @return none *************************************************************************/ -static void publishBadFillSubstates( void ) +static void publishBadFillSubstates( U32 badFill ) { - // publish bad fill sub-states on interval - if ( ++genIdlePublicationTimerCounter >= getU32OverrideValue( &badFillSubstatesPublishInterval ) ) - { - GEN_IDLE_BAD_FILL_STATE data; + GEN_IDLE_BAD_FILL_STATE data; - data.badFillState = (U32)badFillState; + data.badFillState = badFill; - broadcastData( MSG_ID_DG_BAD_FILL_SUB_STATE, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&data, sizeof( GEN_IDLE_BAD_FILL_STATE ) ); - genIdlePublicationTimerCounter = 0; - } + broadcastData( MSG_ID_DG_BAD_FILL_SUB_STATE, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&data, sizeof( GEN_IDLE_BAD_FILL_STATE ) ); }