def test_gmlan_bad_toggle(): p = connect_wo_esp() if p.legacy: return # enable output mode p.set_safety_mode(Panda.SAFETY_ALLOUTPUT) # enable CAN loopback mode p.set_can_loopback(True) # GMLAN_CAN2 for bus in [Panda.GMLAN_CAN2, Panda.GMLAN_CAN3]: p.set_gmlan(bus) comp_kbps_gmlan = time_many_sends(p, 3) assert_greater(comp_kbps_gmlan, 0.6 * SPEED_GMLAN) assert_less(comp_kbps_gmlan, 1.0 * SPEED_GMLAN) # normal for bus in [Panda.GMLAN_CAN2, Panda.GMLAN_CAN3]: p.set_gmlan(None) comp_kbps_normal = time_many_sends(p, bus) assert_greater(comp_kbps_normal, 0.6 * SPEED_NORMAL) assert_less(comp_kbps_normal, 1.0 * SPEED_NORMAL)
def test_gmlan(): p = connect_wo_esp() if p.legacy: return # enable output mode p.set_safety_mode(Panda.SAFETY_ALLOUTPUT) # enable CAN loopback mode p.set_can_loopback(True) p.set_can_speed_kbps(1, SPEED_NORMAL) p.set_can_speed_kbps(2, SPEED_NORMAL) p.set_can_speed_kbps(3, SPEED_GMLAN) # set gmlan on CAN2 for bus in [ Panda.GMLAN_CAN2, Panda.GMLAN_CAN3, Panda.GMLAN_CAN2, Panda.GMLAN_CAN3 ]: p.set_gmlan(bus) comp_kbps_gmlan = time_many_sends(p, 3) assert_greater(comp_kbps_gmlan, 0.8 * SPEED_GMLAN) assert_less(comp_kbps_gmlan, 1.0 * SPEED_GMLAN) p.set_gmlan(None) comp_kbps_normal = time_many_sends(p, bus) assert_greater(comp_kbps_normal, 0.8 * SPEED_NORMAL) assert_less(comp_kbps_normal, 1.0 * SPEED_NORMAL) print("%d: %.2f kbps vs %.2f kbps" % (bus, comp_kbps_gmlan, comp_kbps_normal))
def test_gmlan(): p = connect_wo_esp() if p.legacy: return # enable output mode p.set_safety_mode(Panda.SAFETY_ALLOUTPUT) # enable CAN loopback mode p.set_can_loopback(True) p.set_can_speed_kbps(1, SPEED_NORMAL) p.set_can_speed_kbps(2, SPEED_NORMAL) p.set_can_speed_kbps(3, SPEED_GMLAN) # set gmlan on CAN2 for bus in [Panda.GMLAN_CAN2, Panda.GMLAN_CAN3, Panda.GMLAN_CAN2, Panda.GMLAN_CAN3]: p.set_gmlan(bus) comp_kbps_gmlan = time_many_sends(p, 3) assert_greater(comp_kbps_gmlan, 0.8 * SPEED_GMLAN) assert_less(comp_kbps_gmlan, 1.0 * SPEED_GMLAN) p.set_gmlan(None) comp_kbps_normal = time_many_sends(p, bus) assert_greater(comp_kbps_normal, 0.8 * SPEED_NORMAL) assert_less(comp_kbps_normal, 1.0 * SPEED_NORMAL) print("%d: %.2f kbps vs %.2f kbps" % (bus, comp_kbps_gmlan, comp_kbps_normal))
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_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_send_recv(p_send, p_recv): p_send.set_safety_mode(Panda.SAFETY_ALLOUTPUT) p_recv.set_safety_mode(Panda.SAFETY_ALLOUTPUT) p_send.set_can_loopback(False) p_recv.set_can_loopback(False) assert not p_send.legacy assert not p_recv.legacy p_send.can_send_many([(0x1ba, 0, "message", 0)]*2) time.sleep(0.05) p_recv.can_recv() p_send.can_recv() busses = [0,1,2] for bus in busses: for speed in [100, 250, 500, 750, 1000]: p_send.set_can_speed_kbps(bus, speed) p_recv.set_can_speed_kbps(bus, speed) time.sleep(0.05) comp_kbps = time_many_sends(p_send, bus, p_recv, two_pandas=True) saturation_pct = (comp_kbps/speed) * 100.0 assert_greater(saturation_pct, 80) assert_less(saturation_pct, 100) print("two pandas bus {}, 100 messages at speed {:4d}, comp speed is {:7.2f}, percent {:6.2f}".format(bus, speed, comp_kbps, saturation_pct))
def test_recv_only(): p = Panda() 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_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_throughput(): p = connect_wo_esp() # enable output mode p.set_safety_mode(Panda.SAFETY_ALLOUTPUT) # enable CAN loopback mode p.set_can_loopback(True) for speed in [100,250,500,750,1000]: # set bus 0 speed to speed p.set_can_speed_kbps(0, speed) time.sleep(0.05) 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("loopback 100 messages at speed %d, comp speed is %.2f, percent %.2f" % (speed, comp_kbps, saturation_pct))
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"