DBC parser initial commit.

This commit is contained in:
2026-03-13 13:00:01 -04:00
parent 4270459973
commit 2a90b2d79d
11 changed files with 789 additions and 0 deletions

51
dbc_parser.h Normal file
View File

@@ -0,0 +1,51 @@
#ifndef DBC_PARSER_H
#define DBC_PARSER_H
#include <string>
#include <vector>
#include <cstdint>
#include "dbc_database.h"
/**
* @brief Minimal DBC parser.
*
* Supports:
* - BO_
* - SG_
* - CM_ BO_
* - CM_ SG_
*
* Ignores:
* - attributes
* - multiplexing
* - value tables
*/
class DbcParser {
public:
/**
* @brief Parse DBC file.
* @param filePath Path to input file.
* @return Parsed database.
* @throws std::runtime_error on file or parse errors.
*/
DbcDatabase ParseFile (const std::string &filePath) const;
private:
static bool IsFrameLine (const std::string &line);
static bool IsSignalLine (const std::string &line);
static bool IsCommentLine (const std::string &line);
static std::string Trim (const std::string &text);
static std::vector<std::string> SplitReceivers (const std::string &text);
static std::uint32_t TryExtractPgn (std::uint32_t canId, bool &hasPgn);
static FrameInfo ParseFrameLine (const std::string &line);
static SignalInfo ParseSignalLine (const std::string &line);
static void ParseCommentLine (const std::string &line, DbcDatabase &database);
static FrameInfo *FindFrameById (DbcDatabase &database, std::uint32_t canId);
static SignalInfo *FindSignalByName (FrameInfo &frame, const std::string &signalName);
};
#endif /* DBC_PARSER_H */