diff --git a/selfdrive/can/common.h b/selfdrive/can/common.h index 2ec2507585..a496c3918b 100644 --- a/selfdrive/can/common.h +++ b/selfdrive/can/common.h @@ -1,17 +1,13 @@ -#ifndef SELFDRIVE_CAN_COMMON_H -#define SELFDRIVE_CAN_COMMON_H +#pragma once -#include -#include -#include -#include #include +#include +#include "common_dbc.h" #include #include "cereal/gen/cpp/log.capnp.h" #define MAX_BAD_COUNTER 5 -#define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0])) // Helper functions unsigned int honda_checksum(unsigned int address, uint64_t d, int l); @@ -22,74 +18,6 @@ unsigned int pedal_checksum(uint64_t d, int l); uint64_t read_u64_be(const uint8_t* v); uint64_t read_u64_le(const uint8_t* v); -struct SignalPackValue { - const char* name; - double value; -}; - -struct SignalParseOptions { - uint32_t address; - const char* name; - double default_value; -}; - -struct MessageParseOptions { - uint32_t address; - int check_frequency; -}; - -struct SignalValue { - uint32_t address; - uint16_t ts; - const char* name; - double value; -}; - - -enum SignalType { - DEFAULT, - HONDA_CHECKSUM, - HONDA_COUNTER, - TOYOTA_CHECKSUM, - PEDAL_CHECKSUM, - PEDAL_COUNTER, - VOLKSWAGEN_CHECKSUM, - VOLKSWAGEN_COUNTER, -}; - -struct Signal { - const char* name; - int b1, b2, bo; - bool is_signed; - double factor, offset; - bool is_little_endian; - SignalType type; -}; - -struct Msg { - const char* name; - uint32_t address; - unsigned int size; - size_t num_sigs; - const Signal *sigs; -}; - -struct Val { - const char* name; - uint32_t address; - const char* def_val; - const Signal *sigs; -}; - -struct DBC { - const char* name; - size_t num_msgs; - const Msg *msgs; - const Val *vals; - size_t num_vals; -}; - - class MessageState { public: uint32_t address; @@ -129,17 +57,3 @@ public: std::vector query_latest(); }; - - - - -const DBC* dbc_lookup(const std::string& dbc_name); - -void dbc_register(const DBC* dbc); - -#define dbc_init(dbc) \ -static void __attribute__((constructor)) do_dbc_init_ ## dbc(void) { \ - dbc_register(&dbc); \ -} - -#endif diff --git a/selfdrive/can/common_dbc.h b/selfdrive/can/common_dbc.h new file mode 100644 index 0000000000..ae6f443ec9 --- /dev/null +++ b/selfdrive/can/common_dbc.h @@ -0,0 +1,82 @@ +#pragma once + +#include +#include +#include + +#define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0])) + +struct SignalPackValue { + const char* name; + double value; +}; + +struct SignalParseOptions { + uint32_t address; + const char* name; + double default_value; +}; + +struct MessageParseOptions { + uint32_t address; + int check_frequency; +}; + +struct SignalValue { + uint32_t address; + uint16_t ts; + const char* name; + double value; +}; + +enum SignalType { + DEFAULT, + HONDA_CHECKSUM, + HONDA_COUNTER, + TOYOTA_CHECKSUM, + PEDAL_CHECKSUM, + PEDAL_COUNTER, + VOLKSWAGEN_CHECKSUM, + VOLKSWAGEN_COUNTER, +}; + +struct Signal { + const char* name; + int b1, b2, bo; + bool is_signed; + double factor, offset; + bool is_little_endian; + SignalType type; +}; + +struct Msg { + const char* name; + uint32_t address; + unsigned int size; + size_t num_sigs; + const Signal *sigs; +}; + +struct Val { + const char* name; + uint32_t address; + const char* def_val; + const Signal *sigs; +}; + +struct DBC { + const char* name; + size_t num_msgs; + const Msg *msgs; + const Val *vals; + size_t num_vals; +}; + +const DBC* dbc_lookup(const std::string& dbc_name); + +void dbc_register(const DBC* dbc); + +#define dbc_init(dbc) \ +static void __attribute__((constructor)) do_dbc_init_ ## dbc(void) { \ + dbc_register(&dbc); \ +} diff --git a/selfdrive/can/dbc.cc b/selfdrive/can/dbc.cc index 95d5e4d791..6587de7fe0 100644 --- a/selfdrive/can/dbc.cc +++ b/selfdrive/can/dbc.cc @@ -1,7 +1,6 @@ -#include #include -#include "common.h" +#include "common_dbc.h" namespace { diff --git a/selfdrive/can/dbc_template.cc b/selfdrive/can/dbc_template.cc index 52351aef2f..d916eeada0 100644 --- a/selfdrive/can/dbc_template.cc +++ b/selfdrive/can/dbc_template.cc @@ -1,6 +1,4 @@ -#include - -#include "common.h" +#include "common_dbc.h" namespace { diff --git a/selfdrive/can/packer.cc b/selfdrive/can/packer.cc index f6da562a7a..c658e56731 100644 --- a/selfdrive/can/packer.cc +++ b/selfdrive/can/packer.cc @@ -1,6 +1,4 @@ #include -#include -#include #include #include #include diff --git a/selfdrive/can/parser.cc b/selfdrive/can/parser.cc index 2df843e213..4d2dc32e2a 100644 --- a/selfdrive/can/parser.cc +++ b/selfdrive/can/parser.cc @@ -1,5 +1,3 @@ -#include -#include #include #include @@ -7,13 +5,8 @@ #include #include #include - -#include #include -#include -#include "cereal/gen/cpp/log.capnp.h" - #include "common.h" #define DEBUG(...)