DBC framework
decode_database.h
Go to the documentation of this file.
1/**
2 * @file decode_database.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 DECODE_DATABASE_H
13#define DECODE_DATABASE_H
14
15#include <string>
16#include <vector>
17#include <unordered_map>
18#include <cstdint>
19
20/**
21 * @brief Signal byte order used for runtime decoding.
22 */
23enum class ByteOrder {
24 Intel,
26};
27
28/**
29 * @brief Signal numeric type.
30 */
31enum class ValueType {
33 Signed
34};
35
36/**
37 * @brief Runtime-ready signal definition.
38 */
40 std::string name; /**< Signal name. */
41 std::uint32_t startBit; /**< DBC start bit. */
42 std::uint32_t length; /**< Signal length in bits. */
43 ByteOrder byteOrder; /**< Intel or Motorola. */
44 ValueType valueType; /**< Signed or unsigned. */
45 double factor; /**< Scaling factor. */
46 double offset; /**< Physical offset. */
47 double minimum; /**< Minimum physical value. */
48 double maximum; /**< Maximum physical value. */
49 std::string unit; /**< Physical unit. */
50 std::vector<std::string> receivers; /**< Receivers. */
51 std::string comment; /**< Comment. */
52
54 : name()
55 , startBit (0U)
56 , length (0U)
59 , factor (1.0)
60 , offset (0.0)
61 , minimum (0.0)
62 , maximum (0.0)
63 , unit()
64 , receivers()
65 , comment() {
66 }
67};
68
69/**
70 * @brief Runtime-ready frame definition.
71 */
73 std::string name; /**< Frame name. */
74 std::uint32_t canId; /**< Normalized CAN ID. */
75 bool isExtended; /**< true for extended frame. */
76 std::uint8_t dlc; /**< Payload length. */
77 std::uint32_t pgn; /**< PGN if available. */
78 bool hasPgn; /**< true if PGN is valid. */
79 std::string transmitter; /**< Transmitter ECU. */
80 std::string comment; /**< Frame comment. */
81 std::vector<DecodeSignal> signals; /**< Signal definitions. */
82
84 : name()
85 , canId (0U)
86 , isExtended (false)
87 , dlc (0U)
88 , pgn (0U)
89 , hasPgn (false)
90 , transmitter()
91 , comment()
92 , signals() {
93 }
94};
95
96/**
97 * @brief Key for fast frame lookup.
98 */
99struct FrameKey {
100 std::uint32_t canId;
102
104 : canId (0U)
105 , isExtended (false) {
106 }
107
108 FrameKey (std::uint32_t id, bool extended)
109 : canId (id)
110 , isExtended (extended) {
111 }
112
113 bool operator== (const FrameKey &other) const {
114 return (canId == other.canId) && (isExtended == other.isExtended);
115 }
116};
117
118/**
119 * @brief Hasher for frame key.
120 */
122 std::size_t operator() (const FrameKey &key) const {
123 const std::size_t a = static_cast<std::size_t> (key.canId);
124 const std::size_t b = key.isExtended ? 1U : 0U;
125 return (a * 1315423911U) ^ b;
126 }
127};
128
129/**
130 * @brief Runtime decode database with fast lookup by CAN ID.
131 */
133 std::vector<DecodeFrame> frames;
134 std::unordered_map<FrameKey, std::size_t, FrameKeyHasher> frameIndexByKey;
135};
136
137#endif /* DECODE_DATABASE_H */
ByteOrder
Signal byte order used for runtime decoding.
ValueType
Signal numeric type.
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::uint32_t pgn
std::string comment
std::vector< DecodeSignal > signals
std::uint8_t dlc
std::uint32_t canId
std::string name
std::string transmitter
Runtime-ready signal definition.
std::string unit
std::string name
ValueType valueType
std::uint32_t startBit
std::vector< std::string > receivers
ByteOrder byteOrder
std::uint32_t length
std::string comment
Hasher for frame key.
std::size_t operator()(const FrameKey &key) const
Key for fast frame lookup.
std::uint32_t canId
FrameKey(std::uint32_t id, bool extended)
bool operator==(const FrameKey &other) const