16 bool isExtended)
const {
17 const FrameKey key(canId, isExtended);
18 const std::unordered_map<FrameKey, std::size_t, FrameKeyHasher>::const_iterator it =
19 database.frameIndexByKey.find(key);
21 if (it == database.frameIndexByKey.end())
24 const std::size_t index = it->second;
25 if (index >= database.frames.size())
28 return &database.frames[index];
36 if (definition ==
nullptr)
42 for (std::size_t signalIndex = 0U; signalIndex < definition->signals.size(); ++signalIndex) {
43 const DecodeSignal &signal = definition->signals[signalIndex];
45 std::uint64_t unsignedValue = 0U;
49 if (!ExtractUnsigned(frame.
data, signal, unsignedValue)) {
50 decoded.
valid =
false;
51 result.signals.push_back(decoded);
55 if (signal.
valueType == ValueType::Signed)
61 if (
const auto *signedValue = std::get_if<std::int64_t>(&decoded.
rawValue))
62 numericValue =
static_cast<double>(*signedValue);
64 numericValue =
static_cast<double>(std::get<std::uint64_t>(decoded.
rawValue));
68 result.signals.push_back(decoded);
74bool DbcDecoder::ExtractUnsigned(
const std::vector<std::uint8_t> &data,
76 std::uint64_t &value) {
83 return ExtractMotorola(data, signal.
startBit, signal.
length, value);
86bool DbcDecoder::ExtractIntel(
const std::vector<std::uint8_t> &data,
87 std::uint32_t startBit,
89 std::uint64_t &value) {
92 for (std::uint32_t bitIndex = 0U; bitIndex < length; ++bitIndex) {
93 const std::uint32_t absoluteBit = startBit + bitIndex;
94 const std::uint32_t byteIndex = absoluteBit / 8U;
95 const std::uint32_t bitInByte = absoluteBit % 8U;
97 if (byteIndex >= data.size())
100 const std::uint64_t bitValue =
101 (
static_cast<std::uint64_t
>((data[byteIndex] >> bitInByte) & 0x01U) << bitIndex);
109bool DbcDecoder::ExtractMotorola(
const std::vector<std::uint8_t> &data,
110 std::uint32_t startBit,
111 std::uint32_t length,
112 std::uint64_t &value) {
123 std::size_t byteIndex = startBit / 8U;
124 std::uint32_t bitInByte = startBit % 8U;
126 for (std::uint32_t bitIndex = 0U; bitIndex < length; ++bitIndex) {
127 if (byteIndex >= data.size())
131 value |=
static_cast<std::uint64_t
>((data[byteIndex] >> bitInByte) & 0x01U);
133 if (bitInByte == 0U) {
143std::int64_t DbcDecoder::SignExtend(std::uint64_t value, std::uint32_t bitLength) {
144 if ((bitLength == 0U) || (bitLength > 64U))
147 const std::uint64_t signMask = std::uint64_t(1U) << (bitLength - 1U);
148 const std::uint64_t valueMask = (bitLength == 64U)
150 : (std::uint64_t(1U) << bitLength) - 1U;
153 if ((value & signMask) == 0U)
154 return static_cast<std::int64_t
>(value);
157 return -1 -
static_cast<std::int64_t
>((~value) & valueMask);
DecodedFrameValue Decode(const DecodeDatabase &database, const RawCanFrame &frame) const
Decode one raw CAN frame.
const DecodeFrame * FindFrame(const DecodeDatabase &database, std::uint32_t canId, bool isExtended) const
Find frame definition by CAN ID.
Created: 2026-03-13 Author: Deeaitch (Dim. Himro)
Runtime decode database with fast lookup by CAN ID.
Runtime-ready frame definition.
Runtime-ready signal definition.
const DecodeFrame * definition
One decoded signal value.
std::variant< std::int64_t, std::uint64_t > rawValue
const DecodeSignal * definition
Key for fast frame lookup.
Raw CAN frame used for runtime or trace decoding.
std::vector< std::uint8_t > data