mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
Changed const char* -> string in most of wpilibc.
The HAL will remain untouched in order to maintain C-style compatibility. A few places in wpilibc were left as C-style strings, especially if special formatting (eg, elaborate uses of snprintf or sscanf) was being used. In general, const char* was changed to std::string. character buffers used for formatting were either untouched, changed to std::stringstream, or changed to std::string, depending on what was done with the buffer. Change-Id: I5e431ddf1cc4d9a6d534e1f21b16ea23be26e7f1
This commit is contained in:
@@ -14,8 +14,8 @@
|
||||
|
||||
class NetworkButton : public Button {
|
||||
public:
|
||||
NetworkButton(const char *tableName, const char *field);
|
||||
NetworkButton(::std::shared_ptr<ITable> table, const char *field);
|
||||
NetworkButton(const std::string &tableName, const std::string &field);
|
||||
NetworkButton(::std::shared_ptr<ITable> table, const std::string &field);
|
||||
virtual ~NetworkButton() = default;
|
||||
|
||||
virtual bool Get();
|
||||
|
||||
@@ -56,9 +56,9 @@ class Command : public ErrorBase, public NamedSendable, public ITableListener {
|
||||
|
||||
public:
|
||||
Command();
|
||||
Command(const char *name);
|
||||
Command(const std::string &name);
|
||||
Command(double timeout);
|
||||
Command(const char *name, double timeout);
|
||||
Command(const std::string &name, double timeout);
|
||||
virtual ~Command();
|
||||
double TimeSinceInitialized() const;
|
||||
void Requires(Subsystem *s);
|
||||
@@ -80,7 +80,7 @@ class Command : public ErrorBase, public NamedSendable, public ITableListener {
|
||||
protected:
|
||||
void SetTimeout(double timeout);
|
||||
bool IsTimedOut() const;
|
||||
bool AssertUnlocked(const char *message);
|
||||
bool AssertUnlocked(const std::string &message);
|
||||
void SetParent(CommandGroup *parent);
|
||||
/**
|
||||
* The initialize method is called the first time this Command is run after
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
class CommandGroup : public Command {
|
||||
public:
|
||||
CommandGroup() = default;
|
||||
CommandGroup(const char *name);
|
||||
CommandGroup(const std::string &name);
|
||||
virtual ~CommandGroup() = default;
|
||||
|
||||
void AddSequential(Command *command);
|
||||
|
||||
@@ -18,9 +18,9 @@ class PIDController;
|
||||
|
||||
class PIDCommand : public Command, public PIDOutput, public PIDSource {
|
||||
public:
|
||||
PIDCommand(const char *name, double p, double i, double d);
|
||||
PIDCommand(const char *name, double p, double i, double d, double period);
|
||||
PIDCommand(const char *name, double p, double i, double d, double f,
|
||||
PIDCommand(const std::string &name, double p, double i, double d);
|
||||
PIDCommand(const std::string &name, double p, double i, double d, double period);
|
||||
PIDCommand(const std::string &name, double p, double i, double d, double f,
|
||||
double perioid);
|
||||
PIDCommand(double p, double i, double d);
|
||||
PIDCommand(double p, double i, double d, double period);
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
*/
|
||||
class PIDSubsystem : public Subsystem, public PIDOutput, public PIDSource {
|
||||
public:
|
||||
PIDSubsystem(const char *name, double p, double i, double d);
|
||||
PIDSubsystem(const char *name, double p, double i, double d, double f);
|
||||
PIDSubsystem(const char *name, double p, double i, double d, double f,
|
||||
PIDSubsystem(const std::string &name, double p, double i, double d);
|
||||
PIDSubsystem(const std::string &name, double p, double i, double d, double f);
|
||||
PIDSubsystem(const std::string &name, double p, double i, double d, double f,
|
||||
double period);
|
||||
PIDSubsystem(double p, double i, double d);
|
||||
PIDSubsystem(double p, double i, double d, double f);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
class PrintCommand : public Command {
|
||||
public:
|
||||
PrintCommand(const char *message);
|
||||
PrintCommand(const std::string &message);
|
||||
virtual ~PrintCommand() = default;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -19,7 +19,7 @@ class Subsystem : public ErrorBase, public NamedSendable {
|
||||
friend class Scheduler;
|
||||
|
||||
public:
|
||||
Subsystem(const char *name);
|
||||
Subsystem(const std::string &name);
|
||||
virtual ~Subsystem() = default;
|
||||
|
||||
void SetDefaultCommand(Command *command);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
class WaitCommand : public Command {
|
||||
public:
|
||||
WaitCommand(double timeout);
|
||||
WaitCommand(const char *name, double timeout);
|
||||
WaitCommand(const std::string &name, double timeout);
|
||||
virtual ~WaitCommand() = default;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
class WaitForChildren : public Command {
|
||||
public:
|
||||
WaitForChildren(double timeout);
|
||||
WaitForChildren(const char *name, double timeout);
|
||||
WaitForChildren(const std::string &name, double timeout);
|
||||
virtual ~WaitForChildren() = default;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
class WaitUntilCommand : public Command {
|
||||
public:
|
||||
WaitUntilCommand(double time);
|
||||
WaitUntilCommand(const char *name, double time);
|
||||
WaitUntilCommand(const std::string &name, double time);
|
||||
virtual ~WaitUntilCommand() = default;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -35,16 +35,16 @@ class LiveWindow {
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; pass the component using shared_ptr "
|
||||
"instead.")]]
|
||||
void AddSensor(const char *subsystem, const char *name,
|
||||
void AddSensor(const std::string &subsystem, const std::string &name,
|
||||
LiveWindowSendable *component);
|
||||
void AddSensor(const char *subsystem, const char *name,
|
||||
void AddSensor(const std::string &subsystem, const std::string &name,
|
||||
::std::shared_ptr<LiveWindowSendable> component);
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; pass the component using shared_ptr "
|
||||
"instead.")]]
|
||||
void AddActuator(const char *subsystem, const char *name,
|
||||
void AddActuator(const std::string &subsystem, const std::string &name,
|
||||
LiveWindowSendable *component);
|
||||
void AddActuator(const char *subsystem, const char *name,
|
||||
void AddActuator(const std::string &subsystem, const std::string &name,
|
||||
::std::shared_ptr<LiveWindowSendable> component);
|
||||
void AddSensor(std::string type, int channel, LiveWindowSendable *component);
|
||||
void AddActuator(std::string type, int channel,
|
||||
|
||||
@@ -27,8 +27,8 @@ class Resource : public ErrorBase {
|
||||
virtual ~Resource() = default;
|
||||
static void CreateResourceObject(::std::unique_ptr<Resource>& r, uint32_t elements);
|
||||
explicit Resource(uint32_t size);
|
||||
uint32_t Allocate(const char *resourceDesc);
|
||||
uint32_t Allocate(uint32_t index, const char *resourceDesc);
|
||||
uint32_t Allocate(const std::string &resourceDesc);
|
||||
uint32_t Allocate(uint32_t index, const std::string &resourceDesc);
|
||||
void Free(uint32_t index);
|
||||
|
||||
private:
|
||||
|
||||
@@ -35,8 +35,8 @@ class SendableChooser : public Sendable {
|
||||
public:
|
||||
virtual ~SendableChooser() = default;
|
||||
|
||||
void AddObject(const char *name, void *object);
|
||||
void AddDefault(const char *name, void *object);
|
||||
void AddObject(const std::string &name, void *object);
|
||||
void AddDefault(const std::string &name, void *object);
|
||||
void *GetSelected();
|
||||
|
||||
virtual void InitTable(::std::shared_ptr<ITable> subtable);
|
||||
|
||||
@@ -28,7 +28,7 @@ class Task : public ErrorBase {
|
||||
Task& operator=(Task&& task);
|
||||
|
||||
template <class Function, class... Args>
|
||||
Task(const char* name, Function&& function, Args&&... args);
|
||||
Task(const std::string& name, Function&& function, Args&&... args);
|
||||
|
||||
virtual ~Task();
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
* @param stackSize The size of the stack for the task
|
||||
*/
|
||||
template <class Function, class... Args>
|
||||
Task::Task(const char* name, Function&& function, Args&&... args) {
|
||||
Task::Task(const std::string& name, Function&& function, Args&&... args) {
|
||||
m_taskName = "FRC_";
|
||||
m_taskName += name;
|
||||
|
||||
|
||||
@@ -14,33 +14,33 @@
|
||||
#include <string>
|
||||
|
||||
#define wpi_assert(condition) \
|
||||
wpi_assert_impl(condition, #condition, nullptr, __FILE__, __LINE__, __FUNCTION__)
|
||||
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, nullptr, __FILE__, __LINE__, __FUNCTION__)
|
||||
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, nullptr, __FILE__, __LINE__, __FUNCTION__)
|
||||
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__)
|
||||
|
||||
bool wpi_assert_impl(bool conditionValue, const char *conditionText,
|
||||
const char *message, const char *fileName,
|
||||
uint32_t lineNumber, const char *funcName);
|
||||
bool wpi_assertEqual_impl(int valueA, int valueB, const char *valueAString,
|
||||
const char *valueBString, const char *message,
|
||||
const char *fileName, uint32_t lineNumber,
|
||||
const char *funcName);
|
||||
bool wpi_assertNotEqual_impl(int valueA, int valueB, const char *valueAString,
|
||||
const char *valueBString, const char *message,
|
||||
const char *fileName, uint32_t lineNumber,
|
||||
const char *funcName);
|
||||
bool wpi_assert_impl(bool conditionValue, const std::string &conditionText,
|
||||
const std::string &message, const std::string &fileName,
|
||||
uint32_t lineNumber, const std::string &funcName);
|
||||
bool wpi_assertEqual_impl(int valueA, int valueB, const std::string &valueAString,
|
||||
const std::string &valueBString, const std::string &message,
|
||||
const std::string &fileName, uint32_t lineNumber,
|
||||
const std::string &funcName);
|
||||
bool wpi_assertNotEqual_impl(int valueA, int valueB, const std::string &valueAString,
|
||||
const std::string &valueBString, const std::string &message,
|
||||
const std::string &fileName, uint32_t lineNumber,
|
||||
const std::string &funcName);
|
||||
|
||||
void wpi_suspendOnAssertEnabled(bool enabled);
|
||||
|
||||
|
||||
@@ -10,11 +10,11 @@
|
||||
|
||||
#ifdef WPI_ERRORS_DEFINE_STRINGS
|
||||
#define S(label, offset, message) \
|
||||
const char *wpi_error_s_##label = message; \
|
||||
const char * wpi_error_s_##label = message; \
|
||||
const int32_t wpi_error_value_##label = offset
|
||||
#else
|
||||
#define S(label, offset, message) \
|
||||
extern const char *wpi_error_s_##label; \
|
||||
extern const char * wpi_error_s_##label; \
|
||||
const int32_t wpi_error_value_##label = offset
|
||||
#endif
|
||||
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
#include "Buttons/NetworkButton.h"
|
||||
#include "networktables/NetworkTable.h"
|
||||
|
||||
NetworkButton::NetworkButton(const char *tableName, const char *field)
|
||||
NetworkButton::NetworkButton(const std::string &tableName, const std::string &field)
|
||||
: // TODO how is this supposed to work???
|
||||
m_netTable(NetworkTable::GetTable(tableName)),
|
||||
m_field(field) {}
|
||||
|
||||
NetworkButton::NetworkButton(::std::shared_ptr<ITable> table, const char *field)
|
||||
NetworkButton::NetworkButton(::std::shared_ptr<ITable> table, const std::string &field)
|
||||
: m_netTable(table), m_field(field) {}
|
||||
|
||||
bool NetworkButton::Get() {
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
#include "WPIErrors.h"
|
||||
#include <typeinfo>
|
||||
|
||||
static const char *kName = "name";
|
||||
static const char *kRunning = "running";
|
||||
static const char *kIsParented = "isParented";
|
||||
static const std::string kName = "name";
|
||||
static const std::string kRunning = "running";
|
||||
static const std::string kIsParented = "isParented";
|
||||
|
||||
int Command::m_commandCounter = 0;
|
||||
|
||||
@@ -29,7 +29,7 @@ Command::Command() : Command(nullptr, -1.0) {}
|
||||
* Creates a new command with the given name and no timeout.
|
||||
* @param name the name for this command
|
||||
*/
|
||||
Command::Command(const char *name) : Command(name, -1.0) {}
|
||||
Command::Command(const std::string &name) : Command(name, -1.0) {}
|
||||
|
||||
/**
|
||||
* Creates a new command with the given timeout and a default name.
|
||||
@@ -44,13 +44,13 @@ Command::Command(double timeout) : Command(nullptr, timeout) {}
|
||||
* @param timeout the time (in seconds) before this command "times out"
|
||||
* @see Command#isTimedOut() isTimedOut()
|
||||
*/
|
||||
Command::Command(const char *name, double timeout) {
|
||||
if (name == nullptr) wpi_setWPIErrorWithContext(NullParameter, "name");
|
||||
Command::Command(const std::string &name, double timeout) {
|
||||
if (name.size() == 0) wpi_setWPIErrorWithContext(NullParameter, "name");
|
||||
if (timeout < 0.0)
|
||||
wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0");
|
||||
|
||||
m_timeout = timeout;
|
||||
m_name = name == nullptr ? std::string() : name;
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
Command::~Command() { // TODO deal with cleaning up all listeners
|
||||
@@ -218,12 +218,9 @@ void Command::LockChanges() { m_locked = true; }
|
||||
* message)
|
||||
* @return true if assert passed, false if assert failed
|
||||
*/
|
||||
bool Command::AssertUnlocked(const char *message) {
|
||||
bool Command::AssertUnlocked(const std::string &message) {
|
||||
if (m_locked) {
|
||||
char buf[128];
|
||||
snprintf(buf, 128,
|
||||
"%s after being started or being added to a command group",
|
||||
message);
|
||||
std::string buf = message + " after being started or being added to a command group";
|
||||
wpi_setWPIErrorWithContext(CommandIllegalUse, buf);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* Creates a new {@link CommandGroup CommandGroup} with the given name.
|
||||
* @param name the name for this command group
|
||||
*/
|
||||
CommandGroup::CommandGroup(const char *name) : Command(name) {}
|
||||
CommandGroup::CommandGroup(const std::string &name) : Command(name) {}
|
||||
|
||||
/**
|
||||
* Adds a new {@link Command Command} to the group. The {@link Command Command}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "PIDController.h"
|
||||
#include "float.h"
|
||||
|
||||
PIDCommand::PIDCommand(const char *name, double p, double i, double d, double f,
|
||||
PIDCommand::PIDCommand(const std::string &name, double p, double i, double d, double f,
|
||||
double period)
|
||||
: Command(name) {
|
||||
m_controller = std::make_unique<PIDController>(p, i, d, this, this, period);
|
||||
@@ -20,12 +20,12 @@ PIDCommand::PIDCommand(double p, double i, double d, double f, double period) {
|
||||
m_controller = std::make_unique<PIDController>(p, i, d, f, this, this, period);
|
||||
}
|
||||
|
||||
PIDCommand::PIDCommand(const char *name, double p, double i, double d)
|
||||
PIDCommand::PIDCommand(const std::string &name, double p, double i, double d)
|
||||
: Command(name) {
|
||||
m_controller = std::make_unique<PIDController>(p, i, d, this, this);
|
||||
}
|
||||
|
||||
PIDCommand::PIDCommand(const char *name, double p, double i, double d,
|
||||
PIDCommand::PIDCommand(const std::string &name, double p, double i, double d,
|
||||
double period)
|
||||
: Command(name) {
|
||||
m_controller = std::make_unique<PIDController>(p, i, d, this, this, period);
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
* @param i the integral value
|
||||
* @param d the derivative value
|
||||
*/
|
||||
PIDSubsystem::PIDSubsystem(const char *name, double p, double i, double d)
|
||||
PIDSubsystem::PIDSubsystem(const std::string &name, double p, double i, double d)
|
||||
: Subsystem(name) {
|
||||
m_controller = std::make_unique<PIDController>(p, i, d, this, this);
|
||||
}
|
||||
@@ -31,7 +31,7 @@ PIDSubsystem::PIDSubsystem(const char *name, double p, double i, double d)
|
||||
* @param d the derivative value
|
||||
* @param f the feedforward value
|
||||
*/
|
||||
PIDSubsystem::PIDSubsystem(const char *name, double p, double i, double d,
|
||||
PIDSubsystem::PIDSubsystem(const std::string &name, double p, double i, double d,
|
||||
double f)
|
||||
: Subsystem(name) {
|
||||
m_controller = std::make_unique<PIDController>(p, i, d, f, this, this);
|
||||
@@ -48,7 +48,7 @@ PIDSubsystem::PIDSubsystem(const char *name, double p, double i, double d,
|
||||
* @param f the feedfoward value
|
||||
* @param period the time (in seconds) between calculations
|
||||
*/
|
||||
PIDSubsystem::PIDSubsystem(const char *name, double p, double i, double d,
|
||||
PIDSubsystem::PIDSubsystem(const std::string &name, double p, double i, double d,
|
||||
double f, double period)
|
||||
: Subsystem(name) {
|
||||
m_controller = std::make_unique<PIDController>(p, i, d, f, this, this, period);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "stdio.h"
|
||||
#include <sstream>
|
||||
|
||||
PrintCommand::PrintCommand(const char *message)
|
||||
PrintCommand::PrintCommand(const std::string &message)
|
||||
: Command(((std::stringstream &)(std::stringstream("Print \"") << message
|
||||
<< "\""))
|
||||
.str()
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* Creates a subsystem with the given name
|
||||
* @param name the name of the subsystem
|
||||
*/
|
||||
Subsystem::Subsystem(const char *name) {
|
||||
Subsystem::Subsystem(const std::string &name) {
|
||||
m_name = name;
|
||||
Scheduler::GetInstance().RegisterSubsystem(this);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ WaitCommand::WaitCommand(double timeout)
|
||||
.c_str(),
|
||||
timeout) {}
|
||||
|
||||
WaitCommand::WaitCommand(const char *name, double timeout)
|
||||
WaitCommand::WaitCommand(const std::string &name, double timeout)
|
||||
: Command(name, timeout) {}
|
||||
|
||||
void WaitCommand::Initialize() {}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
WaitForChildren::WaitForChildren(double timeout)
|
||||
: Command("WaitForChildren", timeout) {}
|
||||
|
||||
WaitForChildren::WaitForChildren(const char *name, double timeout)
|
||||
WaitForChildren::WaitForChildren(const std::string &name, double timeout)
|
||||
: Command(name, timeout) {}
|
||||
|
||||
void WaitForChildren::Initialize() {}
|
||||
|
||||
@@ -19,7 +19,7 @@ WaitUntilCommand::WaitUntilCommand(double time)
|
||||
m_time = time;
|
||||
}
|
||||
|
||||
WaitUntilCommand::WaitUntilCommand(const char *name, double time)
|
||||
WaitUntilCommand::WaitUntilCommand(const std::string &name, double time)
|
||||
: Command(name, time) {
|
||||
m_time = time;
|
||||
}
|
||||
|
||||
@@ -56,14 +56,17 @@ void LiveWindow::SetEnabled(bool enabled) {
|
||||
* @param name The name of this component.
|
||||
* @param component A LiveWindowSendable component that represents a sensor.
|
||||
*/
|
||||
void LiveWindow::AddSensor(const char *subsystem, const char *name,
|
||||
void LiveWindow::AddSensor(const std::string &subsystem, const std::string &name,
|
||||
::std::shared_ptr<LiveWindowSendable> component) {
|
||||
m_components[component].subsystem = subsystem;
|
||||
m_components[component].name = name;
|
||||
m_components[component].isSensor = true;
|
||||
}
|
||||
|
||||
void LiveWindow::AddSensor(const char *subsystem, const char *name, LiveWindowSendable *component) {
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; pass the component using shared_ptr "
|
||||
"instead.")]]
|
||||
void LiveWindow::AddSensor(const std::string &subsystem, const std::string &name, LiveWindowSendable *component) {
|
||||
AddSensor(subsystem, name, ::std::shared_ptr<LiveWindowSendable>(
|
||||
component, NullDeleter<LiveWindowSendable>()));
|
||||
}
|
||||
@@ -75,14 +78,17 @@ void LiveWindow::AddSensor(const char *subsystem, const char *name, LiveWindowSe
|
||||
* @param name The name of this component.
|
||||
* @param component A LiveWindowSendable component that represents a actuator.
|
||||
*/
|
||||
void LiveWindow::AddActuator(const char *subsystem, const char *name,
|
||||
void LiveWindow::AddActuator(const std::string &subsystem, const std::string &name,
|
||||
::std::shared_ptr<LiveWindowSendable> component) {
|
||||
m_components[component].subsystem = subsystem;
|
||||
m_components[component].name = name;
|
||||
m_components[component].isSensor = false;
|
||||
}
|
||||
|
||||
void LiveWindow::AddActuator(const char *subsystem, const char *name,
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; pass the component using shared_ptr "
|
||||
"instead.")]]
|
||||
void LiveWindow::AddActuator(const std::string &subsystem, const std::string &name,
|
||||
LiveWindowSendable *component) {
|
||||
AddActuator(subsystem, name,
|
||||
::std::shared_ptr<LiveWindowSendable>(
|
||||
|
||||
@@ -47,7 +47,7 @@ Resource::Resource(uint32_t elements) {
|
||||
* resource value
|
||||
* within the range is located and returned after it is marked allocated.
|
||||
*/
|
||||
uint32_t Resource::Allocate(const char *resourceDesc) {
|
||||
uint32_t Resource::Allocate(const std::string &resourceDesc) {
|
||||
std::unique_lock<priority_recursive_mutex> sync(m_allocateLock);
|
||||
for (uint32_t i = 0; i < m_isAllocated.size(); i++) {
|
||||
if (!m_isAllocated[i]) {
|
||||
@@ -65,7 +65,7 @@ uint32_t Resource::Allocate(const char *resourceDesc) {
|
||||
* verified
|
||||
* unallocated, then returned.
|
||||
*/
|
||||
uint32_t Resource::Allocate(uint32_t index, const char *resourceDesc) {
|
||||
uint32_t Resource::Allocate(uint32_t index, const std::string &resourceDesc) {
|
||||
std::unique_lock<priority_recursive_mutex> sync(m_allocateLock);
|
||||
if (index >= m_isAllocated.size()) {
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, resourceDesc);
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static const char *kDefault = "default";
|
||||
static const char *kOptions = "options";
|
||||
static const char *kSelected = "selected";
|
||||
static const std::string kDefault = "default";
|
||||
static const std::string kOptions = "options";
|
||||
static const std::string kSelected = "selected";
|
||||
|
||||
/**
|
||||
* Adds the given object to the list of options. On the {@link SmartDashboard}
|
||||
@@ -21,7 +21,7 @@ static const char *kSelected = "selected";
|
||||
* @param name the name of the option
|
||||
* @param object the option
|
||||
*/
|
||||
void SendableChooser::AddObject(const char *name, void *object) {
|
||||
void SendableChooser::AddObject(const std::string &name, void *object) {
|
||||
m_choices[name] = object;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ void SendableChooser::AddObject(const char *name, void *object) {
|
||||
* @param name the name of the option
|
||||
* @param object the option
|
||||
*/
|
||||
void SendableChooser::AddDefault(const char *name, void *object) {
|
||||
void SendableChooser::AddDefault(const std::string &name, void *object) {
|
||||
m_defaultChoice = name;
|
||||
AddObject(name, object);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class SerialPort : public ErrorBase {
|
||||
void DisableTermination();
|
||||
int32_t GetBytesReceived();
|
||||
uint32_t Read(char *buffer, int32_t count);
|
||||
uint32_t Write(const char *buffer, int32_t count);
|
||||
uint32_t Write(const std::string &buffer, int32_t count);
|
||||
void SetTimeout(float timeout);
|
||||
void SetReadBufferSize(uint32_t size);
|
||||
void SetWriteBufferSize(uint32_t size);
|
||||
|
||||
@@ -39,6 +39,11 @@ AnalogAccelerometer::AnalogAccelerometer(int32_t channel) {
|
||||
* @param channel The existing AnalogInput object for the analog input the
|
||||
* accelerometer is connected to
|
||||
*/
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; if you just want to construct an "
|
||||
"AnalogAccelerometer with its own AnalogInput, then call the "
|
||||
"AnalogAccelerometer(int channel). If you want to keep your own copy of "
|
||||
"the AnalogInput, use std::shared_ptr.")]]
|
||||
AnalogAccelerometer::AnalogAccelerometer(AnalogInput *channel)
|
||||
: m_analogInput(channel, NullDeleter<AnalogInput>()) {
|
||||
if (channel == nullptr) {
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include "WPIErrors.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
static ::std::unique_ptr<Resource> inputs;
|
||||
|
||||
const uint8_t AnalogInput::kAccumulatorModuleNumber;
|
||||
@@ -24,17 +26,16 @@ const uint32_t AnalogInput::kAccumulatorChannels[] = {0, 1};
|
||||
* on-board 4-7 are on the MXP port.
|
||||
*/
|
||||
AnalogInput::AnalogInput(uint32_t channel) {
|
||||
char buf[64];
|
||||
std::stringstream buf;
|
||||
buf << "Analog Input " << channel;
|
||||
Resource::CreateResourceObject(inputs, kAnalogInputs);
|
||||
|
||||
if (!checkAnalogInputChannel(channel)) {
|
||||
snprintf(buf, 64, "analog input %d", channel);
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf);
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
return;
|
||||
}
|
||||
|
||||
snprintf(buf, 64, "Analog Input %d", channel);
|
||||
if (inputs->Allocate(channel, buf) == ~0ul) {
|
||||
if (inputs->Allocate(channel, buf.str()) == ~0ul) {
|
||||
CloneError(*inputs);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "WPIErrors.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
static ::std::unique_ptr<Resource> outputs;
|
||||
|
||||
/**
|
||||
@@ -20,15 +22,15 @@ static ::std::unique_ptr<Resource> outputs;
|
||||
AnalogOutput::AnalogOutput(uint32_t channel) {
|
||||
Resource::CreateResourceObject(outputs, kAnalogOutputs);
|
||||
|
||||
char buf[64];
|
||||
std::stringstream buf;
|
||||
buf << "analog input " << channel;
|
||||
|
||||
if (!checkAnalogOutputChannel(channel)) {
|
||||
snprintf(buf, 64, "analog input %d", channel);
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf);
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (outputs->Allocate(channel, buf) == ~0ul) {
|
||||
if (outputs->Allocate(channel, buf.str()) == ~0ul) {
|
||||
CloneError(*outputs);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,11 @@ AnalogPotentiometer::AnalogPotentiometer(int channel, double fullRange,
|
||||
* @param offset The angular value (in desired units) representing the angular
|
||||
* output at 0V.
|
||||
*/
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; if you just want to construct an "
|
||||
"AnalogPotentiometer with its own AnalogInput, then call the "
|
||||
"AnalogPotentiometer(int channel). If you want to keep your own copy of "
|
||||
"the AnalogInput, use std::shared_ptr.")]]
|
||||
AnalogPotentiometer::AnalogPotentiometer(AnalogInput *input, double fullRange,
|
||||
double offset)
|
||||
: m_analog_input(input, NullDeleter<AnalogInput>()),
|
||||
|
||||
@@ -111,10 +111,10 @@ void CANJaguar::InitCANJaguar() {
|
||||
m_hardwareVersion = dataBuffer[0];
|
||||
|
||||
if (m_deviceNumber < 1 || m_deviceNumber > 63) {
|
||||
char buf[256];
|
||||
snprintf(buf, 256, "device number \"%d\" must be between 1 and 63",
|
||||
m_deviceNumber);
|
||||
wpi_setWPIErrorWithContext(ParameterOutOfRange, buf);
|
||||
std::stringstream buf;
|
||||
buf << "device number \"" << m_deviceNumber
|
||||
<< "\" must be between 1 and 63";
|
||||
wpi_setWPIErrorWithContext(ParameterOutOfRange, buf.str());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -122,19 +122,17 @@ void CANJaguar::InitCANJaguar() {
|
||||
|
||||
// 3330 was the first shipping RDK firmware version for the Jaguar
|
||||
if (m_firmwareVersion >= 3330 || m_firmwareVersion < 108) {
|
||||
char buf[256];
|
||||
std::stringstream buf;
|
||||
if (m_firmwareVersion < 3330) {
|
||||
snprintf(buf, 256,
|
||||
"Jag #%d firmware (%d) is too old (must be at least version 108 "
|
||||
"of the FIRST approved firmware)",
|
||||
m_deviceNumber, m_firmwareVersion);
|
||||
buf << "Jag #" << m_deviceNumber << " firmware (" << m_firmwareVersion
|
||||
<< ") is too old (must be at least version 108 "
|
||||
"of the FIRST approved firmware)";
|
||||
} else {
|
||||
snprintf(buf, 256,
|
||||
"Jag #%d firmware (%d) is not FIRST approved (must be at least "
|
||||
"version 108 of the FIRST approved firmware)",
|
||||
m_deviceNumber, m_firmwareVersion);
|
||||
buf << "Jag #" << m_deviceNumber << " firmware (" << m_firmwareVersion
|
||||
<< ") is not FIRST approved (must be at least "
|
||||
"version 108 of the FIRST approved firmware)";
|
||||
}
|
||||
wpi_setWPIErrorWithContext(JaguarVersionError, buf);
|
||||
wpi_setWPIErrorWithContext(JaguarVersionError, buf.str());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -178,11 +176,11 @@ void CANJaguar::InitCANJaguar() {
|
||||
*/
|
||||
CANJaguar::CANJaguar(uint8_t deviceNumber)
|
||||
: m_deviceNumber(deviceNumber) {
|
||||
char buf[64];
|
||||
snprintf(buf, 64, "CANJaguar device number %d", m_deviceNumber);
|
||||
std::stringstream buf;
|
||||
buf << "CANJaguar device number " << m_deviceNumber;
|
||||
Resource::CreateResourceObject(allocated, 63);
|
||||
|
||||
if (allocated->Allocate(m_deviceNumber - 1, buf) == ~0ul) {
|
||||
if (allocated->Allocate(m_deviceNumber - 1, buf.str()) == ~0ul) {
|
||||
CloneError(*allocated);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,10 @@ Counter::Counter(Mode mode) {
|
||||
* @param source A pointer to the existing DigitalSource object. It will be set
|
||||
* as the Up Source.
|
||||
*/
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; if you just want to construct a Counter with "
|
||||
"its own DigitalSource, then call the Counter(int channel). If you want to "
|
||||
"keep your own copy of the DigitalSource, use std::shared_ptr.")]]
|
||||
Counter::Counter(DigitalSource *source) : Counter() {
|
||||
SetUpSource(source);
|
||||
ClearDownSource();
|
||||
@@ -89,6 +93,8 @@ Counter::Counter(int32_t channel) : Counter() {
|
||||
* The counter will start counting immediately.
|
||||
* @param trigger The pointer to the existing AnalogTrigger object.
|
||||
*/
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated. Use pass-by-reference instead.")]]
|
||||
Counter::Counter(AnalogTrigger *trigger) : Counter() {
|
||||
SetUpSource(trigger->CreateOutput(kState));
|
||||
ClearDownSource();
|
||||
@@ -115,6 +121,8 @@ Counter::Counter(const AnalogTrigger &trigger) : Counter() {
|
||||
* @param downSource The pointer to the DigitalSource to set as the down source
|
||||
* @param inverted True to invert the output (reverse the direction)
|
||||
*/
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; prefer to use shared_ptr instead.")]]
|
||||
Counter::Counter(EncodingType encodingType, DigitalSource *upSource,
|
||||
DigitalSource *downSource, bool inverted)
|
||||
: Counter(encodingType,
|
||||
@@ -185,6 +193,9 @@ void Counter::SetUpSource(int32_t channel) {
|
||||
* @param analogTrigger The analog trigger object that is used for the Up Source
|
||||
* @param triggerType The analog trigger output that will trigger the counter.
|
||||
*/
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; prefer to call either SetUpSource(int) or "
|
||||
"SetUpSource(shared_ptr).")]]
|
||||
void Counter::SetUpSource(AnalogTrigger *analogTrigger,
|
||||
AnalogTriggerType triggerType) {
|
||||
SetUpSource(::std::shared_ptr<AnalogTrigger>(analogTrigger,
|
||||
@@ -221,6 +232,7 @@ void Counter::SetUpSource(::std::shared_ptr<DigitalSource> source) {
|
||||
}
|
||||
}
|
||||
|
||||
[[deprecated("Raw pointers are deprecated. Use std::shared_ptr instead.")]]
|
||||
void Counter::SetUpSource(DigitalSource *source) {
|
||||
SetUpSource(
|
||||
::std::shared_ptr<DigitalSource>(source, NullDeleter<DigitalSource>()));
|
||||
@@ -231,6 +243,7 @@ void Counter::SetUpSource(DigitalSource *source) {
|
||||
* Set the up counting DigitalSource.
|
||||
* @param source Reference to the DigitalSource object to set as the up source
|
||||
*/
|
||||
[[deprecated("References are deprecated. Use std::shared_ptr instead.")]]
|
||||
void Counter::SetUpSource(DigitalSource &source) {
|
||||
SetUpSource(
|
||||
::std::shared_ptr<DigitalSource>(&source, NullDeleter<DigitalSource>()));
|
||||
@@ -281,6 +294,9 @@ void Counter::SetDownSource(int32_t channel) {
|
||||
* Source
|
||||
* @param triggerType The analog trigger output that will trigger the counter.
|
||||
*/
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; prefer to call either SetUpSource(int) or "
|
||||
"SetUpSource(shared_ptr).")]]
|
||||
void Counter::SetDownSource(AnalogTrigger *analogTrigger,
|
||||
AnalogTriggerType triggerType) {
|
||||
SetDownSource(::std::shared_ptr<AnalogTrigger>(analogTrigger, NullDeleter<AnalogTrigger>()), triggerType);
|
||||
@@ -316,6 +332,7 @@ void Counter::SetDownSource(::std::shared_ptr<DigitalSource> source) {
|
||||
}
|
||||
}
|
||||
|
||||
[[deprecated("Raw pointers are deprecated. Use std::shared_ptr instead.")]]
|
||||
void Counter::SetDownSource(DigitalSource *source) {
|
||||
SetDownSource(::std::shared_ptr<DigitalSource>(source, NullDeleter<DigitalSource>()));
|
||||
}
|
||||
@@ -325,6 +342,7 @@ void Counter::SetDownSource(DigitalSource *source) {
|
||||
* Set the down counting DigitalSource.
|
||||
* @param source Reference to the DigitalSource object to set as the down source
|
||||
*/
|
||||
[[deprecated("References are deprecated. Use std::shared_ptr instead.")]]
|
||||
void Counter::SetDownSource(DigitalSource &source) {
|
||||
SetDownSource(::std::shared_ptr<DigitalSource>(&source, NullDeleter<DigitalSource>()));
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include "WPIErrors.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
/**
|
||||
* Create an instance of a Digital Input class.
|
||||
* Creates a digital input given a channel.
|
||||
@@ -18,11 +20,11 @@
|
||||
* @param channel The DIO channel 0-9 are on-board, 10-25 are on the MXP port
|
||||
*/
|
||||
DigitalInput::DigitalInput(uint32_t channel) {
|
||||
char buf[64];
|
||||
std::stringstream buf;
|
||||
|
||||
if (!CheckDigitalChannel(channel)) {
|
||||
snprintf(buf, 64, "Digital Channel %d", channel);
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf);
|
||||
buf << "Digital Channel " << channel;
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
return;
|
||||
}
|
||||
m_channel = channel;
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "Resource.h"
|
||||
#include "WPIErrors.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
/**
|
||||
* Create an instance of a digital output.
|
||||
* Create a digital output given a channel.
|
||||
@@ -17,11 +19,11 @@
|
||||
* port
|
||||
*/
|
||||
DigitalOutput::DigitalOutput(uint32_t channel) {
|
||||
char buf[64];
|
||||
std::stringstream buf;
|
||||
|
||||
if (!CheckDigitalChannel(channel)) {
|
||||
snprintf(buf, 64, "Digital Channel %d", channel);
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf);
|
||||
buf << "Digital Channel " << channel;
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
return;
|
||||
}
|
||||
m_channel = channel;
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "WPIErrors.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
::std::unique_ptr<Resource> SolenoidBase::m_allocated =
|
||||
::std::make_unique<Resource>(solenoid_kNumDO7_0Elements *
|
||||
kSolenoidChannels);
|
||||
@@ -34,37 +36,39 @@ DoubleSolenoid::DoubleSolenoid(uint8_t moduleNumber, uint32_t forwardChannel,
|
||||
: SolenoidBase(moduleNumber),
|
||||
m_forwardChannel(forwardChannel),
|
||||
m_reverseChannel(reverseChannel) {
|
||||
char buf[64];
|
||||
std::stringstream buf;
|
||||
if (!CheckSolenoidModule(m_moduleNumber)) {
|
||||
snprintf(buf, 64, "Solenoid Module %d", m_moduleNumber);
|
||||
wpi_setWPIErrorWithContext(ModuleIndexOutOfRange, buf);
|
||||
buf << "Solenoid Module " << m_moduleNumber;
|
||||
wpi_setWPIErrorWithContext(ModuleIndexOutOfRange, buf.str());
|
||||
return;
|
||||
}
|
||||
if (!CheckSolenoidChannel(m_forwardChannel)) {
|
||||
snprintf(buf, 64, "Solenoid Channel %d", m_forwardChannel);
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf);
|
||||
buf << "Solenoid Module " << m_forwardChannel;
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
return;
|
||||
}
|
||||
if (!CheckSolenoidChannel(m_reverseChannel)) {
|
||||
snprintf(buf, 64, "Solenoid Channel %d", m_reverseChannel);
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf);
|
||||
buf << "Solenoid Module " << m_reverseChannel;
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
return;
|
||||
}
|
||||
Resource::CreateResourceObject(
|
||||
m_allocated, solenoid_kNumDO7_0Elements * kSolenoidChannels);
|
||||
|
||||
snprintf(buf, 64, "Solenoid %d (Module: %d)", m_forwardChannel,
|
||||
m_moduleNumber);
|
||||
buf << "Solenoid " << m_forwardChannel << " (Module: " << m_moduleNumber
|
||||
<< ")";
|
||||
if (m_allocated->Allocate(
|
||||
m_moduleNumber * kSolenoidChannels + m_forwardChannel, buf) == ~0ul) {
|
||||
m_moduleNumber * kSolenoidChannels + m_forwardChannel, buf.str()) ==
|
||||
~0ul) {
|
||||
CloneError(*m_allocated);
|
||||
return;
|
||||
}
|
||||
|
||||
snprintf(buf, 64, "Solenoid %d (Module: %d)", m_reverseChannel,
|
||||
m_moduleNumber);
|
||||
buf << "Solenoid " << m_reverseChannel << " (Module: " << m_moduleNumber
|
||||
<< ")";
|
||||
if (m_allocated->Allocate(
|
||||
m_moduleNumber * kSolenoidChannels + m_reverseChannel, buf) == ~0ul) {
|
||||
m_moduleNumber * kSolenoidChannels + m_reverseChannel, buf.str()) ==
|
||||
~0ul) {
|
||||
CloneError(*m_allocated);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -125,6 +125,10 @@ Encoder::Encoder(uint32_t aChannel, uint32_t bChannel, bool reverseDirection,
|
||||
* match the spec'd count
|
||||
* or be double (2x) the spec'd count.
|
||||
*/
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; if you wish to construct your own copy of "
|
||||
"the DigitalSource and pass it to the constructor, use an std::shared_ptr "
|
||||
"instead.")]]
|
||||
Encoder::Encoder(DigitalSource *aSource, DigitalSource *bSource,
|
||||
bool reverseDirection, EncodingType encodingType)
|
||||
: m_aSource(aSource, NullDeleter<DigitalSource>()),
|
||||
@@ -170,6 +174,10 @@ Encoder::Encoder(::std::shared_ptr<DigitalSource> aSource,
|
||||
* match the spec'd count
|
||||
* or be double (2x) the spec'd count.
|
||||
*/
|
||||
[[deprecated(
|
||||
"References are deprecated; if you wish to construct your own copy of "
|
||||
"the DigitalSource and pass it to the constructor, use an std::shared_ptr "
|
||||
"instead.")]]
|
||||
Encoder::Encoder(DigitalSource &aSource, DigitalSource &bSource,
|
||||
bool reverseDirection, EncodingType encodingType)
|
||||
: m_aSource(&aSource, NullDeleter<DigitalSource>()),
|
||||
@@ -520,6 +528,7 @@ void Encoder::SetIndexSource(uint32_t channel, Encoder::IndexingType type) {
|
||||
* @param channel A digital source to set as the encoder index
|
||||
* @param type The state that will cause the encoder to reset
|
||||
*/
|
||||
[[deprecated("Raw pointers are dperecated; use references instead.")]]
|
||||
void Encoder::SetIndexSource(DigitalSource *source,
|
||||
Encoder::IndexingType type) {
|
||||
SetIndexSource(*source, type);
|
||||
|
||||
@@ -88,6 +88,9 @@ Gyro::Gyro(int32_t channel) {
|
||||
* @param channel A pointer to the AnalogInput object that the gyro is connected
|
||||
* to.
|
||||
*/
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; consider calling the Gyro constructor with "
|
||||
"a channel number or passing a shared_ptr instead.")]]
|
||||
Gyro::Gyro(AnalogInput *channel)
|
||||
: Gyro(::std::shared_ptr<AnalogInput>(channel,
|
||||
NullDeleter<AnalogInput>())) {}
|
||||
|
||||
@@ -13,12 +13,12 @@
|
||||
#include <vector>
|
||||
#include "HAL/HAL.hpp"
|
||||
|
||||
static const char *kP = "p";
|
||||
static const char *kI = "i";
|
||||
static const char *kD = "d";
|
||||
static const char *kF = "f";
|
||||
static const char *kSetpoint = "setpoint";
|
||||
static const char *kEnabled = "enabled";
|
||||
static const std::string kP = "p";
|
||||
static const std::string kI = "i";
|
||||
static const std::string kD = "d";
|
||||
static const std::string kF = "f";
|
||||
static const std::string kSetpoint = "setpoint";
|
||||
static const std::string kEnabled = "enabled";
|
||||
|
||||
/**
|
||||
* Allocate a PID object with the given constants for P, I, D
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include "WPIErrors.h"
|
||||
#include "HAL/HAL.hpp"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
constexpr float PWM::kDefaultPwmPeriod;
|
||||
constexpr float PWM::kDefaultPwmCenter;
|
||||
const int32_t PWM::kDefaultPwmStepsDown;
|
||||
@@ -28,11 +30,11 @@ const int32_t PWM::kPwmDisabled;
|
||||
* port
|
||||
*/
|
||||
PWM::PWM(uint32_t channel) {
|
||||
char buf[64];
|
||||
std::stringstream buf;
|
||||
|
||||
if (!CheckPWMChannel(channel)) {
|
||||
snprintf(buf, 64, "PWM Channel %d", channel);
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf);
|
||||
buf << "PWM Channel " << channel;
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "HAL/PDP.hpp"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
PowerDistributionPanel::PowerDistributionPanel() : PowerDistributionPanel(0) {}
|
||||
|
||||
/**
|
||||
@@ -60,9 +62,9 @@ double PowerDistributionPanel::GetCurrent(uint8_t channel) const {
|
||||
int32_t status = 0;
|
||||
|
||||
if (!CheckPDPChannel(channel)) {
|
||||
char buf[64];
|
||||
snprintf(buf, 64, "PDP Channel %d", channel);
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf);
|
||||
std::stringstream buf;
|
||||
buf << "PDP Channel " << channel;
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
}
|
||||
|
||||
double current = getPDPChannelCurrent(channel, &status, m_module);
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
#include "HAL/HAL.hpp"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
// Allocate each direction separately.
|
||||
static ::std::unique_ptr<Resource> relayChannels;
|
||||
|
||||
@@ -27,18 +29,18 @@ static ::std::unique_ptr<Resource> relayChannels;
|
||||
*/
|
||||
Relay::Relay(uint32_t channel, Relay::Direction direction)
|
||||
: m_channel(channel), m_direction(direction) {
|
||||
char buf[64];
|
||||
std::stringstream buf;
|
||||
Resource::CreateResourceObject(relayChannels,
|
||||
dio_kNumSystems * kRelayChannels * 2);
|
||||
if (!SensorBase::CheckRelayChannel(m_channel)) {
|
||||
snprintf(buf, 64, "Relay Channel %d", m_channel);
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf);
|
||||
buf << "Relay Channel " << m_channel;
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_direction == kBothDirections || m_direction == kForwardOnly) {
|
||||
snprintf(buf, 64, "Forward Relay %d", m_channel);
|
||||
if (relayChannels->Allocate(m_channel * 2, buf) == ~0ul) {
|
||||
buf << "Forward Relay " << m_channel;
|
||||
if (relayChannels->Allocate(m_channel * 2, buf.str()) == ~0ul) {
|
||||
CloneError(*relayChannels);
|
||||
return;
|
||||
}
|
||||
@@ -46,8 +48,8 @@ Relay::Relay(uint32_t channel, Relay::Direction direction)
|
||||
HALReport(HALUsageReporting::kResourceType_Relay, m_channel);
|
||||
}
|
||||
if (m_direction == kBothDirections || m_direction == kReverseOnly) {
|
||||
snprintf(buf, 64, "Reverse Relay %d", m_channel);
|
||||
if (relayChannels->Allocate(m_channel * 2 + 1, buf) == ~0ul) {
|
||||
buf << "Reverse Relay " << m_channel;
|
||||
if (relayChannels->Allocate(m_channel * 2 + 1, buf.str()) == ~0ul) {
|
||||
CloneError(*relayChannels);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -98,6 +98,7 @@ RobotDrive::RobotDrive(uint32_t frontLeftMotor, uint32_t rearLeftMotor,
|
||||
* @param leftMotor The left SpeedController object used to drive the robot.
|
||||
* @param rightMotor the right SpeedController object used to drive the robot.
|
||||
*/
|
||||
[[deprecated("Raw pointers are deprecated; use shared_ptr instead.")]]
|
||||
RobotDrive::RobotDrive(SpeedController *leftMotor,
|
||||
SpeedController *rightMotor) {
|
||||
InitRobotDrive();
|
||||
@@ -111,6 +112,7 @@ RobotDrive::RobotDrive(SpeedController *leftMotor,
|
||||
}
|
||||
|
||||
//TODO: Change to rvalue references & move syntax.
|
||||
[[deprecated("References are deprecated; use shared_ptr instead.")]]
|
||||
RobotDrive::RobotDrive(SpeedController &leftMotor,
|
||||
SpeedController &rightMotor) {
|
||||
InitRobotDrive();
|
||||
@@ -143,6 +145,7 @@ RobotDrive::RobotDrive(::std::shared_ptr<SpeedController> leftMotor,
|
||||
* @param frontRightMotor The front right SpeedController object used to drive
|
||||
* the robot.
|
||||
*/
|
||||
[[deprecated("Raw pointers are deprecated; use shared_ptr instead.")]]
|
||||
RobotDrive::RobotDrive(SpeedController *frontLeftMotor,
|
||||
SpeedController *rearLeftMotor,
|
||||
SpeedController *frontRightMotor,
|
||||
@@ -159,6 +162,7 @@ RobotDrive::RobotDrive(SpeedController *frontLeftMotor,
|
||||
m_rearRightMotor = make_shared_nodelete(rearRightMotor);
|
||||
}
|
||||
|
||||
[[deprecated("References are deprecated; use shared_ptr instead.")]]
|
||||
RobotDrive::RobotDrive(SpeedController &frontLeftMotor,
|
||||
SpeedController &rearLeftMotor,
|
||||
SpeedController &frontRightMotor,
|
||||
|
||||
@@ -135,9 +135,9 @@ uint32_t SerialPort::Read(char *buffer, int32_t count) {
|
||||
* @param count The maximum number of bytes to write.
|
||||
* @return The number of bytes actually written into the port.
|
||||
*/
|
||||
uint32_t SerialPort::Write(const char *buffer, int32_t count) {
|
||||
uint32_t SerialPort::Write(const std::string &buffer, int32_t count) {
|
||||
int32_t status = 0;
|
||||
int32_t retVal = serialWrite(m_port, buffer, count, &status);
|
||||
int32_t retVal = serialWrite(m_port, buffer.c_str(), count, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "WPIErrors.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
/**
|
||||
* Constructor using the default PCM ID (0).
|
||||
*
|
||||
@@ -26,22 +28,22 @@ Solenoid::Solenoid(uint32_t channel)
|
||||
*/
|
||||
Solenoid::Solenoid(uint8_t moduleNumber, uint32_t channel)
|
||||
: SolenoidBase(moduleNumber), m_channel(channel) {
|
||||
char buf[64];
|
||||
std::stringstream buf;
|
||||
if (!CheckSolenoidModule(m_moduleNumber)) {
|
||||
snprintf(buf, 64, "Solenoid Module %d", m_moduleNumber);
|
||||
wpi_setWPIErrorWithContext(ModuleIndexOutOfRange, buf);
|
||||
buf << "Solenoid Module " << m_moduleNumber;
|
||||
wpi_setWPIErrorWithContext(ModuleIndexOutOfRange, buf.str());
|
||||
return;
|
||||
}
|
||||
if (!CheckSolenoidChannel(m_channel)) {
|
||||
snprintf(buf, 64, "Solenoid Channel %d", m_channel);
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf);
|
||||
buf << "Solenoid Module " << m_channel;
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
return;
|
||||
}
|
||||
Resource::CreateResourceObject(m_allocated, kSolenoidChannels * 63);
|
||||
|
||||
snprintf(buf, 64, "Solenoid %d (Module: %d)", m_channel, m_moduleNumber);
|
||||
buf << "Solenoid " << m_channel << " (Module: " << m_moduleNumber << ")";
|
||||
if (m_allocated->Allocate(m_moduleNumber * kSolenoidChannels + m_channel,
|
||||
buf) == ~0ul) {
|
||||
buf.str()) == ~0ul) {
|
||||
CloneError(*m_allocated);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ bool Task::SetPriority(int32_t priority) {
|
||||
|
||||
/**
|
||||
* Returns the name of the task.
|
||||
* @returns Pointer to the name of the task or nullptr if not allocated
|
||||
* @returns The name of the task (0 length if not allocated).
|
||||
*/
|
||||
std::string Task::GetName() const { return m_taskName; }
|
||||
|
||||
|
||||
@@ -116,6 +116,9 @@ Ultrasonic::Ultrasonic(uint32_t pingChannel, uint32_t echoChannel,
|
||||
* determine the range.
|
||||
* @param units The units returned in either kInches or kMilliMeters
|
||||
*/
|
||||
[[deprecated(
|
||||
"Raw pointers are deprecated; prefer either specifying the channel numbers "
|
||||
"as integers or passing shared_ptrs.")]]
|
||||
Ultrasonic::Ultrasonic(DigitalOutput *pingChannel, DigitalInput *echoChannel,
|
||||
DistanceUnit units)
|
||||
: m_pingChannel(pingChannel, NullDeleter<DigitalOutput>()),
|
||||
@@ -139,6 +142,9 @@ Ultrasonic::Ultrasonic(DigitalOutput *pingChannel, DigitalInput *echoChannel,
|
||||
* determine the range.
|
||||
* @param units The units returned in either kInches or kMilliMeters
|
||||
*/
|
||||
[[deprecated(
|
||||
"References are deprecated; prefer either specifying the channel numbers "
|
||||
"as integers or passing shared_ptrs.")]]
|
||||
Ultrasonic::Ultrasonic(DigitalOutput &pingChannel, DigitalInput &echoChannel,
|
||||
DistanceUnit units)
|
||||
: m_pingChannel(&pingChannel, NullDeleter<DigitalOutput>()),
|
||||
|
||||
@@ -25,17 +25,17 @@
|
||||
* The users don't call this, but instead use the wpi_assert macros in
|
||||
* Utility.h.
|
||||
*/
|
||||
bool wpi_assert_impl(bool conditionValue, const char *conditionText,
|
||||
const char *message, const char *fileName,
|
||||
uint32_t lineNumber, const char *funcName) {
|
||||
bool wpi_assert_impl(bool conditionValue, const std::string &conditionText,
|
||||
const std::string &message, const std::string &fileName,
|
||||
uint32_t lineNumber, const std::string &funcName) {
|
||||
if (!conditionValue) {
|
||||
std::stringstream errorStream;
|
||||
|
||||
errorStream << "Assertion \"" << conditionText << "\" ";
|
||||
errorStream << "on line " << lineNumber << " ";
|
||||
errorStream << "of " << basename(fileName) << " ";
|
||||
errorStream << "of " << basename(fileName.c_str()) << " ";
|
||||
|
||||
if (message) {
|
||||
if (message.size() > 0) {
|
||||
errorStream << "failed: " << message << std::endl;
|
||||
} else {
|
||||
errorStream << "failed." << std::endl;
|
||||
@@ -59,18 +59,18 @@ bool wpi_assert_impl(bool conditionValue, const char *conditionText,
|
||||
* wpi_assertEqual_impl
|
||||
* and wpi_assertNotEqual_impl.
|
||||
*/
|
||||
void wpi_assertEqual_common_impl(const char *valueA, const char *valueB,
|
||||
const char *equalityType, const char *message,
|
||||
const char *fileName, uint32_t lineNumber,
|
||||
const char *funcName) {
|
||||
void wpi_assertEqual_common_impl(const std::string &valueA, const std::string &valueB,
|
||||
const std::string &equalityType, const std::string &message,
|
||||
const std::string &fileName, uint32_t lineNumber,
|
||||
const std::string &funcName) {
|
||||
std::stringstream errorStream;
|
||||
|
||||
errorStream << "Assertion \"" << valueA << " " << equalityType << " "
|
||||
<< valueB << "\" ";
|
||||
errorStream << "on line " << lineNumber << " ";
|
||||
errorStream << "of " << basename(fileName) << " ";
|
||||
errorStream << "of " << basename(fileName.c_str()) << " ";
|
||||
|
||||
if (message) {
|
||||
if (message.size() > 0) {
|
||||
errorStream << "failed: " << message << std::endl;
|
||||
} else {
|
||||
errorStream << "failed." << std::endl;
|
||||
@@ -92,10 +92,10 @@ void wpi_assertEqual_common_impl(const char *valueA, const char *valueB,
|
||||
* 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 char *valueAString,
|
||||
const char *valueBString, const char *message,
|
||||
const char *fileName, uint32_t lineNumber,
|
||||
const char *funcName) {
|
||||
bool wpi_assertEqual_impl(int valueA, int valueB, const std::string &valueAString,
|
||||
const std::string &valueBString, const std::string &message,
|
||||
const std::string &fileName, uint32_t lineNumber,
|
||||
const std::string &funcName) {
|
||||
if (!(valueA == valueB)) {
|
||||
wpi_assertEqual_common_impl(valueAString, valueBString, "==", message,
|
||||
fileName, lineNumber, funcName);
|
||||
@@ -110,10 +110,10 @@ bool wpi_assertEqual_impl(int valueA, int valueB, const char *valueAString,
|
||||
* 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 char *valueAString,
|
||||
const char *valueBString, const char *message,
|
||||
const char *fileName, uint32_t lineNumber,
|
||||
const char *funcName) {
|
||||
bool wpi_assertNotEqual_impl(int valueA, int valueB, const std::string &valueAString,
|
||||
const std::string &valueBString, const std::string &message,
|
||||
const std::string &fileName, uint32_t lineNumber,
|
||||
const std::string &funcName) {
|
||||
if (!(valueA != valueB)) {
|
||||
wpi_assertEqual_common_impl(valueAString, valueBString, "!=", message,
|
||||
fileName, lineNumber, funcName);
|
||||
|
||||
@@ -44,7 +44,7 @@ class ASubsystem : public Subsystem {
|
||||
Command *m_command = nullptr;
|
||||
|
||||
public:
|
||||
ASubsystem(const char *name) : Subsystem(name) {}
|
||||
ASubsystem(const std::string &name) : Subsystem(name) {}
|
||||
|
||||
virtual void InitDefaultCommand() override {
|
||||
if (m_command != nullptr) {
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
#include "PIDOutput.h"
|
||||
#include <math.h>
|
||||
|
||||
static const char *kP = "p";
|
||||
static const char *kI = "i";
|
||||
static const char *kD = "d";
|
||||
static const char *kF = "f";
|
||||
static const char *kSetpoint = "setpoint";
|
||||
static const char *kEnabled = "enabled";
|
||||
static const std::string kP = "p";
|
||||
static const std::string kI = "i";
|
||||
static const std::string kD = "d";
|
||||
static const std::string kF = "f";
|
||||
static const std::string kSetpoint = "setpoint";
|
||||
static const std::string kEnabled = "enabled";
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -56,34 +56,30 @@ static void wpi_handleTracing()
|
||||
* 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 char *conditionText,
|
||||
const char *message,
|
||||
const char *fileName,
|
||||
uint32_t lineNumber,
|
||||
const char *funcName)
|
||||
{
|
||||
if (!conditionValue)
|
||||
{
|
||||
// Error string buffer
|
||||
char error[256];
|
||||
bool wpi_assert_impl(bool conditionValue, const std::string &conditionText,
|
||||
const std::string &message, const std::string &fileName,
|
||||
uint32_t lineNumber, const std::string &funcName) {
|
||||
if (!conditionValue) {
|
||||
// Error string buffer
|
||||
std::stringstream error;
|
||||
|
||||
// If an error message was specified, include it
|
||||
// Build error string
|
||||
if(message != nullptr) {
|
||||
sprintf(error, "Assertion failed: \"%s\", \"%s\" failed in %s() in %s at line %dd\n",
|
||||
message, conditionText, funcName, fileName, lineNumber);
|
||||
} else {
|
||||
sprintf(error, "Assertion failed: \"%s\" in %s() in %s at line %dd\n",
|
||||
conditionText, funcName, fileName, lineNumber);
|
||||
}
|
||||
// If an error message was specified, include it
|
||||
// Build error string
|
||||
if (message.size()) {
|
||||
error << "Assertion failed: \"" << message << "\", \"" << conditionText
|
||||
<< "\" failed in " << funcName + "() in " << fileName << " at line "
|
||||
<< lineNumber;
|
||||
} else {
|
||||
error << "Assertion failed: \"" << conditionText << "\" in " << funcName
|
||||
<< "() in " << fileName << " at line " << lineNumber;
|
||||
}
|
||||
|
||||
// Print to console and send to remote dashboard
|
||||
printf("\n\n>>>>%s", error);
|
||||
// Print to console and send to remote dashboard
|
||||
::std::cout << "\n\n>>>>" << error;
|
||||
|
||||
wpi_handleTracing();
|
||||
}
|
||||
return conditionValue;
|
||||
wpi_handleTracing();
|
||||
}
|
||||
return conditionValue;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,31 +87,31 @@ bool wpi_assert_impl(bool conditionValue,
|
||||
* This should not be called directly; it should only be used by wpi_assertEqual_impl
|
||||
* and wpi_assertNotEqual_impl.
|
||||
*/
|
||||
void wpi_assertEqual_common_impl(int valueA,
|
||||
int valueB,
|
||||
const char *equalityType,
|
||||
const char *message,
|
||||
const char *fileName,
|
||||
uint32_t lineNumber,
|
||||
const char *funcName)
|
||||
{
|
||||
// Error string buffer
|
||||
char error[256];
|
||||
void wpi_assertEqual_common_impl(int valueA, int valueB,
|
||||
const std::string &equalityType,
|
||||
const std::string &message,
|
||||
const std::string &fileName,
|
||||
uint32_t lineNumber,
|
||||
const std::string &funcName) {
|
||||
// Error string buffer
|
||||
std::stringstream error;
|
||||
|
||||
// If an error message was specified, include it
|
||||
// Build error string
|
||||
if(message != nullptr) {
|
||||
sprintf(error, "Assertion failed: \"%s\", \"%d\" %s \"%d\" in %s() in %s at line %d\n",
|
||||
message, valueA, equalityType, valueB, funcName, fileName, lineNumber);
|
||||
} else {
|
||||
sprintf(error, "Assertion failed: \"%d\" %s \"%d\" in %s() in %s at line %d\n",
|
||||
valueA, equalityType, valueB, funcName, fileName, lineNumber);
|
||||
}
|
||||
// If an error message was specified, include it
|
||||
// Build error string
|
||||
if (message.size() > 0) {
|
||||
error << "Assertion failed: \"" << message << "\", \"" << valueA << "\" "
|
||||
<< equalityType << " \"" << valueB << "\" in " << funcName << "() in "
|
||||
<< fileName << " at line " << lineNumber << "\n";
|
||||
} else {
|
||||
error << "Assertion failed: \"" << valueA << "\" " << equalityType << " \""
|
||||
<< valueB << "\" in " << funcName << "() in " << fileName
|
||||
<< " at line " << lineNumber << "\n";
|
||||
}
|
||||
|
||||
// Print to console and send to remote dashboard
|
||||
printf("\n\n>>>>%s", error);
|
||||
// Print to console and send to remote dashboard
|
||||
std::cout << "\n\n>>>>" << error;
|
||||
|
||||
wpi_handleTracing();
|
||||
wpi_handleTracing();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,10 +122,10 @@ void wpi_assertEqual_common_impl(int valueA,
|
||||
*/
|
||||
bool wpi_assertEqual_impl(int valueA,
|
||||
int valueB,
|
||||
const char *message,
|
||||
const char *fileName,
|
||||
const std::string &message,
|
||||
const std::string &fileName,
|
||||
uint32_t lineNumber,
|
||||
const char *funcName)
|
||||
const std::string &funcName)
|
||||
{
|
||||
if(!(valueA == valueB))
|
||||
{
|
||||
@@ -146,10 +142,10 @@ bool wpi_assertEqual_impl(int valueA,
|
||||
*/
|
||||
bool wpi_assertNotEqual_impl(int valueA,
|
||||
int valueB,
|
||||
const char *message,
|
||||
const char *fileName,
|
||||
const std::string &message,
|
||||
const std::string &fileName,
|
||||
uint32_t lineNumber,
|
||||
const char *funcName)
|
||||
const std::string &funcName)
|
||||
{
|
||||
if(!(valueA != valueB))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user