opendbc
opendbc copied to clipboard
CANParser: update_strings returns latest state when passed empty list
CANParser::update_strings returns most recently updated addresses, when called with an empty list.
Is it expected behavior? Shouldn't it return empty list of addresses, since nothing was updated?
Snippet showcasing this behavior:
parser: CANParser = ...
addr = parser.update_strings(cans)
# addr = {...}
addr = parser.update_strings([])
assert len(addr) == 0
# ^ this assertion fails
No it shouldn't return anything. Some confusing interaction with the timing variables in parser.cc is going on. We can choose not to update the vals in query_latest if the last_ts is 0, but unsure if anything relies on that behavior since last_ts not being 0 is an explicit condition of skipping updating the values: https://github.com/commaai/opendbc/blob/7d61776e2b258a028b19d81852a20bc234ec6a37/can/parser.cc#L320-L322
Also, here we set current_sec to the first CAN message, which we should probably set to the latest?
https://github.com/commaai/opendbc/blob/7d61776e2b258a028b19d81852a20bc234ec6a37/can/parser.cc#L212
We can choose not to update the vals in query_latest if the last_ts is 0, but unsure if anything relies on that behavior since last_ts not being 0 is an explicit condition of skipping updating the values:
currently, CANParser::__init__ relies on calling update_strings([]) to initialize vl, vl_all,ts_nanos