reset_cam.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 
37 #include <string.h>
38 #include <cstdio>
39 #include <cstdlib>
40 #include <cstring>
41 #include <cassert>
42 
43 int main(int argc, char** argv)
44 {
45  if (argc != 2 || !strcmp(argv[1], "--help")) {
46  fprintf(stderr, "Usage: %s <camera URL>\n", argv[0]);
47  fprintf(stderr, "Sends the camera a PacketReset packet.\n");
48  fprintf(stderr, "Note: Currently reconfigure_cam and reset_cam have the same effect.\n");
49  fprintf(stderr, "In future versions reset_cam may reset the camera without reconfiguring\n");
50  fprintf(stderr, "the FPGA.\n");
51  return 0;
52  }
53  char* camera_url = argv[1];
54 
55  // Find the camera matching the URL
56  IpCamList camera;
57  const char *errmsg;
58  int outval = wge100FindByUrl(camera_url, &camera, SEC_TO_USEC(0.1), &errmsg);
59  if (outval)
60  {
61  fprintf(stderr, "Matching URL %s : %s\n", camera_url, errmsg);
62  return -1;
63  }
64 
65  // Configure the camera with its IP address, wait up to 500ms for completion
66  int retval = wge100Configure(&camera, camera.ip_str, SEC_TO_USEC(0.5));
67  if (retval != 0) {
68  if (retval == ERR_CONFIG_ARPFAIL) {
69  fprintf(stderr, "Unable to create ARP entry (are you root?), continuing anyway\n");
70  } else {
71  fprintf(stderr, "IP address configuration failed\n");
72  return -1;
73  }
74  }
75 
76  if ( wge100TriggerControl( &camera, TRIG_STATE_INTERNAL ) != 0) {
77  fprintf(stderr, "Could not communicate with camera after configuring IP. Is ARP set? Is %s accessible from %s?\n", camera.ip_str, camera.ifName);
78  return -1;
79  }
80 
81  if ( wge100Reset( &camera ) != 0) {
82  fprintf(stderr, "Error sending reset to camera.\n");
83  return -1;
84  }
85 
86  fprintf(stderr, "Success!\n");
87 
88  return 0;
89 }
int wge100Reset(IpCamList *camInfo)
Definition: wge100lib.c:788
#define TRIG_STATE_INTERNAL
Definition: wge100lib.h:58
int wge100Configure(IpCamList *camInfo, const char *ipAddress, unsigned wait_us)
Definition: wge100lib.c:532
#define ERR_CONFIG_ARPFAIL
Definition: wge100lib.h:116
int main(int argc, char **argv)
Definition: reset_cam.cpp:43
#define SEC_TO_USEC(sec)
Definition: host_netutil.h:65
int wge100FindByUrl(const char *url, IpCamList *camera, unsigned wait_us, const char **errmsg)
Definition: wge100lib.c:94
char ip_str[16]
Definition: list.h:296
int wge100TriggerControl(const IpCamList *camInfo, uint32_t triggerType)
Definition: wge100lib.c:1135
char ifName[128]
Definition: list.h:293


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