16 bool isExtended)
const {
17 const FrameKey key (canId, isExtended);
18 const std::unordered_map<FrameKey, std::size_t, FrameKeyHasher>::const_iterator it =
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) {
45 std::uint64_t unsignedValue = 0U;
50 decoded.
valid =
false;
51 result.
signals.push_back (decoded);
58 decoded.
rawValue =
static_cast<std::int64_t
> (unsignedValue);
64 result.
signals.push_back (decoded);
72 std::uint64_t &value) {
83 std::uint32_t startBit,
85 std::uint64_t &value) {
88 for (std::uint32_t bitIndex = 0U; bitIndex < length; ++bitIndex) {
89 const std::uint32_t absoluteBit = startBit + bitIndex;
90 const std::uint32_t byteIndex = absoluteBit / 8U;
91 const std::uint32_t bitInByte = absoluteBit % 8U;
93 if (byteIndex >= data.size())
96 const std::uint64_t bitValue =
97 (
static_cast<std::uint64_t
> ((data[byteIndex] >> bitInByte) & 0x01U) << bitIndex);
106 std::uint32_t startBit,
107 std::uint32_t length,
108 std::uint64_t &value) {
118 std::int32_t currentBit =
static_cast<std::int32_t
> (startBit);
120 for (std::uint32_t bitIndex = 0U; bitIndex < length; ++bitIndex) {
124 const std::uint32_t absoluteBit =
static_cast<std::uint32_t
> (currentBit);
125 const std::uint32_t byteIndex = absoluteBit / 8U;
126 const std::uint32_t bitFromMsb = absoluteBit % 8U;
127 const std::uint32_t bitInByte = 7U - bitFromMsb;
129 if (byteIndex >= data.size())
133 value |=
static_cast<std::uint64_t
> ((data[byteIndex] >> bitInByte) & 0x01U);
135 if ((absoluteBit % 8U) == 7U)
136 currentBit =
static_cast<std::int32_t
> ((byteIndex + 1U) * 8U);
145 if ((bitLength == 0U) || (bitLength >= 64U))
146 return static_cast<std::int64_t
> (value);
148 const std::uint64_t signMask = (
static_cast<std::uint64_t
> (1U) << (bitLength - 1U));
149 const std::uint64_t valueMask = (
static_cast<std::uint64_t
> (1U) << bitLength) - 1U;
153 if ((value & signMask) == 0U)
154 return static_cast<std::int64_t
> (value);
156 return static_cast<std::int64_t
> (value | (~valueMask));
static bool ExtractUnsigned(const std::vector< std::uint8_t > &data, const DecodeSignal &signal, std::uint64_t &value)
DecodedFrameValue Decode(const DecodeDatabase &database, const RawCanFrame &frame) const
Decode one raw CAN frame.
static std::int64_t SignExtend(std::uint64_t value, std::uint32_t bitLength)
const DecodeFrame * FindFrame(const DecodeDatabase &database, std::uint32_t canId, bool isExtended) const
Find frame definition by CAN ID.
static bool ExtractIntel(const std::vector< std::uint8_t > &data, std::uint32_t startBit, std::uint32_t length, std::uint64_t &value)
static bool ExtractMotorola(const std::vector< std::uint8_t > &data, std::uint32_t startBit, std::uint32_t length, std::uint64_t &value)
Created: 2026-03-13 Author: Deeaitch (Dim. Himro)
Runtime decode database with fast lookup by CAN ID.
std::vector< DecodeFrame > frames
std::unordered_map< FrameKey, std::size_t, FrameKeyHasher > frameIndexByKey
Runtime-ready frame definition.
std::vector< DecodeSignal > signals
Runtime-ready signal definition.
const DecodeFrame * definition
std::vector< DecodedSignalValue > signals
One decoded signal value.
const DecodeSignal * definition
Key for fast frame lookup.
Raw CAN frame used for runtime or trace decoding.
std::vector< std::uint8_t > data