use ConfigDesc, InterfaceDesc and EndpointDesc.
This commit is contained in:
@@ -23,4 +23,4 @@ script:
|
||||
- |-
|
||||
echo 'mode: count' > coverage.merged && go list ./... | xargs -n1 -I{} sh -c ': > coverage.tmp; go test -v -covermode=count -coverprofile=coverage.tmp {} && tail -n +2 coverage.tmp >> coverage.merged' && rm coverage.tmp
|
||||
- |-
|
||||
$HOME/gopath/bin/goveralls -coverprofile=coverage.merged -service=travis-ci -ignore libusb_wrappers.go,error.go || true
|
||||
$HOME/gopath/bin/goveralls -coverprofile=coverage.merged -service=travis-ci -ignore libusb.go,error.go || true
|
||||
|
@@ -34,7 +34,7 @@ type ConfigDesc struct {
|
||||
// in this configuration.
|
||||
MaxPower Milliamperes
|
||||
// Interfaces has a list of USB interfaces available in this configuration.
|
||||
Interfaces []InterfaceInfo
|
||||
Interfaces []InterfaceDesc
|
||||
}
|
||||
|
||||
// String returns the human-readable description of the configuration descriptor.
|
||||
|
@@ -23,7 +23,7 @@ import (
|
||||
|
||||
// EndpointInfo contains the information about an interface endpoint, extracted
|
||||
// from the descriptor.
|
||||
type EndpointInfo struct {
|
||||
type EndpointDesc struct {
|
||||
// Number represents the endpoint number. Note that the endpoint number is different from the
|
||||
// address field in the descriptor - address 0x82 means endpoint number 2,
|
||||
// with endpoint direction IN.
|
||||
@@ -55,7 +55,7 @@ func endpointAddr(n int, d EndpointDirection) int {
|
||||
}
|
||||
|
||||
// String returns the human-readable description of the endpoint.
|
||||
func (e EndpointInfo) String() string {
|
||||
func (e EndpointDesc) String() string {
|
||||
ret := make([]string, 0, 3)
|
||||
ret = append(ret, fmt.Sprintf("ep #%d %s (address 0x%02x) %s", e.Number, e.Direction, endpointAddr(e.Number, e.Direction), e.TransferType))
|
||||
switch e.TransferType {
|
||||
@@ -72,7 +72,7 @@ type endpoint struct {
|
||||
h *libusbDevHandle
|
||||
|
||||
InterfaceSetting
|
||||
Info EndpointInfo
|
||||
Info EndpointDesc
|
||||
|
||||
Timeout time.Duration
|
||||
}
|
||||
|
@@ -24,11 +24,11 @@ func TestEndpoint(t *testing.T) {
|
||||
defer done()
|
||||
|
||||
for _, epData := range []struct {
|
||||
ei EndpointInfo
|
||||
ei EndpointDesc
|
||||
intf InterfaceSetting
|
||||
}{
|
||||
{
|
||||
ei: EndpointInfo{
|
||||
ei: EndpointDesc{
|
||||
Number: 2,
|
||||
Direction: EndpointDirectionIn,
|
||||
MaxPacketSize: 512,
|
||||
@@ -41,7 +41,7 @@ func TestEndpoint(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
ei: EndpointInfo{
|
||||
ei: EndpointDesc{
|
||||
Number: 6,
|
||||
MaxPacketSize: 3 * 1024,
|
||||
TransferType: TransferTypeIsochronous,
|
||||
@@ -55,7 +55,7 @@ func TestEndpoint(t *testing.T) {
|
||||
},
|
||||
},
|
||||
} {
|
||||
epData.intf.Endpoints = map[int]EndpointInfo{epData.ei.Number: epData.ei}
|
||||
epData.intf.Endpoints = map[int]EndpointDesc{epData.ei.Number: epData.ei}
|
||||
for _, tc := range []struct {
|
||||
desc string
|
||||
buf []byte
|
||||
@@ -115,11 +115,11 @@ func TestEndpoint(t *testing.T) {
|
||||
|
||||
func TestEndpointInfo(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
ep EndpointInfo
|
||||
ep EndpointDesc
|
||||
want string
|
||||
}{
|
||||
{
|
||||
ep: EndpointInfo{
|
||||
ep: EndpointDesc{
|
||||
Number: 6,
|
||||
Direction: EndpointDirectionIn,
|
||||
TransferType: TransferTypeBulk,
|
||||
@@ -128,7 +128,7 @@ func TestEndpointInfo(t *testing.T) {
|
||||
want: "ep #6 IN (address 0x86) bulk [512 bytes]",
|
||||
},
|
||||
{
|
||||
ep: EndpointInfo{
|
||||
ep: EndpointDesc{
|
||||
Number: 2,
|
||||
Direction: EndpointDirectionOut,
|
||||
TransferType: TransferTypeIsochronous,
|
||||
@@ -139,7 +139,7 @@ func TestEndpointInfo(t *testing.T) {
|
||||
want: "ep #2 OUT (address 0x02) isochronous - asynchronous data [512 bytes]",
|
||||
},
|
||||
{
|
||||
ep: EndpointInfo{
|
||||
ep: EndpointDesc{
|
||||
Number: 3,
|
||||
Direction: EndpointDirectionIn,
|
||||
TransferType: TransferTypeInterrupt,
|
||||
|
@@ -30,13 +30,13 @@ var fakeDevices = []*DeviceDesc{
|
||||
Configs: map[int]ConfigDesc{1: {
|
||||
Config: 1,
|
||||
MaxPower: Milliamperes(100),
|
||||
Interfaces: []InterfaceInfo{{
|
||||
Interfaces: []InterfaceDesc{{
|
||||
Number: 0,
|
||||
AltSettings: []InterfaceSetting{{
|
||||
Number: 0,
|
||||
Alternate: 0,
|
||||
Class: ClassVendorSpec,
|
||||
Endpoints: map[int]EndpointInfo{
|
||||
Endpoints: map[int]EndpointDesc{
|
||||
1: {
|
||||
Number: 1,
|
||||
Direction: EndpointDirectionOut,
|
||||
@@ -69,7 +69,7 @@ var fakeDevices = []*DeviceDesc{
|
||||
Configs: map[int]ConfigDesc{1: {
|
||||
Config: 1,
|
||||
MaxPower: Milliamperes(100),
|
||||
Interfaces: []InterfaceInfo{{
|
||||
Interfaces: []InterfaceDesc{{
|
||||
Number: 0,
|
||||
AltSettings: []InterfaceSetting{{
|
||||
Number: 0,
|
||||
@@ -82,7 +82,7 @@ var fakeDevices = []*DeviceDesc{
|
||||
Number: 1,
|
||||
Alternate: 0,
|
||||
Class: ClassVendorSpec,
|
||||
Endpoints: map[int]EndpointInfo{
|
||||
Endpoints: map[int]EndpointDesc{
|
||||
5: {
|
||||
Number: 5,
|
||||
Direction: EndpointDirectionOut,
|
||||
@@ -102,7 +102,7 @@ var fakeDevices = []*DeviceDesc{
|
||||
Number: 1,
|
||||
Alternate: 1,
|
||||
Class: ClassVendorSpec,
|
||||
Endpoints: map[int]EndpointInfo{
|
||||
Endpoints: map[int]EndpointDesc{
|
||||
5: {
|
||||
Number: 5,
|
||||
Direction: EndpointDirectionOut,
|
||||
@@ -120,7 +120,7 @@ var fakeDevices = []*DeviceDesc{
|
||||
Number: 1,
|
||||
Alternate: 2,
|
||||
Class: ClassVendorSpec,
|
||||
Endpoints: map[int]EndpointInfo{
|
||||
Endpoints: map[int]EndpointDesc{
|
||||
5: {
|
||||
Number: 5,
|
||||
Direction: EndpointDirectionIn,
|
||||
|
@@ -147,7 +147,7 @@ func (f *fakeLibusb) setAlt(d *libusbDevHandle, intf, alt uint8) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *fakeLibusb) alloc(_ *libusbDevHandle, _ *EndpointInfo, _ time.Duration, _ int, buf []byte, done chan struct{}) (*libusbTransfer, error) {
|
||||
func (f *fakeLibusb) alloc(_ *libusbDevHandle, _ *EndpointDesc, _ time.Duration, _ int, buf []byte, done chan struct{}) (*libusbTransfer, error) {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
t := newFakeTransferPointer()
|
||||
|
@@ -22,7 +22,7 @@ import (
|
||||
|
||||
// InterfaceInfo contains information about a USB interface, extracted from
|
||||
// the descriptor.
|
||||
type InterfaceInfo struct {
|
||||
type InterfaceDesc struct {
|
||||
// Number is the number of this interface, a zero-based index in the array
|
||||
// of interfaces supported by the device configuration.
|
||||
Number int
|
||||
@@ -32,7 +32,7 @@ type InterfaceInfo struct {
|
||||
|
||||
// String returns a human-readable descripton of the interface descriptor and
|
||||
// it's alternate settings.
|
||||
func (i InterfaceInfo) String() string {
|
||||
func (i InterfaceDesc) String() string {
|
||||
return fmt.Sprintf("Interface %d (%d alternate settings)", i.Number, len(i.AltSettings))
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ type InterfaceSetting struct {
|
||||
Protocol Protocol
|
||||
// Endpoints enumerates the endpoints available on this interface with
|
||||
// this alternate setting.
|
||||
Endpoints map[int]EndpointInfo
|
||||
Endpoints map[int]EndpointDesc
|
||||
}
|
||||
|
||||
func (a InterfaceSetting) sortedEndpointIds() []string {
|
||||
@@ -95,7 +95,7 @@ func (i *Interface) Close() {
|
||||
}
|
||||
|
||||
func (i *Interface) openEndpoint(epNum int) (*endpoint, error) {
|
||||
var ep EndpointInfo
|
||||
var ep EndpointDesc
|
||||
ep, ok := i.Setting.Endpoints[epNum]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("%s does not have endpoint number %d. Available endpoints: %v", i, epNum, i.Setting.sortedEndpointIds())
|
||||
|
@@ -39,8 +39,8 @@ type libusbTransfer C.struct_libusb_transfer
|
||||
type libusbIso C.struct_libusb_iso_packet_descriptor
|
||||
type libusbEndpoint C.struct_libusb_endpoint_descriptor
|
||||
|
||||
func (ep libusbEndpoint) endpointInfo(dev *DeviceDesc) EndpointInfo {
|
||||
ei := EndpointInfo{
|
||||
func (ep libusbEndpoint) endpointDesc(dev *DeviceDesc) EndpointDesc {
|
||||
ei := EndpointDesc{
|
||||
Number: int(ep.bEndpointAddress & endpointNumMask),
|
||||
Direction: EndpointDirection((ep.bEndpointAddress & endpointDirectionMask) != 0),
|
||||
TransferType: TransferType(ep.bmAttributes & transferTypeMask),
|
||||
@@ -139,7 +139,7 @@ type libusbIntf interface {
|
||||
setAlt(*libusbDevHandle, uint8, uint8) error
|
||||
|
||||
// transfer
|
||||
alloc(*libusbDevHandle, *EndpointInfo, time.Duration, int, []byte, chan struct{}) (*libusbTransfer, error)
|
||||
alloc(*libusbDevHandle, *EndpointDesc, time.Duration, int, []byte, chan struct{}) (*libusbTransfer, error)
|
||||
cancel(*libusbTransfer) error
|
||||
submit(*libusbTransfer) error
|
||||
data(*libusbTransfer) (int, TransferStatus)
|
||||
@@ -227,7 +227,7 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*DeviceDesc, error) {
|
||||
Len: int(cfg.bNumInterfaces),
|
||||
Cap: int(cfg.bNumInterfaces),
|
||||
}
|
||||
c.Interfaces = make([]InterfaceInfo, 0, len(ifaces))
|
||||
c.Interfaces = make([]InterfaceDesc, 0, len(ifaces))
|
||||
for ifNum, iface := range ifaces {
|
||||
if iface.num_altsetting == 0 {
|
||||
continue
|
||||
@@ -260,15 +260,15 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*DeviceDesc, error) {
|
||||
Len: int(alt.bNumEndpoints),
|
||||
Cap: int(alt.bNumEndpoints),
|
||||
}
|
||||
i.Endpoints = make(map[int]EndpointInfo, len(ends))
|
||||
i.Endpoints = make(map[int]EndpointDesc, len(ends))
|
||||
for _, end := range ends {
|
||||
// TODO(sebek): pass the device descriptor too.
|
||||
epi := libusbEndpoint(end).endpointInfo(nil)
|
||||
epi := libusbEndpoint(end).endpointDesc(nil)
|
||||
i.Endpoints[epi.Number] = epi
|
||||
}
|
||||
descs = append(descs, i)
|
||||
}
|
||||
c.Interfaces = append(c.Interfaces, InterfaceInfo{
|
||||
c.Interfaces = append(c.Interfaces, InterfaceDesc{
|
||||
Number: descs[0].Number,
|
||||
AltSettings: descs,
|
||||
})
|
||||
@@ -379,7 +379,7 @@ func (libusbImpl) setAlt(d *libusbDevHandle, iface, setup uint8) error {
|
||||
return fromErrNo(C.libusb_set_interface_alt_setting((*C.libusb_device_handle)(d), C.int(iface), C.int(setup)))
|
||||
}
|
||||
|
||||
func (libusbImpl) alloc(d *libusbDevHandle, ep *EndpointInfo, timeout time.Duration, isoPackets int, buf []byte, done chan struct{}) (*libusbTransfer, error) {
|
||||
func (libusbImpl) alloc(d *libusbDevHandle, ep *EndpointDesc, timeout time.Duration, isoPackets int, buf []byte, done chan struct{}) (*libusbTransfer, error) {
|
||||
xfer := C.libusb_alloc_transfer(C.int(isoPackets))
|
||||
if xfer == nil {
|
||||
return nil, fmt.Errorf("libusb_alloc_transfer(%d) failed", isoPackets)
|
@@ -111,7 +111,7 @@ func (t *usbTransfer) data() []byte {
|
||||
|
||||
// newUSBTransfer allocates a new transfer structure for communication with a
|
||||
// given device/endpoint, with buf as the underlying transfer buffer.
|
||||
func newUSBTransfer(dev *libusbDevHandle, ei *EndpointInfo, buf []byte, timeout time.Duration) (*usbTransfer, error) {
|
||||
func newUSBTransfer(dev *libusbDevHandle, ei *EndpointDesc, buf []byte, timeout time.Duration) (*usbTransfer, error) {
|
||||
var isoPackets, isoPktSize int
|
||||
if ei.TransferType == TransferTypeIsochronous {
|
||||
isoPktSize = ei.MaxPacketSize
|
||||
|
@@ -52,7 +52,7 @@ func TestNewTransfer(t *testing.T) {
|
||||
wantLength: 10000,
|
||||
},
|
||||
} {
|
||||
xfer, err := newUSBTransfer(nil, &EndpointInfo{
|
||||
xfer, err := newUSBTransfer(nil, &EndpointDesc{
|
||||
Number: 2,
|
||||
Direction: tc.dir,
|
||||
TransferType: tc.tt,
|
||||
@@ -76,7 +76,7 @@ func TestTransferProtocol(t *testing.T) {
|
||||
xfers := make([]*usbTransfer, 2)
|
||||
var err error
|
||||
for i := 0; i < 2; i++ {
|
||||
xfers[i], err = newUSBTransfer(nil, &EndpointInfo{
|
||||
xfers[i], err = newUSBTransfer(nil, &EndpointDesc{
|
||||
Number: 6,
|
||||
Direction: EndpointDirectionIn,
|
||||
TransferType: TransferTypeBulk,
|
||||
|
Reference in New Issue
Block a user