Index: firmware/App/Modes/ModePreTreat.c =================================================================== diff -u -r83310420ae862de4724f8cfbbaeda9936c47801b -r5366722d2325ea93db0ad1f696db78597af3b7c6 --- firmware/App/Modes/ModePreTreat.c (.../ModePreTreat.c) (revision 83310420ae862de4724f8cfbbaeda9936c47801b) +++ firmware/App/Modes/ModePreTreat.c (.../ModePreTreat.c) (revision 5366722d2325ea93db0ad1f696db78597af3b7c6) @@ -20,6 +20,7 @@ #include "BloodFlow.h" #include "Buttons.h" #include "DDInterface.h" +#include "Messaging.h" #include "ModePreTreat.h" #include "OperationModes.h" #include "StatePreTxRecirculate.h" @@ -40,7 +41,9 @@ static TD_PRE_TREATMENT_MODE_STATE_T currentPreTreatmentState; ///< Current Pre-Treatment sub-state static BOOL goToInstallStateRequested; ///< Flag indicating a request to transition to Install state. static BOOL continueFromRecirculateRequested; ///< Flag indicating a request to transition to Patient Connection state. +static BOOL treatmentStartRequested; ///< Flag indicating the UI requested treatment start. + // ********** private function prototypes ********** static void setPreTreatStateTransition( void ); ///< Configure actuators and variables for Pre-Treatment state transitions. @@ -66,6 +69,7 @@ currentPreTreatmentState = TD_PRE_TREATMENT_TUBING_SET_INSTALL_STATE; goToInstallStateRequested = FALSE; continueFromRecirculateRequested = FALSE; + treatmentStartRequested = FALSE; } /*********************************************************************//** @@ -136,7 +140,7 @@ break; case TD_PRE_TREATMENT_PATIENT_CONNECTION_STATE: - // currentPreTreatmentState = handlePatientConnectionState(); + currentPreTreatmentState = handlePatientConnectionState(); break; default: @@ -191,7 +195,17 @@ break; case TD_PRE_TREATMENT_PATIENT_CONNECTION_STATE: - // TODO: actuator configuration + signalBloodPumpHardStop(); + setValvePosition( H1_VALV, VALVE_POSITION_B_OPEN ); + setValvePosition( H19_VALV, VALVE_POSITION_C_CLOSE ); + setAirPumpState( AIR_PUMP_STATE_OFF, AIR_PUMP_MOTOR_OFF ); + set3WayValveState( H13_VALV, VALVE_3WAY_COMMON_TO_CLOSED_STATE ); + set3WayValveState( H20_VALV, VALVE_3WAY_COMMON_TO_CLOSED_STATE ); + stopSyringePump(); + + // TODO: Set H5 ejector Off. + // TODO: Command DD to bypass dialyzer, set QDt to prescribed rate, + // Quf to 0, and Qs to 0. break; default: @@ -284,12 +298,7 @@ if ( TRUE == continueFromRecirculateRequested ) { continueFromRecirculateRequested = FALSE; - - // TODO: Change to TD_PRE_TREATMENT_PATIENT_CONNECTION_STATE - // when Patient Connection state is implemented. - // state = TD_PRE_TREATMENT_PATIENT_CONNECTION_STATE; - - requestNewOperationMode( MODE_TREA ); + state = TD_PRE_TREATMENT_CONFIRM_RX_STATE; } return state; @@ -332,7 +341,7 @@ getTreatmentParameterU32( TREATMENT_PARAM_BICARBONATE ) ); } - state = TD_PRE_TREATMENT_RECIRCULATE_STATE; + state = TD_PRE_TREATMENT_PATIENT_CONNECTION_STATE; } return state; @@ -341,19 +350,23 @@ /*********************************************************************//** * @brief * The handlePatientConnectionState function executes the Patient - * Connection state of pre-treatment mode. - * @details \b Inputs: TODO fill up if any - * @details \b Outputs: TODO fill up if any - * @return next Pre-Treatment mode state. + * Connection pre-treatment step. + * @details \b Inputs: treatmentStartRequested. + * @details \b Outputs: Requests transition to Treatment Mode when the + * UI Start Treatment request is received. + * @return current Pre-Treatment mode state. *************************************************************************/ static TD_PRE_TREATMENT_MODE_STATE_T handlePatientConnectionState( void ) { - TD_PRE_TREATMENT_MODE_STATE_T state = TD_PRE_TREATMENT_PATIENT_CONNECTION_STATE; + TD_PRE_TREATMENT_MODE_STATE_T state = + TD_PRE_TREATMENT_PATIENT_CONNECTION_STATE; - // TODO : after implementing this state, place the transition in the right place + if ( TRUE == treatmentStartRequested ) + { + treatmentStartRequested = FALSE; + requestNewOperationMode( MODE_TREA ); + } - //requestNewOperationMode( MODE_TREA ); - return state; } @@ -385,6 +398,63 @@ /*********************************************************************//** * @brief + * The handleStartTreatmentRequest function handles the UI request to + * start treatment. + * @details \b Inputs: current operation mode and Pre-Treatment state. + * @details \b Outputs: treatmentStartRequested. + * @param message Pointer to the received Start Treatment request message. + * @return TRUE if the request was accepted, otherwise FALSE. + *************************************************************************/ +BOOL handleStartTreatmentRequest( MESSAGE_T *message ) +{ + TD_OP_MODE_T mode = getCurrentOperationMode(); + TD_PRE_TREATMENT_MODE_STATE_T preTxState = currentPreTreatmentState; + U32 payloadLen = message->hdr.payloadLen; + BOOL accepted = FALSE; + UI_RESPONSE_PAYLOAD_T response; + + response.accepted = FALSE; + response.rejectionReason = REQUEST_REJECT_REASON_ACTION_DISABLED_IN_CURRENT_STATE; + + if ( ( 0U == payloadLen ) && ( MODE_PRET == mode ) && ( TD_PRE_TREATMENT_PATIENT_CONNECTION_STATE == preTxState ) ) + { + treatmentStartRequested = TRUE; + accepted = TRUE; + response.accepted = TRUE; + response.rejectionReason = REQUEST_REJECT_REASON_NONE; + } + + sendMessage( MSG_ID_TD_START_TREATMENT_RESPONSE, COMM_BUFFER_OUT_CAN_TD_2_UI, (U08 *)&response, sizeof( UI_RESPONSE_PAYLOAD_T ) ); + + return accepted; +} + +/*********************************************************************//** + * @brief + * The signalPreTreatmentBackoutToStandby function handles a request to + * back out of Pre-Treatment to Standby. + * @details \b Inputs: current operation mode, current Pre-Treatment state, + * and Tube Set Install state. + * @details \b Outputs: Requests Standby Mode when backout is allowed. + * @return TRUE if the request is accepted, otherwise FALSE. + *************************************************************************/ +BOOL signalPreTreatmentBackoutToStandby( void ) +{ + BOOL accepted = FALSE; + + if ( ( MODE_PRET == getCurrentOperationMode() ) && + ( TD_PRE_TREATMENT_TUBING_SET_INSTALL_STATE == currentPreTreatmentState ) && + ( TRUE == isTubeSetInstallAwaitingConfirmation() ) ) + { + requestNewOperationMode( MODE_STAN ); + accepted = TRUE; + } + + return accepted; +} + +/*********************************************************************//** + * @brief * The signalAlarmActionToPreTreatmentMode function executes the given alarm action * as appropriate while in Pre-Treatment Mode. * @details \b Inputs: currentPreTreatmentState