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

Commit e6f68e2

Browse files
authored
Merge pull request #37 from robotpy/datalog
Add DataLog
2 parents fa80026 + a15b7d9 commit e6f68e2

File tree

7 files changed

+764
-13
lines changed

7 files changed

+764
-13
lines changed

examples/printlog.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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.
6+
7+
import argparse
8+
import datetime
9+
10+
from wpiutil.log import DataLogReader
11+
12+
if __name__ == "__main__":
13+
parser = argparse.ArgumentParser()
14+
parser.add_argument("infile")
15+
args = parser.parse_args()
16+
17+
reader = DataLogReader(args.infile)
18+
19+
entries = {}
20+
for record in reader:
21+
timestamp = record.getTimestamp() / 1000000
22+
if record.isStart():
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")
51+
else:
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)

examples/writelog.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import pathlib
5+
6+
from wpiutil.log import DataLog, BooleanLogEntry, StringArrayLogEntry, RawLogEntry
7+
8+
9+
if __name__ == "__main__":
10+
11+
parser = argparse.ArgumentParser()
12+
parser.add_argument("out", type=pathlib.Path)
13+
args = parser.parse_args()
14+
15+
if args.out.is_dir():
16+
datalog = DataLog(str(args.out))
17+
else:
18+
datalog = DataLog(str(args.out.parent), args.out.name)
19+
20+
bools = BooleanLogEntry(datalog, "/bools")
21+
bools.append(True)
22+
bools.append(False)
23+
24+
strings = StringArrayLogEntry(datalog, "/strings")
25+
strings.append(["a", "b", "c"])
26+
strings.append(["d", "e", "f"])
27+
28+
raw = RawLogEntry(datalog, "/raws")
29+
raw.append(b"\x01\x02\x03")
30+
raw.append(b"\x04\x05\x06")

gen/DataLog.yml

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
---
2+
3+
enums:
4+
ControlRecordType:
5+
classes:
6+
DataLog:
7+
subpackage: log
8+
methods:
9+
DataLog:
10+
overloads:
11+
std::string_view, std::string_view, double, std::string_view:
12+
wpi::Logger&, std::string_view, std::string_view, double, std::string_view:
13+
ignore: true
14+
std::function<void ( wpi::span<const uint8_t> data )>, double, std::string_view:
15+
wpi::Logger&, std::function<void ( wpi::span<const uint8_t> data )>, double, std::string_view:
16+
ignore: true
17+
SetFilename:
18+
Flush:
19+
Pause:
20+
Resume:
21+
Start:
22+
Finish:
23+
SetMetadata:
24+
AppendRaw:
25+
AppendRaw2:
26+
AppendBoolean:
27+
AppendInteger:
28+
AppendFloat:
29+
AppendDouble:
30+
AppendString:
31+
AppendBooleanArray:
32+
overloads:
33+
int, wpi::span<const bool>, int64_t:
34+
int, wpi::span<const int>, int64_t:
35+
ignore: true
36+
int, wpi::span<const uint8_t>, int64_t:
37+
ignore: true
38+
AppendIntegerArray:
39+
AppendFloatArray:
40+
AppendDoubleArray:
41+
AppendStringArray:
42+
overloads:
43+
int, wpi::span<const std::string>, int64_t:
44+
ignore: true
45+
int, wpi::span<const std::string_view>, int64_t:
46+
DataLogEntry:
47+
subpackage: log
48+
force_no_trampoline: true
49+
methods:
50+
SetMetadata:
51+
Finish:
52+
DataLogEntry:
53+
overloads:
54+
"":
55+
ignore: true
56+
wpi::log::DataLog&, std::string_view, std::string_view, std::string_view, int64_t:
57+
RawLogEntry:
58+
subpackage: log
59+
force_no_trampoline: true
60+
attributes:
61+
kDataType:
62+
methods:
63+
RawLogEntry:
64+
overloads:
65+
"":
66+
ignore: true
67+
wpi::log::DataLog&, std::string_view, int64_t:
68+
wpi::log::DataLog&, std::string_view, std::string_view, int64_t:
69+
wpi::log::DataLog&, std::string_view, std::string_view, std::string_view, int64_t:
70+
Append:
71+
BooleanLogEntry:
72+
subpackage: log
73+
force_no_trampoline: true
74+
attributes:
75+
kDataType:
76+
methods:
77+
BooleanLogEntry:
78+
overloads:
79+
"":
80+
ignore: true
81+
wpi::log::DataLog&, std::string_view, int64_t:
82+
wpi::log::DataLog&, std::string_view, std::string_view, int64_t:
83+
Append:
84+
IntegerLogEntry:
85+
subpackage: log
86+
force_no_trampoline: true
87+
attributes:
88+
kDataType:
89+
methods:
90+
IntegerLogEntry:
91+
overloads:
92+
"":
93+
ignore: true
94+
wpi::log::DataLog&, std::string_view, int64_t:
95+
wpi::log::DataLog&, std::string_view, std::string_view, int64_t:
96+
Append:
97+
FloatLogEntry:
98+
subpackage: log
99+
force_no_trampoline: true
100+
attributes:
101+
kDataType:
102+
methods:
103+
FloatLogEntry:
104+
overloads:
105+
"":
106+
ignore: true
107+
wpi::log::DataLog&, std::string_view, int64_t:
108+
wpi::log::DataLog&, std::string_view, std::string_view, int64_t:
109+
Append:
110+
DoubleLogEntry:
111+
subpackage: log
112+
force_no_trampoline: true
113+
attributes:
114+
kDataType:
115+
methods:
116+
DoubleLogEntry:
117+
overloads:
118+
"":
119+
ignore: true
120+
wpi::log::DataLog&, std::string_view, int64_t:
121+
wpi::log::DataLog&, std::string_view, std::string_view, int64_t:
122+
Append:
123+
StringLogEntry:
124+
subpackage: log
125+
force_no_trampoline: true
126+
attributes:
127+
kDataType:
128+
methods:
129+
StringLogEntry:
130+
overloads:
131+
"":
132+
ignore: true
133+
wpi::log::DataLog&, std::string_view, int64_t:
134+
wpi::log::DataLog&, std::string_view, std::string_view, int64_t:
135+
wpi::log::DataLog&, std::string_view, std::string_view, std::string_view, int64_t:
136+
Append:
137+
BooleanArrayLogEntry:
138+
subpackage: log
139+
force_no_trampoline: true
140+
attributes:
141+
kDataType:
142+
methods:
143+
BooleanArrayLogEntry:
144+
overloads:
145+
"":
146+
ignore: true
147+
wpi::log::DataLog&, std::string_view, int64_t:
148+
wpi::log::DataLog&, std::string_view, std::string_view, int64_t:
149+
Append:
150+
overloads:
151+
wpi::span<const bool>, int64_t:
152+
std::initializer_list<bool>, int64_t:
153+
ignore: true
154+
wpi::span<const int>, int64_t:
155+
ignore: true
156+
std::initializer_list<int>, int64_t:
157+
ignore: true
158+
wpi::span<const uint8_t>, int64_t:
159+
ignore: true
160+
IntegerArrayLogEntry:
161+
subpackage: log
162+
force_no_trampoline: true
163+
attributes:
164+
kDataType:
165+
methods:
166+
IntegerArrayLogEntry:
167+
overloads:
168+
"":
169+
ignore: true
170+
wpi::log::DataLog&, std::string_view, int64_t:
171+
wpi::log::DataLog&, std::string_view, std::string_view, int64_t:
172+
Append:
173+
overloads:
174+
wpi::span<const int64_t>, int64_t:
175+
std::initializer_list<int64_t>, int64_t:
176+
ignore: true
177+
FloatArrayLogEntry:
178+
subpackage: log
179+
force_no_trampoline: true
180+
attributes:
181+
kDataType:
182+
methods:
183+
FloatArrayLogEntry:
184+
overloads:
185+
"":
186+
ignore: true
187+
wpi::log::DataLog&, std::string_view, int64_t:
188+
wpi::log::DataLog&, std::string_view, std::string_view, int64_t:
189+
Append:
190+
overloads:
191+
wpi::span<const float>, int64_t:
192+
std::initializer_list<float>, int64_t:
193+
ignore: true
194+
DoubleArrayLogEntry:
195+
subpackage: log
196+
force_no_trampoline: true
197+
attributes:
198+
kDataType:
199+
methods:
200+
DoubleArrayLogEntry:
201+
overloads:
202+
"":
203+
ignore: true
204+
wpi::log::DataLog&, std::string_view, int64_t:
205+
wpi::log::DataLog&, std::string_view, std::string_view, int64_t:
206+
Append:
207+
overloads:
208+
wpi::span<const double>, int64_t:
209+
std::initializer_list<double>, int64_t:
210+
ignore: true
211+
StringArrayLogEntry:
212+
subpackage: log
213+
force_no_trampoline: true
214+
attributes:
215+
kDataType:
216+
methods:
217+
StringArrayLogEntry:
218+
overloads:
219+
"":
220+
ignore: true
221+
wpi::log::DataLog&, std::string_view, int64_t:
222+
wpi::log::DataLog&, std::string_view, std::string_view, int64_t:
223+
Append:
224+
overloads:
225+
wpi::span<const std::string>, int64_t:
226+
ignore: true
227+
wpi::span<const std::string_view>, int64_t:
228+
std::initializer_list<std::string_view>, int64_t:
229+
ignore: true

0 commit comments

Comments
 (0)