STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
board_simulator.SimulatedBoard Class Reference

Public Member Functions

 __init__ (self, name, board_config, target_ip, target_port, low_noise=False, board_index=0, sim_pt_targets=None, skip_startup=False, timing=None, sensor_hz=None, allow_ip_fallback=False)
 start (self)

Public Attributes

 name = name
 board_index = board_index
 config = board_config
 allow_ip_fallback = bool(allow_ip_fallback)
 target_ip = target_ip
 target_port = target_port
 low_noise = low_noise
 sim_pt_targets = sim_pt_targets or {}
 sensor_hz = sensor_hz
 timing = timing or TimingPathology()
 drift_ppm
 ip = board_config.get("ip", "127.0.0.1")
 board_id = board_config.get("board_id", 0)
str board_type_str = board_config.get("type", "PT")
list active_connectors
 listen_port = board_config.get("listen_port", 5005)
 board_type = type_map.get(self.board_type_str, BOARD_TYPE_PT)
str is_current_loop = "4-20 mA absolute"
 hp_pt_full_scale_psi = board_config.get("hp_pt_full_scale_psi", 5000.0)
 hp_pt_sense_resistor_ohms
 skip_startup = skip_startup
bool board_state = BOARD_STATE_ACTIVE if skip_startup else BOARD_STATE_SETUP
bool can_receive = False
dict valve_target = {ch: 0 for ch in self.active_connectors}
dict valve_pos = {ch: 0.0 for ch in self.active_connectors}
bool running = False
 sock = None
 thread = None
int packets_sent = 0

Protected Member Functions

 _board_ms (self, now)
 _jitter_delay (self)
 _run (self)
 _check_for_sensor_config (self)
 _step_ball_valve (self, now)
 _send_self_test (self)
 _send_heartbeat (self, ts_ms)
 _send_logs (self, ts_ms, seq)
 _send_sensor_data (self, ts_ms)
 _generate_data (self, sensor_id)

Protected Attributes

 _boot_epoch = time.time()
tuple _clock_base_ms
 _rebooted_at = None
 _jitter_rng = random.Random(0xD1AB70 + board_index * 7919)
list _pending_chunks = []
bool _skip_startup_self_test_sent = False
float _selftest_resend_until = 0.0
float _selftest_last_resend = 0.0
 _valve_last_step = time.time()
 _last_server_heartbeat = None

Detailed Description

Definition at line 79 of file board_simulator.py.

Constructor & Destructor Documentation

◆ __init__()

board_simulator.SimulatedBoard.__init__ ( self,
name,
board_config,
target_ip,
target_port,
low_noise = False,
board_index = 0,
sim_pt_targets = None,
skip_startup = False,
timing = None,
sensor_hz = None,
allow_ip_fallback = False )

Definition at line 80 of file board_simulator.py.

Member Function Documentation

◆ _board_ms()

board_simulator.SimulatedBoard._board_ms ( self,
now )
protected
Board clock (uint32 millis), with optional drift/offset/wrap pathologies.

Definition at line 273 of file board_simulator.py.

References _boot_epoch, _clock_base_ms, drift_ppm, and timing.

Referenced by _run(), and _send_self_test().

◆ _check_for_sensor_config()

◆ _generate_data()

◆ _jitter_delay()

board_simulator.SimulatedBoard._jitter_delay ( self)
protected
One-sided network delay in seconds (0 when jitter disabled).

Definition at line 281 of file board_simulator.py.

References _jitter_rng, and timing.

Referenced by _send_sensor_data().

◆ _run()

◆ _send_heartbeat()

◆ _send_logs()

board_simulator.SimulatedBoard._send_logs ( self,
ts_ms,
seq )
protected
Send a type-15 LOGS packet: a simple, board-identifying diagnostic line.
Wire format matches daq::create_log_packet / parse_log_packet:
  PacketHeader(6B: type,version,ts) + flags(1B) + text_len(2B LE) + text.
The sim always streams these (it does NOT gate on the config mode byte) so
the board→bridge→backend→frontend log path can be exercised end to end.

Definition at line 502 of file board_simulator.py.

References actuator_testing_gui.SensorReceiver.sock, ball_valve_gui.BallValveGui.sock, sock, combined_gui.UDPReceiver.sock, lc_calibration_gui.UDPReceiver.sock, pt_multi_gui.UDPReceiver.sock, sense_testing_gui.UDPReceiver.sock, solenoid_characterization_gui.UDPReceiver.sock, target_ip, and target_port.

Referenced by _run().

◆ _send_self_test()

board_simulator.SimulatedBoard._send_self_test ( self)
protected
Send SELF_TEST packet with pass results for all active connectors.

Wire format (matches firmware SensorHotfireCore.h):
  header(6B) + adc_good(1B) + num_sensors(1B) + N x (sensor_id(1B) + result(1B))

Firmware extracts sensor_0 (TDAC) from the results list and puts it in
the adc_good field. The DAQ bridge publishes adc_good as a sensor_id=0
Elodin row, then publishes each per-channel result separately.

Definition at line 460 of file board_simulator.py.

References _board_ms(), anonymous_namespace{config_broadcast_service_main.cpp}::BoardInfo.active_connectors, active_connectors, fsw::config::BoardConfig.active_connectors, board_type_str, min, actuator_testing_gui.SensorReceiver.sock, ball_valve_gui.BallValveGui.sock, sock, combined_gui.UDPReceiver.sock, lc_calibration_gui.UDPReceiver.sock, pt_multi_gui.UDPReceiver.sock, sense_testing_gui.UDPReceiver.sock, solenoid_characterization_gui.UDPReceiver.sock, target_ip, target_port, and time.time().

Referenced by _check_for_sensor_config(), and _run().

◆ _send_sensor_data()

board_simulator.SimulatedBoard._send_sensor_data ( self,
ts_ms )
protected

◆ _step_ball_valve()

board_simulator.SimulatedBoard._step_ball_valve ( self,
now )
protected
Read server heartbeats and actuator commands, apply the firmware's failsafe, and move
each valve toward its command at BALL_VALVE_TRAVEL_S per full stroke.

Like the firmware, CLOSE is refused while server heartbeats are not current, and the valve
opens itself 5 s after they stop. Unlike it, the gating only starts once a heartbeat has
been heard: a sim stack on loopback may never deliver the broadcast heartbeat, and a valve
that could never be closed would make the sim useless for exercising state transitions.

Definition at line 411 of file board_simulator.py.

References _last_server_heartbeat, _valve_last_step, actuator_testing_gui.ActuatorTestingWindow.board_state, ball_valve_gui.BallValveGui.board_state, board_state, sense_testing_gui.SenseTestingGUIWindow.board_state, can_receive, max, min, actuator_testing_gui.SensorReceiver.sock, ball_valve_gui.BallValveGui.sock, sock, combined_gui.UDPReceiver.sock, lc_calibration_gui.UDPReceiver.sock, pt_multi_gui.UDPReceiver.sock, sense_testing_gui.UDPReceiver.sock, solenoid_characterization_gui.UDPReceiver.sock, valve_pos, and valve_target.

Referenced by _run().

◆ start()

Member Data Documentation

◆ _boot_epoch

board_simulator.SimulatedBoard._boot_epoch = time.time()
protected

Definition at line 116 of file board_simulator.py.

Referenced by _board_ms(), and _run().

◆ _clock_base_ms

tuple board_simulator.SimulatedBoard._clock_base_ms
protected
Initial value:
= (
int(2**32 - 30_000 - self.timing.clock_offset_ms)
if self.timing.start_near_wrap
else 0
)

Definition at line 120 of file board_simulator.py.

Referenced by _board_ms(), and _run().

◆ _jitter_rng

board_simulator.SimulatedBoard._jitter_rng = random.Random(0xD1AB70 + board_index * 7919)
protected

Definition at line 127 of file board_simulator.py.

Referenced by _jitter_delay().

◆ _last_server_heartbeat

board_simulator.SimulatedBoard._last_server_heartbeat = None
protected

Definition at line 192 of file board_simulator.py.

Referenced by _step_ball_valve().

◆ _pending_chunks

board_simulator.SimulatedBoard._pending_chunks = []
protected

Definition at line 128 of file board_simulator.py.

Referenced by _run(), and _send_sensor_data().

◆ _rebooted_at

board_simulator.SimulatedBoard._rebooted_at = None
protected

Definition at line 125 of file board_simulator.py.

Referenced by _run().

◆ _selftest_last_resend

float board_simulator.SimulatedBoard._selftest_last_resend = 0.0
protected

Definition at line 186 of file board_simulator.py.

Referenced by _run().

◆ _selftest_resend_until

float board_simulator.SimulatedBoard._selftest_resend_until = 0.0
protected

Definition at line 185 of file board_simulator.py.

Referenced by _check_for_sensor_config(), and _run().

◆ _skip_startup_self_test_sent

bool board_simulator.SimulatedBoard._skip_startup_self_test_sent = False
protected

Definition at line 179 of file board_simulator.py.

Referenced by _run().

◆ _valve_last_step

board_simulator.SimulatedBoard._valve_last_step = time.time()
protected

Definition at line 191 of file board_simulator.py.

Referenced by _step_ball_valve().

◆ active_connectors

list board_simulator.SimulatedBoard.active_connectors
Initial value:
= [
int(c) for c in board_config.get("active_connectors", []) or []
]

Definition at line 136 of file board_simulator.py.

Referenced by _send_self_test(), and _send_sensor_data().

◆ allow_ip_fallback

board_simulator.SimulatedBoard.allow_ip_fallback = bool(allow_ip_fallback)

Definition at line 100 of file board_simulator.py.

Referenced by start().

◆ board_id

board_simulator.SimulatedBoard.board_id = board_config.get("board_id", 0)

Definition at line 131 of file board_simulator.py.

Referenced by _generate_data(), and _send_heartbeat().

◆ board_index

board_simulator.SimulatedBoard.board_index = board_index

Definition at line 95 of file board_simulator.py.

◆ board_state

bool board_simulator.SimulatedBoard.board_state = BOARD_STATE_ACTIVE if skip_startup else BOARD_STATE_SETUP

◆ board_type

board_simulator.SimulatedBoard.board_type = type_map.get(self.board_type_str, BOARD_TYPE_PT)

Definition at line 153 of file board_simulator.py.

Referenced by _check_for_sensor_config(), _generate_data(), _run(), and start().

◆ board_type_str

str board_simulator.SimulatedBoard.board_type_str = board_config.get("type", "PT")

Definition at line 132 of file board_simulator.py.

Referenced by _generate_data(), _run(), _send_self_test(), and _send_sensor_data().

◆ can_receive

bool board_simulator.SimulatedBoard.can_receive = False

Definition at line 175 of file board_simulator.py.

Referenced by _run(), _step_ball_valve(), and start().

◆ config

board_simulator.SimulatedBoard.config = board_config

Definition at line 96 of file board_simulator.py.

Referenced by engine.layerx.card.EngineSampler.__call__(), engine.core.chamber_solver.ChamberSolver._accel_chamber_pc(), engine.pipeline.time_varying_solver.TimeVaryingCoupledSolver._advance_walls(), engine.pipeline.cea_cache.CEACache._build_cache(), engine.pipeline.cea_cache.CEACache._build_cache_parallel(), engine.pipeline.cea_cache.CEACache._build_cache_sequential(), engine.pipeline.time_varying_solver.TimeVaryingCoupledSolver._build_walls(), calibration_robustness.BackupManager._cleanup_old_backups(), engine.core.chamber_solver.ChamberSolver._compute_cooling_efficiency(), engine.core.chamber_solver.ChamberSolver._evaluate_cooling_models(), engine.core.runner.PintleEngineRunner._evaluate_internal(), engine.core.chamber_solver.ChamberSolver._fluid_props(), engine.pipeline.time_varying_solver.TimeVaryingCoupledSolver._geometry(), engine.core.runner.PintleEngineRunner._get_ambient_pressure(), engine.core.chamber_solver.ChamberSolver._get_chamber_geometry(), engine.core.runner.PintleEngineRunner._get_elevation(), engine.core.chamber_solver.ChamberSolver._get_fuel_props(), engine.pipeline.time_varying_solver.TimeVaryingCoupledSolver._graphite_layers(), engine.core.chamber_solver.ChamberSolver._infer_injector_diameter(), engine.pipeline.time_varying_solver.TimeVaryingCoupledSolver._insert_backing(), engine.core.chamber_solver.ChamberSolver._liner_end(), engine.pipeline.time_varying_solver.TimeVaryingCoupledSolver._liner_layers(), engine.pipeline.cea_cache.CEACache._load_cache(), engine.core.chamber_solver.ChamberSolver._raise_supply_exceeds_demand(), engine.core.chamber_solver.ChamberSolver._rupe_R_opt(), engine.pipeline.cea_cache.CEACache._save_cache(), engine.pipeline.time_varying_solver.TimeVaryingCoupledSolver._station_loads(), engine.core.chamber_solver.ChamberSolver._wall_contour(), engine.pipeline.time_varying_solver.TimeVaryingCoupledSolver._wall_report(), engine.pipeline.cea_cache.CEACache.aux(), calibration_robustness.BackupManager.backup_calibration_state(), engine.pipeline.system_diagnostics.SystemDiagnostics.diagnose_all(), engine.pipeline.cea_cache.CEACache.eval(), engine.pipeline.cea_cache.CEACache.eval_cf_vac(), combined_fsw_gui.ConfigManager.get_actuator_label(), combined_fsw_gui.ConfigManager.get_sensor_label(), backend.state.AppState.has_config(), calibration_robustness.HealthMonitor.is_healthy(), engine.pipeline.time_varying_solver.TimeVaryingCoupledSolver.liner_end(), combined_fsw_gui.ConfigManager.load(), engine.core.chamber_solver.ChamberSolver.residual(), combined_fsw_gui.ConfigManager.save(), combined_fsw_gui.ConfigManager.set_actuator_label(), backend.state.AppState.set_config(), combined_fsw_gui.ConfigManager.set_sensor_label(), calibration_robustness.BackupManager.should_backup(), backend.state.AppState.snapshot(), engine.core.chamber_solver.ChamberSolver.solve(), engine.pipeline.time_varying_solver.TimeVaryingCoupledSolver.solve_time_step(), start(), test_robust_ddp_constraints.TestConstraints.test_all_constraints_safe(), test_robust_ddp_engine_wrapper.TestEngineWrapper.test_cache_stats(), test_robust_ddp_engine_wrapper.TestEngineWrapper.test_caching(), test_robust_ddp_engine_wrapper.TestEngineWrapper.test_clear_cache(), test_robust_ddp_constraints.TestConstraints.test_constraint_summary(), test_robust_ddp_engine_wrapper.TestEngineWrapper.test_convenience_function(), test_robust_ddp_constraints.TestConstraints.test_copv_minimum_constraint(), test_robust_ddp_constraints.TestConstraints.test_edge_cases(), test_robust_ddp_engine_wrapper.TestEngineWrapper.test_estimate_error_handling(), test_robust_ddp_engine_wrapper.TestEngineWrapper.test_estimate_from_pressures_mock(), test_robust_ddp_engine_wrapper.TestEngineWrapper.test_estimate_without_stability(), test_robust_ddp_constraints.TestConstraints.test_headroom_constraints(), test_robust_ddp_constraints.TestConstraints.test_injector_stiffness_constraints(), test_robust_ddp_constraints.TestConstraints.test_mixture_ratio_constraints(), test_robust_ddp_robustness.TestRobustness.test_multiple_updates_convergence(), test_robust_ddp_constraints.TestConstraints.test_multiple_violations(), test_robust_ddp_constraints.TestConstraints.test_nan_handling(), test_robust_ddp_dynamics.TestDynamics.test_regulator_behavior(), test_robust_ddp_robustness.TestRobustness.test_tube_propagate_basic(), test_robust_ddp_robustness.TestRobustness.test_tube_propagate_validation(), test_robust_ddp_robustness.TestRobustness.test_tube_propagate_widens(), test_robust_ddp_robustness.TestRobustness.test_tube_propagate_with_large_w_bar(), test_robust_ddp_constraints.TestConstraints.test_ullage_maximum_constraints(), test_robust_ddp_robustness.TestRobustness.test_update_bounds_basic(), test_robust_ddp_robustness.TestRobustness.test_update_bounds_beta(), test_robust_ddp_robustness.TestRobustness.test_update_bounds_ema_behavior(), test_robust_ddp_robustness.TestRobustness.test_update_bounds_inflation(), test_robust_ddp_robustness.TestRobustness.test_update_bounds_requires_mass_flow(), test_robust_ddp_robustness.TestRobustness.test_update_bounds_residual_spike(), test_robust_ddp_robustness.TestRobustness.test_update_bounds_with_engine_wrapper(), test_robust_ddp_engine_wrapper.TestEngineWrapper.test_wrapper_initialization(), calibration_robustness.CalibrationValidator.validate_calibration_coefficients(), calibration_robustness.CalibrationValidator.validate_consensus_state(), calibration_robustness.CalibrationValidator.validate_covariance_matrix(), calibration_robustness.CalibrationValidator.validate_pressure(), calibration_robustness.CalibrationValidator.validate_uncertainty(), and calibration_robustness.CalibrationValidator.validate_voltage().

◆ drift_ppm

board_simulator.SimulatedBoard.drift_ppm
Initial value:
= self.timing.clock_drift_ppm * (
1 if board_index % 2 == 0 else -1
)

Definition at line 113 of file board_simulator.py.

Referenced by _board_ms().

◆ hp_pt_full_scale_psi

board_simulator.SimulatedBoard.hp_pt_full_scale_psi = board_config.get("hp_pt_full_scale_psi", 5000.0)

Definition at line 165 of file board_simulator.py.

Referenced by _generate_data().

◆ hp_pt_sense_resistor_ohms

board_simulator.SimulatedBoard.hp_pt_sense_resistor_ohms
Initial value:
= board_config.get(
"hp_pt_sense_resistor_ohms", 120
)

Definition at line 166 of file board_simulator.py.

Referenced by _generate_data().

◆ ip

board_simulator.SimulatedBoard.ip = board_config.get("ip", "127.0.0.1")

Definition at line 130 of file board_simulator.py.

Referenced by start().

◆ is_current_loop

str board_simulator.SimulatedBoard.is_current_loop = "4-20 mA absolute"

Definition at line 160 of file board_simulator.py.

Referenced by _generate_data().

◆ listen_port

board_simulator.SimulatedBoard.listen_port = board_config.get("listen_port", 5005)

Definition at line 139 of file board_simulator.py.

Referenced by start().

◆ low_noise

board_simulator.SimulatedBoard.low_noise = low_noise

Definition at line 103 of file board_simulator.py.

Referenced by _generate_data(), and _send_sensor_data().

◆ name

board_simulator.SimulatedBoard.name = name

Definition at line 94 of file board_simulator.py.

Referenced by csv_to_eng.core.EngineMetadata.header_line().

◆ packets_sent

int board_simulator.SimulatedBoard.packets_sent = 0

Definition at line 197 of file board_simulator.py.

Referenced by _send_sensor_data().

◆ running

◆ sensor_hz

board_simulator.SimulatedBoard.sensor_hz = sensor_hz

Definition at line 108 of file board_simulator.py.

Referenced by _run().

◆ sim_pt_targets

board_simulator.SimulatedBoard.sim_pt_targets = sim_pt_targets or {}

Definition at line 104 of file board_simulator.py.

Referenced by _generate_data().

◆ skip_startup

board_simulator.SimulatedBoard.skip_startup = skip_startup

Definition at line 171 of file board_simulator.py.

Referenced by _run().

◆ sock

◆ target_ip

board_simulator.SimulatedBoard.target_ip = target_ip

◆ target_port

board_simulator.SimulatedBoard.target_port = target_port

◆ thread

board_simulator.SimulatedBoard.thread = None

Definition at line 196 of file board_simulator.py.

Referenced by start().

◆ timing

board_simulator.SimulatedBoard.timing = timing or TimingPathology()

Definition at line 111 of file board_simulator.py.

Referenced by _board_ms(), _jitter_delay(), _run(), and _send_sensor_data().

◆ valve_pos

dict board_simulator.SimulatedBoard.valve_pos = {ch: 0.0 for ch in self.active_connectors}

Definition at line 190 of file board_simulator.py.

Referenced by _generate_data(), and _step_ball_valve().

◆ valve_target

dict board_simulator.SimulatedBoard.valve_target = {ch: 0 for ch in self.active_connectors}

Definition at line 189 of file board_simulator.py.

Referenced by _step_ball_valve().


The documentation for this class was generated from the following file: