File: usbread.cpp

package info (click to toggle)
xboxdrv 0.8.4-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,252 kB
  • sloc: cpp: 19,297; xml: 3,202; ansic: 507; python: 483; sh: 89; makefile: 34; ruby: 19
file content (59 lines) | stat: -rw-r--r-- 1,595 bytes parent folder | download | duplicates (3)
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

int main(int argc, char** argv)
{
  srand(time(NULL));

  if (argc == 2 && strcmp("list", argv[1]) == 0)
    {
      usb_init();
      usb_find_busses();
      usb_find_devices();

      list_usb_devices();
    }
  else if ((argc == 4 || argc == 5 || argc == 6) && strcmp("cat", argv[1]) == 0)
    {
      uint16_t idVendor;
      uint16_t idProduct;
      int interface = 0;
      int endpoint  = 1;

      if (sscanf(argv[2], "0x%hx", &idVendor) == 1 &&
          sscanf(argv[3], "0x%hx", &idProduct) == 1)
        {
          if (argc >= 5)
            interface = atoi(argv[4]);
          
          if (argc == 6)
            endpoint  = atoi(argv[5]);

          usb_init();
          usb_find_busses();
          usb_find_devices();

          struct usb_device* dev = find_usb_device(idVendor, idProduct);
          if (!dev)
            {
              std::cout << "Error: Device (" << boost::format("idVendor: 0x%04hx, idProduct: 0x%04hx") 
                % idVendor % idProduct << ") not found" << std::endl;
            }
          else
            {
              std::cout << "Reading data from: " << dev << " Interface: " << interface << " Endpoint: " << endpoint << std::endl; 
              cat_usb_device(dev, interface, endpoint);
            }
        }
      else
        {
          std::cout << "Error: Expected IDVENDOR IDPRODUCT" << std::endl;
        }
    }
  else
    {
      std::cout << "Usage: " << argv[0] << " list\n"
                << "       " << argv[0] << " cat IDVENDOR IDPRODUCT [INTERFACE] [ENDPOINT]"
                << std::endl;
    }
}

/* EOF */