DBC Framework
DBC parsing and CAN signal decoding framework
Loading...
Searching...
No Matches
dbc_decoder.h
Go to the documentation of this file.
1
12#ifndef DBC_DECODER_H
13#define DBC_DECODER_H
14
15#include <cstdint>
16#include <variant>
17#include <vector>
18
19#include "decode_database.h"
20
25 std::uint32_t canId = 0U;
26 bool isExtended = false;
27 std::vector<std::uint8_t> data;
29 RawCanFrame() = default;
30};
31
32enum class SignalDecodeStatus {
33 InvalidDefinition,
34 InsufficientPayload,
35 SelectorUnavailable,
36 Inactive,
37 Valid
38};
39
44 std::shared_ptr<const DecodeSignal> definition;
46 RawSignalValue rawValue = std::uint64_t(0U);
47 double physicalValue = 0.0;
48 bool valid = false;
49 SignalDecodeStatus status = SignalDecodeStatus::InvalidDefinition;
50
52 const std::string *GetValueDescription() const {
53 return valid && definition ? FindValueDescription(definition->valueDescriptions, rawValue) : nullptr;
54 }
55
56 DecodedSignalValue() = default;
57};
58
63 std::shared_ptr<const DecodeFrame> definition;
65 std::vector<DecodedSignalValue> signals;
66 bool valid = false;
68 DecodedFrameValue() = default;
69};
70
75public:
83 std::shared_ptr<const DecodeFrame> FindFrame(const DecodeDatabase &database,
84 std::uint32_t canId,
85 bool isExtended) const;
86
94 const RawCanFrame &frame) const;
95
96private:
97 struct SelectorState {
98 const DecodeSignal *definition = nullptr;
99 bool valid = false;
100 bool available = false;
101 std::uint64_t value = 0U;
102 };
103
104 static SelectorState ReadSelector(const DecodeFrame &definition, const RawCanFrame &frame);
105 static DecodedSignalValue DecodeOneSignal(const DecodeSignal &signal,
106 const RawCanFrame &frame,
107 const SelectorState &selector);
108
109 static bool ExtractUnsigned(const std::vector<std::uint8_t> &data,
110 const DecodeSignal &signal,
111 std::uint64_t &value);
112
113 static bool ExtractIntel(const std::vector<std::uint8_t> &data,
114 std::uint32_t startBit,
115 std::uint32_t length,
116 std::uint64_t &value);
117
118 static bool ExtractMotorola(const std::vector<std::uint8_t> &data,
119 std::uint32_t startBit,
120 std::uint32_t length,
121 std::uint64_t &value);
122
123 static std::int64_t SignExtend(std::uint64_t value, std::uint32_t bitLength);
124};
125
126#endif /* DBC_DECODER_H */
Runtime CAN decoder using prebuilt decode database.
Definition dbc_decoder.h:74
DecodedFrameValue Decode(const DecodeDatabase &database, const RawCanFrame &frame) const
Decode one raw CAN frame.
std::shared_ptr< const DecodeFrame > FindFrame(const DecodeDatabase &database, std::uint32_t canId, bool isExtended) const
Find frame definition by CAN ID.
Immutable runtime snapshot. Copies share storage; reload replaces a snapshot. Owning lookup handles a...
Created: 2026-03-13 Author: Deeaitch (Dim. Himro)
Runtime-ready frame definition.
Runtime-ready signal definition.
Fully decoded frame.
Definition dbc_decoder.h:62
std::shared_ptr< const DecodeFrame > definition
Definition dbc_decoder.h:63
One decoded signal value.
Definition dbc_decoder.h:43
RawSignalValue rawValue
Definition dbc_decoder.h:46
std::shared_ptr< const DecodeSignal > definition
Definition dbc_decoder.h:44
const std::string * GetValueDescription() const
Definition dbc_decoder.h:52
Stable frame identifier: normalized CAN ID and frame type.
Raw CAN frame used for runtime or trace decoding.
Definition dbc_decoder.h:24
std::vector< std::uint8_t > data
Definition dbc_decoder.h:27
std::uint32_t canId
Definition dbc_decoder.h:25
bool isExtended
Definition dbc_decoder.h:26