Regras do Udev para dispositivos aparentemente indistinguíveis

1

Estou tentando usar o udev para configurar links simbólicos automaticamente para um Intel RealSense D415. Isso ocorre porque eu uso várias câmeras na máquina e preciso ser capaz de referenciá-las de forma confiável por meio de um nome de arquivo (isso não muda na reinicialização).

O RealSense D415 cria três dispositivos de vídeo em /dev . Não estou tendo problemas para configurar links simbólicos para os dois primeiros, mas até onde eu posso ver, o primeiro e o terceiro dispositivos são idênticos, além dos atributos KERNEL e KERNELS , que podem mudar se outra câmera estiver conectada primeiro.

Como posso usar uma regra do udev para diferenciá-los?

Saída para sudo udevadm info -ap /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/video4linux/video0 :

  looking at device '/devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/video4linux/video0':
    KERNEL=="video0"
    SUBSYSTEM=="video4linux"
    DRIVER==""
    ATTR{dev_debug}=="0"
    ATTR{index}=="0"
    ATTR{name}=="Intel(R) RealSense(TM) 415: Int"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0':
    KERNELS=="2-1:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="uvcvideo"
    ATTRS{authorized}=="1"
    ATTRS{bAlternateSetting}==" 0"
    ATTRS{bInterfaceClass}=="0e"
    ATTRS{bInterfaceNumber}=="00"
    ATTRS{bInterfaceProtocol}=="00"
    ATTRS{bInterfaceSubClass}=="01"
    ATTRS{bNumEndpoints}=="01"
    ATTRS{iad_bFirstInterface}=="00"
    ATTRS{iad_bFunctionClass}=="0e"
    ATTRS{iad_bFunctionProtocol}=="00"
    ATTRS{iad_bFunctionSubClass}=="03"
    ATTRS{iad_bInterfaceCount}=="03"
    ATTRS{interface}=="Intel(R) RealSense(TM) 415 Depth"
    ATTRS{supports_autosuspend}=="1"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb2/2-1':
    KERNELS=="2-1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{authorized}=="1"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bDeviceClass}=="ef"
    ATTRS{bDeviceProtocol}=="01"
    ATTRS{bDeviceSubClass}=="02"
    ATTRS{bMaxPacketSize0}=="9"
    ATTRS{bMaxPower}=="440mA"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bNumInterfaces}==" 5"
    ATTRS{bcdDevice}=="508f"
    ATTRS{bmAttributes}=="c0"
    ATTRS{busnum}=="2"
    ATTRS{configuration}==""
    ATTRS{devnum}=="2"
    ATTRS{devpath}=="1"
    ATTRS{idProduct}=="0ad3"
    ATTRS{idVendor}=="8086"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="Intel(R) RealSense(TM) 415"
    ATTRS{maxchild}=="0"
    ATTRS{product}=="Intel(R) RealSense(TM) 415"
    ATTRS{quirks}=="0x0"
    ATTRS{removable}=="removable"
    ATTRS{serial}=="736613021813"
    ATTRS{speed}=="5000"
    ATTRS{urbnum}=="56"
    ATTRS{version}==" 3.10"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb2':
    KERNELS=="usb2"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{authorized}=="1"
    ATTRS{authorized_default}=="1"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bDeviceClass}=="09"
    ATTRS{bDeviceProtocol}=="03"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bMaxPacketSize0}=="9"
    ATTRS{bMaxPower}=="0mA"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bcdDevice}=="0415"
    ATTRS{bmAttributes}=="e0"
    ATTRS{busnum}=="2"
    ATTRS{configuration}==""
    ATTRS{devnum}=="1"
    ATTRS{devpath}=="0"
    ATTRS{idProduct}=="0003"
    ATTRS{idVendor}=="1d6b"
    ATTRS{interface_authorized_default}=="1"
    ATTRS{ltm_capable}=="yes"
    ATTRS{manufacturer}=="Linux 4.15.0-36-generic xhci-hcd"
    ATTRS{maxchild}=="10"
    ATTRS{product}=="xHCI Host Controller"
    ATTRS{quirks}=="0x0"
    ATTRS{removable}=="unknown"
    ATTRS{serial}=="0000:00:14.0"
    ATTRS{speed}=="5000"
    ATTRS{urbnum}=="101"
    ATTRS{version}==" 3.00"

  looking at parent device '/devices/pci0000:00/0000:00:14.0':
    KERNELS=="0000:00:14.0"
    SUBSYSTEMS=="pci"
    DRIVERS=="xhci_hcd"
    ATTRS{broken_parity_status}=="0"
    ATTRS{class}=="0x0c0330"
    ATTRS{consistent_dma_mask_bits}=="64"
    ATTRS{d3cold_allowed}=="1"
    ATTRS{dbc}=="disabled"
    ATTRS{device}=="0xa2af"
    ATTRS{dma_mask_bits}=="64"
    ATTRS{driver_override}=="(null)"
    ATTRS{enable}=="1"
    ATTRS{irq}=="123"
    ATTRS{local_cpulist}=="0-3"
    ATTRS{local_cpus}=="f"
    ATTRS{msi_bus}=="1"
    ATTRS{numa_node}=="-1"
    ATTRS{revision}=="0x00"
    ATTRS{subsystem_device}=="0x310c"
    ATTRS{subsystem_vendor}=="0x17aa"
    ATTRS{vendor}=="0x8086"

  looking at parent device '/devices/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""

Saída para sudo udevadm info -ap /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.3/video4linux/video2 :

  looking at device '/devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.3/video4linux/video2':
    KERNEL=="video2"
    SUBSYSTEM=="video4linux"
    DRIVER==""
    ATTR{dev_debug}=="0"
    ATTR{index}=="0"
    ATTR{name}=="Intel(R) RealSense(TM) 415: Int"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.3':
    KERNELS=="2-1:1.3"
    SUBSYSTEMS=="usb"
    DRIVERS=="uvcvideo"
    ATTRS{authorized}=="1"
    ATTRS{bAlternateSetting}==" 0"
    ATTRS{bInterfaceClass}=="0e"
    ATTRS{bInterfaceNumber}=="03"
    ATTRS{bInterfaceProtocol}=="00"
    ATTRS{bInterfaceSubClass}=="01"
    ATTRS{bNumEndpoints}=="00"
    ATTRS{iad_bFirstInterface}=="03"
    ATTRS{iad_bFunctionClass}=="0e"
    ATTRS{iad_bFunctionProtocol}=="00"
    ATTRS{iad_bFunctionSubClass}=="03"
    ATTRS{iad_bInterfaceCount}=="02"
    ATTRS{interface}=="Intel(R) RealSense(TM) 415 RGB"
    ATTRS{supports_autosuspend}=="1"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb2/2-1':
    KERNELS=="2-1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{authorized}=="1"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bDeviceClass}=="ef"
    ATTRS{bDeviceProtocol}=="01"
    ATTRS{bDeviceSubClass}=="02"
    ATTRS{bMaxPacketSize0}=="9"
    ATTRS{bMaxPower}=="440mA"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bNumInterfaces}==" 5"
    ATTRS{bcdDevice}=="508f"
    ATTRS{bmAttributes}=="c0"
    ATTRS{busnum}=="2"
    ATTRS{configuration}==""
    ATTRS{devnum}=="2"
    ATTRS{devpath}=="1"
    ATTRS{idProduct}=="0ad3"
    ATTRS{idVendor}=="8086"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="Intel(R) RealSense(TM) 415"
    ATTRS{maxchild}=="0"
    ATTRS{product}=="Intel(R) RealSense(TM) 415"
    ATTRS{quirks}=="0x0"
    ATTRS{removable}=="removable"
    ATTRS{serial}=="736613021813"
    ATTRS{speed}=="5000"
    ATTRS{urbnum}=="56"
    ATTRS{version}==" 3.10"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb2':
    KERNELS=="usb2"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{authorized}=="1"
    ATTRS{authorized_default}=="1"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bDeviceClass}=="09"
    ATTRS{bDeviceProtocol}=="03"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bMaxPacketSize0}=="9"
    ATTRS{bMaxPower}=="0mA"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bcdDevice}=="0415"
    ATTRS{bmAttributes}=="e0"
    ATTRS{busnum}=="2"
    ATTRS{configuration}==""
    ATTRS{devnum}=="1"
    ATTRS{devpath}=="0"
    ATTRS{idProduct}=="0003"
    ATTRS{idVendor}=="1d6b"
    ATTRS{interface_authorized_default}=="1"
    ATTRS{ltm_capable}=="yes"
    ATTRS{manufacturer}=="Linux 4.15.0-36-generic xhci-hcd"
    ATTRS{maxchild}=="10"
    ATTRS{product}=="xHCI Host Controller"
    ATTRS{quirks}=="0x0"
    ATTRS{removable}=="unknown"
    ATTRS{serial}=="0000:00:14.0"
    ATTRS{speed}=="5000"
    ATTRS{urbnum}=="101"
    ATTRS{version}==" 3.00"

  looking at parent device '/devices/pci0000:00/0000:00:14.0':
    KERNELS=="0000:00:14.0"
    SUBSYSTEMS=="pci"
    DRIVERS=="xhci_hcd"
    ATTRS{broken_parity_status}=="0"
    ATTRS{class}=="0x0c0330"
    ATTRS{consistent_dma_mask_bits}=="64"
    ATTRS{d3cold_allowed}=="1"
    ATTRS{dbc}=="disabled"
    ATTRS{device}=="0xa2af"
    ATTRS{dma_mask_bits}=="64"
    ATTRS{driver_override}=="(null)"
    ATTRS{enable}=="1"
    ATTRS{irq}=="123"
    ATTRS{local_cpulist}=="0-3"
    ATTRS{local_cpus}=="f"
    ATTRS{msi_bus}=="1"
    ATTRS{numa_node}=="-1"
    ATTRS{revision}=="0x00"
    ATTRS{subsystem_device}=="0x310c"
    ATTRS{subsystem_vendor}=="0x17aa"
    ATTRS{vendor}=="0x8086"

  looking at parent device '/devices/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""
    
por Omegastick 02.11.2018 / 05:34

1 resposta

2

Parece haver um fator distintivo aqui:

ATTRS{interface}=="Intel(R) RealSense(TM) 415 Depth"

vs.

ATTRS{interface}=="Intel(R) RealSense(TM) 415 RGB"

E para diferenciar várias câmeras, você provavelmente precisará desta:

ATTRS{serial}=="736613021813"

A página udev(7) man diz:

If multiple keys that match a parent device are specified in a single rule, all these keys must match at one and the same parent device.

O atributo que torna as interfaces distinguíveis está no bloco pai e o atributo que torna as câmeras distinguíveis está no bloco de avós. Então, você terá que usar várias linhas de regra.

Para cada câmera, deve haver um grupo de regras como este:

SUBSYSTEM=="video4linux", ATTRS{serial}!="736613021813", GOTO="not_first_camera"
SUBSYSTEM=="video4linux", KERNEL=="video*", ATTRS{interface}=="Intel(R) RealSense(TM) 415 Depth", SYMLINK+="cam1_depth"
SUBSYSTEM=="video4linux", KERNEL=="video*", ATTRS{interface}=="Intel(R) RealSense(TM) 415 RGB", SYMLINK+="cam1_rgb"
LABEL="not_first_camera"

A primeira regra ignora as duas regras a seguir, se o número de série da câmera não corresponder. Dessa forma, entre a primeira regra e o LABEL associado a ela, podemos ter certeza da identidade da câmera de que estamos falando e podemos nos concentrar em diferenciar as interfaces.

Cada bloco deve ter uma instrução exclusiva LABEL= e GOTO= que corresponda ao rótulo exclusivo. Claro que você pode nomear o SYMLINK s como quiser.

    
por 02.11.2018 / 07:19

Tags