Commit Graph

314 Commits

Author SHA1 Message Date
Sebastian Zagrodzki
730c32b9fd Add tests for endpoint NewStream.
Rename OpenWithVidPid to OpenWithVIDPID.
2017-04-29 12:57:55 +02:00
Sebastian Zagrodzki
58c1e6ddb4 add tests for active config and reset 2017-04-29 12:23:45 +02:00
Sebastian Zagrodzki
2794d88744 config is %d, not %s 2017-04-29 12:21:17 +02:00
Sebastian Zagrodzki
6d81ca37d3 Use a map to store endpoint descriptors. Allows easy access to a
particular endpoint number.
2017-04-29 12:19:34 +02:00
Sebastian Zagrodzki
77c176cd4c Replace descriptor Configs with a map - config ids are arbitrary numbers
(unlike interface or alt setting numbers, which are 0-based array indices).
This makes it easier to access a particular config without having to
iterate over the descriptors.
2017-04-29 11:56:49 +02:00
Sebastian Zagrodzki
60d0aba507 Use int for Bus/Addr, not uint8. 2017-04-29 02:12:04 +02:00
Sebastian Zagrodzki
541275d5b9 update error message to be more verbose 2017-04-29 01:37:39 +02:00
Sebastian Zagrodzki
b39b8d9521 Add "empty" to confirm no transfers are in flight in fakeusb.
Update endpoint_test - if buffer length is 0, no transfer is submitted.
2017-04-29 01:35:09 +02:00
Sebastian Zagrodzki
c2d1a4c03d Format bus/addr with a dot. 2017-04-29 01:00:19 +02:00
Sebastian Zagrodzki
ef59587a24 move descriptor to the device, like config and interface.
Clear separation between descriptor stringers and value stringers for
the device and interface.
2017-04-29 00:59:13 +02:00
Sebastian Zagrodzki
59b493ec3c Separate descriptor Stringer from value Stringer. 2017-04-29 00:53:42 +02:00
Sebastian Zagrodzki
a69a315dbd Verify that interface and alternate numbers are 0-based indices, we rely
on this assumption in the config.
2017-04-29 00:50:38 +02:00
Sebastian Zagrodzki
80f3c60b2b Better error messages.
Update rawread to use the new endpoint interface.
2017-04-29 00:41:26 +02:00
Sebastian Zagrodzki
1fd4e7f4c4 Check if the device is already closed and if the interface is already
claimed.
2017-04-29 00:27:51 +02:00
Sebastian Zagrodzki
0cfaee3514 Fail operations if Close was called before. 2017-04-29 00:18:26 +02:00
Sebastian Zagrodzki
b6268be76b Merge branch 'gousb2.0-dev' of https://github.com/kylelemons/gousb into gousb2.0-dev 2017-04-29 00:04:01 +02:00
Sebastian Zagrodzki
5f122b4dcd Introduce two more layers between device and endpoint:
device -> active config -> claimed interface -> endpoints.
Device can have at most one active config. A config can have
multiple claimed interfaces, each with a specific alt setting.
An interface with an alt setting defines a list of endpoints.
2017-04-29 00:01:11 +02:00
Sebastian Zagrodzki
d193e605a4 fix extra Logf arguments 2017-04-28 23:58:56 +02:00
Sebastian Zagrodzki
5c63741f14 more readable debug log prefix 2017-04-28 23:58:16 +02:00
Sebastian Zagrodzki
26b662893d Use a new behavior of newFakeLibusb.
Add a benchmark for subslicing.
2017-04-27 03:26:08 +02:00
Sebastian Zagrodzki
d85a738414 a new fakelibusb will overwrite libusb and restore it automatically on
done()
2017-04-27 03:25:36 +02:00
Sebastian Zagrodzki
d5a8179068 Exit libusb context when done. 2017-04-27 03:12:47 +02:00
Sebastian Zagrodzki
462651f20f use the new fakeTransferPointer function to allocate a fake transfer
struct.
2017-04-27 03:12:25 +02:00
Sebastian Zagrodzki
b9dabf4da9 Add a method to return a fake allocated transfer. 2017-04-27 03:12:06 +02:00
Sebastian Zagrodzki
76df46148e Fix typo in log args. 2017-04-27 03:11:36 +02:00
Sebastian Zagrodzki
7ee11b48c5 Close the Context 2017-04-27 03:01:35 +02:00
Sebastian Zagrodzki
60ee821dd6 Close the Context 2017-04-27 03:01:20 +02:00
Sebastian Zagrodzki
2bcc25f8d0 Close the Context 2017-04-27 03:01:10 +02:00
Sebastian Zagrodzki
a1b915080e Close returns error, to satisfy the io.Closer interface. 2017-04-27 02:48:43 +02:00
Sebastian Zagrodzki
76f4548b85 Add info about concurrency safety for stream. 2017-04-26 22:49:37 +02:00
Sebastian Zagrodzki
6c9e76f578 s/USB involving/USB transfers involving/ 2017-04-26 22:27:46 +02:00
Sebastian Zagrodzki
93355e7490 replace uint32 in MaxPacketSize with int 2017-04-26 22:27:12 +02:00
Sebastian Zagrodzki
22ff844a3d s/DeviceSpeed/Speed/ 2017-04-26 22:24:46 +02:00
Sebastian Zagrodzki
6c60468e06 Update to use ints instead of uint8s 2017-04-26 22:23:58 +02:00
Sebastian Zagrodzki
83276566fc Replace uint8 with Go-idiomatic int, where it makes sense. 2017-04-26 22:22:07 +02:00
Sebastian Zagrodzki
a55abe9076 Disable Write streams for now. 2017-04-26 21:51:00 +02:00
Sebastian Zagrodzki
cdd4223813 Handle a case where transfers channel was not closed properly. 2017-04-26 21:50:10 +02:00
Sebastian Zagrodzki
ae8627a890 update tests with the new "transfer done" logic. 2017-04-26 21:40:51 +02:00
Sebastian Zagrodzki
fbd26497e6 NewStream takes int now. 2017-04-26 21:36:14 +02:00
Sebastian Zagrodzki
eed8b77a16 NewStream takes int now. 2017-04-26 21:35:50 +02:00
Sebastian Zagrodzki
eed6d08423 Re-use the same done channel for every callback of a single transfer. 2017-04-26 21:35:26 +02:00
Sebastian Zagrodzki
c1009ed25d Call back to Go function directly, it will know how to deal with an xfer
pointer.
2017-04-26 21:33:45 +02:00
Sebastian Zagrodzki
550fe8d1f2 Introduce xferMap, avoid passing Go pointer into the C code.
Weirdness with memory barriers.
2017-04-26 21:32:49 +02:00
Sebastian Zagrodzki
dacae32d83 Tests for read transfers, starting on write transfers. 2017-04-23 22:58:30 +02:00
Sebastian Zagrodzki
b50bc8761f First version of streaming transfers. 2017-04-23 10:45:04 +02:00
Sebastian Zagrodzki
d92ea14c33 Add a test to catch invalud endpoint info. 2017-04-10 03:25:32 +02:00
Sebastian Zagrodzki
9cecdec977 Fix a bug where EndpointInfo would always be picked from the last
alternative setting.

When looking up matching EndpointInfo and InterfaceSetting for
an endpoint, a reference to range variable is stored. If range is
allowed to continue, the value of this variable will be updated.
It's a trick to allow use of "nil" pointer as a "found" variable, but it
requires a careful management of the range iterations.
2017-04-10 03:16:59 +02:00
Sebastian Zagrodzki
b0d5519c67 Change the iso packet size if the buffer is very small.
Previously number of iso packets could have amounted to a transfer
buffer larger than passed buffer, which could lead to overflow.

Now the number of bytes requested from device is always smaller or equal
to the buffer size.

In theory, it could lead to inefficiencies in transfer: if max packet
size is 1024 and user request 2046 bytes of data, transfer will return at most
1024 bytes, while it could use a more efficient 2 packets of 1023 bytes.
But at least it's correct now. It seems that for efficiency the user would
always use the reported max packet size anyway.

The device could still send more data than requested, but libusb takes
care of it.
2017-04-10 02:45:16 +02:00
Sebastian Zagrodzki
961f271746 rename setup to alternate, print endpoint description first. 2017-04-10 02:44:23 +02:00
Sebastian Zagrodzki
5efb68e45e iota used on the second line of const block starts from 1, not from 0... 2017-04-10 01:41:36 +02:00