Ran format.py after writing unit tests for and fixing bugs in it (#239)

This commit is contained in:
Tyler Veness
2016-09-21 23:48:54 -07:00
committed by Peter Johnson
parent ac9b6f7b18
commit 659dbef751
20 changed files with 96 additions and 75 deletions

View File

@@ -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" {

View File

@@ -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 <typename Lock, typename Rep, typename Period>
std::cv_status wait_for(Lock& lock,
const std::chrono::duration<Rep, Period>& rtime) {
return wait_until(lock, clock_t::now() + rtime);
return wait_until(lock, clock::now() + rtime);
}
template <typename Lock, typename Rep, typename Period, typename Predicate>
bool wait_for(Lock& lock, const std::chrono::duration<Rep, Period>& 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(); }

View File

@@ -5,6 +5,7 @@
/* the project. */
/*----------------------------------------------------------------------------*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <limits>
@@ -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) {

View File

@@ -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.

View File

@@ -8,6 +8,7 @@
#include "HAL/SPI.h"
#include <atomic>
#include <cstdio>
#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

View File

@@ -7,7 +7,7 @@
#include "AnalogGyro.h"
#include <limits.h>
#include <climits>
#include "AnalogInput.h"
#include "HAL/HAL.h"

View File

@@ -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;

View File

@@ -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) {

View File

@@ -8,6 +8,7 @@
#include "Task.h"
#include <cerrno>
#include <cstdio>
#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;

View File

@@ -10,6 +10,7 @@
#include "Utility.h"
#include <chrono>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <memory>
@@ -160,7 +161,7 @@ void USBCamera::UpdateSettings() {
int height = static_cast<int>(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 =

View File

@@ -10,6 +10,8 @@
#include <cxxabi.h>
#include <execinfo.h>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#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();
}

View File

@@ -13,6 +13,7 @@
#include <sys/types.h>
#include <unistd.h>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
@@ -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) {

View File

@@ -14,6 +14,7 @@
#include <cmath>
#include <cstdarg>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
@@ -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;

View File

@@ -6,8 +6,9 @@
/*----------------------------------------------------------------------------*/
#include "Commands/PrintCommand.h"
#include <cstdio>
#include <sstream>
#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() {}

View File

@@ -8,6 +8,8 @@
#include "ErrorBase.h"
#include <cerrno>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <sstream>
@@ -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;

View File

@@ -7,14 +7,16 @@
#include "Utility.h"
#include <cstdio>
#include <iostream>
#include <sstream>
#if not defined(_WIN32)
#ifndef _WIN32
#include <cxxabi.h>
#include <execinfo.h>
#endif
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include "Timer.h"
#include "simulation/simTime.h"
@@ -192,7 +194,7 @@ std::string GetStackTrace(int offset) {
}
}
free(mangledSymbols);
std::free(mangledSymbols);
return trace.str();
}

View File

@@ -5,6 +5,8 @@
/* the project. */
/*----------------------------------------------------------------------------*/
#include <cstdlib>
#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

View File

@@ -205,7 +205,7 @@ public class IterativeRobot extends RobotBase {
}
/* ----------- Overridable periodic code ----------------- */
private boolean m_rpFirstRun = true;
/**

View File

@@ -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();

View File

@@ -210,7 +210,7 @@ public class IterativeRobot extends RobotBase {
}
/* ----------- Overridable periodic code -----------------*/
private boolean m_rpFirstRun = true;
/**