DBC framework
dbc_decoder.h
Go to the documentation of this file.
1/**
2 * @file dbc_decoder.h
3 * @brief
4 *
5 * Created: 2026-03-13
6 * Author: Deeaitch (Dim. Himro)
7 *
8 * Licensed under the MIT License.
9 * See LICENSE file in the project root for full license text.
10 */
11
12#ifndef DBC_DECODER_H
13#define DBC_DECODER_H
14
15#include <vector>
16#include <cstdint>
17
18#include "decode_database.h"
19
20/**
21 * @brief Raw CAN frame used for runtime or trace decoding.
22 */
24 std::uint32_t canId; /**< Normalized CAN ID. */
25 bool isExtended; /**< true for extended frame. */
26 std::vector<std::uint8_t> data; /**< Payload bytes. */
27
29 : canId (0U)
30 , isExtended (false)
31 , data() {
32 }
33};
34
35/**
36 * @brief One decoded signal value.
37 */
39 const DecodeSignal *definition; /**< Signal definition. */
40 std::int64_t rawValue; /**< Extracted raw integer value. */
41 double physicalValue; /**< Converted physical value. */
42 bool valid; /**< true if decoding succeeded. */
43
45 : definition (nullptr)
46 , rawValue (0)
47 , physicalValue (0.0)
48 , valid (false) {
49 }
50};
51
52/**
53 * @brief Fully decoded frame.
54 */
56 const DecodeFrame *definition; /**< Frame definition. */
57 std::vector<DecodedSignalValue> signals; /**< Decoded signal values. */
58 bool valid; /**< true if frame was matched. */
59
61 : definition (nullptr)
62 , signals()
63 , valid (false) {
64 }
65};
66
67/**
68 * @brief Runtime CAN decoder using prebuilt decode database.
69 */
71 public:
72 /**
73 * @brief Find frame definition by CAN ID.
74 * @param database Runtime decode database.
75 * @param canId Normalized CAN ID.
76 * @param isExtended true for extended frame.
77 * @return Pointer to frame definition or nullptr.
78 */
79 const DecodeFrame *FindFrame (const DecodeDatabase &database,
80 std::uint32_t canId,
81 bool isExtended) const;
82
83 /**
84 * @brief Decode one raw CAN frame.
85 * @param database Runtime decode database.
86 * @param frame Raw CAN frame.
87 * @return Decoded frame value.
88 */
90 const RawCanFrame &frame) const;
91
92 private:
93 static bool ExtractUnsigned (const std::vector<std::uint8_t> &data,
94 const DecodeSignal &signal,
95 std::uint64_t &value);
96
97 static bool ExtractIntel (const std::vector<std::uint8_t> &data,
98 std::uint32_t startBit,
99 std::uint32_t length,
100 std::uint64_t &value);
101
102 static bool ExtractMotorola (const std::vector<std::uint8_t> &data,
103 std::uint32_t startBit,
104 std::uint32_t length,
105 std::uint64_t &value);
106
107 static std::int64_t SignExtend (std::uint64_t value, std::uint32_t bitLength);
108};
109
110#endif /* DBC_DECODER_H */
Runtime CAN decoder using prebuilt decode database.
Definition: dbc_decoder.h:70
static bool ExtractUnsigned(const std::vector< std::uint8_t > &data, const DecodeSignal &signal, std::uint64_t &value)
Definition: dbc_decoder.cpp:70
DecodedFrameValue Decode(const DecodeDatabase &database, const RawCanFrame &frame) const
Decode one raw CAN frame.
Definition: dbc_decoder.cpp:31
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.
Definition: dbc_decoder.cpp:14
static bool ExtractIntel(const std::vector< std::uint8_t > &data, std::uint32_t startBit, std::uint32_t length, std::uint64_t &value)
Definition: dbc_decoder.cpp:82
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.
Runtime-ready frame definition.
Runtime-ready signal definition.
Fully decoded frame.
Definition: dbc_decoder.h:55
const DecodeFrame * definition
Definition: dbc_decoder.h:56
std::vector< DecodedSignalValue > signals
Definition: dbc_decoder.h:57
One decoded signal value.
Definition: dbc_decoder.h:38
std::int64_t rawValue
Definition: dbc_decoder.h:40
const DecodeSignal * definition
Definition: dbc_decoder.h:39
Raw CAN frame used for runtime or trace decoding.
Definition: dbc_decoder.h:23
std::vector< std::uint8_t > data
Definition: dbc_decoder.h:26
std::uint32_t canId
Definition: dbc_decoder.h:24
bool isExtended
Definition: dbc_decoder.h:25