Beispiel #1
0
def raw_panda():
    p = Panda()
    print(p)

    p.set_uart_baud(2, 9600)
    p.set_uart_baud(3, 9600)

    p.set_uart_parity(2, 1)
    p.set_uart_parity(3, 1)

    p.set_uart_callback(2, 1)
    p.set_uart_callback(3, 1)

    idx = 0
    while 1:
        """
    dat = p.serial_read(2)
    if len(dat) > 0:
      print "2:",
      hexdump(dat)

    dat = p.serial_read(3)
    if len(dat) > 0:
      print "3:",
      hexdump(dat)

    print "read done, waiting"
    time.sleep(0.01)
    """

        if idx % 2 == 1:
            dat = "\x20\x80\xc0\xa0"
        else:
            dat = "\x00\x80\xc0\xc0"
        p.can_send(0, dat, 8)

        for r in p.can_recv():
            if r[-1] in [8, 9]:
                print(r[-1], r[2].encode("hex"))

        time.sleep(0.01)
        idx += 1
if __name__ == "__main__":
  if os.getenv("WIFI") is not None:
    p = Panda("WIFI")
  else:
    p = Panda()
  print p.get_serial()
  print p.health()

  t1 = time.time()
  for i in range(100):
    p.get_serial()
  t2 = time.time()
  print "100 requests took %.2f ms" % ((t2-t1)*1000)

  p.set_controls_allowed(True)

  a = 0
  while 1:
    # flood
    msg = "\xaa"*4 + struct.pack("I", a)
    p.can_send(0xaa, msg, 0)
    p.can_send(0xaa, msg, 1)
    p.can_send(0xaa, msg, 4)
    time.sleep(0.01)

    dat = p.can_recv()
    if len(dat) > 0:
      print dat
    a += 1

  #exit(0)

  p_out.set_controls_allowed(True)

  set_out, set_in = set(), set()

  # drain
  p_out.can_recv()
  p_in.can_recv()
  
  BATCH_SIZE = 16
  for a in tqdm(range(0, 10000, BATCH_SIZE)):
    for b in range(0, BATCH_SIZE):
      msg = "\xaa"*4 + struct.pack("I", a+b)
      if a%1 == 0:
        p_out.can_send(0xaa, msg, 0)

    dat_out, dat_in = p_out.can_recv(), p_in.can_recv()
    if len(dat_in) != 0:
      print len(dat_in)

    num_out = [struct.unpack("I", i[4:])[0] for _, _, i, _ in dat_out]
    num_in = [struct.unpack("I", i[4:])[0] for _, _, i, _ in dat_in]

    set_in.update(num_in)
    set_out.update(num_out)

  # swag
  print "waiting for packets"
  time.sleep(2.0)
  dat_in = p_in.can_recv()