Use Twine in error checks.

This commit is contained in:
Peter Johnson
2017-12-01 21:50:24 -08:00
parent fe53dd2f28
commit 54326311ad
9 changed files with 27 additions and 60 deletions

View File

@@ -11,8 +11,6 @@
#include <HAL/AnalogInput.h>
#include <HAL/HAL.h>
#include <HAL/Ports.h>
#include <llvm/SmallString.h>
#include <llvm/raw_ostream.h>
#include "SmartDashboard/SendableBuilder.h"
#include "Timer.h"
@@ -27,12 +25,9 @@ using namespace frc;
* on-board 4-7 are on the MXP port.
*/
AnalogInput::AnalogInput(int channel) {
llvm::SmallString<32> str;
llvm::raw_svector_ostream buf(str);
buf << "Analog Input " << channel;
if (!SensorBase::CheckAnalogInputChannel(channel)) {
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
"Analog Input " + llvm::Twine(channel));
return;
}

View File

@@ -11,8 +11,6 @@
#include <HAL/HAL.h>
#include <HAL/Ports.h>
#include <llvm/SmallString.h>
#include <llvm/raw_ostream.h>
#include "SensorBase.h"
#include "SmartDashboard/SendableBuilder.h"
@@ -28,12 +26,9 @@ using namespace frc;
* @param channel The channel number on the roboRIO to represent.
*/
AnalogOutput::AnalogOutput(int channel) {
llvm::SmallString<32> str;
llvm::raw_svector_ostream buf(str);
buf << "analog output " << channel;
if (!SensorBase::CheckAnalogOutputChannel(channel)) {
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
"analog output " + llvm::Twine(channel));
m_channel = std::numeric_limits<int>::max();
m_port = HAL_kInvalidHandle;
return;

View File

@@ -12,8 +12,6 @@
#include <HAL/DIO.h>
#include <HAL/HAL.h>
#include <HAL/Ports.h>
#include <llvm/SmallString.h>
#include <llvm/raw_ostream.h>
#include "SmartDashboard/SendableBuilder.h"
#include "WPIErrors.h"
@@ -28,12 +26,9 @@ using namespace frc;
* @param channel The DIO channel 0-9 are on-board, 10-25 are on the MXP port
*/
DigitalInput::DigitalInput(int channel) {
llvm::SmallString<32> str;
llvm::raw_svector_ostream buf(str);
if (!CheckDigitalChannel(channel)) {
buf << "Digital Channel " << channel;
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
"Digital Channel " + llvm::Twine(channel));
m_channel = std::numeric_limits<int>::max();
return;
}

View File

@@ -12,8 +12,6 @@
#include <HAL/DIO.h>
#include <HAL/HAL.h>
#include <HAL/Ports.h>
#include <llvm/SmallString.h>
#include <llvm/raw_ostream.h>
#include "SensorBase.h"
#include "SmartDashboard/SendableBuilder.h"
@@ -30,13 +28,10 @@ using namespace frc;
* port
*/
DigitalOutput::DigitalOutput(int channel) {
llvm::SmallString<32> str;
llvm::raw_svector_ostream buf(str);
m_pwmGenerator = HAL_kInvalidHandle;
if (!SensorBase::CheckDigitalChannel(channel)) {
buf << "Digital Channel " << channel;
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
"Digital Channel " + llvm::Twine(channel));
m_channel = std::numeric_limits<int>::max();
return;
}

View File

@@ -10,8 +10,6 @@
#include <HAL/HAL.h>
#include <HAL/Ports.h>
#include <HAL/Solenoid.h>
#include <llvm/SmallString.h>
#include <llvm/raw_ostream.h>
#include "SensorBase.h"
#include "SmartDashboard/SendableBuilder.h"
@@ -43,21 +41,22 @@ DoubleSolenoid::DoubleSolenoid(int moduleNumber, int forwardChannel,
: SolenoidBase(moduleNumber),
m_forwardChannel(forwardChannel),
m_reverseChannel(reverseChannel) {
llvm::SmallString<32> str;
llvm::raw_svector_ostream buf(str);
if (!SensorBase::CheckSolenoidModule(m_moduleNumber)) {
buf << "Solenoid Module " << m_moduleNumber;
wpi_setWPIErrorWithContext(ModuleIndexOutOfRange, buf.str());
wpi_setWPIErrorWithContext(
ModuleIndexOutOfRange,
"Solenoid Module " + llvm::Twine(m_moduleNumber));
return;
}
if (!SensorBase::CheckSolenoidChannel(m_forwardChannel)) {
buf << "Solenoid Module " << m_forwardChannel;
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
wpi_setWPIErrorWithContext(
ChannelIndexOutOfRange,
"Solenoid Channel " + llvm::Twine(m_forwardChannel));
return;
}
if (!SensorBase::CheckSolenoidChannel(m_reverseChannel)) {
buf << "Solenoid Module " << m_reverseChannel;
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
wpi_setWPIErrorWithContext(
ChannelIndexOutOfRange,
"Solenoid Channel " + llvm::Twine(m_reverseChannel));
return;
}
int32_t status = 0;

View File

@@ -8,8 +8,6 @@
#include "Error.h"
#include <llvm/Path.h>
#include <llvm/SmallString.h>
#include <llvm/raw_ostream.h>
#include "DriverStation.h"
#include "Timer.h"

View File

@@ -10,8 +10,6 @@
#include <HAL/HAL.h>
#include <HAL/PWM.h>
#include <HAL/Ports.h>
#include <llvm/SmallString.h>
#include <llvm/raw_ostream.h>
#include "SensorBase.h"
#include "SmartDashboard/SendableBuilder.h"
@@ -31,12 +29,9 @@ using namespace frc;
* MXP port
*/
PWM::PWM(int channel) {
llvm::SmallString<32> str;
llvm::raw_svector_ostream buf(str);
if (!SensorBase::CheckPWMChannel(channel)) {
buf << "PWM Channel " << channel;
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
"PWM Channel " + llvm::Twine(channel));
return;
}

View File

@@ -10,7 +10,7 @@
#include <HAL/HAL.h>
#include <HAL/Ports.h>
#include <HAL/Relay.h>
#include <llvm/SmallString.h>
#include <llvm/raw_ostream.h>
#include "MotorSafetyHelper.h"
#include "SensorBase.h"
@@ -30,11 +30,9 @@ using namespace frc;
*/
Relay::Relay(int channel, Relay::Direction direction)
: m_channel(channel), m_direction(direction) {
llvm::SmallString<128> str;
llvm::raw_svector_ostream buf(str);
if (!SensorBase::CheckRelayChannel(m_channel)) {
buf << "Relay Channel " << m_channel;
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
"Relay Channel " + llvm::Twine(m_channel));
return;
}

View File

@@ -10,8 +10,6 @@
#include <HAL/HAL.h>
#include <HAL/Ports.h>
#include <HAL/Solenoid.h>
#include <llvm/SmallString.h>
#include <llvm/raw_ostream.h>
#include "SensorBase.h"
#include "SmartDashboard/SendableBuilder.h"
@@ -35,16 +33,15 @@ Solenoid::Solenoid(int channel)
*/
Solenoid::Solenoid(int moduleNumber, int channel)
: SolenoidBase(moduleNumber), m_channel(channel) {
llvm::SmallString<32> str;
llvm::raw_svector_ostream buf(str);
if (!SensorBase::CheckSolenoidModule(m_moduleNumber)) {
buf << "Solenoid Module " << m_moduleNumber;
wpi_setWPIErrorWithContext(ModuleIndexOutOfRange, buf.str());
wpi_setWPIErrorWithContext(
ModuleIndexOutOfRange,
"Solenoid Module " + llvm::Twine(m_moduleNumber));
return;
}
if (!SensorBase::CheckSolenoidChannel(m_channel)) {
buf << "Solenoid Module " << m_channel;
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
"Solenoid Channel " + llvm::Twine(m_channel));
return;
}