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
|
2020-05-30 02:52:03 +08:00
|
|
|
from typing import Any, List
|
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:
|
|
|
|
from panda_jungle import PandaJungle
|
|
|
|
|
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
|
2020-04-07 07:49:42 +08:00
|
|
|
packet = [[0xaa, None, msg, 0], [0xaa, None, msg, 1], [0xaa, None, msg, 2]] * NUM_MESSAGES_PER_BUS
|
|
|
|
panda.can_send_many(packet)
|
|
|
|
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])
|
|
|
|
receiver = Panda(serials[1])
|
|
|
|
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)
|
2021-10-01 18:39:05 +08:00
|
|
|
sender.set_heartbeat_disabled()
|
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
|
2020-05-30 02:52:03 +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)
|
|
|
|
rx.extend(receiver.can_recv())
|
|
|
|
print(f"Received {len(rx)} messages")
|