ChangeResolution.cc
Go to the documentation of this file.
00001 
00036 #ifdef WIN32
00037 #ifndef WIN32_LEAN_AND_MEAN
00038 #define WIN32_LEAN_AND_MEAN 1
00039 #endif
00040 
00041 #include <windows.h>
00042 #include <winsock2.h>
00043 #else
00044 #include <unistd.h>
00045 #include <netdb.h>
00046 #include <sys/socket.h>
00047 #include <netinet/in.h>
00048 #include <arpa/inet.h>
00049 #endif
00050 
00051 #include <stdio.h>
00052 #include <stdlib.h>
00053 #include <string>
00054 #include <fstream>
00055 #include <iostream>
00056 #include <iomanip>
00057 
00058 #include <errno.h>
00059 #include <string.h>
00060 
00061 #include <LibMultiSense/details/utility/Portability.hh>
00062 #include <LibMultiSense/MultiSenseChannel.hh>
00063 
00064 #include <LibMultiSense/details/utility/BufferStream.hh>
00065 #include <LibMultiSense/details/wire/Protocol.h>
00066 #include <LibMultiSense/details/wire/SysNetworkMessage.h>
00067 
00068 #include <Utilities/portability/getopt/getopt.h>
00069 
00070 namespace {  // anonymous
00071 
00072 void usage(const char *programNameP)
00073 {
00074     fprintf(stderr, "USAGE: %s [<options>]\n", programNameP);
00075     fprintf(stderr, "Where <options> are:\n");
00076     fprintf(stderr, "\t-a address : MultiSense IP Address (default=10.66.171.21)\n");
00077     fprintf(stderr, "\t-h height  : Imager width, in px (default=544)\n");
00078     fprintf(stderr, "\t-w width   : Imager height, in px (default=1024)\n");
00079     fprintf(stderr, "\t-m mode    : Imager crop mode, (default=0)\n");
00080     fprintf(stderr, "\t             0    = No change sent\n");
00081     fprintf(stderr, "\t             2000 = Switch to CMV2000 ROI\n");
00082     fprintf(stderr, "\t             4000 = Switch to CMV4000 ROI\n");
00083     fprintf(stderr, "\t-o offset  : Position of cropped ROI, in px from bottom of image\n");
00084     fprintf(stderr, "\t             -1   = No change sent\n");
00085     fprintf(stderr, "\t             0    = ROI is bottom of CMV4000 FOV\n");
00086     fprintf(stderr, "\t             480  = ROI is center of CMV4000 FOV, assuming full resolution\n");
00087     fprintf(stderr, "\t             960  = ROI is top of CMV4000 FOV, assuming full resolution\n");
00088 
00089     exit(-1);
00090 }
00091 
00092 }; // anonymous
00093 
00094 using namespace crl::multisense;
00095 
00096 int main(int    argc,
00097          char **argvPP)
00098 {
00099     std::string currentAddress = "10.66.171.21";
00100     int32_t height = 544;
00101     uint32_t width = 1024;
00102     int mode = 0;
00103     int offset = -1;
00104 
00105     //
00106     // Parse args
00107 
00108     int c;
00109 
00110     while(-1 != (c = getopt(argc, argvPP, "a:h:w:m:o:")))
00111         switch(c) {
00112         case 'a': currentAddress = std::string(optarg);    break;
00113         case 'h': height         = atoi(optarg);           break;
00114         case 'w': width          = atoi(optarg);           break;
00115         case 'm': mode           = atoi(optarg);           break;
00116         case 'o': offset         = atoi(optarg);           break;
00117         default: usage(*argvPP);                           break;
00118         }
00119 
00120     //
00121     // Initialize communications.
00122 
00123     Channel *channelP = Channel::Create(currentAddress);
00124     if (NULL == channelP) {
00125                 std::cerr << "Failed to establish communications with \"" << currentAddress << "\"" << std::endl;
00126         return -1;
00127     }
00128 
00129     //
00130     // Query version
00131 
00132     Status status;
00133     system::VersionInfo v;
00134 
00135     status = channelP->getVersionInfo(v);
00136     if (Status_Ok != status) {
00137                 std::cerr << "Failed to query sensor version: " << Channel::statusString(status) << std::endl;
00138         goto clean_out;
00139     }
00140 
00141         std::cout << "API build date      :  " << v.apiBuildDate << "\n";
00142     std::cout << "API version         :  0x" << std::hex << std::setw(4) << std::setfill('0') << v.apiVersion << "\n";
00143         std::cout << "Firmware build date :  " << v.sensorFirmwareBuildDate << "\n";
00144         std::cout << "Firmware version    :  0x" << std::hex << std::setw(4) << std::setfill('0') << v.sensorFirmwareVersion << "\n";
00145         std::cout << "Hardware version    :  0x" << std::hex << v.sensorHardwareVersion << "\n";
00146         std::cout << "Hardware magic      :  0x" << std::hex << v.sensorHardwareMagic << "\n";
00147         std::cout << "FPGA DNA            :  0x" << std::hex << v.sensorFpgaDna << "\n";
00148         std::cout << std::dec;
00149 
00150     if (v.sensorFirmwareVersion < 0x0305) {
00151         if (mode != 0 || offset >= 0) {
00152             std::cerr << "Changing crop mode of a CMV4000 imager requires v3.5 or greater, sensor is " <<
00153             "running v" << (v.sensorFirmwareVersion >> 8) << "." << (v.sensorFirmwareVersion & 0xff) << std::endl;
00154             goto clean_out;
00155         }
00156     }
00157 
00158     //
00159     // Change operating parameters
00160 
00161     {
00162         image::Config cfg;
00163 
00164         status = channelP->getImageConfig(cfg);
00165         if (Status_Ok != status) {
00166                         std::cerr << "Failed to get image config: " << Channel::statusString(status) << std::endl;
00167             goto clean_out;
00168         } else {
00169             if (mode != 0) {
00170                 cfg.setCamMode(mode);
00171             }
00172 
00173             cfg.setResolution(width, height);
00174 
00175             if (offset >= 0) {
00176                 cfg.setOffset(offset);
00177             }
00178 
00179             status = channelP->setImageConfig(cfg);
00180             if (Status_Ok != status) {
00181                                 std::cerr << "Failed to configure sensor: " << Channel::statusString(status) << std::endl;
00182                 goto clean_out;
00183             }
00184         }
00185     }
00186 
00187 clean_out:
00188 
00189     Channel::Destroy(channelP);
00190     return 0;
00191 }


multisense_lib
Author(s):
autogenerated on Fri Apr 5 2019 02:28:24