Index: firmware/App/Modes/ModePreTreat.c =================================================================== diff -u -r0a62c26f8c74795bd1a695de879e1a33524481ed -rb74d08ff24839ebbea51582772ed2b9588558ea0 --- firmware/App/Modes/ModePreTreat.c (.../ModePreTreat.c) (revision 0a62c26f8c74795bd1a695de879e1a33524481ed) +++ firmware/App/Modes/ModePreTreat.c (.../ModePreTreat.c) (revision b74d08ff24839ebbea51582772ed2b9588558ea0) @@ -15,15 +15,10 @@ * ***************************************************************************/ -#include "BloodFlow.h" #include "Buttons.h" -#include "Messaging.h" #include "ModePreTreat.h" #include "OperationModes.h" -#include "PeristalticPump.h" -#include "Switches.h" -#include "TaskGeneral.h" -#include "TDDefs.h" +#include "StateServices/TubeSetInstall.h" #include "Timers.h" #include "TxParams.h" @@ -34,19 +29,7 @@ // ********** private definitions ********** -///< Auto-Load timeout interval (ms/task time) -#define AUTO_LOAD_TIMEOUT_INTERVAL ( ( 10 * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ) - -//< Blood pump flow rate (mL/min) for Auto-Load operation -#define AUTO_LOAD_BLOOD_FLOW_RATE_ML_MIN 100U - -// ********** private data ********** - -static BOOL confirmTubesetPlaced; ///< Flag indicating user has confirmed tubeset is placed -static U32 autoLoadTimerCounter; ///< Auto-Load operation timer counter - static TD_PRE_TREATMENT_MODE_STATE_T currentPreTreatmentState; ///< Current Pre-Treatment sub-state -static PRE_TX_INSTALL_STATE_T currentPreTxInstallState; ///< Current Pre-Treatment Install sub-state // ********** private function prototypes ********** @@ -60,9 +43,6 @@ static TD_PRE_TREATMENT_MODE_STATE_T handleRxState( void ); ///< Handle Confirm Rx state during Pre-Treatment static TD_PRE_TREATMENT_MODE_STATE_T handlePatientConnectionState( void ); ///< Handle Patient Connection state during Pre-Treatment -static PRE_TX_INSTALL_STATE_T handleAwaitTubesetConfirmationState( void ); ///< Handle Await Tubset Install Confirmation sub-state -static PRE_TX_INSTALL_STATE_T handleAutoLoadState( void ); ///< Handle Auto-Load sub-state - /*********************************************************************//** * @brief * The initPreTreatmentMode function initializes the Pre-Treatment mode. @@ -76,9 +56,6 @@ // Start a fresh Treatment Parameters session for this run. resetTreatmentParameters(); currentPreTreatmentState = TD_PRE_TREATMENT_TUBING_SET_INSTALL_STATE; - currentPreTxInstallState = PRE_TX_INSTALL_STATE_AWAIT_TUBING_SET_CONFIRMATION; - confirmTubesetPlaced = FALSE; - autoLoadTimerCounter = 0; } /*********************************************************************//** @@ -93,6 +70,7 @@ U32 transitionToPreTreatmentMode( void ) { initPreTreatmentMode(); + initTubeSetInstall(); return (U32)currentPreTreatmentState; } @@ -219,35 +197,23 @@ /*********************************************************************//** * @brief - * The handleInstallState function executes the Pre-Treatment Install - * state machine. - * @details Inputs: currentPreTxInstallState - * @details Outputs: Advances the Pre-Treatment Install sub-state and - * next Pre-Treatment top-level state when install is complete. - * @return current Pre-Treatment state. + * The handleInstallState function calls Tube Set Install Service and + * advances to Self Test Dry state once the service signals + * completion. + * @details Inputs: none + * @details Outputs: Advances Pre-Treatment state when install is complete. + * @return next Pre-Treatment mode state *************************************************************************/ static TD_PRE_TREATMENT_MODE_STATE_T handleInstallState( void ) { TD_PRE_TREATMENT_MODE_STATE_T state = TD_PRE_TREATMENT_TUBING_SET_INSTALL_STATE; - switch(currentPreTxInstallState) - { - case PRE_TX_INSTALL_STATE_AWAIT_TUBING_SET_CONFIRMATION: - currentPreTxInstallState = handleAwaitTubesetConfirmationState(); - break; + // call tube set install service to auto-load tube set + execTubeSetInstall(); - case PRE_TX_INSTALL_STATE_AUTO_LOAD: - currentPreTxInstallState = handleAutoLoadState(); - - if ( NUM_OF_PRE_TX_INSTALL_SUB_STATES == currentPreTxInstallState ) - { - state = TD_PRE_TREATMENT_SELF_TEST_DRY_STATE; - } - break; - - default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_PRE_TX_INSTALL_INVALID_STATE, (U32)currentPreTxInstallState ); - break; + if ( TRUE == isTubeSetInstallComplete() ) + { + state = TD_PRE_TREATMENT_SELF_TEST_DRY_STATE; } return state; @@ -351,104 +317,16 @@ /*********************************************************************//** * @brief - * The handleAwaitTubesetConfirmationState function handles the Await - * tubeset confirmation state of Pre-Treatement mode install state - * machine. Should wait for the user to confirm the tubeset is placed, - * and verifies that the blood pump door (H9) is closed. - * @details Inputs: confirmTubsetPlaced - * @details Outputs: confirmTubesetPlaced - * return next Pre-Treatment Install sub-state - *************************************************************************/ -static PRE_TX_INSTALL_STATE_T handleAwaitTubesetConfirmationState( void ) -{ - PRE_TX_INSTALL_STATE_T subState = PRE_TX_INSTALL_STATE_AWAIT_TUBING_SET_CONFIRMATION; - - if ( TRUE == confirmTubesetPlaced ) - { - // Door closed required from Auto-loading onwards, set to false if not required in subsequent states - doorClosedRequired( TRUE ); - - if ( STATE_CLOSED == getSwitchState( H9_SWCH ) ) - { - confirmTubesetPlaced = FALSE; - setBloodPumpTargetFlowRate( AUTO_LOAD_BLOOD_FLOW_RATE_ML_MIN, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); - subState = PRE_TX_INSTALL_STATE_AUTO_LOAD; - } - } - - return subState; -} - -/*********************************************************************//** - * @brief - * The handleAutoLoadState function handles the Auto-Load state of - * Pre-Treatement mode install state. - * @details Inputs: autoLoadTimerCounter - * @details Outputs: autoLoadTimerCounter - * return next Pre-Treatment Install sub-state - *************************************************************************/ -static PRE_TX_INSTALL_STATE_T handleAutoLoadState( void ) -{ - PRE_TX_INSTALL_STATE_T subState = PRE_TX_INSTALL_STATE_AUTO_LOAD; - - // Timeout check - if ( ++autoLoadTimerCounter >= AUTO_LOAD_TIMEOUT_INTERVAL ) - { - signalBloodPumpHardStop(); - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_AUTO_LOAD_EJECT_BP_TIMEOUT, isPeristalticPumpHome(), autoLoadTimerCounter ); - } - else if ( TRUE == isPeristalticPumpHome() ) - { - signalBloodPumpHardStop(); - autoLoadTimerCounter = 0; - subState = NUM_OF_PRE_TX_INSTALL_SUB_STATES; - } - - return subState; -} - -/*********************************************************************//** - * @brief - * The handleAutoLoadRequest function handles a UI request to - * confirm tubeset installation. + * The signalGoToInstallState function resets the Tube Set Install Service + * and set the current state of pre-treatment to install state. * @details Inputs: none - * @details Outputs: confirmTubesetPlaced - * @param message UI message which includes the user confirmation of - * tubset installation. - * @return TRUE if confirmation/rejection accepted, FALSE if not + * @details Outputs: currentPreTreatmentState, initTubeSetInstall() + * @return none *************************************************************************/ -BOOL handleAutoLoadRequest( MESSAGE_T *message ) +void signalGoToInstallState( void ) { - BOOL result = FALSE; - BOOL notInValidState = FALSE; - TD_OP_MODE_T mode = getCurrentOperationMode(); - UI_RESPONSE_PAYLOAD_T response; - - if ( 0 == message->hdr.payloadLen ) - { - notInValidState = ( ( ( TD_PRE_TREATMENT_TUBING_SET_INSTALL_STATE != currentPreTreatmentState ) || - ( PRE_TX_INSTALL_STATE_AWAIT_TUBING_SET_CONFIRMATION != currentPreTxInstallState ) ) ? TRUE : FALSE ); - - if ( ( mode != MODE_PRET ) || ( TRUE == notInValidState ) ) - { - response.rejectionReason = REQUEST_REJECT_REASON_NOT_ALLOWED_IN_CURRENT_MODE; - } - else - { - confirmTubesetPlaced = TRUE; - result = TRUE; - response.rejectionReason = REQUEST_REJECT_REASON_NONE; - } - } - else - { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_MESSAGE_PAYLOAD_LENGTH, (U32)message->hdr.payloadLen ); - } - - response.accepted = result; - sendMessage( MSG_ID_TD_ADJUST_DISPOSABLES_CONFIRM_RESPONSE, COMM_BUFFER_OUT_CAN_TD_2_UI, (U08*)(&response), sizeof( UI_RESPONSE_PAYLOAD_T ) ); - - return result; + initTubeSetInstall(); + currentPreTreatmentState = TD_PRE_TREATMENT_TUBING_SET_INSTALL_STATE; } /**@}*/