Index: firmware/App/Modes/ModeStandby.c =================================================================== diff -u -ra961fefac71ca2635036b78532acc8aea468c33e -rf9c86e807b65164850947909bf63bd327ed69a32 --- firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision a961fefac71ca2635036b78532acc8aea468c33e) +++ firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision f9c86e807b65164850947909bf63bd327ed69a32) @@ -7,8 +7,8 @@ * * @file ModeStandby.c * -* @author (last) Arpita Srivastava -* @date (last) 18-May-2026 +* @author (last) Praneeth Bunne +* @date (last) 02-Jul-2026 * * @author (original) Sean Nash * @date (original) 01-Aug-2024 @@ -31,8 +31,8 @@ #include "SystemCommTD.h" #include "SyringePump.h" #include "TxParams.h" -#include "Valves.h" #include "Valve3Way.h" +#include "Valves.h" /** * @addtogroup TDStandbyMode @@ -61,9 +61,11 @@ static TD_STANDBY_STATE_T currentStandbyState; ///< Current state (sub-mode) of standby mode. static BOOL treatStartReqReceived; ///< Flag indicates user has requested initiation of a treatment. static GENERIC_CONFIRM_ID_T disinfectCancelReqID; ///< ID of requested cancel disinfect mode. -static BOOL homingInitiated; ///< Boolean flag to indicate homing is initiated. static DD_CLEANING_MODE_STATUS_T currentDDCleaningMode; ///< Current DG cleaning mode status. static BOOL flagNoDisinfectRequired = FALSE; ///< Flag indicates disinfect not required on next mode entry. +static BOOL homingInitiated; ///< Flag indicates actuators have been homed. +static FLUID_TYPE_T fluidType; ///< Fluid type assigned based on user selection. +static TREATMENT_TYPE_T modality; ///< Modality from the treatment initiation. // ********** private function prototypes ********** @@ -81,7 +83,7 @@ * @brief * The initStandbyMode function initializes the Standby Mode Unit. * @details \b Inputs: none - * @details \b Outputs: currentStandbyState, treatStartReqReceived + * @details \b Outputs: Standby mode variables initialized. * @return none *************************************************************************/ void initStandbyMode( void ) @@ -90,6 +92,8 @@ treatStartReqReceived = FALSE; disinfectCancelReqID = GENERIC_CONFIRM_ID_NONE; homingInitiated = FALSE; + fluidType = FLUID_TYPE_UNKNOWN; + modality = TREATMENT_MODALITY_HD_SALINE_FLUID; } /*********************************************************************//** @@ -121,19 +125,36 @@ setAlarmUserActionEnabled( ALARM_USER_ACTION_RINSEBACK, FALSE ); setAlarmUserActionEnabled( ALARM_USER_ACTION_END_TREATMENT, FALSE ); - setStandbyWaitForTreatmentActuators(); + //ToDo: need to enable +// setStandbyWaitForTreatmentActuators(); // Standby currently supports Start and Wait For Treatment states. // Disinfect/cleaning states are not enabled until the handlers are implemented. flagNoDisinfectRequired = FALSE; - doorClosedRequired( FALSE ); currentStandbyState = STANDBY_START_STATE; + // Pumps should be off + signalBloodPumpHardStop(); +// stopSyringePump(); + // Set valves to default positions + set3WayValveState( H13_VALV, VALVE_3WAY_COMMON_TO_CLOSED_STATE ); + set3WayValveState( H20_VALV, VALVE_3WAY_COMMON_TO_CLOSED_STATE ); + if ( getValveState( H1_VALV ) < VALVE_STATE_IDLE ) + { + setValvePosition( H1_VALV, VALVE_POSITION_A_INSERT_EJECT ); + } + if ( getValveState( H19_VALV ) < VALVE_STATE_IDLE ) + { + setValvePosition( H19_VALV, VALVE_POSITION_A_INSERT_EJECT ); + } + + doorClosedRequired( FALSE ); // door no longer required to be closed in standby mode + // Request DD service record and usage information from DD // sendDDServiceRequestToDD(); //ToDo: Service record id not available // broadcastData( MSG_ID_TD_DD_REQUEST_SERVICE_RECORD_FROM_TD, COMM_BUFFER_OUT_CAN_TD_2_DD, requestPayload, sizeof( requestPayload ) ); - broadcastData( MSG_ID_TD_DD_USAGE_INFO_REQUEST, COMM_BUFFER_OUT_CAN_TD_2_DD, requestPayload, sizeof( requestPayload ) ); +// broadcastData( MSG_ID_TD_DD_USAGE_INFO_REQUEST, COMM_BUFFER_OUT_CAN_TD_2_DD, requestPayload, sizeof( requestPayload ) ); // sendDDUsageInfoRequestToDD(); //TODO need to enable return currentStandbyState; @@ -212,7 +233,7 @@ // Home pumps and valves for ( valve = H1_VALV; valve < NUM_OF_VALVES; ++valve ) { - homeValve( valve, VALVE_NO_FORCE_HOME, VALVE_CARTRIDGE_MAY_BE_PRESENT ); + homeValve( valve, FALSE, TRUE ); } if ( FALSE == isSyringePumpHome() ) { @@ -310,6 +331,8 @@ // Start treatment workflow with pretreatment mode requestNewOperationMode( MODE_PRET ); treatStartReqReceived = FALSE; + // Set fluid type + setFluidType( modality ); } return state; @@ -348,38 +371,89 @@ } /*********************************************************************//** + * The setFluidType function sets the fluid type based on the user's + * treatment selection from the home screen. + * @details \b Inputs: none + * @details \b Outputs: fluidType + * @param modality Treatment modality selected by the user on the home screen. + * @return none + *************************************************************************/ +void setFluidType( TREATMENT_TYPE_T modality ) +{ + if ( TREATMENT_MODALITY_HD_SALINE_FLUID == modality ) + { + fluidType = FLUID_TYPE_SALINE; + } + else + { + // For HDF and HD_ONLINE_FLUID + fluidType = FLUID_TYPE_SUBSTITUTE; + } +} + +/*********************************************************************//** * @brief + * The getFluidType function returns the current fluid type assigned + * based on the user's treatment selection. + * @details \b Inputs: none + * @details \b Outputs: none + * @return Current fluid type (saline or substitution fluid). + *************************************************************************/ +FLUID_TYPE_T getFluidType( void ) +{ + return fluidType; +} + +/*********************************************************************//** + * @brief + * The getModality function returns the treatment modality received from + * the UI at treatment initiation. + * @details \b Inputs: modality + * @details \b Outputs: none + * @return Treatment modality selected by the user on the home screen. + *************************************************************************/ +TREATMENT_TYPE_T getModality( void ) +{ + return modality; +} + +/*********************************************************************//** + * @brief * The signalUserInitiateTreatment function handles user initiation of a * treatment. * @details \b Inputs: none - * @details \b Outputs: treatStartReqReceived + * @details \b Outputs: treatStartReqReceived, modality * @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; + BOOL result = FALSE; + U32 cmd = 0; + TD_OP_MODE_T mode = getCurrentOperationMode(); + REQUEST_REJECT_REASON_CODE_T rejReason = REQUEST_REJECT_REASON_NONE; + INITIATE_TREATMENT_REQUEST_PAYLOAD_T request; UI_RESPONSE_PAYLOAD_T response; - memset( &response, 0, sizeof( UI_RESPONSE_PAYLOAD_T ) ); - - // Verify message payload length is valid. - if ( sizeof( U32 ) == message->hdr.payloadLen ) + // Verify message payload length is valid + if ( sizeof( INITIATE_TREATMENT_REQUEST_PAYLOAD_T ) == message->hdr.payloadLen ) { - memcpy( &cmd, message->payload, sizeof( U32 ) ); + memcpy( &request, message->payload, sizeof( INITIATE_TREATMENT_REQUEST_PAYLOAD_T ) ); + cmd = request.command; + if ( USER_COMMAND_INITIATE == cmd ) { // Verify TD is in Standby mode and waiting for treatment start request. if ( ( MODE_STAN != mode ) || ( STANDBY_WAIT_FOR_TREATMENT_STATE != currentStandbyState ) ) { rejReason = REQUEST_REJECT_REASON_NOT_ALLOWED_IN_CURRENT_MODE; } - + else if ( request.modality >= NUM_OF_TREATMENT_MODALITY_TYPES ) + { + rejReason = REQUEST_REJECT_REASON_INVALID_COMMAND; + } #ifndef TEST_UI_ONLY // Verify DD is communicating. else if ( TRUE != isDDCommunicating() ) @@ -438,6 +512,8 @@ // If request to start treatment not rejected, set flag to initiate treatment workflow. result = TRUE; treatStartReqReceived = TRUE; + // Save modality to set later + modality = (TREATMENT_TYPE_T)request.modality; } } else if ( USER_COMMAND_CANCEL == cmd )