2020-04-07 07:49:42 +08:00
|
|
|
#!/usr/bin/env python3
|
2021-10-01 18:39:05 +08:00
|
|
|
import os
|
2020-05-30 02:52:03 +08:00
|
|
|
import time
|
2021-10-01 18:39:05 +08:00
|
|
|
import threading
|
2024-02-25 05:56:28 +08:00
|
|
|
from typing import Any
|
2020-04-07 07:49:42 +08:00
|
|
|
|
|
|
|
from panda import Panda
|
|
|
|
|
2021-10-01 18:39:05 +08:00
|
|
|
JUNGLE = "JUNGLE" in os.environ
|
|
|
|
if JUNGLE:
|
2023-08-04 14:55:13 +08:00
|
|
|
from panda import PandaJungle
|
2021-10-01 18:39:05 +08:00
|
|
|
|
2020-04-07 07:49:42 +08:00
|
|
|
# The TX buffers on pandas is 0x100 in length.
|
|
|
|
NUM_MESSAGES_PER_BUS = 10000
|
|
|
|
|
|
|
|
def flood_tx(panda):
|
|
|
|
print('Sending!')
|
2020-06-01 16:49:26 +08:00
|
|
|
msg = b"\xaa" * 4
|
2024-07-31 12:20:48 +08:00
|
|
|
packet = [[0xaa, msg, 0], [0xaa, msg, 1], [0xaa, msg, 2]] * NUM_MESSAGES_PER_BUS
|
2021-10-01 19:57:44 +08:00
|
|
|
panda.can_send_many(packet, timeout=10000)
|
2020-04-07 07:49:42 +08:00
|
|
|
print(f"Done sending {3*NUM_MESSAGES_PER_BUS} messages!")
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
serials = Panda.list()
|
2021-10-01 18:39:05 +08:00
|
|
|
if JUNGLE:
|
|
|
|
sender = Panda()
|
|
|
|
receiver = PandaJungle()
|
|
|
|
else:
|
|
|
|
if len(serials) != 2:
|
|
|
|
raise Exception("Connect two pandas to perform this test!")
|
|
|
|
sender = Panda(serials[0])
|
2023-08-04 14:55:13 +08:00
|
|
|
receiver = Panda(serials[1]) # type: ignore
|
2021-10-01 18:39:05 +08:00
|
|
|
receiver.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
|
2020-05-30 02:52:03 +08:00
|
|
|
|
2020-04-07 07:49:42 +08:00
|
|
|
sender.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
|
2020-05-30 02:52:03 +08:00
|
|
|
|
2020-04-07 07:49:42 +08:00
|
|
|
# Start transmisson
|
|
|
|
threading.Thread(target=flood_tx, args=(sender,)).start()
|
|
|
|
|
|
|
|
# Receive as much as we can in a few second time period
|
2024-02-25 05:56:28 +08:00
|
|
|
rx: list[Any] = []
|
2020-04-07 07:49:42 +08:00
|
|
|
old_len = 0
|
|
|
|
start_time = time.time()
|
2021-10-01 18:39:05 +08:00
|
|
|
while time.time() - start_time < 3 or len(rx) > old_len:
|
2020-04-07 07:49:42 +08:00
|
|
|
old_len = len(rx)
|
2021-10-01 19:57:44 +08:00
|
|
|
print(old_len)
|
2020-04-07 07:49:42 +08:00
|
|
|
rx.extend(receiver.can_recv())
|
|
|
|
print(f"Received {len(rx)} messages")
|