5.5 KiB
Control Panel — AI coding assistant quick guide
This file gives focused, actionable guidance for an AI coding agent to be immediately productive in this repository.
-
Big picture: Desktop Tkinter app that receives SAR/MFD image streams via UDP (custom SFP), processes images, displays them in separate windows, optionally overlays SAR on a stitched map, records GeoTIFFs, and can export KML for Google Earth. See README.md for full feature list.
-
Key entrypoints:
- Start app:
python -m controlpanel(runs controlpanel/main.py). - Main orchestrator:
ControlPanelAppin controlpanel/app_main.py.
- Start app:
-
State & patterns:
- Centralized shared state lives in
AppState(controlpanel/app_state.py). Prefer reading/updating via the provided methods (update_map_scale_factor,update_sar_overlay_shift,update_sar_parameters, etc.) rather than mutating attributes directly. - Inter-thread communication uses bounded
queue.Queueinstances created inControlPanelApp(SAR, MFD, mouse, tkinter). Producers must useput_queuehelpers incontrolpanel/utilsto avoid drops; consumers must handle full/drop counts tracked inAppState. - UI callbacks should schedule UI updates with
root.after_idle(...)or push totkinter_queueto avoid Tkinter thread issues.
- Centralized shared state lives in
-
Network / payload flow:
- Transport layer:
SfpTransport(controlpanel/core/sfp_transport.py) receives UDP fragments. - Payload processing:
ImagePayloadProcessor(controlpanel/core/receiver.py) reassembles and calls payload callbacks. - App registers handlers in
_setup_network_receiver()mappingord('S')-> SAR handler andord('M')-> MFD handler. Example: seepayload_handlersin controlpanel/app_main.py.
- Transport layer:
-
Image pipeline & display:
- Image normalization, palette application and LUT updates are coordinated in
ImagePipelineandDisplayManagermodules (controlpanel/core and controlpanel/gui/display.py). When adjusting visual params, callControlPanelApp.update_brightness_contrast_lut()andupdate_mfd_lut()then trigger_trigger_sar_update()/_trigger_mfd_update(). - MFD LUTs are created from
state.mfd_params(see_initialize_mfd_params()in controlpanel/app_state.py).
- Image normalization, palette application and LUT updates are coordinated in
-
Map & geospatial integration:
- Map features are optional and gated by
config.ENABLE_MAP_OVERLAYand the presence ofmercantile,pyproj, andPillow. If map libs are missing the app will log and disable map modules (seeMAP_MODULES_LOADEDin controlpanel/app_main.py). - GeoElevation integration is dynamic: set
GEOELEVATION_PROJECT_ROOT_PATHin controlpanel/config.py to point to a local GeoElevation project; the code will temporarily add the path tosys.pathand importget_point_elevation.
- Map features are optional and gated by
-
Configuration & logging:
- Primary config lives in controlpanel/config.py. Many debug flags (e.g.,
DEBUG_RECEIVER_PACKETS,DEBUG_IMAGE_RECORDER) control filtered logging.LOG_ROOT_LEVELandLOG_HANDLER_LEVELcontrol overall and handler levels; adjust flags for targeted verbosity.
- Primary config lives in controlpanel/config.py. Many debug flags (e.g.,
-
Developer workflows / run & debug tips:
- Run locally:
python -m controlpanelfrom repo root. - If using maps, ensure
mercantile,pyproj, andPilloware installed (checkrequirements.txtor wheel folder_req_packages). Missing map libs will result in graceful fallback with logs. - To reproduce image flows during development without a live UDP source, enable
config.USE_LOCAL_IMAGESorENABLE_TEST_MODE; theTestModeManagerproduces synthetic frames. Inspectcontrolpanel/core/test_mode_manager.py. - To debug import/runtime failures during startup, inspect console output:
__main__.pyprints critical errors before exiting.
- Run locally:
-
Project-specific conventions:
- Prefer using
controlpanel.utilshelper functions (put_queue,decimal_to_dms,generate_sar_kml,open_google_maps) rather than reimplementing parsing/formatting logic. - Respect BGR ordering used widely for colors (OpenCV convention) — state and LUTs use BGR tuples.
- Sizes: SAR raw shape is
config.SAR_WIDTH x config.SAR_HEIGHT(2048x2048 by default) and MFD is484x484— many buffers assume these constants.
- Prefer using
-
Where to change common behaviors:
- Network port/IP defaults: controlpanel/config.py (
DEFAULT_SER_IP,DEFAULT_SER_PORT). - Map provider and caching:
MAP_SERVICE_PROVIDER,MAP_CACHE_DIRECTORYinconfig.pyand implementations incontrolpanel/map/*. - SAR recording & KML output locations:
DEFAULT_SAR_RECORDING_DIRECTORYandKML_OUTPUT_DIRECTORYinconfig.py.
- Network port/IP defaults: controlpanel/config.py (
-
Files and modules to inspect first (quick tour):
- controlpanel/app_main.py — lifecycle, wiring, queues, and callbacks.
- controlpanel/app_state.py — canonical state and LUT logic.
- controlpanel/config.py — toggles, sizes, debug flags, paths.
- controlpanel/core/ (SFP transport, receiver, pipeline, recorder, test manager).
- controlpanel/gui/ (UI widgets, display manager, status bar).
If anything is unclear or you want additional examples (e.g., sample unit tests, a focused walkthrough on the SFP reassembly or map stitching), tell me which area and I will expand this file with specific code snippets and references.