|
1 | 1 | #!/usr/bin/env python3
|
| 2 | +# |
| 3 | +# Copyright (c) FIRST and other WPILib contributors. |
| 4 | +# Open Source Software; you can modify and/or share it under the terms of |
| 5 | +# the WPILib BSD license file in the root directory of this project. |
2 | 6 |
|
3 | 7 | import argparse
|
4 |
| -import pathlib |
| 8 | +import datetime |
5 | 9 |
|
6 | 10 | from wpiutil.log import DataLogReader
|
7 | 11 |
|
|
11 | 15 | args = parser.parse_args()
|
12 | 16 |
|
13 | 17 | reader = DataLogReader(args.infile)
|
| 18 | + |
| 19 | + entries = {} |
14 | 20 | for record in reader:
|
| 21 | + timestamp = record.getTimestamp() / 1000000 |
15 | 22 | if record.isStart():
|
16 |
| - print(record.getStartData()) |
| 23 | + try: |
| 24 | + data = record.getStartData() |
| 25 | + print(f"{data} [{timestamp}]") |
| 26 | + if data.entry in entries: |
| 27 | + print("...DUPLICATE entry ID, overriding") |
| 28 | + entries[data.entry] = data |
| 29 | + except TypeError as e: |
| 30 | + print("Start(INVALID)") |
| 31 | + elif record.isFinish(): |
| 32 | + try: |
| 33 | + entry = record.getFinishEntry() |
| 34 | + print(f"Finish({entry}) [{timestamp}]") |
| 35 | + if entry not in entries: |
| 36 | + print("...ID not found") |
| 37 | + else: |
| 38 | + del entries[entry] |
| 39 | + except TypeError as e: |
| 40 | + print("Finish(INVALID)") |
| 41 | + elif record.isSetMetadata(): |
| 42 | + try: |
| 43 | + data = record.getSetMetadataData() |
| 44 | + print(f"{data} [{timestamp}]") |
| 45 | + if data.entry not in entries: |
| 46 | + print("...ID not found") |
| 47 | + except TypeError as e: |
| 48 | + print("SetMetadata(INVALID)") |
| 49 | + elif record.isControl(): |
| 50 | + print("Unrecognized control record") |
17 | 51 | else:
|
18 |
| - print(record.getBoolean()) |
| 52 | + print(f"Data({record.getEntry()}, size={record.getSize()}) ", end="") |
| 53 | + entry = entries.get(record.getEntry(), None) |
| 54 | + if entry is None: |
| 55 | + print("<ID not found>") |
| 56 | + continue |
| 57 | + print(f"<name='{entry.name}', type='{entry.type}'> [{timestamp}]") |
| 58 | + |
| 59 | + try: |
| 60 | + # handle systemTime specially |
| 61 | + if entry.name == "systemTime" and entry.type == "int64": |
| 62 | + dt = datetime.fromtimestamp(record.getInteger() / 1000000) |
| 63 | + print(" {:%Y-%m-%d %H:%M:%S.%f}".format(dt)) |
| 64 | + continue |
| 65 | + |
| 66 | + if entry.type == "double": |
| 67 | + print(f" {record.getDouble()}") |
| 68 | + elif entry.type == "int64": |
| 69 | + print(f" {record.getInteger()}") |
| 70 | + elif entry.type == "string" or entry.type == "json": |
| 71 | + print(f" '{record.getString()}'") |
| 72 | + elif entry.type == "boolean": |
| 73 | + print(f" {record.getBoolean()}") |
| 74 | + elif entry.type == "boolean[]": |
| 75 | + arr = record.getBooleanArray() |
| 76 | + print(f" {arr}") |
| 77 | + elif entry.type == "double[]": |
| 78 | + arr = record.getDoubleArray() |
| 79 | + print(f" {arr}") |
| 80 | + elif entry.type == "float[]": |
| 81 | + arr = record.getFloatArray() |
| 82 | + print(f" {arr}") |
| 83 | + elif entry.type == "int64[]": |
| 84 | + arr = record.getIntegerArray() |
| 85 | + print(f" {arr}") |
| 86 | + elif entry.type == "string[]": |
| 87 | + arr = record.getStringArray() |
| 88 | + print(f" {arr}") |
| 89 | + elif entry.type == "raw": |
| 90 | + print(f" {record.getRaw()}") |
| 91 | + except TypeError as e: |
| 92 | + print(" invalid", e) |
0 commit comments