mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
JNI for java
Normal vs recursive mutex HAL delineation
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tInstances;
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInstances;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
|
||||
@@ -6,14 +6,17 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
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 com.sun.jna.Pointer;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
|
||||
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.AnalogJNI;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
@@ -42,7 +45,7 @@ public class AnalogChannel extends SensorBase implements PIDSource,
|
||||
private static final int kAccumulatorSlot = 1;
|
||||
private static Resource channels = new Resource(kAnalogModules
|
||||
* kAnalogChannels);
|
||||
private Pointer m_port;
|
||||
private ByteBuffer m_port;
|
||||
private int m_moduleNumber, m_channel;
|
||||
private static final int[] kAccumulatorChannels = { 1, 2 };
|
||||
private long m_accumulatorOffset;
|
||||
@@ -66,39 +69,38 @@ public class AnalogChannel extends SensorBase implements PIDSource,
|
||||
* The channel number to represent.
|
||||
*/
|
||||
public AnalogChannel(final int moduleNumber, final int channel) {
|
||||
System.out.println("Module Number: " + moduleNumber + " Channel: "
|
||||
+ channel);
|
||||
System.out.println(Thread.currentThread().getStackTrace());
|
||||
m_channel = channel;
|
||||
m_moduleNumber = moduleNumber;
|
||||
if (HALLibrary.checkAnalogModule((byte) moduleNumber) == 0) {
|
||||
if (AnalogJNI.checkAnalogModule((byte)moduleNumber) == 0) {
|
||||
throw new AllocationException("Analog channel " + m_channel
|
||||
+ " on module " + m_moduleNumber
|
||||
+ " cannot be allocated. Module is not present.");
|
||||
}
|
||||
if (HALLibrary.checkAnalogChannel(channel) == 0) {
|
||||
if (AnalogJNI.checkAnalogChannel(channel) == 0) {
|
||||
throw new AllocationException("Analog channel " + m_channel
|
||||
+ " on module " + m_moduleNumber
|
||||
+ " cannot be allocated. Channel is not present.");
|
||||
}
|
||||
try {
|
||||
channels.allocate((moduleNumber - 1) * kAnalogChannels + m_channel
|
||||
channels.allocate((moduleNumber - 1) * kAnalogChannels + channel
|
||||
- 1);
|
||||
} catch (CheckedAllocationException e) {
|
||||
throw new AllocationException("Analog channel " + m_channel
|
||||
+ " on module " + m_moduleNumber + " is already allocated");
|
||||
}
|
||||
|
||||
Pointer port_pointer = HALLibrary.getPortWithModule(
|
||||
ByteBuffer port_pointer = AnalogJNI.getPortWithModule(
|
||||
(byte) moduleNumber, (byte) channel);
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
// XXX: Uncomment when Analog has been fixed
|
||||
m_port = HALLibrary.initializeAnalogPort(port_pointer, status);
|
||||
HALUtil.checkStatus(status);
|
||||
m_port = AnalogJNI.initializeAnalogPort(port_pointer, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
|
||||
LiveWindow.addSensor("Analog", moduleNumber, channel, this);
|
||||
UsageReporting.report(tResourceType.kResourceType_AnalogChannel,
|
||||
channel, m_moduleNumber - 1);
|
||||
channel, moduleNumber - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,9 +131,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
|
||||
* @return A sample straight from this channel on the module.
|
||||
*/
|
||||
public int getValue() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
int value = HALLibrary.getAnalogValue(m_port, status);
|
||||
HALUtil.checkStatus(status);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -147,9 +151,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
|
||||
* @return A sample from the oversample and average engine for this channel.
|
||||
*/
|
||||
public int getAverageValue() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
int value = HALLibrary.getAnalogAverageValue(m_port, status);
|
||||
HALUtil.checkStatus(status);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -161,9 +167,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
|
||||
* @return A scaled sample straight from this channel on the module.
|
||||
*/
|
||||
public double getVoltage() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
double value = Float.intBitsToFloat(HALLibrary.getAnalogVoltageIntHack(m_port, status));
|
||||
HALUtil.checkStatus(status);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -179,9 +187,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
|
||||
* engine for this channel.
|
||||
*/
|
||||
public double getAverageVoltage() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
double value = Float.intBitsToFloat(HALLibrary.getAnalogAverageVoltageIntHack(m_port, status));
|
||||
HALUtil.checkStatus(status);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -195,9 +205,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
|
||||
* @return Least significant bit weight.
|
||||
*/
|
||||
public long getLSBWeight() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
long value = HALLibrary.getAnalogLSBWeight(m_port, status);
|
||||
HALUtil.checkStatus(status);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -211,9 +223,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
|
||||
* @return Offset constant.
|
||||
*/
|
||||
public int getOffset() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
int value = HALLibrary.getAnalogOffset(m_port, status);
|
||||
HALUtil.checkStatus(status);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -244,9 +258,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
|
||||
* The number of averaging bits.
|
||||
*/
|
||||
public void setAverageBits(final int bits) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setAnalogAverageBits(m_port, bits, status);
|
||||
HALUtil.checkStatus(status);
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -257,9 +273,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
|
||||
* @return The number of averaging bits.
|
||||
*/
|
||||
public int getAverageBits() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
int value = HALLibrary.getAnalogAverageBits(m_port, status);
|
||||
HALUtil.checkStatus(status);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -272,9 +290,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
|
||||
* The number of oversample bits.
|
||||
*/
|
||||
public void setOversampleBits(final int bits) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setAnalogOversampleBits(m_port, bits, status);
|
||||
HALUtil.checkStatus(status);
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -285,9 +305,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
|
||||
* @return The number of oversample bits.
|
||||
*/
|
||||
public int getOversampleBits() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
int value = HALLibrary.getAnalogOversampleBits(m_port, status);
|
||||
HALUtil.checkStatus(status);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -303,9 +325,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
|
||||
+ kAccumulatorChannels[1]);
|
||||
}
|
||||
m_accumulatorOffset = 0;
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.initAccumulator(m_port, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
AnalogJNI.initAccumulator(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -324,9 +348,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
|
||||
* Resets the accumulator to the initial value.
|
||||
*/
|
||||
public void resetAccumulator() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.resetAccumulator(m_port, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
AnalogJNI.resetAccumulator(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -342,18 +368,22 @@ public class AnalogChannel extends SensorBase implements PIDSource,
|
||||
* affect the size of the value for this field.
|
||||
*/
|
||||
public void setAccumulatorCenter(int center) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setAccumulatorCenter(m_port, center, status);
|
||||
HALUtil.checkStatus(status);
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the accumulator's deadband.
|
||||
*/
|
||||
public void setAccumulatorDeadband(int deadband) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setAccumulatorDeadband(m_port, deadband, status);
|
||||
HALUtil.checkStatus(status);
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -365,9 +395,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
|
||||
* @return The 64-bit value accumulated since the last Reset().
|
||||
*/
|
||||
public long getAccumulatorValue() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
long value = HALLibrary.getAccumulatorValue(m_port, status);
|
||||
HALUtil.checkStatus(status);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -380,9 +412,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
|
||||
* @return The number of times samples from the channel were accumulated.
|
||||
*/
|
||||
public long getAccumulatorCount() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
long value = HALLibrary.getAccumulatorCount(m_port, status);
|
||||
HALUtil.checkStatus(status);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -405,13 +439,19 @@ public class AnalogChannel extends SensorBase implements PIDSource,
|
||||
+ " on module " + m_moduleNumber
|
||||
+ " is not an accumulator channel.");
|
||||
}
|
||||
LongBuffer value = LongBuffer.allocate(1);
|
||||
IntBuffer count = IntBuffer.allocate(1);
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.getAccumulatorOutput(m_port, value, count, status);
|
||||
result.value = value.get(0) + m_accumulatorOffset;
|
||||
result.count = count.get(0);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer value = ByteBuffer.allocateDirect(8);
|
||||
// set the byte order
|
||||
value.order(ByteOrder.LITTLE_ENDIAN);
|
||||
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());
|
||||
result.value = value.asLongBuffer().get(0) + m_accumulatorOffset;
|
||||
result.count = count.asIntBuffer().get(0);
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -434,9 +474,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
|
||||
public void setSampleRate(final double samplesPerSecond) {
|
||||
// TODO: This will change when variable size scan lists are implemented.
|
||||
// TODO: Need float comparison with epsilon.
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setAnalogSampleRate((float) samplesPerSecond, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
AnalogJNI.setAnalogSampleRate((float) samplesPerSecond, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,12 +7,11 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tModuleType;
|
||||
import edu.wpi.first.wpilibj.hal.HALLibrary;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tModuleType;
|
||||
import edu.wpi.first.wpilibj.hal.AnalogJNI;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
|
||||
/**
|
||||
@@ -40,7 +39,7 @@ public class AnalogModule extends Module {
|
||||
* The default sample rate
|
||||
*/
|
||||
public static final double kDefaultSampleRate = 50000.0;
|
||||
private Pointer[] m_ports;
|
||||
private ByteBuffer[] m_ports;
|
||||
|
||||
/**
|
||||
* Get an instance of an Analog Module.
|
||||
@@ -70,13 +69,15 @@ public class AnalogModule extends Module {
|
||||
protected AnalogModule(final int moduleNumber) {
|
||||
super(tModuleType.kModuleType_Analog, moduleNumber);
|
||||
|
||||
m_ports = new Pointer[8];
|
||||
m_ports = new ByteBuffer[8];
|
||||
for (int i = 0; i < SensorBase.kAnalogChannels; i++) {
|
||||
Pointer port_pointer = HALLibrary.getPortWithModule((byte) moduleNumber, (byte) (i+1));
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
ByteBuffer port_pointer = AnalogJNI.getPortWithModule((byte) moduleNumber, (byte) (i+1));
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
// XXX: Uncomment when analogchannel has been fixed
|
||||
// m_ports[i] = HALLibrary.initializeAnalogPort(port_pointer, status);
|
||||
HALUtil.checkStatus(status);
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,9 +92,11 @@ public class AnalogModule extends Module {
|
||||
public void setSampleRate(final double samplesPerSecond) {
|
||||
// TODO: This will change when variable size scan lists are implemented.
|
||||
// TODO: Need float comparison with epsilon.
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setAnalogSampleRateWithModule((byte) m_moduleNumber, (float) samplesPerSecond, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
AnalogJNI.setAnalogSampleRateWithModule((byte) m_moduleNumber, (float) samplesPerSecond, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,9 +108,11 @@ public class AnalogModule extends Module {
|
||||
* @return Sample rate.
|
||||
*/
|
||||
public double getSampleRate() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
double value = HALLibrary.getAnalogSampleRateWithModule((byte) m_moduleNumber, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
double value = AnalogJNI.getAnalogSampleRateWithModule((byte) m_moduleNumber, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -123,9 +128,11 @@ public class AnalogModule extends Module {
|
||||
* Number of bits to average.
|
||||
*/
|
||||
public void setAverageBits(final int channel, final int bits) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setAnalogAverageBits(m_ports[channel], bits, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
AnalogJNI.setAnalogAverageBits(m_ports[channel], bits, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,9 +146,11 @@ public class AnalogModule extends Module {
|
||||
* @return Bits to average.
|
||||
*/
|
||||
public int getAverageBits(final int channel) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
int value = HALLibrary.getAnalogAverageBits(m_ports[channel], status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int value = AnalogJNI.getAnalogAverageBits(m_ports[channel], status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -156,9 +165,11 @@ public class AnalogModule extends Module {
|
||||
* @param bits Number of bits to oversample.
|
||||
*/
|
||||
public void setOversampleBits(final int channel, final int bits) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setAnalogOversampleBits(m_ports[channel], bits, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
AnalogJNI.setAnalogOversampleBits(m_ports[channel], bits, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -172,9 +183,11 @@ public class AnalogModule extends Module {
|
||||
* @return Bits to oversample.
|
||||
*/
|
||||
public int getOversampleBits(final int channel) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
int value = HALLibrary.getAnalogOversampleBits(m_ports[channel], status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int value = AnalogJNI.getAnalogOversampleBits(m_ports[channel], status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -187,9 +200,11 @@ public class AnalogModule extends Module {
|
||||
* @return Raw value.
|
||||
*/
|
||||
public int getValue(final int channel) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
int value = HALLibrary.getAnalogValue(m_ports[channel], status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int value = AnalogJNI.getAnalogValue(m_ports[channel], status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -200,9 +215,11 @@ public class AnalogModule extends Module {
|
||||
* @return The averaged and oversampled raw value.
|
||||
*/
|
||||
public int getAverageValue(final int channel) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
int value = HALLibrary.getAnalogAverageValue(m_ports[channel], status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int value = AnalogJNI.getAnalogAverageValue(m_ports[channel], status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -222,9 +239,11 @@ public class AnalogModule extends Module {
|
||||
*/
|
||||
public int voltsToValue(final int channel, final double voltage) {
|
||||
// wpi_assert(voltage >= -10.0 && voltage <= 10.0);
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
int value = HALLibrary.getAnalogVoltsToValue(m_ports[channel], (float) voltage, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocate(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int value = AnalogJNI.getAnalogVoltsToValue(m_ports[channel], (float) voltage, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -237,9 +256,11 @@ public class AnalogModule extends Module {
|
||||
* @return The scaled voltage from the channel.
|
||||
*/
|
||||
public double getVoltage(final int channel) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
double value = HALLibrary.getAnalogVoltage(m_ports[channel], status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
double value = AnalogJNI.getAnalogVoltage(m_ports[channel], status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -252,9 +273,11 @@ public class AnalogModule extends Module {
|
||||
* @return The scaled averaged and oversampled voltage from the channel.
|
||||
*/
|
||||
public double getAverageVoltage(final int channel) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
double value = HALLibrary.getAnalogAverageVoltage(m_ports[channel], status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
double value = AnalogJNI.getAnalogAverageVoltage(m_ports[channel], status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -266,9 +289,11 @@ public class AnalogModule extends Module {
|
||||
*/
|
||||
public long getLSBWeight(final int channel) {
|
||||
// TODO: add scaling to make this worth while.
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
long value = HALLibrary.getAnalogLSBWeight(m_ports[channel], status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
long value = AnalogJNI.getAnalogLSBWeight(m_ports[channel], status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -281,9 +306,11 @@ public class AnalogModule extends Module {
|
||||
public int getOffset(final int channel) {
|
||||
// TODO: add scaling to make this worth while.
|
||||
// TODO: actually use this function.
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
int value = HALLibrary.getAnalogOffset(m_ports[channel], status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int value = AnalogJNI.getAnalogOffset(m_ports[channel], status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,13 @@
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
//import com.sun.jna.Pointer;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
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.AnalogJNI;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.parsing.IInputOutput;
|
||||
import edu.wpi.first.wpilibj.util.BoundaryException;
|
||||
@@ -45,7 +46,7 @@ public class AnalogTrigger implements IInputOutput {
|
||||
/**
|
||||
* Where the analog trigger is attached
|
||||
*/
|
||||
protected Pointer m_port;
|
||||
protected ByteBuffer m_port;
|
||||
protected int m_index;
|
||||
|
||||
/**
|
||||
@@ -59,7 +60,7 @@ public class AnalogTrigger implements IInputOutput {
|
||||
* the port to use for the analog trigger
|
||||
*/
|
||||
protected void initTrigger(final int moduleNumber, final int channel) {
|
||||
Pointer port_pointer = HALLibrary.getPortWithModule(
|
||||
ByteBuffer port_pointer = AnalogJNI.getPortWithModule(
|
||||
(byte) moduleNumber, (byte) channel);
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
IntBuffer index = IntBuffer.allocate(1);
|
||||
@@ -114,7 +115,7 @@ public class AnalogTrigger implements IInputOutput {
|
||||
*/
|
||||
public void free() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.cleanAnalogTrigger(m_port, status);
|
||||
AnalogJNI.cleanAnalogTrigger(m_port, status);
|
||||
HALUtil.checkStatus(status);
|
||||
m_port = null;
|
||||
}
|
||||
@@ -134,7 +135,7 @@ public class AnalogTrigger implements IInputOutput {
|
||||
throw new BoundaryException("Lower bound is greater than upper");
|
||||
}
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setAnalogTriggerLimitsRaw(m_port, lower, upper, status);
|
||||
AnalogJNI.setAnalogTriggerLimitsRaw(m_port, lower, upper, status);
|
||||
HALUtil.checkStatus(status);
|
||||
}
|
||||
|
||||
@@ -155,7 +156,7 @@ public class AnalogTrigger implements IInputOutput {
|
||||
// TODO: This depends on the averaged setting. Only raw values will work
|
||||
// as is.
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setAnalogTriggerLimitsVoltage(m_port, (float) lower,
|
||||
AnalogJNI.setAnalogTriggerLimitsVoltage(m_port, (float) lower,
|
||||
(float) upper, status);
|
||||
HALUtil.checkStatus(status);
|
||||
}
|
||||
@@ -170,7 +171,7 @@ public class AnalogTrigger implements IInputOutput {
|
||||
*/
|
||||
public void setAveraged(boolean useAveragedValue) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setAnalogTriggerAveraged(m_port,
|
||||
AnalogJNI.setAnalogTriggerAveraged(m_port,
|
||||
(byte) (useAveragedValue ? 1 : 0), status);
|
||||
HALUtil.checkStatus(status);
|
||||
}
|
||||
@@ -186,7 +187,7 @@ public class AnalogTrigger implements IInputOutput {
|
||||
*/
|
||||
public void setFiltered(boolean useFilteredValue) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setAnalogTriggerFiltered(m_port,
|
||||
AnalogJNI.setAnalogTriggerFiltered(m_port,
|
||||
(byte) (useFilteredValue ? 1 : 0), status);
|
||||
HALUtil.checkStatus(status);
|
||||
}
|
||||
@@ -209,7 +210,7 @@ public class AnalogTrigger implements IInputOutput {
|
||||
*/
|
||||
public boolean getInWindow() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
byte value = HALLibrary.getAnalogTriggerInWindow(m_port, status);
|
||||
byte value = AnalogJNI.getAnalogTriggerInWindow(m_port, status);
|
||||
HALUtil.checkStatus(status);
|
||||
return value != 0;
|
||||
}
|
||||
@@ -223,7 +224,7 @@ public class AnalogTrigger implements IInputOutput {
|
||||
*/
|
||||
public boolean getTriggerState() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
byte value = HALLibrary.getAnalogTriggerTriggerState(m_port, status);
|
||||
byte value = AnalogJNI.getAnalogTriggerTriggerState(m_port, status);
|
||||
HALUtil.checkStatus(status);
|
||||
return value != 0;
|
||||
}
|
||||
|
||||
@@ -8,10 +8,11 @@
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
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.AnalogJNI;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.parsing.IInputOutput;
|
||||
|
||||
@@ -99,7 +100,7 @@ public class AnalogTriggerOutput extends DigitalSource implements IInputOutput {
|
||||
*/
|
||||
public boolean get() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
byte value = HALLibrary.getAnalogTriggerOutput(m_trigger.m_port,
|
||||
byte value = AnalogJNI.getAnalogTriggerOutput(m_trigger.m_port,
|
||||
m_outputType, status);
|
||||
HALUtil.checkStatus(status);
|
||||
return value != 0;
|
||||
|
||||
@@ -8,12 +8,14 @@
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import edu.wpi.first.wpilibj.can.CANExceptionFactory;
|
||||
import edu.wpi.first.wpilibj.can.CANJaguarVersionException;
|
||||
import edu.wpi.first.wpilibj.can.CANLibrary;
|
||||
import edu.wpi.first.wpilibj.can.CANJNI;
|
||||
import edu.wpi.first.wpilibj.can.CANTimeoutException;
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
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;
|
||||
@@ -354,29 +356,29 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
|
||||
switch (m_controlMode.value) {
|
||||
case ControlMode.kPercentVbus_val:
|
||||
messageID = CANLibrary.LM_API_VOLT_T_SET;
|
||||
messageID = CANJNI.LM_API_VOLT_T_SET;
|
||||
if (outputValue > 1.0) outputValue = 1.0;
|
||||
if (outputValue < -1.0) outputValue = -1.0;
|
||||
packPercentage(dataBuffer, outputValue);
|
||||
dataSize = 2;
|
||||
break;
|
||||
case ControlMode.kSpeed_val: {
|
||||
messageID = CANLibrary.LM_API_SPD_T_SET;
|
||||
messageID = CANJNI.LM_API_SPD_T_SET;
|
||||
dataSize = packFXP16_16(dataBuffer, outputValue);
|
||||
}
|
||||
break;
|
||||
case ControlMode.kPosition_val: {
|
||||
messageID = CANLibrary.LM_API_POS_T_SET;
|
||||
messageID = CANJNI.LM_API_POS_T_SET;
|
||||
dataSize = packFXP16_16(dataBuffer, outputValue);
|
||||
}
|
||||
break;
|
||||
case ControlMode.kCurrent_val: {
|
||||
messageID = CANLibrary.LM_API_ICTRL_T_SET;
|
||||
messageID = CANJNI.LM_API_ICTRL_T_SET;
|
||||
dataSize = packFXP8_8(dataBuffer, outputValue);
|
||||
}
|
||||
break;
|
||||
case ControlMode.kVoltage_val: {
|
||||
messageID = CANLibrary.LM_API_VCOMP_T_SET;
|
||||
messageID = CANJNI.LM_API_VCOMP_T_SET;
|
||||
dataSize = packFXP8_8(dataBuffer, outputValue);
|
||||
}
|
||||
break;
|
||||
@@ -424,31 +426,31 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
|
||||
switch (m_controlMode.value) {
|
||||
case ControlMode.kPercentVbus_val:
|
||||
dataSize = getTransaction(CANLibrary.LM_API_VOLT_SET, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_VOLT_SET, dataBuffer);
|
||||
if (dataSize == 2) {
|
||||
return unpackPercentage(dataBuffer);
|
||||
}
|
||||
break;
|
||||
case ControlMode.kSpeed_val:
|
||||
dataSize = getTransaction(CANLibrary.LM_API_SPD_SET, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_SPD_SET, dataBuffer);
|
||||
if (dataSize == 4) {
|
||||
return unpackFXP16_16(dataBuffer);
|
||||
}
|
||||
break;
|
||||
case ControlMode.kPosition_val:
|
||||
dataSize = getTransaction(CANLibrary.LM_API_POS_SET, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_POS_SET, dataBuffer);
|
||||
if (dataSize == 4) {
|
||||
return unpackFXP16_16(dataBuffer);
|
||||
}
|
||||
break;
|
||||
case ControlMode.kCurrent_val:
|
||||
dataSize = getTransaction(CANLibrary.LM_API_ICTRL_SET, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_ICTRL_SET, dataBuffer);
|
||||
if (dataSize == 2) {
|
||||
return unpackFXP8_8(dataBuffer);
|
||||
}
|
||||
break;
|
||||
case ControlMode.kVoltage_val:
|
||||
dataSize = getTransaction(CANLibrary.LM_API_VCOMP_SET, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_VCOMP_SET, dataBuffer);
|
||||
if (dataSize == 2) {
|
||||
return unpackFXP8_8(dataBuffer);
|
||||
}
|
||||
@@ -548,7 +550,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
long unpackINT32(byte[] buffer) {
|
||||
return unpack32(buffer,0);
|
||||
}
|
||||
private static final byte[] sendTrustedDataBuffer = new byte[kMaxMessageDataSize];
|
||||
private static final ByteBuffer sendTrustedDataBuffer = ByteBuffer.allocateDirect(kMaxMessageDataSize);
|
||||
|
||||
/**
|
||||
* Send a message on the CAN bus through the CAN driver in FRC_NetworkCommunication
|
||||
@@ -562,33 +564,58 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
*/
|
||||
protected static void sendMessage(int messageID, byte[] data, int dataSize) throws CANTimeoutException {
|
||||
final int[] kTrustedMessages = {
|
||||
CANLibrary.LM_API_VOLT_T_EN, CANLibrary.LM_API_VOLT_T_SET,
|
||||
CANLibrary.LM_API_SPD_T_EN, CANLibrary.LM_API_SPD_T_SET,
|
||||
CANLibrary.LM_API_VCOMP_T_EN, CANLibrary.LM_API_VCOMP_T_SET,
|
||||
CANLibrary.LM_API_POS_T_EN, CANLibrary.LM_API_POS_T_SET,
|
||||
CANLibrary.LM_API_ICTRL_T_EN, CANLibrary.LM_API_ICTRL_T_SET
|
||||
CANJNI.LM_API_VOLT_T_EN, CANJNI.LM_API_VOLT_T_SET,
|
||||
CANJNI.LM_API_SPD_T_EN, CANJNI.LM_API_SPD_T_SET,
|
||||
CANJNI.LM_API_VCOMP_T_EN, CANJNI.LM_API_VCOMP_T_SET,
|
||||
CANJNI.LM_API_POS_T_EN, CANJNI.LM_API_POS_T_SET,
|
||||
CANJNI.LM_API_ICTRL_T_EN, CANJNI.LM_API_ICTRL_T_SET
|
||||
};
|
||||
|
||||
byte i;
|
||||
for (i = 0; i < kTrustedMessages.length; i++) {
|
||||
if ((kFullMessageIDMask & messageID) == kTrustedMessages[i]) {
|
||||
sendTrustedDataBuffer[0] = 0;
|
||||
sendTrustedDataBuffer[1] = 0;
|
||||
if ((kFullMessageIDMask & messageID) == kTrustedMessages[i])
|
||||
{
|
||||
// Make sure the data will still fit after adjusting for the token.
|
||||
if (dataSize > kMaxMessageDataSize - 2) {
|
||||
throw new RuntimeException("CAN message has too much data.");
|
||||
}
|
||||
|
||||
ByteBuffer trustedBuffer = ByteBuffer.allocateDirect(dataSize+2);
|
||||
trustedBuffer.put(0, (byte)0);
|
||||
trustedBuffer.put(1, (byte)0);
|
||||
|
||||
byte j;
|
||||
for (j = 0; j < dataSize; j++) {
|
||||
sendTrustedDataBuffer[j + 2] = data[j];
|
||||
trustedBuffer.put(j+2, data[j]);
|
||||
}
|
||||
|
||||
CANLibrary.FRC_NetworkCommunication_JaguarCANDriver_sendMessage(messageID, sendTrustedDataBuffer, (byte) sendTrustedDataBuffer.length, IntBuffer.wrap(new int[]{dataSize + 2}));
|
||||
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
status.asIntBuffer().put(0,dataSize+2);
|
||||
|
||||
|
||||
CANJNI.FRCNetworkCommunicationJaguarCANDriverSendMessage(messageID, trustedBuffer, status.asIntBuffer());
|
||||
return;
|
||||
}
|
||||
}
|
||||
CANLibrary.FRC_NetworkCommunication_JaguarCANDriver_sendMessage(messageID, data, (byte) data.length, IntBuffer.wrap(new int[]{dataSize}));
|
||||
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
status.asIntBuffer().put(0,dataSize);
|
||||
|
||||
ByteBuffer dataBuffer = null;
|
||||
if( dataSize > 0)
|
||||
{
|
||||
dataBuffer = ByteBuffer.allocateDirect(dataSize);
|
||||
dataBuffer.put(data);
|
||||
}
|
||||
|
||||
CANJNI.FRCNetworkCommunicationJaguarCANDriverSendMessage(messageID, dataBuffer, status.asIntBuffer());
|
||||
|
||||
CANExceptionFactory.checkStatus(status.asIntBuffer().get(0), messageID);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -599,17 +626,36 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
* @param timeout Specify how long to wait for a message (in seconds)
|
||||
*/
|
||||
protected static byte receiveMessage(int messageID, byte[] data, double timeout) throws CANTimeoutException {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
ByteBuffer dataSize = ByteBuffer.wrap(new byte[]{(byte) data.length});
|
||||
CANLibrary.FRC_NetworkCommunication_JaguarCANDriver_receiveMessage(
|
||||
IntBuffer.wrap(new int[]{messageID}), ByteBuffer.wrap(data),
|
||||
dataSize, (int) timeout, status);
|
||||
HALUtil.checkStatus(status);
|
||||
return dataSize.get();
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
ByteBuffer messageIDBuffer = ByteBuffer.allocateDirect(4);
|
||||
messageIDBuffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
messageIDBuffer.asIntBuffer().put(0,messageID);
|
||||
|
||||
ByteBuffer dataBuffer = CANJNI.FRCNetworkCommunicationJaguarCANDriverReceiveMessage(
|
||||
messageIDBuffer.asIntBuffer(), (int) (timeout*1000), status.asIntBuffer());
|
||||
|
||||
CANExceptionFactory.checkStatus(status.asIntBuffer().get(0), messageID);
|
||||
|
||||
byte returnValue = 0;
|
||||
|
||||
if( dataBuffer != null )
|
||||
{
|
||||
returnValue = (byte)dataBuffer.capacity();
|
||||
for(int index = 0; index < returnValue; index++)
|
||||
{
|
||||
data[index] = dataBuffer.get(index);
|
||||
}
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
protected static byte receiveMessage(int messageID, byte[] data) throws CANTimeoutException {
|
||||
return receiveMessage(messageID, data, 0.01);
|
||||
//return receiveMessage(messageID, data, 0.01);
|
||||
return receiveMessage(messageID, data, 0.1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -623,7 +669,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
* @param dataSize Specify how much of the data in "data" to send
|
||||
*/
|
||||
protected byte setTransaction(int messageID, byte[] data, byte dataSize) throws CANTimeoutException {
|
||||
int ackMessageID = CANLibrary.LM_API_ACK | m_deviceNumber;
|
||||
int ackMessageID = CANJNI.LM_API_ACK | m_deviceNumber;
|
||||
|
||||
// Make sure we don't have more than one transaction with the same Jaguar outstanding.
|
||||
synchronized (m_transactionMutex) {
|
||||
@@ -674,7 +720,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
byte[] dataBuffer = new byte[8];
|
||||
|
||||
dataBuffer[0] = reference.value;
|
||||
setTransaction(CANLibrary.LM_API_SPD_REF, dataBuffer, (byte) 1);
|
||||
setTransaction(CANJNI.LM_API_SPD_REF, dataBuffer, (byte) 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -686,7 +732,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
byte[] dataBuffer = new byte[8];
|
||||
byte dataSize = 0;
|
||||
|
||||
dataSize = getTransaction(CANLibrary.LM_API_SPD_REF, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_SPD_REF, dataBuffer);
|
||||
if (dataSize == 1) {
|
||||
switch (dataBuffer[0]) {
|
||||
case SpeedReference.kEncoder_val:
|
||||
@@ -714,7 +760,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
byte[] dataBuffer = new byte[8];
|
||||
|
||||
dataBuffer[0] = reference.value;
|
||||
setTransaction(CANLibrary.LM_API_POS_REF, dataBuffer, (byte) 1);
|
||||
setTransaction(CANJNI.LM_API_POS_REF, dataBuffer, (byte) 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -726,7 +772,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
byte[] dataBuffer = new byte[8];
|
||||
byte dataSize = 0;
|
||||
|
||||
dataSize = getTransaction(CANLibrary.LM_API_POS_REF, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_POS_REF, dataBuffer);
|
||||
if (dataSize == 1) {
|
||||
switch (dataBuffer[0]) {
|
||||
case PositionReference.kPotentiometer_val:
|
||||
@@ -758,27 +804,27 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
break;
|
||||
case ControlMode.kSpeed_val:
|
||||
dataSize = packFXP16_16(dataBuffer, p);
|
||||
setTransaction(CANLibrary.LM_API_SPD_PC, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_SPD_PC, dataBuffer, dataSize);
|
||||
dataSize = packFXP16_16(dataBuffer, i);
|
||||
setTransaction(CANLibrary.LM_API_SPD_IC, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_SPD_IC, dataBuffer, dataSize);
|
||||
dataSize = packFXP16_16(dataBuffer, d);
|
||||
setTransaction(CANLibrary.LM_API_SPD_DC, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_SPD_DC, dataBuffer, dataSize);
|
||||
break;
|
||||
case ControlMode.kPosition_val:
|
||||
dataSize = packFXP16_16(dataBuffer, p);
|
||||
setTransaction(CANLibrary.LM_API_POS_PC, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_POS_PC, dataBuffer, dataSize);
|
||||
dataSize = packFXP16_16(dataBuffer, i);
|
||||
setTransaction(CANLibrary.LM_API_POS_IC, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_POS_IC, dataBuffer, dataSize);
|
||||
dataSize = packFXP16_16(dataBuffer, d);
|
||||
setTransaction(CANLibrary.LM_API_POS_DC, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_POS_DC, dataBuffer, dataSize);
|
||||
break;
|
||||
case ControlMode.kCurrent_val:
|
||||
dataSize = packFXP16_16(dataBuffer, p);
|
||||
setTransaction(CANLibrary.LM_API_ICTRL_PC, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_ICTRL_PC, dataBuffer, dataSize);
|
||||
dataSize = packFXP16_16(dataBuffer, i);
|
||||
setTransaction(CANLibrary.LM_API_ICTRL_IC, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_ICTRL_IC, dataBuffer, dataSize);
|
||||
dataSize = packFXP16_16(dataBuffer, d);
|
||||
setTransaction(CANLibrary.LM_API_ICTRL_DC, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_ICTRL_DC, dataBuffer, dataSize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -798,19 +844,19 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
// TODO: Error, Not Valid
|
||||
break;
|
||||
case ControlMode.kSpeed_val:
|
||||
dataSize = getTransaction(CANLibrary.LM_API_SPD_PC, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_SPD_PC, dataBuffer);
|
||||
if (dataSize == 4) {
|
||||
return unpackFXP16_16(dataBuffer);
|
||||
}
|
||||
break;
|
||||
case ControlMode.kPosition_val:
|
||||
dataSize = getTransaction(CANLibrary.LM_API_POS_PC, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_POS_PC, dataBuffer);
|
||||
if (dataSize == 4) {
|
||||
return unpackFXP16_16(dataBuffer);
|
||||
}
|
||||
break;
|
||||
case ControlMode.kCurrent_val:
|
||||
dataSize = getTransaction(CANLibrary.LM_API_ICTRL_PC, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_ICTRL_PC, dataBuffer);
|
||||
if (dataSize == 4) {
|
||||
return unpackFXP16_16(dataBuffer);
|
||||
}
|
||||
@@ -834,19 +880,19 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
// TODO: Error, Not Valid
|
||||
break;
|
||||
case ControlMode.kSpeed_val:
|
||||
dataSize = getTransaction(CANLibrary.LM_API_SPD_IC, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_SPD_IC, dataBuffer);
|
||||
if (dataSize == 4) {
|
||||
return unpackFXP16_16(dataBuffer);
|
||||
}
|
||||
break;
|
||||
case ControlMode.kPosition_val:
|
||||
dataSize = getTransaction(CANLibrary.LM_API_POS_IC, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_POS_IC, dataBuffer);
|
||||
if (dataSize == 4) {
|
||||
return unpackFXP16_16(dataBuffer);
|
||||
}
|
||||
break;
|
||||
case ControlMode.kCurrent_val:
|
||||
dataSize = getTransaction(CANLibrary.LM_API_ICTRL_IC, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_ICTRL_IC, dataBuffer);
|
||||
if (dataSize == 4) {
|
||||
return unpackFXP16_16(dataBuffer);
|
||||
}
|
||||
@@ -870,19 +916,19 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
// TODO: Error, Not Valid
|
||||
break;
|
||||
case ControlMode.kSpeed_val:
|
||||
dataSize = getTransaction(CANLibrary.LM_API_SPD_DC, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_SPD_DC, dataBuffer);
|
||||
if (dataSize == 4) {
|
||||
return unpackFXP16_16(dataBuffer);
|
||||
}
|
||||
break;
|
||||
case ControlMode.kPosition_val:
|
||||
dataSize = getTransaction(CANLibrary.LM_API_POS_DC, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_POS_DC, dataBuffer);
|
||||
if (dataSize == 4) {
|
||||
return unpackFXP16_16(dataBuffer);
|
||||
}
|
||||
break;
|
||||
case ControlMode.kCurrent_val:
|
||||
dataSize = getTransaction(CANLibrary.LM_API_ICTRL_DC, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_ICTRL_DC, dataBuffer);
|
||||
if (dataSize == 4) {
|
||||
return unpackFXP16_16(dataBuffer);
|
||||
}
|
||||
@@ -915,20 +961,20 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
|
||||
switch (m_controlMode.value) {
|
||||
case ControlMode.kPercentVbus_val:
|
||||
setTransaction(CANLibrary.LM_API_VOLT_T_EN, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_VOLT_T_EN, dataBuffer, dataSize);
|
||||
break;
|
||||
case ControlMode.kSpeed_val:
|
||||
setTransaction(CANLibrary.LM_API_SPD_T_EN, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_SPD_T_EN, dataBuffer, dataSize);
|
||||
break;
|
||||
case ControlMode.kPosition_val:
|
||||
dataSize = packFXP16_16(dataBuffer, encoderInitialPosition);
|
||||
setTransaction(CANLibrary.LM_API_POS_T_EN, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_POS_T_EN, dataBuffer, dataSize);
|
||||
break;
|
||||
case ControlMode.kCurrent_val:
|
||||
setTransaction(CANLibrary.LM_API_ICTRL_T_EN, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_ICTRL_T_EN, dataBuffer, dataSize);
|
||||
break;
|
||||
case ControlMode.kVoltage_val:
|
||||
setTransaction(CANLibrary.LM_API_VCOMP_T_EN, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_VCOMP_T_EN, dataBuffer, dataSize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -944,19 +990,19 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
|
||||
switch (m_controlMode.value) {
|
||||
case ControlMode.kPercentVbus_val:
|
||||
setTransaction(CANLibrary.LM_API_VOLT_DIS, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_VOLT_DIS, dataBuffer, dataSize);
|
||||
break;
|
||||
case ControlMode.kSpeed_val:
|
||||
setTransaction(CANLibrary.LM_API_SPD_DIS, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_SPD_DIS, dataBuffer, dataSize);
|
||||
break;
|
||||
case ControlMode.kPosition_val:
|
||||
setTransaction(CANLibrary.LM_API_POS_DIS, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_POS_DIS, dataBuffer, dataSize);
|
||||
break;
|
||||
case ControlMode.kCurrent_val:
|
||||
setTransaction(CANLibrary.LM_API_ICTRL_DIS, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_ICTRL_DIS, dataBuffer, dataSize);
|
||||
break;
|
||||
case ControlMode.kVoltage_val:
|
||||
setTransaction(CANLibrary.LM_API_VCOMP_DIS, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_VCOMP_DIS, dataBuffer, dataSize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -991,7 +1037,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
byte[] dataBuffer = new byte[8];
|
||||
byte dataSize = 0;
|
||||
|
||||
dataSize = getTransaction(CANLibrary.LM_API_STATUS_CMODE, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_STATUS_CMODE, dataBuffer);
|
||||
if (dataSize == 1) {
|
||||
switch (dataBuffer[0]) {
|
||||
case ControlMode.kPercentVbus_val:
|
||||
@@ -1018,7 +1064,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
byte[] dataBuffer = new byte[8];
|
||||
byte dataSize = 0;
|
||||
|
||||
dataSize = getTransaction(CANLibrary.LM_API_STATUS_VOLTBUS, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_STATUS_VOLTBUS, dataBuffer);
|
||||
if (dataSize == 2) {
|
||||
return unpackFXP8_8(dataBuffer);
|
||||
}
|
||||
@@ -1035,7 +1081,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
byte dataSize = 0;
|
||||
|
||||
// Read the volt out which is in Volts units.
|
||||
dataSize = getTransaction(CANLibrary.LM_API_STATUS_VOUT, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_STATUS_VOUT, dataBuffer);
|
||||
if (dataSize == 2) {
|
||||
return unpackFXP8_8(dataBuffer);
|
||||
}
|
||||
@@ -1051,7 +1097,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
byte[] dataBuffer = new byte[8];
|
||||
byte dataSize;
|
||||
|
||||
dataSize = getTransaction(CANLibrary.LM_API_STATUS_CURRENT, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_STATUS_CURRENT, dataBuffer);
|
||||
if (dataSize == 2) {
|
||||
return unpackFXP8_8(dataBuffer);
|
||||
}
|
||||
@@ -1068,7 +1114,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
byte[] dataBuffer = new byte[8];
|
||||
byte dataSize;
|
||||
|
||||
dataSize = getTransaction(CANLibrary.LM_API_STATUS_TEMP, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_STATUS_TEMP, dataBuffer);
|
||||
if (dataSize == 2) {
|
||||
return unpackFXP8_8(dataBuffer);
|
||||
}
|
||||
@@ -1084,7 +1130,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
byte[] dataBuffer = new byte[8];
|
||||
byte dataSize;
|
||||
|
||||
dataSize = getTransaction(CANLibrary.LM_API_STATUS_POS, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_STATUS_POS, dataBuffer);
|
||||
if (dataSize == 4) {
|
||||
return unpackFXP16_16(dataBuffer);
|
||||
}
|
||||
@@ -1100,7 +1146,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
byte[] dataBuffer = new byte[8];
|
||||
byte dataSize;
|
||||
|
||||
dataSize = getTransaction(CANLibrary.LM_API_STATUS_SPD, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_STATUS_SPD, dataBuffer);
|
||||
if (dataSize == 4) {
|
||||
return unpackFXP16_16(dataBuffer);
|
||||
}
|
||||
@@ -1116,7 +1162,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
byte[] dataBuffer = new byte[8];
|
||||
byte dataSize;
|
||||
|
||||
dataSize = getTransaction(CANLibrary.LM_API_STATUS_LIMIT, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_STATUS_LIMIT, dataBuffer);
|
||||
if (dataSize == 1) {
|
||||
return (dataBuffer[0] & Limits.kForwardLimit_val) != 0;
|
||||
}
|
||||
@@ -1132,7 +1178,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
byte[] dataBuffer = new byte[8];
|
||||
byte dataSize;
|
||||
|
||||
dataSize = getTransaction(CANLibrary.LM_API_STATUS_LIMIT, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_STATUS_LIMIT, dataBuffer);
|
||||
if (dataSize == 1) {
|
||||
return (dataBuffer[0] & Limits.kReverseLimit_val) != 0;
|
||||
}
|
||||
@@ -1148,7 +1194,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
byte[] dataBuffer = new byte[8];
|
||||
byte dataSize;
|
||||
|
||||
dataSize = getTransaction(CANLibrary.LM_API_STATUS_FAULT, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_STATUS_FAULT, dataBuffer);
|
||||
if (dataSize == 2) {
|
||||
return (short)unpackINT16(dataBuffer);
|
||||
}
|
||||
@@ -1167,14 +1213,14 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
byte[] dataBuffer = new byte[8];
|
||||
byte dataSize;
|
||||
|
||||
dataSize = getTransaction(CANLibrary.LM_API_STATUS_POWER, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_STATUS_POWER, dataBuffer);
|
||||
if (dataSize == 1) {
|
||||
boolean powerCycled = dataBuffer[0] != 0;
|
||||
|
||||
// Clear the power cycled bit now that we've accessed it
|
||||
if (powerCycled) {
|
||||
dataBuffer[0] = 1;
|
||||
setTransaction(CANLibrary.LM_API_STATUS_POWER, dataBuffer, (byte) 1);
|
||||
setTransaction(CANJNI.LM_API_STATUS_POWER, dataBuffer, (byte) 1);
|
||||
}
|
||||
|
||||
return powerCycled;
|
||||
@@ -1197,11 +1243,11 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
switch (m_controlMode.value) {
|
||||
case ControlMode.kPercentVbus_val:
|
||||
dataSize = packPercentage(dataBuffer, rampRate / (m_maxOutputVoltage * kControllerRate));
|
||||
setTransaction(CANLibrary.LM_API_VOLT_SET_RAMP, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_VOLT_SET_RAMP, dataBuffer, dataSize);
|
||||
break;
|
||||
case ControlMode.kVoltage_val:
|
||||
dataSize = packFXP8_8(dataBuffer, rampRate / kControllerRate);
|
||||
setTransaction(CANLibrary.LM_API_VCOMP_IN_RAMP, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_VCOMP_IN_RAMP, dataBuffer, dataSize);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
@@ -1218,7 +1264,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
byte dataSize;
|
||||
|
||||
// Set the MSB to tell the 2CAN that this is a remote message.
|
||||
dataSize = getTransaction(0x80000000 | CANLibrary.CAN_MSGID_API_FIRMVER, dataBuffer);
|
||||
dataSize = getTransaction(0x80000000 | CANJNI.CAN_MSGID_API_FIRMVER, dataBuffer);
|
||||
if (dataSize == 4) {
|
||||
return (int)unpackINT32(dataBuffer);
|
||||
}
|
||||
@@ -1234,14 +1280,14 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
byte[] dataBuffer = new byte[8];
|
||||
byte dataSize;
|
||||
|
||||
dataSize = getTransaction(CANLibrary.LM_API_HWVER, dataBuffer);
|
||||
dataSize = getTransaction(CANJNI.LM_API_HWVER, dataBuffer);
|
||||
if (dataSize == 1 + 1) {
|
||||
if (dataBuffer[0] == m_deviceNumber) {
|
||||
return dataBuffer[1];
|
||||
}
|
||||
}
|
||||
// Assume Gray Jag if there is no response
|
||||
return CANLibrary.LM_HWVER_JAG_1_0;
|
||||
return CANJNI.LM_HWVER_JAG_1_0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1255,7 +1301,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
byte[] dataBuffer = new byte[8];
|
||||
|
||||
dataBuffer[0] = mode.value;
|
||||
setTransaction(CANLibrary.LM_API_CFG_BRAKE_COAST, dataBuffer, (byte) 1);
|
||||
setTransaction(CANJNI.LM_API_CFG_BRAKE_COAST, dataBuffer, (byte) 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1268,7 +1314,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
byte dataSize;
|
||||
|
||||
dataSize = packINT16(dataBuffer, (short)codesPerRev);
|
||||
setTransaction(CANLibrary.LM_API_CFG_ENC_LINES, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_CFG_ENC_LINES, dataBuffer, dataSize);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1284,7 +1330,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
byte dataSize;
|
||||
|
||||
dataSize = packINT16(dataBuffer, (short)turns);
|
||||
setTransaction(CANLibrary.LM_API_CFG_POT_TURNS, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_CFG_POT_TURNS, dataBuffer, dataSize);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1303,14 +1349,14 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
|
||||
dataSize = packFXP16_16(dataBuffer, forwardLimitPosition);
|
||||
dataBuffer[dataSize++] = (forwardLimitPosition > reverseLimitPosition) ? (byte) 1 : (byte) 0;
|
||||
setTransaction(CANLibrary.LM_API_CFG_LIMIT_FWD, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_CFG_LIMIT_FWD, dataBuffer, dataSize);
|
||||
|
||||
dataSize = packFXP16_16(dataBuffer, reverseLimitPosition);
|
||||
dataBuffer[dataSize++] = forwardLimitPosition <= reverseLimitPosition ? (byte) 1 : (byte) 0;
|
||||
setTransaction(CANLibrary.LM_API_CFG_LIMIT_REV, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_CFG_LIMIT_REV, dataBuffer, dataSize);
|
||||
|
||||
dataBuffer[0] = LimitMode.kSoftPositionLimit_val;
|
||||
setTransaction(CANLibrary.LM_API_CFG_LIMIT_MODE, dataBuffer, (byte) 1);
|
||||
setTransaction(CANJNI.LM_API_CFG_LIMIT_MODE, dataBuffer, (byte) 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1322,7 +1368,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
byte[] dataBuffer = new byte[8];
|
||||
|
||||
dataBuffer[0] = LimitMode.kSwitchInputsOnly_val;
|
||||
setTransaction(CANLibrary.LM_API_CFG_LIMIT_MODE, dataBuffer, (byte) 1);
|
||||
setTransaction(CANJNI.LM_API_CFG_LIMIT_MODE, dataBuffer, (byte) 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1339,7 +1385,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
|
||||
m_maxOutputVoltage = voltage;
|
||||
dataSize = packFXP8_8(dataBuffer, voltage);
|
||||
setTransaction(CANLibrary.LM_API_CFG_MAX_VOUT, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_CFG_MAX_VOUT, dataBuffer, dataSize);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1356,7 +1402,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
|
||||
// Message takes ms
|
||||
dataSize = packINT16(dataBuffer, (short) (faultTime * 1000.0));
|
||||
setTransaction(CANLibrary.LM_API_CFG_FAULT_TIME, dataBuffer, dataSize);
|
||||
setTransaction(CANJNI.LM_API_CFG_FAULT_TIME, dataBuffer, dataSize);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1368,7 +1414,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
|
||||
byte[] dataBuffer = new byte[8];
|
||||
|
||||
dataBuffer[0] = syncGroup;
|
||||
sendMessage(CANLibrary.CAN_MSGID_API_SYNC, dataBuffer, 1);
|
||||
sendMessage(CANJNI.CAN_MSGID_API_SYNC, dataBuffer, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
import edu.wpi.first.wpilibj.parsing.IDevice;
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
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.AnalogJNI;
|
||||
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;
|
||||
@@ -68,16 +68,21 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
private DigitalSource m_downSource; // /< What makes the counter count down.
|
||||
private boolean m_allocatedUpSource;
|
||||
private boolean m_allocatedDownSource;
|
||||
private Pointer m_counter; // /< The FPGA counter object.
|
||||
private ByteBuffer m_counter; // /< The FPGA counter object.
|
||||
private int m_index; // /< The index of this counter.
|
||||
private PIDSourceParameter m_pidSource;
|
||||
private double m_distancePerPulse; // distance of travel for each tick
|
||||
|
||||
private void initCounter(final Mode mode) {
|
||||
IntBuffer status = IntBuffer.allocate(1), index = IntBuffer.allocate(1);
|
||||
m_counter = HALLibrary.initializeCounter(mode.value, index, status);
|
||||
HALUtil.checkStatus(status);
|
||||
m_index = index.get();
|
||||
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_index = index.asIntBuffer().get(0);
|
||||
|
||||
m_allocatedUpSource = false;
|
||||
m_allocatedDownSource = false;
|
||||
@@ -189,7 +194,7 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
*/
|
||||
public Counter(AnalogTrigger trigger) {
|
||||
initCounter(Mode.kTwoPulse);
|
||||
setUpSource(trigger.createOutput(HALLibrary.AnalogTriggerType.kState));
|
||||
setUpSource(trigger.createOutput(AnalogJNI.AnalogTriggerType.kState));
|
||||
}
|
||||
|
||||
public void free() {
|
||||
@@ -198,9 +203,10 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
clearUpSource();
|
||||
clearDownSource();
|
||||
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.freeCounter(m_counter, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.freeCounter(m_counter, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
|
||||
m_upSource = null;
|
||||
m_downSource = null;
|
||||
@@ -245,12 +251,13 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
m_allocatedUpSource = false;
|
||||
}
|
||||
m_upSource = source;
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setCounterUpSourceWithModule(m_counter,
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.setCounterUpSourceWithModule(m_counter,
|
||||
(byte) source.getModuleForRouting(),
|
||||
source.getChannelForRouting(),
|
||||
(byte) (source.getAnalogTriggerForRouting() ? 1 : 0), status);
|
||||
HALUtil.checkStatus(status);
|
||||
(byte) (source.getAnalogTriggerForRouting() ? 1 : 0), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -279,11 +286,12 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
if (m_upSource == null)
|
||||
throw new RuntimeException(
|
||||
"Up Source must be set before setting the edge!");
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setCounterUpSourceEdge(m_counter,
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.setCounterUpSourceEdge(m_counter,
|
||||
(byte) (risingEdge ? 1 : 0), (byte) (fallingEdge ? 1 : 0),
|
||||
status);
|
||||
HALUtil.checkStatus(status);
|
||||
status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -296,9 +304,10 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
}
|
||||
m_upSource = null;
|
||||
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.clearCounterUpSource(m_counter, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.clearCounterUpSource(m_counter, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -338,16 +347,17 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
m_downSource.free();
|
||||
m_allocatedDownSource = false;
|
||||
}
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setCounterDownSourceWithModule(m_counter,
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.setCounterDownSourceWithModule(m_counter,
|
||||
(byte) source.getModuleForRouting(),
|
||||
source.getChannelForRouting(),
|
||||
(byte) (source.getAnalogTriggerForRouting() ? 1 : 0), status);
|
||||
if (status.get() == HALLibrary.PARAMETER_OUT_OF_RANGE) {
|
||||
(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);
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
m_downSource = source;
|
||||
}
|
||||
|
||||
@@ -377,10 +387,11 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
if (m_downSource == null)
|
||||
throw new RuntimeException(
|
||||
" Down Source must be set before setting the edge!");
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setCounterDownSourceEdge(m_counter, (byte) (risingEdge ? 1
|
||||
: 0), (byte) (fallingEdge ? 0 : 1), status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.setCounterDownSourceEdge(m_counter, (byte) (risingEdge ? 1
|
||||
: 0), (byte) (fallingEdge ? 0 : 1), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -393,9 +404,10 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
}
|
||||
m_downSource = null;
|
||||
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.clearCounterDownSource(m_counter, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.clearCounterDownSource(m_counter, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -403,9 +415,10 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
* are sourced independently from two inputs.
|
||||
*/
|
||||
public void setUpDownCounterMode() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setCounterUpDownMode(m_counter, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.setCounterUpDownMode(m_counter, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -413,9 +426,10 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
* counter input. The Down counter input represents the direction to count.
|
||||
*/
|
||||
public void setExternalDirectionMode() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setCounterExternalDirectionMode(m_counter, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.setCounterExternalDirectionMode(m_counter, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -426,10 +440,11 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
* true to count up on both rising and falling
|
||||
*/
|
||||
public void setSemiPeriodMode(boolean highSemiPeriod) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setCounterSemiPeriodMode(m_counter,
|
||||
(byte) (highSemiPeriod ? 1 : 0), status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.setCounterSemiPeriodMode(m_counter,
|
||||
(byte) (highSemiPeriod ? 1 : 0), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -442,10 +457,11 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
* direction. Units are seconds.
|
||||
*/
|
||||
public void setPulseLengthMode(double threshold) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setCounterPulseLengthMode(m_counter, (float) threshold,
|
||||
status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.setCounterPulseLengthMode(m_counter, threshold,
|
||||
status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -454,9 +470,10 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
* is not reset on starting, and still has the previous value.
|
||||
*/
|
||||
public void start() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.startCounter(m_counter, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.startCounter(m_counter, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -465,9 +482,10 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
* it might have a different value.
|
||||
*/
|
||||
public int get() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
int value = HALLibrary.getCounter(m_counter, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int value = CounterJNI.getCounter(m_counter, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -487,9 +505,10 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
* zero.
|
||||
*/
|
||||
public void reset() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.resetCounter(m_counter, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.resetCounter(m_counter, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -497,9 +516,10 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
* value.
|
||||
*/
|
||||
public void stop() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.stopCounter(m_counter, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.stopCounter(m_counter, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -513,9 +533,10 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
* moving in seconds.
|
||||
*/
|
||||
public void setMaxPeriod(double maxPeriod) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setCounterMaxPeriod(m_counter, maxPeriod, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.setCounterMaxPeriod(m_counter, maxPeriod, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -536,10 +557,11 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
* true to continue updating
|
||||
*/
|
||||
public void setUpdateWhenEmpty(boolean enabled) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setCounterUpdateWhenEmpty(m_counter,
|
||||
(byte) (enabled ? 1 : 0), status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.setCounterUpdateWhenEmpty(m_counter,
|
||||
(byte) (enabled ? 1 : 0), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -552,9 +574,10 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
* MaxPeriod value set by SetMaxPeriod.
|
||||
*/
|
||||
public boolean getStopped() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
boolean value = HALLibrary.getCounterStopped(m_counter, status) != 0;
|
||||
HALUtil.checkStatus(status);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -564,9 +587,10 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
* @return The last direction the counter value changed.
|
||||
*/
|
||||
public boolean getDirection() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
boolean value = HALLibrary.getCounterDirection(m_counter, status) != 0;
|
||||
HALUtil.checkStatus(status);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -579,10 +603,11 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
* true if the value counted should be negated.
|
||||
*/
|
||||
public void setReverseDirection(boolean reverseDirection) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setCounterReverseDirection(m_counter,
|
||||
(byte) (reverseDirection ? 1 : 0), status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
CounterJNI.setCounterReverseDirection(m_counter,
|
||||
(byte) (reverseDirection ? 1 : 0), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -593,9 +618,10 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
* @returns The period of the last two pulses in units of seconds.
|
||||
*/
|
||||
public double getPeriod() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
double value = HALLibrary.getCounterPeriod(m_counter, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
double value = CounterJNI.getCounterPeriod(m_counter, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -620,14 +646,15 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
* The number of samples to average from 1 to 127.
|
||||
*/
|
||||
public void setSamplesToAverage(int samplesToAverage) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setCounterSamplesToAverage(m_counter, samplesToAverage,
|
||||
status);
|
||||
if (status.get() == HALLibrary.PARAMETER_OUT_OF_RANGE) {
|
||||
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);
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -640,9 +667,10 @@ public class Counter extends SensorBase implements CounterBase,
|
||||
* 127)
|
||||
*/
|
||||
public int getSamplesToAverage() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
int value = HALLibrary.getCounterSamplesToAverage(m_counter, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int value = CounterJNI.getCounterSamplesToAverage(m_counter, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.parsing.IInputOutput;
|
||||
|
||||
|
||||
@@ -7,12 +7,14 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
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.HALLibrary.InterruptHandlerFunction;
|
||||
import edu.wpi.first.wpilibj.hal.InterruptJNI;
|
||||
import edu.wpi.first.wpilibj.hal.DIOJNI;
|
||||
import edu.wpi.first.wpilibj.hal.InterruptJNI.InterruptHandlerFunction;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
import edu.wpi.first.wpilibj.parsing.IInputOutput;
|
||||
@@ -64,9 +66,11 @@ public class DigitalInput extends DigitalSource implements IInputOutput,
|
||||
* @return the stats of the digital input
|
||||
*/
|
||||
public boolean get() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
boolean value = HALLibrary.getDIO(m_port, status) != 0;
|
||||
HALUtil.checkStatus(status);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -106,13 +110,15 @@ public class DigitalInput extends DigitalSource implements IInputOutput,
|
||||
|
||||
allocateInterrupts(false);
|
||||
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.requestInterrupts(m_interrupt, (byte) getModuleForRouting(),
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
InterruptJNI.requestInterrupts(m_interrupt, (byte) getModuleForRouting(),
|
||||
getChannelForRouting(),
|
||||
(byte) (getAnalogTriggerForRouting() ? 1 : 0), status);
|
||||
(byte) (getAnalogTriggerForRouting() ? 1 : 0), status.asIntBuffer());
|
||||
setUpSourceEdge(true, false);
|
||||
HALLibrary.attachInterruptHandler(m_interrupt, handler, null, status);
|
||||
HALUtil.checkStatus(status);
|
||||
InterruptJNI.attachInterruptHandler(m_interrupt, handler, null, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,11 +137,13 @@ public class DigitalInput extends DigitalSource implements IInputOutput,
|
||||
|
||||
allocateInterrupts(true);
|
||||
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.requestInterrupts(m_interrupt, (byte) getModuleForRouting(),
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
InterruptJNI.requestInterrupts(m_interrupt, (byte) getModuleForRouting(),
|
||||
getChannelForRouting(),
|
||||
(byte) (getAnalogTriggerForRouting() ? 1 : 0), status);
|
||||
HALUtil.checkStatus(status);
|
||||
(byte) (getAnalogTriggerForRouting() ? 1 : 0), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
setUpSourceEdge(true, false);
|
||||
|
||||
}
|
||||
@@ -150,11 +158,13 @@ public class DigitalInput extends DigitalSource implements IInputOutput,
|
||||
*/
|
||||
public void setUpSourceEdge(boolean risingEdge, boolean fallingEdge) {
|
||||
if (m_interrupt != null) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setInterruptUpSourceEdge(m_interrupt,
|
||||
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);
|
||||
HALUtil.checkStatus(status);
|
||||
status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"You must call RequestInterrupts before setUpSourceEdge");
|
||||
|
||||
@@ -6,12 +6,18 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
//import com.sun.jna.Pointer;
|
||||
//import com.sun.jna.ptr.IntByReference;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tModuleType;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tModuleType;
|
||||
import edu.wpi.first.wpilibj.hal.DIOJNI;
|
||||
import edu.wpi.first.wpilibj.hal.PWMJNI;
|
||||
import edu.wpi.first.wpilibj.hal.RelayJNI;
|
||||
import edu.wpi.first.wpilibj.hal.HALLibrary;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
|
||||
@@ -27,9 +33,9 @@ public class DigitalModule extends Module {
|
||||
*/
|
||||
public static final int kExpectedLoopTiming = 260;
|
||||
private int m_module;
|
||||
private Pointer[] m_digital_ports;
|
||||
private Pointer[] m_relay_ports;
|
||||
private Pointer[] m_pwm_ports;
|
||||
private ByteBuffer[] m_digital_ports;
|
||||
private ByteBuffer[] m_relay_ports;
|
||||
private ByteBuffer[] m_pwm_ports;
|
||||
|
||||
/**
|
||||
* Get an instance of an Digital Module. Singleton digital module creation
|
||||
@@ -46,32 +52,6 @@ public class DigitalModule extends Module {
|
||||
moduleNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* Convert a channel to its fpga reference
|
||||
*
|
||||
* @param channel
|
||||
* the channel to convert
|
||||
* @return the converted channel
|
||||
*/
|
||||
public static int remapDigitalChannel(final int channel) {
|
||||
System.err.println("This is going away for compatability reasons. Don't use it.");
|
||||
return SensorBase.kDigitalChannels - channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* Convert a channel from it's fpga reference
|
||||
*
|
||||
* @param channel
|
||||
* the channel to convert
|
||||
* @return the converted channel
|
||||
*/
|
||||
public static int unmapDigitalChannel(final int channel) {
|
||||
System.err.println("This is going away for compatability reasons. Don't use it.");
|
||||
return SensorBase.kDigitalChannels - channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new digital module
|
||||
*
|
||||
@@ -82,33 +62,39 @@ public class DigitalModule extends Module {
|
||||
super(tModuleType.kModuleType_Digital, moduleNumber);
|
||||
m_module = moduleNumber;
|
||||
|
||||
m_digital_ports = new Pointer[SensorBase.kDigitalChannels];
|
||||
m_digital_ports = new ByteBuffer[SensorBase.kDigitalChannels];
|
||||
for (int i = 0; i < SensorBase.kDigitalChannels; i++) {
|
||||
Pointer port_pointer = HALLibrary.getPortWithModule(
|
||||
ByteBuffer port_pointer = DIOJNI.getPortWithModule(
|
||||
(byte) moduleNumber, (byte) (i + 1));
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
m_digital_ports[i] = HALLibrary.initializeDigitalPort(port_pointer,
|
||||
status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
m_digital_ports[i] = DIOJNI.initializeDigitalPort(port_pointer,
|
||||
status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
m_relay_ports = new Pointer[SensorBase.kRelayChannels];
|
||||
m_relay_ports = new ByteBuffer[SensorBase.kRelayChannels];
|
||||
for (int i = 0; i < SensorBase.kRelayChannels; i++) {
|
||||
Pointer port_pointer = HALLibrary.getPortWithModule(
|
||||
ByteBuffer port_pointer = RelayJNI.getPortWithModule(
|
||||
(byte) moduleNumber, (byte) (i + 1));
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
m_relay_ports[i] = HALLibrary.initializeDigitalPort(port_pointer,
|
||||
status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
m_relay_ports[i] = RelayJNI.initializeDigitalPort(port_pointer,
|
||||
status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
m_pwm_ports = new Pointer[SensorBase.kPwmChannels];
|
||||
m_pwm_ports = new ByteBuffer[SensorBase.kPwmChannels];
|
||||
for (int i = 0; i < SensorBase.kPwmChannels; i++) {
|
||||
Pointer port_pointer = HALLibrary.getPortWithModule(
|
||||
ByteBuffer port_pointer = PWMJNI.getPortWithModule(
|
||||
(byte) moduleNumber, (byte) (i + 1));
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
m_pwm_ports[i] = HALLibrary.initializeDigitalPort(port_pointer,
|
||||
status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
m_pwm_ports[i] = PWMJNI.initializeDigitalPort(port_pointer,
|
||||
status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -123,9 +109,11 @@ public class DigitalModule extends Module {
|
||||
* The PWM value to set.
|
||||
*/
|
||||
public void setPWM(final int channel, final int value) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setPWM(m_pwm_ports[channel - 1], (short) value, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
PWMJNI.setPWM(m_pwm_ports[channel - 1], (short) value, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,9 +124,11 @@ public class DigitalModule extends Module {
|
||||
* @return The raw PWM value.
|
||||
*/
|
||||
public int getPWM(final int channel) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
int value = (int) HALLibrary.getPWM(m_pwm_ports[channel - 1], status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int value = (int) PWMJNI.getPWM(m_pwm_ports[channel - 1], status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -151,10 +141,12 @@ public class DigitalModule extends Module {
|
||||
* The 2-bit mask of outputs to squelch.
|
||||
*/
|
||||
public void setPWMPeriodScale(final int channel, final int squelchMask) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setPWMPeriodScale(m_pwm_ports[channel - 1], squelchMask,
|
||||
status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
PWMJNI.setPWMPeriodScale(m_pwm_ports[channel - 1], squelchMask,
|
||||
status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,10 +159,12 @@ public class DigitalModule extends Module {
|
||||
* Indicates whether to set the relay to the On state.
|
||||
*/
|
||||
public void setRelayForward(final int channel, final boolean on) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setRelayForward(m_relay_ports[channel - 1], (byte) (on ? 1
|
||||
: 0), status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
RelayJNI.setRelayForward(m_relay_ports[channel - 1], (byte) (on ? 1
|
||||
: 0), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,10 +177,12 @@ public class DigitalModule extends Module {
|
||||
* Indicates whether to set the relay to the On state.
|
||||
*/
|
||||
public void setRelayReverse(final int channel, final boolean on) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setRelayReverse(m_relay_ports[channel - 1], (byte) (on ? 1
|
||||
: 0), status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
RelayJNI.setRelayReverse(m_relay_ports[channel - 1], (byte) (on ? 1
|
||||
: 0), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -197,10 +193,12 @@ public class DigitalModule extends Module {
|
||||
* @return The current state of the relay.
|
||||
*/
|
||||
public boolean getRelayForward(int channel) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
boolean value = HALLibrary.getRelayForward(m_relay_ports[channel - 1],
|
||||
status) != 0;
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
boolean value = RelayJNI.getRelayForward(m_relay_ports[channel - 1],
|
||||
status.asIntBuffer()) != 0;
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -212,11 +210,13 @@ public class DigitalModule extends Module {
|
||||
*/
|
||||
public byte getRelayForward() {
|
||||
byte value = 0;
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
for (int i = 0; i < SensorBase.kRelayChannels; i++) {
|
||||
value |= HALLibrary.getRelayForward(m_relay_ports[i], status) << i;
|
||||
value |= RelayJNI.getRelayForward(m_relay_ports[i], status.asIntBuffer()) << i;
|
||||
}
|
||||
HALUtil.checkStatus(status);
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -228,10 +228,12 @@ public class DigitalModule extends Module {
|
||||
* @return The current statte of the relay
|
||||
*/
|
||||
public boolean getRelayReverse(int channel) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
boolean value = HALLibrary.getRelayReverse(m_relay_ports[channel - 1],
|
||||
status) != 0;
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
boolean value = RelayJNI.getRelayReverse(m_relay_ports[channel - 1],
|
||||
status.asIntBuffer()) != 0;
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -243,11 +245,13 @@ public class DigitalModule extends Module {
|
||||
*/
|
||||
public byte getRelayReverse() {
|
||||
byte value = 0;
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
for (int i = 0; i < SensorBase.kRelayChannels; i++) {
|
||||
value |= HALLibrary.getRelayReverse(m_relay_ports[i], status) << i;
|
||||
value |= RelayJNI.getRelayReverse(m_relay_ports[i], status.asIntBuffer()) << i;
|
||||
}
|
||||
HALUtil.checkStatus(status);
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -264,10 +268,12 @@ public class DigitalModule extends Module {
|
||||
* @return True if the I/O pin was allocated, false otherwise.
|
||||
*/
|
||||
public boolean allocateDIO(final int channel, final boolean input) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
boolean allocated = HALLibrary.allocateDIO(
|
||||
m_digital_ports[channel - 1], (byte) (input ? 1 : 0), status) != 0;
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
boolean allocated = DIOJNI.allocateDIO(
|
||||
m_digital_ports[channel - 1], (byte) (input ? 1 : 0), status.asIntBuffer()) != 0;
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return allocated;
|
||||
}
|
||||
|
||||
@@ -278,9 +284,11 @@ public class DigitalModule extends Module {
|
||||
* The channel whose resources should be freed.
|
||||
*/
|
||||
public void freeDIO(final int channel) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.freeDIO(m_digital_ports[channel - 1], status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
DIOJNI.freeDIO(m_digital_ports[channel - 1], status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -293,10 +301,12 @@ public class DigitalModule extends Module {
|
||||
* The value to set.
|
||||
*/
|
||||
public void setDIO(final int channel, final boolean value) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setDIO(m_digital_ports[channel - 1], (byte) (value ? 1 : 0),
|
||||
status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
DIOJNI.setDIO(m_digital_ports[channel - 1], (byte) (value ? 1 : 0),
|
||||
status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -308,9 +318,11 @@ public class DigitalModule extends Module {
|
||||
* @return The value of the selected channel
|
||||
*/
|
||||
public boolean getDIO(final int channel) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
boolean value = HALLibrary.getDIO(m_digital_ports[channel - 1], status) != 0;
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
boolean value = DIOJNI.getDIO(m_digital_ports[channel - 1], status.asIntBuffer()) != 0;
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -321,12 +333,14 @@ public class DigitalModule extends Module {
|
||||
* @return The state of all the Digital IO lines in hardware order
|
||||
*/
|
||||
public short getAllDIO() {
|
||||
byte value = 0;
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
short value = 0;
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
for (int i = 0; i < SensorBase.kDigitalChannels; i++) {
|
||||
value |= HALLibrary.getDIO(m_digital_ports[i], status) << i;
|
||||
value |= DIOJNI.getDIO(m_digital_ports[i], status.asIntBuffer()) << i;
|
||||
}
|
||||
HALUtil.checkStatus(status);
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -339,10 +353,12 @@ public class DigitalModule extends Module {
|
||||
* it is an input
|
||||
*/
|
||||
public boolean getDIODirection(int channel) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
boolean value = HALLibrary.getDIODirection(
|
||||
m_digital_ports[channel - 1], status) != 0;
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
boolean value = DIOJNI.getDIODirection(
|
||||
m_digital_ports[channel - 1], status.asIntBuffer()) != 0;
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -355,11 +371,13 @@ public class DigitalModule extends Module {
|
||||
*/
|
||||
public short getDIODirection() {
|
||||
byte value = 0;
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
for (int i = 0; i < SensorBase.kDigitalChannels; i++) {
|
||||
value |= HALLibrary.getDIODirection(m_digital_ports[i], status) << i;
|
||||
value |= DIOJNI.getDIODirection(m_digital_ports[i], status.asIntBuffer()) << i;
|
||||
}
|
||||
HALUtil.checkStatus(status);
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -373,9 +391,11 @@ public class DigitalModule extends Module {
|
||||
* The length of the pulse.
|
||||
*/
|
||||
public void pulse(final int channel, final float pulseLength) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.pulse(m_digital_ports[channel - 1], pulseLength, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
DIOJNI.pulse(m_digital_ports[channel - 1], pulseLength, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -389,13 +409,14 @@ public class DigitalModule extends Module {
|
||||
* The length of the pulse.
|
||||
*/
|
||||
public void pulse(final int channel, final int pulseLength) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
float convertedPulse = (float) (pulseLength / 1.0e9 * (HALLibrary
|
||||
.getLoopTiming(status) * 25));
|
||||
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));
|
||||
System.err
|
||||
.println("You should use the float version of pulse for portability. This is deprecated");
|
||||
HALLibrary.pulse(m_digital_ports[channel - 1], convertedPulse, status);
|
||||
HALUtil.checkStatus(status);
|
||||
DIOJNI.pulse(m_digital_ports[channel - 1], convertedPulse, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -406,10 +427,12 @@ public class DigitalModule extends Module {
|
||||
* @return True if the channel is pulsing, false otherwise.
|
||||
*/
|
||||
public boolean isPulsing(final int channel) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
boolean value = HALLibrary.isPulsing(m_digital_ports[channel - 1],
|
||||
status) != 0;
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
boolean value = DIOJNI.isPulsing(m_digital_ports[channel - 1],
|
||||
status.asIntBuffer()) != 0;
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -420,9 +443,11 @@ public class DigitalModule extends Module {
|
||||
*/
|
||||
public boolean isPulsing() {
|
||||
boolean value;
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
value = HALLibrary.isAnyPulsingWithModule((byte) m_module, status) != 0;
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
value = DIOJNI.isAnyPulsingWithModule((byte) m_module, status.asIntBuffer()) != 0;
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -430,22 +455,24 @@ public class DigitalModule extends Module {
|
||||
* Allocate a DO PWM Generator. Allocate PWM generators so that they are not
|
||||
* accidently reused.
|
||||
*/
|
||||
public int allocateDO_PWM() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
int value = HALLibrary.allocatePWMWithModule((byte) m_module, status)
|
||||
.getInt(0); // XXX: Hacky, needs heavy testing
|
||||
HALUtil.checkStatus(status);
|
||||
public ByteBuffer allocateDO_PWM() {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
ByteBuffer value = PWMJNI.allocatePWMWithModule((byte) m_module, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Free the resource associated with a DO PWM generator.
|
||||
*/
|
||||
public void freeDO_PWM(int pwmGenerator) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
Pointer pointer = new IntByReference(pwmGenerator).getPointer();
|
||||
HALLibrary.freePWMWithModule((byte) m_module, pointer, status);
|
||||
HALUtil.checkStatus(status);
|
||||
public void freeDO_PWM(ByteBuffer pwmGenerator) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
PWMJNI.freePWMWithModule((byte) m_module, pwmGenerator, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -459,9 +486,11 @@ public class DigitalModule extends Module {
|
||||
* module.
|
||||
*/
|
||||
public void setDO_PWMRate(double rate) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setPWMRateWithModuleIntHack((byte) m_module, Float.floatToIntBits((float) rate), status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
PWMJNI.setPWMRateWithModule((byte) m_module, rate, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -472,12 +501,13 @@ public class DigitalModule extends Module {
|
||||
* @param channel
|
||||
* The Digital Output channel to output on
|
||||
*/
|
||||
public void setDO_PWMOutputChannel(int pwmGenerator, int channel) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
Pointer pointer = new IntByReference(pwmGenerator).getPointer();
|
||||
HALLibrary.setPWMOutputChannelWithModule((byte) m_module, pointer,
|
||||
channel, status);
|
||||
HALUtil.checkStatus(status);
|
||||
public void setDO_PWMOutputChannel(ByteBuffer pwmGenerator, int channel) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
PWMJNI.setPWMOutputChannelWithModule((byte) m_module, pwmGenerator,
|
||||
channel, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -488,12 +518,12 @@ public class DigitalModule extends Module {
|
||||
* @param dutyCycle
|
||||
* The percent duty cycle to output [0..1].
|
||||
*/
|
||||
public void setDO_PWMDutyCycle(int pwmGenerator, double dutyCycle) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
Pointer pointer = new IntByReference(pwmGenerator).getPointer();
|
||||
HALLibrary.setPWMDutyCycleWithModuleIntHack((byte) m_module, pointer,
|
||||
Float.floatToIntBits((float) dutyCycle), status);
|
||||
HALUtil.checkStatus(status);
|
||||
public void setDO_PWMDutyCycle(ByteBuffer pwmGenerator, double dutyCycle) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
PWMJNI.setPWMDutyCycleWithModule((byte) m_module, pwmGenerator, dutyCycle, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -513,9 +543,11 @@ public class DigitalModule extends Module {
|
||||
* @return The number of clock ticks per DIO loop
|
||||
*/
|
||||
public int getLoopTiming() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
int value = HALLibrary.getLoopTiming(status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int value = DIOJNI.getLoopTiming(status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,13 +7,17 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
//import com.sun.jna.Pointer;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
|
||||
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.DIOJNI;
|
||||
import edu.wpi.first.wpilibj.hal.PWMJNI;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
import edu.wpi.first.wpilibj.parsing.IInputOutput;
|
||||
@@ -28,7 +32,7 @@ import edu.wpi.first.wpilibj.tables.ITableListener;
|
||||
public class DigitalOutput extends DigitalSource implements IInputOutput,
|
||||
LiveWindowSendable {
|
||||
|
||||
private Pointer m_pwmGenerator;
|
||||
private ByteBuffer m_pwmGenerator;
|
||||
|
||||
/**
|
||||
* Create an instance of a digital output. Create an instance of a digital
|
||||
@@ -75,9 +79,11 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
|
||||
* true is on, off is false
|
||||
*/
|
||||
public void set(boolean value) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setDIO(m_port, (short) (value ? 1 : 0), status);
|
||||
HALUtil.checkStatus(status);
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,9 +103,11 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
|
||||
* The length of the pulse.
|
||||
*/
|
||||
public void pulse(final int channel, final float pulseLength) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.pulse(m_port, pulseLength, status);
|
||||
HALUtil.checkStatus(status);
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,13 +121,14 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
|
||||
* The length of the pulse.
|
||||
*/
|
||||
public void pulse(final int channel, final int pulseLength) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
float convertedPulse = (float) (pulseLength / 1.0e9 * (HALLibrary
|
||||
.getLoopTiming(status) * 25));
|
||||
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));
|
||||
System.err
|
||||
.println("You should use the float version of pulse for portability. This is deprecated");
|
||||
HALLibrary.pulse(m_port, convertedPulse, status);
|
||||
HALUtil.checkStatus(status);
|
||||
DIOJNI.pulse(m_port, convertedPulse, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,9 +138,11 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
|
||||
* @return true if pulsing
|
||||
*/
|
||||
public boolean isPulsing() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
boolean value = HALLibrary.isPulsing(m_port, status) != 0;
|
||||
HALUtil.checkStatus(status);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -148,10 +159,12 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
|
||||
* module.
|
||||
*/
|
||||
public void setPWMRate(double rate) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setPWMRateWithModule((byte) m_moduleNumber, (float) rate,
|
||||
status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
PWMJNI.setPWMRateWithModule((byte) m_moduleNumber, rate,
|
||||
status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,15 +184,17 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
|
||||
public void enablePWM(double initialDutyCycle) {
|
||||
if (m_pwmGenerator == null)
|
||||
return;
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
m_pwmGenerator = HALLibrary.allocatePWMWithModule(
|
||||
(byte) m_moduleNumber, status);
|
||||
HALUtil.checkStatus(status);
|
||||
HALLibrary.setPWMDutyCycle(m_pwmGenerator, (float) initialDutyCycle,
|
||||
status);
|
||||
HALUtil.checkStatus(status);
|
||||
HALLibrary.setPWMOutputChannelWithModule((byte) m_moduleNumber,
|
||||
m_pwmGenerator, m_channel, status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
m_pwmGenerator = PWMJNI.allocatePWMWithModule(
|
||||
(byte) m_moduleNumber, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
PWMJNI.setPWMDutyCycle(m_pwmGenerator, initialDutyCycle,
|
||||
status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
PWMJNI.setPWMOutputChannelWithModule((byte) m_moduleNumber,
|
||||
m_pwmGenerator, m_channel, status.asIntBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,12 +204,13 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
|
||||
*/
|
||||
public void disablePWM() {
|
||||
// Disable the output by routing to a dead bit.
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary
|
||||
.setPWMOutputChannel(m_pwmGenerator, kDigitalChannels, status);
|
||||
HALUtil.checkStatus(status);
|
||||
HALLibrary.freePWMWithModule((byte) m_moduleNumber, m_pwmGenerator,
|
||||
status);
|
||||
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.freePWMWithModule((byte) m_moduleNumber, m_pwmGenerator,
|
||||
status.asIntBuffer());
|
||||
m_pwmGenerator = null;
|
||||
}
|
||||
|
||||
@@ -208,10 +224,12 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
|
||||
* The duty-cycle to change to. [0..1]
|
||||
*/
|
||||
public void updateDutyCycle(double dutyCycle) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setPWMDutyCycleWithModule((byte) m_moduleNumber,
|
||||
m_pwmGenerator, (float) dutyCycle, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
PWMJNI.setPWMDutyCycleWithModule((byte) m_moduleNumber,
|
||||
m_pwmGenerator, dutyCycle, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.HALLibrary;
|
||||
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;
|
||||
@@ -27,14 +27,14 @@ public abstract class DigitalSource extends InterruptableSensorBase {
|
||||
|
||||
protected static Resource channels = new Resource(kDigitalChannels
|
||||
* kDigitalModules);
|
||||
protected Pointer m_port;
|
||||
protected ByteBuffer m_port;
|
||||
protected int m_moduleNumber, m_channel;
|
||||
|
||||
protected void initDigitalPort(int moduleNumber, int channel, boolean input) {
|
||||
|
||||
m_channel = channel;
|
||||
m_moduleNumber = moduleNumber;
|
||||
if (HALLibrary.checkDigitalModule((byte) m_moduleNumber) != 1) {
|
||||
if (DIOJNI.checkDigitalModule((byte) m_moduleNumber) != 1) {
|
||||
throw new AllocationException("Digital input " + m_channel
|
||||
+ " on module " + m_moduleNumber
|
||||
+ " cannot be allocated. Module is not present.");
|
||||
@@ -51,20 +51,24 @@ public abstract class DigitalSource extends InterruptableSensorBase {
|
||||
+ " on module " + m_moduleNumber + " is already allocated");
|
||||
}
|
||||
|
||||
Pointer port_pointer = HALLibrary.getPortWithModule(
|
||||
ByteBuffer port_pointer = DIOJNI.getPortWithModule(
|
||||
(byte) moduleNumber, (byte) channel);
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
m_port = HALLibrary.initializeDigitalPort(port_pointer, status);
|
||||
HALUtil.checkStatus(status);
|
||||
HALLibrary.allocateDIO(m_port, (byte) (input ? 1 : 0), status);
|
||||
HALUtil.checkStatus(status);
|
||||
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());
|
||||
}
|
||||
|
||||
public void free() {
|
||||
channels.free(((m_moduleNumber - 1) * kDigitalChannels + m_channel - 1));
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.freeDIO(m_port, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
DIOJNI.freeDIO(m_port, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
m_channel = 0;
|
||||
m_moduleNumber = 0;
|
||||
}
|
||||
@@ -75,10 +79,7 @@ public abstract class DigitalSource extends InterruptableSensorBase {
|
||||
* @return channel routing number
|
||||
*/
|
||||
public int getChannelForRouting() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
int channel = HALLibrary.remapDigitalChannel(m_channel - 1, status);
|
||||
HALUtil.checkStatus(status);
|
||||
return channel;
|
||||
return m_channel - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
@@ -50,28 +50,28 @@ public class DoubleSolenoid extends SolenoidBase implements LiveWindowSendable {
|
||||
* Common function to implement constructor behavior.
|
||||
*/
|
||||
private synchronized void initSolenoid() {
|
||||
checkSolenoidModule(m_moduleNumber);
|
||||
checkSolenoidChannel(m_forwardChannel);
|
||||
checkSolenoidChannel(m_reverseChannel);
|
||||
|
||||
try {
|
||||
m_allocated.allocate((m_moduleNumber - 1) * kSolenoidChannels + m_forwardChannel - 1);
|
||||
} catch (CheckedAllocationException e) {
|
||||
throw new AllocationException(
|
||||
"Solenoid channel " + m_forwardChannel + " on module " + m_moduleNumber + " is already allocated");
|
||||
}
|
||||
try {
|
||||
m_allocated.allocate((m_moduleNumber - 1) * kSolenoidChannels + m_reverseChannel - 1);
|
||||
} catch (CheckedAllocationException e) {
|
||||
throw new AllocationException(
|
||||
"Solenoid channel " + m_reverseChannel + " on module " + m_moduleNumber + " is already allocated");
|
||||
}
|
||||
m_forwardMask = (byte) (1 << (m_forwardChannel - 1));
|
||||
m_reverseMask = (byte) (1 << (m_reverseChannel - 1));
|
||||
|
||||
UsageReporting.report(tResourceType.kResourceType_Solenoid, m_forwardChannel, m_moduleNumber-1);
|
||||
UsageReporting.report(tResourceType.kResourceType_Solenoid, m_reverseChannel, m_moduleNumber-1);
|
||||
LiveWindow.addActuator("DoubleSolenoid", m_moduleNumber, m_forwardChannel, this);
|
||||
// checkSolenoidModule(m_moduleNumber);
|
||||
// checkSolenoidChannel(m_forwardChannel);
|
||||
// checkSolenoidChannel(m_reverseChannel);
|
||||
//
|
||||
// try {
|
||||
// m_allocated.allocate((m_moduleNumber - 1) * kSolenoidChannels + m_forwardChannel - 1);
|
||||
// } catch (CheckedAllocationException e) {
|
||||
// throw new AllocationException(
|
||||
// "Solenoid channel " + m_forwardChannel + " on module " + m_moduleNumber + " is already allocated");
|
||||
// }
|
||||
// try {
|
||||
// m_allocated.allocate((m_moduleNumber - 1) * kSolenoidChannels + m_reverseChannel - 1);
|
||||
// } catch (CheckedAllocationException e) {
|
||||
// throw new AllocationException(
|
||||
// "Solenoid channel " + m_reverseChannel + " on module " + m_moduleNumber + " is already allocated");
|
||||
// }
|
||||
// m_forwardMask = (byte) (1 << (m_forwardChannel - 1));
|
||||
// m_reverseMask = (byte) (1 << (m_reverseChannel - 1));
|
||||
//
|
||||
// UsageReporting.report(tResourceType.kResourceType_Solenoid, m_forwardChannel, m_moduleNumber-1);
|
||||
// UsageReporting.report(tResourceType.kResourceType_Solenoid, m_reverseChannel, m_moduleNumber-1);
|
||||
// LiveWindow.addActuator("DoubleSolenoid", m_moduleNumber, m_forwardChannel, this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,8 +105,8 @@ public class DoubleSolenoid extends SolenoidBase implements LiveWindowSendable {
|
||||
* Destructor.
|
||||
*/
|
||||
public synchronized void free() {
|
||||
m_allocated.free((m_moduleNumber - 1) * kSolenoidChannels + m_forwardChannel - 1);
|
||||
m_allocated.free((m_moduleNumber - 1) * kSolenoidChannels + m_reverseChannel - 1);
|
||||
// m_allocated.free((m_moduleNumber - 1) * kSolenoidChannels + m_forwardChannel - 1);
|
||||
// m_allocated.free((m_moduleNumber - 1) * kSolenoidChannels + m_reverseChannel - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,10 +6,13 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.*;
|
||||
import edu.wpi.first.wpilibj.hal.HALLibrary;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary;
|
||||
import edu.wpi.first.wpilibj.communication.FRCCommonControlData;
|
||||
import edu.wpi.first.wpilibj.communication.FRCCommonControlMasks;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.parsing.IInputOutput;
|
||||
|
||||
/**
|
||||
@@ -20,7 +23,7 @@ public class DriverStation implements IInputOutput {
|
||||
/**
|
||||
* The size of the user status data
|
||||
*/
|
||||
public static final int USER_STATUS_DATA_SIZE = FRC_NetworkCommunicationsLibrary.USER_STATUS_DATA_SIZE;
|
||||
public static final int USER_STATUS_DATA_SIZE = FRCNetworkCommunicationsLibrary.USER_STATUS_DATA_SIZE;
|
||||
/**
|
||||
* Slot for the analog module to read the battery
|
||||
*/
|
||||
@@ -100,7 +103,7 @@ public class DriverStation implements IInputOutput {
|
||||
private boolean m_userInTeleop = false;
|
||||
private boolean m_userInTest = false;
|
||||
private boolean m_newControlData;
|
||||
private final Pointer m_packetDataAvailableSem;
|
||||
private final ByteBuffer m_packetDataAvailableSem;
|
||||
// XXX: Add DriverStationEnhancedIO back
|
||||
// private DriverStationEnhancedIO m_enhancedIO = new DriverStationEnhancedIO();
|
||||
|
||||
@@ -132,8 +135,12 @@ public class DriverStation implements IInputOutput {
|
||||
// XXX: Uncomment when analogChannel is fixed
|
||||
//m_batteryChannel = new AnalogChannel(kBatterySlot, kBatteryChannel);
|
||||
|
||||
m_packetDataAvailableSem = HALLibrary.initializeMutex(HALLibrary.SEMAPHORE_Q_PRIORITY.get());
|
||||
FRC_NetworkCommunicationsLibrary.setNewDataSem(m_packetDataAvailableSem);
|
||||
m_packetDataAvailableSem = HALUtil.initializeMutexNormal();
|
||||
|
||||
// set the byte order
|
||||
m_packetDataAvailableSem.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
FRCNetworkCommunicationsLibrary.setNewDataSem(m_packetDataAvailableSem);
|
||||
|
||||
m_thread = new Thread(new DriverStationTask(this), "FRCDriverStation");
|
||||
m_thread.setPriority((Thread.NORM_PRIORITY + Thread.MAX_PRIORITY) / 2);
|
||||
@@ -154,7 +161,7 @@ public class DriverStation implements IInputOutput {
|
||||
private void task() {
|
||||
int safetyCounter = 0;
|
||||
while (m_thread_keepalive) {
|
||||
HALLibrary.takeMutex(m_packetDataAvailableSem, HALLibrary.SEMAPHORE_WAIT_FOREVER.get());
|
||||
HALUtil.takeMutex(m_packetDataAvailableSem);
|
||||
synchronized (this) {
|
||||
getData();
|
||||
// XXX: Add DriverStationEnhancedIO back
|
||||
@@ -170,16 +177,16 @@ public class DriverStation implements IInputOutput {
|
||||
safetyCounter = 0;
|
||||
}
|
||||
if (m_userInDisabled) {
|
||||
FRC_NetworkCommunicationsLibrary.FRC_NetworkCommunication_observeUserProgramDisabled();
|
||||
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramDisabled();
|
||||
}
|
||||
if (m_userInAutonomous) {
|
||||
FRC_NetworkCommunicationsLibrary.FRC_NetworkCommunication_observeUserProgramAutonomous();
|
||||
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramAutonomous();
|
||||
}
|
||||
if (m_userInTeleop) {
|
||||
FRC_NetworkCommunicationsLibrary.FRC_NetworkCommunication_observeUserProgramTeleop();
|
||||
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramTeleop();
|
||||
}
|
||||
if (m_userInTest) {
|
||||
FRC_NetworkCommunicationsLibrary.FRC_NetworkCommunication_observeUserProgramTest();
|
||||
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramTest();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -213,7 +220,7 @@ public class DriverStation implements IInputOutput {
|
||||
* the data will be copied from the DS polling loop.
|
||||
*/
|
||||
protected synchronized void getData() {
|
||||
FRC_NetworkCommunicationsLibrary.getCommonControlData(m_controlData, HALLibrary.SEMAPHORE_WAIT_FOREVER.get());
|
||||
FRCNetworkCommunicationsLibrary.getCommonControlData(m_controlData);
|
||||
|
||||
if (!lastEnabled && isEnabled()) {
|
||||
// If starting teleop, assume that autonomous just took up 15 seconds
|
||||
@@ -236,14 +243,13 @@ public class DriverStation implements IInputOutput {
|
||||
*/
|
||||
protected void setData() {
|
||||
synchronized (m_semaphore) {
|
||||
FRC_NetworkCommunicationsLibrary.setStatusData((float) getBatteryVoltage(),
|
||||
FRCNetworkCommunicationsLibrary.setStatusData((float) getBatteryVoltage(),
|
||||
(byte) m_digitalOut,
|
||||
(byte) m_updateNumber,
|
||||
new String(m_dashboardInUseHigh.getBytes()),
|
||||
m_dashboardInUseHigh.getBytesLength(),
|
||||
new String(m_dashboardInUseLow.getBytes()),
|
||||
m_dashboardInUseLow.getBytesLength(),
|
||||
HALLibrary.SEMAPHORE_WAIT_FOREVER.get());
|
||||
m_dashboardInUseLow.getBytesLength());
|
||||
m_dashboardInUseHigh.flush();
|
||||
m_dashboardInUseLow.flush();
|
||||
}
|
||||
@@ -282,16 +288,16 @@ public class DriverStation implements IInputOutput {
|
||||
int value;
|
||||
switch (stick) {
|
||||
case 1:
|
||||
value = m_controlData.field2.stick0Axes[axis - 1];
|
||||
value = m_controlData.stick0Axes[axis - 1];
|
||||
break;
|
||||
case 2:
|
||||
value = m_controlData.field3.stick1Axes[axis - 1];
|
||||
value = m_controlData.stick1Axes[axis - 1];
|
||||
break;
|
||||
case 3:
|
||||
value = m_controlData.field4.stick2Axes[axis - 1];
|
||||
value = m_controlData.stick2Axes[axis - 1];
|
||||
break;
|
||||
case 4:
|
||||
value = m_controlData.field5.stick3Axes[axis - 1];
|
||||
value = m_controlData.stick3Axes[axis - 1];
|
||||
break;
|
||||
default:
|
||||
return 0.0;
|
||||
@@ -400,7 +406,7 @@ public class DriverStation implements IInputOutput {
|
||||
* @return True if the robot is enabled, false otherwise.
|
||||
*/
|
||||
public boolean isEnabled() {
|
||||
return (m_controlData.field1.control & FRCCommonControlMasks.ENABLED) != 0;
|
||||
return (m_controlData.control & FRCCommonControlMasks.ENABLED) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -420,7 +426,7 @@ public class DriverStation implements IInputOutput {
|
||||
* @return True if autonomous mode should be enabled, false otherwise.
|
||||
*/
|
||||
public boolean isAutonomous() {
|
||||
return (m_controlData.field1.control & FRCCommonControlMasks.AUTONOMOUS) != 0;
|
||||
return (m_controlData.control & FRCCommonControlMasks.AUTONOMOUS) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -429,7 +435,7 @@ public class DriverStation implements IInputOutput {
|
||||
* @return True if test mode should be enabled, false otherwise.
|
||||
*/
|
||||
public boolean isTest() {
|
||||
return (m_controlData.field1.control & FRCCommonControlMasks.TEST) != 0;
|
||||
return (m_controlData.control & FRCCommonControlMasks.TEST) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -588,7 +594,7 @@ public class DriverStation implements IInputOutput {
|
||||
* @return True if the robot is competing on a field being controlled by a Field Management System
|
||||
*/
|
||||
public boolean isFMSAttached() {
|
||||
return (m_controlData.field1.control & FRCCommonControlMasks.FMS_ATTATCHED) > 0;
|
||||
return (m_controlData.control & FRCCommonControlMasks.FMS_ATTATCHED) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,8 +10,8 @@ package edu.wpi.first.wpilibj;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary;
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.parsing.IInputOutput;
|
||||
|
||||
@@ -111,9 +111,9 @@ public class DriverStationLCD extends SensorBase implements IInputOutput {
|
||||
* This is only called once the first time GetInstance() is called
|
||||
*/
|
||||
private DriverStationLCD() {
|
||||
m_textBuffer = new byte[FRC_NetworkCommunicationsLibrary.USER_DS_LCD_DATA_SIZE];
|
||||
m_textBuffer = new byte[FRCNetworkCommunicationsLibrary.USER_DS_LCD_DATA_SIZE];
|
||||
|
||||
for (int i = 0; i < FRC_NetworkCommunicationsLibrary.USER_DS_LCD_DATA_SIZE; i++) {
|
||||
for (int i = 0; i < FRCNetworkCommunicationsLibrary.USER_DS_LCD_DATA_SIZE; i++) {
|
||||
m_textBuffer[i] = ' ';
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ public class DriverStationLCD extends SensorBase implements IInputOutput {
|
||||
* Send the text data to the Driver Station.
|
||||
*/
|
||||
public synchronized void updateLCD() {
|
||||
FRC_NetworkCommunicationsLibrary.setUserDsLcdData(new String(m_textBuffer), FRC_NetworkCommunicationsLibrary.USER_DS_LCD_DATA_SIZE, kSyncTimeout_ms);
|
||||
FRCNetworkCommunicationsLibrary.setUserDsLcdData(new String(m_textBuffer), FRCNetworkCommunicationsLibrary.USER_DS_LCD_DATA_SIZE, kSyncTimeout_ms);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,14 +6,13 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tInstances;
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInstances;
|
||||
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.EncoderJNI;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
@@ -46,7 +45,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource,
|
||||
* The index source
|
||||
*/
|
||||
protected DigitalSource m_indexSource = null; // Index on some encoders
|
||||
private Pointer m_encoder;
|
||||
private ByteBuffer m_encoder;
|
||||
private int m_index;
|
||||
private double m_distancePerPulse; // distance of travel for each encoder
|
||||
// tick
|
||||
@@ -75,18 +74,22 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource,
|
||||
private void initEncoder(boolean reverseDirection) {
|
||||
switch (m_encodingType.value) {
|
||||
case EncodingType.k4X_val:
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
IntBuffer index = IntBuffer.allocate(1);
|
||||
m_encoder = HALLibrary.initializeEncoder(
|
||||
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),
|
||||
(byte) m_bSource.getModuleForRouting(),
|
||||
m_bSource.getChannelForRouting(),
|
||||
(byte) (m_bSource.getAnalogTriggerForRouting() ? 1 : 0),
|
||||
(byte) (reverseDirection ? 1 : 0), index, status);
|
||||
HALUtil.checkStatus(status);
|
||||
m_index = index.get();
|
||||
(byte) (reverseDirection ? 1 : 0), index.asIntBuffer(), status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
m_index = index.asIntBuffer().get(0);
|
||||
m_counter = null;
|
||||
break;
|
||||
case EncodingType.k2X_val:
|
||||
@@ -511,9 +514,11 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource,
|
||||
m_counter.free();
|
||||
m_counter = null;
|
||||
} else {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.freeEncoder(m_encoder, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
EncoderJNI.freeEncoder(m_encoder, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -524,9 +529,11 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource,
|
||||
if (m_counter != null) {
|
||||
m_counter.start();
|
||||
} else {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.startEncoder(m_encoder, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
EncoderJNI.startEncoder(m_encoder, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -537,9 +544,11 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource,
|
||||
if (m_counter != null) {
|
||||
m_counter.stop();
|
||||
} else {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.stopEncoder(m_encoder, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
EncoderJNI.stopEncoder(m_encoder, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -554,9 +563,11 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource,
|
||||
if (m_counter != null) {
|
||||
value = m_counter.get();
|
||||
} else {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
value = HALLibrary.getEncoder(m_encoder, status);
|
||||
HALUtil.checkStatus(status);
|
||||
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());
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@@ -580,9 +591,11 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource,
|
||||
if (m_counter != null) {
|
||||
m_counter.reset();
|
||||
} else {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.resetEncoder(m_encoder, status);
|
||||
HALUtil.checkStatus(status);
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
EncoderJNI.resetEncoder(m_encoder, status.asIntBuffer());
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -602,9 +615,11 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource,
|
||||
if (m_counter != null) {
|
||||
measuredPeriod = m_counter.getPeriod();
|
||||
} else {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
measuredPeriod = HALLibrary.getEncoderPeriod(m_encoder, status);
|
||||
HALUtil.checkStatus(status);
|
||||
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());
|
||||
}
|
||||
return measuredPeriod / decodingScaleFactor();
|
||||
}
|
||||
@@ -626,10 +641,11 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource,
|
||||
if (m_counter != null) {
|
||||
m_counter.setMaxPeriod(maxPeriod * decodingScaleFactor());
|
||||
} else {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary
|
||||
.setEncoderMaxPeriod(m_encoder, (float) maxPeriod, status);
|
||||
HALUtil.checkStatus(status);
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -645,9 +661,11 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource,
|
||||
if (m_counter != null) {
|
||||
return m_counter.getStopped();
|
||||
} else {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
boolean value = HALLibrary.getEncoderStopped(m_encoder, status) != 0;
|
||||
HALUtil.checkStatus(status);
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -661,9 +679,11 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource,
|
||||
if (m_counter != null) {
|
||||
return m_counter.getDirection();
|
||||
} else {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
boolean value = HALLibrary.getEncoderDirection(m_encoder, status) != 0;
|
||||
HALUtil.checkStatus(status);
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -766,14 +786,16 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource,
|
||||
public void setSamplesToAverage(int samplesToAverage) {
|
||||
switch (m_encodingType.value) {
|
||||
case EncodingType.k4X_val:
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setEncoderSamplesToAverage(m_encoder, samplesToAverage,
|
||||
status);
|
||||
if (status.get() == HALLibrary.PARAMETER_OUT_OF_RANGE) {
|
||||
ByteBuffer status = ByteBuffer.allocateDirect(4);
|
||||
// set the byte order
|
||||
status.order(ByteOrder.LITTLE_ENDIAN);
|
||||
EncoderJNI.setEncoderSamplesToAverage(m_encoder, samplesToAverage,
|
||||
status.asIntBuffer());
|
||||
if (status.get() == HALUtil.PARAMETER_OUT_OF_RANGE) {
|
||||
throw new BoundaryException(BoundaryException.getMessage(
|
||||
samplesToAverage, 1, 127));
|
||||
}
|
||||
HALUtil.checkStatus(status);
|
||||
HALUtil.checkStatus(status.asIntBuffer());
|
||||
break;
|
||||
case EncodingType.k1X_val:
|
||||
case EncodingType.k2X_val:
|
||||
@@ -793,10 +815,11 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource,
|
||||
public int getSamplesToAverage() {
|
||||
switch (m_encodingType.value) {
|
||||
case EncodingType.k4X_val:
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
int value = HALLibrary
|
||||
.getEncoderSamplesToAverage(m_encoder, status);
|
||||
HALUtil.checkStatus(status);
|
||||
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;
|
||||
case EncodingType.k1X_val:
|
||||
case EncodingType.k2X_val:
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.parsing.ISensor;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
|
||||
@@ -9,10 +9,11 @@ package edu.wpi.first.wpilibj;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -80,12 +81,12 @@ public class I2C extends SensorBase {
|
||||
ByteBuffer dataReceivedBuffer = ByteBuffer.allocate(1);
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
|
||||
aborted = HALLibrary
|
||||
aborted = I2CJNI
|
||||
.doI2CTransactionWithModule((byte) m_module.m_moduleNumber,
|
||||
(byte) m_deviceAddress, (byte) (m_compatibilityMode ? 1
|
||||
: 0), dataToSendBuffer, (byte) sendSize,
|
||||
dataReceivedBuffer, (byte) receiveSize, status) != 0;
|
||||
if (status.get() == HALLibrary.PARAMETER_OUT_OF_RANGE) {
|
||||
if (status.get() == HALUtil.PARAMETER_OUT_OF_RANGE) {
|
||||
if (sendSize > 6) {
|
||||
throw new BoundaryException(BoundaryException.getMessage(
|
||||
sendSize, 0, 6));
|
||||
|
||||
@@ -8,11 +8,10 @@
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.HALLibrary;
|
||||
import edu.wpi.first.wpilibj.hal.HALLibrary.InterruptHandlerFunction;
|
||||
import edu.wpi.first.wpilibj.hal.InterruptJNI;
|
||||
import edu.wpi.first.wpilibj.hal.InterruptJNI.InterruptHandlerFunction;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
|
||||
/**
|
||||
@@ -23,7 +22,7 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
/**
|
||||
* The interrupt resource
|
||||
*/
|
||||
protected Pointer m_interrupt;
|
||||
protected ByteBuffer m_interrupt;
|
||||
/**
|
||||
* The interrupt manager resource
|
||||
*/
|
||||
@@ -35,7 +34,7 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
/**
|
||||
* Resource manager
|
||||
*/
|
||||
protected static Resource interrupts = new Resource(HALLibrary.interrupt_kNumSystems.get());
|
||||
protected static Resource interrupts = new Resource(8);
|
||||
|
||||
/**
|
||||
* Create a new InterrupatableSensorBase
|
||||
@@ -57,7 +56,7 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
}
|
||||
// Expects the calling leaf class to allocate an interrupt index.
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
m_interrupt = HALLibrary.initializeInterrupts(m_interruptIndex,
|
||||
m_interrupt = InterruptJNI.initializeInterrupts(m_interruptIndex,
|
||||
(byte) (watcher ? 1 : 0), status);
|
||||
HALUtil.checkStatus(status);
|
||||
}
|
||||
@@ -71,7 +70,7 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.cleanInterrupts(m_interrupt, status);
|
||||
InterruptJNI.cleanInterrupts(m_interrupt, status);
|
||||
HALUtil.checkStatus(status);
|
||||
|
||||
}
|
||||
@@ -87,7 +86,7 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.waitForInterrupt(m_interrupt, (float) timeout, status);
|
||||
InterruptJNI.waitForInterrupt(m_interrupt, (float) timeout, status);
|
||||
HALUtil.checkStatus(status);
|
||||
}
|
||||
|
||||
@@ -101,7 +100,7 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.enableInterrupts(m_interrupt, status);
|
||||
InterruptJNI.enableInterrupts(m_interrupt, status);
|
||||
HALUtil.checkStatus(status);
|
||||
}
|
||||
|
||||
@@ -113,7 +112,7 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.disableInterrupts(m_interrupt, status);
|
||||
InterruptJNI.disableInterrupts(m_interrupt, status);
|
||||
HALUtil.checkStatus(status);
|
||||
}
|
||||
|
||||
@@ -128,7 +127,7 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
double timestamp = HALLibrary.readInterruptTimestamp(m_interrupt, status);
|
||||
double timestamp = InterruptJNI.readInterruptTimestamp(m_interrupt, status);
|
||||
HALUtil.checkStatus(status);
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary;
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tInstances;
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInstances;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
|
||||
@@ -94,7 +94,7 @@ public class IterativeRobot extends RobotBase {
|
||||
m_testInitialized = false;
|
||||
}
|
||||
if (nextPeriodReady()) {
|
||||
FRC_NetworkCommunicationsLibrary.FRC_NetworkCommunication_observeUserProgramDisabled();
|
||||
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramDisabled();
|
||||
disabledPeriodic();
|
||||
didDisabledPeriodic = true;
|
||||
}
|
||||
@@ -110,7 +110,7 @@ public class IterativeRobot extends RobotBase {
|
||||
m_disabledInitialized = false;
|
||||
}
|
||||
if (nextPeriodReady()) {
|
||||
FRC_NetworkCommunicationsLibrary.FRC_NetworkCommunication_observeUserProgramTest();
|
||||
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramTest();
|
||||
testPeriodic();
|
||||
didTestPeriodic = true;
|
||||
}
|
||||
@@ -129,7 +129,8 @@ public class IterativeRobot extends RobotBase {
|
||||
m_disabledInitialized = false;
|
||||
}
|
||||
if (nextPeriodReady()) {
|
||||
FRC_NetworkCommunicationsLibrary.FRC_NetworkCommunication_observeUserProgramAutonomous();
|
||||
getWatchdog().feed();
|
||||
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramAutonomous();
|
||||
autonomousPeriodic();
|
||||
didAutonomousPeriodic = true;
|
||||
}
|
||||
@@ -145,7 +146,8 @@ public class IterativeRobot extends RobotBase {
|
||||
m_disabledInitialized = false;
|
||||
}
|
||||
if (nextPeriodReady()) {
|
||||
FRC_NetworkCommunicationsLibrary.FRC_NetworkCommunication_observeUserProgramTeleop();
|
||||
getWatchdog().feed();
|
||||
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramTeleop();
|
||||
teleopPeriodic();
|
||||
didTeleopPeriodic = true;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.parsing.IDeviceController;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.parsing.IInputOutput;
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary;
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tModuleType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tModuleType;
|
||||
|
||||
/**
|
||||
* Base class for AnalogModule and DigitalModule.
|
||||
@@ -20,7 +20,7 @@ public class Module extends SensorBase {
|
||||
/**
|
||||
* An array holding the object representing each module
|
||||
*/
|
||||
protected static Module[] m_modules = new Module[tModuleType.kModuleType_Solenoid * FRC_NetworkCommunicationsLibrary.kMaxModuleNumber + (FRC_NetworkCommunicationsLibrary.kMaxModuleNumber - 1)];
|
||||
protected static Module[] m_modules = new Module[tModuleType.kModuleType_Solenoid * FRCNetworkCommunicationsLibrary.kMaxModuleNumber + (FRCNetworkCommunicationsLibrary.kMaxModuleNumber - 1)];
|
||||
/**
|
||||
* The module number of the module
|
||||
*/
|
||||
@@ -86,8 +86,8 @@ public class Module extends SensorBase {
|
||||
* @return The index into m_modules.
|
||||
*/
|
||||
private static int toIndex(int moduleType, int moduleNumber) {
|
||||
if(moduleNumber == 0 || moduleNumber > FRC_NetworkCommunicationsLibrary.kMaxModuleNumber)
|
||||
if(moduleNumber == 0 || moduleNumber > FRCNetworkCommunicationsLibrary.kMaxModuleNumber)
|
||||
return 0;
|
||||
return moduleType * FRC_NetworkCommunicationsLibrary.kMaxModuleNumber + (moduleNumber - 1);
|
||||
return moduleType * FRCNetworkCommunicationsLibrary.kMaxModuleNumber + (moduleNumber - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.util.TimerTask;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
import edu.wpi.first.wpilibj.parsing.IUtility;
|
||||
@@ -201,7 +201,7 @@ public class PIDController implements IUtility, LiveWindowSendable, Controller {
|
||||
* This should only be called by the PIDTask
|
||||
* and is created during initialization.
|
||||
*/
|
||||
protected void calculate() {
|
||||
private void calculate() {
|
||||
boolean enabled;
|
||||
PIDSource pidInput;
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
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.PWMJNI;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
import edu.wpi.first.wpilibj.tables.ITable;
|
||||
import edu.wpi.first.wpilibj.tables.ITableListener;
|
||||
@@ -39,7 +39,7 @@ public class PWM extends SensorBase implements LiveWindowSendable {
|
||||
* tests running for the first time.
|
||||
*/
|
||||
|
||||
private static Resource allocated = new Resource((HALLibrary.dio_kNumSystems.get() * kPwmChannels));
|
||||
private static Resource allocated = new Resource( kPwmChannels);
|
||||
|
||||
/**
|
||||
* Represents the amount to multiply the minimum servo-pulse pwm period by.
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.io.OutputStream;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.networktables.NetworkTable;
|
||||
import edu.wpi.first.wpilibj.tables.ITable;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
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.livewindow.LiveWindow;
|
||||
@@ -122,8 +122,7 @@ public class Relay extends SensorBase implements IDeviceController,
|
||||
private int m_channel;
|
||||
private Direction m_direction;
|
||||
private DigitalModule m_module;
|
||||
private static Resource relayChannels = new Resource(
|
||||
HALLibrary.dio_kNumSystems.get() * kRelayChannels * 2);
|
||||
private static Resource relayChannels = new Resource(kRelayChannels * 2);
|
||||
|
||||
/**
|
||||
* Common relay initialization method. This code is common to all Relay
|
||||
|
||||
@@ -108,4 +108,5 @@ public class Resource {
|
||||
throw new AllocationException("No resource available to be freed");
|
||||
m_numAllocated[index] = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,14 +9,16 @@ package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.Enumeration;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary;
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tInstances;
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInstances;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.hal.HALLibrary;
|
||||
import edu.wpi.first.wpilibj.networktables.NetworkTable;
|
||||
|
||||
/**
|
||||
@@ -39,6 +41,7 @@ public abstract class RobotBase {
|
||||
public final static String ERRORS_TO_DRIVERSTATION_PROP = "first.driverstation.senderrors";
|
||||
|
||||
protected final DriverStation m_ds;
|
||||
private final Watchdog m_watchdog = Watchdog.getInstance();
|
||||
|
||||
/**
|
||||
* Constructor for a generic robot program.
|
||||
@@ -58,6 +61,7 @@ public abstract class RobotBase {
|
||||
// }
|
||||
NetworkTable.setServerMode();//must be before b
|
||||
m_ds = DriverStation.getInstance();
|
||||
m_watchdog.setEnabled(false);
|
||||
NetworkTable.getTable(""); // forces network tables to initialize
|
||||
NetworkTable.getTable("LiveWindow").getSubTable("~STATUS~").putBoolean("LW Enabled", false);
|
||||
}
|
||||
@@ -69,13 +73,23 @@ public abstract class RobotBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This has been deprecated in favor of {@link #isEnabled()}
|
||||
* Check on the overall status of the system.
|
||||
*
|
||||
* @return Is the system active (i.e. PWM motor outputs, etc. enabled)?
|
||||
*/
|
||||
public boolean isSystemActive() {
|
||||
return isEnabled();
|
||||
return m_watchdog.isSystemActive();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the instance of the Watchdog timer.
|
||||
* Get the watchdog timer so the user program can either disable it or feed it when
|
||||
* necessary.
|
||||
*
|
||||
* @return The Watchdog timer.
|
||||
*/
|
||||
public Watchdog getWatchdog() {
|
||||
return m_watchdog;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,9 +166,108 @@ public abstract class RobotBase {
|
||||
*/
|
||||
public static void main(String args[]) { // TODO: expose main to teams?{
|
||||
boolean errorOnExit = false;
|
||||
|
||||
/* JNI Testing */
|
||||
boolean booleanTest = true;
|
||||
byte byteTest = (byte)0xa5;
|
||||
char charTest = 'X';
|
||||
short shortTest = 12346;
|
||||
int intTest = 2987654;
|
||||
long longTest = 897678665;
|
||||
float floatTest = 45.123456f;
|
||||
double doubleTest = 234E16;
|
||||
|
||||
FRCNetworkCommunicationsLibrary.JNIValueParameterTest(booleanTest, byteTest, charTest, shortTest,
|
||||
intTest, longTest, floatTest, doubleTest);
|
||||
|
||||
boolean booleanReturn = FRCNetworkCommunicationsLibrary.JNIValueReturnBooleanTest(booleanTest);
|
||||
System.out.println("Boolean Return: " + booleanReturn );
|
||||
|
||||
HALLibrary.FRC_NetworkCommunication_Reserve();
|
||||
FRC_NetworkCommunicationsLibrary.FRC_NetworkCommunication_observeUserProgramStarting();
|
||||
byte byteReturn = FRCNetworkCommunicationsLibrary.JNIValueReturnByteTest(byteTest);
|
||||
System.out.println("Byte Return: " + byteReturn );
|
||||
|
||||
char charReturn = FRCNetworkCommunicationsLibrary.JNIValueReturnCharTest(charTest);
|
||||
System.out.println("Char Return: " + charReturn );
|
||||
|
||||
short shortReturn = FRCNetworkCommunicationsLibrary.JNIValueReturnShortTest(shortTest);
|
||||
System.out.println("Short Return: " + shortReturn );
|
||||
|
||||
int intReturn = FRCNetworkCommunicationsLibrary.JNIValueReturnIntTest(intTest);
|
||||
System.out.println("Int Return: " + intReturn );
|
||||
|
||||
long longReturn = FRCNetworkCommunicationsLibrary.JNIValueReturnLongTest(longTest);
|
||||
System.out.println("Long Return: " + longReturn );
|
||||
|
||||
float floatReturn = FRCNetworkCommunicationsLibrary.JNIValueReturnFloatTest(floatTest);
|
||||
System.out.println("Float Return: " + floatReturn );
|
||||
|
||||
double doubleReturn = FRCNetworkCommunicationsLibrary.JNIValueReturnDoubleTest(doubleTest);
|
||||
System.out.println("Double Return: " + doubleReturn );
|
||||
|
||||
|
||||
|
||||
String testValue = "This is a test string";
|
||||
|
||||
String returnValue = FRCNetworkCommunicationsLibrary.JNIObjectReturnStringTest(testValue);
|
||||
|
||||
System.out.println("String Return:" + returnValue);
|
||||
|
||||
ByteBuffer directBuffer = ByteBuffer.allocateDirect(4);
|
||||
|
||||
directBuffer.put(0, (byte)0xFA);
|
||||
directBuffer.put(1, (byte)0xAB);
|
||||
directBuffer.put(2, (byte)0xB4);
|
||||
directBuffer.put(3, (byte)0xCD);
|
||||
|
||||
ByteBuffer returnBuffer1 = FRCNetworkCommunicationsLibrary.JNIObjectReturnByteBufferTest(directBuffer);
|
||||
|
||||
System.out.println("Return Buffer Capacity: " + returnBuffer1.capacity());
|
||||
System.out.println("ByteBuffer1 Return0: " + returnBuffer1.get(0) );
|
||||
System.out.println("ByteBuffer1 Return1: " + returnBuffer1.get(1) );
|
||||
System.out.println("ByteBuffer1 Return2: " + returnBuffer1.get(2) );
|
||||
System.out.println("ByteBuffer1 Return3: " + returnBuffer1.get(3) );
|
||||
|
||||
|
||||
ByteBuffer directByteBuffer = ByteBuffer.allocateDirect(4);
|
||||
// set to little endian for C++
|
||||
directByteBuffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
directByteBuffer.putInt(0,2874933);
|
||||
|
||||
System.out.println("Param In: " + directByteBuffer.getInt(0));
|
||||
System.out.println("Param In Byte0: " + directByteBuffer.get(0) );
|
||||
System.out.println("Param In Byte1: " + directByteBuffer.get(1) );
|
||||
System.out.println("Param In Byte2: " + directByteBuffer.get(2) );
|
||||
System.out.println("Param In Byte3: " + directByteBuffer.get(3) );
|
||||
|
||||
|
||||
ByteBuffer returnBuffer2 = FRCNetworkCommunicationsLibrary.JNIObjectAndParamReturnIntBufferTest(directByteBuffer.asIntBuffer());
|
||||
|
||||
System.out.println("Param Out: " + directByteBuffer.getInt(0));
|
||||
|
||||
|
||||
|
||||
System.out.println("Return Buffer Capacity: " + returnBuffer2.capacity());
|
||||
System.out.println("ByteBuffer2 Return0: " + returnBuffer2.get(0) );
|
||||
System.out.println("ByteBuffer2 Return1: " + returnBuffer2.get(1) );
|
||||
System.out.println("ByteBuffer2 Return2: " + returnBuffer2.get(2) );
|
||||
System.out.println("ByteBuffer2 Return3: " + returnBuffer2.get(3) );
|
||||
|
||||
System.out.println("Byte Order from C++" + returnBuffer2.order().toString());
|
||||
System.out.println("ByteBuffer2 as Int" + returnBuffer2.getInt(0));
|
||||
// change to little endian
|
||||
returnBuffer2.order(ByteOrder.LITTLE_ENDIAN);
|
||||
System.out.println("ByteBuffer2 as Int" + returnBuffer2.getInt(0));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* End JNI Testing */
|
||||
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationReserve();
|
||||
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramStarting();
|
||||
Watchdog.getInstance().setExpiration(0.1);
|
||||
Watchdog.getInstance().setEnabled(false);
|
||||
|
||||
UsageReporting.report(tResourceType.kResourceType_Language, tInstances.kLanguage_Java);
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.can.CANNotInitializedException;
|
||||
import edu.wpi.first.wpilibj.can.CANTimeoutException;
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tInstances;
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInstances;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.parsing.IUtility;
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.HALLibrary;
|
||||
import edu.wpi.first.wpilibj.hal.DIOJNI;
|
||||
import edu.wpi.first.wpilibj.hal.AnalogJNI;
|
||||
|
||||
/**
|
||||
* Base class for all sensors.
|
||||
@@ -27,20 +28,20 @@ public abstract class SensorBase { // TODO: Refactor
|
||||
/**
|
||||
* Number of digital channels per digital sidecar
|
||||
*/
|
||||
public static final int kDigitalChannels = 14;
|
||||
public static final int kDigitalChannels = 10;
|
||||
/**
|
||||
* Number of digital modules
|
||||
* XXX: This number is incorrect. We need to find the correct number.
|
||||
*/
|
||||
public static final int kDigitalModules = 2;
|
||||
public static final int kDigitalModules = 1;
|
||||
/**
|
||||
* Number of analog channels per module
|
||||
*/
|
||||
public static final int kAnalogChannels = 8;
|
||||
public static final int kAnalogChannels = 4;
|
||||
/**
|
||||
* Number of analog modules
|
||||
*/
|
||||
public static final int kAnalogModules = 2;
|
||||
public static final int kAnalogModules = 1;
|
||||
/**
|
||||
* Number of solenoid channels per module
|
||||
*/
|
||||
@@ -56,7 +57,7 @@ public abstract class SensorBase { // TODO: Refactor
|
||||
/**
|
||||
* Number of relay channels per sidecar
|
||||
*/
|
||||
public static final int kRelayChannels = 8;
|
||||
public static final int kRelayChannels = 4;
|
||||
|
||||
private static int m_defaultAnalogModule = 1;
|
||||
private static int m_defaultDigitalModule = 1;
|
||||
@@ -111,7 +112,7 @@ public abstract class SensorBase { // TODO: Refactor
|
||||
* @param moduleNumber The digital module module number to check.
|
||||
*/
|
||||
protected static void checkDigitalModule(final int moduleNumber) {
|
||||
if(HALLibrary.checkDigitalModule((byte) moduleNumber) != 1)
|
||||
if(DIOJNI.checkDigitalModule((byte) moduleNumber) != 1)
|
||||
System.err.println("Digital module " + moduleNumber + " is not present.");
|
||||
}
|
||||
|
||||
@@ -142,7 +143,7 @@ public abstract class SensorBase { // TODO: Refactor
|
||||
* @param moduleNumber The analog module module number to check.
|
||||
*/
|
||||
protected static void checkAnalogModule(final int moduleNumber) {
|
||||
if(HALLibrary.checkAnalogModule((byte) (moduleNumber - 1)) != 0) {
|
||||
if(AnalogJNI.checkAnalogModule((byte) (moduleNumber - 1)) != 0) {
|
||||
System.err.println("Analog module " + moduleNumber + " is not present.");
|
||||
}
|
||||
}
|
||||
@@ -154,9 +155,9 @@ public abstract class SensorBase { // TODO: Refactor
|
||||
* @param moduleNumber The solenoid module module number to check.
|
||||
*/
|
||||
protected static void checkSolenoidModule(final int moduleNumber) {
|
||||
if(HALLibrary.checkSolenoidModule((byte) (moduleNumber - 1)) != 0) {
|
||||
System.err.println("Solenoid module " + moduleNumber + " is not present.");
|
||||
}
|
||||
// if(HALLibrary.checkSolenoidModule((byte) (moduleNumber - 1)) != 0) {
|
||||
// System.err.println("Solenoid module " + moduleNumber + " is not present.");
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.parsing.IDevice;
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tInstances;
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInstances;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,12 +8,10 @@
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
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.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
@@ -31,30 +29,30 @@ import edu.wpi.first.wpilibj.util.CheckedAllocationException;
|
||||
public class Solenoid extends SolenoidBase implements LiveWindowSendable {
|
||||
|
||||
private int m_channel; ///< The channel on the module to control.
|
||||
private Pointer m_port;
|
||||
private ByteBuffer m_port;
|
||||
|
||||
/**
|
||||
* Common function to implement constructor behavior.
|
||||
*/
|
||||
private synchronized void initSolenoid() {
|
||||
checkSolenoidModule(m_moduleNumber);
|
||||
checkSolenoidChannel(m_channel);
|
||||
|
||||
try {
|
||||
m_allocated.allocate((m_moduleNumber - 1) * kSolenoidChannels + m_channel - 1);
|
||||
} catch (CheckedAllocationException e) {
|
||||
throw new AllocationException(
|
||||
"Solenoid channel " + m_channel + " on module " + m_moduleNumber + " is already allocated");
|
||||
}
|
||||
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
m_port = HALLibrary.getPortWithModule((byte) m_moduleNumber, (byte) m_channel);
|
||||
HALUtil.checkStatus(status);
|
||||
HALLibrary.initializeSolenoidPort(m_port, status);
|
||||
HALUtil.checkStatus(status);
|
||||
|
||||
LiveWindow.addActuator("Solenoid", m_moduleNumber, m_channel, this);
|
||||
UsageReporting.report(tResourceType.kResourceType_Solenoid, m_channel, m_moduleNumber - 1);
|
||||
// checkSolenoidModule(m_moduleNumber);
|
||||
// checkSolenoidChannel(m_channel);
|
||||
//
|
||||
// try {
|
||||
// m_allocated.allocate((m_moduleNumber - 1) * kSolenoidChannels + m_channel - 1);
|
||||
// } catch (CheckedAllocationException e) {
|
||||
// throw new AllocationException(
|
||||
// "Solenoid channel " + m_channel + " on module " + m_moduleNumber + " is already allocated");
|
||||
// }
|
||||
//
|
||||
// IntBuffer status = IntBuffer.allocate(1);
|
||||
// m_port = SolenoidJNI.getPortWithModule((byte) m_moduleNumber, (byte) m_channel);
|
||||
// HALUtil.checkStatus(status);
|
||||
// SolenoidJNI.initializeSolenoidPort(m_port, status);
|
||||
// HALUtil.checkStatus(status);
|
||||
//
|
||||
// LiveWindow.addActuator("Solenoid", m_moduleNumber, m_channel, this);
|
||||
// UsageReporting.report(tResourceType.kResourceType_Solenoid, m_channel, m_moduleNumber - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,7 +82,7 @@ public class Solenoid extends SolenoidBase implements LiveWindowSendable {
|
||||
* Destructor.
|
||||
*/
|
||||
public synchronized void free() {
|
||||
m_allocated.free((m_moduleNumber - 1) * kSolenoidChannels + m_channel - 1);
|
||||
// m_allocated.free((m_moduleNumber - 1) * kSolenoidChannels + m_channel - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,9 +91,9 @@ public class Solenoid extends SolenoidBase implements LiveWindowSendable {
|
||||
* @param on Turn the solenoid output off or on.
|
||||
*/
|
||||
public void set(boolean on) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
HALLibrary.setSolenoid(m_port, (byte) (on ? 1 : 0), status);
|
||||
HALUtil.checkStatus(status);
|
||||
// IntBuffer status = IntBuffer.allocate(1);
|
||||
// SolenoidJNI.setSolenoid(m_port, (byte) (on ? 1 : 0), status);
|
||||
// HALUtil.checkStatus(status);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,9 +102,10 @@ public class Solenoid extends SolenoidBase implements LiveWindowSendable {
|
||||
* @return The current value of the solenoid.
|
||||
*/
|
||||
public boolean get() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
boolean value = HALLibrary.getSolenoid(m_port, status) != 0;
|
||||
HALUtil.checkStatus(status);
|
||||
boolean value = false;
|
||||
// IntBuffer status = IntBuffer.allocate(1);
|
||||
// boolean value = SolenoidJNI.getSolenoid(m_port, status) != 0;
|
||||
// HALUtil.checkStatus(status);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,10 +8,8 @@
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.HALLibrary;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.parsing.IDeviceController;
|
||||
|
||||
@@ -21,10 +19,10 @@ import edu.wpi.first.wpilibj.parsing.IDeviceController;
|
||||
*/
|
||||
public abstract class SolenoidBase extends SensorBase implements IDeviceController {
|
||||
|
||||
private Pointer[] m_ports;
|
||||
private ByteBuffer[] m_ports;
|
||||
protected int m_moduleNumber; ///< The number of the solenoid module being used.
|
||||
// XXX: Move this to be both HAL calls
|
||||
protected Resource m_allocated = new Resource(HALLibrary.solenoid_kNumDO7_0Elements.get() * SensorBase.kSolenoidChannels);
|
||||
//protected Resource m_allocated = new Resource(SolenoidJNI.getModuleCount() * SensorBase.kSolenoidChannels);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -32,14 +30,14 @@ public abstract class SolenoidBase extends SensorBase implements IDeviceControll
|
||||
* @param moduleNumber The number of the solenoid module to use.
|
||||
*/
|
||||
public SolenoidBase(final int moduleNumber) {
|
||||
m_moduleNumber = moduleNumber;
|
||||
m_ports = new Pointer[SensorBase.kSolenoidChannels];
|
||||
for (int i = 0; i < SensorBase.kSolenoidChannels; i++) {
|
||||
Pointer port = HALLibrary.getPortWithModule((byte) moduleNumber, (byte) (i+1));
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
m_ports[i] = HALLibrary.initializeSolenoidPort(port, status);
|
||||
HALUtil.checkStatus(status);
|
||||
}
|
||||
// m_moduleNumber = moduleNumber;
|
||||
// m_ports = new ByteBuffer[SensorBase.kSolenoidChannels];
|
||||
// for (int i = 0; i < SensorBase.kSolenoidChannels; i++) {
|
||||
// ByteBuffer port = SolenoidJNI.getPortWithModule((byte) moduleNumber, (byte) (i+1));
|
||||
// IntBuffer status = IntBuffer.allocate(1);
|
||||
// m_ports[i] = SolenoidJNI.initializeSolenoidPort(port, status);
|
||||
// HALUtil.checkStatus(status);
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,13 +47,13 @@ public abstract class SolenoidBase extends SensorBase implements IDeviceControll
|
||||
* @param mask The channels you want to be affected.
|
||||
*/
|
||||
protected synchronized void set(int value, int mask) {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
for (int i = 0; i < SensorBase.kSolenoidChannels; i++) {
|
||||
int local_mask = 1 << i;
|
||||
if ((mask & local_mask) != 0)
|
||||
HALLibrary.setSolenoid(m_ports[i], (byte) (value & local_mask), status);
|
||||
}
|
||||
HALUtil.checkStatus(status);
|
||||
// IntBuffer status = IntBuffer.allocate(1);
|
||||
// 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);
|
||||
// }
|
||||
// HALUtil.checkStatus(status);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,11 +63,11 @@ public abstract class SolenoidBase extends SensorBase implements IDeviceControll
|
||||
*/
|
||||
public byte getAll() {
|
||||
byte value = 0;
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
for (int i = 0; i < SensorBase.kSolenoidChannels; i++) {
|
||||
value |= HALLibrary.getSolenoid(m_ports[i], status) << i;
|
||||
}
|
||||
HALUtil.checkStatus(status);
|
||||
// IntBuffer status = IntBuffer.allocate(1);
|
||||
// for (int i = 0; i < SensorBase.kSolenoidChannels; i++) {
|
||||
// value |= SolenoidJNI.getSolenoid(m_ports[i], status) << i;
|
||||
// }
|
||||
// HALUtil.checkStatus(status);
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -88,7 +86,9 @@ public abstract class SolenoidBase extends SensorBase implements IDeviceControll
|
||||
* @return The current value of all 8 solenoids on the specified module.
|
||||
*/
|
||||
public static byte getAllFromModule(int moduleNumber) {
|
||||
checkSolenoidModule(moduleNumber);
|
||||
throw new RuntimeException("Not supported right now.");
|
||||
byte value = 0;
|
||||
// checkSolenoidModule(moduleNumber);
|
||||
// throw new RuntimeException("Not supported right now.");
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.parsing.IDeviceController;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.HALLibrary;
|
||||
@@ -27,9 +29,11 @@ public class Utility implements IUtility {
|
||||
* @return FPGA Version number.
|
||||
*/
|
||||
int getFPGAVersion() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
int value = HALLibrary.getFPGAVersion(status);
|
||||
HALUtil.checkStatus(status);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -41,9 +45,11 @@ public class Utility implements IUtility {
|
||||
* @return FPGA Revision number.
|
||||
*/
|
||||
long getFPGARevision() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
int value = HALLibrary.getFPGARevision(status);
|
||||
HALUtil.checkStatus(status);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -53,10 +59,13 @@ public class Utility implements IUtility {
|
||||
* @return The current time in microseconds according to the FPGA.
|
||||
*/
|
||||
public static long getFPGATime() {
|
||||
IntBuffer status = IntBuffer.allocate(1);
|
||||
int value = HALLibrary.getFPGATime(status);
|
||||
HALUtil.checkStatus(status);
|
||||
return (long) value;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.parsing.IDeviceController;
|
||||
|
||||
@@ -12,8 +12,8 @@ import java.util.Vector;
|
||||
|
||||
import edu.wpi.first.wpilibj.NamedSendable;
|
||||
import edu.wpi.first.wpilibj.buttons.Trigger.ButtonScheduler;
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tInstances;
|
||||
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInstances;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.networktables2.type.NumberArray;
|
||||
import edu.wpi.first.wpilibj.networktables2.type.StringArray;
|
||||
|
||||
@@ -1,36 +1,33 @@
|
||||
package edu.wpi.first.wpilibj.communication;
|
||||
import com.ochafik.lang.jnaerator.runtime.Structure;
|
||||
import com.ochafik.lang.jnaerator.runtime.Union;
|
||||
//import com.ochafik.lang.jnaerator.runtime.Structure;
|
||||
//import com.ochafik.lang.jnaerator.runtime.Union;
|
||||
//import com.sun.jna.Pointer;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
/**
|
||||
* <i>native declaration : /home/alex/Projects/WPILib-Development/WPILibC/WPILib/src/main/include/NetworkCommunication/FRCComm.h:29</i><br>
|
||||
* <i>native declaration : src\main\include\NetworkCommunication\FRCComm.h:11</i><br>
|
||||
* This file was autogenerated by <a href="http://jnaerator.googlecode.com/">JNAerator</a>,<br>
|
||||
* a tool written by <a href="http://ochafik.com/">Olivier Chafik</a> that <a href="http://code.google.com/p/jnaerator/wiki/CreditsAndLicense">uses a few opensource projects.</a>.<br>
|
||||
* For help, please visit <a href="http://nativelibs4java.googlecode.com/">NativeLibs4Java</a> , <a href="http://rococoa.dev.java.net/">Rococoa</a>, or <a href="http://jna.dev.java.net/">JNA</a>.
|
||||
*/
|
||||
public class FRCCommonControlData extends Structure<FRCCommonControlData, FRCCommonControlData.ByValue, FRCCommonControlData.ByReference > {
|
||||
public class FRCCommonControlData /*extends Structure<FRCCommonControlData, FRCCommonControlData.ByValue, FRCCommonControlData.ByReference >*/ {
|
||||
public short packetIndex;
|
||||
/** C type : field1_union */
|
||||
public field1_union field1;
|
||||
public byte control;
|
||||
public byte dsDigitalIn;
|
||||
public short teamID;
|
||||
public byte dsID_Alliance;
|
||||
public byte dsID_Position;
|
||||
/** C type : field2_union */
|
||||
public field2_union field2;
|
||||
public byte[] stick0Axes = new byte[6];
|
||||
/** Left-most 4 bits are unused */
|
||||
public short stick0Buttons;
|
||||
/** C type : field3_union */
|
||||
public field3_union field3;
|
||||
public byte[] stick1Axes = new byte[6];
|
||||
/** Left-most 4 bits are unused */
|
||||
public short stick1Buttons;
|
||||
/** C type : field4_union */
|
||||
public field4_union field4;
|
||||
public byte[] stick2Axes = new byte[6];
|
||||
/** Left-most 4 bits are unused */
|
||||
public short stick2Buttons;
|
||||
/** C type : field5_union */
|
||||
public field5_union field5;
|
||||
public byte[] stick3Axes = new byte[6];
|
||||
/** Left-most 4 bits are unused */
|
||||
public short stick3Buttons;
|
||||
/** Analog inputs are 10 bit right-justified */
|
||||
@@ -45,38 +42,76 @@ public class FRCCommonControlData extends Structure<FRCCommonControlData, FRCCom
|
||||
public int FPGAChecksum3;
|
||||
/** C type : char[8] */
|
||||
public byte[] versionData = new byte[8];
|
||||
/** <i>native declaration : /home/alex/Projects/WPILib-Development/WPILibC/WPILib/src/main/include/NetworkCommunication/FRCComm.h:31</i> */
|
||||
public static class field1_union extends Union<field1_union, field1_union.ByValue, field1_union.ByReference > {
|
||||
|
||||
/** <i>native declaration : src\main\include\NetworkCommunication\FRCComm.h:13</i> */
|
||||
public static class field1_union /*extends Union<field1_union, field1_union.ByValue, field1_union.ByReference >*/ {
|
||||
public byte control;
|
||||
/** C type : field1_struct */
|
||||
public field1_struct field1;
|
||||
/** <i>native declaration : src\main\include\NetworkCommunication\FRCComm.h:16</i> */
|
||||
public static abstract class field1_struct /*extends Structure<field1_struct, field1_struct.ByValue, field1_struct.ByReference >*/ {
|
||||
/** Conversion Error : checkVersions:1 (This runtime does not support bit fields : JNAerator (based on JNA) (please use BridJ instead)) */
|
||||
/** Conversion Error : test:1 (This runtime does not support bit fields : JNAerator (based on JNA) (please use BridJ instead)) */
|
||||
/** Conversion Error : resync:1 (This runtime does not support bit fields : JNAerator (based on JNA) (please use BridJ instead)) */
|
||||
/** Conversion Error : fmsAttached:1 (This runtime does not support bit fields : JNAerator (based on JNA) (please use BridJ instead)) */
|
||||
/** Conversion Error : autonomous:1 (This runtime does not support bit fields : JNAerator (based on JNA) (please use BridJ instead)) */
|
||||
/** Conversion Error : enabled:1 (This runtime does not support bit fields : JNAerator (based on JNA) (please use BridJ instead)) */
|
||||
/** Conversion Error : notEStop:1 (This runtime does not support bit fields : JNAerator (based on JNA) (please use BridJ instead)) */
|
||||
/** Conversion Error : reset:1 (This runtime does not support bit fields : JNAerator (based on JNA) (please use BridJ instead)) */
|
||||
public field1_struct() {
|
||||
super();
|
||||
}
|
||||
protected List<? > getFieldOrder() {
|
||||
return Arrays.asList();
|
||||
}
|
||||
//public field1_struct(Pointer peer) {
|
||||
// super(peer);
|
||||
//}
|
||||
//public static abstract class ByReference extends field1_struct implements Structure.ByReference {
|
||||
|
||||
//};
|
||||
//public static abstract class ByValue extends field1_struct implements Structure.ByValue {
|
||||
|
||||
//};
|
||||
};
|
||||
public field1_union() {
|
||||
super();
|
||||
}
|
||||
/** @param field1 C type : field1_struct */
|
||||
public field1_union(field1_struct field1) {
|
||||
super();
|
||||
this.field1 = field1;
|
||||
//setType(field1_struct.class);
|
||||
}
|
||||
public field1_union(byte control) {
|
||||
super();
|
||||
this.control = control;
|
||||
setType(Byte.TYPE);
|
||||
//setType(Byte.TYPE);
|
||||
}
|
||||
protected ByReference newByReference() { return new ByReference(); }
|
||||
protected ByValue newByValue() { return new ByValue(); }
|
||||
//public field1_union(Pointer peer) {
|
||||
// super(peer);
|
||||
//}
|
||||
//protected ByReference newByReference() { return new ByReference(); }
|
||||
//protected ByValue newByValue() { return new ByValue(); }
|
||||
protected field1_union newInstance() { return new field1_union(); }
|
||||
public static field1_union[] newArray(int arrayLength) {
|
||||
return Union.newArray(field1_union.class, arrayLength);
|
||||
}
|
||||
public static class ByReference extends field1_union implements Structure.ByReference {
|
||||
//public static field1_union[] newArray(int arrayLength) {
|
||||
// return Union.newArray(field1_union.class, arrayLength);
|
||||
//}
|
||||
//public static class ByReference extends field1_union implements Structure.ByReference {
|
||||
|
||||
};
|
||||
public static class ByValue extends field1_union implements Structure.ByValue {
|
||||
//};
|
||||
//public static class ByValue extends field1_union implements Structure.ByValue {
|
||||
|
||||
};
|
||||
//};
|
||||
};
|
||||
/** <i>native declaration : /home/alex/Projects/WPILib-Development/WPILibC/WPILib/src/main/include/NetworkCommunication/FRCComm.h:63</i> */
|
||||
public static class field2_union extends Union<field2_union, field2_union.ByValue, field2_union.ByReference > {
|
||||
/** <i>native declaration : src\main\include\NetworkCommunication\FRCComm.h:45</i> */
|
||||
public static class field2_union /*extends Union<field2_union, field2_union.ByValue, field2_union.ByReference >*/ {
|
||||
/** C type : int8_t[6] */
|
||||
public byte[] stick0Axes = new byte[6];
|
||||
/** C type : field1_struct */
|
||||
public field1_struct field1;
|
||||
/** <i>native declaration : /home/alex/Projects/WPILib-Development/WPILibC/WPILib/src/main/include/NetworkCommunication/FRCComm.h:65</i> */
|
||||
public static class field1_struct extends Structure<field1_struct, field1_struct.ByValue, field1_struct.ByReference > {
|
||||
/** <i>native declaration : src\main\include\NetworkCommunication\FRCComm.h:47</i> */
|
||||
public static class field1_struct /*extends Structure<field1_struct, field1_struct.ByValue, field1_struct.ByReference >*/ {
|
||||
public byte stick0Axis1;
|
||||
public byte stick0Axis2;
|
||||
public byte stick0Axis3;
|
||||
@@ -98,18 +133,21 @@ public class FRCCommonControlData extends Structure<FRCCommonControlData, FRCCom
|
||||
this.stick0Axis5 = stick0Axis5;
|
||||
this.stick0Axis6 = stick0Axis6;
|
||||
}
|
||||
protected ByReference newByReference() { return new ByReference(); }
|
||||
protected ByValue newByValue() { return new ByValue(); }
|
||||
//public field1_struct(Pointer peer) {
|
||||
// super(peer);
|
||||
//}
|
||||
//protected ByReference newByReference() { return new ByReference(); }
|
||||
//protected ByValue newByValue() { return new ByValue(); }
|
||||
protected field1_struct newInstance() { return new field1_struct(); }
|
||||
public static field1_struct[] newArray(int arrayLength) {
|
||||
return Structure.newArray(field1_struct.class, arrayLength);
|
||||
}
|
||||
public static class ByReference extends field1_struct implements Structure.ByReference {
|
||||
//public static field1_struct[] newArray(int arrayLength) {
|
||||
// return Structure.newArray(field1_struct.class, arrayLength);
|
||||
//}
|
||||
//public static class ByReference extends field1_struct implements Structure.ByReference {
|
||||
|
||||
};
|
||||
public static class ByValue extends field1_struct implements Structure.ByValue {
|
||||
//};
|
||||
//public static class ByValue extends field1_struct implements Structure.ByValue {
|
||||
|
||||
};
|
||||
//};
|
||||
};
|
||||
public field2_union() {
|
||||
super();
|
||||
@@ -118,7 +156,7 @@ public class FRCCommonControlData extends Structure<FRCCommonControlData, FRCCom
|
||||
public field2_union(field1_struct field1) {
|
||||
super();
|
||||
this.field1 = field1;
|
||||
setType(field1_struct.class);
|
||||
//setType(field1_struct.class);
|
||||
}
|
||||
/** @param stick0Axes C type : int8_t[6] */
|
||||
public field2_union(byte stick0Axes[]) {
|
||||
@@ -126,29 +164,32 @@ public class FRCCommonControlData extends Structure<FRCCommonControlData, FRCCom
|
||||
if ((stick0Axes.length != this.stick0Axes.length))
|
||||
throw new IllegalArgumentException("Wrong array size !");
|
||||
this.stick0Axes = stick0Axes;
|
||||
setType(byte[].class);
|
||||
//setType(byte[].class);
|
||||
}
|
||||
protected ByReference newByReference() { return new ByReference(); }
|
||||
protected ByValue newByValue() { return new ByValue(); }
|
||||
//public field2_union(Pointer peer) {
|
||||
// super(peer);
|
||||
//}
|
||||
//protected ByReference newByReference() { return new ByReference(); }
|
||||
//protected ByValue newByValue() { return new ByValue(); }
|
||||
protected field2_union newInstance() { return new field2_union(); }
|
||||
public static field2_union[] newArray(int arrayLength) {
|
||||
return Union.newArray(field2_union.class, arrayLength);
|
||||
}
|
||||
public static class ByReference extends field2_union implements Structure.ByReference {
|
||||
//public static field2_union[] newArray(int arrayLength) {
|
||||
// return Union.newArray(field2_union.class, arrayLength);
|
||||
//}
|
||||
//public static class ByReference extends field2_union implements Structure.ByReference {
|
||||
|
||||
};
|
||||
public static class ByValue extends field2_union implements Structure.ByValue {
|
||||
//};
|
||||
//public static class ByValue extends field2_union implements Structure.ByValue {
|
||||
|
||||
};
|
||||
//};
|
||||
};
|
||||
/** <i>native declaration : /home/alex/Projects/WPILib-Development/WPILibC/WPILib/src/main/include/NetworkCommunication/FRCComm.h:76</i> */
|
||||
public static class field3_union extends Union<field3_union, field3_union.ByValue, field3_union.ByReference > {
|
||||
/** <i>native declaration : src\main\include\NetworkCommunication\FRCComm.h:58</i> */
|
||||
public static class field3_union /*extends Union<field3_union, field3_union.ByValue, field3_union.ByReference >*/ {
|
||||
/** C type : int8_t[6] */
|
||||
public byte[] stick1Axes = new byte[6];
|
||||
/** C type : field1_struct */
|
||||
public field1_struct field1;
|
||||
/** <i>native declaration : /home/alex/Projects/WPILib-Development/WPILibC/WPILib/src/main/include/NetworkCommunication/FRCComm.h:78</i> */
|
||||
public static class field1_struct extends Structure<field1_struct, field1_struct.ByValue, field1_struct.ByReference > {
|
||||
/** <i>native declaration : src\main\include\NetworkCommunication\FRCComm.h:60</i> */
|
||||
public static class field1_struct /* extends Structure<field1_struct, field1_struct.ByValue, field1_struct.ByReference >*/ {
|
||||
public byte stick1Axis1;
|
||||
public byte stick1Axis2;
|
||||
public byte stick1Axis3;
|
||||
@@ -170,18 +211,21 @@ public class FRCCommonControlData extends Structure<FRCCommonControlData, FRCCom
|
||||
this.stick1Axis5 = stick1Axis5;
|
||||
this.stick1Axis6 = stick1Axis6;
|
||||
}
|
||||
protected ByReference newByReference() { return new ByReference(); }
|
||||
protected ByValue newByValue() { return new ByValue(); }
|
||||
//public field1_struct(Pointer peer) {
|
||||
// super(peer);
|
||||
//}
|
||||
//protected ByReference newByReference() { return new ByReference(); }
|
||||
//protected ByValue newByValue() { return new ByValue(); }
|
||||
protected field1_struct newInstance() { return new field1_struct(); }
|
||||
public static field1_struct[] newArray(int arrayLength) {
|
||||
return Structure.newArray(field1_struct.class, arrayLength);
|
||||
}
|
||||
public static class ByReference extends field1_struct implements Structure.ByReference {
|
||||
|
||||
};
|
||||
public static class ByValue extends field1_struct implements Structure.ByValue {
|
||||
|
||||
};
|
||||
//public static field1_struct[] newArray(int arrayLength) {
|
||||
// return Structure.newArray(field1_struct.class, arrayLength);
|
||||
//}
|
||||
//public static class ByReference extends field1_struct implements Structure.ByReference {
|
||||
//
|
||||
//};
|
||||
//public static class ByValue extends field1_struct implements Structure.ByValue {
|
||||
//
|
||||
//};
|
||||
};
|
||||
public field3_union() {
|
||||
super();
|
||||
@@ -190,7 +234,7 @@ public class FRCCommonControlData extends Structure<FRCCommonControlData, FRCCom
|
||||
public field3_union(field1_struct field1) {
|
||||
super();
|
||||
this.field1 = field1;
|
||||
setType(field1_struct.class);
|
||||
//setType(field1_struct.class);
|
||||
}
|
||||
/** @param stick1Axes C type : int8_t[6] */
|
||||
public field3_union(byte stick1Axes[]) {
|
||||
@@ -198,29 +242,32 @@ public class FRCCommonControlData extends Structure<FRCCommonControlData, FRCCom
|
||||
if ((stick1Axes.length != this.stick1Axes.length))
|
||||
throw new IllegalArgumentException("Wrong array size !");
|
||||
this.stick1Axes = stick1Axes;
|
||||
setType(byte[].class);
|
||||
//setType(byte[].class);
|
||||
}
|
||||
protected ByReference newByReference() { return new ByReference(); }
|
||||
protected ByValue newByValue() { return new ByValue(); }
|
||||
//public field3_union(Pointer peer) {
|
||||
// super(peer);
|
||||
//}
|
||||
//protected ByReference newByReference() { return new ByReference(); }
|
||||
//protected ByValue newByValue() { return new ByValue(); }
|
||||
protected field3_union newInstance() { return new field3_union(); }
|
||||
public static field3_union[] newArray(int arrayLength) {
|
||||
return Union.newArray(field3_union.class, arrayLength);
|
||||
}
|
||||
public static class ByReference extends field3_union implements Structure.ByReference {
|
||||
//public static field3_union[] newArray(int arrayLength) {
|
||||
// return Union.newArray(field3_union.class, arrayLength);
|
||||
//}
|
||||
//public static class ByReference extends field3_union implements Structure.ByReference {
|
||||
//
|
||||
//};
|
||||
//public static class ByValue extends field3_union implements Structure.ByValue {
|
||||
|
||||
};
|
||||
public static class ByValue extends field3_union implements Structure.ByValue {
|
||||
|
||||
};
|
||||
//};
|
||||
};
|
||||
/** <i>native declaration : /home/alex/Projects/WPILib-Development/WPILibC/WPILib/src/main/include/NetworkCommunication/FRCComm.h:89</i> */
|
||||
public static class field4_union extends Union<field4_union, field4_union.ByValue, field4_union.ByReference > {
|
||||
/** <i>native declaration : src\main\include\NetworkCommunication\FRCComm.h:71</i> */
|
||||
public static class field4_union /*extends Union<field4_union, field4_union.ByValue, field4_union.ByReference >*/ {
|
||||
/** C type : int8_t[6] */
|
||||
public byte[] stick2Axes = new byte[6];
|
||||
/** C type : field1_struct */
|
||||
public field1_struct field1;
|
||||
/** <i>native declaration : /home/alex/Projects/WPILib-Development/WPILibC/WPILib/src/main/include/NetworkCommunication/FRCComm.h:91</i> */
|
||||
public static class field1_struct extends Structure<field1_struct, field1_struct.ByValue, field1_struct.ByReference > {
|
||||
/** <i>native declaration : src\main\include\NetworkCommunication\FRCComm.h:73</i> */
|
||||
public static class field1_struct /* extends Structure<field1_struct, field1_struct.ByValue, field1_struct.ByReference >*/ {
|
||||
public byte stick2Axis1;
|
||||
public byte stick2Axis2;
|
||||
public byte stick2Axis3;
|
||||
@@ -242,18 +289,21 @@ public class FRCCommonControlData extends Structure<FRCCommonControlData, FRCCom
|
||||
this.stick2Axis5 = stick2Axis5;
|
||||
this.stick2Axis6 = stick2Axis6;
|
||||
}
|
||||
protected ByReference newByReference() { return new ByReference(); }
|
||||
protected ByValue newByValue() { return new ByValue(); }
|
||||
//public field1_struct(Pointer peer) {
|
||||
// super(peer);
|
||||
//}
|
||||
//protected ByReference newByReference() { return new ByReference(); }
|
||||
//protected ByValue newByValue() { return new ByValue(); }
|
||||
protected field1_struct newInstance() { return new field1_struct(); }
|
||||
public static field1_struct[] newArray(int arrayLength) {
|
||||
return Structure.newArray(field1_struct.class, arrayLength);
|
||||
}
|
||||
public static class ByReference extends field1_struct implements Structure.ByReference {
|
||||
//public static field1_struct[] newArray(int arrayLength) {
|
||||
// return Structure.newArray(field1_struct.class, arrayLength);
|
||||
//}
|
||||
//public static class ByReference extends field1_struct implements Structure.ByReference {
|
||||
|
||||
};
|
||||
public static class ByValue extends field1_struct implements Structure.ByValue {
|
||||
//};
|
||||
//public static class ByValue extends field1_struct implements Structure.ByValue {
|
||||
|
||||
};
|
||||
//};
|
||||
};
|
||||
public field4_union() {
|
||||
super();
|
||||
@@ -262,7 +312,7 @@ public class FRCCommonControlData extends Structure<FRCCommonControlData, FRCCom
|
||||
public field4_union(field1_struct field1) {
|
||||
super();
|
||||
this.field1 = field1;
|
||||
setType(field1_struct.class);
|
||||
//setType(field1_struct.class);
|
||||
}
|
||||
/** @param stick2Axes C type : int8_t[6] */
|
||||
public field4_union(byte stick2Axes[]) {
|
||||
@@ -270,29 +320,32 @@ public class FRCCommonControlData extends Structure<FRCCommonControlData, FRCCom
|
||||
if ((stick2Axes.length != this.stick2Axes.length))
|
||||
throw new IllegalArgumentException("Wrong array size !");
|
||||
this.stick2Axes = stick2Axes;
|
||||
setType(byte[].class);
|
||||
//setType(byte[].class);
|
||||
}
|
||||
protected ByReference newByReference() { return new ByReference(); }
|
||||
protected ByValue newByValue() { return new ByValue(); }
|
||||
//public field4_union(Pointer peer) {
|
||||
// super(peer);
|
||||
//}
|
||||
//protected ByReference newByReference() { return new ByReference(); }
|
||||
//protected ByValue newByValue() { return new ByValue(); }
|
||||
protected field4_union newInstance() { return new field4_union(); }
|
||||
public static field4_union[] newArray(int arrayLength) {
|
||||
return Union.newArray(field4_union.class, arrayLength);
|
||||
}
|
||||
public static class ByReference extends field4_union implements Structure.ByReference {
|
||||
//public static field4_union[] newArray(int arrayLength) {
|
||||
// return Union.newArray(field4_union.class, arrayLength);
|
||||
//}
|
||||
//public static class ByReference extends field4_union implements Structure.ByReference {
|
||||
|
||||
};
|
||||
public static class ByValue extends field4_union implements Structure.ByValue {
|
||||
//};
|
||||
//public static class ByValue extends field4_union implements Structure.ByValue {
|
||||
|
||||
};
|
||||
//};
|
||||
};
|
||||
/** <i>native declaration : /home/alex/Projects/WPILib-Development/WPILibC/WPILib/src/main/include/NetworkCommunication/FRCComm.h:102</i> */
|
||||
public static class field5_union extends Union<field5_union, field5_union.ByValue, field5_union.ByReference > {
|
||||
/** <i>native declaration : src\main\include\NetworkCommunication\FRCComm.h:84</i> */
|
||||
public static class field5_union /* extends Union<field5_union, field5_union.ByValue, field5_union.ByReference >*/ {
|
||||
/** C type : int8_t[6] */
|
||||
public byte[] stick3Axes = new byte[6];
|
||||
/** C type : field1_struct */
|
||||
public field1_struct field1;
|
||||
/** <i>native declaration : /home/alex/Projects/WPILib-Development/WPILibC/WPILib/src/main/include/NetworkCommunication/FRCComm.h:104</i> */
|
||||
public static class field1_struct extends Structure<field1_struct, field1_struct.ByValue, field1_struct.ByReference > {
|
||||
/** <i>native declaration : src\main\include\NetworkCommunication\FRCComm.h:86</i> */
|
||||
public static class field1_struct /*extends Structure<field1_struct, field1_struct.ByValue, field1_struct.ByReference >*/ {
|
||||
public byte stick3Axis1;
|
||||
public byte stick3Axis2;
|
||||
public byte stick3Axis3;
|
||||
@@ -314,18 +367,21 @@ public class FRCCommonControlData extends Structure<FRCCommonControlData, FRCCom
|
||||
this.stick3Axis5 = stick3Axis5;
|
||||
this.stick3Axis6 = stick3Axis6;
|
||||
}
|
||||
protected ByReference newByReference() { return new ByReference(); }
|
||||
protected ByValue newByValue() { return new ByValue(); }
|
||||
//public field1_struct(Pointer peer) {
|
||||
// super(peer);
|
||||
//}
|
||||
//protected ByReference newByReference() { return new ByReference(); }
|
||||
//protected ByValue newByValue() { return new ByValue(); }
|
||||
protected field1_struct newInstance() { return new field1_struct(); }
|
||||
public static field1_struct[] newArray(int arrayLength) {
|
||||
return Structure.newArray(field1_struct.class, arrayLength);
|
||||
}
|
||||
public static class ByReference extends field1_struct implements Structure.ByReference {
|
||||
//public static field1_struct[] newArray(int arrayLength) {
|
||||
// return Structure.newArray(field1_struct.class, arrayLength);
|
||||
//}
|
||||
//public static class ByReference extends field1_struct implements Structure.ByReference {
|
||||
|
||||
};
|
||||
public static class ByValue extends field1_struct implements Structure.ByValue {
|
||||
//};
|
||||
//public static class ByValue extends field1_struct implements Structure.ByValue {
|
||||
|
||||
};
|
||||
//};
|
||||
};
|
||||
public field5_union() {
|
||||
super();
|
||||
@@ -334,7 +390,7 @@ public class FRCCommonControlData extends Structure<FRCCommonControlData, FRCCom
|
||||
public field5_union(field1_struct field1) {
|
||||
super();
|
||||
this.field1 = field1;
|
||||
setType(field1_struct.class);
|
||||
//setType(field1_struct.class);
|
||||
}
|
||||
/** @param stick3Axes C type : int8_t[6] */
|
||||
public field5_union(byte stick3Axes[]) {
|
||||
@@ -342,20 +398,23 @@ public class FRCCommonControlData extends Structure<FRCCommonControlData, FRCCom
|
||||
if ((stick3Axes.length != this.stick3Axes.length))
|
||||
throw new IllegalArgumentException("Wrong array size !");
|
||||
this.stick3Axes = stick3Axes;
|
||||
setType(byte[].class);
|
||||
//setType(byte[].class);
|
||||
}
|
||||
protected ByReference newByReference() { return new ByReference(); }
|
||||
protected ByValue newByValue() { return new ByValue(); }
|
||||
//public field5_union(Pointer peer) {
|
||||
// super(peer);
|
||||
//}
|
||||
//protected ByReference newByReference() { return new ByReference(); }
|
||||
//protected ByValue newByValue() { return new ByValue(); }
|
||||
protected field5_union newInstance() { return new field5_union(); }
|
||||
public static field5_union[] newArray(int arrayLength) {
|
||||
return Union.newArray(field5_union.class, arrayLength);
|
||||
}
|
||||
public static class ByReference extends field5_union implements Structure.ByReference {
|
||||
//public static field5_union[] newArray(int arrayLength) {
|
||||
// return Union.newArray(field5_union.class, arrayLength);
|
||||
//}
|
||||
//public static class ByReference extends field5_union implements Structure.ByReference {
|
||||
|
||||
};
|
||||
public static class ByValue extends field5_union implements Structure.ByValue {
|
||||
//};
|
||||
//public static class ByValue extends field5_union implements Structure.ByValue {
|
||||
|
||||
};
|
||||
//};
|
||||
};
|
||||
public FRCCommonControlData() {
|
||||
super();
|
||||
@@ -363,16 +422,19 @@ public class FRCCommonControlData extends Structure<FRCCommonControlData, FRCCom
|
||||
protected List<? > getFieldOrder() {
|
||||
return Arrays.asList("packetIndex", "field1", "dsDigitalIn", "teamID", "dsID_Alliance", "dsID_Position", "field2", "stick0Buttons", "field3", "stick1Buttons", "field4", "stick2Buttons", "field5", "stick3Buttons", "analog1", "analog2", "analog3", "analog4", "cRIOChecksum", "FPGAChecksum0", "FPGAChecksum1", "FPGAChecksum2", "FPGAChecksum3", "versionData");
|
||||
}
|
||||
protected ByReference newByReference() { return new ByReference(); }
|
||||
protected ByValue newByValue() { return new ByValue(); }
|
||||
//public FRCCommonControlData(Pointer peer) {
|
||||
// super(peer);
|
||||
//}
|
||||
//protected ByReference newByReference() { return new ByReference(); }
|
||||
//protected ByValue newByValue() { return new ByValue(); }
|
||||
protected FRCCommonControlData newInstance() { return new FRCCommonControlData(); }
|
||||
public static FRCCommonControlData[] newArray(int arrayLength) {
|
||||
return Structure.newArray(FRCCommonControlData.class, arrayLength);
|
||||
}
|
||||
public static class ByReference extends FRCCommonControlData implements Structure.ByReference {
|
||||
//public static FRCCommonControlData[] newArray(int arrayLength) {
|
||||
// return Structure.newArray(FRCCommonControlData.class, arrayLength);
|
||||
//}
|
||||
//public static class ByReference extends FRCCommonControlData implements Structure.ByReference {
|
||||
//
|
||||
//};
|
||||
//public static class ByValue extends FRCCommonControlData implements Structure.ByValue {
|
||||
|
||||
};
|
||||
public static class ByValue extends FRCCommonControlData implements Structure.ByValue {
|
||||
|
||||
};
|
||||
//};
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public class UsageReporting {
|
||||
|
||||
public static void report(int resource, int instanceNumber, int i,
|
||||
String string) {
|
||||
FRC_NetworkCommunicationsLibrary.FRC_NetworkCommunication_nUsageReporting_report((byte)resource, (byte) instanceNumber, (byte) i, string);
|
||||
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationUsageReportingReport((byte)resource, (byte) instanceNumber, (byte) i, string);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,29 +1,53 @@
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class HALUtil {
|
||||
public class HALUtil extends JNIWrapper {
|
||||
public static final int NULL_PARAMETER = -5;
|
||||
public static final int SAMPLE_RATE_TOO_HIGH = 1;
|
||||
public static final int VOLTAGE_OUT_OF_RANGE = 2;
|
||||
public static final int LOOP_TIMING_ERROR = 4;
|
||||
public static final int INCOMPATIBLE_STATE = 15;
|
||||
public static final int ANALOG_TRIGGER_PULSE_OUTPUT_ERROR = -11;
|
||||
public static final int NO_AVAILABLE_RESOURCES = -4;
|
||||
public static final int PARAMETER_OUT_OF_RANGE = -28;
|
||||
|
||||
public static void checkStatus(IntBuffer status) {
|
||||
//public static final int SEMAPHORE_WAIT_FOREVER = -1;
|
||||
//public static final int SEMAPHORE_Q_PRIORITY = 0x01;
|
||||
|
||||
public static native ByteBuffer initializeMutexNormal();
|
||||
public static native void deleteMutex(ByteBuffer sem);
|
||||
public static native byte takeMutex(ByteBuffer 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 short getFPGAVersion(IntBuffer status);
|
||||
public static native int getFPGARevision(IntBuffer status);
|
||||
public static native long getFPGATime(IntBuffer status);
|
||||
|
||||
public static native String getHALErrorMessage(int code);
|
||||
|
||||
public static void checkStatus(IntBuffer status)
|
||||
{
|
||||
int s = status.get(0);
|
||||
String message = "Code: " + s + ". " + HALLibrary.getHALErrorMessage(s);
|
||||
if (s == 0)
|
||||
return;
|
||||
else if (s == HALLibrary.NULL_PARAMETER
|
||||
|| s == HALLibrary.SAMPLE_RATE_TOO_HIGH
|
||||
|| s == HALLibrary.VOLTAGE_OUT_OF_RANGE)
|
||||
throw new IllegalArgumentException(message);
|
||||
else if (s == HALLibrary.LOOP_TIMING_ERROR) // TODO: Make these a
|
||||
// WPILibRuntimeException
|
||||
throw new RuntimeException(message);
|
||||
else if (s == HALLibrary.INCOMPATIBLE_STATE
|
||||
|| s == HALLibrary.ANALOG_TRIGGER_PULSE_OUTPUT_ERROR)
|
||||
throw new IllegalStateException(message);
|
||||
else if (s == HALLibrary.NO_AVAILABLE_RESOURCES)
|
||||
throw new RuntimeException(message);
|
||||
else
|
||||
throw new RuntimeException("Unknown error. Code: " + s + ". "
|
||||
+ message);
|
||||
if (s != 0)
|
||||
{
|
||||
String message = "Code: " + s + ". " + HALUtil.getHALErrorMessage(s);
|
||||
if (s == HALUtil.NULL_PARAMETER
|
||||
|| s == HALUtil.SAMPLE_RATE_TOO_HIGH
|
||||
|| s == HALUtil.VOLTAGE_OUT_OF_RANGE)
|
||||
throw new IllegalArgumentException(message);
|
||||
else if (s == HALUtil.LOOP_TIMING_ERROR)
|
||||
throw new RuntimeException(message);
|
||||
else if (s == HALUtil.INCOMPATIBLE_STATE
|
||||
|| s == HALUtil.ANALOG_TRIGGER_PULSE_OUTPUT_ERROR)
|
||||
throw new IllegalStateException(message);
|
||||
else if (s == HALUtil.NO_AVAILABLE_RESOURCES)
|
||||
throw new RuntimeException(message);
|
||||
else
|
||||
throw new RuntimeException("Unknown error. Code: " + s + ". " + message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class JNIWrapper
|
||||
if( !libraryLoaded )
|
||||
{
|
||||
// create temporary file
|
||||
jniLibrary = File.createTempFile("libwpilibJavaJNI", "so");
|
||||
jniLibrary = File.createTempFile("libwpilibJavaJNI", ".so");
|
||||
// flag for delete on exit
|
||||
jniLibrary.deleteOnExit();
|
||||
|
||||
@@ -28,7 +28,7 @@ public class JNIWrapper
|
||||
|
||||
int readBytes;
|
||||
|
||||
InputStream is = JNIWrapper.class.getResourceAsStream("linux-arm/libwpilibJavaJNI.so");
|
||||
InputStream is = JNIWrapper.class.getResourceAsStream("/linux-arm/libwpilibJavaJNI.so");
|
||||
|
||||
OutputStream os = new FileOutputStream(jniLibrary);
|
||||
|
||||
@@ -50,7 +50,7 @@ public class JNIWrapper
|
||||
libraryLoaded = true;
|
||||
}
|
||||
|
||||
System.loadLibrary(jniLibrary.getAbsolutePath());
|
||||
System.load(jniLibrary.getAbsolutePath());
|
||||
}
|
||||
catch( Exception ex )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user