diff --git a/wpilibc/athena/include/SensorBase.h b/wpilibc/athena/include/SensorBase.h index ef8ab9bc33..5e90d76bf6 100644 --- a/wpilibc/athena/include/SensorBase.h +++ b/wpilibc/athena/include/SensorBase.h @@ -31,8 +31,8 @@ class SensorBase : public ErrorBase { static bool CheckDigitalChannel(int channel); static bool CheckRelayChannel(int channel); static bool CheckPWMChannel(int channel); - static bool CheckAnalogInput(int channel); - static bool CheckAnalogOutput(int channel); + static bool CheckAnalogInputChannel(int channel); + static bool CheckAnalogOutputChannel(int channel); static bool CheckSolenoidChannel(int channel); static bool CheckPDPChannel(int channel); diff --git a/wpilibc/athena/src/AnalogInput.cpp b/wpilibc/athena/src/AnalogInput.cpp index f0d1f8bd2a..69529a1adf 100644 --- a/wpilibc/athena/src/AnalogInput.cpp +++ b/wpilibc/athena/src/AnalogInput.cpp @@ -27,7 +27,7 @@ AnalogInput::AnalogInput(uint32_t channel) { std::stringstream buf; buf << "Analog Input " << channel; - if (!HAL_CheckAnalogInputChannel(channel)) { + if (!SensorBase::CheckAnalogInputChannel(channel)) { wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str()); return; } diff --git a/wpilibc/athena/src/AnalogOutput.cpp b/wpilibc/athena/src/AnalogOutput.cpp index 65357fa964..8e8584848a 100644 --- a/wpilibc/athena/src/AnalogOutput.cpp +++ b/wpilibc/athena/src/AnalogOutput.cpp @@ -24,7 +24,7 @@ AnalogOutput::AnalogOutput(uint32_t channel) { std::stringstream buf; buf << "analog input " << channel; - if (!HAL_CheckAnalogOutputChannel(channel)) { + if (!SensorBase::CheckAnalogOutputChannel(channel)) { wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str()); m_channel = std::numeric_limits::max(); m_port = HAL_kInvalidHandle; diff --git a/wpilibc/athena/src/SensorBase.cpp b/wpilibc/athena/src/SensorBase.cpp index e508859556..b1b76f5ab5 100644 --- a/wpilibc/athena/src/SensorBase.cpp +++ b/wpilibc/athena/src/SensorBase.cpp @@ -72,7 +72,7 @@ bool SensorBase::CheckPWMChannel(int channel) { * * @return Analog channel is valid */ -bool SensorBase::CheckAnalogInput(int channel) { +bool SensorBase::CheckAnalogInputChannel(int channel) { return HAL_CheckAnalogInputChannel(channel); } @@ -84,7 +84,7 @@ bool SensorBase::CheckAnalogInput(int channel) { * * @return Analog channel is valid */ -bool SensorBase::CheckAnalogOutput(int channel) { +bool SensorBase::CheckAnalogOutputChannel(int channel) { return HAL_CheckAnalogOutputChannel(channel); } diff --git a/wpilibc/sim/include/SensorBase.h b/wpilibc/sim/include/SensorBase.h index e78014d05c..15c63e0ceb 100644 --- a/wpilibc/sim/include/SensorBase.h +++ b/wpilibc/sim/include/SensorBase.h @@ -31,8 +31,8 @@ class SensorBase : public ErrorBase { static bool CheckDigitalChannel(int channel); static bool CheckRelayChannel(int channel); static bool CheckPWMChannel(int channel); - static bool CheckAnalogInput(int channel); - static bool CheckAnalogOutput(int channel); + static bool CheckAnalogInputChannel(int channel); + static bool CheckAnalogOutputChannel(int channel); static bool CheckSolenoidChannel(int channel); static bool CheckPDPChannel(int channel); diff --git a/wpilibc/sim/src/SensorBase.cpp b/wpilibc/sim/src/SensorBase.cpp index 0d7c50f3a8..2b9975702d 100644 --- a/wpilibc/sim/src/SensorBase.cpp +++ b/wpilibc/sim/src/SensorBase.cpp @@ -73,7 +73,7 @@ bool SensorBase::CheckPWMChannel(int channel) { * * @return Analog channel is valid */ -bool SensorBase::CheckAnalogInput(int channel) { +bool SensorBase::CheckAnalogInputChannel(int channel) { if (channel >= 0 && channel < kAnalogInputs) return true; return false; } @@ -86,7 +86,7 @@ bool SensorBase::CheckAnalogInput(int channel) { * * @return Analog channel is valid */ -bool SensorBase::CheckAnalogOutput(int channel) { +bool SensorBase::CheckAnalogOutputChannel(int channel) { if (channel >= 0 && channel < kAnalogOutputs) return true; return false; } diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/AnalogInput.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/AnalogInput.java index c7ec668087..534cce2409 100644 --- a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/AnalogInput.java +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/AnalogInput.java @@ -47,10 +47,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend public AnalogInput(final int channel) { m_channel = channel; - if (!AnalogJNI.checkAnalogInputChannel(channel)) { - throw new AllocationException("Analog input channel " + m_channel - + " cannot be allocated. Channel is not present."); - } + SensorBase.checkAnalogInputChannel(channel); final int portHandle = AnalogJNI.getPort((byte) channel); m_port = AnalogJNI.initializeAnalogInputPort(portHandle); diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/AnalogOutput.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/AnalogOutput.java index debec93fb9..4d757c7d87 100644 --- a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/AnalogOutput.java +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/AnalogOutput.java @@ -30,10 +30,7 @@ public class AnalogOutput extends SensorBase implements LiveWindowSendable { public AnalogOutput(final int channel) { m_channel = channel; - if (!AnalogJNI.checkAnalogOutputChannel(channel)) { - throw new AllocationException("Analog output channel " + m_channel - + " cannot be allocated. Channel is not present."); - } + SensorBase.checkAnalogOutputChannel(channel); final int portHandle = AnalogJNI.getPort((byte) channel); m_port = AnalogJNI.initializeAnalogOutputPort(portHandle); diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/Relay.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/Relay.java index 02e1eca51a..6c14de9afe 100644 --- a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/Relay.java +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/Relay.java @@ -87,9 +87,8 @@ public class Relay extends SensorBase implements MotorSafety, LiveWindowSendable * set to both lines at 0v. */ private void initRelay() { - if (!RelayJNI.checkRelayChannel(m_channel)) { - throw new IndexOutOfBoundsException("Requested relay channel number is out of range."); - } + SensorBase.checkRelayChannel(m_channel); + int portHandle = RelayJNI.getPort((byte)m_channel); if (m_direction == Direction.kBoth || m_direction == Direction.kForward) { m_forwardHandle = RelayJNI.initializeRelayPort(portHandle, true); diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/SensorBase.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/SensorBase.java index c21d6b4e80..615914cd45 100644 --- a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/SensorBase.java +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/SensorBase.java @@ -88,7 +88,12 @@ public abstract class SensorBase { // TODO: Refactor */ protected static void checkSolenoidModule(final int moduleNumber) { if (!SolenoidJNI.checkSolenoidModule(moduleNumber)) { - throw new IndexOutOfBoundsException("Requested solenoid module number is out of range"); + StringBuilder buf = new StringBuilder(); + buf.append("Requested solenoid module is out of range. Minimumm: 0, Maximum: "); + buf.append(kPCMModules); + buf.append(", Requested: "); + buf.append(moduleNumber); + throw new IndexOutOfBoundsException(buf.toString()); } } @@ -100,7 +105,12 @@ public abstract class SensorBase { // TODO: Refactor */ protected static void checkDigitalChannel(final int channel) { if (!DIOJNI.checkDIOChannel(channel)) { - throw new IndexOutOfBoundsException("Requested digital channel number is out of range."); + StringBuilder buf = new StringBuilder(); + buf.append("Requested DIO channel is out of range. Minimumm: 0, Maximum: "); + buf.append(kDigitalChannels); + buf.append(", Requested: "); + buf.append(channel); + throw new IndexOutOfBoundsException(buf.toString()); } } @@ -112,7 +122,12 @@ public abstract class SensorBase { // TODO: Refactor */ protected static void checkRelayChannel(final int channel) { if (!RelayJNI.checkRelayChannel(channel)) { - throw new IndexOutOfBoundsException("Requested relay channel number is out of range."); + StringBuilder buf = new StringBuilder(); + buf.append("Requested relay channel is out of range. Minimumm: 0, Maximum: "); + buf.append(kRelayChannels); + buf.append(", Requested: "); + buf.append(channel); + throw new IndexOutOfBoundsException(buf.toString()); } } @@ -124,7 +139,12 @@ public abstract class SensorBase { // TODO: Refactor */ protected static void checkPWMChannel(final int channel) { if (!PWMJNI.checkPWMChannel(channel)) { - throw new IndexOutOfBoundsException("Requested PWM channel number is out of range."); + StringBuilder buf = new StringBuilder(); + buf.append("Requested PWM channel is out of range. Minimumm: 0, Maximum: "); + buf.append(kPwmChannels); + buf.append(", Requested: "); + buf.append(channel); + throw new IndexOutOfBoundsException(buf.toString()); } } @@ -136,7 +156,12 @@ public abstract class SensorBase { // TODO: Refactor */ protected static void checkAnalogInputChannel(final int channel) { if (!AnalogJNI.checkAnalogInputChannel(channel)) { - throw new IndexOutOfBoundsException("Requested analog input channel number is out of range."); + StringBuilder buf = new StringBuilder(); + buf.append("Requested analog input channel is out of range. Minimumm: 0, Maximum: "); + buf.append(kAnalogInputChannels); + buf.append(", Requested: "); + buf.append(channel); + throw new IndexOutOfBoundsException(buf.toString()); } } @@ -148,8 +173,12 @@ public abstract class SensorBase { // TODO: Refactor */ protected static void checkAnalogOutputChannel(final int channel) { if (!AnalogJNI.checkAnalogOutputChannel(channel)) { - throw new IndexOutOfBoundsException( - "Requested analog output channel number is out of range."); + StringBuilder buf = new StringBuilder(); + buf.append("Requested analog output channel is out of range. Minimumm: 0, Maximum: "); + buf.append(kAnalogOutputChannels); + buf.append(", Requested: "); + buf.append(channel); + throw new IndexOutOfBoundsException(buf.toString()); } } @@ -160,7 +189,12 @@ public abstract class SensorBase { // TODO: Refactor */ protected static void checkSolenoidChannel(final int channel) { if (!SolenoidJNI.checkSolenoidChannel(channel)) { - throw new IndexOutOfBoundsException("Requested solenoid channel number is out of range."); + StringBuilder buf = new StringBuilder(); + buf.append("Requested solenoid channel is out of range. Minimumm: 0, Maximum: "); + buf.append(kSolenoidChannels); + buf.append(", Requested: "); + buf.append(channel); + throw new IndexOutOfBoundsException(buf.toString()); } } @@ -172,7 +206,12 @@ public abstract class SensorBase { // TODO: Refactor */ protected static void checkPDPChannel(final int channel) { if (!PDPJNI.checkPDPChannel(channel)) { - throw new IndexOutOfBoundsException("Requested PDP channel number is out of range."); + StringBuilder buf = new StringBuilder(); + buf.append("Requested PDP channel is out of range. Minimumm: 0, Maximum: "); + buf.append(kPDPChannels); + buf.append(", Requested: "); + buf.append(channel); + throw new IndexOutOfBoundsException(buf.toString()); } } @@ -183,7 +222,12 @@ public abstract class SensorBase { // TODO: Refactor */ protected static void checkPDPModule(final int module) { if (!PDPJNI.checkPDPModule(module)) { - throw new IndexOutOfBoundsException("Requested PDP module number is out of range."); + StringBuilder buf = new StringBuilder(); + buf.append("Requested PDP module is out of range. Minimumm: 0, Maximum: "); + buf.append(kPDPModules); + buf.append(", Requested: "); + buf.append(module); + throw new IndexOutOfBoundsException(buf.toString()); } }