Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Add DataLog #37

Merged
merged 8 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions examples/printlog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/usr/bin/env python3
#
# Copyright (c) FIRST and other WPILib contributors.
# Open Source Software; you can modify and/or share it under the terms of
# the WPILib BSD license file in the root directory of this project.

import argparse
import datetime

from wpiutil.log import DataLogReader

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("infile")
args = parser.parse_args()

reader = DataLogReader(args.infile)

entries = {}
for record in reader:
timestamp = record.getTimestamp() / 1000000
if record.isStart():
try:
data = record.getStartData()
print(f"{data} [{timestamp}]")
if data.entry in entries:
print("...DUPLICATE entry ID, overriding")
entries[data.entry] = data
except TypeError as e:
print("Start(INVALID)")
elif record.isFinish():
try:
entry = record.getFinishEntry()
print(f"Finish({entry}) [{timestamp}]")
if entry not in entries:
print("...ID not found")
else:
del entries[entry]
except TypeError as e:
print("Finish(INVALID)")
elif record.isSetMetadata():
try:
data = record.getSetMetadataData()
print(f"{data} [{timestamp}]")
if data.entry not in entries:
print("...ID not found")
except TypeError as e:
print("SetMetadata(INVALID)")
elif record.isControl():
print("Unrecognized control record")
else:
print(f"Data({record.getEntry()}, size={record.getSize()}) ", end="")
entry = entries.get(record.getEntry(), None)
if entry is None:
print("<ID not found>")
continue
print(f"<name='{entry.name}', type='{entry.type}'> [{timestamp}]")

try:
# handle systemTime specially
if entry.name == "systemTime" and entry.type == "int64":
dt = datetime.fromtimestamp(record.getInteger() / 1000000)
print(" {:%Y-%m-%d %H:%M:%S.%f}".format(dt))
continue

if entry.type == "double":
print(f" {record.getDouble()}")
elif entry.type == "int64":
print(f" {record.getInteger()}")
elif entry.type == "string" or entry.type == "json":
print(f" '{record.getString()}'")
elif entry.type == "boolean":
print(f" {record.getBoolean()}")
elif entry.type == "boolean[]":
arr = record.getBooleanArray()
print(f" {arr}")
elif entry.type == "double[]":
arr = record.getDoubleArray()
print(f" {arr}")
elif entry.type == "float[]":
arr = record.getFloatArray()
print(f" {arr}")
elif entry.type == "int64[]":
arr = record.getIntegerArray()
print(f" {arr}")
elif entry.type == "string[]":
arr = record.getStringArray()
print(f" {arr}")
elif entry.type == "raw":
print(f" {record.getRaw()}")
except TypeError as e:
print(" invalid", e)
30 changes: 30 additions & 0 deletions examples/writelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python3

import argparse
import pathlib

from wpiutil.log import DataLog, BooleanLogEntry, StringArrayLogEntry, RawLogEntry


if __name__ == "__main__":

parser = argparse.ArgumentParser()
parser.add_argument("out", type=pathlib.Path)
args = parser.parse_args()

if args.out.is_dir():
datalog = DataLog(str(args.out))
else:
datalog = DataLog(str(args.out.parent), args.out.name)

bools = BooleanLogEntry(datalog, "/bools")
bools.append(True)
bools.append(False)

strings = StringArrayLogEntry(datalog, "/strings")
strings.append(["a", "b", "c"])
strings.append(["d", "e", "f"])

raw = RawLogEntry(datalog, "/raws")
raw.append(b"\x01\x02\x03")
raw.append(b"\x04\x05\x06")
229 changes: 229 additions & 0 deletions gen/DataLog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
---

enums:
ControlRecordType:
classes:
DataLog:
subpackage: log
methods:
DataLog:
overloads:
std::string_view, std::string_view, double, std::string_view:
wpi::Logger&, std::string_view, std::string_view, double, std::string_view:
ignore: true
std::function<void ( wpi::span<const uint8_t> data )>, double, std::string_view:
wpi::Logger&, std::function<void ( wpi::span<const uint8_t> data )>, double, std::string_view:
ignore: true
SetFilename:
Flush:
Pause:
Resume:
Start:
Finish:
SetMetadata:
AppendRaw:
AppendRaw2:
AppendBoolean:
AppendInteger:
AppendFloat:
AppendDouble:
AppendString:
AppendBooleanArray:
overloads:
int, wpi::span<const bool>, int64_t:
int, wpi::span<const int>, int64_t:
ignore: true
int, wpi::span<const uint8_t>, int64_t:
ignore: true
AppendIntegerArray:
AppendFloatArray:
AppendDoubleArray:
AppendStringArray:
overloads:
int, wpi::span<const std::string>, int64_t:
ignore: true
int, wpi::span<const std::string_view>, int64_t:
DataLogEntry:
subpackage: log
force_no_trampoline: true
methods:
SetMetadata:
Finish:
DataLogEntry:
overloads:
"":
ignore: true
wpi::log::DataLog&, std::string_view, std::string_view, std::string_view, int64_t:
RawLogEntry:
subpackage: log
force_no_trampoline: true
attributes:
kDataType:
methods:
RawLogEntry:
overloads:
"":
ignore: true
wpi::log::DataLog&, std::string_view, int64_t:
wpi::log::DataLog&, std::string_view, std::string_view, int64_t:
wpi::log::DataLog&, std::string_view, std::string_view, std::string_view, int64_t:
Append:
BooleanLogEntry:
subpackage: log
force_no_trampoline: true
attributes:
kDataType:
methods:
BooleanLogEntry:
overloads:
"":
ignore: true
wpi::log::DataLog&, std::string_view, int64_t:
wpi::log::DataLog&, std::string_view, std::string_view, int64_t:
Append:
IntegerLogEntry:
subpackage: log
force_no_trampoline: true
attributes:
kDataType:
methods:
IntegerLogEntry:
overloads:
"":
ignore: true
wpi::log::DataLog&, std::string_view, int64_t:
wpi::log::DataLog&, std::string_view, std::string_view, int64_t:
Append:
FloatLogEntry:
subpackage: log
force_no_trampoline: true
attributes:
kDataType:
methods:
FloatLogEntry:
overloads:
"":
ignore: true
wpi::log::DataLog&, std::string_view, int64_t:
wpi::log::DataLog&, std::string_view, std::string_view, int64_t:
Append:
DoubleLogEntry:
subpackage: log
force_no_trampoline: true
attributes:
kDataType:
methods:
DoubleLogEntry:
overloads:
"":
ignore: true
wpi::log::DataLog&, std::string_view, int64_t:
wpi::log::DataLog&, std::string_view, std::string_view, int64_t:
Append:
StringLogEntry:
subpackage: log
force_no_trampoline: true
attributes:
kDataType:
methods:
StringLogEntry:
overloads:
"":
ignore: true
wpi::log::DataLog&, std::string_view, int64_t:
wpi::log::DataLog&, std::string_view, std::string_view, int64_t:
wpi::log::DataLog&, std::string_view, std::string_view, std::string_view, int64_t:
Append:
BooleanArrayLogEntry:
subpackage: log
force_no_trampoline: true
attributes:
kDataType:
methods:
BooleanArrayLogEntry:
overloads:
"":
ignore: true
wpi::log::DataLog&, std::string_view, int64_t:
wpi::log::DataLog&, std::string_view, std::string_view, int64_t:
Append:
overloads:
wpi::span<const bool>, int64_t:
std::initializer_list<bool>, int64_t:
ignore: true
wpi::span<const int>, int64_t:
ignore: true
std::initializer_list<int>, int64_t:
ignore: true
wpi::span<const uint8_t>, int64_t:
ignore: true
IntegerArrayLogEntry:
subpackage: log
force_no_trampoline: true
attributes:
kDataType:
methods:
IntegerArrayLogEntry:
overloads:
"":
ignore: true
wpi::log::DataLog&, std::string_view, int64_t:
wpi::log::DataLog&, std::string_view, std::string_view, int64_t:
Append:
overloads:
wpi::span<const int64_t>, int64_t:
std::initializer_list<int64_t>, int64_t:
ignore: true
FloatArrayLogEntry:
subpackage: log
force_no_trampoline: true
attributes:
kDataType:
methods:
FloatArrayLogEntry:
overloads:
"":
ignore: true
wpi::log::DataLog&, std::string_view, int64_t:
wpi::log::DataLog&, std::string_view, std::string_view, int64_t:
Append:
overloads:
wpi::span<const float>, int64_t:
std::initializer_list<float>, int64_t:
ignore: true
DoubleArrayLogEntry:
subpackage: log
force_no_trampoline: true
attributes:
kDataType:
methods:
DoubleArrayLogEntry:
overloads:
"":
ignore: true
wpi::log::DataLog&, std::string_view, int64_t:
wpi::log::DataLog&, std::string_view, std::string_view, int64_t:
Append:
overloads:
wpi::span<const double>, int64_t:
std::initializer_list<double>, int64_t:
ignore: true
StringArrayLogEntry:
subpackage: log
force_no_trampoline: true
attributes:
kDataType:
methods:
StringArrayLogEntry:
overloads:
"":
ignore: true
wpi::log::DataLog&, std::string_view, int64_t:
wpi::log::DataLog&, std::string_view, std::string_view, int64_t:
Append:
overloads:
wpi::span<const std::string>, int64_t:
ignore: true
wpi::span<const std::string_view>, int64_t:
std::initializer_list<std::string_view>, int64_t:
ignore: true
Loading