Index: firmware/App/Modes/ModePostTreat.c =================================================================== diff -u -rbcc80fde38b8b94c64a7ad615f9ca3cb6e98c77e -r176bb5bc32a18891912e179dc1bc9293b370bed4 --- firmware/App/Modes/ModePostTreat.c (.../ModePostTreat.c) (revision bcc80fde38b8b94c64a7ad615f9ca3cb6e98c77e) +++ firmware/App/Modes/ModePostTreat.c (.../ModePostTreat.c) (revision 176bb5bc32a18891912e179dc1bc9293b370bed4) @@ -19,12 +19,15 @@ #include "AirTrap.h" #include "BloodFlow.h" #include "Buttons.h" +#include "DDInterface.h" #include "EjectorMotor.h" +#include "Messaging.h" #include "ModePostTreat.h" +#include "ModeStandby.h" #include "OperationModes.h" -#include "RotaryValve.h" #include "Switches.h" #include "SyringePump.h" +#include "TaskPriority.h" #include "Timers.h" #include "TubeSetAutoEject.h" #include "TxParams.h" @@ -36,13 +39,15 @@ * @{ */ +#define POST_TREAT_STATE_BROADCAST_COUNT (MS_PER_SECOND / TASK_PRIORITY_INTERVAL) + // ********** private definitions ********** static BOOL patientDisconnectionConfirmed; ///< Flag indicates user confirms patient disconnection. static BOOL patientDisconnectHandled; ///< Flag indicates patient disconnect actions have been handled static BOOL disposableRemovalConfirmed; ///< Flag indicates user confirms disposable removal. -static DD_COMMAND_T selectedDisinfectionCommand; ///< Flag indicates user confirms disinfection selection. -static volatile U32 postTreatmentStateBroadcastTimer; ///< Timer counter for pending power off request. +static DISINFECT_SELECTION_T selectedDisinfectionSelection; ///< Selected disinfection option from UI.static BOOL disinfectionSelectionReceived; +static volatile U32 postTreatmentStateBroadcastTimer; ///< Timer counter for pending power off request. static TD_POST_TREATMENT_STATE_T currentPostTreatmentState; ///< Current Post-Treatment sub-state @@ -63,11 +68,13 @@ **************************************************************************/ void initPostTreatmentMode( void ) { - patientDisconnectionConfirmed = FALSE; - patientDisconnectHandled = FALSE; - disposableRemovalConfirmed = FALSE; - selectedDisinfectionCommand = DD_CMD_NONE; - currentPostTreatmentState = TD_POST_TREATMENT_PATIENT_DISCONNECTION_STATE; + currentPostTreatmentState = TD_POST_TREATMENT_PATIENT_DISCONNECTION_STATE; + patientDisconnectionConfirmed = FALSE; + patientDisconnectHandled = FALSE; + disposableRemovalConfirmed = FALSE; + disinfectionSelectionReceived = FALSE; + selectedDisinfectionSelection = DISINFECT_SEL_SKIP; + postTreatmentStateBroadcastTimer = 0; } /*********************************************************************//** @@ -113,35 +120,32 @@ VALVE_3WAY_COMMON_TO_CLOSED_STATE ); //H10 Heparin/Syringe Pump - Off. stopSyringePump(); + signalBloodPumpHardStop(); switch ( currentPostTreatmentState ) { case TD_POST_TREATMENT_PATIENT_DISCONNECTION_STATE: - signalBloodPumpHardStop(); - disableEjectorMotor(); - //TODO check on valve positions setValvePosition( H1_VALV, VALVE_POSITION_C_CLOSE ); setValvePosition( H19_VALV, VALVE_POSITION_C_CLOSE ); break; case TD_POST_TREATMENT_AUTO_EJECT_STATE: - signalBloodPumpHardStop(); + setValvePosition( H1_VALV, + VALVE_POSITION_A_INSERT_EJECT ); + setValvePosition( H19_VALV, + VALVE_POSITION_A_INSERT_EJECT ); break; case TD_POST_TREATMENT_DISPOSABLE_REMOVAL_STATE: - signalBloodPumpHardStop(); - disableEjectorMotor(); setValvePosition( H1_VALV, VALVE_POSITION_A_INSERT_EJECT ); setValvePosition( H19_VALV, VALVE_POSITION_A_INSERT_EJECT ); break; case TD_POST_TREATMENT_DISINFECTION_STATE: - signalBloodPumpHardStop(); - disableEjectorMotor(); setValvePosition( H1_VALV, VALVE_POSITION_A_INSERT_EJECT ); setValvePosition( H19_VALV, @@ -201,12 +205,13 @@ currentPostTreatmentState ); break; } - if ( TRUE == didTimeout( postTreatmentStateBroadcastTimer, POST_TREATMENT_STATE_BROADCAST_INTERVAL_MS ) ) + postTreatmentStateBroadcastTimer++; + + if (postTreatmentStateBroadcastTimer >= POST_TREAT_STATE_BROADCAST_COUNT) { - postTreatmentStateBroadcastTimer = getMSTimerCount(); - //TODO: broadcast current state to UI + postTreatmentStateBroadcastTimer = 0U; + //TODO: need to broadcast currentstate on which msgid } - if ( prevPostTreatmentState != currentPostTreatmentState) { setPostTreatStateTransition(); @@ -217,15 +222,16 @@ /*********************************************************************//** * @brief - * The checkPostTreatmentPatientDisconnect function checks UI patient - * disconnect and handles valve release, pump homing, door requirement. - * @details \b Inputs: patientDisconnectionConfirmed, patientDisconnectHandled - * @details \b Outputs: patientDisconnectHandled, home pumps, open valves, - * retract syringe, door closed requirement. - * @return none + * The handlePatientDisconnectionState function executes the Post-Treatment + * mode Patient Disconnection state machine. + * @details \b Inputs: none + * @details \b Outputs: processed patient disconnection confirmation + * @return next post-treatment mode state *************************************************************************/ -static void checkPostTreatmentPatientDisconnect( void ) +static TD_POST_TREATMENT_STATE_T handlePatientDisconnectionState( void ) { + TD_POST_TREATMENT_STATE_T state = TD_POST_TREATMENT_PATIENT_DISCONNECTION_STATE; + VALVE_T valve; if ( ( TRUE == patientDisconnectionConfirmed ) && ( FALSE == patientDisconnectHandled ) ) @@ -246,22 +252,6 @@ // Patient Disconnect State needs it to move to next state patientDisconnectHandled = TRUE; } -} - -/*********************************************************************//** - * @brief - * The handlePatientDisconnectionState function executes the Post-Treatment - * mode Patient Disconnection state machine. - * @details \b Inputs: none - * @details \b Outputs: processed patient disconnection confirmation - * @return next post-treatment mode state - *************************************************************************/ -static TD_POST_TREATMENT_STATE_T handlePatientDisconnectionState( void ) -{ - TD_POST_TREATMENT_STATE_T state = TD_POST_TREATMENT_PATIENT_DISCONNECTION_STATE; - - checkPostTreatmentPatientDisconnect(); - if ( TRUE == patientDisconnectionConfirmed ) { patientDisconnectionConfirmed = FALSE; @@ -322,39 +312,66 @@ * The handleDisinfectionState function executes the Post-Treatment * Disinfection state. * @details \b Inputs: User disinfection selection from UI. - * @details \b Outputs: Initiates the selected disinfection operation or - * transitions the system to Standby. + * @details \b Outputs: selectedDisinfectionSelection * @return Current Post-Treatment state. *************************************************************************/ static TD_POST_TREATMENT_STATE_T handleDisinfectionState( void ) { - TD_POST_TREATMENT_STATE_T state = TD_POST_TREATMENT_DISINFECTION_STATE; + TD_POST_TREATMENT_STATE_T state = + TD_POST_TREATMENT_DISINFECTION_STATE; - switch ( selectedDisinfectionCommand ) + if ( TRUE == disinfectionSelectionReceived ) { - case DD_CMD_NONE: - //TODO: transitionToStandbyMode - break; - case DD_CMD_START_FLUSH: - //TODO: Need to send info to DD - break; - case DD_CMD_START_DISINFECT_HEAT: - //TODO: Need to send info to DD - break; - case DD_CMD_START_DISINFECT_CITRIC_DD: - break; - case DD_CMD_START_DISINFECT_CITRIC_DD_IOFP: - break; - case DD_CMD_START_DISINFECT_SUBSTITUTION_PORT: - break; - default: - //TODO: do i need to set any alarm here - break; + // Save selected disinfection option in Standby. + signalStandbyDisinfectionSelection( + selectedDisinfectionSelection ); + + // Request DD transition to Standby. + cmdStopGenerateDialysate(); + + // Transition TD to Standby. + requestNewOperationMode( MODE_STAN ); + + disinfectionSelectionReceived = FALSE; } return state; } +/*********************************************************************//** + * @brief + * The handleDisinfectionConfirmCmd function handles user selection + * of the Post-Treatment disinfection operation. + * @details \b Inputs: Disinfection selection message. + * @details \b Outputs: Acceptance response and selected disinfection command. + * @param message Pointer to the message to handle. + * @return TRUE if the selection is accepted, FALSE otherwise. + *************************************************************************/ +BOOL handleDisinfectionConfirmCmd( MESSAGE_T *message ) +{ + BOOL result = FALSE; + TD_OP_MODE_T mode = getCurrentOperationMode(); + UI_RESPONSE_PAYLOAD_T response; + response.rejectionReason = REQUEST_REJECT_REASON_NONE; + + if ( sizeof( U32 ) == message->hdr.payloadLen ) + { + disinfectionSelectionReceived = TRUE; + } + else + { + response.rejectionReason = + REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } + + response.accepted = result; + + sendMessage( MSG_ID_TD_DISINFECT_RESPONSE, COMM_BUFFER_OUT_CAN_TD_2_UI, + (U08 *)&response, sizeof( UI_RESPONSE_PAYLOAD_T ) ); + + return result; +} + /*********************************************************************//** * @brief * The signalUserConfirmPatientDisconnection signals post-treatment mode @@ -389,9 +406,9 @@ * @details \b Outputs: selectedDisinfectionCommand * @return none *************************************************************************/ -void signalUserConfirmDisinfection( DD_COMMAND_T state ) +void signalUserConfirmDisinfection( DISINFECT_SELECTION_T selection ) { - selectedDisinfectionCommand = state; + selectedDisinfectionSelection = selection; }