start renaming the constants to Go-style.
This commit is contained in:
@@ -163,7 +163,7 @@ func main() {
|
||||
}
|
||||
|
||||
log.Printf("Connecting to endpoint %d...", *endpoint)
|
||||
ep, err := dev.OpenEndpoint(uint8(*config), uint8(*iface), uint8(*setup), uint8(*endpoint)|uint8(usb.ENDPOINT_DIR_IN))
|
||||
ep, err := dev.OpenEndpoint(uint8(*config), uint8(*iface), uint8(*setup), uint8(*endpoint)|uint8(usb.EndpointDirectionIn))
|
||||
if err != nil {
|
||||
log.Fatalf("open: %s", err)
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@ type EndpointInfo struct {
|
||||
}
|
||||
|
||||
func (e EndpointInfo) Number() int {
|
||||
return int(e.Address) & ENDPOINT_NUM_MASK
|
||||
return int(e.Address) & EndpointNumMask
|
||||
}
|
||||
|
||||
func (e EndpointInfo) TransferType() TransferType {
|
||||
@@ -38,7 +38,7 @@ func (e EndpointInfo) TransferType() TransferType {
|
||||
}
|
||||
|
||||
func (e EndpointInfo) Direction() EndpointDirection {
|
||||
return EndpointDirection(e.Address) & ENDPOINT_DIR_MASK
|
||||
return EndpointDirection(e.Address) & EndpointDirectionMask
|
||||
}
|
||||
|
||||
func (e EndpointInfo) String() string {
|
||||
|
@@ -21,33 +21,33 @@ import "C"
|
||||
type Class uint8
|
||||
|
||||
const (
|
||||
CLASS_PER_INTERFACE Class = C.LIBUSB_CLASS_PER_INTERFACE
|
||||
CLASS_AUDIO Class = C.LIBUSB_CLASS_AUDIO
|
||||
CLASS_COMM Class = C.LIBUSB_CLASS_COMM
|
||||
CLASS_HID Class = C.LIBUSB_CLASS_HID
|
||||
CLASS_PRINTER Class = C.LIBUSB_CLASS_PRINTER
|
||||
CLASS_PTP Class = C.LIBUSB_CLASS_PTP
|
||||
CLASS_MASS_STORAGE Class = C.LIBUSB_CLASS_MASS_STORAGE
|
||||
CLASS_HUB Class = C.LIBUSB_CLASS_HUB
|
||||
CLASS_DATA Class = C.LIBUSB_CLASS_DATA
|
||||
CLASS_WIRELESS Class = C.LIBUSB_CLASS_WIRELESS
|
||||
CLASS_APPLICATION Class = C.LIBUSB_CLASS_APPLICATION
|
||||
CLASS_VENDOR_SPEC Class = C.LIBUSB_CLASS_VENDOR_SPEC
|
||||
ClassPerInterface Class = C.LIBUSB_CLASS_PER_INTERFACE
|
||||
ClassAudio Class = C.LIBUSB_CLASS_AUDIO
|
||||
ClassComm Class = C.LIBUSB_CLASS_COMM
|
||||
ClassHID Class = C.LIBUSB_CLASS_HID
|
||||
ClassPrinter Class = C.LIBUSB_CLASS_PRINTER
|
||||
ClassPTP Class = C.LIBUSB_CLASS_PTP
|
||||
ClassMassStorage Class = C.LIBUSB_CLASS_MASS_STORAGE
|
||||
ClassHub Class = C.LIBUSB_CLASS_HUB
|
||||
ClassData Class = C.LIBUSB_CLASS_DATA
|
||||
ClassWireless Class = C.LIBUSB_CLASS_WIRELESS
|
||||
ClassApplication Class = C.LIBUSB_CLASS_APPLICATION
|
||||
ClassVendorSpec Class = C.LIBUSB_CLASS_VENDOR_SPEC
|
||||
)
|
||||
|
||||
var classDescription = map[Class]string{
|
||||
CLASS_PER_INTERFACE: "per-interface",
|
||||
CLASS_AUDIO: "audio",
|
||||
CLASS_COMM: "communications",
|
||||
CLASS_HID: "human interface device",
|
||||
CLASS_PRINTER: "printer dclass",
|
||||
CLASS_PTP: "picture transfer protocol",
|
||||
CLASS_MASS_STORAGE: "mass storage",
|
||||
CLASS_HUB: "hub",
|
||||
CLASS_DATA: "data",
|
||||
CLASS_WIRELESS: "wireless",
|
||||
CLASS_APPLICATION: "application",
|
||||
CLASS_VENDOR_SPEC: "vendor-specific",
|
||||
ClassPerInterface: "per-interface",
|
||||
ClassAudio: "audio",
|
||||
ClassComm: "communications",
|
||||
ClassHID: "human interface device",
|
||||
ClassPrinter: "printer dclass",
|
||||
ClassPTP: "picture transfer protocol",
|
||||
ClassMassStorage: "mass storage",
|
||||
ClassHub: "hub",
|
||||
ClassData: "data",
|
||||
ClassWireless: "wireless",
|
||||
ClassApplication: "application",
|
||||
ClassVendorSpec: "vendor-specific",
|
||||
}
|
||||
|
||||
func (c Class) String() string {
|
||||
@@ -57,27 +57,27 @@ func (c Class) String() string {
|
||||
type DescriptorType uint8
|
||||
|
||||
const (
|
||||
DT_DEVICE DescriptorType = C.LIBUSB_DT_DEVICE
|
||||
DT_CONFIG DescriptorType = C.LIBUSB_DT_CONFIG
|
||||
DT_STRING DescriptorType = C.LIBUSB_DT_STRING
|
||||
DT_INTERFACE DescriptorType = C.LIBUSB_DT_INTERFACE
|
||||
DT_ENDPOINT DescriptorType = C.LIBUSB_DT_ENDPOINT
|
||||
DT_HID DescriptorType = C.LIBUSB_DT_HID
|
||||
DT_REPORT DescriptorType = C.LIBUSB_DT_REPORT
|
||||
DT_PHYSICAL DescriptorType = C.LIBUSB_DT_PHYSICAL
|
||||
DT_HUB DescriptorType = C.LIBUSB_DT_HUB
|
||||
DescriptorTypeDevice DescriptorType = C.LIBUSB_DT_DEVICE
|
||||
DescriptorTypeConfig DescriptorType = C.LIBUSB_DT_CONFIG
|
||||
DescriptorTypeString DescriptorType = C.LIBUSB_DT_STRING
|
||||
DescriptorTypeInterface DescriptorType = C.LIBUSB_DT_INTERFACE
|
||||
DescriptorTypeEndpoint DescriptorType = C.LIBUSB_DT_ENDPOINT
|
||||
DescriptorTypeHID DescriptorType = C.LIBUSB_DT_HID
|
||||
DescriptorTypeReport DescriptorType = C.LIBUSB_DT_REPORT
|
||||
DescriptorTypePhysical DescriptorType = C.LIBUSB_DT_PHYSICAL
|
||||
DescriptorTypeHub DescriptorType = C.LIBUSB_DT_HUB
|
||||
)
|
||||
|
||||
var descriptorTypeDescription = map[DescriptorType]string{
|
||||
DT_DEVICE: "device",
|
||||
DT_CONFIG: "configuration",
|
||||
DT_STRING: "string",
|
||||
DT_INTERFACE: "interface",
|
||||
DT_ENDPOINT: "endpoint",
|
||||
DT_HID: "HID",
|
||||
DT_REPORT: "HID report",
|
||||
DT_PHYSICAL: "physical",
|
||||
DT_HUB: "hub",
|
||||
DescriptorTypeDevice: "device",
|
||||
DescriptorTypeConfig: "configuration",
|
||||
DescriptorTypeString: "string",
|
||||
DescriptorTypeInterface: "interface",
|
||||
DescriptorTypeEndpoint: "endpoint",
|
||||
DescriptorTypeHID: "HID",
|
||||
DescriptorTypeReport: "HID report",
|
||||
DescriptorTypePhysical: "physical",
|
||||
DescriptorTypeHub: "hub",
|
||||
}
|
||||
|
||||
func (dt DescriptorType) String() string {
|
||||
@@ -87,15 +87,15 @@ func (dt DescriptorType) String() string {
|
||||
type EndpointDirection uint8
|
||||
|
||||
const (
|
||||
ENDPOINT_NUM_MASK = 0x0f
|
||||
ENDPOINT_DIR_IN EndpointDirection = C.LIBUSB_ENDPOINT_IN
|
||||
ENDPOINT_DIR_OUT EndpointDirection = C.LIBUSB_ENDPOINT_OUT
|
||||
ENDPOINT_DIR_MASK EndpointDirection = 0x80
|
||||
EndpointNumMask = 0x0f
|
||||
EndpointDirectionMask = 0x80
|
||||
EndpointDirectionIn EndpointDirection = C.LIBUSB_ENDPOINT_IN
|
||||
EndpointDirectionOut EndpointDirection = C.LIBUSB_ENDPOINT_OUT
|
||||
)
|
||||
|
||||
var endpointDirectionDescription = map[EndpointDirection]string{
|
||||
ENDPOINT_DIR_IN: "IN",
|
||||
ENDPOINT_DIR_OUT: "OUT",
|
||||
EndpointDirectionIn: "IN",
|
||||
EndpointDirectionOut: "OUT",
|
||||
}
|
||||
|
||||
func (ed EndpointDirection) String() string {
|
||||
|
@@ -31,7 +31,7 @@ type Endpoint struct {
|
||||
}
|
||||
|
||||
func (e *Endpoint) Read(buf []byte) (int, error) {
|
||||
if EndpointDirection(e.Address)&ENDPOINT_DIR_MASK != ENDPOINT_DIR_IN {
|
||||
if EndpointDirection(e.Address)&EndpointDirectionMask != EndpointDirectionIn {
|
||||
return 0, fmt.Errorf("usb: read: not an IN endpoint")
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ func (e *Endpoint) Read(buf []byte) (int, error) {
|
||||
}
|
||||
|
||||
func (e *Endpoint) Write(buf []byte) (int, error) {
|
||||
if EndpointDirection(e.Address)&ENDPOINT_DIR_MASK != ENDPOINT_DIR_OUT {
|
||||
if EndpointDirection(e.Address)&EndpointDirectionMask != EndpointDirectionOut {
|
||||
return 0, fmt.Errorf("usb: write: not an OUT endpoint")
|
||||
}
|
||||
|
||||
|
@@ -25,7 +25,7 @@ var testBulkInEP = EndpointInfo{
|
||||
var testBulkInSetup = InterfaceSetup{
|
||||
Number: 0,
|
||||
Alternate: 0,
|
||||
IfClass: uint8(CLASS_VENDOR_SPEC),
|
||||
IfClass: uint8(ClassVendorSpec),
|
||||
Endpoints: []EndpointInfo{testBulkInEP},
|
||||
}
|
||||
|
||||
@@ -41,6 +41,6 @@ var testIsoOutEP = EndpointInfo{
|
||||
var testIsoOutSetup = InterfaceSetup{
|
||||
Number: 0,
|
||||
Alternate: 0,
|
||||
IfClass: uint8(CLASS_VENDOR_SPEC),
|
||||
IfClass: uint8(ClassVendorSpec),
|
||||
Endpoints: []EndpointInfo{testIsoOutEP},
|
||||
}
|
||||
|
@@ -44,13 +44,13 @@ var (
|
||||
Setups: []InterfaceSetup{{
|
||||
Number: 0,
|
||||
Alternate: 0,
|
||||
IfClass: uint8(CLASS_VENDOR_SPEC),
|
||||
IfClass: uint8(ClassVendorSpec),
|
||||
Endpoints: []EndpointInfo{{
|
||||
Address: uint8(0x01 | ENDPOINT_DIR_OUT),
|
||||
Address: uint8(0x01 | EndpointDirectionOut),
|
||||
Attributes: uint8(TRANSFER_TYPE_BULK),
|
||||
MaxPacketSize: 512,
|
||||
}, {
|
||||
Address: uint8(0x02 | ENDPOINT_DIR_IN),
|
||||
Address: uint8(0x02 | EndpointDirectionIn),
|
||||
Attributes: uint8(TRANSFER_TYPE_BULK),
|
||||
MaxPacketSize: 512,
|
||||
}},
|
||||
@@ -78,21 +78,21 @@ var (
|
||||
Setups: []InterfaceSetup{{
|
||||
Number: 0,
|
||||
Alternate: 0,
|
||||
IfClass: uint8(CLASS_VENDOR_SPEC),
|
||||
IfClass: uint8(ClassVendorSpec),
|
||||
}},
|
||||
}, {
|
||||
Number: 1,
|
||||
Setups: []InterfaceSetup{{
|
||||
Number: 1,
|
||||
Alternate: 0,
|
||||
IfClass: uint8(CLASS_VENDOR_SPEC),
|
||||
IfClass: uint8(ClassVendorSpec),
|
||||
Endpoints: []EndpointInfo{{
|
||||
Address: uint8(0x05 | ENDPOINT_DIR_OUT),
|
||||
Address: uint8(0x05 | EndpointDirectionOut),
|
||||
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
|
||||
MaxPacketSize: 2<<11 | 1024,
|
||||
MaxIsoPacket: 3 * 1024,
|
||||
}, {
|
||||
Address: uint8(0x06 | ENDPOINT_DIR_IN),
|
||||
Address: uint8(0x06 | EndpointDirectionIn),
|
||||
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
|
||||
MaxPacketSize: 2<<11 | 1024,
|
||||
MaxIsoPacket: 3 * 1024,
|
||||
@@ -100,14 +100,14 @@ var (
|
||||
}, {
|
||||
Number: 1,
|
||||
Alternate: 1,
|
||||
IfClass: uint8(CLASS_VENDOR_SPEC),
|
||||
IfClass: uint8(ClassVendorSpec),
|
||||
Endpoints: []EndpointInfo{{
|
||||
Address: uint8(0x05 | ENDPOINT_DIR_OUT),
|
||||
Address: uint8(0x05 | EndpointDirectionOut),
|
||||
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
|
||||
MaxPacketSize: 1<<11 | 1024,
|
||||
MaxIsoPacket: 2 * 1024,
|
||||
}, {
|
||||
Address: uint8(0x06 | ENDPOINT_DIR_IN),
|
||||
Address: uint8(0x06 | EndpointDirectionIn),
|
||||
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
|
||||
MaxPacketSize: 1<<11 | 1024,
|
||||
MaxIsoPacket: 2 * 1024,
|
||||
@@ -115,14 +115,14 @@ var (
|
||||
}, {
|
||||
Number: 1,
|
||||
Alternate: 2,
|
||||
IfClass: uint8(CLASS_VENDOR_SPEC),
|
||||
IfClass: uint8(ClassVendorSpec),
|
||||
Endpoints: []EndpointInfo{{
|
||||
Address: uint8(0x05 | ENDPOINT_DIR_OUT),
|
||||
Address: uint8(0x05 | EndpointDirectionOut),
|
||||
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
|
||||
MaxPacketSize: 1024,
|
||||
MaxIsoPacket: 1024,
|
||||
}, {
|
||||
Address: uint8(0x06 | ENDPOINT_DIR_IN),
|
||||
Address: uint8(0x06 | EndpointDirectionIn),
|
||||
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
|
||||
MaxPacketSize: 1024,
|
||||
MaxIsoPacket: 1024,
|
||||
|
@@ -37,7 +37,7 @@ func TestNewTransfer(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
desc: "bulk in transfer, 512B packets",
|
||||
dir: ENDPOINT_DIR_IN,
|
||||
dir: EndpointDirectionIn,
|
||||
tt: TRANSFER_TYPE_BULK,
|
||||
maxPkt: 512,
|
||||
buf: 1024,
|
||||
@@ -46,7 +46,7 @@ func TestNewTransfer(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "iso out transfer, 3 * 1024B packets",
|
||||
dir: ENDPOINT_DIR_OUT,
|
||||
dir: EndpointDirectionOut,
|
||||
tt: TRANSFER_TYPE_ISOCHRONOUS,
|
||||
maxPkt: 2<<11 + 1024,
|
||||
maxIso: 3 * 1024,
|
||||
|
Reference in New Issue
Block a user