[wpilibc] DriverStation: Remove ReportError and ReportWarning

Change use cases to directly call FRC_ReportError.
This commit is contained in:
Peter Johnson
2021-05-24 23:36:26 -07:00
parent 831c10bdfc
commit a04d1b4f97
26 changed files with 169 additions and 146 deletions

View File

@@ -12,6 +12,7 @@ repoRootNameOverride {
}
includeOtherLibs {
^fmt/
^hal/
^networktables/
^opencv2/

View File

@@ -625,8 +625,8 @@ cs::CvSink CameraServer::GetVideo(const cs::VideoSource& camera) {
auto kind = it->second.GetKind();
if (kind != cs::VideoSink::kCv) {
auto csShared = GetCameraServerShared();
csShared->SetCameraServerError("expected OpenCV sink, but got " +
wpi::Twine(kind));
csShared->SetCameraServerError("expected OpenCV sink, but got {}",
kind);
return cs::CvSink{};
}
return *static_cast<cs::CvSink*>(&it->second);
@@ -648,7 +648,7 @@ cs::CvSink CameraServer::GetVideo(const wpi::Twine& name) {
auto it = m_impl->m_sources.find(nameStr);
if (it == m_impl->m_sources.end()) {
auto csShared = GetCameraServerShared();
csShared->SetCameraServerError("could not find camera " + nameStr);
csShared->SetCameraServerError("could not find camera {}", nameStr);
return cs::CvSink{};
}
source = it->second;
@@ -711,7 +711,7 @@ cs::VideoSink CameraServer::GetServer(const wpi::Twine& name) {
auto it = m_impl->m_sinks.find(nameStr);
if (it == m_impl->m_sinks.end()) {
auto csShared = GetCameraServerShared();
csShared->SetCameraServerError("could not find server " + nameStr);
csShared->SetCameraServerError("could not find server {}", nameStr);
return cs::VideoSink{};
}
return it->second;

View File

@@ -12,9 +12,12 @@ class DefaultCameraServerShared : public frc::CameraServerShared {
void ReportUsbCamera(int id) override {}
void ReportAxisCamera(int id) override {}
void ReportVideoServer(int id) override {}
void SetCameraServerError(const wpi::Twine& error) override {}
void SetVisionRunnerError(const wpi::Twine& error) override {}
void ReportDriverStationError(const wpi::Twine& error) override {}
void SetCameraServerErrorV(fmt::string_view format,
fmt::format_args args) override {}
void SetVisionRunnerErrorV(fmt::string_view format,
fmt::format_args args) override {}
void ReportDriverStationErrorV(fmt::string_view format,
fmt::format_args args) override {}
std::pair<std::thread::id, bool> GetRobotMainThreadId() const override {
return std::make_pair(std::thread::id(), false);
}

View File

@@ -33,7 +33,7 @@ void VisionRunnerBase::RunOnce() {
auto frameTime = m_cvSink.GrabFrame(*m_image);
if (frameTime == 0) {
auto error = m_cvSink.GetError();
csShared->ReportDriverStationError(error);
csShared->ReportDriverStationError(error.c_str());
} else {
DoProcess(*m_image);
}

View File

@@ -8,7 +8,7 @@
#include <thread>
#include <utility>
#include <wpi/Twine.h>
#include <fmt/format.h>
namespace frc {
class CameraServerShared {
@@ -17,10 +17,31 @@ class CameraServerShared {
virtual void ReportUsbCamera(int id) = 0;
virtual void ReportAxisCamera(int id) = 0;
virtual void ReportVideoServer(int id) = 0;
virtual void SetCameraServerError(const wpi::Twine& error) = 0;
virtual void SetVisionRunnerError(const wpi::Twine& error) = 0;
virtual void ReportDriverStationError(const wpi::Twine& error) = 0;
virtual void SetCameraServerErrorV(fmt::string_view format,
fmt::format_args args) = 0;
virtual void SetVisionRunnerErrorV(fmt::string_view format,
fmt::format_args args) = 0;
virtual void ReportDriverStationErrorV(fmt::string_view format,
fmt::format_args args) = 0;
virtual std::pair<std::thread::id, bool> GetRobotMainThreadId() const = 0;
template <typename S, typename... Args>
inline void SetCameraServerError(const S& format, Args&&... args) {
SetCameraServerErrorV(format,
fmt::make_args_checked<Args...>(format, args...));
}
template <typename S, typename... Args>
inline void SetVisionRunnerError(const S& format, Args&&... args) {
SetVisionRunnerErrorV(format,
fmt::make_args_checked<Args...>(format, args...));
}
template <typename S, typename... Args>
inline void ReportDriverStationError(const S& format, Args&&... args) {
ReportDriverStationErrorV(format,
fmt::make_args_checked<Args...>(format, args...));
}
};
CameraServerShared* GetCameraServerShared();

View File

@@ -6,7 +6,7 @@
#include <hal/FRCUsageReporting.h>
#include "frc/DriverStation.h"
#include "frc/Errors.h"
#include "frc/smartdashboard/SendableBuilder.h"
#include "frc/smartdashboard/SendableRegistry.h"
@@ -56,7 +56,7 @@ ADXL362::ADXL362(SPI::Port port, Range range)
commands[2] = 0;
m_spi.Transaction(commands, commands, 3);
if (commands[2] != 0xF2) {
DriverStation::ReportError("could not find ADXL362");
FRC_ReportError(err::Error, "{}", "could not find ADXL362");
m_gsPerLSB = 0.0;
return;
}

View File

@@ -6,7 +6,7 @@
#include <hal/FRCUsageReporting.h>
#include "frc/DriverStation.h"
#include "frc/Errors.h"
#include "frc/Timer.h"
#include "frc/smartdashboard/SendableBuilder.h"
#include "frc/smartdashboard/SendableRegistry.h"
@@ -46,7 +46,7 @@ ADXRS450_Gyro::ADXRS450_Gyro(SPI::Port port)
if (!m_simDevice) {
// Validate the part ID
if ((ReadRegister(kPIDRegister) & 0xff00) != 0x5200) {
DriverStation::ReportError("could not find ADXRS450 gyro");
FRC_ReportError(err::Error, "{}", "could not find ADXRS450 gyro");
return;
}

View File

@@ -7,7 +7,7 @@
#include "frc/AnalogInput.h"
#include "frc/Base.h"
#include "frc/Counter.h"
#include "frc/DriverStation.h"
#include "frc/Errors.h"
#include "frc/smartdashboard/SendableBuilder.h"
using namespace frc;
@@ -72,7 +72,8 @@ units::turn_t AnalogEncoder::Get() const {
}
}
frc::DriverStation::GetInstance().ReportWarning(
FRC_ReportError(
warn::Warning, "{}",
"Failed to read Analog Encoder. Potential Speed Overrun. Returning last "
"value");
return m_lastPosition;

View File

@@ -14,8 +14,6 @@
#include <networktables/NetworkTable.h>
#include <networktables/NetworkTableEntry.h>
#include <networktables/NetworkTableInstance.h>
#include <wpi/SmallString.h>
#include <wpi/StringRef.h>
#include "frc/Errors.h"
#include "frc/MotorSafety.h"
@@ -113,31 +111,6 @@ DriverStation& DriverStation::GetInstance() {
return instance;
}
void DriverStation::ReportError(const wpi::Twine& error) {
wpi::SmallString<128> temp;
HAL_SendError(1, 1, 0, error.toNullTerminatedStringRef(temp).data(), "", "",
1);
}
void DriverStation::ReportWarning(const wpi::Twine& error) {
wpi::SmallString<128> temp;
HAL_SendError(0, 1, 0, error.toNullTerminatedStringRef(temp).data(), "", "",
1);
}
void DriverStation::ReportError(bool isError, int32_t code,
const wpi::Twine& error,
const wpi::Twine& location,
const wpi::Twine& stack) {
wpi::SmallString<128> errorTemp;
wpi::SmallString<128> locationTemp;
wpi::SmallString<128> stackTemp;
HAL_SendError(isError, code, 0,
error.toNullTerminatedStringRef(errorTemp).data(),
location.toNullTerminatedStringRef(locationTemp).data(),
stack.toNullTerminatedStringRef(stackTemp).data(), 1);
}
bool DriverStation::GetStickButton(int stick, int button) {
if (stick < 0 || stick >= kJoystickPorts) {
FRC_ReportError(warn::BadJoystickIndex, "stick {} out of range", stick);
@@ -145,7 +118,7 @@ bool DriverStation::GetStickButton(int stick, int button) {
}
if (button <= 0) {
ReportJoystickUnpluggedError(
"ERROR: Button indexes begin at 1 in WPILib for C++ and Java");
"Joystick Button {} index out of range; indexes begin at 1", button);
return false;
}
@@ -154,7 +127,9 @@ bool DriverStation::GetStickButton(int stick, int button) {
if (button > buttons.count) {
ReportJoystickUnpluggedWarning(
"Joystick Button missing, check if all controllers are plugged in");
"Joystick Button {} missing (max {}), check if all controllers are "
"plugged in",
button, buttons.count);
return false;
}
@@ -168,7 +143,7 @@ bool DriverStation::GetStickButtonPressed(int stick, int button) {
}
if (button <= 0) {
ReportJoystickUnpluggedError(
"ERROR: Button indexes begin at 1 in WPILib for C++ and Java");
"Joystick Button {} index out of range; indexes begin at 1", button);
return false;
}
@@ -177,7 +152,9 @@ bool DriverStation::GetStickButtonPressed(int stick, int button) {
if (button > buttons.count) {
ReportJoystickUnpluggedWarning(
"Joystick Button missing, check if all controllers are plugged in");
"Joystick Button {} missing (max {}), check if all controllers are "
"plugged in",
button, buttons.count);
return false;
}
std::unique_lock lock(m_buttonEdgeMutex);
@@ -197,7 +174,7 @@ bool DriverStation::GetStickButtonReleased(int stick, int button) {
}
if (button <= 0) {
ReportJoystickUnpluggedError(
"ERROR: Button indexes begin at 1 in WPILib for C++ and Java");
"Joystick Button {} index out of range; indexes begin at 1", button);
return false;
}
@@ -206,7 +183,9 @@ bool DriverStation::GetStickButtonReleased(int stick, int button) {
if (button > buttons.count) {
ReportJoystickUnpluggedWarning(
"Joystick Button missing, check if all controllers are plugged in");
"Joystick Button {} missing (max {}), check if all controllers are "
"plugged in",
button, buttons.count);
return false;
}
std::unique_lock lock(m_buttonEdgeMutex);
@@ -234,7 +213,9 @@ double DriverStation::GetStickAxis(int stick, int axis) {
if (axis >= axes.count) {
ReportJoystickUnpluggedWarning(
"Joystick Axis missing, check if all controllers are plugged in");
"Joystick Axis {} missing (max {}), check if all controllers are "
"plugged in",
axis, axes.count);
return 0.0;
}
@@ -256,7 +237,9 @@ int DriverStation::GetStickPOV(int stick, int pov) {
if (pov >= povs.count) {
ReportJoystickUnpluggedWarning(
"Joystick POV missing, check if all controllers are plugged in");
"Joystick POV {} missing (max {}), check if all controllers are "
"plugged in",
pov, povs.count);
return -1;
}
@@ -600,19 +583,21 @@ DriverStation::DriverStation() {
m_dsThread = std::thread(&DriverStation::Run, this);
}
void DriverStation::ReportJoystickUnpluggedError(const wpi::Twine& message) {
void DriverStation::ReportJoystickUnpluggedErrorV(fmt::string_view format,
fmt::format_args args) {
double currentTime = Timer::GetFPGATimestamp();
if (currentTime > m_nextMessageTime) {
ReportError(message);
ReportErrorV(err::Error, "", 0, "", format, args);
m_nextMessageTime = currentTime + kJoystickUnpluggedMessageInterval;
}
}
void DriverStation::ReportJoystickUnpluggedWarning(const wpi::Twine& message) {
void DriverStation::ReportJoystickUnpluggedWarningV(fmt::string_view format,
fmt::format_args args) {
if (IsFMSAttached() || !m_silenceJoystickWarning) {
double currentTime = Timer::GetFPGATimestamp();
if (currentTime > m_nextMessageTime) {
ReportWarning(message);
ReportErrorV(warn::Warning, "", 0, "", format, args);
m_nextMessageTime = currentTime + kJoystickUnpluggedMessageInterval;
}
}

View File

@@ -8,8 +8,8 @@
#include "frc/Counter.h"
#include "frc/DigitalInput.h"
#include "frc/DigitalSource.h"
#include "frc/DriverStation.h"
#include "frc/DutyCycle.h"
#include "frc/Errors.h"
#include "frc/smartdashboard/SendableBuilder.h"
using namespace frc;
@@ -94,7 +94,8 @@ units::turn_t DutyCycleEncoder::Get() const {
}
}
frc::DriverStation::GetInstance().ReportWarning(
FRC_ReportError(
warn::Warning, "{}",
"Failed to read DutyCycle Encoder. Potential Speed Overrun. Returning "
"last value");
return m_lastPosition;

View File

@@ -35,13 +35,15 @@ void RuntimeError::Report() const {
}
const char* frc::GetErrorMessage(int32_t* code) {
using namespace err;
using namespace warn;
switch (*code) {
#define S(label, offset, message) \
case label: \
case err::label: \
return message;
#include "frc/WPIErrors.mac"
#undef S
#define S(label, offset, message) \
case warn::label: \
return message;
#include "frc/WPIWarnings.mac"
#undef S
default:

View File

@@ -6,11 +6,9 @@
#include <hal/DriverStation.h>
#include <networktables/NetworkTableInstance.h>
#include <wpi/Format.h>
#include <wpi/SmallString.h>
#include <wpi/raw_ostream.h>
#include "frc/DriverStation.h"
#include "frc/Errors.h"
#include "frc/livewindow/LiveWindow.h"
#include "frc/shuffleboard/Shuffleboard.h"
#include "frc/smartdashboard/SmartDashboard.h"
@@ -197,11 +195,6 @@ void IterativeRobotBase::LoopFunc() {
}
void IterativeRobotBase::PrintLoopOverrunMessage() {
wpi::SmallString<128> str;
wpi::raw_svector_ostream buf(str);
buf << "Loop time of " << wpi::format("%.6f", m_period.to<double>())
<< "s overrun\n";
DriverStation::ReportWarning(str);
FRC_ReportError(err::Error, "Loop time of {:.6f}s overrun",
m_period.to<double>());
}

View File

@@ -8,7 +8,7 @@
#include <wpi/SmallString.h>
#include <wpi/raw_ostream.h>
#include "frc/DriverStation.h"
#include "frc/Errors.h"
using namespace frc;
@@ -36,7 +36,7 @@ void Tracer::PrintEpochs() {
wpi::raw_svector_ostream os(buf);
PrintEpochs(os);
if (!buf.empty()) {
DriverStation::ReportWarning(buf);
FRC_ReportError(warn::Warning, "{}", buf.c_str());
}
}

View File

@@ -5,15 +5,14 @@
#include "frc/Watchdog.h"
#include <atomic>
#include <thread>
#include <utility>
#include <fmt/format.h>
#include <hal/Notifier.h>
#include <wpi/Format.h>
#include <wpi/SmallString.h>
#include <wpi/mutex.h>
#include <wpi/priority_queue.h>
#include <wpi/raw_ostream.h>
#include "frc/DriverStation.h"
#include "frc/Errors.h"
#include "frc2/Timer.h"
@@ -114,11 +113,8 @@ void Watchdog::Impl::Main() {
if (now - watchdog->m_lastTimeoutPrintTime > kMinPrintPeriod) {
watchdog->m_lastTimeoutPrintTime = now;
if (!watchdog->m_suppressTimeoutMessage) {
wpi::SmallString<128> buf;
wpi::raw_svector_ostream err(buf);
err << "Watchdog not fed within "
<< wpi::format("%.6f", watchdog->m_timeout.to<double>()) << "s\n";
frc::DriverStation::ReportWarning(err.str());
FRC_ReportError(warn::Warning, "Watchdog not fed within {:.6f}s",
watchdog->m_timeout.to<double>());
}
}

View File

@@ -9,7 +9,7 @@
#include <hal/FRCUsageReporting.h>
#include "frc/DriverStation.h"
#include "frc/Errors.h"
#include "frc/MathUtil.h"
#include "frc/smartdashboard/SendableBuilder.h"
#include "frc/smartdashboard/SendableRegistry.h"
@@ -20,10 +20,13 @@ PIDController::PIDController(double Kp, double Ki, double Kd,
units::second_t period)
: m_Kp(Kp), m_Ki(Ki), m_Kd(Kd), m_period(period) {
if (period <= 0_s) {
frc::DriverStation::ReportError(
"Controller period must be a non-zero positive number!");
FRC_ReportError(
frc::err::Error,
"Controller period must be a non-zero positive number, got {}!",
period.to<double>());
m_period = 20_ms;
frc::DriverStation::ReportWarning("Controller period defaulted to 20ms.");
FRC_ReportError(frc::warn::Warning, "{}",
"Controller period defaulted to 20ms.");
}
static int instances = 0;
instances++;

View File

@@ -4,7 +4,7 @@
#include "frc/shuffleboard/RecordingController.h"
#include "frc/DriverStation.h"
#include "frc/Errors.h"
using namespace frc;
using namespace frc::detail;
@@ -38,7 +38,8 @@ void RecordingController::AddEventMarker(
wpi::StringRef name, wpi::StringRef description,
ShuffleboardEventImportance importance) {
if (name.empty()) {
DriverStation::ReportError("Shuffleboard event name was not specified");
FRC_ReportError(err::Error, "{}",
"Shuffleboard event name was not specified");
return;
}
m_eventsTable->GetSubTable(name)->GetEntry("Info").SetStringArray(

View File

@@ -8,6 +8,8 @@
#include <utility>
#include <wpi/MathExtras.h>
#include "frc/RobotController.h"
#include "frc/system/NumericalIntegration.h"

View File

@@ -11,10 +11,10 @@
#include <cstdio>
#include <cameraserver/CameraServerShared.h>
#include <fmt/format.h>
#include <hal/FRCUsageReporting.h>
#include <hal/HALBase.h>
#include <networktables/NetworkTableInstance.h>
#include <wpi/SmallString.h>
#include <wpimath/MathShared.h>
#include "WPILibVersion.h"
@@ -53,16 +53,18 @@ class WPILibCameraServerShared : public frc::CameraServerShared {
void ReportVideoServer(int id) override {
HAL_Report(HALUsageReporting::kResourceType_PCVideoServer, id);
}
void SetCameraServerError(const wpi::Twine& error) override {
wpi::SmallString<128> buf;
FRC_ReportError(err::CameraServerError, "{}", error.toStringRef(buf));
void SetCameraServerErrorV(fmt::string_view format,
fmt::format_args args) override {
ReportErrorV(err::CameraServerError, __FILE__, __LINE__, __FUNCTION__,
format, args);
}
void SetVisionRunnerError(const wpi::Twine& error) override {
wpi::SmallString<128> buf;
FRC_ReportError(-1, "{}", error.toStringRef(buf));
void SetVisionRunnerErrorV(fmt::string_view format,
fmt::format_args args) override {
ReportErrorV(err::Error, __FILE__, __LINE__, __FUNCTION__, format, args);
}
void ReportDriverStationError(const wpi::Twine& error) override {
DriverStation::ReportError(error);
void ReportDriverStationErrorV(fmt::string_view format,
fmt::format_args args) override {
ReportErrorV(err::Error, __FILE__, __LINE__, __FUNCTION__, format, args);
}
std::pair<std::thread::id, bool> GetRobotMainThreadId() const override {
return std::make_pair(RobotBase::GetThreadId(), true);
@@ -70,8 +72,9 @@ class WPILibCameraServerShared : public frc::CameraServerShared {
};
class WPILibMathShared : public wpi::math::MathShared {
public:
void ReportError(const wpi::Twine& error) override {
DriverStation::ReportError(error);
void ReportErrorV(fmt::string_view format, fmt::format_args args) override {
frc::ReportErrorV(err::Error, __FILE__, __LINE__, __FUNCTION__, format,
args);
}
void ReportUsage(wpi::math::MathUsageId id, int count) override {

View File

@@ -10,8 +10,8 @@
#include <string>
#include <thread>
#include <fmt/format.h>
#include <hal/DriverStationTypes.h>
#include <wpi/Twine.h>
#include <wpi/condition_variable.h>
#include <wpi/mutex.h>
@@ -40,28 +40,6 @@ class DriverStation {
*/
static DriverStation& GetInstance();
/**
* Report an error to the DriverStation messages window.
*
* The error is also printed to the program console.
*/
static void ReportError(const wpi::Twine& error);
/**
* Report a warning to the DriverStation messages window.
*
* The warning is also printed to the program console.
*/
static void ReportWarning(const wpi::Twine& error);
/**
* Report an error to the DriverStation messages window.
*
* The error is also printed to the program console.
*/
static void ReportError(bool isError, int code, const wpi::Twine& error,
const wpi::Twine& location, const wpi::Twine& stack);
static constexpr int kJoystickPorts = 6;
/**
@@ -465,14 +443,28 @@ class DriverStation {
*
* Throttles the errors so that they don't overwhelm the DS.
*/
void ReportJoystickUnpluggedError(const wpi::Twine& message);
void ReportJoystickUnpluggedErrorV(fmt::string_view format,
fmt::format_args args);
template <typename S, typename... Args>
inline void ReportJoystickUnpluggedError(const S& format, Args&&... args) {
ReportJoystickUnpluggedErrorV(
format, fmt::make_args_checked<Args...>(format, args...));
}
/**
* Reports errors related to unplugged joysticks.
*
* Throttles the errors so that they don't overwhelm the DS.
*/
void ReportJoystickUnpluggedWarning(const wpi::Twine& message);
void ReportJoystickUnpluggedWarningV(fmt::string_view format,
fmt::format_args args);
template <typename S, typename... Args>
inline void ReportJoystickUnpluggedWarning(const S& format, Args&&... args) {
ReportJoystickUnpluggedWarningV(
format, fmt::make_args_checked<Args...>(format, args...));
}
void Run();

View File

@@ -59,3 +59,4 @@ S(UnsupportedInSimulation, -80, "Unsupported in simulation")
S(CameraServerError, -90, "CameraServer error")
S(InvalidParameter, -100, "Invalid parameter value")
S(AssertionFailure, -110, "Assertion failed")
S(Error, -111, "Error")

View File

@@ -21,3 +21,4 @@ S(SPIReadNoMISO, 13, "Cannot read from SPI port with no MISO input")
S(SPIReadNoData, 14, "No data available to read from SPI")
S(IncompatibleState, 15,
"Incompatible State: The operation cannot be completed")
S(Warning, 16, "Warning")

View File

@@ -54,18 +54,24 @@ TEST_P(JoystickConnectionWarningTests, JoystickConnectionWarnings) {
EXPECT_EQ(
frc::DriverStation::GetInstance().IsJoystickConnectionWarningSilenced(),
std::get<2>(GetParam()));
EXPECT_EQ(::testing::internal::GetCapturedStderr(), std::get<3>(GetParam()));
EXPECT_EQ(::testing::internal::GetCapturedStderr().substr(
0, std::get<3>(GetParam()).size()),
std::get<3>(GetParam()));
}
INSTANTIATE_TEST_SUITE_P(
DriverStation, JoystickConnectionWarningTests,
::testing::Values(std::make_tuple(false, true, true, ""),
std::make_tuple(false, false, false,
"Joystick Button missing, check if all "
"controllers are plugged in\n"),
std::make_tuple(true, true, false,
"Joystick Button missing, check if all "
"controllers are plugged in\n"),
std::make_tuple(true, false, false,
"Joystick Button missing, check if all "
"controllers are plugged in\n")));
::testing::Values(
std::make_tuple(false, true, true, ""),
std::make_tuple(
false, false, false,
"Warning: Joystick Button 1 missing (max 0), check if all "
"controllers are plugged in\n"),
std::make_tuple(
true, true, false,
"Warning: Joystick Button 1 missing (max 0), check if all "
"controllers are plugged in\n"),
std::make_tuple(
true, false, false,
"Warning: Joystick Button 1 missing (max 0), check if all "
"controllers are plugged in\n")));

View File

@@ -6,7 +6,7 @@
#include <frc/DigitalInput.h>
#include <frc/DigitalOutput.h>
#include <frc/DriverStation.h>
#include <frc/Errors.h>
#include <frc2/Timer.h>
OnBoardIO::OnBoardIO(OnBoardIO::ChannelMode dio1, OnBoardIO::ChannelMode dio2) {
@@ -32,7 +32,7 @@ bool OnBoardIO::GetButtonBPressed() {
auto currentTime = frc2::Timer::GetFPGATimestamp();
if (currentTime > m_nextMessageTime) {
frc::DriverStation::ReportError("Button B was not configured");
FRC_ReportError(frc::err::Error, "Button {} was not configured", "B");
m_nextMessageTime = currentTime + kMessageInterval;
}
return false;
@@ -45,7 +45,7 @@ bool OnBoardIO::GetButtonCPressed() {
auto currentTime = frc2::Timer::GetFPGATimestamp();
if (currentTime > m_nextMessageTime) {
frc::DriverStation::ReportError("Button C was not configured");
FRC_ReportError(frc::err::Error, "Button {} was not configured", "C");
m_nextMessageTime = currentTime + kMessageInterval;
}
return false;
@@ -57,7 +57,7 @@ void OnBoardIO::SetGreenLed(bool value) {
} else {
auto currentTime = frc2::Timer::GetFPGATimestamp();
if (currentTime > m_nextMessageTime) {
frc::DriverStation::ReportError("Green LED was not configured");
FRC_ReportError(frc::err::Error, "{} LED was not configured", "Green");
m_nextMessageTime = currentTime + kMessageInterval;
}
}
@@ -69,7 +69,7 @@ void OnBoardIO::SetRedLed(bool value) {
} else {
auto currentTime = frc2::Timer::GetFPGATimestamp();
if (currentTime > m_nextMessageTime) {
frc::DriverStation::ReportError("Red LED was not configured");
FRC_ReportError(frc::err::Error, "{} LED was not configured", "Red");
m_nextMessageTime = currentTime + kMessageInterval;
}
}

View File

@@ -31,6 +31,7 @@ includeGuardRoots {
}
includeOtherLibs {
^fmt/
^wpi/
}

View File

@@ -11,7 +11,7 @@ using namespace wpi::math;
namespace {
class DefaultMathShared : public MathShared {
public:
void ReportError(const wpi::Twine& error) override {}
void ReportErrorV(fmt::string_view format, fmt::format_args args) override {}
void ReportUsage(MathUsageId id, int count) override {}
};
} // namespace

View File

@@ -6,7 +6,7 @@
#include <memory>
#include <wpi/Twine.h>
#include <fmt/format.h>
namespace wpi::math {
@@ -24,8 +24,13 @@ enum class MathUsageId {
class MathShared {
public:
virtual ~MathShared() = default;
virtual void ReportError(const wpi::Twine& error) = 0;
virtual void ReportErrorV(fmt::string_view format, fmt::format_args args) = 0;
virtual void ReportUsage(MathUsageId id, int count) = 0;
template <typename S, typename... Args>
inline void ReportError(const S& format, Args&&... args) {
ReportErrorV(format, fmt::make_args_checked<Args...>(format, args...));
}
};
class MathSharedStore {
@@ -34,8 +39,13 @@ class MathSharedStore {
static void SetMathShared(std::unique_ptr<MathShared> shared);
static void ReportError(const wpi::Twine& error) {
GetMathShared().ReportError(error);
static void ReportErrorV(fmt::string_view format, fmt::format_args args) {
GetMathShared().ReportErrorV(format, args);
}
template <typename S, typename... Args>
static inline void ReportError(const S& format, Args&&... args) {
ReportErrorV(format, fmt::make_args_checked<Args...>(format, args...));
}
static void ReportUsage(MathUsageId id, int count) {