diff --git a/hal/include/HAL/HAL.h b/hal/include/HAL/HAL.h index 3ff7699a25..0a5642841b 100644 --- a/hal/include/HAL/HAL.h +++ b/hal/include/HAL/HAL.h @@ -38,10 +38,7 @@ namespace HALUsageReporting = nUsageReporting; -enum HAL_RuntimeType : int32_t { - HAL_Athena, - HAL_Mock -}; +enum HAL_RuntimeType : int32_t { HAL_Athena, HAL_Mock }; #ifdef __cplusplus extern "C" { diff --git a/hal/include/HAL/cpp/priority_condition_variable.h b/hal/include/HAL/cpp/priority_condition_variable.h index 021785e520..349ce57110 100644 --- a/hal/include/HAL/cpp/priority_condition_variable.h +++ b/hal/include/HAL/cpp/priority_condition_variable.h @@ -23,7 +23,7 @@ #include "priority_mutex.h" class priority_condition_variable { - typedef std::chrono::system_clock clock_t; + typedef std::chrono::system_clock clock; public: typedef std::condition_variable::native_handle_type native_handle_type; @@ -93,13 +93,13 @@ class priority_condition_variable { template std::cv_status wait_for(Lock& lock, const std::chrono::duration& rtime) { - return wait_until(lock, clock_t::now() + rtime); + return wait_until(lock, clock::now() + rtime); } template bool wait_for(Lock& lock, const std::chrono::duration& rtime, Predicate p) { - return wait_until(lock, clock_t::now() + rtime, std::move(p)); + return wait_until(lock, clock::now() + rtime, std::move(p)); } native_handle_type native_handle() { return m_cond.native_handle(); } diff --git a/hal/lib/athena/FRCDriverStation.cpp b/hal/lib/athena/FRCDriverStation.cpp index 2c86fd7807..87a7cb325a 100644 --- a/hal/lib/athena/FRCDriverStation.cpp +++ b/hal/lib/athena/FRCDriverStation.cpp @@ -5,6 +5,7 @@ /* the project. */ /*----------------------------------------------------------------------------*/ +#include #include #include #include @@ -54,11 +55,12 @@ int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode, details, location, callStack); if (printMsg) { if (location && location[0] != '\0') { - fprintf(stderr, "%s at %s: ", isError ? "Error" : "Warning", location); + std::fprintf(stderr, "%s at %s: ", isError ? "Error" : "Warning", + location); } - fprintf(stderr, "%s\n", details); + std::fprintf(stderr, "%s\n", details); if (callStack && callStack[0] != '\0') { - fprintf(stderr, "%s\n", callStack); + std::fprintf(stderr, "%s\n", callStack); } } if (i == KEEP_MSGS) { diff --git a/hal/lib/athena/HAL.cpp b/hal/lib/athena/HAL.cpp index 982500ffeb..4a3d5ad39c 100644 --- a/hal/lib/athena/HAL.cpp +++ b/hal/lib/athena/HAL.cpp @@ -167,9 +167,7 @@ const char* HAL_GetErrorMessage(int32_t code) { /** * Returns the runtime type of this HAL */ -HAL_RuntimeType HAL_GetRuntimeType() { - return HAL_Athena; -} +HAL_RuntimeType HAL_GetRuntimeType() { return HAL_Athena; } /** * Return the FPGA Version number. diff --git a/hal/lib/athena/SPI.cpp b/hal/lib/athena/SPI.cpp index 3c92d216a6..0e7f0086c3 100644 --- a/hal/lib/athena/SPI.cpp +++ b/hal/lib/athena/SPI.cpp @@ -8,6 +8,7 @@ #include "HAL/SPI.h" #include +#include #include "DigitalInternal.h" #include "HAL/DIO.h" @@ -98,18 +99,18 @@ void HAL_InitializeSPI(int32_t port, int32_t* status) { if (*status != 0) return; if ((spiMXPDigitalHandle1 = HAL_InitializeDIOPort( HAL_GetPort(14), false, status)) == HAL_kInvalidHandle) { - printf("Failed to allocate DIO 14\n"); + std::printf("Failed to allocate DIO 14\n"); return; } if ((spiMXPDigitalHandle2 = HAL_InitializeDIOPort( HAL_GetPort(15), false, status)) == HAL_kInvalidHandle) { - printf("Failed to allocate DIO 15\n"); + std::printf("Failed to allocate DIO 15\n"); HAL_FreeDIOPort(spiMXPDigitalHandle1); // free the first port allocated return; } if ((spiMXPDigitalHandle3 = HAL_InitializeDIOPort( HAL_GetPort(16), false, status)) == HAL_kInvalidHandle) { - printf("Failed to allocate DIO 16\n"); + std::printf("Failed to allocate DIO 16\n"); HAL_FreeDIOPort(spiMXPDigitalHandle1); // free the first port allocated HAL_FreeDIOPort( spiMXPDigitalHandle2); // free the second port allocated @@ -117,7 +118,7 @@ void HAL_InitializeSPI(int32_t port, int32_t* status) { } if ((spiMXPDigitalHandle4 = HAL_InitializeDIOPort( HAL_GetPort(17), false, status)) == HAL_kInvalidHandle) { - printf("Failed to allocate DIO 17\n"); + std::printf("Failed to allocate DIO 17\n"); HAL_FreeDIOPort(spiMXPDigitalHandle1); // free the first port allocated HAL_FreeDIOPort( spiMXPDigitalHandle2); // free the second port allocated diff --git a/wpilibc/athena/src/AnalogGyro.cpp b/wpilibc/athena/src/AnalogGyro.cpp index be40f5ba36..b11e2dd820 100644 --- a/wpilibc/athena/src/AnalogGyro.cpp +++ b/wpilibc/athena/src/AnalogGyro.cpp @@ -7,7 +7,7 @@ #include "AnalogGyro.h" -#include +#include #include "AnalogInput.h" #include "HAL/HAL.h" diff --git a/wpilibc/athena/src/IterativeRobot.cpp b/wpilibc/athena/src/IterativeRobot.cpp index 9853d87bc1..05f38ad6d5 100644 --- a/wpilibc/athena/src/IterativeRobot.cpp +++ b/wpilibc/athena/src/IterativeRobot.cpp @@ -19,7 +19,7 @@ constexpr double IterativeRobot::kDefaultPeriod; * Provide an alternate "main loop" via StartCompetition(). * * This specific StartCompetition() implements "main loop" behaviour synced with - * the DS packets + * the DS packets. */ void IterativeRobot::StartCompetition() { HAL_Report(HALUsageReporting::kResourceType_Framework, @@ -164,12 +164,14 @@ void IterativeRobot::TestInit() { /** * Periodic code for all modes should go here. * - * This function is called each time a new packet is received from the driver station. + * This function is called each time a new packet is received from the driver + * station. * - * Packets are received approximately every 20ms. Fixed loop timing is not guaranteed due to - * network timing variability and the function may not be called at all if the Driver Station is - * disconnected. For most use cases the variable timing will not be an issue. If your code does - * require guaranteed fixed periodic timing, consider using Notifier or PIDController instead. + * Packets are received approximately every 20ms. Fixed loop timing is not + * guaranteed due to network timing variability and the function may not be + * called at all if the Driver Station is disconnected. For most use cases the + * variable timing will not be an issue. If your code does require guaranteed + * fixed periodic timing, consider using Notifier or PIDController instead. */ void IterativeRobot::RobotPeriodic() { static bool firstRun = true; @@ -182,13 +184,15 @@ void IterativeRobot::RobotPeriodic() { /** * Periodic code for disabled mode should go here. * - * Users should override this method for code which will be called each time a new packet is - * received from the driver station and the robot is in disabled mode. + * Users should override this method for code which will be called each time a + * new packet is received from the driver station and the robot is in disabled + * mode. * - * Packets are received approximately every 20ms. Fixed loop timing is not guaranteed due to - * network timing variability and the function may not be called at all if the Driver Station is - * disconnected. For most use cases the variable timing will not be an issue. If your code does - * require guaranteed fixed periodic timing, consider using Notifier or PIDController instead. + * Packets are received approximately every 20ms. Fixed loop timing is not + * guaranteed due to network timing variability and the function may not be + * called at all if the Driver Station is disconnected. For most use cases the + * variable timing will not be an issue. If your code does require guaranteed + * fixed periodic timing, consider using Notifier or PIDController instead. */ void IterativeRobot::DisabledPeriodic() { static bool firstRun = true; @@ -201,13 +205,15 @@ void IterativeRobot::DisabledPeriodic() { /** * Periodic code for autonomous mode should go here. * - * Users should override this method for code which will be called each time a new packet is - * received from the driver station and the robot is in autonomous mode. + * Users should override this method for code which will be called each time a + * new packet is received from the driver station and the robot is in autonomous + * mode. * - * Packets are received approximately every 20ms. Fixed loop timing is not guaranteed due to - * network timing variability and the function may not be called at all if the Driver Station is - * disconnected. For most use cases the variable timing will not be an issue. If your code does - * require guaranteed fixed periodic timing, consider using Notifier or PIDController instead. + * Packets are received approximately every 20ms. Fixed loop timing is not + * guaranteed due to network timing variability and the function may not be + * called at all if the Driver Station is disconnected. For most use cases the + * variable timing will not be an issue. If your code does require guaranteed + * fixed periodic timing, consider using Notifier or PIDController instead. */ void IterativeRobot::AutonomousPeriodic() { static bool firstRun = true; @@ -220,13 +226,15 @@ void IterativeRobot::AutonomousPeriodic() { /** * Periodic code for teleop mode should go here. * - * Users should override this method for code which will be called each time a new packet is - * received from the driver station and the robot is in teleop mode. + * Users should override this method for code which will be called each time a + * new packet is received from the driver station and the robot is in teleop + * mode. * - * Packets are received approximately every 20ms. Fixed loop timing is not guaranteed due to - * network timing variability and the function may not be called at all if the Driver Station is - * disconnected. For most use cases the variable timing will not be an issue. If your code does - * require guaranteed fixed periodic timing, consider using Notifier or PIDController instead. + * Packets are received approximately every 20ms. Fixed loop timing is not + * guaranteed due to network timing variability and the function may not be + * called at all if the Driver Station is disconnected. For most use cases the + * variable timing will not be an issue. If your code does require guaranteed + * fixed periodic timing, consider using Notifier or PIDController instead. */ void IterativeRobot::TeleopPeriodic() { static bool firstRun = true; @@ -239,13 +247,14 @@ void IterativeRobot::TeleopPeriodic() { /** * Periodic code for test mode should go here. * - * Users should override this method for code which will be called each time a new packet is - * received from the driver station and the robot is in test mode. + * Users should override this method for code which will be called each time a + * new packet is received from the driver station and the robot is in test mode. * - * Packets are received approximately every 20ms. Fixed loop timing is not guaranteed due to - * network timing variability and the function may not be called at all if the Driver Station is - * disconnected. For most use cases the variable timing will not be an issue. If your code does - * require guaranteed fixed periodic timing, consider using Notifier or PIDController instead. + * Packets are received approximately every 20ms. Fixed loop timing is not + * guaranteed due to network timing variability and the function may not be + * called at all if the Driver Station is disconnected. For most use cases the + * variable timing will not be an issue. If your code does require guaranteed + * fixed periodic timing, consider using Notifier or PIDController instead. */ void IterativeRobot::TestPeriodic() { static bool firstRun = true; diff --git a/wpilibc/athena/src/RobotBase.cpp b/wpilibc/athena/src/RobotBase.cpp index 7165aba5a3..fd6ae2eb24 100644 --- a/wpilibc/athena/src/RobotBase.cpp +++ b/wpilibc/athena/src/RobotBase.cpp @@ -35,7 +35,7 @@ RobotBase::RobotBase() : m_ds(DriverStation::GetInstance()) { NetworkTable::SetNetworkIdentity("Robot"); NetworkTable::SetPersistentFilename("/home/lvuser/networktables.ini"); - FILE* file = nullptr; + std::FILE* file = nullptr; file = std::fopen("/tmp/frc_versions/FRC_Lib_Version.ini", "w"); if (file != nullptr) { diff --git a/wpilibc/athena/src/Task.cpp b/wpilibc/athena/src/Task.cpp index 82cbf36285..8d7b236960 100644 --- a/wpilibc/athena/src/Task.cpp +++ b/wpilibc/athena/src/Task.cpp @@ -8,6 +8,7 @@ #include "Task.h" #include +#include #include "WPIErrors.h" @@ -98,7 +99,7 @@ bool Task::HandleError(STATUS results) { if (errsv == HAL_TaskLib_ILLEGAL_PRIORITY) { wpi_setWPIErrorWithContext(TaskPriorityError, m_taskName.c_str()); } else { - printf("ERROR: errno=%i", errsv); + std::printf("ERROR: errno=%i", errsv); wpi_setWPIErrorWithContext(TaskError, m_taskName.c_str()); } return false; diff --git a/wpilibc/athena/src/USBCamera.cpp b/wpilibc/athena/src/USBCamera.cpp index a9cd5d9d7c..e5af0a6825 100644 --- a/wpilibc/athena/src/USBCamera.cpp +++ b/wpilibc/athena/src/USBCamera.cpp @@ -10,6 +10,7 @@ #include "Utility.h" #include +#include #include #include #include @@ -160,7 +161,7 @@ void USBCamera::UpdateSettings() { int height = static_cast(std::stoul(m[2].str())); if (width != m_width) continue; if (height != m_height) continue; - double fps = atof(m[4].str().c_str()); + double fps = std::atof(m[4].str().c_str()); if (fps < m_fps) continue; if (fps > foundFps) continue; bool isJpeg = diff --git a/wpilibc/athena/src/Utility.cpp b/wpilibc/athena/src/Utility.cpp index dace891281..5bac39be10 100644 --- a/wpilibc/athena/src/Utility.cpp +++ b/wpilibc/athena/src/Utility.cpp @@ -10,6 +10,8 @@ #include #include +#include +#include #include #include "HAL/HAL.h" @@ -182,7 +184,7 @@ static std::string demangle(char const* mangledSymbol) { size_t length; int32_t status; - if (sscanf(mangledSymbol, "%*[^(]%*[(]%255[^)+]", buffer)) { + if (std::sscanf(mangledSymbol, "%*[^(]%*[(]%255[^)+]", buffer)) { char* symbol = abi::__cxa_demangle(buffer, nullptr, &length, &status); if (status == 0) { return symbol; @@ -214,7 +216,7 @@ std::string GetStackTrace(int offset) { } } - free(mangledSymbols); + std::free(mangledSymbols); return trace.str(); } diff --git a/wpilibc/athena/src/Vision/AxisCamera.cpp b/wpilibc/athena/src/Vision/AxisCamera.cpp index 4eb94c8fc2..e5a270d96c 100644 --- a/wpilibc/athena/src/Vision/AxisCamera.cpp +++ b/wpilibc/athena/src/Vision/AxisCamera.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -463,8 +464,8 @@ void AxisCamera::ReadImagesFromCamera() { if (imgBuffer) delete[] imgBuffer; return; } - contentLength = contentLength + 16; // skip past "content length" - int readLength = atol(contentLength); // get the image byte count + contentLength = contentLength + 16; // skip past "content length" + int readLength = std::atol(contentLength); // get the image byte count // Make sure buffer is large enough if (imgBufferLength < readLength) { diff --git a/wpilibc/athena/src/Vision/BaeUtilities.cpp b/wpilibc/athena/src/Vision/BaeUtilities.cpp index 7d13538d5d..e51ec6da16 100644 --- a/wpilibc/athena/src/Vision/BaeUtilities.cpp +++ b/wpilibc/athena/src/Vision/BaeUtilities.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -55,7 +56,7 @@ void dprintf(const char* tempString, ...) { const char* functionName; /* Format passed in argument */ const char* fmt; /* Format passed in argument */ char text[512]; /* Text string */ - FILE* outfile_fd; /* Output file pointer */ + std::FILE* outfile_fd; /* Output file pointer */ char filepath[128]; /* Text string */ int fatalFlag = 0; const char* filename; @@ -68,7 +69,7 @@ void dprintf(const char* tempString, ...) { va_start(args, tempString); - tempStringLen = strlen(tempString); + tempStringLen = std::strlen(tempString); filename = tempString; for (index = 0; index < tempStringLen; index++) { if (tempString[index] == ' ') { @@ -298,7 +299,7 @@ void panForTarget(Servo* panServo, double sinStart) { * @return int number of lines or -1 if error **/ int processFile(char* inputFile, char* outputString, int lineNumber) { - FILE* infile; + std::FILE* infile; const int kStringSize = 80; // max size of one line in file char inputStr[kStringSize]; inputStr[0] = '\0'; @@ -348,7 +349,7 @@ int emptyString(char* string) { if (string == nullptr) return (1); - len = strlen(string); + len = std::strlen(string); for (i = 0; i < len; i++) { // Ignore the following characters if (string[i] == '\n' || string[i] == '\r' || string[i] == '\t' || @@ -368,7 +369,7 @@ void stripString(char* string) { if (string == nullptr) return; - len = strlen(string); + len = std::strlen(string); for (i = 0, j = 0; i < len; i++) { // Remove the following characters from the string if (string[i] == '\n' || string[i] == '\r' || string[i] == '\"') continue; diff --git a/wpilibc/shared/src/Commands/PrintCommand.cpp b/wpilibc/shared/src/Commands/PrintCommand.cpp index ba4cad1868..e2bab36455 100644 --- a/wpilibc/shared/src/Commands/PrintCommand.cpp +++ b/wpilibc/shared/src/Commands/PrintCommand.cpp @@ -6,8 +6,9 @@ /*----------------------------------------------------------------------------*/ #include "Commands/PrintCommand.h" + +#include #include -#include "stdio.h" PrintCommand::PrintCommand(const std::string& message) : Command(((std::stringstream&)(std::stringstream("Print \"") << message @@ -17,7 +18,7 @@ PrintCommand::PrintCommand(const std::string& message) m_message = message; } -void PrintCommand::Initialize() { printf("%s", m_message.c_str()); } +void PrintCommand::Initialize() { std::printf("%s", m_message.c_str()); } void PrintCommand::Execute() {} diff --git a/wpilibc/shared/src/ErrorBase.cpp b/wpilibc/shared/src/ErrorBase.cpp index d3ec716b99..6882c7823f 100644 --- a/wpilibc/shared/src/ErrorBase.cpp +++ b/wpilibc/shared/src/ErrorBase.cpp @@ -8,6 +8,8 @@ #include "ErrorBase.h" #include +#include +#include #include #include @@ -49,7 +51,7 @@ void ErrorBase::SetErrnoError(llvm::StringRef contextMessage, err += contextMessage; } else { std::ostringstream oss; - oss << strerror(errNo) << " (0x" << std::setfill('0') << std::hex + oss << std::strerror(errNo) << " (0x" << std::setfill('0') << std::hex << std::uppercase << std::setw(8) << errNo << "): " << contextMessage; err = oss.str(); } @@ -140,9 +142,10 @@ void ErrorBase::SetErrorRange(Error::Code code, int32_t minRange, if (code != 0) { size_t size = contextMessage.size() + 100; char* buf = new char[size]; - snprintf(buf, size, - "%s, Minimum Value: %d, Maximum Value: %d, Requested Value: %d", - contextMessage.data(), minRange, maxRange, requestedValue); + std::snprintf( + buf, size, + "%s, Minimum Value: %d, Maximum Value: %d, Requested Value: %d", + contextMessage.data(), minRange, maxRange, requestedValue); // Set the current error information for this object. m_error.Set(code, buf, filename, function, lineNumber, this); delete[] buf; diff --git a/wpilibc/sim/src/Utility.cpp b/wpilibc/sim/src/Utility.cpp index 450f941c80..28c3f62e7b 100644 --- a/wpilibc/sim/src/Utility.cpp +++ b/wpilibc/sim/src/Utility.cpp @@ -7,14 +7,16 @@ #include "Utility.h" -#include -#include -#include -#if not defined(_WIN32) +#ifndef _WIN32 #include #include #endif +#include +#include +#include +#include + #include "Timer.h" #include "simulation/simTime.h" @@ -192,7 +194,7 @@ std::string GetStackTrace(int offset) { } } - free(mangledSymbols); + std::free(mangledSymbols); return trace.str(); } diff --git a/wpilibcIntegrationTests/src/TestEnvironment.cpp b/wpilibcIntegrationTests/src/TestEnvironment.cpp index 968d8fe344..6d19ede5df 100644 --- a/wpilibcIntegrationTests/src/TestEnvironment.cpp +++ b/wpilibcIntegrationTests/src/TestEnvironment.cpp @@ -5,6 +5,8 @@ /* the project. */ /*----------------------------------------------------------------------------*/ +#include + #include "DriverStation.h" #include "LiveWindow/LiveWindow.h" #include "Timer.h" @@ -22,7 +24,7 @@ class TestEnvironment : public testing::Environment { if (!HAL_Initialize(0)) { std::cerr << "FATAL ERROR: HAL could not be initialized" << std::endl; - exit(-1); + std::exit(-1); } /* This sets up the network communications library to enable the driver diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/IterativeRobot.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/IterativeRobot.java index 078aedcfff..050e273027 100644 --- a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/IterativeRobot.java +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/IterativeRobot.java @@ -205,7 +205,7 @@ public class IterativeRobot extends RobotBase { } /* ----------- Overridable periodic code ----------------- */ - + private boolean m_rpFirstRun = true; /** diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/hal/HALUtil.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/hal/HALUtil.java index 7a82ba9a95..cae63793cf 100644 --- a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/hal/HALUtil.java +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/hal/HALUtil.java @@ -23,7 +23,7 @@ public class HALUtil extends JNIWrapper { public static native int getFPGARevision(); public static native long getFPGATime(); - + public static native int getHALRuntimeType(); public static native boolean getFPGAButton(); diff --git a/wpilibj/src/sim/java/edu/wpi/first/wpilibj/IterativeRobot.java b/wpilibj/src/sim/java/edu/wpi/first/wpilibj/IterativeRobot.java index 740096c40d..83a225be30 100644 --- a/wpilibj/src/sim/java/edu/wpi/first/wpilibj/IterativeRobot.java +++ b/wpilibj/src/sim/java/edu/wpi/first/wpilibj/IterativeRobot.java @@ -210,7 +210,7 @@ public class IterativeRobot extends RobotBase { } /* ----------- Overridable periodic code -----------------*/ - + private boolean m_rpFirstRun = true; /**