Skip to content

Commit

Permalink
CANPacker: msg type is tuple (commaai#1077)
Browse files Browse the repository at this point in the history
not mutable list
  • Loading branch information
sshane authored Aug 7, 2024
1 parent 1e9f853 commit f4d077b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion opendbc/can/packer_pyx.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ cdef class CANPacker:
pass

cdef vector[uint8_t] val = self.pack(addr, values)
return [addr, (<char *>&val[0])[:val.size()], bus]
return addr, (<char *>&val[0])[:val.size()], bus
11 changes: 6 additions & 5 deletions opendbc/can/tests/test_packer_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ def rx_steering_msg(values, bad_checksum=False):
msg = packer.make_can_msg("STEERING_CONTROL", 0, values)
if bad_checksum:
# add 1 to checksum
msg[1] = bytearray(msg[1])
msg[1][4] = (msg[1][4] & 0xF0) | ((msg[1][4] & 0x0F) + 1)
dat = bytearray(msg[1])
dat[4] = (dat[4] & 0xF0) | ((dat[4] & 0x0F) + 1)
msg = (msg[0], bytes(dat), msg[2])

parser.update_strings([0, [msg]])

Expand Down Expand Up @@ -350,6 +351,6 @@ def test_allow_undefined_msgs(self):
# discovery tests in openpilot first
packer = CANPacker("toyota_nodsu_pt_generated")

assert packer.make_can_msg("ACC_CONTROL", 0, {"UNKNOWN_SIGNAL": 0}) == [835, b'\x00\x00\x00\x00\x00\x00\x00N', 0]
assert packer.make_can_msg("UNKNOWN_MESSAGE", 0, {"UNKNOWN_SIGNAL": 0}) == [0, b'', 0]
assert packer.make_can_msg(0, 0, {"UNKNOWN_SIGNAL": 0}) == [0, b'', 0]
assert packer.make_can_msg("ACC_CONTROL", 0, {"UNKNOWN_SIGNAL": 0}) == (835, b'\x00\x00\x00\x00\x00\x00\x00N', 0)
assert packer.make_can_msg("UNKNOWN_MESSAGE", 0, {"UNKNOWN_SIGNAL": 0}) == (0, b'', 0)
assert packer.make_can_msg(0, 0, {"UNKNOWN_SIGNAL": 0}) == (0, b'', 0)

0 comments on commit f4d077b

Please sign in to comment.