def main():
    args = get_args()
    open_args = 'rb' if args.format == 'bin' else 'r'
    with open(args.file, open_args) as fd:
        if args.format == 'json':
            iterator = JSONLogIterator(fd)
        elif args.format == 'bin':
            driver = FileDriver(fd)
            iterator = Framer(driver.read, driver.write)
        else:
            raise Exception(
                "Usage Error: Unknown input format. Valid input formats for -f arg are bin and json.")
        msg_class = None
        for my_id, my_class in _SBP_TABLE.iteritems():
            if my_class.__name__ == args.type or (args.id and my_id == int(args.id)):
                print("Extracing class {} with msg_id {}".format(my_class, my_id))
                msg_class = my_class
        assert msg_class is not None, "Invalid message type specified"
        with open(msg_class.__name__ + "_" + args.outfile, 'w+') as outfile:
            conv = MsgExtractor(outfile, msg_class, metadata=(args.format == 'json'))
            if args.format == 'json':
                iterator = iterator.next()
            while True:
                try:
                    (msg, data) = iterator.next()
                    if isinstance(msg, msg_class):
                        conv._callback(msg, data)
                except StopIteration:
                    break
def collect_positions(infile, msgtype, debouncetime):
  """
  Collects data from the log file and calls functions to analyze that data 

  Parameters
  ----------
  infile : string
    Log file to get data from.
  msgtype : string
    type of parameters to analyze and output
  debouncetime : integer
    time in milliseconds to compensate for switch debounce 
  """

  with JSONLogIterator(infile) as log:
    log = log.next()
    
    #declaring all lists 
    message_type = []
    msg_tow = []
    msg_horizontal = []
    msg_vertical = []
    msg_depth = []
    msg_sats = []
    msg_flag = []
    numofmsg = 0;

    while True:
      try:
        msg, metadata = log.next()
        hostdelta = metadata['delta']
        hosttimestamp = metadata['timestamp']
        valid_msg = ["MsgBaselineECEF", "MsgPosECEF", "MsgBaselineNED", "MsgPosLLH", "MsgExtEvent"]
        #collect all data in lists
        if msg.__class__.__name__ in valid_msg :
          message_type.append(msg.__class__.__name__)
          msg_tow.append(msg.tow)
          msg_flag.append(msg.flags)
          if msg.__class__.__name__ == "MsgBaselineECEF" or msg.__class__.__name__ == "MsgPosECEF" :
            msg_horizontal.append(msg.x)
            msg_vertical.append(msg.y)
            msg_depth.append(msg.z)
            msg_sats.append(msg.n_sats)
          elif msg.__class__.__name__ == "MsgBaselineNED":
            msg_horizontal.append(msg.n)
            msg_vertical.append(msg.e)
            msg_depth.append(msg.d)
            msg_sats.append(msg.n_sats)
          elif msg.__class__.__name__ == "MsgPosLLH":
            msg_horizontal.append(msg.lat)
            msg_vertical.append(msg.lon)
            msg_depth.append(msg.height)
            msg_sats.append(msg.n_sats)
          elif msg.__class__.__name__ == "MsgExtEvent":
            print msg.tow
            msg_horizontal.append("0")
            msg_vertical.append("0")
            msg_depth.append("0")
            msg_sats.append("0")
          numofmsg += 1

      except StopIteration:
        print "reached end of file after {0} milli-seconds".format(hostdelta)
        fix_trigger_rollover(message_type, msg_tow, numofmsg)
        print 'done roll'
        fix_trigger_debounce(message_type, msg_tow, numofmsg, debouncetime)
        print ' done bebounce'
        get_trigger_positions(message_type, msg_tow, msgtype, numofmsg, msg_horizontal, msg_vertical, msg_depth, msg_sats)
        print 'done interpolation'
        print 
        numofmsg =  rid_access_data (message_type, msg_tow, msg_horizontal , msg_vertical , msg_depth , msg_flag , msg_sats , numofmsg)

        return message_type, msg_tow, msg_horizontal , msg_vertical , msg_depth , msg_flag , msg_sats , numofmsg
Exemple #3
0
def main():
    warnings.simplefilter(action="ignore", category=FutureWarning)
    logging.basicConfig()
    args = None
    parser = get_args()
    try:
        args = parser.parse_args()
        show_usage = args.help
        error_str = ""
    except (ArgumentParserError, argparse.ArgumentError,
            argparse.ArgumentTypeError) as e:
        print(e)
        show_usage = True
        error_str = "ERROR: " + str(e)

    # 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)
    if show_usage:
        usage_str = parser.format_help()
        print(usage_str)
        usage = ShowUsage(usage_str, error_str)
        usage.configure_traits()
        sys.exit(1)

    # fail out if connection failed to initialize
    cnx_data = do_connection(args)
    if cnx_data is None:
        print('Unable to Initialize Connection. Exiting...')
        sys.exit(1)

    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(cnx_data.driver, conventional=True)
    else:
        source = sbpc.Framer(cnx_data.driver.read,
                             cnx_data.driver.write,
                             args.verbose,
                             sender_id_filter_list=sender_id_filter)

    with sbpc.Handler(source) as link:
        if args.reset:
            link(MsgReset(flags=0))
        log_filter = DEFAULT_LOG_LEVEL_FILTER
        if args.initloglevel[0]:
            log_filter = args.initloglevel[0]
        with SwiftConsole(link,
                          cnx_data.driver,
                          args.update,
                          log_filter,
                          cnx_desc=cnx_data.description,
                          error=args.error,
                          json_logging=args.log,
                          show_csv_log=args.show_csv_log,
                          log_dirname=args.log_dirname,
                          override_filename=args.logfilename,
                          log_console=args.log_console,
                          connection_info=cnx_data.connection_info,
                          expand_json=args.expand_json,
                          hide_legend=args.hide_legend) as console:
            console.configure_traits()

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