read_all_flash.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> > dump.bin\n", argv[0]);
47  return 0;
48  }
49  char* camera_url = argv[1];
50 
51  // Find the camera matching the URL
52  IpCamList camera;
53  const char *errmsg;
54  int outval = wge100FindByUrl(camera_url, &camera, SEC_TO_USEC(0.1), &errmsg);
55  if (outval)
56  {
57  fprintf(stderr, "Matching URL %s : %s\n", camera_url, errmsg);
58  return -1;
59  }
60 
61  // Configure the camera with its IP address, wait up to 500ms for completion
62  int retval = wge100Configure(&camera, camera.ip_str, SEC_TO_USEC(0.5));
63  if (retval != 0) {
64  if (retval == ERR_CONFIG_ARPFAIL) {
65  fprintf(stderr, "Unable to create ARP entry (are you root?), continuing anyway\n");
66  } else {
67  fprintf(stderr, "IP address configuration failed\n");
68  return -1;
69  }
70  }
71 
72  uint8_t buffer[FLASH_PAGE_SIZE];
73 
74  for (int i = 0; i <= FLASH_MAX_PAGENO; i++)
75  {
76  int retries = 20;
77  if (i % 100 == 0)
78  {
79  fprintf(stderr, ".");
80  fflush(stderr);
81  }
82  if (wge100ReliableFlashRead(&camera, i, buffer, &retries) != 0) {
83  fprintf(stderr, "Flash read error\n");
84  return -1;
85  }
86  if (retries < 20)
87  fprintf(stderr, "x");
88  if (fwrite(buffer, FLASH_PAGE_SIZE, 1, stdout) != 1)
89  {
90  fprintf(stderr, "error: fwrite did not write one item. Image will be corrupt.\n");
91  }
92  }
93 
94  fprintf(stderr, "\n");
95 
96  return 0;
97 }
#define FLASH_PAGE_SIZE
Definition: ipcam_packet.h:60
int wge100ReliableFlashRead(const IpCamList *camInfo, uint32_t address, uint8_t *pageDataOut, int *retries)
Definition: wge100lib.c:906
int wge100Configure(IpCamList *camInfo, const char *ipAddress, unsigned wait_us)
Definition: wge100lib.c:532
#define ERR_CONFIG_ARPFAIL
Definition: wge100lib.h:116
#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 main(int argc, char **argv)
#define FLASH_MAX_PAGENO
Definition: ipcam_packet.h:59


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