1 | --- io/hpiod/device.cpp.orig 2006-03-02 19:07:26.000000000 -0500 |
---|
2 | +++ io/hpiod/device.cpp 2006-04-27 15:47:38.000000000 -0400 |
---|
3 | @@ -99,14 +99,62 @@ |
---|
4 | |
---|
5 | int Device::Write(int fd, const void *buf, int size) |
---|
6 | { |
---|
7 | - syslog(LOG_ERR, "error Write: unimplemented (osx) %s %s %d\n", URI, __FILE__, __LINE__); |
---|
8 | - return -1; |
---|
9 | + int r, ep; |
---|
10 | + |
---|
11 | + if (FD[fd].pHD == NULL) |
---|
12 | + { |
---|
13 | + syslog(LOG_ERR, "invalid Device::Write state (osx): %s %s %d\n", URI,__FILE__, __LINE__); |
---|
14 | + return r; |
---|
15 | + } |
---|
16 | + |
---|
17 | + if ((ep = GetOutEP(dev, FD[fd].Config, FD[fd].Interface, FD[fd].AltSetting, USB_ENDPOINT_TYPE_BULK)) < 0) |
---|
18 | + { |
---|
19 | + syslog(LOG_ERR, "invalid bulk out endpoint (osx) %s %s %d\n", URI, __FILE__, __LINE__); |
---|
20 | + return r; |
---|
21 | + } |
---|
22 | + |
---|
23 | + r = usb_bulk_write(FD[fd].pHD, ep, (char *)buf, size, LIBUSB_TIMEOUT); |
---|
24 | + |
---|
25 | + if (r < 0) |
---|
26 | + { |
---|
27 | + syslog(LOG_ERR, "error Write (osx) %s: %s %d\n", URI, __FILE__, __LINE__); |
---|
28 | + return r; |
---|
29 | + } |
---|
30 | + |
---|
31 | + return r; |
---|
32 | } |
---|
33 | |
---|
34 | int Device::Read(int fd, void *buf, int size, int usec) |
---|
35 | { |
---|
36 | - syslog(LOG_ERR, "error Read: unimplemented (osx) %s %s %d\n", URI, __FILE__, __LINE__); |
---|
37 | - return -2; |
---|
38 | + int r, ep; |
---|
39 | + |
---|
40 | + if (FD[fd].pHD == NULL) |
---|
41 | + { |
---|
42 | + syslog(LOG_ERR, "invalid Device::Read state (osx): %s %s %d\n", URI,__FILE__, __LINE__); |
---|
43 | + return -1; |
---|
44 | + } |
---|
45 | + |
---|
46 | + if ((ep = GetInEP(dev, FD[fd].Config, FD[fd].Interface, FD[fd].AltSetting, USB_ENDPOINT_TYPE_BULK)) < 0) |
---|
47 | + { |
---|
48 | + syslog(LOG_ERR, "invalid bulk in endpoint (osx) %s %s %d\n", URI, __FILE__, __LINE__); |
---|
49 | + return -1; |
---|
50 | + } |
---|
51 | + |
---|
52 | + r = usb_bulk_read(FD[fd].pHD, ep, (char *)buf, size, usec/1000); |
---|
53 | + |
---|
54 | + if (r < 0) |
---|
55 | + { |
---|
56 | + syslog(LOG_ERR, "error Read (osx) %s: %s %d\n", URI, __FILE__, __LINE__); |
---|
57 | + return r; |
---|
58 | + } |
---|
59 | + |
---|
60 | + if (r != size) |
---|
61 | + { |
---|
62 | + syslog(LOG_ERR, "error Read (osx) %s: %s %d\n", URI, __FILE__, __LINE__); |
---|
63 | + return -1; |
---|
64 | + } |
---|
65 | + |
---|
66 | + return r; |
---|
67 | } |
---|
68 | |
---|
69 | #else |
---|