This commit is contained in:
deeaitch committed 2026-10-05 18:37:20 -04:00
1 parent 8d82b13dad
commit b91cf4aae5
21 files changed
+1165 -1146

No files matched your search

+39 -46
View File
@@ -12,9 +12,9 @@
#ifndef DBC_DECODER_H
#define DBC_DECODER_H
#include <vector>
#include <cstdint>
#include <variant>
#include <vector>
#include "decode_database.h"
@@ -22,54 +22,47 @@
* @brief Raw CAN frame used for runtime or trace decoding.
*/
struct RawCanFrame {
std::uint32_t canId; /**< Normalized CAN ID. */
bool isExtended; /**< true for extended frame. */
std::vector<std::uint8_t> data; /**< Payload bytes. */
std::uint32_t canId; /**< Normalized CAN ID. */
bool isExtended; /**< true for extended frame. */
std::vector<std::uint8_t> data; /**< Payload bytes. */
RawCanFrame()
: canId (0U)
, isExtended (false)
, data() {
}
RawCanFrame()
: canId(0U), isExtended(false), data() {
}
};
/**
* @brief One decoded signal value.
*/
struct DecodedSignalValue {
const DecodeSignal *definition; /**< Signal definition. */
std::variant<std::int64_t, std::uint64_t> rawValue; /**< Exact signed or unsigned raw value. */
double physicalValue; /**< Converted physical value. */
bool valid; /**< true if decoding succeeded. */
const DecodeSignal *definition; /**< Signal definition. */
std::variant<std::int64_t, std::uint64_t> rawValue; /**< Exact signed or unsigned raw value. */
double physicalValue; /**< Converted physical value. */
bool valid; /**< true if decoding succeeded. */
DecodedSignalValue()
: definition (nullptr)
, rawValue (std::uint64_t (0U))
, physicalValue (0.0)
, valid (false) {
}
DecodedSignalValue()
: definition(nullptr), rawValue(std::uint64_t(0U)), physicalValue(0.0), valid(false) {
}
};
/**
* @brief Fully decoded frame.
*/
struct DecodedFrameValue {
const DecodeFrame *definition; /**< Frame definition. */
std::vector<DecodedSignalValue> signals; /**< Decoded signal values. */
bool valid; /**< true if frame was matched. */
const DecodeFrame *definition; /**< Frame definition. */
std::vector<DecodedSignalValue> signals; /**< Decoded signal values. */
bool valid; /**< true if frame was matched. */
DecodedFrameValue()
: definition (nullptr)
, signals()
, valid (false) {
}
DecodedFrameValue()
: definition(nullptr), signals(), valid(false) {
}
};
/**
* @brief Runtime CAN decoder using prebuilt decode database.
*/
class DbcDecoder {
public:
public:
/**
* @brief Find frame definition by CAN ID.
* @param database Runtime decode database.
@@ -77,9 +70,9 @@ class DbcDecoder {
* @param isExtended true for extended frame.
* @return Pointer to frame definition or nullptr.
*/
const DecodeFrame *FindFrame (const DecodeDatabase &database,
std::uint32_t canId,
bool isExtended) const;
const DecodeFrame *FindFrame(const DecodeDatabase &database,
std::uint32_t canId,
bool isExtended) const;
/**
* @brief Decode one raw CAN frame.
@@ -87,25 +80,25 @@ class DbcDecoder {
* @param frame Raw CAN frame.
* @return Decoded frame value.
*/
DecodedFrameValue Decode (const DecodeDatabase &database,
const RawCanFrame &frame) const;
DecodedFrameValue Decode(const DecodeDatabase &database,
const RawCanFrame &frame) const;
private:
static bool ExtractUnsigned (const std::vector<std::uint8_t> &data,
const DecodeSignal &signal,
std::uint64_t &value);
private:
static bool ExtractUnsigned(const std::vector<std::uint8_t> &data,
const DecodeSignal &signal,
std::uint64_t &value);
static bool ExtractIntel (const std::vector<std::uint8_t> &data,
std::uint32_t startBit,
std::uint32_t length,
std::uint64_t &value);
static bool ExtractIntel(const std::vector<std::uint8_t> &data,
std::uint32_t startBit,
std::uint32_t length,
std::uint64_t &value);
static bool ExtractMotorola (const std::vector<std::uint8_t> &data,
std::uint32_t startBit,
std::uint32_t length,
std::uint64_t &value);
static bool ExtractMotorola(const std::vector<std::uint8_t> &data,
std::uint32_t startBit,
std::uint32_t length,
std::uint64_t &value);
static std::int64_t SignExtend (std::uint64_t value, std::uint32_t bitLength);
static std::int64_t SignExtend(std::uint64_t value, std::uint32_t bitLength);
};
#endif /* DBC_DECODER_H */