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 update_panda(): panda = None panda_dfu = None cloudlog.info("Connecting to panda") while True: # break on normal mode Panda panda_list = Panda.list() if len(panda_list) > 0: cloudlog.info("Panda found, connecting") panda = Panda(panda_list[0]) break # flash on DFU mode Panda panda_dfu = PandaDFU.list() if len(panda_dfu) > 0: cloudlog.info("Panda in DFU mode found, flashing recovery") panda_dfu = PandaDFU(panda_dfu[0]) panda_dfu.recover() time.sleep(1) fw_fn = get_firmware_fn() fw_signature = get_expected_signature(fw_fn) try: serial = panda.get_serial()[0].decode("utf-8") except Exception: serial = None panda_version = "bootstub" if panda.bootstub else panda.get_version() panda_signature = b"" if panda.bootstub else panda.get_signature() cloudlog.warning( "Panda %s connected, version: %s, signature %s, expected %s" % ( serial, panda_version, panda_signature.hex(), fw_signature.hex(), )) if panda.bootstub or panda_signature != fw_signature: cloudlog.info("Panda firmware out of date, update required") panda.flash(fw_fn) cloudlog.info("Done flashing") if panda.bootstub: cloudlog.info( "Flashed firmware not booting, flashing development bootloader") panda.recover() cloudlog.info("Done flashing bootloader") if panda.bootstub: cloudlog.info("Panda still not booting, exiting") raise AssertionError panda_signature = panda.get_signature() if panda_signature != fw_signature: cloudlog.info("Version mismatch after flashing, exiting") raise AssertionError
def update_panda(): repo_version = get_expected_version() panda = None panda_dfu = None cloudlog.info("Connecting to panda") while True: # break on normal mode Panda panda_list = Panda.list() if len(panda_list) > 0: cloudlog.info("Panda found, connecting") panda = Panda(panda_list[0]) break # flash on DFU mode Panda panda_dfu = PandaDFU.list() if len(panda_dfu) > 0: cloudlog.info("Panda in DFU mode found, flashing recovery") panda_dfu = PandaDFU(panda_dfu[0]) panda_dfu.recover() print("waiting for board...") time.sleep(1) try: serial = panda.get_serial()[0].decode("utf-8") except Exception: serial = None current_version = "bootstub" if panda.bootstub else panda.get_version() cloudlog.warning("Panda %s connected, version: %s, expected %s" % (serial, current_version, repo_version)) if panda.bootstub or not current_version.startswith(repo_version): cloudlog.info("Panda firmware out of date, update required") signed_fn = os.path.join(BASEDIR, "board", "obj", "panda.bin.signed") if os.path.exists(signed_fn): cloudlog.info("Flashing signed firmware") panda.flash(fn=signed_fn) else: cloudlog.info("Building and flashing unsigned firmware") panda.flash() cloudlog.info("Done flashing") if panda.bootstub: cloudlog.info("Flashed firmware not booting, flashing development bootloader") panda.recover() cloudlog.info("Done flashing bootloader") if panda.bootstub: cloudlog.info("Panda still not booting, exiting") raise AssertionError version = panda.get_version() if not version.startswith(repo_version): cloudlog.info("Version mismatch after flashing, exiting") raise AssertionError
def connect_wifi(): p = Panda() ssid, pw = p.get_serial() ssid = ssid.strip("\x00") assert (ssid.isalnum()) assert (pw.isalnum()) ssid = "panda-" + ssid # Mac OS X only # TODO: Ubuntu os.system("networksetup -setairportnetwork en0 %s %s" % (ssid, pw))
def get_panda_password(): try: print("Trying to connect to Panda over USB...") p = Panda() except AssertionError: print("USB connection failed") sys.exit(0) wifi = p.get_serial() print("SSID: " + wifi[0]) print("Password: " + wifi[1])
def get_panda_password(): try: print("Trying to connect to Panda over USB...") p = Panda() except AssertionError: print("USB connection failed") sys.exit(0) wifi = p.get_serial() #print('[%s]' % ', '.join(map(str, wifi))) print("SSID: " + wifi[0].decode("utf-8")) print("Password: "******"utf-8"))
#!/usr/bin/env python import os import sys import struct import time sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) from 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_mode() a = 0 while True: # flood msg = b"\xaa" * 4 + struct.pack("I", a) p.can_send(0xaa, msg, 0)
#!/usr/bin/env python3 from panda import Panda if __name__ == "__main__": for p in Panda.list(): pp = Panda(p) print("%s: %s" % (pp.get_serial()[0], pp.get_version()))
def connect_wifi(serial=None): p = Panda(serial=serial) p.set_esp_power(True) dongle_id, pw = p.get_serial() assert (dongle_id.isalnum()) _connect_wifi(dongle_id, pw)
def _connect_wifi(dongle_id, pw, insecure_okay=False): ssid = "panda-" + dongle_id r = subprocess.call(["ping", "-W", "4", "-c", "1", "192.168.0.10"], stdout=FNULL, stderr=subprocess.STDOUT) if not r: #Can already ping, try connecting on wifi try: p = Panda("WIFI") p.get_serial() print("Already connected") return except: pass print("WIFI: connecting to %s" % ssid) while 1: if sys.platform == "darwin": os.system("networksetup -setairportnetwork en0 %s %s" % (ssid, pw)) else: wlan_interface = subprocess.check_output([ "sh", "-c", "iw dev | awk '/Interface/ {print $2}'" ]).strip().decode('utf8') cnt = 0 MAX_TRIES = 10 while cnt < MAX_TRIES: print("WIFI: scanning %d" % cnt) os.system("iwlist %s scanning > /dev/null" % wlan_interface) os.system("nmcli device wifi rescan") wifi_networks = [ x.decode("utf8") for x in subprocess.check_output( ["nmcli", "dev", "wifi", "list"]).split(b"\n") ] wifi_scan = [x for x in wifi_networks if ssid in x] if len(wifi_scan) != 0: break time.sleep(0.1) # MAX_TRIES tries, ~10 seconds max cnt += 1 assert cnt < MAX_TRIES if "-pair" in wifi_scan[0]: os.system("nmcli d wifi connect %s-pair" % (ssid)) connect_cnt = 0 MAX_TRIES = 100 while connect_cnt < MAX_TRIES: connect_cnt += 1 r = subprocess.call( ["ping", "-W", "4", "-c", "1", "192.168.0.10"], stdout=FNULL, stderr=subprocess.STDOUT) if r: print("Waiting for panda to ping...") time.sleep(0.5) else: break if insecure_okay: break # fetch webpage print("connecting to insecure network to secure") try: r = requests.get("http://192.168.0.10/") except requests.ConnectionError: r = requests.get("http://192.168.0.10/") assert r.status_code == 200 print("securing") try: r = requests.get("http://192.168.0.10/secure", timeout=0.01) except requests.exceptions.Timeout: print("timeout http request to secure") pass else: ret = os.system("nmcli d wifi connect %s password %s" % (ssid, pw)) if os.WEXITSTATUS(ret) == 0: #check ping too ping_ok = False connect_cnt = 0 MAX_TRIES = 10 while connect_cnt < MAX_TRIES: connect_cnt += 1 r = subprocess.call( ["ping", "-W", "4", "-c", "1", "192.168.0.10"], stdout=FNULL, stderr=subprocess.STDOUT) if r: print("Waiting for panda to ping...") time.sleep(0.1) else: ping_ok = True break if ping_ok: break
def test_get_serial(): p = Panda() print(p.get_serial())
def test_get_serial_wifi(serial=None): connect_wifi(serial) p = Panda("WIFI") print(p.get_serial())
from __future__ import print_function import os import sys import struct import time from tqdm import tqdm sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) from panda import Panda, PandaWifiStreaming # 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 True: # p_in.can_recv() #sys.exit(0) p_out.set_controls_allowed(True) set_out, set_in = set(), set() # drain
def flash_release(path=None, st_serial=None): from panda import Panda, PandaDFU, ESPROM, CesantaFlasher from zipfile import ZipFile def status(x): print("\033[1;32;40m" + x + "\033[00m") if st_serial == None: # look for Panda panda_list = Panda.list() if len(panda_list) == 0: raise Exception( "panda not found, make sure it's connected and your user can access it" ) elif len(panda_list) > 1: raise Exception("Please only connect one panda") st_serial = panda_list[0] print("Using panda with serial %s" % st_serial) if path == None: print( "Fetching latest firmware from github.com/commaai/panda-artifacts") r = requests.get( "https://raw.githubusercontent.com/commaai/panda-artifacts/master/latest.json" ) url = json.loads(r.text)['url'] r = requests.get(url) print("Fetching firmware from %s" % url) path = io.StringIO(r.content) zf = ZipFile(path) zf.printdir() version = zf.read("version") status("0. Preparing to flash " + version) code_bootstub = zf.read("bootstub.panda.bin") code_panda = zf.read("panda.bin") code_boot_15 = zf.read("boot_v1.5.bin") code_boot_15 = code_boot_15[0:2] + "\x00\x30" + code_boot_15[4:] code_user1 = zf.read("user1.bin") code_user2 = zf.read("user2.bin") # enter DFU mode status("1. Entering DFU mode") panda = Panda(st_serial) panda.enter_bootloader() time.sleep(1) # program bootstub status("2. Programming bootstub") dfu = PandaDFU(PandaDFU.st_serial_to_dfu_serial(st_serial)) dfu.program_bootstub(code_bootstub) time.sleep(1) # flash main code status("3. Flashing main code") panda = Panda(st_serial) panda.flash(code=code_panda) panda.close() # flashing ESP if panda.is_white(): status("4. Flashing ESP (slow!)") align = lambda x, sz=0x1000: x + "\xFF" * ((sz - len(x)) % sz) esp = ESPROM(st_serial) esp.connect() flasher = CesantaFlasher(esp, 230400) flasher.flash_write(0x0, align(code_boot_15), True) flasher.flash_write(0x1000, align(code_user1), True) flasher.flash_write(0x81000, align(code_user2), True) flasher.flash_write(0x3FE000, "\xFF" * 0x1000) flasher.boot_fw() del flasher del esp time.sleep(1) else: status("4. No ESP in non-white panda") # check for connection status("5. Verifying version") panda = Panda(st_serial) my_version = panda.get_version() print("dongle id: %s" % panda.get_serial()[0]) print(my_version, "should be", version) assert (str(version) == str(my_version)) # done! status("6. Success!")
import os import sys import struct import time from tqdm import tqdm sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) from panda import Panda, PandaWifiStreaming # 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() # type: ignore #while True: # p_in.can_recv() #sys.exit(0) p_out.set_safety_mode(Panda.SAFETY_ALLOUTPUT) set_out, set_in = set(), set() # drain
def test_get_serial_in_flash_mode(serial=None): p = Panda(serial) p.reset(enter_bootstub=True) assert (p.bootstub) print(p.get_serial()) p.reset()
def test_get_serial(serial=None): p = Panda(serial) print(p.get_serial())
#!/usr/bin/env python import os import sys import struct import time sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) from 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 True: # flood msg = b"\xaa"*4 + struct.pack("I", a) p.can_send(0xaa, msg, 0) p.can_send(0xaa, msg, 1)
def connect_wifi(): p = Panda() dongle_id, pw = p.get_serial() dongle_id = ssid.strip("\x00") assert(dongle_id.isalnum()) _connect_wifi(dongle_id, pw)
def flash_release(path=None, st_serial=None): from panda import Panda, PandaDFU, ESPROM, CesantaFlasher from zipfile import ZipFile def status(x): print("\033[1;32;40m"+x+"\033[00m") if st_serial == None: # look for Panda panda_list = Panda.list() if len(panda_list) == 0: raise Exception("panda not found, make sure it's connected and your user can access it") elif len(panda_list) > 1: raise Exception("Please only connect one panda") st_serial = panda_list[0] print("Using panda with serial %s" % st_serial) if path == None: print("Fetching latest firmware from github.com/commaai/panda-artifacts") r = requests.get("https://raw.githubusercontent.com/commaai/panda-artifacts/master/latest.json") url = json.loads(r.text)['url'] r = requests.get(url) print("Fetching firmware from %s" % url) path = StringIO.StringIO(r.content) zf = ZipFile(path) zf.printdir() version = zf.read("version") status("0. Preparing to flash "+version) code_bootstub = zf.read("bootstub.panda.bin") code_panda = zf.read("panda.bin") code_boot_15 = zf.read("boot_v1.5.bin") code_boot_15 = code_boot_15[0:2] + "\x00\x30" + code_boot_15[4:] code_user1 = zf.read("user1.bin") code_user2 = zf.read("user2.bin") # enter DFU mode status("1. Entering DFU mode") panda = Panda(st_serial) panda.enter_bootloader() time.sleep(1) # program bootstub status("2. Programming bootstub") dfu = PandaDFU(PandaDFU.st_serial_to_dfu_serial(st_serial)) dfu.program_bootstub(code_bootstub) time.sleep(1) # flash main code status("3. Flashing main code") panda = Panda(st_serial) panda.flash(code=code_panda) panda.close() # flashing ESP status("4. Flashing ESP (slow!)") align = lambda x, sz=0x1000: x+"\xFF"*((sz-len(x)) % sz) esp = ESPROM(st_serial) esp.connect() flasher = CesantaFlasher(esp, 230400) flasher.flash_write(0x0, align(code_boot_15), True) flasher.flash_write(0x1000, align(code_user1), True) flasher.flash_write(0x81000, align(code_user2), True) flasher.flash_write(0x3FE000, "\xFF"*0x1000) flasher.boot_fw() del flasher del esp time.sleep(1) # check for connection status("5. Verifying version") panda = Panda(st_serial) my_version = panda.get_version() print("dongle id: %s" % panda.get_serial()[0]) print(my_version, "should be", version) assert(str(version) == str(my_version)) # done! status("6. Success!")
def test_get_serial_wifi(): connect_wifi() p = Panda("WIFI") print(p.get_serial())
#!/usr/bin/env python from panda import Panda if __name__ == "__main__": for p in Panda.list(): pp = Panda(p) print("%s: %s" % (pp.get_serial()[0], pp.get_version()))
def test_get_serial_wifi(): p = Panda("WIFI") print(p.get_serial())
def test_get_serial_in_flash_mode(): p = Panda() p.reset(enter_bootstub=True) assert(p.bootstub) print(p.get_serial()) p.reset()
def flash_release(path=None, st_serial=None): from panda import Panda, PandaDFU from zipfile import ZipFile def status(x): print("\033[1;32;40m" + x + "\033[00m") if st_serial is not None: # look for Panda panda_list = Panda.list() if len(panda_list) == 0: raise Exception( "panda not found, make sure it's connected and your user can access it" ) elif len(panda_list) > 1: raise Exception("Please only connect one panda") st_serial = panda_list[0] print("Using panda with serial %s" % st_serial) if path is None: print( "Fetching latest firmware from github.com/commaai/panda-artifacts") r = requests.get( "https://raw.githubusercontent.com/commaai/panda-artifacts/master/latest.json" ) url = json.loads(r.text)['url'] r = requests.get(url) print("Fetching firmware from %s" % url) path = io.BytesIO(r.content) zf = ZipFile(path) zf.printdir() version = zf.read("version").decode() status("0. Preparing to flash " + str(version)) code_bootstub = zf.read("bootstub.panda.bin") code_panda = zf.read("panda.bin") # enter DFU mode status("1. Entering DFU mode") panda = Panda(st_serial) panda.reset(enter_bootstub=True) panda.reset(enter_bootloader=True) time.sleep(1) # program bootstub status("2. Programming bootstub") dfu = PandaDFU(PandaDFU.st_serial_to_dfu_serial(st_serial)) dfu.program_bootstub(code_bootstub) time.sleep(1) # flash main code status("3. Flashing main code") panda = Panda(st_serial) panda.flash(code=code_panda) panda.close() # check for connection status("4. Verifying version") panda = Panda(st_serial) my_version = panda.get_version() print("dongle id: %s" % panda.get_serial()[0]) print(my_version, "should be", version) assert (str(version) == str(my_version)) # done! status("6. Success!")
def connect_wifi(): p = Panda() dongle_id, pw = p.get_serial() assert (dongle_id.isalnum()) _connect_wifi(dongle_id, pw)