def run_test(): pandas = Panda.list() print pandas if len(pandas) == 0: print "NO PANDAS" assert False if len(pandas) == 1: # if we only have one on USB, assume the other is on wifi pandas.append("WIFI") run_test_w_pandas(pandas)
def can_printer(): p = Panda() start = sec_since_boot() lp = sec_since_boot() msgs = defaultdict(list) canbus = int(os.getenv("CAN", 0)) while 1: can_recv = p.can_recv() for address, _, dat, src in can_recv: if src == canbus: msgs[address].append(dat) if sec_since_boot() - lp > 0.1: dd = chr(27) + "[2J" dd += "%5.2f\n" % (sec_since_boot() - start) for k, v in sorted( zip(msgs.keys(), map(lambda x: x[-1].encode("hex"), msgs.values()))): dd += "%s(%6d) %s\n" % ("%04X(%4d)" % (k, k), len(msgs[k]), v) print dd lp = sec_since_boot()
#!/usr/bin/env python import os import struct import time from panda.lib.panda import Panda 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)
def run_test_w_pandas(pandas): h = map(lambda x: Panda(x), pandas) print h for hh in h: hh.set_controls_allowed(True) # test both directions for ho in permutations(range(len(h)), r=2): print "***************** TESTING", ho # **** test health packet **** print "health", ho[0], h[ho[0]].health() # **** test K/L line loopback **** for bus in [2, 3]: # flush the output h[ho[1]].kline_drain(bus=bus) # send the characters st = get_test_string() st = "\xaa" + chr(len(st) + 3) + st h[ho[0]].kline_send(st, bus=bus, checksum=False) # check for receive ret = h[ho[1]].kline_drain(bus=bus) hexdump(st) hexdump(ret) assert st == ret print "K/L pass", bus, ho # **** test can line loopback **** for bus in [0, 1, 4, 5]: print "test can", bus # flush cans_echo = h[ho[0]].can_recv() cans_loop = h[ho[1]].can_recv() # set GMLAN mode if bus == 5: h[ho[0]].set_gmlan(True) h[ho[1]].set_gmlan(True) bus = 1 # GMLAN is multiplexed with CAN2 is_gmlan = True else: h[ho[0]].set_gmlan(False) h[ho[1]].set_gmlan(False) is_gmlan = False # send the characters # pick addresses high enough to not conflict with honda code at = random.randint(1024, 2000) st = get_test_string()[0:8] h[ho[0]].can_send(at, st, bus) time.sleep(0.1) # check for receive cans_echo = h[ho[0]].can_recv() cans_loop = h[ho[1]].can_recv() print bus, cans_echo, cans_loop assert len(cans_echo) == 1 assert len(cans_loop) == 1 assert cans_echo[0][0] == at assert cans_loop[0][0] == at assert cans_echo[0][2] == st assert cans_loop[0][2] == st assert cans_echo[0][3] == bus + 2 assert cans_loop[0][3] == bus print "CAN pass", bus, ho
def run_test(): pandas = Panda.list() print pandas if len(pandas) == 0: print "NO PANDAS" assert False if len(pandas) == 1: # if we only have one on USB, assume the other is on wifi pandas.append("WIFI") h = map(lambda x: Panda(x), pandas) print h # test both directions for ho in [[0,1], [1,0]]: # **** test health packet **** print "health", ho[0], h[ho[0]].health() # **** test K/L line loopback **** for bus in [2,3]: # flush the output h[ho[1]].kline_drain(bus=bus) # send the characters st = get_test_string() st = "\xaa"+chr(len(st)+3)+st h[ho[0]].kline_send(st, bus=bus, checksum=False) # check for receive ret = h[ho[1]].kline_drain(bus=bus) hexdump(st) hexdump(ret) assert st == ret print "K/L pass", bus, ho # **** test can line loopback **** for bus in [0,1,4,5]: print "test can", bus # flush cans_echo = h[ho[0]].can_recv() cans_loop = h[ho[1]].can_recv() # set GMLAN mode if bus == 5: h[ho[0]].set_gmlan(True) h[ho[1]].set_gmlan(True) bus = 1 # GMLAN is multiplexed with CAN2 is_gmlan = True else: h[ho[0]].set_gmlan(False) h[ho[1]].set_gmlan(False) is_gmlan = False # send the characters # pick addresses high enough to not conflict with honda code at = random.randint(1024, 2000) st = get_test_string()[0:8] h[ho[0]].can_send(at, st, bus) time.sleep(0.1) # check for receive cans_echo = h[ho[0]].can_recv() cans_loop = h[ho[1]].can_recv() print bus, cans_echo, cans_loop assert len(cans_echo) == 1 assert len(cans_loop) == 1 assert cans_echo[0][0] == at assert cans_loop[0][0] == at assert cans_echo[0][2] == st assert cans_loop[0][2] == st assert cans_echo[0][3] == bus+2 assert cans_loop[0][3] == bus print "CAN pass", bus, ho
#!/usr/bin/env python import os import sys import usb1 import time import select from panda.lib.panda import Panda setcolor = ["\033[1;32;40m", "\033[1;31;40m"] unsetcolor = "\033[00m" if __name__ == "__main__": port_number = int(os.getenv("PORT", 0)) serials = Panda.list() pandas = map(lambda x: Panda(x, False), serials) while 1: for i, panda in enumerate(pandas): ret = panda.serial_read(port_number) if len(ret) > 0: sys.stdout.write(setcolor[i] + ret + unsetcolor) sys.stdout.flush() if select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []): ln = sys.stdin.readline() panda.serial_write(port_number, ln) time.sleep(0.05)
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
#!/usr/bin/env python import os from panda.lib.panda import Panda if __name__ == "__main__": if os.getenv("WIFI") is not None: p = Panda("WIFI") else: p = Panda() print p.health()
#!/usr/bin/env python import os import struct import time from panda.lib.panda import Panda, PandaWifiStreaming from tqdm import tqdm # test throughput between USB and wifi if __name__ == "__main__": print Panda.list() p_out = Panda("108018800f51363038363036") print p_out.get_serial() #p_in = Panda("02001b000f51363038363036") p_in = Panda("WIFI") print p_in.get_serial() p_in = PandaWifiStreaming() #while 1: # p_in.can_recv() #exit(0) p_out.set_controls_allowed(True) set_out, set_in = set(), set() # drain p_out.can_recv() p_in.can_recv()