set_ip.cpp
Go to the documentation of this file.
00001 #include <cstdio>
00002 #include "prosilica/prosilica.h"
00003 #include <arpa/inet.h>
00004 
00005 void printSettings(const tPvCameraInfo& info, const tPvIpSettings& conf)
00006 {
00007   printf("\t%s - %7s - Unique ID = %lu\n", info.SerialString, info.DisplayName, info.UniqueId);
00008   printf("\tMode:\t\t");
00009   if (conf.ConfigMode & ePvIpConfigPersistent)
00010     printf("FIXED\n");
00011   else if (conf.ConfigMode & ePvIpConfigDhcp)
00012     printf("DHCP&AutoIP\n");
00013   else if (conf.ConfigMode & ePvIpConfigAutoIp)
00014     printf("AutoIP\n");
00015   else
00016     printf("None\n");
00017 
00018   struct in_addr addr;
00019   addr.s_addr = conf.CurrentIpAddress;
00020   printf("\tAddress:\t%s\n", inet_ntoa(addr));
00021   addr.s_addr = conf.CurrentIpSubnet;
00022   printf("\tSubnet:\t\t%s\n", inet_ntoa(addr));
00023   addr.s_addr = conf.CurrentIpGateway;
00024   printf("\tGateway:\t%s\n", inet_ntoa(addr));
00025 }
00026 
00027 int main(int argc, char** argv)
00028 {
00029   if (argc < 2) {
00030     printf("Usage: %s 10.68.0.20 [255.255.255.0] [0.0.0.0]\n", argv[0]);
00031     return 0;
00032   }
00033 
00034   char nm[] = "255.255.255.0";
00035   char* netmask = nm;
00036   if (argc >= 3) {
00037     netmask = argv[2];
00038   }
00039 
00040   char gw[] = "0.0.0.0";
00041   char* gateway = gw;
00042   if (argc >= 4) {
00043     gateway = argv[3];
00044   }
00045 
00046   prosilica::init();
00047   // Make sure we call prosilica::fini() on exit.
00048   boost::shared_ptr<void> guard(static_cast<void*>(0), boost::bind(prosilica::fini));
00049 
00050   // Check if camera IP is already set
00051   char* ip_address = argv[1];
00052   unsigned long IP = inet_addr(ip_address);
00053   tPvCameraInfo info;
00054   tPvIpSettings conf;
00055   tPvErr err = PvCameraInfoByAddr(IP, &info, &conf);
00056   if (!err) {
00057     printf("Camera found at requested IP address:\n");
00058     printSettings(info, conf);
00059   }
00060   else {
00061     printf("No camera found at %s, trying to change settings of a local camera...\n", ip_address);
00062     size_t num_cams = prosilica::numCameras();
00063     if (num_cams == 0) {
00064       printf("ERROR: No camera detected. Is it plugged in?\n");
00065       return 1;
00066     }
00067     if (num_cams == 2) {
00068       printf("ERROR: Multiple cameras (%u) found. Do you have more than one plugged in?\n", (unsigned)num_cams);
00069       return 1;
00070     }
00071     
00072     printf("Detected camera.\n");
00073     unsigned long uid = prosilica::getGuid(0);
00074     
00075     if (PvCameraInfo(uid, &info)) {
00076       printf("ERROR: could not retrieve camera info.\n");
00077       return 1;
00078     }
00079     if (PvCameraIpSettingsGet(uid, &conf)) {
00080       printf("ERROR: could not retrieve camera IP settings.\n");
00081       return 1;
00082     }
00083     printf("Original settings:\n");
00084     printSettings(info, conf);
00085 
00086     printf("Applying new settings...\n");
00087     conf.ConfigMode = ePvIpConfigPersistent;
00088     //conf.ConfigMode = ePvIpConfigDhcp;
00089     conf.CurrentIpAddress = conf.PersistentIpAddr = IP;
00090     conf.CurrentIpSubnet = conf.PersistentIpSubnet = inet_addr(netmask);
00091     conf.CurrentIpGateway = conf.PersistentIpGateway = inet_addr(gateway);
00092     if (PvCameraIpSettingsChange(uid, &conf)) {
00093       printf("ERROR: Failed to apply the new settings\n");
00094       return 1;
00095     }
00096     printf("New settings:\n");
00097     printSettings(info, conf);
00098   }
00099 
00100   return 0;
00101 }


prosilica_camera
Author(s): Maintained by William Woodall - wwoodall@willowgarage.com, Contributions by Allison Thackston - allison.thackston@nasa.gov
autogenerated on Fri Aug 28 2015 12:15:29