2019-11-23 13:46:33 +08:00
|
|
|
# distutils: language = c++
|
2022-02-25 14:58:37 +08:00
|
|
|
# cython: language_level=3
|
2019-11-23 13:46:33 +08:00
|
|
|
|
2022-03-01 01:10:34 +08:00
|
|
|
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t
|
|
|
|
from libcpp cimport bool
|
2023-08-11 09:49:14 +08:00
|
|
|
from libcpp.pair cimport pair
|
2019-11-23 13:46:33 +08:00
|
|
|
from libcpp.string cimport string
|
2022-03-01 01:10:34 +08:00
|
|
|
from libcpp.vector cimport vector
|
2024-06-08 08:59:22 +08:00
|
|
|
from libcpp.unordered_map cimport unordered_map
|
2019-11-23 13:46:33 +08:00
|
|
|
|
|
|
|
|
2022-07-01 02:31:58 +08:00
|
|
|
ctypedef unsigned int (*calc_checksum_type)(uint32_t, const Signal&, const vector[uint8_t] &)
|
|
|
|
|
2019-12-04 00:43:05 +08:00
|
|
|
cdef extern from "common_dbc.h":
|
2019-11-23 13:46:33 +08:00
|
|
|
ctypedef enum SignalType:
|
|
|
|
DEFAULT,
|
2022-07-12 03:36:43 +08:00
|
|
|
COUNTER,
|
2019-11-23 13:46:33 +08:00
|
|
|
HONDA_CHECKSUM,
|
|
|
|
TOYOTA_CHECKSUM,
|
|
|
|
PEDAL_CHECKSUM,
|
2022-07-01 02:31:58 +08:00
|
|
|
VOLKSWAGEN_MQB_CHECKSUM,
|
2022-07-16 01:29:12 +08:00
|
|
|
XOR_CHECKSUM,
|
2020-05-01 05:06:26 +08:00
|
|
|
SUBARU_CHECKSUM,
|
|
|
|
CHRYSLER_CHECKSUM
|
2022-05-16 09:26:19 +08:00
|
|
|
HKG_CAN_FD_CHECKSUM,
|
2019-11-23 13:46:33 +08:00
|
|
|
|
|
|
|
cdef struct Signal:
|
2022-05-13 08:59:33 +08:00
|
|
|
string name
|
2022-03-01 01:10:34 +08:00
|
|
|
int start_bit, msb, lsb, size
|
2019-11-23 13:46:33 +08:00
|
|
|
bool is_signed
|
|
|
|
double factor, offset
|
2022-05-13 08:59:33 +08:00
|
|
|
bool is_little_endian
|
2019-11-23 13:46:33 +08:00
|
|
|
SignalType type
|
2022-07-01 02:31:58 +08:00
|
|
|
calc_checksum_type calc_checksum
|
2019-11-23 13:46:33 +08:00
|
|
|
|
|
|
|
cdef struct Msg:
|
2022-05-13 08:59:33 +08:00
|
|
|
string name
|
2019-11-23 13:46:33 +08:00
|
|
|
uint32_t address
|
|
|
|
unsigned int size
|
2022-05-13 08:59:33 +08:00
|
|
|
vector[Signal] sigs
|
2019-11-23 13:46:33 +08:00
|
|
|
|
|
|
|
cdef struct Val:
|
2022-05-13 08:59:33 +08:00
|
|
|
string name
|
2019-11-23 13:46:33 +08:00
|
|
|
uint32_t address
|
2022-05-13 08:59:33 +08:00
|
|
|
string def_val
|
|
|
|
vector[Signal] sigs
|
2019-11-23 13:46:33 +08:00
|
|
|
|
|
|
|
cdef struct DBC:
|
2022-05-13 08:59:33 +08:00
|
|
|
string name
|
|
|
|
vector[Msg] msgs
|
|
|
|
vector[Val] vals
|
2024-06-08 08:59:22 +08:00
|
|
|
unordered_map[uint32_t, const Msg*] addr_to_msg
|
|
|
|
unordered_map[string, const Msg*] name_to_msg
|
2019-11-23 13:46:33 +08:00
|
|
|
|
|
|
|
cdef struct SignalValue:
|
|
|
|
uint32_t address
|
2023-02-08 15:00:22 +08:00
|
|
|
uint64_t ts_nanos
|
2022-05-13 08:59:33 +08:00
|
|
|
string name
|
2019-11-23 13:46:33 +08:00
|
|
|
double value
|
2022-02-11 05:01:30 +08:00
|
|
|
vector[double] all_values
|
2019-11-23 13:46:33 +08:00
|
|
|
|
2019-12-04 00:43:05 +08:00
|
|
|
cdef struct SignalPackValue:
|
2021-09-03 05:25:47 +08:00
|
|
|
string name
|
2019-12-04 00:43:05 +08:00
|
|
|
double value
|
|
|
|
|
|
|
|
|
|
|
|
cdef extern from "common.h":
|
2023-10-26 04:51:15 +08:00
|
|
|
cdef const DBC* dbc_lookup(const string) except +
|
2019-11-23 13:46:33 +08:00
|
|
|
|
|
|
|
cdef cppclass CANParser:
|
|
|
|
bool can_valid
|
2022-04-13 13:34:27 +08:00
|
|
|
bool bus_timeout
|
2023-08-30 01:09:43 +08:00
|
|
|
CANParser(int, string, vector[pair[uint32_t, int]]) except +
|
2023-08-11 04:03:55 +08:00
|
|
|
void update_strings(vector[string]&, vector[SignalValue]&, bool) except +
|
2019-12-04 00:43:05 +08:00
|
|
|
|
|
|
|
cdef cppclass CANPacker:
|
|
|
|
CANPacker(string)
|
2023-03-29 03:33:37 +08:00
|
|
|
vector[uint8_t] pack(uint32_t, vector[SignalPackValue]&)
|