1
|
#include <stdlib.h>
|
2
|
#include <stdio.h>
|
3
|
#include <unistd.h>
|
4
|
#include <string.h>
|
5
|
|
6
|
#include "ausb.h"
|
7
|
|
8
|
#define CJPPA_USB_VENDOR_ID 0x0c4b
|
9
|
#define CJPPA_USB_DEVICE_ID 0x0100
|
10
|
|
11
|
static struct usb_device *find_cj_usbdev(int num)
|
12
|
{
|
13
|
struct usb_bus *busses, *bus;
|
14
|
struct usb_device *dev;
|
15
|
int found = 0;
|
16
|
|
17
|
busses = usb_get_busses();
|
18
|
|
19
|
for (bus = busses; bus; bus = bus->next) {
|
20
|
for (dev = bus->devices; dev; dev = dev->next) {
|
21
|
if (dev->descriptor.idVendor == CJPPA_USB_VENDOR_ID &&
|
22
|
dev->descriptor.idProduct == CJPPA_USB_DEVICE_ID) {
|
23
|
found++;
|
24
|
if (found == num)
|
25
|
return dev;
|
26
|
}
|
27
|
}
|
28
|
}
|
29
|
return NULL;
|
30
|
}
|
31
|
|
32
|
static void int_cb(struct usbdevfs_urb *uurb, void *data)
|
33
|
{
|
34
|
struct ausb_dev_handle *ah = uurb->usercontext;
|
35
|
unsigned char *buffer = uurb->buffer;
|
36
|
int i;
|
37
|
|
38
|
fprintf(stdout, "int_cb() called, ");
|
39
|
|
40
|
ausb_dump_urb(uurb);
|
41
|
|
42
|
for (i = 0; i < uurb->actual_length; i++)
|
43
|
printf("%02x ", buffer[i]);
|
44
|
|
45
|
if (ausb_submit_urb(ah, uurb)) {
|
46
|
fprintf(stderr, "unable to resubmit urb\n");
|
47
|
ausb_close(ah);
|
48
|
exit(1);
|
49
|
}
|
50
|
|
51
|
fflush(stdout);
|
52
|
}
|
53
|
|
54
|
int main(int argc, char **argv)
|
55
|
{
|
56
|
struct usb_device *dev;
|
57
|
struct ausb_dev_handle *ah;
|
58
|
struct usbdevfs_urb *uurb;
|
59
|
char buffer[280];
|
60
|
ausb_init();
|
61
|
|
62
|
uurb = malloc(sizeof(*uurb));
|
63
|
|
64
|
dev = find_cj_usbdev(1);
|
65
|
|
66
|
if (!dev) {
|
67
|
fprintf(stderr, "unable to find matching usb device\n");
|
68
|
exit(1);
|
69
|
}
|
70
|
|
71
|
ah = ausb_open(dev);
|
72
|
if (!ah) {
|
73
|
fprintf(stderr, "error while opening usb device\n");
|
74
|
exit(1);
|
75
|
}
|
76
|
|
77
|
if (ausb_claim_interface(ah, 0)) {
|
78
|
fprintf(stderr, "unable to claim interface\n");
|
79
|
ausb_close(ah);
|
80
|
exit(1);
|
81
|
}
|
82
|
|
83
|
if (usb_set_configuration(ah->uh, 1)) {
|
84
|
fprintf(stderr, "unable to set configuration 1\n");
|
85
|
ausb_close(ah);
|
86
|
exit(1);
|
87
|
}
|
88
|
|
89
|
ausb_register_callback(ah, USBDEVFS_URB_TYPE_INTERRUPT, &int_cb, ah);
|
90
|
|
91
|
#if 1
|
92
|
ausb_fill_int_urb(uurb, 0x81, buffer, sizeof(buffer));
|
93
|
if (ausb_submit_urb(ah, uurb)) {
|
94
|
fprintf(stderr, "unable to submit urb\n");
|
95
|
ausb_close(ah);
|
96
|
exit(1);
|
97
|
}
|
98
|
|
99
|
while (1) {
|
100
|
sleep(10);
|
101
|
}
|
102
|
#endif
|
103
|
|
104
|
ausb_close(ah);
|
105
|
|
106
|
exit(0);
|
107
|
}
|