Closes #7
This commit is contained in:
1 parent
8d82b13dad
commit
b91cf4aae5
21 files changed
+1165
-1146
No files matched your search
+52
-73
@@ -12,126 +12,105 @@
|
||||
#ifndef DECODE_DATABASE_H
|
||||
#define DECODE_DATABASE_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
* @brief Signal byte order used for runtime decoding.
|
||||
*/
|
||||
enum class ByteOrder {
|
||||
Intel,
|
||||
Motorola
|
||||
Intel,
|
||||
Motorola
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Signal numeric type.
|
||||
*/
|
||||
enum class ValueType {
|
||||
Unsigned,
|
||||
Signed
|
||||
Unsigned,
|
||||
Signed
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Runtime-ready signal definition.
|
||||
*/
|
||||
struct DecodeSignal {
|
||||
std::string name; /**< Signal name. */
|
||||
std::uint32_t startBit; /**< DBC start bit. */
|
||||
std::uint32_t length; /**< Signal length in bits. */
|
||||
ByteOrder byteOrder; /**< Intel or Motorola. */
|
||||
ValueType valueType; /**< Signed or unsigned. */
|
||||
double factor; /**< Scaling factor. */
|
||||
double offset; /**< Physical offset. */
|
||||
double minimum; /**< Minimum physical value. */
|
||||
double maximum; /**< Maximum physical value. */
|
||||
std::string unit; /**< Physical unit. */
|
||||
std::vector<std::string> receivers; /**< Receivers. */
|
||||
std::string comment; /**< Comment. */
|
||||
std::string name; /**< Signal name. */
|
||||
std::uint32_t startBit; /**< DBC start bit. */
|
||||
std::uint32_t length; /**< Signal length in bits. */
|
||||
ByteOrder byteOrder; /**< Intel or Motorola. */
|
||||
ValueType valueType; /**< Signed or unsigned. */
|
||||
double factor; /**< Scaling factor. */
|
||||
double offset; /**< Physical offset. */
|
||||
double minimum; /**< Minimum physical value. */
|
||||
double maximum; /**< Maximum physical value. */
|
||||
std::string unit; /**< Physical unit. */
|
||||
std::vector<std::string> receivers; /**< Receivers. */
|
||||
std::string comment; /**< Comment. */
|
||||
|
||||
DecodeSignal()
|
||||
: name()
|
||||
, startBit (0U)
|
||||
, length (0U)
|
||||
, byteOrder (ByteOrder::Intel)
|
||||
, valueType (ValueType::Unsigned)
|
||||
, factor (1.0)
|
||||
, offset (0.0)
|
||||
, minimum (0.0)
|
||||
, maximum (0.0)
|
||||
, unit()
|
||||
, receivers()
|
||||
, comment() {
|
||||
}
|
||||
DecodeSignal()
|
||||
: name(), startBit(0U), length(0U), byteOrder(ByteOrder::Intel), valueType(ValueType::Unsigned), factor(1.0), offset(0.0), minimum(0.0), maximum(0.0), unit(), receivers(), comment() {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Runtime-ready frame definition.
|
||||
*/
|
||||
struct DecodeFrame {
|
||||
std::string name; /**< Frame name. */
|
||||
std::uint32_t canId; /**< Normalized CAN ID. */
|
||||
bool isExtended; /**< true for extended frame. */
|
||||
std::uint8_t dlc; /**< Payload length. */
|
||||
std::uint32_t pgn; /**< PGN if available. */
|
||||
bool hasPgn; /**< true if PGN is valid. */
|
||||
std::string transmitter; /**< Transmitter ECU. */
|
||||
std::string comment; /**< Frame comment. */
|
||||
std::vector<DecodeSignal> signals; /**< Signal definitions. */
|
||||
std::string name; /**< Frame name. */
|
||||
std::uint32_t canId; /**< Normalized CAN ID. */
|
||||
bool isExtended; /**< true for extended frame. */
|
||||
std::uint8_t dlc; /**< Payload length. */
|
||||
std::uint32_t pgn; /**< PGN if available. */
|
||||
bool hasPgn; /**< true if PGN is valid. */
|
||||
std::string transmitter; /**< Transmitter ECU. */
|
||||
std::string comment; /**< Frame comment. */
|
||||
std::vector<DecodeSignal> signals; /**< Signal definitions. */
|
||||
|
||||
DecodeFrame()
|
||||
: name()
|
||||
, canId (0U)
|
||||
, isExtended (false)
|
||||
, dlc (0U)
|
||||
, pgn (0U)
|
||||
, hasPgn (false)
|
||||
, transmitter()
|
||||
, comment()
|
||||
, signals() {
|
||||
}
|
||||
DecodeFrame()
|
||||
: name(), canId(0U), isExtended(false), dlc(0U), pgn(0U), hasPgn(false), transmitter(), comment(), signals() {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Key for fast frame lookup.
|
||||
*/
|
||||
struct FrameKey {
|
||||
std::uint32_t canId;
|
||||
bool isExtended;
|
||||
std::uint32_t canId;
|
||||
bool isExtended;
|
||||
|
||||
FrameKey()
|
||||
: canId (0U)
|
||||
, isExtended (false) {
|
||||
}
|
||||
FrameKey()
|
||||
: canId(0U), isExtended(false) {
|
||||
}
|
||||
|
||||
FrameKey (std::uint32_t id, bool extended)
|
||||
: canId (id)
|
||||
, isExtended (extended) {
|
||||
}
|
||||
FrameKey(std::uint32_t id, bool extended)
|
||||
: canId(id), isExtended(extended) {
|
||||
}
|
||||
|
||||
bool operator== (const FrameKey &other) const {
|
||||
return (canId == other.canId) && (isExtended == other.isExtended);
|
||||
}
|
||||
bool operator==(const FrameKey &other) const {
|
||||
return (canId == other.canId) && (isExtended == other.isExtended);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Hasher for frame key.
|
||||
*/
|
||||
struct FrameKeyHasher {
|
||||
std::size_t operator() (const FrameKey &key) const {
|
||||
const std::size_t a = static_cast<std::size_t> (key.canId);
|
||||
const std::size_t b = key.isExtended ? 1U : 0U;
|
||||
return (a * 1315423911U) ^ b;
|
||||
}
|
||||
std::size_t operator()(const FrameKey &key) const {
|
||||
const std::size_t a = static_cast<std::size_t>(key.canId);
|
||||
const std::size_t b = key.isExtended ? 1U : 0U;
|
||||
return (a * 1315423911U) ^ b;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Runtime decode database with fast lookup by CAN ID.
|
||||
*/
|
||||
struct DecodeDatabase {
|
||||
std::vector<DecodeFrame> frames;
|
||||
std::unordered_map<FrameKey, std::size_t, FrameKeyHasher> frameIndexByKey;
|
||||
std::vector<DecodeFrame> frames;
|
||||
std::unordered_map<FrameKey, std::size_t, FrameKeyHasher> frameIndexByKey;
|
||||
};
|
||||
|
||||
#endif /* DECODE_DATABASE_H */
|
||||
Reference in new issue
Block a user