discover.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2009-2010, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * 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
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 // Author: Blaise Gassend
36 
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <string>
41 #include <vector>
42 
43 #include <net/if.h>
44 
47 
48 int discover(const std::string &if_name, bool verbose, bool report_rp_filter)
49 {
50  // Create a new IpCamList to hold the camera list
51  IpCamList camList;
52  wge100CamListInit(&camList);
53 
54  // Set anti-spoofing filter off on camera interface. Needed to prevent
55  // the first reply from the camera from being filtered out.
56  // @todo Should we be setting rp_filter to zero here? This may violate
57  // the user's secutity preferences?
58 // 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";
59 // int retval = system(rp_str.c_str());
60 // if ((retval == -1 || !WIFEXITED(retval) || WEXITSTATUS(retval)) && report_rp_filter)
61 // {
62 // fprintf(stderr, "Unable to set rp_filter to 0 on interface %s. Camera discovery is likely to fail.\n", if_name.c_str());
63 // }
64 
65  // Discover any connected cameras, wait for 0.5 second for replies
66  if( wge100Discover(if_name.c_str(), &camList, NULL, SEC_TO_USEC(0.5)) == -1) {
67  if (verbose)
68  fprintf(stderr, "Discover error on interface %s.\n", if_name.c_str());
69  return -1;
70  }
71 
72  if (wge100CamListNumEntries(&camList) == 0) {
73  if (verbose)
74  fprintf(stderr, "No cameras found on interface %s\n", if_name.c_str());
75  return 1;
76  }
77 
78  for (int i = 0; i < wge100CamListNumEntries(&camList); i++)
79  {
80  IpCamList *camera = wge100CamListGetEntry(&camList, i);
81  uint8_t *mac = camera->mac;
82  uint8_t *ip = (uint8_t *) &camera->ip;
83  char pcb_rev = 0x0A + (0x0000000F & camera->hw_version);
84  int hdl_rev = 0x00000FFF & (camera->hw_version>>4);
85  printf("Found camera serial://%u ", camera->serial);
86  if (camera->cam_name[0])
87  printf("name://%s ", camera->cam_name);
88  else
89  printf("<unnamed> ");
90  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",
91  mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], camera->ifName, ip[0], ip[1], ip[2], ip[3],
92  pcb_rev, hdl_rev, camera->fw_version);
93  }
94 
95  return 0;
96 }
97 
98 int main(int argc, char **argv)
99 {
100  if (argc > 1 && !strcmp(argv[1], "--help"))
101  {} // We want usage.
102  if (argc == 2)
103  return discover(argv[1], true, true);
104  else if (argc == 1)
105  return discover("", true, true);
106 
107  fprintf(stderr, "usage: discover [<interface>]\n");
108  return 1;
109 }
int discover(const std::string &if_name, bool verbose, bool report_rp_filter)
Definition: discover.cpp:48
IpCamList * wge100CamListGetEntry(const IpCamList *ipCamList, int index)
Definition: list.c:123
IPAddress ip
Definition: list.h:295
#define SEC_TO_USEC(sec)
Definition: host_netutil.h:65
int wge100CamListNumEntries(const IpCamList *ipCamList)
Definition: list.c:171
int main(int argc, char **argv)
Definition: discover.cpp:98
int wge100CamListInit(IpCamList *ipCamList)
Definition: list.c:50
uint32_t fw_version
Definition: list.h:291
uint8_t mac[6]
Definition: list.h:294
int wge100Discover(const char *ifName, IpCamList *ipCamList, const char *ipAddress, unsigned wait_us)
Definition: wge100lib.c:372
char cam_name[CAMERA_NAME_LEN]
Definition: list.h:304
char ifName[128]
Definition: list.h:293
uint32_t serial
Definition: list.h:275
uint32_t hw_version
Definition: list.h:283


wge100_camera
Author(s): Blaise Gassend, Patrick Mihelich, Eric MacIntosh, David Palchak
autogenerated on Mon Jun 10 2019 15:44:15