Add Path to DeviceDesc (#101)
Populates information about device port path in the device descriptor.
This commit is contained in:
21
device.go
21
device.go
@@ -24,11 +24,22 @@ import (
|
||||
|
||||
// DeviceDesc is a representation of a USB device descriptor.
|
||||
type DeviceDesc struct {
|
||||
// Bus information
|
||||
Bus int // The bus on which the device was detected
|
||||
Address int // The address of the device on the bus
|
||||
Speed Speed // The negotiated operating speed for the device
|
||||
Port int // The usb port on which the device was detected
|
||||
// The bus on which the device was detected
|
||||
Bus int
|
||||
// The address of the device on the bus
|
||||
Address int
|
||||
// The negotiated operating speed for the device
|
||||
Speed Speed
|
||||
// The pyhsical port on the parent hub on which the device is connected.
|
||||
// Ports are numbered from 1, excepting root hub devices which are always 0.
|
||||
Port int
|
||||
// Physical path of connected parent ports, starting at the root hub device.
|
||||
// A path length of 0 represents a root hub device,
|
||||
// a path length of 1 represents a device directly connected to a root hub,
|
||||
// a path length of 2 or more are connected to intermediate hub devices.
|
||||
// e.g. [1,2,3] represents a device connected to port 3 of a hub connected
|
||||
// to port 2 of a hub connected to port 1 of a root hub.
|
||||
Path []int
|
||||
|
||||
// Version information
|
||||
Spec BCD // USB Specification Release Number
|
||||
|
16
libusb.go
16
libusb.go
@@ -224,14 +224,26 @@ func (libusbImpl) setDebug(c *libusbContext, lvl int) {
|
||||
}
|
||||
|
||||
func (libusbImpl) getDeviceDesc(d *libusbDevice) (*DeviceDesc, error) {
|
||||
var desc C.struct_libusb_device_descriptor
|
||||
var (
|
||||
desc C.struct_libusb_device_descriptor
|
||||
pathData [8]uint8
|
||||
path []int
|
||||
port int
|
||||
)
|
||||
if err := fromErrNo(C.libusb_get_device_descriptor((*C.libusb_device)(d), &desc)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pathLen := int(C.libusb_get_port_numbers((*C.libusb_device)(d), (*C.uint8_t)(&pathData[0]), 8))
|
||||
for _, nPort := range pathData[:pathLen] {
|
||||
port = int(nPort)
|
||||
path = append(path, port)
|
||||
}
|
||||
// Defaults to port = 0, path = [] for root device
|
||||
dev := &DeviceDesc{
|
||||
Bus: int(C.libusb_get_bus_number((*C.libusb_device)(d))),
|
||||
Address: int(C.libusb_get_device_address((*C.libusb_device)(d))),
|
||||
Port: int(C.libusb_get_port_number((*C.libusb_device)(d))),
|
||||
Port: port,
|
||||
Path: path,
|
||||
Speed: Speed(C.libusb_get_device_speed((*C.libusb_device)(d))),
|
||||
Spec: BCD(desc.bcdUSB),
|
||||
Device: BCD(desc.bcdDevice),
|
||||
|
Reference in New Issue
Block a user