discover.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2009-2010, Willow Garage, Inc.
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  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
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of the Willow Garage nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 *********************************************************************/
00034 
00035 // Author: Blaise Gassend
00036 
00037 #include <stdio.h>
00038 #include <stdlib.h>
00039 #include <string.h>
00040 #include <string>
00041 #include <vector>
00042 
00043 #include <net/if.h>
00044 
00045 #include "wge100_camera/wge100lib.h"
00046 #include "wge100_camera/host_netutil.h"
00047 
00048 int discover(const std::string &if_name, bool verbose, bool report_rp_filter)
00049 {
00050   // Create a new IpCamList to hold the camera list
00051   IpCamList camList;
00052   wge100CamListInit(&camList);
00053 
00054   // Set anti-spoofing filter off on camera interface. Needed to prevent
00055   // the first reply from the camera from being filtered out.
00056   // @todo Should we be setting rp_filter to zero here? This may violate
00057   // the user's secutity preferences?
00058 //  std::string rp_str = "sysctl net.ipv4.conf."+if_name+".rp_filter|grep -q 0||sysctl -q -w net.ipv4.conf."+if_name+".rp_filter=0 2> /dev/null";
00059 //  int retval = system(rp_str.c_str());
00060 //  if ((retval == -1 || !WIFEXITED(retval) || WEXITSTATUS(retval)) && report_rp_filter)
00061 //  {
00062 //    fprintf(stderr, "Unable to set rp_filter to 0 on interface %s. Camera discovery is likely to fail.\n", if_name.c_str());
00063 //  }
00064 
00065   // Discover any connected cameras, wait for 0.5 second for replies
00066   if( wge100Discover(if_name.c_str(), &camList, NULL, SEC_TO_USEC(0.5)) == -1) {
00067     if (verbose)
00068       fprintf(stderr, "Discover error on interface %s.\n", if_name.c_str());
00069     return -1;
00070   }
00071 
00072   if (wge100CamListNumEntries(&camList) == 0) {
00073     if (verbose)
00074       fprintf(stderr, "No cameras found on interface %s\n", if_name.c_str());
00075     return 1;
00076   }
00077 
00078   for (int i = 0; i < wge100CamListNumEntries(&camList); i++)
00079   {
00080     IpCamList *camera = wge100CamListGetEntry(&camList, i);
00081     uint8_t *mac = camera->mac;
00082     uint8_t *ip = (uint8_t *) &camera->ip;
00083     char pcb_rev = 0x0A + (0x0000000F & camera->hw_version);
00084     int hdl_rev = 0x00000FFF & (camera->hw_version>>4);
00085     printf("Found camera serial://%u ", camera->serial);
00086     if (camera->cam_name[0])
00087       printf("name://%s ", camera->cam_name);
00088     else
00089       printf("<unnamed> ");
00090     printf("MAC: %02x:%02x:%02x:%02x:%02x:%02x iface: %s current IP: %i.%i.%i.%i, PCB rev: %X HDL rev: %3X FW rev: %3X\n", 
00091         mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], camera->ifName, ip[0], ip[1], ip[2], ip[3], 
00092         pcb_rev, hdl_rev, camera->fw_version);
00093   }
00094 
00095   return 0;
00096 }
00097 
00098 int main(int argc, char **argv)
00099 {
00100   if (argc > 1 && !strcmp(argv[1], "--help"))
00101   {} // We want usage.
00102   if (argc == 2)
00103     return discover(argv[1], true, true);
00104   else if (argc == 1)
00105     return discover("", true, true);
00106     
00107   fprintf(stderr, "usage: discover [<interface>]\n");
00108   return 1;
00109 } 


wge100_camera
Author(s): Blaise Gassend, Patrick Mihelich, Eric MacIntosh, David Palchak
autogenerated on Fri Jan 3 2014 12:16:00