SXXXXXXX_PyBusMonitor1553/pybusmonitor1553/core/controller.py
2025-12-11 13:38:49 +01:00

96 lines
3.5 KiB
Python

from ..lib1553 import messages as msgs
from ..lib1553.constants import (
TargetHistory, RadarMode, AltitudeBlock,
RWSSubmode, GMSubmode
)
class RadarController:
"""
High-level controller for the Radar state.
Holds the instances of 1553 messages (A-Transmit / B-Receive).
Acts as the interface for the GUI or Scripts to modify radar behavior.
"""
def __init__(self):
# --- TX Messages (BC -> RT) ---
# These are the commands we send to the Radar
self.msg_a1 = msgs.MsgA1() # Settings
self.msg_a2 = msgs.MsgA2() # Commands
self.msg_a3 = msgs.MsgA3() # Graphics
self.msg_a4 = msgs.MsgA4() # Nav Data
self.msg_a5 = msgs.MsgA5() # INU Data
self.msg_a7 = msgs.MsgA7() # Data Link 1
self.msg_a8 = msgs.MsgA8() # Data Link 2
# --- RX Messages (RT -> BC) ---
# These are placeholders/requests we send to get data back
self.msg_b1 = msgs.MsgB1() # TWS 1-2
self.msg_b2 = msgs.MsgB2() # TWS 3-5
self.msg_b3 = msgs.MsgB3() # TWS 6-8
self.msg_b4 = msgs.MsgB4() # SPT
self.msg_b5 = msgs.MsgB5() # Tracked Target
self.msg_b6 = msgs.MsgB6() # Settings Tell-back
self.msg_b7 = msgs.MsgB7() # Status Tell-back
self.msg_b8 = msgs.MsgB8() # BIT Report
# Initialize default state immediately
self.apply_defaults()
def apply_defaults(self):
"""
Sets the default values for the radar commands.
Based on legacy initialization logic.
"""
print("[Controller] Applying default configuration...")
# --- A1: Settings ---
# Legacy: settings.set_history_level(TARGET_HISTORY_LEVEL_04)
self.msg_a1.target_history = TargetHistory.LEVEL_4
# Legacy: rdr_symbology_intensity = 127
self.msg_a1.symbol_intensity = 127
# Additional safe defaults for A1
self.msg_a1.altitude_block = AltitudeBlock.NORMAL
self.msg_a1.beacon_delay = 0.0
# --- A2: Operation Command ---
# Legacy: set_master_mode(RWS)
self.msg_a2.master_mode = RadarMode.RWS
# Legacy: set_gm_submode(0) -> RBM
self.msg_a2.gm_submode = GMSubmode.RBM
# Legacy: set_spare_0_4(0) -> (Handled by default 0 initialization)
# Ensure other modes are in a known state
self.msg_a2.rws_submode = RWSSubmode.NAM
# --- A3: Graphic ---
# Legacy: just instantiated (all zeros)
# Note: A3 controls symbology. 0 usually means nothing displayed.
# --- A4: Nav Data ---
# Legacy: validity_and_slew.raw = 0
# This implies all validity bits are 0 (Data is VALID)
self.msg_a4.nav_data_invalid = 0
self.msg_a4.attitude_data_invalid = 0
self.msg_a4.radalt_invalid = 0
# ... (MsgA4 initializes with 0s, so data is considered valid by default)
# --- A5: INU Data ---
# Legacy: timetag.raw = 0
self.msg_a5.time_tag = 0.0
print("[Controller] Defaults applied. Radar set to RWS.")
def set_master_mode(self, mode: RadarMode):
"""API to change the Radar Master Mode."""
self.msg_a2.master_mode = mode
print(f"[Controller] Master Mode set to: {mode.name}")
def update_navigation_data(self, alt=None, vel_x=None):
"""Example API to update navigation data."""
if alt is not None:
self.msg_a4.baro_inertial_alt = alt
if vel_x is not None:
self.msg_a5.velocity_x = vel_x