示例#1
0
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
示例#2
0
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
示例#3
0
def main():
    # First, we start up an SBP driver reading from STDInput
    first = True
    args = get_args()
    with open(args.file, 'r') as fd:
        if args.format == 'json':
            iterator = JSONLogIterator(fd)
        elif args.format == 'bin':
            driver = FileDriver(fd)
            iterator = Framer(driver.read, driver.write)
        else:
            raise ("unkonwn format")
        with open(args.outfile, 'w+') as outfile:
            conv = Extractor(outfile)
            if args.format == 'json':
                iterator = iterator.next()
            while True:
                try:
                    (msg, data) = iterator.next()
                    if first:
                        first = False
                    if isinstance(msg, MsgCommandResp):
                        conv._callback(msg)
                except StopIteration:
                    break

    df = pd.read_csv(open(args.outfile, 'r'))
    fig = plt.figure(figsize=[20, 10])
    plt.plot(df["tow (ms)"], df['acc_x'])
    plt.legend(['acc_x'])
    fig.savefig('acc.png')
示例#4
0
def main():
    # First, we start up an SBP driver reading from STDInput
    first = True
    args = get_args()
    with open(args.file, 'r') as fd:
        if args.format == 'json':
            iterator = JSONLogIterator(fd)
        elif args.format == 'bin':
            driver = FileDriver(fd)
            iterator = Framer(driver.read, driver.write)
        else:
            raise ("unkonwn format")
        with open(args.type + "_" + args.outfile, 'w+') as outfile:
            conv = MsgExtractor(outfile, args.type)
            if args.format == 'json':
                iterator = iterator.next()
            while True:
                try:
                    (msg, data) = iterator.next()
                    if first:
                        first = False
                    if isinstance(msg, eval(args.type)):
                        conv._callback(msg)
                except StopIteration:
                    break
示例#5
0
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
        with open(args.outfile, 'wb') as outfile:
            conv = MsgInjector(outfile,
                               msg_class,
                               metadata=(args.format == 'json'))
            if args.format == 'json':
                iterator = iterator.next()
            while True:
                try:
                    (msg, data) = iterator.next()
                    if msg.msg_type == SBP_MSG_IMU_RAW:
                        conv.imu_raw_callback(msg, data)
                    else:
                        conv.any_callback(msg, data)
                except StopIteration:
                    break
示例#6
0
def main():
    # First, we start up an SBP driver reading from STDInput
    first = True
    args = get_args()
    outfile_str = ""
    with open(args.file, 'r') as fd:
        if args.format == 'json':
            iterator = JSONLogIterator(fd)
        elif args.format == 'bin':
            driver = FileDriver(fd)
            iterator = Framer(driver.read, driver.write)
        else:
            raise ("unkonwn format")
        outfile_str = args.outfile + args.file + "imu.csv"
        with open(outfile_str, 'w') as outfile:
            conv = MagExtractor(outfile)
            if args.format == 'json':
                iterator = iterator.next()
            while True:
                try:
                    (msg, data) = iterator.next()
                    if first:
                        first = False
                    if isinstance(msg, MsgImuRaw):
                        conv.mag_callback(msg)
                except StopIteration:
                    break

    df = pd.read_csv(open(outfile_str, 'r'))
    fig = plt.figure(figsize=[20, 10])
    fig = plt.figure(figsize=[20, 10])
    plt.subplot(3, 1, 1)
    plt.plot(df["tow (ms)"], df["tow (ms)"].diff())
    plt.ylabel(['tow period (milliseconds)'])
    ax = plt.subplot(3, 1, 2)
    df["tow (ms)"].diff().hist(ax=ax)
    fig.savefig(args.file + '.png')
示例#7
0
def main():
    # open a file, iterate through it,
    # do something when particular message type is found
    args = get_args()
    with open(args.file, 'r') as fd:
        if args.format == 'json':
            iterator = JSONLogIterator(fd).next()
        elif args.format == 'bin':
            driver = FileDriver(fd)
            iterator = Framer(driver.read, driver.write)
        else:
            raise ("unknown format: possible formats are bin and json")
        conv = EventExtractor()
        while True:
            try:
                (msg, data) = iterator.next()
                if isinstance(msg, MsgExtEvent):
                    conv._event_callback(msg)
            except StopIteration:
                break