usb_reset.c
Go to the documentation of this file.
1 /* usbreset -- send a USB port reset to a USB device */
2 
3 /*
4  * Copyright (c) 2014, JSK Robotics Lab, Inc.
5  * Copyright (c) 2016, Orbbec Ltd.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  * * Neither the name of the Willow Garage, Inc. nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  * Author: Tim Liu (liuhua@orbbec.com)
33  */
34 
35 #include <stdio.h>
36 #include <unistd.h>
37 #include <fcntl.h>
38 #include <errno.h>
39 #include <sys/ioctl.h>
40 
41 #include <linux/usbdevice_fs.h>
42 
43 
44 int main(int argc, char **argv)
45 {
46  const char *filename;
47  int fd;
48  int rc;
49 
50  if (argc != 2) {
51  fprintf(stderr, "Usage: usbreset device-filename\n");
52  return 1;
53  }
54  filename = argv[1];
55 
56  fd = open(filename, O_WRONLY);
57  if (fd < 0) {
58  perror("Error opening output file");
59  return 1;
60  }
61 
62  printf("Resetting USB device %s\n", filename);
63  rc = ioctl(fd, USBDEVFS_RESET, 0);
64  if (rc < 0) {
65  perror("Error in ioctl");
66  return 1;
67  }
68  printf("Reset successful\n");
69 
70  close(fd);
71  return 0;
72 }
filename
int main(int argc, char **argv)
Definition: usb_reset.c:44


astra_camera
Author(s): Tim Liu
autogenerated on Wed Dec 16 2020 03:54:34