DBC Framework
DBC parsing and CAN signal decoding framework
decode_database.h
Go to the documentation of this file.
1
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
23enum class ByteOrder {
24 Intel,
25 Motorola
26};
27
31enum class ValueType {
32 Unsigned,
33 Signed
34};
35
40 std::string name;
41 std::uint32_t startBit;
42 std::uint32_t length;
45 double factor;
46 double offset;
47 double minimum;
48 double maximum;
49 std::string unit;
50 std::vector<std::string> receivers;
51 std::string comment;
54 : name()
55 , startBit (0U)
56 , length (0U)
57 , byteOrder (ByteOrder::Intel)
58 , valueType (ValueType::Unsigned)
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
73 std::string name;
74 std::uint32_t canId;
76 std::uint8_t dlc;
77 std::uint32_t pgn;
78 bool hasPgn;
79 std::string transmitter;
80 std::string comment;
81 std::vector<DecodeSignal> signals;
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
99struct FrameKey {
100 std::uint32_t canId;
101 bool isExtended;
102
103 FrameKey()
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
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
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.
Runtime-ready frame definition.
std::uint32_t pgn
std::string comment
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.
Key for fast frame lookup.