コード例 #1
0
def main(args):
  """
  Get configuration, get driver, get logger, and build handler and start it.
  """
  port = args.port
  baud = args.baud
  timeout = args.timeout
  log_filename = args.log_filename
  append_log_filename = args.append_log_filename
  tags = args.tags
  # State for handling a networked base stations.
  channel = args.channel_id
  serial_id = int(args.serial_id) if args.serial_id is not None else None
  base = args.base
  use_broker = args.broker
  # Driver with context
  with get_driver(args.ftdi, port, baud, args.file) as driver:
    # Handler with context
    with Handler(Framer(driver.read, driver.write, args.verbose)) as link:
      # Logger with context
      with get_logger(args.log, log_filename) as logger:
        with get_append_logger(append_log_filename, tags) as append_logger:
          link.add_callback(printer, SBP_MSG_PRINT_DEP)
          link.add_callback(log_printer, SBP_MSG_LOG)
          Forwarder(link, logger).start()
          Forwarder(link, append_logger).start()
          if use_broker and base and serial_id:
            device_id = get_uuid(channel, serial_id)
            with HTTPDriver(str(device_id), base) as http:
              with Handler(Framer(http.read, http.write, args.verbose)) as slink:
                Forwarder(slink, swriter(link)).start()
                run(args, link)
          else:
            run(args, link)
コード例 #2
0
def main(args):
    """
    Get configuration, get driver, get logger, and build handler and start it.
    """
    timeout = args.timeout
    log_filename = args.logfilename
    log_dirname = args.log_dirname
    if not log_filename:
        log_filename = logfilename()
    if log_dirname:
        log_filename = os.path.join(log_dirname, log_filename)
    # State for handling a networked base stations.
    channel = args.channel_id
    serial_id = int(args.serial_id) if args.serial_id is not None else None
    base = args.base
    use_broker = args.broker
    # Driver with context
    driver = get_base_args_driver(args)
    with Handler(Framer(driver.read, driver.write, args.verbose)) as link:
        # Logger with context
        with get_logger(args.log, log_filename, args.expand_json) as logger:
            link.add_callback(printer, SBP_MSG_PRINT_DEP)
            link.add_callback(log_printer, SBP_MSG_LOG)
            Forwarder(link, logger).start()
            if use_broker and base and serial_id:
                device_id = get_uuid(channel, serial_id)
                with HTTPDriver(str(device_id), base) as http:
                    with Handler(Framer(http.read, http.write,
                                        args.verbose)) as slink:
                        Forwarder(slink, swriter(link)).start()
                        run(args, link)
            else:
                run(args, link)
コード例 #3
0
def main(args):
    """
    Get configuration, get driver, get logger, and build handler and start it.
    """
    port = args.port
    baud = args.baud
    timeout = args.timeout
    log_filename = args.logfilename
    log_dirname = args.log_dirname
    if not log_filename:
        log_filename = logfilename()
    if log_dirname:
        log_filename = os.path.join(log_dirname, log_filename)
    append_log_filename = args.append_log_filename
    tags = args.tags
    # State for handling a networked base stations.
    channel = args.channel_id
    serial_id = int(args.serial_id) if args.serial_id is not None else None
    base = args.base
    use_broker = args.broker
    # Driver with context
    if args.tcp:
        try:
            host, port = port.split(':')
            driver = TCPDriver(host, int(port))
        except:  # noqa
            raise Exception('Invalid host and/or port')
    else:
        driver = get_driver(args.ftdi,
                            port,
                            baud,
                            args.file,
                            rtscts=args.rtscts)
        # Handler with context
    with Handler(Framer(driver.read, driver.write, args.verbose)) as link:
        # Logger with context
        with get_logger(args.log, log_filename, args.expand_json) as logger:
            with get_append_logger(append_log_filename, tags) as append_logger:
                link.add_callback(printer, SBP_MSG_PRINT_DEP)
                link.add_callback(log_printer, SBP_MSG_LOG)
                Forwarder(link, logger).start()
                Forwarder(link, append_logger).start()
                if use_broker and base and serial_id:
                    device_id = get_uuid(channel, serial_id)
                    with HTTPDriver(str(device_id), base) as http:
                        with Handler(
                                Framer(http.read, http.write,
                                       args.verbose)) as slink:
                            Forwarder(slink, swriter(link)).start()
                            run(args, link)
                else:
                    run(args, link)
コード例 #4
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)
コード例 #5
0
def main():
    """
  Get configuration, get driver, get logger, and build handler and start it.
  """
    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]
    tags = args.tags[0]
    # Driver with context
    with 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 get_logger(args.log, log_filename) as logger:
                with get_append_logger(append_log_filename,
                                       tags) as append_logger:
                    link.add_callback(printer, SBP_MSG_PRINT_DEP)
                    link.add_callback(log_printer, SBP_MSG_LOG)
                    Forwarder(link, logger).start()
                    Forwarder(link, append_logger).start()
                    # Reset device
                    if args.reset:
                        link(MsgReset())
                    try:
                        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 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)
コード例 #6
0
def base_pos_log(source):
    # Hold for 2 hours, + 1 minute to allow Piksi to acquire satellite signal
    TIME_INTERVAL = 60

    filename = time.strftime("gnss-%Y%m%d-%H%M%S.sbp.json")
    infile = open(filename, 'w')
    #filename = os.path.normpath(
    #            os.path.join("data", filename))

    # Data structure for logging
    logger = JSONLogger(infile)

    # Sends data from Piksi to logger
    fwd = Forwarder(source, logger)
    fwd.start()
    
    # Collect data during interval
    start = time.perf_counter()
    diff = 0
    while diff < TIME_INTERVAL:
        diff = time.perf_counter() - start
    
    fwd.stop()
    logger.flush()
    logger.close()

    send_to_OPUS(filename)
コード例 #7
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)
コード例 #8
0
def main(args):
    """
    Get configuration, get driver, get logger, and build handler and start it.
    """
    log_filename = args.logfilename
    log_dirname = args.log_dirname

    stop_function = lambda: None  # noqa

    if not log_filename:
        log_filename = logfilename()
    if log_dirname:
        log_filename = os.path.join(log_dirname, log_filename)
    driver = get_base_args_driver(args)
    sender_id_filter = []
    if args.sender_id_filter is not None:
        sender_id_filter = [int(x) for x in args.sender_id_filter.split(",")]
    if args.json:
        source = JSONLogIterator(driver, conventional=True)
    else:
        source = Framer(driver.read,
                        driver.write,
                        args.verbose,
                        skip_metadata=args.skip_metadata,
                        sender_id_filter_list=sender_id_filter)
    last_bytes_read = [0]
    if args.status:

        def print_io_data(last_bytes_read):
            # bitrate is will be kilobytes per second. 2 second period, 1024 bytes per kilobyte
            kbs_avg = driver.bytes_read_since(
                last_bytes_read[0]) / (2 * 1024.0)
            print("{0:.2f} KB/s average data rate (2 second period).".format(
                kbs_avg))
            last_bytes_read[0] = driver.total_bytes_read

        stop_function = call_repeatedly(2, print_io_data, last_bytes_read)
    with Handler(source, autostart=False) as link, get_logger(
            args.log, log_filename, args.expand_json,
            args.sort_keys) as logger:
        link.add_callback(printer, SBP_MSG_PRINT_DEP)
        link.add_callback(log_printer, SBP_MSG_LOG)
        Forwarder(link, logger).start()
        run(args, link, stop_function=stop_function)
コード例 #9
0
ファイル: serial_link.py プロジェクト: wangyu78/piksi_tools
def main(args):
    """
    Get configuration, get driver, get logger, and build handler and start it.
    """
    log_filename = args.logfilename
    log_dirname = args.log_dirname
    if not log_filename:
        log_filename = logfilename()
    if log_dirname:
        log_filename = os.path.join(log_dirname, log_filename)
    driver = get_base_args_driver(args)
    with Handler(Framer(driver.read,
                        driver.write,
                        args.verbose,
                        skip_metadata=args.skip_metadata),
                 autostart=False) as link:
        # Logger with context
        with get_logger(args.log, log_filename, args.expand_json,
                        args.sort_keys) as logger:
            link.add_callback(printer, SBP_MSG_PRINT_DEP)
            link.add_callback(log_printer, SBP_MSG_LOG)
            Forwarder(link, logger).start()
            run(args, link)