[hal] Change usage reporting to string-based (#7763)

This commit is contained in:
Peter Johnson
2025-02-07 12:37:23 -08:00
committed by GitHub
parent bfff891b5c
commit 764ada9b66
188 changed files with 637 additions and 2298 deletions

View File

@@ -70,6 +70,7 @@ void InitializeHAL() {
InitializeSerialPort();
InitializeSmartIo();
InitializeThreads();
InitializeUsageReporting();
}
} // namespace init
@@ -343,16 +344,4 @@ void HAL_SimPeriodicBefore(void) {}
void HAL_SimPeriodicAfter(void) {}
int64_t HAL_Report(int32_t resource, int32_t instanceNumber, int32_t context,
const char* feature) {
if (feature == nullptr) {
feature = "";
}
return 0;
// return FRC_NetworkCommunication_nUsageReporting_report(
// resource, instanceNumber, context, feature);
}
} // extern "C"

View File

@@ -43,4 +43,5 @@ extern void InitializePWM();
extern void InitializeSerialPort();
extern void InitializeSmartIo();
extern void InitializeThreads();
extern void InitializeUsageReporting();
} // namespace hal::init

View File

@@ -0,0 +1,51 @@
// 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.
#include <stdint.h>
#include <fmt/format.h>
#include <networktables/NetworkTableInstance.h>
#include <networktables/StringTopic.h>
#include <wpi/StringMap.h>
#include <wpi/string.h>
#include "SystemServerInternal.h"
namespace {
struct SystemServerUsageReporting {
nt::NetworkTableInstance ntInst;
wpi::StringMap<nt::StringPublisher> publishers;
explicit SystemServerUsageReporting(nt::NetworkTableInstance inst)
: ntInst{inst} {}
};
} // namespace
static ::SystemServerUsageReporting* systemServerUsage;
extern "C" {
int32_t HAL_ReportUsage(const struct WPI_String* resource,
const struct WPI_String* data) {
auto resourceStr = wpi::to_string_view(resource);
auto& publisher = systemServerUsage->publishers[resourceStr];
if (!publisher) {
publisher =
systemServerUsage->ntInst
.GetStringTopic(fmt::format("/UsageReporting/{}", resourceStr))
.Publish();
}
publisher.Set(wpi::to_string_view(data));
return 0;
}
} // extern "C"
namespace hal::init {
void InitializeUsageReporting() {
systemServerUsage = new ::SystemServerUsageReporting{hal::GetSystemServer()};
}
} // namespace hal::init