41 #ifndef WIN32_LEAN_AND_MEAN 42 #define WIN32_LEAN_AND_MEAN 1 57 #include <sys/types.h> 67 std::string byte_to_binary(uint8_t x)
72 for (z = 128; z > 0; z >>= 1)
74 b << (((x & z) == z) ?
"1" :
"0");
80 std::string bytes_to_binary(uint64_t x,
int bits)
84 for(currentByte = 0; currentByte*8<bits; currentByte++)
86 b = byte_to_binary(static_cast<uint8_t> (x >> (currentByte*8))) +
" " + b;
89 return b.erase(0,(currentByte*8 - bits));
92 void usage(
const char *programNameP)
94 std::cerr <<
"USAGE: " << programNameP <<
" [<options>]" << std::endl;
95 std::cerr <<
"Where <options> are:" << std::endl;
96 std::cerr <<
"\t-a <ip_address> : ip address (default=10.66.171.21)" << std::endl;
97 std::cerr <<
"\t-s : set the calibration (default is query)" << std::endl;
98 std::cerr <<
"\t-l : set the left calibration" << std::endl;
99 std::cerr <<
"\t-r : set the right calibration" << std::endl;
100 std::cerr <<
"\t-e : set the right black level" << std::endl;
101 std::cerr <<
"\t-k : set the left black level" << std::endl;
112 std::string ipAddress =
"10.66.171.21";
113 std::string leftIn =
"50";
114 std::string rightIn =
"50";
117 std::string leftBlackIn =
"-61";
118 std::string rightBlackIn =
"-61";
126 bool setLeftBlack=
false;
127 bool setRightBlack=
false;
134 while(-1 != (inArgument =
getopt(argc, argvPP,
"l:r:k:e:a:sy")))
136 case 'a': ipAddress = std::string(
optarg);
break;
137 case 'l': leftIn = std::string(
optarg); setLeft=
true;
break;
138 case 'r': rightIn = std::string(
optarg); setRight=
true;
break;
139 case 'k': leftBlackIn = std::string(
optarg); setLeftBlack=
true;
break;
140 case 'e': rightBlackIn = std::string(
optarg); setRightBlack=
true;
break;
141 case 's': setCal =
true;
break;
142 default:
usage(*argvPP);
break;
148 if (setCal && (!setLeft && !setRight && !setLeftBlack && !setRightBlack)) {
149 std::cerr <<
"Please specify a value to set using -l, -r, -e, or -k" << std::endl;
155 std::cout <<
"Attempting to establish communications with: " << ipAddress << std::endl;
158 if (NULL == channelP) {
159 std::cerr <<
"Failed to establish communications with: " << ipAddress << std::endl;
176 if (setCal && setLeft) {
177 left = atoi(leftIn.c_str());
179 if (left > 255 || left < 0)
181 std::cerr <<
"Left sensor gain range is 0-255" << std::endl;
186 sensorCalibration.
adc_gain[0] =
static_cast<uint8_t
> (left);
189 if (setCal && setRight) {
190 right = atoi(rightIn.c_str());
192 if (right > 255 || right < 0)
194 std::cerr <<
"Right sensor gain range is 0-255" << std::endl;
199 sensorCalibration.
adc_gain[1] =
static_cast<uint8_t
> (right);
202 if (setCal && setLeftBlack)
204 leftBlack = atoi(leftBlackIn.c_str());
206 if (leftBlack > 8191 || leftBlack < -8192)
208 std::cerr <<
"Left black offset range is -8192 to 8191" << std::endl;
214 sensorCalibration.
bl_offset[0] =
static_cast<uint16_t
> (leftBlack) & 0x7FFF;
217 if (setCal && setRightBlack)
219 rightBlack = atoi(rightBlackIn.c_str());
221 if (rightBlack > 8191 || rightBlack < -8192)
223 std::cerr <<
"Right black offset range is -8192 to 8191" << std::endl;
229 sensorCalibration.
bl_offset[1] =
static_cast<uint16_t
> (rightBlack) & 0x7FFF;
233 if (
false == setCal) {
235 std::cout <<
"left sensor gain: " <<
static_cast<uint32_t
>(sensorCalibration.
adc_gain[0]) << std::endl;
236 std::cout <<
"right sensor gain: " <<
static_cast<uint32_t
>(sensorCalibration.
adc_gain[1]) << std::endl;
237 std::cout <<
"left sensor black level: " <<
static_cast<uint32_t
>(sensorCalibration.
bl_offset[0]) << std::endl;
238 std::cout <<
"right sensor black level: " <<
static_cast<uint32_t
>(sensorCalibration.
bl_offset[1]) << std::endl;
239 std::cout <<
"left sensor vramp: " <<
static_cast<uint32_t
>(sensorCalibration.
vramp[0]) << std::endl;
240 std::cout <<
"right sensor vramp: " <<
static_cast<uint32_t
>(sensorCalibration.
vramp[1]) << std::endl;
242 std::cout <<
"Setting :" << std::endl;
243 std::cout <<
"left sensor gain: " <<
static_cast<uint32_t
>(sensorCalibration.
adc_gain[0]) <<
" binary: " << byte_to_binary(sensorCalibration.
adc_gain[0]) << std::endl;
244 std::cout <<
"right sensor gain: " <<
static_cast<uint32_t
>(sensorCalibration.
adc_gain[1]) <<
" binary: " << byte_to_binary(sensorCalibration.
adc_gain[1]) << std::endl;
245 std::cout <<
"left sensor black level: " <<
static_cast<uint32_t
>(sensorCalibration.
bl_offset[0]) <<
" binary: " << bytes_to_binary(sensorCalibration.
bl_offset[0], 14) << std::endl;
246 std::cout <<
"right sensor black level: " <<
static_cast<uint32_t
>(sensorCalibration.
bl_offset[1]) <<
" binary: " << bytes_to_binary(sensorCalibration.
bl_offset[1], 14) << std::endl;
254 std::cout <<
"Sensor calibration successfully updated" << std::endl;
static const char * statusString(Status status)
virtual Status getSensorCalibration(image::SensorCalibration &c)=0
static Channel * Create(const std::string &sensorAddress)
int getopt(int argc, char **argv, char *opts)
static CRL_CONSTEXPR Status Status_Ok
int main(int argc, char **argvPP)
virtual Status setSensorCalibration(const image::SensorCalibration &c)=0
static void Destroy(Channel *instanceP)