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 "multiplexing.h"
18#include "value_descriptions.h"
19#include <cstdint>
20#include <memory>
21#include <string>
22#include <unordered_map>
23#include <vector>
24
28enum class ByteOrder {
29 Intel,
30 Motorola
31};
32
36enum class ValueType {
37 Unsigned,
38 Signed
39};
40
46 std::string name;
47 std::uint32_t startBit = 0U;
48 std::uint32_t length = 0U;
49 ByteOrder byteOrder = ByteOrder::Intel;
50 ValueType valueType = ValueType::Unsigned;
51 double factor = 1.0;
52 double offset = 0.0;
53 double minimum = 0.0;
54 double maximum = 0.0;
55 std::string unit;
56 std::vector<std::string> receivers;
57 ValueDescriptions valueDescriptions;
58 std::string comment;
60 AttributeMap attributes;
62 DecodeSignal() = default;
63};
64
69 std::string name;
70 std::uint32_t canId = 0U;
71 bool isExtended = false;
72 std::uint8_t dlc = 0U;
73 std::uint32_t pgn = 0U;
74 bool hasPgn = false;
75 std::string transmitter;
76 std::string comment;
77 std::vector<DecodeSignal> signals;
79 AttributeMap attributes;
80 std::optional<std::string> frameFormat;
81 std::optional<std::uint32_t> cycleTimeMs;
83 DecodeFrame() = default;
84
86 FrameKey GetKey() const {
87 return FrameKey(canId, isExtended);
88 }
89};
90
93 std::shared_ptr<const DecodeFrame> definition;
94 bool ambiguous = false;
95};
96
102public:
103 DecodeDatabase() = default;
109 explicit DecodeDatabase(const std::vector<DecodeFrame> &frames);
110
112 const std::vector<DecodeFrame> &GetFrames() const;
114 std::shared_ptr<const DecodeFrame> FindFrame(const FrameKey &key) const;
116 PgnLookupResult FindFrameByPgn(std::uint32_t pgn) const;
118 std::shared_ptr<const DecodeSignal> FindSignal(const SignalKey &key) const;
119
120private:
121 struct Storage {
122 std::vector<DecodeFrame> frames;
123 std::unordered_map<FrameKey, std::size_t, FrameKeyHasher> frameIndexByKey;
124
125 std::unordered_map<std::uint32_t, std::vector<std::size_t>> frameIndicesByPgn;
126
127 explicit Storage(const std::vector<DecodeFrame> &definitions);
128 };
129
130 std::shared_ptr<const Storage> storage;
131};
132
133#endif /* DECODE_DATABASE_H */
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.
std::shared_ptr< const DecodeFrame > definition