Exemplo n.º 1
0
def main():
    """
    Get configuration, get driver, get logger, and build handler and start it.
    Create relevant TestState object and perform associated actions.
    Modeled after serial_link main function.
    """
    args = get_args()
    port = args.port
    baud = args.baud
    timeout = args.timeout[0]
    log_filename = args.log_filename[0]
    interval = int(args.interval[0])
    minsats = int(args.minsats[0])

    # Driver with context
    with sl.get_driver(args.ftdi, port, baud) as driver:
        # Handler with context
        with Handler(Framer(driver.read, driver.write, args.verbose)) as link:
            # Logger with context
            with sl.get_logger(args.log, log_filename) as logger:
                # print out SBP_MSG_PRINT_DEP messages
                link.add_callback(sl.printer, SBP_MSG_PRINT_DEP)
                link.add_callback(sl.log_printer, SBP_MSG_LOG)
                # add logger callback
                Forwarder(link, logger).start()
                try:
                    # Get device info
                    # Diagnostics reads out the device settings and resets the Piksi
                    piksi_diag = ptd.Diagnostics(link)
                    while not piksi_diag.heartbeat_received:
                        time.sleep(0.1)
                    # add Teststates and associated callbacks
                    with DropSatsState(
                            link,
                            piksi_diag.sbp_version,
                            interval,
                            minsats,
                            debug=args.verbose) as drop:
                        link.add_callback(drop.process_message)

                        if timeout is not None:
                            expire = time.time() + float(args.timeout[0])

                        while True:
                            if timeout is None or time.time() < expire:
                                # Wait forever until the user presses Ctrl-C
                                time.sleep(1)
                            else:
                                print("Timer expired!")
                                break
                            if not link.is_alive():
                                sys.stderr.write("ERROR: link is gone!\n")
                                sys.exit(1)
                except KeyboardInterrupt:
                    # Callbacks call thread.interrupt_main(), which throw a KeyboardInterrupt
                    # exception. To get the proper error condition, return exit code
                    # of 1. Note that the finally block does get caught since exit
                    # itself throws a SystemExit exception.
                    sys.exit(1)
Exemplo n.º 2
0
 def _start_json_logging(self, override_filename=None):
   if override_filename:
     filename = override_filename
   else:
     filename = s.logfilename()
   filename = os.path.normpath(os.path.join(self.directory_name, filename))
   self.logger = s.get_logger(True, filename)
   self.forwarder = sbpc.Forwarder(self.link, self.logger)
   self.forwarder.start()
Exemplo n.º 3
0
 def _start_json_logging(self, override_filename=None):
   if override_filename:
     filename = override_filename
   else:
     filename = time.strftime("swift-gnss-%Y%m%d-%H%M%S.sbp.json")
     filename = os.path.normpath(os.path.join(self.directory_name, filename))
   self.logger = s.get_logger(True, filename)
   self.forwarder = sbpc.Forwarder(self.link, self.logger)
   self.forwarder.start()
   if self.settings_view:
     self.settings_view._settings_read_button_fired()
Exemplo n.º 4
0
 def _start_json_logging(self, override_filename=None):
     if override_filename:
         filename = override_filename
     else:
         filename = time.strftime("swift-gnss-%Y%m%d-%H%M%S.sbp.json")
         filename = os.path.normpath(
             os.path.join(self.directory_name, filename))
     self.logger = s.get_logger(True, filename, self.expand_json)
     self.forwarder = sbpc.Forwarder(self.link, self.logger)
     self.forwarder.start()
     if self.settings_view:
         self.settings_view._settings_read_by_index()
Exemplo n.º 5
0
def main():
    """
    Get configuration, get driver, get logger, and build handler and start it.
    Create relevant TestState object and perform associated actions.
    Modeled after serial_link main function.
    """
    args = get_args()
    port = args.port
    baud = args.baud
    timeout = args.timeout
    log_filename = args.logfilename
    log_dirname = args.log_dirname
    if not log_filename:
        log_filename = sl.logfilename()
    if log_dirname:
        log_filename = os.path.join(log_dirname, log_filename)
    interval = int(args.interval[0])
    # Driver with context
    with sl.get_driver(args.ftdi, port, baud) as driver:
        # Handler with context
        with Handler(Framer(driver.read, driver.write, args.verbose)) as link:
            # Logger with context
            with sl.get_logger(args.log, log_filename, expand_json=args.expand_json) as logger:
                Forwarder(link, logger).start()
                try:
                    # Get device info
                    # add Teststates and associated callbacks
                    with CellModemTestState(link, interval, filename=args.outfile,
                                            commanded_cycles=int(args.cycles)) as cell:

                        if timeout is not None:
                            expire = time.time() + float(args.timeout)

                        while True:
                            if timeout is None or time.time() < expire:
                            # Wait forever until the user presses Ctrl-C
                                time.sleep(1)
                            else:
                                print "Timer expired!"
                                break
                            if not link.is_alive():
                                sys.stderr.write("ERROR: Thread died!")
                                sys.exit(1)
                except KeyboardInterrupt:
                    # Callbacks call thread.interrupt_main(), which throw a KeyboardInterrupt
                    # exception. To get the proper error condition, return exit code
                    # of 1. Note that the finally block does get caught since exit
                    # itself throws a SystemExit exception.
                    sys.exit(1)
Exemplo n.º 6
0
    port = port_chooser.port
    if not port or not is_ok:
        print "No serial device selected!"
        sys.exit(1)
    else:
        print "Using serial device '%s'" % port

# Make sure that SIGINT (i.e. Ctrl-C from command line) actually stops the
# application event loop (otherwise Qt swallows KeyboardInterrupt exceptions)
signal.signal(signal.SIGINT, signal.SIG_DFL)

with serial_link.get_driver(args.ftdi, port, baud) as driver:
    with sbp.client.Handler(
            sbp.client.Framer(driver.read, driver.write,
                              args.verbose)) as link:
        with serial_link.get_logger(args.log, log_filename) as logger:
            link.add_callback(logger)
            if args.reset:
                link(MsgReset())
            log_level_filter = DEFAULT_LOG_LEVEL_FILTER
            if args.initloglevel[0]:
                log_level_filter = args.initloglevel[0]
            console = SwiftConsole(link,
                                   update=args.update,
                                   log_level_filter=log_level_filter)
            console.configure_traits()

# Force exit, even if threads haven't joined
try:
    os._exit(0)
except:
Exemplo n.º 7
0
# application event loop (otherwise Qt swallows KeyboardInterrupt exceptions)
signal.signal(signal.SIGINT, signal.SIG_DFL)

# Passing only a base station argument, we just want to display the
# base station data in the console. Otherwise, continue, assuming a
# rover connected to the serial port.
if port is None and base is None:
    sys.stderr.write("ERROR: No data source specified!")
    sys.exit(1)
if port is None and base and use_broker:
    device_id = get_uuid(channel, serial_id)
    with HTTPDriver(str(device_id), base) as http_driver:
        with sbpc.Handler(sbpc.Framer(http_driver.read, None, args.verbose)) as link:
            if os.path.isdir(log_filename):
                log_filename = os.path.join(log_filename, s.LOG_FILENAME)
            with s.get_logger(args.log, log_filename) as logger:
                link.add_callback(logger)
                log_filter = DEFAULT_LOG_LEVEL_FILTER
                if args.initloglevel[0]:
                    log_filter = args.initloglevel[0]
                SwiftConsole(link, args.update, log_filter, True).configure_traits()
    try:
        os._exit(0)
    except:
        pass

# If using a device connected to an actual port, then invoke the
# regular console dialog for port selection
class PortChooser(HasTraits):
    ports = List()
    port = Str(None)
Exemplo n.º 8
0
  def __init__(self):
    try:
      self.ports = [p for p, _, _ in serial_link.get_ports()]
    except TypeError:
      pass

if not port:
  port_chooser = PortChooser()
  is_ok = port_chooser.configure_traits()
  port = port_chooser.port
  if not port or not is_ok:
    print "No serial device selected!"
    sys.exit(1)
  else:
    print "Using serial device '%s'" % port

with serial_link.get_driver(args.ftdi, port, baud) as driver:
  with sbp.client.handler.Handler(driver.read, driver.write, args.verbose) as link:
    with serial_link.get_logger(args.log, serial_link.LOG_FILENAME) as logger:
      link.add_callback(logger)
      if args.reset:
        link.send(SBP_MSG_RESET, "")
      console = SwiftConsole(link, update=args.update)
      console.configure_traits()

# Force exit, even if threads haven't joined
try:
  os._exit(0)
except:
  pass
Exemplo n.º 9
0
signal.signal(signal.SIGINT, signal.SIG_DFL)

# Passing only a base station argument, we just want to display the
# base station data in the console. Otherwise, continue, assuming a
# rover connected to the serial port.
if port is None and base is None:
    sys.stderr.write("ERROR: No data source specified!")
    sys.exit(1)
if port is None and base and use_broker:
    device_id = get_uuid(channel, serial_id)
    with HTTPDriver(str(device_id), base) as http_driver:
        with sbpc.Handler(sbpc.Framer(http_driver.read, None,
                                      args.verbose)) as link:
            if os.path.isdir(log_filename):
                log_filename = os.path.join(log_filename, s.LOG_FILENAME)
            with s.get_logger(args.log, log_filename) as logger:
                link.add_callback(logger)
                log_filter = DEFAULT_LOG_LEVEL_FILTER
                if args.initloglevel[0]:
                    log_filter = args.initloglevel[0]
                SwiftConsole(link, args.update, log_filter,
                             True).configure_traits()
    try:
        os._exit(0)
    except:
        pass


# If using a device connected to an actual port, then invoke the
# regular console dialog for port selection
class PortChooser(HasTraits):
Exemplo n.º 10
0

if not port:
    port_chooser = PortChooser()
    is_ok = port_chooser.configure_traits()
    port = port_chooser.port
    if not port or not is_ok:
        print "No serial device selected!"
        sys.exit(1)
    else:
        print "Using serial device '%s'" % port

# Make sure that SIGINT (i.e. Ctrl-C from command line) actually stops the
# application event loop (otherwise Qt swallows KeyboardInterrupt exceptions)
signal.signal(signal.SIGINT, signal.SIG_DFL)

with serial_link.get_driver(args.ftdi, port, baud) as driver:
    with sbp.client.handler.Handler(driver.read, driver.write, args.verbose) as link:
        with serial_link.get_logger(args.log, log_filename) as logger:
            link.add_callback(logger)
            if args.reset:
                link.send(SBP_MSG_RESET, "")
            console = SwiftConsole(link, update=args.update)
            console.configure_traits()

# Force exit, even if threads haven't joined
try:
    os._exit(0)
except:
    pass
Exemplo n.º 11
0
  def __init__(self):
    try:
      self.ports = [p for p, _, _ in serial_link.get_ports()]
    except TypeError:
      pass

if not port:
  port_chooser = PortChooser()
  is_ok = port_chooser.configure_traits()
  port = port_chooser.port
  if not port or not is_ok:
    print "No serial device selected!"
    sys.exit(1)
  else:
    print "Using serial device '%s'" % port

with serial_link.get_driver(args.ftdi, port, baud) as driver:
  with sbp.client.handler.Handler(driver.read, driver.write, args.verbose) as link:
    with serial_link.get_logger(args.log, serial_link.LOG_FILENAME) as logger:
      link.add_callback(logger)
      if args.reset:
        link.send(SBP_MSG_RESET, "")
      console = SwiftConsole(link, update=args.update)
      console.configure_traits()

# Force exit, even if threads haven't joined
try:
  os._exit(0)
except:
  pass
Exemplo n.º 12
0
def main():
  """
  Get configuration, get driver, get logger, and build handler and start it.
  Create relevant TestState object and perform associated actions.
  Modeled after serial_link main function.
  """
  args = get_args()
  port = args.port[0]
  baud = args.baud[0]
  timeout = args.timeout[0]
  log_filename = args.log_filename[0]
  append_log_filename = args.append_log_filename[0]
  watchdog = args.watchdog[0]
  tags = args.tags[0]
  interval = int(args.interval[0])
  minsats = int(args.minsats[0])

  # Driver with context
  with sl.get_driver(args.ftdi, port, baud) as driver:
    # Handler with context
    with Handler(driver.read, driver.write, args.verbose) as link:
      # Logger with context
      with sl.get_logger(args.log, log_filename) as logger:
        # Append logger iwth context
        with sl.get_append_logger(append_log_filename, tags) as append_logger:
          # print out SBP_MSG_PRINT messages
          link.add_callback(sl.printer, SBP_MSG_PRINT)
          # add logger callback
          link.add_callback(logger)
          # ad append logger callback
          link.add_callback(append_logger)
          # Reset device
          if args.reset:
            link.send(SBP_MSG_RESET, "")
          # Setup watchdog
          if watchdog:
            link.add_callback(sl.Watchdog(float(watchdog), sl.watchdog_alarm),
                              SBP_MSG_HEARTBEAT)
          try:
            # Get device info
            piksi_diag = ptd.Diagnostics(link)
            while not piksi_diag.heartbeat_received:
              time.sleep(0.1)
            # add Teststates and associated callbacks
            with DropSatsState(link, piksi_diag.sbp_version, interval,
                               minsats, debug=args.verbose) as drop:
              link.add_callback(drop.process_message)

              if timeout is not None:
                expire = time.time() + float(args.timeout[0])

              while True:
                if timeout is None or time.time() < expire:
                # Wait forever until the user presses Ctrl-C
                  time.sleep(1)
                else:
                  print "Timer expired!"
                  break
                if not link.is_alive():
                  sys.stderr.write("ERROR: Thread died!")
                  sys.exit(1)
          except KeyboardInterrupt:
            # Callbacks, such as the watchdog timer on SBP_HEARTBEAT call
            # thread.interrupt_main(), which throw a KeyboardInterrupt
            # exception. To get the proper error condition, return exit code
            # of 1. Note that the finally block does get caught since exit
            # itself throws a SystemExit exception.
            sys.exit(1)
Exemplo n.º 13
0
    try:
      self.ports = [p for p, _, _ in s.get_ports()]
      if self.ports:
        self.port = self.ports[0]
      self.bauds = [4800, 9600, 19200, 38400, 43000, 56000, 57600, 115200]
    except TypeError:
      pass

if not port:
  port_chooser = PortChooser()
  is_ok = port_chooser.configure_traits()
  port = port_chooser.port
  baud = port_chooser.baud
  if not port or not is_ok:
    print "No serial device selected!"
    sys.exit(1)
  else:
    print "Using serial device '%s', bauderate %d" % (port, baud)

with s.get_driver(False, port, baud) as driver:
  with sbpc.Handler(sbpc.Framer(driver.read, driver.write, False)) as link:
    with s.get_logger() as logger:
      sbpc.Forwarder(link, logger).start()
      SwiftConsole(link).configure_traits()

# Force exit, even if threads haven't joined
try:
  os._exit(0)
except:
  pass
Exemplo n.º 14
0
                self.port = self.ports[0]
            self.bauds = [
                4800, 9600, 19200, 38400, 43000, 56000, 57600, 115200
            ]
        except TypeError:
            pass


if not port:
    port_chooser = PortChooser()
    is_ok = port_chooser.configure_traits()
    port = port_chooser.port
    baud = port_chooser.baud
    if not port or not is_ok:
        print "No serial device selected!"
        sys.exit(1)
    else:
        print "Using serial device '%s', bauderate %d" % (port, baud)

with s.get_driver(False, port, baud) as driver:
    with sbpc.Handler(sbpc.Framer(driver.read, driver.write, False)) as link:
        with s.get_logger() as logger:
            sbpc.Forwarder(link, logger).start()
            SwiftConsole(link).configure_traits()

# Force exit, even if threads haven't joined
try:
    os._exit(0)
except:
    pass