Rename more "Info" fields to "Desc"
This commit is contained in:
18
config.go
18
config.go
@@ -20,11 +20,11 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ConfigInfo contains the information about a USB device configuration,
|
// ConfigDesc contains the information about a USB device configuration,
|
||||||
// extracted from the device descriptor.
|
// extracted from the device descriptor.
|
||||||
type ConfigDesc struct {
|
type ConfigDesc struct {
|
||||||
// Config is the configuration number.
|
// Number is the configuration number.
|
||||||
Config int
|
Number int
|
||||||
// SelfPowered is true if the device is powered externally, i.e. not
|
// SelfPowered is true if the device is powered externally, i.e. not
|
||||||
// drawing power from the USB bus.
|
// drawing power from the USB bus.
|
||||||
SelfPowered bool
|
SelfPowered bool
|
||||||
@@ -39,7 +39,7 @@ type ConfigDesc struct {
|
|||||||
|
|
||||||
// String returns the human-readable description of the configuration descriptor.
|
// String returns the human-readable description of the configuration descriptor.
|
||||||
func (c ConfigDesc) String() string {
|
func (c ConfigDesc) String() string {
|
||||||
return fmt.Sprintf("Configuration %d", c.Config)
|
return fmt.Sprintf("Configuration %d", c.Number)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config represents a USB device set to use a particular configuration.
|
// Config represents a USB device set to use a particular configuration.
|
||||||
@@ -47,7 +47,7 @@ func (c ConfigDesc) String() string {
|
|||||||
// To access device endpoints, claim an interface and it's alternate
|
// To access device endpoints, claim an interface and it's alternate
|
||||||
// setting number through a call to Interface().
|
// setting number through a call to Interface().
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Info ConfigDesc
|
Desc ConfigDesc
|
||||||
|
|
||||||
dev *Device
|
dev *Device
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ func (c *Config) Close() error {
|
|||||||
|
|
||||||
// String returns the human-readable description of the configuration.
|
// String returns the human-readable description of the configuration.
|
||||||
func (c *Config) String() string {
|
func (c *Config) String() string {
|
||||||
return fmt.Sprintf("%s,config=%d", c.dev.String(), c.Info.Config)
|
return fmt.Sprintf("%s,config=%d", c.dev.String(), c.Desc.Number)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interface claims and returns an interface on a USB device.
|
// Interface claims and returns an interface on a USB device.
|
||||||
@@ -89,10 +89,10 @@ func (c *Config) Interface(intf, alt int) (*Interface, error) {
|
|||||||
if c.dev == nil {
|
if c.dev == nil {
|
||||||
return nil, fmt.Errorf("Interface(%d, %d) called on %s after Close", intf, alt, c)
|
return nil, fmt.Errorf("Interface(%d, %d) called on %s after Close", intf, alt, c)
|
||||||
}
|
}
|
||||||
if intf < 0 || intf >= len(c.Info.Interfaces) {
|
if intf < 0 || intf >= len(c.Desc.Interfaces) {
|
||||||
return nil, fmt.Errorf("interface %d not found in %s, available interfaces 0..%d", intf, c, len(c.Info.Interfaces)-1)
|
return nil, fmt.Errorf("interface %d not found in %s, available interfaces 0..%d", intf, c, len(c.Desc.Interfaces)-1)
|
||||||
}
|
}
|
||||||
ifInfo := c.Info.Interfaces[intf]
|
ifInfo := c.Desc.Interfaces[intf]
|
||||||
if alt < 0 || alt >= len(ifInfo.AltSettings) {
|
if alt < 0 || alt >= len(ifInfo.AltSettings) {
|
||||||
return nil, fmt.Errorf("alternate setting %d not found for %s in %s, available alt settings 0..%d", alt, ifInfo, c, len(ifInfo.AltSettings)-1)
|
return nil, fmt.Errorf("alternate setting %d not found for %s in %s, available alt settings 0..%d", alt, ifInfo, c, len(ifInfo.AltSettings)-1)
|
||||||
}
|
}
|
||||||
|
@@ -117,12 +117,12 @@ func (d *Device) Config(cfgNum int) (*Config, error) {
|
|||||||
if d.handle == nil {
|
if d.handle == nil {
|
||||||
return nil, fmt.Errorf("Config(%d) called on %s after Close", cfgNum, d)
|
return nil, fmt.Errorf("Config(%d) called on %s after Close", cfgNum, d)
|
||||||
}
|
}
|
||||||
info, ok := d.Desc.Configs[cfgNum]
|
desc, ok := d.Desc.Configs[cfgNum]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("configuration id %d not found in the descriptor of the device %s. Available config ids: %v", cfgNum, d, d.Desc.sortedConfigIds())
|
return nil, fmt.Errorf("configuration id %d not found in the descriptor of the device %s. Available config ids: %v", cfgNum, d, d.Desc.sortedConfigIds())
|
||||||
}
|
}
|
||||||
cfg := &Config{
|
cfg := &Config{
|
||||||
Info: info,
|
Desc: desc,
|
||||||
dev: d,
|
dev: d,
|
||||||
claimed: make(map[int]bool),
|
claimed: make(map[int]bool),
|
||||||
}
|
}
|
||||||
@@ -175,7 +175,7 @@ func (d *Device) Close() error {
|
|||||||
d.mu.Lock()
|
d.mu.Lock()
|
||||||
defer d.mu.Unlock()
|
defer d.mu.Unlock()
|
||||||
if d.claimed != nil {
|
if d.claimed != nil {
|
||||||
return fmt.Errorf("can't release the device %s, it has an open config %s", d, d.claimed.Info.Config)
|
return fmt.Errorf("can't release the device %s, it has an open config %s", d, d.claimed.Desc.Number)
|
||||||
}
|
}
|
||||||
libusb.close(d.handle)
|
libusb.close(d.handle)
|
||||||
d.handle = nil
|
d.handle = nil
|
||||||
|
@@ -62,7 +62,7 @@ func TestClaimAndRelease(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%s.InEndpoint(%d): got error %v, want nil", intf, ep1Num, err)
|
t.Fatalf("%s.InEndpoint(%d): got error %v, want nil", intf, ep1Num, err)
|
||||||
}
|
}
|
||||||
if want := fakeDevices[devIdx].Configs[cfgNum].Interfaces[if1Num].AltSettings[alt1Num].Endpoints[ep1Num]; !reflect.DeepEqual(got.Info, want) {
|
if want := fakeDevices[devIdx].Configs[cfgNum].Interfaces[if1Num].AltSettings[alt1Num].Endpoints[ep1Num]; !reflect.DeepEqual(got.Desc, want) {
|
||||||
t.Errorf("%s.InEndpoint(%d): got %+v, want %+v", intf, ep1Num, got, want)
|
t.Errorf("%s.InEndpoint(%d): got %+v, want %+v", intf, ep1Num, got, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,7 +21,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// EndpointInfo contains the information about an interface endpoint, extracted
|
// EndpointDesc contains the information about an interface endpoint, extracted
|
||||||
// from the descriptor.
|
// from the descriptor.
|
||||||
type EndpointDesc struct {
|
type EndpointDesc struct {
|
||||||
// Number represents the endpoint number. Note that the endpoint number is different from the
|
// Number represents the endpoint number. Note that the endpoint number is different from the
|
||||||
@@ -72,14 +72,14 @@ type endpoint struct {
|
|||||||
h *libusbDevHandle
|
h *libusbDevHandle
|
||||||
|
|
||||||
InterfaceSetting
|
InterfaceSetting
|
||||||
Info EndpointDesc
|
Desc EndpointDesc
|
||||||
|
|
||||||
Timeout time.Duration
|
Timeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// String returns a human-readable description of the endpoint.
|
// String returns a human-readable description of the endpoint.
|
||||||
func (e *endpoint) String() string {
|
func (e *endpoint) String() string {
|
||||||
return e.Info.String()
|
return e.Desc.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *endpoint) transfer(buf []byte) (int, error) {
|
func (e *endpoint) transfer(buf []byte) (int, error) {
|
||||||
@@ -87,7 +87,7 @@ func (e *endpoint) transfer(buf []byte) (int, error) {
|
|||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
t, err := newUSBTransfer(e.h, &e.Info, buf, e.Timeout)
|
t, err := newUSBTransfer(e.h, &e.Desc, buf, e.Timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
@@ -17,7 +17,7 @@ package gousb
|
|||||||
func (e *endpoint) newStream(size, count int, submit bool) (*stream, error) {
|
func (e *endpoint) newStream(size, count int, submit bool) (*stream, error) {
|
||||||
var ts []transferIntf
|
var ts []transferIntf
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
t, err := newUSBTransfer(e.h, &e.Info, make([]byte, size), e.Timeout)
|
t, err := newUSBTransfer(e.h, &e.Desc, make([]byte, size), e.Timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, t := range ts {
|
for _, t := range ts {
|
||||||
t.free()
|
t.free()
|
||||||
|
@@ -89,7 +89,7 @@ func TestEndpoint(t *testing.T) {
|
|||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
ep := &endpoint{h: nil, InterfaceSetting: epData.intf, Info: epData.ei}
|
ep := &endpoint{h: nil, InterfaceSetting: epData.intf, Desc: epData.ei}
|
||||||
if tc.wantSubmit {
|
if tc.wantSubmit {
|
||||||
go func() {
|
go func() {
|
||||||
fakeT := lib.waitForSubmitted()
|
fakeT := lib.waitForSubmitted()
|
||||||
|
@@ -28,7 +28,7 @@ var fakeDevices = []*DeviceDesc{
|
|||||||
Product: ID(0x0001),
|
Product: ID(0x0001),
|
||||||
Protocol: 255,
|
Protocol: 255,
|
||||||
Configs: map[int]ConfigDesc{1: {
|
Configs: map[int]ConfigDesc{1: {
|
||||||
Config: 1,
|
Number: 1,
|
||||||
MaxPower: Milliamperes(100),
|
MaxPower: Milliamperes(100),
|
||||||
Interfaces: []InterfaceDesc{{
|
Interfaces: []InterfaceDesc{{
|
||||||
Number: 0,
|
Number: 0,
|
||||||
@@ -67,7 +67,7 @@ var fakeDevices = []*DeviceDesc{
|
|||||||
Product: ID(0x0002),
|
Product: ID(0x0002),
|
||||||
Protocol: 255,
|
Protocol: 255,
|
||||||
Configs: map[int]ConfigDesc{1: {
|
Configs: map[int]ConfigDesc{1: {
|
||||||
Config: 1,
|
Number: 1,
|
||||||
MaxPower: Milliamperes(100),
|
MaxPower: Milliamperes(100),
|
||||||
Interfaces: []InterfaceDesc{{
|
Interfaces: []InterfaceDesc{{
|
||||||
Number: 0,
|
Number: 0,
|
||||||
|
10
interface.go
10
interface.go
@@ -20,7 +20,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
// InterfaceInfo contains information about a USB interface, extracted from
|
// InterfaceDesc contains information about a USB interface, extracted from
|
||||||
// the descriptor.
|
// the descriptor.
|
||||||
type InterfaceDesc struct {
|
type InterfaceDesc struct {
|
||||||
// Number is the number of this interface, a zero-based index in the array
|
// Number is the number of this interface, a zero-based index in the array
|
||||||
@@ -39,7 +39,7 @@ func (i InterfaceDesc) String() string {
|
|||||||
// InterfaceSetting contains information about a USB interface with a particular
|
// InterfaceSetting contains information about a USB interface with a particular
|
||||||
// alternate setting, extracted from the descriptor.
|
// alternate setting, extracted from the descriptor.
|
||||||
type InterfaceSetting struct {
|
type InterfaceSetting struct {
|
||||||
// Number is the number of this interface, the same as in InterfaceInfo.
|
// Number is the number of this interface, the same as in InterfaceDesc.
|
||||||
Number int
|
Number int
|
||||||
// Alternate is the number of this alternate setting.
|
// Alternate is the number of this alternate setting.
|
||||||
Alternate int
|
Alternate int
|
||||||
@@ -102,7 +102,7 @@ func (i *Interface) openEndpoint(epNum int) (*endpoint, error) {
|
|||||||
}
|
}
|
||||||
return &endpoint{
|
return &endpoint{
|
||||||
InterfaceSetting: i.Setting,
|
InterfaceSetting: i.Setting,
|
||||||
Info: ep,
|
Desc: ep,
|
||||||
h: i.config.dev.handle,
|
h: i.config.dev.handle,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -116,7 +116,7 @@ func (i *Interface) InEndpoint(epNum int) (*InEndpoint, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if ep.Info.Direction != EndpointDirectionIn {
|
if ep.Desc.Direction != EndpointDirectionIn {
|
||||||
return nil, fmt.Errorf("%s is not an IN endpoint", ep)
|
return nil, fmt.Errorf("%s is not an IN endpoint", ep)
|
||||||
}
|
}
|
||||||
return &InEndpoint{
|
return &InEndpoint{
|
||||||
@@ -133,7 +133,7 @@ func (i *Interface) OutEndpoint(epNum int) (*OutEndpoint, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if ep.Info.Direction != EndpointDirectionOut {
|
if ep.Desc.Direction != EndpointDirectionOut {
|
||||||
return nil, fmt.Errorf("%s is not an OUT endpoint", ep)
|
return nil, fmt.Errorf("%s is not an OUT endpoint", ep)
|
||||||
}
|
}
|
||||||
return &OutEndpoint{
|
return &OutEndpoint{
|
||||||
|
@@ -214,7 +214,7 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*DeviceDesc, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
c := ConfigDesc{
|
c := ConfigDesc{
|
||||||
Config: int(cfg.bConfigurationValue),
|
Number: int(cfg.bConfigurationValue),
|
||||||
SelfPowered: (cfg.bmAttributes & selfPoweredMask) != 0,
|
SelfPowered: (cfg.bmAttributes & selfPoweredMask) != 0,
|
||||||
RemoteWakeup: (cfg.bmAttributes & remoteWakeupMask) != 0,
|
RemoteWakeup: (cfg.bmAttributes & remoteWakeupMask) != 0,
|
||||||
// TODO(sebek): at GenX speeds MaxPower is expressed in units of 8mA, not 2mA.
|
// TODO(sebek): at GenX speeds MaxPower is expressed in units of 8mA, not 2mA.
|
||||||
@@ -249,10 +249,10 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*DeviceDesc, error) {
|
|||||||
Protocol: Protocol(alt.bInterfaceProtocol),
|
Protocol: Protocol(alt.bInterfaceProtocol),
|
||||||
}
|
}
|
||||||
if ifNum != i.Number {
|
if ifNum != i.Number {
|
||||||
return nil, fmt.Errorf("config %d interface at index %d has number %d, USB standard states they should be identical", c.Config, ifNum, i.Number)
|
return nil, fmt.Errorf("config %d interface at index %d has number %d, USB standard states they should be identical", c.Number, ifNum, i.Number)
|
||||||
}
|
}
|
||||||
if altNum != i.Alternate {
|
if altNum != i.Alternate {
|
||||||
return nil, fmt.Errorf("config %d interface %d alternate settings at index %d has number %d, USB standard states they should be identical", c.Config, i.Number, altNum, i.Alternate)
|
return nil, fmt.Errorf("config %d interface %d alternate settings at index %d has number %d, USB standard states they should be identical", c.Number, i.Number, altNum, i.Alternate)
|
||||||
}
|
}
|
||||||
var ends []C.struct_libusb_endpoint_descriptor
|
var ends []C.struct_libusb_endpoint_descriptor
|
||||||
*(*reflect.SliceHeader)(unsafe.Pointer(&ends)) = reflect.SliceHeader{
|
*(*reflect.SliceHeader)(unsafe.Pointer(&ends)) = reflect.SliceHeader{
|
||||||
@@ -274,7 +274,7 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*DeviceDesc, error) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
C.libusb_free_config_descriptor(cfg)
|
C.libusb_free_config_descriptor(cfg)
|
||||||
cfgs[c.Config] = c
|
cfgs[c.Number] = c
|
||||||
}
|
}
|
||||||
|
|
||||||
return &DeviceDesc{
|
return &DeviceDesc{
|
||||||
|
@@ -194,7 +194,7 @@ func Example_complex() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Buffer large enough for 10 USB packets from endpoint 6.
|
// Buffer large enough for 10 USB packets from endpoint 6.
|
||||||
buf := make([]byte, 10*epIn.Info.MaxPacketSize)
|
buf := make([]byte, 10*epIn.Desc.MaxPacketSize)
|
||||||
total := 0
|
total := 0
|
||||||
// Repeat the read/write cycle 10 times.
|
// Repeat the read/write cycle 10 times.
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
|
Reference in New Issue
Block a user