From 43de72196a963b08713fbd7c6e7bc65b3acc79ba Mon Sep 17 00:00:00 2001 From: deanlee Date: Thu, 7 Nov 2024 12:35:41 +0800 Subject: [PATCH] direct capnp to vector[CanData] conversion --- opendbc/can/parser_pyx.pyx | 19 +++++++++++++++---- opendbc/car/chrysler/radar_interface.py | 2 +- opendbc/car/ford/radar_interface.py | 2 +- opendbc/car/gm/radar_interface.py | 2 +- opendbc/car/honda/radar_interface.py | 2 +- opendbc/car/hyundai/radar_interface.py | 2 +- opendbc/car/interfaces.py | 2 +- opendbc/car/toyota/radar_interface.py | 2 +- 8 files changed, 22 insertions(+), 11 deletions(-) diff --git a/opendbc/can/parser_pyx.pyx b/opendbc/can/parser_pyx.pyx index f35995cd72..b3509155c8 100644 --- a/opendbc/can/parser_pyx.pyx +++ b/opendbc/can/parser_pyx.pyx @@ -4,7 +4,7 @@ from libcpp.pair cimport pair from libcpp.string cimport string from libcpp.vector cimport vector -from libc.stdint cimport uint32_t +from libc.stdint cimport uint32_t, uintptr_t from .common cimport CANParser as cpp_CANParser from .common cimport dbc_lookup, Msg, DBC, CanData @@ -67,13 +67,18 @@ cdef class CANParser: if self.can: del self.can + def update(self, data, sendcan=False): + if not hasattr(data, 'get_data_pointer'): + return self.update_strings(self, data, sendcan) + + cdef uintptr_t pointer = data.get_data_pointer() + can_data = pointer + return self._update(can_data[0], sendcan) + def update_strings(self, strings, sendcan=False): # input format: # [nanos, [[address, data, src], ...]] # [[nanos, [[address, data, src], ...], ...]] - for address in self.addresses: - self.vl_all[address].clear() - cdef vector[CanData] can_data_array try: @@ -95,6 +100,12 @@ cdef class CANParser: except TypeError: raise RuntimeError("invalid parameter") + return self._update(can_data_array, sendcan) + + cdef _update(self, vector[CanData] &can_data_array, sendcan): + for address in self.addresses: + self.vl_all[address].clear() + updated_addrs = self.can.update(can_data_array) for addr in updated_addrs: vl = self.vl[addr] diff --git a/opendbc/car/chrysler/radar_interface.py b/opendbc/car/chrysler/radar_interface.py index 3528373f8d..7618b8e328 100755 --- a/opendbc/car/chrysler/radar_interface.py +++ b/opendbc/car/chrysler/radar_interface.py @@ -47,7 +47,7 @@ def update(self, can_strings): if self.rcp is None or self.CP.radarUnavailable: return super().update(None) - vls = self.rcp.update_strings(can_strings) + vls = self.rcp.update(can_strings) self.updated_messages.update(vls) if self.trigger_msg not in self.updated_messages: diff --git a/opendbc/car/ford/radar_interface.py b/opendbc/car/ford/radar_interface.py index b5e98867c9..66814cad55 100644 --- a/opendbc/car/ford/radar_interface.py +++ b/opendbc/car/ford/radar_interface.py @@ -115,7 +115,7 @@ def update(self, can_strings): if self.rcp is None: return super().update(None) - vls = self.rcp.update_strings(can_strings) + vls = self.rcp.update(can_strings) self.updated_messages.update(vls) if self.trigger_msg not in self.updated_messages: diff --git a/opendbc/car/gm/radar_interface.py b/opendbc/car/gm/radar_interface.py index e79d26533b..6cfd78e650 100755 --- a/opendbc/car/gm/radar_interface.py +++ b/opendbc/car/gm/radar_interface.py @@ -45,7 +45,7 @@ def update(self, can_strings): if self.rcp is None: return super().update(None) - vls = self.rcp.update_strings(can_strings) + vls = self.rcp.update(can_strings) self.updated_messages.update(vls) if self.trigger_msg not in self.updated_messages: diff --git a/opendbc/car/honda/radar_interface.py b/opendbc/car/honda/radar_interface.py index 97c6664d0e..5330790f77 100755 --- a/opendbc/car/honda/radar_interface.py +++ b/opendbc/car/honda/radar_interface.py @@ -33,7 +33,7 @@ def update(self, can_strings): if self.radar_off_can: return super().update(None) - vls = self.rcp.update_strings(can_strings) + vls = self.rcp.update(can_strings) self.updated_messages.update(vls) if self.trigger_msg not in self.updated_messages: diff --git a/opendbc/car/hyundai/radar_interface.py b/opendbc/car/hyundai/radar_interface.py index a9078749d6..2929ef2d07 100644 --- a/opendbc/car/hyundai/radar_interface.py +++ b/opendbc/car/hyundai/radar_interface.py @@ -32,7 +32,7 @@ def update(self, can_strings): if self.radar_off_can or (self.rcp is None): return super().update(None) - vls = self.rcp.update_strings(can_strings) + vls = self.rcp.update(can_strings) self.updated_messages.update(vls) if self.trigger_msg not in self.updated_messages: diff --git a/opendbc/car/interfaces.py b/opendbc/car/interfaces.py index f5644a5cff..764995e8f9 100644 --- a/opendbc/car/interfaces.py +++ b/opendbc/car/interfaces.py @@ -227,7 +227,7 @@ def update(self, can_packets: list[tuple[int, list[CanData]]]) -> structs.CarSta # parse can for cp in self.can_parsers: if cp is not None: - cp.update_strings(can_packets) + cp.update(can_packets) # get CarState ret = self._update() diff --git a/opendbc/car/toyota/radar_interface.py b/opendbc/car/toyota/radar_interface.py index bfb2df0494..9417cea4e4 100755 --- a/opendbc/car/toyota/radar_interface.py +++ b/opendbc/car/toyota/radar_interface.py @@ -41,7 +41,7 @@ def update(self, can_strings): if self.rcp is None: return super().update(None) - vls = self.rcp.update_strings(can_strings) + vls = self.rcp.update(can_strings) self.updated_messages.update(vls) if self.trigger_msg not in self.updated_messages: