deprecate busTime (#1989)

* deprecate busTime

* fix test_comms.py

* update opendbc

* way more than i thought

* and here

* oops
This commit is contained in:
Shane Smiskol 2024-07-30 21:20:48 -07:00 committed by GitHub
parent f6375848ca
commit 8c3bb0151e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
30 changed files with 77 additions and 77 deletions

View File

@ -48,7 +48,7 @@ RUN /tmp/install.sh && rm -rf $CPPCHECK_DIR/.git/
ENV SKIP_CPPCHECK_INSTALL=1 ENV SKIP_CPPCHECK_INSTALL=1
ENV CEREAL_REF="861144c136c91f70dcbc652c2ffe99f57440ad47" ENV CEREAL_REF="861144c136c91f70dcbc652c2ffe99f57440ad47"
ENV OPENDBC_REF="e0d4be4a6215d44809718dc84efe1b9f0299ad63" ENV OPENDBC_REF="8e9d3688412405154a8189c421cfdc9d5feea715"
RUN git config --global --add safe.directory /tmp/openpilot/panda RUN git config --global --add safe.directory /tmp/openpilot/panda
RUN mkdir -p /tmp/openpilot/ && \ RUN mkdir -p /tmp/openpilot/ && \

View File

@ -19,7 +19,7 @@ def can_printer():
canbus = int(os.getenv("CAN", "0")) canbus = int(os.getenv("CAN", "0"))
while True: while True:
can_recv = p.can_recv() can_recv = p.can_recv()
for address, _, dat, src in can_recv: for address, dat, src in can_recv:
if src == canbus: if src == canbus:
msgs[address].append(dat) msgs[address].append(dat)

View File

@ -37,7 +37,7 @@ def test_loopback():
incoming = jungle.can_recv() incoming = jungle.can_recv()
found = False found = False
for message in incoming: for message in incoming:
incomingAddress, _, incomingData, incomingBus = message incomingAddress, incomingData, incomingBus = message
if incomingAddress == address and incomingData == data[::-1] and incomingBus == bus: if incomingAddress == address and incomingData == data[::-1] and incomingBus == bus:
found = True found = True
break break

View File

@ -74,11 +74,11 @@ def can_loopback(sender):
raise Exception("Amount of received CAN messages (" + str(len(content)) + ") does not equal 1. Bus: " + str(bus) +" OBD: " + str(obd)) raise Exception("Amount of received CAN messages (" + str(len(content)) + ") does not equal 1. Bus: " + str(bus) +" OBD: " + str(obd))
# Check content # Check content
if content[0][0] != addr or content[0][2] != string: if content[0][0] != addr or content[0][1] != string:
raise Exception("Received CAN message content or address does not match") raise Exception("Received CAN message content or address does not match")
# Check bus # Check bus
if content[0][3] != bus: if content[0][2] != bus:
raise Exception("Received CAN message bus does not match") raise Exception("Received CAN message bus does not match")
################################################################# #################################################################

View File

@ -22,7 +22,7 @@ def can_logger():
while True: while True:
can_recv = p.can_recv() can_recv = p.can_recv()
for address, _, dat, src in can_recv: for address, dat, src in can_recv:
csvwriter.writerow( csvwriter.writerow(
[str(src), str(hex(address)), f"0x{dat.hex()}", len(dat), str(time.time() - start_time)]) [str(src), str(hex(address)), f"0x{dat.hex()}", len(dat), str(time.time() - start_time)])

View File

@ -34,7 +34,7 @@ def tesla_tester():
while True: while True:
#Read the VIN #Read the VIN
can_recv = p.can_recv() can_recv = p.can_recv()
for address, _, dat, src in can_recv: for address, dat, src in can_recv:
if src == body_bus_num: if src == body_bus_num:
if address == 1384: # 0x568 is VIN if address == 1384: # 0x568 is VIN
vin_index = int(binascii.hexlify(dat)[:2]) # first byte is the index, 00, 01, 02 vin_index = int(binascii.hexlify(dat)[:2]) # first byte is the index, 00, 01, 02

View File

@ -37,7 +37,7 @@ def calculate_checksum(data):
def pack_can_buffer(arr): def pack_can_buffer(arr):
snds = [b''] snds = [b'']
for address, _, dat, bus in arr: for address, dat, bus in arr:
assert len(dat) in LEN_TO_DLC assert len(dat) in LEN_TO_DLC
#logging.debug(" W 0x%x: 0x%s", address, dat.hex()) #logging.debug(" W 0x%x: 0x%s", address, dat.hex())
@ -85,7 +85,7 @@ def unpack_can_buffer(dat):
data = dat[CANPACKET_HEAD_SIZE:(CANPACKET_HEAD_SIZE+data_len)] data = dat[CANPACKET_HEAD_SIZE:(CANPACKET_HEAD_SIZE+data_len)]
dat = dat[(CANPACKET_HEAD_SIZE+data_len):] dat = dat[(CANPACKET_HEAD_SIZE+data_len):]
ret.append((address, 0, data, bus)) ret.append((address, data, bus))
return (ret, dat) return (ret, dat)
@ -812,7 +812,7 @@ class Panda:
logging.error("CAN: BAD SEND MANY, RETRYING") logging.error("CAN: BAD SEND MANY, RETRYING")
def can_send(self, addr, dat, bus, timeout=CAN_SEND_TIMEOUT_MS): def can_send(self, addr, dat, bus, timeout=CAN_SEND_TIMEOUT_MS):
self.can_send_many([[addr, None, dat, bus]], timeout=timeout) self.can_send_many([[addr, dat, bus]], timeout=timeout)
@ensure_can_packet_version @ensure_can_packet_version
def can_recv(self): def can_recv(self):

View File

@ -99,7 +99,7 @@ class CcpClient():
msgs = self._panda.can_recv() or [] msgs = self._panda.can_recv() or []
if len(msgs) >= 256: if len(msgs) >= 256:
print("CAN RX buffer overflow!!!", file=sys.stderr) print("CAN RX buffer overflow!!!", file=sys.stderr)
for rx_addr, _, rx_data_bytearray, rx_bus in msgs: for rx_addr, rx_data_bytearray, rx_bus in msgs:
if rx_bus == self.can_bus and rx_addr == self.rx_addr: if rx_bus == self.can_bus and rx_addr == self.rx_addr:
rx_data = bytes(rx_data_bytearray) rx_data = bytes(rx_data_bytearray)
if self.debug: if self.debug:

View File

@ -18,12 +18,12 @@ def recv(panda, cnt, addr, nbus):
while len(ret) < cnt: while len(ret) < cnt:
kmsgs += panda.can_recv() kmsgs += panda.can_recv()
nmsgs = [] nmsgs = []
for ids, ts, dat, bus in kmsgs: for ids, dat, bus in kmsgs:
if ids == addr and bus == nbus and len(ret) < cnt: if ids == addr and bus == nbus and len(ret) < cnt:
ret.append(dat) ret.append(dat)
else: else:
# leave around # leave around
nmsgs.append((ids, ts, dat, bus)) nmsgs.append((ids, dat, bus))
kmsgs = nmsgs[-256:] kmsgs = nmsgs[-256:]
return ret return ret
@ -96,7 +96,7 @@ def isotp_send(panda, x, addr, bus=0, recvaddr=None, subaddr=None, rate=None):
panda.can_send(addr, sends[-1], 0) panda.can_send(addr, sends[-1], 0)
else: else:
if rate is None: if rate is None:
panda.can_send_many([(addr, None, s, bus) for s in sends]) panda.can_send_many([(addr, s, bus) for s in sends])
else: else:
for dat in sends: for dat in sends:
panda.can_send(addr, dat, bus) panda.can_send(addr, dat, bus)

View File

@ -145,7 +145,7 @@ class XcpClient():
msgs = self._panda.can_recv() or [] msgs = self._panda.can_recv() or []
if len(msgs) >= 256: if len(msgs) >= 256:
print("CAN RX buffer overflow!!!", file=sys.stderr) print("CAN RX buffer overflow!!!", file=sys.stderr)
for rx_addr, _, rx_data, rx_bus in msgs: for rx_addr, rx_data, rx_bus in msgs:
if rx_bus == self.can_bus and rx_addr == self.rx_addr: if rx_bus == self.can_bus and rx_addr == self.rx_addr:
rx_data = bytes(rx_data) # convert bytearray to bytes rx_data = bytes(rx_data) # convert bytearray to bytes
if self.debug: if self.debug:

View File

@ -118,11 +118,11 @@ def test_buses(black_panda, other_panda, direction, test_array, sleep_duration):
loop_buses = [] loop_buses = []
for loop in cans_loop: for loop in cans_loop:
if (loop[0] != at) or (loop[2] != st): if (loop[0] != at) or (loop[1] != st):
content_errors += 1 content_errors += 1
print(" Loop on bus", str(loop[3])) print(" Loop on bus", str(loop[2]))
loop_buses.append(loop[3]) loop_buses.append(loop[2])
if len(cans_loop) == 0: if len(cans_loop) == 0:
print(" No loop") print(" No loop")
assert not os.getenv("NOASSERT") assert not os.getenv("NOASSERT")

View File

@ -126,11 +126,11 @@ def test_buses(black_panda, other_panda, direction, test_array, sleep_duration):
loop_buses = [] loop_buses = []
for loop in cans_loop: for loop in cans_loop:
if (loop[0] != at) or (loop[2] != st): if (loop[0] != at) or (loop[1] != st):
content_errors += 1 content_errors += 1
print(" Loop on bus", str(loop[3])) print(" Loop on bus", str(loop[2]))
loop_buses.append(loop[3]) loop_buses.append(loop[2])
if len(cans_loop) == 0: if len(cans_loop) == 0:
print(" No loop") print(" No loop")
assert os.getenv("NOASSERT") assert os.getenv("NOASSERT")

View File

@ -109,9 +109,9 @@ def test_buses(black_panda, other_panda, test_obj):
loop_buses = [] loop_buses = []
for loop in cans_loop: for loop in cans_loop:
if (loop[0] != at) or (loop[2] != st): if (loop[0] != at) or (loop[1] != st):
content_errors += 1 content_errors += 1
loop_buses.append(loop[3]) loop_buses.append(loop[2])
# test loop buses # test loop buses
recv_buses.sort() recv_buses.sort()

View File

@ -16,7 +16,7 @@ NUM_MESSAGES_PER_BUS = 10000
def flood_tx(panda): def flood_tx(panda):
print('Sending!') print('Sending!')
msg = b"\xaa" * 4 msg = b"\xaa" * 4
packet = [[0xaa, None, msg, 0], [0xaa, None, msg, 1], [0xaa, None, msg, 2]] * NUM_MESSAGES_PER_BUS packet = [[0xaa, msg, 0], [0xaa, msg, 1], [0xaa, msg, 2]] * NUM_MESSAGES_PER_BUS
panda.can_send_many(packet, timeout=10000) panda.can_send_many(packet, timeout=10000)
print(f"Done sending {3*NUM_MESSAGES_PER_BUS} messages!") print(f"Done sending {3*NUM_MESSAGES_PER_BUS} messages!")

View File

@ -20,7 +20,7 @@ def can_printer():
canbus = int(os.getenv("CAN", "0")) canbus = int(os.getenv("CAN", "0"))
while True: while True:
can_recv = p.can_recv() can_recv = p.can_recv()
for address, _, dat, src in can_recv: for address, dat, src in can_recv:
if src == canbus: if src == canbus:
msgs[address].append(dat) msgs[address].append(dat)

View File

@ -86,7 +86,7 @@ def canfd_test(p_send, p_recv):
data = bytearray(random.getrandbits(8) for _ in range(DLC_TO_LEN[dlc])) data = bytearray(random.getrandbits(8) for _ in range(DLC_TO_LEN[dlc]))
if len(data) >= 2: if len(data) >= 2:
data[0] = calculate_checksum(data[1:] + bytes(str(address), encoding="utf-8")) data[0] = calculate_checksum(data[1:] + bytes(str(address), encoding="utf-8"))
to_send.append([address, 0, data, bus]) to_send.append([address, data, bus])
sent_msgs[bus].add((address, bytes(data))) sent_msgs[bus].add((address, bytes(data)))
p_send.can_send_many(to_send, timeout=0) p_send.can_send_many(to_send, timeout=0)
@ -95,7 +95,7 @@ def canfd_test(p_send, p_recv):
while (time.monotonic() - start_time < 1) and any(len(x) > 0 for x in sent_msgs.values()): while (time.monotonic() - start_time < 1) and any(len(x) > 0 for x in sent_msgs.values()):
incoming = p_recv.can_recv() incoming = p_recv.can_recv()
for msg in incoming: for msg in incoming:
address, _, data, bus = msg address, data, bus = msg
if len(data) >= 2: if len(data) >= 2:
assert calculate_checksum(data[1:] + bytes(str(address), encoding="utf-8")) == data[0] assert calculate_checksum(data[1:] + bytes(str(address), encoding="utf-8")) == data[0]
k = (address, bytes(data)) k = (address, bytes(data))

View File

@ -11,6 +11,6 @@ if __name__ == "__main__":
while True: while True:
incoming = p.can_recv() incoming = p.can_recv()
for message in incoming: for message in incoming:
address, notused, data, bus = message address, data, bus = message
if b'test' in data: if b'test' in data:
p.can_send(address, data[::-1], bus) p.can_send(address, data[::-1], bus)

View File

@ -77,11 +77,11 @@ class ELMCarSimulator():
self.panda.can_recv() # Toss whatever was already there self.panda.can_recv() # Toss whatever was already there
while not self.__stop: while not self.__stop:
for address, ts, data, src in self.panda.can_recv(): for address, data, src in self.panda.can_recv():
if self.__on and src == 0 and len(data) == 8 and data[0] >= 2: if self.__on and src == 0 and len(data) == 8 and data[0] >= 2:
if not self.__silent: if not self.__silent:
print("Processing CAN message", src, hex(address), binascii.hexlify(data)) print("Processing CAN message", src, hex(address), binascii.hexlify(data))
self.__can_process_msg(data[1], data[2], address, ts, data, src) self.__can_process_msg(data[1], data[2], address, data, src)
elif not self.__silent: elif not self.__silent:
print("Rejecting CAN message", src, hex(address), binascii.hexlify(data)) print("Rejecting CAN message", src, hex(address), binascii.hexlify(data))
@ -120,7 +120,7 @@ class ELMCarSimulator():
return True return True
return False return False
def __can_process_msg(self, mode, pid, address, ts, data, src): def __can_process_msg(self, mode, pid, address, data, src):
if not self.__silent: if not self.__silent:
print("CAN MSG", binascii.hexlify(data[1:1 + data[0]]), print("CAN MSG", binascii.hexlify(data[1:1 + data[0]]),
"Addr:", hex(address), "Mode:", hex(mode)[2:].zfill(2), "Addr:", hex(address), "Mode:", hex(mode)[2:].zfill(2),

View File

@ -18,14 +18,14 @@ def test_can_loopback(p):
# confirm receive both on loopback and send receipt # confirm receive both on loopback and send receipt
time.sleep(0.05) time.sleep(0.05)
r = p.can_recv() r = p.can_recv()
sr = [x for x in r if x[3] == 0x80 | bus] sr = [x for x in r if x[2] == 0x80 | bus]
lb = [x for x in r if x[3] == bus] lb = [x for x in r if x[2] == bus]
assert len(sr) == 1 assert len(sr) == 1
assert len(lb) == 1 assert len(lb) == 1
# confirm data is correct # confirm data is correct
assert 0x1aa == sr[0][0] == lb[0][0] assert 0x1aa == sr[0][0] == lb[0][0]
assert b"message" == sr[0][2] == lb[0][2] assert b"message" == sr[0][1] == lb[0][1]
def test_reliability(p): def test_reliability(p):
MSG_COUNT = 100 MSG_COUNT = 100
@ -35,7 +35,7 @@ def test_reliability(p):
p.set_can_speed_kbps(0, 1000) p.set_can_speed_kbps(0, 1000)
addrs = list(range(100, 100 + MSG_COUNT)) addrs = list(range(100, 100 + MSG_COUNT))
ts = [(j, 0, b"\xaa" * 8, 0) for j in addrs] ts = [(j, b"\xaa" * 8, 0) for j in addrs]
for _ in range(100): for _ in range(100):
st = time.monotonic() st = time.monotonic()
@ -46,8 +46,8 @@ def test_reliability(p):
while len(r) < 200 and (time.monotonic() - st) < 0.5: while len(r) < 200 and (time.monotonic() - st) < 0.5:
r.extend(p.can_recv()) r.extend(p.can_recv())
sent_echo = [x for x in r if x[3] == 0x80] sent_echo = [x for x in r if x[2] == 0x80]
loopback_resp = [x for x in r if x[3] == 0] loopback_resp = [x for x in r if x[2] == 0]
assert sorted([x[0] for x in loopback_resp]) == addrs assert sorted([x[0] for x in loopback_resp]) == addrs
assert sorted([x[0] for x in sent_echo]) == addrs assert sorted([x[0] for x in sent_echo]) == addrs

View File

@ -118,10 +118,10 @@ def test_gen2_loopback(p, panda_jungle):
assert len(content) == 1 assert len(content) == 1
# Check content # Check content
assert content[0][0] == addr and content[0][2] == string assert content[0][0] == addr and content[0][1] == string
# Check bus # Check bus
assert content[0][3] == bus assert content[0][2] == bus
print("Bus:", bus, "address:", addr, "OBD:", obd, "OK") print("Bus:", bus, "address:", addr, "OBD:", obd, "OK")
@ -148,9 +148,9 @@ def test_bulk_write(p, panda_jungle):
msg = b"\xaa" * 8 msg = b"\xaa" * 8
packet = [] packet = []
# start with many messages on a single bus (higher contention for single TX ring buffer) # start with many messages on a single bus (higher contention for single TX ring buffer)
packet += [[0xaa, None, msg, 0]] * NUM_MESSAGES_PER_BUS packet += [[0xaa, msg, 0]] * NUM_MESSAGES_PER_BUS
# end with many messages on multiple buses # end with many messages on multiple buses
packet += [[0xaa, None, msg, 0], [0xaa, None, msg, 1], [0xaa, None, msg, 2]] * NUM_MESSAGES_PER_BUS packet += [[0xaa, msg, 0], [0xaa, msg, 1], [0xaa, msg, 2]] * NUM_MESSAGES_PER_BUS
# Disable timeout # Disable timeout
panda.set_safety_mode(Panda.SAFETY_ALLOUTPUT) panda.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
@ -182,18 +182,18 @@ def test_message_integrity(p):
for _ in range(random.randrange(10)): for _ in range(random.randrange(10)):
to_send = get_random_can_messages(random.randrange(100)) to_send = get_random_can_messages(random.randrange(100))
for m in to_send: for m in to_send:
sent_msgs[m[3]].add((m[0], m[2])) sent_msgs[m[2]].add((m[0], m[1]))
p.can_send_many(to_send, timeout=0) p.can_send_many(to_send, timeout=0)
start_time = time.monotonic() start_time = time.monotonic()
while time.monotonic() - start_time < 2 and any(len(sent_msgs[bus]) for bus in range(3)): while time.monotonic() - start_time < 2 and any(len(sent_msgs[bus]) for bus in range(3)):
recvd = p.can_recv() recvd = p.can_recv()
for msg in recvd: for msg in recvd:
if msg[3] >= 128: if msg[2] >= 128:
k = (msg[0], bytes(msg[2])) k = (msg[0], bytes(msg[1]))
bus = msg[3]-128 bus = msg[2]-128
assert k in sent_msgs[bus], f"message {k} was never sent on bus {bus}" assert k in sent_msgs[bus], f"message {k} was never sent on bus {bus}"
sent_msgs[msg[3]-128].discard(k) sent_msgs[msg[2]-128].discard(k)
# if a set isn't empty, messages got dropped # if a set isn't empty, messages got dropped
for bus in range(3): for bus in range(3):

View File

@ -14,8 +14,8 @@ def test_safety_nooutput(p):
time.sleep(0.05) time.sleep(0.05)
r = p.can_recv() r = p.can_recv()
# bus 192 is messages blocked by TX safety hook on bus 0 # bus 192 is messages blocked by TX safety hook on bus 0
assert len([x for x in r if x[3] != 192]) == 0 assert len([x for x in r if x[2] != 192]) == 0
assert len([x for x in r if x[3] == 192]) == 1 assert len([x for x in r if x[2] == 192]) == 1
def test_canfd_safety_modes(p): def test_canfd_safety_modes(p):

View File

@ -51,7 +51,7 @@ def test_harness_status(p, panda_jungle):
time.sleep(0.5) time.sleep(0.5)
msgs = p.can_recv() msgs = p.can_recv()
buses = {int(dat): bus for _, _, dat, bus in msgs if bus <= 3} buses = {int(dat): bus for _, dat, bus in msgs if bus <= 3}
print(msgs) print(msgs)
# jungle doesn't actually switch buses when switching orientation # jungle doesn't actually switch buses when switching orientation

View File

@ -8,7 +8,7 @@ def get_random_can_messages(n):
bus = random.randrange(3) bus = random.randrange(3)
addr = random.randrange(1 << 29) addr = random.randrange(1 << 29)
dat = bytes([random.getrandbits(8) for _ in range(random.randrange(1, 9))]) dat = bytes([random.getrandbits(8) for _ in range(random.randrange(1, 9))])
m.append([addr, None, dat, bus]) m.append([addr, dat, bus])
return m return m
@ -19,7 +19,7 @@ def time_many_sends(p, bus, p_recv=None, msg_count=100, two_pandas=False, msg_le
raise ValueError("Cannot have two pandas that are the same panda") raise ValueError("Cannot have two pandas that are the same panda")
msg_id = random.randint(0x100, 0x200) msg_id = random.randint(0x100, 0x200)
to_send = [(msg_id, 0, b"\xaa" * msg_len, bus)] * msg_count to_send = [(msg_id, b"\xaa" * msg_len, bus)] * msg_count
start_time = time.monotonic() start_time = time.monotonic()
p.can_send_many(to_send) p.can_send_many(to_send)
@ -35,11 +35,11 @@ def time_many_sends(p, bus, p_recv=None, msg_count=100, two_pandas=False, msg_le
while len(r_echo) < r_echo_len_exected and (time.monotonic() - start_time) < 10: while len(r_echo) < r_echo_len_exected and (time.monotonic() - start_time) < 10:
r_echo.extend(p.can_recv()) r_echo.extend(p.can_recv())
sent_echo = [x for x in r if x[3] == 0x80 | bus and x[0] == msg_id] sent_echo = [x for x in r if x[2] == 0x80 | bus and x[0] == msg_id]
sent_echo.extend([x for x in r_echo if x[3] == 0x80 | bus and x[0] == msg_id]) sent_echo.extend([x for x in r_echo if x[2] == 0x80 | bus and x[0] == msg_id])
resp = [x for x in r if x[3] == bus and x[0] == msg_id] resp = [x for x in r if x[2] == bus and x[0] == msg_id]
leftovers = [x for x in r if (x[3] != 0x80 | bus and x[3] != bus) or x[0] != msg_id] leftovers = [x for x in r if (x[2] != 0x80 | bus and x[2] != bus) or x[0] != msg_id]
assert len(leftovers) == 0 assert len(leftovers) == 0
assert len(resp) == msg_count assert len(resp) == msg_count

View File

@ -69,13 +69,13 @@ def run_test_w_pandas(pandas, sleep_duration):
assert cans_echo[0][0] == at assert cans_echo[0][0] == at
assert cans_loop[0][0] == at assert cans_loop[0][0] == at
assert cans_echo[0][2] == st assert cans_echo[0][1] == st
assert cans_loop[0][2] == st assert cans_loop[0][1] == st
assert cans_echo[0][3] == 0x80 | bus assert cans_echo[0][2] == 0x80 | bus
if cans_loop[0][3] != bus: if cans_loop[0][2] != bus:
print("EXPECTED %d GOT %d" % (bus, cans_loop[0][3])) print("EXPECTED %d GOT %d" % (bus, cans_loop[0][2]))
assert cans_loop[0][3] == bus assert cans_loop[0][2] == bus
print("CAN pass", bus, ho) print("CAN pass", bus, ho)
time.sleep(sleep_duration) time.sleep(sleep_duration)

View File

@ -16,7 +16,7 @@ if JUNGLE:
# Generate unique messages # Generate unique messages
NUM_MESSAGES_PER_BUS = 10000 NUM_MESSAGES_PER_BUS = 10000
messages = [bytes(struct.pack("Q", i)) for i in range(NUM_MESSAGES_PER_BUS)] messages = [bytes(struct.pack("Q", i)) for i in range(NUM_MESSAGES_PER_BUS)]
tx_messages = list(itertools.chain.from_iterable([[0xaa, None, msg, 0], [0xaa, None, msg, 1], [0xaa, None, msg, 2]] for msg in messages)) tx_messages = list(itertools.chain.from_iterable([[0xaa, msg, 0], [0xaa, msg, 1], [0xaa, msg, 2]] for msg in messages))
def flood_tx(panda): def flood_tx(panda):
print('Sending!') print('Sending!')
@ -65,6 +65,6 @@ if __name__ == "__main__":
# Check if we received everything # Check if we received everything
for bus in range(3): for bus in range(3):
received_msgs = {bytes(m[2]) for m in filter(lambda m, b=bus: m[3] == b, rx)} # type: ignore received_msgs = {bytes(m[1]) for m in filter(lambda m, b=bus: m[2] == b, rx)} # type: ignore
dropped_msgs = set(messages).difference(received_msgs) dropped_msgs = set(messages).difference(received_msgs)
print(f"Bus {bus} dropped msgs: {len(list(dropped_msgs))} / {len(messages)}") print(f"Bus {bus} dropped msgs: {len(list(dropped_msgs))} / {len(messages)}")

View File

@ -30,7 +30,7 @@ class CANPackerPanda(CANPacker):
msg = self.make_can_msg(name_or_addr, bus, values) msg = self.make_can_msg(name_or_addr, bus, values)
if fix_checksum is not None: if fix_checksum is not None:
msg = fix_checksum(msg) msg = fix_checksum(msg)
addr, _, dat, bus = msg addr, dat, bus = msg
return libpanda_py.make_CANPacket(addr, bus, dat) return libpanda_py.make_CANPacket(addr, bus, dat)

View File

@ -24,7 +24,7 @@ MSG_IPMA_Data = 0x3D8 # TX by OP, IPMA and LKAS user interface
def checksum(msg): def checksum(msg):
addr, t, dat, bus = msg addr, dat, bus = msg
ret = bytearray(dat) ret = bytearray(dat)
if addr == MSG_Yaw_Data_FD1: if addr == MSG_Yaw_Data_FD1:
@ -50,7 +50,7 @@ def checksum(msg):
chksum = 0xff - (chksum & 0xff) chksum = 0xff - (chksum & 0xff)
ret[1] = chksum ret[1] = chksum
return addr, t, ret, bus return addr, ret, bus
class Buttons: class Buttons:

View File

@ -11,7 +11,7 @@ from panda.tests.safety.hyundai_common import HyundaiButtonBase, HyundaiLongitud
# 4 bit checkusm used in some hyundai messages # 4 bit checkusm used in some hyundai messages
# lives outside the can packer because we never send this msg # lives outside the can packer because we never send this msg
def checksum(msg): def checksum(msg):
addr, t, dat, bus = msg addr, dat, bus = msg
chksum = 0 chksum = 0
if addr == 0x386: if addr == 0x386:
@ -40,7 +40,7 @@ def checksum(msg):
ret = bytearray(dat) ret = bytearray(dat)
ret[6 if addr == 0x394 else 7] |= chksum << (4 if addr == 0x421 else 0) ret[6 if addr == 0x394 else 7] |= chksum << (4 if addr == 0x421 else 0)
return addr, t, ret, bus return addr, ret, bus
class TestHyundaiSafety(HyundaiButtonBase, common.PandaCarSafetyTest, common.DriverTorqueSteeringSafetyTest, common.SteerRequestCutSafetyTest): class TestHyundaiSafety(HyundaiButtonBase, common.PandaCarSafetyTest, common.DriverTorqueSteeringSafetyTest, common.SteerRequestCutSafetyTest):

View File

@ -14,7 +14,7 @@ TX_QUEUES = (lpp.tx1_q, lpp.tx2_q, lpp.tx3_q)
def unpackage_can_msg(pkt): def unpackage_can_msg(pkt):
dat_len = DLC_TO_LEN[pkt[0].data_len_code] dat_len = DLC_TO_LEN[pkt[0].data_len_code]
dat = bytes(pkt[0].data[0:dat_len]) dat = bytes(pkt[0].data[0:dat_len])
return pkt[0].addr, 0, dat, pkt[0].bus return pkt[0].addr, dat, pkt[0].bus
def random_can_messages(n, bus=None): def random_can_messages(n, bus=None):
@ -24,7 +24,7 @@ def random_can_messages(n, bus=None):
bus = random.randint(0, 3) bus = random.randint(0, 3)
address = random.randint(1, (1 << 29) - 1) address = random.randint(1, (1 << 29) - 1)
data = bytes([random.getrandbits(8) for _ in range(DLC_TO_LEN[random.randrange(0, len(DLC_TO_LEN))])]) data = bytes([random.getrandbits(8) for _ in range(DLC_TO_LEN[random.randrange(0, len(DLC_TO_LEN))])])
msgs.append((address, 0, data, bus)) msgs.append((address, data, bus))
return msgs return msgs
@ -34,9 +34,9 @@ class TestPandaComms(unittest.TestCase):
def test_tx_queues(self): def test_tx_queues(self):
for bus in range(len(TX_QUEUES)): for bus in range(len(TX_QUEUES)):
message = (0x100, 0, b"test", bus) message = (0x100, b"test", bus)
can_pkt_tx = libpanda_py.make_CANPacket(message[0], message[3], message[2]) can_pkt_tx = libpanda_py.make_CANPacket(message[0], message[2], message[1])
can_pkt_rx = libpanda_py.ffi.new('CANPacket_t *') can_pkt_rx = libpanda_py.ffi.new('CANPacket_t *')
assert lpp.can_push(TX_QUEUES[bus], can_pkt_tx), "CAN push failed" assert lpp.can_push(TX_QUEUES[bus], can_pkt_tx), "CAN push failed"
@ -46,9 +46,9 @@ class TestPandaComms(unittest.TestCase):
def test_comms_reset_rx(self): def test_comms_reset_rx(self):
# store some test messages in the queue # store some test messages in the queue
test_msg = (0x100, 0, b"test", 0) test_msg = (0x100, b"test", 0)
for _ in range(100): for _ in range(100):
can_pkt_tx = libpanda_py.make_CANPacket(test_msg[0], test_msg[3], test_msg[2]) can_pkt_tx = libpanda_py.make_CANPacket(test_msg[0], test_msg[2], test_msg[1])
lpp.can_push(lpp.rx_q, can_pkt_tx) lpp.can_push(lpp.rx_q, can_pkt_tx)
# read a small chunk such that we have some overflow # read a small chunk such that we have some overflow
@ -76,7 +76,7 @@ class TestPandaComms(unittest.TestCase):
def test_comms_reset_tx(self): def test_comms_reset_tx(self):
# store some test messages in the queue # store some test messages in the queue
test_msg = (0x100, 0, b"test", 0) test_msg = (0x100, b"test", 0)
packed = pack_can_buffer([test_msg for _ in range(100)]) packed = pack_can_buffer([test_msg for _ in range(100)])
# write a small chunk such that we have some overflow # write a small chunk such that we have some overflow
@ -126,7 +126,7 @@ class TestPandaComms(unittest.TestCase):
def test_can_receive_usb(self): def test_can_receive_usb(self):
msgs = random_can_messages(50000) msgs = random_can_messages(50000)
packets = [libpanda_py.make_CANPacket(m[0], m[3], m[2]) for m in msgs] packets = [libpanda_py.make_CANPacket(m[0], m[2], m[1]) for m in msgs]
rx_msgs = [] rx_msgs = []
overflow_buf = b"" overflow_buf = b""

View File

@ -12,7 +12,7 @@ class PandaTestPackUnpack(unittest.TestCase):
for _ in range(10000): for _ in range(10000):
address = random.randint(1, (1 << 29) - 1) address = random.randint(1, (1 << 29) - 1)
data = bytes([random.getrandbits(8) for _ in range(DLC_TO_LEN[random.randrange(0, len(DLC_TO_LEN))])]) data = bytes([random.getrandbits(8) for _ in range(DLC_TO_LEN[random.randrange(0, len(DLC_TO_LEN))])])
to_pack.append((address, 0, data, 0)) to_pack.append((address, data, 0))
packed = pack_can_buffer(to_pack) packed = pack_can_buffer(to_pack)
unpacked = [] unpacked = []