# Step 2 — LDF Loading & Display ## What Was Built LDF file parsing, GUI table population, baud rate detection, schedule table loading, and auto-reload on file change. ## Architecture ``` User clicks Browse → QFileDialog → file_path │ ▼ _load_ldf_file(path) │ ┌────────────┼────────────┐ ▼ ▼ ▼ parse_ldf() On error: Setup file (ldf_handler) show dialog watcher │ ▼ LdfData ┌────┼────────────┬──────────────┐ ▼ ▼ ▼ ▼ Baud Tx table Rx table Schedule rate (master (slave dropdown label frames) frames) ``` ## Key Module: ldf_handler.py Adapter between `ldfparser` library and our GUI. Converts complex library objects into simple dataclasses: | Dataclass | Purpose | |-----------|---------| | `LdfData` | Complete parsed result — baudrate, frames, schedules | | `FrameInfo` | One frame: name, ID, publisher, length, is_master_tx, signals | | `SignalInfo` | One signal: name, bit_offset, width, init_value | | `ScheduleTableInfo` | One schedule: name, entries [(frame_name, delay_ms)] | ### ldfparser API notes - `ldf.baudrate` returns bps * 1000 (19200 kbps → 19200000) — divide by 1000 - `frame.signal_map` is list of (bit_offset, LinSignal) tuples - `frame.publisher` is LinMaster or LinSlave — use isinstance() to classify - Schedule delay is in seconds (0.01 = 10ms) — multiply by 1000 ## Features - **LDF parsing**: Extracts frames, signals, schedules, baud rate - **Tx table**: Populated with master frames (name, ID, length, interval, data, signals) - **Rx table**: Prepared with slave frame definitions (data filled at runtime) - **Baud rate**: Auto-detected from LDF's LIN_speed field - **Schedule dropdown**: Populated with schedule table names - **Per-frame intervals**: Auto-filled from first schedule table - **Auto-reload**: QFileSystemWatcher detects file changes, re-parses automatically - **Error handling**: Invalid files show error dialog, don't corrupt GUI state ## Files | File | Purpose | |------|---------| | `python/src/ldf_handler.py` | LDF parsing adapter — parse_ldf() → LdfData | | `python/src/main_window.py` | Updated with _load_ldf_file(), table population, file watcher | | `python/tests/test_ldf_handler.py` | 27 tests for the parsing layer | | `python/tests/test_ldf_loading.py` | 20 tests for GUI integration | | `resources/sample.ldf` | Sample LIN 2.1 LDF with 4 frames, 2 schedule tables | ## Test Results - 79 total tests passing (Step 1: 32 + Step 2: 47) - Parser tests: valid/invalid files, frame classification, signal extraction, schedules - GUI tests: table population, baud rate, schedule combo, error handling, auto-reload