diff --git a/wpilibc/src/main/native/cpp/DigitalGlitchFilter.cpp b/wpilibc/src/main/native/cpp/DigitalGlitchFilter.cpp index 9fae85dbd7..d66bbd299e 100644 --- a/wpilibc/src/main/native/cpp/DigitalGlitchFilter.cpp +++ b/wpilibc/src/main/native/cpp/DigitalGlitchFilter.cpp @@ -16,7 +16,6 @@ #include "frc/Encoder.h" #include "frc/Errors.h" #include "frc/SensorUtil.h" -#include "frc/Utility.h" #include "frc/smartdashboard/SendableRegistry.h" using namespace frc; diff --git a/wpilibc/src/main/native/cpp/InterruptableSensorBase.cpp b/wpilibc/src/main/native/cpp/InterruptableSensorBase.cpp index 334fd3c1d3..1fc17d641a 100644 --- a/wpilibc/src/main/native/cpp/InterruptableSensorBase.cpp +++ b/wpilibc/src/main/native/cpp/InterruptableSensorBase.cpp @@ -5,7 +5,6 @@ #include "frc/InterruptableSensorBase.h" #include "frc/Errors.h" -#include "frc/Utility.h" using namespace frc; diff --git a/wpilibc/src/main/native/cpp/Notifier.cpp b/wpilibc/src/main/native/cpp/Notifier.cpp index c65a68ce2a..c761167d74 100644 --- a/wpilibc/src/main/native/cpp/Notifier.cpp +++ b/wpilibc/src/main/native/cpp/Notifier.cpp @@ -13,7 +13,6 @@ #include "frc/Errors.h" #include "frc/Timer.h" -#include "frc/Utility.h" using namespace frc; diff --git a/wpilibc/src/main/native/cpp/PWM.cpp b/wpilibc/src/main/native/cpp/PWM.cpp index b9aa1d8ffa..7484621fc2 100644 --- a/wpilibc/src/main/native/cpp/PWM.cpp +++ b/wpilibc/src/main/native/cpp/PWM.cpp @@ -14,7 +14,6 @@ #include "frc/Errors.h" #include "frc/SensorUtil.h" -#include "frc/Utility.h" #include "frc/smartdashboard/SendableBuilder.h" #include "frc/smartdashboard/SendableRegistry.h" @@ -119,7 +118,7 @@ void PWM::SetPeriodMultiplier(PeriodMultiplier mult) { HAL_SetPWMPeriodScale(m_handle, 0, &status); // Don't squelch any outputs break; default: - wpi_assert(false); + throw FRC_MakeError(err::InvalidParameter, "PeriodMultiplier value"); } FRC_CheckErrorStatus(status, "SetPeriodMultiplier"); diff --git a/wpilibc/src/main/native/cpp/TimedRobot.cpp b/wpilibc/src/main/native/cpp/TimedRobot.cpp index d4ddc6c656..cb0552bbee 100644 --- a/wpilibc/src/main/native/cpp/TimedRobot.cpp +++ b/wpilibc/src/main/native/cpp/TimedRobot.cpp @@ -14,7 +14,6 @@ #include "frc/Errors.h" #include "frc/Timer.h" -#include "frc/Utility.h" using namespace frc; diff --git a/wpilibc/src/main/native/cpp/Ultrasonic.cpp b/wpilibc/src/main/native/cpp/Ultrasonic.cpp index 2389eda1e0..3442f064a4 100644 --- a/wpilibc/src/main/native/cpp/Ultrasonic.cpp +++ b/wpilibc/src/main/native/cpp/Ultrasonic.cpp @@ -14,7 +14,6 @@ #include "frc/DigitalOutput.h" #include "frc/Errors.h" #include "frc/Timer.h" -#include "frc/Utility.h" #include "frc/smartdashboard/SendableBuilder.h" #include "frc/smartdashboard/SendableRegistry.h" @@ -83,7 +82,10 @@ Ultrasonic::~Ultrasonic() { } void Ultrasonic::Ping() { - wpi_assert(!m_automaticEnabled); + if (m_automaticEnabled) { + throw FRC_MakeError(err::IncompatibleMode, + "cannot call Ping() in automatic mode"); + } // Reset the counter to zero (invalid data now) m_counter.Reset(); diff --git a/wpilibc/src/main/native/cpp/Utility.cpp b/wpilibc/src/main/native/cpp/Utility.cpp deleted file mode 100644 index 0adc71f408..0000000000 --- a/wpilibc/src/main/native/cpp/Utility.cpp +++ /dev/null @@ -1,109 +0,0 @@ -// 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 "frc/Utility.h" - -#ifndef _WIN32 -#include -#include -#endif - -#include -#include -#include -#include -#include -#include - -using namespace frc; - -bool wpi_assert_impl(bool conditionValue, const wpi::Twine& conditionText, - const wpi::Twine& message, wpi::StringRef fileName, - int lineNumber, wpi::StringRef funcName) { - if (!conditionValue) { - wpi::SmallString<128> locBuf; - wpi::raw_svector_ostream locStream(locBuf); - locStream << funcName << " [" << wpi::sys::path::filename(fileName) << ":" - << lineNumber << "]"; - - wpi::SmallString<128> errorBuf; - wpi::raw_svector_ostream errorStream(errorBuf); - - errorStream << "Assertion \"" << conditionText << "\" "; - - if (message.isTriviallyEmpty() || - (message.isSingleStringRef() && message.getSingleStringRef().empty())) { - errorStream << "failed.\n"; - } else { - errorStream << "failed: " << message << "\n"; - } - - std::string stack = wpi::GetStackTrace(2); - - // Print the error and send it to the DriverStation - HAL_SendError(1, 1, 0, errorBuf.c_str(), locBuf.c_str(), stack.c_str(), 1); - } - - return conditionValue; -} - -/** - * Common error routines for wpi_assertEqual_impl and wpi_assertNotEqual_impl. - * - * This should not be called directly; it should only be used by - * wpi_assertEqual_impl and wpi_assertNotEqual_impl. - */ -void wpi_assertEqual_common_impl(const wpi::Twine& valueA, - const wpi::Twine& valueB, - const wpi::Twine& equalityType, - const wpi::Twine& message, - wpi::StringRef fileName, int lineNumber, - wpi::StringRef funcName) { - wpi::SmallString<128> locBuf; - wpi::raw_svector_ostream locStream(locBuf); - locStream << funcName << " [" << wpi::sys::path::filename(fileName) << ":" - << lineNumber << "]"; - - wpi::SmallString<128> errorBuf; - wpi::raw_svector_ostream errorStream(errorBuf); - - errorStream << "Assertion \"" << valueA << " " << equalityType << " " - << valueB << "\" "; - - if (message.isTriviallyEmpty() || - (message.isSingleStringRef() && message.getSingleStringRef().empty())) { - errorStream << "failed.\n"; - } else { - errorStream << "failed: " << message << "\n"; - } - - std::string trace = wpi::GetStackTrace(3); - - // Print the error and send it to the DriverStation - HAL_SendError(1, 1, 0, errorBuf.c_str(), locBuf.c_str(), trace.c_str(), 1); -} - -bool wpi_assertEqual_impl(int valueA, int valueB, - const wpi::Twine& valueAString, - const wpi::Twine& valueBString, - const wpi::Twine& message, wpi::StringRef fileName, - int lineNumber, wpi::StringRef funcName) { - if (!(valueA == valueB)) { - wpi_assertEqual_common_impl(valueAString, valueBString, "==", message, - fileName, lineNumber, funcName); - } - return valueA == valueB; -} - -bool wpi_assertNotEqual_impl(int valueA, int valueB, - const wpi::Twine& valueAString, - const wpi::Twine& valueBString, - const wpi::Twine& message, wpi::StringRef fileName, - int lineNumber, wpi::StringRef funcName) { - if (!(valueA != valueB)) { - wpi_assertEqual_common_impl(valueAString, valueBString, "!=", message, - fileName, lineNumber, funcName); - } - return valueA != valueB; -} diff --git a/wpilibc/src/main/native/cppcs/RobotBase.cpp b/wpilibc/src/main/native/cppcs/RobotBase.cpp index b3923bf6df..36927a7e6e 100644 --- a/wpilibc/src/main/native/cppcs/RobotBase.cpp +++ b/wpilibc/src/main/native/cppcs/RobotBase.cpp @@ -20,7 +20,6 @@ #include "frc/DriverStation.h" #include "frc/Errors.h" #include "frc/RobotState.h" -#include "frc/Utility.h" #include "frc/livewindow/LiveWindow.h" #include "frc/smartdashboard/SmartDashboard.h" diff --git a/wpilibc/src/main/native/include/frc/Utility.h b/wpilibc/src/main/native/include/frc/Utility.h deleted file mode 100644 index e9c6d9c715..0000000000 --- a/wpilibc/src/main/native/include/frc/Utility.h +++ /dev/null @@ -1,65 +0,0 @@ -// 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. - -#pragma once - -/** - * @file Contains global utility functions - */ - -#include -#include - -#define wpi_assert(condition) \ - wpi_assert_impl(condition, #condition, "", __FILE__, __LINE__, __FUNCTION__) -#define wpi_assertWithMessage(condition, message) \ - wpi_assert_impl(condition, #condition, message, __FILE__, __LINE__, \ - __FUNCTION__) - -#define wpi_assertEqual(a, b) \ - wpi_assertEqual_impl(a, b, #a, #b, "", __FILE__, __LINE__, __FUNCTION__) -#define wpi_assertEqualWithMessage(a, b, message) \ - wpi_assertEqual_impl(a, b, #a, #b, message, __FILE__, __LINE__, __FUNCTION__) - -#define wpi_assertNotEqual(a, b) \ - wpi_assertNotEqual_impl(a, b, #a, #b, "", __FILE__, __LINE__, __FUNCTION__) -#define wpi_assertNotEqualWithMessage(a, b, message) \ - wpi_assertNotEqual_impl(a, b, #a, #b, message, __FILE__, __LINE__, \ - __FUNCTION__) - -/** - * Assert implementation. - * - * This allows breakpoints to be set on an assert. The users don't call this, - * but instead use the wpi_assert macros in Utility.h. - */ -bool wpi_assert_impl(bool conditionValue, const wpi::Twine& conditionText, - const wpi::Twine& message, wpi::StringRef fileName, - int lineNumber, wpi::StringRef funcName); - -/** - * Assert equal implementation. - * - * This determines whether the two given integers are equal. If not, the value - * of each is printed along with an optional message string. The users don't - * call this, but instead use the wpi_assertEqual macros in Utility.h. - */ -bool wpi_assertEqual_impl(int valueA, int valueB, - const wpi::Twine& valueAString, - const wpi::Twine& valueBString, - const wpi::Twine& message, wpi::StringRef fileName, - int lineNumber, wpi::StringRef funcName); - -/** - * Assert not equal implementation. - * - * This determines whether the two given integers are equal. If so, the value of - * each is printed along with an optional message string. The users don't call - * this, but instead use the wpi_assertNotEqual macros in Utility.h. - */ -bool wpi_assertNotEqual_impl(int valueA, int valueB, - const wpi::Twine& valueAString, - const wpi::Twine& valueBString, - const wpi::Twine& message, wpi::StringRef fileName, - int lineNumber, wpi::StringRef funcName);