2019-11-22 21:46:33 -08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <string>
|
2021-03-09 07:33:37 -08:00
|
|
|
#include <vector>
|
2019-11-22 21:46:33 -08:00
|
|
|
|
|
|
|
#define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
|
|
|
|
|
|
|
|
struct SignalPackValue {
|
2021-09-02 14:25:47 -07:00
|
|
|
std::string name;
|
2019-11-22 21:46:33 -08:00
|
|
|
double value;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SignalParseOptions {
|
|
|
|
uint32_t address;
|
2022-05-12 17:59:33 -07:00
|
|
|
std::string name;
|
2019-11-22 21:46:33 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct MessageParseOptions {
|
|
|
|
uint32_t address;
|
|
|
|
int check_frequency;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SignalValue {
|
|
|
|
uint32_t address;
|
2023-02-07 23:00:22 -08:00
|
|
|
uint64_t ts_nanos;
|
2022-05-12 17:59:33 -07:00
|
|
|
std::string name;
|
2022-02-10 13:01:30 -08:00
|
|
|
double value; // latest value
|
|
|
|
std::vector<double> all_values; // all values from this cycle
|
2019-11-22 21:46:33 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum SignalType {
|
|
|
|
DEFAULT,
|
2022-07-11 12:36:43 -07:00
|
|
|
COUNTER,
|
2019-11-22 21:46:33 -08:00
|
|
|
HONDA_CHECKSUM,
|
|
|
|
TOYOTA_CHECKSUM,
|
|
|
|
PEDAL_CHECKSUM,
|
2022-06-30 11:31:58 -07:00
|
|
|
VOLKSWAGEN_MQB_CHECKSUM,
|
2022-07-15 10:29:12 -07:00
|
|
|
XOR_CHECKSUM,
|
2020-04-13 15:06:28 -07:00
|
|
|
SUBARU_CHECKSUM,
|
2020-04-30 14:06:26 -07:00
|
|
|
CHRYSLER_CHECKSUM,
|
2022-05-15 18:26:19 -07:00
|
|
|
HKG_CAN_FD_CHECKSUM,
|
2019-11-22 21:46:33 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Signal {
|
2022-05-12 17:59:33 -07:00
|
|
|
std::string name;
|
2022-02-28 09:10:34 -08:00
|
|
|
int start_bit, msb, lsb, size;
|
2019-11-22 21:46:33 -08:00
|
|
|
bool is_signed;
|
|
|
|
double factor, offset;
|
|
|
|
bool is_little_endian;
|
|
|
|
SignalType type;
|
2022-06-30 11:31:58 -07:00
|
|
|
unsigned int (*calc_checksum)(uint32_t address, const Signal &sig, const std::vector<uint8_t> &d);
|
2019-11-22 21:46:33 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Msg {
|
2022-05-12 17:59:33 -07:00
|
|
|
std::string name;
|
2019-11-22 21:46:33 -08:00
|
|
|
uint32_t address;
|
|
|
|
unsigned int size;
|
2022-05-12 17:59:33 -07:00
|
|
|
std::vector<Signal> sigs;
|
2019-11-22 21:46:33 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Val {
|
2022-05-12 17:59:33 -07:00
|
|
|
std::string name;
|
2019-11-22 21:46:33 -08:00
|
|
|
uint32_t address;
|
2022-05-12 17:59:33 -07:00
|
|
|
std::string def_val;
|
|
|
|
std::vector<Signal> sigs;
|
2019-11-22 21:46:33 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct DBC {
|
2022-05-12 17:59:33 -07:00
|
|
|
std::string name;
|
|
|
|
std::vector<Msg> msgs;
|
|
|
|
std::vector<Val> vals;
|
2019-11-22 21:46:33 -08:00
|
|
|
};
|
|
|
|
|
2022-10-17 21:25:13 -07:00
|
|
|
typedef struct ChecksumState {
|
|
|
|
int checksum_size;
|
|
|
|
int counter_size;
|
|
|
|
int checksum_start_bit;
|
|
|
|
int counter_start_bit;
|
|
|
|
bool little_endian;
|
|
|
|
SignalType checksum_type;
|
|
|
|
unsigned int (*calc_checksum)(uint32_t address, const Signal &sig, const std::vector<uint8_t> &d);
|
|
|
|
} ChecksumState;
|
|
|
|
|
2022-06-22 14:17:22 -07:00
|
|
|
DBC* dbc_parse(const std::string& dbc_path);
|
2023-03-27 11:48:45 -07:00
|
|
|
DBC* dbc_parse_from_stream(const std::string &dbc_name, std::istream &stream, ChecksumState *checksum = nullptr, bool allow_duplicate_msg_name=false);
|
2019-11-22 21:46:33 -08:00
|
|
|
const DBC* dbc_lookup(const std::string& dbc_name);
|
2022-05-12 17:59:33 -07:00
|
|
|
std::vector<std::string> get_dbc_names();
|