usb_reset.c
Go to the documentation of this file.
00001 /* usbreset -- send a USB port reset to a USB device */
00002 
00003 /*
00004  * Copyright (c) 2014, JSK Robotics Lab, Inc.
00005  * Copyright (c) 2016, Orbbec Ltd.
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *
00011  *     * Redistributions of source code must retain the above copyright
00012  *       notice, this list of conditions and the following disclaimer.
00013  *     * Redistributions in binary form must reproduce the above copyright
00014  *       notice, this list of conditions and the following disclaimer in the
00015  *       documentation and/or other materials provided with the distribution.
00016  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00017  *       contributors may be used to endorse or promote products derived from
00018  *       this software without specific prior written permission.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00021  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00022  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00023  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00024  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00025  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00026  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00027  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00028  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00029  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00030  * POSSIBILITY OF SUCH DAMAGE.
00031  *
00032  *      Author: Tim Liu (liuhua@orbbec.com)
00033  */
00034 
00035 #include <stdio.h>
00036 #include <unistd.h>
00037 #include <fcntl.h>
00038 #include <errno.h>
00039 #include <sys/ioctl.h>
00040 
00041 #include <linux/usbdevice_fs.h>
00042 
00043 
00044 int main(int argc, char **argv)
00045 {
00046   const char *filename;
00047   int fd;
00048   int rc;
00049 
00050   if (argc != 2) {
00051     fprintf(stderr, "Usage: usbreset device-filename\n");
00052     return 1;
00053   }
00054   filename = argv[1];
00055 
00056   fd = open(filename, O_WRONLY);
00057   if (fd < 0) {
00058     perror("Error opening output file");
00059     return 1;
00060   }
00061 
00062   printf("Resetting USB device %s\n", filename);
00063   rc = ioctl(fd, USBDEVFS_RESET, 0);
00064   if (rc < 0) {
00065     perror("Error in ioctl");
00066     return 1;
00067   }
00068   printf("Reset successful\n");
00069 
00070   close(fd);
00071   return 0;
00072 }


astra_camera
Author(s): Tim Liu
autogenerated on Wed Jul 10 2019 03:18:55