Skip to content

Commit

Permalink
direct capnp to vector[CanData] conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee committed Nov 7, 2024
1 parent 2d08ede commit fe60520
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions opendbc/can/parser_pyx.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -67,13 +67,15 @@ cdef class CANParser:
if self.can:
del self.can

def update(self, parsed_data, sendcan=False):
cdef uintptr_t pointer = parsed_data.get_data_pointer()
can_data = <vector[CanData]*> 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:
Expand All @@ -95,6 +97,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]
Expand Down

0 comments on commit fe60520

Please sign in to comment.