Beispiel #1
0
def get_device_info(address: str) -> usb_config.UsbInfo:
    """Gets the usb info of a specific device.

  Args:
      address: Serial path or adb serial.

  Returns:
      UsbInfo instance encoding information for that specific address.
  """
    address_to_info_dict = get_address_to_usb_info_dict()
    if address in address_to_info_dict:
        return address_to_info_dict[address]

    return usb_config.UsbInfo()
Beispiel #2
0
def _create_device_entry(
        device_dict: _DeviceDictType,
        port_mapping: Optional[Dict[str, int]] = None,
        parent_device_dict: Optional[_DeviceDictType] = None) -> _UsbInfoDict:
    """Creates a standard usb_info entry for a device.

  Args:
   device_dict: device info from system profiler.
   port_mapping: map of port identifiers to port numbers.
   parent_device_dict: dictionary of parent hub (Cambrionix).

  Returns:
    dict: UsbInfo dictionary entries stored by address as the key.
  """
    return_dict = {}
    usb_entry = usb_config.UsbInfo()
    usb_entry.serial_number = device_dict['serial_num']
    usb_entry.manufacturer = device_dict.get('manufacturer',
                                             '')  # can be empty
    usb_entry.product_id = _get_product_id(device_dict)
    usb_entry.vendor_id = _get_vendor_id(device_dict)
    # Product names are reported inconsistently between gLinuxes and Macs; either
    # undescores or spaces are used. Convert all underscores to spaces as a
    # workaround.
    usb_entry.product_name = device_dict['_name'].replace('_', ' ')
    usb_entry.usb_hub_port = _get_port_number(device_dict, port_mapping,
                                              parent_device_dict)
    address = _get_entry_address(usb_entry.serial_number)
    if 'Media' in device_dict:  # mounted device

        if 'volumes' in device_dict['Media'][0]:
            volume = device_dict['Media'][0]['volumes'][0]
            address = '/dev/' + volume['bsd_name']
            usb_entry.disk = address
    if usb_entry.product_name in usb_config.ANDROID_NAMES:
        usb_entry.address = usb_entry.serial_number  # android serial
        return_dict[usb_entry.address] = usb_entry
    else:
        usb_entry.address = address
        if os.path.exists(usb_entry.address):
            return_dict[usb_entry.address] = usb_entry
    return return_dict
Beispiel #3
0
def _process_udev_device(udev_device):
  """Convert pyudev dict to the system agnostic form."""
  model = None
  dev_path = udev_device.get('DEVPATH', '')

  entry = usb_config.UsbInfo()
  address = _get_address(udev_device)
  if not address:
    return '', {}, None, None
  entry.address = address
  entry.product_id = udev_device.get('ID_MODEL_ID', '')
  entry.vendor_id = udev_device.get('ID_VENDOR_ID', '')
  entry.ftdi_interface = int(udev_device.get('ID_USB_INTERFACE_NUM', 0))
  entry.manufacturer = udev_device.get('ID_VENDOR', '')
  entry.serial_number = udev_device.get('ID_SERIAL_SHORT', '')
  entry.product_name = _get_product_name(udev_device)
  if entry.product_name in usb_config.CAMBRIONIX_NAMES:
    entry.child_addresses = _get_child_addresses(udev_device)
    model = _get_cambrionix_model(udev_device)
  return address, entry, dev_path, model
Beispiel #4
0
_CAMBRIONIX_USB3_ADDRESS = "/dev/serial/by-id/usb-cambrionix_PS15-USB3_0000007567CE143A-if01"
_J_LINK_ADDRESS = "/dev/serial/by-id/usb-SEGGER_J-Link_000050130117-if00"
_M5STACK_ADDRESS = (
    "/dev/serial/by-id/"
    "usb-Silicon_Labs_CP2104_USB_to_UART_Bridge_Controller_01EDB69B-if00-port0"
)
_DOCKER_ID = "123abcdefghij"
_PTY_PROCESS_DIRECTORY = "/home/someuser/gazoo/gdm/pty_proc/some_device_dir"
_BAUDRATE = 115200
_USB_SERIAL_NUMBER = "123789"

_MOCK_USB_MAP = {
    _CAMBRIONIX_ADDRESS:
    usb_config.UsbInfo(product_name="FT230X Basic UART",
                       ftdi_interface=0,
                       serial_number="DJ00JMN0",
                       product_id="6015",
                       address=_CAMBRIONIX_ADDRESS),
    _CAMBRIONIX_USB3_ADDRESS:
    usb_config.UsbInfo(product_name="PS15-USB3",
                       ftdi_interface=1,
                       serial_number="7567CE353A",
                       product_id="0021",
                       address=_CAMBRIONIX_USB3_ADDRESS),
    "/dev/serial/by-id/usb-FTDI_FT230X_Basic_UART_DJ00JMN0-if02-port0":
    usb_config.UsbInfo(
        product_name="FT230X Basic UART",
        ftdi_interface=2,
        serial_number="DJ00JMN0",
        product_id="6015",
        address=
Beispiel #5
0
CHILD_DEVICE_SYMLINK_0 = (
    "/dev/serial/by-id/usb-FTDI_ChildDevice_1234567-if00-port0")
CHILD_DEVICE_USB_SYMLINK = (
    "/dev/serial/by-id/usb-SomeCompany_Some_Child_Device_1234567890-if01")
LINUX_REAL_PATH = u"/dev/ttyUSB3"
MAC_PATH = "/dev/tty.usbserial-DJ00JMN0"
USB_INFO_DICT_LINUX = {
    CAMBRIONIX_SYMLINK:
        usb_config.UsbInfo(
            vendor_id="0403",
            ftdi_interface=0,
            product_name="FT230X Basic UART",
            manufacturer="FTDI",
            disk=LINUX_REAL_PATH,
            product_id="6015",
            serial_number="DJ00JMN0",
            address=CAMBRIONIX_SYMLINK,
            child_addresses=[
                CHILD_DEVICE_SYMLINK_0,
                CHILD_DEVICE_SYMLINK_3,
                CHILD_DEVICE_USB_SYMLINK,
                "360av3",
            ]),
    CHILD_DEVICE_SYMLINK_3:
        usb_config.UsbInfo(
            vendor_id="0403",
            ftdi_interface=3,
            product_name="ChildDevice",
            manufacturer="FTDI",
            disk=LINUX_REAL_PATH,
            product_id="1234",