Index: firmware/App/Modes/ModeStandby.c =================================================================== diff -u -rce9145f506c3b7b970285bf2ab2e464b66f83bab -r027a8c7ac2a20cae3304dd6d72d54a1edbc19820 --- firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision ce9145f506c3b7b970285bf2ab2e464b66f83bab) +++ firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision 027a8c7ac2a20cae3304dd6d72d54a1edbc19820) @@ -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 ) Index: firmware/App/Services/AlarmMgmtTD.c =================================================================== diff -u -r593393009f0796d971fd90ce072bee561109debc -r027a8c7ac2a20cae3304dd6d72d54a1edbc19820 --- firmware/App/Services/AlarmMgmtTD.c (.../AlarmMgmtTD.c) (revision 593393009f0796d971fd90ce072bee561109debc) +++ firmware/App/Services/AlarmMgmtTD.c (.../AlarmMgmtTD.c) (revision 027a8c7ac2a20cae3304dd6d72d54a1edbc19820) @@ -7,8 +7,8 @@ * * @file AlarmMgmtTD.c * -* @author (last) Dara Navaei -* @date (last) 01-Aug-2025 +* @author (last) Praneeth Bunne +* @date (last) 11-Jun-2026 * * @author (original) Sean Nash * @date (original) 01-Aug-2024 @@ -22,6 +22,7 @@ #include "AlarmMgmtTD.h" #include "Bubbles.h" #include "CpldInterface.h" +#include "FluidBolus.h" #include "Messaging.h" #include "OperationModes.h" #include "TaskGeneral.h" @@ -236,13 +237,14 @@ if ( TRUE == props.alarmStops ) { alarmStatus.stop = TRUE; + // Signal when alarm with stop property is triggered to fluid bolus + signalNewStopAlarmActivated(); } // If alarm is a fault (and not in service mode), request transition to fault mode if ( ( TRUE == props.alarmIsFault ) && ( getCurrentOperationMode() != MODE_SERV ) ) { requestNewOperationMode( MODE_FAUL ); } - // If alarm has stop property, signal stop now if ( TRUE == props.alarmStops ) { Index: firmware/App/Services/StateServices/TubeSetInstall.c =================================================================== diff -u -rce9145f506c3b7b970285bf2ab2e464b66f83bab -r027a8c7ac2a20cae3304dd6d72d54a1edbc19820 --- firmware/App/Services/StateServices/TubeSetInstall.c (.../TubeSetInstall.c) (revision ce9145f506c3b7b970285bf2ab2e464b66f83bab) +++ firmware/App/Services/StateServices/TubeSetInstall.c (.../TubeSetInstall.c) (revision 027a8c7ac2a20cae3304dd6d72d54a1edbc19820) @@ -8,7 +8,7 @@ * @file TubeSetInstall.c * * @author (last) Praneeth Bunne -* @date (last) 04-Jun-2026 +* @date (last) 26-Jun-2026 * * @author (original) Praneeth Bunne * @date (original) 01-May-2026 @@ -52,6 +52,8 @@ static TUBE_SET_INSTALL_STATE_T previousInstallState; ///< Previous tube set install sub-state static TUBE_SET_INSTALL_STATE_T currentInstallState; ///< Current tubing set install sub-state +static TUBE_SET_TYPE_T currentTubeSetType; ///< Current installed tube set type + // ********** private function prototypes ********** static TUBE_SET_INSTALL_STATE_T handleAwaitTubesetConfirmationState( void ); ///< Handle Await Tubset Install Confirmation sub-state @@ -78,6 +80,7 @@ bloodPumpTimerCounter = 0; bpLastHome = TRUE; bpLeftHomeTimerCounter = 0; + currentTubeSetType = TUBE_SET_TYPE_UNKNOWN; } /*********************************************************************//** @@ -124,8 +127,8 @@ if ( previousInstallState != currentInstallState ) { - previousInstallState = currentInstallState; SEND_EVENT_WITH_2_U32_DATA( TD_EVENT_SUB_STATE_CHANGE, previousInstallState, currentInstallState ); + previousInstallState = currentInstallState; } } @@ -418,4 +421,71 @@ return result; } +/*********************************************************************//** +* The setTubeSetType function sets the current installed tube set type. + * @details \b Alarms: ALARM_ID_TD_SOFTWARE_FAULT if tube set is invalid type + * @details \b Inputs: none + * @details \b Outputs: currentTubeSetType + * @param type Tube set type determined from barcode scan. + * @return none + *************************************************************************/ +void setTubeSetType( TUBE_SET_TYPE_T type ) +{ + if ( type < NUM_OF_TUBE_SET_TYPES ) + { + currentTubeSetType = type; + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_TUBE_SET_TYPE, (U32)type ); + } +} + +/*********************************************************************//** + * @brief + * The getTubeSetType function returns the current installed tube set type. + * @details \b Inputs: currentTubeSetType + * @details \b Outputs: none + * @return Current installed tube set type. + *************************************************************************/ +TUBE_SET_TYPE_T getTubeSetType( void ) +{ + return currentTubeSetType; +} + +/*********************************************************************//** + * @brief + * The validateTubeSetType function validates the current installed tube set type + * based on modality. + * @details \b Alarm: + * @details \b Inputs: none + * @details \b Outputs: none + * @return none. + *************************************************************************/ +void validateTubeSetType( void ) +{ + U32 modality = getTreatmentParameterU32( TREATMENT_PARAM_TREATMENT_MODALITY ); + BOOL misMatch = FALSE; + + if ( TREATMENT_MODALITY_HDF_ONLINE_FLUID == modality ) + { + if ( TUBE_SET_TYPE_HDF != currentTubeSetType ) + { + misMatch = TRUE; + } + } + else + { + if ( TREATMENT_MODALITY_HD_SALINE_FLUID != currentTubeSetType ) + { + misMatch = TRUE; + } + } + + if ( TRUE == misMatch ) + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_TUBE_SET_MISMATCH, modality, (U32)currentTubeSetType ); + } +} + /**@}*/ Index: firmware/App/Services/StateServices/TubeSetInstall.h =================================================================== diff -u -r8345f0415ce34f2f47afcbf613a00216769f51c6 -r027a8c7ac2a20cae3304dd6d72d54a1edbc19820 --- firmware/App/Services/StateServices/TubeSetInstall.h (.../TubeSetInstall.h) (revision 8345f0415ce34f2f47afcbf613a00216769f51c6) +++ firmware/App/Services/StateServices/TubeSetInstall.h (.../TubeSetInstall.h) (revision 027a8c7ac2a20cae3304dd6d72d54a1edbc19820) @@ -35,23 +35,25 @@ /// Enumeration of Tube Set install sub-states. enum Tube_Set_Install_States { - TUBE_SET_INSTALL_STATE_AWAIT_TUBE_SET_CONFIRMATION = 0, ///< Awaiting user confirmation that tubeset is placed. - TUBE_SET_INSTALL_STATE_AWAIT_BP_DOOR_CLOSE, ///< Waiting for blood pump door to be closed. - TUBE_SET_INSTALL_STATE_AUTO_LOAD, ///< Auto-Load the tubeset state - TUBE_SET_INSTALL_STATE_AUTO_LOAD_BACK_OFF, ///< Auto-Load Back-off state - TUBE_SET_INSTALL_STATE_COMPLETE, ///< Install state complete - NUM_OF_TUBE_SET_INSTALL_SUB_STATES, ///< Num of install sub-states + TUBE_SET_INSTALL_STATE_AWAIT_TUBE_SET_CONFIRMATION = 0, // Awaiting user confirmation that tubeset is placed. + TUBE_SET_INSTALL_STATE_AWAIT_BP_DOOR_CLOSE, // Waiting for blood pump door to be closed. + TUBE_SET_INSTALL_STATE_AUTO_LOAD, // Auto-Load the tubeset state + TUBE_SET_INSTALL_STATE_AWAIT_SETUP_CONNECTION_CONFIRMATION, // Awaiting user confirmation that setup connections are complete. + TUBE_SET_INSTALL_STATE_AUTO_LOAD_BACK_OFF, // Auto-Load Back-off state + TUBE_SET_INSTALL_STATE_COMPLETE, // Install state complete + NUM_OF_TUBE_SET_INSTALL_SUB_STATES, // Num of install sub-states }; /// Type for tube set install states enumeration typedef enum Tube_Set_Install_States TUBE_SET_INSTALL_STATE_T; // ********** public function prototypes ********** -void initTubeSetInstall( void ); // Initialize this service -void execTubeSetInstall( void ); // Execute the service state machine (call from ModePreTreat and ModeTreatment) +void initTubeSetInstall( void ); // Initialize this service +void execTubeSetInstall( void ); // Execute the service state machine (call from ModePreTreat and ModeTreatment) -BOOL isTubeSetInstallComplete( void ); // Returns True once auto-load finished successfully -BOOL handleAutoLoadRequest( MESSAGE_T *message ); // Handle UI auto-load confirmation request +BOOL isTubeSetInstallComplete( void ); // Returns True once auto-load finished successfully +BOOL handleAutoLoadRequest( MESSAGE_T *message ); // Handle UI auto-load confirmation request +BOOL handleSetupTubingSetConnectionConfirmRequest( MESSAGE_T *message ); // Handle UI setup tubing set connection confirmation request void setTubeSetType( TUBE_SET_TYPE_T type ); // Set the current installed tube set type TODO: Call this after implementing bar code logic TUBE_SET_TYPE_T getTubeSetType( void ); // Get the current installed tube set type Index: firmware/App/Services/TxParams.c =================================================================== diff -u -rce9145f506c3b7b970285bf2ab2e464b66f83bab -r027a8c7ac2a20cae3304dd6d72d54a1edbc19820 --- firmware/App/Services/TxParams.c (.../TxParams.c) (revision ce9145f506c3b7b970285bf2ab2e464b66f83bab) +++ firmware/App/Services/TxParams.c (.../TxParams.c) (revision 027a8c7ac2a20cae3304dd6d72d54a1edbc19820) @@ -7,8 +7,8 @@ * * @file TxParams.c * -* @author (last) Vijay Pamula -* @date (last) 11-Jun-2026 +* @author (last) Praneeth Bunne +* @date (last) 02-Jul-2026 * * @author (original) Varshini Nagabooshanam * @date (original) 02-Dec-2025 @@ -21,6 +21,7 @@ #include "BloodFlow.h" #include "Buttons.h" #include "Messaging.h" +#include "ModeStandby.h" #include "ModeTreatment.h" #include "ModePreTreat.h" #include "OperationModes.h" @@ -575,11 +576,11 @@ switch ( txType ) { - case TREATMENT_MODALITY_HDF: + case TREATMENT_MODALITY_HDF_ONLINE_FLUID: result = FALSE; break; - case TREATMENT_MODALITY_HD: + case TREATMENT_MODALITY_HD_SALINE_FLUID: result = ( ( ( param == TREATMENT_PARAM_HDF_DILUTION ) || ( param == TREATMENT_PARAM_SUBST_FLUID_VOLUME ) ) ? TRUE : FALSE ); break; @@ -738,6 +739,7 @@ F32 hepDR = stagedParams[ TREATMENT_PARAM_HEPARIN_DELIVERY_RATE ].sFlt; F32 hepBV = stagedParams[ TREATMENT_PARAM_HEPARIN_BOLUS_VOLUME ].sFlt; F32 txVol = hepBV + ( hepDR * ( hepST / (F32)SEC_PER_MIN ) ) + SYRINGE_PUMP_PRIME_VOLUME_ML + SYRINGE_PUMP_FILL_VOLUME_OFFSET_ML; + TREATMENT_TYPE_T modality = (TREATMENT_TYPE_T)stagedParams[ TREATMENT_PARAM_TREATMENT_MODALITY ].uInt; // Variable to validate acid conversion factor consistency U32 acidType = stagedParams[ TREATMENT_PARAM_ACID_CONCENTRATE ].uInt; @@ -768,6 +770,13 @@ result = FALSE; } + // Verify Rx entered modality with the treatment initiation modality + if ( modality != getModality() ) + { + reasons[ TREATMENT_PARAM_TREATMENT_MODALITY ] = REQUEST_REJECT_REASON_MODALITY_MISMATCH; + result = FALSE; + } + return result; }