探测 USB 设备,例如 CAN 总线

探测 USB 设备,例如 CAN 总线

我有一个 USB 设备,可能是 CAN 总线,我正在尝试与它交互。我想知道是否有人可以提供一些建议来探测和发现可用的服务。我想一个好的开始是检查它是否真的是 CAN 总线。不过,我不确定如何做到这一点。

具体来说,我插入了 DJI Phantom 四轴飞行器的 USB 接口。这是一架小型自主无人机。

以下是我目前所掌握的信息:

如果我打电话的lsusb时候无人机插上电源并通电,

Bus 003 Device 003: ID fff0:0008

是新的。 lsusb -vvv提供进一步的详细信息:

Bus 003 Device 003: ID fff0:0008
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            2 Communications
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0xfff0
  idProduct          0x0008
  bcdDevice            1.00
  iManufacturer           1 DJI  CONFIF
  iProduct                2 DJI    CONTROLLER
  iSerial                 3 0001A0000000
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           75
    bNumInterfaces          2
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              100mA
    Interface Association:
      bLength                 8
      bDescriptorType        11
      bFirstInterface         0
      bInterfaceCount         2
      bFunctionClass          2 Communications
      bFunctionSubClass       2 Abstract (modem)
      bFunctionProtocol       0 None
      iFunction               4 VCOM
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         2 Communications
      bInterfaceSubClass      2 Abstract (modem)
      bInterfaceProtocol      0 None
      iInterface              4 VCOM
      CDC Header:
        bcdCDC               1.10
      CDC Call Management:
        bmCapabilities       0x01
          call management
        bDataInterface          1
      CDC ACM:
        bmCapabilities       0x02
          line coding and serial state
      CDC Union:
        bMasterInterface        0
        bSlaveInterface         1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0010  1x 16 bytes
        bInterval               2
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass        10 CDC Data
      bInterfaceSubClass      0 Unused
      bInterfaceProtocol      0
      iInterface              4 VCOM
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
Device Status:     0x0000
  (Bus Powered)

如果我打电话udevadm并移除四轴飞行器的 USB 电缆,我会得到:

UDEV  [41256.502177] remove   /devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2:1.0/tty/ttyACM0 (tty)
UDEV  [41256.502247] remove   /devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2:1.1 (usb)
UDEV  [41256.502286] remove   /devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2:1.0 (usb)
UDEV  [41256.502346] remove   /devices/pci0000:00/0000:00:14.0/usb3/3-2 (usb)`

and when I plug it in...

`UDEV  [41261.068689] add      /devices/pci0000:00/0000:00:14.0/usb3/3-2 (usb)
UDEV  [41261.070265] add      /devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2:1.0 (usb)
UDEV  [41261.071507] add      /devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2:1.1 (usb)
UDEV  [41261.072843] add      /devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2:1.0/tty/ttyACM0 (tty)

所以我尝试将其视为 CAN 总线接口。使用以下命令似乎没问题:

sudo slcand -o -s6 -t hw -S 1000000 /dev/ttyACM0

即没有错误消息,并且

sudo ip link set up slcan0

创建网络接口slcan0ifconfig显示:

slcan0    Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
          UP RUNNING NOARP  MTU:16  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:10
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

从这里,有人能判断出我所交互的是否真的是 CAN 总线吗?还是我走错了路?

相关内容