From a00fe4590c75b273a7bf770ce10071c44ad43460 Mon Sep 17 00:00:00 2001 From: deanlee Date: Sat, 2 Nov 2024 20:01:58 +0800 Subject: [PATCH] use dict --- opendbc/can/parser_pyx.pyx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/opendbc/can/parser_pyx.pyx b/opendbc/can/parser_pyx.pyx index f35995cd72..2bf52b3517 100644 --- a/opendbc/can/parser_pyx.pyx +++ b/opendbc/can/parser_pyx.pyx @@ -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] @@ -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 @@ -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] @@ -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