Ejemplo n.º 1
0
def program_image_serial(context, nrfjprog, full_image_path, snr):
    lister = DeviceLister()

    return_code = subprocess.call(
        "\"{nrfjprog}\" --eraseall --snr {snr}".format(nrfjprog=nrfjprog,
                                                       snr=snr),
        shell=True)

    assert return_code == 0, "Nrfjprog could not erase board with serial number {}".format(
        snr)

    return_code = subprocess.call(
        "\"{nrfjprog}\" --program {image} --chiperase -r  --snr {snr}".format(
            nrfjprog=nrfjprog, image=full_image_path, snr=snr),
        shell=True)

    assert return_code == 0, \
    "Nrfjprog could program image {} to board with serial number {}".format(full_image_path, snr)

    time.sleep(ENUMERATE_WAIT_TIME)  # Waiting for device to enumerate

    snr_left_pad = snr
    if (len(snr_left_pad)) < 12:
        snr_left_pad = '0' * (12 - len(snr_left_pad)) + snr_left_pad

    device = lister.get_device(get_all=False, serial_number=snr_left_pad)
    devices = lister.enumerate()

    assert device, "Device was programmed, but did not enumerate in {} seconds.".format(
        ENUMERATE_WAIT_TIME)

    port = device.get_first_available_com_port()
    return port
Ejemplo n.º 2
0
def program_image_serial(context, nrfjprog, full_image_path, snr):
    lister = DeviceLister()

    return_code = subprocess.call("\"{nrfjprog}\" --eraseall --snr {snr}"
    .format(nrfjprog=nrfjprog,snr=snr), shell=True)

    assert return_code == 0, "Nrfjprog could not erase board with serial number {}".format(snr)

    return_code = subprocess.call("\"{nrfjprog}\" --program {image} --chiperase -r  --snr {snr}"
    .format(nrfjprog=nrfjprog, image=full_image_path, snr=snr), shell=True)

    assert return_code == 0, \
    "Nrfjprog could program image {} to board with serial number {}".format(full_image_path, snr)

    time.sleep(ENUMERATE_WAIT_TIME) # Waiting for device to enumerate

    snr_left_pad = snr
    if (len(snr_left_pad)) < 12:
        snr_left_pad = '0'*(12-len(snr_left_pad)) + snr_left_pad

    device = lister.get_device(get_all=False, serial_number=snr_left_pad)
    devices = lister.enumerate()

    assert device, "Device was programmed, but did not enumerate in {} seconds.".format(ENUMERATE_WAIT_TIME)

    port = device.get_first_available_com_port()
    return port
Ejemplo n.º 3
0
def program_image_usb_serial(context, nrfjprog, full_image_path, snr):
    lister = DeviceLister()

    return_code = subprocess.call("\"{nrfjprog}\" --eraseall --snr {snr}" .format(nrfjprog=nrfjprog,snr=snr), shell=True)
    assert return_code == 0, "Nrfjprog could not erase board with serial number {}".format(snr)
    time.sleep(ENUMERATE_WAIT_TIME) # Waiting for device to enumerate

    devices_before_programming = lister.get_device(get_all=True, vendor_id="1915", product_id="521F")

    return_code = subprocess.call("\"{nrfjprog}\" --program {image} --chiperase -r  --snr {snr}"
    .format(nrfjprog=nrfjprog, image=full_image_path, snr=snr), shell=True)

    assert return_code == 0, \
    "Nrfjprog could program image {} to board with serial number {}".format(full_image_path, snr)

    time.sleep(ENUMERATE_WAIT_TIME) # Waiting for device to enumerate

    devices_after_programming = lister.get_device(get_all=True, vendor_id="1915", product_id="521F")

    dfu_device = None

    for device in devices_after_programming:
        match = False
        for device_old in devices_before_programming:
            if device.serial_number == device_old.serial_number:
                match = True
                break
        if not match:
            dfu_device = device
            break

    assert dfu_device, "Device was programmed, but did not enumerate in {} seconds.".format(ENUMERATE_WAIT_TIME)

    port = dfu_device.get_first_available_com_port()
    return port
Ejemplo n.º 4
0
    def __ensure_bootloader(self):
        lister = DeviceLister()
        device = lister.get_device(com=self.com_port)
        if device:
            device_serial_number = device.serial_number

            if not self.__is_device_in_bootloader_mode(device):
                retry_count = 10
                wait_time_ms = 500

                trigger = DFUTrigger()
                try:
                    trigger.enter_bootloader_mode(device)
                    logger.info("Serial: DFU bootloader was triggered")
                except NordicSemiException as err:
                    logger.error(err)
                    retry_count = 0

                for checks in range(retry_count):
                    logger.info("Serial: Waiting {} ms for device to enter bootloader {}/{} time"\
                    .format(500, checks + 1, retry_count))

                    time.sleep(wait_time_ms / 1000.0)

                    device = lister.get_device(
                        serial_number=device_serial_number)
                    if self.__is_device_in_bootloader_mode(device):
                        self.com_port = device.get_first_available_com_port()
                        break

                trigger.clean()
            if not self.__is_device_in_bootloader_mode(device):
                logger.info(
                    "Serial: Device is either not in bootloader mode, or using an unsupported bootloader."
                )
Ejemplo n.º 5
0
def program_image_usb_serial(context, nrfjprog, full_image_path, snr):
    lister = DeviceLister()

    return_code = subprocess.call("\"{nrfjprog}\" --eraseall --snr {snr}" .format(nrfjprog=nrfjprog,snr=snr), shell=True)
    assert return_code == 0, "Nrfjprog could not erase board with serial number {}".format(snr)
    time.sleep(ENUMERATE_WAIT_TIME) # Waiting for device to enumerate

    devices_before_programming = lister.get_device(get_all=True, vendor_id="1915", product_id="521F")
    return_code = subprocess.call("\"{nrfjprog}\" --program {image} --chiperase -r  --snr {snr}"
    .format(nrfjprog=nrfjprog, image=full_image_path, snr=snr), shell=True)

    assert return_code == 0, \
    "Nrfjprog could program image {} to board with serial number {}".format(full_image_path, snr)

    time.sleep(ENUMERATE_WAIT_TIME) # Waiting for device to enumerate

    devices_after_programming = lister.get_device(get_all=True, vendor_id="1915", product_id="521F")
    dfu_device = None

    for device in devices_after_programming:
        match = False
        for device_old in devices_before_programming:
            if device.serial_number == device_old.serial_number:
                match = True
                break
        if not match:
            dfu_device = device
            break

    assert dfu_device, "Device was programmed, but did not enumerate in {} seconds.".format(ENUMERATE_WAIT_TIME)

    port = dfu_device.get_first_available_com_port()
    return port
Ejemplo n.º 6
0
def step_impl(context):
    lister = DeviceLister()

    devices_before_programming = lister.get_device(get_all=True,
                                                   vendor_id="1915",
                                                   product_id="521F")

    result = context.runner.invoke(cli, context.args)
    logger.debug("exit_code: %s, output: \'%s\'", result.exit_code,
                 result.output)
    assert result.exit_code == 0, "exit_code: {}, output: \'{}\'".format(
        result.exit_code, result.output)
    time.sleep(ENUMERATE_WAIT_TIME)  # Waiting for device to enumerate

    devices_after_programming = lister.get_device(get_all=True,
                                                  vendor_id="1915",
                                                  product_id="C00A")
    dfu_device = None

    for device in devices_after_programming:
        match = False
        for device_old in devices_before_programming:
            if device.serial_number == device_old.serial_number:
                dfu_device = device
                match = True
                break
        if match:
            break

    assert dfu_device, "Device was programmed, but did not enumerate in {} seconds.".format(
        ENUMERATE_WAIT_TIME)

    port = dfu_device.get_first_available_com_port()
    context.args[-1] = port
    result = context.runner.invoke(cli, context.args)
    logger.debug("exit_code: %s, output: \'%s\'", result.exit_code,
                 result.output)
    assert result.exit_code == 0, "exit_code: {}, output: \'{}\'".format(
        result.exit_code, result.output)
    time.sleep(ENUMERATE_WAIT_TIME
               )  # Waiting some time to ensure enumeration before next test.
    def __ensure_bootloader(self):
        lister = DeviceLister()

        device = None
        start = datetime.now()
        while not device and datetime.now() - start < timedelta(seconds=self.timeout):
            time.sleep(0.5)
            device = lister.get_device(com=self.com_port)

        if device:
            device_serial_number = device.serial_number

            if not self.__is_device_in_bootloader_mode(device):
                retry_count = 10
                wait_time_ms = 500

                trigger = DFUTrigger()
                try:
                    trigger.enter_bootloader_mode(device)
                    logger.info("Serial: DFU bootloader was triggered")
                except NordicSemiException as err:
                    logger.error(err)


                for checks in range(retry_count):
                    logger.info("Serial: Waiting {} ms for device to enter bootloader {}/{} time"\
                    .format(500, checks + 1, retry_count))

                    time.sleep(wait_time_ms / 1000.0)

                    device = lister.get_device(serial_number=device_serial_number)
                    if self.__is_device_in_bootloader_mode(device):
                        self.com_port = device.get_first_available_com_port()
                        break

                trigger.clean()
            if not self.__is_device_in_bootloader_mode(device):
                logger.info("Serial: Device is either not in bootloader mode, or using an unsupported bootloader.")
Ejemplo n.º 8
0
import time

from click.testing import CliRunner
import click
from behave import then, given

from nordicsemi.__main__ import cli
from nordicsemi.lister.device_lister import DeviceLister
from pc_ble_driver_py import config
connectivity_root = os.path.join(os.path.dirname(config.__file__), 'hex',
                                 'sd_api_v5')

ENUMERATE_WAIT_TIME = 5.0  # Seconds to wait for enumeration to finish

all_boards = {
    'PCA10056': DeviceLister().get_device(get_all=True, vendor_id='1366'),
    'PCA10059': DeviceLister().get_device(get_all=True, vendor_id='1915')
}
boards = {}


def exe_runner(exe_name):
    @click.command(name=exe_name,
                   context_settings=dict(ignore_unknown_options=True, ))
    @click.argument('command', nargs=-1)
    def f(command):
        subprocess.run([exe_name, *command], shell=True)

    return f