def send_thread(sender_serial): while True: try: if jungle: sender = PandaJungle(sender_serial) else: sender = Panda(sender_serial) sender.set_safety_mode(Panda.SAFETY_ALLOUTPUT) sender.set_can_loopback(False) can_sock = messaging.sub_sock('can') while True: tsc = messaging.recv_one(can_sock) snd = can_capnp_to_can_list(tsc.can) snd = list(filter(lambda x: x[-1] <= 2, snd)) try: sender.can_send_many(snd) except usb1.USBErrorTimeout: pass # Drain panda message buffer sender.can_recv() except Exception: traceback.print_exc() time.sleep(1)
def send_thread(sender_serial): global jungle try: if jungle: sender = PandaJungle(sender_serial) else: sender = Panda(sender_serial) sender.set_safety_mode(Panda.SAFETY_ALLOUTPUT) sender.set_can_loopback(False) can_sock = messaging.sub_sock('can') while True: # Send messages one bus 0 and 1 tsc = messaging.recv_one(can_sock) snd = can_capnp_to_can_list(tsc.can) snd = list(filter(lambda x: x[-1] <= 2, snd)) sender.can_send_many(snd) # Drain panda message buffer sender.can_recv() except Exception: traceback.print_exc()
print("timeout, transferred: ", transferred) print(f"Done sending {3*NUM_MESSAGES_PER_BUS} messages!") if __name__ == "__main__": serials = Panda.list() 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) sender.set_safety_mode(Panda.SAFETY_ALLOUTPUT) sender.set_heartbeat_disabled() # Start transmisson threading.Thread(target=flood_tx, args=(sender, )).start() # Receive as much as we can, and stop when there hasn't been anything for a second rx: List[Any] = [] old_len = 0 last_change = time.monotonic() while time.monotonic() - last_change < 1: if old_len < len(rx): last_change = time.monotonic() old_len = len(rx)