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 True: # flood msg = b"\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
# try: # for block_msg in accum: # for msg in block_msg: # if msg: # try: # p.can_send(msg[0], str(msg[2]), CAMERA_CAN) # except TypeError as e: # print("error: " + str(e)) # print(msg) # break # except KeyboardInterrupt: # p.close() try: for block_msg in accum: for msg in block_msg: if msg: try: p.can_send(msg[0], str(msg[2]), 0) except TypeError as e: print("error: " + str(e)) print(msg) break except KeyboardInterrupt: p.close() print("Done")
#sys.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 = b"\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()
# Boostrap CSS file (local) @app.server.route('/static/<path:path>') def static_file(path): static_folder = os.path.join(os.getcwd(), 'static') return send_from_directory(static_folder, path) # Global variables and initialization # Open panda device (comma ai) and clear the buffer PANDA = Panda() PANDA.can_clear(0xFFFF) PANDA.set_safety_mode(Panda.SAFETY_ALLOUTPUT) # Send request to broadcast leddar messages dat = '0301000000000000' PANDA.can_send(0x740, dat.decode('hex'), 1) # DBC files: car and leddar base_path = dirname(abspath(__file__)) parent_path = abspath(join(base_path, os.pardir)) leddar = join(parent_path, 'dbc_files/leddar_vu_8_segments.dbc') LEDDAR_DBC = cantools.database.load_file(leddar) # Layout of the app app.layout = html.Div([ html.Link(rel='stylesheet', href='/static/stylesheet.css'), dcc.Interval(id='refresh', interval=200, n_intervals=0), html.Div([ html.Div([ html.Label( 'Gap (m):',