cltool.cpp
Go to the documentation of this file.
1 /*
2 MIT LICENSE
3 
4 Copyright (c) 2014-2021 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, "-evbFlashConfig="))
114  {
115  g_commandLineOptions.evbFlashConfig = &a[16];
116  }
117  else if (startsWith(a, "-evbFlashConfig"))
118  {
119  g_commandLineOptions.evbFlashConfig = ".";
120  }
121  else if (startsWith(a, "-flashConfig="))
122  {
123  g_commandLineOptions.flashConfig = &a[13];
124  }
125  else if (startsWith(a, "-flashConfig"))
126  {
127  g_commandLineOptions.flashConfig = ".";
128  }
129  else if (startsWith(a, "-host="))
130  {
131  g_commandLineOptions.host = &a[6];
132  }
133  else if (startsWith(a, "-h") || startsWith(a, "--h") || startsWith(a, "-help") || startsWith(a, "--help"))
134  {
136  return false;
137  }
138  else if (startsWith(a, "-lms="))
139  {
140  g_commandLineOptions.maxLogSpacePercent = (float)atof(&a[5]);
141  }
142  else if (startsWith(a, "-lmf="))
143  {
144  g_commandLineOptions.maxLogFileSize = (uint32_t)strtoul(&a[5], NULL, 10);
145  }
146  else if (startsWith(a, "-log-flush-timeout="))
147  {
148  g_commandLineOptions.timeoutFlushLoggerSeconds = strtoul(&a[19], NULLPTR, 10);
149  }
150  else if (startsWith(a, "-lts="))
151  {
152  const char* subFolder = &a[5];
153  if (*subFolder == '1' || startsWith(subFolder, "true"))
154  {
155  g_commandLineOptions.logSubFolder = cISLogger::CreateCurrentTimestamp();
156  }
157  else if (*subFolder == '\0' || *subFolder == '0' || startsWith(subFolder, "false"))
158  {
159  g_commandLineOptions.logSubFolder = cISLogger::g_emptyString;
160  }
161  else
162  {
163  g_commandLineOptions.logSubFolder = subFolder;
164  }
165  }
166  else if (startsWith(a, "-lp="))
167  {
168  g_commandLineOptions.logPath = &a[4];
169  }
170  else if (startsWith(a, "-lt="))
171  {
172  g_commandLineOptions.logType = &a[4];
173  }
174  else if (startsWith(a, "-lon"))
175  {
176  g_commandLineOptions.enableLogging = true;
177  }
178  else if (startsWith(a, "-magRecal"))
179  {
180  g_commandLineOptions.rmcPreset = 0;
181  g_commandLineOptions.magRecal = true;
182  g_commandLineOptions.magRecalMode = strtol(a + 9, NULL, 10);
183  }
184  else if (startsWith(a, "-survey="))
185  {
186  g_commandLineOptions.rmcPreset = 0;
187  g_commandLineOptions.surveyIn.state = strtol(a + 8, NULL, 10);
188  int maxDurationSec = strtol(a + 10, NULL, 10);
189  if (maxDurationSec > 5)
190  {
191  g_commandLineOptions.surveyIn.maxDurationSec = maxDurationSec;
192  }
193  }
194  else if (startsWith(a, "-msgBaro="))
195  {
196  g_commandLineOptions.streamBaro = (int)atof(&a[9]);
197  }
198  else if (startsWith(a, "-msgBaro"))
199  {
200  g_commandLineOptions.streamBaro = 50;
201  }
202  else if (startsWith(a, "-msgDualIMU="))
203  {
204  g_commandLineOptions.streamDualIMU = (int)atof(&a[12]);
205  }
206  else if (startsWith(a, "-msgDualIMU"))
207  {
208  g_commandLineOptions.streamDualIMU = 50;
209  }
210  else if (startsWith(a, "-msgGPS="))
211  {
212  g_commandLineOptions.streamGPS = (int)atof(&a[8]);
213  }
214  else if (startsWith(a, "-msgGPS"))
215  {
216  g_commandLineOptions.streamGPS = 1;
217  }
218  else if (startsWith(a, "-msgIMU1="))
219  {
220  g_commandLineOptions.streamIMU1 = (int)atof(&a[9]);
221  }
222  else if (startsWith(a, "-msgIMU1"))
223  {
224  g_commandLineOptions.streamIMU1 = 50;
225  }
226  else if (startsWith(a, "-msgIMU2="))
227  {
228  g_commandLineOptions.streamIMU2 = (int)atof(&a[9]);
229  }
230  else if (startsWith(a, "-msgIMU2"))
231  {
232  g_commandLineOptions.streamIMU2 = 50;
233  }
234  else if (startsWith(a, "-msgINS1="))
235  {
236  g_commandLineOptions.streamINS1 = (int)atof(&a[9]);
237  }
238  else if (startsWith(a, "-msgINS1"))
239  {
240  g_commandLineOptions.streamINS1 = 50;
241  }
242  else if (startsWith(a, "-msgINS2="))
243  {
244  g_commandLineOptions.streamINS2 = (int)atof(&a[9]);
245  }
246  else if (startsWith(a, "-msgINS2"))
247  {
248  g_commandLineOptions.streamINS2 = 50;
249  }
250  else if (startsWith(a, "-msgINS3="))
251  {
252  g_commandLineOptions.streamINS3 = (int)atof(&a[9]);
253  }
254  else if (startsWith(a, "-msgINS3"))
255  {
256  g_commandLineOptions.streamINS3 = 50;
257  }
258  else if (startsWith(a, "-msgINS4="))
259  {
260  g_commandLineOptions.streamINS4 = (int)atof(&a[9]);
261  }
262  else if (startsWith(a, "-msgINS4"))
263  {
264  g_commandLineOptions.streamINS4 = 50;
265  }
266  else if (startsWith(a, "-msgMag1="))
267  {
268  g_commandLineOptions.streamMag1 = (int)atof(&a[9]);
269  }
270  else if (startsWith(a, "-msgMag1"))
271  {
272  g_commandLineOptions.streamMag1 = 50;
273  }
274  else if (startsWith(a, "-msgMag2="))
275  {
276  g_commandLineOptions.streamMag2 = (int)atof(&a[9]);
277  }
278  else if (startsWith(a, "-msgMag2"))
279  {
280  g_commandLineOptions.streamMag2 = 50;
281  }
282  else if (startsWith(a, "-msgPIMU"))
283  {
284  g_commandLineOptions.streamDThetaVel = 1;
285  }
286  else if (startsWith(a, "-msgPresetPPD"))
287  {
288  g_commandLineOptions.rmcPreset = RMC_PRESET_PPD_BITS;
289  }
290  else if (startsWith(a, "-msgPresetINS2"))
291  {
292  g_commandLineOptions.rmcPreset = RMC_PRESET_INS_BITS;
293  }
294  else if (startsWith(a, "-msgRtkPosRel="))
295  {
296  g_commandLineOptions.streamRtkPosRel = (int)atof(&a[11]);
297  }
298  else if (startsWith(a, "-msgRtkPosRel"))
299  {
300  g_commandLineOptions.streamRtkPosRel = 1;
301  }
302  else if (startsWith(a, "-msgRtkCmpRel="))
303  {
304  g_commandLineOptions.streamRtkCmpRel = (int)atof(&a[11]);
305  }
306  else if (startsWith(a, "-msgRtkCmpRel"))
307  {
308  g_commandLineOptions.streamRtkCmpRel = 1;
309  }
310  else if (startsWith(a, "-msgRtkPos="))
311  {
312  g_commandLineOptions.streamRtkPos = (int)atof(&a[11]);
313  }
314  else if (startsWith(a, "-msgRtkPos"))
315  {
316  g_commandLineOptions.streamRtkPos = 1;
317  }
318  else if (startsWith(a, "-msgRTOS="))
319  {
320  g_commandLineOptions.streamRTOS = (int)atof(&a[9]);
321  }
322  else if (startsWith(a, "-msgRTOS"))
323  {
324  g_commandLineOptions.streamRTOS = 250;
325  }
326  else if (startsWith(a, "-msgSensorsADC="))
327  {
328  g_commandLineOptions.streamSensorsADC = (int)atof(&a[15]);
329  }
330  else if (startsWith(a, "-msgSensorsADC"))
331  {
332  g_commandLineOptions.streamSensorsADC = 50;
333  }
334  else if (startsWith(a, "-msgSensors="))
335  {
336  g_commandLineOptions.streamSysSensors = (int)atof(&a[12]);
337  }
338  else if (startsWith(a, "-msgSensors"))
339  {
340  g_commandLineOptions.streamSysSensors = 50;
341  }
342  else if (startsWith(a, "-msgWheel"))
343  {
344  g_commandLineOptions.streamWheelEncoder = 1;
345  }
346  else if (startsWith(a, "-persistent"))
347  {
348  g_commandLineOptions.persistentMessages = true;
349  }
350  else if (startsWith(a, "-q"))
351  {
352  g_commandLineOptions.displayMode = cInertialSenseDisplay::DMODE_QUIET;
353  }
354  else if (startsWith(a, "-rp="))
355  {
356  g_commandLineOptions.replayDataLog = true;
357  g_commandLineOptions.logPath = &a[4];
358  }
359  else if (startsWith(a, "-rs="))
360  {
361  g_commandLineOptions.replayDataLog = true;
362  g_commandLineOptions.replaySpeed = (float)atof(&a[4]);
363  }
364  else if (startsWith(a, "-reset"))
365  {
366  g_commandLineOptions.softwareReset = true;
367  }
368  else if (startsWith(a, "-r"))
369  {
370  g_commandLineOptions.replayDataLog = true;
371  }
372  else if (startsWith(a, "-stats"))
373  {
374  g_commandLineOptions.displayMode = cInertialSenseDisplay::DMODE_STATS;
375  }
376  else if (startsWith(a, "-svr=") || startsWith(a, "-srv="))
377  {
378  g_commandLineOptions.serverConnection = &a[5];
379  }
380  else if (startsWith(a, "-s"))
381  {
382  g_commandLineOptions.displayMode = cInertialSenseDisplay::DMODE_SCROLL;
383  }
384  else if (startsWith(a, "-ub="))
385  {
386  g_commandLineOptions.updateBootloaderFilename = &a[4];
387  }
388  else if (startsWith(a, "-uf="))
389  {
390  g_commandLineOptions.updateAppFirmwareFilename = &a[4];
391  }
392  else if (startsWith(a, "-uv"))
393  {
394  g_commandLineOptions.bootloaderVerify = true;
395  }
396  else
397  {
398  cout << "Unrecognized command line option: " << a << endl;
400  return false;
401  }
402  }
403 
404  // We are either using a serial port or replaying data
405  if ((g_commandLineOptions.comPort.length() == 0) && !g_commandLineOptions.replayDataLog)
406  {
408  return false;
409  }
410  else if (g_commandLineOptions.updateAppFirmwareFilename.length() != 0 && g_commandLineOptions.comPort.length() == 0)
411  {
412  cout << "Use COM_PORT option \"-c=\" with bootloader" << endl;
413  return false;
414  }
415  else if (g_commandLineOptions.updateBootloaderFilename.length() != 0 && g_commandLineOptions.comPort.length() == 0)
416  {
417  cout << "Use COM_PORT option \"-c=\" with bootloader" << endl;
418  return false;
419  }
420 
421  return true;
422 }
423 
425 {
426  if (g_commandLineOptions.logPath.length() == 0)
427  {
428  cout << "Please specify the replay log path!" << endl;
429  return false;
430  }
431 
432  cISLogger logger;
433  if (!logger.LoadFromDirectory(g_commandLineOptions.logPath, cISLogger::ParseLogType(g_commandLineOptions.logType), { "ALL" }))
434  {
435  cout << "Failed to load log files: " << g_commandLineOptions.logPath << endl;
436  return false;
437  }
438 
439  cout << "Replaying log files: " << g_commandLineOptions.logPath << endl;
440  p_data_t *data;
441  while ((data = logger.ReadData()) != NULL)
442  {
443  g_inertialSenseDisplay.ProcessData(data, g_commandLineOptions.replayDataLog, g_commandLineOptions.replaySpeed);
444 
445 // if (data->hdr.id == DID_GPS1_RAW)
446 // {
447 // // Insert your code for processing data here
448 // }
449  }
450 
451  cout << "Done replaying log files: " << g_commandLineOptions.logPath << endl;
452  g_inertialSenseDisplay.Goodbye();
453  return true;
454 }
455 
457 {
458  cout << boldOff;
459  cout << "-----------------------------------------------------------------" << endl;
460  cout << endlbOn;
461  cout << "DESCRIPTION" << endlbOff;
462  cout << " Command line utility for communicating, logging, and updating" << endl;
463  cout << " firmware with Inertial Sense product line." << endl;
464  cout << endlbOn;
465  cout << "EXAMPLES" << endlbOn;
466  cout << " " << APP_NAME << APP_EXT << " -c=" << EXAMPLE_PORT << " -msgPresetPPD " << EXAMPLE_SPACE_1 << boldOff << " # stream post processing data (PPD) with INS2" << endlbOn;
467  cout << " " << APP_NAME << APP_EXT << " -c=" << EXAMPLE_PORT << " -msgPresetPPD -lon " << EXAMPLE_SPACE_1 << boldOff << " # stream PPD + INS2 data, logging" << endlbOn;
468  cout << " " << APP_NAME << APP_EXT << " -c=" << EXAMPLE_PORT << " -msgPresetPPD -lon -lts=1" << EXAMPLE_SPACE_1 << boldOff << " # stream PPD + INS2 data, logging, dir timestamp" << endlbOn;
469  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;
470  cout << " " << APP_NAME << APP_EXT << " -rp=" << EXAMPLE_LOG_DIR << boldOff << " # replay log files from a folder" << endlbOn;
471  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;
472  cout << " " << APP_NAME << APP_EXT << " -c=* -baud=921600 " << EXAMPLE_SPACE_2 << boldOff << " # 921600 bps baudrate on all serial ports" << endlbOn;
473  cout << endlbOn;
474  cout << "OPTIONS (General)" << endl;
475  cout << " -h --help" << boldOff << " display this help menu" << endlbOn;
476  cout << " -c=" << boldOff << "COM_PORT select the serial port. Set COM_PORT to \"*\" for all ports and \"*4\" to use" << endlbOn;
477  cout << " " << boldOff << " only the first four ports. " << endlbOn;
478  cout << " -baud=" << boldOff << "BAUDRATE set serial port baudrate. Options: " << IS_BAUDRATE_115200 << ", " << IS_BAUDRATE_230400 << ", " << IS_BAUDRATE_460800 << ", " << IS_BAUDRATE_921600 << " (default)" << endlbOn;
479  cout << " -magRecal[n]" << boldOff << " recalibrate magnetometers: 0=multi-axis, 1=single-axis" << endlbOn;
480  cout << " -q" << boldOff << " quiet mode, no display" << endlbOn;
481  cout << " -reset " << boldOff << " issue software reset. Use caution." << endlbOn;
482  cout << " -s" << boldOff << " scroll displayed messages to show history" << endlbOn;
483  cout << " -stats" << boldOff << " display statistics of data received" << endlbOn;
484  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;
485  cout << " -uf=" << boldOff << "FILEPATH update firmware using .hex file FILEPATH. Add -baud=115200 for systems w/ baud rate limits." << endlbOn;
486  cout << " -ub=" << boldOff << "BLFILEPATH update bootloader using .bin file BLFILEPATH. Combine with -b option to check version and updated if needed." << endlbOn;
487  cout << " -uv" << boldOff << " verify after firmware update." << endlbOn;
488 
489  cout << endlbOn;
490  cout << "OPTIONS (Message Streaming)" << endl;
491  cout << " -msgPresetPPD " << boldOff << " stream preset: post processing data sets" << endlbOn;
492  cout << " -msgPresetINS2" << boldOff << " stream preset: INS2 sets" << endlbOn;
493  cout << " -msgINS[n] * " << boldOff << " stream DID_INS_[n], where [n] = 1, 2, 3 or 4 (without brackets)" << endlbOn;
494  cout << " -msgDualIMU * " << boldOff << " stream DID_DUAL_IMU" << endlbOn;
495  cout << " -msgPIMU " << boldOff << " stream DID_PREINTEGRATED_IMU" << endlbOn;
496  cout << " -msgMag[n] * " << boldOff << " stream DID_MAGNETOMETER_[n], where [n] = 1 or 2 (without brackets)" << endlbOn;
497  cout << " -msgBaro * " << boldOff << " stream DID_BAROMETER" << endlbOn;
498  cout << " -msgGPS * " << boldOff << " stream DID_GPS_NAV" << endlbOn;
499  cout << " -msgSensors * " << boldOff << " stream DID_SYS_SENSORS" << endlbOn;
500  cout << " -msgRtkPos * " << boldOff << " stream DID_GPS1_RTK_POS" << endlbOn;
501  cout << " -msgRtkPosRel *" << boldOff << " stream DID_GPS1_RTK_POS_REL" << endlbOn;
502  cout << " -msgRtkCmpRel *" << boldOff << " stream DID_GPS2_RTK_CMP_REL" << endlbOn;
503  cout << " -persistent " << boldOff << " save current streams as persistent messages enabled on startup" << endlbOn;
504  cout << " * Message can be appended with =<PERIODMULTIPLE> to change message frequency. Period is then equal to message" << endlbOn;
505  cout << " source times the PERIODMULTIPLE. If not appended the data will stream at a default rate." << endlbOn;
506  cout << " Example: -msgINS2=10 will stream data at startupNavDtMs x 10" << endlbOn;
507  cout << endlbOn;
508  cout << "OPTIONS (Logging to file, disabled by default)" << endl;
509  cout << " -lon" << boldOff << " enable logging" << endlbOn;
510  cout << " -lt=" << boldOff << "TYPE log type dat (default), sdat, kml or csv" << endlbOn;
511  cout << " -lp=" << boldOff << "PATH log data to path (default: ./" << CL_DEFAULT_LOGS_DIRECTORY << ")" << endlbOn;
512  cout << " -lms=" << boldOff << "PERCENT log max space in percent of free space (default: " << CL_DEFAULT_MAX_LOG_SPACE_PERCENT << ")" << endlbOn;
513  cout << " -lmf=" << boldOff << "BYTES log max file size in bytes (default: " << CL_DEFAULT_MAX_LOG_FILE_SIZE << ")" << endlbOn;
514  cout << " -lts=" << boldOff << "0 log sub folder, 0 or blank for none, 1 for timestamp, else use as is" << endlbOn;
515  cout << " -r" << boldOff << " replay data log from default path" << endlbOn;
516  cout << " -rp=" << boldOff << "PATH replay data log from PATH" << endlbOn;
517  cout << " -rs=" << boldOff << "SPEED replay data log at x SPEED. SPEED=0 runs as fast as possible." << endlbOn;
518  cout << endlbOn;
519  cout << "OPTIONS (Read or write flash configuration)" << endl;
520  cout << " -flashConfig" << boldOff << " list all \"keys\" and \"values\"" << endlbOn;
521  cout << " \"-flashConfig=key=value|key=value\" " << boldOff << endlbOn;
522  cout << " -evbFlashConfig" << boldOff << " list all \"keys\" and \"values\"" << endlbOn;
523  cout << " \"-evbFlashConfig=key=value|key=value\" " << boldOff << endlbOn;
524  cout << " " << boldOff << " set key / value pairs in flash config. Surround with \"quotes\" when using pipe operator." << endlbOn;
525  cout << "EXAMPLES" << endlbOn;
526  cout << " " << APP_NAME << APP_EXT << " -c=" << EXAMPLE_PORT << " -flashConfig " << boldOff << "# Read from device and print all keys and values" << endlbOn;
527  cout << " " << APP_NAME << APP_EXT << " -c=" << EXAMPLE_PORT << " -flashConfig=insRotation[0]=1.5708|insOffset[1]=1.2 " << boldOff << "# Set multiple flashConfig values" << endlbOn;
528  cout << endlbOn;
529  cout << "OPTIONS (Client / Server)" << endl;
530  cout << " -svr=" << boldOff << "INFO used to retrieve external data and send to the uINS. Examples:" << endl;
531  cout << " - SERIAL: -svr=RTCM3:SERIAL:" << EXAMPLE_PORT << ":57600 (port, baud rate)" << endl;
532  cout << " - RTCM3: -svr=RTCM3:192.168.1.100:7777:URL:user:password" << endl;
533  cout << " (URL, user, password optional)" << endl;
534  cout << " - UBLOX data: -svr=UBLOX:192.168.1.100:7777 (no URL, user or password)" << endl;
535  cout << " - InertialSense: -svr=IS:192.168.1.100:7777 (no URL, user or password)" << endlbOn;
536  cout << " -host=" << boldOff << "IP:PORT used to host a TCP/IP InertialSense server. Examples:" << endl;
537  cout << " -host=:7777 (IP is optional)" << endl;
538  cout << " -host=192.168.1.43:7777" << endl;
539 
540  cout << boldOff; // Last line. Leave bold text off on exit.
541 }
542 
544 {
545  cout << endlbOff << "Run \"" << boldOn << "cltool -h" << boldOff << "\" to display the help menu." << endl;
546 }
547 
548 bool cltool_updateFlashConfig(InertialSense& inertialSenseInterface, string flashConfigString)
549 {
550  nvm_flash_cfg_t flashConfig = inertialSenseInterface.GetFlashConfig();
552 
553  if (flashConfigString.length() < 2)
554  {
555  // read flash config and display
556  data_mapping_string_t stringBuffer;
557  cout << "Current flash config" << endl;
558  for (map_name_to_info_t::const_iterator i = flashMap.begin(); i != flashMap.end(); i++)
559  {
560  if (cISDataMappings::DataToString(i->second, NULL, (const uint8_t*)&flashConfig, stringBuffer))
561  {
562  cout << i->second.name << " = " << stringBuffer << endl;
563  }
564  }
565  return false;
566  }
567  else
568  {
569  vector<string> keyValues;
570  splitString(flashConfigString, "|", keyValues);
571  for (size_t i = 0; i < keyValues.size(); i++)
572  {
573  vector<string> keyAndValue;
574  splitString(keyValues[i], "=", keyAndValue);
575  if (keyAndValue.size() == 2)
576  {
577  if (flashMap.find(keyAndValue[0]) == flashMap.end())
578  {
579  cout << "Unrecognized flash config key '" << keyAndValue[0] << "' specified, ignoring." << endl;
580  }
581  else
582  {
583  const data_info_t& info = flashMap.at(keyAndValue[0]);
584  int radix = (keyAndValue[1].compare(0, 2, "0x") == 0 ? 16 : 10);
585  int substrIndex = 2 * (radix == 16); // skip 0x for hex
586  const string& str = keyAndValue[1].substr(substrIndex);
587  cISDataMappings::StringToData(str.c_str(), (int)str.length(), NULL, (uint8_t*)&flashConfig, info, radix);
588  cout << "Updated flash config key '" << keyAndValue[0] << "' to '" << keyAndValue[1].c_str() << "'" << endl;
589  }
590  }
591  }
592  inertialSenseInterface.SetFlashConfig(flashConfig);
593  g_inertialSenseDisplay.Clear();
594  return true;
595  }
596 }
597 
598 bool cltool_updateEvbFlashConfig(InertialSense& inertialSenseInterface, string flashConfigString)
599 {
600  evb_flash_cfg_t evbFlashCfg = inertialSenseInterface.GetEvbFlashConfig();
602 
603  if (flashConfigString.length() < 2)
604  {
605  // read flash config and display
606  data_mapping_string_t stringBuffer;
607  cout << "Current EVB flash config" << endl;
608  for (map_name_to_info_t::const_iterator i = flashMap.begin(); i != flashMap.end(); i++)
609  {
610  if (cISDataMappings::DataToString(i->second, NULL, (const uint8_t*)&evbFlashCfg, stringBuffer))
611  {
612  cout << i->second.name << " = " << stringBuffer << endl;
613  }
614  }
615  return false;
616  }
617  else
618  {
619  vector<string> keyValues;
620  splitString(flashConfigString, "|", keyValues);
621  for (size_t i = 0; i < keyValues.size(); i++)
622  {
623  vector<string> keyAndValue;
624  splitString(keyValues[i], "=", keyAndValue);
625  if (keyAndValue.size() == 2)
626  {
627  if (flashMap.find(keyAndValue[0]) == flashMap.end())
628  {
629  cout << "Unrecognized EVB flash config key '" << keyAndValue[0] << "' specified, ignoring." << endl;
630  }
631  else
632  {
633  const data_info_t& info = flashMap.at(keyAndValue[0]);
634  int radix = (keyAndValue[1].compare(0, 2, "0x") == 0 ? 16 : 10);
635  int substrIndex = 2 * (radix == 16); // skip 0x for hex
636  const string& str = keyAndValue[1].substr(substrIndex);
637  cISDataMappings::StringToData(str.c_str(), (int)str.length(), NULL, (uint8_t*)&evbFlashCfg, info, radix);
638  cout << "Updated EVB flash config key '" << keyAndValue[0] << "' to '" << keyAndValue[1].c_str() << "'" << endl;
639  }
640  }
641  }
642  inertialSenseInterface.SetEvbFlashConfig(evbFlashCfg);
643  g_inertialSenseDisplay.Clear();
644  return true;
645  }
646 }
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
evb_flash_cfg_t GetEvbFlashConfig(int pHandle=0)
#define CL_DEFAULT_BOOTLOAD_VERIFY
Definition: cltool.cpp:61
ostream & boldOn(ostream &os)
Definition: ISDisplay.cpp:1415
bool bootloaderVerify
Definition: cltool.h:54
string logPath
Definition: cltool.h:88
bool cltool_updateEvbFlashConfig(InertialSense &inertialSenseInterface, string flashConfigString)
Definition: cltool.cpp:598
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:199
int streamRtkPosRel
Definition: cltool.h:75
#define EXAMPLE_FIRMWARE_FILE
Definition: cltool.h:42
uint32_t maxDurationSec
Definition: data_sets.h:2966
uint32_t state
Definition: data_sets.h:2963
cInertialSenseDisplay g_inertialSenseDisplay
Definition: cltool.cpp:18
ostream & endlbOff(ostream &os)
Definition: ISDisplay.cpp:1462
#define EXAMPLE_LOG_DIR
Definition: cltool.h:41
bool cltool_replayDataLog()
Definition: cltool.cpp:424
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:89
int streamRTOS
Definition: cltool.h:82
double replaySpeed
Definition: cltool.h:61
#define RMC_PRESET_INS_BITS
Definition: data_sets.h:1342
p_data_t * ReadData(unsigned int device=0)
Definition: ISLogger.cpp:402
ostream & endlbOn(ostream &os)
Definition: ISDisplay.cpp:1446
int baudRate
Definition: cltool.h:92
#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
void SetEvbFlashConfig(const evb_flash_cfg_t &evbFlashCfg, int pHandle=0)
#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:86
nvm_flash_cfg_t GetFlashConfig(int pHandle=0)
string evbFlashConfig
Definition: cltool.h:99
bool magRecal
Definition: cltool.h:57
bool cltool_updateFlashConfig(InertialSense &inertialSenseInterface, string flashConfigString)
Definition: cltool.cpp:548
void cltool_outputUsage()
Definition: cltool.cpp:456
ostream & boldOff(ostream &os)
Definition: ISDisplay.cpp:1430
string logType
Definition: cltool.h:87
bool disableBroadcastsOnClose
Definition: cltool.h:93
void SetFlashConfig(const nvm_flash_cfg_t &flashConfig, int pHandle=0)
float minAccuracy
Definition: data_sets.h:2969
string logSubFolder
Definition: cltool.h:91
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 serialPortWrite(serial_port_t *serialPort, const unsigned char *buffer, int writeCount)
Definition: serialPort.c:201
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
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:196
#define DID_EVB_FLASH_CFG
Definition: data_sets.h:115
#define false
Definition: compiler.h:424
string flashConfig
Definition: cltool.h:98
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:90
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:101
#define RMC_PRESET_PPD_BITS
Definition: data_sets.h:1340
static bool startsWith(const char *str, const char *pre)
Definition: cltool.cpp:46
bool replayDataLog
Definition: cltool.h:55
int streamWheelEncoder
Definition: cltool.h:84
string host
Definition: cltool.h:96
#define CL_DEFAULT_MAX_LOG_FILE_SIZE
Definition: cltool.cpp:58
void cltool_outputHelp()
Definition: cltool.cpp:543
string serverConnection
Definition: cltool.h:95
#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 Sun Feb 28 2021 03:17:57