38 #ifndef WIN32_LEAN_AND_MEAN 39 #define WIN32_LEAN_AND_MEAN 1 50 #include <sys/types.h> 64 void usage(
const char *programNameP)
67 "USAGE: %s -f <calibration_file> [<options>]\n",
69 fprintf(stderr,
"Where <options> are:\n");
70 fprintf(stderr,
"\t-a <ip_address> : ip address (default=10.66.171.21)\n");
71 fprintf(stderr,
"\t-s : set the external calibration (default is query)\n");
72 fprintf(stderr,
"\t-y : disable confirmation prompts\n");
77 bool fileExists(
const std::string& name)
80 return (0 == stat(name.c_str(), &sbuf));
83 const char *externalCalibrationNameP =
"external_calibration";
88 stream <<
"%YAML:1.0\n";
91 tmpCal[0] = calibration.
x;
92 tmpCal[1] = calibration.
y;
93 tmpCal[2] = calibration.
z;
94 tmpCal[3] = calibration.
roll;
95 tmpCal[4] = calibration.
pitch;
96 tmpCal[5] = calibration.
yaw;
98 writeMatrix (stream, externalCalibrationNameP, 1, 6, &tmpCal[0]);
108 std::string ipAddress =
"10.66.171.21";
118 while(-1 != (c =
getopt(argc, argvPP,
"a:f:sy")))
120 case 'a': ipAddress = std::string(
optarg);
break;
121 case 'f': calFile = std::string(
optarg);
break;
122 case 's': setCal =
true;
break;
123 case 'y': prompt =
false;
break;
124 default:
usage(*argvPP);
break;
130 if (calFile.empty()) {
131 fprintf(stderr,
"Must provide a file argument\n");
135 if (
true == setCal &&
false == fileExists(calFile)) {
137 fprintf(stderr,
"file not found: \"%s\"\n", calFile.c_str());
141 if (
false == setCal &&
true == prompt &&
142 true == fileExists(calFile)) {
145 "\"%s\" already exists.\n\n" 146 "Really overwrite this file? (y/n): ",
151 if (
'Y' != c &&
'y' != c) {
152 fprintf(stdout,
"Aborting\n");
161 if (NULL == channelP) {
162 fprintf(stderr,
"Failed to establish communications with \"%s\"\n",
175 fprintf(stderr,
"failed to query sensor version: %s\n",
183 if (
false == setCal) {
189 fprintf(stderr,
"failed to query external calibration: %s\n",
194 std::ofstream cvFile (calFile.c_str (), std::ios_base::out | std::ios_base::trunc);
197 fprintf(stderr,
"failed to open '%s' for writing\n",
202 writeCal (cvFile, c);
208 std::map<std::string, std::vector<float> > data;
209 std::ifstream cvFile (calFile.c_str ());
212 fprintf(stderr,
"failed to open '%s' for reading\n",
221 if (data[externalCalibrationNameP].size () != 6 ) {
223 fprintf(stderr,
"calibration matrices incomplete in %s, " 224 "expecting two 4x4 matrices\n", calFile.c_str());
230 c.
x = data[externalCalibrationNameP][0];
231 c.
y = data[externalCalibrationNameP][1];
232 c.
z = data[externalCalibrationNameP][2];
233 c.
roll = data[externalCalibrationNameP][3];
234 c.
pitch = data[externalCalibrationNameP][4];
235 c.
yaw = data[externalCalibrationNameP][5];
239 fprintf(stderr,
"failed to set external calibration: %s\n",
244 fprintf(stdout,
"External calibration successfully updated\n");
static const char * statusString(Status status)
virtual Status getExternalCalibration(system::ExternalCalibration &calibration)=0
static Channel * Create(const std::string &sensorAddress)
std::ostream & writeMatrix(std::ostream &stream, std::string const &name, uint32_t rows, uint32_t columns, T const *data)
virtual Status setExternalCalibration(const system::ExternalCalibration &calibration)=0
int getopt(int argc, char **argv, char *opts)
int main(int argc, char **argvPP)
static CRL_CONSTEXPR Status Status_Ok
std::istream & parseYaml(std::istream &stream, std::map< std::string, std::vector< float > > &data)
static void Destroy(Channel *instanceP)
virtual Status getSensorVersion(VersionType &version)=0