mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
[hal] Change usage reporting to string-based (#7763)
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -43,4 +43,5 @@ extern void InitializePWM();
|
||||
extern void InitializeSerialPort();
|
||||
extern void InitializeSmartIo();
|
||||
extern void InitializeThreads();
|
||||
extern void InitializeUsageReporting();
|
||||
} // namespace hal::init
|
||||
|
||||
51
hal/src/main/native/systemcore/UsageReporting.cpp
Normal file
51
hal/src/main/native/systemcore/UsageReporting.cpp
Normal 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
|
||||
Reference in New Issue
Block a user