Index: firmware/App/Modes/ModeStandby.c =================================================================== diff -u -r285b5d82539c96524c93703d52a66fff76fb64fc -rf90801d4a4f5cd1276b4a54175d101710b4096f2 --- firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision 285b5d82539c96524c93703d52a66fff76fb64fc) +++ firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision f90801d4a4f5cd1276b4a54175d101710b4096f2) @@ -16,10 +16,17 @@ ***************************************************************************/ #include "AirTrap.h" +#include "BloodFlow.h" +#include "Buttons.h" #include "DDInterface.h" #include "Messaging.h" +#include "ModePreTreat.h" +#include "ModeTreatment.h" #include "ModeStandby.h" #include "OperationModes.h" +#include "Switches.h" +#include "SystemCommTD.h" +#include "TxParams.h" /** * @addtogroup TDStandbyMode @@ -28,6 +35,9 @@ // ********** private definitions ********** +#define USER_COMMAND_CANCEL 0 ///< Cancel treatment workflow command code. +#define USER_COMMAND_INITIATE 1 ///< Initiate treatment workflow command code. + // ********** private data ********** static TD_STANDBY_STATE_T currentStandbyState; ///< Current state (sub-mode) of standby mode. @@ -42,8 +52,7 @@ * @brief * The initStandbyMode function initializes the Standby Mode Unit. * @details \b Inputs: none - * @details \b Outputs: currentStandbyState, treatStartReqReceived, - * disinfectCancelReqID, homingInitiated + * @details \b Outputs: currentStandbyState, treatStartReqReceived * @return none *************************************************************************/ void initStandbyMode( void ) @@ -56,8 +65,8 @@ * @brief * The transitionToStandbyMode function prepares for transition to standby mode. * @details \b Inputs: none - * @details \b Outputs: Standby Mode unit re-initialized, DG interface initialized, - * blood & dialysate pumps shut off. + * @details \b Outputs: Standby Mode unit re-initialized, DD interface initialized, + * actuators off. * @return initial state *************************************************************************/ U32 transitionToStandbyMode( void ) @@ -66,7 +75,7 @@ // Re-initialize when transitioning to standby mode initStandbyMode(); - initDDInterface(); + resetDDInterface(); setCurrentSubState( NO_SUB_STATE ); // Set user alarm recovery actions allowed in this mode @@ -83,7 +92,7 @@ // setValvePosition( H1_VALV, VALVE_POSITION_A_INSERT_EJECT ); // setValvePosition( H19, VALVE_POSITION_A_INSERT_EJECT ); -// doorClosedRequired( FALSE, FALSE ); // door no longer required to be closed in standby mode +// doorClosedRequired( FALSE ); // door no longer required to be closed in standby mode // syringeDetectionRequired( FALSE ); // Request DD service record and usage information from DD @@ -102,9 +111,14 @@ *************************************************************************/ U32 execStandbyMode( void ) { -// BOOL stop = isStopButtonPressed(); + BOOL stop = isStopButtonPressed(); - // State machine to get DG to prep a reservoir so we can start a treatment + if ( TRUE == stop ) + { + // Ignore stop button in this mode. + } + + // State machine for standby mode switch ( currentStandbyState ) { case STANDBY_START_STATE: @@ -172,7 +186,7 @@ // { // syringePumpVerifyForceSensorDACCalibration(); // homingInitiated = FALSE; // reset for next time -// doorClosedRequired( FALSE, FALSE ); // door no longer required to be closed in standby mode +// doorClosedRequired( FALSE ); // door no longer required to be closed in standby mode // state = STANDBY_WAIT_FOR_TREATMENT_STATE; // Go to wait for treatment state after above check // } // } @@ -193,7 +207,7 @@ static TD_STANDBY_STATE_T handleStandbyModeWaitForTreatmentState( void ) { TD_STANDBY_STATE_T state = STANDBY_WAIT_FOR_TREATMENT_STATE; -// DG_OP_MODE_T dgOperationMode = getDDOpMode(); + DD_OP_MODE_T ddOperationMode = getDDOpMode(); // switch ( dgOperationMode ) // { @@ -235,9 +249,8 @@ // PRESSURE_LIMIT_CHANGE_RESPONSE_T respRecord = { TRUE, REQUEST_REJECT_REASON_NONE, 0, 0, 0 }; // Initialize treatment modes before starting a new treatment -// initTreatParamsMode(); -// initPreTreatmentMode(); -// initTreatmentMode(); + initPreTreatmentMode(); + initTreatmentMode(); // initPostTreatmentMode(); resetAirTrap(); // Send UI default pressure settings since user is not asked to set them. @@ -246,15 +259,86 @@ // respRecord.venPresLimitAsymmetricmmHg = getTreatmentParameterS32DefaultValue( TREATMENT_PARAM_VEN_PRES_LIMIT_ASYMMETRIC ); // sendPressureLimitsChangeResponse( &respRecord ); // Start treatment workflow with treatment parameters mode -// requestNewOperationMode( MODE_TPAR ); -// treatStartReqReceived = FALSE; + requestNewOperationMode( MODE_PRET ); + treatStartReqReceived = FALSE; } return state; } /*********************************************************************//** * @brief + * The signalUserInitiateTreatment function handles user initiation of a + * treatment. + * @details \b Inputs: none + * @details \b Outputs: treatStartReqReceived + * @param message initiate/reject treatment workflow message from UI which + * includes the command code (0=cancel, 1=initiate). + * @return TRUE if signal accepted, FALSE if not + *************************************************************************/ +BOOL signalUserInitiateTreatment( MESSAGE_T *message ) +{ + BOOL result = FALSE; + U32 cmd = 0; + TD_OP_MODE_T mode = getCurrentOperationMode(); + REQUEST_REJECT_REASON_CODE_T rejReason = REQUEST_REJECT_REASON_NONE; + UI_RESPONSE_PAYLOAD_T response; + + // Verify message payload length is valid + if ( sizeof( U32 ) == message->hdr.payloadLen ) + { + memcpy( &cmd, message->payload, sizeof( U32 ) ); + + if ( USER_COMMAND_INITIATE == cmd ) + { + // Verify TD is in standby mode waiting for treatment start request + if ( ( mode != MODE_STAN ) || ( STANDBY_WAIT_FOR_TREATMENT_STATE != currentStandbyState ) ) + { + rejReason = REQUEST_REJECT_REASON_NOT_ALLOWED_IN_CURRENT_MODE; + } +#ifndef TEST_UI_ONLY + // Verify DD is communicating with HD + else if ( isDDCommunicating() != TRUE ) + { + rejReason = REQUEST_REJECT_REASON_DD_COMM_LOST; + } + // Verify DD is not busy + else if ( ( DD_MODE_STAN != getDDOpMode() ) || ( DD_STANDBY_MODE_STATE_IDLE != getDDSubMode() ) ) // || ( isDDPOSTPassed() != TRUE ) ) + { + rejReason = REQUEST_REJECT_REASON_DD_NOT_IN_STANDBY_IDLE_STATE; + } +#endif + else + { + // If request to start treatment not rejected, set flag to initiate treatment workflow + result = TRUE; + treatStartReqReceived = TRUE; + } + } + else if ( USER_COMMAND_CANCEL == cmd ) + { + //result = signalUserCancelTreatment(); + if ( result != TRUE ) + { + rejReason = REQUEST_REJECT_REASON_NOT_ALLOWED_IN_CURRENT_MODE; + } + } + else + { + rejReason = REQUEST_REJECT_REASON_INVALID_COMMAND; + } + } + + // Respond to request to start treatment + response.accepted = result; + response.rejectionReason = rejReason; + sendMessage( MSG_ID_TD_RESP_INITIATE_TREATMENT_WORKFLOW, COMM_BUFFER_OUT_CAN_TD_2_UI, (U08*)(&response), sizeof( UI_RESPONSE_PAYLOAD_T ) ); + + return result; +} + +/*********************************************************************//** + * @brief * The signalAlarmActionToStandbyMode function executes the given alarm action * as appropriate while in Standby Mode. * @details \b Inputs: none