def test_throughput(serial=None): connect_wifi(serial) p = Panda(serial) # enable output mode p.set_safety_mode(Panda.SAFETY_ALLOUTPUT) # send heartbeat p.send_heartbeat() # enable CAN loopback mode p.set_can_loopback(True) p = Panda("WIFI") for speed in [100,250,500,750,1000]: # send heartbeat p.send_heartbeat() # set bus 0 speed to speed p.set_can_speed_kbps(0, speed) time.sleep(0.1) comp_kbps = time_many_sends(p, 0) # bit count from https://en.wikipedia.org/wiki/CAN_bus saturation_pct = (comp_kbps/speed) * 100.0 #assert_greater(saturation_pct, 80) #assert_less(saturation_pct, 100) print("WIFI loopback 100 messages at speed %d, comp speed is %.2f, percent %.2f" % (speed, comp_kbps, saturation_pct))
def test_udp_doesnt_drop(): connect_wifi() p = Panda() p.set_safety_mode(Panda.SAFETY_ALLOUTPUT) p.set_can_loopback(True) pwifi = PandaWifiStreaming() while 1: if len(pwifi.can_recv()) == 0: break for msg_count in [1, 100]: for i in range({1: 0x80, 100: 0x20}[msg_count]): pwifi.kick() speed = 500 p.set_can_speed_kbps(0, speed) comp_kbps = time_many_sends(p, 0, pwifi, msg_count=msg_count, msg_id=0x100 + i) saturation_pct = (comp_kbps / speed) * 100.0 if msg_count == 1: sys.stdout.write(".") sys.stdout.flush() else: print( "UDP WIFI loopback %d messages at speed %d, comp speed is %.2f, percent %.2f" % (msg_count, speed, comp_kbps, saturation_pct)) assert_greater(saturation_pct, 40) assert_less(saturation_pct, 100) print("")
def test_wifi_flash_st(serial=None): connect_wifi(serial) assert Panda.flash_ota_st(), "OTA ST Flash Failed" connected = False st = time.time() while not connected and (time.time() - st) < 20: try: p = Panda(serial=serial) p.get_serial() connected = True except: time.sleep(1) if not connected: assert False, "Panda failed to connect on USB after flashing"
def test_recv_only(serial=None): connect_wifi(serial) p = Panda(serial) p.set_safety_mode(Panda.SAFETY_ALLOUTPUT) p.set_can_loopback(True) pwifi = Panda("WIFI") # TODO: msg_count=1000 drops packets, is this fixable? for msg_count in [10,100,200]: speed = 500 p.set_can_speed_kbps(0, speed) comp_kbps = time_many_sends(p, 0, pwifi, msg_count) saturation_pct = (comp_kbps/speed) * 100.0 print("HT WIFI loopback %d messages at speed %d, comp speed is %.2f, percent %.2f" % (msg_count, speed, comp_kbps, saturation_pct))
def test_get_serial_wifi(): connect_wifi() p = Panda("WIFI") print(p.get_serial())
def test_udp_doesnt_drop(serials=None): connect_wifi(serials[0]) p = Panda(serials[0]) p.set_safety_mode(Panda.SAFETY_ALLOUTPUT) p.set_can_loopback(True) pwifi = PandaWifiStreaming() while 1: if len(pwifi.can_recv()) == 0: break for msg_count in [1, 100]: saturation_pcts = [] for i in range({1: 0x80, 100: 0x20}[msg_count]): pwifi.kick() speed = 500 p.set_can_speed_kbps(0, speed) comp_kbps = time_many_sends(p, 0, pwifi, msg_count=msg_count, msg_id=0x100 + i) saturation_pct = (comp_kbps / speed) * 100.0 if msg_count == 1: sys.stdout.write(".") sys.stdout.flush() else: print( "UDP WIFI loopback %d messages at speed %d, comp speed is %.2f, percent %.2f" % (msg_count, speed, comp_kbps, saturation_pct)) assert_greater(saturation_pct, 20) #sometimes the wifi can be slow... assert_less(saturation_pct, 100) saturation_pcts.append(saturation_pct) if len(saturation_pcts) > 0: assert_greater(sum(saturation_pcts) / len(saturation_pcts), 60) time.sleep(5) usb_ok_cnt = 0 REQ_USB_OK_CNT = 500 st = time.time() msg_id = 0x1bb bus = 0 last_missing_msg = 0 while usb_ok_cnt < REQ_USB_OK_CNT and (time.time() - st) < 40: p.can_send(msg_id, "message", bus) time.sleep(0.01) r = [1] missing = True while len(r) > 0: r = p.can_recv() r = filter(lambda x: x[3] == bus and x[0] == msg_id, r) if len(r) > 0: missing = False usb_ok_cnt += len(r) if missing: last_missing_msg = time.time() et = time.time() - st last_missing_msg = last_missing_msg - st print( "waited {} for panda to recv can on usb, {} msgs, last missing at {}". format(et, usb_ok_cnt, last_missing_msg)) assert usb_ok_cnt >= REQ_USB_OK_CNT, "Unable to recv can on USB after UDP"
def test_get_serial_wifi(serial=None): connect_wifi(serial) p = Panda("WIFI") print(p.get_serial())
def test_flash_wifi(): Panda.flash_ota_wifi() connect_wifi()
def test_connect_wifi(): connect_wifi()
def test_webpage_fetch(serial=None): connect_wifi(serial) r = requests.get("http://192.168.0.10/") print(r.text) assert "This is your comma.ai panda" in r.text
def test_flash_wifi(serial=None): connect_wifi(serial) assert Panda.flash_ota_wifi(release=True), "OTA Wifi Flash Failed" connect_wifi(serial)
def test_connect_wifi(serial=None): connect_wifi(serial)
def test_flash_wifi(serials=None): connect_wifi(serials[0]) assert Panda.flash_ota_wifi(release=False), "OTA Wifi Flash Failed" connect_wifi(serials[0])
def test_connect_wifi(serials=None): connect_wifi(serials[0])