Skip to content

Commit 764ada9

Browse files
authored
[hal] Change usage reporting to string-based (#7763)
1 parent bfff891 commit 764ada9

File tree

188 files changed

+637
-2298
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+637
-2298
lines changed

.github/actions/pregen/action.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ runs:
1818
wget https://github.com/HebiRobotics/QuickBuffers/releases/download/1.3.3/protoc-gen-quickbuf-1.3.3-linux-x86_64.exe
1919
chmod +x protoc-gen-quickbuf-1.3.3-linux-x86_64.exe
2020
shell: bash
21-
- name: Regenerate hal
22-
run: ./hal/generate_usage_reporting.py
23-
shell: bash
2421

2522
- name: Regenerate ntcore
2623
run: ./ntcore/generate_topics.py

cameraserver/src/main/java/edu/wpi/first/cameraserver/CameraServer.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,7 @@ private CameraServer() {}
540540
* @return The USB camera capturing images.
541541
*/
542542
public static UsbCamera startAutomaticCapture() {
543-
UsbCamera camera = startAutomaticCapture(m_defaultUsbDevice.getAndIncrement());
544-
CameraServerSharedStore.getCameraServerShared().reportUsbCamera(camera.getHandle());
545-
return camera;
543+
return startAutomaticCapture(m_defaultUsbDevice.getAndIncrement());
546544
}
547545

548546
/**
@@ -557,7 +555,7 @@ public static UsbCamera startAutomaticCapture() {
557555
public static UsbCamera startAutomaticCapture(int dev) {
558556
UsbCamera camera = new UsbCamera("USB Camera " + dev, dev);
559557
startAutomaticCapture(camera);
560-
CameraServerSharedStore.getCameraServerShared().reportUsbCamera(camera.getHandle());
558+
CameraServerSharedStore.reportUsage("UsbCamera[" + dev + "]", "auto");
561559
return camera;
562560
}
563561

@@ -571,7 +569,7 @@ public static UsbCamera startAutomaticCapture(int dev) {
571569
public static UsbCamera startAutomaticCapture(String name, int dev) {
572570
UsbCamera camera = new UsbCamera(name, dev);
573571
startAutomaticCapture(camera);
574-
CameraServerSharedStore.getCameraServerShared().reportUsbCamera(camera.getHandle());
572+
CameraServerSharedStore.reportUsage("UsbCamera[" + dev + "]", "name");
575573
return camera;
576574
}
577575

@@ -585,7 +583,7 @@ public static UsbCamera startAutomaticCapture(String name, int dev) {
585583
public static UsbCamera startAutomaticCapture(String name, String path) {
586584
UsbCamera camera = new UsbCamera(name, path);
587585
startAutomaticCapture(camera);
588-
CameraServerSharedStore.getCameraServerShared().reportUsbCamera(camera.getHandle());
586+
CameraServerSharedStore.reportUsage("UsbCamera[" + path + "]", "path");
589587
return camera;
590588
}
591589

cameraserver/src/main/java/edu/wpi/first/cameraserver/CameraServerShared.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,12 @@ public interface CameraServerShared {
2121
void reportDriverStationError(String error);
2222

2323
/**
24-
* Report an video server usage.
24+
* Report usage.
2525
*
26-
* @param id the usage id
26+
* @param resource the resource name
27+
* @param data arbitrary string data
2728
*/
28-
void reportVideoServer(int id);
29-
30-
/**
31-
* Report a usb camera usage.
32-
*
33-
* @param id the usage id
34-
*/
35-
void reportUsbCamera(int id);
36-
37-
/**
38-
* Report an axis camera usage.
39-
*
40-
* @param id the usage id
41-
*/
42-
void reportAxisCamera(int id);
29+
void reportUsage(String resource, String data);
4330

4431
/**
4532
* Get if running on a roboRIO.

cameraserver/src/main/java/edu/wpi/first/cameraserver/CameraServerSharedStore.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,11 @@ public static synchronized CameraServerShared getCameraServerShared() {
2020
cameraServerShared =
2121
new CameraServerShared() {
2222
@Override
23-
public void reportVideoServer(int id) {}
24-
25-
@Override
26-
public void reportUsbCamera(int id) {}
23+
public void reportUsage(String resource, String data) {}
2724

2825
@Override
2926
public void reportDriverStationError(String error) {}
3027

31-
@Override
32-
public void reportAxisCamera(int id) {}
33-
3428
@Override
3529
public Long getRobotMainThreadId() {
3630
return null;
@@ -40,6 +34,16 @@ public Long getRobotMainThreadId() {
4034
return cameraServerShared;
4135
}
4236

37+
/**
38+
* Report usage.
39+
*
40+
* @param resource the resource name
41+
* @param data arbitrary string data
42+
*/
43+
public static void reportUsage(String resource, String data) {
44+
getCameraServerShared().reportUsage(resource, data);
45+
}
46+
4347
/**
4448
* Set the CameraServerShared object.
4549
*

cameraserver/src/main/native/cpp/cameraserver/CameraServer.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -471,19 +471,15 @@ Instance::Instance() {
471471
}
472472

473473
cs::UsbCamera CameraServer::StartAutomaticCapture() {
474-
cs::UsbCamera camera =
475-
StartAutomaticCapture(::GetInstance().m_defaultUsbDevice++);
476-
auto csShared = GetCameraServerShared();
477-
csShared->ReportUsbCamera(camera.GetHandle());
478-
return camera;
474+
return StartAutomaticCapture(::GetInstance().m_defaultUsbDevice++);
479475
}
480476

481477
cs::UsbCamera CameraServer::StartAutomaticCapture(int dev) {
482478
::GetInstance();
483479
cs::UsbCamera camera{fmt::format("USB Camera {}", dev), dev};
484480
StartAutomaticCapture(camera);
485481
auto csShared = GetCameraServerShared();
486-
csShared->ReportUsbCamera(camera.GetHandle());
482+
csShared->ReportUsage(fmt::format("UsbCamera[{}]", dev), "auto");
487483
return camera;
488484
}
489485

@@ -493,7 +489,7 @@ cs::UsbCamera CameraServer::StartAutomaticCapture(std::string_view name,
493489
cs::UsbCamera camera{name, dev};
494490
StartAutomaticCapture(camera);
495491
auto csShared = GetCameraServerShared();
496-
csShared->ReportUsbCamera(camera.GetHandle());
492+
csShared->ReportUsage(fmt::format("UsbCamera[{}]", dev), "name");
497493
return camera;
498494
}
499495

@@ -503,7 +499,7 @@ cs::UsbCamera CameraServer::StartAutomaticCapture(std::string_view name,
503499
cs::UsbCamera camera{name, path};
504500
StartAutomaticCapture(camera);
505501
auto csShared = GetCameraServerShared();
506-
csShared->ReportUsbCamera(camera.GetHandle());
502+
csShared->ReportUsage(fmt::format("UsbCamera[{}]", path), "path");
507503
return camera;
508504
}
509505

cameraserver/src/main/native/cpp/cameraserver/CameraServerShared.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
namespace {
1313
class DefaultCameraServerShared : public frc::CameraServerShared {
1414
public:
15-
void ReportUsbCamera(int id) override {}
16-
void ReportAxisCamera(int id) override {}
17-
void ReportVideoServer(int id) override {}
15+
void ReportUsage(std::string_view resource, std::string_view data) override {}
1816
void SetCameraServerErrorV(fmt::string_view format,
1917
fmt::format_args args) override {}
2018
void SetVisionRunnerErrorV(fmt::string_view format,

cameraserver/src/main/native/include/cameraserver/CameraServerShared.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#pragma once
66

77
#include <memory>
8+
#include <string_view>
89
#include <thread>
910
#include <utility>
1011

@@ -14,9 +15,8 @@ namespace frc {
1415
class CameraServerShared {
1516
public:
1617
virtual ~CameraServerShared() = default;
17-
virtual void ReportUsbCamera(int id) = 0;
18-
virtual void ReportAxisCamera(int id) = 0;
19-
virtual void ReportVideoServer(int id) = 0;
18+
virtual void ReportUsage(std::string_view resource,
19+
std::string_view data) = 0;
2020
virtual void SetCameraServerErrorV(fmt::string_view format,
2121
fmt::format_args args) = 0;
2222
virtual void SetVisionRunnerErrorV(fmt::string_view format,

epilogue-processor/src/main/java/edu/wpi/first/epilogue/processor/EpilogueGenerator.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public void writeEpilogueFile(
5555
out.println("import static edu.wpi.first.units.Units.Seconds;");
5656
out.println();
5757

58-
out.println("import edu.wpi.first.hal.FRCNetComm;");
5958
out.println("import edu.wpi.first.hal.HAL;");
6059
out.println();
6160

@@ -89,10 +88,7 @@ public void writeEpilogueFile(
8988
out.println(
9089
"""
9190
static {
92-
HAL.report(
93-
FRCNetComm.tResourceType.kResourceType_LoggingFramework,
94-
FRCNetComm.tInstances.kLoggingFramework_Epilogue
95-
);
91+
HAL.reportUsage("Epilogue", "");
9692
}
9793
""");
9894

epilogue-processor/src/test/java/edu/wpi/first/epilogue/processor/EpilogueGeneratorTest.java

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,13 @@ class Example {
3333
3434
import static edu.wpi.first.units.Units.Seconds;
3535
36-
import edu.wpi.first.hal.FRCNetComm;
3736
import edu.wpi.first.hal.HAL;
3837
3938
import edu.wpi.first.epilogue.ExampleLogger;
4039
4140
public final class Epilogue {
4241
static {
43-
HAL.report(
44-
FRCNetComm.tResourceType.kResourceType_LoggingFramework,
45-
FRCNetComm.tInstances.kLoggingFramework_Epilogue
46-
);
42+
HAL.reportUsage("Epilogue", "");
4743
}
4844
4945
private static final EpilogueConfiguration config = new EpilogueConfiguration();
@@ -92,17 +88,13 @@ public void endCompetition() {}
9288
9389
import static edu.wpi.first.units.Units.Seconds;
9490
95-
import edu.wpi.first.hal.FRCNetComm;
9691
import edu.wpi.first.hal.HAL;
9792
9893
import edu.wpi.first.epilogue.ExampleLogger;
9994
10095
public final class Epilogue {
10196
static {
102-
HAL.report(
103-
FRCNetComm.tResourceType.kResourceType_LoggingFramework,
104-
FRCNetComm.tInstances.kLoggingFramework_Epilogue
105-
);
97+
HAL.reportUsage("Epilogue", "");
10698
}
10799
108100
private static final EpilogueConfiguration config = new EpilogueConfiguration();
@@ -146,17 +138,13 @@ class Example extends edu.wpi.first.wpilibj.TimedRobot {
146138
147139
import static edu.wpi.first.units.Units.Seconds;
148140
149-
import edu.wpi.first.hal.FRCNetComm;
150141
import edu.wpi.first.hal.HAL;
151142
152143
import edu.wpi.first.epilogue.ExampleLogger;
153144
154145
public final class Epilogue {
155146
static {
156-
HAL.report(
157-
FRCNetComm.tResourceType.kResourceType_LoggingFramework,
158-
FRCNetComm.tInstances.kLoggingFramework_Epilogue
159-
);
147+
HAL.reportUsage("Epilogue", "");
160148
}
161149
162150
private static final EpilogueConfiguration config = new EpilogueConfiguration();
@@ -234,18 +222,14 @@ class BetaBot extends edu.wpi.first.wpilibj.TimedRobot { }
234222
235223
import static edu.wpi.first.units.Units.Seconds;
236224
237-
import edu.wpi.first.hal.FRCNetComm;
238225
import edu.wpi.first.hal.HAL;
239226
240227
import edu.wpi.first.epilogue.AlphaBotLogger;
241228
import edu.wpi.first.epilogue.BetaBotLogger;
242229
243230
public final class Epilogue {
244231
static {
245-
HAL.report(
246-
FRCNetComm.tResourceType.kResourceType_LoggingFramework,
247-
FRCNetComm.tInstances.kLoggingFramework_Epilogue
248-
);
232+
HAL.reportUsage("Epilogue", "");
249233
}
250234
251235
private static final EpilogueConfiguration config = new EpilogueConfiguration();
@@ -371,18 +355,14 @@ class Example {
371355
372356
import static edu.wpi.first.units.Units.Seconds;
373357
374-
import edu.wpi.first.hal.FRCNetComm;
375358
import edu.wpi.first.hal.HAL;
376359
377360
import edu.wpi.first.epilogue.ExampleLogger;
378361
import edu.wpi.first.epilogue.CustomLogger;
379362
380363
public final class Epilogue {
381364
static {
382-
HAL.report(
383-
FRCNetComm.tResourceType.kResourceType_LoggingFramework,
384-
FRCNetComm.tInstances.kLoggingFramework_Epilogue
385-
);
365+
HAL.reportUsage("Epilogue", "");
386366
}
387367
388368
private static final EpilogueConfiguration config = new EpilogueConfiguration();

hal/BUILD.bazel

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@ load("@rules_java//java:defs.bzl", "java_binary")
33
load("//shared/bazel/rules:java_rules.bzl", "wpilib_java_junit5_test")
44
load("//shared/bazel/rules:jni_rules.bzl", "wpilib_jni_cc_library", "wpilib_jni_java_library")
55

6-
cc_library(
7-
name = "generated_cc_headers",
8-
hdrs = glob(["src/generated/main/native/include/**"]),
9-
includes = ["src/generated/main/native/include"],
10-
strip_include_prefix = "src/generated/main/native/include",
11-
visibility = ["//hal:__subpackages__"],
12-
)
13-
146
cc_library(
157
name = "mrc_cc_headers",
168
hdrs = glob(["src/mrc/include/**"]),
@@ -27,12 +19,6 @@ cc_library(
2719
visibility = ["//hal:__subpackages__"],
2820
)
2921

30-
filegroup(
31-
name = "generated_java",
32-
srcs = glob(["src/generated/main/java/**/*.java"]),
33-
visibility = ["//hal:__subpackages__"],
34-
)
35-
3622
SYSTEMCORE_SRCS = glob(["src/main/native/systemcore/**"])
3723

3824
SIM_SRCS = glob(["src/main/native/sim/**"])
@@ -59,7 +45,6 @@ cc_library(
5945
strip_include_prefix = "src/main/native/include",
6046
visibility = ["//visibility:public"],
6147
deps = [
62-
":generated_cc_headers",
6348
":generated_mrc_cc_headers",
6449
":mrc_cc_headers",
6550
"//ntcore:ntcore.static",
@@ -80,7 +65,7 @@ wpilib_jni_cc_library(
8065

8166
wpilib_jni_java_library(
8267
name = "hal-java",
83-
srcs = [":generated_java"] + glob(["src/main/java/**/*.java"]),
68+
srcs = glob(["src/main/java/**/*.java"]),
8469
native_libs = [":wpiHaljni"],
8570
visibility = ["//visibility:public"],
8671
deps = [

hal/CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ target_include_directories(
1919
hal
2020
PUBLIC
2121
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/include>
22-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/generated/main/native/include>
2322
$<INSTALL_INTERFACE:${include_dest}/hal>
2423
)
2524
target_link_libraries(hal PUBLIC ntcore wpiutil)
@@ -29,7 +28,6 @@ set_property(TARGET hal PROPERTY FOLDER "libraries")
2928
install(TARGETS hal EXPORT hal)
3029
export(TARGETS hal FILE hal.cmake NAMESPACE hal::)
3130
install(DIRECTORY src/main/native/include/ DESTINATION "${include_dest}/hal")
32-
install(DIRECTORY src/generated/main/native/include/ DESTINATION "${include_dest}/hal")
3331

3432
configure_file(hal-config.cmake.in ${WPILIB_BINARY_DIR}/hal-config.cmake)
3533
install(FILES ${WPILIB_BINARY_DIR}/hal-config.cmake DESTINATION share/hal)
@@ -41,7 +39,7 @@ if(WITH_JAVA)
4139

4240
file(GLOB_RECURSE hal_shared_jni_src src/main/native/cpp/jni/*.cpp)
4341

44-
file(GLOB_RECURSE JAVA_SOURCES src/main/java/*.java src/generated/main/java/*.java)
42+
file(GLOB_RECURSE JAVA_SOURCES src/main/java/*.java)
4543
set(CMAKE_JNI_TARGET true)
4644

4745
add_jar(
@@ -77,9 +75,7 @@ if(WITH_JAVA_SOURCE)
7775
include(CreateSourceJar)
7876
add_source_jar(
7977
hal_src_jar
80-
BASE_DIRECTORIES
81-
${CMAKE_CURRENT_SOURCE_DIR}/src/main/java
82-
${CMAKE_CURRENT_SOURCE_DIR}/src/generated/main/java
78+
BASE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/src/main/java
8379
OUTPUT_NAME wpiHal-sources
8480
OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest}
8581
)

0 commit comments

Comments
 (0)