From 36241e869e2a888d8bb002cbee9f20f135738870 Mon Sep 17 00:00:00 2001 From: Sebastian Zagrodzki Date: Mon, 27 Mar 2017 22:29:24 +0200 Subject: [PATCH] more constants --- usb/config.go | 2 +- usb/constants.go | 18 +++++++++--------- usb/endpoint_info_test.go | 4 ++-- usb/fakelibusb_test.go | 16 ++++++++-------- usb/libusb.go | 4 ++-- usb/transfer.go | 4 ++-- usb/transfer_test.go | 6 +++--- 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/usb/config.go b/usb/config.go index 71b547c..0b863fa 100644 --- a/usb/config.go +++ b/usb/config.go @@ -34,7 +34,7 @@ func (e EndpointInfo) Number() int { } func (e EndpointInfo) TransferType() TransferType { - return TransferType(e.Attributes) & TRANSFER_TYPE_MASK + return TransferType(e.Attributes) & TransferTypeMask } func (e EndpointInfo) Direction() EndpointDirection { diff --git a/usb/constants.go b/usb/constants.go index b5cc21e..f78242e 100644 --- a/usb/constants.go +++ b/usb/constants.go @@ -105,18 +105,18 @@ func (ed EndpointDirection) String() string { type TransferType uint8 const ( - TRANSFER_TYPE_CONTROL TransferType = C.LIBUSB_TRANSFER_TYPE_CONTROL - TRANSFER_TYPE_ISOCHRONOUS TransferType = C.LIBUSB_TRANSFER_TYPE_ISOCHRONOUS - TRANSFER_TYPE_BULK TransferType = C.LIBUSB_TRANSFER_TYPE_BULK - TRANSFER_TYPE_INTERRUPT TransferType = C.LIBUSB_TRANSFER_TYPE_INTERRUPT - TRANSFER_TYPE_MASK TransferType = 0x03 + TransferTypeControl TransferType = C.LIBUSB_TRANSFER_TYPE_CONTROL + TransferTypeIsochronous TransferType = C.LIBUSB_TRANSFER_TYPE_ISOCHRONOUS + TransferTypeBulk TransferType = C.LIBUSB_TRANSFER_TYPE_BULK + TransferTypeInterrupt TransferType = C.LIBUSB_TRANSFER_TYPE_INTERRUPT + TransferTypeMask = 0x03 ) var transferTypeDescription = map[TransferType]string{ - TRANSFER_TYPE_CONTROL: "control", - TRANSFER_TYPE_ISOCHRONOUS: "isochronous", - TRANSFER_TYPE_BULK: "bulk", - TRANSFER_TYPE_INTERRUPT: "interrupt", + TransferTypeControl: "control", + TransferTypeIsochronous: "isochronous", + TransferTypeBulk: "bulk", + TransferTypeInterrupt: "interrupt", } func (tt TransferType) String() string { diff --git a/usb/endpoint_info_test.go b/usb/endpoint_info_test.go index fc52b79..45f6f0d 100644 --- a/usb/endpoint_info_test.go +++ b/usb/endpoint_info_test.go @@ -17,7 +17,7 @@ package usb // IN bulk endpoint var testBulkInEP = EndpointInfo{ Address: 0x82, - Attributes: uint8(TRANSFER_TYPE_BULK), + Attributes: uint8(TransferTypeBulk), MaxPacketSize: 512, PollInterval: 1, } @@ -32,7 +32,7 @@ var testBulkInSetup = InterfaceSetup{ // OUT iso endpoint var testIsoOutEP = EndpointInfo{ Address: 0x06, - Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS), + Attributes: uint8(TransferTypeIsochronous), MaxPacketSize: 3<<11 + 1024, MaxIsoPacket: 3 * 1024, PollInterval: 1, diff --git a/usb/fakelibusb_test.go b/usb/fakelibusb_test.go index 2f52aa8..e251bd1 100644 --- a/usb/fakelibusb_test.go +++ b/usb/fakelibusb_test.go @@ -47,11 +47,11 @@ var ( IfClass: uint8(ClassVendorSpec), Endpoints: []EndpointInfo{{ Address: uint8(0x01 | EndpointDirectionOut), - Attributes: uint8(TRANSFER_TYPE_BULK), + Attributes: uint8(TransferTypeBulk), MaxPacketSize: 512, }, { Address: uint8(0x02 | EndpointDirectionIn), - Attributes: uint8(TRANSFER_TYPE_BULK), + Attributes: uint8(TransferTypeBulk), MaxPacketSize: 512, }}, }}, @@ -88,12 +88,12 @@ var ( IfClass: uint8(ClassVendorSpec), Endpoints: []EndpointInfo{{ Address: uint8(0x05 | EndpointDirectionOut), - Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS), + Attributes: uint8(TransferTypeIsochronous), MaxPacketSize: 2<<11 | 1024, MaxIsoPacket: 3 * 1024, }, { Address: uint8(0x06 | EndpointDirectionIn), - Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS), + Attributes: uint8(TransferTypeIsochronous), MaxPacketSize: 2<<11 | 1024, MaxIsoPacket: 3 * 1024, }}, @@ -103,12 +103,12 @@ var ( IfClass: uint8(ClassVendorSpec), Endpoints: []EndpointInfo{{ Address: uint8(0x05 | EndpointDirectionOut), - Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS), + Attributes: uint8(TransferTypeIsochronous), MaxPacketSize: 1<<11 | 1024, MaxIsoPacket: 2 * 1024, }, { Address: uint8(0x06 | EndpointDirectionIn), - Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS), + Attributes: uint8(TransferTypeIsochronous), MaxPacketSize: 1<<11 | 1024, MaxIsoPacket: 2 * 1024, }}, @@ -118,12 +118,12 @@ var ( IfClass: uint8(ClassVendorSpec), Endpoints: []EndpointInfo{{ Address: uint8(0x05 | EndpointDirectionOut), - Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS), + Attributes: uint8(TransferTypeIsochronous), MaxPacketSize: 1024, MaxIsoPacket: 1024, }, { Address: uint8(0x06 | EndpointDirectionIn), - Attributes: uint8(TRANSFER_TYPE_ISOCHRONOUS), + Attributes: uint8(TransferTypeIsochronous), MaxPacketSize: 1024, MaxIsoPacket: 1024, }}, diff --git a/usb/libusb.go b/usb/libusb.go index c991ae6..f88f079 100644 --- a/usb/libusb.go +++ b/usb/libusb.go @@ -193,7 +193,7 @@ func (libusbImpl) getDeviceDesc(d *libusbDevice) (*Descriptor, error) { RefreshRate: uint8(end.bRefresh), SynchAddress: uint8(end.bSynchAddress), } - if ei.TransferType() == TRANSFER_TYPE_ISOCHRONOUS { + if ei.TransferType() == TransferTypeIsochronous { // bits 0-10 identify the packet size, bits 11-12 are the number of additional transactions per microframe. // Don't use libusb_get_max_iso_packet_size, as it has a bug where it returns the same value // regardless of alternative setting used, where different alternative settings might define different @@ -338,7 +338,7 @@ func (libusbImpl) submit(t *libusbTransfer, done chan struct{}) error { } func (libusbImpl) data(t *libusbTransfer) (int, TransferStatus) { - if TransferType(t._type) == TRANSFER_TYPE_ISOCHRONOUS { + if TransferType(t._type) == TransferTypeIsochronous { var status TransferStatus n := int(C.compact_iso_data((*C.struct_libusb_transfer)(t), (*C.uchar)(unsafe.Pointer(&status)))) return n, status diff --git a/usb/transfer.go b/usb/transfer.go index 4e783ae..cd42048 100644 --- a/usb/transfer.go +++ b/usb/transfer.go @@ -115,7 +115,7 @@ func (t *usbTransfer) free() error { func newUSBTransfer(dev *libusbDevHandle, ei EndpointInfo, buf []byte, timeout time.Duration) (*usbTransfer, error) { var isoPackets int tt := ei.TransferType() - if tt == TRANSFER_TYPE_ISOCHRONOUS { + if tt == TransferTypeIsochronous { isoPackets = len(buf) / int(ei.MaxIsoPacket) if int(ei.MaxIsoPacket)*isoPackets < len(buf) { isoPackets++ @@ -127,7 +127,7 @@ func newUSBTransfer(dev *libusbDevHandle, ei EndpointInfo, buf []byte, timeout t return nil, err } - if tt == TRANSFER_TYPE_ISOCHRONOUS { + if tt == TransferTypeIsochronous { libusb.setIsoPacketLengths(xfer, ei.MaxIsoPacket) } diff --git a/usb/transfer_test.go b/usb/transfer_test.go index 23452f1..6e13ae6 100644 --- a/usb/transfer_test.go +++ b/usb/transfer_test.go @@ -38,7 +38,7 @@ func TestNewTransfer(t *testing.T) { { desc: "bulk in transfer, 512B packets", dir: EndpointDirectionIn, - tt: TRANSFER_TYPE_BULK, + tt: TransferTypeBulk, maxPkt: 512, buf: 1024, timeout: time.Second, @@ -47,7 +47,7 @@ func TestNewTransfer(t *testing.T) { { desc: "iso out transfer, 3 * 1024B packets", dir: EndpointDirectionOut, - tt: TRANSFER_TYPE_ISOCHRONOUS, + tt: TransferTypeIsochronous, maxPkt: 2<<11 + 1024, maxIso: 3 * 1024, buf: 10000, @@ -82,7 +82,7 @@ func TestTransferProtocol(t *testing.T) { for i := 0; i < 2; i++ { xfers[i], err = newUSBTransfer(nil, EndpointInfo{ Address: 0x86, - Attributes: uint8(TRANSFER_TYPE_BULK), + Attributes: uint8(TransferTypeBulk), MaxPacketSize: 512, PollInterval: 1, }, make([]byte, 10240), time.Second)