Skip to content

Commit

Permalink
use dict
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee committed Nov 2, 2024
1 parent 472c62e commit a00fe45
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions opendbc/can/parser_pyx.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ cdef class CANParser:

self.vl[address] = {name: 0.0 for name in signal_names}
self.vl[name] = self.vl[address]
self.vl_all[address] = defaultdict(list)
self.vl_all[address] = {name: [] for name in signal_names}
self.vl_all[name] = self.vl_all[address]
self.ts_nanos[address] = {name: 0.0 for name in signal_names}
self.ts_nanos[name] = self.ts_nanos[address]
Expand All @@ -71,8 +71,6 @@ cdef class CANParser:
# 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

Expand All @@ -95,7 +93,8 @@ cdef class CANParser:
except TypeError:
raise RuntimeError("invalid parameter")

updated_addrs = self.can.update(can_data_array)
cdef set updated_addrs = self.can.update(can_data_array)

for addr in updated_addrs:
vl = self.vl[addr]
vl_all = self.vl_all[addr]
Expand All @@ -108,6 +107,12 @@ cdef class CANParser:
vl_all[name] = state.all_vals[i]
ts_nanos[name] = state.last_seen_nanos

# Clear vl_all for unupdated addresses
unupdated_addrs = self.addresses - updated_addrs
for addr in unupdated_addrs:
for value in self.vl_all[addr].values():
value.clear()

return updated_addrs

@property
Expand Down

0 comments on commit a00fe45

Please sign in to comment.