Index: firmware/App/Modes/ModeStandby.c =================================================================== diff -u -r120487ddf3e3d69d1de5094d5252c037588e2ed8 -r069dee3a2428d3c6bb281db1844a372ae6e2063a --- firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision 120487ddf3e3d69d1de5094d5252c037588e2ed8) +++ firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision 069dee3a2428d3c6bb281db1844a372ae6e2063a) @@ -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 @@ -27,6 +27,8 @@ #include "Switches.h" #include "SystemCommTD.h" #include "TxParams.h" +#include "Valve3Way.h" +#include "Valves.h" /** * @addtogroup TDStandbyMode @@ -42,6 +44,9 @@ 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 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 ********** @@ -52,13 +57,16 @@ * @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 ) { currentStandbyState = STANDBY_START_STATE; treatStartReqReceived = FALSE; + homingInitiated = FALSE; + fluidType = FLUID_TYPE_UNKNOWN; + modality = TREATMENT_MODALITY_HD_SALINE_FLUID; } /*********************************************************************//** @@ -84,15 +92,22 @@ setAlarmUserActionEnabled( ALARM_USER_ACTION_END_TREATMENT, FALSE ); // Pumps should be off -// signalBloodPumpHardStop(); + signalBloodPumpHardStop(); // stopSyringePump(); // Set valves to default positions -// setValveAirTrap( VALVE_3WAY_COMMON_TO_CLOSED_STATE ); -// setValvePosition( H1_VALV, VALVE_POSITION_A_INSERT_EJECT ); -// setValvePosition( H19, VALVE_POSITION_A_INSERT_EJECT ); + 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 + doorClosedRequired( FALSE ); // door no longer required to be closed in standby mode // Request DD service record and usage information from DD // sendDGServiceRequestToDG(); @@ -153,23 +168,23 @@ // Wait for door to be closed so we can home actuators // if ( STATE_CLOSED == getSwitchState( H9_SWCH ) ) // { -// // If we haven't already initiated homing of actuators, initiate now -// if ( homingInitiated != TRUE ) -// { -// VALVE_T valve; -// -// // Home pumps and valves -// for ( valve = VDI; valve < NUM_OF_VALVES; ++valve ) -// { -// homeValve( valve, VALVE_NO_FORCE_HOME, VALVE_CARTRIDGE_MAY_BE_PRESENT ); -// } + // If we haven't already initiated homing of actuators, initiate now + if ( homingInitiated != TRUE ) + { + VALVE_T valve; + + // Home pumps and valves + for ( valve = FIRST_VALVE; valve < NUM_OF_VALVES; ++valve ) + { + homeValve( valve, FALSE, TRUE ); + } // homeBloodPump(); // homeDialInPump(); // homeDialOutPump(); // retractSyringePump(); -// -// homingInitiated = TRUE; -// } + + homingInitiated = TRUE; + } // else // { // // If homing has been initiated, wait for syringe pump to home and the verify force sensor calibration @@ -269,17 +284,67 @@ // Start treatment workflow with pretreatment mode requestNewOperationMode( MODE_PRET ); treatStartReqReceived = FALSE; + // Set fluid type + setFluidType( modality ); } return state; } /*********************************************************************//** * @brief + * 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 @@ -290,20 +355,27 @@ 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; // Verify message payload length is valid - if ( sizeof( U32 ) == message->hdr.payloadLen ) + 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 waiting for treatment start request if ( ( mode != MODE_STAN ) || ( 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 with HD else if ( isDDCommunicating() != TRUE ) @@ -321,6 +393,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 )