DBC Framework
DBC parsing and CAN signal decoding framework
Loading...
Searching...
No Matches
decode_database.h
Go to the documentation of this file.
1
12#ifndef DECODE_DATABASE_H
13#define DECODE_DATABASE_H
14
15#include "attributes.h"
16#include "definition_key.h"
17#include "multiplex_graph.h"
18#include "multiplexing.h"
19#include "value_descriptions.h"
20#include <cstdint>
21#include <memory>
22#include <string>
23#include <unordered_map>
24#include <vector>
25
29enum class ByteOrder {
30 Intel,
31 Motorola
32};
33
37enum class ValueType {
38 Unsigned,
39 Signed
40};
41
47 std::string name;
48 std::uint32_t startBit = 0U;
49 std::uint32_t length = 0U;
50 ByteOrder byteOrder = ByteOrder::Intel;
51 ValueType valueType = ValueType::Unsigned;
52 double factor = 1.0;
53 double offset = 0.0;
54 double minimum = 0.0;
55 double maximum = 0.0;
56 std::string unit;
57 std::vector<std::string> receivers;
58 ValueDescriptions valueDescriptions;
59 std::string comment;
61 AttributeMap attributes;
63 DecodeSignal() = default;
64};
65
70 std::string name;
71 std::uint32_t canId = 0U;
72 bool isExtended = false;
73 std::uint8_t dlc = 0U;
74 std::uint32_t pgn = 0U;
75 bool hasPgn = false;
76 std::string transmitter;
77 std::string comment;
78 std::vector<DecodeSignal> signals;
80 AttributeMap attributes;
81 std::optional<std::string> frameFormat;
82 std::optional<std::uint32_t> cycleTimeMs;
84 DecodeFrame() = default;
85
87 FrameKey GetKey() const {
88 return FrameKey(canId, isExtended);
89 }
90};
91
94 std::shared_ptr<const DecodeFrame> definition;
95 bool ambiguous = false;
96};
97
103public:
104 DecodeDatabase() = default;
110 explicit DecodeDatabase(const std::vector<DecodeFrame> &frames);
111
113 const std::vector<DecodeFrame> &GetFrames() const;
115 std::shared_ptr<const DecodeFrame> FindFrame(const FrameKey &key) const;
117 PgnLookupResult FindFrameByPgn(std::uint32_t pgn) const;
119 std::shared_ptr<const DecodeSignal> FindSignal(const SignalKey &key) const;
120
121private:
122 friend class DbcDecoder;
123 const dbc_detail::MultiplexGraph &GetMultiplexGraph(const FrameKey &key) const;
124
125 struct Storage {
126 std::vector<dbc_detail::MultiplexGraph> multiplexGraphs;
127 std::vector<DecodeFrame> frames;
128 std::unordered_map<FrameKey, std::size_t, FrameKeyHasher> frameIndexByKey;
129
130 std::unordered_map<std::uint32_t, std::vector<std::size_t>> frameIndicesByPgn;
131
132 explicit Storage(const std::vector<DecodeFrame> &definitions);
133 };
134
135 std::shared_ptr<const Storage> storage;
136};
137
138#endif /* DECODE_DATABASE_H */
Runtime CAN decoder using prebuilt decode database.
Definition dbc_decoder.h:87
Immutable runtime snapshot. Copies share storage; reload replaces a snapshot. Owning lookup handles a...
std::shared_ptr< const DecodeSignal > FindSignal(const SignalKey &key) const
Return an owning signal handle, or an empty handle for a missing key.
std::shared_ptr< const DecodeFrame > FindFrame(const FrameKey &key) const
const std::vector< DecodeFrame > & GetFrames() const
PgnLookupResult FindFrameByPgn(std::uint32_t pgn) const
ByteOrder
Signal byte order used for runtime decoding.
ValueType
Signal numeric type.
Runtime-ready frame definition.
FrameKey GetKey() const
Return the stable normalized frame identifier.
std::uint32_t pgn
std::string comment
std::optional< std::string > frameFormat
std::uint8_t dlc
std::uint32_t canId
std::optional< std::uint32_t > cycleTimeMs
std::string name
AttributeMap attributes
std::string transmitter
Runtime-ready signal definition.
AttributeMap attributes
std::string unit
std::string name
ValueDescriptions valueDescriptions
ValueType valueType
std::uint32_t startBit
std::vector< std::string > receivers
ByteOrder byteOrder
std::uint32_t length
std::string comment
Multiplexing multiplexing
Stable frame identifier: normalized CAN ID and frame type.
Basic markers and optional explicit extended multiplexing condition.
std::shared_ptr< const DecodeFrame > definition