This commit is contained in:
deeaitch committed 2026-10-20 13:12:30 -04:00
1 parent fc97682b37
commit e555ebb571
16 files changed
+337 -52

No files matched your search

+5 -26
View File
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: MIT
#include "dbc_statement_handler.h"
#include "j1939.h"
#include "text_utils.h"
#include "signal_layout.h"
#include <charconv>
@@ -167,31 +168,6 @@ namespace {
normalizedCanId = rawCanId;
}
}
std::uint32_t TryExtractPgn(std::uint32_t canId, bool isExtended, bool &hasPgn) {
hasPgn = false;
if (!isExtended)
return 0U;
if ((canId & 0x1FFFFFFFU) != canId)
return 0U;
const std::uint32_t pf = (canId >> 16U) & 0xFFU;
const std::uint32_t ps = (canId >> 8U) & 0xFFU;
const std::uint32_t dp = (canId >> 24U) & 0x01U;
std::uint32_t pgn = 0U;
if (pf < 240U)
pgn = (dp << 16U) | (pf << 8U);
else
pgn = (dp << 16U) | (pf << 8U) | ps;
hasPgn = true;
return pgn;
}
} // namespace
FrameInfo DbcFrameHandler::ParseFrameLine(const std::string &line) {
@@ -228,7 +204,6 @@ FrameInfo DbcFrameHandler::ParseFrameLine(const std::string &line) {
throw std::runtime_error("Unexpected trailing field in frame definition: " + extra);
NormalizeCanId(rawCanId, frame.canId, frame.isExtended);
frame.pgn = TryExtractPgn(frame.canId, frame.isExtended, frame.hasPgn);
return frame;
}
@@ -307,6 +282,10 @@ namespace {
void DbcFrameHandler::Handle(const std::string &line, DbcParseContext &context) const {
FrameInfo frame = ParseFrameLine(line);
if (context.enableJ1939 && frame.isExtended) {
frame.hasPgn = true;
frame.pgn = ExtractJ1939Pgn(frame.canId);
}
if (FindFrameById(context.database, frame.canId, frame.isExtended) != nullptr)
throw std::runtime_error("Duplicate " + std::string(frame.isExtended ? "extended" : "standard") +
" frame CAN ID: " + std::to_string(frame.canId));