38 #ifndef WIN32_LEAN_AND_MEAN 39 #define WIN32_LEAN_AND_MEAN 1 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-q : query device info (default)\n");
70 fprintf(stderr,
"\t-y : disable confirmation prompt\n");
78 const char *skipSpace(
const char *strP)
81 while (isspace(*strP))
93 fprintf(fP,
"deviceName: %s\n", info.
name.c_str());
94 fprintf(fP,
"buildDate: %s\n", info.
buildDate.c_str());
95 fprintf(fP,
"serialNumber: %s\n", info.
serialNumber.c_str());
98 fprintf(fP,
"imagerName: %s\n", info.
imagerName.c_str());
99 fprintf(fP,
"imagerType: %d\n", info.
imagerType);
100 fprintf(fP,
"imagerWidth: %d\n", info.
imagerWidth);
103 fprintf(fP,
"lensName: %s\n", info.
lensName.c_str());
104 fprintf(fP,
"lensType: %d\n", info.
lensType);
112 fprintf(fP,
"laserName: %s\n", info.
laserName.c_str());
113 fprintf(fP,
"laserType: %d\n\n", info.
laserType);
115 fprintf(fP,
"motorName: %s\n", info.
motorName.c_str());
116 fprintf(fP,
"motorType: %d\n", info.
motorType);
119 for(uint32_t i=0; i<info.
pcbs.size(); i++)
120 fprintf(fP,
"pcb: %d %s\n", info.
pcbs[i].revision,
121 info.
pcbs[i].name.c_str());
127 bool parseFile(
const std::string& fileName,
130 FILE *fP = fopen(fileName.c_str(),
"r");
132 fprintf(stderr,
"fopen(\"%s\") failed: %s",
133 fileName.c_str(), strerror(errno));
139 char lineP[512] = {0};
140 char tempP[512] = {0};
144 if (NULL == fgets(lineP, 512, fP))
147 const char *s = skipSpace(lineP);
148 if (!s ||
'#' == *s ||
'\0' == *s)
152 #define strncasecmp _strnicmp 155 #define CASE_STR(str_,x_) \ 156 if (0 == strncasecmp(s, str_, strlen(str_))) { \ 157 if (1 != sscanf(s, str_"%[^\n]", tempP)) { \ 158 fprintf(stderr, "malformed " str_ " %s\n",s); \ 161 x_ = std::string(tempP); \ 165 #define CASE_INT(str_,x_) \ 166 if (0 == strncasecmp(s, str_, strlen(str_))) { \ 167 if (1 != sscanf(s, str_"%d\n", &tempi)) { \ 168 fprintf(stderr, "malformed " str_ " %s\n",s); \ 175 #define CASE_FLT(str_,x_) \ 176 if (0 == strncasecmp(s, str_, strlen(str_))) { \ 177 if (1 != sscanf(s, str_"%f\n", &tempf)) { \ 178 fprintf(stderr, "malformed " str_ " %s\n",s); \ 185 #define CASE_PCB(str_) \ 186 if (0 == strncasecmp(s, str_, strlen(str_))) { \ 187 if (2 != sscanf(s, str_"%d %[^\n]", &tempi, tempP)) { \ 188 fprintf(stderr, "malformed " str_ " %s\n",s); \ 215 fprintf(stderr,
"no room for pcb: %s %d\n", tempP, tempi);
219 pcb.
name = std::string(tempP);
221 info.
pcbs.push_back(pcb);
226 fprintf(stderr,
"malformed line: \"%s\"\n", s);
239 std::string ipAddress =
"10.66.171.21";
241 std::string fileName;
250 while(-1 != (c =
getopt(argc, argvPP,
"a:k:s:qy")))
252 case 'a': ipAddress = std::string(
optarg);
break;
253 case 'k': key = std::string(
optarg);
break;
254 case 's': fileName = std::string(
optarg);
break;
255 case 'q': query =
true;
break;
256 case 'y': prompt =
false;
break;
257 default:
usage(*argvPP);
break;
260 if (!fileName.empty() && key.empty()) {
262 "To program device info, please also specify the device's key with '-k'\n");
266 if (fileName.empty())
273 if (NULL == channelP) {
274 fprintf(stderr,
"Failed to establish communications with \"%s\"\n",
287 fprintf(stderr,
"Failed to query sensor version: %s\n",
295 if (!fileName.empty()) {
299 if (
false == parseFile(fileName, info))
304 printDeviceInfo(info);
305 fprintf(stdout,
"\nReally update device information? (y/n): ");
309 if (
'Y' != c &&
'y' != c) {
310 fprintf(stdout,
"Aborting\n");
317 fprintf(stderr,
"Failed to set the device info: %s\n",
321 fprintf(stdout,
"Device info updated successfully\n");
334 fprintf(stderr,
"Failed to query device info: %s\n",
337 printDeviceInfo(info);
std::vector< PcbInfo > pcbs
virtual Status setDeviceInfo(const std::string &key, const system::DeviceInfo &i)=0
static const char * statusString(Status status)
int main(int argc, char **argvPP)
static Channel * Create(const std::string &sensorAddress)
#define CASE_INT(str_, x_)
int getopt(int argc, char **argv, char *opts)
#define CASE_STR(str_, x_)
static CRL_CONSTEXPR uint32_t MAX_PCBS
uint32_t hardwareRevision
static CRL_CONSTEXPR Status Status_Ok
float nominalRelativeAperture
virtual Status getDeviceInfo(system::DeviceInfo &info)=0
static void Destroy(Channel *instanceP)
#define CASE_FLT(str_, x_)
virtual Status getSensorVersion(VersionType &version)=0