/** * ldf_parser.h — LDF file parsing and data extraction. * * C++ equivalent of python/src/ldf_handler.py. * * Data structures mirror the Python dataclasses exactly. * The custom regex-based parser replaces Python's ldfparser library. */ #ifndef LDF_PARSER_H #define LDF_PARSER_H #include #include #include /** * One signal within a LIN frame. * Python equivalent: SignalInfo dataclass */ struct SignalInfo { QString name; // Signal identifier (e.g., "MotorSpeed") int bit_offset; // Starting bit position within the frame data int width; // Number of bits this signal occupies (1-64) int init_value; // Default/initial value defined in the LDF }; /** * One LIN frame with its metadata and signals. * Python equivalent: FrameInfo dataclass * * Note: `signal_list` is used instead of `signals` because Qt defines * `signals` as a macro for its meta-object system. */ struct FrameInfo { QString name; int frame_id; QString publisher; int length; bool is_master_tx; QVector signal_list; // Can't use "signals" — Qt macro collision }; /** * One entry in a schedule table. * * Two types: * 1. Frame entry: sends a named frame (frame_name set, data empty) * 2. Free-format: sends raw bytes (frame_name = "FreeFormat [XX XX ...]", data filled) * * Python equivalent: ScheduleEntryInfo dataclass */ struct ScheduleEntryInfo { QString frame_name; // Frame name, or "FreeFormat [XX ...]" for raw entries int delay_ms; // Delay in milliseconds QVector data; // Raw bytes for free-format entries (empty for frame entries) }; /** * One schedule table from the LDF. * Python equivalent: ScheduleTableInfo dataclass */ struct ScheduleTableInfo { QString name; QVector entries; }; /** * Complete parsed result of an LDF file. * Python equivalent: LdfData dataclass */ struct LdfData { QString file_path; QString protocol_version; QString language_version; int baudrate; // In bps (e.g., 19200) QString master_name; QVector slave_names; QVector tx_frames; // Master publishes (Tx panel) QVector rx_frames; // Slaves publish (Rx panel) QVector schedule_tables; }; /** * Parse an LDF file and return structured data for the GUI. * @throws std::runtime_error if the file can't be opened or parsed */ LdfData parseLdf(const QString& filePath); #endif // LDF_PARSER_H