main.c
2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "libusb_wrapper.h"
#include <stdio.h>
#include <string.h>
#define VID 1003
#define PID 8259
int main(int argc, char *argv[]){
printf("Hello World :-|\n");
libusb_context *context;
usbinit(&context);
#ifdef DEBUG
libusb_set_option(context, LIBUSB_OPTION_LOG_LEVEL, LIBUSB_LOG_LEVEL_DEBUG);
#endif
if(argc>1){
//command mode
if(strcmp(argv[1], "demo4.1") == 0) { //if 4.1
printf("\e[91mDemo 4.1\e[39m\n");
displayDevices(context);
}
else if(strcmp(argv[1], "demo4.1plus") == 0) { //if 4.1 bonus
printf("\e[91mDemo 4.1\e[39m\n");
displayDevicesMore(context);
}
else if(strcmp(argv[1], "demo4.2") == 0){//if 4.2
printf("\e[91mDemo 4.2\e[39m\n");
if(argc > 3){
uint16_t vendor_id;
uint16_t product_id;
sscanf(argv[2], "%hu", &vendor_id);
sscanf(argv[3], "%hu", &product_id);
libusb_device_handle* handle;
handle = libusb_open_device_with_vid_pid(context, vendor_id, product_id);
if(handle != NULL){
printf("Show endpoints of VID:%hu;PID:%hu\n", vendor_id, product_id);
displayDeviceEndpoints(handle);
}
else{
printf("Error while getting handle of VID:%hu;PID:%hu\n", vendor_id, product_id);
}
}else{
printf("Error, need VID and PID\n");
}
}else{
printf("Wrong command\n");
}
}else{
//interactive mode
printf("Welcome to interactive mode\n");
printf("Compiled for VID:PID => %d:%d\n", VID, PID);
//Find the device
printf("Iterate list of devices, and getting the right one\n");
libusb_device *device = NULL;
getFirstDeviceFromID(context, VID, PID, &device);
//code
if(device==NULL){
printf("Error : cannot find the device !\n");
return 1;
}
//Take the interfaces
printf("Finished\n");
}
usbclose(context);
return 0;
}