Use Protocol type for USB interface protocol.
This commit is contained in:
@@ -86,7 +86,7 @@ type InterfaceSetup struct {
|
|||||||
// IfClass is the USB-IF subclass code, as defined by the USB spec.
|
// IfClass is the USB-IF subclass code, as defined by the USB spec.
|
||||||
IfSubClass Class
|
IfSubClass Class
|
||||||
// IfProtocol is USB protocol code, as defined by the USB spe.c
|
// IfProtocol is USB protocol code, as defined by the USB spe.c
|
||||||
IfProtocol uint8
|
IfProtocol Protocol
|
||||||
// Endpoints has the list of endpoints available on this interface with
|
// Endpoints has the list of endpoints available on this interface with
|
||||||
// this alternate setting.
|
// this alternate setting.
|
||||||
Endpoints []EndpointInfo
|
Endpoints []EndpointInfo
|
||||||
|
@@ -19,6 +19,7 @@ package usb
|
|||||||
import "C"
|
import "C"
|
||||||
import "strconv"
|
import "strconv"
|
||||||
|
|
||||||
|
// Class represents a USB-IF class or subclass code.
|
||||||
type Class uint8
|
type Class uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -58,6 +59,14 @@ func (c Class) String() string {
|
|||||||
return strconv.Itoa(int(c))
|
return strconv.Itoa(int(c))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Protocol is the interface class protocol, qualified by the values
|
||||||
|
// of interface class and subclass.
|
||||||
|
type Protocol uint8
|
||||||
|
|
||||||
|
func (p Protocol) String() string {
|
||||||
|
return strconv.Itoa(int(p))
|
||||||
|
}
|
||||||
|
|
||||||
type DescriptorType uint8
|
type DescriptorType uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@@ -29,9 +29,9 @@ type Descriptor struct {
|
|||||||
Product ID // The Product identifier
|
Product ID // The Product identifier
|
||||||
|
|
||||||
// Protocol information
|
// Protocol information
|
||||||
Class Class // The class of this device
|
Class Class // The class of this device
|
||||||
SubClass Class // The sub-class (within the class) of this device
|
SubClass Class // The sub-class (within the class) of this device
|
||||||
Protocol uint8 // The protocol (within the sub-class) of this device
|
Protocol Protocol // The protocol (within the sub-class) of this device
|
||||||
|
|
||||||
// Configuration information
|
// Configuration information
|
||||||
Configs []ConfigInfo
|
Configs []ConfigInfo
|
||||||
|
@@ -245,7 +245,7 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*Descriptor, error) {
|
|||||||
Alternate: uint8(alt.bAlternateSetting),
|
Alternate: uint8(alt.bAlternateSetting),
|
||||||
IfClass: Class(alt.bInterfaceClass),
|
IfClass: Class(alt.bInterfaceClass),
|
||||||
IfSubClass: Class(alt.bInterfaceSubClass),
|
IfSubClass: Class(alt.bInterfaceSubClass),
|
||||||
IfProtocol: uint8(alt.bInterfaceProtocol),
|
IfProtocol: Protocol(alt.bInterfaceProtocol),
|
||||||
}
|
}
|
||||||
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{
|
||||||
@@ -278,7 +278,7 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*Descriptor, error) {
|
|||||||
Product: ID(desc.idProduct),
|
Product: ID(desc.idProduct),
|
||||||
Class: Class(desc.bDeviceClass),
|
Class: Class(desc.bDeviceClass),
|
||||||
SubClass: Class(desc.bDeviceSubClass),
|
SubClass: Class(desc.bDeviceSubClass),
|
||||||
Protocol: uint8(desc.bDeviceProtocol),
|
Protocol: Protocol(desc.bDeviceProtocol),
|
||||||
Configs: cfgs,
|
Configs: cfgs,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@@ -58,7 +58,7 @@ func Describe(val interface{}) string {
|
|||||||
func Classify(val interface{}) string {
|
func Classify(val interface{}) string {
|
||||||
var (
|
var (
|
||||||
class, sub usb.Class
|
class, sub usb.Class
|
||||||
proto uint8
|
proto usb.Protocol
|
||||||
)
|
)
|
||||||
switch val := val.(type) {
|
switch val := val.(type) {
|
||||||
case *usb.Descriptor:
|
case *usb.Descriptor:
|
||||||
|
@@ -63,7 +63,7 @@ func (c Class) String() string {
|
|||||||
// A SubClass contains the name of the subclass and any associated protocols.
|
// A SubClass contains the name of the subclass and any associated protocols.
|
||||||
type SubClass struct {
|
type SubClass struct {
|
||||||
Name string
|
Name string
|
||||||
Protocol map[uint8]string
|
Protocol map[usb.Protocol]string
|
||||||
}
|
}
|
||||||
|
|
||||||
// String returns the name of the SubClass.
|
// String returns the name of the SubClass.
|
||||||
@@ -186,9 +186,9 @@ func ParseIDs(r io.Reader) (map[usb.ID]*Vendor, map[usb.Class]*Class, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if subclass.Protocol == nil {
|
if subclass.Protocol == nil {
|
||||||
subclass.Protocol = make(map[uint8]string)
|
subclass.Protocol = make(map[usb.Protocol]string)
|
||||||
}
|
}
|
||||||
subclass.Protocol[uint8(id)] = name
|
subclass.Protocol[usb.Protocol(id)] = name
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("too many levels of nesting for class")
|
return fmt.Errorf("too many levels of nesting for class")
|
||||||
|
@@ -64,7 +64,7 @@ var (
|
|||||||
0x01: {Name: "Direct Line"},
|
0x01: {Name: "Direct Line"},
|
||||||
0x02: {
|
0x02: {
|
||||||
Name: "Abstract (modem)",
|
Name: "Abstract (modem)",
|
||||||
Protocol: map[uint8]string{
|
Protocol: map[usb.Protocol]string{
|
||||||
0x00: "None",
|
0x00: "None",
|
||||||
0x01: "AT-commands (v.25ter)",
|
0x01: "AT-commands (v.25ter)",
|
||||||
0x02: "AT-commands (PCCA101)",
|
0x02: "AT-commands (PCCA101)",
|
||||||
|
Reference in New Issue
Block a user