Skip to content

Commit 71d96d4

Browse files
committed
struct logging, a lot of refactors, more progress to a stable 1.0.
1 parent e0ded7b commit 71d96d4

23 files changed

Lines changed: 975 additions & 206 deletions

TelemetryKit.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"fileName": "TelemetryKit.json",
33
"name": "TelemetryKit",
44
"version": "1.0.0",
5-
"frcYear": "2026beta",
5+
"frcYear": "2026",
66
"uuid": "bf2eaa28-c978-45c9-8b1e-206f7620bd79",
77
"mavenUrls": [],
88
"jsonUrl": "",

publish.gradle

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ model {
196196
groupId = artifactGroupId
197197
version = pubVersion
198198
}
199-
199+
200200

201201

202202
java(MavenPublication) {
@@ -219,3 +219,33 @@ model {
219219
}
220220
}
221221
}
222+
223+
// Task to copy published artifacts to WPILib local maven repository
224+
task copyToWpilibLocal(type: Copy) {
225+
description = 'Copies published artifacts to wpilib/{year}/maven for local testing'
226+
group = 'Publishing'
227+
228+
dependsOn publish
229+
230+
// Read FRC year from vendordep JSON during configuration
231+
def vendorJson = new groovy.json.JsonSlurper().parseText(file(templateVendorFile).text)
232+
def frcYear = vendorJson.frcYear
233+
def wpilibMavenPath
234+
235+
// WPILib location differs by OS:
236+
// Windows: C:\Users\Public\wpilib\{year}\maven
237+
// Unix/Mac: ~/wpilib/{year}/maven
238+
if (System.properties['os.name'].toLowerCase().contains('windows')) {
239+
wpilibMavenPath = file("C:\\Users\\Public\\wpilib\\${frcYear}\\maven")
240+
} else {
241+
wpilibMavenPath = file("${System.properties['user.home']}/wpilib/${frcYear}/maven")
242+
}
243+
244+
from releasesRepoUrl
245+
into wpilibMavenPath
246+
247+
doLast {
248+
println "Published ${baseArtifactId} to WPILib local maven: ${wpilibMavenPath}"
249+
println "Artifacts are now available for local robot projects to use."
250+
}
251+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "telemetrykit/LogTable.h"
1+
#include "telemetrykit/core/LogTable.h"
22

33
#include <mutex>
44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "telemetrykit/LogValue.h"
1+
#include "telemetrykit/core/LogValue.h"
22

33
namespace telemetrykit {
44

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#include "telemetrykit/Logger.h"
1+
#include "telemetrykit/core/Logger.h"
22

33
#include <frc/RobotController.h>
44

5-
#include "telemetrykit/LogDataReceiver.h"
6-
#include "telemetrykit/LoggableInputs.h"
5+
#include "telemetrykit/receiver/LogDataReceiver.h"
6+
#include "telemetrykit/core/LoggableInputs.h"
77

88
namespace telemetrykit {
99

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
#include "telemetrykit/receiver/ConsoleReceiver.h"
2+
3+
#include <iomanip>
4+
#include <sstream>
5+
6+
#include "telemetrykit/core/LogTable.h"
7+
8+
namespace telemetrykit {
9+
10+
ConsoleReceiver::ConsoleReceiver(std::string_view prefix, bool printOnlyChanges)
11+
: m_prefix(prefix), m_printOnlyChanges(printOnlyChanges), m_output(std::cout) {}
12+
13+
void ConsoleReceiver::OnStart() {
14+
m_lastValues.clear();
15+
m_output << m_prefix << " Logging started" << std::endl;
16+
}
17+
18+
void ConsoleReceiver::OnUpdate(const LogTable& table, int64_t timestamp) {
19+
// Get all entries from the table
20+
auto entries = table.GetAllEntries();
21+
22+
// Process each entry
23+
for (const auto& [key, value] : entries) {
24+
// Check if value has changed
25+
bool hasChanged = true;
26+
auto lastIt = m_lastValues.find(key);
27+
if (lastIt != m_lastValues.end()) {
28+
hasChanged = (lastIt->second != value);
29+
}
30+
31+
// Skip if unchanged and we only want changes
32+
if (m_printOnlyChanges && !hasChanged) {
33+
continue;
34+
}
35+
36+
// Print the value
37+
m_output << m_prefix << " "
38+
<< std::setw(40) << std::left << key << " = "
39+
<< FormatValue(value);
40+
41+
// Add timestamp if changed
42+
if (hasChanged) {
43+
m_output << " (t=" << timestamp << ")";
44+
}
45+
46+
m_output << std::endl;
47+
48+
// Update last value
49+
m_lastValues[key] = value;
50+
}
51+
}
52+
53+
void ConsoleReceiver::OnEnd() {
54+
m_output << m_prefix << " Logging ended" << std::endl;
55+
m_lastValues.clear();
56+
}
57+
58+
std::string ConsoleReceiver::FormatValue(const LogValue& value) const {
59+
std::stringstream ss;
60+
61+
switch (value.GetType()) {
62+
case LogType::kBoolean:
63+
ss << (value.Get<bool>() ? "true" : "false");
64+
break;
65+
66+
case LogType::kInt64:
67+
ss << value.Get<int64_t>();
68+
break;
69+
70+
case LogType::kFloat:
71+
ss << std::fixed << std::setprecision(3) << value.Get<float>();
72+
break;
73+
74+
case LogType::kDouble:
75+
ss << std::fixed << std::setprecision(3) << value.Get<double>();
76+
break;
77+
78+
case LogType::kString:
79+
ss << "\"" << value.Get<std::string>() << "\"";
80+
break;
81+
82+
case LogType::kBooleanArray: {
83+
const auto& arr = value.Get<std::vector<bool>>();
84+
ss << "[";
85+
for (size_t i = 0; i < arr.size(); ++i) {
86+
if (i > 0) ss << ", ";
87+
ss << (arr[i] ? "true" : "false");
88+
if (i >= 9 && arr.size() > 10) {
89+
ss << ", ... (" << arr.size() << " total)";
90+
break;
91+
}
92+
}
93+
ss << "]";
94+
break;
95+
}
96+
97+
case LogType::kInt64Array: {
98+
const auto& arr = value.Get<std::vector<int64_t>>();
99+
ss << "[";
100+
for (size_t i = 0; i < arr.size(); ++i) {
101+
if (i > 0) ss << ", ";
102+
ss << arr[i];
103+
if (i >= 9 && arr.size() > 10) {
104+
ss << ", ... (" << arr.size() << " total)";
105+
break;
106+
}
107+
}
108+
ss << "]";
109+
break;
110+
}
111+
112+
case LogType::kFloatArray: {
113+
const auto& arr = value.Get<std::vector<float>>();
114+
ss << "[";
115+
for (size_t i = 0; i < arr.size(); ++i) {
116+
if (i > 0) ss << ", ";
117+
ss << std::fixed << std::setprecision(3) << arr[i];
118+
if (i >= 9 && arr.size() > 10) {
119+
ss << ", ... (" << arr.size() << " total)";
120+
break;
121+
}
122+
}
123+
ss << "]";
124+
break;
125+
}
126+
127+
case LogType::kDoubleArray: {
128+
const auto& arr = value.Get<std::vector<double>>();
129+
ss << "[";
130+
for (size_t i = 0; i < arr.size(); ++i) {
131+
if (i > 0) ss << ", ";
132+
ss << std::fixed << std::setprecision(3) << arr[i];
133+
if (i >= 9 && arr.size() > 10) {
134+
ss << ", ... (" << arr.size() << " total)";
135+
break;
136+
}
137+
}
138+
ss << "]";
139+
break;
140+
}
141+
142+
case LogType::kStringArray: {
143+
const auto& arr = value.Get<std::vector<std::string>>();
144+
ss << "[";
145+
for (size_t i = 0; i < arr.size(); ++i) {
146+
if (i > 0) ss << ", ";
147+
ss << "\"" << arr[i] << "\"";
148+
if (i >= 4 && arr.size() > 5) {
149+
ss << ", ... (" << arr.size() << " total)";
150+
break;
151+
}
152+
}
153+
ss << "]";
154+
break;
155+
}
156+
157+
case LogType::kRaw: {
158+
const auto& data = value.Get<std::vector<uint8_t>>();
159+
ss << "<raw: " << data.size() << " bytes>";
160+
break;
161+
}
162+
163+
case LogType::kStruct: {
164+
const auto& data = value.Get<std::vector<uint8_t>>();
165+
ss << "<struct " << value.GetTypeString() << ": " << data.size() << " bytes>";
166+
break;
167+
}
168+
169+
case LogType::kStructArray: {
170+
const auto& data = value.Get<std::vector<uint8_t>>();
171+
ss << "<struct[] " << value.GetTypeString() << ": " << data.size() << " bytes>";
172+
break;
173+
}
174+
}
175+
176+
return ss.str();
177+
}
178+
179+
} // namespace telemetrykit

0 commit comments

Comments
 (0)