commaai / opendbc

democratize access to car decoder rings

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CAN Packer: undefined behavior when not setting a signal

sshane opened this issue · comments

While looking at commaai/openpilot#27785 I noticed that the CAN packer takes on different behavior depending on if you define a signal to 0, or leave it out of the dictionary. if you define it to 0, it will take the correct offset and scaling into account, but if you don't it will just set the bytes to 0x00. This can lead to unintended behavior as you expect them to produce the same behavior

reproduction:

from opendbc.can.packer import CANPacker
packer = CANPacker('hyundai_canfd')
packer.make_can_msg('SCC_CONTROL', 0, {'VSetDis': 0})[2][16]
Out[59]: 0
packer.make_can_msg('SCC_CONTROL', 0, {'VSetDis': 0, 'aReqValue': 0})[2][16]
Out[61]: 255

openpilot issue: commaai/openpilot#28822

@deanlee what do you think is better, in cython adding all signals with default values of 0, or handle in packer.cc?

It might be better to implement it inside packer.cc. #884