set_ip.cpp
Go to the documentation of this file.
1 #include <cstdio>
2 #include "prosilica/prosilica.h"
3 #include <arpa/inet.h>
4 
5 void printSettings(const tPvCameraInfo& info, const tPvIpSettings& conf)
6 {
7  printf("\t%s - %7s - Unique ID = %lu\n", info.SerialString, info.DisplayName, info.UniqueId);
8  printf("\tMode:\t\t");
10  printf("FIXED\n");
11  else if (conf.ConfigMode & ePvIpConfigDhcp)
12  printf("DHCP&AutoIP\n");
13  else if (conf.ConfigMode & ePvIpConfigAutoIp)
14  printf("AutoIP\n");
15  else
16  printf("None\n");
17 
18  struct in_addr addr;
19  addr.s_addr = conf.CurrentIpAddress;
20  printf("\tAddress:\t%s\n", inet_ntoa(addr));
21  addr.s_addr = conf.CurrentIpSubnet;
22  printf("\tSubnet:\t\t%s\n", inet_ntoa(addr));
23  addr.s_addr = conf.CurrentIpGateway;
24  printf("\tGateway:\t%s\n", inet_ntoa(addr));
25 }
26 
27 int main(int argc, char** argv)
28 {
29  if (argc < 2) {
30  printf("Usage: %s 10.68.0.20 [255.255.255.0] [0.0.0.0]\n", argv[0]);
31  return 0;
32  }
33 
34  char nm[] = "255.255.255.0";
35  char* netmask = nm;
36  if (argc >= 3) {
37  netmask = argv[2];
38  }
39 
40  char gw[] = "0.0.0.0";
41  char* gateway = gw;
42  if (argc >= 4) {
43  gateway = argv[3];
44  }
45 
47  // Make sure we call prosilica::fini() on exit.
48  boost::shared_ptr<void> guard(static_cast<void*>(0), boost::bind(prosilica::fini));
49 
50  // Check if camera IP is already set
51  char* ip_address = argv[1];
52  unsigned long IP = inet_addr(ip_address);
53  tPvCameraInfo info;
54  tPvIpSettings conf;
55  tPvErr err = PvCameraInfoByAddr(IP, &info, &conf);
56  if (!err) {
57  printf("Camera found at requested IP address:\n");
58  printSettings(info, conf);
59  }
60  else {
61  printf("No camera found at %s, trying to change settings of a local camera...\n", ip_address);
62  size_t num_cams = prosilica::numCameras();
63  if (num_cams == 0) {
64  printf("ERROR: No camera detected. Is it plugged in?\n");
65  return 1;
66  }
67  if (num_cams == 2) {
68  printf("ERROR: Multiple cameras (%u) found. Do you have more than one plugged in?\n", (unsigned)num_cams);
69  return 1;
70  }
71 
72  printf("Detected camera.\n");
73  unsigned long uid = prosilica::getGuid(0);
74 
75  if (PvCameraInfo(uid, &info)) {
76  printf("ERROR: could not retrieve camera info.\n");
77  return 1;
78  }
79  if (PvCameraIpSettingsGet(uid, &conf)) {
80  printf("ERROR: could not retrieve camera IP settings.\n");
81  return 1;
82  }
83  printf("Original settings:\n");
84  printSettings(info, conf);
85 
86  printf("Applying new settings...\n");
88  //conf.ConfigMode = ePvIpConfigDhcp;
89  conf.CurrentIpAddress = conf.PersistentIpAddr = IP;
90  conf.CurrentIpSubnet = conf.PersistentIpSubnet = inet_addr(netmask);
91  conf.CurrentIpGateway = conf.PersistentIpGateway = inet_addr(gateway);
92  if (PvCameraIpSettingsChange(uid, &conf)) {
93  printf("ERROR: Failed to apply the new settings\n");
94  return 1;
95  }
96  printf("New settings:\n");
97  printSettings(info, conf);
98  }
99 
100  return 0;
101 }
tPvErr PVDECL PvCameraIpSettingsChange(unsigned long UniqueId, const tPvIpSettings *pSettings)
unsigned long PersistentIpSubnet
unsigned long UniqueId
void init()
Definition: prosilica.cpp:88
uint64_t getGuid(size_t i)
Definition: prosilica.cpp:104
tPvErr
char SerialString[32]
tPvIpConfig ConfigMode
void printSettings(const tPvCameraInfo &info, const tPvIpSettings &conf)
Definition: set_ip.cpp:5
size_t numCameras()
Definition: prosilica.cpp:98
void fini()
Definition: prosilica.cpp:93
int main(int argc, char **argv)
Definition: set_ip.cpp:27
unsigned long CurrentIpGateway
ePvIpConfigAutoIp
unsigned long PersistentIpAddr
unsigned long CurrentIpAddress
ePvIpConfigPersistent
unsigned long PersistentIpGateway
tPvErr PVDECL PvCameraInfo(unsigned long UniqueId, tPvCameraInfo *pInfo)
ePvIpConfigDhcp
tPvErr PVDECL PvCameraIpSettingsGet(unsigned long UniqueId, tPvIpSettings *pSettings)
tPvErr PVDECL PvCameraInfoByAddr(unsigned long IpAddr, tPvCameraInfo *pInfo, tPvIpSettings *pIpSettings)
char DisplayName[16]
unsigned long CurrentIpSubnet


prosilica_camera
Author(s): Maintained by William Woodall - wwoodall@willowgarage.com, Contributions by Allison Thackston - allison.thackston@nasa.gov
autogenerated on Mon Jun 10 2019 14:20:19