From 5dcaa6d6715ba3e9fea613e72001e0186897783c Mon Sep 17 00:00:00 2001 From: Jade Date: Sun, 28 Jul 2024 11:20:08 +0800 Subject: [PATCH] [wpilibc] Add FRC_ReportWarning (#6681) --- ntcoreffi/src/main/native/cpp/DataLogManager.cpp | 1 - wpilibc/src/main/native/cpp/DataLogManager.cpp | 10 +++++----- wpilibc/src/main/native/cpp/I2C.cpp | 8 ++++---- wpilibc/src/main/native/cpp/Tracer.cpp | 2 +- wpilibc/src/main/native/cpp/Watchdog.cpp | 4 ++-- wpilibc/src/main/native/cppcs/RobotBase.cpp | 3 +-- wpilibc/src/main/native/include/frc/Errors.h | 11 +++++++++++ 7 files changed, 24 insertions(+), 15 deletions(-) diff --git a/ntcoreffi/src/main/native/cpp/DataLogManager.cpp b/ntcoreffi/src/main/native/cpp/DataLogManager.cpp index 2692b8781b..d8543482fe 100644 --- a/ntcoreffi/src/main/native/cpp/DataLogManager.cpp +++ b/ntcoreffi/src/main/native/cpp/DataLogManager.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #ifdef __FRC_ROBORIO__ #include diff --git a/wpilibc/src/main/native/cpp/DataLogManager.cpp b/wpilibc/src/main/native/cpp/DataLogManager.cpp index 43870728d4..dc9d3d7387 100644 --- a/wpilibc/src/main/native/cpp/DataLogManager.cpp +++ b/wpilibc/src/main/native/cpp/DataLogManager.cpp @@ -73,9 +73,9 @@ static std::string MakeLogDir(std::string_view dir) { return "/u/logs"; } if (RobotBase::GetRuntimeType() == kRoboRIO) { - FRC_ReportError(warn::Warning, - "DataLogManager: Logging to RoboRIO 1 internal storage is " - "not recommended! Plug in a FAT32 formatted flash drive!"); + FRC_ReportWarning( + "DataLogManager: Logging to RoboRIO 1 internal storage is " + "not recommended! Plug in a FAT32 formatted flash drive!"); } fs::create_directory("/home/lvuser/logs", ec); return "/home/lvuser/logs"; @@ -151,8 +151,8 @@ void Thread::Main() { } auto size = entry.file_size(); if (fs::remove(entry.path(), ec)) { - FRC_ReportError(warn::Warning, "DataLogManager: Deleted {}", - entry.path().string()); + FRC_ReportWarning("DataLogManager: Deleted {}", + entry.path().string()); freeSpace += size; if (freeSpace >= kFreeSpaceThreshold) { break; diff --git a/wpilibc/src/main/native/cpp/I2C.cpp b/wpilibc/src/main/native/cpp/I2C.cpp index 232a47f0f1..dbc624dcc1 100644 --- a/wpilibc/src/main/native/cpp/I2C.cpp +++ b/wpilibc/src/main/native/cpp/I2C.cpp @@ -19,10 +19,10 @@ I2C::I2C(Port port, int deviceAddress) int32_t status = 0; if (port == I2C::Port::kOnboard) { - FRC_ReportError(warn::Warning, - "Onboard I2C port is subject to system lockups. See Known " - "Issues page for " - "details"); + FRC_ReportWarning( + "Onboard I2C port is subject to system lockups. See Known " + "Issues page for " + "details"); } HAL_InitializeI2C(m_port, &status); diff --git a/wpilibc/src/main/native/cpp/Tracer.cpp b/wpilibc/src/main/native/cpp/Tracer.cpp index 1375411ff1..41b0863e47 100644 --- a/wpilibc/src/main/native/cpp/Tracer.cpp +++ b/wpilibc/src/main/native/cpp/Tracer.cpp @@ -36,7 +36,7 @@ void Tracer::PrintEpochs() { wpi::raw_svector_ostream os(buf); PrintEpochs(os); if (!buf.empty()) { - FRC_ReportError(warn::Warning, "{}", buf.c_str()); + FRC_ReportWarning("{}", buf.c_str()); } } diff --git a/wpilibc/src/main/native/cpp/Watchdog.cpp b/wpilibc/src/main/native/cpp/Watchdog.cpp index 37e253616e..e626d27352 100644 --- a/wpilibc/src/main/native/cpp/Watchdog.cpp +++ b/wpilibc/src/main/native/cpp/Watchdog.cpp @@ -113,8 +113,8 @@ void Watchdog::Impl::Main() { if (now - watchdog->m_lastTimeoutPrintTime > kMinPrintPeriod) { watchdog->m_lastTimeoutPrintTime = now; if (!watchdog->m_suppressTimeoutMessage) { - FRC_ReportError(warn::Warning, "Watchdog not fed within {:.6f}s", - watchdog->m_timeout.value()); + FRC_ReportWarning("Watchdog not fed within {:.6f}s", + watchdog->m_timeout.value()); } } diff --git a/wpilibc/src/main/native/cppcs/RobotBase.cpp b/wpilibc/src/main/native/cppcs/RobotBase.cpp index c4052ac6e0..da75ad4c87 100644 --- a/wpilibc/src/main/native/cppcs/RobotBase.cpp +++ b/wpilibc/src/main/native/cppcs/RobotBase.cpp @@ -47,8 +47,7 @@ int frc::RunHALInitialization() { HALUsageReporting::kLanguage_CPlusPlus, 0, GetWPILibVersion()); if (!frc::Notifier::SetHALThreadPriority(true, 40)) { - FRC_ReportError(warn::Warning, - "Setting HAL Notifier RT priority to 40 failed\n"); + FRC_ReportWarning("Setting HAL Notifier RT priority to 40 failed\n"); } std::puts("\n********** Robot program starting **********"); diff --git a/wpilibc/src/main/native/include/frc/Errors.h b/wpilibc/src/main/native/include/frc/Errors.h index 4dae6c94bb..44c02b11d5 100644 --- a/wpilibc/src/main/native/include/frc/Errors.h +++ b/wpilibc/src/main/native/include/frc/Errors.h @@ -142,6 +142,17 @@ namespace warn { } \ } while (0) +/** + * Reports a warning to the driver station (using HAL_SendError). + * + * @param[in] format error message format + */ +#define FRC_ReportWarning(format, ...) \ + do { \ + ::frc::ReportError(warn::Warning, __FILE__, __LINE__, __FUNCTION__, \ + FMT_STRING(format) __VA_OPT__(, ) __VA_ARGS__); \ + } while (0) + /** * Makes a runtime error exception object. This object should be thrown * by the caller.