cltool.cpp
Go to the documentation of this file.
1 /*
2 MIT LICENSE
3 
4 Copyright (c) 2014-2020 Inertial Sense, Inc. - http://inertialsense.com
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions :
7 
8 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9 
10 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 */
12 
13 #include "cltool.h"
14 #include "ISDataMappings.h"
15 
19 
20 int cltool_serialPortSendComManager(CMHANDLE cmHandle, int pHandle, buffer_t* bufferToSend)
21 {
22  (void)cmHandle;
23  (void)pHandle;
24  return serialPortWrite(&g_serialPort, bufferToSend->buf, bufferToSend->size);
25 }
26 
27 bool cltool_setupLogger(InertialSense& inertialSenseInterface)
28 {
29  // Enable logging in continuous background mode
30  return inertialSenseInterface.SetLoggerEnabled
31  (
32  g_commandLineOptions.enableLogging, // enable logger
33  g_commandLineOptions.logPath, // path to log to, if empty defaults to DEFAULT_LOGS_DIRECTORY
34  cISLogger::ParseLogType(g_commandLineOptions.logType), // log type
35  g_commandLineOptions.rmcPreset, // Stream rmc preset
36  g_commandLineOptions.maxLogSpacePercent, // max space in percentage of free space to use, 0 for unlimited
37  g_commandLineOptions.maxLogFileSize, // each log file will be no larger than this in bytes
38  g_commandLineOptions.logSubFolder // log sub folder name
39  );
40 
41  // Call these elsewhere as needed
42 // inertialSenseInterface.EnableLogger(false); // Enable/disable during runtime
43 // inertialSenseInterface.CloseLogger(); // Stop logging and save remaining data to file
44 }
45 
46 static bool startsWith(const char* str, const char* pre)
47 {
48  size_t lenpre = strlen(pre), lenstr = strlen(str);
49  return lenstr < lenpre ? false : strncasecmp(pre, str, lenpre) == 0;
50 }
51 
52 #define CL_DEFAULT_BAUD_RATE IS_COM_BAUDRATE_DEFAULT
53 #define CL_DEFAULT_COM_PORT "*"
54 #define CL_DEFAULT_DISPLAY_MODE cInertialSenseDisplay::DMODE_PRETTY
55 #define CL_DEFAULT_LOG_TYPE "dat"
56 #define CL_DEFAULT_LOGS_DIRECTORY DEFAULT_LOGS_DIRECTORY
57 #define CL_DEFAULT_ENABLE_LOGGING false
58 #define CL_DEFAULT_MAX_LOG_FILE_SIZE 1024 * 1024 * 5
59 #define CL_DEFAULT_MAX_LOG_SPACE_PERCENT 0.5f
60 #define CL_DEFAULT_REPLAY_SPEED 1.0
61 #define CL_DEFAULT_BOOTLOAD_VERIFY false
62 
63 bool cltool_parseCommandLine(int argc, char* argv[])
64 {
65  // set defaults
66  g_commandLineOptions.baudRate = CL_DEFAULT_BAUD_RATE;
67  g_commandLineOptions.comPort = CL_DEFAULT_COM_PORT;
68  g_commandLineOptions.displayMode = CL_DEFAULT_DISPLAY_MODE;
69  g_commandLineOptions.rmcPreset = 0;
70  g_commandLineOptions.enableLogging = CL_DEFAULT_ENABLE_LOGGING;
71  g_commandLineOptions.logType = CL_DEFAULT_LOG_TYPE;
72  g_commandLineOptions.logPath = CL_DEFAULT_LOGS_DIRECTORY;
73  g_commandLineOptions.maxLogFileSize = CL_DEFAULT_MAX_LOG_FILE_SIZE;
75  g_commandLineOptions.replaySpeed = CL_DEFAULT_REPLAY_SPEED;
76  g_commandLineOptions.bootloaderVerify = CL_DEFAULT_BOOTLOAD_VERIFY;
77  g_commandLineOptions.timeoutFlushLoggerSeconds = 3;
78  g_commandLineOptions.asciiMessages = "";
79  g_commandLineOptions.updateBootloaderFilename = "";
80 
81  g_commandLineOptions.surveyIn.state = 0;
82  g_commandLineOptions.surveyIn.maxDurationSec = 15 * 60; // default survey of 15 minutes
83  g_commandLineOptions.surveyIn.minAccuracy = 0;
84 
86 
87  if(argc <= 1)
88  { // Display usage menu if no options are provided
90  return false;
91  }
92 
93  // parse command line. Keep these options in alphabetic order!
94  for (int i = 1; i < argc; i++)
95  {
96  const char* a = argv[i];
97  if (startsWith(a, "-asciiMessages="))
98  {
99  g_commandLineOptions.asciiMessages = &a[15];
100  }
101  else if (startsWith(a, "-baud="))
102  {
103  g_commandLineOptions.baudRate = strtol(&a[6], NULL, 10);
104  }
105  else if (startsWith(a, "-c="))
106  {
107  g_commandLineOptions.comPort = &a[3];
108  }
109  else if (startsWith(a, "-dboc"))
110  {
111  g_commandLineOptions.disableBroadcastsOnClose = true;
112  }
113  else if (startsWith(a, "-flashConfig="))
114  {
115  g_commandLineOptions.flashConfig = &a[13];
116  }
117  else if (startsWith(a, "-flashConfig"))
118  {
119  g_commandLineOptions.flashConfig = ".";
120  }
121  else if (startsWith(a, "-host="))
122  {
123  g_commandLineOptions.host = &a[6];
124  }
125  else if (startsWith(a, "-h") || startsWith(a, "--h") || startsWith(a, "-help") || startsWith(a, "--help"))
126  {
128  return false;
129  }
130  else if (startsWith(a, "-lms="))
131  {
132  g_commandLineOptions.maxLogSpacePercent = (float)atof(&a[5]);
133  }
134  else if (startsWith(a, "-lmf="))
135  {
136  g_commandLineOptions.maxLogFileSize = (uint32_t)strtoul(&a[5], NULL, 10);
137  }
138  else if (startsWith(a, "-log-flush-timeout="))
139  {
140  g_commandLineOptions.timeoutFlushLoggerSeconds = strtoul(&a[19], NULLPTR, 10);
141  }
142  else if (startsWith(a, "-lts="))
143  {
144  const char* subFolder = &a[5];
145  if (*subFolder == '1' || startsWith(subFolder, "true"))
146  {
147  g_commandLineOptions.logSubFolder = cISLogger::CreateCurrentTimestamp();
148  }
149  else if (*subFolder == '\0' || *subFolder == '0' || startsWith(subFolder, "false"))
150  {
151  g_commandLineOptions.logSubFolder = cISLogger::g_emptyString;
152  }
153  else
154  {
155  g_commandLineOptions.logSubFolder = subFolder;
156  }
157  }
158  else if (startsWith(a, "-lp="))
159  {
160  g_commandLineOptions.logPath = &a[4];
161  }
162  else if (startsWith(a, "-lt="))
163  {
164  g_commandLineOptions.logType = &a[4];
165  }
166  else if (startsWith(a, "-lon"))
167  {
168  g_commandLineOptions.enableLogging = true;
169  }
170  else if (startsWith(a, "-magRecal"))
171  {
172  g_commandLineOptions.rmcPreset = 0;
173  g_commandLineOptions.magRecal = true;
174  g_commandLineOptions.magRecalMode = strtol(a + 9, NULL, 10);
175  }
176  else if (startsWith(a, "-survey="))
177  {
178  g_commandLineOptions.rmcPreset = 0;
179  g_commandLineOptions.surveyIn.state = strtol(a + 8, NULL, 10);
180  int maxDurationSec = strtol(a + 10, NULL, 10);
181  if (maxDurationSec > 5)
182  {
183  g_commandLineOptions.surveyIn.maxDurationSec = maxDurationSec;
184  }
185  }
186  else if (startsWith(a, "-msgBaro="))
187  {
188  g_commandLineOptions.streamBaro = (int)atof(&a[9]);
189  }
190  else if (startsWith(a, "-msgBaro"))
191  {
192  g_commandLineOptions.streamBaro = 50;
193  }
194  else if (startsWith(a, "-msgDualIMU="))
195  {
196  g_commandLineOptions.streamDualIMU = (int)atof(&a[12]);
197  }
198  else if (startsWith(a, "-msgDualIMU"))
199  {
200  g_commandLineOptions.streamDualIMU = 50;
201  }
202  else if (startsWith(a, "-msgGPS="))
203  {
204  g_commandLineOptions.streamGPS = (int)atof(&a[8]);
205  }
206  else if (startsWith(a, "-msgGPS"))
207  {
208  g_commandLineOptions.streamGPS = 1;
209  }
210  else if (startsWith(a, "-msgIMU1="))
211  {
212  g_commandLineOptions.streamIMU1 = (int)atof(&a[9]);
213  }
214  else if (startsWith(a, "-msgIMU1"))
215  {
216  g_commandLineOptions.streamIMU1 = 50;
217  }
218  else if (startsWith(a, "-msgIMU2="))
219  {
220  g_commandLineOptions.streamIMU2 = (int)atof(&a[9]);
221  }
222  else if (startsWith(a, "-msgIMU2"))
223  {
224  g_commandLineOptions.streamIMU2 = 50;
225  }
226  else if (startsWith(a, "-msgINS1="))
227  {
228  g_commandLineOptions.streamINS1 = (int)atof(&a[9]);
229  }
230  else if (startsWith(a, "-msgINS1"))
231  {
232  g_commandLineOptions.streamINS1 = 50;
233  }
234  else if (startsWith(a, "-msgINS2="))
235  {
236  g_commandLineOptions.streamINS2 = (int)atof(&a[9]);
237  }
238  else if (startsWith(a, "-msgINS2"))
239  {
240  g_commandLineOptions.streamINS2 = 50;
241  }
242  else if (startsWith(a, "-msgINS3="))
243  {
244  g_commandLineOptions.streamINS3 = (int)atof(&a[9]);
245  }
246  else if (startsWith(a, "-msgINS3"))
247  {
248  g_commandLineOptions.streamINS3 = 50;
249  }
250  else if (startsWith(a, "-msgINS4="))
251  {
252  g_commandLineOptions.streamINS4 = (int)atof(&a[9]);
253  }
254  else if (startsWith(a, "-msgINS4"))
255  {
256  g_commandLineOptions.streamINS4 = 50;
257  }
258  else if (startsWith(a, "-msgMag1="))
259  {
260  g_commandLineOptions.streamMag1 = (int)atof(&a[9]);
261  }
262  else if (startsWith(a, "-msgMag1"))
263  {
264  g_commandLineOptions.streamMag1 = 50;
265  }
266  else if (startsWith(a, "-msgMag2="))
267  {
268  g_commandLineOptions.streamMag2 = (int)atof(&a[9]);
269  }
270  else if (startsWith(a, "-msgMag2"))
271  {
272  g_commandLineOptions.streamMag2 = 50;
273  }
274  else if (startsWith(a, "-msgPIMU"))
275  {
276  g_commandLineOptions.streamDThetaVel = 1;
277  }
278  else if (startsWith(a, "-msgPresetPPD"))
279  {
280  g_commandLineOptions.rmcPreset = RMC_PRESET_PPD_BITS;
281  }
282  else if (startsWith(a, "-msgPresetINS2"))
283  {
284  g_commandLineOptions.rmcPreset = RMC_PRESET_INS_BITS;
285  }
286  else if (startsWith(a, "-msgRtkPosRel="))
287  {
288  g_commandLineOptions.streamRtkPosRel = (int)atof(&a[11]);
289  }
290  else if (startsWith(a, "-msgRtkPosRel"))
291  {
292  g_commandLineOptions.streamRtkPosRel = 1;
293  }
294  else if (startsWith(a, "-msgRtkCmpRel="))
295  {
296  g_commandLineOptions.streamRtkCmpRel = (int)atof(&a[11]);
297  }
298  else if (startsWith(a, "-msgRtkCmpRel"))
299  {
300  g_commandLineOptions.streamRtkCmpRel = 1;
301  }
302  else if (startsWith(a, "-msgRtkPos="))
303  {
304  g_commandLineOptions.streamRtkPos = (int)atof(&a[11]);
305  }
306  else if (startsWith(a, "-msgRtkPos"))
307  {
308  g_commandLineOptions.streamRtkPos = 1;
309  }
310  else if (startsWith(a, "-msgRTOS="))
311  {
312  g_commandLineOptions.streamRTOS = (int)atof(&a[9]);
313  }
314  else if (startsWith(a, "-msgRTOS"))
315  {
316  g_commandLineOptions.streamRTOS = 250;
317  }
318  else if (startsWith(a, "-msgSensorsADC="))
319  {
320  g_commandLineOptions.streamSensorsADC = (int)atof(&a[15]);
321  }
322  else if (startsWith(a, "-msgSensorsADC"))
323  {
324  g_commandLineOptions.streamSensorsADC = 50;
325  }
326  else if (startsWith(a, "-msgSensors="))
327  {
328  g_commandLineOptions.streamSysSensors = (int)atof(&a[12]);
329  }
330  else if (startsWith(a, "-msgSensors"))
331  {
332  g_commandLineOptions.streamSysSensors = 50;
333  }
334  else if (startsWith(a, "-persistent"))
335  {
336  g_commandLineOptions.persistentMessages = true;
337  }
338  else if (startsWith(a, "-q"))
339  {
340  g_commandLineOptions.displayMode = cInertialSenseDisplay::DMODE_QUIET;
341  }
342  else if (startsWith(a, "-rp="))
343  {
344  g_commandLineOptions.replayDataLog = true;
345  g_commandLineOptions.logPath = &a[4];
346  }
347  else if (startsWith(a, "-rs="))
348  {
349  g_commandLineOptions.replayDataLog = true;
350  g_commandLineOptions.replaySpeed = (float)atof(&a[4]);
351  }
352  else if (startsWith(a, "-reset"))
353  {
354  g_commandLineOptions.softwareReset = true;
355  }
356  else if (startsWith(a, "-r"))
357  {
358  g_commandLineOptions.replayDataLog = true;
359  }
360  else if (startsWith(a, "-stats"))
361  {
362  g_commandLineOptions.displayMode = cInertialSenseDisplay::DMODE_STATS;
363  }
364  else if (startsWith(a, "-svr=") || startsWith(a, "-srv="))
365  {
366  g_commandLineOptions.serverConnection = &a[5];
367  }
368  else if (startsWith(a, "-s"))
369  {
370  g_commandLineOptions.displayMode = cInertialSenseDisplay::DMODE_SCROLL;
371  }
372  else if (startsWith(a, "-ub="))
373  {
374  g_commandLineOptions.updateBootloaderFilename = &a[4];
375  }
376  else if (startsWith(a, "-uf="))
377  {
378  g_commandLineOptions.updateAppFirmwareFilename = &a[4];
379  }
380  else if (startsWith(a, "-uv"))
381  {
382  g_commandLineOptions.bootloaderVerify = true;
383  }
384  else
385  {
386  cout << "Unrecognized command line option: " << a << endl;
388  return false;
389  }
390  }
391 
392  // We are either using a serial port or replaying data
393  if ((g_commandLineOptions.comPort.length() == 0) && !g_commandLineOptions.replayDataLog)
394  {
396  return false;
397  }
398  else if (g_commandLineOptions.updateAppFirmwareFilename.length() != 0 && g_commandLineOptions.comPort.length() == 0)
399  {
400  cout << "Use COM_PORT option \"-c=\" with bootloader" << endl;
401  return false;
402  }
403  else if (g_commandLineOptions.updateBootloaderFilename.length() != 0 && g_commandLineOptions.comPort.length() == 0)
404  {
405  cout << "Use COM_PORT option \"-c=\" with bootloader" << endl;
406  return false;
407  }
408 
409  return true;
410 }
411 
413 {
414  if (g_commandLineOptions.logPath.length() == 0)
415  {
416  cout << "Please specify the replay log path!" << endl;
417  return false;
418  }
419 
420  cISLogger logger;
421  if (!logger.LoadFromDirectory(g_commandLineOptions.logPath, cISLogger::ParseLogType(g_commandLineOptions.logType), { "ALL" }))
422  {
423  cout << "Failed to load log files: " << g_commandLineOptions.logPath << endl;
424  return false;
425  }
426 
427  cout << "Replaying log files: " << g_commandLineOptions.logPath << endl;
428  p_data_t *data;
429  while ((data = logger.ReadData()) != NULL)
430  {
431  g_inertialSenseDisplay.ProcessData(data, g_commandLineOptions.replayDataLog, g_commandLineOptions.replaySpeed);
432 
433 // if (data->hdr.id == DID_GPS1_RAW)
434 // {
435 // // Insert your code for processing data here
436 // }
437  }
438 
439  cout << "Done replaying log files: " << g_commandLineOptions.logPath << endl;
440  g_inertialSenseDisplay.Goodbye();
441  return true;
442 }
443 
445 {
446  cout << boldOff;
447  cout << "-----------------------------------------------------------------" << endl;
448  cout << endlbOn;
449  cout << "DESCRIPTION" << endlbOff;
450  cout << " Command line utility for communicating, logging, and updating" << endl;
451  cout << " firmware with Inertial Sense product line." << endl;
452  cout << endlbOn;
453  cout << "EXAMPLES" << endlbOn;
454  cout << " " << APP_NAME << APP_EXT << " -c=" << EXAMPLE_PORT << " -msgPresetPPD " << EXAMPLE_SPACE_1 << boldOff << " # stream post processing data (PPD) with INS2" << endlbOn;
455  cout << " " << APP_NAME << APP_EXT << " -c=" << EXAMPLE_PORT << " -msgPresetPPD -lon " << EXAMPLE_SPACE_1 << boldOff << " # stream PPD + INS2 data, logging" << endlbOn;
456  cout << " " << APP_NAME << APP_EXT << " -c=" << EXAMPLE_PORT << " -msgPresetPPD -lon -lts=1" << EXAMPLE_SPACE_1 << boldOff << " # stream PPD + INS2 data, logging, dir timestamp" << endlbOn;
457  cout << " " << APP_NAME << APP_EXT << " -c=" << EXAMPLE_PORT << " -baud=115200 -msgINS2 -msgGPS=10 -msgBaro" << boldOff << " # stream multiple at 115200 bps, GPS data streamed at 10 times the base period (200ms x 10 = 2 sec)" << endlbOn;
458  cout << " " << APP_NAME << APP_EXT << " -rp=" << EXAMPLE_LOG_DIR << boldOff << " # replay log files from a folder" << endlbOn;
459  cout << " " << APP_NAME << APP_EXT << " -c=" << EXAMPLE_PORT << " -b=" << EXAMPLE_FIRMWARE_FILE << " -bl=" << EXAMPLE_BOOTLOADER_FILE << " -bv" << boldOff << " # bootload application firmware and update bootloader if needed" << endlbOn;
460  cout << " " << APP_NAME << APP_EXT << " -c=* -baud=921600 " << EXAMPLE_SPACE_2 << boldOff << " # 921600 bps baudrate on all serial ports" << endlbOn;
461  cout << endlbOn;
462  cout << "OPTIONS (General)" << endl;
463  cout << " -h --help" << boldOff << " display this help menu" << endlbOn;
464  cout << " -c=" << boldOff << "COM_PORT select the serial port. Set COM_PORT to \"*\" for all ports and \"*4\" to use" << endlbOn;
465  cout << " " << boldOff << " only the first four ports. " << endlbOn;
466  cout << " -baud=" << boldOff << "BAUDRATE set serial port baudrate. Options: " << IS_BAUDRATE_115200 << ", " << IS_BAUDRATE_230400 << ", " << IS_BAUDRATE_460800 << ", " << IS_BAUDRATE_921600 << " (default)" << endlbOn;
467  cout << " -magRecal[n]" << boldOff << " recalibrate magnetometers: 0=multi-axis, 1=single-axis" << endlbOn;
468  cout << " -q" << boldOff << " quiet mode, no display" << endlbOn;
469  cout << " -reset " << boldOff << " issue software reset. Use caution." << endlbOn;
470  cout << " -s" << boldOff << " scroll displayed messages to show history" << endlbOn;
471  cout << " -stats" << boldOff << " display statistics of data received" << endlbOn;
472  cout << " -survey=[s],[d]" << boldOff << " survey-in and store base position to refLla: s=[" << SURVEY_IN_STATE_START_3D << "=3D, " << SURVEY_IN_STATE_START_FLOAT << "=float, " << SURVEY_IN_STATE_START_FIX << "=fix], d=durationSec" << endlbOn;
473  cout << " -uf=" << boldOff << "FILEPATH update firmware using .hex file FILEPATH. Add -baud=115200 for systems w/ baud rate limits." << endlbOn;
474  cout << " -ub=" << boldOff << "BLFILEPATH update bootloader using .bin file BLFILEPATH. Combine with -b option to check version and updated if needed." << endlbOn;
475  cout << " -uv" << boldOff << " verify after firmware update." << endlbOn;
476 
477  cout << endlbOn;
478  cout << "OPTIONS (Message Streaming)" << endl;
479  cout << " -msgPresetPPD " << boldOff << " stream preset: post processing data sets" << endlbOn;
480  cout << " -msgPresetINS2" << boldOff << " stream preset: INS2 sets" << endlbOn;
481  cout << " -msgINS[n] * " << boldOff << " stream DID_INS_[n], where [n] = 1, 2, 3 or 4 (without brackets)" << endlbOn;
482  cout << " -msgDualIMU * " << boldOff << " stream DID_DUAL_IMU" << endlbOn;
483  cout << " -msgPIMU " << boldOff << " stream DID_PREINTEGRATED_IMU" << endlbOn;
484  cout << " -msgMag[n] * " << boldOff << " stream DID_MAGNETOMETER_[n], where [n] = 1 or 2 (without brackets)" << endlbOn;
485  cout << " -msgBaro * " << boldOff << " stream DID_BAROMETER" << endlbOn;
486  cout << " -msgGPS * " << boldOff << " stream DID_GPS_NAV" << endlbOn;
487  cout << " -msgSensors * " << boldOff << " stream DID_SYS_SENSORS" << endlbOn;
488  cout << " -msgRtkPos * " << boldOff << " stream DID_GPS1_RTK_POS" << endlbOn;
489  cout << " -msgRtkPosRel *" << boldOff << " stream DID_GPS1_RTK_POS_REL" << endlbOn;
490  cout << " -msgRtkCmpRel *" << boldOff << " stream DID_GPS2_RTK_CMP_REL" << endlbOn;
491  cout << " -persistent " << boldOff << " save current streams as persistent messages enabled on startup" << endlbOn;
492  cout << " * Message can be appended with =<PERIODMULTIPLE> to change message frequency. Period is then equal to message" << endlbOn;
493  cout << " source times the PERIODMULTIPLE. If not appended the data will stream at a default rate." << endlbOn;
494  cout << " Example: -msgINS2=10 will stream data at startupNavDtMs x 10" << endlbOn;
495  cout << endlbOn;
496  cout << "OPTIONS (Logging to file, disabled by default)" << endl;
497  cout << " -lon" << boldOff << " enable logging" << endlbOn;
498  cout << " -lt=" << boldOff << "TYPE log type dat (default), sdat, kml or csv" << endlbOn;
499  cout << " -lp=" << boldOff << "PATH log data to path (default: ./" << CL_DEFAULT_LOGS_DIRECTORY << ")" << endlbOn;
500  cout << " -lms=" << boldOff << "PERCENT log max space in percent of free space (default: " << CL_DEFAULT_MAX_LOG_SPACE_PERCENT << ")" << endlbOn;
501  cout << " -lmf=" << boldOff << "BYTES log max file size in bytes (default: " << CL_DEFAULT_MAX_LOG_FILE_SIZE << ")" << endlbOn;
502  cout << " -lts=" << boldOff << "0 log sub folder, 0 or blank for none, 1 for timestamp, else use as is" << endlbOn;
503  cout << " -r" << boldOff << " replay data log from default path" << endlbOn;
504  cout << " -rp=" << boldOff << "PATH replay data log from PATH" << endlbOn;
505  cout << " -rs=" << boldOff << "SPEED replay data log at x SPEED. SPEED=0 runs as fast as possible." << endlbOn;
506  cout << endlbOn;
507  cout << "OPTIONS (Read or write flash configuration)" << endl;
508  cout << " -flashConfig" << boldOff << " list all \"keys\" and \"values\"" << endlbOn;
509  cout << " \"-flashConfig=key=value|key=value\" " << boldOff << endlbOn;
510  cout << " " << boldOff << " set key / value pairs in flash config. Surround with \"quotes\" when using pipe operator." << endlbOn;
511  cout << "EXAMPLES" << endlbOn;
512  cout << " " << APP_NAME << APP_EXT << " -c=" << EXAMPLE_PORT << " -flashConfig " << boldOff << "# Read from device and print all keys and values" << endlbOn;
513  cout << " " << APP_NAME << APP_EXT << " -c=" << EXAMPLE_PORT << " -flashConfig=insRotation[0]=1.5708|insOffset[1]=1.2 " << boldOff << "# Set multiple flashConfig values" << endlbOn;
514  cout << endlbOn;
515  cout << "OPTIONS (Client / Server)" << endl;
516  cout << " -svr=" << boldOff << "INFO used to retrieve external data and send to the uINS. Examples:" << endl;
517  cout << " - SERIAL: -svr=RTCM3:SERIAL:" << EXAMPLE_PORT << ":57600 (port, baud rate)" << endl;
518  cout << " - RTCM3: -svr=RTCM3:192.168.1.100:7777:URL:user:password" << endl;
519  cout << " (URL, user, password optional)" << endl;
520  cout << " - UBLOX data: -svr=UBLOX:192.168.1.100:7777 (no URL, user or password)" << endl;
521  cout << " - InertialSense: -svr=IS:192.168.1.100:7777 (no URL, user or password)" << endlbOn;
522  cout << " -host=" << boldOff << "IP:PORT used to host a TCP/IP InertialSense server. Examples:" << endl;
523  cout << " -host=:7777 (IP is optional)" << endl;
524  cout << " -host=192.168.1.43:7777" << endl;
525 
526  cout << boldOff; // Last line. Leave bold text off on exit.
527 }
528 
530 {
531  cout << endlbOff << "Run \"" << boldOn << "cltool -h" << boldOff << "\" to display the help menu." << endl;
532 }
533 
534 bool cltool_updateFlashConfig(InertialSense& inertialSenseInterface, string flashConfigString)
535 {
536  nvm_flash_cfg_t flashConfig = inertialSenseInterface.GetFlashConfig();
538 
539  if (flashConfigString.length() < 2)
540  {
541  // read flash config and display
542  data_mapping_string_t stringBuffer;
543  cout << "Current flash config" << endl;
544  for (map_name_to_info_t::const_iterator i = flashMap.begin(); i != flashMap.end(); i++)
545  {
546  if (cISDataMappings::DataToString(i->second, NULL, (const uint8_t*)&flashConfig, stringBuffer))
547  {
548  cout << i->second.name << " = " << stringBuffer << endl;
549  }
550  }
551  return false;
552  }
553  else
554  {
555  vector<string> keyValues;
556  splitString(flashConfigString, "|", keyValues);
557  for (size_t i = 0; i < keyValues.size(); i++)
558  {
559  vector<string> keyAndValue;
560  splitString(keyValues[i], "=", keyAndValue);
561  if (keyAndValue.size() == 2)
562  {
563  if (flashMap.find(keyAndValue[0]) == flashMap.end())
564  {
565  cout << "Unrecognized flash config key '" << keyAndValue[0] << "' specified, ignoring." << endl;
566  }
567  else
568  {
569  const data_info_t& info = flashMap.at(keyAndValue[0]);
570  int radix = (keyAndValue[1].compare(0, 2, "0x") == 0 ? 16 : 10);
571  int substrIndex = 2 * (radix == 16); // skip 0x for hex
572  const string& str = keyAndValue[1].substr(substrIndex);
573  cISDataMappings::StringToData(str.c_str(), (int)str.length(), NULL, (uint8_t*)&flashConfig, info, radix);
574  cout << "Updated flash config key '" << keyAndValue[0] << "' to '" << keyAndValue[1].c_str() << "'" << endl;
575  }
576  }
577  }
578  inertialSenseInterface.SetFlashConfig(flashConfig);
579  g_inertialSenseDisplay.Clear();
580  return true;
581  }
582 }
string asciiMessages
Definition: cltool.h:60
int streamRtkCmpRel
Definition: cltool.h:76
static const map_name_to_info_t * GetMapInfo(uint32_t dataId)
#define CL_DEFAULT_DISPLAY_MODE
Definition: cltool.cpp:54
#define CL_DEFAULT_BOOTLOAD_VERIFY
Definition: cltool.cpp:61
ostream & boldOn(ostream &os)
Definition: ISDisplay.cpp:1386
bool bootloaderVerify
Definition: cltool.h:54
string logPath
Definition: cltool.h:87
string updateBootloaderFilename
Definition: cltool.h:53
void ProcessData(p_data_t *data, bool enableReplay=false, double replaySpeedX=1.0)
Definition: ISDisplay.cpp:283
#define EXAMPLE_PORT
Definition: cltool.h:40
int streamIMU1
Definition: cltool.h:71
uint8_t buf[PKT_BUF_SIZE]
Definition: ISComm.h:198
int streamRtkPosRel
Definition: cltool.h:75
#define EXAMPLE_FIRMWARE_FILE
Definition: cltool.h:42
uint32_t maxDurationSec
Definition: data_sets.h:2849
uint32_t state
Definition: data_sets.h:2846
cInertialSenseDisplay g_inertialSenseDisplay
Definition: cltool.cpp:18
ostream & endlbOff(ostream &os)
Definition: ISDisplay.cpp:1433
#define EXAMPLE_LOG_DIR
Definition: cltool.h:41
bool cltool_replayDataLog()
Definition: cltool.cpp:412
int streamIMU2
Definition: cltool.h:72
size_t splitString(const string &s, const string &delimiter, vector< string > &result)
bool softwareReset
Definition: cltool.h:56
#define EXAMPLE_SPACE_2
Definition: cltool.h:45
cmd_options_t g_commandLineOptions
Definition: cltool.cpp:16
#define NULL
Definition: nm_bsp.h:52
float maxLogSpacePercent
Definition: cltool.h:88
int streamRTOS
Definition: cltool.h:82
double replaySpeed
Definition: cltool.h:61
#define RMC_PRESET_INS_BITS
Definition: data_sets.h:1284
p_data_t * ReadData(unsigned int device=0)
Definition: ISLogger.cpp:402
ostream & endlbOn(ostream &os)
Definition: ISDisplay.cpp:1417
int baudRate
Definition: cltool.h:91
#define EXAMPLE_SPACE_1
Definition: cltool.h:44
int streamSensorsADC
Definition: cltool.h:83
bool cltool_parseCommandLine(int argc, char *argv[])
Definition: cltool.cpp:63
#define NULLPTR
Definition: ISConstants.h:426
bool persistentMessages
Definition: cltool.h:65
bool cltool_setupLogger(InertialSense &inertialSenseInterface)
Definition: cltool.cpp:27
static bool StringToData(const char *stringBuffer, int stringLength, const p_data_hdr_t *hdr, uint8_t *dataBuffer, const data_info_t &info, int radix=10, bool json=false)
char data_mapping_string_t[IS_DATA_MAPPING_MAX_STRING_LENGTH]
int cltool_serialPortSendComManager(CMHANDLE cmHandle, int pHandle, buffer_t *bufferToSend)
Definition: cltool.cpp:20
int streamINS2
Definition: cltool.h:67
std::ostream & cout()
bool SetLoggerEnabled(bool enable, const string &path=cISLogger::g_emptyString, cISLogger::eLogType logType=cISLogger::eLogType::LOGTYPE_DAT, uint64_t rmcPreset=RMC_PRESET_PPD_BITS, float maxDiskSpacePercent=0.5f, uint32_t maxFileSize=1024 *1024 *5, const string &subFolder=cISLogger::g_emptyString)
static eLogType ParseLogType(const string &logTypeString)
Definition: ISLogger.h:134
bool enableLogging
Definition: cltool.h:85
nvm_flash_cfg_t GetFlashConfig(int pHandle=0)
bool magRecal
Definition: cltool.h:57
bool cltool_updateFlashConfig(InertialSense &inertialSenseInterface, string flashConfigString)
Definition: cltool.cpp:534
void cltool_outputUsage()
Definition: cltool.cpp:444
ostream & boldOff(ostream &os)
Definition: ISDisplay.cpp:1401
string logType
Definition: cltool.h:86
bool disableBroadcastsOnClose
Definition: cltool.h:92
void SetFlashConfig(const nvm_flash_cfg_t &flashConfig, int pHandle=0)
float minAccuracy
Definition: data_sets.h:2852
string logSubFolder
Definition: cltool.h:90
string updateAppFirmwareFilename
Definition: cltool.h:52
int streamGPS
Definition: cltool.h:73
void * CMHANDLE
Definition: com_manager.h:119
#define DID_FLASH_CONFIG
Definition: data_sets.h:46
int streamDThetaVel
Definition: cltool.h:81
int streamSysSensors
Definition: cltool.h:80
survey_in_t surveyIn
Definition: cltool.h:59
int streamRtkPos
Definition: cltool.h:74
int serialPortWrite(serial_port_t *serialPort, const unsigned char *buffer, int writeCount)
uint64_t rmcPreset
Definition: cltool.h:64
serial_port_t g_serialPort
Definition: cltool.cpp:17
int streamMag1
Definition: cltool.h:77
string comPort
Definition: cltool.h:51
int displayMode
Definition: cltool.h:62
int streamDualIMU
Definition: cltool.h:70
#define EXAMPLE_BOOTLOADER_FILE
Definition: cltool.h:43
int streamBaro
Definition: cltool.h:79
USBInterfaceDescriptor data
#define CL_DEFAULT_REPLAY_SPEED
Definition: cltool.cpp:60
#define CL_DEFAULT_ENABLE_LOGGING
Definition: cltool.cpp:57
uint32_t size
Definition: ISComm.h:195
#define false
Definition: compiler.h:424
string flashConfig
Definition: cltool.h:97
static bool DataToString(const data_info_t &info, const p_data_hdr_t *hdr, const uint8_t *dataBuffer, data_mapping_string_t stringBuffer, bool json=false)
#define CL_DEFAULT_COM_PORT
Definition: cltool.cpp:53
uint32_t magRecalMode
Definition: cltool.h:58
int streamINS4
Definition: cltool.h:69
bool LoadFromDirectory(const string &directory, eLogType logType=LOGTYPE_DAT, vector< string > serials={})
Definition: ISLogger.cpp:259
uint32_t maxLogFileSize
Definition: cltool.h:89
static const string g_emptyString
Definition: ISLogger.h:59
#define CL_DEFAULT_LOG_TYPE
Definition: cltool.cpp:55
map< string, data_info_t, sCaseInsensitiveCompare > map_name_to_info_t
#define CL_DEFAULT_BAUD_RATE
Definition: cltool.cpp:52
static string CreateCurrentTimestamp()
Definition: ISLogger.cpp:180
#define CL_DEFAULT_MAX_LOG_SPACE_PERCENT
Definition: cltool.cpp:59
#define CL_DEFAULT_LOGS_DIRECTORY
Definition: cltool.cpp:56
int streamINS3
Definition: cltool.h:68
uint32_t timeoutFlushLoggerSeconds
Definition: cltool.h:99
#define RMC_PRESET_PPD_BITS
Definition: data_sets.h:1282
static bool startsWith(const char *str, const char *pre)
Definition: cltool.cpp:46
bool replayDataLog
Definition: cltool.h:55
string host
Definition: cltool.h:95
#define CL_DEFAULT_MAX_LOG_FILE_SIZE
Definition: cltool.cpp:58
void cltool_outputHelp()
Definition: cltool.cpp:529
string serverConnection
Definition: cltool.h:94
#define APP_EXT
Definition: cltool.h:39
int streamMag2
Definition: cltool.h:78
#define APP_NAME
Definition: cltool.h:29
int streamINS1
Definition: cltool.h:66


inertial_sense_ros
Author(s):
autogenerated on Sat Sep 19 2020 03:19:04