From 7023013c4ba3355bc742926d263b43e936191ac2 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sun, 1 Nov 2015 09:11:52 -0800 Subject: [PATCH] Simplify JNI interfaces. These changes both simplify the Java code and improve performance across the JNI boundary. This also fixes the AnalogCrossConnectTest by adding delays to setInterruptHigh() and setInterruptLow() to ensure the change in voltage has time to propagate and extends the timeouts in AbstractInterruptTest. Detailed changes: Hoisted status checks to C. This avoids the need to create direct byte buffers (expensive) and significantly simplifies the Java code. The C code now directly generates the exception or reports the error to the DS. The JVM pointer is now a global across the JNI, initialized by the OnLoad function, avoiding the need for some of the class-specific initializers to get this pointer for callbacks. Opaque pointers (such as ports) are now passed as long values rather than with a ByteBuffer wrapper. Added extern "C" to source files. This allows earlier detection of JNI definition mismatches to the Java source headers. Changed JNI signatures to more closely match HAL signatures (in particular, boolean is now universally used instead of byte for HAL bool, which cleans up mapping back and forth to 1/0 from true/false). Change-Id: I4ea0032cabb0871cd74106a3a70d947258c29d2d --- .../edu/wpi/first/wpilibj/AnalogInput.java | 142 +---- .../edu/wpi/first/wpilibj/AnalogOutput.java | 36 +- .../edu/wpi/first/wpilibj/AnalogTrigger.java | 52 +- .../first/wpilibj/AnalogTriggerOutput.java | 6 +- .../java/edu/wpi/first/wpilibj/CANJaguar.java | 37 +- .../edu/wpi/first/wpilibj/Compressor.java | 100 +-- .../wpi/first/wpilibj/ControllerPower.java | 89 +-- .../java/edu/wpi/first/wpilibj/Counter.java | 138 +---- .../edu/wpi/first/wpilibj/DigitalInput.java | 11 +- .../edu/wpi/first/wpilibj/DigitalOutput.java | 75 +-- .../edu/wpi/first/wpilibj/DigitalSource.java | 23 +- .../edu/wpi/first/wpilibj/DriverStation.java | 24 +- .../java/edu/wpi/first/wpilibj/Encoder.java | 87 +-- .../main/java/edu/wpi/first/wpilibj/I2C.java | 8 +- .../wpilibj/InterruptableSensorBase.java | 106 +--- .../java/edu/wpi/first/wpilibj/Notifier.java | 37 +- .../main/java/edu/wpi/first/wpilibj/PWM.java | 69 +-- .../first/wpilibj/PowerDistributionPanel.java | 54 +- .../java/edu/wpi/first/wpilibj/Relay.java | 54 +- .../java/edu/wpi/first/wpilibj/RobotBase.java | 38 +- .../main/java/edu/wpi/first/wpilibj/SPI.java | 23 +- .../edu/wpi/first/wpilibj/SerialPort.java | 88 +-- .../java/edu/wpi/first/wpilibj/Solenoid.java | 14 +- .../edu/wpi/first/wpilibj/SolenoidBase.java | 48 +- .../java/edu/wpi/first/wpilibj/Utility.java | 37 +- .../wpilibj/can/CANExceptionFactory.java | 42 -- .../edu/wpi/first/wpilibj/can/CANJNI.java | 4 +- .../FRCNetworkCommunicationsLibrary.java | 6 +- .../edu/wpi/first/wpilibj/hal/AnalogJNI.java | 98 ++- .../wpi/first/wpilibj/hal/CompressorJNI.java | 35 +- .../edu/wpi/first/wpilibj/hal/CounterJNI.java | 66 +- .../edu/wpi/first/wpilibj/hal/DIOJNI.java | 25 +- .../edu/wpi/first/wpilibj/hal/EncoderJNI.java | 36 +- .../edu/wpi/first/wpilibj/hal/HALLibrary.java | 9 +- .../edu/wpi/first/wpilibj/hal/HALUtil.java | 43 +- .../edu/wpi/first/wpilibj/hal/I2CJNI.java | 9 +- .../wpi/first/wpilibj/hal/InterruptJNI.java | 34 +- .../edu/wpi/first/wpilibj/hal/JNIWrapper.java | 5 +- .../wpi/first/wpilibj/hal/NotifierJNI.java | 15 +- .../edu/wpi/first/wpilibj/hal/PDPJNI.java | 19 +- .../edu/wpi/first/wpilibj/hal/PWMJNI.java | 30 +- .../edu/wpi/first/wpilibj/hal/PowerJNI.java | 30 +- .../edu/wpi/first/wpilibj/hal/RelayJNI.java | 13 +- .../edu/wpi/first/wpilibj/hal/SPIJNI.java | 7 +- .../wpi/first/wpilibj/hal/SerialPortJNI.java | 37 +- .../wpi/first/wpilibj/hal/SolenoidJNI.java | 20 +- .../first/wpilibj/AbstractInterruptTest.java | 4 +- .../first/wpilibj/AnalogCrossConnectTest.java | 2 + .../wpilibJavaJNI/lib/AccelerometerJNI.cpp | 4 + wpilibj/wpilibJavaJNI/lib/AnalogJNI.cpp | 572 ++++++++---------- wpilibj/wpilibJavaJNI/lib/CANJNI.cpp | 29 +- wpilibj/wpilibJavaJNI/lib/CompressorJNI.cpp | 169 +++--- wpilibj/wpilibJavaJNI/lib/CounterJNI.cpp | 392 ++++++------ wpilibj/wpilibJavaJNI/lib/DIOJNI.cpp | 182 +++--- wpilibj/wpilibJavaJNI/lib/EncoderJNI.cpp | 212 +++---- .../lib/FRCNetworkCommunicationsLibrary.cpp | 35 +- wpilibj/wpilibJavaJNI/lib/HALUtil.cpp | 422 ++++++++++--- wpilibj/wpilibJavaJNI/lib/HALUtil.h | 28 + wpilibj/wpilibJavaJNI/lib/I2CJNI.cpp | 59 +- wpilibj/wpilibJavaJNI/lib/InterruptJNI.cpp | 193 +++--- wpilibj/wpilibJavaJNI/lib/JNIWrapper.cpp | 26 +- wpilibj/wpilibJavaJNI/lib/NotifierJNI.cpp | 105 +--- wpilibj/wpilibJavaJNI/lib/PDPJNI.cpp | 101 ++-- wpilibj/wpilibJavaJNI/lib/PWMJNI.cpp | 181 +++--- wpilibj/wpilibJavaJNI/lib/PowerJNI.cpp | 158 ++--- wpilibj/wpilibJavaJNI/lib/RelayJNI.cpp | 73 ++- wpilibj/wpilibJavaJNI/lib/SPIJNI.cpp | 73 +-- wpilibj/wpilibJavaJNI/lib/SerialPortJNI.cpp | 221 +++---- wpilibj/wpilibJavaJNI/lib/SolenoidJNI.cpp | 130 ++-- 69 files changed, 2232 insertions(+), 3118 deletions(-) delete mode 100644 wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/can/CANExceptionFactory.java create mode 100644 wpilibj/wpilibJavaJNI/lib/HALUtil.h diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogInput.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogInput.java index d496a29112..a2873f4007 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogInput.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogInput.java @@ -16,7 +16,6 @@ import java.nio.ByteBuffer; import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; import edu.wpi.first.wpilibj.communication.UsageReporting; import edu.wpi.first.wpilibj.hal.AnalogJNI; -import edu.wpi.first.wpilibj.hal.HALUtil; import edu.wpi.first.wpilibj.livewindow.LiveWindow; import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable; import edu.wpi.first.wpilibj.tables.ITable; @@ -42,7 +41,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend private static final int kAccumulatorSlot = 1; private static Resource channels = new Resource(kAnalogInputChannels); - private ByteBuffer m_port; + private long m_port; private int m_channel; private static final int[] kAccumulatorChannels = {0, 1}; private long m_accumulatorOffset; @@ -57,7 +56,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend public AnalogInput(final int channel) { m_channel = channel; - if (AnalogJNI.checkAnalogInputChannel(channel) == 0) { + if (!AnalogJNI.checkAnalogInputChannel(channel)) { throw new AllocationException("Analog input channel " + m_channel + " cannot be allocated. Channel is not present."); } @@ -67,12 +66,8 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend throw new AllocationException("Analog input channel " + m_channel + " is already allocated"); } - ByteBuffer port_pointer = AnalogJNI.getPort((byte) channel); - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - m_port = AnalogJNI.initializeAnalogInputPort(port_pointer, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + long port_pointer = AnalogJNI.getPort((byte) channel); + m_port = AnalogJNI.initializeAnalogInputPort(port_pointer); LiveWindow.addSensor("AnalogInput", channel, this); UsageReporting.report(tResourceType.kResourceType_AnalogChannel, channel); @@ -96,12 +91,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend * @return A sample straight from this channel. */ public int getValue() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - int value = AnalogJNI.getAnalogValue(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return value; + return AnalogJNI.getAnalogValue(m_port); } /** @@ -116,12 +106,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend * @return A sample from the oversample and average engine for this channel. */ public int getAverageValue() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - int value = AnalogJNI.getAnalogAverageValue(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return value; + return AnalogJNI.getAnalogAverageValue(m_port); } /** @@ -132,12 +117,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend * @return A scaled sample straight from this channel. */ public double getVoltage() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - double value = AnalogJNI.getAnalogVoltage(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return value; + return AnalogJNI.getAnalogVoltage(m_port); } /** @@ -152,12 +132,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend * engine for this channel. */ public double getAverageVoltage() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - double value = AnalogJNI.getAnalogAverageVoltage(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return value; + return AnalogJNI.getAnalogAverageVoltage(m_port); } /** @@ -170,12 +145,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend * @return Least significant bit weight. */ public long getLSBWeight() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - long value = AnalogJNI.getAnalogLSBWeight(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return value; + return AnalogJNI.getAnalogLSBWeight(m_port); } /** @@ -187,12 +157,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend * @return Offset constant. */ public int getOffset() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - int value = AnalogJNI.getAnalogOffset(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return value; + return AnalogJNI.getAnalogOffset(m_port); } /** @@ -212,11 +177,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend * @param bits The number of averaging bits. */ public void setAverageBits(final int bits) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - AnalogJNI.setAnalogAverageBits(m_port, bits, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + AnalogJNI.setAnalogAverageBits(m_port, bits); } /** @@ -227,12 +188,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend * @return The number of averaging bits. */ public int getAverageBits() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - int value = AnalogJNI.getAnalogAverageBits(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return value; + return AnalogJNI.getAnalogAverageBits(m_port); } /** @@ -243,11 +199,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend * @param bits The number of oversample bits. */ public void setOversampleBits(final int bits) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - AnalogJNI.setAnalogOversampleBits(m_port, bits, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + AnalogJNI.setAnalogOversampleBits(m_port, bits); } /** @@ -258,12 +210,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend * @return The number of oversample bits. */ public int getOversampleBits() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - int value = AnalogJNI.getAnalogOversampleBits(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return value; + return AnalogJNI.getAnalogOversampleBits(m_port); } /** @@ -275,11 +222,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend + " on channels " + kAccumulatorChannels[0] + "," + kAccumulatorChannels[1]); } m_accumulatorOffset = 0; - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - AnalogJNI.initAccumulator(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + AnalogJNI.initAccumulator(m_port); } /** @@ -298,11 +241,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend * Resets the accumulator to the initial value. */ public void resetAccumulator() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - AnalogJNI.resetAccumulator(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + AnalogJNI.resetAccumulator(m_port); // Wait until the next sample, so the next call to getAccumulator*() // won't have old values. @@ -325,11 +264,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend * bits will affect the size of the value for this field. */ public void setAccumulatorCenter(int center) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - AnalogJNI.setAccumulatorCenter(m_port, center, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + AnalogJNI.setAccumulatorCenter(m_port, center); } /** @@ -338,11 +273,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend * @param deadband The deadband size in ADC codes (12-bit value) */ public void setAccumulatorDeadband(int deadband) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - AnalogJNI.setAccumulatorDeadband(m_port, deadband, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + AnalogJNI.setAccumulatorDeadband(m_port, deadband); } /** @@ -354,12 +285,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend * @return The 64-bit value accumulated since the last Reset(). */ public long getAccumulatorValue() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - long value = AnalogJNI.getAccumulatorValue(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return value + m_accumulatorOffset; + return AnalogJNI.getAccumulatorValue(m_port) + m_accumulatorOffset; } /** @@ -371,12 +297,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend * @return The number of times samples from the channel were accumulated. */ public long getAccumulatorCount() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - long value = AnalogJNI.getAccumulatorCount(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return value; + return AnalogJNI.getAccumulatorCount(m_port); } /** @@ -400,14 +321,9 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend ByteBuffer count = ByteBuffer.allocateDirect(4); // set the byte order count.order(ByteOrder.LITTLE_ENDIAN); - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - AnalogJNI.getAccumulatorOutput(m_port, value.asLongBuffer(), count.asIntBuffer(), - status.asIntBuffer()); + AnalogJNI.getAccumulatorOutput(m_port, value.asLongBuffer(), count.asIntBuffer()); result.value = value.asLongBuffer().get(0) + m_accumulatorOffset; result.count = count.asIntBuffer().get(0); - HALUtil.checkStatus(status.asIntBuffer()); } /** @@ -434,12 +350,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend * @param samplesPerSecond The number of samples per second. */ public static void setGlobalSampleRate(final double samplesPerSecond) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - AnalogJNI.setAnalogSampleRate((float) samplesPerSecond, status.asIntBuffer()); - - HALUtil.checkStatus(status.asIntBuffer()); + AnalogJNI.setAnalogSampleRate((float) samplesPerSecond); } /** @@ -451,14 +362,7 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend * @return Sample rate. */ public static double getGlobalSampleRate() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - double value = AnalogJNI.getAnalogSampleRate(status.asIntBuffer()); - - HALUtil.checkStatus(status.asIntBuffer()); - - return value; + return AnalogJNI.getAnalogSampleRate(); } /** diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogOutput.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogOutput.java index 2396ea4cb0..5a66357885 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogOutput.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogOutput.java @@ -6,17 +6,9 @@ /*----------------------------------------------------------------------------*/ package edu.wpi.first.wpilibj; -import java.nio.ByteOrder; -import java.nio.IntBuffer; -import java.nio.LongBuffer; -import java.nio.ByteBuffer; - -// import com.sun.jna.Pointer; - import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; import edu.wpi.first.wpilibj.communication.UsageReporting; import edu.wpi.first.wpilibj.hal.AnalogJNI; -import edu.wpi.first.wpilibj.hal.HALUtil; import edu.wpi.first.wpilibj.livewindow.LiveWindow; import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable; import edu.wpi.first.wpilibj.tables.ITable; @@ -28,7 +20,7 @@ import edu.wpi.first.wpilibj.util.CheckedAllocationException; */ public class AnalogOutput extends SensorBase implements LiveWindowSendable { private static Resource channels = new Resource(kAnalogOutputChannels); - private ByteBuffer m_port; + private long m_port; private int m_channel; /** @@ -39,7 +31,7 @@ public class AnalogOutput extends SensorBase implements LiveWindowSendable { public AnalogOutput(final int channel) { m_channel = channel; - if (AnalogJNI.checkAnalogOutputChannel(channel) == 0) { + if (!AnalogJNI.checkAnalogOutputChannel(channel)) { throw new AllocationException("Analog output channel " + m_channel + " cannot be allocated. Channel is not present."); } @@ -49,12 +41,8 @@ public class AnalogOutput extends SensorBase implements LiveWindowSendable { throw new AllocationException("Analog output channel " + m_channel + " is already allocated"); } - ByteBuffer port_pointer = AnalogJNI.getPort((byte) channel); - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - m_port = AnalogJNI.initializeAnalogOutputPort(port_pointer, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + long port_pointer = AnalogJNI.getPort((byte) channel); + m_port = AnalogJNI.initializeAnalogOutputPort(port_pointer); LiveWindow.addSensor("AnalogOutput", channel, this); UsageReporting.report(tResourceType.kResourceType_AnalogOutput, channel); @@ -69,23 +57,11 @@ public class AnalogOutput extends SensorBase implements LiveWindowSendable { } public void setVoltage(double voltage) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - AnalogJNI.setAnalogOutput(m_port, voltage, status.asIntBuffer()); - - HALUtil.checkStatus(status.asIntBuffer()); + AnalogJNI.setAnalogOutput(m_port, voltage); } public double getVoltage() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - double voltage = AnalogJNI.getAnalogOutput(m_port, status.asIntBuffer()); - - HALUtil.checkStatus(status.asIntBuffer()); - - return voltage; + return AnalogJNI.getAnalogOutput(m_port); } /* diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogTrigger.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogTrigger.java index 80b4031721..a15a9ae09f 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogTrigger.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogTrigger.java @@ -11,7 +11,6 @@ import edu.wpi.first.wpilibj.AnalogTriggerOutput.AnalogTriggerType; import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; import edu.wpi.first.wpilibj.communication.UsageReporting; import edu.wpi.first.wpilibj.hal.AnalogJNI; -import edu.wpi.first.wpilibj.hal.HALUtil; import edu.wpi.first.wpilibj.util.BoundaryException; import java.nio.ByteBuffer; @@ -46,7 +45,7 @@ public class AnalogTrigger { /** * Where the analog trigger is attached */ - protected ByteBuffer m_port; + protected long m_port; protected int m_index; /** @@ -55,15 +54,12 @@ public class AnalogTrigger { * @param channel the port to use for the analog trigger */ protected void initTrigger(final int channel) { - ByteBuffer port_pointer = AnalogJNI.getPort((byte) channel); + long port_pointer = AnalogJNI.getPort((byte) channel); ByteBuffer index = ByteBuffer.allocateDirect(4); - ByteBuffer status = ByteBuffer.allocateDirect(4); index.order(ByteOrder.LITTLE_ENDIAN); - status.order(ByteOrder.LITTLE_ENDIAN); m_port = - AnalogJNI.initializeAnalogTrigger(port_pointer, index.asIntBuffer(), status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + AnalogJNI.initializeAnalogTrigger(port_pointer, index.asIntBuffer()); m_index = index.asIntBuffer().get(0); UsageReporting.report(tResourceType.kResourceType_AnalogTrigger, channel); @@ -97,11 +93,8 @@ public class AnalogTrigger { * Release the resources used by this object */ public void free() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - AnalogJNI.cleanAnalogTrigger(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - m_port = null; + AnalogJNI.cleanAnalogTrigger(m_port); + m_port = 0; } /** @@ -116,10 +109,7 @@ public class AnalogTrigger { if (lower > upper) { throw new BoundaryException("Lower bound is greater than upper"); } - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - AnalogJNI.setAnalogTriggerLimitsRaw(m_port, lower, upper, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + AnalogJNI.setAnalogTriggerLimitsRaw(m_port, lower, upper); } /** @@ -133,11 +123,7 @@ public class AnalogTrigger { if (lower > upper) { throw new BoundaryException("Lower bound is greater than upper bound"); } - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - AnalogJNI.setAnalogTriggerLimitsVoltage(m_port, (float) lower, (float) upper, - status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + AnalogJNI.setAnalogTriggerLimitsVoltage(m_port, lower, upper); } /** @@ -148,11 +134,7 @@ public class AnalogTrigger { * @param useAveragedValue true to use an averaged value, false otherwise */ public void setAveraged(boolean useAveragedValue) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - AnalogJNI.setAnalogTriggerAveraged(m_port, (byte) (useAveragedValue ? 1 : 0), - status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + AnalogJNI.setAnalogTriggerAveraged(m_port, useAveragedValue); } /** @@ -164,11 +146,7 @@ public class AnalogTrigger { * @param useFilteredValue true to use a filterd value, false otherwise */ public void setFiltered(boolean useFilteredValue) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - AnalogJNI.setAnalogTriggerFiltered(m_port, (byte) (useFilteredValue ? 1 : 0), - status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + AnalogJNI.setAnalogTriggerFiltered(m_port, useFilteredValue); } /** @@ -188,11 +166,7 @@ public class AnalogTrigger { * @return The InWindow output of the analog trigger. */ public boolean getInWindow() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - byte value = AnalogJNI.getAnalogTriggerInWindow(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return value != 0; + return AnalogJNI.getAnalogTriggerInWindow(m_port); } /** @@ -203,11 +177,7 @@ public class AnalogTrigger { * @return The TriggerState output of the analog trigger. */ public boolean getTriggerState() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - byte value = AnalogJNI.getAnalogTriggerTriggerState(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return value != 0; + return AnalogJNI.getAnalogTriggerTriggerState(m_port); } /** diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogTriggerOutput.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogTriggerOutput.java index 2503a31591..71ac3dcd8b 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogTriggerOutput.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogTriggerOutput.java @@ -10,7 +10,6 @@ package edu.wpi.first.wpilibj; import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; import edu.wpi.first.wpilibj.communication.UsageReporting; import edu.wpi.first.wpilibj.hal.AnalogJNI; -import edu.wpi.first.wpilibj.hal.HALUtil; import java.nio.IntBuffer; @@ -99,10 +98,7 @@ public class AnalogTriggerOutput extends DigitalSource { * @return The state of the analog trigger output. */ public boolean get() { - IntBuffer status = IntBuffer.allocate(1); - byte value = AnalogJNI.getAnalogTriggerOutput(m_trigger.m_port, m_outputType.value, status); - HALUtil.checkStatus(status); - return value != 0; + return AnalogJNI.getAnalogTriggerOutput(m_trigger.m_port, m_outputType.value); } @Override diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/CANJaguar.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/CANJaguar.java index f9818dd52c..43e18bd1a7 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/CANJaguar.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/CANJaguar.java @@ -10,7 +10,6 @@ package edu.wpi.first.wpilibj; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import edu.wpi.first.wpilibj.can.CANExceptionFactory; import edu.wpi.first.wpilibj.can.CANJNI; import edu.wpi.first.wpilibj.can.CANMessageNotFoundException; import edu.wpi.first.wpilibj.tables.ITable; @@ -275,10 +274,6 @@ public class CANJaguar implements MotorSafety, PIDOutput, CANSpeedController { allocated.free(m_deviceNumber - 1); m_safetyHelper = null; - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - status.asIntBuffer().put(0, 0); - int messageID; // Disable periodic setpoints @@ -308,7 +303,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, CANSpeedController { } CANJNI.FRCNetworkCommunicationCANSessionMuxSendMessage(messageID, null, - CANJNI.CAN_SEND_PERIOD_STOP_REPEATING, status.asIntBuffer()); + CANJNI.CAN_SEND_PERIOD_STOP_REPEATING); configMaxOutputVoltage(kApproxBusVoltage); } @@ -1904,10 +1899,6 @@ public class CANJaguar implements MotorSafety, PIDOutput, CANSpeedController { CANJNI.LM_API_POS_T_EN, CANJNI.LM_API_POS_T_SET, CANJNI.LM_API_ICTRL_T_EN, CANJNI.LM_API_ICTRL_T_SET}; - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - status.asIntBuffer().put(0, 0); - for (byte i = 0; i < kTrustedMessages.length; i++) { if ((kFullMessageIDMask & messageID) == kTrustedMessages[i]) { // Make sure the data will still fit after adjusting for the token. @@ -1923,12 +1914,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, CANSpeedController { trustedBuffer.put(j + 2, data[j]); } - CANJNI.FRCNetworkCommunicationCANSessionMuxSendMessage(messageID, trustedBuffer, period, - status.asIntBuffer()); - int statusCode = status.asIntBuffer().get(0); - if (statusCode < 0) { - CANExceptionFactory.checkStatus(statusCode, messageID); - } + CANJNI.FRCNetworkCommunicationCANSessionMuxSendMessage(messageID, trustedBuffer, period); return; } @@ -1945,13 +1931,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, CANSpeedController { buffer = null; } - CANJNI.FRCNetworkCommunicationCANSessionMuxSendMessage(messageID, buffer, period, - status.asIntBuffer()); - - int statusCode = status.asIntBuffer().get(0); - if (statusCode < 0) { - CANExceptionFactory.checkStatus(statusCode, messageID); - } + CANJNI.FRCNetworkCommunicationCANSessionMuxSendMessage(messageID, buffer, period); } /** @@ -2022,25 +2002,16 @@ public class CANJaguar implements MotorSafety, PIDOutput, CANSpeedController { ByteBuffer timeStamp = ByteBuffer.allocateDirect(4); - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - status.asIntBuffer().put(0, 0); - // Get the data. ByteBuffer dataBuffer = CANJNI.FRCNetworkCommunicationCANSessionMuxReceiveMessage(targetedMessageID.asIntBuffer(), - messageMask, timeStamp, status.asIntBuffer()); + messageMask, timeStamp); if (data != null) { for (int i = 0; i < dataBuffer.capacity(); i++) { data[i] = dataBuffer.get(i); } } - - int statusCode = status.asIntBuffer().get(0); - if (statusCode < 0) { - CANExceptionFactory.checkStatus(statusCode, messageID); - } } /** diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Compressor.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Compressor.java index 86bbe96e73..39bf4b3925 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Compressor.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Compressor.java @@ -1,11 +1,7 @@ package edu.wpi.first.wpilibj; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - import edu.wpi.first.wpilibj.SensorBase; import edu.wpi.first.wpilibj.hal.CompressorJNI; -import edu.wpi.first.wpilibj.hal.HALUtil; import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable; import edu.wpi.first.wpilibj.tables.ITable; @@ -22,7 +18,7 @@ import edu.wpi.first.wpilibj.tables.ITable; * closed loop control, thereby stopping the compressor from operating. */ public class Compressor extends SensorBase implements LiveWindowSendable { - private ByteBuffer m_pcm; + private long m_pcm; /** * Create an instance of the Compressor @@ -76,13 +72,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable { * @return true if the compressor is on */ public boolean enabled() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - boolean on = CompressorJNI.getCompressor(m_pcm, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - - return on; + return CompressorJNI.getCompressor(m_pcm); } /** @@ -92,13 +82,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable { * plugged into the PCM */ public boolean getPressureSwitchValue() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - boolean on = CompressorJNI.getPressureSwitch(m_pcm, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - - return on; + return CompressorJNI.getPressureSwitch(m_pcm); } /** @@ -107,13 +91,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable { * @return current consumed in amps for the compressor motor */ public float getCompressorCurrent() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - float current = CompressorJNI.getCompressorCurrent(m_pcm, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - - return current; + return CompressorJNI.getCompressorCurrent(m_pcm); } /** @@ -123,11 +101,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable { * otherwise normal operation of the compressor is disabled. */ public void setClosedLoopControl(boolean on) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - CompressorJNI.setClosedLoopControl(m_pcm, on, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + CompressorJNI.setClosedLoopControl(m_pcm, on); } /** @@ -137,13 +111,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable { * return false. */ public boolean getClosedLoopControl() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - boolean on = CompressorJNI.getClosedLoopControl(m_pcm, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - - return on; + return CompressorJNI.getClosedLoopControl(m_pcm); } /** @@ -151,13 +119,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable { * compressor current being too high. */ public boolean getCompressorCurrentTooHighFault() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - boolean retval = CompressorJNI.getCompressorCurrentTooHighFault(m_pcm, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - - return retval; + return CompressorJNI.getCompressorCurrentTooHighFault(m_pcm); } /** @@ -165,14 +127,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable { * to compressor current being too high. */ public boolean getCompressorCurrentTooHighStickyFault() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - boolean retval = - CompressorJNI.getCompressorCurrentTooHighStickyFault(m_pcm, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - - return retval; + return CompressorJNI.getCompressorCurrentTooHighStickyFault(m_pcm); } /** @@ -180,13 +135,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable { * shorted. */ public boolean getCompressorShortedStickyFault() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - boolean retval = CompressorJNI.getCompressorShortedStickyFault(m_pcm, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - - return retval; + return CompressorJNI.getCompressorShortedStickyFault(m_pcm); } /** @@ -194,13 +143,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable { * shorted. */ public boolean getCompressorShortedFault() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - boolean retval = CompressorJNI.getCompressorShortedFault(m_pcm, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - - return retval; + return CompressorJNI.getCompressorShortedFault(m_pcm); } /** @@ -208,14 +151,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable { * wired, i.e. compressor is not drawing enough current. */ public boolean getCompressorNotConnectedStickyFault() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - boolean retval = - CompressorJNI.getCompressorNotConnectedStickyFault(m_pcm, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - - return retval; + return CompressorJNI.getCompressorNotConnectedStickyFault(m_pcm); } /** @@ -223,13 +159,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable { * wired, i.e. compressor is not drawing enough current. */ public boolean getCompressorNotConnectedFault() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - boolean retval = CompressorJNI.getCompressorNotConnectedFault(m_pcm, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - - return retval; + return CompressorJNI.getCompressorNotConnectedFault(m_pcm); } /** @@ -243,11 +173,7 @@ public class Compressor extends SensorBase implements LiveWindowSendable { * If no sticky faults are set then this call will have no effect. */ public void clearAllPCMStickyFaults() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - CompressorJNI.clearAllPCMStickyFaults(m_pcm, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + CompressorJNI.clearAllPCMStickyFaults(m_pcm); } @Override diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/ControllerPower.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/ControllerPower.java index b009f4bd8f..c775afe334 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/ControllerPower.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/ControllerPower.java @@ -7,11 +7,6 @@ package edu.wpi.first.wpilibj; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.IntBuffer; - -import edu.wpi.first.wpilibj.hal.HALUtil; import edu.wpi.first.wpilibj.hal.PowerJNI; public class ControllerPower { @@ -21,11 +16,7 @@ public class ControllerPower { * @return The controller input voltage value in Volts */ public static double getInputVoltage() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - double retVal = PowerJNI.getVinVoltage(status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return retVal; + return PowerJNI.getVinVoltage(); } /** @@ -34,11 +25,7 @@ public class ControllerPower { * @return The controller input current value in Amps */ public static double getInputCurrent() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - double retVal = PowerJNI.getVinCurrent(status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return retVal; + return PowerJNI.getVinCurrent(); } /** @@ -47,11 +34,7 @@ public class ControllerPower { * @return The controller 3.3V rail voltage value in Volts */ public static double getVoltage3V3() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - double retVal = PowerJNI.getUserVoltage3V3(status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return retVal; + return PowerJNI.getUserVoltage3V3(); } /** @@ -60,11 +43,7 @@ public class ControllerPower { * @return The controller 3.3V rail output current value in Volts */ public static double getCurrent3V3() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - double retVal = PowerJNI.getUserCurrent3V3(status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return retVal; + return PowerJNI.getUserCurrent3V3(); } /** @@ -75,11 +54,7 @@ public class ControllerPower { * @return The controller 3.3V rail enabled value */ public static boolean getEnabled3V3() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - boolean retVal = PowerJNI.getUserActive3V3(status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return retVal; + return PowerJNI.getUserActive3V3(); } /** @@ -89,11 +64,7 @@ public class ControllerPower { * @return The number of faults */ public static int getFaultCount3V3() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - int retVal = PowerJNI.getUserCurrentFaults3V3(status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return retVal; + return PowerJNI.getUserCurrentFaults3V3(); } /** @@ -102,11 +73,7 @@ public class ControllerPower { * @return The controller 5V rail voltage value in Volts */ public static double getVoltage5V() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - double retVal = PowerJNI.getUserVoltage5V(status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return retVal; + return PowerJNI.getUserVoltage5V(); } /** @@ -115,11 +82,7 @@ public class ControllerPower { * @return The controller 5V rail output current value in Amps */ public static double getCurrent5V() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - double retVal = PowerJNI.getUserCurrent5V(status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return retVal; + return PowerJNI.getUserCurrent5V(); } /** @@ -130,11 +93,7 @@ public class ControllerPower { * @return The controller 5V rail enabled value */ public static boolean getEnabled5V() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - boolean retVal = PowerJNI.getUserActive5V(status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return retVal; + return PowerJNI.getUserActive5V(); } /** @@ -144,11 +103,7 @@ public class ControllerPower { * @return The number of faults */ public static int getFaultCount5V() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - int retVal = PowerJNI.getUserCurrentFaults5V(status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return retVal; + return PowerJNI.getUserCurrentFaults5V(); } /** @@ -157,11 +112,7 @@ public class ControllerPower { * @return The controller 6V rail voltage value in Volts */ public static double getVoltage6V() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - double retVal = PowerJNI.getUserVoltage6V(status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return retVal; + return PowerJNI.getUserVoltage6V(); } /** @@ -170,11 +121,7 @@ public class ControllerPower { * @return The controller 6V rail output current value in Amps */ public static double getCurrent6V() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - double retVal = PowerJNI.getUserCurrent6V(status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return retVal; + return PowerJNI.getUserCurrent6V(); } /** @@ -185,11 +132,7 @@ public class ControllerPower { * @return The controller 6V rail enabled value */ public static boolean getEnabled6V() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - boolean retVal = PowerJNI.getUserActive6V(status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return retVal; + return PowerJNI.getUserActive6V(); } /** @@ -199,10 +142,6 @@ public class ControllerPower { * @return The number of faults */ public static int getFaultCount6V() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - int retVal = PowerJNI.getUserCurrentFaults6V(status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return retVal; + return PowerJNI.getUserCurrentFaults6V(); } } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Counter.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Counter.java index 06e1787b94..8ba2592562 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Counter.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Counter.java @@ -14,7 +14,6 @@ import edu.wpi.first.wpilibj.AnalogTriggerOutput.AnalogTriggerType; import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; import edu.wpi.first.wpilibj.communication.UsageReporting; import edu.wpi.first.wpilibj.hal.CounterJNI; -import edu.wpi.first.wpilibj.hal.HALUtil; import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable; import edu.wpi.first.wpilibj.tables.ITable; import edu.wpi.first.wpilibj.util.BoundaryException; @@ -65,20 +64,16 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab private DigitalSource m_downSource; // /< What makes the counter count down. private boolean m_allocatedUpSource; private boolean m_allocatedDownSource; - private ByteBuffer m_counter; // /< The FPGA counter object. + private long m_counter; // /< The FPGA counter object. private int m_index; // /< The index of this counter. private PIDSourceType m_pidSource; private double m_distancePerPulse; // distance of travel for each tick private void initCounter(final Mode mode) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); ByteBuffer index = ByteBuffer.allocateDirect(4); // set the byte order index.order(ByteOrder.LITTLE_ENDIAN); - m_counter = CounterJNI.initializeCounter(mode.value, index.asIntBuffer(), status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + m_counter = CounterJNI.initializeCounter(mode.value, index.asIntBuffer()); m_index = index.asIntBuffer().get(0); m_allocatedUpSource = false; @@ -161,16 +156,14 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab if (encodingType == null) throw new NullPointerException("Encoding type given was null"); - ByteBuffer status = ByteBuffer.allocateDirect(4); if (encodingType == EncodingType.k1X) { setUpSourceEdge(true, false); - CounterJNI.setCounterAverageSize(m_counter, 1, status.asIntBuffer()); + CounterJNI.setCounterAverageSize(m_counter, 1); } else { setUpSourceEdge(true, true); - CounterJNI.setCounterAverageSize(m_counter, 2, status.asIntBuffer()); + CounterJNI.setCounterAverageSize(m_counter, 2); } - HALUtil.checkStatus(status.asIntBuffer()); setDownSourceEdge(inverted, true); } @@ -198,14 +191,11 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab clearUpSource(); clearDownSource(); - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - CounterJNI.freeCounter(m_counter, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + CounterJNI.freeCounter(m_counter); m_upSource = null; m_downSource = null; - m_counter = null; + m_counter = 0; } /** @@ -238,11 +228,8 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab m_allocatedUpSource = false; } m_upSource = source; - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); CounterJNI.setCounterUpSource(m_counter, source.getChannelForRouting(), - (byte) (source.getAnalogTriggerForRouting() ? 1 : 0), status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + source.getAnalogTriggerForRouting()); } /** @@ -273,11 +260,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab public void setUpSourceEdge(boolean risingEdge, boolean fallingEdge) { if (m_upSource == null) throw new RuntimeException("Up Source must be set before setting the edge!"); - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - CounterJNI.setCounterUpSourceEdge(m_counter, (byte) (risingEdge ? 1 : 0), - (byte) (fallingEdge ? 1 : 0), status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + CounterJNI.setCounterUpSourceEdge(m_counter, risingEdge, fallingEdge); } /** @@ -290,10 +273,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab } m_upSource = null; - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - CounterJNI.clearCounterUpSource(m_counter, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + CounterJNI.clearCounterUpSource(m_counter); } /** @@ -322,15 +302,8 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab m_downSource.free(); m_allocatedDownSource = false; } - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); CounterJNI.setCounterDownSource(m_counter, source.getChannelForRouting(), - (byte) (source.getAnalogTriggerForRouting() ? 1 : 0), status.asIntBuffer()); - if (status.asIntBuffer().get(0) == HALUtil.PARAMETER_OUT_OF_RANGE) { - throw new IllegalArgumentException( - "Counter only supports DownSource in TwoPulse and ExternalDirection modes."); - } - HALUtil.checkStatus(status.asIntBuffer()); + source.getAnalogTriggerForRouting()); m_downSource = source; } @@ -363,11 +336,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab public void setDownSourceEdge(boolean risingEdge, boolean fallingEdge) { if (m_downSource == null) throw new RuntimeException(" Down Source must be set before setting the edge!"); - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - CounterJNI.setCounterDownSourceEdge(m_counter, (byte) (risingEdge ? 1 : 0), - (byte) (fallingEdge ? 1 : 0), status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + CounterJNI.setCounterDownSourceEdge(m_counter, risingEdge, fallingEdge); } /** @@ -380,10 +349,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab } m_downSource = null; - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - CounterJNI.clearCounterDownSource(m_counter, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + CounterJNI.clearCounterDownSource(m_counter); } /** @@ -391,10 +357,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab * are sourced independently from two inputs. */ public void setUpDownCounterMode() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - CounterJNI.setCounterUpDownMode(m_counter, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + CounterJNI.setCounterUpDownMode(m_counter); } /** @@ -402,10 +365,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab * counter input. The Down counter input represents the direction to count. */ public void setExternalDirectionMode() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - CounterJNI.setCounterExternalDirectionMode(m_counter, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + CounterJNI.setCounterExternalDirectionMode(m_counter); } /** @@ -415,11 +375,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab * @param highSemiPeriod true to count up on both rising and falling */ public void setSemiPeriodMode(boolean highSemiPeriod) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - CounterJNI.setCounterSemiPeriodMode(m_counter, (byte) (highSemiPeriod ? 1 : 0), - status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + CounterJNI.setCounterSemiPeriodMode(m_counter, highSemiPeriod); } /** @@ -431,10 +387,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab * opposite direction. Units are seconds. */ public void setPulseLengthMode(double threshold) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - CounterJNI.setCounterPulseLengthMode(m_counter, threshold, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + CounterJNI.setCounterPulseLengthMode(m_counter, threshold); } /** @@ -444,11 +397,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab */ @Override public int get() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - int value = CounterJNI.getCounter(m_counter, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return value; + return CounterJNI.getCounter(m_counter); } /** @@ -468,10 +417,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab */ @Override public void reset() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - CounterJNI.resetCounter(m_counter, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + CounterJNI.resetCounter(m_counter); } /** @@ -485,10 +431,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab */ @Override public void setMaxPeriod(double maxPeriod) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - CounterJNI.setCounterMaxPeriod(m_counter, maxPeriod, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + CounterJNI.setCounterMaxPeriod(m_counter, maxPeriod); } /** @@ -508,10 +451,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab * @param enabled true to continue updating */ public void setUpdateWhenEmpty(boolean enabled) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - CounterJNI.setCounterUpdateWhenEmpty(m_counter, (byte) (enabled ? 1 : 0), status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + CounterJNI.setCounterUpdateWhenEmpty(m_counter, enabled); } /** @@ -525,11 +465,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab */ @Override public boolean getStopped() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - boolean value = CounterJNI.getCounterStopped(m_counter, status.asIntBuffer()) != 0; - HALUtil.checkStatus(status.asIntBuffer()); - return value; + return CounterJNI.getCounterStopped(m_counter); } /** @@ -539,11 +475,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab */ @Override public boolean getDirection() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - boolean value = CounterJNI.getCounterDirection(m_counter, status.asIntBuffer()) != 0; - HALUtil.checkStatus(status.asIntBuffer()); - return value; + return CounterJNI.getCounterDirection(m_counter); } /** @@ -554,11 +486,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab * @param reverseDirection true if the value counted should be negated. */ public void setReverseDirection(boolean reverseDirection) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - CounterJNI.setCounterReverseDirection(m_counter, (byte) (reverseDirection ? 1 : 0), - status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + CounterJNI.setCounterReverseDirection(m_counter, reverseDirection); } /** @@ -570,11 +498,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab */ @Override public double getPeriod() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - double value = CounterJNI.getCounterPeriod(m_counter, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return value; + return CounterJNI.getCounterPeriod(m_counter); } /** @@ -596,13 +520,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab * @param samplesToAverage The number of samples to average from 1 to 127. */ public void setSamplesToAverage(int samplesToAverage) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - CounterJNI.setCounterSamplesToAverage(m_counter, samplesToAverage, status.asIntBuffer()); - if (status.asIntBuffer().get(0) == HALUtil.PARAMETER_OUT_OF_RANGE) { - throw new BoundaryException(BoundaryException.getMessage(samplesToAverage, 1, 127)); - } - HALUtil.checkStatus(status.asIntBuffer()); + CounterJNI.setCounterSamplesToAverage(m_counter, samplesToAverage); } /** @@ -614,11 +532,7 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab * 127) */ public int getSamplesToAverage() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - int value = CounterJNI.getCounterSamplesToAverage(m_counter, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return value; + return CounterJNI.getCounterSamplesToAverage(m_counter); } /** diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DigitalInput.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DigitalInput.java index 0addea5d45..13d9cf0abe 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DigitalInput.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DigitalInput.java @@ -7,13 +7,9 @@ package edu.wpi.first.wpilibj; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; import edu.wpi.first.wpilibj.communication.UsageReporting; import edu.wpi.first.wpilibj.hal.DIOJNI; -import edu.wpi.first.wpilibj.hal.HALUtil; import edu.wpi.first.wpilibj.livewindow.LiveWindow; import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable; import edu.wpi.first.wpilibj.tables.ITable; @@ -48,12 +44,7 @@ public class DigitalInput extends DigitalSource implements LiveWindowSendable { * @return the status of the digital input */ public boolean get() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - boolean value = DIOJNI.getDIO(m_port, status.asIntBuffer()) != 0; - HALUtil.checkStatus(status.asIntBuffer()); - return value; + return DIOJNI.getDIO(m_port); } /** diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DigitalOutput.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DigitalOutput.java index 0a2bc084bc..50a0a6f0af 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DigitalOutput.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DigitalOutput.java @@ -7,17 +7,12 @@ package edu.wpi.first.wpilibj; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - import edu.wpi.first.wpilibj.communication.UsageReporting; import edu.wpi.first.wpilibj.hal.DIOJNI; -import edu.wpi.first.wpilibj.hal.HALUtil; import edu.wpi.first.wpilibj.hal.PWMJNI; import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable; import edu.wpi.first.wpilibj.tables.ITable; import edu.wpi.first.wpilibj.tables.ITableListener; -// import com.sun.jna.Pointer; import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; /** @@ -27,7 +22,7 @@ import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tReso */ public class DigitalOutput extends DigitalSource implements LiveWindowSendable { - private ByteBuffer m_pwmGenerator; + private long m_pwmGenerator; /** * Create an instance of a digital output. Create an instance of a digital @@ -48,7 +43,7 @@ public class DigitalOutput extends DigitalSource implements LiveWindowSendable { @Override public void free() { // disable the pwm only if we have allocated it - if (m_pwmGenerator != null) { + if (m_pwmGenerator != 0) { disablePWM(); } super.free(); @@ -60,11 +55,7 @@ public class DigitalOutput extends DigitalSource implements LiveWindowSendable { * @param value true is on, off is false */ public void set(boolean value) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - DIOJNI.setDIO(m_port, (short) (value ? 1 : 0), status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + DIOJNI.setDIO(m_port, (short) (value ? 1 : 0)); } /** @@ -82,11 +73,7 @@ public class DigitalOutput extends DigitalSource implements LiveWindowSendable { * @param pulseLength The length of the pulse. */ public void pulse(final int channel, final float pulseLength) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - DIOJNI.pulse(m_port, pulseLength, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + DIOJNI.pulse(m_port, pulseLength); } /** @@ -99,15 +86,11 @@ public class DigitalOutput extends DigitalSource implements LiveWindowSendable { */ @Deprecated public void pulse(final int channel, final int pulseLength) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); float convertedPulse = - (float) (pulseLength / 1.0e9 * (DIOJNI.getLoopTiming(status.asIntBuffer()) * 25)); + (float) (pulseLength / 1.0e9 * (DIOJNI.getLoopTiming() * 25)); System.err .println("You should use the float version of pulse for portability. This is deprecated"); - DIOJNI.pulse(m_port, convertedPulse, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + DIOJNI.pulse(m_port, convertedPulse); } /** @@ -117,12 +100,7 @@ public class DigitalOutput extends DigitalSource implements LiveWindowSendable { * @return true if pulsing */ public boolean isPulsing() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - boolean value = DIOJNI.isPulsing(m_port, status.asIntBuffer()) != 0; - HALUtil.checkStatus(status.asIntBuffer()); - return value; + return DIOJNI.isPulsing(m_port); } /** @@ -136,11 +114,7 @@ public class DigitalOutput extends DigitalSource implements LiveWindowSendable { * @param rate The frequency to output all digital output PWM signals. */ public void setPWMRate(double rate) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - PWMJNI.setPWMRate(rate, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + PWMJNI.setPWMRate(rate); } /** @@ -157,16 +131,11 @@ public class DigitalOutput extends DigitalSource implements LiveWindowSendable { * @param initialDutyCycle The duty-cycle to start generating. [0..1] */ public void enablePWM(double initialDutyCycle) { - if (m_pwmGenerator != null) + if (m_pwmGenerator != 0) return; - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - m_pwmGenerator = PWMJNI.allocatePWM(status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - PWMJNI.setPWMDutyCycle(m_pwmGenerator, initialDutyCycle, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - PWMJNI.setPWMOutputChannel(m_pwmGenerator, m_channel, status.asIntBuffer()); + m_pwmGenerator = PWMJNI.allocatePWM(); + PWMJNI.setPWMDutyCycle(m_pwmGenerator, initialDutyCycle); + PWMJNI.setPWMOutputChannel(m_pwmGenerator, m_channel); } /** @@ -175,16 +144,12 @@ public class DigitalOutput extends DigitalSource implements LiveWindowSendable { * Free up one of the 6 DO PWM generator resources that were in use. */ public void disablePWM() { - if (m_pwmGenerator == null) + if (m_pwmGenerator == 0) return; // Disable the output by routing to a dead bit. - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - PWMJNI.setPWMOutputChannel(m_pwmGenerator, kDigitalChannels, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - PWMJNI.freePWM(m_pwmGenerator, status.asIntBuffer()); - m_pwmGenerator = null; + PWMJNI.setPWMOutputChannel(m_pwmGenerator, kDigitalChannels); + PWMJNI.freePWM(m_pwmGenerator); + m_pwmGenerator = 0; } /** @@ -196,13 +161,9 @@ public class DigitalOutput extends DigitalSource implements LiveWindowSendable { * @param dutyCycle The duty-cycle to change to. [0..1] */ public void updateDutyCycle(double dutyCycle) { - if (m_pwmGenerator == null) + if (m_pwmGenerator == 0) return; - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - PWMJNI.setPWMDutyCycle(m_pwmGenerator, dutyCycle, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + PWMJNI.setPWMDutyCycle(m_pwmGenerator, dutyCycle); } /* diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DigitalSource.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DigitalSource.java index abc66b41b0..160486fdd9 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DigitalSource.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DigitalSource.java @@ -7,11 +7,7 @@ package edu.wpi.first.wpilibj; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - import edu.wpi.first.wpilibj.hal.DIOJNI; -import edu.wpi.first.wpilibj.hal.HALUtil; import edu.wpi.first.wpilibj.util.AllocationException; import edu.wpi.first.wpilibj.util.CheckedAllocationException; @@ -25,7 +21,7 @@ import edu.wpi.first.wpilibj.util.CheckedAllocationException; public abstract class DigitalSource extends InterruptableSensorBase { protected static Resource channels = new Resource(kDigitalChannels); - protected ByteBuffer m_port; + protected long m_port; protected int m_channel; protected void initDigitalPort(int channel, boolean input) { @@ -42,24 +38,15 @@ public abstract class DigitalSource extends InterruptableSensorBase { throw new AllocationException("Digital input " + m_channel + " is already allocated"); } - ByteBuffer port_pointer = DIOJNI.getPort((byte) channel); - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - m_port = DIOJNI.initializeDigitalPort(port_pointer, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - DIOJNI.allocateDIO(m_port, (byte) (input ? 1 : 0), status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + long port_pointer = DIOJNI.getPort((byte) channel); + m_port = DIOJNI.initializeDigitalPort(port_pointer); + DIOJNI.allocateDIO(m_port, input); } @Override public void free() { channels.free(m_channel); - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - DIOJNI.freeDIO(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + DIOJNI.freeDIO(m_port); m_channel = 0; } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DriverStation.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DriverStation.java index b047e3f108..74928bf1cb 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DriverStation.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/DriverStation.java @@ -6,9 +6,7 @@ /*----------------------------------------------------------------------------*/ package edu.wpi.first.wpilibj; -import java.nio.IntBuffer; import java.nio.ByteBuffer; -import java.nio.ByteOrder; import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary; import edu.wpi.first.wpilibj.communication.HALControlWord; @@ -76,8 +74,8 @@ public class DriverStation implements RobotState.Interface { private boolean m_userInTeleop = false; private boolean m_userInTest = false; private boolean m_newControlData; - private final ByteBuffer m_packetDataAvailableMutex; - private final ByteBuffer m_packetDataAvailableSem; + private final long m_packetDataAvailableMutex; + private final long m_packetDataAvailableSem; /** * Gets an instance of the DriverStation @@ -197,11 +195,7 @@ public class DriverStation implements RobotState.Interface { * @return The battery voltage in Volts. */ public double getBatteryVoltage() { - IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer(); - float voltage = PowerJNI.getVinVoltage(status); - HALUtil.checkStatus(status); - - return voltage; + return PowerJNI.getVinVoltage(); } /** @@ -485,11 +479,7 @@ public class DriverStation implements RobotState.Interface { * @return True if the FPGA outputs are enabled. */ public boolean isSysActive() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - boolean retVal = FRCNetworkCommunicationsLibrary.HALGetSystemActive(status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return retVal; + return FRCNetworkCommunicationsLibrary.HALGetSystemActive(); } /** @@ -498,11 +488,7 @@ public class DriverStation implements RobotState.Interface { * @return True if the system is browned out */ public boolean isBrownedOut() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - boolean retVal = FRCNetworkCommunicationsLibrary.HALGetBrownedOut(status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return retVal; + return FRCNetworkCommunicationsLibrary.HALGetBrownedOut(); } /** diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Encoder.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Encoder.java index 269bea15a8..4a2130dfba 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Encoder.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Encoder.java @@ -13,7 +13,6 @@ import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInst import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; import edu.wpi.first.wpilibj.communication.UsageReporting; import edu.wpi.first.wpilibj.hal.EncoderJNI; -import edu.wpi.first.wpilibj.hal.HALUtil; import edu.wpi.first.wpilibj.livewindow.LiveWindow; import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable; import edu.wpi.first.wpilibj.tables.ITable; @@ -49,7 +48,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW * The index source */ protected DigitalSource m_indexSource = null; // Index on some encoders - private ByteBuffer m_encoder; + private long m_encoder; private int m_index; private double m_distancePerPulse; // distance of travel for each encoder // tick @@ -80,19 +79,15 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW switch (m_encodingType) { case k4X: m_encodingScale = 4; - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); ByteBuffer index = ByteBuffer.allocateDirect(4); // set the byte order index.order(ByteOrder.LITTLE_ENDIAN); m_encoder = EncoderJNI.initializeEncoder((byte) m_aSource.getModuleForRouting(), m_aSource - .getChannelForRouting(), (byte) (m_aSource.getAnalogTriggerForRouting() ? 1 : 0), + .getChannelForRouting(), m_aSource.getAnalogTriggerForRouting(), (byte) m_bSource.getModuleForRouting(), m_bSource.getChannelForRouting(), - (byte) (m_bSource.getAnalogTriggerForRouting() ? 1 : 0), - (byte) (reverseDirection ? 1 : 0), index.asIntBuffer(), status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + m_bSource.getAnalogTriggerForRouting(), + reverseDirection, index.asIntBuffer()); m_index = index.asIntBuffer().get(0); m_counter = null; setMaxPeriod(.5); @@ -378,11 +373,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW m_counter.free(); m_counter = null; } else { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - EncoderJNI.freeEncoder(m_encoder, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + EncoderJNI.freeEncoder(m_encoder); } } @@ -397,11 +388,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW if (m_counter != null) { value = m_counter.get(); } else { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - value = EncoderJNI.getEncoder(m_encoder, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + value = EncoderJNI.getEncoder(m_encoder); } return value; } @@ -425,11 +412,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW if (m_counter != null) { m_counter.reset(); } else { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - EncoderJNI.resetEncoder(m_encoder, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + EncoderJNI.resetEncoder(m_encoder); } } @@ -449,11 +432,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW if (m_counter != null) { measuredPeriod = m_counter.getPeriod() / decodingScaleFactor(); } else { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - measuredPeriod = EncoderJNI.getEncoderPeriod(m_encoder, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + measuredPeriod = EncoderJNI.getEncoderPeriod(m_encoder); } return measuredPeriod; } @@ -474,11 +453,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW if (m_counter != null) { m_counter.setMaxPeriod(maxPeriod * decodingScaleFactor()); } else { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - EncoderJNI.setEncoderMaxPeriod(m_encoder, maxPeriod, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + EncoderJNI.setEncoderMaxPeriod(m_encoder, maxPeriod); } } @@ -494,12 +469,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW if (m_counter != null) { return m_counter.getStopped(); } else { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - boolean value = EncoderJNI.getEncoderStopped(m_encoder, status.asIntBuffer()) != 0; - HALUtil.checkStatus(status.asIntBuffer()); - return value; + return EncoderJNI.getEncoderStopped(m_encoder); } } @@ -512,12 +482,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW if (m_counter != null) { return m_counter.getDirection(); } else { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - boolean value = EncoderJNI.getEncoderDirection(m_encoder, status.asIntBuffer()) != 0; - HALUtil.checkStatus(status.asIntBuffer()); - return value; + return EncoderJNI.getEncoderDirection(m_encoder); } } @@ -613,18 +578,12 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW public void setSamplesToAverage(int samplesToAverage) { switch (m_encodingType) { case k4X: - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - EncoderJNI.setEncoderSamplesToAverage(m_encoder, samplesToAverage, status.asIntBuffer()); - if (status.duplicate().get() == HALUtil.PARAMETER_OUT_OF_RANGE) { - throw new BoundaryException(BoundaryException.getMessage(samplesToAverage, 1, 127)); - } - HALUtil.checkStatus(status.asIntBuffer()); + EncoderJNI.setEncoderSamplesToAverage(m_encoder, samplesToAverage); break; case k1X: case k2X: m_counter.setSamplesToAverage(samplesToAverage); + break; } } @@ -639,12 +598,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW public int getSamplesToAverage() { switch (m_encodingType) { case k4X: - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - int value = EncoderJNI.getEncoderSamplesToAverage(m_encoder, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return value; + return EncoderJNI.getEncoderSamplesToAverage(m_encoder); case k1X: case k2X: return m_counter.getSamplesToAverage(); @@ -693,17 +647,12 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW * @param type The state that will cause the encoder to reset */ public void setIndexSource(int channel, IndexingType type) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - boolean activeHigh = (type == IndexingType.kResetWhileHigh) || (type == IndexingType.kResetOnRisingEdge); boolean edgeSensitive = (type == IndexingType.kResetOnFallingEdge) || (type == IndexingType.kResetOnRisingEdge); - EncoderJNI.setEncoderIndexSource(m_encoder, channel, false, activeHigh, edgeSensitive, - status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + EncoderJNI.setEncoderIndexSource(m_encoder, channel, false, activeHigh, edgeSensitive); } /** @@ -724,17 +673,13 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW * @param type The state that will cause the encoder to reset */ public void setIndexSource(DigitalSource source, IndexingType type) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - boolean activeHigh = (type == IndexingType.kResetWhileHigh) || (type == IndexingType.kResetOnRisingEdge); boolean edgeSensitive = (type == IndexingType.kResetOnFallingEdge) || (type == IndexingType.kResetOnRisingEdge); EncoderJNI.setEncoderIndexSource(m_encoder, source.getChannelForRouting(), - source.getAnalogTriggerForRouting(), activeHigh, edgeSensitive, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + source.getAnalogTriggerForRouting(), activeHigh, edgeSensitive); } /** diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/I2C.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/I2C.java index 959de2dcc5..2efdc4da4c 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/I2C.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/I2C.java @@ -7,13 +7,11 @@ package edu.wpi.first.wpilibj; import java.nio.ByteOrder; -import java.nio.IntBuffer; import java.nio.ByteBuffer; import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; import edu.wpi.first.wpilibj.communication.UsageReporting; import edu.wpi.first.wpilibj.hal.HALLibrary; -import edu.wpi.first.wpilibj.hal.HALUtil; import edu.wpi.first.wpilibj.hal.I2CJNI; import edu.wpi.first.wpilibj.util.BoundaryException; @@ -48,14 +46,10 @@ public class I2C extends SensorBase { * @param deviceAddress The address of the device on the I2C bus. */ public I2C(Port port, int deviceAddress) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - m_port = port; m_deviceAddress = deviceAddress; - I2CJNI.i2CInitialize((byte) m_port.getValue(), status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + I2CJNI.i2CInitialize((byte) m_port.getValue()); UsageReporting.report(tResourceType.kResourceType_I2C, deviceAddress); } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/InterruptableSensorBase.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/InterruptableSensorBase.java index 06433b3022..744e59f1f0 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/InterruptableSensorBase.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/InterruptableSensorBase.java @@ -7,10 +7,6 @@ package edu.wpi.first.wpilibj; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -import edu.wpi.first.wpilibj.hal.HALUtil; import edu.wpi.first.wpilibj.hal.InterruptJNI; import edu.wpi.first.wpilibj.util.AllocationException; import edu.wpi.first.wpilibj.util.CheckedAllocationException; @@ -19,22 +15,10 @@ import edu.wpi.first.wpilibj.util.CheckedAllocationException; * Base for sensors to be used with interrupts */ public abstract class InterruptableSensorBase extends SensorBase { - /** - * This is done to store the JVM variable in the InterruptJNI This is done - * because the HAL must have access to the JVM variable in order to attach the - * newly spawned thread when an interrupt is fired. - */ - static { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - InterruptJNI.initializeInterruptJVM(status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - } - /** * The interrupt resource */ - protected ByteBuffer m_interrupt = null; + protected long m_interrupt = 0; /** * Flags if the interrupt being allocated is synchronous @@ -54,7 +38,7 @@ public abstract class InterruptableSensorBase extends SensorBase { * Create a new InterrupatableSensorBase */ public InterruptableSensorBase() { - m_interrupt = null; + m_interrupt = 0; } /** @@ -83,24 +67,19 @@ public abstract class InterruptableSensorBase extends SensorBase { * default is interrupt on rising edges only. */ public void requestInterrupts(InterruptHandlerFunction handler) { - if (m_interrupt != null) { + if (m_interrupt != 0) { throw new AllocationException("The interrupt has already been allocated"); } allocateInterrupts(false); - assert (m_interrupt != null); + assert (m_interrupt != 0); - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); InterruptJNI.requestInterrupts(m_interrupt, getModuleForRouting(), getChannelForRouting(), - (byte) (getAnalogTriggerForRouting() ? 1 : 0), status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + getAnalogTriggerForRouting()); setUpSourceEdge(true, false); InterruptJNI.attachInterruptHandler(m_interrupt, handler.function, - handler.overridableParameter(), status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + handler.overridableParameter()); } /** @@ -110,20 +89,16 @@ public abstract class InterruptableSensorBase extends SensorBase { * The default is interrupt on rising edges only. */ public void requestInterrupts() { - if (m_interrupt != null) { + if (m_interrupt != 0) { throw new AllocationException("The interrupt has already been allocated"); } allocateInterrupts(true); - assert (m_interrupt != null); + assert (m_interrupt != 0); - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); InterruptJNI.requestInterrupts(m_interrupt, getModuleForRouting(), getChannelForRouting(), - (byte) (getAnalogTriggerForRouting() ? 1 : 0), status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + getAnalogTriggerForRouting()); setUpSourceEdge(true, false); } @@ -143,12 +118,8 @@ public abstract class InterruptableSensorBase extends SensorBase { } m_isSynchronousInterrupt = watcher; - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); m_interrupt = - InterruptJNI.initializeInterrupts(m_interruptIndex, (byte) (watcher ? 1 : 0), - status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + InterruptJNI.initializeInterrupts(m_interruptIndex, watcher); } /** @@ -156,14 +127,11 @@ public abstract class InterruptableSensorBase extends SensorBase { * structures and disables any interrupts. */ public void cancelInterrupts() { - if (m_interrupt == null) { + if (m_interrupt == 0) { throw new IllegalStateException("The interrupt is not allocated."); } - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - InterruptJNI.cleanInterrupts(m_interrupt, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - m_interrupt = null; + InterruptJNI.cleanInterrupts(m_interrupt); + m_interrupt = 0; interrupts.free(m_interruptIndex); } @@ -175,14 +143,10 @@ public abstract class InterruptableSensorBase extends SensorBase { * waitForInterrupt was called. */ public void waitForInterrupt(double timeout, boolean ignorePrevious) { - if (m_interrupt == null) { + if (m_interrupt == 0) { throw new IllegalStateException("The interrupt is not allocated."); } - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - InterruptJNI.waitForInterrupt(m_interrupt, (float) timeout, ignorePrevious, - status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + InterruptJNI.waitForInterrupt(m_interrupt, timeout, ignorePrevious); } /** @@ -200,32 +164,26 @@ public abstract class InterruptableSensorBase extends SensorBase { * options before starting to field interrupts. */ public void enableInterrupts() { - if (m_interrupt == null) { + if (m_interrupt == 0) { throw new IllegalStateException("The interrupt is not allocated."); } if (m_isSynchronousInterrupt) { throw new IllegalStateException("You do not need to enable synchronous interrupts"); } - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - InterruptJNI.enableInterrupts(m_interrupt, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + InterruptJNI.enableInterrupts(m_interrupt); } /** * Disable Interrupts without without deallocating structures. */ public void disableInterrupts() { - if (m_interrupt == null) { + if (m_interrupt == 0) { throw new IllegalStateException("The interrupt is not allocated."); } if (m_isSynchronousInterrupt) { throw new IllegalStateException("You can not disable synchronous interrupts"); } - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - InterruptJNI.disableInterrupts(m_interrupt, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + InterruptJNI.disableInterrupts(m_interrupt); } /** @@ -236,14 +194,10 @@ public abstract class InterruptableSensorBase extends SensorBase { * @return Timestamp in seconds since boot. */ public double readRisingTimestamp() { - if (m_interrupt == null) { + if (m_interrupt == 0) { throw new IllegalStateException("The interrupt is not allocated."); } - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - double timestamp = InterruptJNI.readRisingTimestamp(m_interrupt, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return timestamp; + return InterruptJNI.readRisingTimestamp(m_interrupt); } /** @@ -254,14 +208,10 @@ public abstract class InterruptableSensorBase extends SensorBase { * @return Timestamp in seconds since boot. */ public double readFallingTimestamp() { - if (m_interrupt == null) { + if (m_interrupt == 0) { throw new IllegalStateException("The interrupt is not allocated."); } - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - double timestamp = InterruptJNI.readFallingTimestamp(m_interrupt, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return timestamp; + return InterruptJNI.readFallingTimestamp(m_interrupt); } /** @@ -271,13 +221,9 @@ public abstract class InterruptableSensorBase extends SensorBase { * @param fallingEdge true to interrupt on falling edge */ public void setUpSourceEdge(boolean risingEdge, boolean fallingEdge) { - if (m_interrupt != null) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - InterruptJNI.setInterruptUpSourceEdge(m_interrupt, (byte) (risingEdge ? 1 : 0), - (byte) (fallingEdge ? 1 : 0), status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + if (m_interrupt != 0) { + InterruptJNI.setInterruptUpSourceEdge(m_interrupt, risingEdge, + fallingEdge); } else { throw new IllegalArgumentException("You must call RequestInterrupts before setUpSourceEdge"); } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Notifier.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Notifier.java index 57dd459f44..e407ef6bd2 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Notifier.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Notifier.java @@ -1,12 +1,9 @@ package edu.wpi.first.wpilibj; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.lang.Runtime; -import edu.wpi.first.wpilibj.hal.HALUtil; import edu.wpi.first.wpilibj.hal.NotifierJNI; import edu.wpi.first.wpilibj.Utility; @@ -58,7 +55,7 @@ public class Notifier { static private Notifier timerQueueHead = null; // The C pointer to the notifier object. We don't use it directly, it is just // passed to the JNI bindings. - private static ByteBuffer m_notifier; + private static long m_notifier; // The lock for the queue information (namely, timerQueueHead and the // m_nextEvent members). private static ReentrantLock queueLock = new ReentrantLock(); @@ -88,17 +85,6 @@ public class Notifier { // destructed. private ReentrantLock m_handlerLock = new ReentrantLock(); - /** - * This is done to store the JVM variable in the InterruptJNI This is done - * because the HAL must have access to the JVM variable in order to attach the - * newly spawned thread when an interrupt is fired. - */ - static { - ByteBuffer status = pointer(); - NotifierJNI.initializeNotifierJVM(status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - } - /** * Create a Notifier for timer event notification. *$ @@ -120,9 +106,7 @@ public class Notifier { // If this was the last instance of a Notifier, clean up after ourselves. if ((--refcount) == 0) { - ByteBuffer status = pointer(); - NotifierJNI.cleanNotifier(m_notifier, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + NotifierJNI.cleanNotifier(m_notifier); } queueLock.unlock(); @@ -140,10 +124,7 @@ public class Notifier { */ static protected void updateAlarm() { if (timerQueueHead != null) { - ByteBuffer status = pointer(); - NotifierJNI.updateNotifierAlarm(m_notifier, (int) (timerQueueHead.m_expirationTime * 1e6), - status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + NotifierJNI.updateNotifierAlarm(m_notifier, (int) (timerQueueHead.m_expirationTime * 1e6)); } } @@ -271,17 +252,7 @@ public class Notifier { // First time init. protected static void init() { - ByteBuffer status = pointer(); m_processQueue = new ProcessQueue(); - m_notifier = NotifierJNI.initializeNotifier(m_processQueue, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - } - - // Returns a ByteBuffer with the appropriate length and endianness to pass to - // the JNI bindings. - protected static ByteBuffer pointer() { - ByteBuffer buf = ByteBuffer.allocateDirect(HALUtil.pointerSize()); - buf.order(ByteOrder.LITTLE_ENDIAN); - return buf; + m_notifier = NotifierJNI.initializeNotifier(m_processQueue); } } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/PWM.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/PWM.java index 27ec4f8c59..899e633130 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/PWM.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/PWM.java @@ -7,9 +7,6 @@ package edu.wpi.first.wpilibj; -import java.nio.ByteOrder; -import java.nio.ByteBuffer; - import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; import edu.wpi.first.wpilibj.communication.UsageReporting; import edu.wpi.first.wpilibj.hal.PWMJNI; @@ -19,7 +16,6 @@ import edu.wpi.first.wpilibj.tables.ITable; import edu.wpi.first.wpilibj.tables.ITableListener; import edu.wpi.first.wpilibj.util.AllocationException; import edu.wpi.first.wpilibj.util.CheckedAllocationException; -import edu.wpi.first.wpilibj.hal.HALUtil; /** * Class implements the PWM generation in the FPGA. @@ -67,7 +63,7 @@ public class PWM extends SensorBase implements LiveWindowSendable { } private int m_channel; - private ByteBuffer m_port; + private long m_port; /** * kDefaultPwmPeriod is in ms * @@ -116,19 +112,13 @@ public class PWM extends SensorBase implements LiveWindowSendable { checkPWMChannel(channel); m_channel = channel; - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); + m_port = DIOJNI.initializeDigitalPort(DIOJNI.getPort((byte) m_channel)); - m_port = DIOJNI.initializeDigitalPort(DIOJNI.getPort((byte) m_channel), status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - - if (!PWMJNI.allocatePWMChannel(m_port, status.asIntBuffer())) { + if (!PWMJNI.allocatePWMChannel(m_port)) { throw new AllocationException("PWM channel " + channel + " is already allocated"); } - HALUtil.checkStatus(status.asIntBuffer()); - PWMJNI.setPWM(m_port, (short) 0, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + PWMJNI.setPWM(m_port, (short) 0); m_eliminateDeadband = false; @@ -150,17 +140,9 @@ public class PWM extends SensorBase implements LiveWindowSendable { * Free the resource associated with the PWM channel and set the value to 0. */ public void free() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - PWMJNI.setPWM(m_port, (short) 0, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - - PWMJNI.freePWMChannel(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - - PWMJNI.freeDIO(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + PWMJNI.setPWM(m_port, (short) 0); + PWMJNI.freePWMChannel(m_port); + PWMJNI.freeDIO(m_port); } /** @@ -209,11 +191,8 @@ public class PWM extends SensorBase implements LiveWindowSendable { */ protected void setBounds(double max, double deadbandMax, double center, double deadbandMin, double min) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - double loopTime = - DIOJNI.getLoopTiming(status.asIntBuffer()) / (kSystemClockTicksPerMicrosecond * 1e3); + DIOJNI.getLoopTiming() / (kSystemClockTicksPerMicrosecond * 1e3); m_maxPwm = (int) ((max - kDefaultPwmCenter) / loopTime + kDefaultPwmStepsDown - 1); m_deadbandMaxPwm = @@ -352,11 +331,7 @@ public class PWM extends SensorBase implements LiveWindowSendable { * @param value Raw PWM value. Range 0 - 255. */ public void setRaw(int value) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - PWMJNI.setPWM(m_port, (short) value, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + PWMJNI.setPWM(m_port, (short) value); } /** @@ -367,13 +342,7 @@ public class PWM extends SensorBase implements LiveWindowSendable { * @return Raw PWM control value. Range: 0 - 255. */ public int getRaw() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - int value = PWMJNI.getPWM(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - - return value; + return PWMJNI.getPWM(m_port); } /** @@ -382,36 +351,26 @@ public class PWM extends SensorBase implements LiveWindowSendable { * @param mult The period multiplier to apply to this channel */ public void setPeriodMultiplier(PeriodMultiplier mult) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - switch (mult.value) { case PeriodMultiplier.k4X_val: // Squelch 3 out of 4 outputs - PWMJNI.setPWMPeriodScale(m_port, 3, status.asIntBuffer()); + PWMJNI.setPWMPeriodScale(m_port, 3); break; case PeriodMultiplier.k2X_val: // Squelch 1 out of 2 outputs - PWMJNI.setPWMPeriodScale(m_port, 1, status.asIntBuffer()); + PWMJNI.setPWMPeriodScale(m_port, 1); break; case PeriodMultiplier.k1X_val: // Don't squelch any outputs - PWMJNI.setPWMPeriodScale(m_port, 0, status.asIntBuffer()); + PWMJNI.setPWMPeriodScale(m_port, 0); break; default: // Cannot hit this, limited by PeriodMultiplier enum } - - HALUtil.checkStatus(status.asIntBuffer()); } protected void setZeroLatch() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - PWMJNI.latchPWMZero(m_port, status.asIntBuffer()); - - HALUtil.checkStatus(status.asIntBuffer()); + PWMJNI.latchPWMZero(m_port); } private int getMaxPositivePwm() { diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/PowerDistributionPanel.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/PowerDistributionPanel.java index 50e551ee04..68edf4b178 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/PowerDistributionPanel.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/PowerDistributionPanel.java @@ -7,9 +7,6 @@ package edu.wpi.first.wpilibj; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - import edu.wpi.first.wpilibj.hal.PDPJNI; import edu.wpi.first.wpilibj.hal.HALUtil; import edu.wpi.first.wpilibj.livewindow.LiveWindow; @@ -43,12 +40,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend * @return The voltage of the PDP in volts */ public double getVoltage() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - double voltage = PDPJNI.getPDPVoltage(status.asIntBuffer(), m_module); - - return voltage; + return PDPJNI.getPDPVoltage(m_module); } /** @@ -57,12 +49,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend * @return The temperature of the PDP in degrees Celsius */ public double getTemperature() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - double temperature = PDPJNI.getPDPTemperature(status.asIntBuffer(), m_module); - - return temperature; + return PDPJNI.getPDPTemperature(m_module); } /** @@ -71,10 +58,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend * @return The current of one of the PDP channels (channels 0-15) in Amperes */ public double getCurrent(int channel) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - double current = PDPJNI.getPDPChannelCurrent((byte) channel, status.asIntBuffer(), m_module); + double current = PDPJNI.getPDPChannelCurrent((byte) channel, m_module); checkPDPChannel(channel); @@ -87,12 +71,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend * @return The current of all the channels in Amperes */ public double getTotalCurrent() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - double current = PDPJNI.getPDPTotalCurrent(status.asIntBuffer(), m_module); - - return current; + return PDPJNI.getPDPTotalCurrent(m_module); } /** @@ -101,13 +80,7 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend * @return the total power in Watts */ public double getTotalPower() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - double power = PDPJNI.getPDPTotalPower(status.asIntBuffer(), m_module); - - return power; - + return PDPJNI.getPDPTotalPower(m_module); } /** @@ -116,32 +89,21 @@ public class PowerDistributionPanel extends SensorBase implements LiveWindowSend * @return the total energy in Joules */ public double getTotalEnergy() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - double energy = PDPJNI.getPDPTotalEnergy(status.asIntBuffer(), m_module); - - return energy; + return PDPJNI.getPDPTotalEnergy(m_module); } /** * Reset the total energy to 0 */ public void resetTotalEnergy() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - PDPJNI.resetPDPTotalEnergy(status.asIntBuffer(), m_module); + PDPJNI.resetPDPTotalEnergy(m_module); } /** * Clear all PDP sticky faults */ public void clearStickyFaults() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - PDPJNI.clearPDPStickyFaults(status.asIntBuffer(), m_module); + PDPJNI.clearPDPStickyFaults(m_module); } public String getSmartDashboardType() { diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Relay.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Relay.java index 1f6843e981..8284bf49c4 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Relay.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Relay.java @@ -7,13 +7,9 @@ package edu.wpi.first.wpilibj; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; import edu.wpi.first.wpilibj.communication.UsageReporting; import edu.wpi.first.wpilibj.hal.DIOJNI; -import edu.wpi.first.wpilibj.hal.HALUtil; import edu.wpi.first.wpilibj.hal.RelayJNI; import edu.wpi.first.wpilibj.livewindow.LiveWindow; import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable; @@ -112,7 +108,7 @@ public class Relay extends SensorBase implements MotorSafety, LiveWindowSendable } private final int m_channel; - private ByteBuffer m_port; + private long m_port; private Direction m_direction; private static Resource relayChannels = new Resource(kRelayChannels * 2); @@ -137,11 +133,7 @@ public class Relay extends SensorBase implements MotorSafety, LiveWindowSendable throw new AllocationException("Relay channel " + m_channel + " is already allocated"); } - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - m_port = DIOJNI.initializeDigitalPort(DIOJNI.getPort((byte) m_channel), status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + m_port = DIOJNI.initializeDigitalPort(DIOJNI.getPort((byte) m_channel)); m_safetyHelper = new MotorSafetyHelper(this); m_safetyHelper.setSafetyEnabled(false); @@ -182,16 +174,10 @@ public class Relay extends SensorBase implements MotorSafety, LiveWindowSendable relayChannels.free(m_channel * 2 + 1); } - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); + RelayJNI.setRelayForward(m_port, false); + RelayJNI.setRelayReverse(m_port, false); - RelayJNI.setRelayForward(m_port, (byte) 0, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - RelayJNI.setRelayReverse(m_port, (byte) 0, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - - DIOJNI.freeDIO(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + DIOJNI.freeDIO(m_port); } /** @@ -210,51 +196,46 @@ public class Relay extends SensorBase implements MotorSafety, LiveWindowSendable * @param value The state to set the relay. */ public void set(Value value) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - switch (value) { case kOff: if (m_direction == Direction.kBoth || m_direction == Direction.kForward) { - RelayJNI.setRelayForward(m_port, (byte) 0, status.asIntBuffer()); + RelayJNI.setRelayForward(m_port, false); } if (m_direction == Direction.kBoth || m_direction == Direction.kReverse) { - RelayJNI.setRelayReverse(m_port, (byte) 0, status.asIntBuffer()); + RelayJNI.setRelayReverse(m_port, false); } break; case kOn: if (m_direction == Direction.kBoth || m_direction == Direction.kForward) { - RelayJNI.setRelayForward(m_port, (byte) 1, status.asIntBuffer()); + RelayJNI.setRelayForward(m_port, true); } if (m_direction == Direction.kBoth || m_direction == Direction.kReverse) { - RelayJNI.setRelayReverse(m_port, (byte) 1, status.asIntBuffer()); + RelayJNI.setRelayReverse(m_port, true); } break; case kForward: if (m_direction == Direction.kReverse) throw new InvalidValueException("A relay configured for reverse cannot be set to forward"); if (m_direction == Direction.kBoth || m_direction == Direction.kForward) { - RelayJNI.setRelayForward(m_port, (byte) 1, status.asIntBuffer()); + RelayJNI.setRelayForward(m_port, true); } if (m_direction == Direction.kBoth) { - RelayJNI.setRelayReverse(m_port, (byte) 0, status.asIntBuffer()); + RelayJNI.setRelayReverse(m_port, false); } break; case kReverse: if (m_direction == Direction.kForward) throw new InvalidValueException("A relay configured for forward cannot be set to reverse"); if (m_direction == Direction.kBoth) { - RelayJNI.setRelayForward(m_port, (byte) 0, status.asIntBuffer()); + RelayJNI.setRelayForward(m_port, false); } if (m_direction == Direction.kBoth || m_direction == Direction.kReverse) { - RelayJNI.setRelayReverse(m_port, (byte) 1, status.asIntBuffer()); + RelayJNI.setRelayReverse(m_port, true); } break; default: // Cannot hit this, limited by Value enum } - - HALUtil.checkStatus(status.asIntBuffer()); } /** @@ -268,11 +249,8 @@ public class Relay extends SensorBase implements MotorSafety, LiveWindowSendable * @return The current state of the relay as a Relay::Value */ public Value get() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - if (RelayJNI.getRelayForward(m_port, status.asIntBuffer()) != 0) { - if (RelayJNI.getRelayReverse(m_port, status.asIntBuffer()) != 0) { + if (RelayJNI.getRelayForward(m_port)) { + if (RelayJNI.getRelayReverse(m_port)) { return Value.kOn; } else { if (m_direction == Direction.kForward) { @@ -282,7 +260,7 @@ public class Relay extends SensorBase implements MotorSafety, LiveWindowSendable } } } else { - if (RelayJNI.getRelayReverse(m_port, status.asIntBuffer()) != 0) { + if (RelayJNI.getRelayReverse(m_port)) { if (m_direction == Direction.kReverse) { return Value.kOn; } else { diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/RobotBase.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/RobotBase.java index 51df54dd44..0250c4a6e4 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/RobotBase.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/RobotBase.java @@ -23,6 +23,7 @@ import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tReso import edu.wpi.first.wpilibj.communication.UsageReporting; import edu.wpi.first.wpilibj.internal.HardwareHLUsageReporting; import edu.wpi.first.wpilibj.internal.HardwareTimer; +import edu.wpi.first.wpilibj.networktables.NetworkTablesJNI; import edu.wpi.first.wpilibj.networktables.NetworkTable; import edu.wpi.first.wpilibj.Utility; @@ -44,6 +45,12 @@ public abstract class RobotBase { protected final DriverStation m_ds; + private static class MyLogger implements NetworkTablesJNI.LoggerFunction { + public void apply(int level, String file, int line, String msg) { + System.err.println(msg); + } + } + /** * Constructor for a generic robot program. User code should be placed in the * constructor that runs before the Autonomous or Operator Control period @@ -59,6 +66,7 @@ public abstract class RobotBase { // TODO: See if the next line is necessary // Resource.RestartProgram(); + NetworkTablesJNI.setLogger(new MyLogger(), 0); NetworkTable.setNetworkIdentity("Robot"); NetworkTable.setServerMode();// must be before b m_ds = DriverStation.getInstance(); @@ -194,21 +202,21 @@ public abstract class RobotBase { UsageReporting.report(tResourceType.kResourceType_Language, tInstances.kLanguage_Java); - String robotName = ""; - Enumeration resources = null; - try { - resources = RobotBase.class.getClassLoader().getResources("META-INF/MANIFEST.MF"); - } catch (IOException e) { - e.printStackTrace(); - } - while (resources != null && resources.hasMoreElements()) { - try { - Manifest manifest = new Manifest(resources.nextElement().openStream()); - robotName = manifest.getMainAttributes().getValue("Robot-Class"); - } catch (IOException e) { - e.printStackTrace(); - } - } + String robotName = "MyRobot"; + //Enumeration resources = null; + //try { + // resources = RobotBase.class.getClassLoader().getResources("META-INF/MANIFEST.MF"); + //} catch (IOException e) { + // e.printStackTrace(); + //} + //while (resources != null && resources.hasMoreElements()) { + // try { + // Manifest manifest = new Manifest(resources.nextElement().openStream()); + // robotName = manifest.getMainAttributes().getValue("Robot-Class"); + // } catch (IOException e) { + // e.printStackTrace(); + // } + //} RobotBase robot; try { diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SPI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SPI.java index 9210abe5b8..a97f845929 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SPI.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SPI.java @@ -1,13 +1,10 @@ package edu.wpi.first.wpilibj; -import java.nio.ByteOrder; -import java.nio.IntBuffer; import java.nio.ByteBuffer; import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; import edu.wpi.first.wpilibj.communication.UsageReporting; import edu.wpi.first.wpilibj.hal.HALLibrary; -import edu.wpi.first.wpilibj.hal.HALUtil; import edu.wpi.first.wpilibj.hal.SPIJNI; /** @@ -45,14 +42,10 @@ public class SPI extends SensorBase { * @param port the physical SPI port */ public SPI(Port port) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - m_port = (byte) port.getValue(); devices++; - SPIJNI.spiInitialize(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + SPIJNI.spiInitialize(m_port); UsageReporting.report(tResourceType.kResourceType_SPI, devices); } @@ -132,24 +125,14 @@ public class SPI extends SensorBase { * Configure the chip select line to be active high. */ public final void setChipSelectActiveHigh() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - SPIJNI.spiSetChipSelectActiveHigh(m_port, status.asIntBuffer()); - - HALUtil.checkStatus(status.asIntBuffer()); + SPIJNI.spiSetChipSelectActiveHigh(m_port); } /** * Configure the chip select line to be active low. */ public final void setChipSelectActiveLow() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - SPIJNI.spiSetChipSelectActiveLow(m_port, status.asIntBuffer()); - - HALUtil.checkStatus(status.asIntBuffer()); + SPIJNI.spiSetChipSelectActiveLow(m_port); } /** diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SerialPort.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SerialPort.java index 7f1a16bc50..ff2e9c1f78 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SerialPort.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SerialPort.java @@ -8,14 +8,11 @@ package edu.wpi.first.wpilibj; import java.io.UnsupportedEncodingException; -import java.nio.ByteOrder; -import java.nio.IntBuffer; import java.nio.ByteBuffer; import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; import edu.wpi.first.wpilibj.communication.UsageReporting; import edu.wpi.first.wpilibj.hal.HALLibrary; -import edu.wpi.first.wpilibj.hal.HALUtil; import edu.wpi.first.wpilibj.hal.SerialPortJNI; /** @@ -191,20 +188,13 @@ public class SerialPort { */ public SerialPort(final int baudRate, Port port, final int dataBits, Parity parity, StopBits stopBits) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); m_port = (byte) port.getValue(); - SerialPortJNI.serialInitializePort(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - SerialPortJNI.serialSetBaudRate(m_port, baudRate, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - SerialPortJNI.serialSetDataBits(m_port, (byte) dataBits, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - SerialPortJNI.serialSetParity(m_port, (byte) parity.value, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - SerialPortJNI.serialSetStopBits(m_port, (byte) stopBits.value, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + SerialPortJNI.serialInitializePort(m_port); + SerialPortJNI.serialSetBaudRate(m_port, baudRate); + SerialPortJNI.serialSetDataBits(m_port, (byte) dataBits); + SerialPortJNI.serialSetParity(m_port, (byte) parity.value); + SerialPortJNI.serialSetStopBits(m_port, (byte) stopBits.value); // Set the default read buffer size to 1 to return bytes immediately setReadBufferSize(1); @@ -258,10 +248,7 @@ public class SerialPort { * Destructor. */ public void free() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - SerialPortJNI.serialClose(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + SerialPortJNI.serialClose(m_port); } /** @@ -272,10 +259,7 @@ public class SerialPort { * @param flowControl the FlowControl value to use */ public void setFlowControl(FlowControl flowControl) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - SerialPortJNI.serialSetFlowControl(m_port, (byte) flowControl.value, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + SerialPortJNI.serialSetFlowControl(m_port, (byte) flowControl.value); } /** @@ -288,10 +272,7 @@ public class SerialPort { * @param terminator The character to use for termination. */ public void enableTermination(char terminator) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - SerialPortJNI.serialEnableTermination(m_port, terminator, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + SerialPortJNI.serialEnableTermination(m_port, terminator); } /** @@ -311,10 +292,7 @@ public class SerialPort { * Disable termination behavior. */ public void disableTermination() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - SerialPortJNI.serialDisableTermination(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + SerialPortJNI.serialDisableTermination(m_port); } /** @@ -323,12 +301,7 @@ public class SerialPort { * @return The number of bytes available to read. */ public int getBytesReceived() { - int retVal = 0; - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - retVal = SerialPortJNI.serialGetBytesRecieved(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return retVal; + return SerialPortJNI.serialGetBytesRecieved(m_port); } /** @@ -363,11 +336,8 @@ public class SerialPort { * @return An array of the read bytes */ public byte[] read(final int count) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); ByteBuffer dataReceivedBuffer = ByteBuffer.allocateDirect(count); - int gotten = SerialPortJNI.serialRead(m_port, dataReceivedBuffer, count, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + int gotten = SerialPortJNI.serialRead(m_port, dataReceivedBuffer, count); byte[] retVal = new byte[gotten]; dataReceivedBuffer.get(retVal); return retVal; @@ -381,13 +351,9 @@ public class SerialPort { * @return The number of bytes actually written into the port. */ public int write(byte[] buffer, int count) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); ByteBuffer dataToSendBuffer = ByteBuffer.allocateDirect(count); dataToSendBuffer.put(buffer, 0, count); - int retVal = SerialPortJNI.serialWrite(m_port, dataToSendBuffer, count, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return retVal; + return SerialPortJNI.serialWrite(m_port, dataToSendBuffer, count); } /** @@ -410,10 +376,7 @@ public class SerialPort { * @param timeout The number of seconds to to wait for I/O. */ public void setTimeout(double timeout) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - SerialPortJNI.serialSetTimeout(m_port, (float) timeout, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + SerialPortJNI.serialSetTimeout(m_port, (float) timeout); } /** @@ -429,10 +392,7 @@ public class SerialPort { * @param size The read buffer size. */ public void setReadBufferSize(int size) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - SerialPortJNI.serialSetReadBufferSize(m_port, size, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + SerialPortJNI.serialSetReadBufferSize(m_port, size); } /** @@ -444,10 +404,7 @@ public class SerialPort { * @param size The write buffer size. */ public void setWriteBufferSize(int size) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - SerialPortJNI.serialSetWriteBufferSize(m_port, size, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + SerialPortJNI.serialSetWriteBufferSize(m_port, size); } /** @@ -462,10 +419,7 @@ public class SerialPort { * @param mode The write buffer mode. */ public void setWriteBufferMode(WriteBufferMode mode) { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - SerialPortJNI.serialSetWriteMode(m_port, (byte) mode.value, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + SerialPortJNI.serialSetWriteMode(m_port, (byte) mode.value); } /** @@ -475,10 +429,7 @@ public class SerialPort { * flush before the buffer is full. */ public void flush() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - SerialPortJNI.serialFlush(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + SerialPortJNI.serialFlush(m_port); } /** @@ -487,9 +438,6 @@ public class SerialPort { * Empty the transmit and receive buffers in the device and formatted I/O. */ public void reset() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - SerialPortJNI.serialClear(m_port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + SerialPortJNI.serialClear(m_port); } } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Solenoid.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Solenoid.java index fb9f360600..bbcc033dc8 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Solenoid.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Solenoid.java @@ -7,12 +7,8 @@ package edu.wpi.first.wpilibj; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; import edu.wpi.first.wpilibj.communication.UsageReporting; -import edu.wpi.first.wpilibj.hal.HALUtil; import edu.wpi.first.wpilibj.hal.SolenoidJNI; import edu.wpi.first.wpilibj.livewindow.LiveWindow; import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable; @@ -30,7 +26,7 @@ import edu.wpi.first.wpilibj.util.CheckedAllocationException; public class Solenoid extends SolenoidBase implements LiveWindowSendable { private int m_channel; // /< The channel to control. - private ByteBuffer m_solenoid_port; + private long m_solenoid_port; /** * Common function to implement constructor behavior. @@ -39,12 +35,8 @@ public class Solenoid extends SolenoidBase implements LiveWindowSendable { checkSolenoidModule(m_moduleNumber); checkSolenoidChannel(m_channel); - ByteBuffer status = ByteBuffer.allocateDirect(4); - status.order(ByteOrder.LITTLE_ENDIAN); - - ByteBuffer port = SolenoidJNI.getPortWithModule((byte) m_moduleNumber, (byte) m_channel); - m_solenoid_port = SolenoidJNI.initializeSolenoidPort(port, status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); + long port = SolenoidJNI.getPortWithModule((byte) m_moduleNumber, (byte) m_channel); + m_solenoid_port = SolenoidJNI.initializeSolenoidPort(port); LiveWindow.addActuator("Solenoid", m_moduleNumber, m_channel, this); UsageReporting.report(tResourceType.kResourceType_Solenoid, m_channel, m_moduleNumber); diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SolenoidBase.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SolenoidBase.java index ffcc3017ba..6462ab1fd3 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SolenoidBase.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/SolenoidBase.java @@ -7,10 +7,6 @@ package edu.wpi.first.wpilibj; -import java.nio.IntBuffer; -import java.nio.ByteBuffer; - -import edu.wpi.first.wpilibj.hal.HALUtil; import edu.wpi.first.wpilibj.hal.SolenoidJNI; /** @@ -19,7 +15,7 @@ import edu.wpi.first.wpilibj.hal.SolenoidJNI; */ public abstract class SolenoidBase extends SensorBase { - private ByteBuffer[] m_ports; + private long[] m_ports; protected int m_moduleNumber; // /< The number of the solenoid module being // used. protected Resource m_allocated = new Resource(63 * SensorBase.kSolenoidChannels); @@ -31,12 +27,10 @@ public abstract class SolenoidBase extends SensorBase { */ public SolenoidBase(final int moduleNumber) { m_moduleNumber = moduleNumber; - m_ports = new ByteBuffer[SensorBase.kSolenoidChannels]; + m_ports = new long[SensorBase.kSolenoidChannels]; for (int i = 0; i < SensorBase.kSolenoidChannels; i++) { - ByteBuffer port = SolenoidJNI.getPortWithModule((byte) moduleNumber, (byte) i); - IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer(); - m_ports[i] = SolenoidJNI.initializeSolenoidPort(port, status); - HALUtil.checkStatus(status); + long port = SolenoidJNI.getPortWithModule((byte) moduleNumber, (byte) i); + m_ports[i] = SolenoidJNI.initializeSolenoidPort(port); } } @@ -47,13 +41,11 @@ public abstract class SolenoidBase extends SensorBase { * @param mask The channels you want to be affected. */ protected synchronized void set(int value, int mask) { - IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer(); for (int i = 0; i < SensorBase.kSolenoidChannels; i++) { int local_mask = 1 << i; if ((mask & local_mask) != 0) - SolenoidJNI.setSolenoid(m_ports[i], (byte) (value & local_mask), status); + SolenoidJNI.setSolenoid(m_ports[i], (value & local_mask) != 0); } - HALUtil.checkStatus(status); } /** @@ -63,11 +55,9 @@ public abstract class SolenoidBase extends SensorBase { */ public byte getAll() { byte value = 0; - IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer(); for (int i = 0; i < SensorBase.kSolenoidChannels; i++) { - value |= SolenoidJNI.getSolenoid(m_ports[i], status) << i; + value |= (SolenoidJNI.getSolenoid(m_ports[i]) ? 1 : 0) << i; } - HALUtil.checkStatus(status); return value; } @@ -82,12 +72,7 @@ public abstract class SolenoidBase extends SensorBase { * @return The solenoid blacklist of all 8 solenoids on the module. */ public byte getPCMSolenoidBlackList() { - IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer(); - - byte retval = SolenoidJNI.getPCMSolenoidBlackList(m_ports[0], status); - HALUtil.checkStatus(status); - - return retval; + return (byte)SolenoidJNI.getPCMSolenoidBlackList(m_ports[0]); } /** @@ -95,12 +80,7 @@ public abstract class SolenoidBase extends SensorBase { * voltage rail is too low, most likely a solenoid channel is shorted. */ public boolean getPCMSolenoidVoltageStickyFault() { - IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer(); - - boolean retval = SolenoidJNI.getPCMSolenoidVoltageStickyFault(m_ports[0], status); - HALUtil.checkStatus(status); - - return retval; + return SolenoidJNI.getPCMSolenoidVoltageStickyFault(m_ports[0]); } /** @@ -108,12 +88,7 @@ public abstract class SolenoidBase extends SensorBase { * voltage rail is too low, most likely a solenoid channel is shorted. */ public boolean getPCMSolenoidVoltageFault() { - IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer(); - - boolean retval = SolenoidJNI.getPCMSolenoidVoltageFault(m_ports[0], status); - HALUtil.checkStatus(status); - - return retval; + return SolenoidJNI.getPCMSolenoidVoltageFault(m_ports[0]); } /** @@ -127,9 +102,6 @@ public abstract class SolenoidBase extends SensorBase { * If no sticky faults are set then this call will have no effect. */ public void clearAllPCMStickyFaults() { - IntBuffer status = ByteBuffer.allocateDirect(4).asIntBuffer(); - - SolenoidJNI.clearAllPCMStickyFaults(m_ports[0], status); - HALUtil.checkStatus(status); + SolenoidJNI.clearAllPCMStickyFaults(m_ports[0]); } } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Utility.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Utility.java index 6d8d0f0336..e0878c7d47 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Utility.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Utility.java @@ -7,14 +7,7 @@ package edu.wpi.first.wpilibj; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.IntBuffer; -import java.lang.StackTraceElement; - -import edu.wpi.first.wpilibj.hal.HALLibrary; import edu.wpi.first.wpilibj.hal.HALUtil; -import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary; /** * Contains global utility functions @@ -29,12 +22,7 @@ public class Utility { * @return FPGA Version number. */ int getFPGAVersion() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - int value = HALUtil.getFPGAVersion(status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return value; + return HALUtil.getFPGAVersion(); } /** @@ -45,12 +33,7 @@ public class Utility { * @return FPGA Revision number. */ long getFPGARevision() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - int value = HALUtil.getFPGARevision(status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return (long) value; + return (long) HALUtil.getFPGARevision(); } /** @@ -59,13 +42,7 @@ public class Utility { * @return The current time in microseconds according to the FPGA. */ public static long getFPGATime() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - - long value = HALUtil.getFPGATime(status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return value; + return HALUtil.getFPGATime(); } /** @@ -74,12 +51,6 @@ public class Utility { * @return true if the button is currently pressed down */ public static boolean getUserButton() { - ByteBuffer status = ByteBuffer.allocateDirect(4); - // set the byte order - status.order(ByteOrder.LITTLE_ENDIAN); - - boolean value = HALUtil.getFPGAButton(status.asIntBuffer()); - HALUtil.checkStatus(status.asIntBuffer()); - return value; + return HALUtil.getFPGAButton(); } } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/can/CANExceptionFactory.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/can/CANExceptionFactory.java deleted file mode 100644 index 44fb9d0ca2..0000000000 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/can/CANExceptionFactory.java +++ /dev/null @@ -1,42 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ -/* Open Source Software - may be modified and shared by FRC teams. The code */ -/* must be accompanied by the FIRST BSD license file in the root directory of */ -/* the project. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.can; - -import edu.wpi.first.wpilibj.communication.NIRioStatus; -import edu.wpi.first.wpilibj.util.UncleanStatusException; - -public class CANExceptionFactory { - // FRC Error codes - static final int ERR_CANSessionMux_InvalidBuffer = -44086; - static final int ERR_CANSessionMux_MessageNotFound = -44087; - static final int ERR_CANSessionMux_NotAllowed = -44088; - static final int ERR_CANSessionMux_NotInitialized = -44089; - - public static void checkStatus(int status, int messageID) throws CANInvalidBufferException, - CANMessageNotAllowedException, CANNotInitializedException, UncleanStatusException { - switch (status) { - case NIRioStatus.kRioStatusSuccess: - // Everything is ok... don't throw. - return; - case ERR_CANSessionMux_InvalidBuffer: - case NIRioStatus.kRIOStatusBufferInvalidSize: - throw new CANInvalidBufferException(); - case ERR_CANSessionMux_MessageNotFound: - case NIRioStatus.kRIOStatusOperationTimedOut: - throw new CANMessageNotFoundException(); - case ERR_CANSessionMux_NotAllowed: - case NIRioStatus.kRIOStatusFeatureNotSupported: - throw new CANMessageNotAllowedException("MessageID = " + Integer.toString(messageID)); - case ERR_CANSessionMux_NotInitialized: - case NIRioStatus.kRIOStatusResourceNotInitialized: - throw new CANNotInitializedException(); - default: - throw new UncleanStatusException("Fatal status code detected: " + Integer.toString(status)); - } - } -} diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/can/CANJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/can/CANJNI.java index 825e304403..353f6749e4 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/can/CANJNI.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/can/CANJNI.java @@ -497,8 +497,8 @@ public class CANJNI extends JNIWrapper { public static final int CAN_IS_FRAME_11BIT = 0x40000000; public static native void FRCNetworkCommunicationCANSessionMuxSendMessage(int messageID, - ByteBuffer data, int periodMs, IntBuffer status); + ByteBuffer data, int periodMs); public static native ByteBuffer FRCNetworkCommunicationCANSessionMuxReceiveMessage( - IntBuffer messageID, int messageIDMask, ByteBuffer timeStamp, IntBuffer status); + IntBuffer messageID, int messageIDMask, ByteBuffer timeStamp); } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/communication/FRCNetworkCommunicationsLibrary.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/communication/FRCNetworkCommunicationsLibrary.java index 016a059399..871c3f8059 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/communication/FRCNetworkCommunicationsLibrary.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/communication/FRCNetworkCommunicationsLibrary.java @@ -855,7 +855,7 @@ public class FRCNetworkCommunicationsLibrary extends JNIWrapper { * native declaration : * src\main\include\NetworkCommunication\FRCComm.h:147 */ - public static native void setNewDataSem(ByteBuffer mutexId); + public static native void setNewDataSem(long mutexId); /** * Original signature : void setResyncSem(pthread_mutex_t*)
@@ -971,9 +971,9 @@ public class FRCNetworkCommunicationsLibrary extends JNIWrapper { public static native float HALGetMatchTime(); - public static native boolean HALGetSystemActive(IntBuffer status); + public static native boolean HALGetSystemActive(); - public static native boolean HALGetBrownedOut(IntBuffer status); + public static native boolean HALGetBrownedOut(); public static native int HALSetErrorData(String error); } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/AnalogJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/AnalogJNI.java index ea0cb60450..a90e592494 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/AnalogJNI.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/AnalogJNI.java @@ -1,7 +1,6 @@ package edu.wpi.first.wpilibj.hal; import java.nio.IntBuffer; -import java.nio.ByteBuffer; import java.nio.LongBuffer; public class AnalogJNI extends JNIWrapper { @@ -33,95 +32,82 @@ public class AnalogJNI extends JNIWrapper { public static final int kFallingPulse = 3; }; - public static native ByteBuffer initializeAnalogInputPort(ByteBuffer port_pointer, - IntBuffer status); + public static native long initializeAnalogInputPort(long port_pointer); - public static native ByteBuffer initializeAnalogOutputPort(ByteBuffer port_pointer, - IntBuffer status); + public static native long initializeAnalogOutputPort(long port_pointer); - public static native byte checkAnalogModule(byte module); + public static native boolean checkAnalogModule(byte module); - public static native byte checkAnalogInputChannel(int pin); + public static native boolean checkAnalogInputChannel(int pin); - public static native byte checkAnalogOutputChannel(int pin); + public static native boolean checkAnalogOutputChannel(int pin); - public static native void setAnalogOutput(ByteBuffer port_pointer, double voltage, - IntBuffer status); + public static native void setAnalogOutput(long port_pointer, double voltage); - public static native double getAnalogOutput(ByteBuffer port_pointer, IntBuffer status); + public static native double getAnalogOutput(long port_pointer); - public static native void setAnalogSampleRate(double samplesPerSecond, IntBuffer status); + public static native void setAnalogSampleRate(double samplesPerSecond); - public static native double getAnalogSampleRate(IntBuffer status); + public static native double getAnalogSampleRate(); - public static native void setAnalogAverageBits(ByteBuffer analog_port_pointer, int bits, - IntBuffer status); + public static native void setAnalogAverageBits(long analog_port_pointer, int bits); - public static native int getAnalogAverageBits(ByteBuffer analog_port_pointer, IntBuffer status); + public static native int getAnalogAverageBits(long analog_port_pointer); - public static native void setAnalogOversampleBits(ByteBuffer analog_port_pointer, int bits, - IntBuffer status); + public static native void setAnalogOversampleBits(long analog_port_pointer, int bits); - public static native int getAnalogOversampleBits(ByteBuffer analog_port_pointer, IntBuffer status); + public static native int getAnalogOversampleBits(long analog_port_pointer); - public static native short getAnalogValue(ByteBuffer analog_port_pointer, IntBuffer status); + public static native short getAnalogValue(long analog_port_pointer); - public static native int getAnalogAverageValue(ByteBuffer analog_port_pointer, IntBuffer status); + public static native int getAnalogAverageValue(long analog_port_pointer); - public static native int getAnalogVoltsToValue(ByteBuffer analog_port_pointer, double voltage, - IntBuffer status); + public static native int getAnalogVoltsToValue(long analog_port_pointer, double voltage); - public static native double getAnalogVoltage(ByteBuffer analog_port_pointer, IntBuffer status); + public static native double getAnalogVoltage(long analog_port_pointer); - public static native double getAnalogAverageVoltage(ByteBuffer analog_port_pointer, - IntBuffer status); + public static native double getAnalogAverageVoltage(long analog_port_pointer); - public static native int getAnalogLSBWeight(ByteBuffer analog_port_pointer, IntBuffer status); + public static native int getAnalogLSBWeight(long analog_port_pointer); - public static native int getAnalogOffset(ByteBuffer analog_port_pointer, IntBuffer status); + public static native int getAnalogOffset(long analog_port_pointer); - public static native byte isAccumulatorChannel(ByteBuffer analog_port_pointer, IntBuffer status); + public static native boolean isAccumulatorChannel(long analog_port_pointer); - public static native void initAccumulator(ByteBuffer analog_port_pointer, IntBuffer status); + public static native void initAccumulator(long analog_port_pointer); - public static native void resetAccumulator(ByteBuffer analog_port_pointer, IntBuffer status); + public static native void resetAccumulator(long analog_port_pointer); - public static native void setAccumulatorCenter(ByteBuffer analog_port_pointer, int center, - IntBuffer status); + public static native void setAccumulatorCenter(long analog_port_pointer, int center); - public static native void setAccumulatorDeadband(ByteBuffer analog_port_pointer, int deadband, - IntBuffer status); + public static native void setAccumulatorDeadband(long analog_port_pointer, int deadband); - public static native long getAccumulatorValue(ByteBuffer analog_port_pointer, IntBuffer status); + public static native long getAccumulatorValue(long analog_port_pointer); - public static native int getAccumulatorCount(ByteBuffer analog_port_pointer, IntBuffer status); + public static native int getAccumulatorCount(long analog_port_pointer); - public static native void getAccumulatorOutput(ByteBuffer analog_port_pointer, LongBuffer value, - IntBuffer count, IntBuffer status); + public static native void getAccumulatorOutput(long analog_port_pointer, LongBuffer value, + IntBuffer count); - public static native ByteBuffer initializeAnalogTrigger(ByteBuffer port_pointer, IntBuffer index, - IntBuffer status); + public static native long initializeAnalogTrigger(long port_pointer, IntBuffer index); - public static native void cleanAnalogTrigger(ByteBuffer analog_trigger_pointer, IntBuffer status); + public static native void cleanAnalogTrigger(long analog_trigger_pointer); - public static native void setAnalogTriggerLimitsRaw(ByteBuffer analog_trigger_pointer, int lower, - int upper, IntBuffer status); + public static native void setAnalogTriggerLimitsRaw(long analog_trigger_pointer, int lower, + int upper); - public static native void setAnalogTriggerLimitsVoltage(ByteBuffer analog_trigger_pointer, - double lower, double upper, IntBuffer status); + public static native void setAnalogTriggerLimitsVoltage(long analog_trigger_pointer, + double lower, double upper); - public static native void setAnalogTriggerAveraged(ByteBuffer analog_trigger_pointer, - byte useAveragedValue, IntBuffer status); + public static native void setAnalogTriggerAveraged(long analog_trigger_pointer, + boolean useAveragedValue); - public static native void setAnalogTriggerFiltered(ByteBuffer analog_trigger_pointer, - byte useFilteredValue, IntBuffer status); + public static native void setAnalogTriggerFiltered(long analog_trigger_pointer, + boolean useFilteredValue); - public static native byte getAnalogTriggerInWindow(ByteBuffer analog_trigger_pointer, - IntBuffer status); + public static native boolean getAnalogTriggerInWindow(long analog_trigger_pointer); - public static native byte getAnalogTriggerTriggerState(ByteBuffer analog_trigger_pointer, - IntBuffer status); + public static native boolean getAnalogTriggerTriggerState(long analog_trigger_pointer); - public static native byte getAnalogTriggerOutput(ByteBuffer analog_trigger_pointer, int type, - IntBuffer status); + public static native boolean getAnalogTriggerOutput(long analog_trigger_pointer, int type); } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/CompressorJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/CompressorJNI.java index 8a2363a046..569828ad57 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/CompressorJNI.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/CompressorJNI.java @@ -1,40 +1,31 @@ package edu.wpi.first.wpilibj.hal; -import java.nio.ByteBuffer; -import java.nio.IntBuffer; - public class CompressorJNI extends JNIWrapper { - public static native ByteBuffer initializeCompressor(byte module); + public static native long initializeCompressor(byte module); public static native boolean checkCompressorModule(byte module); - public static native boolean getCompressor(ByteBuffer pcm_pointer, IntBuffer status); + public static native boolean getCompressor(long pcm_pointer); - public static native void setClosedLoopControl(ByteBuffer pcm_pointer, boolean value, - IntBuffer status); + public static native void setClosedLoopControl(long pcm_pointer, boolean value); - public static native boolean getClosedLoopControl(ByteBuffer pcm_pointer, IntBuffer status); + public static native boolean getClosedLoopControl(long pcm_pointer); - public static native boolean getPressureSwitch(ByteBuffer pcm_pointer, IntBuffer status); + public static native boolean getPressureSwitch(long pcm_pointer); - public static native float getCompressorCurrent(ByteBuffer pcm_pointer, IntBuffer status); + public static native float getCompressorCurrent(long pcm_pointer); - public static native boolean getCompressorCurrentTooHighFault(ByteBuffer pcm_pointer, - IntBuffer status); + public static native boolean getCompressorCurrentTooHighFault(long pcm_pointer); - public static native boolean getCompressorCurrentTooHighStickyFault(ByteBuffer pcm_pointer, - IntBuffer status); + public static native boolean getCompressorCurrentTooHighStickyFault(long pcm_pointer); - public static native boolean getCompressorShortedStickyFault(ByteBuffer pcm_pointer, - IntBuffer status); + public static native boolean getCompressorShortedStickyFault(long pcm_pointer); - public static native boolean getCompressorShortedFault(ByteBuffer pcm_pointer, IntBuffer status); + public static native boolean getCompressorShortedFault(long pcm_pointer); - public static native boolean getCompressorNotConnectedStickyFault(ByteBuffer pcm_pointer, - IntBuffer status); + public static native boolean getCompressorNotConnectedStickyFault(long pcm_pointer); - public static native boolean getCompressorNotConnectedFault(ByteBuffer pcm_pointer, - IntBuffer status); + public static native boolean getCompressorNotConnectedFault(long pcm_pointer); - public static native void clearAllPCMStickyFaults(ByteBuffer pcm_pointer, IntBuffer status); + public static native void clearAllPCMStickyFaults(long pcm_pointer); } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/CounterJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/CounterJNI.java index b9097e62ca..2b627ef4a3 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/CounterJNI.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/CounterJNI.java @@ -1,64 +1,58 @@ package edu.wpi.first.wpilibj.hal; import java.nio.IntBuffer; -import java.nio.ByteBuffer; public class CounterJNI extends JNIWrapper { - public static native ByteBuffer initializeCounter(int mode, IntBuffer index, IntBuffer status); + public static native long initializeCounter(int mode, IntBuffer index); - public static native void freeCounter(ByteBuffer counter_pointer, IntBuffer status); + public static native void freeCounter(long counter_pointer); - public static native void setCounterAverageSize(ByteBuffer counter_pointer, int size, - IntBuffer status); + public static native void setCounterAverageSize(long counter_pointer, int size); - public static native void setCounterUpSource(ByteBuffer counter_pointer, int pin, - byte analogTrigger, IntBuffer status); + public static native void setCounterUpSource(long counter_pointer, int pin, + boolean analogTrigger); - public static native void setCounterUpSourceEdge(ByteBuffer counter_pointer, byte risingEdge, - byte fallingEdge, IntBuffer status); + public static native void setCounterUpSourceEdge(long counter_pointer, boolean risingEdge, + boolean fallingEdge); - public static native void clearCounterUpSource(ByteBuffer counter_pointer, IntBuffer status); + public static native void clearCounterUpSource(long counter_pointer); - public static native void setCounterDownSource(ByteBuffer counter_pointer, int pin, - byte analogTrigger, IntBuffer status); + public static native void setCounterDownSource(long counter_pointer, int pin, + boolean analogTrigger); - public static native void setCounterDownSourceEdge(ByteBuffer counter_pointer, byte risingEdge, - byte fallingEdge, IntBuffer status); + public static native void setCounterDownSourceEdge(long counter_pointer, boolean risingEdge, + boolean fallingEdge); - public static native void clearCounterDownSource(ByteBuffer counter_pointer, IntBuffer status); + public static native void clearCounterDownSource(long counter_pointer); - public static native void setCounterUpDownMode(ByteBuffer counter_pointer, IntBuffer status); + public static native void setCounterUpDownMode(long counter_pointer); - public static native void setCounterExternalDirectionMode(ByteBuffer counter_pointer, - IntBuffer status); + public static native void setCounterExternalDirectionMode(long counter_pointer); - public static native void setCounterSemiPeriodMode(ByteBuffer counter_pointer, - byte highSemiPeriod, IntBuffer status); + public static native void setCounterSemiPeriodMode(long counter_pointer, + boolean highSemiPeriod); - public static native void setCounterPulseLengthMode(ByteBuffer counter_pointer, double threshold, - IntBuffer status); + public static native void setCounterPulseLengthMode(long counter_pointer, double threshold); - public static native int getCounterSamplesToAverage(ByteBuffer counter_pointer, IntBuffer status); + public static native int getCounterSamplesToAverage(long counter_pointer); - public static native void setCounterSamplesToAverage(ByteBuffer counter_pointer, - int samplesToAverage, IntBuffer status); + public static native void setCounterSamplesToAverage(long counter_pointer, + int samplesToAverage); - public static native void resetCounter(ByteBuffer counter_pointer, IntBuffer status); + public static native void resetCounter(long counter_pointer); - public static native int getCounter(ByteBuffer counter_pointer, IntBuffer status); + public static native int getCounter(long counter_pointer); - public static native double getCounterPeriod(ByteBuffer counter_pointer, IntBuffer status); + public static native double getCounterPeriod(long counter_pointer); - public static native void setCounterMaxPeriod(ByteBuffer counter_pointer, double maxPeriod, - IntBuffer status); + public static native void setCounterMaxPeriod(long counter_pointer, double maxPeriod); - public static native void setCounterUpdateWhenEmpty(ByteBuffer counter_pointer, byte enabled, - IntBuffer status); + public static native void setCounterUpdateWhenEmpty(long counter_pointer, boolean enabled); - public static native byte getCounterStopped(ByteBuffer counter_pointer, IntBuffer status); + public static native boolean getCounterStopped(long counter_pointer); - public static native byte getCounterDirection(ByteBuffer counter_pointer, IntBuffer status); + public static native boolean getCounterDirection(long counter_pointer); - public static native void setCounterReverseDirection(ByteBuffer counter_pointer, - byte reverseDirection, IntBuffer status); + public static native void setCounterReverseDirection(long counter_pointer, + boolean reverseDirection); } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/DIOJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/DIOJNI.java index d7bda85a23..d6ac993676 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/DIOJNI.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/DIOJNI.java @@ -1,28 +1,23 @@ package edu.wpi.first.wpilibj.hal; -import java.nio.IntBuffer; -import java.nio.ByteBuffer; - public class DIOJNI extends JNIWrapper { - public static native ByteBuffer initializeDigitalPort(ByteBuffer port_pointer, IntBuffer status); + public static native long initializeDigitalPort(long port_pointer); - public static native byte allocateDIO(ByteBuffer digital_port_pointer, byte input, - IntBuffer status); + public static native boolean allocateDIO(long digital_port_pointer, boolean input); - public static native void freeDIO(ByteBuffer digital_port_pointer, IntBuffer status); + public static native void freeDIO(long digital_port_pointer); - public static native void setDIO(ByteBuffer digital_port_pointer, short value, IntBuffer status); + public static native void setDIO(long digital_port_pointer, short value); - public static native byte getDIO(ByteBuffer digital_port_pointer, IntBuffer status); + public static native boolean getDIO(long digital_port_pointer); - public static native byte getDIODirection(ByteBuffer digital_port_pointer, IntBuffer status); + public static native boolean getDIODirection(long digital_port_pointer); - public static native void pulse(ByteBuffer digital_port_pointer, double pulseLength, - IntBuffer status); + public static native void pulse(long digital_port_pointer, double pulseLength); - public static native byte isPulsing(ByteBuffer digital_port_pointer, IntBuffer status); + public static native boolean isPulsing(long digital_port_pointer); - public static native byte isAnyPulsing(IntBuffer status); + public static native boolean isAnyPulsing(); - public static native short getLoopTiming(IntBuffer status); + public static native short getLoopTiming(); } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/EncoderJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/EncoderJNI.java index 45cd14772f..ae6f2c9a45 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/EncoderJNI.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/EncoderJNI.java @@ -1,36 +1,34 @@ package edu.wpi.first.wpilibj.hal; import java.nio.IntBuffer; -import java.nio.ByteBuffer; public class EncoderJNI extends JNIWrapper { - public static native ByteBuffer initializeEncoder(byte port_a_module, int port_a_pin, - byte port_a_analog_trigger, byte port_b_module, int port_b_pin, byte port_b_analog_trigger, - byte reverseDirection, IntBuffer index, IntBuffer status); + public static native long initializeEncoder(byte port_a_module, int port_a_pin, + boolean port_a_analog_trigger, byte port_b_module, int port_b_pin, boolean port_b_analog_trigger, + boolean reverseDirection, IntBuffer index); - public static native void freeEncoder(ByteBuffer encoder_pointer, IntBuffer status); + public static native void freeEncoder(long encoder_pointer); - public static native void resetEncoder(ByteBuffer encoder_pointer, IntBuffer status); + public static native void resetEncoder(long encoder_pointer); - public static native int getEncoder(ByteBuffer encoder_pointer, IntBuffer status); + public static native int getEncoder(long encoder_pointer); - public static native double getEncoderPeriod(ByteBuffer encoder_pointer, IntBuffer status); + public static native double getEncoderPeriod(long encoder_pointer); - public static native void setEncoderMaxPeriod(ByteBuffer encoder_pointer, double maxPeriod, - IntBuffer status); + public static native void setEncoderMaxPeriod(long encoder_pointer, double maxPeriod); - public static native byte getEncoderStopped(ByteBuffer encoder_pointer, IntBuffer status); + public static native boolean getEncoderStopped(long encoder_pointer); - public static native byte getEncoderDirection(ByteBuffer encoder_pointer, IntBuffer status); + public static native boolean getEncoderDirection(long encoder_pointer); - public static native void setEncoderReverseDirection(ByteBuffer encoder_pointer, - byte reverseDirection, IntBuffer status); + public static native void setEncoderReverseDirection(long encoder_pointer, + boolean reverseDirection); - public static native void setEncoderSamplesToAverage(ByteBuffer encoder_pointer, - int samplesToAverage, IntBuffer status); + public static native void setEncoderSamplesToAverage(long encoder_pointer, + int samplesToAverage); - public static native int getEncoderSamplesToAverage(ByteBuffer encoder_pointer, IntBuffer status); + public static native int getEncoderSamplesToAverage(long encoder_pointer); - public static native void setEncoderIndexSource(ByteBuffer digital_port, int pin, - boolean analogTrigger, boolean activeHigh, boolean edgeSensitive, IntBuffer status); + public static native void setEncoderIndexSource(long digital_port, int pin, + boolean analogTrigger, boolean activeHigh, boolean edgeSensitive); } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/HALLibrary.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/HALLibrary.java index bbef819ae6..20e7741a38 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/HALLibrary.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/HALLibrary.java @@ -12,8 +12,7 @@ package edu.wpi.first.wpilibj.hal; // import com.sun.jna.PointerType; // import com.sun.jna.ptr.IntByReference; // import com.sun.jna.ptr.LongByReference; -import java.nio.ByteBuffer; -import java.nio.IntBuffer; +// import java.nio.IntBuffer; /** * JNA Wrapper for library HAL
@@ -282,7 +281,7 @@ public class HALLibrary /* implements Library */{ * native declaration : * AthenaJava\target\native\include\HAL\Semaphore.h:385 */ - public static native ByteBuffer initializeMutex(int flags); + public static native long initializeMutex(int flags); /** * Original signature : void deleteMutex(MUTEX_ID)
@@ -300,7 +299,7 @@ public class HALLibrary /* implements Library */{ * native declaration : * AthenaJava\target\native\include\HAL\Semaphore.h:387 */ - public static native void deleteMutex(ByteBuffer sem); + public static native void deleteMutex(long sem); /** * Original signature : int8_t takeMutex(MUTEX_ID, int32_t)
@@ -318,7 +317,7 @@ public class HALLibrary /* implements Library */{ * native declaration : * AthenaJava\target\native\include\HAL\Semaphore.h:389 */ - public static native byte takeMutex(ByteBuffer sem, int timeout); + public static native byte takeMutex(long sem, int timeout); /** * Original signature : int8_t giveMutex(MUTEX_ID)
diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/HALUtil.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/HALUtil.java index ac00a004fd..b89d44530e 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/HALUtil.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/HALUtil.java @@ -1,9 +1,5 @@ package edu.wpi.first.wpilibj.hal; -import java.nio.ByteBuffer; -import java.nio.IntBuffer; -import edu.wpi.first.wpilibj.DriverStation; - public class HALUtil extends JNIWrapper { public static final int NULL_PARAMETER = -1005; public static final int SAMPLE_RATE_TOO_HIGH = 1001; @@ -17,28 +13,28 @@ public class HALUtil extends JNIWrapper { // public static final int SEMAPHORE_WAIT_FOREVER = -1; // public static final int SEMAPHORE_Q_PRIORITY = 0x01; - public static native ByteBuffer initializeMutexNormal(); + public static native long initializeMutexNormal(); - public static native void deleteMutex(ByteBuffer sem); + public static native void deleteMutex(long sem); - public static native byte takeMutex(ByteBuffer sem); + public static native void takeMutex(long sem); - // public static native ByteBuffer initializeSemaphore(int initialValue); - // public static native void deleteSemaphore(ByteBuffer sem); - // public static native byte takeSemaphore(ByteBuffer sem, int timeout); - public static native ByteBuffer initializeMultiWait(); + // public static native long initializeSemaphore(int initialValue); + // public static native void deleteSemaphore(long sem); + // public static native byte takeSemaphore(long sem, int timeout); + public static native long initializeMultiWait(); - public static native void deleteMultiWait(ByteBuffer sem); + public static native void deleteMultiWait(long sem); - public static native byte takeMultiWait(ByteBuffer sem, ByteBuffer m); + public static native void takeMultiWait(long sem, long m); - public static native short getFPGAVersion(IntBuffer status); + public static native short getFPGAVersion(); - public static native int getFPGARevision(IntBuffer status); + public static native int getFPGARevision(); - public static native long getFPGATime(IntBuffer status); + public static native long getFPGATime(); - public static native boolean getFPGAButton(IntBuffer status); + public static native boolean getFPGAButton(); public static native String getHALErrorMessage(int code); @@ -49,17 +45,4 @@ public class HALUtil extends JNIWrapper { public static String getHALstrerror() { return getHALstrerror(getHALErrno()); } - - public static void checkStatus(IntBuffer status) { - int s = status.get(0); - if (s < 0) { - String message = getHALErrorMessage(s); - throw new RuntimeException(" Code: " + s + ". " + message); - } else if (s > 0) { - String message = getHALErrorMessage(s); - DriverStation.reportError(message, true); - } - } - - public static native int pointerSize(); } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/I2CJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/I2CJNI.java index 0a66c6da60..6adf45a61c 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/I2CJNI.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/I2CJNI.java @@ -1,17 +1,16 @@ package edu.wpi.first.wpilibj.hal; import java.nio.ByteBuffer; -import java.nio.IntBuffer; public class I2CJNI extends JNIWrapper { - public static native void i2CInitialize(byte port, IntBuffer status); + public static native void i2CInitialize(byte port); - public static native byte i2CTransaction(byte port, byte address, ByteBuffer dataToSend, + public static native int i2CTransaction(byte port, byte address, ByteBuffer dataToSend, byte sendSize, ByteBuffer dataReceived, byte receiveSize); - public static native byte i2CWrite(byte port, byte address, ByteBuffer dataToSend, byte sendSize); + public static native int i2CWrite(byte port, byte address, ByteBuffer dataToSend, byte sendSize); - public static native byte i2CRead(byte port, byte address, ByteBuffer dataRecieved, + public static native int i2CRead(byte port, byte address, ByteBuffer dataRecieved, byte receiveSize); public static native void i2CClose(byte port); diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/InterruptJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/InterruptJNI.java index 8e8ac4203b..6784b91b2e 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/InterruptJNI.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/InterruptJNI.java @@ -1,37 +1,31 @@ package edu.wpi.first.wpilibj.hal; -import java.nio.ByteBuffer; -import java.nio.IntBuffer; - public class InterruptJNI extends JNIWrapper { public interface InterruptJNIHandlerFunction { void apply(int interruptAssertedMask, Object param); }; - public static native void initializeInterruptJVM(IntBuffer status); + public static native long initializeInterrupts(int interruptIndex, boolean watcher); - public static native ByteBuffer initializeInterrupts(int interruptIndex, byte watcher, - IntBuffer status); + public static native void cleanInterrupts(long interrupt_pointer); - public static native void cleanInterrupts(ByteBuffer interrupt_pointer, IntBuffer status); + public static native int waitForInterrupt(long interrupt_pointer, double timeout, + boolean ignorePrevious); - public static native int waitForInterrupt(ByteBuffer interrupt_pointer, double timeout, - boolean ignorePrevious, IntBuffer status); + public static native void enableInterrupts(long interrupt_pointer); - public static native void enableInterrupts(ByteBuffer interrupt_pointer, IntBuffer status); + public static native void disableInterrupts(long interrupt_pointer); - public static native void disableInterrupts(ByteBuffer interrupt_pointer, IntBuffer status); + public static native double readRisingTimestamp(long interrupt_pointer); - public static native double readRisingTimestamp(ByteBuffer interrupt_pointer, IntBuffer status); + public static native double readFallingTimestamp(long interrupt_pointer); - public static native double readFallingTimestamp(ByteBuffer interrupt_pointer, IntBuffer status); + public static native void requestInterrupts(long interrupt_pointer, byte routing_module, + int routing_pin, boolean routing_analog_trigger); - public static native void requestInterrupts(ByteBuffer interrupt_pointer, byte routing_module, - int routing_pin, byte routing_analog_trigger, IntBuffer status); + public static native void attachInterruptHandler(long interrupt_pointer, + InterruptJNIHandlerFunction handler, Object param); - public static native void attachInterruptHandler(ByteBuffer interrupt_pointer, - InterruptJNIHandlerFunction handler, Object param, IntBuffer status); - - public static native void setInterruptUpSourceEdge(ByteBuffer interrupt_pointer, byte risingEdge, - byte fallingEdge, IntBuffer status); + public static native void setInterruptUpSourceEdge(long interrupt_pointer, boolean risingEdge, + boolean fallingEdge); } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/JNIWrapper.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/JNIWrapper.java index fc77dddf10..5b9d3e89ee 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/JNIWrapper.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/JNIWrapper.java @@ -4,7 +4,6 @@ import java.io.File; import java.io.InputStream; import java.io.OutputStream; import java.io.FileOutputStream; -import java.nio.ByteBuffer; // // base class for all JNI wrappers @@ -49,7 +48,7 @@ public class JNIWrapper { } } - public static native ByteBuffer getPortWithModule(byte module, byte pin); + public static native long getPortWithModule(byte module, byte pin); - public static native ByteBuffer getPort(byte pin); + public static native long getPort(byte pin); } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/NotifierJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/NotifierJNI.java index 7df2ce7317..8ac72daa4d 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/NotifierJNI.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/NotifierJNI.java @@ -1,7 +1,5 @@ package edu.wpi.first.wpilibj.hal; -import java.nio.ByteBuffer; -import java.nio.IntBuffer; import java.lang.Runtime; /** @@ -17,22 +15,15 @@ public class NotifierJNI extends JNIWrapper { * * Should be called after initializeNotifierJVM(). */ - public static native ByteBuffer initializeNotifier(Runnable func, IntBuffer status); - - /** - * Initializes the JVM for use by the callback. Should be called before - * anything else. - */ - public static native void initializeNotifierJVM(IntBuffer status); + public static native long initializeNotifier(Runnable func); /** * Deletes the notifier object when we are done with it. */ - public static native void cleanNotifier(ByteBuffer notifierPtr, IntBuffer status); + public static native void cleanNotifier(long notifierPtr); /** * Sets the notifier to call the callback in another triggerTime microseconds. */ - public static native void updateNotifierAlarm(ByteBuffer notifierPtr, int triggerTime, - IntBuffer status); + public static native void updateNotifierAlarm(long notifierPtr, int triggerTime); } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/PDPJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/PDPJNI.java index 1623c0aa37..5b007259ad 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/PDPJNI.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/PDPJNI.java @@ -1,24 +1,21 @@ package edu.wpi.first.wpilibj.hal; -import java.nio.ByteBuffer; -import java.nio.IntBuffer; - public class PDPJNI extends JNIWrapper { public static native void initializePDP(int module); - public static native double getPDPTemperature(IntBuffer status, int module); + public static native double getPDPTemperature(int module); - public static native double getPDPVoltage(IntBuffer status, int module); + public static native double getPDPVoltage(int module); - public static native double getPDPChannelCurrent(byte channel, IntBuffer status, int module); + public static native double getPDPChannelCurrent(byte channel, int module); - public static native double getPDPTotalCurrent(IntBuffer status, int module); + public static native double getPDPTotalCurrent(int module); - public static native double getPDPTotalPower(IntBuffer status, int module); + public static native double getPDPTotalPower(int module); - public static native double getPDPTotalEnergy(IntBuffer status, int module); + public static native double getPDPTotalEnergy(int module); - public static native void resetPDPTotalEnergy(IntBuffer status, int module); + public static native void resetPDPTotalEnergy(int module); - public static native void clearPDPStickyFaults(IntBuffer status, int module); + public static native void clearPDPStickyFaults(int module); } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/PWMJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/PWMJNI.java index f60fad8925..aff87e75a0 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/PWMJNI.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/PWMJNI.java @@ -1,33 +1,25 @@ package edu.wpi.first.wpilibj.hal; -import java.nio.IntBuffer; -import java.nio.ByteBuffer; - -import edu.wpi.first.wpilibj.SensorBase; - - public class PWMJNI extends DIOJNI { - public static native boolean allocatePWMChannel(ByteBuffer digital_port_pointer, IntBuffer status); + public static native boolean allocatePWMChannel(long digital_port_pointer); - public static native void freePWMChannel(ByteBuffer digital_port_pointer, IntBuffer status); + public static native void freePWMChannel(long digital_port_pointer); - public static native void setPWM(ByteBuffer digital_port_pointer, short value, IntBuffer status); + public static native void setPWM(long digital_port_pointer, short value); - public static native short getPWM(ByteBuffer digital_port_pointer, IntBuffer status); + public static native short getPWM(long digital_port_pointer); - public static native void latchPWMZero(ByteBuffer digital_port_pointer, IntBuffer status); + public static native void latchPWMZero(long digital_port_pointer); - public static native void setPWMPeriodScale(ByteBuffer digital_port_pointer, int squelchMask, - IntBuffer status); + public static native void setPWMPeriodScale(long digital_port_pointer, int squelchMask); - public static native ByteBuffer allocatePWM(IntBuffer status); + public static native long allocatePWM(); - public static native void freePWM(ByteBuffer pwmGenerator, IntBuffer status); + public static native void freePWM(long pwmGenerator); - public static native void setPWMRate(double rate, IntBuffer status); + public static native void setPWMRate(double rate); - public static native void setPWMDutyCycle(ByteBuffer pwmGenerator, double dutyCycle, - IntBuffer status); + public static native void setPWMDutyCycle(long pwmGenerator, double dutyCycle); - public static native void setPWMOutputChannel(ByteBuffer pwmGenerator, int pin, IntBuffer status); + public static native void setPWMOutputChannel(long pwmGenerator, int pin); } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/PowerJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/PowerJNI.java index 4217ac0572..cddb5e6f5e 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/PowerJNI.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/PowerJNI.java @@ -1,33 +1,31 @@ package edu.wpi.first.wpilibj.hal; -import java.nio.IntBuffer; - public class PowerJNI extends JNIWrapper { - public static native float getVinVoltage(IntBuffer status); + public static native float getVinVoltage(); - public static native float getVinCurrent(IntBuffer status); + public static native float getVinCurrent(); - public static native float getUserVoltage6V(IntBuffer status); + public static native float getUserVoltage6V(); - public static native float getUserCurrent6V(IntBuffer status); + public static native float getUserCurrent6V(); - public static native boolean getUserActive6V(IntBuffer status); + public static native boolean getUserActive6V(); - public static native int getUserCurrentFaults6V(IntBuffer status); + public static native int getUserCurrentFaults6V(); - public static native float getUserVoltage5V(IntBuffer status); + public static native float getUserVoltage5V(); - public static native float getUserCurrent5V(IntBuffer status); + public static native float getUserCurrent5V(); - public static native boolean getUserActive5V(IntBuffer status); + public static native boolean getUserActive5V(); - public static native int getUserCurrentFaults5V(IntBuffer status); + public static native int getUserCurrentFaults5V(); - public static native float getUserVoltage3V3(IntBuffer status); + public static native float getUserVoltage3V3(); - public static native float getUserCurrent3V3(IntBuffer status); + public static native float getUserCurrent3V3(); - public static native boolean getUserActive3V3(IntBuffer status); + public static native boolean getUserActive3V3(); - public static native int getUserCurrentFaults3V3(IntBuffer status); + public static native int getUserCurrentFaults3V3(); } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/RelayJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/RelayJNI.java index a5f6c8553b..df6f6b3e71 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/RelayJNI.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/RelayJNI.java @@ -1,16 +1,11 @@ package edu.wpi.first.wpilibj.hal; -import java.nio.ByteBuffer; -import java.nio.IntBuffer; - public class RelayJNI extends DIOJNI { - public static native void setRelayForward(ByteBuffer digital_port_pointer, byte on, - IntBuffer status); + public static native void setRelayForward(long digital_port_pointer, boolean on); - public static native void setRelayReverse(ByteBuffer digital_port_pointer, byte on, - IntBuffer status); + public static native void setRelayReverse(long digital_port_pointer, boolean on); - public static native byte getRelayForward(ByteBuffer digital_port_pointer, IntBuffer status); + public static native boolean getRelayForward(long digital_port_pointer); - public static native byte getRelayReverse(ByteBuffer digital_port_pointer, IntBuffer status); + public static native boolean getRelayReverse(long digital_port_pointer); } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/SPIJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/SPIJNI.java index cab32a59d2..a8251f4a47 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/SPIJNI.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/SPIJNI.java @@ -1,10 +1,9 @@ package edu.wpi.first.wpilibj.hal; import java.nio.ByteBuffer; -import java.nio.IntBuffer; public class SPIJNI extends JNIWrapper { - public static native void spiInitialize(byte port, IntBuffer status); + public static native void spiInitialize(byte port); public static native int spiTransaction(byte port, ByteBuffer dataToSend, ByteBuffer dataReceived, byte size); @@ -22,7 +21,7 @@ public class SPIJNI extends JNIWrapper { public static native void spiSetOpts(byte port, int msb_first, int sample_on_trailing, int clk_idle_high); - public static native void spiSetChipSelectActiveHigh(byte port, IntBuffer status); + public static native void spiSetChipSelectActiveHigh(byte port); - public static native void spiSetChipSelectActiveLow(byte port, IntBuffer status); + public static native void spiSetChipSelectActiveLow(byte port); } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/SerialPortJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/SerialPortJNI.java index fd1e83532f..73511d951e 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/SerialPortJNI.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/SerialPortJNI.java @@ -1,42 +1,41 @@ package edu.wpi.first.wpilibj.hal; -import java.nio.IntBuffer; import java.nio.ByteBuffer; public class SerialPortJNI extends JNIWrapper { - public static native void serialInitializePort(byte port, IntBuffer status); + public static native void serialInitializePort(byte port); - public static native void serialSetBaudRate(byte port, int baud, IntBuffer status); + public static native void serialSetBaudRate(byte port, int baud); - public static native void serialSetDataBits(byte port, byte bits, IntBuffer status); + public static native void serialSetDataBits(byte port, byte bits); - public static native void serialSetParity(byte port, byte parity, IntBuffer status); + public static native void serialSetParity(byte port, byte parity); - public static native void serialSetStopBits(byte port, byte stopBits, IntBuffer status); + public static native void serialSetStopBits(byte port, byte stopBits); - public static native void serialSetWriteMode(byte port, byte mode, IntBuffer status); + public static native void serialSetWriteMode(byte port, byte mode); - public static native void serialSetFlowControl(byte port, byte flow, IntBuffer status); + public static native void serialSetFlowControl(byte port, byte flow); - public static native void serialSetTimeout(byte port, float timeout, IntBuffer status); + public static native void serialSetTimeout(byte port, float timeout); - public static native void serialEnableTermination(byte port, char terminator, IntBuffer status); + public static native void serialEnableTermination(byte port, char terminator); - public static native void serialDisableTermination(byte port, IntBuffer status); + public static native void serialDisableTermination(byte port); - public static native void serialSetReadBufferSize(byte port, int size, IntBuffer status); + public static native void serialSetReadBufferSize(byte port, int size); - public static native void serialSetWriteBufferSize(byte port, int size, IntBuffer status); + public static native void serialSetWriteBufferSize(byte port, int size); - public static native int serialGetBytesRecieved(byte port, IntBuffer status); + public static native int serialGetBytesRecieved(byte port); - public static native int serialRead(byte port, ByteBuffer buffer, int count, IntBuffer status); + public static native int serialRead(byte port, ByteBuffer buffer, int count); - public static native int serialWrite(byte port, ByteBuffer buffer, int count, IntBuffer status); + public static native int serialWrite(byte port, ByteBuffer buffer, int count); - public static native void serialFlush(byte port, IntBuffer status); + public static native void serialFlush(byte port); - public static native void serialClear(byte port, IntBuffer status); + public static native void serialClear(byte port); - public static native void serialClose(byte port, IntBuffer status); + public static native void serialClose(byte port); } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/SolenoidJNI.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/SolenoidJNI.java index ee58aade41..857ac11c59 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/SolenoidJNI.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/hal/SolenoidJNI.java @@ -1,23 +1,19 @@ package edu.wpi.first.wpilibj.hal; -import java.nio.IntBuffer; -import java.nio.ByteBuffer; - public class SolenoidJNI extends JNIWrapper { - public static native ByteBuffer initializeSolenoidPort(ByteBuffer portPointer, IntBuffer status); + public static native long initializeSolenoidPort(long portPointer); - public static native ByteBuffer getPortWithModule(byte module, byte channel); + public static native long getPortWithModule(byte module, byte channel); - public static native void setSolenoid(ByteBuffer port, byte on, IntBuffer status); + public static native void setSolenoid(long port, boolean on); - public static native byte getSolenoid(ByteBuffer port, IntBuffer status); + public static native boolean getSolenoid(long port); - public static native byte getPCMSolenoidBlackList(ByteBuffer pcm_pointer, IntBuffer status); + public static native int getPCMSolenoidBlackList(long pcm_pointer); - public static native boolean getPCMSolenoidVoltageStickyFault(ByteBuffer pcm_pointer, - IntBuffer status); + public static native boolean getPCMSolenoidVoltageStickyFault(long pcm_pointer); - public static native boolean getPCMSolenoidVoltageFault(ByteBuffer pcm_pointer, IntBuffer status); + public static native boolean getPCMSolenoidVoltageFault(long pcm_pointer); - public static native void clearAllPCMStickyFaults(ByteBuffer pcm_pointer, IntBuffer status); + public static native void clearAllPCMStickyFaults(long pcm_pointer); } diff --git a/wpilibj/wpilibJavaIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AbstractInterruptTest.java b/wpilibj/wpilibJavaIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AbstractInterruptTest.java index c8a581d139..2ca2931767 100644 --- a/wpilibj/wpilibJavaIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AbstractInterruptTest.java +++ b/wpilibj/wpilibJavaIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AbstractInterruptTest.java @@ -159,7 +159,7 @@ public abstract class AbstractInterruptTest extends AbstractComsSetup { lessThan((interruptTriggerTime + range) / 1e6))); } - @Test(timeout = 1000) + @Test(timeout = 2000) public void testMultipleInterruptsTriggering() throws Exception { // Given final InterruptCounter counter = new InterruptCounter(); @@ -219,7 +219,7 @@ public abstract class AbstractInterruptTest extends AbstractComsSetup { } - @Test(timeout = 2000) + @Test(timeout = 4000) public void testDisableStopsInterruptFiring() { final InterruptCounter counter = new InterruptCounter(); TestInterruptHandlerFunction function = new TestInterruptHandlerFunction(counter); diff --git a/wpilibj/wpilibJavaIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AnalogCrossConnectTest.java b/wpilibj/wpilibJavaIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AnalogCrossConnectTest.java index 2415bdc9d8..eccbc305b9 100644 --- a/wpilibj/wpilibJavaIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AnalogCrossConnectTest.java +++ b/wpilibj/wpilibJavaIntegrationTests/src/main/java/edu/wpi/first/wpilibj/AnalogCrossConnectTest.java @@ -196,6 +196,7 @@ public class AnalogCrossConnectTest extends AbstractInterruptTest { @Override void setInterruptHigh() { analogIO.getOutput().setVoltage(4.0); + Timer.delay(kDelayTime); } /* @@ -206,5 +207,6 @@ public class AnalogCrossConnectTest extends AbstractInterruptTest { @Override void setInterruptLow() { analogIO.getOutput().setVoltage(1.0); + Timer.delay(kDelayTime); } } diff --git a/wpilibj/wpilibJavaJNI/lib/AccelerometerJNI.cpp b/wpilibj/wpilibJavaJNI/lib/AccelerometerJNI.cpp index f9edfe5701..8c618c562a 100644 --- a/wpilibj/wpilibJavaJNI/lib/AccelerometerJNI.cpp +++ b/wpilibj/wpilibJavaJNI/lib/AccelerometerJNI.cpp @@ -2,6 +2,8 @@ #include "edu_wpi_first_wpilibj_hal_AccelerometerJNI.h" #include "HAL/Accelerometer.hpp" +extern "C" { + /* * Class: edu_wpi_first_wpilibj_hal_AccelerometerJNI * Method: setAccelerometerActive @@ -56,3 +58,5 @@ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_AccelerometerJNI_getAcc { return getAccelerometerZ(); } + +} // extern "C" diff --git a/wpilibj/wpilibJavaJNI/lib/AnalogJNI.cpp b/wpilibj/wpilibJavaJNI/lib/AnalogJNI.cpp index 44da9d76d7..04bc6367dd 100644 --- a/wpilibj/wpilibJavaJNI/lib/AnalogJNI.cpp +++ b/wpilibj/wpilibJavaJNI/lib/AnalogJNI.cpp @@ -5,6 +5,7 @@ #include "edu_wpi_first_wpilibj_hal_AnalogJNI.h" #include "HAL/Analog.hpp" +#include "HALUtil.h" // set the logging level TLogLevel analogJNILogLevel = logWARNING; @@ -13,56 +14,52 @@ TLogLevel analogJNILogLevel = logWARNING; if (level > analogJNILogLevel) ; \ else Log().Get(level) +extern "C" { + /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: initializeAnalogInputPort - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Ljava/nio/ByteBuffer; + * Signature: (J)J */ -JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogInputPort - (JNIEnv * env, jclass, jobject id, jobject status) +JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogInputPort + (JNIEnv * env, jclass, jlong id) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - ANALOGJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - void** analogPtr = (void**)new unsigned char[4]; - *statusPtr = 0; - *analogPtr = initializeAnalogInputPort(*javaId, statusPtr); - ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; - ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *analogPtr; - return env->NewDirectByteBuffer( analogPtr, 4); + ANALOGJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id; + int32_t status = 0; + void* analog = initializeAnalogInputPort((void*)id, &status); + ANALOGJNI_LOG(logDEBUG) << "Status = " << status; + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << analog; + CheckStatus(env, status); + return (jlong)analog; } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: initializeAnalogOutputPort - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Ljava/nio/ByteBuffer; + * Signature: (J)J */ -JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogOutputPort - (JNIEnv * env, jclass, jobject id, jobject status) +JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogOutputPort + (JNIEnv * env, jclass, jlong id) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - ANALOGJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - void** analogPtr = (void**)new unsigned char[4]; - *statusPtr = 0; - *analogPtr = initializeAnalogOutputPort(*javaId, statusPtr); - ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; - ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *analogPtr; - return env->NewDirectByteBuffer( analogPtr, 4); + ANALOGJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id; + int32_t status = 0; + void* analog = initializeAnalogOutputPort((void*)id, &status); + ANALOGJNI_LOG(logDEBUG) << "Status = " << status; + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << analog; + CheckStatus(env, status); + return (jlong)analog; } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: checkAnalogModule - * Signature: (B)B + * Signature: (B)Z */ -JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_checkAnalogModule +JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_checkAnalogModule (JNIEnv *, jclass, jbyte value) { //ANALOGJNI_LOG(logDEBUG) << "Module = " << (jint)value; - jbyte returnValue = checkAnalogModule( value ); + jboolean returnValue = checkAnalogModule( value ); //ANALOGJNI_LOG(logDEBUG) << "checkAnalogModuleResult = " << (jint)returnValue; return returnValue; } @@ -70,13 +67,13 @@ JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_checkAnalogModu /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: checkAnalogInputChannel - * Signature: (I)B + * Signature: (I)Z */ -JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_checkAnalogInputChannel +JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_checkAnalogInputChannel (JNIEnv *, jclass, jint value) { //ANALOGJNI_LOG(logDEBUG) << "Channel = " << value; - jbyte returnValue = checkAnalogInputChannel( value ); + jboolean returnValue = checkAnalogInputChannel( value ); //ANALOGJNI_LOG(logDEBUG) << "checkAnalogChannelResult = " << (jint)returnValue; return returnValue; } @@ -84,13 +81,13 @@ JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_checkAnalogInpu /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: checkAnalogOutputChannel - * Signature: (I)B + * Signature: (I)Z */ -JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_checkAnalogOutputChannel +JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_checkAnalogOutputChannel (JNIEnv *, jclass, jint value) { //ANALOGJNI_LOG(logDEBUG) << "Channel = " << value; - jbyte returnValue = checkAnalogOutputChannel( value ); + jboolean returnValue = checkAnalogOutputChannel( value ); //ANALOGJNI_LOG(logDEBUG) << "checkAnalogChannelResult = " << (jint)returnValue; return returnValue; } @@ -98,372 +95,349 @@ JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_checkAnalogOutp /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: setAnalogOutput - * Signature: (Ljava/nio/ByteBuffer;DLjava/nio/IntBuffer;)V + * Signature: (JD)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAnalogOutput - (JNIEnv * env, jclass, jobject id, jdouble voltage, jobject status) + (JNIEnv * env, jclass, jlong id, jdouble voltage) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - setAnalogOutput(*javaId, voltage, statusPtr); + ANALOGJNI_LOG(logDEBUG) << "Calling setAnalogOutput"; + ANALOGJNI_LOG(logDEBUG) << "Voltage = " << voltage; + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id; + int32_t status = 0; + setAnalogOutput((void*)id, voltage, &status); + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: getAnalogOutput - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)D + * Signature: (J)D */ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogOutput - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - return getAnalogOutput(*javaId, statusPtr); + int32_t status = 0; + double val = getAnalogOutput((void*)id, &status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: setAnalogSampleRate - * Signature: (DLjava/nio/IntBuffer;)V + * Signature: (D)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAnalogSampleRate - (JNIEnv * env, jclass, jdouble value, jobject status) + (JNIEnv * env, jclass, jdouble value) { ANALOGJNI_LOG(logDEBUG) << "SampleRate = " << value; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - setAnalogSampleRate( value, statusPtr ); - ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + setAnalogSampleRate( value, &status ); + ANALOGJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: getAnalogSampleRate - * Signature: (Ljava/nio/IntBuffer;)D + * Signature: ()D */ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogSampleRate - (JNIEnv * env, jclass, jobject status) + (JNIEnv * env, jclass) { - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - double returnValue = getAnalogSampleRate( statusPtr ); - ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + double returnValue = getAnalogSampleRate( &status ); + ANALOGJNI_LOG(logDEBUG) << "Status = " << status; ANALOGJNI_LOG(logDEBUG) << "SampleRate = " << returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: setAnalogAverageBits - * Signature: (Ljava/nio/ByteBuffer;ILjava/nio/IntBuffer;)V + * Signature: (JI)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAnalogAverageBits - (JNIEnv * env, jclass, jobject id, jint value, jobject status) + (JNIEnv * env, jclass, jlong id, jint value) { ANALOGJNI_LOG(logDEBUG) << "AverageBits = " << value; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - setAnalogAverageBits( *javaId, value, statusPtr ); - ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id; + int32_t status = 0; + setAnalogAverageBits((void*)id, value, &status); + ANALOGJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: getAnalogAverageBits - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)I + * Signature: (J)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogAverageBits - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - jint returnValue = getAnalogAverageBits( *javaId, statusPtr ); - ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id; + int32_t status = 0; + jint returnValue = getAnalogAverageBits((void*)id, &status); + ANALOGJNI_LOG(logDEBUG) << "Status = " << status; ANALOGJNI_LOG(logDEBUG) << "AverageBits = " << returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: setAnalogOversampleBits - * Signature: (Ljava/nio/ByteBuffer;ILjava/nio/IntBuffer;)V + * Signature: (JI)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAnalogOversampleBits - (JNIEnv * env, jclass, jobject id, jint value, jobject status) + (JNIEnv * env, jclass, jlong id, jint value) { ANALOGJNI_LOG(logDEBUG) << "OversampleBits = " << value; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - setAnalogOversampleBits( *javaId, value, statusPtr ); - ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id; + int32_t status = 0; + setAnalogOversampleBits((void*)id, value, &status); + ANALOGJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: getAnalogOversampleBits - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)I + * Signature: (J)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogOversampleBits - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - jint returnValue = getAnalogOversampleBits( *javaId, statusPtr ); - ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id; + int32_t status = 0; + jint returnValue = getAnalogOversampleBits((void*)id, &status); + ANALOGJNI_LOG(logDEBUG) << "Status = " << status; ANALOGJNI_LOG(logDEBUG) << "OversampleBits = " << returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: getAnalogValue - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)S + * Signature: (J)S */ JNIEXPORT jshort JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogValue - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - //ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - jshort returnValue = getAnalogValue( *javaId, statusPtr ); - //ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + //ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id; + int32_t status = 0; + jshort returnValue = getAnalogValue((void*)id, &status); + //ANALOGJNI_LOG(logDEBUG) << "Status = " << status; //ANALOGJNI_LOG(logDEBUG) << "Value = " << returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: getAnalogAverageValue - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)I + * Signature: (J)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogAverageValue - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - jint returnValue = getAnalogAverageValue( *javaId, statusPtr ); - ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id; + int32_t status = 0; + jint returnValue = getAnalogAverageValue((void*)id, &status); + ANALOGJNI_LOG(logDEBUG) << "Status = " << status; ANALOGJNI_LOG(logDEBUG) << "AverageValue = " << returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: getAnalogVoltsToValue - * Signature: (Ljava/nio/ByteBuffer;DLjava/nio/IntBuffer;)I + * Signature: (JD)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogVoltsToValue - (JNIEnv * env, jclass, jobject id, jdouble voltageValue, jobject status) + (JNIEnv * env, jclass, jlong id, jdouble voltageValue) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id; ANALOGJNI_LOG(logDEBUG) << "VoltageValue = " << voltageValue; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - jint returnValue = getAnalogVoltsToValue( *javaId, voltageValue, statusPtr ); - ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + jint returnValue = getAnalogVoltsToValue((void*)id, voltageValue, &status); + ANALOGJNI_LOG(logDEBUG) << "Status = " << status; ANALOGJNI_LOG(logDEBUG) << "Value = " << returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: getAnalogVoltage - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)D + * Signature: (J)D */ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogVoltage - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - //ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - jdouble returnValue = getAnalogVoltage( *javaId, statusPtr ); - //ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + //ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id; + int32_t status = 0; + jdouble returnValue = getAnalogVoltage((void*)id, &status); + //ANALOGJNI_LOG(logDEBUG) << "Status = " << status; //ANALOGJNI_LOG(logDEBUG) << "Voltage = " << returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: getAnalogAverageVoltage - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)D + * Signature: (J)D */ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogAverageVoltage - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - jdouble returnValue = getAnalogAverageVoltage( *javaId, statusPtr ); - ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id; + int32_t status = 0; + jdouble returnValue = getAnalogAverageVoltage((void*)id, &status); + ANALOGJNI_LOG(logDEBUG) << "Status = " << status; ANALOGJNI_LOG(logDEBUG) << "AverageVoltage = " << returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: getAnalogLSBWeight - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)I + * Signature: (J)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogLSBWeight - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id; + int32_t status = 0; - jint returnValue = getAnalogLSBWeight(*javaId, statusPtr); - ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + jint returnValue = getAnalogLSBWeight((void*)id, &status); + ANALOGJNI_LOG(logDEBUG) << "Status = " << status; ANALOGJNI_LOG(logDEBUG) << "AnalogLSBWeight = " << returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: getAnalogOffset - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)I + * Signature: (J)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogOffset - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id; + int32_t status = 0; - jint returnValue = getAnalogOffset(*javaId, statusPtr); - ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + jint returnValue = getAnalogOffset((void*)id, &status); + ANALOGJNI_LOG(logDEBUG) << "Status = " << status; ANALOGJNI_LOG(logDEBUG) << "AnalogOffset = " << returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: isAccumulatorChannel - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B + * Signature: (J)Z */ -JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_isAccumulatorChannel - (JNIEnv * env, jclass, jobject id, jobject status) +JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_isAccumulatorChannel + (JNIEnv * env, jclass, jlong id) { ANALOGJNI_LOG(logDEBUG) << "isAccumulatorChannel"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id; + int32_t status = 0; - // isAccumulaotrChanel returns a boolean - char vOut = isAccumulatorChannel(*javaId, statusPtr) ? 1 : 0; - //The C++ equivalent of a jbyte is a char - jbyte returnValue = vOut; - ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + jboolean returnValue = isAccumulatorChannel((void*)id, &status); + ANALOGJNI_LOG(logDEBUG) << "Status = " << status; ANALOGJNI_LOG(logDEBUG) << "AnalogOffset = " << returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: initAccumulator - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V + * Signature: (J)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initAccumulator - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; - - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - - initAccumulator(*javaId, statusPtr); - - ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; - + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id; + int32_t status = 0; + initAccumulator((void*)id, &status); + ANALOGJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: resetAccumulator - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V + * Signature: (J)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_resetAccumulator - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id; + int32_t status = 0; - resetAccumulator(*javaId, statusPtr); - ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + resetAccumulator((void*)id, &status); + ANALOGJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: setAccumulatorCenter - * Signature: (Ljava/nio/ByteBuffer;ILjava/nio/IntBuffer;)V + * Signature: (JI)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAccumulatorCenter - (JNIEnv * env, jclass, jobject id, jint center, jobject status) + (JNIEnv * env, jclass, jlong id, jint center) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - - setAccumulatorCenter(*javaId, center, statusPtr); - ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id; + int32_t status = 0; + setAccumulatorCenter((void*)id, center, &status); + ANALOGJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: setAccumulatorDeadband - * Signature: (Ljava/nio/ByteBuffer;ILjava/nio/IntBuffer;)V + * Signature: (JI)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAccumulatorDeadband - (JNIEnv * env, jclass, jobject id, jint deadband, jobject status) + (JNIEnv * env, jclass, jlong id, jint deadband) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id; + int32_t status = 0; - setAccumulatorDeadband(*javaId, deadband, statusPtr); - ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + setAccumulatorDeadband((void*)id, deadband, &status); + ANALOGJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: getAccumulatorValue - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)J + * Signature: (J)J */ JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAccumulatorValue - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id; + int32_t status = 0; - jlong returnValue = getAccumulatorValue(*javaId, statusPtr); - ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + jlong returnValue = getAccumulatorValue((void*)id, &status); + ANALOGJNI_LOG(logDEBUG) << "Status = " << status; ANALOGJNI_LOG(logDEBUG) << "AccumulatorValue = " << returnValue; + CheckStatus(env, status); return returnValue; } @@ -471,211 +445,185 @@ JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAccumulatorV /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: getAccumulatorCount - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)I + * Signature: (J)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAccumulatorCount - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id; + int32_t status = 0; - jint returnValue = getAccumulatorCount(*javaId, statusPtr); - ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + jint returnValue = getAccumulatorCount((void*)id, &status); + ANALOGJNI_LOG(logDEBUG) << "Status = " << status; ANALOGJNI_LOG(logDEBUG) << "AccumulatorCount = " << returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: getAccumulatorOutput - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/LongBuffer;Ljava/nio/IntBuffer;Ljava/nio/IntBuffer;)V + * Signature: (JLjava/nio/LongBuffer;Ljava/nio/IntBuffer;)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAccumulatorOutput - (JNIEnv * env, jclass, jobject id, jobject value, jobject count, jobject status) + (JNIEnv * env, jclass, jlong id, jobject value, jobject count) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; + ANALOGJNI_LOG(logDEBUG) << "Analog Ptr = " << (void*)id; + int32_t status = 0; jlong * valuePtr = (jlong*)env->GetDirectBufferAddress(value); uint32_t * countPtr = (uint32_t*)env->GetDirectBufferAddress(count); - getAccumulatorOutput(*javaId, valuePtr, countPtr, statusPtr); + getAccumulatorOutput((void*)id, valuePtr, countPtr, &status); ANALOGJNI_LOG(logDEBUG) << "Value = " << *valuePtr; ANALOGJNI_LOG(logDEBUG) << "Count = " << *countPtr; - ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + ANALOGJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: initializeAnalogTrigger - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;Ljava/nio/IntBuffer;)Ljava/nio/ByteBuffer; + * Signature: (JLjava/nio/IntBuffer;)J */ -JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogTrigger - (JNIEnv * env, jclass, jobject id, jobject index, jobject status) +JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogTrigger + (JNIEnv * env, jclass, jlong id, jobject index) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId; + ANALOGJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id; jint * indexPtr = (jint*)env->GetDirectBufferAddress(index); ANALOGJNI_LOG(logDEBUG) << "Index Ptr = " << indexPtr; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - ANALOGJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - - void ** analogTriggerPtr = new void *; - *statusPtr = 0; - *analogTriggerPtr = initializeAnalogTrigger(*javaId, (uint32_t *)indexPtr, statusPtr); - ANALOGJNI_LOG(logDEBUG) << "Status = " << *statusPtr; - ANALOGJNI_LOG(logDEBUG) << "AnalogTrigger Ptr = " << *analogTriggerPtr; - - return env->NewDirectByteBuffer(analogTriggerPtr, 4); + int32_t status = 0; + void* analogTrigger = initializeAnalogTrigger((void*)id, (uint32_t *)indexPtr, &status); + ANALOGJNI_LOG(logDEBUG) << "Status = " << status; + ANALOGJNI_LOG(logDEBUG) << "AnalogTrigger Ptr = " << analogTrigger; + CheckStatus(env, status); + return (jlong)analogTrigger; } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: cleanAnalogTrigger - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V + * Signature: (J)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_cleanAnalogTrigger - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << *javaId; + ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << (void*)id; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - ANALOGJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - - *statusPtr = 0; - cleanAnalogTrigger( *javaId, statusPtr ); - - delete javaId; + int32_t status = 0; + cleanAnalogTrigger((void*)id, &status); + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: setAnalogTriggerLimitsRaw - * Signature: (Ljava/nio/ByteBuffer;IILjava/nio/IntBuffer;)V + * Signature: (JII)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAnalogTriggerLimitsRaw - (JNIEnv * env, jclass, jobject id, jint lower, jint upper, jobject status) + (JNIEnv * env, jclass, jlong id, jint lower, jint upper) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << *javaId; + ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << (void*)id; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - ANALOGJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - - *statusPtr = 0; - setAnalogTriggerLimitsRaw( *javaId, lower, upper, statusPtr ); + int32_t status = 0; + setAnalogTriggerLimitsRaw((void*)id, lower, upper, &status); + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: setAnalogTriggerLimitsVoltage - * Signature: (Ljava/nio/ByteBuffer;DDLjava/nio/IntBuffer;)V + * Signature: (JDD)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAnalogTriggerLimitsVoltage - (JNIEnv * env, jclass, jobject id, jdouble lower, jdouble upper, jobject status) + (JNIEnv * env, jclass, jlong id, jdouble lower, jdouble upper) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << *javaId; + ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << (void*)id; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - ANALOGJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - - *statusPtr = 0; - setAnalogTriggerLimitsVoltage( *javaId, lower, upper, statusPtr ); + int32_t status = 0; + setAnalogTriggerLimitsVoltage((void*)id, lower, upper, &status); + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: setAnalogTriggerAveraged - * Signature: (Ljava/nio/ByteBuffer;BLjava/nio/IntBuffer;)V + * Signature: (JZ)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAnalogTriggerAveraged - (JNIEnv * env, jclass, jobject id, jbyte averaged, jobject status){ - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << *javaId; + (JNIEnv * env, jclass, jlong id, jboolean averaged) +{ + ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << (void*)id; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - ANALOGJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - - *statusPtr = 0; - setAnalogTriggerAveraged( *javaId, averaged, statusPtr ); + int32_t status = 0; + setAnalogTriggerAveraged((void*)id, averaged, &status); + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: setAnalogTriggerFiltered - * Signature: (Ljava/nio/ByteBuffer;BLjava/nio/IntBuffer;)V + * Signature: (JZ)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_setAnalogTriggerFiltered - (JNIEnv * env, jclass, jobject id, jbyte filtered, jobject status){ - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << *javaId; + (JNIEnv * env, jclass, jlong id, jboolean filtered) +{ + ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << (void*)id; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - ANALOGJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - - *statusPtr = 0; - setAnalogTriggerFiltered( *javaId, filtered, statusPtr ); + int32_t status = 0; + setAnalogTriggerFiltered((void*)id, filtered, &status); + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: getAnalogTriggerInWindow - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B + * Signature: (J)Z */ -JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogTriggerInWindow - (JNIEnv * env, jclass, jobject id, jobject status) +JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogTriggerInWindow + (JNIEnv * env, jclass, jlong id) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << *javaId; + ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << (void*)id; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - ANALOGJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - - *statusPtr = 0; - return getAnalogTriggerInWindow( *javaId, statusPtr ); + int32_t status = 0; + jboolean val = getAnalogTriggerInWindow((void*)id, &status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: getAnalogTriggerTriggerState - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B + * Signature: (J)Z */ -JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogTriggerTriggerState - (JNIEnv * env, jclass, jobject id, jobject status) +JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogTriggerTriggerState + (JNIEnv * env, jclass, jlong id) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << *javaId; + ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << (void*)id; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - ANALOGJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - - *statusPtr = 0; - return getAnalogTriggerTriggerState( *javaId, statusPtr ); + int32_t status = 0; + jboolean val = getAnalogTriggerTriggerState((void*)id, &status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_AnalogJNI * Method: getAnalogTriggerOutput - * Signature: (Ljava/nio/ByteBuffer;ILjava/nio/IntBuffer;)B + * Signature: (JI)Z */ -JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogTriggerOutput - (JNIEnv * env, jclass, jobject id, jint type, jobject status) +JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAnalogTriggerOutput + (JNIEnv * env, jclass, jlong id, jint type) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << *javaId; + ANALOGJNI_LOG(logDEBUG) << "Analog Trigger Ptr = " << (void*)id; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - ANALOGJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - - *statusPtr = 0; - return getAnalogTriggerOutput( *javaId, (AnalogTriggerType)type, statusPtr )? 1 : 0; + int32_t status = 0; + jboolean val = getAnalogTriggerOutput((void*)id, (AnalogTriggerType)type, &status); + CheckStatus(env, status); + return val; } + +} // extern "C" diff --git a/wpilibj/wpilibJavaJNI/lib/CANJNI.cpp b/wpilibj/wpilibJavaJNI/lib/CANJNI.cpp index 51458cb84d..e211bcdb6b 100644 --- a/wpilibj/wpilibJavaJNI/lib/CANJNI.cpp +++ b/wpilibj/wpilibJavaJNI/lib/CANJNI.cpp @@ -6,6 +6,7 @@ #include "HAL/CAN.hpp" #include "FRC_NetworkCommunication/CANSessionMux.h" +#include "HALUtil.h" // set the logging level //TLogLevel canJNILogLevel = logDEBUG; @@ -15,19 +16,20 @@ TLogLevel canJNILogLevel = logERROR; if (level > canJNILogLevel) ; \ else Log().Get(level) +extern "C" { + /* * Class: edu_wpi_first_wpilibj_can_CANJNI * Method: FRCNetworkCommunicationCANSessionMuxSendMessage - * Signature: (ILjava/nio/ByteBuffer;ILjava/nio/IntBuffer;)V + * Signature: (ILjava/nio/ByteBuffer;I)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_can_CANJNI_FRCNetworkCommunicationCANSessionMuxSendMessage - (JNIEnv * env, jclass, jint messageID, jobject data, jint periodMs, jobject status) + (JNIEnv * env, jclass, jint messageID, jobject data, jint periodMs) { CANJNI_LOG(logDEBUG) << "Calling CANJNI FRCNetworkCommunicationCANSessionMuxSendMessage"; uint8_t *dataBuffer = (uint8_t *)(data? env->GetDirectBufferAddress(data) : 0); uint8_t dataSize = (uint8_t)(data? env->GetDirectBufferCapacity(data) : 0); - int32_t *statusPtr = (int32_t *)env->GetDirectBufferAddress(status); CANJNI_LOG(logDEBUG) << "Message ID " << std::hex << messageID; @@ -52,10 +54,11 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_can_CANJNI_FRCNetworkCommunica CANJNI_LOG(logDEBUG) << "Period: " << periodMs; - *statusPtr = 0; - FRC_NetworkCommunication_CANSessionMux_sendMessage(messageID, dataBuffer, dataSize, periodMs, statusPtr); + int32_t status = 0; + FRC_NetworkCommunication_CANSessionMux_sendMessage(messageID, dataBuffer, dataSize, periodMs, &status); - CANJNI_LOG(logDEBUG) << "Status: " << *statusPtr; + CANJNI_LOG(logDEBUG) << "Status: " << status; + CheckCANStatus(env, status, messageID); } static uint8_t buffer[8]; @@ -63,21 +66,20 @@ static uint8_t buffer[8]; /* * Class: edu_wpi_first_wpilibj_can_CANJNI * Method: FRCNetworkCommunicationCANSessionMuxReceiveMessage - * Signature: (Ljava/nio/IntBuffer;ILjava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Ljava/nio/ByteBuffer; + * Signature: (Ljava/nio/IntBuffer;ILjava/nio/ByteBuffer;)Ljava/nio/ByteBuffer; */ JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_can_CANJNI_FRCNetworkCommunicationCANSessionMuxReceiveMessage - (JNIEnv * env, jclass, jobject messageID, jint messageIDMask, jobject timeStamp, jobject status) + (JNIEnv * env, jclass, jobject messageID, jint messageIDMask, jobject timeStamp) { CANJNI_LOG(logDEBUG) << "Calling CANJNI FRCNetworkCommunicationCANSessionMuxReceiveMessage"; uint32_t *messageIDPtr = (uint32_t *)env->GetDirectBufferAddress(messageID); uint32_t *timeStampPtr = (uint32_t *)env->GetDirectBufferAddress(timeStamp); - int32_t *statusPtr = (int32_t *)env->GetDirectBufferAddress(status); uint8_t dataSize = 0; - *statusPtr = 0; - FRC_NetworkCommunication_CANSessionMux_receiveMessage(messageIDPtr, messageIDMask, buffer, &dataSize, timeStampPtr, statusPtr); + int32_t status = 0; + FRC_NetworkCommunication_CANSessionMux_receiveMessage(messageIDPtr, messageIDMask, buffer, &dataSize, timeStampPtr, &status); CANJNI_LOG(logDEBUG) << "Message ID " << std::hex << *messageIDPtr; @@ -94,7 +96,10 @@ JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_can_CANJNI_FRCNetworkCommun } CANJNI_LOG(logDEBUG) << "Timestamp: " << *timeStampPtr; - CANJNI_LOG(logDEBUG) << "Status: " << *statusPtr; + CANJNI_LOG(logDEBUG) << "Status: " << status; + if (!CheckCANStatus(env, status, *messageIDPtr)) return nullptr; return env->NewDirectByteBuffer(buffer, dataSize); } + +} // extern "C" diff --git a/wpilibj/wpilibJavaJNI/lib/CompressorJNI.cpp b/wpilibj/wpilibJavaJNI/lib/CompressorJNI.cpp index bcafdfbc3d..80af1373ca 100644 --- a/wpilibj/wpilibJavaJNI/lib/CompressorJNI.cpp +++ b/wpilibj/wpilibJavaJNI/lib/CompressorJNI.cpp @@ -1,21 +1,20 @@ #include "Log.hpp" #include "edu_wpi_first_wpilibj_hal_CompressorJNI.h" #include "HAL/HAL.hpp" +#include "HALUtil.h" -typedef void *VoidPointer; +extern "C" { /* * Class: edu_wpi_first_wpilibj_hal_CompressorJNI * Method: initializeCompressor - * Signature: (B)Ljava/nio/ByteBuffer; + * Signature: (B)J */ -JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_initializeCompressor +JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_initializeCompressor (JNIEnv *env, jclass, jbyte module) { - VoidPointer *pcm_pointer = new VoidPointer; - *pcm_pointer = initializeCompressor(module); - - return env->NewDirectByteBuffer(pcm_pointer, 4); + void* pcm = initializeCompressor(module); + return (jlong)pcm; } /* @@ -33,178 +32,166 @@ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_checkCom /* * Class: edu_wpi_first_wpilibj_hal_CompressorJNI * Method: getCompressor - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z + * Signature: (J)Z */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressor - (JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status) + (JNIEnv *env, jclass, jlong pcm_pointer) { - VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object); - jint *status_pointer = (jint *)env->GetDirectBufferAddress(status); - - *status_pointer = 0; - return getCompressor(*pcm_pointer, status_pointer); + int32_t status = 0; + bool val = getCompressor((void*)pcm_pointer, &status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_CompressorJNI * Method: setClosedLoopControl - * Signature: (Ljava/nio/ByteBuffer;ZLjava/nio/IntBuffer;)V + * Signature: (JZ)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_setClosedLoopControl - (JNIEnv *env, jclass, jobject pcm_pointer_object, jboolean value, jobject status) + (JNIEnv *env, jclass, jlong pcm_pointer, jboolean value) { - VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object); - jint *status_pointer = (jint *)env->GetDirectBufferAddress(status); - - *status_pointer = 0; - setClosedLoopControl(*pcm_pointer, value, status_pointer); + int32_t status = 0; + setClosedLoopControl((void*)pcm_pointer, value, &status); + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_CompressorJNI * Method: getClosedLoopControl - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z + * Signature: (J)Z */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getClosedLoopControl - (JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status) + (JNIEnv *env, jclass, jlong pcm_pointer) { - VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object); - jint *status_pointer = (jint *)env->GetDirectBufferAddress(status); - - *status_pointer = 0; - return getClosedLoopControl(*pcm_pointer, status_pointer); + int32_t status = 0; + bool val = getClosedLoopControl((void*)pcm_pointer, &status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_CompressorJNI * Method: getPressureSwitch - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z + * Signature: (J)Z */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getPressureSwitch - (JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status) + (JNIEnv *env, jclass, jlong pcm_pointer) { - VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object); - jint *status_pointer = (jint *)env->GetDirectBufferAddress(status); - - *status_pointer = 0; - return getPressureSwitch(*pcm_pointer, status_pointer); + int32_t status = 0; + bool val = getPressureSwitch((void*)pcm_pointer, &status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_CompressorJNI * Method: getCompressorCurrent - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)F + * Signature: (J)F */ JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorCurrent - (JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status) + (JNIEnv *env, jclass, jlong pcm_pointer) { - VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object); - jint *status_pointer = (jint *)env->GetDirectBufferAddress(status); - - *status_pointer = 0; - return getCompressorCurrent(*pcm_pointer, status_pointer); + int32_t status = 0; + float val = getCompressorCurrent((void*)pcm_pointer, &status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_CompressorJNI * Method: getCompressorCurrentTooHighFault - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z + * Signature: (J)Z */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorCurrentTooHighFault - (JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status) + (JNIEnv *env, jclass, jlong pcm_pointer) { - VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object); - jint *status_pointer = (jint *)env->GetDirectBufferAddress(status); - - *status_pointer = 0; - return getCompressorCurrentTooHighFault(*pcm_pointer, status_pointer); + int32_t status = 0; + bool val = getCompressorCurrentTooHighFault((void*)pcm_pointer, &status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_CompressorJNI * Method: getCompressorCurrentTooHighStickyFault - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z + * Signature: (J)Z */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorCurrentTooHighStickyFault - (JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status) + (JNIEnv *env, jclass, jlong pcm_pointer) { - VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object); - jint *status_pointer = (jint *)env->GetDirectBufferAddress(status); - - *status_pointer = 0; - return getCompressorCurrentTooHighStickyFault(*pcm_pointer, status_pointer); + int32_t status = 0; + bool val = getCompressorCurrentTooHighStickyFault((void*)pcm_pointer, &status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_CompressorJNI * Method: getCompressorShortedStickyFault - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z + * Signature: (J)Z */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorShortedStickyFault - (JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status) + (JNIEnv *env, jclass, jlong pcm_pointer) { - VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object); - jint *status_pointer = (jint *)env->GetDirectBufferAddress(status); - - *status_pointer = 0; - return getCompressorShortedStickyFault(*pcm_pointer, status_pointer); + int32_t status = 0; + bool val = getCompressorShortedStickyFault((void*)pcm_pointer, &status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_CompressorJNI * Method: getCompressorShortedFault - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z + * Signature: (J)Z */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorShortedFault - (JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status) + (JNIEnv *env, jclass, jlong pcm_pointer) { - VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object); - jint *status_pointer = (jint *)env->GetDirectBufferAddress(status); - - *status_pointer = 0; - return getCompressorShortedFault(*pcm_pointer, status_pointer); + int32_t status = 0; + bool val = getCompressorShortedFault((void*)pcm_pointer, &status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_CompressorJNI * Method: getCompressorNotConnectedStickyFault - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z + * Signature: (J)Z */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorNotConnectedStickyFault - (JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status) + (JNIEnv *env, jclass, jlong pcm_pointer) { - VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object); - jint *status_pointer = (jint *)env->GetDirectBufferAddress(status); - - *status_pointer = 0; - return getCompressorNotConnectedStickyFault(*pcm_pointer, status_pointer); + int32_t status = 0; + bool val = getCompressorNotConnectedStickyFault((void*)pcm_pointer, &status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_CompressorJNI * Method: getCompressorNotConnectedFault - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z + * Signature: (J)Z */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_getCompressorNotConnectedFault - (JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status) + (JNIEnv *env, jclass, jlong pcm_pointer) { - VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object); - jint *status_pointer = (jint *)env->GetDirectBufferAddress(status); - - *status_pointer = 0; - return getCompressorNotConnectedFault(*pcm_pointer, status_pointer); + int32_t status = 0; + bool val = getCompressorNotConnectedFault((void*)pcm_pointer, &status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_CompressorJNI * Method: clearAllPCMStickyFaults - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V + * Signature: (J)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CompressorJNI_clearAllPCMStickyFaults - (JNIEnv *env, jclass, jobject pcm_pointer_object, jobject status) + (JNIEnv *env, jclass, jlong pcm_pointer) { - VoidPointer *pcm_pointer = (VoidPointer *)env->GetDirectBufferAddress(pcm_pointer_object); - jint *status_pointer = (jint *)env->GetDirectBufferAddress(status); - - *status_pointer = 0; - clearAllPCMStickyFaults(*pcm_pointer, status_pointer); + int32_t status = 0; + clearAllPCMStickyFaults((void*)pcm_pointer, &status); + CheckStatus(env, status); } + +} // extern "C" diff --git a/wpilibj/wpilibJavaJNI/lib/CounterJNI.cpp b/wpilibj/wpilibJavaJNI/lib/CounterJNI.cpp index e29c6af5b1..2f0d4dc0db 100644 --- a/wpilibj/wpilibJavaJNI/lib/CounterJNI.cpp +++ b/wpilibj/wpilibJavaJNI/lib/CounterJNI.cpp @@ -5,6 +5,8 @@ #include "edu_wpi_first_wpilibj_hal_CounterJNI.h" #include "HAL/Digital.hpp" +#include "HAL/Errors.hpp" +#include "HALUtil.h" // set the logging level TLogLevel counterJNILogLevel = logWARNING; @@ -13,446 +15,412 @@ TLogLevel counterJNILogLevel = logWARNING; if (level > counterJNILogLevel) ; \ else Log().Get(level) +extern "C" { + /* * Class: edu_wpi_first_wpilibj_hal_CounterJNI * Method: initializeCounter - * Signature: (ILjava/nio/IntBuffer;Ljava/nio/IntBuffer;)Ljava/nio/ByteBuffer; + * Signature: (ILjava/nio/IntBuffer;)J */ -JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_initializeCounter - (JNIEnv * env, jclass, jint mode, jobject index, jobject status) +JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_initializeCounter + (JNIEnv * env, jclass, jint mode, jobject index) { COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI initializeCounter"; COUNTERJNI_LOG(logDEBUG) << "Mode = " << mode; jint * indexPtr = (jint*)env->GetDirectBufferAddress(index); - COUNTERJNI_LOG(logDEBUG) << "Index Ptr = " << indexPtr; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - void** counterPtr = (void**)new unsigned char[4]; - *statusPtr = 0; - *counterPtr = initializeCounter((Mode)mode, (uint32_t*)indexPtr, statusPtr); + COUNTERJNI_LOG(logDEBUG) << "Index Ptr = " << (uint32_t*)indexPtr; + int32_t status = 0; + void* counter = initializeCounter((Mode)mode, (uint32_t*)indexPtr, &status); COUNTERJNI_LOG(logDEBUG) << "Index = " << *indexPtr; - COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; - COUNTERJNI_LOG(logDEBUG) << "COUNTER Ptr = " << *counterPtr; - return env->NewDirectByteBuffer( counterPtr, 4); + COUNTERJNI_LOG(logDEBUG) << "Status = " << status; + COUNTERJNI_LOG(logDEBUG) << "COUNTER Ptr = " << counter; + CheckStatus(env, status); + return (jlong)counter; } /* * Class: edu_wpi_first_wpilibj_hal_CounterJNI * Method: freeCounter - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V + * Signature: (J)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_freeCounter - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI freeCounter"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - freeCounter(*javaId, statusPtr); - COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id; + int32_t status = 0; + freeCounter((void*)id, &status); + COUNTERJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_CounterJNI * Method: setCounterAverageSize - * Signature: (Ljava/nio/ByteBuffer;ILjava/nio/IntBuffer;)V + * Signature: (JI)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterAverageSize - (JNIEnv * env, jclass, jobject id, jint value, jobject status) + (JNIEnv * env, jclass, jlong id, jint value) { COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterAverageSize"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId; + COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id; COUNTERJNI_LOG(logDEBUG) << "AverageSize = " << value; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - setCounterAverageSize(*javaId, value, statusPtr); - COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + setCounterAverageSize((void*)id, value, &status); + COUNTERJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_CounterJNI * Method: setCounterUpSource - * Signature: (Ljava/nio/ByteBuffer;BIBLjava/nio/IntBuffer;)V + * Signature: (JIZ)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterUpSource - (JNIEnv * env, jclass, jobject id, jint pin, jbyte analogTrigger, jobject status) + (JNIEnv * env, jclass, jlong id, jint pin, jboolean analogTrigger) { COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterUpSource"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId; + COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id; COUNTERJNI_LOG(logDEBUG) << "Pin = " << pin; COUNTERJNI_LOG(logDEBUG) << "AnalogTrigger = " << (jint)analogTrigger; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - setCounterUpSource(*javaId, pin, analogTrigger, statusPtr); - COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + setCounterUpSource((void*)id, pin, analogTrigger, &status); + COUNTERJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_CounterJNI * Method: setCounterUpSourceEdge - * Signature: (Ljava/nio/ByteBuffer;BBLjava/nio/IntBuffer;)V + * Signature: (JZZ)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterUpSourceEdge - (JNIEnv * env, jclass, jobject id, jbyte valueRise, jbyte valueFall, jobject status) + (JNIEnv * env, jclass, jlong id, jboolean valueRise, jboolean valueFall) { COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterUpSourceEdge"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId; + COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id; COUNTERJNI_LOG(logDEBUG) << "Rise = " << (jint)valueRise; COUNTERJNI_LOG(logDEBUG) << "Fall = " << (jint)valueFall; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - setCounterUpSourceEdge(*javaId, valueRise, valueFall, statusPtr); - COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + setCounterUpSourceEdge((void*)id, valueRise, valueFall, &status); + COUNTERJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_CounterJNI * Method: clearCounterUpSource - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V + * Signature: (J)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_clearCounterUpSource - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI clearCounterUpSource"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - clearCounterUpSource(*javaId, statusPtr); - COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id; + int32_t status = 0; + clearCounterUpSource((void*)id, &status); + COUNTERJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_CounterJNI * Method: setCounterDownSource - * Signature: (Ljava/nio/ByteBuffer;BIBLjava/nio/IntBuffer;)V + * Signature: (JIZ)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterDownSource - (JNIEnv * env, jclass, jobject id, jint pin, jbyte analogTrigger, jobject status) + (JNIEnv * env, jclass, jlong id, jint pin, jboolean analogTrigger) { COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterDownSource"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId; + COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id; COUNTERJNI_LOG(logDEBUG) << "Pin = " << pin; COUNTERJNI_LOG(logDEBUG) << "AnalogTrigger = " << (jint)analogTrigger; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - setCounterDownSource(*javaId, pin, analogTrigger, statusPtr); - COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + setCounterDownSource((void*)id, pin, analogTrigger, &status); + COUNTERJNI_LOG(logDEBUG) << "Status = " << status; + if (status == PARAMETER_OUT_OF_RANGE) { + ThrowIllegalArgumentException(env, "Counter only supports DownSource in TwoPulse and ExternalDirection modes."); + return; + } + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_CounterJNI * Method: setCounterDownSourceEdge - * Signature: (Ljava/nio/ByteBuffer;BBLjava/nio/IntBuffer;)V + * Signature: (JZZ)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterDownSourceEdge - (JNIEnv * env, jclass, jobject id, jbyte valueRise, jbyte valueFall, jobject status) + (JNIEnv * env, jclass, jlong id, jboolean valueRise, jboolean valueFall) { COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterDownSourceEdge"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId; + COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id; COUNTERJNI_LOG(logDEBUG) << "Rise = " << (jint)valueRise; COUNTERJNI_LOG(logDEBUG) << "Fall = " << (jint)valueFall; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - setCounterDownSourceEdge(*javaId, valueRise, valueFall, statusPtr); - COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + setCounterDownSourceEdge((void*)id, valueRise, valueFall, &status); + COUNTERJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_CounterJNI * Method: clearCounterDownSource - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V + * Signature: (J)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_clearCounterDownSource - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI clearCounterDownSource"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - clearCounterDownSource(*javaId, statusPtr); - COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id; + int32_t status = 0; + clearCounterDownSource((void*)id, &status); + COUNTERJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_CounterJNI * Method: setCounterUpDownMode - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V + * Signature: (J)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterUpDownMode - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterUpDownMode"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - setCounterUpDownMode(*javaId, statusPtr); - COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id; + int32_t status = 0; + setCounterUpDownMode((void*)id, &status); + COUNTERJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_CounterJNI * Method: setCounterExternalDirectionMode - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V + * Signature: (J)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterExternalDirectionMode - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterExternalDirectionMode"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - setCounterExternalDirectionMode(*javaId, statusPtr); - COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id; + int32_t status = 0; + setCounterExternalDirectionMode((void*)id, &status); + COUNTERJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_CounterJNI * Method: setCounterSemiPeriodMode - * Signature: (Ljava/nio/ByteBuffer;BLjava/nio/IntBuffer;)V + * Signature: (JZ)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterSemiPeriodMode - (JNIEnv * env, jclass, jobject id, jbyte value, jobject status) + (JNIEnv * env, jclass, jlong id, jboolean value) { COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterSemiPeriodMode"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId; + COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id; COUNTERJNI_LOG(logDEBUG) << "SemiPeriodMode = " << (jint)value; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - setCounterSemiPeriodMode(*javaId, value, statusPtr); - COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + setCounterSemiPeriodMode((void*)id, value, &status); + COUNTERJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_CounterJNI * Method: setCounterPulseLengthMode - * Signature: (Ljava/nio/ByteBuffer;DLjava/nio/IntBuffer;)V + * Signature: (JD)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterPulseLengthMode - (JNIEnv * env, jclass, jobject id, jdouble value, jobject status) + (JNIEnv * env, jclass, jlong id, jdouble value) { COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterPulseLengthMode"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId; + COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id; COUNTERJNI_LOG(logDEBUG) << "PulseLengthMode = " << value; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - setCounterPulseLengthMode(*javaId, value, statusPtr); - COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + setCounterPulseLengthMode((void*)id, value, &status); + COUNTERJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_CounterJNI * Method: getCounterSamplesToAverage - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)I + * Signature: (J)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounterSamplesToAverage - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI getCounterSamplesToAverage"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - jint returnValue = getCounterSamplesToAverage(*javaId, statusPtr); - COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id; + int32_t status = 0; + jint returnValue = getCounterSamplesToAverage((void*)id, &status); + COUNTERJNI_LOG(logDEBUG) << "Status = " << status; COUNTERJNI_LOG(logDEBUG) << "getCounterSamplesToAverageResult = " << returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_CounterJNI * Method: setCounterSamplesToAverage - * Signature: (Ljava/nio/ByteBuffer;ILjava/nio/IntBuffer;)V + * Signature: (JI)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterSamplesToAverage - (JNIEnv * env, jclass, jobject id, jint value, jobject status) + (JNIEnv * env, jclass, jlong id, jint value) { COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterSamplesToAverage"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId; + COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id; COUNTERJNI_LOG(logDEBUG) << "SamplesToAverage = " << value; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - setCounterSamplesToAverage(*javaId, value, statusPtr); - COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + setCounterSamplesToAverage((void*)id, value, &status); + COUNTERJNI_LOG(logDEBUG) << "Status = " << status; + if (status == PARAMETER_OUT_OF_RANGE) { + ThrowBoundaryException(env, value, 1, 127); + return; + } + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_CounterJNI * Method: resetCounter - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V + * Signature: (J)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_resetCounter - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI resetCounter"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - resetCounter(*javaId, statusPtr); - COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id; + int32_t status = 0; + resetCounter((void*)id, &status); + COUNTERJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_CounterJNI * Method: getCounter - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)I + * Signature: (J)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounter - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { //COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI getCounter"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - //COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - //COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - jint returnValue = getCounter(*javaId, statusPtr); - //COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + //COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id; + int32_t status = 0; + jint returnValue = getCounter((void*)id, &status); + //COUNTERJNI_LOG(logDEBUG) << "Status = " << status; //COUNTERJNI_LOG(logDEBUG) << "getCounterResult = " << returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_CounterJNI * Method: getCounterPeriod - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)D + * Signature: (J)D */ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounterPeriod - (JNIEnv *env, jclass, jobject id, jobject status) + (JNIEnv *env, jclass, jlong id) { COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI getCounterPeriod"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - jdouble returnValue = getCounterPeriod(*javaId, statusPtr); - COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id; + int32_t status = 0; + jdouble returnValue = getCounterPeriod((void*)id, &status); + COUNTERJNI_LOG(logDEBUG) << "Status = " << status; COUNTERJNI_LOG(logDEBUG) << "getCounterPeriodResult = " << returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_CounterJNI * Method: setCounterMaxPeriod - * Signature: (Ljava/nio/ByteBuffer;DLjava/nio/IntBuffer;)V + * Signature: (JD)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterMaxPeriod - (JNIEnv * env, jclass, jobject id, jdouble value, jobject status) + (JNIEnv * env, jclass, jlong id, jdouble value) { COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterMaxPeriod"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId; + COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id; COUNTERJNI_LOG(logDEBUG) << "MaxPeriod = " << value; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - setCounterMaxPeriod(*javaId, value, statusPtr); - COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + setCounterMaxPeriod((void*)id, value, &status); + COUNTERJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_CounterJNI * Method: setCounterUpdateWhenEmpty - * Signature: (Ljava/nio/ByteBuffer;BLjava/nio/IntBuffer;)V + * Signature: (JZ)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterUpdateWhenEmpty - (JNIEnv * env, jclass, jobject id, jbyte value, jobject status) + (JNIEnv * env, jclass, jlong id, jboolean value) { COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterMaxPeriod"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId; + COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id; COUNTERJNI_LOG(logDEBUG) << "UpdateWhenEmpty = " << (jint)value; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - setCounterUpdateWhenEmpty(*javaId, value, statusPtr); - COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + setCounterUpdateWhenEmpty((void*)id, value, &status); + COUNTERJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_CounterJNI * Method: getCounterStopped - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B + * Signature: (J)Z */ -JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounterStopped - (JNIEnv * env, jclass, jobject id, jobject status) +JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounterStopped + (JNIEnv * env, jclass, jlong id) { COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI getCounterStopped"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - jbyte returnValue = getCounterStopped(*javaId, statusPtr); - COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id; + int32_t status = 0; + jboolean returnValue = getCounterStopped((void*)id, &status); + COUNTERJNI_LOG(logDEBUG) << "Status = " << status; COUNTERJNI_LOG(logDEBUG) << "getCounterStoppedResult = " << (jint)returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_CounterJNI * Method: getCounterDirection - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B + * Signature: (J)Z */ -JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounterDirection - (JNIEnv * env, jclass, jobject id, jobject status) +JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_getCounterDirection + (JNIEnv * env, jclass, jlong id) { COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI getCounterDirection"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - jbyte returnValue = getCounterDirection(*javaId, statusPtr); - COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id; + int32_t status = 0; + jboolean returnValue = getCounterDirection((void*)id, &status); + COUNTERJNI_LOG(logDEBUG) << "Status = " << status; COUNTERJNI_LOG(logDEBUG) << "getCounterDirectionResult = " << (jint)returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_CounterJNI * Method: setCounterReverseDirection - * Signature: (Ljava/nio/ByteBuffer;BLjava/nio/IntBuffer;)V + * Signature: (JZ)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterReverseDirection - (JNIEnv * env, jclass, jobject id, jbyte value, jobject status) + (JNIEnv * env, jclass, jlong id, jboolean value) { COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterReverseDirection"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << *javaId; + COUNTERJNI_LOG(logDEBUG) << "Counter Ptr = " << (void*)id; COUNTERJNI_LOG(logDEBUG) << "ReverseDirection = " << (jint)value; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - COUNTERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - setCounterReverseDirection(*javaId, value, statusPtr); - COUNTERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + setCounterReverseDirection((void*)id, value, &status); + COUNTERJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } + +} // extern "C" diff --git a/wpilibj/wpilibJavaJNI/lib/DIOJNI.cpp b/wpilibj/wpilibJavaJNI/lib/DIOJNI.cpp index e30dabb70e..a79b5a85a7 100644 --- a/wpilibj/wpilibJavaJNI/lib/DIOJNI.cpp +++ b/wpilibj/wpilibJavaJNI/lib/DIOJNI.cpp @@ -5,6 +5,7 @@ #include "edu_wpi_first_wpilibj_hal_DIOJNI.h" #include "HAL/Digital.hpp" +#include "HALUtil.h" // set the logging level TLogLevel dioJNILogLevel = logWARNING; @@ -13,101 +14,92 @@ TLogLevel dioJNILogLevel = logWARNING; if (level > dioJNILogLevel) ; \ else Log().Get(level) +extern "C" { + /* * Class: edu_wpi_first_wpilibj_hal_DIOJNI * Method: initializeDigitalPort - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Ljava/nio/ByteBuffer; + * Signature: (J)J; */ -JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_initializeDigitalPort - (JNIEnv * env, jclass, jobject id, jobject status) +JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_initializeDigitalPort + (JNIEnv * env, jclass, jlong id) { DIOJNI_LOG(logDEBUG) << "Calling DIOJNI initializeDigitalPort"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - DIOJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - DIOJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - void** dioPtr = (void**)new unsigned char[4]; - *statusPtr = 0; - *dioPtr = initializeDigitalPort(*javaId, statusPtr); - DIOJNI_LOG(logDEBUG) << "Status = " << *statusPtr; - DIOJNI_LOG(logDEBUG) << "DIO Ptr = " << *dioPtr; - return env->NewDirectByteBuffer( dioPtr, 4); + DIOJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id; + int32_t status = 0; + void* dio = initializeDigitalPort((void*)id, &status); + DIOJNI_LOG(logDEBUG) << "Status = " << status; + DIOJNI_LOG(logDEBUG) << "DIO Ptr = " << dio; + CheckStatus(env, status); + return (jlong)dio; } /* * Class: edu_wpi_first_wpilibj_hal_DIOJNI * Method: allocateDIO - * Signature: (Ljava/nio/ByteBuffer;BLjava/nio/IntBuffer;)B + * Signature: (JZ)Z */ -JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_allocateDIO - (JNIEnv * env, jclass, jobject id, jbyte value, jobject status) +JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_allocateDIO + (JNIEnv * env, jclass, jlong id, jboolean value) { DIOJNI_LOG(logDEBUG) << "Calling DIOJNI allocateDIO"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - DIOJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - DIOJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - jbyte returnValue = allocateDIO(*javaId, value, statusPtr); - DIOJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + DIOJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id; + int32_t status = 0; + jboolean returnValue = allocateDIO((void*)id, value, &status); + DIOJNI_LOG(logDEBUG) << "Status = " << status; DIOJNI_LOG(logDEBUG) << "allocateDIOResult = " << (jint)returnValue; - return returnValue; + CheckStatus(env, status); + return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_DIOJNI * Method: freeDIO - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V + * Signature: (J)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_freeDIO - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { DIOJNI_LOG(logDEBUG) << "Calling DIOJNI freeDIO"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - DIOJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - DIOJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - freeDIO(*javaId, statusPtr); - DIOJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + DIOJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id; + int32_t status = 0; + freeDIO((void*)id, &status); + DIOJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_DIOJNI * Method: setDIO - * Signature: (Ljava/nio/ByteBuffer;SLjava/nio/IntBuffer;)V + * Signature: (JS)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_setDIO - (JNIEnv *env, jclass, jobject id, jshort value, jobject status) + (JNIEnv *env, jclass, jlong id, jshort value) { //DIOJNI_LOG(logDEBUG) << "Calling DIOJNI setDIO"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - //DIOJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId; + //DIOJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id; //DIOJNI_LOG(logDEBUG) << "Value = " << value; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - //DIOJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - setDIO(*javaId, value, statusPtr); - //DIOJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + setDIO((void*)id, value, &status); + //DIOJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_DIOJNI * Method: getDIO - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B + * Signature: (J)Z */ -JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_getDIO - (JNIEnv * env, jclass, jobject id, jobject status) +JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_getDIO + (JNIEnv * env, jclass, jlong id) { //DIOJNI_LOG(logDEBUG) << "Calling DIOJNI getDIO"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - //DIOJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - //DIOJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - jbyte returnValue = getDIO(*javaId, statusPtr); - //DIOJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + //DIOJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id; + int32_t status = 0; + jboolean returnValue = getDIO((void*)id, &status); + //DIOJNI_LOG(logDEBUG) << "Status = " << status; //DIOJNI_LOG(logDEBUG) << "getDIOResult = " << (jint)returnValue; + CheckStatus(env, status); return returnValue; } @@ -115,59 +107,53 @@ JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_getDIO /* * Class: edu_wpi_first_wpilibj_hal_DIOJNI * Method: getDIODirection - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B + * Signature: (J)Z */ -JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_getDIODirection - (JNIEnv *env, jclass, jobject id, jobject status) +JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_getDIODirection + (JNIEnv *env, jclass, jlong id) { DIOJNI_LOG(logDEBUG) << "Calling DIOJNI getDIODirection (RR upd)"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - //DIOJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - //DIOJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - jbyte returnValue = getDIODirection(*javaId, statusPtr); - //DIOJNI_LOG(logDEBUG) << "Status = " << *statusPtr; - DIOJNI_LOG(logDEBUG) << "getDIODirectionResult = " << (jbyte)returnValue; + //DIOJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id; + int32_t status = 0; + jboolean returnValue = getDIODirection((void*)id, &status); + //DIOJNI_LOG(logDEBUG) << "Status = " << status; + DIOJNI_LOG(logDEBUG) << "getDIODirectionResult = " << (jint)returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_DIOJNI * Method: pulse - * Signature: (Ljava/nio/ByteBuffer;DLjava/nio/IntBuffer;)V + * Signature: (JD)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_pulse - (JNIEnv *env, jclass, jobject id, jdouble value, jobject status) + (JNIEnv *env, jclass, jlong id, jdouble value) { DIOJNI_LOG(logDEBUG) << "Calling DIOJNI pulse (RR upd)"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - //DIOJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId; + //DIOJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id; //DIOJNI_LOG(logDEBUG) << "Value = " << value; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - //DIOJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - pulse(*javaId, value, statusPtr); - DIOJNI_LOG(logDEBUG) << "Did it work? Status = " << *statusPtr; + int32_t status = 0; + pulse((void*)id, value, &status); + DIOJNI_LOG(logDEBUG) << "Did it work? Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_DIOJNI * Method: isPulsing - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B + * Signature: (J)Z */ -JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_isPulsing - (JNIEnv *env, jclass, jobject id, jobject status) +JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_isPulsing + (JNIEnv *env, jclass, jlong id) { DIOJNI_LOG(logDEBUG) << "Calling DIOJNI isPulsing (RR upd)"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - //DIOJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - //DIOJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - jbyte returnValue = isPulsing(*javaId, statusPtr); - //DIOJNI_LOG(logDEBUG) << "Status = " << *statusPtr; - DIOJNI_LOG(logDEBUG) << "isPulsingResult = " << (jbyte)returnValue; + //DIOJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id; + int32_t status = 0; + jboolean returnValue = isPulsing((void*)id, &status); + //DIOJNI_LOG(logDEBUG) << "Status = " << status; + DIOJNI_LOG(logDEBUG) << "isPulsingResult = " << (jint)returnValue; + CheckStatus(env, status); return returnValue; @@ -176,34 +162,36 @@ JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_isPulsing /* * Class: edu_wpi_first_wpilibj_hal_DIOJNI * Method: isAnyPulsing - * Signature: (Ljava/nio/IntBuffer;)B + * Signature: ()Z */ -JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_isAnyPulsing - (JNIEnv *env, jclass, jobject status) +JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_isAnyPulsing + (JNIEnv *env, jclass) { DIOJNI_LOG(logDEBUG) << "Calling DIOJNI isAnyPulsing (RR upd)"; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - jbyte returnValue = isAnyPulsing( statusPtr ); - //DIOJNI_LOG(logDEBUG) << "Status = " << *statusPtr; - DIOJNI_LOG(logDEBUG) << "isAnyPulsingResult = " << (jbyte)returnValue; + int32_t status = 0; + jboolean returnValue = isAnyPulsing( &status ); + //DIOJNI_LOG(logDEBUG) << "Status = " << status; + DIOJNI_LOG(logDEBUG) << "isAnyPulsingResult = " << (jint)returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_DIOJNI * Method: getLoopTiming - * Signature: (Ljava/nio/IntBuffer;)S + * Signature: ()S */ JNIEXPORT jshort JNICALL Java_edu_wpi_first_wpilibj_hal_DIOJNI_getLoopTiming - (JNIEnv * env, jclass, jobject status) + (JNIEnv * env, jclass) { DIOJNI_LOG(logDEBUG) << "Calling DIOJNI getLoopTimeing"; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - jshort returnValue = getLoopTiming( statusPtr ); - DIOJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + jshort returnValue = getLoopTiming( &status ); + DIOJNI_LOG(logDEBUG) << "Status = " << status; DIOJNI_LOG(logDEBUG) << "LoopTiming = " << returnValue; + CheckStatus(env, status); return returnValue; } + +} // extern "C" diff --git a/wpilibj/wpilibJavaJNI/lib/EncoderJNI.cpp b/wpilibj/wpilibJavaJNI/lib/EncoderJNI.cpp index 216cd7b7a1..47d0d07424 100644 --- a/wpilibj/wpilibJavaJNI/lib/EncoderJNI.cpp +++ b/wpilibj/wpilibJavaJNI/lib/EncoderJNI.cpp @@ -5,6 +5,8 @@ #include "edu_wpi_first_wpilibj_hal_EncoderJNI.h" #include "HAL/Digital.hpp" +#include "HAL/Errors.hpp" +#include "HALUtil.h" // set the logging level TLogLevel encoderJNILogLevel = logWARNING; @@ -13,13 +15,15 @@ TLogLevel encoderJNILogLevel = logWARNING; if (level > encoderJNILogLevel) ; \ else Log().Get(level) +extern "C" { + /* * Class: edu_wpi_first_wpilibj_hal_EncoderJNI * Method: initializeEncoder - * Signature: (BIBBIBBLjava/nio/IntBuffer;Ljava/nio/IntBuffer;)Ljava/nio/ByteBuffer; + * Signature: (BIZBIZZLjava/nio/IntBuffer;)J */ -JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_initializeEncoder - (JNIEnv * env, jclass, jbyte port_a_module, jint port_a_pin, jbyte port_a_analog_trigger, jbyte port_b_module, jint port_b_pin, jbyte port_b_analog_trigger, jbyte reverseDirection, jobject index, jobject status) +JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_initializeEncoder + (JNIEnv * env, jclass, jbyte port_a_module, jint port_a_pin, jboolean port_a_analog_trigger, jbyte port_b_module, jint port_b_pin, jboolean port_b_analog_trigger, jboolean reverseDirection, jobject index) { ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI initializeEncoder"; ENCODERJNI_LOG(logDEBUG) << "Module A = " << (jint)port_a_module; @@ -31,228 +35,210 @@ JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_initializeEn ENCODERJNI_LOG(logDEBUG) << "Reverse direction = " << (jint)reverseDirection; jint * indexPtr = (jint*)env->GetDirectBufferAddress(index); ENCODERJNI_LOG(logDEBUG) << "Index Ptr = " << indexPtr; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - ENCODERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - void** encoderPtr = (void**)new unsigned char[4]; - *statusPtr = 0; - *encoderPtr = initializeEncoder(port_a_module, port_a_pin, port_a_analog_trigger, + int32_t status = 0; + void* encoder = initializeEncoder(port_a_module, port_a_pin, port_a_analog_trigger, port_b_module, port_b_pin, port_b_analog_trigger, - reverseDirection, indexPtr, statusPtr); + reverseDirection, indexPtr, &status); ENCODERJNI_LOG(logDEBUG) << "Index = " << *indexPtr; - ENCODERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; - ENCODERJNI_LOG(logDEBUG) << "ENCODER Ptr = " << *encoderPtr; - return env->NewDirectByteBuffer( encoderPtr, 4); + ENCODERJNI_LOG(logDEBUG) << "Status = " << status; + ENCODERJNI_LOG(logDEBUG) << "ENCODER Ptr = " << encoder; + CheckStatus(env, status); + return (jlong)encoder; } /* * Class: edu_wpi_first_wpilibj_hal_EncoderJNI * Method: freeEncoder - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V + * Signature: (J)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_freeEncoder - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI freeEncoder"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - ENCODERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - freeEncoder(*javaId, statusPtr); - ENCODERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << (void*)id; + int32_t status = 0; + freeEncoder((void*)id, &status); + ENCODERJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_EncoderJNI * Method: resetEncoder - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V + * Signature: (J)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_resetEncoder - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI resetEncoder"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - ENCODERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - resetEncoder(*javaId, statusPtr); - ENCODERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << (void*)id; + int32_t status = 0; + resetEncoder((void*)id, &status); + ENCODERJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_EncoderJNI * Method: getEncoder - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)I + * Signature: (J)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_getEncoder - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI getEncoder"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - ENCODERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - jint returnValue = getEncoder(*javaId, statusPtr); - ENCODERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << (void*)id; + int32_t status = 0; + jint returnValue = getEncoder((void*)id, &status); + ENCODERJNI_LOG(logDEBUG) << "Status = " << status; ENCODERJNI_LOG(logDEBUG) << "getEncoderResult = " << returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_EncoderJNI * Method: getEncoderPeriod - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)D + * Signature: (J)D */ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_getEncoderPeriod - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI getEncoderPeriod"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - ENCODERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - double returnValue = getEncoderPeriod(*javaId, statusPtr); - ENCODERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << (void*)id; + int32_t status = 0; + double returnValue = getEncoderPeriod((void*)id, &status); + ENCODERJNI_LOG(logDEBUG) << "Status = " << status; ENCODERJNI_LOG(logDEBUG) << "getEncoderPeriodResult = " << returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_EncoderJNI * Method: setEncoderMaxPeriod - * Signature: (Ljava/nio/ByteBuffer;DLjava/nio/IntBuffer;)V + * Signature: (JD)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_setEncoderMaxPeriod - (JNIEnv * env, jclass, jobject id, jdouble value, jobject status) + (JNIEnv * env, jclass, jlong id, jdouble value) { ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI setEncoderMaxPeriod"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - ENCODERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - setEncoderMaxPeriod(*javaId, value, statusPtr); - ENCODERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << (void*)id; + int32_t status = 0; + setEncoderMaxPeriod((void*)id, value, &status); + ENCODERJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_EncoderJNI * Method: getEncoderStopped - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B + * Signature: (J)Z */ -JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_getEncoderStopped - (JNIEnv * env, jclass, jobject id, jobject status) +JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_getEncoderStopped + (JNIEnv * env, jclass, jlong id) { ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI getEncoderStopped"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - ENCODERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - jbyte returnValue = getEncoderStopped(*javaId, statusPtr); - ENCODERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << (void*)id; + int32_t status = 0; + jboolean returnValue = getEncoderStopped((void*)id, &status); + ENCODERJNI_LOG(logDEBUG) << "Status = " << status; ENCODERJNI_LOG(logDEBUG) << "getEncoderStoppedResult = " << returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_EncoderJNI * Method: getEncoderDirection - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B + * Signature: (J)Z */ -JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_getEncoderDirection - (JNIEnv * env, jclass, jobject id, jobject status) +JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_getEncoderDirection + (JNIEnv * env, jclass, jlong id) { ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI getEncoderDirection"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - ENCODERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - jbyte returnValue = getEncoderDirection(*javaId, statusPtr); - ENCODERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << (void*)id; + int32_t status = 0; + jboolean returnValue = getEncoderDirection((void*)id, &status); + ENCODERJNI_LOG(logDEBUG) << "Status = " << status; ENCODERJNI_LOG(logDEBUG) << "getEncoderDirectionResult = " << returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_EncoderJNI * Method: setEncoderReverseDirection - * Signature: (Ljava/nio/ByteBuffer;BLjava/nio/IntBuffer;)V + * Signature: (JZ)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_setEncoderReverseDirection - (JNIEnv * env, jclass, jobject id, jbyte value, jobject status) + (JNIEnv * env, jclass, jlong id, jboolean value) { ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI setEncoderReverseDirection"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - ENCODERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - setEncoderReverseDirection(*javaId, value, statusPtr); - ENCODERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << (void*)id; + int32_t status = 0; + setEncoderReverseDirection((void*)id, value, &status); + ENCODERJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_EncoderJNI * Method: setEncoderSamplesToAverage - * Signature: (Ljava/nio/ByteBuffer;ILjava/nio/IntBuffer;)V + * Signature: (JI)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_setEncoderSamplesToAverage - (JNIEnv * env, jclass, jobject id, jint value, jobject status) + (JNIEnv * env, jclass, jlong id, jint value) { ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI setEncoderSamplesToAverage"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - ENCODERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - setEncoderSamplesToAverage(*javaId, value, statusPtr); - ENCODERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << (void*)id; + int32_t status = 0; + setEncoderSamplesToAverage((void*)id, value, &status); + ENCODERJNI_LOG(logDEBUG) << "Status = " << status; + if (status == PARAMETER_OUT_OF_RANGE) { + ThrowBoundaryException(env, value, 1, 127); + return; + } + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_EncoderJNI * Method: getEncoderSamplesToAverage - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)I + * Signature: (J)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_getEncoderSamplesToAverage - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI getEncoderSamplesToAverage"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - ENCODERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - jint returnValue = getEncoderSamplesToAverage(*javaId, statusPtr); - ENCODERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << (void*)id; + int32_t status = 0; + jint returnValue = getEncoderSamplesToAverage((void*)id, &status); + ENCODERJNI_LOG(logDEBUG) << "Status = " << status; ENCODERJNI_LOG(logDEBUG) << "getEncoderSamplesToAverageResult = " << returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_EncoderJNI * Method: setEncoderIndexSource - * Signature: (Ljava/nio/ByteBuffer;IZZZLjava/nio/IntBuffer;)V + * Signature: (JIZZZ)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_EncoderJNI_setEncoderIndexSource - (JNIEnv * env, jclass, jobject id, jint pin, jboolean analogTrigger, jboolean activeHigh, jboolean edgeSensitive, jobject status) + (JNIEnv * env, jclass, jlong id, jint pin, jboolean analogTrigger, jboolean activeHigh, jboolean edgeSensitive) { ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI setEncoderIndexSource"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); + ENCODERJNI_LOG(logDEBUG) << "Encoder Ptr = " << (void*)id; ENCODERJNI_LOG(logDEBUG) << "Pin = " << pin; ENCODERJNI_LOG(logDEBUG) << "Analog Trigger = " << (analogTrigger?"true":"false"); ENCODERJNI_LOG(logDEBUG) << "Active High = " << (activeHigh?"true":"false"); ENCODERJNI_LOG(logDEBUG) << "Edge Sensitive = " << (edgeSensitive?"true":"false"); - ENCODERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - setEncoderIndexSource(*javaId, pin, analogTrigger, activeHigh, edgeSensitive, statusPtr); - ENCODERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + setEncoderIndexSource((void*)id, pin, analogTrigger, activeHigh, edgeSensitive, &status); + ENCODERJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } + +} // extern "C" diff --git a/wpilibj/wpilibJavaJNI/lib/FRCNetworkCommunicationsLibrary.cpp b/wpilibj/wpilibJavaJNI/lib/FRCNetworkCommunicationsLibrary.cpp index 58e4f8c648..9f63a5f396 100644 --- a/wpilibj/wpilibJavaJNI/lib/FRCNetworkCommunicationsLibrary.cpp +++ b/wpilibj/wpilibJavaJNI/lib/FRCNetworkCommunicationsLibrary.cpp @@ -6,6 +6,7 @@ #include "HAL/HAL.hpp" //#include "NetworkCommunication/FRCComm.h" //#include "NetworkCommunication/UsageReporting.h" +#include "HALUtil.h" // set the logging level TLogLevel netCommLogLevel = logWARNING; @@ -14,7 +15,7 @@ TLogLevel netCommLogLevel = logWARNING; if (level > netCommLogLevel) ; \ else Log().Get(level) - +extern "C" { /* * Class: edu_wpi_first_wpilibj_communication_FRC_NetworkCommunicationsLibrary @@ -394,14 +395,13 @@ JNIEXPORT jstring JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCom /* * Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary * Method: setNewDataSem - * Signature: ([B)V + * Signature: (J)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_setNewDataSem - (JNIEnv * env, jclass, jobject id ) + (JNIEnv * env, jclass, jlong id ) { - MULTIWAIT_ID javaId = (MULTIWAIT_ID)env->GetDirectBufferAddress(id); - NETCOMM_LOG(logDEBUG) << "Mutex Ptr = " << javaId; - HALSetNewDataSem(javaId->native_handle()); + NETCOMM_LOG(logDEBUG) << "Mutex Ptr = " << (void*)id; + HALSetNewDataSem(((MULTIWAIT_ID)id)->native_handle()); } /* @@ -609,27 +609,29 @@ JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkComm /* * Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary * Method: HALGetSystemActive - * Signature: (Ljava/nio/IntBuffer;)Z + * Signature: ()Z */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_HALGetSystemActive - (JNIEnv * env, jclass, jobject status) + (JNIEnv * env, jclass) { - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - return HALGetSystemActive((int32_t*)statusPtr); + int32_t status = 0; + bool val = HALGetSystemActive(&status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary * Method: HALGetBrownedOut - * Signature: (Ljava/nio/IntBuffer;)Z + * Signature: ()Z */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_HALGetBrownedOut - (JNIEnv * env, jclass, jobject status) + (JNIEnv * env, jclass) { - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - return HALGetBrownedOut((int32_t*)statusPtr); + int32_t status = 0; + bool val = HALGetBrownedOut(&status); + CheckStatus(env, status); + return val; } /* @@ -650,3 +652,4 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommun return returnValue; } +} // extern "C" diff --git a/wpilibj/wpilibJavaJNI/lib/HALUtil.cpp b/wpilibj/wpilibJavaJNI/lib/HALUtil.cpp index da847726ef..95f43313d4 100644 --- a/wpilibj/wpilibJavaJNI/lib/HALUtil.cpp +++ b/wpilibj/wpilibJavaJNI/lib/HALUtil.cpp @@ -1,10 +1,13 @@ +#include "HALUtil.h" #include #include #include "Log.hpp" #include "edu_wpi_first_wpilibj_hal_HALUtil.h" +#include "FRC_NetworkCommunication/CANSessionMux.h" #include "HAL/HAL.hpp" #include "errno.h" #include +#include // set the logging level TLogLevel halUtilLogLevel = logWARNING; @@ -13,174 +16,430 @@ TLogLevel halUtilLogLevel = logWARNING; if (level > halUtilLogLevel) ; \ else Log().Get(level) +#define kRioStatusOffset -63000 +#define kRioStatusSuccess 0 +#define kRIOStatusBufferInvalidSize (kRioStatusOffset - 80) +#define kRIOStatusOperationTimedOut -52007 +#define kRIOStatusFeatureNotSupported (kRioStatusOffset - 193) +#define kRIOStatusResourceNotInitialized -52010 + +JavaVM *jvm = nullptr; +static jclass throwableCls = nullptr; +static jclass stackTraceElementCls = nullptr; +static jclass runtimeExCls = nullptr; +static jclass illegalArgExCls = nullptr; +static jclass boundaryExCls = nullptr; +static jclass canInvalidBufferExCls = nullptr; +static jclass canMessageNotFoundExCls = nullptr; +static jclass canMessageNotAllowedExCls = nullptr; +static jclass canNotInitializedExCls = nullptr; +static jclass uncleanStatusExCls = nullptr; + +static void GetStackTrace(JNIEnv *env, std::string& res) { + // create a throwable + static jmethodID constructorId = nullptr; + if (!constructorId) + constructorId = env->GetMethodID(throwableCls, "", "()V"); + jobject throwable = env->NewObject(throwableCls, constructorId); + + // retrieve information from the exception. + // get method id + // getStackTrace returns an array of StackTraceElement + static jmethodID getStackTraceId = nullptr; + if (!getStackTraceId) + getStackTraceId = env->GetMethodID(throwableCls, "getStackTrace", + "()[Ljava/lang/StackTraceElement;"); + + // call getStackTrace + jobjectArray stackTrace = + (jobjectArray)env->CallObjectMethod(throwable, getStackTraceId); + + if (!stackTrace) return; + + // get length of the array + jsize stackTraceLength = env->GetArrayLength(stackTrace); + + // get toString methodId of StackTraceElement class + static jmethodID toStringId = nullptr; + if (!toStringId) + toStringId = env->GetMethodID(stackTraceElementCls, "toString", + "()Ljava/lang/String;"); + + for (jsize i = 0; i < stackTraceLength; i++) { + // add the result of toString method of each element in the result + jobject curStackTraceElement = env->GetObjectArrayElement(stackTrace, i); + + // call to string on the object + jstring stackElementString = + (jstring)env->CallObjectMethod(curStackTraceElement, toStringId); + + if (!stackElementString) { + env->DeleteLocalRef(stackTrace); + env->DeleteLocalRef(curStackTraceElement); + return; + } + + // add a line to res + //res += " at "; + const char *tmp = env->GetStringUTFChars(stackElementString, nullptr); + res += tmp; + res += '\n'; + env->ReleaseStringUTFChars(stackElementString, tmp); + + env->DeleteLocalRef(curStackTraceElement); + env->DeleteLocalRef(stackElementString); + } + + // release java resources + env->DeleteLocalRef(stackTrace); +} + +void ReportError(JNIEnv *env, int32_t status, bool do_throw) { + if (status == 0) return; + const char *message = getHALErrorMessage(status); + if (do_throw && status < 0) { + char *buf = new char[strlen(message) + 30]; + sprintf(buf, " Code: %d. %s", status, message); + env->ThrowNew(runtimeExCls, buf); + delete[] buf; + } else { + std::string fullmsg = message; + fullmsg += " at "; + GetStackTrace(env, fullmsg); + fprintf(stderr, "%s\n", fullmsg.c_str()); + HALControlWord controlWord; + HALGetControlWord(&controlWord); + if (controlWord.dsAttached) + HALSetErrorData(fullmsg.c_str(), fullmsg.size(), 0); + } +} + +void ReportCANError(JNIEnv *env, int32_t status, int message_id) { + if (status >= 0) return; + switch (status) { + case kRioStatusSuccess: + // Everything is ok... don't throw. + break; + case ERR_CANSessionMux_InvalidBuffer: + case kRIOStatusBufferInvalidSize: { + static jmethodID invalidBufConstruct = nullptr; + if (!invalidBufConstruct) + invalidBufConstruct = + env->GetMethodID(canInvalidBufferExCls, "", "()V"); + jobject exception = + env->NewObject(canInvalidBufferExCls, invalidBufConstruct); + env->Throw(static_cast(exception)); + break; + } + case ERR_CANSessionMux_MessageNotFound: + case kRIOStatusOperationTimedOut: { + static jmethodID messageNotFoundConstruct = nullptr; + if (!messageNotFoundConstruct) + messageNotFoundConstruct = + env->GetMethodID(canMessageNotFoundExCls, "", "()V"); + jobject exception = + env->NewObject(canMessageNotFoundExCls, messageNotFoundConstruct); + env->Throw(static_cast(exception)); + break; + } + case ERR_CANSessionMux_NotAllowed: + case kRIOStatusFeatureNotSupported: { + char buf[100]; + sprintf(buf, "MessageID = %d", message_id); + env->ThrowNew(canMessageNotAllowedExCls, buf); + break; + } + case ERR_CANSessionMux_NotInitialized: + case kRIOStatusResourceNotInitialized: { + static jmethodID notInitConstruct = nullptr; + if (!notInitConstruct) + notInitConstruct = + env->GetMethodID(canNotInitializedExCls, "", "()V"); + jobject exception = + env->NewObject(canNotInitializedExCls, notInitConstruct); + env->Throw(static_cast(exception)); + break; + } + default: { + char buf[100]; + sprintf(buf, "Fatal status code detected: %d", status); + env->ThrowNew(uncleanStatusExCls, buf); + break; + } + } +} + +void ThrowIllegalArgumentException(JNIEnv *env, const char *msg) { + env->ThrowNew(illegalArgExCls, msg); +} + +void ThrowBoundaryException(JNIEnv *env, double value, double lower, + double upper) { + static jmethodID getMessage = nullptr; + if (!getMessage) + getMessage = env->GetStaticMethodID(boundaryExCls, "getMessage", + "(DDD)Ljava/lang/String;"); + + static jmethodID constructor = nullptr; + if (!constructor) + constructor = + env->GetMethodID(boundaryExCls, "", "(Ljava/lang/String;)V"); + + jobject msg = + env->CallStaticObjectMethod(boundaryExCls, getMessage, (jdouble)value, + (jdouble)lower, (jdouble)upper); + jobject ex = env->NewObject(boundaryExCls, constructor, msg); + env->Throw(static_cast(ex)); +} + +extern "C" { // -// indicate JNI version support desired +// indicate JNI version support desired and load classes // JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { + jvm = vm; + // set our logging level Log::ReportingLevel() = logDEBUG; + + JNIEnv *env; + if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6) != JNI_OK) + return JNI_ERR; + + // Cache references to classes + jclass local; + + local = env->FindClass("java/lang/Throwable"); + if (!local) return JNI_ERR; + throwableCls = static_cast(env->NewGlobalRef(local)); + if (!throwableCls) return JNI_ERR; + env->DeleteLocalRef(local); + + local = env->FindClass("java/lang/StackTraceElement"); + if (!local) return JNI_ERR; + stackTraceElementCls = static_cast(env->NewGlobalRef(local)); + if (!stackTraceElementCls) return JNI_ERR; + env->DeleteLocalRef(local); + + local = env->FindClass("java/lang/RuntimeException"); + if (!local) return JNI_ERR; + runtimeExCls = static_cast(env->NewGlobalRef(local)); + if (!runtimeExCls) return JNI_ERR; + env->DeleteLocalRef(local); + + local = env->FindClass("java/lang/IllegalArgumentException"); + if (!local) return JNI_ERR; + illegalArgExCls = static_cast(env->NewGlobalRef(local)); + if (!illegalArgExCls) return JNI_ERR; + env->DeleteLocalRef(local); + + local = env->FindClass("edu/wpi/first/wpilibj/util/BoundaryException"); + if (!local) return JNI_ERR; + boundaryExCls = static_cast(env->NewGlobalRef(local)); + if (!boundaryExCls) return JNI_ERR; + env->DeleteLocalRef(local); + + local = env->FindClass("edu/wpi/first/wpilibj/can/CANInvalidBufferException"); + if (!local) return JNI_ERR; + canInvalidBufferExCls = static_cast(env->NewGlobalRef(local)); + if (!canInvalidBufferExCls) return JNI_ERR; + env->DeleteLocalRef(local); + + local = + env->FindClass("edu/wpi/first/wpilibj/can/CANMessageNotFoundException"); + if (!local) return JNI_ERR; + canMessageNotFoundExCls = static_cast(env->NewGlobalRef(local)); + if (!canMessageNotFoundExCls) return JNI_ERR; + env->DeleteLocalRef(local); + + local = + env->FindClass("edu/wpi/first/wpilibj/can/CANMessageNotAllowedException"); + if (!local) return JNI_ERR; + canMessageNotAllowedExCls = static_cast(env->NewGlobalRef(local)); + if (!canMessageNotAllowedExCls) return JNI_ERR; + env->DeleteLocalRef(local); + + local = + env->FindClass("edu/wpi/first/wpilibj/can/CANNotInitializedException"); + if (!local) return JNI_ERR; + canNotInitializedExCls = static_cast(env->NewGlobalRef(local)); + if (!canNotInitializedExCls) return JNI_ERR; + env->DeleteLocalRef(local); + + local = env->FindClass("edu/wpi/first/wpilibj/util/UncleanStatusException"); + if (!local) return JNI_ERR; + uncleanStatusExCls = static_cast(env->NewGlobalRef(local)); + if (!uncleanStatusExCls) return JNI_ERR; + env->DeleteLocalRef(local); + return JNI_VERSION_1_6; } +JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) +{ + JNIEnv *env; + if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6) != JNI_OK) + return; + // Delete global references + if (throwableCls) env->DeleteGlobalRef(throwableCls); + if (stackTraceElementCls) env->DeleteGlobalRef(stackTraceElementCls); + if (runtimeExCls) env->DeleteGlobalRef(runtimeExCls); + if (illegalArgExCls) env->DeleteGlobalRef(illegalArgExCls); + if (boundaryExCls) env->DeleteGlobalRef(boundaryExCls); + if (canInvalidBufferExCls) env->DeleteGlobalRef(canInvalidBufferExCls); + if (canMessageNotFoundExCls) env->DeleteGlobalRef(canMessageNotFoundExCls); + if (canMessageNotAllowedExCls) env->DeleteGlobalRef(canMessageNotAllowedExCls); + if (canNotInitializedExCls) env->DeleteGlobalRef(canNotInitializedExCls); + if (uncleanStatusExCls) env->DeleteGlobalRef(uncleanStatusExCls); + jvm = nullptr; +} + /* * Class: edu_wpi_first_wpilibj_hal_HALUtil * Method: initializeMutex - * Signature: (I)Ljava/nio/ByteBuffer; + * Signature: (I)J */ - JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_initializeMutexNormal -(JNIEnv * env, jclass) +JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_initializeMutexNormal + (JNIEnv * env, jclass) { HALUTIL_LOG(logDEBUG) << "Calling HALUtil initializeMutex"; - MUTEX_ID mutexPtr = (MUTEX_ID)new unsigned char[sizeof(MUTEX_ID)]; - mutexPtr = initializeMutexNormal(); - HALUTIL_LOG(logDEBUG) << "Mutex Ptr = " << mutexPtr; - return env->NewDirectByteBuffer(mutexPtr, sizeof(MUTEX_ID)); + MUTEX_ID mutex = initializeMutexNormal(); + HALUTIL_LOG(logDEBUG) << "Mutex Ptr = " << mutex; + return (jlong)mutex; } /* * Class: edu_wpi_first_wpilibj_hal_HALUtil * Method: deleteMutex - * Signature: (Ljava/nio/ByteBuffer;)V + * Signature: (J)V */ - JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_deleteMutex -(JNIEnv * env, jclass, jobject id ) +JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_deleteMutex + (JNIEnv * env, jclass, jlong id ) { HALUTIL_LOG(logDEBUG) << "Calling HALUtil deleteMutex"; - MUTEX_ID javaId = (MUTEX_ID)env->GetDirectBufferAddress(id); - HALUTIL_LOG(logDEBUG) << "Mutex Ptr = " << javaId; - deleteMutex( javaId ); - delete[] javaId; + HALUTIL_LOG(logDEBUG) << "Mutex Ptr = " << (MUTEX_ID)id; + deleteMutex((MUTEX_ID)id); } /* * Class: edu_wpi_first_wpilibj_hal_HALUtil * Method: takeMutex - * Signature: (Ljava/nio/ByteBuffer;I)B + * Signature: (JI)V */ - JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_takeMutex -(JNIEnv * env, jclass, jobject id) +JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_takeMutex + (JNIEnv * env, jclass, jlong id) { //HALUTIL_LOG(logDEBUG) << "Calling HALUtil takeMutex"; - MUTEX_ID javaId = (MUTEX_ID)env->GetDirectBufferAddress(id); - //HALUTIL_LOG(logDEBUG) << "Mutex Ptr = " << *javaId; - takeMutex(javaId); - //HALUTIL_LOG(logDEBUG) << "Take Result = " << (void*)returnValue; - return 0; + //HALUTIL_LOG(logDEBUG) << "Mutex Ptr = " << (MUTEX_ID)id; + takeMutex((MUTEX_ID)id); } /* * Class: edu_wpi_first_wpilibj_hal_HALUtil * Method: initializeMultiWait - * Signature: ()Ljava/nio/ByteBuffer; + * Signature: ()J */ - JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_initializeMultiWait -(JNIEnv * env, jclass) +JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_initializeMultiWait + (JNIEnv * env, jclass) { HALUTIL_LOG(logDEBUG) << "Calling HALUtil initializeMultiWait"; - MULTIWAIT_ID multiWaitPtr = (MULTIWAIT_ID)new unsigned char[4]; - multiWaitPtr = initializeMultiWait(); - HALUTIL_LOG(logDEBUG) << "MultiWait Ptr = " << multiWaitPtr; - return env->NewDirectByteBuffer( multiWaitPtr, 4); + MULTIWAIT_ID multiWait = initializeMultiWait(); + HALUTIL_LOG(logDEBUG) << "MultiWait Ptr = " << multiWait; + return (jlong)multiWait; } /* * Class: edu_wpi_first_wpilibj_hal_HALUtil * Method: deleteMultiWait - * Signature: (Ljava/nio/ByteBuffer;)V + * Signature: (J)V */ - JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_deleteMultiWait -(JNIEnv * env, jclass, jobject id) +JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_deleteMultiWait + (JNIEnv * env, jclass, jlong id) { HALUTIL_LOG(logDEBUG) << "Calling HALUtil deleteMultiWait"; - MULTIWAIT_ID javaId = (MULTIWAIT_ID)env->GetDirectBufferAddress(id); - HALUTIL_LOG(logDEBUG) << "MultiWait Ptr = " << javaId; - deleteMultiWait( javaId ); + HALUTIL_LOG(logDEBUG) << "MultiWait Ptr = " << (MULTIWAIT_ID)id; + deleteMultiWait((MULTIWAIT_ID)id); } /* * Class: edu_wpi_first_wpilibj_hal_HALUtil * Method: takeMultiWait - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;I)B + * Signature: (JJ)V */ - JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_takeMultiWait -(JNIEnv * env, jclass, jobject multiWaitId, jobject mutexId) +JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_takeMultiWait + (JNIEnv * env, jclass, jlong multiWaitId, jlong mutexId) { - MULTIWAIT_ID javaMultiWaitId = (MULTIWAIT_ID)env->GetDirectBufferAddress(multiWaitId); - MUTEX_ID javaMutexId = (MUTEX_ID)env->GetDirectBufferAddress(mutexId); - takeMultiWait(javaMultiWaitId, javaMutexId); - return 0; + takeMultiWait((MULTIWAIT_ID)multiWaitId, (MUTEX_ID)mutexId); } /* * Class: edu_wpi_first_wpilibj_hal_HALUtil * Method: getFPGAVersion - * Signature: (Ljava/nio/IntBuffer;)S + * Signature: ()S */ - JNIEXPORT jshort JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGAVersion -(JNIEnv * env, jclass, jobject status) +JNIEXPORT jshort JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGAVersion + (JNIEnv * env, jclass) { HALUTIL_LOG(logDEBUG) << "Calling HALUtil getFPGAVersion"; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - jshort returnValue = getFPGAVersion( statusPtr ); - HALUTIL_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + jshort returnValue = getFPGAVersion(&status); + HALUTIL_LOG(logDEBUG) << "Status = " << status; HALUTIL_LOG(logDEBUG) << "FPGAVersion = " << returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_HALUtil * Method: getFPGARevision - * Signature: (Ljava/nio/IntBuffer;)I + * Signature: ()I */ - JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGARevision -(JNIEnv * env, jclass, jobject status) +JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGARevision + (JNIEnv * env, jclass) { HALUTIL_LOG(logDEBUG) << "Calling HALUtil getFPGARevision"; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - jint returnValue = getFPGARevision( statusPtr ); - HALUTIL_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + jint returnValue = getFPGARevision(&status); + HALUTIL_LOG(logDEBUG) << "Status = " << status; HALUTIL_LOG(logDEBUG) << "FPGARevision = " << returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_HALUtil * Method: getFPGATime - * Signature: (Ljava/nio/IntBuffer;)I + * Signature: ()J */ - JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGATime -(JNIEnv * env, jclass, jobject status) +JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGATime + (JNIEnv * env, jclass) { //HALUTIL_LOG(logDEBUG) << "Calling HALUtil getFPGATime"; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - jlong returnValue = getFPGATime( statusPtr ); - //HALUTIL_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + jlong returnValue = getFPGATime(&status); + //HALUTIL_LOG(logDEBUG) << "Status = " << status; //HALUTIL_LOG(logDEBUG) << "FPGATime = " << returnValue; + CheckStatus(env, status); return returnValue; - } /* * Class: edu_wpi_first_wpilibj_hal_HALUtil * Method: getFPGAButton - * Signature: (Ljava/nio/IntBuffer;)I + * Signature: ()I */ - JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGAButton -(JNIEnv * env, jclass, jobject status) +JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGAButton + (JNIEnv * env, jclass) { //HALUTIL_LOG(logDEBUG) << "Calling HALUtil getFPGATime"; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - jboolean returnValue = getFPGAButton( statusPtr ); - //HALUTIL_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + jboolean returnValue = getFPGAButton(&status); + //HALUTIL_LOG(logDEBUG) << "Status = " << status; //HALUTIL_LOG(logDEBUG) << "FPGATime = " << returnValue; + CheckStatus(env, status); return returnValue; - } /* @@ -188,8 +447,8 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) * Method: getHALErrorMessage * Signature: (I)Ljava/lang/String; */ - JNIEXPORT jstring JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getHALErrorMessage -(JNIEnv * paramEnv, jclass, jint paramId) +JNIEXPORT jstring JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getHALErrorMessage + (JNIEnv * paramEnv, jclass, jint paramId) { const char * msg = getHALErrorMessage(paramId); HALUTIL_LOG(logDEBUG) << "Calling HALUtil getHALErrorMessage id=" << paramId << " msg=" << msg; @@ -201,8 +460,8 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) * Method: getHALErrno * Signature: ()I */ - JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getHALErrno -(JNIEnv *, jclass) +JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getHALErrno + (JNIEnv *, jclass) { return errno; } @@ -212,15 +471,12 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) * Method: getHALstrerror * Signature: (I)Ljava/lang/String; */ - JNIEXPORT jstring JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getHALstrerror -(JNIEnv * env, jclass, jint errorCode) +JNIEXPORT jstring JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getHALstrerror + (JNIEnv * env, jclass, jint errorCode) { const char * msg = strerror(errno); HALUTIL_LOG(logDEBUG) << "Calling HALUtil getHALstrerror errorCode=" << errorCode << " msg=" << msg; return env->NewStringUTF(msg); } -JNIEXPORT jint JNICALL -Java_edu_wpi_first_wpilibj_hal_HALUtil_pointerSize(JNIEnv*, jclass) { - return sizeof(void*); -} +} // extern "C" diff --git a/wpilibj/wpilibJavaJNI/lib/HALUtil.h b/wpilibj/wpilibJavaJNI/lib/HALUtil.h new file mode 100644 index 0000000000..18366810d3 --- /dev/null +++ b/wpilibj/wpilibJavaJNI/lib/HALUtil.h @@ -0,0 +1,28 @@ +#ifndef HALUTIL_H +#define HALUTIL_H + +#include + +#include + +extern JavaVM *jvm; + +void ReportError(JNIEnv *env, int32_t status, bool do_throw = true); + +inline bool CheckStatus(JNIEnv *env, int32_t status, bool do_throw = true) { + if (status != 0) ReportError(env, status, do_throw); + return status == 0; +} + +void ReportCANError(JNIEnv *env, int32_t status, int message_id); + +inline bool CheckCANStatus(JNIEnv *env, int32_t status, int message_id) { + if (status != 0) ReportCANError(env, status, message_id); + return status == 0; +} + +void ThrowIllegalArgumentException(JNIEnv *env, const char *msg); +void ThrowBoundaryException(JNIEnv *env, double value, double lower, + double upper); + +#endif // HALUTIL_H diff --git a/wpilibj/wpilibJavaJNI/lib/I2CJNI.cpp b/wpilibj/wpilibJavaJNI/lib/I2CJNI.cpp index 8f7e5d566e..8cfd078cc8 100644 --- a/wpilibj/wpilibJavaJNI/lib/I2CJNI.cpp +++ b/wpilibj/wpilibJavaJNI/lib/I2CJNI.cpp @@ -5,6 +5,7 @@ #include "edu_wpi_first_wpilibj_hal_I2CJNI.h" #include "HAL/Digital.hpp" +#include "HALUtil.h" // set the logging level TLogLevel i2cJNILogLevel = logWARNING; @@ -13,44 +14,45 @@ TLogLevel i2cJNILogLevel = logWARNING; if (level > i2cJNILogLevel) ; \ else Log().Get(level) +extern "C" { + /* * Class: edu_wpi_first_wpilibj_hal_I2CJNI * Method: i2cInitialize - * Signature: (BLjava/nio/IntBuffer;)V + * Signature: (B)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CInitialize - (JNIEnv * env, jclass, jbyte value, jobject status) + (JNIEnv * env, jclass, jbyte value) { I2CJNI_LOG(logDEBUG) << "Calling I2CJNI i2CInititalize"; I2CJNI_LOG(logDEBUG) << "Port: " << (jint) value; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - i2CInitialize(value, statusPtr); - I2CJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + i2CInitialize(value, &status); + I2CJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_I2CJNI * Method: i2CTransaction - * Signature: (BBLjava/nio/ByteBuffer;BLjava/nio/ByteBuffer;B)B + * Signature: (BBLjava/nio/ByteBuffer;BLjava/nio/ByteBuffer;B)I */ -JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CTransaction +JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CTransaction (JNIEnv * env, jclass, jbyte port, jbyte address, jobject dataToSend, jbyte sendSize, jobject dataReceived, jbyte receiveSize) { I2CJNI_LOG(logDEBUG) << "Calling I2CJNI i2CTransaction"; I2CJNI_LOG(logDEBUG) << "Port = " << (jint)port; I2CJNI_LOG(logDEBUG) << "Address = " << (jint)address; - jbyte * dataToSendPtr = NULL; - jbyte * dataReceivedPtr = NULL; - if(dataToSend !=0){ - dataToSendPtr = (jbyte*)env->GetDirectBufferAddress(dataToSend); + uint8_t* dataToSendPtr = nullptr; + if (dataToSend != 0) { + dataToSendPtr = (uint8_t*)env->GetDirectBufferAddress(dataToSend); } I2CJNI_LOG(logDEBUG) << "DataToSendPtr = " << (jint*)dataToSendPtr; I2CJNI_LOG(logDEBUG) << "SendSize = " << (jint)sendSize; - dataReceivedPtr = (jbyte*)env->GetDirectBufferAddress(dataReceived); + uint8_t* dataReceivedPtr = (uint8_t*)env->GetDirectBufferAddress(dataReceived); I2CJNI_LOG(logDEBUG) << "DataReceivedPtr = " << (jint*)dataReceivedPtr; I2CJNI_LOG(logDEBUG) << "ReceiveSize = " << (jint)receiveSize; - jbyte returnValue = i2CTransaction(port, address, (uint8_t*)dataToSendPtr, sendSize, (uint8_t*) dataReceivedPtr, receiveSize); + jint returnValue = i2CTransaction(port, address, dataToSendPtr, sendSize, dataReceivedPtr, receiveSize); I2CJNI_LOG(logDEBUG) << "ReturnValue = " << returnValue; return returnValue; } @@ -58,23 +60,23 @@ JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CTransaction /* * Class: edu_wpi_first_wpilibj_hal_I2CJNI * Method: i2CWrite - * Signature: (BBLjava/nio/ByteBuffer;B)B + * Signature: (BBLjava/nio/ByteBuffer;B)I */ -JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CWrite +JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CWrite (JNIEnv * env, jclass, jbyte port, jbyte address, jobject dataToSend, jbyte sendSize) { I2CJNI_LOG(logDEBUG) << "Calling I2CJNI i2CWrite"; I2CJNI_LOG(logDEBUG) << "Port = " << (jint)port; I2CJNI_LOG(logDEBUG) << "Address = " << (jint)address; - jbyte * dataToSendPtr = NULL; + uint8_t* dataToSendPtr = nullptr; - if(dataToSend !=0){ - dataToSendPtr = (jbyte*)env->GetDirectBufferAddress(dataToSend); + if (dataToSend != 0) { + dataToSendPtr = (uint8_t*)env->GetDirectBufferAddress(dataToSend); } - I2CJNI_LOG(logDEBUG) << "DataToSendPtr = " << (jint*)dataToSendPtr; + I2CJNI_LOG(logDEBUG) << "DataToSendPtr = " << dataToSendPtr; I2CJNI_LOG(logDEBUG) << "SendSize = " << (jint)dataToSend; - jbyte returnValue = i2CWrite(port, address, (uint8_t*)dataToSendPtr, sendSize); + jint returnValue = i2CWrite(port, address, dataToSendPtr, sendSize); I2CJNI_LOG(logDEBUG) << "ReturnValue = " << (jint)returnValue; return returnValue; } @@ -82,19 +84,18 @@ JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CWrite /* * Class: edu_wpi_first_wpilibj_hal_I2CJNI * Method: i2CRead - * Signature: (BBLjava/nio/ByteBuffer;B)B + * Signature: (BBLjava/nio/ByteBuffer;B)I */ -JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CRead +JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CRead (JNIEnv * env, jclass, jbyte port, jbyte address, jobject dataReceived, jbyte receiveSize) { I2CJNI_LOG(logDEBUG) << "Calling I2CJNI i2CRead"; I2CJNI_LOG(logDEBUG) << "Port = " << port; I2CJNI_LOG(logDEBUG) << "Address = " << address; - jbyte * dataReceivedPtr = NULL; - dataReceivedPtr = (jbyte*)env->GetDirectBufferAddress(dataReceived); - I2CJNI_LOG(logDEBUG) << "DataReceivedPtr = " << (jint*)dataReceivedPtr; + uint8_t* dataReceivedPtr = (uint8_t*)env->GetDirectBufferAddress(dataReceived); + I2CJNI_LOG(logDEBUG) << "DataReceivedPtr = " << dataReceivedPtr; I2CJNI_LOG(logDEBUG) << "ReceiveSize = " << receiveSize; - jbyte returnValue = i2CRead(port, address, (uint8_t*) dataReceivedPtr, receiveSize); + jint returnValue = i2CRead(port, address, dataReceivedPtr, receiveSize); I2CJNI_LOG(logDEBUG) << "ReturnValue = " << returnValue; return returnValue; } @@ -107,6 +108,8 @@ JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CRead JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_I2CJNI_i2CClose (JNIEnv *, jclass, jbyte value) { - I2CJNI_LOG(logDEBUG) << "Calling I2CJNI i2cClose"; + I2CJNI_LOG(logDEBUG) << "Calling I2CJNI i2CClose"; i2CClose(value); } + +} // extern "C" diff --git a/wpilibj/wpilibJavaJNI/lib/InterruptJNI.cpp b/wpilibj/wpilibJavaJNI/lib/InterruptJNI.cpp index 1138f4de82..25ce6cfe41 100644 --- a/wpilibj/wpilibJavaJNI/lib/InterruptJNI.cpp +++ b/wpilibj/wpilibJavaJNI/lib/InterruptJNI.cpp @@ -4,6 +4,7 @@ #include "edu_wpi_first_wpilibj_hal_InterruptJNI.h" #include "HAL/Interrupts.hpp" +#include "HALUtil.h" TLogLevel interruptJNILogLevel = logERROR; @@ -11,197 +12,165 @@ TLogLevel interruptJNILogLevel = logERROR; if (level > interruptJNILogLevel) ; \ else Log().Get(level) -//Used for callback when an interrupt is fired. -static JavaVM *jvm; - -/* - * Class: edu_wpi_first_wpilibj_hal_InterruptJNI - * Method: initializeInterruptJVM - * Signature: (Ljava/nio/IntBuffer;)V - */ -JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_initializeInterruptJVM - (JNIEnv * env, jclass, jobject status) -{ - //This method should be called once to setup the JVM - INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI initializeInterruptJVM"; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - INTERRUPTJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - jint rs = env->GetJavaVM(&jvm); - assert (rs == JNI_OK); -} - +extern "C" { /* * Class: edu_wpi_first_wpilibj_hal_InterruptJNI * Method: initializeInterrupts - * Signature: (IBLjava/nio/IntBuffer;)Ljava/nio/ByteBuffer; + * Signature: (IZ)J */ -JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_initializeInterrupts - (JNIEnv * env, jclass, jint interruptIndex, jbyte watcher, jobject status) +JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_initializeInterrupts + (JNIEnv * env, jclass, jint interruptIndex, jboolean watcher) { INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI initializeInterrupts"; INTERRUPTJNI_LOG(logDEBUG) << "interruptIndex = " << interruptIndex; INTERRUPTJNI_LOG(logDEBUG) << "watcher = " << (bool) watcher; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - INTERRUPTJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - void** interruptPtr = (void**)new unsigned char[4]; - *statusPtr = 0; - *interruptPtr = (void**) initializeInterrupts(interruptIndex, watcher, statusPtr); + int32_t status = 0; + void* interrupt = initializeInterrupts(interruptIndex, watcher, &status); - INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << *interruptPtr; - INTERRUPTJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << interrupt; + INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status; - return env->NewDirectByteBuffer(interruptPtr, 4); + CheckStatus(env, status); + return (jlong)interrupt; } /* * Class: edu_wpi_first_wpilibj_hal_InterruptJNI * Method: cleanInterrupts - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V + * Signature: (J)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_cleanInterrupts - (JNIEnv * env, jclass, jobject interrupt_pointer, jobject status) + (JNIEnv * env, jclass, jlong interrupt_pointer) { INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI cleanInterrupts"; - void ** javaId = (void**)env->GetDirectBufferAddress(interrupt_pointer); - INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - INTERRUPTJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; + INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer; - *statusPtr = 0; - cleanInterrupts(*javaId, statusPtr); + int32_t status = 0; + cleanInterrupts((void*)interrupt_pointer, &status); - INTERRUPTJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status; + + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_InterruptJNI * Method: waitForInterrupt - * Signature: (Ljava/nio/ByteBuffer;DLjava/nio/IntBuffer;)V + * Signature: (JD)V */ JNIEXPORT int JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_waitForInterrupt - (JNIEnv * env, jclass, jobject interrupt_pointer, jdouble timeout, jboolean ignorePrevious, jobject status) + (JNIEnv * env, jclass, jlong interrupt_pointer, jdouble timeout, jboolean ignorePrevious) { INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI waitForInterrupt"; - void ** javaId = (void**)env->GetDirectBufferAddress(interrupt_pointer); - INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - INTERRUPTJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; + INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer; - *statusPtr = 0; - int result = waitForInterrupt(*javaId, timeout, ignorePrevious, statusPtr); + int32_t status = 0; + int result = waitForInterrupt((void*)interrupt_pointer, timeout, ignorePrevious, &status); - INTERRUPTJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); return result; } /* * Class: edu_wpi_first_wpilibj_hal_InterruptJNI * Method: enableInterrupts - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V + * Signature: (J)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_enableInterrupts - (JNIEnv * env, jclass, jobject interrupt_pointer, jobject status) + (JNIEnv * env, jclass, jlong interrupt_pointer) { INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI enableInterrupts"; - void ** javaId = (void**)env->GetDirectBufferAddress(interrupt_pointer); - INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - INTERRUPTJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; + INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer; - *statusPtr = 0; - enableInterrupts(*javaId, statusPtr); + int32_t status = 0; + enableInterrupts((void*)interrupt_pointer, &status); - INTERRUPTJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status; + + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_InterruptJNI * Method: disableInterrupts - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V + * Signature: (J)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_disableInterrupts - (JNIEnv * env, jclass, jobject interrupt_pointer, jobject status) + (JNIEnv * env, jclass, jlong interrupt_pointer) { INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI disableInterrupts"; - void ** javaId = (void**)env->GetDirectBufferAddress(interrupt_pointer); - INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - INTERRUPTJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; + INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer; - *statusPtr = 0; - disableInterrupts(*javaId, statusPtr); + int32_t status = 0; + disableInterrupts((void*)interrupt_pointer, &status); - INTERRUPTJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status; + + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_InterruptJNI * Method: readRisingTimestamp - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)D + * Signature: (J)D */ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_readRisingTimestamp - (JNIEnv * env, jclass, jobject interrupt_pointer, jobject status) + (JNIEnv * env, jclass, jlong interrupt_pointer) { INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI readRisingTimestamp"; - void ** javaId = (void**)env->GetDirectBufferAddress(interrupt_pointer); - INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - INTERRUPTJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; + INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer; - *statusPtr = 0; - jdouble timeStamp = readRisingTimestamp(*javaId, statusPtr); + int32_t status = 0; + jdouble timeStamp = readRisingTimestamp((void*)interrupt_pointer, &status); - INTERRUPTJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); return timeStamp; } /* * Class: edu_wpi_first_wpilibj_hal_InterruptJNI * Method: readFallingTimestamp - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)D + * Signature: (J)D */ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_readFallingTimestamp - (JNIEnv * env, jclass, jobject interrupt_pointer, jobject status) + (JNIEnv * env, jclass, jlong interrupt_pointer) { INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI readFallingTimestamp"; - void ** javaId = (void**)env->GetDirectBufferAddress(interrupt_pointer); - INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - INTERRUPTJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; + INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer; - *statusPtr = 0; - jdouble timeStamp = readFallingTimestamp(*javaId, statusPtr); + int32_t status = 0; + jdouble timeStamp = readFallingTimestamp((void*)interrupt_pointer, &status); - INTERRUPTJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); return timeStamp; } /* * Class: edu_wpi_first_wpilibj_hal_InterruptJNI * Method: requestInterrupts - * Signature: (Ljava/nio/ByteBuffer;BIBLjava/nio/IntBuffer;)V + * Signature: (JBIZ)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_requestInterrupts - (JNIEnv * env, jclass, jobject interrupt_pointer, jbyte routing_module, jint routing_pin, jbyte routing_analog_trigger, jobject status) + (JNIEnv * env, jclass, jlong interrupt_pointer, jbyte routing_module, jint routing_pin, jboolean routing_analog_trigger) { INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI requestInterrupts"; - void ** javaId = (void**)env->GetDirectBufferAddress(interrupt_pointer); - INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << *javaId; + INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer; INTERRUPTJNI_LOG(logDEBUG) << "routing module = " << (jint) routing_module; INTERRUPTJNI_LOG(logDEBUG) << "routing pin = " << routing_pin; INTERRUPTJNI_LOG(logDEBUG) << "routing analog trigger = " << (jint) routing_analog_trigger; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - INTERRUPTJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - requestInterrupts(*javaId, (uint8_t) routing_module, (uint32_t) routing_pin, routing_analog_trigger, statusPtr); + int32_t status = 0; + requestInterrupts((void*)interrupt_pointer, (uint8_t) routing_module, (uint32_t) routing_pin, routing_analog_trigger, &status); - INTERRUPTJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } @@ -260,17 +229,13 @@ void interruptHandler(uint32_t mask, void *data) { /* * Class: edu_wpi_first_wpilibj_hal_InterruptJNI * Method: attachInterruptHandler - * Signature: (Ljava/nio/ByteBuffer;Ledu/wpi/first/wpilibj/hal/InterruptJNI/InterruptHandlerFunction;Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V + * Signature: (JLedu/wpi/first/wpilibj/hal/InterruptJNI/InterruptHandlerFunction;Ljava/nio/ByteBuffer;)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_attachInterruptHandler - (JNIEnv * env, jclass, jobject interrupt_pointer, jobject handler, jobject param, jobject status) + (JNIEnv * env, jclass, jlong interrupt_pointer, jobject handler, jobject param) { INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI attachInterruptHandler"; - void ** javaId = (void**)env->GetDirectBufferAddress(interrupt_pointer); - INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << *javaId; - - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - INTERRUPTJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; + INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer; //Store the interrupt callback paramaters InterruptHandlerParam *interruptHandlerParam = new InterruptHandlerParam(); @@ -301,31 +266,31 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_attachInterru INTERRUPTJNI_LOG(logDEBUG) << "InterruptHandlerParam->mid = " << interruptHandlerParam->mid; INTERRUPTJNI_LOG(logDEBUG) << "InterruptHandlerParam->param = " << interruptHandlerParam->param; - *statusPtr = 0; - attachInterruptHandler(*javaId, interruptHandler, interruptHandlerParam, statusPtr); + int32_t status = 0; + attachInterruptHandler((void*)interrupt_pointer, interruptHandler, interruptHandlerParam, &status); - INTERRUPTJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_InterruptJNI * Method: setInterruptUpSourceEdge - * Signature: (Ljava/nio/ByteBuffer;BBLjava/nio/IntBuffer;)V + * Signature: (JZZ)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_InterruptJNI_setInterruptUpSourceEdge - (JNIEnv * env, jclass, jobject interrupt_pointer, jbyte risingEdge, jbyte fallingEdge, jobject status) + (JNIEnv * env, jclass, jlong interrupt_pointer, jboolean risingEdge, jboolean fallingEdge) { INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI setInterruptUpSourceEdge"; - void ** javaId = (void**)env->GetDirectBufferAddress(interrupt_pointer); - INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << *javaId; + INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Ptr = " << (void*)interrupt_pointer; INTERRUPTJNI_LOG(logDEBUG) << "Rising Edge = " << (bool) risingEdge; INTERRUPTJNI_LOG(logDEBUG) << "Falling Edge = " << (bool) fallingEdge; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - INTERRUPTJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; + int32_t status = 0; + setInterruptUpSourceEdge((void*)interrupt_pointer, risingEdge, fallingEdge, &status); - *statusPtr = 0; - setInterruptUpSourceEdge(*javaId, risingEdge, fallingEdge, statusPtr); - - INTERRUPTJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } + +} // extern "C" diff --git a/wpilibj/wpilibJavaJNI/lib/JNIWrapper.cpp b/wpilibj/wpilibJavaJNI/lib/JNIWrapper.cpp index a31bf9a95e..f8d0e95e61 100644 --- a/wpilibj/wpilibJavaJNI/lib/JNIWrapper.cpp +++ b/wpilibj/wpilibJavaJNI/lib/JNIWrapper.cpp @@ -6,36 +6,38 @@ #include "HAL/HAL.hpp" +extern "C" { + /* * Class: edu_wpi_first_wpilibj_hal_JNIWrapper * Method: getPortWithModule - * Signature: (BB)Ljava/nio/ByteBuffer; + * Signature: (BB)J */ -JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_JNIWrapper_getPortWithModule +JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_JNIWrapper_getPortWithModule (JNIEnv * env, jclass, jbyte module, jbyte pin) { //FILE_LOG(logDEBUG) << "Calling JNIWrapper getPortWithModlue"; //FILE_LOG(logDEBUG) << "Module = " << (jint)module; //FILE_LOG(logDEBUG) << "Pin = " << (jint)pin; - void** portPtr = (void**)new unsigned char[4]; - *portPtr = getPortWithModule(module,pin); - //FILE_LOG(logDEBUG) << "Port Ptr = " << *portPtr; - return env->NewDirectByteBuffer( portPtr, 4); + void* port = getPortWithModule(module, pin); + //FILE_LOG(logDEBUG) << "Port Ptr = " << port; + return (jlong)port; } /* * Class: edu_wpi_first_wpilibj_hal_JNIWrapper * Method: getPort - * Signature: (BB)Ljava/nio/ByteBuffer; + * Signature: (BB)J */ -JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_JNIWrapper_getPort +JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_JNIWrapper_getPort (JNIEnv * env, jclass, jbyte pin) { //FILE_LOG(logDEBUG) << "Calling JNIWrapper getPortWithModlue"; //FILE_LOG(logDEBUG) << "Module = " << (jint)module; //FILE_LOG(logDEBUG) << "Pin = " << (jint)pin; - void** portPtr = (void**)new unsigned char[4]; - *portPtr = getPort(pin); - //FILE_LOG(logDEBUG) << "Port Ptr = " << *portPtr; - return env->NewDirectByteBuffer( portPtr, 4); + void* port = getPort(pin); + //FILE_LOG(logDEBUG) << "Port Ptr = " << port; + return (jlong)port; } + +} // extern "C" diff --git a/wpilibj/wpilibJavaJNI/lib/NotifierJNI.cpp b/wpilibj/wpilibJavaJNI/lib/NotifierJNI.cpp index 6f4aebfc8a..3b83eedfb0 100644 --- a/wpilibj/wpilibJavaJNI/lib/NotifierJNI.cpp +++ b/wpilibj/wpilibJavaJNI/lib/NotifierJNI.cpp @@ -5,6 +5,7 @@ #include "Log.hpp" #include "edu_wpi_first_wpilibj_hal_NotifierJNI.h" #include "HAL/Notifier.hpp" +#include "HALUtil.h" // set the logging level TLogLevel notifierJNILogLevel = logWARNING; @@ -13,29 +14,6 @@ TLogLevel notifierJNILogLevel = logWARNING; if (level > notifierJNILogLevel) ; \ else Log().Get(level) -// The jvm object is necessary in order to attach new threads (ie, -// notifierHandler), to the JVM. -static JavaVM *jvm; - -static const int kPtrSize = sizeof(void*); - -// Utility functions which convert back and forth between pointers and Java -// ByteBuffers. - -jint* GetStatusPtr(JNIEnv *env, jobject status) { - return (jint*)env->GetDirectBufferAddress(status); -} - -jobject PtrToByteBuf(JNIEnv *env, void *ptr) { - // Stores a pointer into a byte buffer of the appropriate length. - return env->NewDirectByteBuffer(ptr, kPtrSize); -} - -void *ByteBufToPtr(JNIEnv *env, jobject bytebuf) { - void * ptr = (void*)env->GetDirectBufferAddress(bytebuf); - return ptr; -} - // These two are used to pass information to the notifierHandler without using // up function parameters. // See below for more information. @@ -48,7 +26,7 @@ void notifierHandler(uint32_t mask, void* param) { jobject handler_obj = func_global; jmethodID mid = mid_global; - NOTIFIERJNI_LOG(logDEBUG) << "Calling NOTIFIERJNI interruptHandler"; + NOTIFIERJNI_LOG(logDEBUG) << "Calling NOTIFIERJNI notifierHandler"; //Because this is a callback in a new thread we must attach it to the JVM. JNIEnv *env; @@ -73,37 +51,20 @@ void notifierHandler(uint32_t mask, void* param) { rs = jvm->DetachCurrentThread(); assert (rs == JNI_OK); } - NOTIFIERJNI_LOG(logDEBUG) << "Leaving NOTIFIERJNI interruptHandler"; + NOTIFIERJNI_LOG(logDEBUG) << "Leaving NOTIFIERJNI notifierHandler"; } -/* - * Class: edu_wpi_first_wpilibj_hal_NotifierJNI - * Method: initializeNotifierJVM - * Signature: (Ljava/nio/IntBuffer;)V - */ -JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_NotifierJNI_initializeNotifierJVM - (JNIEnv *env, jclass, jobject status) -{ - //This method should be called once to setup the JVM - NOTIFIERJNI_LOG(logDEBUG) << "Calling NOTIFIERJNI initializeNotifierJVM"; - jint * statusPtr = GetStatusPtr(env, status); - NOTIFIERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - jint rs = env->GetJavaVM(&jvm); - assert (rs == JNI_OK); -} +extern "C" { /* * Class: edu_wpi_first_wpilibj_hal_NotifierJNI * Method: initializeNotifier - * Signature: (Ljava/lang/Runnable;Ljava/nio/IntBuffer;)Ljava/lang/ByteBuffer; + * Signature: (Ljava/lang/Runnable;)J */ -JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_NotifierJNI_initializeNotifier - (JNIEnv *env, jclass, jobject func, jobject status) +JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_NotifierJNI_initializeNotifier + (JNIEnv *env, jclass, jobject func) { NOTIFIERJNI_LOG(logDEBUG) << "Calling NOTIFIERJNI initializeNotifier"; - jint * statusPtr = GetStatusPtr(env, status); - NOTIFIERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; jclass cls = env->GetObjectClass(func); jmethodID mid = env->GetMethodID(cls, "run", "()V"); @@ -120,54 +81,52 @@ JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_NotifierJNI_initializeN func_global = env->NewGlobalRef(func); mid_global = mid; - *statusPtr = 0; - void *notifierPtr = initializeNotifier(notifierHandler, statusPtr); + int32_t status = 0; + void *notifierPtr = initializeNotifier(notifierHandler, &status); NOTIFIERJNI_LOG(logDEBUG) << "Notifier Ptr = " << notifierPtr; - NOTIFIERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + NOTIFIERJNI_LOG(logDEBUG) << "Status = " << status; - return PtrToByteBuf(env, notifierPtr); + CheckStatus(env, status); + return (jlong)notifierPtr; } /* * Class: edu_wpi_first_wpilibj_hal_NotifierJNI * Method: cleanNotifier - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V + * Signature: (J)V */ -JNIEXPORT void JNICALL - Java_edu_wpi_first_wpilibj_hal_NotifierJNI_cleanNotifier(JNIEnv *env, jclass, jobject notifierPtr, jobject status) { +JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_NotifierJNI_cleanNotifier + (JNIEnv *env, jclass, jlong notifierPtr) +{ NOTIFIERJNI_LOG(logDEBUG) << "Calling NOTIFIERJNI cleanNotifier"; - void *ptr = ByteBufToPtr(env, notifierPtr); - NOTIFIERJNI_LOG(logDEBUG) << "Notifier Ptr = " << ptr; + NOTIFIERJNI_LOG(logDEBUG) << "Notifier Ptr = " << (void*)notifierPtr; - jint *statusPtr = GetStatusPtr(env, status); - NOTIFIERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - - *statusPtr = 0; - cleanNotifier(ptr, statusPtr); - NOTIFIERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + cleanNotifier((void*)notifierPtr, &status); + NOTIFIERJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_NotifierJNI * Method: updateNotifierAlarm - * Signature: (Ljava/nio/ByteBuffer;ILjava/nio/IntBuffer;)V + * Signature: (JI)V */ -JNIEXPORT void JNICALL - Java_edu_wpi_first_wpilibj_hal_NotifierJNI_updateNotifierAlarm( - JNIEnv *env, jclass cls, jobject notifierPtr, jint triggerTime, - jobject status) { +JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_NotifierJNI_updateNotifierAlarm + (JNIEnv *env, jclass cls, jlong notifierPtr, jint triggerTime) +{ NOTIFIERJNI_LOG(logDEBUG) << "Calling NOTIFIERJNI updateNotifierAlarm"; - void *ptr = ByteBufToPtr(env, notifierPtr); - NOTIFIERJNI_LOG(logDEBUG) << "Notifier Ptr = " << ptr; + NOTIFIERJNI_LOG(logDEBUG) << "Notifier Ptr = " << (void*)notifierPtr; - jint *statusPtr = GetStatusPtr(env, status); - NOTIFIERJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; NOTIFIERJNI_LOG(logDEBUG) << "triggerTime Ptr = " << &triggerTime; - *statusPtr = 0; - updateNotifierAlarm(ptr, (uint32_t)triggerTime, statusPtr); - NOTIFIERJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + updateNotifierAlarm((void*)notifierPtr, (uint32_t)triggerTime, &status); + NOTIFIERJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } + +} // extern "C" diff --git a/wpilibj/wpilibJavaJNI/lib/PDPJNI.cpp b/wpilibj/wpilibJavaJNI/lib/PDPJNI.cpp index 9db72d1a69..4f1ea2294b 100644 --- a/wpilibj/wpilibJavaJNI/lib/PDPJNI.cpp +++ b/wpilibj/wpilibJavaJNI/lib/PDPJNI.cpp @@ -1,10 +1,13 @@ #include "edu_wpi_first_wpilibj_hal_PDPJNI.h" #include "HAL/PDP.hpp" +#include "HALUtil.h" + +extern "C" { /* * Class: edu_wpi_first_wpilibj_hal_PDPJNI * Method: getPDPTemperature - * Signature: (Ljava/nio/IntBuffer;)D + * Signature: (I)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_initializePDP (JNIEnv *, jclass, jint module) @@ -15,112 +18,112 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_initializePDP /* * Class: edu_wpi_first_wpilibj_hal_PDPJNI * Method: getPDPTemperature - * Signature: (Ljava/nio/IntBuffer;)D + * Signature: (I)D */ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPTemperature - (JNIEnv *env, jclass, jobject status, jint module) + (JNIEnv *env, jclass, jint module) { - jint *status_ptr = (jint *)env->GetDirectBufferAddress(status); - - *status_ptr = 0; - return getPDPTemperature(status_ptr, module); + int32_t status = 0; + double temperature = getPDPTemperature(&status, module); + CheckStatus(env, status, false); + return temperature; } /* * Class: edu_wpi_first_wpilibj_hal_PDPJNI * Method: getPDPVoltage - * Signature: (Ljava/nio/IntBuffer;)D + * Signature: (I)D */ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPVoltage - (JNIEnv *env, jclass, jobject status, jint module) + (JNIEnv *env, jclass, jint module) { - jint *status_ptr = (jint *)env->GetDirectBufferAddress(status); - - *status_ptr = 0; - return getPDPVoltage(status_ptr, module); + int32_t status = 0; + double voltage = getPDPVoltage(&status, module); + CheckStatus(env, status, false); + return voltage; } /* * Class: edu_wpi_first_wpilibj_hal_PDPJNI * Method: getPDPChannelCurrent - * Signature: (BLjava/nio/IntBuffer;)D + * Signature: (BI)D */ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPChannelCurrent - (JNIEnv *env, jclass, jbyte channel, jobject status, jint module) + (JNIEnv *env, jclass, jbyte channel, jint module) { - jint *status_ptr = (jint *)env->GetDirectBufferAddress(status); - - *status_ptr = 0; - return getPDPChannelCurrent(channel, status_ptr, module); + int32_t status = 0; + double current = getPDPChannelCurrent(channel, &status, module); + CheckStatus(env, status, false); + return current; } /* * Class: edu_wpi_first_wpilibj_hal_PDPJNI * Method: getPDPTotalCurrent - * Signature: (BLjava/nio/IntBuffer;)D + * Signature: (I)D */ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPTotalCurrent - (JNIEnv *env, jclass, jobject status, jint module) + (JNIEnv *env, jclass, jint module) { - jint *status_ptr = (jint *)env->GetDirectBufferAddress(status); - - *status_ptr = 0; - return getPDPTotalCurrent(status_ptr, module); + int32_t status = 0; + double current = getPDPTotalCurrent(&status, module); + CheckStatus(env, status, false); + return current; } /* * Class: edu_wpi_first_wpilibj_hal_PDPJNI * Method: getPDPTotalPower - * Signature: (BLjava/nio/IntBuffer;)D + * Signature: (I)D */ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPTotalPower - (JNIEnv *env, jclass, jobject status, jint module) + (JNIEnv *env, jclass, jint module) { - jint *status_ptr = (jint *)env->GetDirectBufferAddress(status); - - *status_ptr = 0; - return getPDPTotalPower(status_ptr, module); + int32_t status = 0; + double power = getPDPTotalPower(&status, module); + CheckStatus(env, status, false); + return power; } /* * Class: edu_wpi_first_wpilibj_hal_PDPJNI * Method: resetPDPTotalEnergy - * Signature: (BLjava/nio/IntBuffer;)D + * Signature: (I)D */ JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_getPDPTotalEnergy - (JNIEnv *env, jclass, jobject status, jint module) + (JNIEnv *env, jclass, jint module) { - jint *status_ptr = (jint *)env->GetDirectBufferAddress(status); - - *status_ptr = 0; - return getPDPTotalEnergy(status_ptr, module); + int32_t status = 0; + double energy = getPDPTotalEnergy(&status, module); + CheckStatus(env, status, false); + return energy; } /* * Class: edu_wpi_first_wpilibj_hal_PDPJNI * Method: resetPDPTotalEnergy - * Signature: (BLjava/nio/IntBuffer;)D + * Signature: (I)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_resetPDPTotalEnergy - (JNIEnv *env, jclass, jobject status, jint module) + (JNIEnv *env, jclass, jint module) { - jint *status_ptr = (jint *)env->GetDirectBufferAddress(status); - - *status_ptr = 0; - resetPDPTotalEnergy(status_ptr, module); + int32_t status = 0; + resetPDPTotalEnergy(&status, module); + CheckStatus(env, status, false); } /* * Class: edu_wpi_first_wpilibj_hal_PDPJNI * Method: clearStickyFaults - * Signature: (BLjava/nio/IntBuffer;)D + * Signature: (I)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_clearPDPStickyFaults - (JNIEnv *env, jclass, jobject status, jint module) + (JNIEnv *env, jclass, jint module) { - jint *status_ptr = (jint *)env->GetDirectBufferAddress(status); - - *status_ptr = 0; - clearPDPStickyFaults(status_ptr, module); + int32_t status = 0; + clearPDPStickyFaults(&status, module); + CheckStatus(env, status, false); } + +} // extern "C" diff --git a/wpilibj/wpilibJavaJNI/lib/PWMJNI.cpp b/wpilibj/wpilibJavaJNI/lib/PWMJNI.cpp index b791ed4dfa..55584ae8b2 100644 --- a/wpilibj/wpilibJavaJNI/lib/PWMJNI.cpp +++ b/wpilibj/wpilibJavaJNI/lib/PWMJNI.cpp @@ -5,6 +5,7 @@ #include "edu_wpi_first_wpilibj_hal_PWMJNI.h" #include "HAL/Digital.hpp" +#include "HALUtil.h" // set the logging level TLogLevel pwmJNILogLevel = logWARNING; @@ -13,203 +14,187 @@ TLogLevel pwmJNILogLevel = logWARNING; if (level > pwmJNILogLevel) ; \ else Log().Get(level) +extern "C" { /* * Class: edu_wpi_first_wpilibj_hal_PWMJNI * Method: allocatePWMChannel - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z + * Signature: (J)Z */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_allocatePWMChannel - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { PWMJNI_LOG(logDEBUG) << "Calling DIOJNI allocatePWMChannel"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - PWMJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - PWMJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - jbyte returnValue = allocatePWMChannel(*javaId, statusPtr); - PWMJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + PWMJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id; + int32_t status = 0; + jboolean returnValue = allocatePWMChannel((void*)id, &status); + PWMJNI_LOG(logDEBUG) << "Status = " << status; PWMJNI_LOG(logDEBUG) << "allocatePWMChannelResult = " << (jint)returnValue; - return returnValue; + CheckStatus(env, status); + return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_PWMJNI * Method: freePWMChannel - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V + * Signature: (J)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_freePWMChannel - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { PWMJNI_LOG(logDEBUG) << "Calling DIOJNI freePWMChannel"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - PWMJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - PWMJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - freePWMChannel(*javaId, statusPtr); - PWMJNI_LOG(logDEBUG) << "Status = " << *statusPtr; - + PWMJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id; + int32_t status = 0; + freePWMChannel((void*)id, &status); + PWMJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_PWMJNI * Method: setPWM - * Signature: (Ljava/nio/ByteBuffer;SLjava/nio/IntBuffer;)V + * Signature: (JS)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_setPWM - (JNIEnv * env, jclass, jobject id, jshort value, jobject status) + (JNIEnv * env, jclass, jlong id, jshort value) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - PWMJNI_LOG(logDEBUG) << "DigitalPort Ptr = " << *javaId; + PWMJNI_LOG(logDEBUG) << "DigitalPort Ptr = " << (void*)id; PWMJNI_LOG(logDEBUG) << "PWM Value = " << value; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - setPWM( *javaId, value, statusPtr ); - PWMJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + setPWM((void*)id, value, &status); + PWMJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_PWMJNI * Method: getPWM - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)S + * Signature: (J)S */ JNIEXPORT jshort JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_getPWM - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - jshort returnValue = getPWM( *javaId, statusPtr ); - PWMJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << (void*)id; + int32_t status = 0; + jshort returnValue = getPWM((void*)id, &status); + PWMJNI_LOG(logDEBUG) << "Status = " << status; PWMJNI_LOG(logDEBUG) << "Value = " << returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_PWMJNI * Method: latchPWMZero - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V + * Signature: (J)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_latchPWMZero - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - latchPWMZero( *javaId, statusPtr ); - PWMJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << (void*)id; + int32_t status = 0; + latchPWMZero((void*)id, &status); + PWMJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_PWMJNI * Method: setPWMPeriodScale - * Signature: (Ljava/nio/ByteBuffer;ILjava/nio/IntBuffer;)V + * Signature: (JI)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_setPWMPeriodScale - (JNIEnv * env, jclass, jobject id, jint value, jobject status ) + (JNIEnv * env, jclass, jlong id, jint value) { - void ** javaId = (void**)env->GetDirectBufferAddress(id); - PWMJNI_LOG(logDEBUG) << "DigitalPort Ptr = " << *javaId; + PWMJNI_LOG(logDEBUG) << "DigitalPort Ptr = " << (void*)id; PWMJNI_LOG(logDEBUG) << "PeriodScale Value = " << value; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - setPWMPeriodScale( *javaId, value, statusPtr ); - PWMJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + setPWMPeriodScale((void*)id, value, &status); + PWMJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_PWMJNI * Method: allocatePWM - * Signature: (Ljava/nio/IntBuffer;)Ljava/nio/ByteBuffer; + * Signature: ()J */ -JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_allocatePWM - (JNIEnv * env, jclass, jobject status) +JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_allocatePWM + (JNIEnv * env, jclass) { PWMJNI_LOG(logDEBUG) << "Calling PWMJNI allocatePWM"; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - PWMJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - void** pwmPtr = (void**)new unsigned char[4]; - *statusPtr = 0; - *pwmPtr = allocatePWM(statusPtr); - PWMJNI_LOG(logDEBUG) << "Status = " << *statusPtr; - PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << *pwmPtr; - return env->NewDirectByteBuffer( pwmPtr, 4); - + int32_t status = 0; + void* pwm = allocatePWM(&status); + PWMJNI_LOG(logDEBUG) << "Status = " << status; + PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << pwm; + CheckStatus(env, status); + return (jlong)pwm; } /* * Class: edu_wpi_first_wpilibj_hal_PWMJNI * Method: freePWM - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V + * Signature: (J)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_freePWM - (JNIEnv * env, jclass, jobject id, jobject status) + (JNIEnv * env, jclass, jlong id) { PWMJNI_LOG(logDEBUG) << "Calling PWMJNI freePWM"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - PWMJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - freePWM(*javaId, statusPtr); - PWMJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << (void*)id; + int32_t status = 0; + freePWM((void*)id, &status); + PWMJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_PWMJNI * Method: setPWMRate - * Signature: (DLjava/nio/IntBuffer;)V + * Signature: (D)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_setPWMRate - (JNIEnv * env, jclass, jdouble value, jobject status) + (JNIEnv * env, jclass, jdouble value) { PWMJNI_LOG(logDEBUG) << "Calling PWMJNI setPWMRate"; PWMJNI_LOG(logDEBUG) << "Rate= " << value; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - PWMJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - setPWMRate(value, statusPtr); - PWMJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + setPWMRate(value, &status); + PWMJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_PWMJNI * Method: setPWMDutyCycle - * Signature: (Ljava/nio/ByteBuffer;DLjava/nio/IntBuffer;)V + * Signature: (JD)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_setPWMDutyCycle - (JNIEnv * env, jclass, jobject id, jdouble value, jobject status) + (JNIEnv * env, jclass, jlong id, jdouble value) { PWMJNI_LOG(logDEBUG) << "Calling PWMJNI setPWMDutyCycle"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << *javaId; + PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << (void*)id; PWMJNI_LOG(logDEBUG) << "DutyCycle= " << value; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - PWMJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - setPWMDutyCycle(*javaId, value, statusPtr); - PWMJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + setPWMDutyCycle((void*)id, value, &status); + PWMJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_PWMJNI * Method: setPWMOutputChannel - * Signature: (Ljava/nio/ByteBuffer;ILjava/nio/IntBuffer;)V + * Signature: (JI)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PWMJNI_setPWMOutputChannel - (JNIEnv * env, jclass, jobject id, jint value, jobject status) + (JNIEnv * env, jclass, jlong id, jint value) { PWMJNI_LOG(logDEBUG) << "Calling PWMJNI setPWMOutputChannel"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << *javaId; + PWMJNI_LOG(logDEBUG) << "PWM Ptr = " << (void*)id; PWMJNI_LOG(logDEBUG) << "Pin= " << value; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - PWMJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - setPWMOutputChannel(*javaId, (uint32_t) value, statusPtr); - PWMJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + setPWMOutputChannel((void*)id, (uint32_t) value, &status); + PWMJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } + +} // extern "C" diff --git a/wpilibj/wpilibJavaJNI/lib/PowerJNI.cpp b/wpilibj/wpilibJavaJNI/lib/PowerJNI.cpp index 90d4a5076d..b3d2fca31a 100644 --- a/wpilibj/wpilibJavaJNI/lib/PowerJNI.cpp +++ b/wpilibj/wpilibJavaJNI/lib/PowerJNI.cpp @@ -1,186 +1,204 @@ #include #include "edu_wpi_first_wpilibj_hal_PowerJNI.h" #include "HAL/Power.hpp" +#include "HALUtil.h" + +extern "C" { /* * Class: edu_wpi_first_wpilibj_hal_PowerJNI * Method: getVinVoltage - * Signature: (Ljava/nio/IntBuffer;)F + * Signature: ()F */ JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getVinVoltage - (JNIEnv * env, jclass, jobject status) + (JNIEnv * env, jclass) { - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - return getVinVoltage(statusPtr); + int32_t status = 0; + float val = getVinVoltage(&status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_PowerJNI * Method: getVinCurrent - * Signature: (Ljava/nio/IntBuffer;)F + * Signature: ()F */ JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getVinCurrent - (JNIEnv * env, jclass, jobject status) + (JNIEnv * env, jclass) { - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - return getVinCurrent(statusPtr); + int32_t status = 0; + float val = getVinCurrent(&status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_PowerJNI * Method: getUserVoltage6V - * Signature: (Ljava/nio/IntBuffer;)F + * Signature: ()F */ JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserVoltage6V - (JNIEnv * env, jclass, jobject status) + (JNIEnv * env, jclass) { - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - return getUserVoltage6V(statusPtr); + int32_t status = 0; + float val = getUserVoltage6V(&status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_PowerJNI * Method: getUserCurrent6V - * Signature: (Ljava/nio/IntBuffer;)F + * Signature: ()F */ JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserCurrent6V - (JNIEnv * env, jclass, jobject status) + (JNIEnv * env, jclass) { - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - return getUserCurrent6V(statusPtr); + int32_t status = 0; + float val = getUserCurrent6V(&status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_PowerJNI * Method: getUserActive6V - * Signature: (Ljava/nio/IntBuffer;)Z + * Signature: ()Z */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserActive6V - (JNIEnv * env, jclass, jobject status) + (JNIEnv * env, jclass) { - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - return getUserActive6V(statusPtr); + int32_t status = 0; + bool val = getUserActive6V(&status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_PowerJNI * Method: getUserCurrentFaults6V - * Signature: (Ljava/nio/IntBuffer;)I + * Signature: ()I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserCurrentFaults6V - (JNIEnv * env, jclass, jobject status) + (JNIEnv * env, jclass) { - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - return getUserCurrentFaults6V(statusPtr); + int32_t status = 0; + int val = getUserCurrentFaults6V(&status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_PowerJNI * Method: getUserVoltage5V - * Signature: (Ljava/nio/IntBuffer;)F + * Signature: ()F */ JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserVoltage5V - (JNIEnv * env, jclass, jobject status) + (JNIEnv * env, jclass) { - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - return getUserVoltage5V(statusPtr); + int32_t status = 0; + float val = getUserVoltage5V(&status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_PowerJNI * Method: getUserCurrent5V - * Signature: (Ljava/nio/IntBuffer;)F + * Signature: ()F */ JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserCurrent5V - (JNIEnv * env, jclass, jobject status) + (JNIEnv * env, jclass) { - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - return getUserCurrent5V(statusPtr); + int32_t status = 0; + float val = getUserCurrent5V(&status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_PowerJNI * Method: getUserActive5V - * Signature: (Ljava/nio/IntBuffer;)Z + * Signature: ()Z */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserActive5V - (JNIEnv * env, jclass, jobject status) + (JNIEnv * env, jclass) { - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - return getUserActive5V(statusPtr); + int32_t status = 0; + bool val = getUserActive5V(&status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_PowerJNI * Method: getUserCurrentFaults5V - * Signature: (Ljava/nio/IntBuffer;)I + * Signature: ()I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserCurrentFaults5V - (JNIEnv * env, jclass, jobject status) + (JNIEnv * env, jclass) { - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - return getUserCurrentFaults5V(statusPtr); + int32_t status = 0; + int val = getUserCurrentFaults5V(&status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_PowerJNI * Method: getUserVoltage3V3 - * Signature: (Ljava/nio/IntBuffer;)F + * Signature: ()F */ JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserVoltage3V3 - (JNIEnv * env, jclass, jobject status) + (JNIEnv * env, jclass) { - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - return getUserVoltage3V3(statusPtr); + int32_t status = 0; + float val = getUserVoltage3V3(&status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_PowerJNI * Method: getUserCurrent3V3 - * Signature: (Ljava/nio/IntBuffer;)F + * Signature: ()F */ JNIEXPORT jfloat JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserCurrent3V3 - (JNIEnv * env, jclass, jobject status) + (JNIEnv * env, jclass) { - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - return getUserCurrent3V3(statusPtr); + int32_t status = 0; + float val = getUserCurrent3V3(&status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_PowerJNI * Method: getUserActive3V3 - * Signature: (Ljava/nio/IntBuffer;)Z + * Signature: ()Z */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserActive3V3 - (JNIEnv * env, jclass, jobject status) + (JNIEnv * env, jclass) { - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - return getUserActive3V3(statusPtr); + int32_t status = 0; + bool val = getUserActive3V3(&status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_PowerJNI * Method: getUserCurrentFaults3V3 - * Signature: (Ljava/nio/IntBuffer;)I + * Signature: ()I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_PowerJNI_getUserCurrentFaults3V3 - (JNIEnv * env, jclass, jobject status) + (JNIEnv * env, jclass) { - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - return getUserCurrentFaults3V3(statusPtr); + int32_t status = 0; + int val = getUserCurrentFaults3V3(&status); + CheckStatus(env, status); + return val; } +} // extern "C" diff --git a/wpilibj/wpilibJavaJNI/lib/RelayJNI.cpp b/wpilibj/wpilibJavaJNI/lib/RelayJNI.cpp index f7f2e2044a..e44be1f50e 100644 --- a/wpilibj/wpilibJavaJNI/lib/RelayJNI.cpp +++ b/wpilibj/wpilibJavaJNI/lib/RelayJNI.cpp @@ -5,6 +5,7 @@ #include "edu_wpi_first_wpilibj_hal_RelayJNI.h" #include "HAL/Digital.hpp" +#include "HALUtil.h" // set the logging level TLogLevel relayJNILogLevel = logWARNING; @@ -13,80 +14,76 @@ TLogLevel relayJNILogLevel = logWARNING; if (level > relayJNILogLevel) ; \ else Log().Get(level) +extern "C" { + /* * Class: edu_wpi_first_wpilibj_hal_RelayJNI * Method: setRelayForward - * Signature: (Ljava/nio/ByteBuffer;BLjava/nio/IntBuffer;)V + * Signature: (JZ)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_RelayJNI_setRelayForward - (JNIEnv * env, jclass, jobject id, jbyte value, jobject status) + (JNIEnv * env, jclass, jlong id, jboolean value) { RELAYJNI_LOG(logDEBUG) << "Calling RELAYJNI setRelayForward"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - RELAYJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId; + RELAYJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id; RELAYJNI_LOG(logDEBUG) << "Flag = " << (jint)value; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - RELAYJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - setRelayForward(*javaId, value, statusPtr); - RELAYJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + setRelayForward((void*)id, value, &status); + RELAYJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_RelayJNI * Method: setRelayReverse - * Signature: (Ljava/nio/ByteBuffer;BLjava/nio/IntBuffer;)V + * Signature: (JZ)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_RelayJNI_setRelayReverse - (JNIEnv * env, jclass, jobject id, jbyte value, jobject status) + (JNIEnv * env, jclass, jlong id, jboolean value) { RELAYJNI_LOG(logDEBUG) << "Calling RELAYJNI setRelayReverse"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - RELAYJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId; + RELAYJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id; RELAYJNI_LOG(logDEBUG) << "Flag = " << (jint)value; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - RELAYJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - setRelayReverse(*javaId, value, statusPtr); - RELAYJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + setRelayReverse((void*)id, value, &status); + RELAYJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_RelayJNI * Method: getRelayForward - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B + * Signature: (J)Z */ -JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_RelayJNI_getRelayForward - (JNIEnv * env, jclass, jobject id, jobject status) +JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_RelayJNI_getRelayForward + (JNIEnv * env, jclass, jlong id) { RELAYJNI_LOG(logDEBUG) << "Calling RELAYJNI getRelayForward"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - RELAYJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - RELAYJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - jbyte returnValue = getRelayForward(*javaId, statusPtr); - RELAYJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + RELAYJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id; + int32_t status = 0; + jboolean returnValue = getRelayForward((void*)id, &status); + RELAYJNI_LOG(logDEBUG) << "Status = " << status; RELAYJNI_LOG(logDEBUG) << "getRelayForwardResult = " << (jint)returnValue; + CheckStatus(env, status); return returnValue; } /* * Class: edu_wpi_first_wpilibj_hal_RelayJNI * Method: getRelayReverse - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B + * Signature: (J)Z */ -JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_RelayJNI_getRelayReverse - (JNIEnv * env, jclass, jobject id, jobject status) +JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_RelayJNI_getRelayReverse + (JNIEnv * env, jclass, jlong id) { RELAYJNI_LOG(logDEBUG) << "Calling RELAYJNI getRelayReverse"; - void ** javaId = (void**)env->GetDirectBufferAddress(id); - RELAYJNI_LOG(logDEBUG) << "Port Ptr = " << *javaId; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - RELAYJNI_LOG(logDEBUG) << "Status Ptr = " << statusPtr; - *statusPtr = 0; - jbyte returnValue = getRelayReverse(*javaId, statusPtr); - RELAYJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + RELAYJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)id; + int32_t status = 0; + jboolean returnValue = getRelayReverse((void*)id, &status); + RELAYJNI_LOG(logDEBUG) << "Status = " << status; RELAYJNI_LOG(logDEBUG) << "getRelayReverseResult = " << (jint)returnValue; + CheckStatus(env, status); return returnValue; } + +} // extern "C" diff --git a/wpilibj/wpilibJavaJNI/lib/SPIJNI.cpp b/wpilibj/wpilibJavaJNI/lib/SPIJNI.cpp index 099967c135..e35d93f90a 100644 --- a/wpilibj/wpilibJavaJNI/lib/SPIJNI.cpp +++ b/wpilibj/wpilibJavaJNI/lib/SPIJNI.cpp @@ -5,7 +5,7 @@ #include "edu_wpi_first_wpilibj_hal_SPIJNI.h" #include "HAL/Digital.hpp" - +#include "HALUtil.h" // set the logging level TLogLevel spiJNILogLevel = logWARNING; @@ -14,20 +14,22 @@ TLogLevel spiJNILogLevel = logWARNING; if (level > spiJNILogLevel) ; \ else Log().Get(level) +extern "C" { + /* * Class: edu_wpi_first_wpilibj_hal_SPIJNI * Method: spiInitialize - * Signature: (BLjava/nio/IntBuffer;)V + * Signature: (B)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiInitialize - (JNIEnv * env, jclass, jbyte port, jobject status) + (JNIEnv * env, jclass, jbyte port) { SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiInitialize"; SPIJNI_LOG(logDEBUG) << "Port = " << (jint) port; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - spiInitialize(port, statusPtr); - SPIJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + spiInitialize(port, &status); + SPIJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* @@ -40,16 +42,15 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiTransaction { SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiTransaction"; SPIJNI_LOG(logDEBUG) << "Port = " << (jint) port; - jbyte * dataToSendPtr = NULL; - jbyte * dataReceivedPtr = NULL; - if(dataToSend != 0){ - dataToSendPtr = (jbyte*)env->GetDirectBufferAddress(dataToSend); + uint8_t* dataToSendPtr = nullptr; + if (dataToSend != 0) { + dataToSendPtr = (uint8_t*)env->GetDirectBufferAddress(dataToSend); } - dataReceivedPtr = (jbyte*)env->GetDirectBufferAddress(dataReceived); + uint8_t* dataReceivedPtr = (uint8_t*)env->GetDirectBufferAddress(dataReceived); SPIJNI_LOG(logDEBUG) << "Size = " << (jint)size; - SPIJNI_LOG(logDEBUG) << "DataToSendPtr = " << (jint*)dataToSendPtr; - SPIJNI_LOG(logDEBUG) << "DataReceivedPtr = " << (jint*) dataReceivedPtr; - jbyte retVal = spiTransaction(port, (uint8_t*)dataToSendPtr, (uint8_t*)dataReceivedPtr, size); + SPIJNI_LOG(logDEBUG) << "DataToSendPtr = " << dataToSendPtr; + SPIJNI_LOG(logDEBUG) << "DataReceivedPtr = " << dataReceivedPtr; + jint retVal = spiTransaction(port, dataToSendPtr, dataReceivedPtr, size); SPIJNI_LOG(logDEBUG) << "ReturnValue = " << (jint)retVal; return retVal; } @@ -64,13 +65,13 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiWrite { SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiWrite"; SPIJNI_LOG(logDEBUG) << "Port = " << (jint) port; - jbyte * dataToSendPtr = NULL; - if(dataToSend != 0){ - dataToSendPtr = (jbyte*)env->GetDirectBufferAddress(dataToSend); + uint8_t* dataToSendPtr = nullptr; + if (dataToSend != 0) { + dataToSendPtr = (uint8_t*)env->GetDirectBufferAddress(dataToSend); } SPIJNI_LOG(logDEBUG) << "Size = " << (jint)size; - SPIJNI_LOG(logDEBUG) << "DataToSendPtr = " << (jint*)dataToSendPtr; - jbyte retVal = spiWrite(port, (uint8_t*)dataToSendPtr, size); + SPIJNI_LOG(logDEBUG) << "DataToSendPtr = " << dataToSendPtr; + jint retVal = spiWrite(port, dataToSendPtr, size); SPIJNI_LOG(logDEBUG) << "ReturnValue = " << (jint)retVal; return retVal; } @@ -86,11 +87,10 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiRead { SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiRead"; SPIJNI_LOG(logDEBUG) << "Port = " << (jint) port; - jbyte * dataReceivedPtr = NULL; - dataReceivedPtr = (jbyte*)env->GetDirectBufferAddress(dataReceived); + uint8_t* dataReceivedPtr = (uint8_t*)env->GetDirectBufferAddress(dataReceived); SPIJNI_LOG(logDEBUG) << "Size = " << (jint)size; - SPIJNI_LOG(logDEBUG) << "DataReceivedPtr = " << (jint*) dataReceivedPtr; - jbyte retVal = spiRead(port, (uint8_t*)dataReceivedPtr, size); + SPIJNI_LOG(logDEBUG) << "DataReceivedPtr = " << dataReceivedPtr; + jint retVal = spiRead(port, (uint8_t*)dataReceivedPtr, size); SPIJNI_LOG(logDEBUG) << "ReturnValue = " << (jint)retVal; return retVal; } @@ -142,32 +142,33 @@ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiSetOpts /* * Class: edu_wpi_first_wpilibj_hal_SPIJNI * Method: spiSetChipSelectActiveHigh - * Signature: (BLjava/nio/IntBuffer;)V + * Signature: (B)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiSetChipSelectActiveHigh - (JNIEnv * env, jclass, jbyte port, jobject status) + (JNIEnv * env, jclass, jbyte port) { SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiSetCSActiveHigh"; SPIJNI_LOG(logDEBUG) << "Port = " << (jint) port; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - spiSetChipSelectActiveHigh(port, statusPtr); - SPIJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + spiSetChipSelectActiveHigh(port, &status); + SPIJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_SPIJNI * Method: spiSetChipSelectActiveLow - * Signature: (BLjava/nio/IntBuffer;)V + * Signature: (B)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiSetChipSelectActiveLow - (JNIEnv * env, jclass, jbyte port, jobject status) + (JNIEnv * env, jclass, jbyte port) { SPIJNI_LOG(logDEBUG) << "Calling SPIJNI spiSetCSActiveLow"; SPIJNI_LOG(logDEBUG) << "Port = " << (jint) port; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - spiSetChipSelectActiveLow(port, statusPtr); - SPIJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + spiSetChipSelectActiveLow(port, &status); + SPIJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } +} // extern "C" diff --git a/wpilibj/wpilibJavaJNI/lib/SerialPortJNI.cpp b/wpilibj/wpilibJavaJNI/lib/SerialPortJNI.cpp index ef8da030b7..0473f36d4b 100644 --- a/wpilibj/wpilibJavaJNI/lib/SerialPortJNI.cpp +++ b/wpilibj/wpilibJavaJNI/lib/SerialPortJNI.cpp @@ -5,6 +5,7 @@ #include "edu_wpi_first_wpilibj_hal_SerialPortJNI.h" #include "HAL/SerialPort.hpp" +#include "HALUtil.h" // set the logging level TLogLevel serialJNILogLevel = logWARNING; @@ -13,294 +14,298 @@ TLogLevel serialJNILogLevel = logWARNING; if (level > serialJNILogLevel) ; \ else Log().Get(level) +extern "C" { + /* * Class: edu_wpi_first_wpilibj_hal_SerialPortJNI * Method: serialInitializePort - * Signature: (BLjava/nio/IntBuffer;)V + * Signature: (B)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialInitializePort - (JNIEnv * env, jclass, jbyte port, jobject status) + (JNIEnv * env, jclass, jbyte port) { SERIALJNI_LOG(logDEBUG) << "Calling Serial Initialize"; SERIALJNI_LOG(logDEBUG) << "Port = " << (jint) port; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - serialInitializePort(port, statusPtr); - SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + serialInitializePort(port, &status); + SERIALJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_SerialPortJNI * Method: serialSetBaudRate - * Signature: (BILjava/nio/IntBuffer;)V + * Signature: (BI)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetBaudRate - (JNIEnv * env, jclass, jbyte port, jint rate, jobject status) + (JNIEnv * env, jclass, jbyte port, jint rate) { SERIALJNI_LOG(logDEBUG) << "Setting Serial Baud Rate"; SERIALJNI_LOG(logDEBUG) << "Baud: " << rate; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - serialSetBaudRate(port, rate, statusPtr); - SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + serialSetBaudRate(port, rate, &status); + SERIALJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_SerialPortJNI * Method: serialSetDataBits - * Signature: (BBLjava/nio/IntBuffer;)V + * Signature: (BB)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetDataBits - (JNIEnv * env, jclass, jbyte port, jbyte bits, jobject status) + (JNIEnv * env, jclass, jbyte port, jbyte bits) { SERIALJNI_LOG(logDEBUG) << "Setting Serial Data Bits"; SERIALJNI_LOG(logDEBUG) << "Data Bits: " << bits; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - serialSetDataBits(port, bits, statusPtr); - SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + serialSetDataBits(port, bits, &status); + SERIALJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_SerialPortJNI * Method: serialSetParity - * Signature: (BBLjava/nio/IntBuffer;)V + * Signature: (BB)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetParity - (JNIEnv * env, jclass, jbyte port, jbyte parity, jobject status) + (JNIEnv * env, jclass, jbyte port, jbyte parity) { SERIALJNI_LOG(logDEBUG) << "Setting Serial Parity"; SERIALJNI_LOG(logDEBUG) << "Parity: " << parity; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - serialSetParity(port, parity, statusPtr); - SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + serialSetParity(port, parity, &status); + SERIALJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_SerialPortJNI * Method: serialSetStopBits - * Signature: (BBLjava/nio/IntBuffer;)V + * Signature: (BB)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetStopBits - (JNIEnv * env, jclass, jbyte port, jbyte bits, jobject status) + (JNIEnv * env, jclass, jbyte port, jbyte bits) { SERIALJNI_LOG(logDEBUG) << "Setting Serial Stop Bits"; SERIALJNI_LOG(logDEBUG) << "Stop Bits: " << bits; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - serialSetStopBits(port, bits, statusPtr); - SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + serialSetStopBits(port, bits, &status); + SERIALJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_SerialPortJNI * Method: serialSetWriteMode - * Signature: (BBLjava/nio/IntBuffer;)V + * Signature: (BB)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetWriteMode - (JNIEnv * env, jclass, jbyte port, jbyte mode, jobject status) + (JNIEnv * env, jclass, jbyte port, jbyte mode) { SERIALJNI_LOG(logDEBUG) << "Setting Serial Write Mode"; SERIALJNI_LOG(logDEBUG) << "Write mode: " << mode; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - serialSetWriteMode(port, mode, statusPtr); - SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + serialSetWriteMode(port, mode, &status); + SERIALJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_SerialPortJNI * Method: serialSetFlowControl - * Signature: (BBLjava/nio/IntBuffer;)V + * Signature: (BB)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetFlowControl - (JNIEnv * env, jclass, jbyte port, jbyte flow, jobject status) + (JNIEnv * env, jclass, jbyte port, jbyte flow) { SERIALJNI_LOG(logDEBUG) << "Setting Serial Flow Control"; SERIALJNI_LOG(logDEBUG) << "Flow Control: " << flow; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - serialSetFlowControl(port, flow, statusPtr); - SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + serialSetFlowControl(port, flow, &status); + SERIALJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_SerialPortJNI * Method: serialSetTimeout - * Signature: (BFLjava/nio/IntBuffer;)V + * Signature: (BF)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetTimeout - (JNIEnv * env, jclass, jbyte port, jfloat timeout, jobject status) + (JNIEnv * env, jclass, jbyte port, jfloat timeout) { SERIALJNI_LOG(logDEBUG) << "Setting Serial Timeout"; SERIALJNI_LOG(logDEBUG) << "Timeout: " << timeout; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - serialSetTimeout(port, timeout, statusPtr); - SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + serialSetTimeout(port, timeout, &status); + SERIALJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_SerialPortJNI * Method: serialEnableTermination - * Signature: (BCLjava/nio/IntBuffer;)V + * Signature: (BC)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialEnableTermination - (JNIEnv * env, jclass, jbyte port, jchar terminator, jobject status) + (JNIEnv * env, jclass, jbyte port, jchar terminator) { SERIALJNI_LOG(logDEBUG) << "Setting Serial Enable Termination"; SERIALJNI_LOG(logDEBUG) << "Terminator: " << terminator; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - serialEnableTermination(port, terminator, statusPtr); - SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + serialEnableTermination(port, terminator, &status); + SERIALJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_SerialPortJNI * Method: serialDisableTermination - * Signature: (BLjava/nio/IntBuffer;)V + * Signature: (B)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialDisableTermination - (JNIEnv * env, jclass, jbyte port, jobject status) + (JNIEnv * env, jclass, jbyte port) { SERIALJNI_LOG(logDEBUG) << "Setting Serial Disable termination"; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - serialDisableTermination(port, statusPtr); - SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + serialDisableTermination(port, &status); + SERIALJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_SerialPortJNI * Method: serialSetReadBufferSize - * Signature: (BILjava/nio/IntBuffer;)V + * Signature: (BI)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetReadBufferSize - (JNIEnv * env, jclass, jbyte port, jint size, jobject status) + (JNIEnv * env, jclass, jbyte port, jint size) { SERIALJNI_LOG(logDEBUG) << "Setting Serial Read Buffer Size"; SERIALJNI_LOG(logDEBUG) << "Size: " << size; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - serialSetReadBufferSize(port, size, statusPtr); - SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + serialSetReadBufferSize(port, size, &status); + SERIALJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_SerialPortJNI * Method: serialSetWriteBufferSize - * Signature: (BILjava/nio/IntBuffer;)V + * Signature: (BI)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialSetWriteBufferSize - (JNIEnv * env, jclass, jbyte port, jint size, jobject status) + (JNIEnv * env, jclass, jbyte port, jint size) { SERIALJNI_LOG(logDEBUG) << "Setting Serial Write Buffer Size"; SERIALJNI_LOG(logDEBUG) << "Size: " << size; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - serialSetWriteBufferSize(port, size, statusPtr); - SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + serialSetWriteBufferSize(port, size, &status); + SERIALJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_SerialPortJNI * Method: serialGetBytesRecieved - * Signature: (BLjava/nio/IntBuffer;)I + * Signature: (B)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialGetBytesRecieved - (JNIEnv * env, jclass, jbyte port, jobject status) + (JNIEnv * env, jclass, jbyte port) { SERIALJNI_LOG(logDEBUG) << "Serial Get Bytes Received"; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - jint retVal = serialGetBytesReceived(port, statusPtr); - SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + jint retVal = serialGetBytesReceived(port, &status); + SERIALJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); return retVal; } /* * Class: edu_wpi_first_wpilibj_hal_SerialPortJNI * Method: serialRead - * Signature: (BLjava/nio/ByteBuffer;ILjava/nio/IntBuffer;)I + * Signature: (BLjava/nio/ByteBuffer;I)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialRead - (JNIEnv * env, jclass, jbyte port, jobject dataReceived, jint size, jobject status) + (JNIEnv * env, jclass, jbyte port, jobject dataReceived, jint size) { SERIALJNI_LOG(logDEBUG) << "Serial Read"; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); jbyte * dataReceivedPtr = NULL; dataReceivedPtr = (jbyte*)env->GetDirectBufferAddress(dataReceived); - *statusPtr = 0; - jint retVal = serialRead(port, (char*)dataReceivedPtr, size, statusPtr); + int32_t status = 0; + jint retVal = serialRead(port, (char*)dataReceivedPtr, size, &status); SERIALJNI_LOG(logDEBUG) << "ReturnValue = " << retVal; - SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + SERIALJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); return retVal; } /* * Class: edu_wpi_first_wpilibj_hal_SerialPortJNI * Method: serialWrite - * Signature: (BLjava/nio/ByteBuffer;ILjava/nio/IntBuffer;)I + * Signature: (BLjava/nio/ByteBuffer;I)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialWrite - (JNIEnv * env, jclass, jbyte port, jobject dataToSend, jint size, jobject status) + (JNIEnv * env, jclass, jbyte port, jobject dataToSend, jint size) { SERIALJNI_LOG(logDEBUG) << "Serial Write"; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); jbyte * dataToSendPtr = NULL; if(dataToSend != 0){ dataToSendPtr = (jbyte*)env->GetDirectBufferAddress(dataToSend); } - *statusPtr = 0; - jint retVal = serialWrite(port, (const char*)dataToSendPtr, size, statusPtr); + int32_t status = 0; + jint retVal = serialWrite(port, (const char*)dataToSendPtr, size, &status); SERIALJNI_LOG(logDEBUG) << "ReturnValue = " << retVal; - SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + SERIALJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); return retVal; } /* * Class: edu_wpi_first_wpilibj_hal_SerialPortJNI * Method: serialFlush - * Signature: (BLjava/nio/IntBuffer;)V + * Signature: (B)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialFlush - (JNIEnv * env, jclass, jbyte port, jobject status) + (JNIEnv * env, jclass, jbyte port) { SERIALJNI_LOG(logDEBUG) << "Serial Flush"; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - serialFlush(port, statusPtr); - SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + serialFlush(port, &status); + SERIALJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_SerialPortJNI * Method: serialClear - * Signature: (BLjava/nio/IntBuffer;)V + * Signature: (B)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialClear - (JNIEnv * env, jclass, jbyte port, jobject status) + (JNIEnv * env, jclass, jbyte port) { SERIALJNI_LOG(logDEBUG) << "Serial Clear"; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - serialClear(port, statusPtr); - SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + serialClear(port, &status); + SERIALJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_SerialPortJNI * Method: serialClose - * Signature: (BLjava/nio/IntBuffer;)V + * Signature: (B)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialClose - (JNIEnv * env, jclass, jbyte port, jobject status) + (JNIEnv * env, jclass, jbyte port) { SERIALJNI_LOG(logDEBUG) << "Serial Close"; - jint * statusPtr = (jint*)env->GetDirectBufferAddress(status); - *statusPtr = 0; - serialClose(port, statusPtr); - SERIALJNI_LOG(logDEBUG) << "Status = " << *statusPtr; + int32_t status = 0; + serialClose(port, &status); + SERIALJNI_LOG(logDEBUG) << "Status = " << status; + CheckStatus(env, status); } + +} // extern "C" diff --git a/wpilibj/wpilibJavaJNI/lib/SolenoidJNI.cpp b/wpilibj/wpilibJavaJNI/lib/SolenoidJNI.cpp index 3cf4883f73..861a3ce5b1 100644 --- a/wpilibj/wpilibJavaJNI/lib/SolenoidJNI.cpp +++ b/wpilibj/wpilibJavaJNI/lib/SolenoidJNI.cpp @@ -4,149 +4,137 @@ #include "edu_wpi_first_wpilibj_hal_SolenoidJNI.h" +#include "HALUtil.h" + TLogLevel solenoidJNILogLevel = logERROR; #define SOLENOIDJNI_LOG(level) \ if (level > solenoidJNILogLevel) ; \ else Log().Get(level) -typedef void *VoidPointer; +extern "C" { /* * Class: edu_wpi_first_wpilibj_hal_SolenoidJNI * Method: initializeSolenoidPort - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V + * Signature: (J)J */ -JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_initializeSolenoidPort - (JNIEnv *env, jclass, jobject port_pointer, jobject status) +JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_initializeSolenoidPort + (JNIEnv *env, jclass, jlong port_pointer) { SOLENOIDJNI_LOG(logDEBUG) << "Calling SolenoidJNI initializeSolenoidPort"; - VoidPointer *port_pointer_pointer = (VoidPointer *)env->GetDirectBufferAddress(port_pointer); - SOLENOIDJNI_LOG(logDEBUG) << "Port Ptr = " << *port_pointer_pointer; - char *aschars = (char *)(*port_pointer_pointer); + SOLENOIDJNI_LOG(logDEBUG) << "Port Ptr = " << (void*)port_pointer; + char *aschars = (char *)port_pointer; SOLENOIDJNI_LOG(logDEBUG) << '\t' << (int)aschars[0] << '\t' << (int)aschars[1] << std::endl; - jint *status_pointer = (jint*)env->GetDirectBufferAddress(status); - SOLENOIDJNI_LOG(logDEBUG) << "Status Ptr = " << status_pointer; + int32_t status = 0; + void* solenoid_port_pointer = initializeSolenoidPort((void*)port_pointer, &status); - VoidPointer *solenoid_port_pointer = new VoidPointer; - *status_pointer = 0; - *solenoid_port_pointer = initializeSolenoidPort(*port_pointer_pointer, status_pointer); + SOLENOIDJNI_LOG(logDEBUG) << "Status = " << status; + SOLENOIDJNI_LOG(logDEBUG) << "Solenoid Port Pointer = " << solenoid_port_pointer; - SOLENOIDJNI_LOG(logDEBUG) << "Status = " << *status_pointer; - SOLENOIDJNI_LOG(logDEBUG) << "Solenoid Port Pointer = " << *solenoid_port_pointer; - - int *asints = (int *)(*solenoid_port_pointer); + int *asints = (int *)solenoid_port_pointer; SOLENOIDJNI_LOG(logDEBUG) << '\t' << asints[0] << '\t' << asints[1] << std::endl; - - return env->NewDirectByteBuffer(solenoid_port_pointer, 4); + + CheckStatus(env, status); + return (jlong)solenoid_port_pointer; } /* * Class: edu_wpi_first_wpilibj_hal_SolenoidJNI * Method: getPortWithModule - * Signature: (BB)Ljava/nio/ByteBuffer; + * Signature: (BB)J */ -JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getPortWithModule +JNIEXPORT jlong JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getPortWithModule (JNIEnv *env, jclass, jbyte module, jbyte channel) { - VoidPointer *port_pointer = new VoidPointer; - *port_pointer = getPortWithModule(module, channel); + void* port_pointer = getPortWithModule(module, channel); - return env->NewDirectByteBuffer(port_pointer, 4); + return (jlong)port_pointer; } /* * Class: edu_wpi_first_wpilibj_hal_SolenoidJNI * Method: setSolenoid - * Signature: (Ljava/nio/ByteBuffer;BLjava/nio/IntBuffer;)V + * Signature: (JZ)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_setSolenoid - (JNIEnv *env, jclass, jobject solenoid_port, jbyte value, jobject status) + (JNIEnv *env, jclass, jlong solenoid_port, jboolean value) { SOLENOIDJNI_LOG(logDEBUG) << "Calling SolenoidJNI SetSolenoid"; - VoidPointer *solenoid_port_pointer = (VoidPointer *)env->GetDirectBufferAddress(solenoid_port); - SOLENOIDJNI_LOG(logDEBUG) << "Solenoid Port Pointer = " << *solenoid_port_pointer; + SOLENOIDJNI_LOG(logDEBUG) << "Solenoid Port Pointer = " << (void*)solenoid_port; - jint *status_pointer = (jint*)env->GetDirectBufferAddress(status); - SOLENOIDJNI_LOG(logDEBUG) << "Status Ptr = " << status_pointer; - - *status_pointer = 0; - setSolenoid(*solenoid_port_pointer, value, status_pointer); + int32_t status = 0; + setSolenoid((void*)solenoid_port, value, &status); + CheckStatus(env, status); } /* * Class: edu_wpi_first_wpilibj_hal_SolenoidJNI * Method: getSolenoid - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B + * Signature: (J)Z */ -JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getSolenoid - (JNIEnv *env, jclass, jobject solenoid_port, jobject status) +JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getSolenoid + (JNIEnv *env, jclass, jlong solenoid_port) { - - VoidPointer *solenoid_port_pointer = (VoidPointer *)env->GetDirectBufferAddress(solenoid_port); - jint *status_pointer = (jint*)env->GetDirectBufferAddress(status); - - *status_pointer = 0; - return getSolenoid(*solenoid_port_pointer, status_pointer); + int32_t status = 0; + jboolean val = getSolenoid((void*)solenoid_port, &status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_SolenoidJNI * Method: getPCMSolenoidBlackList - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)B + * Signature: (J)I */ -JNIEXPORT jbyte JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getPCMSolenoidBlackList - (JNIEnv *env, jclass, jobject solenoid_port, jobject status) +JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getPCMSolenoidBlackList + (JNIEnv *env, jclass, jlong solenoid_port) { - - VoidPointer *solenoid_port_pointer = (VoidPointer *)env->GetDirectBufferAddress(solenoid_port); - jint *status_pointer = (jint*)env->GetDirectBufferAddress(status); - - *status_pointer = 0; - return getPCMSolenoidBlackList(*solenoid_port_pointer, status_pointer); + int32_t status = 0; + jint val = getPCMSolenoidBlackList((void*)solenoid_port, &status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_SolenoidJNI * Method: getPCMSolenoidVoltageStickyFault - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z + * Signature: (J)Z */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getPCMSolenoidVoltageStickyFault - (JNIEnv *env, jclass, jobject solenoid_port, jobject status) + (JNIEnv *env, jclass, jlong solenoid_port) { - VoidPointer *solenoid_port_pointer = (VoidPointer *)env->GetDirectBufferAddress(solenoid_port); - jint *status_pointer = (jint *)env->GetDirectBufferAddress(status); - - *status_pointer = 0; - return getPCMSolenoidVoltageStickyFault(*solenoid_port_pointer, status_pointer); + int32_t status = 0; + bool val = getPCMSolenoidVoltageStickyFault((void*)solenoid_port, &status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_SolenoidJNI * Method: getPCMSolenoidVoltageFault - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Z + * Signature: (J)Z */ JNIEXPORT jboolean JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_getPCMSolenoidVoltageFault - (JNIEnv *env, jclass, jobject solenoid_port, jobject status) + (JNIEnv *env, jclass, jlong solenoid_port) { - VoidPointer *solenoid_port_pointer = (VoidPointer *)env->GetDirectBufferAddress(solenoid_port); - jint *status_pointer = (jint *)env->GetDirectBufferAddress(status); - - *status_pointer = 0; - return getPCMSolenoidVoltageFault(*solenoid_port_pointer, status_pointer); + int32_t status = 0; + bool val = getPCMSolenoidVoltageFault((void*)solenoid_port, &status); + CheckStatus(env, status); + return val; } /* * Class: edu_wpi_first_wpilibj_hal_SolenoidJNI * Method: clearAllPCMStickyFaults - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;)V + * Signature: (J)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_SolenoidJNI_clearAllPCMStickyFaults - (JNIEnv *env, jclass, jobject solenoid_port, jobject status) + (JNIEnv *env, jclass, jlong solenoid_port) { - VoidPointer *solenoid_port_pointer = (VoidPointer *)env->GetDirectBufferAddress(solenoid_port); - jint *status_pointer = (jint *)env->GetDirectBufferAddress(status); - - *status_pointer = 0; - clearAllPCMStickyFaults_sol(*solenoid_port_pointer, status_pointer); + int32_t status = 0; + clearAllPCMStickyFaults_sol((void*)solenoid_port, &status); + CheckStatus(env, status); } + +} // extern "C"