common.pxd 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # distutils: language = c++
  2. # cython: language_level=3
  3. from libc.stdint cimport uint8_t, uint32_t, uint64_t
  4. from libcpp cimport bool
  5. from libcpp.pair cimport pair
  6. from libcpp.string cimport string
  7. from libcpp.vector cimport vector
  8. from libcpp.unordered_map cimport unordered_map
  9. ctypedef unsigned int (*calc_checksum_type)(uint32_t, const Signal&, const vector[uint8_t] &)
  10. cdef extern from "common_dbc.h":
  11. ctypedef enum SignalType:
  12. DEFAULT,
  13. COUNTER,
  14. HONDA_CHECKSUM,
  15. TOYOTA_CHECKSUM,
  16. PEDAL_CHECKSUM,
  17. VOLKSWAGEN_MQB_CHECKSUM,
  18. XOR_CHECKSUM,
  19. SUBARU_CHECKSUM,
  20. CHRYSLER_CHECKSUM
  21. HKG_CAN_FD_CHECKSUM,
  22. cdef struct Signal:
  23. string name
  24. int start_bit, msb, lsb, size
  25. bool is_signed
  26. double factor, offset
  27. bool is_little_endian
  28. SignalType type
  29. calc_checksum_type calc_checksum
  30. cdef struct Msg:
  31. string name
  32. uint32_t address
  33. unsigned int size
  34. vector[Signal] sigs
  35. cdef struct Val:
  36. string name
  37. uint32_t address
  38. string def_val
  39. vector[Signal] sigs
  40. cdef struct DBC:
  41. string name
  42. vector[Msg] msgs
  43. vector[Val] vals
  44. unordered_map[uint32_t, const Msg*] addr_to_msg
  45. unordered_map[string, const Msg*] name_to_msg
  46. cdef struct SignalValue:
  47. uint32_t address
  48. uint64_t ts_nanos
  49. string name
  50. double value
  51. vector[double] all_values
  52. cdef struct SignalPackValue:
  53. string name
  54. double value
  55. cdef extern from "candbc.h":
  56. cdef const DBC* dbc_lookup(const string) except +
  57. cdef struct CanFrame:
  58. long src
  59. uint32_t address
  60. vector[uint8_t] dat
  61. cdef struct CanData:
  62. uint64_t nanos
  63. vector[CanFrame] frames
  64. cdef cppclass CANParser:
  65. bool can_valid
  66. bool bus_timeout
  67. CANParser(int, string, vector[pair[uint32_t, int]]) except +
  68. void update(vector[CanData]&, vector[SignalValue]&) except +
  69. cdef cppclass CANPacker:
  70. CANPacker(string)
  71. vector[uint8_t] pack(uint32_t, vector[SignalPackValue]&)