Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
class TestPedal(unittest.TestCase):
  
  def setUp(self):
    self.jungle = PandaJungle(JUNGLE_SERIAL)
    self.jungle.set_panda_power(True)
    self.jungle.set_ignition(False)

  def tearDown(self):
    self.jungle.close()

  def _flash_over_can(self, bus, fw_file):
    print(f"Flashing {fw_file}")
    while len(self.jungle.can_recv()) != 0:
      continue
    self.jungle.can_send(0x200, b"\xce\xfa\xad\xde\x1e\x0b\xb0\x0a", bus)

    time.sleep(0.1)
    with open(fw_file, "rb") as code:
      PandaJungle.flash_static(CanHandle(self.jungle, bus), code.read())

  def _listen_can_frames(self):
    self.jungle.can_clear(0xFFFF)
    msgs = 0
    for _ in range(10):
      incoming = self.jungle.can_recv()
      for message in incoming:
        address, _, _, bus = message
        if address == 0x201 and bus == PEDAL_BUS:
          msgs += 1
      time.sleep(0.1)
    return msgs

  def test_usb_fw(self):
    subprocess.check_output(f"cd {BASEDIR} && PEDAL=1 PEDAL_USB=1 scons", shell=True)
    self._flash_over_can(PEDAL_BUS, f"{BASEDIR}board/obj/pedal_usb.bin.signed")
    time.sleep(2)
    p = Panda(PEDAL_SERIAL)
    self.assertTrue(p.is_pedal())
    p.close()
    self.assertTrue(self._listen_can_frames() > 40)

  def test_nonusb_fw(self):
    subprocess.check_output(f"cd {BASEDIR} && PEDAL=1 scons", shell=True)
    self._flash_over_can(PEDAL_BUS, f"{BASEDIR}board/obj/pedal.bin.signed")
    time.sleep(2)
    self.assertTrue(PEDAL_SERIAL not in Panda.list())
    self.assertTrue(self._listen_can_frames() > 40)
Ejemplo n.º 3
0
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()
Ejemplo n.º 4
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)

        rx.extend(receiver.can_recv())
    print(f"Received {len(rx)} messages")

    # Check if we received everything
    for bus in range(3):
        received_msgs = set(
            map(lambda m: bytes(m[2]), filter(lambda m, b=bus: m[3] == b,
                                              rx)))  # type: ignore
        dropped_msgs = set(messages).difference(received_msgs)
        print(
            f"Bus {bus} dropped msgs: {len(list(dropped_msgs))} / {len(messages)}"
        )