38 #ifndef WIN32_LEAN_AND_MEAN
39 #define WIN32_LEAN_AND_MEAN 1
54 #include <MultiSense/MultiSenseChannel.hh>
62 void usage(
const char *programNameP)
64 fprintf(stderr,
"USAGE: %s [<options>]\n", programNameP);
65 fprintf(stderr,
"Where <options> are:\n");
66 fprintf(stderr,
"\t-a <ip_address> : ip address (default=10.66.171.21)\n");
67 fprintf(stderr,
"\t-k <passphrase> : passphrase for setting device info\n");
68 fprintf(stderr,
"\t-s <file_name> : set device info from file\n");
69 fprintf(stderr,
"\t-r : remote head channel (options: VPB, 0, 1, 2, 3)\n");
70 fprintf(stderr,
"\t-q : query device info (default)\n");
71 fprintf(stderr,
"\t-y : disable confirmation prompt\n");
76 static int getRemoteHeadIdFromString(
const std::string &head_str,
RemoteHeadChannel & rh)
80 if (head_str ==
"VPB")
82 else if (head_str ==
"0")
84 else if (head_str ==
"1")
86 else if (head_str ==
"2")
88 else if (head_str ==
"3")
91 fprintf(stderr,
"Error: Unrecognized remote head\n");
92 fprintf(stderr,
"Please use one of the following:\n");
93 fprintf(stderr,
"\tVPB\n");
94 fprintf(stderr,
"\t0'\n");
95 fprintf(stderr,
"\t1\n");
96 fprintf(stderr,
"\t2\n");
97 fprintf(stderr,
"\t3\n");
107 const char *skipSpace(
const char *strP)
110 while (isspace(*strP))
122 fprintf(fP,
"deviceName: %s\n", info.
name.c_str());
123 fprintf(fP,
"buildDate: %s\n", info.
buildDate.c_str());
124 fprintf(fP,
"serialNumber: %s\n", info.
serialNumber.c_str());
127 fprintf(fP,
"imagerName: %s\n", info.
imagerName.c_str());
128 fprintf(fP,
"imagerType: %d\n", info.
imagerType);
129 fprintf(fP,
"imagerWidth: %d\n", info.
imagerWidth);
132 fprintf(fP,
"lensName: %s\n", info.
lensName.c_str());
133 fprintf(fP,
"lensType: %d\n", info.
lensType);
141 fprintf(fP,
"laserName: %s\n", info.
laserName.c_str());
142 fprintf(fP,
"laserType: %d\n\n", info.
laserType);
144 fprintf(fP,
"motorName: %s\n", info.
motorName.c_str());
145 fprintf(fP,
"motorType: %d\n", info.
motorType);
148 for(uint32_t i=0; i<info.
pcbs.size(); i++)
149 fprintf(fP,
"pcb: %d %s\n", info.
pcbs[i].revision,
150 info.
pcbs[i].name.c_str());
156 bool parseFile(
const std::string& fileName,
159 FILE *fP = fopen(fileName.c_str(),
"r");
161 fprintf(stderr,
"fopen(\"%s\") failed: %s",
162 fileName.c_str(), strerror(errno));
168 char lineP[513] = {0};
169 char tempP[513] = {0};
173 if (NULL == fgets(lineP, 512, fP))
176 const char *s = skipSpace(lineP);
177 if (!s ||
'#' == *s ||
'\0' == *s)
181 #define strncasecmp _strnicmp
184 #define CASE_STR(str_,x_) \
185 if (0 == strncasecmp(s, str_, strlen(str_))) { \
186 if (1 != sscanf(s, str_"%512[^\n]", tempP)) { \
187 fprintf(stderr, "malformed " str_ " %s\n",s); \
190 x_ = std::string(tempP); \
194 #define CASE_INT(str_,x_) \
195 if (0 == strncasecmp(s, str_, strlen(str_))) { \
196 if (1 != sscanf(s, str_"%d\n", &tempi)) { \
197 fprintf(stderr, "malformed " str_ " %s\n",s); \
204 #define CASE_FLT(str_,x_) \
205 if (0 == strncasecmp(s, str_, strlen(str_))) { \
206 if (1 != sscanf(s, str_"%f\n", &tempf)) { \
207 fprintf(stderr, "malformed " str_ " %s\n",s); \
214 #define CASE_PCB(str_) \
215 if (0 == strncasecmp(s, str_, strlen(str_))) { \
216 if (2 != sscanf(s, str_"%d %512[^\n]", &tempi, tempP)) { \
217 fprintf(stderr, "malformed " str_ " %s\n",s); \
244 fprintf(stderr,
"no room for pcb: %s %d\n", tempP, tempi);
248 pcb.
name = std::string(tempP);
250 info.
pcbs.push_back(pcb);
255 fprintf(stderr,
"malformed line: \"%s\"\n", s);
268 std::string ipAddress =
"10.66.171.21";
270 std::string fileName;
271 std::string remoteHeadChannelId;
272 bool cameraRemoteHead=
false;
281 while(-1 != (c =
getopt(argc, argvPP,
"a:k:s:r:qy")))
283 case 'a': ipAddress = std::string(
optarg);
break;
284 case 'k': key = std::string(
optarg);
break;
285 case 's': fileName = std::string(
optarg);
break;
287 remoteHeadChannelId = std::string(
optarg);
288 cameraRemoteHead =
true;
291 case 'q': query =
true;
break;
292 case 'y': prompt =
false;
break;
293 default:
usage(*argvPP);
break;
296 if (!fileName.empty() && key.empty()) {
298 "To program device info, please also specify the device's key with '-k'\n");
302 if (fileName.empty())
309 if (cameraRemoteHead) {
311 if (getRemoteHeadIdFromString(remoteHeadChannelId, rch) < 0) {
314 channelP = Channel::Create(ipAddress, rch);
317 channelP = Channel::Create(ipAddress);
320 if (NULL == channelP) {
321 fprintf(stderr,
"Failed to establish communications with \"%s\"\n",
334 fprintf(stderr,
"Failed to query sensor version: %s\n",
335 Channel::statusString(status));
342 if (!fileName.empty()) {
346 if (
false == parseFile(fileName, info))
351 printDeviceInfo(info);
352 fprintf(stdout,
"\nReally update device information? (y/n): ");
354 int reply = getchar();
356 if (
'Y' != reply &&
'y' != reply) {
357 fprintf(stdout,
"Aborting\n");
364 fprintf(stderr,
"Failed to set the device info: %s\n",
365 Channel::statusString(status));
368 fprintf(stdout,
"Device info updated successfully\n");
381 fprintf(stderr,
"Failed to query device info: %s\n",
382 Channel::statusString(status));
384 printDeviceInfo(info);
389 Channel::Destroy(channelP);