示例#1
0
def reset_dev(port=None,
              disk=None,
              reset_type='default',
              reset_timeout=1,
              serial_port=None,
              baudrate=115200,
              timeout=1,
              verbose=False):
    """! Reset device using pythonic interface
    @param port Switch -p <port>
    @param disk Switch -d <disk>
    @param reset_type Switch -r <reset_type>
    @param reset_timeout Switch -R <reset_timeout>
    @param serial_port Serial port handler, set to None if you want this function to open serial

    @param baudrate Serial port baudrate
    @param timeout Serial port timeout
    @param verbose Verbose mode
    """

    result = False
    if not serial_port:
        try:
            with Serial(port, baudrate=baudrate,
                        timeout=timeout) as serial_port:
                result = host_tests_plugins.call_plugin('ResetMethod',
                                                        reset_type,
                                                        serial=serial_port,
                                                        disk=disk)
            sleep(reset_timeout)
        except SerialException as e:
            if verbose:
                print "%s" % (str(e))
            result = False
    return result
示例#2
0
def reset_dev(port=None,
              disk=None,
              reset_type='default',
              reset_timeout=1,
              serial_port=None,
              baudrate=115200,
              timeout=1,
              verbose=False):
    """! Reset device using pythonic interface
    @param port Switch -p <port>
    @param disk Switch -d <disk>
    @param reset_type Switch -r <reset_type>
    @param reset_timeout Switch -R <reset_timeout>
    @param serial_port Serial port handler, set to None if you want this function to open serial

    @param baudrate Serial port baudrate
    @param timeout Serial port timeout
    @param verbose Verbose mode
    """

    result = False
    if not serial_port:
        try:
            with Serial(port, baudrate=baudrate, timeout=timeout) as serial_port:
                result = host_tests_plugins.call_plugin('ResetMethod',
                                                        reset_type,
                                                        serial=serial_port,
                                                        disk=disk)
            sleep(reset_timeout)
        except SerialException as e:
            if verbose:
                print "%s" % (str(e))
            result = False
    return result
示例#3
0
    def copy_image_raw(self,
                       image_path=None,
                       disk=None,
                       copy_method=None,
                       port=None):
        """! Copy file depending on method you want to use. Handles exception
             and return code from shell copy commands.
        @return Returns result from copy plugin
        @details Method which is actually copying image to mbed
        """
        # image_path - Where is binary with target's firmware

        # Select copy_method
        # We override 'default' method with 'shell' method
        copy_method = {
            None: 'shell',
            'default': 'shell',
        }.get(copy_method, copy_method)

        result = ht_plugins.call_plugin('CopyMethod',
                                        copy_method,
                                        image_path=image_path,
                                        serial=port,
                                        destination_disk=disk,
                                        target_id=self.target_id,
                                        pooling_timeout=self.polling_timeout)
        return result
示例#4
0
    def reset(self):
        """! Calls proper reset plugin to do the job.

        @return Returns result from reset plugin

        @details Please refer to host_test_plugins functionality
        """
        # Flush serials to get only input after reset
        self.flush()
        if self.options.forced_reset_type:
            result = ht_plugins.call_plugin('ResetMethod', self.options.forced_reset_type, disk=self.disk)
        else:
            result = ht_plugins.call_plugin('ResetMethod', 'default', serial=self.serial)
        # Give time to wait for the image loading
        reset_tout_s = self.options.forced_reset_timeout if self.options.forced_reset_timeout is not None else self.DEFAULT_RESET_TOUT
        self.reset_timeout(reset_tout_s)
        return result
示例#5
0
    def hw_reset(self):
        """
        Performs hardware reset of target ned device.

        :return:
        """
        device_info = {}
        result = ht_plugins.call_plugin('ResetMethod',
                                        'power_cycle',
                                        target_id=self.target_id,
                                        device_info=device_info)
        if result:
            self.port = device_info['serial_port']
            self.disk = device_info['mount_point']
        return result
示例#6
0
    def hw_reset(self):
        """
        Performs hardware reset of target ned device.

        :return:
        """
        device_info = {}
        result = ht_plugins.call_plugin('ResetMethod',
                                        'power_cycle',
                                        target_id=self.target_id,
                                        device_info=device_info)
        if result:
            self.port = device_info['serial_port']
            self.disk = device_info['mount_point']
        return result
示例#7
0
    def reset_dev_via_serial(self, delay=1):
        """! Reset device using selected method, calls one of the reset plugins """
        reset_type = self.config.get('reset_type', 'default')
        if not reset_type:
            reset_type = 'default'
        disk = self.config.get('disk', None)

        self.logger.prn_inf("reset device using '%s' plugin..."% reset_type)
        result = host_tests_plugins.call_plugin('ResetMethod',
            reset_type,
            serial=self.serial,
            disk=disk)
        # Post-reset sleep
        self.logger.prn_inf("wait for it...")
        sleep(delay)
        return result
示例#8
0
    def copy_image_raw(self, image_path=None, disk=None, copy_method=None):
        """! Copy file depending on method you want to use. Handles exception
            and return code from shell copy commands.

        @return Returns result from copy plugin

        @details Method which is actually copying image to mbed
        """
        # image_path - Where is binary with target's firmware
        if copy_method is not None:
            # We override 'default' method with 'shell' method
            if copy_method == 'default':
                copy_method = 'shell'
        else:
            copy_method = 'shell'
        result = ht_plugins.call_plugin('CopyMethod', copy_method, image_path=image_path, destination_disk=disk)
        return result;
示例#9
0
    def reset_dev_via_serial(self, delay=1):
        """! Reset device using selected method, calls one of the reset plugins """
        reset_type = self.config.get("reset_type", "default")
        if not reset_type:
            reset_type = "default"
        disk = self.config.get("disk", None)

        self.logger.prn_inf("reset device using '%s' plugin..." % reset_type)
        result = host_tests_plugins.call_plugin(
            "ResetMethod", reset_type, serial=self.serial, disk=disk, target_id=self.target_id
        )
        # Post-reset sleep
        if delay:
            self.logger.prn_inf("waiting %.2f sec after reset" % delay)
            sleep(delay)
        self.logger.prn_inf("wait for it...")
        return result
示例#10
0
    def reset_dev_via_serial(self, delay=1):
        """! Reset device using selected method, calls one of the reset plugins """
        reset_type = self.config.get('reset_type', 'default')
        if not reset_type:
            reset_type = 'default'
        disk = self.config.get('disk', None)

        self.logger.prn_inf("reset device using '%s' plugin..." % reset_type)
        result = host_tests_plugins.call_plugin('ResetMethod',
                                                reset_type,
                                                serial=self.serial,
                                                disk=disk,
                                                target_id=self.target_id)
        # Post-reset sleep
        if delay:
            self.logger.prn_inf("waiting %.2f sec after reset" % delay)
            sleep(delay)
        self.logger.prn_inf("wait for it...")
        return result
示例#11
0
    def reset(self):
        """! Calls proper reset plugin to do the job.

        @return Returns result from reset plugin

        @details Please refer to host_test_plugins functionality
        """
        # Flush serials to get only input after reset
        self.flush()
        if self.options.forced_reset_type:
            reset_method = self.options.forced_reset_type
        else:
            reset_method = 'default'
        result = ht_plugins.call_plugin('ResetMethod', reset_method,
                                        serial=self.serial, disk=self.disk,
                                        image_path=self.image_path)
        # Give time to wait for the image loading
        reset_tout_s = self.options.forced_reset_timeout if self.options.forced_reset_timeout is not None else self.DEFAULT_RESET_TOUT
        self.reset_timeout(reset_tout_s)
        return result
示例#12
0
def flash_dev(disk=None,
              image_path=None,
              copy_method='default',
              port=None,
              program_cycle_s=4):
    """! Flash device using pythonic interface
    @param disk Switch -d <disk>
    @param image_path Switch -f <image_path>
    @param copy_method Switch -c <copy_method> (default: shell)
    @param port Switch -p <port>
    """
    if copy_method == 'default':
        copy_method = 'shell'
    result = False
    result = host_tests_plugins.call_plugin('CopyMethod',
                                            copy_method,
                                            image_path=image_path,
                                            serial=port,
                                            destination_disk=disk)
    sleep(program_cycle_s)
    return result
示例#13
0
    def copy_image_raw(self, image_path=None, disk=None, copy_method=None, port=None):
        """! Copy file depending on method you want to use. Handles exception
            and return code from shell copy commands.

        @return Returns result from copy plugin

        @details Method which is actually copying image to mbed
        """
        # image_path - Where is binary with target's firmware
        if copy_method is not None:
            # We override 'default' method with 'shell' method
            if copy_method == 'default':
                copy_method = 'shell'
        else:
            copy_method = 'shell'
        result = ht_plugins.call_plugin('CopyMethod',
                                        copy_method,
                                        image_path=image_path,
                                        serial=port,
                                        destination_disk=disk)
        return result;
示例#14
0
def flash_dev(disk=None,
              image_path=None,
              copy_method='default',
              port=None,
              program_cycle_s=4):
    """! Flash device using pythonic interface
    @param disk Switch -d <disk>
    @param image_path Switch -f <image_path>
    @param copy_method Switch -c <copy_method> (default: shell)
    @param port Switch -p <port>
    """
    if copy_method == 'default':
        copy_method = 'shell'
    result = False
    result = host_tests_plugins.call_plugin('CopyMethod',
                                            copy_method,
                                            image_path=image_path,
                                            serial=port,
                                            destination_disk=disk)
    sleep(program_cycle_s)
    return result
示例#15
0
    def copy_image_raw(self, image_path=None, disk=None, copy_method=None, port=None):
        """! Copy file depending on method you want to use. Handles exception
             and return code from shell copy commands.
        @return Returns result from copy plugin
        @details Method which is actually copying image to mbed
        """
        # image_path - Where is binary with target's firmware

        # Select copy_method
        # We override 'default' method with 'shell' method
        copy_method = {
            None : 'shell',
            'default' : 'shell',
        }.get(copy_method, copy_method)

        result = ht_plugins.call_plugin('CopyMethod',
                                        copy_method,
                                        image_path=image_path,
                                        serial=port,
                                        destination_disk=disk,
                                        target_id=self.target_id,
                                        pooling_timeout=self.pooling_timeout)
        return result
示例#16
0
def handle_send_break_cmd(port,
                          disk,
                          reset_type=None,
                          baudrate=115200,
                          timeout=1,
                          verbose=False):
    """! Resets platforms and prints serial port output
        @detail Mix with switch -r RESET_TYPE and -p PORT for versatility
    """
    if not reset_type:
        reset_type = 'default'

    port_config = port.split(':')
    if len(port_config) == 2:
        # -p COM4:115200
        port = port_config[0]
        baudrate = int(port_config[1])
    elif len(port_config) == 3:
        # -p COM4:115200:0.5
        port = port_config[0]
        baudrate = int(port_config[1])
        timeout = float(port_config[2])

    if verbose:
        print "mbedhtrun: serial port configuration: %s:%s:%s" % (
            port, str(baudrate), str(timeout))

    try:
        serial_port = Serial(port, baudrate=baudrate, timeout=timeout)
    except Exception as e:
        print "mbedhtrun: %s" % (str(e))
        print json.dumps(
            {
                "port": port,
                "disk": disk,
                "baudrate": baudrate,
                "timeout": timeout,
                "reset_type": reset_type,
            },
            indent=4)
        return False

    serial_port.flush()
    # Reset using one of the plugins
    result = host_tests_plugins.call_plugin('ResetMethod',
                                            reset_type,
                                            serial=serial_port,
                                            disk=disk)
    if not result:
        print "mbedhtrun: reset plugin failed"
        print json.dumps(
            {
                "port": port,
                "disk": disk,
                "baudrate": baudrate,
                "timeout": timeout,
                "reset_type": reset_type
            },
            indent=4)
        return False

    print "mbedhtrun: serial dump started (use ctrl+c to break)"
    try:
        while True:
            test_output = serial_port.read(512)
            if test_output:
                sys.stdout.write('%s' % test_output)
            if "{end}" in test_output:
                if verbose:
                    print
                    print "mbedhtrun: stopped (found '{end}' terminator)"
                break
    except KeyboardInterrupt:
        print "ctrl+c break"

    serial_port.close()
    return True
示例#17
0
def handle_send_break_cmd(port, 
                          disk, 
                          reset_type=None, 
                          baudrate=115200, 
                          timeout=1, 
                          verbose=False):
    """! Resets platforms and prints serial port output
        @detail Mix with switch -r RESET_TYPE and -p PORT for versatility
    """
    if not reset_type:
        reset_type = 'default'

    port_config = port.split(':')
    if len(port_config) == 2:
        # -p COM4:115200
        port = port_config[0]
        baudrate = int(port_config[1])
    elif len(port_config) == 3:
        # -p COM4:115200:0.5
        port = port_config[0]
        baudrate = int(port_config[1])
        timeout = float(port_config[2])

    if verbose:
        print "mbedhtrun: serial port configuration: %s:%s:%s"% (port, str(baudrate), str(timeout))

    try:
        serial_port = Serial(port, baudrate=baudrate, timeout=timeout)
    except Exception as e:
        print "mbedhtrun: %s" % (str(e))
        print json.dumps({
            "port" : port,
            "disk" : disk,
            "baudrate" : baudrate,
            "timeout" : timeout,
            "reset_type" : reset_type,
            }, indent=4)
        return False

    serial_port.flush()
    # Reset using one of the plugins
    result = host_tests_plugins.call_plugin('ResetMethod', reset_type, serial=serial_port, disk=disk)
    if not result:
        print "mbedhtrun: reset plugin failed"
        print json.dumps({
            "port" : port,
            "disk" : disk,
            "baudrate" : baudrate,
            "timeout" : timeout,
            "reset_type" : reset_type
            }, indent=4)
        return False

    print "mbedhtrun: serial dump started (use ctrl+c to break)"
    try:
        while True:
            test_output = serial_port.read(512)
            if test_output:
                sys.stdout.write('%s'% test_output)
            if "{end}" in test_output:
                if verbose:
                    print
                    print "mbedhtrun: stopped (found '{end}' terminator)"
                break
    except KeyboardInterrupt:
        print "ctrl+c break"

    serial_port.close()
    return True