Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
laelaps_diag.application Class Reference

Laelaps diagnositcs application class. More...

Public Member Functions

def __init__ (self)
 Constructor.
 
def printUsageErr (self, emsg)
 Print usage error. More...
 
def printUsage (self)
 Print Command-Line Usage Message. More...
 
def getOptions (self, argv=None, kwargs)
 Get command-line options. More...
 
def run (self, argv=None, kwargs)
 Run application. More...
 

Public Attributes

 m_win
 
 kwargs
 

Detailed Description

Laelaps diagnositcs application class.

Definition at line 571 of file laelaps_diag.py.

Member Function Documentation

def laelaps_diag.application.getOptions (   self,
  argv = None,
  kwargs 
)

Get command-line options.

Parameters
argvArgument list. If not None, then overrides command-line arguments.
[out]kwargsKeyword argument list.
Returns
Parsed keyword arguments.

Definition at line 626 of file laelaps_diag.py.

References laelaps_diag.application._Argv0, laelaps_diag.application.printUsage(), and laelaps_diag.application.printUsageErr().

Referenced by laelaps_sane.application.run(), laelaps_speed.application.run(), laelaps_diag.application.run(), laelaps_init.application.run(), and laelaps_tune_motors.application.run().

626  def getOptions(self, argv=None, **kwargs):
627  if argv is None:
628  argv = sys.argv
629 
630  self._Argv0 = os.path.basename(kwargs.get('argv0', __file__))
631 
632  # defaults
633  kwargs['debug'] = False
634  kwargs['fake'] = False
635 
636  # parse command-line options
637  try:
638  opts, args = getopt.getopt(argv[1:], "f?h",
639  ['help', 'fake', ''])
640  except getopt.error, msg:
641  raise usage(msg)
642  for opt, optarg in opts:
643  if opt in ('-f', '--fake'):
644  kwargs['fake'] = True
645  elif opt in ('-h', '--help', '-?'):
646  self.printUsage()
647  sys.exit(0)
648 
649  if len(args) < 1:
650  self.printUsageErr("No diagnostic(s) specified.")
651  sys.exit(128)
652  try:
653  args.index('all')
654  kwargs['diags'] = Diagnostics
655  except ValueError:
656  kwargs['diags'] = args
657 
658  return kwargs
659 
def getOptions(self, argv=None, kwargs)
Get command-line options.
def printUsageErr(self, emsg)
Print usage error.
Usage exception class.
def printUsage(self)
Print Command-Line Usage Message.
def laelaps_diag.application.printUsage (   self)

Print Command-Line Usage Message.

Definition at line 593 of file laelaps_diag.py.

References laelaps_diag.application._Argv0.

Referenced by laelaps_sane.application.getOptions(), laelaps_speed.application.getOptions(), laelaps_diag.application.getOptions(), laelaps_init.application.getOptions(), and laelaps_tune_motors.application.getOptions().

593  def printUsage(self):
594  print \
595 """
596 usage: %s [OPTIONS] DIAG [DIAG ...]
597  %s --help
598 
599 Run Laelaps diagnostic(s).
600 
601 Options and arguments:
602  --fake : Run diagnostics on fake hardware."
603 -h, --help : Display this help and exit.
604 
605 DIAG : Diagnostic to run. One of:
606  all - Run all dignostics.
607  motors - Run motors diagnotics.
608  tofs - Run time-of-flight sensors diagnostics.
609  imu - Run Inertia Measurement Unit diagnostics.
610  watchdog - Run Arduino watchdog sub-processor diagnostics.
611 
612 Exit Status:
613  The number of diagnostics passed. An exit status of 128 indicates usage
614  error.
615 """ % (self._Argv0, self._Argv0)
616 
def printUsage(self)
Print Command-Line Usage Message.
def laelaps_diag.application.printUsageErr (   self,
  emsg 
)

Print usage error.

Parameters
emsgError message string.

Definition at line 585 of file laelaps_diag.py.

References laelaps_diag.application._Argv0.

Referenced by laelaps_sane.application.getOptions(), laelaps_speed.application.getOptions(), and laelaps_diag.application.getOptions().

585  def printUsageErr(self, emsg):
586  if emsg:
587  print "%s: Error: %s" % (self._Argv0, emsg)
588  else:
589  print "%s: Error" % (self._Argv0)
590  print "Try '%s --help' for more information." % (self._Argv0)
591 
def printUsageErr(self, emsg)
Print usage error.
def laelaps_diag.application.run (   self,
  argv = None,
  kwargs 
)

Run application.

Parameters
argvOptional argument list to override command-line arguments.
kwargsOptional keyword argument list.
Returns
Exit code.

Definition at line 668 of file laelaps_diag.py.

References laelaps_diag.application.getOptions(), laelaps_diag.DiagMotors.kwargs, laelaps_diag.DiagToFs.kwargs, laelaps_diag.DiagImu.kwargs, laelaps_diag.DiagWatchdog.kwargs, and laelaps_diag.application.kwargs.

668  def run(self, argv=None, **kwargs):
669 
670  # parse command-line options and arguments
671  try:
672  self.kwargs = self.getOptions(argv, **kwargs)
673  except usage, e:
674  print e.msg
675  return 128
676 
677  passCnt = 0
678  diagCnt = 0
679  for diag in self.kwargs['diags']:
680  try:
681  Diagnostics.index(diag)
682  except ValueError:
683  print "%s: Unknown diagnostic - ignoring" % (diag)
684  continue
685  diagCnt += 1
686  if diag == 'motors':
687  diag = DiagMotors(self.kwargs)
688  elif diag == 'tofs':
689  diag = DiagToFs(self.kwargs)
690  elif diag == 'imu':
691  diag = DiagImu(self.kwargs)
692  elif diag == 'watchdog':
693  diag = DiagWatchdog(self.kwargs)
694  passCnt += diag.run()
695 
696  print
697  print " ~~~"
698  print "%d/%d diagnostics passed." % (passCnt, diagCnt)
699  print
700 
701  return passCnt
702 
703 
704 # ------------------------------------------------------------------------------
705 # main
706 # ------------------------------------------------------------------------------
def getOptions(self, argv=None, kwargs)
Get command-line options.
def run(self, argv=None, kwargs)
Run application.

The documentation for this class was generated from the following file: