4.9 KiB
4.9 KiB
Copilot / AI agent instructions — Target Simulator (concise)
This file contains the minimal, repository-specific guidance an AI coding agent needs to be productive.
- Big picture
- Type: Python desktop app (Tkinter) that simulates radar targets and communicates with hardware/emulators via SFP/TFTP/Serial.
- Major areas:
target_simulator/core/— simulation, command builders, communicator interfaces (CommunicatorInterface is the contract).target_simulator/gui/— Tkinter windows;MainViewis the app host and coordinates simulation + communicators.target_simulator/utils/—ConfigManager, logging helpers (utils/logger.py), CSV trace helpers.
- Key workflows & commands (PowerShell)
- Run app (development): $env:PYTHONPATH='C:\src____GitProjects\target_simulator'; python -m target_simulator
- Open REPL with project path: $env:PYTHONPATH='C:\src____GitProjects\target_simulator'; python
- Run tests (coverage task available): use the workspace task labeled "pytest coverage report" or run directly: $env:PYTHONPATH='C:\src____GitProjects\target_simulator'; pytest --cov=target_simulator.core.models --cov-report=term-missing
- Project-specific patterns & conventions
- Absolute imports are used throughout;
__main__.pyinserts the project root intosys.pathfor convenience. - Persistence:
ConfigManagerstores general settings insettings.jsonand scenarios inscenarios.json(atomic write + rotating backups.bak1,.bak2). - Logging: central queue-based logging that forwards to console/file/GUI. Use
setup_basic_logging(app, LOGGING_CONFIG)andadd_tkinter_handler(widget, LOGGING_CONFIG); temporary increases viatemporary_log_level(logger, level). - Simulation:
SimulationEngineruns as a daemon thread and emits GUI updates via a Queue; do not change update semantics lightly — runtime sendstgtsetwithout qualifiers while debug GUI may include qualifiers. - Communicator contract: implement
CommunicatorInterface(methods likeconnect(config)->bool,disconnect(),send_commands(list), propertyis_open).SFPcommunicator supports deferred connect and an optional_use_json_protocolflag (checked by engine).
- Important implementation details to preserve
- Debug vs runtime sending: the SFP debug window intentionally sends
tgtsetwith state qualifiers (Active/Traceable/Restart) while the liveSimulationEngineusestgtsetwithout qualifiers to avoid changing lifecycle flags. Seegui/sfp_debug_window.pyandcore/command_builder.pyfor the builders. - Scenarios are saved to a separate
scenarios.json;ConfigManagerwill avoid overwriting it with empty data and performs atomic replace + rotating backups. MainView._setup_communicatorshows how new communicator types are wired (update this method when adding a protocol).
- Integration points & external artifacts
- Native libs: Tkinter (GUI). No heavy third-party dependencies are required for core features.
- Optional C++ helpers exist in
cpp/(e.g.,BupTFTP.cpp) but are not integrated by default. - Temporary CSV logs and traces live in
Temp/(filenames configured insettings.jsondebugblock).
- Files to inspect for common tasks (quick links)
- App start:
target_simulator/__main__.py - Main UI and lifecycle:
target_simulator/gui/main_view.py - Simulation loop and sending logic:
target_simulator/core/simulation_engine.py - Command builders:
target_simulator/core/command_builder.py - Communicators:
target_simulator/core/*.py(look forSFP,Serial,TFTPimplementations) - Persistence:
target_simulator/utils/config_manager.pyandsettings.json/scenarios.json - Logging helpers:
target_simulator/utils/logger.pyandlogger_prefs.json
- Small examples (copyable snippets)
- Enable module debug at runtime (REPL): import logging; logging.getLogger('target_simulator.gui.sfp_debug_window').setLevel(logging.DEBUG)
- Start app (PowerShell): $env:PYTHONPATH='C:\src____GitProjects\target_simulator'; python -m target_simulator
- When changing behavior
- If you change how commands are formatted (e.g.,
build_tgtset_*), update both the SimulationEngine logic and the SFP debug sender to keep debug vs runtime semantics clear. - If you add a new persistent key, prefer storing it under
generalinsettings.jsonviaConfigManager.save_general_settings().
- What the agent should not do automatically
- Do not change scenario storage semantics (moving scenarios back into
settings.json), sinceConfigManagerintentionally separates scenarios and performs backups.
- If more detail is needed
- Ask which area to expand (GUI wiring, communicator API, command builders, or logging). Provide the specific file and a brief goal and the agent will produce patches and tests.
If anything here is unclear or you want additional examples (unit tests, small refactors, or a runtime checklist), tell me which sections to expand and I will iterate.