Example #1
0
def connectToDevice(device: dai.DeviceInfo) -> dai.DeviceBootloader:
    try:
        bl = dai.DeviceBootloader(device, False)
        return bl
    except Exception as ex:
        PrintException()
        sg.Popup(f'{ex}')
Example #2
0
def flash_bootloader():
    (f, bl) = dai.DeviceBootloader.getFirstAvailableDevice()
    bootloader = dai.DeviceBootloader(bl)
    print(bootloader.getVersion())

    progress = lambda p: print(f'Flashing progress: {p*100:.1f}%')
    bootloader.flashBootloader(progress)
Example #3
0
def flashFromUsb(device: dai.DeviceInfo):
    try:
        bl = dai.DeviceBootloader(device, True)
        bl.bootUsbRomBootloader()
    except Exception as ex:
        PrintException()
        sg.Popup(f'{ex}')
Example #4
0
def factoryReset(device: dai.DeviceInfo):
    sel = SelectBootloader(['USB', 'NETWORK'],
                           "Select bootloader type used for factory reset.")
    ok, type = sel.wait()
    if not ok:
        print("Factory reset canceled.")
        return

    try:
        blBinary = dai.DeviceBootloader.getEmbeddedBootloaderBinary(type)
        # Clear 1 MiB for USB BL and 8 MiB for NETWORK BL
        mib = 1 if type == dai.DeviceBootloader.Type.USB else 8
        blBinary = blBinary + ([0xFF] *
                               ((mib * 1024 * 1024 + 512) - len(blBinary)))
        bl = dai.DeviceBootloader(device, True)
        tmpBlFw = tempfile.NamedTemporaryFile(delete=False)
        tmpBlFw.write(bytes(blBinary))

        pr = Progress()
        progress = lambda p: pr.update(p)
        success, msg = bl.flashBootloader(progress, tmpBlFw.name)
        msg = "Factory reset was successful." if success else f"Factory reset failed. Error: {msg}"
        pr.finish(msg)
        tmpBlFw.close()
    except Exception as ex:
        PrintException()
        sg.Popup(f'{ex}')
Example #5
0
def flashFromFile(file, device: dai.DeviceInfo):
    try:
        bl = dai.DeviceBootloader(device, True)
        if str(file)[-3:] == "dap":
            bl.flashDepthaiApplicationPackage(file)
        else:
            sg.Popup("Selected file is not .dap!")
    except Exception as ex:
        PrintException()
        sg.Popup(f'{ex}')
Example #6
0
def flash_image():
    pipeline = create_spi_demo_pipeline()

    (found, bl) = dai.DeviceBootloader.getFirstAvailableDevice()

    if (found):
        bootloader = dai.DeviceBootloader(bl)
        progress = lambda p: print(f'Flashing progress: {p*100:.1f}%')
        bootloader.flash(progress, pipeline)
    else:
        print("No booted (bootloader) devices found...")
Example #7
0
def flashConfig(values, device: dai.DeviceInfo, devType: str, staticIp: bool):
    try:
        bl = dai.DeviceBootloader(device, True)
        conf = dai.DeviceBootloader.Config()
        if devType == "POE":
            if staticIp:
                if check_ip(values['ip']) and check_ip(
                        values['mask']) and check_ip(values['gateway']):
                    conf.setStaticIPv4(values['ip'], values['mask'],
                                       values['gateway'])
            else:
                if check_ip(values['ip']) and check_ip(
                        values['mask']) and check_ip(values['gateway']):
                    conf.setDynamicIPv4(values['ip'], values['mask'],
                                        values['gateway'])
            if values['dns'] != "" and values['dnsAlt'] != "":
                conf.setDnsIPv4(values['dns'], values['dnsAlt'])
            if values['networkTimeout'] != "":
                if int(values['networkTimeout']) >= 0:
                    conf.setNetworkTimeout(
                        timedelta(seconds=int(values['networkTimeout']) /
                                  1000))
                else:
                    sg.Popup("Values can not be negative!")
            if values['mac'] != "":
                if check_mac(values['mac']):
                    conf.setMacAddress(values['mac'])
        else:
            if values['usbTimeout'] != "":
                if int(values['usbTimeout']) >= 0:
                    conf.setUsbTimeout(
                        timedelta(seconds=int(values['usbTimeout']) / 1000))
                else:
                    sg.Popup("Values can not be negative!")
            if values['usbSpeed'] != "":
                conf.setUsbMaxSpeed(getattr(dai.UsbSpeed, values['usbSpeed']))

        success, error = bl.flashConfig(conf)
        if not success:
            sg.Popup(f"Flashing failed: {error}")
        else:
            sg.Popup("Flashing successful.")
    except Exception as ex:
        PrintException()
        sg.Popup(f'{ex}')
Example #8
0
def flashBootloader(window, device: dai.DeviceInfo):
    # FIXME - to flash bootloader, boot the same device again (from saved device info) but with allowFlashingBootloader = True
    try:
        sel = SelectBootloader(['AUTO', 'USB', 'NETWORK'],
                               "Select bootloader type to flash.")
        ok, type = sel.wait()
        if not ok:
            print("Flashing bootloader canceled.")
            return

        bl = dai.DeviceBootloader(device, True)

        pr = Progress()
        progress = lambda p: pr.update(p)
        bl.flashBootloader(memory=dai.DeviceBootloader.Memory.FLASH,
                           type=type,
                           progressCallback=progress)
        window.Element('currBoot').update(bl.getVersion())
        pr.finish("Flashed newest bootloader version.")
    except Exception as ex:
        PrintException()
        sg.Popup(f'{ex}')
Example #9
0
    exit(-1)

hasBootloader = (info.state == dai.XLinkDeviceState.X_LINK_BOOTLOADER)
if hasBootloader:
    print(
        "Warning! Flashing bootloader can potentially soft brick your device and should be done with caution."
    )
    print("Do not unplug your device while the bootloader is flashing.")
    print("Type 'y' and press enter to proceed, otherwise exits: ")
    if input() != 'y':
        print("Prompt declined, exiting...")
        exit(-1)

# Open DeviceBootloader and allow flashing bootloader
print(f"Booting latest bootloader first, will take a tad longer...")
with dai.DeviceBootloader(info, allowFlashingBootloader=True) as bl:
    currentBlType = bl.getType()

    if blType == dai.DeviceBootloader.Type.AUTO:
        blType = currentBlType

    # Check if bootloader type is the same, if already booted by bootloader (not in USB recovery mode)
    if currentBlType != blType and hasBootloader:
        print(
            f"Are you sure you want to flash '{blType.name}' bootloader over current '{currentBlType.name}' bootloader?"
        )
        print(f"Type 'y' and press enter to proceed, otherwise exits: ")
        if input() != 'y':
            print("Prompt declined, exiting...")
            exit(-1)
    else:
        usage = True
else:
    usage = True

if usage:
    print(
        f'Usage: {sys.argv[0]} [read/flash/clear] [flash: path/to/config/json]'
    )
    exit(-1)

(res, info) = dai.DeviceBootloader.getFirstAvailableDevice()

if res:
    print(f'Found device with name: {info.desc.name}')
    with dai.DeviceBootloader(info) as bl:
        if read:
            print('Current flashed configuration')
            print(json.dumps(bl.readConfigData()))
        else:
            success = None
            error = None
            if clear:
                (success, error) = bl.flashConfigClear()
            else:
                if path == '':
                    (success,
                     error) = bl.flashConfig(dai.DeviceBootloader.Config())
                else:
                    (success, error) = bl.flashConfigFile(path)
            if success:
#!/usr/bin/env python3

import depthai as dai

(res, info) = dai.DeviceBootloader.getFirstAvailableDevice()

if res == True:
    print(f'Found device with name: {info.desc.name}')
    bl = dai.DeviceBootloader(info)
    print(f'Version: {bl.getVersion()}')
else:
    print('No devices found')