sdhoptions.cpp
Go to the documentation of this file.
1 //======================================================================
28 //======================================================================
29 
30 //----------------------------------------------------------------------
31 // System Includes - include with <>
32 //----------------------------------------------------------------------
33 
34 #include <getopt.h>
35 #include <assert.h>
36 
37 #include <iostream>
38 #include <fstream>
39 
40 using namespace std;
41 
42 //----------------------------------------------------------------------
43 // Project Includes - include with ""
44 //---------------------------------------------------------------------
45 
46 #include "sdh/sdh.h"
48 #include "sdh/release.h"
49 #include "sdh/dsa.h"
50 #include "sdhoptions.h"
51 
52 //----------------------------------------------------------------------
53 // Defines, enums, unions, structs,
54 //----------------------------------------------------------------------
55 
57 
69 #define XSTRINGIFY(_x) STRINGIFY(_x)
70 
72 #define STRINGIFY(_s) #_s
73 
74 //----------------------------------------------------------------------
75 // Global variables
76 //----------------------------------------------------------------------
77 
78 
80 static char const* sdhusage_general =
81  //2345678901234567890123456789012345678901234567890123456789012345678901234567890
82  // 1 2 3 4 5 6 7 8
83  "\nGeneral options:\n"
84  " -h, --help\n"
85  " Show this help message and exit.\n"
86  " \n"
87  " -v, --version\n"
88  " Print the version (revision/release names) and dates of application,\n"
89  " library (and the attached SDH firmware, if found), then exit.\n"
90  " \n"
91  " -V, --version_check\n"
92  " Check the firmware release of the connected SDH if it is the one\n"
93  " recommended by this library. A message will be printed accordingly.\n"
94  " \n"
95  " -d LEVEL, --debug=LEVEL\n"
96  " Print debug messages of level LEVEL or lower while executing the program.\n"
97  " Level 0 (default): No messages, 1: application-level messages, \n"
98  " 2: cSDH-level messages, 3: cSDHSerial-level messages\n"
99  " \n"
100  " -l LOGFILE, --debuglog=LOGFILE\n"
101  " Redirect the printed debug messages to LOGFILE instead of default \n"
102  " standard error. If LOGFILE starts with '+' then the output will be \n"
103  " appended to the file (without the leading '+'), else the file will be\n"
104  " overwritten.\n"
105  " \n"
106  ;
107 
109 static char const* sdhusage_sdhcom_serial =
110  "\nCommunication options:\n"
111  " -p PORT, --port=PORT, --sdhport=PORT\n"
112  " Use RS232 communication PORT to connect to the SDH instead of the default\n"
113  " 0='COM1'='/dev/ttyS0'.\n"
114  " \n"
115 #if ! SDH_USE_VCC
116  " --sdh_rs_device=DEVICE_FORMAT_STRING\n"
117  " Use DEVICE_FORMAT_STRING instead of the default \"/dev/ttyS%d\". Useful\n"
118  " e.g. to use USB to RS232 converters available via \"/dev/ttyUSB%d\". \n"
119  " If the DEVICE_FORMAT_STRING contains '%d' then the PORT must also be \n"
120  " provided. If not then the DEVICE_FORMAT_STRING is the full device name. \n"
121  " \n"
122 #endif
123  ;
124 
126 static char const* sdhusage_sdhcom_common =
127  " -T TIMEOUT, --timeout=TIMEOUT Timeout in seconds when waiting for data from\n"
128  " SDH. The default -1 means: wait forever.\n"
129  " \n"
130  " -b BAUDRATE, --baud=BAUDRATE\n"
131  " Use BAUDRATE in bit/s for communication. Default=115200 Bit/s for RS232\n"
132 #if WITH_ESD_CAN || WITH_PEAK_CAN
133  " and 1000000 Bit/s (1MBit/s) for CAN\n"
134 #endif
135  ;
136 
138 static char const* sdhusage_sdhcom_esdcan =
139 #if WITH_ESD_CAN
140  " -c, --can, --canesd\n"
141  " Use CAN bus via an ESD adapter to connect to the SDH instead of RS232.\n"
142  " \n"
143  " -n NET, --net=NET\n"
144  " Use ESD CAN NET for CAN communication, default=0.\n"
145  " \n"
146 #else
147  ""
148 #endif
149  ;
151 static char const* sdhusage_sdhcom_peakcan =
152 #if WITH_PEAK_CAN
153  " --canpeak\n"
154  " Use CAN bus via a PEAK adapter to connect to the SDH instead of RS232.\n"
155  " \n"
156 #else
157  ""
158 #endif
159 #if WITH_PEAK_CAN && defined( OSNAME_LINUX )
160  " --sdh_canpeak_device=DEVICE_NAME\n"
161  " Use DEVICE_NAME instead of the default \"/dev/pcanusb0\"."
162  " \n"
163 #endif
164  ;
166 static char const* sdhusage_sdhcom_cancommon =
167 #if WITH_ESD_CAN || WITH_PEAK_CAN
168  " -e ID_READ, --id_read=ID_READ\n"
169  " Use CAN ID ID_READ for receiving CAN messages (default: 43=0x2B).\n"
170  " \n"
171  " -w ID_WRITE, --id_write=ID_WRITE\n"
172  " Use CAN ID ID_WRITE for writing CAN messages (default: 42=0x2A).\n"
173  " \n"
174 #else
175  ""
176 #endif
177  ;
178 
180 static char const* sdhusage_sdhcom_tcp =
181  " --tcp[=[IP_OR_HOSTNAME][:PORT]]\n"
182  " Use TCP for communication with the SDH. The SDH can be reached via\n"
183  " TCP/IP on port PORT at IP_OR_HOSTNAME, which can be a numeric IPv4\n"
184  " address or a hostname. The default is \"" SDH_DEFAULT_TCP_ADR ":" XSTRINGIFY(SDH_DEFAULT_TCP_PORT) "\"\n"
185  " When using --tcp and --dsa_tcp then only the last set IP_OR_HOSTNAME\n"
186  " is used for both.\n"
187  " (This feature requires at least SDH firmware 0.0.3.1)\n"
188  " \n"
189  ;
190 
191 
193 static char const* sdhusage_sdhother =
194  "\nOther options:\n"
195  " -R, --radians\n"
196  " Use radians and radians per second for angles and angular velocities\n"
197  " instead of default degrees and degrees per second.\n"
198  " (The demo programs provided might not evaluate this parameter\n"
199  " correctly. Thus they might fail if this parameter is used.)\n"
200  " \n"
201  " -F, --fahrenheit\n"
202  " Use degrees fahrenheit to report temperatures instead of default degrees\n"
203  " celsius.\n"
204  " \n"
205  " -t PERIOD, --period=PERIOD\n"
206  " For periodic commands only: Time period of measurements in seconds. The\n"
207  " default of '0' means: report once only. If set then the time since start\n"
208  " of measurement is printed at the beginning of every line.\n"
209  " \n"
210  ;
212 static char const* sdhusage_dsacom =
213  "\nDSA options (tactile sensor):\n"
214  " -q PORT, --dsaport=PORT\n"
215  " use RS232 communication PORT to connect to to tactile sensor controller\n"
216  " of SDH instead of default 1='COM2'='/dev/ttyS1'.\n"
217  " \n"
218  " --dsa_tcp[=[IP_OR_HOSTNAME][:PORT]]\n"
219  " use TCP for communication with the tactile sensor controller.\n"
220  " The tactile sensor can be reached via TCP/IP on port PORT at\n"
221  " IP_OR_HOSTNAME, which can be a numeric IPv4 address or a hostname.\n"
222  " The default is \"" SDH_DEFAULT_TCP_ADR ":" XSTRINGIFY(DSA_DEFAULT_TCP_PORT) "\"\n"
223  " When using --tcp and --dsa_tcp then only the last set IP_OR_HOSTNAME\n"
224  " is used for both.\n"
225  " (This feature requires at least SDH firmware 0.0.3.2)\n"
226  " \n"
227 #if ! SDH_USE_VCC
228  " --dsa_rs_device=DEVICE_FORMAT_STRING\n"
229  " Use DEVICE_FORMAT_STRING instead of the default \"/dev/ttyS%d\". Useful\n"
230  " e.g. to use USB to RS232 converters available via \"/dev/ttyUSB%d\". If \n"
231  " the DEVICE_FORMAT_STRING contains '%d' then the dsa PORT must also be \n"
232  " provided. If not then the DEVICE_FORMAT_STRING is the full device name.\n"
233  " \n"
234 #endif
235  " --no_rle\n"
236  " Do not use the RunLengthEncoding\n"
237  " \n"
238  ;
240 static char const* sdhusage_dsaother =
241  " -r, --framerate=FRAMERATE\n"
242  " Framerate for acquiring full tactile sensor frames. Default value 0\n"
243  " means 'acquire a single frame only'. Any value > 0 will make the\n"
244  " DSACON32m controller in the SDH send data at the highest possible rate \n"
245  " (ca. 30 FPS (frames per second)).\n"
246  " \n"
247  " -f, --fullframe\n"
248  " Print acquired full frames numerically.\n"
249  " \n"
250  " -S, --sensorinfo\n"
251  " Print sensor info from DSA (texel dimensions, number of texels...).\n"
252  " \n"
253  " -C, --controllerinfo\n"
254  " Print controller info from DSA (version...).\n"
255  " \n"
256  " -M, --matrixinfo=MATRIX_INDEX\n"
257  " Print matrix info for matrix with index MATRIX_INDEX from DSA.\n"
258  " This includes the current setting for sensitivity and threshold\n"
259  " of the addressed matrix (if supported by the tactile sensor firmware)."
260  " This option can be used multiple times.\n"
261  ;
262 
264 static char const* sdhusage_dsaadjust =
265  " --sensitivity=SENSITIVITY\n"
266  " Set the sensor sensitivity for all tactile sensor pads to the given\n"
267  " value. The value SENSITIVITY must be in range [0.0 .. 1.0], where\n"
268  " 0.0 is minimum and 1.0 is maximum sensitivity.\n"
269  " If --reset is given as well then SENSITIVITY is ignored and\n"
270  " the sensitivity is reset to the factory default.\n"
271  " To see the current setting for sensitivity use -M --matrixinfo\n"
272  " For setting sensitivities individually for a specific sensor X [0..5]\n"
273  " use --sensitivityX=SENSITIVITY\n"
274  "\n"
275  " --sensitivityX=SENSITIVITY\n"
276  " X is a sensor index in range [0..5]. Set sensor sensitivity for a\n"
277  " a specific sensor X. See also --sensitivity. \n"
278  " This option can be used multiple times (with different X).\n"
279  " \n"
280  " --threshold=THRESHOLD\n"
281  " Set the sensor threshold for all tactile sensor pads to the given \n"
282  " value. The value THRESHOLD must be in range [0 .. 4095], where\n"
283  " (0 is minimum, 4095 is maximum threshold).\n"
284  " If --reset is given as well then THRESHOLD is ignored and\n"
285  " the threshold is reset to the factory default."
286  " \n"
287  " --thresholdX=THRESHOLD\n"
288  " Set sensor threshold for a specific sensor X.\n"
289  " X is a sensor index in range [0..5]. See also option --threshold.\n"
290  " This option can be used multiple times (with different X).\n"
291  " \n"
292  " --reset\n"
293  " If given, then the values given with --sensitivity(X) \n"
294  " and/or --threshold(X) are reset to their factory default.\n"
295  " \n"
296  " --persistent\n"
297  " If given, then all the currently set values for sensitivity\n"
298  " and threshold are saved persistently in the configuration\n"
299  " memory of the DSACON32m controller in the SDH.\n"
300  " PLEASE NOTE: the maximum write endurance of the configuration memory\n"
301  " is about 100.000 times!\n"
302  " \n"
303  " --showdsasettings\n"
304  " If given, then current settings for sensitivity and\n"
305  " threshold will be printed on stdout first.\n"
306  " \n"
307  ;
308 
310 static char const* sdhoptions_short_options = "hvVd:l:p:T:b:cn:e:w:RFt:q:r:fSCM:";
313 {
314  // name , has_arg, flag, val
315  {"help" , 0 , 0 , 'h' },
316  {"version" , 0 , 0 , 'v' },
317  {"version_check" , 0 , 0 , 'V' },
318  {"debug" , 1 , 0 , 'd' },
319  {"debuglog" , 1 , 0 , 'l' },
320 
321  {"port" , 1 , 0 , 'p' },
322  {"sdhport" , 1 , 0 , 'p' },
323  {"sdh_rs_device" , 1 , 0 , 'S' + 256},
324  {"timeout" , 1 , 0 , 'T' },
325  {"baud" , 1 , 0 , 'b' },
326 
327  {"can" , 0 , 0 , 'c' },
328  {"canesd" , 0 , 0 , 'c' },
329  {"net" , 1 , 0 , 'n' },
330 
331  {"canpeak" , 0 , 0 , 'p' + 256},
332  {"sdh_canpeak_device", 1 , 0 , 'P' + 256},
333 
334  {"id_read" , 1 , 0 , 'e' },
335  {"id_write" , 1 , 0 , 'w' },
336 
337  {"tcp" , 2 , 0 , 'T' + 256 },
338 
339  {"radians" , 0 , 0 , 'R' },
340  {"fahrenheit" , 0 , 0 , 'F' },
341  {"period" , 1 , 0 , 't' },
342 
343  {"dsaport" , 1 , 0 , 'q' },
344  {"dsa_tcp" , 2 , 0 , 'T' + 512 },
345  {"dsa_rs_device" , 1 , 0 , 'D' + 256},
346  {"no_rle" , 0 , 0 , 'r' + 256},
347  {"framerate" , 1 , 0 , 'r' },
348  {"fullframe" , 0 , 0 , 'f' },
349  {"sensorinfo" , 0 , 0 , 'S' },
350  {"controllerinfo" , 0 , 0 , 'C' },
351  {"matrixinfo" , 1 , 0 , 'M' },
352 
353  {"sensitivity" , 1 , 0 , 999 },
354  {"sensitivity0" , 1 , 0 , 1000 },
355  {"sensitivity1" , 1 , 0 , 1001 },
356  {"sensitivity2" , 1 , 0 , 1002 },
357  {"sensitivity3" , 1 , 0 , 1003 },
358  {"sensitivity4" , 1 , 0 , 1004 },
359  {"sensitivity5" , 1 , 0 , 1005 },
360  {"threshold" , 1 , 0 , 1009 },
361  {"threshold0" , 1 , 0 , 1010 },
362  {"threshold1" , 1 , 0 , 1011 },
363  {"threshold2" , 1 , 0 , 1011 },
364  {"threshold3" , 1 , 0 , 1013 },
365  {"threshold4" , 1 , 0 , 1014 },
366  {"threshold5" , 1 , 0 , 1015 },
367  {"reset" , 0 , 0 , 'R' + 512},
368  {"persistent" , 0 , 0 , 'P' + 512},
369  {"showdsasettings" , 0 , 0 , 'S' + 512},
370 
371  {0, 0, 0, 0}
372 };
373 
374 
375 //----------------------------------------------------------------------
376 // Function and class member implementation (function definitions)
377 //----------------------------------------------------------------------
378 
379 
380 cSDHOptions::cSDHOptions( char const* option_selection )
381 {
382  std::string os( option_selection );
383 
384  if ( os.find( "general" ) != string::npos )
385  usage.append( sdhusage_general );
386  if ( os.find( "sdhcom_serial" ) != string::npos )
387  usage.append( sdhusage_sdhcom_serial );
388  if ( os.find( "sdhcom_common" ) != string::npos )
389  usage.append( sdhusage_sdhcom_common );
390  if ( os.find( "sdhcom_esdcan" ) != string::npos )
391  usage.append( sdhusage_sdhcom_esdcan );
392  if ( os.find( "sdhcom_peakcan" ) != string::npos )
393  usage.append( sdhusage_sdhcom_peakcan );
394  if ( os.find( "sdhcom_cancommon" ) != string::npos )
396  if ( os.find( "sdhcom_tcp" ) != string::npos )
397  usage.append( sdhusage_sdhcom_tcp );
398  if ( os.find( "sdhother" ) != string::npos )
399  usage.append( sdhusage_sdhother );
400  if ( os.find( "dsacom" ) != string::npos )
401  usage.append( sdhusage_dsacom );
402  if ( os.find( "dsaother" ) != string::npos )
403  usage.append( sdhusage_dsaother );
404  if ( os.find( "dsaadjust" ) != string::npos )
405  usage.append( sdhusage_dsaadjust );
406 
407  // set default options
408  debug_level = 0; // 0: no debug messages
409  debuglog = &cerr;
410 
411  sdhport = 0; // 0=/dev/ttyS0=COM1
412  strncpy( sdh_rs_device, "/dev/ttyS%d", MAX_DEV_LENGTH );
413  timeout = -1.0; // no timeout, wait forever (which is what we need)
414  rs232_baudrate = 115200;
415 
416  use_can_esd = false;
417  net = 0;
418 
419  use_can_peak = false;
420  strncpy( sdh_canpeak_device, "/dev/pcanusb0", MAX_DEV_LENGTH );
421 
422  can_baudrate = 1000000;
423  id_read = 43;
424  id_write = 42;
425 
426  use_tcp = false;
427  tcp_adr = SDH_DEFAULT_TCP_ADR;
428  tcp_port = SDH_DEFAULT_TCP_PORT;
429 
430  use_radians = false;
431  use_fahrenheit = false;
432  period = 0.0; // no period, read only once
433 
434  dsaport = 0; // 0=/dev/ttyS0=COM1
435  strncpy( dsa_rs_device, "/dev/ttyS%d", MAX_DEV_LENGTH );
436  do_RLE = true;
437  dsa_use_tcp = false;
438  dsa_tcp_port = DSA_DEFAULT_TCP_PORT;
439 
440  framerate = -1;
441  fullframe = false;
442  sensorinfo = false;
443  controllerinfo = false;
444 
445  for ( int i=0; i<6; i++ )
446  {
447  matrixinfo[i] = -1;
448  sensitivity[i] = -1.0;
449  threshold[i] = 65535;
450  }
451  reset_to_default = false;
452  persistent = false;
453  showdsasettings = false;
454 }
455 //----------------------------------------------------------------------
456 
458 {
459  if ( debuglog && debuglog != &cerr )
460  delete debuglog;
461 }
462 //----------------------------------------------------------------------
463 
464 int cSDHOptions::Parse( int argc, char** argv,
465  char const* helptext, char const* progname, char const* version, char const* libname, char const* librelease )
466 {
467  // parse options from command line
468  unsigned long baudrate = 0;
469  bool do_print_version = false;
470  bool do_check_version = false;
471  int option_index = 0;
472  int rc;
473  int i;
474  int nb_matrixinfos = 0;
475 
476  while (1)
477  {
478  int c;
479  c = getopt_long( argc, argv,
480  sdhoptions_short_options, sdhoptions_long_options,
481  &option_index );
482  if (c == -1)
483  break;
484 
485  switch (c)
486  {
487  case 'h':
488  cout << helptext << "\n\nusage: " << progname << " [options]\n" << usage << "\n";
489  exit(0);
490 
491  case 'v':
492  do_print_version = true; // defer actual printing until all options are parsed (which might change the communication to use)
493  break;
494 
495  case 'V':
496  do_check_version = true; // defer actual checking until all options are parsed (which might change the communication to use)
497  break;
498 
499  case 'd':
500  rc = sscanf( optarg, "%d", &debug_level );
501  assert( rc == 1 );
502  break;
503 
504  case 'l':
505  {
506  ios_base::openmode mode = ios_base::out | ios_base::trunc;
507  if ( optarg[0] == '+' )
508  {
509  mode = ios_base::app;
510  optarg = optarg+1;
511  }
512  debuglog = new ofstream( optarg, mode );
513  assert( debuglog != NULL );
514  assert( ! debuglog->fail() );
515  break;
516  }
517 
518  case 'p':
519  rc = sscanf( optarg, "%d", &sdhport );
520  assert( rc == 1 );
521  break;
522 
523  case 'S'+256:
524  strncpy( sdh_rs_device, optarg, MAX_DEV_LENGTH );
525  break;
526 
527  case 'T':
528  rc = sscanf( optarg, "%lf", &timeout );
529  assert( rc == 1 );
530  break;
531 
532  case 'b':
533  rc = sscanf( optarg, "%lu", &baudrate ); // store in intermediate variable since -b might be specified before --can
534  assert( rc == 1 );
535  break;
536 
537  //---
538  case 'c':
539  use_can_esd = true;
540  break;
541 
542  case 'n':
543  rc = sscanf( optarg, "%d", &net );
544  assert( rc == 1 );
545  break;
546 
547  //---
548  case 'p'+256:
549  use_can_peak = true;
550  break;
551 
552  case 'P'+256:
553  strncpy( sdh_canpeak_device, optarg, MAX_DEV_LENGTH );
554  break;
555 
556 
557  //---
558  case 'e':
559  if ( !strncmp( optarg, "0x", 2 ) || !strncmp( optarg, "0X", 2 ) )
560  rc = sscanf( optarg, "0x%x", &id_read );
561  else
562  rc = sscanf( optarg, "%u", &id_read );
563  assert( rc == 1 );
564  break;
565 
566  case 'w':
567  if ( !strncmp( optarg, "0x", 2 ) || !strncmp( optarg, "0X", 2 ) )
568  rc = sscanf( optarg, "0x%x", &id_write );
569  else
570  rc = sscanf( optarg, "%u", &id_write );
571  assert( rc == 1 );
572  break;
573 
574  //---
575  case 'R':
576  use_radians = true;
577  break;
578 
579  case 'F':
580  use_fahrenheit = true;
581  break;
582 
583  case 't':
584  rc = sscanf( optarg, "%lf", &period );
585  assert( rc == 1 );
586  break;
587 
588  //---
589  case 'q':
590  rc = sscanf( optarg, "%d", &dsaport );
591  assert( rc == 1 );
592  break;
593 
594  case 'D'+256:
595  strncpy( dsa_rs_device, optarg, MAX_DEV_LENGTH );
596  break;
597 
598  case 256+'r':
599  do_RLE = false;
600  break;
601 
602  //---
603  case 'r':
604  rc = sscanf( optarg, "%d", &framerate );
605  assert( rc == 1 );
606  break;
607  case 'f':
608  fullframe = true;
609  break;
610  case 'S':
611  sensorinfo = true;
612  break;
613  case 'C':
614  controllerinfo = true;
615  break;
616  case 'M':
617  if ( nb_matrixinfos > 5 )
618  {
619  cerr << "Error: matrixinfo requested more than 6 times!";
620  exit( 1 );
621  }
622  rc = sscanf( optarg, "%d", &(matrixinfo[nb_matrixinfos++]) );
623  assert( rc == 1 );
624  break;
625 
626  //---
627  case 999:
628  rc = sscanf( optarg, "%lf", &(sensitivity[0]) ); // scan value
629  assert( rc == 1 );
630  assert( 0.0 <= sensitivity[0] ); // check value
631  assert( sensitivity[0] <= 1.0 );
632  for ( i=1; i<6; i++) // copy value
633  sensitivity[i] = sensitivity[0];
634  break;
635  case 1000:
636  case 1001:
637  case 1002:
638  case 1003:
639  case 1004:
640  case 1005:
641  i = c - 1000;
642  rc = sscanf( optarg, "%lf", &(sensitivity[i]) );// scan value
643  assert( rc == 1 );
644  assert( 0.0 <= sensitivity[i] ); // check value
645  assert( sensitivity[i] <= 1.0 );
646  break;
647 
648  case 1009:
649  rc = sscanf( optarg, "%d", &(threshold[0]) ); // scan value
650  assert( rc == 1 );
651  assert( 0 <= threshold[0] ); // check value
652  assert( threshold[0] <= 4095 );
653  for ( i=1; i<6; i++)
654  threshold[i] = threshold[0]; // copy value
655  break;
656  case 1010:
657  case 1011:
658  case 1012:
659  case 1013:
660  case 1014:
661  case 1015:
662  i = c - 1010;
663  rc = sscanf( optarg, "%d", &(threshold[i]) ); // scan value
664  assert( rc == 1 );
665  assert( 0 <= threshold[i] ); // check value
666  assert( threshold[i] <= 4095 );
667  break;
668 
669  case 'P'+512:
670  persistent = true;
671  break;
672 
673  case 'R'+512:
674  reset_to_default = true;
675  break;
676 
677  case 'S'+512:
678  showdsasettings = true;
679  break;
680 
681  case 'T'+256:
682  {
683  use_tcp = true;
684  if ( optarg )
685  {
686  char* colon = strchr( optarg, (int) ':' );
687  if ( colon )
688  {
689  if ( colon - optarg > 0 )
690  {
691  *colon = '\0';
692  tcp_adr = optarg;
693  }
694  tcp_port = atoi( colon+1 );
695  }
696  else if ( strlen( optarg ) > 0 )
697  tcp_adr = optarg;
698  }
699  break;
700  }
701  case 'T'+512:
702  {
703  dsa_use_tcp = true;
704  if ( optarg )
705  {
706  char* colon = strchr( optarg, (int) ':' );
707  if ( colon )
708  {
709  if ( colon - optarg > 0 )
710  {
711  *colon = '\0';
712  tcp_adr = optarg;
713  }
714  dsa_tcp_port = atoi( colon+1 );
715  }
716  else if ( strlen( optarg ) > 0 )
717  tcp_adr = optarg;
718  }
719  break;
720  }
721  //---
722 
723  default:
724  cerr << "Error: getopt returned invalid character code '" << char(c) << "' = " << int(c) << ", giving up!\n";
725  exit( 1 );
726  }
727  }
728 
729  if ( baudrate != 0 )
730  {
731  // a baudrate was specified on the command line, so overwrite the selected one
732  if ( use_can_esd || use_can_peak )
733  can_baudrate = baudrate;
734  else
735  rs232_baudrate = baudrate;
736  }
737 
738  //-----
739  if ( do_check_version )
740  {
741  try
742  {
743  g_sdh_debug_log = debuglog;
744  cSDH hand( false, false, debug_level-1 );
745 
746  // Open configured communication to the SDH device
747  OpenCommunication( hand );
748 
749 
750  if ( hand.CheckFirmwareRelease() )
751  {
752  cout << "The firmware release of the connected SDH is the one recommended by\n";
753  cout << "this SDHLibrary. Good.\n";
754  }
755  else
756  {
757  cout << "The firmware release of the connected SDH is NOT the one recommended\n";
758  cout << "by this SDHLibrary:\n";
759  cout << " Actual SDH firmware release: " << hand.GetFirmwareRelease() << "\n";
760  cout << " Recommended SDH firmware release: " << hand.GetFirmwareReleaseRecommended() << "\n";
761  cout << " => Communication with the SDH might not work as expected!\n";
762  }
763  hand.Close();
764  }
765  catch ( cSDHLibraryException* e )
766  {
767  cerr << "Could not check firmware release from SDH: " << e->what() << "\n";
768  delete e;
769 
770  exit(1);
771  }
772  }
773  //-----
774 
775  //-----
776  char const* libdate = PROJECT_DATE;
777  if ( do_print_version )
778  {
779  cout << "PC-side:\n";
780  cout << " Demo-program name: " << argv[0] << "\n";
781  cout << " Demo-program revision: " << version << "\n";
782  cout << " " << libname << " release: " << librelease << "\n";
783  cout << " " << libname << " date: " << libdate << "\n";
784  cout << " Recommended firmware release: " << cSDH::GetFirmwareReleaseRecommended() << "\n";
785  cout.flush();
786 
787  try
788  {
789  g_sdh_debug_log = debuglog;
790  cSDH hand( false, false, debug_level-1 );
791 
792  // Open configured communication to the SDH device
793  OpenCommunication( hand );
794 
795  cout << "SDH-side:\n";
796  cout << " SDH firmware release: " << hand.GetInfo( "release-firmware" ) << "\n";
797  cout << " SDH firmware date: " << hand.GetInfo( "date-firmware" ) << "\n";
798  cout << " SDH SoC ID: " << hand.GetInfo( "release-soc" ) << "\n";
799  cout << " SDH SoC date: " << hand.GetInfo( "date-soc" ) << "\n";
800  cout << " SDH ID: " << hand.GetInfo( "id-sdh" ) << "\n";
801  cout << " SDH Serial Number: " << hand.GetInfo( "sn-sdh" ) << "\n";
802  hand.Close();
803  }
804  catch ( cSDHLibraryException* e )
805  {
806  cerr << "Could not get all version info from SDH: " << e->what() << "\n";
807  delete e;
808  }
809 
810  cDSA* ts = NULL;
811  try
812  {
813  if ( dsa_use_tcp )
814  {
815  ts = new cDSA( 0, tcp_adr.c_str(), dsa_tcp_port );
816  }
817  else
818  {
819  ts = new cDSA( 0, dsaport );
820  }
821 
822  cout << "DSA-side:\n";
823  cout << " DSA controller info hw_version: " << (int) ts->GetControllerInfo().hw_version << "\n";
824 
825 
826  char buffer[8];
828  snprintf( buffer, 8, "%hu", sw_version );
829  std::string dsa_controller_sw_version( buffer );
830  if ( sw_version >= 0x1000 )
831  {
832  // version numbering has changed, see bug 996
833  std::string new_version_string( "" );
834  std::string sep( "" );
835  for ( int i=0; i < 4; i++ )
836  {
837  snprintf( buffer, 8, "%hu", (sw_version >> (i*4)) & 0x0f );
838  new_version_string = buffer + sep + new_version_string;
839  sep = ".";
840  }
841  dsa_controller_sw_version += " (" + (new_version_string) + ")";
842  }
843  cout << " DSA controller info sw_version: " << dsa_controller_sw_version << "\n";
844  cout << " DSA sensor info hw_revision: " << (int) ts->GetSensorInfo().hw_revision << "\n";
845  ts->Close();
846  }
847  catch ( cDSAException* e )
848  {
849  cerr << "Could not get sensor controller firmware release from DSA: " << e->what() << "\n";
850  delete e;
851  }
852  delete ts;
853 
854  exit( 0 );
855  }
856  //-----
857 
858  return optind;
859  //
860  //----------------------------------------------------------------------
861 }
862 //----------------------------------------------------------------------
863 
864 
866 {
867  if ( use_can_esd )
868  // use CAN bus via an interface device from ESD
869  hand.OpenCAN_ESD( net, // ESD CAN net number
870  can_baudrate, // CAN baudrate in bit/s
871  timeout, // timeout in s
872  id_read, // CAN ID used for reading
873  id_write ); // CAN ID used for writing
874  else if ( use_can_peak )
875  // use CAN bus via an interface device from Peak
876  hand.OpenCAN_PEAK( can_baudrate, // CAN baudrate in bit/s
877  timeout, // timeout in s
878  id_read, // CAN ID used for reading
879  id_write, // CAN ID used for writing
880  sdh_canpeak_device ); // PEAK CAN device to use (only on Linux)
881  else if ( use_tcp )
882  // use TCP/IP
883  hand.OpenTCP( tcp_adr.c_str(), // TCP address, IP or hostname
884  tcp_port, // TCP port number
885  timeout ); // timeout in s
886  else
887  // use RS232
888  hand.OpenRS232( sdhport, // RS232 port number
889  rs232_baudrate, // baudrate
890  timeout, // timeout in s
891  sdh_rs_device ); // RS232 device (only on Linux)
892 }
893 //----------------------------------------------------------------------
894 
895 //======================================================================
896 /*
897  Here are some settings for the emacs/xemacs editor (and can be safely ignored):
898  (e.g. to explicitely set C++ mode for *.h header files)
899 
900  Local Variables:
901  mode:C++
902  mode:ELSE
903  End:
904 */
905 //======================================================================
#SDH::cSDH is the end user interface class to control a SDH (SCHUNK Dexterous Hand).
Definition: sdh.h:172
UInt16 sw_version
Definition: dsa.h:119
int Parse(int argc, char **argv, char const *helptext, char const *progname, char const *version, char const *libname, char const *librelease)
Definition: sdhoptions.cpp:464
This file contains the interface to class #SDH::cSDH, the end user class to access the SDH from a PC...
static char const * sdhusage_sdhcom_serial
RS232 communication options.
Definition: sdhoptions.cpp:109
int optind
Definition: getopt.c:131
static char const * sdhusage_dsaadjust
DSA (tactile sensor) adjustment options.
Definition: sdhoptions.cpp:264
static char const * sdhusage_sdhcom_common
Common communication options.
Definition: sdhoptions.cpp:126
static char const * GetFirmwareReleaseRecommended(void)
Definition: sdh.cpp:649
#define NULL
Definition: getopt1.c:56
Derived exception class for low-level DSA related exceptions.
Definition: dsa.h:88
static char const * sdhoptions_short_options
short command line options accepted by the cSDHOptions class
Definition: sdhoptions.cpp:310
static char const * sdhusage_general
general options
Definition: sdhoptions.cpp:80
void Close(void)
Set the framerate of the remote DSACON32m controller to 0 and close connection to it...
Definition: dsa.cpp:739
static char const * sdhusage_dsaother
DSA (tactile sensor) other options.
Definition: sdhoptions.cpp:240
Implementation of a class to parse common SDH related command line options.
UInt8 hw_revision
Definition: dsa.h:175
#define XSTRINGIFY(_x)
Definition: sdhoptions.cpp:69
static char const * sdhusage_sdhcom_peakcan
PEAK CAN communication options.
Definition: sdhoptions.cpp:151
bool CheckFirmwareRelease(void)
Definition: sdh.cpp:655
char const * GetFirmwareRelease(void)
Definition: sdh.cpp:640
static char const * sdhusage_sdhother
Other options.
Definition: sdhoptions.cpp:193
#define DSA_DEFAULT_TCP_PORT
Definition: sdhoptions.h:68
Definition: getopt.h:81
static struct option sdhoptions_long_options[]
long command line options accepted by the cSDHOptions class
Definition: sdhoptions.cpp:312
static char const * sdhusage_sdhcom_cancommon
Common CAN communication options.
Definition: sdhoptions.cpp:166
char const * GetInfo(char const *what)
Definition: sdh.cpp:661
void OpenTCP(char const *_tcp_adr="192.168.1.1", int _tcp_port=23, double _timeout=0.0)
Definition: sdh.cpp:866
char const * usage
cSDHOptions(char const *option_selection=SDHUSAGE_DEFAULT)
Definition: sdhoptions.cpp:380
void OpenCommunication(NS_SDH cSDH &hand)
Definition: sdhoptions.cpp:865
SDH::cDSA is the end user interface class to access the DSACON32m, the tactile sensor controller of t...
Definition: dsa.h:111
Base class for exceptions in the SDHLibrary-CPP.
Definition: sdhexception.h:132
virtual const char * what() const
static char const * sdhusage_sdhcom_esdcan
ESD CAN communication options.
Definition: sdhoptions.cpp:138
void Close(bool leave_enabled=false)
Definition: sdh.cpp:888
This file contains interface to #SDH::cDSA, a class to communicate with the tactile sensors of the SD...
void OpenRS232(int _port=0, unsigned long _baudrate=115200, double _timeout=-1, char const *_device_format_string="/dev/ttyS%d")
Definition: sdh.cpp:733
#define USING_NAMESPACE_SDH
void OpenCAN_ESD(int _net=0, unsigned long _baudrate=1000000, double _timeout=0.0, Int32 _id_read=43, Int32 _id_write=42)
Definition: sdh.cpp:754
static char const * sdhusage_sdhcom_tcp
TCP communication options.
Definition: sdhoptions.cpp:180
UInt16 sw_version
Definition: dsa.h:160
int getopt_long(int argc, char *const *argv, const char *shortopts, const struct option *longopts, int *longind)
Definition: getopt1.c:60
static char const * sdhusage_dsacom
DSA (tactile sensor) communication options.
Definition: sdhoptions.cpp:212
~cSDHOptions()
destructor, clean up
Definition: sdhoptions.cpp:457
This file contains settings to make the SDHLibrary compile on differen systems:
#define SDH_DEFAULT_TCP_ADR
Definition: sdhoptions.h:66
char * optarg
Definition: getopt.c:116
#define PROJECT_DATE
Date of the release of the software project.
Definition: release.h:499
sSensorInfo const & GetSensorInfo(void) const
Return a reference to the sSensorInfo read from the remote DSACON32m controller.
Definition: dsa.h:478
USING_NAMESPACE_SDH NAMESPACE_SDH_START std::ostream * g_sdh_debug_log
Definition: sdhbase.cpp:55
This file contains nothing but C/C++ defines with the name of the project itself (PROJECT_NAME) and t...
#define SDH_DEFAULT_TCP_PORT
Definition: sdhoptions.h:67
sControllerInfo const & GetControllerInfo(void) const
Return a reference to the sControllerInfo read from the remote DSACON32m controller.
Definition: dsa.h:471
void OpenCAN_PEAK(unsigned long _baudrate=1000000, double _timeout=0.0, Int32 _id_read=43, Int32 _id_write=42, const char *_device="/dev/pcanusb0")
Definition: sdh.cpp:810
uint16_t UInt16
unsigned integer, size 2 Byte (16 Bit)
Definition: basisdef.h:63
UInt8 hw_version
Definition: dsa.h:159
UInt32 can_baudrate
Definition: dsa.h:124


sdhlibrary_cpp
Author(s): Dirk Osswald
autogenerated on Sun Aug 18 2019 03:42:20