Index: firmware/App/Controllers/BloodFlow.c =================================================================== diff -u -r0cc67ce4bbaac3aeae8a3324e50e1b31e5ab49c3 -red21c935443549b87ab6665e76ce1d32d9867082 --- firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision 0cc67ce4bbaac3aeae8a3324e50e1b31e5ab49c3) +++ firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision ed21c935443549b87ab6665e76ce1d32d9867082) @@ -417,13 +417,9 @@ *************************************************************************/ BOOL homeBloodPump( void ) { -// BOOL result = FALSE; - if ( BLOOD_PUMP_OFF_STATE == bloodPumpState ) { bpHomeRequested = TRUE; -// bpHomeStartTime = getMSTimerCount(); -// result = setBloodPumpTargetRPM( BP_HOME_SPEED, MOTOR_DIR_FORWARD ); } else { Index: firmware/App/Modes/ModePostTreat.c =================================================================== diff -u -r0cc67ce4bbaac3aeae8a3324e50e1b31e5ab49c3 -red21c935443549b87ab6665e76ce1d32d9867082 --- firmware/App/Modes/ModePostTreat.c (.../ModePostTreat.c) (revision 0cc67ce4bbaac3aeae8a3324e50e1b31e5ab49c3) +++ firmware/App/Modes/ModePostTreat.c (.../ModePostTreat.c) (revision ed21c935443549b87ab6665e76ce1d32d9867082) @@ -15,14 +15,20 @@ * ***************************************************************************/ +#include "AirPump.h" +#include "AirTrap.h" #include "BloodFlow.h" #include "Buttons.h" +#include "EjectorMotor.h" #include "ModePostTreat.h" #include "OperationModes.h" +#include "RotaryValve.h" #include "Switches.h" #include "SyringePump.h" #include "TubeSetAutoEject.h" #include "TxParams.h" +#include "Valve3Way.h" +#include "Valves.h" /** * @addtogroup TDPostTreatmentMode @@ -32,8 +38,9 @@ // ********** private definitions ********** static BOOL patientDisconnectionConfirmed; ///< Flag indicates user confirms patient disconnection. -static bool patientDisconnectHandled; ///< Flag indicates patient disconnect actions have been handled +static BOOL patientDisconnectHandled; ///< Flag indicates patient disconnect actions have been handled static BOOL disposableRemovalConfirmed; ///< Flag indicates user confirms disposable removal. +static BOOL disinfectionConfirmed; ///< Flag indicates user confirms disinfection selection. static TD_POST_TREATMENT_STATE_T currentPostTreatmentState; ///< Current Post-Treatment sub-state // ********** private function prototypes ********** @@ -42,7 +49,7 @@ static TD_POST_TREATMENT_STATE_T handlePatientDisconnectionState( void ); static TD_POST_TREATMENT_STATE_T handleAutoEjectState( void ); static TD_POST_TREATMENT_STATE_T handleDisposableRemovalState(void ); -static TD_POST_TREATMENT_STATE_T handleVerifyState( void ); +static TD_POST_TREATMENT_STATE_T handleDisinfectionState( void ); /*********************************************************************//** * @brief @@ -56,7 +63,8 @@ patientDisconnectionConfirmed = FALSE; patientDisconnectHandled = FALSE; disposableRemovalConfirmed = FALSE; - currentPostTreatmentState = TD_POST_TREATMENT_AUTO_EJECT_STATE; + disinfectionConfirmed = FALSE; + currentPostTreatmentState = TD_POST_TREATMENT_PATIENT_DISCONNECTION_STATE; } /*********************************************************************//** @@ -89,10 +97,31 @@ **************************************************************************/ static void setPostTreatStateTransition( void ) { + resetAirTrap(); + resetBloodPumpRotorCount(); + resetPreLoadStatus(); + disableEjectorMotor(); + // Set valves to default positions + set3WayValveState( H13_VALV, VALVE_3WAY_COMMON_TO_CLOSED_STATE ); + set3WayValveState( H20_VALV, VALVE_3WAY_COMMON_TO_CLOSED_STATE ); + if ( VALVE_STATE_IDLE == getValveState( H1_VALV ) ) + { + setValvePosition( H1_VALV, VALVE_POSITION_A_INSERT_EJECT ); + } + if ( VALVE_STATE_IDLE == getValveState( H19_VALV ) ) + { + setValvePosition( H19_VALV, VALVE_POSITION_A_INSERT_EJECT ); + } + // Stop H12 air pump + setAirPumpState( AIR_PUMP_STATE_OFF, AIR_PUMP_MOTOR_OFF ); + + signalBloodPumpHardStop(); + + // TODO: H10 syringe/heparin pump OFF switch( currentPostTreatmentState ) { case TD_POST_TREATMENT_PATIENT_DISCONNECTION_STATE: - //TODO: actuator configuration; + signalBloodPumpHardStop(); break; case TD_POST_TREATMENT_AUTO_EJECT_STATE: @@ -103,12 +132,14 @@ //TODO: actuator configuration; break; - case TD_POST_TREATMENT_VERIFY_STATE: + case TD_POST_TREATMENT_DISINFECTION_STATE: //TODO: actuator configuration; break; default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_POST_TREATMENT_INVALID_STATE1, currentPostTreatmentState ); + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, + SW_FAULT_ID_MODE_POST_TREATMENT_INVALID_STATE1, + currentPostTreatmentState ); break; } } @@ -124,6 +155,12 @@ U32 execPostTreatmentMode( void ) { BOOL stop = isStopButtonPressed(); + + if ( TRUE == stop ) + { + // Ignore stop button in this mode. + } + TD_POST_TREATMENT_STATE_T prevPostTreatmentState = currentPostTreatmentState; // Execute mode state machine @@ -141,16 +178,14 @@ currentPostTreatmentState = handleDisposableRemovalState(); break; - case TD_POST_TREATMENT_VERIFY_STATE: - currentPostTreatmentState = handleVerifyState(); - break; - case TD_POST_TREATMENT_DISINFECTION_STATE: - //currentPostTreatmentState = handleDisinfectionState(); + currentPostTreatmentState = handleDisinfectionState(); break; default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_POST_TREATMENT_INVALID_STATE, currentPostTreatmentState ); + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, + SW_FAULT_ID_MODE_POST_TREATMENT_INVALID_STATE, + currentPostTreatmentState ); break; } @@ -173,15 +208,15 @@ *************************************************************************/ static void checkPostTreatmentPatientDisconnect( void ) { -// VALVE_T valve; + VALVE_T valve; if ( ( TRUE == patientDisconnectionConfirmed ) && ( FALSE == patientDisconnectHandled ) ) { // home valves and pumps while front door is still closed. homeBloodPump(); -// for ( valve = VDI; valve < NUM_OF_VALVES; valve++ ) + for ( valve = H1_VALV; valve < NUM_OF_VALVES; valve++ ) { -// setValvePosition( valve, VALVE_POSITION_A_INSERT_EJECT ); + setValvePosition( valve, VALVE_POSITION_A_INSERT_EJECT ); } if ( ( getTreatmentParameterF32( TREATMENT_PARAM_HEPARIN_BOLUS_VOLUME ) > 0.0 ) || ( getTreatmentParameterF32( TREATMENT_PARAM_HEPARIN_DELIVERY_RATE ) > 0.0 ) ) @@ -213,7 +248,7 @@ { patientDisconnectionConfirmed = FALSE; patientDisconnectHandled = FALSE; - state = TD_POST_TREATMENT_DISPOSABLE_REMOVAL_STATE; + state = TD_POST_TREATMENT_AUTO_EJECT_STATE; } return state; @@ -258,26 +293,36 @@ if ( TRUE == disposableRemovalConfirmed ) { disposableRemovalConfirmed = FALSE; - state = TD_POST_TREATMENT_VERIFY_STATE; + state = TD_POST_TREATMENT_DISINFECTION_STATE; } return state; } /*********************************************************************//** * @brief - * The handleVerifyState function executes the Post-Treatment - * mode Verify state machine. - * @details \b Inputs: TODO fill up if any - * @details \b Outputs: TODO fill up if any - * @return next post-treatment mode state + * 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. + * @return Current Post-Treatment state. *************************************************************************/ -static TD_POST_TREATMENT_STATE_T handleVerifyState( void ) +static TD_POST_TREATMENT_STATE_T handleDisinfectionState( void ) { - TD_POST_TREATMENT_STATE_T state = TD_POST_TREATMENT_VERIFY_STATE; + TD_POST_TREATMENT_STATE_T state = TD_POST_TREATMENT_DISINFECTION_STATE; - // TODO + if ( TRUE == disinfectionConfirmed ) + { + disinfectionConfirmed = FALSE; + /* + * TODO: + * Process the selected disinfection option and request the + * appropriate transition to Standby. + */ + } + return state; } @@ -307,4 +352,18 @@ disposableRemovalConfirmed = TRUE; } +/*********************************************************************//** + * @brief + * The signalUserConfirmDisinfection signals Post-Treatment mode that + * the user has confirmed the disinfection selection. + * @details \b Inputs: none + * @details \b Outputs: disinfectionConfirmed + * @return none + *************************************************************************/ +void signalUserConfirmDisinfection( void ) +{ + disinfectionConfirmed = TRUE; +} + + /**@}*/ Index: firmware/App/Modes/ModePostTreat.h =================================================================== diff -u -r0cc67ce4bbaac3aeae8a3324e50e1b31e5ab49c3 -red21c935443549b87ab6665e76ce1d32d9867082 --- firmware/App/Modes/ModePostTreat.h (.../ModePostTreat.h) (revision 0cc67ce4bbaac3aeae8a3324e50e1b31e5ab49c3) +++ firmware/App/Modes/ModePostTreat.h (.../ModePostTreat.h) (revision ed21c935443549b87ab6665e76ce1d32d9867082) @@ -35,6 +35,8 @@ U32 transitionToPostTreatmentMode( void ); // Prepares for transition to post-treatment mode U32 execPostTreatmentMode( void ); // Execute the post-treatment mode state machine (call from OperationModes) void signalUserConfirmPatientDisconnection( void ); +void signalUserConfirmDisposableRemoval( void ); +void signalUserConfirmDisinfection( void ); /**@}*/ Index: firmware/App/Services/Messaging.c =================================================================== diff -u -r0cc67ce4bbaac3aeae8a3324e50e1b31e5ab49c3 -red21c935443549b87ab6665e76ce1d32d9867082 --- firmware/App/Services/Messaging.c (.../Messaging.c) (revision 0cc67ce4bbaac3aeae8a3324e50e1b31e5ab49c3) +++ firmware/App/Services/Messaging.c (.../Messaging.c) (revision ed21c935443549b87ab6665e76ce1d32d9867082) @@ -32,6 +32,7 @@ #include "LevelSensors.h" #include "Messaging.h" #include "ModeInitPOST.h" +#include "ModePostTreat.h" #include "ModePreTreat.h" #include "ModeStandby.h" #include "ModeTreatment.h" @@ -116,7 +117,6 @@ { MSG_ID_UI_VERSION_INFO_RESPONSE, &handleUIVersionResponse }, { MSG_ID_DD_GEN_DIALYSATE_MODE_DATA, &setDialysateData }, { MSG_ID_DD_PRESSURES_DATA, &setDialysatePressure }, - { MSG_ID_UI_PATIENT_DISCONNECT_CONFIRM_REQUEST, &handlePatientDisconnectionConfirmCmd }, { MSG_ID_UI_TREATMENT_PARAMS_TO_VALIDATE, &validateAndSetTreatmentParameters }, { MSG_ID_UI_TREATMENT_UF_VOLUME_VALIDATE_REQUEST, &validateAndSetUFVolume }, { MSG_ID_UI_ULTRAFILTRATION_CHANGE_CONFIRM_REQUEST, &signalUserConfirmationOfUFVolume }, @@ -142,7 +142,9 @@ { MSG_ID_FFU_SIGNAL_TD_UPDATE_AVAILABLE, &handleUpdateAvailable }, { MSG_ID_UI_FLUID_BOLUS_REQUEST, &handleFluidBolusRequest }, { MSG_ID_UI_GENERIC_CONFIRMATION_RESULT_RESPONSE, &handleUIConfirmationResponse }, + { MSG_ID_UI_PATIENT_DISCONNECT_CONFIRM_REQUEST, &handlePatientDisconnectionConfirmCmd }, { MSG_ID_UI_POST_TREATMENT_DISPOSABLE_REMOVAL_CONFIRM_REQUEST, &handleDisposableRemovalConfirmCmd }, + { MSG_ID_UI_POST_TREATMENT_DISINFECTION_SELECTION_REQUEST, &handleDisinfectionConfirmCmd }, { MSG_ID_TD_SOFTWARE_RESET_REQUEST, &testTDSoftwareResetRequest }, { MSG_ID_TD_BUBBLE_OVERRIDE_REQUEST, &testBubbleDetectOverride }, { MSG_ID_TD_BUBBLE_PUBLISH_INTERVAL_OVERRIDE_REQUEST, &testBubblesDataPublishIntervalOverride }, @@ -557,47 +559,147 @@ } /*********************************************************************//** - * @brief - * The handlePatientDisconnectionConfirmCmd function handles user confirms - * patient disconnection. - * @details \b Inputs: none - * @details \b Outputs: message handled - * @param message a pointer to the message to handle - * @return none. + * @brief + * The handlePatientDisconnectionConfirmCmd function handles user + * confirmation of patient disconnection. + * @details \b Inputs: Patient disconnection confirmation message. + * @details \b Outputs: Acceptance response and patient disconnection signal. + * @param message Pointer to the message to handle. + * @return TRUE if the confirmation is accepted, FALSE otherwise. *************************************************************************/ -void handlePatientDisconnectionConfirmCmd( MESSAGE_T *message ) +static BOOL handlePatientDisconnectionConfirmCmd( MESSAGE_T *message ) { + BOOL result = FALSE; + BOOL modeValid = FALSE; + TD_OP_MODE_T mode = getCurrentOperationMode(); + UI_RESPONSE_PAYLOAD_T response; + + response.rejectionReason = REQUEST_REJECT_REASON_NONE; + if ( 0 == message->hdr.payloadLen ) { - signalUserConfirmPatientDisconnection(); + modeValid = ( MODE_POST == mode ) ? TRUE : FALSE; + + if ( ( TRUE != modeValid ) ) + { + response.rejectionReason = REQUEST_REJECT_REASON_NOT_ALLOWED_IN_CURRENT_MODE; + } + else + { + signalUserConfirmPatientDisconnection(); + result = TRUE; + } } else { - sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_TD_2_UI, FALSE ); + response.rejectionReason = REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; } + + response.accepted = result; + sendMessage( MSG_ID_TD_PATIENT_DISCONNECT_CONFIRM_RESPONSE, COMM_BUFFER_OUT_CAN_TD_2_UI, (U08*)(&response), sizeof( UI_RESPONSE_PAYLOAD_T ) ); + + return result; } /*********************************************************************//** - * @brief - * The handleDisposableRemovalConfirmCmd function handles user confirms - * disposable removal. - * @details \b Inputs: none - * @details \b Outputs: message handled - * @param message a pointer to the message to handle - * @return none. + * @brief + * The handleDisposableRemovalConfirmCmd function handles user confirmation + * of disposable removal. + * @details \b Inputs: Disposable removal confirmation message. + * @details \b Outputs: Acceptance response and disposable removal signal. + * @param message Pointer to the message to handle. + * @return TRUE if the confirmation is accepted, FALSE otherwise. *************************************************************************/ -void handleDisposableRemovalConfirmCmd( MESSAGE_T *message ) +static BOOL handleDisposableRemovalConfirmCmd( MESSAGE_T *message ) { + BOOL result = FALSE; + BOOL modeValid = FALSE; + TD_OP_MODE_T mode = getCurrentOperationMode(); + UI_RESPONSE_PAYLOAD_T response; + + response.rejectionReason = REQUEST_REJECT_REASON_NONE; + if ( 0 == message->hdr.payloadLen ) { - signalUserConfirmDisposableRemoval(); + modeValid = ( MODE_POST == mode ) ? TRUE : FALSE; + + if ( FALSE == modeValid ) + { + response.rejectionReason = + REQUEST_REJECT_REASON_NOT_ALLOWED_IN_CURRENT_MODE; + } + else + { + signalUserConfirmDisposableRemoval(); + result = TRUE; + } } else { - sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_TD_2_UI, FALSE ); + response.rejectionReason = + REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; } + + response.accepted = result; + + sendMessage( MSG_ID_TD_POST_TREATMENT_DISPOSABLE_REMOVAL_CONFIRM_RESPONSE, + COMM_BUFFER_OUT_CAN_TD_2_UI, + (U08 *)&response, + sizeof( UI_RESPONSE_PAYLOAD_T ) ); + + return result; } +/*********************************************************************//** + * @brief + * The handleDisinfectionConfirmCmd function handles user confirmation + * of the disinfection selection. + * @details \b Inputs: Disinfection confirmation message. + * @details \b Outputs: Acceptance response and disinfection confirmation signal. + * @param message Pointer to the message to handle. + * @return TRUE if the confirmation is accepted, FALSE otherwise. + *************************************************************************/ +static BOOL handleDisinfectionConfirmCmd( MESSAGE_T *message ) +{ + BOOL result = FALSE; + BOOL modeValid = FALSE; + TD_OP_MODE_T mode = getCurrentOperationMode(); + UI_RESPONSE_PAYLOAD_T response; + + response.rejectionReason = REQUEST_REJECT_REASON_NONE; + + if ( 0 == message->hdr.payloadLen ) + { + modeValid = ( MODE_POST == mode ) ? TRUE : FALSE; + + if ( FALSE == modeValid ) + { + response.rejectionReason = + REQUEST_REJECT_REASON_NOT_ALLOWED_IN_CURRENT_MODE; + } + else + { + signalUserConfirmDisinfection(); + result = TRUE; + } + } + else + { + response.rejectionReason = + REQUEST_REJECT_REASON_INVALID_REQUEST_FORMAT; + } + + response.accepted = result; + + sendMessage( MSG_ID_TD_POST_TREATMENT_DISINFECTION_SELECTION_RESPONSE, + COMM_BUFFER_OUT_CAN_TD_2_UI, + (U08 *)&response, + sizeof( UI_RESPONSE_PAYLOAD_T ) ); + + return result; +} + + // *********************************************************************** // ***************** Message Sending Helper Functions ******************** // *********************************************************************** Index: firmware/App/Services/Messaging.h =================================================================== diff -u -r0cc67ce4bbaac3aeae8a3324e50e1b31e5ab49c3 -red21c935443549b87ab6665e76ce1d32d9867082 --- firmware/App/Services/Messaging.h (.../Messaging.h) (revision 0cc67ce4bbaac3aeae8a3324e50e1b31e5ab49c3) +++ firmware/App/Services/Messaging.h (.../Messaging.h) (revision ed21c935443549b87ab6665e76ce1d32d9867082) @@ -144,8 +144,9 @@ BOOL handleTesterLogInRequest( MESSAGE_T *message ); BOOL handleUpdateAvailable( MESSAGE_T *message ); BOOL handleUIVersionResponse( MESSAGE_T *message ); -void handlePatientDisconnectionConfirmCmd( MESSAGE_T *message ); -void handleDisposableRemovalConfirmCmd( MESSAGE_T *message ); +static BOOL handlePatientDisconnectionConfirmCmd( MESSAGE_T *message ); +static BOOL handleDisposableRemovalConfirmCmd( MESSAGE_T *message ); +static BOOL handleDisinfectionConfirmCmd( MESSAGE_T *message ); // Test send message helper functions BOOL sendEvent( TD_EVENT_ID_T event, EVENT_DATA_T dat1, EVENT_DATA_T dat2 );