start renaming the constants to Go-style.

This commit is contained in:
Sebastian Zagrodzki
2017-03-27 22:23:47 +02:00
parent 341fde410e
commit b70848cf73
7 changed files with 70 additions and 70 deletions

View File

@@ -163,7 +163,7 @@ func main() {
} }
log.Printf("Connecting to endpoint %d...", *endpoint) 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 { if err != nil {
log.Fatalf("open: %s", err) log.Fatalf("open: %s", err)
} }

View File

@@ -30,7 +30,7 @@ type EndpointInfo struct {
} }
func (e EndpointInfo) Number() int { func (e EndpointInfo) Number() int {
return int(e.Address) & ENDPOINT_NUM_MASK return int(e.Address) & EndpointNumMask
} }
func (e EndpointInfo) TransferType() TransferType { func (e EndpointInfo) TransferType() TransferType {
@@ -38,7 +38,7 @@ func (e EndpointInfo) TransferType() TransferType {
} }
func (e EndpointInfo) Direction() EndpointDirection { func (e EndpointInfo) Direction() EndpointDirection {
return EndpointDirection(e.Address) & ENDPOINT_DIR_MASK return EndpointDirection(e.Address) & EndpointDirectionMask
} }
func (e EndpointInfo) String() string { func (e EndpointInfo) String() string {

View File

@@ -21,33 +21,33 @@ import "C"
type Class uint8 type Class uint8
const ( const (
CLASS_PER_INTERFACE Class = C.LIBUSB_CLASS_PER_INTERFACE ClassPerInterface Class = C.LIBUSB_CLASS_PER_INTERFACE
CLASS_AUDIO Class = C.LIBUSB_CLASS_AUDIO ClassAudio Class = C.LIBUSB_CLASS_AUDIO
CLASS_COMM Class = C.LIBUSB_CLASS_COMM ClassComm Class = C.LIBUSB_CLASS_COMM
CLASS_HID Class = C.LIBUSB_CLASS_HID ClassHID Class = C.LIBUSB_CLASS_HID
CLASS_PRINTER Class = C.LIBUSB_CLASS_PRINTER ClassPrinter Class = C.LIBUSB_CLASS_PRINTER
CLASS_PTP Class = C.LIBUSB_CLASS_PTP ClassPTP Class = C.LIBUSB_CLASS_PTP
CLASS_MASS_STORAGE Class = C.LIBUSB_CLASS_MASS_STORAGE ClassMassStorage Class = C.LIBUSB_CLASS_MASS_STORAGE
CLASS_HUB Class = C.LIBUSB_CLASS_HUB ClassHub Class = C.LIBUSB_CLASS_HUB
CLASS_DATA Class = C.LIBUSB_CLASS_DATA ClassData Class = C.LIBUSB_CLASS_DATA
CLASS_WIRELESS Class = C.LIBUSB_CLASS_WIRELESS ClassWireless Class = C.LIBUSB_CLASS_WIRELESS
CLASS_APPLICATION Class = C.LIBUSB_CLASS_APPLICATION ClassApplication Class = C.LIBUSB_CLASS_APPLICATION
CLASS_VENDOR_SPEC Class = C.LIBUSB_CLASS_VENDOR_SPEC ClassVendorSpec Class = C.LIBUSB_CLASS_VENDOR_SPEC
) )
var classDescription = map[Class]string{ var classDescription = map[Class]string{
CLASS_PER_INTERFACE: "per-interface", ClassPerInterface: "per-interface",
CLASS_AUDIO: "audio", ClassAudio: "audio",
CLASS_COMM: "communications", ClassComm: "communications",
CLASS_HID: "human interface device", ClassHID: "human interface device",
CLASS_PRINTER: "printer dclass", ClassPrinter: "printer dclass",
CLASS_PTP: "picture transfer protocol", ClassPTP: "picture transfer protocol",
CLASS_MASS_STORAGE: "mass storage", ClassMassStorage: "mass storage",
CLASS_HUB: "hub", ClassHub: "hub",
CLASS_DATA: "data", ClassData: "data",
CLASS_WIRELESS: "wireless", ClassWireless: "wireless",
CLASS_APPLICATION: "application", ClassApplication: "application",
CLASS_VENDOR_SPEC: "vendor-specific", ClassVendorSpec: "vendor-specific",
} }
func (c Class) String() string { func (c Class) String() string {
@@ -57,27 +57,27 @@ func (c Class) String() string {
type DescriptorType uint8 type DescriptorType uint8
const ( const (
DT_DEVICE DescriptorType = C.LIBUSB_DT_DEVICE DescriptorTypeDevice DescriptorType = C.LIBUSB_DT_DEVICE
DT_CONFIG DescriptorType = C.LIBUSB_DT_CONFIG DescriptorTypeConfig DescriptorType = C.LIBUSB_DT_CONFIG
DT_STRING DescriptorType = C.LIBUSB_DT_STRING DescriptorTypeString DescriptorType = C.LIBUSB_DT_STRING
DT_INTERFACE DescriptorType = C.LIBUSB_DT_INTERFACE DescriptorTypeInterface DescriptorType = C.LIBUSB_DT_INTERFACE
DT_ENDPOINT DescriptorType = C.LIBUSB_DT_ENDPOINT DescriptorTypeEndpoint DescriptorType = C.LIBUSB_DT_ENDPOINT
DT_HID DescriptorType = C.LIBUSB_DT_HID DescriptorTypeHID DescriptorType = C.LIBUSB_DT_HID
DT_REPORT DescriptorType = C.LIBUSB_DT_REPORT DescriptorTypeReport DescriptorType = C.LIBUSB_DT_REPORT
DT_PHYSICAL DescriptorType = C.LIBUSB_DT_PHYSICAL DescriptorTypePhysical DescriptorType = C.LIBUSB_DT_PHYSICAL
DT_HUB DescriptorType = C.LIBUSB_DT_HUB DescriptorTypeHub DescriptorType = C.LIBUSB_DT_HUB
) )
var descriptorTypeDescription = map[DescriptorType]string{ var descriptorTypeDescription = map[DescriptorType]string{
DT_DEVICE: "device", DescriptorTypeDevice: "device",
DT_CONFIG: "configuration", DescriptorTypeConfig: "configuration",
DT_STRING: "string", DescriptorTypeString: "string",
DT_INTERFACE: "interface", DescriptorTypeInterface: "interface",
DT_ENDPOINT: "endpoint", DescriptorTypeEndpoint: "endpoint",
DT_HID: "HID", DescriptorTypeHID: "HID",
DT_REPORT: "HID report", DescriptorTypeReport: "HID report",
DT_PHYSICAL: "physical", DescriptorTypePhysical: "physical",
DT_HUB: "hub", DescriptorTypeHub: "hub",
} }
func (dt DescriptorType) String() string { func (dt DescriptorType) String() string {
@@ -87,15 +87,15 @@ func (dt DescriptorType) String() string {
type EndpointDirection uint8 type EndpointDirection uint8
const ( const (
ENDPOINT_NUM_MASK = 0x0f EndpointNumMask = 0x0f
ENDPOINT_DIR_IN EndpointDirection = C.LIBUSB_ENDPOINT_IN EndpointDirectionMask = 0x80
ENDPOINT_DIR_OUT EndpointDirection = C.LIBUSB_ENDPOINT_OUT EndpointDirectionIn EndpointDirection = C.LIBUSB_ENDPOINT_IN
ENDPOINT_DIR_MASK EndpointDirection = 0x80 EndpointDirectionOut EndpointDirection = C.LIBUSB_ENDPOINT_OUT
) )
var endpointDirectionDescription = map[EndpointDirection]string{ var endpointDirectionDescription = map[EndpointDirection]string{
ENDPOINT_DIR_IN: "IN", EndpointDirectionIn: "IN",
ENDPOINT_DIR_OUT: "OUT", EndpointDirectionOut: "OUT",
} }
func (ed EndpointDirection) String() string { func (ed EndpointDirection) String() string {

View File

@@ -31,7 +31,7 @@ type Endpoint struct {
} }
func (e *Endpoint) Read(buf []byte) (int, error) { 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") 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) { 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") return 0, fmt.Errorf("usb: write: not an OUT endpoint")
} }

View File

@@ -25,7 +25,7 @@ var testBulkInEP = EndpointInfo{
var testBulkInSetup = InterfaceSetup{ var testBulkInSetup = InterfaceSetup{
Number: 0, Number: 0,
Alternate: 0, Alternate: 0,
IfClass: uint8(CLASS_VENDOR_SPEC), IfClass: uint8(ClassVendorSpec),
Endpoints: []EndpointInfo{testBulkInEP}, Endpoints: []EndpointInfo{testBulkInEP},
} }
@@ -41,6 +41,6 @@ var testIsoOutEP = EndpointInfo{
var testIsoOutSetup = InterfaceSetup{ var testIsoOutSetup = InterfaceSetup{
Number: 0, Number: 0,
Alternate: 0, Alternate: 0,
IfClass: uint8(CLASS_VENDOR_SPEC), IfClass: uint8(ClassVendorSpec),
Endpoints: []EndpointInfo{testIsoOutEP}, Endpoints: []EndpointInfo{testIsoOutEP},
} }

View File

@@ -44,13 +44,13 @@ var (
Setups: []InterfaceSetup{{ Setups: []InterfaceSetup{{
Number: 0, Number: 0,
Alternate: 0, Alternate: 0,
IfClass: uint8(CLASS_VENDOR_SPEC), IfClass: uint8(ClassVendorSpec),
Endpoints: []EndpointInfo{{ Endpoints: []EndpointInfo{{
Address: uint8(0x01 | ENDPOINT_DIR_OUT), Address: uint8(0x01 | EndpointDirectionOut),
Attributes: uint8(TRANSFER_TYPE_BULK), Attributes: uint8(TRANSFER_TYPE_BULK),
MaxPacketSize: 512, MaxPacketSize: 512,
}, { }, {
Address: uint8(0x02 | ENDPOINT_DIR_IN), Address: uint8(0x02 | EndpointDirectionIn),
Attributes: uint8(TRANSFER_TYPE_BULK), Attributes: uint8(TRANSFER_TYPE_BULK),
MaxPacketSize: 512, MaxPacketSize: 512,
}}, }},
@@ -78,21 +78,21 @@ var (
Setups: []InterfaceSetup{{ Setups: []InterfaceSetup{{
Number: 0, Number: 0,
Alternate: 0, Alternate: 0,
IfClass: uint8(CLASS_VENDOR_SPEC), IfClass: uint8(ClassVendorSpec),
}}, }},
}, { }, {
Number: 1, Number: 1,
Setups: []InterfaceSetup{{ Setups: []InterfaceSetup{{
Number: 1, Number: 1,
Alternate: 0, Alternate: 0,
IfClass: uint8(CLASS_VENDOR_SPEC), IfClass: uint8(ClassVendorSpec),
Endpoints: []EndpointInfo{{ Endpoints: []EndpointInfo{{
Address: uint8(0x05 | ENDPOINT_DIR_OUT), Address: uint8(0x05 | EndpointDirectionOut),
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS), Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
MaxPacketSize: 2<<11 | 1024, MaxPacketSize: 2<<11 | 1024,
MaxIsoPacket: 3 * 1024, MaxIsoPacket: 3 * 1024,
}, { }, {
Address: uint8(0x06 | ENDPOINT_DIR_IN), Address: uint8(0x06 | EndpointDirectionIn),
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS), Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
MaxPacketSize: 2<<11 | 1024, MaxPacketSize: 2<<11 | 1024,
MaxIsoPacket: 3 * 1024, MaxIsoPacket: 3 * 1024,
@@ -100,14 +100,14 @@ var (
}, { }, {
Number: 1, Number: 1,
Alternate: 1, Alternate: 1,
IfClass: uint8(CLASS_VENDOR_SPEC), IfClass: uint8(ClassVendorSpec),
Endpoints: []EndpointInfo{{ Endpoints: []EndpointInfo{{
Address: uint8(0x05 | ENDPOINT_DIR_OUT), Address: uint8(0x05 | EndpointDirectionOut),
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS), Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
MaxPacketSize: 1<<11 | 1024, MaxPacketSize: 1<<11 | 1024,
MaxIsoPacket: 2 * 1024, MaxIsoPacket: 2 * 1024,
}, { }, {
Address: uint8(0x06 | ENDPOINT_DIR_IN), Address: uint8(0x06 | EndpointDirectionIn),
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS), Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
MaxPacketSize: 1<<11 | 1024, MaxPacketSize: 1<<11 | 1024,
MaxIsoPacket: 2 * 1024, MaxIsoPacket: 2 * 1024,
@@ -115,14 +115,14 @@ var (
}, { }, {
Number: 1, Number: 1,
Alternate: 2, Alternate: 2,
IfClass: uint8(CLASS_VENDOR_SPEC), IfClass: uint8(ClassVendorSpec),
Endpoints: []EndpointInfo{{ Endpoints: []EndpointInfo{{
Address: uint8(0x05 | ENDPOINT_DIR_OUT), Address: uint8(0x05 | EndpointDirectionOut),
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS), Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
MaxPacketSize: 1024, MaxPacketSize: 1024,
MaxIsoPacket: 1024, MaxIsoPacket: 1024,
}, { }, {
Address: uint8(0x06 | ENDPOINT_DIR_IN), Address: uint8(0x06 | EndpointDirectionIn),
Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS), Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS),
MaxPacketSize: 1024, MaxPacketSize: 1024,
MaxIsoPacket: 1024, MaxIsoPacket: 1024,

View File

@@ -37,7 +37,7 @@ func TestNewTransfer(t *testing.T) {
}{ }{
{ {
desc: "bulk in transfer, 512B packets", desc: "bulk in transfer, 512B packets",
dir: ENDPOINT_DIR_IN, dir: EndpointDirectionIn,
tt: TRANSFER_TYPE_BULK, tt: TRANSFER_TYPE_BULK,
maxPkt: 512, maxPkt: 512,
buf: 1024, buf: 1024,
@@ -46,7 +46,7 @@ func TestNewTransfer(t *testing.T) {
}, },
{ {
desc: "iso out transfer, 3 * 1024B packets", desc: "iso out transfer, 3 * 1024B packets",
dir: ENDPOINT_DIR_OUT, dir: EndpointDirectionOut,
tt: TRANSFER_TYPE_ISOCHRONOUS, tt: TRANSFER_TYPE_ISOCHRONOUS,
maxPkt: 2<<11 + 1024, maxPkt: 2<<11 + 1024,
maxIso: 3 * 1024, maxIso: 3 * 1024,