mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Enable checkstyle on cscore, ntcore, wpiutil (#1032)
Also update to version 8.10.
This commit is contained in:
committed by
Peter Johnson
parent
ecfe95383c
commit
40cc743cc7
@@ -82,7 +82,7 @@ subprojects {
|
||||
}
|
||||
|
||||
checkstyle {
|
||||
toolVersion = "8.1"
|
||||
toolVersion = "8.10"
|
||||
configFile = new File(rootDir, "styleguide/checkstyle.xml")
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import edu.wpi.cscore.AxisCamera;
|
||||
import edu.wpi.cscore.CameraServerJNI;
|
||||
import edu.wpi.cscore.CvSink;
|
||||
@@ -21,17 +25,11 @@ import edu.wpi.cscore.VideoMode.PixelFormat;
|
||||
import edu.wpi.cscore.VideoProperty;
|
||||
import edu.wpi.cscore.VideoSink;
|
||||
import edu.wpi.cscore.VideoSource;
|
||||
//import edu.wpi.first.wpilibj.hal.FRCNetComm.tResourceType;
|
||||
//import edu.wpi.first.wpilibj.hal.HAL;
|
||||
import edu.wpi.first.networktables.EntryListenerFlags;
|
||||
import edu.wpi.first.networktables.NetworkTable;
|
||||
import edu.wpi.first.networktables.NetworkTableEntry;
|
||||
import edu.wpi.first.networktables.NetworkTableInstance;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* Singleton class for creating and keeping camera servers.
|
||||
* Also publishes camera information to NetworkTables.
|
||||
@@ -420,7 +418,7 @@ public class CameraServer {
|
||||
// synchronization issues, so just update to current setting if someone
|
||||
// else tries to change it.
|
||||
m_tableListener = NetworkTableInstance.getDefault().addEntryListener(kPublishName + "/",
|
||||
(event) -> {
|
||||
event -> {
|
||||
String relativeKey = event.name.substring(kPublishName.length() + 1);
|
||||
|
||||
// get source (sourceName/...)
|
||||
|
||||
@@ -7,14 +7,12 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.vision;
|
||||
|
||||
import org.opencv.core.Mat;
|
||||
|
||||
import edu.wpi.cscore.CvSink;
|
||||
import edu.wpi.cscore.VideoSource;
|
||||
import edu.wpi.first.wpilibj.CameraServerSharedStore;
|
||||
|
||||
//import edu.wpi.first.wpilibj.DriverStation;
|
||||
//import edu.wpi.first.wpilibj.RobotBase;
|
||||
import org.opencv.core.Mat;
|
||||
|
||||
/**
|
||||
* A vision runner is a convenient wrapper object to make it easy to run vision pipelines
|
||||
* from robot code. The easiest way to use this is to run it in a {@link VisionThread}
|
||||
|
||||
@@ -109,7 +109,3 @@ model {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
checkstyle {
|
||||
sourceSets = []
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@ package edu.wpi.cscore;
|
||||
import edu.wpi.first.wpiutil.RuntimeDetector;
|
||||
|
||||
public class DevMain {
|
||||
/**
|
||||
* Main method.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
System.out.println(RuntimeDetector.getPlatformPath());
|
||||
|
||||
@@ -8,12 +8,14 @@
|
||||
package edu.wpi.cscore;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.opencv.core.Core;
|
||||
|
||||
import edu.wpi.first.wpiutil.RuntimeDetector;
|
||||
|
||||
public class CameraServerJNI {
|
||||
@@ -21,11 +23,12 @@ public class CameraServerJNI {
|
||||
static File jniLibrary = null;
|
||||
static boolean cvLibraryLoaded = false;
|
||||
static File cvJniLibrary = null;
|
||||
|
||||
static {
|
||||
if (!libraryLoaded) {
|
||||
try {
|
||||
System.loadLibrary("cscore");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
} catch (UnsatisfiedLinkError linkError) {
|
||||
try {
|
||||
String resname = RuntimeDetector.getLibraryResource("cscore");
|
||||
InputStream is = CameraServerJNI.class.getResourceAsStream(resname);
|
||||
@@ -69,7 +72,7 @@ public class CameraServerJNI {
|
||||
try {
|
||||
|
||||
System.loadLibrary(opencvName);
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
} catch (UnsatisfiedLinkError linkError) {
|
||||
try {
|
||||
String resname = RuntimeDetector.getLibraryResource(opencvName);
|
||||
InputStream is = CameraServerJNI.class.getResourceAsStream(resname);
|
||||
@@ -109,7 +112,7 @@ public class CameraServerJNI {
|
||||
}
|
||||
}
|
||||
|
||||
public static void ForceLoad() {}
|
||||
public static void forceLoad() {}
|
||||
|
||||
//
|
||||
// Property Functions
|
||||
@@ -239,9 +242,10 @@ public class CameraServerJNI {
|
||||
kSourceBytesReceived(1),
|
||||
kSourceFramesReceived(2);
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
private int value;
|
||||
|
||||
private TelemetryKind(int value) {
|
||||
TelemetryKind(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,11 @@ public class CvSource extends VideoSource {
|
||||
* @param mode Video mode being generated
|
||||
*/
|
||||
public CvSource(String name, VideoMode mode) {
|
||||
super(CameraServerJNI.createCvSource(name, mode.pixelFormat.getValue(), mode.width, mode.height, mode.fps));
|
||||
super(CameraServerJNI.createCvSource(name,
|
||||
mode.pixelFormat.getValue(),
|
||||
mode.width,
|
||||
mode.height,
|
||||
mode.fps));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,66 +84,108 @@ public class CvSource extends VideoSource {
|
||||
* @param value Current value
|
||||
* @return Property
|
||||
*/
|
||||
public VideoProperty createProperty(String name, VideoProperty.Kind kind, int minimum, int maximum, int step, int defaultValue, int value) {
|
||||
public VideoProperty createProperty(String name,
|
||||
VideoProperty.Kind kind,
|
||||
int minimum,
|
||||
int maximum,
|
||||
int step,
|
||||
int defaultValue,
|
||||
int value) {
|
||||
return new VideoProperty(
|
||||
CameraServerJNI.createSourceProperty(m_handle, name, kind.getValue(), minimum, maximum, step, defaultValue, value));
|
||||
CameraServerJNI.createSourceProperty(m_handle,
|
||||
name,
|
||||
kind.getValue(),
|
||||
minimum,
|
||||
maximum,
|
||||
step,
|
||||
defaultValue,
|
||||
value));
|
||||
}
|
||||
|
||||
/// Create an integer property.
|
||||
/// @param name Property name
|
||||
/// @param minimum Minimum value
|
||||
/// @param maximum Maximum value
|
||||
/// @param step Step value
|
||||
/// @param defaultValue Default value
|
||||
/// @param value Current value
|
||||
/// @return Property
|
||||
public VideoProperty createIntegerProperty(String name, int minimum, int maximum, int step, int defaultValue, int value) {
|
||||
/**
|
||||
* Create an integer property.
|
||||
* @param name Property name
|
||||
* @param minimum Minimum value
|
||||
* @param maximum Maximum value
|
||||
* @param step Step value
|
||||
* @param defaultValue Default value
|
||||
* @param value Current value
|
||||
* @return Property
|
||||
*/
|
||||
public VideoProperty createIntegerProperty(String name,
|
||||
int minimum,
|
||||
int maximum,
|
||||
int step,
|
||||
int defaultValue,
|
||||
int value) {
|
||||
return new VideoProperty(
|
||||
CameraServerJNI.createSourceProperty(m_handle, name, VideoProperty.Kind.kInteger.getValue(), minimum, maximum, step, defaultValue, value));
|
||||
CameraServerJNI.createSourceProperty(m_handle,
|
||||
name,
|
||||
VideoProperty.Kind.kInteger.getValue(),
|
||||
minimum,
|
||||
maximum,
|
||||
step,
|
||||
defaultValue,
|
||||
value));
|
||||
}
|
||||
|
||||
/// Create a boolean property.
|
||||
/// @param name Property name
|
||||
/// @param defaultValue Default value
|
||||
/// @param value Current value
|
||||
/// @return Property
|
||||
/**
|
||||
* Create a boolean property.
|
||||
* @param name Property name
|
||||
* @param defaultValue Default value
|
||||
* @param value Current value
|
||||
* @return Property
|
||||
*/
|
||||
public VideoProperty createBooleanProperty(String name, boolean defaultValue, boolean value) {
|
||||
return new VideoProperty(
|
||||
CameraServerJNI.createSourceProperty(m_handle, name, VideoProperty.Kind.kBoolean.getValue(), 0, 1, 1, defaultValue ? 1 : 0, value ? 1 : 0));
|
||||
CameraServerJNI.createSourceProperty(m_handle,
|
||||
name,
|
||||
VideoProperty.Kind.kBoolean.getValue(),
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
defaultValue ? 1 : 0,
|
||||
value ? 1 : 0));
|
||||
}
|
||||
|
||||
/// Create a string property.
|
||||
/// @param name Property name
|
||||
/// @param value Current value
|
||||
/// @return Property
|
||||
/**
|
||||
* Create a string property.
|
||||
* @param name Property name
|
||||
* @param value Current value
|
||||
* @return Property
|
||||
*/
|
||||
public VideoProperty createStringProperty(String name, String value) {
|
||||
VideoProperty prop = new VideoProperty(
|
||||
CameraServerJNI.createSourceProperty(m_handle, name, VideoProperty.Kind.kString.getValue(), 0, 0, 0, 0, 0));
|
||||
CameraServerJNI.createSourceProperty(m_handle,
|
||||
name,
|
||||
VideoProperty.Kind.kString.getValue(),
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0));
|
||||
prop.setString(value);
|
||||
return prop;
|
||||
}
|
||||
|
||||
/// Create a property with a change callback.
|
||||
/// @param name Property name
|
||||
/// @param kind Property kind
|
||||
/// @param minimum Minimum value
|
||||
/// @param maximum Maximum value
|
||||
/// @param step Step value
|
||||
/// @param defaultValue Default value
|
||||
/// @param value Current value
|
||||
/// @param onChange Callback to call when the property value changes
|
||||
/// @return Property
|
||||
//public VideoProperty createProperty(
|
||||
// String name, VideoProperty.Kind kind, int minimum, int maximum, int step, int defaultValue, int value,
|
||||
// std::function<void(VideoProperty property)>
|
||||
// onChange);
|
||||
|
||||
/**
|
||||
* Configure enum property choices.
|
||||
* @param property Property
|
||||
* @param choices Choices
|
||||
*/
|
||||
public void SetEnumPropertyChoices(VideoProperty property, String[] choices) {
|
||||
public void setEnumPropertyChoices(VideoProperty property, String[] choices) {
|
||||
CameraServerJNI.setSourceEnumPropertyChoices(m_handle, property.m_handle, choices);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure enum property choices.
|
||||
* @param property Property
|
||||
* @param choices Choices
|
||||
* @deprecated Use {@code setEnumPropertyChoices} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("MethodName")
|
||||
public void SetEnumPropertyChoices(VideoProperty property, String[] choices) {
|
||||
setEnumPropertyChoices(property, choices);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,11 @@ package edu.wpi.cscore;
|
||||
public class HttpCamera extends VideoCamera {
|
||||
public enum HttpCameraKind {
|
||||
kUnknown(0), kMJPGStreamer(1), kCSCore(2), kAxis(3);
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
private int value;
|
||||
|
||||
private HttpCameraKind(int value) {
|
||||
HttpCameraKind(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -24,6 +26,12 @@ public class HttpCamera extends VideoCamera {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from the numerical representation of kind to an enum type.
|
||||
*
|
||||
* @param kind The numerical representation of kind
|
||||
* @return The kind
|
||||
*/
|
||||
public static HttpCameraKind getHttpCameraKindFromInt(int kind) {
|
||||
switch (kind) {
|
||||
case 1: return HttpCameraKind.kMJPGStreamer;
|
||||
|
||||
@@ -8,9 +8,15 @@
|
||||
package edu.wpi.cscore;
|
||||
|
||||
/**
|
||||
* USB camera information
|
||||
* USB camera information.
|
||||
*/
|
||||
public class UsbCameraInfo {
|
||||
/**
|
||||
* Create a new set of UsbCameraInfo.
|
||||
* @param dev Device number (e.g. N in '/dev/videoN' on Linux)
|
||||
* @param path Path to device if available (e.g. '/dev/video0' on Linux)
|
||||
* @param name Vendor/model name of the camera as provided by the USB driver
|
||||
*/
|
||||
public UsbCameraInfo(int dev, String path, String name) {
|
||||
this.dev = dev;
|
||||
this.path = path;
|
||||
@@ -18,17 +24,20 @@ public class UsbCameraInfo {
|
||||
}
|
||||
|
||||
/**
|
||||
* Device number (e.g. N in '/dev/videoN' on Linux)
|
||||
* Device number (e.g. N in '/dev/videoN' on Linux).
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public int dev;
|
||||
|
||||
/**
|
||||
* Path to device if available (e.g. '/dev/video0' on Linux)
|
||||
* Path to device if available (e.g. '/dev/video0' on Linux).
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public String path;
|
||||
|
||||
/**
|
||||
* Vendor/model name of the camera as provided by the USB driver
|
||||
* Vendor/model name of the camera as provided by the USB driver.
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public String name;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
package edu.wpi.cscore;
|
||||
|
||||
/**
|
||||
* Video event
|
||||
* Video event.
|
||||
*/
|
||||
public class VideoEvent {
|
||||
public enum Kind {
|
||||
@@ -30,9 +30,10 @@ public class VideoEvent {
|
||||
kNetworkInterfacesChanged(0x4000),
|
||||
kTelemetryUpdated(0x8000);
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
private int value;
|
||||
|
||||
private Kind(int value) {
|
||||
Kind(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -41,6 +42,12 @@ public class VideoEvent {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from the numerical representation of kind to an enum type.
|
||||
*
|
||||
* @param kind The numerical representation of kind
|
||||
* @return The kind
|
||||
*/
|
||||
public static Kind getKindFromInt(int kind) {
|
||||
switch (kind) {
|
||||
case 0x0001: return Kind.kSourceCreated;
|
||||
@@ -76,22 +83,31 @@ public class VideoEvent {
|
||||
this.valueStr = valueStr;
|
||||
}
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public Kind kind;
|
||||
|
||||
// Valid for kSource* and kSink* respectively
|
||||
@SuppressWarnings("MemberName")
|
||||
public int sourceHandle;
|
||||
@SuppressWarnings("MemberName")
|
||||
public int sinkHandle;
|
||||
|
||||
// Source/sink/property name
|
||||
@SuppressWarnings("MemberName")
|
||||
public String name;
|
||||
|
||||
// Fields for kSourceVideoModeChanged event
|
||||
@SuppressWarnings("MemberName")
|
||||
public VideoMode mode;
|
||||
|
||||
// Fields for kSourceProperty* events
|
||||
@SuppressWarnings("MemberName")
|
||||
public int propertyHandle;
|
||||
@SuppressWarnings("MemberName")
|
||||
public VideoProperty.Kind propertyKind;
|
||||
@SuppressWarnings("MemberName")
|
||||
public int value;
|
||||
@SuppressWarnings("MemberName")
|
||||
public String valueStr;
|
||||
|
||||
public VideoSource getSource() {
|
||||
|
||||
@@ -8,14 +8,16 @@
|
||||
package edu.wpi.cscore;
|
||||
|
||||
/**
|
||||
* Video mode
|
||||
* Video mode.
|
||||
*/
|
||||
public class VideoMode {
|
||||
public enum PixelFormat {
|
||||
kUnknown(0), kMJPEG(1), kYUYV(2), kRGB565(3), kBGR(4), kGray(5);
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
private int value;
|
||||
|
||||
private PixelFormat(int value) {
|
||||
PixelFormat(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -23,12 +25,16 @@ public class VideoMode {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
private static final PixelFormat[] m_pixelFormatValues = PixelFormat.values();
|
||||
|
||||
public static PixelFormat getPixelFormatFromInt(int pixelFormat) {
|
||||
return m_pixelFormatValues[pixelFormat];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new video mode.
|
||||
*/
|
||||
public VideoMode(int pixelFormat, int width, int height, int fps) {
|
||||
this.pixelFormat = getPixelFormatFromInt(pixelFormat);
|
||||
this.width = width;
|
||||
@@ -36,6 +42,9 @@ public class VideoMode {
|
||||
this.fps = fps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new video mode.
|
||||
*/
|
||||
public VideoMode(PixelFormat pixelFormat, int width, int height, int fps) {
|
||||
this.pixelFormat = pixelFormat;
|
||||
this.width = width;
|
||||
@@ -44,22 +53,26 @@ public class VideoMode {
|
||||
}
|
||||
|
||||
/**
|
||||
* Pixel format
|
||||
* Pixel format.
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public PixelFormat pixelFormat;
|
||||
|
||||
/**
|
||||
* Width in pixels
|
||||
* Width in pixels.
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public int width;
|
||||
|
||||
/**
|
||||
* Height in pixels
|
||||
* Height in pixels.
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public int height;
|
||||
|
||||
/**
|
||||
* Frames per second
|
||||
* Frames per second.
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public int fps;
|
||||
}
|
||||
|
||||
@@ -10,9 +10,11 @@ package edu.wpi.cscore;
|
||||
public class VideoProperty {
|
||||
public enum Kind {
|
||||
kNone(0), kBoolean(1), kInteger(2), kString(4), kEnum(8);
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
private int value;
|
||||
|
||||
private Kind(int value) {
|
||||
Kind(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -21,6 +23,12 @@ public class VideoProperty {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from the numerical representation of kind to an enum type.
|
||||
*
|
||||
* @param kind The numerical representation of kind
|
||||
* @return The kind
|
||||
*/
|
||||
public static Kind getKindFromInt(int kind) {
|
||||
switch (kind) {
|
||||
case 1: return Kind.kBoolean;
|
||||
|
||||
@@ -15,9 +15,11 @@ package edu.wpi.cscore;
|
||||
public class VideoSink implements AutoCloseable {
|
||||
public enum Kind {
|
||||
kUnknown(0), kMjpeg(2), kCv(4);
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
private int value;
|
||||
|
||||
private Kind(int value) {
|
||||
Kind(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -26,6 +28,12 @@ public class VideoSink implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from the numerical representation of kind to an enum type.
|
||||
*
|
||||
* @param kind The numerical representation of kind
|
||||
* @return The kind
|
||||
*/
|
||||
public static Kind getKindFromInt(int kind) {
|
||||
switch (kind) {
|
||||
case 2: return Kind.kMjpeg;
|
||||
@@ -59,6 +67,7 @@ public class VideoSink implements AutoCloseable {
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
@@ -73,6 +82,7 @@ public class VideoSink implements AutoCloseable {
|
||||
return m_handle == sink.m_handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return m_handle;
|
||||
}
|
||||
@@ -141,7 +151,7 @@ public class VideoSink implements AutoCloseable {
|
||||
public static VideoSink[] enumerateSinks() {
|
||||
int[] handles = CameraServerJNI.enumerateSinks();
|
||||
VideoSink[] rv = new VideoSink[handles.length];
|
||||
for (int i=0; i<handles.length; i++) {
|
||||
for (int i = 0; i < handles.length; i++) {
|
||||
rv[i] = new VideoSink(handles[i]);
|
||||
}
|
||||
return rv;
|
||||
|
||||
@@ -15,9 +15,11 @@ package edu.wpi.cscore;
|
||||
public class VideoSource implements AutoCloseable {
|
||||
public enum Kind {
|
||||
kUnknown(0), kUsb(1), kHttp(2), kCv(4);
|
||||
private int value;
|
||||
|
||||
private Kind(int value) {
|
||||
@SuppressWarnings("MemberName")
|
||||
private final int value;
|
||||
|
||||
Kind(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -26,6 +28,12 @@ public class VideoSource implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from the numerical representation of kind to an enum type.
|
||||
*
|
||||
* @param kind The numerical representation of kind
|
||||
* @return The kind
|
||||
*/
|
||||
public static Kind getKindFromInt(int kind) {
|
||||
switch (kind) {
|
||||
case 1: return Kind.kUsb;
|
||||
@@ -60,6 +68,7 @@ public class VideoSource implements AutoCloseable {
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
@@ -74,6 +83,7 @@ public class VideoSource implements AutoCloseable {
|
||||
return m_handle == source.m_handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return m_handle;
|
||||
}
|
||||
@@ -109,7 +119,7 @@ public class VideoSource implements AutoCloseable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the source currently connected to whatever is providing the images?
|
||||
* Returns if the source currently connected to whatever is providing the images.
|
||||
*/
|
||||
public boolean isConnected() {
|
||||
return CameraServerJNI.isSourceConnected(m_handle);
|
||||
@@ -131,7 +141,7 @@ public class VideoSource implements AutoCloseable {
|
||||
public VideoProperty[] enumerateProperties() {
|
||||
int[] handles = CameraServerJNI.enumerateSourceProperties(m_handle);
|
||||
VideoProperty[] rv = new VideoProperty[handles.length];
|
||||
for (int i=0; i<handles.length; i++) {
|
||||
for (int i = 0; i < handles.length; i++) {
|
||||
rv[i] = new VideoProperty(handles[i]);
|
||||
}
|
||||
return rv;
|
||||
@@ -149,7 +159,11 @@ public class VideoSource implements AutoCloseable {
|
||||
* @param mode Video mode
|
||||
*/
|
||||
public boolean setVideoMode(VideoMode mode) {
|
||||
return CameraServerJNI.setSourceVideoMode(m_handle, mode.pixelFormat.getValue(), mode.width, mode.height, mode.fps);
|
||||
return CameraServerJNI.setSourceVideoMode(m_handle,
|
||||
mode.pixelFormat.getValue(),
|
||||
mode.width,
|
||||
mode.height,
|
||||
mode.fps);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -199,7 +213,8 @@ public class VideoSource implements AutoCloseable {
|
||||
* @return Actual FPS averaged over the telemetry period.
|
||||
*/
|
||||
public double getActualFPS() {
|
||||
return CameraServerJNI.getTelemetryAverageValue(m_handle, CameraServerJNI.TelemetryKind.kSourceFramesReceived);
|
||||
return CameraServerJNI.getTelemetryAverageValue(m_handle,
|
||||
CameraServerJNI.TelemetryKind.kSourceFramesReceived);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,7 +224,8 @@ public class VideoSource implements AutoCloseable {
|
||||
* @return Data rate averaged over the telemetry period.
|
||||
*/
|
||||
public double getActualDataRate() {
|
||||
return CameraServerJNI.getTelemetryAverageValue(m_handle, CameraServerJNI.TelemetryKind.kSourceBytesReceived);
|
||||
return CameraServerJNI.getTelemetryAverageValue(m_handle,
|
||||
CameraServerJNI.TelemetryKind.kSourceBytesReceived);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -226,7 +242,7 @@ public class VideoSource implements AutoCloseable {
|
||||
public VideoSink[] enumerateSinks() {
|
||||
int[] handles = CameraServerJNI.enumerateSourceSinks(m_handle);
|
||||
VideoSink[] rv = new VideoSink[handles.length];
|
||||
for (int i=0; i<handles.length; i++) {
|
||||
for (int i = 0; i < handles.length; i++) {
|
||||
rv[i] = new VideoSink(handles[i]);
|
||||
}
|
||||
return rv;
|
||||
@@ -239,7 +255,7 @@ public class VideoSource implements AutoCloseable {
|
||||
public static VideoSource[] enumerateSources() {
|
||||
int[] handles = CameraServerJNI.enumerateSources();
|
||||
VideoSource[] rv = new VideoSource[handles.length];
|
||||
for (int i=0; i<handles.length; i++) {
|
||||
for (int i = 0; i < handles.length; i++) {
|
||||
rv[i] = new VideoSource(handles[i]);
|
||||
}
|
||||
return rv;
|
||||
|
||||
@@ -10,9 +10,9 @@ package edu.wpi.cscore;
|
||||
import org.junit.Test;
|
||||
|
||||
public class JNITest {
|
||||
@Test
|
||||
public void jniLinkTest() {
|
||||
// Test to verify that the JNI test link works correctly.
|
||||
edu.wpi.cscore.CameraServerJNI.getHostname();
|
||||
}
|
||||
@Test
|
||||
public void jniLinkTest() {
|
||||
// Test to verify that the JNI test link works correctly.
|
||||
edu.wpi.cscore.CameraServerJNI.getHostname();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,10 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
import edu.wpi.first.wpilibj.AccumulatorResult;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import edu.wpi.first.wpilibj.AccumulatorResult;
|
||||
|
||||
public class AnalogJNI extends JNIWrapper {
|
||||
/**
|
||||
* <i>native declaration : AthenaJava\target\native\include\HAL\Analog.h:58</i><br> enum values
|
||||
|
||||
@@ -7,13 +7,14 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
import edu.wpi.first.wpiutil.RuntimeDetector;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import edu.wpi.first.wpiutil.RuntimeDetector;
|
||||
|
||||
/**
|
||||
* Base class for all JNI wrappers.
|
||||
*/
|
||||
|
||||
@@ -44,10 +44,6 @@ model {
|
||||
}
|
||||
}
|
||||
|
||||
checkstyle {
|
||||
sourceSets = []
|
||||
}
|
||||
|
||||
pmdMain {
|
||||
pmdMain.enabled = false
|
||||
}
|
||||
|
||||
@@ -11,9 +11,12 @@ import edu.wpi.first.networktables.NetworkTablesJNI;
|
||||
import edu.wpi.first.wpiutil.RuntimeDetector;
|
||||
|
||||
public class DevMain {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
System.out.println(RuntimeDetector.getPlatformPath());
|
||||
NetworkTablesJNI.flush(NetworkTablesJNI.getDefaultInstance());
|
||||
}
|
||||
/**
|
||||
* Main method.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
System.out.println(RuntimeDetector.getPlatformPath());
|
||||
NetworkTablesJNI.flush(NetworkTablesJNI.getDefaultInstance());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,43 +15,49 @@ public final class ConnectionInfo {
|
||||
* The remote identifier (as set on the remote node by
|
||||
* {@link NetworkTableInstance#setNetworkIdentity(String)}).
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public final String remote_id;
|
||||
|
||||
/**
|
||||
* The IP address of the remote node.
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public final String remote_ip;
|
||||
|
||||
/**
|
||||
* The port number of the remote node.
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public final int remote_port;
|
||||
|
||||
/**
|
||||
* The last time any update was received from the remote node (same scale as
|
||||
* returned by {@link NetworkTablesJNI#now()}).
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public final long last_update;
|
||||
|
||||
/**
|
||||
* The protocol version being used for this connection. This is in protocol
|
||||
* layer format, so 0x0200 = 2.0, 0x0300 = 3.0).
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public final int protocol_version;
|
||||
|
||||
/** Constructor.
|
||||
* This should generally only be used internally to NetworkTables.
|
||||
* @param remote_id Remote identifier
|
||||
* @param remote_ip Remote IP address
|
||||
* @param remote_port Remote port number
|
||||
* @param last_update Last time an update was received
|
||||
* @param protocol_version The protocol version used for the connection
|
||||
* @param remoteId Remote identifier
|
||||
* @param remoteIp Remote IP address
|
||||
* @param remotePort Remote port number
|
||||
* @param lastUpdate Last time an update was received
|
||||
* @param protocolVersion The protocol version used for the connection
|
||||
*/
|
||||
public ConnectionInfo(String remote_id, String remote_ip, int remote_port, long last_update, int protocol_version) {
|
||||
this.remote_id = remote_id;
|
||||
this.remote_ip = remote_ip;
|
||||
this.remote_port = remote_port;
|
||||
this.last_update = last_update;
|
||||
this.protocol_version = protocol_version;
|
||||
public ConnectionInfo(String remoteId, String remoteIp, int remotePort, long lastUpdate,
|
||||
int protocolVersion) {
|
||||
remote_id = remoteId;
|
||||
remote_ip = remoteIp;
|
||||
remote_port = remotePort;
|
||||
last_update = lastUpdate;
|
||||
protocol_version = protocolVersion;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,16 +14,19 @@ public final class ConnectionNotification {
|
||||
/**
|
||||
* Listener that was triggered.
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public final int listener;
|
||||
|
||||
/**
|
||||
* True if event is due to connection being established.
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean connected;
|
||||
|
||||
/**
|
||||
* Connection information.
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public final ConnectionInfo conn;
|
||||
|
||||
/** Constructor.
|
||||
@@ -33,16 +36,17 @@ public final class ConnectionNotification {
|
||||
* @param connected Connected if true
|
||||
* @param conn Connection information
|
||||
*/
|
||||
public ConnectionNotification(NetworkTableInstance inst, int listener, boolean connected, ConnectionInfo conn) {
|
||||
this.inst = inst;
|
||||
public ConnectionNotification(NetworkTableInstance inst, int listener, boolean connected,
|
||||
ConnectionInfo conn) {
|
||||
this.m_inst = inst;
|
||||
this.listener = listener;
|
||||
this.connected = connected;
|
||||
this.conn = conn;
|
||||
}
|
||||
|
||||
private final NetworkTableInstance inst;
|
||||
private final NetworkTableInstance m_inst;
|
||||
|
||||
public NetworkTableInstance getInstance() {
|
||||
return inst;
|
||||
return m_inst;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,18 +12,23 @@ package edu.wpi.first.networktables;
|
||||
*/
|
||||
public final class EntryInfo {
|
||||
/** Entry handle. */
|
||||
@SuppressWarnings("MemberName")
|
||||
public final int entry;
|
||||
|
||||
/** Entry name. */
|
||||
@SuppressWarnings("MemberName")
|
||||
public final String name;
|
||||
|
||||
/** Entry type. */
|
||||
@SuppressWarnings("MemberName")
|
||||
public final NetworkTableType type;
|
||||
|
||||
/** Entry flags. */
|
||||
@SuppressWarnings("MemberName")
|
||||
public final int flags;
|
||||
|
||||
/** Timestamp of last change to entry (type or value). */
|
||||
@SuppressWarnings("MemberName")
|
||||
public final long last_change;
|
||||
|
||||
/** Constructor.
|
||||
@@ -33,31 +38,32 @@ public final class EntryInfo {
|
||||
* @param name Name
|
||||
* @param type Type (integer version of {@link NetworkTableType})
|
||||
* @param flags Flags
|
||||
* @param last_change Timestamp of last change
|
||||
* @param lastChange Timestamp of last change
|
||||
*/
|
||||
public EntryInfo(NetworkTableInstance inst, int entry, String name, int type, int flags, long last_change) {
|
||||
this.inst = inst;
|
||||
public EntryInfo(NetworkTableInstance inst, int entry, String name, int type, int flags,
|
||||
long lastChange) {
|
||||
this.m_inst = inst;
|
||||
this.entry = entry;
|
||||
this.name = name;
|
||||
this.type = NetworkTableType.getFromInt(type);
|
||||
this.flags = flags;
|
||||
this.last_change = last_change;
|
||||
this.last_change = lastChange;
|
||||
}
|
||||
|
||||
/* Network table instance. */
|
||||
private final NetworkTableInstance inst;
|
||||
private final NetworkTableInstance m_inst;
|
||||
|
||||
/* Cached entry object. */
|
||||
private NetworkTableEntry entryObject;
|
||||
private NetworkTableEntry m_entryObject;
|
||||
|
||||
/**
|
||||
* Get the entry as an object.
|
||||
* @return NetworkTableEntry for this entry.
|
||||
*/
|
||||
NetworkTableEntry getEntry() {
|
||||
if (entryObject == null) {
|
||||
entryObject = new NetworkTableEntry(inst, entry);
|
||||
if (m_entryObject == null) {
|
||||
m_entryObject = new NetworkTableEntry(m_inst, entry);
|
||||
}
|
||||
return entryObject;
|
||||
return m_entryObject;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,51 +10,63 @@ package edu.wpi.first.networktables;
|
||||
/**
|
||||
* Flag values for use with entry listeners.
|
||||
*
|
||||
* The flags are a bitmask and must be OR'ed together to indicate the
|
||||
* <p>The flags are a bitmask and must be OR'ed together to indicate the
|
||||
* combination of events desired to be received.
|
||||
*
|
||||
* The constants kNew, kDelete, kUpdate, and kFlags represent different events
|
||||
* <p>The constants kNew, kDelete, kUpdate, and kFlags represent different events
|
||||
* that can occur to entries.
|
||||
*
|
||||
* By default, notifications are only generated for remote changes occurring
|
||||
* <p>By default, notifications are only generated for remote changes occurring
|
||||
* after the listener is created. The constants kImmediate and kLocal are
|
||||
* modifiers that cause notifications to be generated at other times.
|
||||
*/
|
||||
public interface EntryListenerFlags {
|
||||
/** Initial listener addition.
|
||||
* Set this flag to receive immediate notification of entries matching the
|
||||
/**
|
||||
* Initial listener addition.
|
||||
*
|
||||
* <p>Set this flag to receive immediate notification of entries matching the
|
||||
* flag criteria (generally only useful when combined with kNew).
|
||||
*/
|
||||
public static final int kImmediate = 0x01;
|
||||
int kImmediate = 0x01;
|
||||
|
||||
/** Changed locally.
|
||||
* Set this flag to receive notification of both local changes and changes
|
||||
/**
|
||||
* Changed locally.
|
||||
*
|
||||
* <p>Set this flag to receive notification of both local changes and changes
|
||||
* coming from remote nodes. By default, notifications are only generated
|
||||
* for remote changes. Must be combined with some combination of kNew,
|
||||
* kDelete, kUpdate, and kFlags to receive notifications of those respective
|
||||
* events.
|
||||
*/
|
||||
public static final int kLocal = 0x02;
|
||||
int kLocal = 0x02;
|
||||
|
||||
/** Newly created entry.
|
||||
* Set this flag to receive a notification when an entry is created.
|
||||
/**
|
||||
* Newly created entry.
|
||||
*
|
||||
* <p>Set this flag to receive a notification when an entry is created.
|
||||
*/
|
||||
public static final int kNew = 0x04;
|
||||
int kNew = 0x04;
|
||||
|
||||
/** Entry was deleted.
|
||||
* Set this flag to receive a notification when an entry is deleted.
|
||||
/**
|
||||
* Entry was deleted.
|
||||
*
|
||||
* <p>Set this flag to receive a notification when an entry is deleted.
|
||||
*/
|
||||
public static final int kDelete = 0x08;
|
||||
int kDelete = 0x08;
|
||||
|
||||
/** Entry's value changed.
|
||||
* Set this flag to receive a notification when an entry's value (or type)
|
||||
/**
|
||||
* Entry's value changed.
|
||||
*
|
||||
* <p>Set this flag to receive a notification when an entry's value (or type)
|
||||
* changes.
|
||||
*/
|
||||
public static final int kUpdate = 0x10;
|
||||
int kUpdate = 0x10;
|
||||
|
||||
/** Entry's flags changed.
|
||||
* Set this flag to receive a notification when an entry's flags value
|
||||
/**
|
||||
* Entry's flags changed.
|
||||
*
|
||||
* <p>Set this flag to receive a notification when an entry's flags value
|
||||
* changes.
|
||||
*/
|
||||
public static final int kFlags = 0x20;
|
||||
int kFlags = 0x20;
|
||||
}
|
||||
|
||||
@@ -14,27 +14,32 @@ public final class EntryNotification {
|
||||
/**
|
||||
* Listener that was triggered.
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public final int listener;
|
||||
|
||||
/**
|
||||
* Entry handle.
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public final int entry;
|
||||
|
||||
/**
|
||||
* Entry name.
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public final String name;
|
||||
|
||||
/**
|
||||
* The new value.
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public final NetworkTableValue value;
|
||||
|
||||
/**
|
||||
* Update flags. For example, {@link EntryListenerFlags#kNew} if the key did
|
||||
* not previously exist.
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public final int flags;
|
||||
|
||||
/** Constructor.
|
||||
@@ -46,8 +51,9 @@ public final class EntryNotification {
|
||||
* @param value The new value
|
||||
* @param flags Update flags
|
||||
*/
|
||||
public EntryNotification(NetworkTableInstance inst, int listener, int entry, String name, NetworkTableValue value, int flags) {
|
||||
this.inst = inst;
|
||||
public EntryNotification(NetworkTableInstance inst, int listener, int entry, String name,
|
||||
NetworkTableValue value, int flags) {
|
||||
this.m_inst = inst;
|
||||
this.listener = listener;
|
||||
this.entry = entry;
|
||||
this.name = name;
|
||||
@@ -56,19 +62,19 @@ public final class EntryNotification {
|
||||
}
|
||||
|
||||
/* Network table instance. */
|
||||
private final NetworkTableInstance inst;
|
||||
private final NetworkTableInstance m_inst;
|
||||
|
||||
/* Cached entry object. */
|
||||
NetworkTableEntry entryObject;
|
||||
NetworkTableEntry m_entryObject;
|
||||
|
||||
/**
|
||||
* Get the entry as an object.
|
||||
* @return NetworkTableEntry for this entry.
|
||||
*/
|
||||
public NetworkTableEntry getEntry() {
|
||||
if (entryObject == null) {
|
||||
entryObject = new NetworkTableEntry(inst, entry);
|
||||
if (m_entryObject == null) {
|
||||
m_entryObject = new NetworkTableEntry(m_inst, entry);
|
||||
}
|
||||
return entryObject;
|
||||
return m_entryObject;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,26 +27,31 @@ public final class LogMessage {
|
||||
/**
|
||||
* The logger that generated the message.
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public final int logger;
|
||||
|
||||
/**
|
||||
* Log level of the message.
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public final int level;
|
||||
|
||||
/**
|
||||
* The filename of the source file that generated the message.
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public final String filename;
|
||||
|
||||
/**
|
||||
* The line number in the source file that generated the message.
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public final int line;
|
||||
|
||||
/**
|
||||
* The message.
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public final String message;
|
||||
|
||||
/** Constructor.
|
||||
@@ -58,8 +63,9 @@ public final class LogMessage {
|
||||
* @param line Line number
|
||||
* @param message Message
|
||||
*/
|
||||
public LogMessage(NetworkTableInstance inst, int logger, int level, String filename, int line, String message) {
|
||||
this.inst = inst;
|
||||
public LogMessage(NetworkTableInstance inst, int logger, int level, String filename, int line,
|
||||
String message) {
|
||||
this.m_inst = inst;
|
||||
this.logger = logger;
|
||||
this.level = level;
|
||||
this.filename = filename;
|
||||
@@ -67,9 +73,9 @@ public final class LogMessage {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
private final NetworkTableInstance inst;
|
||||
private final NetworkTableInstance m_inst;
|
||||
|
||||
NetworkTableInstance getInstance() {
|
||||
return inst;
|
||||
return m_inst;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,14 +21,14 @@ import java.util.function.Consumer;
|
||||
*/
|
||||
public final class NetworkTable {
|
||||
/**
|
||||
* The path separator for sub-tables and keys
|
||||
* The path separator for sub-tables and keys.
|
||||
*
|
||||
*/
|
||||
public static final char PATH_SEPARATOR = '/';
|
||||
|
||||
private final String path;
|
||||
private final String pathWithSep;
|
||||
private final NetworkTableInstance inst;
|
||||
private final String m_path;
|
||||
private final String m_pathWithSep;
|
||||
private final NetworkTableInstance m_inst;
|
||||
|
||||
/**
|
||||
* Gets the "base name" of a key. For example, "/foo/bar" becomes "bar".
|
||||
@@ -121,31 +121,35 @@ public final class NetworkTable {
|
||||
* Constructor. Use NetworkTableInstance.getTable() or getSubTable() instead.
|
||||
*/
|
||||
NetworkTable(NetworkTableInstance inst, String path) {
|
||||
this.path = path;
|
||||
this.pathWithSep = path + PATH_SEPARATOR;
|
||||
this.inst = inst;
|
||||
m_path = path;
|
||||
m_pathWithSep = path + PATH_SEPARATOR;
|
||||
m_inst = inst;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the instance for the table.
|
||||
* @return Instance
|
||||
*/
|
||||
public NetworkTableInstance getInstance() { return inst; }
|
||||
public NetworkTableInstance getInstance() {
|
||||
return m_inst;
|
||||
}
|
||||
|
||||
public String toString() { return "NetworkTable: " + path; }
|
||||
public String toString() {
|
||||
return "NetworkTable: " + m_path;
|
||||
}
|
||||
|
||||
private final ConcurrentMap<String, NetworkTableEntry> entries = new ConcurrentHashMap<String, NetworkTableEntry>();
|
||||
private final ConcurrentMap<String, NetworkTableEntry> m_entries = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* Gets the entry for a subkey.
|
||||
* Gets the entry for a sub key.
|
||||
* @param key the key name
|
||||
* @return Network table entry.
|
||||
*/
|
||||
public NetworkTableEntry getEntry(String key) {
|
||||
NetworkTableEntry entry = entries.get(key);
|
||||
NetworkTableEntry entry = m_entries.get(key);
|
||||
if (entry == null) {
|
||||
entry = inst.getEntry(pathWithSep + key);
|
||||
entries.putIfAbsent(key, entry);
|
||||
entry = m_inst.getEntry(m_pathWithSep + key);
|
||||
m_entries.putIfAbsent(key, entry);
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
@@ -157,11 +161,13 @@ public final class NetworkTable {
|
||||
* @return Listener handle
|
||||
*/
|
||||
public int addEntryListener(TableEntryListener listener, int flags) {
|
||||
final int prefixLen = path.length() + 1;
|
||||
return inst.addEntryListener(pathWithSep, (event) -> {
|
||||
final int prefixLen = m_path.length() + 1;
|
||||
return m_inst.addEntryListener(m_pathWithSep, event -> {
|
||||
String relativeKey = event.name.substring(prefixLen);
|
||||
if (relativeKey.indexOf(PATH_SEPARATOR) != -1) // part of a subtable
|
||||
if (relativeKey.indexOf(PATH_SEPARATOR) != -1) {
|
||||
// part of a sub table
|
||||
return;
|
||||
}
|
||||
listener.valueChanged(this, relativeKey, event.getEntry(), event.value, event.flags);
|
||||
}, flags);
|
||||
}
|
||||
@@ -175,9 +181,8 @@ public final class NetworkTable {
|
||||
*/
|
||||
public int addEntryListener(String key, TableEntryListener listener, int flags) {
|
||||
final NetworkTableEntry entry = getEntry(key);
|
||||
return inst.addEntryListener(entry, (event) -> {
|
||||
listener.valueChanged(this, key, entry, event.value, event.flags);
|
||||
}, flags);
|
||||
return m_inst.addEntryListener(entry,
|
||||
event -> listener.valueChanged(this, key, entry, event.value, event.flags), flags);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,7 +190,7 @@ public final class NetworkTable {
|
||||
* @param listener listener handle
|
||||
*/
|
||||
public void removeEntryListener(int listener) {
|
||||
inst.removeEntryListener(listener);
|
||||
m_inst.removeEntryListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,25 +203,28 @@ public final class NetworkTable {
|
||||
*/
|
||||
public int addSubTableListener(TableListener listener, boolean localNotify) {
|
||||
int flags = EntryListenerFlags.kNew | EntryListenerFlags.kImmediate;
|
||||
if (localNotify)
|
||||
if (localNotify) {
|
||||
flags |= EntryListenerFlags.kLocal;
|
||||
}
|
||||
|
||||
final int prefixLen = path.length() + 1;
|
||||
final int prefixLen = m_path.length() + 1;
|
||||
final NetworkTable parent = this;
|
||||
|
||||
return inst.addEntryListener(pathWithSep, new Consumer<EntryNotification>() {
|
||||
final Set<String> notifiedTables = new HashSet<String>();
|
||||
return m_inst.addEntryListener(m_pathWithSep, new Consumer<EntryNotification>() {
|
||||
final Set<String> m_notifiedTables = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public void accept(EntryNotification event) {
|
||||
String relativeKey = event.name.substring(prefixLen);
|
||||
int endSubTable = relativeKey.indexOf(PATH_SEPARATOR);
|
||||
if (endSubTable == -1)
|
||||
if (endSubTable == -1) {
|
||||
return;
|
||||
}
|
||||
String subTableKey = relativeKey.substring(0, endSubTable);
|
||||
if (notifiedTables.contains(subTableKey))
|
||||
if (m_notifiedTables.contains(subTableKey)) {
|
||||
return;
|
||||
notifiedTables.add(subTableKey);
|
||||
}
|
||||
m_notifiedTables.add(subTableKey);
|
||||
listener.tableCreated(parent, subTableKey, parent.getSubTable(subTableKey));
|
||||
}
|
||||
}, flags);
|
||||
@@ -227,7 +235,7 @@ public final class NetworkTable {
|
||||
* @param listener listener handle
|
||||
*/
|
||||
public void removeTableListener(int listener) {
|
||||
inst.removeEntryListener(listener);
|
||||
m_inst.removeEntryListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,11 +246,11 @@ public final class NetworkTable {
|
||||
* @return a sub table relative to this one
|
||||
*/
|
||||
public NetworkTable getSubTable(String key) {
|
||||
return new NetworkTable(inst, pathWithSep + key);
|
||||
return new NetworkTable(m_inst, m_pathWithSep + key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the table and tells if it contains the specified key
|
||||
* Checks the table and tells if it contains the specified key.
|
||||
*
|
||||
* @param key the key to search for
|
||||
* @return true if the table as a value assigned to the given key
|
||||
@@ -252,12 +260,15 @@ public final class NetworkTable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the table and tells if it contains the specified sub table.
|
||||
*
|
||||
* @param key the key to search for
|
||||
* @return true if there is a subtable with the key which contains at least
|
||||
* one key/subtable of its own
|
||||
* @return true if there is a subtable with the key which contains at least one key/subtable of
|
||||
* its own
|
||||
*/
|
||||
public boolean containsSubTable(String key) {
|
||||
int[] handles = NetworkTablesJNI.getEntries(inst.getHandle(), pathWithSep + key + PATH_SEPARATOR, 0);
|
||||
int[] handles = NetworkTablesJNI.getEntries(m_inst.getHandle(),
|
||||
m_pathWithSep + key + PATH_SEPARATOR, 0);
|
||||
return handles.length != 0;
|
||||
}
|
||||
|
||||
@@ -267,16 +278,17 @@ public final class NetworkTable {
|
||||
* @return keys currently in the table
|
||||
*/
|
||||
public Set<String> getKeys(int types) {
|
||||
Set<String> keys = new HashSet<String>();
|
||||
int prefixLen = path.length() + 1;
|
||||
for (EntryInfo info : inst.getEntryInfo(pathWithSep, types)) {
|
||||
Set<String> keys = new HashSet<>();
|
||||
int prefixLen = m_path.length() + 1;
|
||||
for (EntryInfo info : m_inst.getEntryInfo(m_pathWithSep, types)) {
|
||||
String relativeKey = info.name.substring(prefixLen);
|
||||
if (relativeKey.indexOf(PATH_SEPARATOR) != -1)
|
||||
if (relativeKey.indexOf(PATH_SEPARATOR) != -1) {
|
||||
continue;
|
||||
}
|
||||
keys.add(relativeKey);
|
||||
// populate entries as we go
|
||||
if (entries.get(relativeKey) == null) {
|
||||
entries.putIfAbsent(relativeKey, new NetworkTableEntry(inst, info.entry));
|
||||
if (m_entries.get(relativeKey) == null) {
|
||||
m_entries.putIfAbsent(relativeKey, new NetworkTableEntry(m_inst, info.entry));
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
@@ -295,13 +307,14 @@ public final class NetworkTable {
|
||||
* @return subtables currently in the table
|
||||
*/
|
||||
public Set<String> getSubTables() {
|
||||
Set<String> keys = new HashSet<String>();
|
||||
int prefixLen = path.length() + 1;
|
||||
for (EntryInfo info : inst.getEntryInfo(pathWithSep, 0)) {
|
||||
Set<String> keys = new HashSet<>();
|
||||
int prefixLen = m_path.length() + 1;
|
||||
for (EntryInfo info : m_inst.getEntryInfo(m_pathWithSep, 0)) {
|
||||
String relativeKey = info.name.substring(prefixLen);
|
||||
int endSubTable = relativeKey.indexOf(PATH_SEPARATOR);
|
||||
if (endSubTable == -1)
|
||||
if (endSubTable == -1) {
|
||||
continue;
|
||||
}
|
||||
keys.add(relativeKey.substring(0, endSubTable));
|
||||
}
|
||||
return keys;
|
||||
@@ -318,7 +331,7 @@ public final class NetworkTable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a value in the table
|
||||
* Put a value in the table.
|
||||
*
|
||||
* @param key the key to be assigned to
|
||||
* @param value the value that will be assigned
|
||||
@@ -339,21 +352,20 @@ public final class NetworkTable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value associated with a key as an object
|
||||
* Gets the value associated with a key as an object.
|
||||
*
|
||||
* @param key the key of the value to look up
|
||||
* @return the value associated with the given key, or nullptr if the key
|
||||
* does not exist
|
||||
* @return the value associated with the given key, or nullptr if the key does not exist
|
||||
*/
|
||||
NetworkTableValue getValue(String key) {
|
||||
return getEntry(key).getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* Get the path of the NetworkTable.
|
||||
*/
|
||||
public String getPath() {
|
||||
return path;
|
||||
return m_path;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -363,7 +375,7 @@ public final class NetworkTable {
|
||||
* @throws PersistentException if error saving file
|
||||
*/
|
||||
public void saveEntries(String filename) throws PersistentException {
|
||||
inst.saveEntries(filename, pathWithSep);
|
||||
m_inst.saveEntries(filename, m_pathWithSep);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -374,23 +386,23 @@ public final class NetworkTable {
|
||||
* @throws PersistentException if error saving file
|
||||
*/
|
||||
public String[] loadEntries(String filename) throws PersistentException {
|
||||
return inst.loadEntries(filename, pathWithSep);
|
||||
return m_inst.loadEntries(filename, m_pathWithSep);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) {
|
||||
public boolean equals(Object other) {
|
||||
if (other == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof NetworkTable)) {
|
||||
if (!(other instanceof NetworkTable)) {
|
||||
return false;
|
||||
}
|
||||
NetworkTable other = (NetworkTable) o;
|
||||
return inst.equals(other.inst) && path.equals(other.path);
|
||||
NetworkTable ntOther = (NetworkTable) other;
|
||||
return m_inst.equals(ntOther.m_inst) && m_path.equals(ntOther.m_path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(inst, path);
|
||||
return Objects.hash(m_inst, m_path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.nio.ByteBuffer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* NetworkTables Entry
|
||||
* NetworkTables Entry.
|
||||
*/
|
||||
public final class NetworkTableEntry {
|
||||
/**
|
||||
@@ -178,7 +178,8 @@ public final class NetworkTableEntry {
|
||||
* @return the entry's value or the given default value
|
||||
*/
|
||||
public Boolean[] getBooleanArray(Boolean[] defaultValue) {
|
||||
return NetworkTableValue.fromNative(NetworkTablesJNI.getBooleanArray(m_handle, NetworkTableValue.toNative(defaultValue)));
|
||||
return NetworkTableValue.fromNative(NetworkTablesJNI.getBooleanArray(m_handle,
|
||||
NetworkTableValue.toNative(defaultValue)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,7 +199,8 @@ public final class NetworkTableEntry {
|
||||
* @return the entry's value or the given default value
|
||||
*/
|
||||
public Double[] getDoubleArray(Double[] defaultValue) {
|
||||
return NetworkTableValue.fromNative(NetworkTablesJNI.getDoubleArray(m_handle, NetworkTableValue.toNative(defaultValue)));
|
||||
return NetworkTableValue.fromNative(NetworkTablesJNI.getDoubleArray(m_handle,
|
||||
NetworkTableValue.toNative(defaultValue)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,7 +210,8 @@ public final class NetworkTableEntry {
|
||||
* @return the entry's value or the given default value
|
||||
*/
|
||||
public Number[] getNumberArray(Number[] defaultValue) {
|
||||
return NetworkTableValue.fromNative(NetworkTablesJNI.getDoubleArray(m_handle, NetworkTableValue.toNative(defaultValue)));
|
||||
return NetworkTableValue.fromNative(NetworkTablesJNI.getDoubleArray(m_handle,
|
||||
NetworkTableValue.toNative(defaultValue)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -229,46 +232,48 @@ public final class NetworkTableEntry {
|
||||
*/
|
||||
public boolean setDefaultValue(Object defaultValue) {
|
||||
if (defaultValue instanceof NetworkTableValue) {
|
||||
long time = ((NetworkTableValue)defaultValue).getTime();
|
||||
Object o = ((NetworkTableValue)defaultValue).getValue();
|
||||
switch (((NetworkTableValue)defaultValue).getType()) {
|
||||
long time = ((NetworkTableValue) defaultValue).getTime();
|
||||
Object otherValue = ((NetworkTableValue) defaultValue).getValue();
|
||||
switch (((NetworkTableValue) defaultValue).getType()) {
|
||||
case kBoolean:
|
||||
return NetworkTablesJNI.setDefaultBoolean(m_handle, time, ((Boolean)o).booleanValue());
|
||||
return NetworkTablesJNI.setDefaultBoolean(m_handle, time,
|
||||
((Boolean) otherValue).booleanValue());
|
||||
case kDouble:
|
||||
return NetworkTablesJNI.setDefaultDouble(m_handle, time, ((Number)o).doubleValue());
|
||||
return NetworkTablesJNI.setDefaultDouble(m_handle, time,
|
||||
((Number) otherValue).doubleValue());
|
||||
case kString:
|
||||
return NetworkTablesJNI.setDefaultString(m_handle, time, (String)o);
|
||||
return NetworkTablesJNI.setDefaultString(m_handle, time, (String) otherValue);
|
||||
case kRaw:
|
||||
return NetworkTablesJNI.setDefaultRaw(m_handle, time, (byte[])o);
|
||||
return NetworkTablesJNI.setDefaultRaw(m_handle, time, (byte[]) otherValue);
|
||||
case kBooleanArray:
|
||||
return NetworkTablesJNI.setDefaultBooleanArray(m_handle, time, (boolean[])o);
|
||||
return NetworkTablesJNI.setDefaultBooleanArray(m_handle, time, (boolean[]) otherValue);
|
||||
case kDoubleArray:
|
||||
return NetworkTablesJNI.setDefaultDoubleArray(m_handle, time, (double[])o);
|
||||
return NetworkTablesJNI.setDefaultDoubleArray(m_handle, time, (double[]) otherValue);
|
||||
case kStringArray:
|
||||
return NetworkTablesJNI.setDefaultStringArray(m_handle, time, (String[])o);
|
||||
return NetworkTablesJNI.setDefaultStringArray(m_handle, time, (String[]) otherValue);
|
||||
case kRpc:
|
||||
// TODO
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
} else if (defaultValue instanceof Boolean) {
|
||||
return setDefaultBoolean((Boolean)defaultValue);
|
||||
return setDefaultBoolean((Boolean) defaultValue);
|
||||
} else if (defaultValue instanceof Number) {
|
||||
return setDefaultNumber((Number)defaultValue);
|
||||
return setDefaultNumber((Number) defaultValue);
|
||||
} else if (defaultValue instanceof String) {
|
||||
return setDefaultString((String)defaultValue);
|
||||
} else if (defaultValue instanceof byte[]) {
|
||||
return setDefaultRaw((byte[])defaultValue);
|
||||
} else if (defaultValue instanceof boolean[]) {
|
||||
return setDefaultBooleanArray((boolean[])defaultValue);
|
||||
} else if (defaultValue instanceof double[]) {
|
||||
return setDefaultDoubleArray((double[])defaultValue);
|
||||
} else if (defaultValue instanceof Boolean[]) {
|
||||
return setDefaultBooleanArray((Boolean[])defaultValue);
|
||||
} else if (defaultValue instanceof Number[]) {
|
||||
return setDefaultNumberArray((Number[])defaultValue);
|
||||
} else if (defaultValue instanceof String[]) {
|
||||
return setDefaultStringArray((String[])defaultValue);
|
||||
return setDefaultString((String) defaultValue);
|
||||
} else if (defaultValue instanceof byte[]) {
|
||||
return setDefaultRaw((byte[]) defaultValue);
|
||||
} else if (defaultValue instanceof boolean[]) {
|
||||
return setDefaultBooleanArray((boolean[]) defaultValue);
|
||||
} else if (defaultValue instanceof double[]) {
|
||||
return setDefaultDoubleArray((double[]) defaultValue);
|
||||
} else if (defaultValue instanceof Boolean[]) {
|
||||
return setDefaultBooleanArray((Boolean[]) defaultValue);
|
||||
} else if (defaultValue instanceof Number[]) {
|
||||
return setDefaultNumberArray((Number[]) defaultValue);
|
||||
} else if (defaultValue instanceof String[]) {
|
||||
return setDefaultStringArray((String[]) defaultValue);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Value of type " + defaultValue.getClass().getName()
|
||||
+ " cannot be put into a table");
|
||||
@@ -335,7 +340,8 @@ public final class NetworkTableEntry {
|
||||
* @return False if the entry exists with a different type
|
||||
*/
|
||||
public boolean setDefaultBooleanArray(Boolean[] defaultValue) {
|
||||
return NetworkTablesJNI.setDefaultBooleanArray(m_handle, 0, NetworkTableValue.toNative(defaultValue));
|
||||
return NetworkTablesJNI.setDefaultBooleanArray(m_handle,
|
||||
0, NetworkTableValue.toNative(defaultValue));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -353,7 +359,8 @@ public final class NetworkTableEntry {
|
||||
* @return False if the entry exists with a different type
|
||||
*/
|
||||
public boolean setDefaultNumberArray(Number[] defaultValue) {
|
||||
return NetworkTablesJNI.setDefaultDoubleArray(m_handle, 0, NetworkTableValue.toNative(defaultValue));
|
||||
return NetworkTablesJNI.setDefaultDoubleArray(m_handle,
|
||||
0, NetworkTableValue.toNative(defaultValue));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -366,53 +373,55 @@ public final class NetworkTableEntry {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the entry's value
|
||||
* Sets the entry's value.
|
||||
* @param value the value that will be assigned
|
||||
* @return False if the table key already exists with a different type
|
||||
* @throws IllegalArgumentException if the value is not a known type
|
||||
*/
|
||||
public boolean setValue(Object value) {
|
||||
if (value instanceof NetworkTableValue) {
|
||||
long time = ((NetworkTableValue)value).getTime();
|
||||
Object o = ((NetworkTableValue)value).getValue();
|
||||
switch (((NetworkTableValue)value).getType()) {
|
||||
long time = ((NetworkTableValue) value).getTime();
|
||||
Object otherValue = ((NetworkTableValue) value).getValue();
|
||||
switch (((NetworkTableValue) value).getType()) {
|
||||
case kBoolean:
|
||||
return NetworkTablesJNI.setBoolean(m_handle, time, ((Boolean)o).booleanValue(), false);
|
||||
return NetworkTablesJNI.setBoolean(m_handle, time, ((Boolean) otherValue).booleanValue(),
|
||||
false);
|
||||
case kDouble:
|
||||
return NetworkTablesJNI.setDouble(m_handle, time, ((Number)o).doubleValue(), false);
|
||||
return NetworkTablesJNI.setDouble(m_handle, time, ((Number) otherValue).doubleValue(),
|
||||
false);
|
||||
case kString:
|
||||
return NetworkTablesJNI.setString(m_handle, time, (String)o, false);
|
||||
return NetworkTablesJNI.setString(m_handle, time, (String) otherValue, false);
|
||||
case kRaw:
|
||||
return NetworkTablesJNI.setRaw(m_handle, time, (byte[])o, false);
|
||||
return NetworkTablesJNI.setRaw(m_handle, time, (byte[]) otherValue, false);
|
||||
case kBooleanArray:
|
||||
return NetworkTablesJNI.setBooleanArray(m_handle, time, (boolean[])o, false);
|
||||
return NetworkTablesJNI.setBooleanArray(m_handle, time, (boolean[]) otherValue, false);
|
||||
case kDoubleArray:
|
||||
return NetworkTablesJNI.setDoubleArray(m_handle, time, (double[])o, false);
|
||||
return NetworkTablesJNI.setDoubleArray(m_handle, time, (double[]) otherValue, false);
|
||||
case kStringArray:
|
||||
return NetworkTablesJNI.setStringArray(m_handle, time, (String[])o, false);
|
||||
return NetworkTablesJNI.setStringArray(m_handle, time, (String[]) otherValue, false);
|
||||
case kRpc:
|
||||
// TODO
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
} else if (value instanceof Boolean) {
|
||||
return setBoolean((Boolean)value);
|
||||
return setBoolean((Boolean) value);
|
||||
} else if (value instanceof Number) {
|
||||
return setNumber((Number)value);
|
||||
return setNumber((Number) value);
|
||||
} else if (value instanceof String) {
|
||||
return setString((String)value);
|
||||
return setString((String) value);
|
||||
} else if (value instanceof byte[]) {
|
||||
return setRaw((byte[])value);
|
||||
return setRaw((byte[]) value);
|
||||
} else if (value instanceof boolean[]) {
|
||||
return setBooleanArray((boolean[])value);
|
||||
return setBooleanArray((boolean[]) value);
|
||||
} else if (value instanceof double[]) {
|
||||
return setDoubleArray((double[])value);
|
||||
return setDoubleArray((double[]) value);
|
||||
} else if (value instanceof Boolean[]) {
|
||||
return setBooleanArray((Boolean[])value);
|
||||
return setBooleanArray((Boolean[]) value);
|
||||
} else if (value instanceof Number[]) {
|
||||
return setNumberArray((Number[])value);
|
||||
return setNumberArray((Number[]) value);
|
||||
} else if (value instanceof String[]) {
|
||||
return setStringArray((String[])value);
|
||||
return setStringArray((String[]) value);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Value of type " + value.getClass().getName()
|
||||
+ " cannot be put into a table");
|
||||
@@ -471,10 +480,12 @@ public final class NetworkTableEntry {
|
||||
* @return False if the entry exists with a different type
|
||||
*/
|
||||
public boolean setRaw(ByteBuffer value, int len) {
|
||||
if (!value.isDirect())
|
||||
if (!value.isDirect()) {
|
||||
throw new IllegalArgumentException("must be a direct buffer");
|
||||
if (value.capacity() < len)
|
||||
}
|
||||
if (value.capacity() < len) {
|
||||
throw new IllegalArgumentException("buffer is too small, must be at least " + len);
|
||||
}
|
||||
return NetworkTablesJNI.setRaw(m_handle, 0, value, len, false);
|
||||
}
|
||||
|
||||
@@ -531,29 +542,29 @@ public final class NetworkTableEntry {
|
||||
*/
|
||||
public void forceSetValue(Object value) {
|
||||
if (value instanceof NetworkTableValue) {
|
||||
long time = ((NetworkTableValue)value).getTime();
|
||||
Object o = ((NetworkTableValue)value).getValue();
|
||||
switch (((NetworkTableValue)value).getType()) {
|
||||
long time = ((NetworkTableValue) value).getTime();
|
||||
Object otherValue = ((NetworkTableValue) value).getValue();
|
||||
switch (((NetworkTableValue) value).getType()) {
|
||||
case kBoolean:
|
||||
NetworkTablesJNI.setBoolean(m_handle, time, ((Boolean)o).booleanValue(), true);
|
||||
NetworkTablesJNI.setBoolean(m_handle, time, ((Boolean) otherValue).booleanValue(), true);
|
||||
return;
|
||||
case kDouble:
|
||||
NetworkTablesJNI.setDouble(m_handle, time, ((Number)o).doubleValue(), true);
|
||||
NetworkTablesJNI.setDouble(m_handle, time, ((Number) otherValue).doubleValue(), true);
|
||||
return;
|
||||
case kString:
|
||||
NetworkTablesJNI.setString(m_handle, time, (String)o, true);
|
||||
NetworkTablesJNI.setString(m_handle, time, (String) otherValue, true);
|
||||
return;
|
||||
case kRaw:
|
||||
NetworkTablesJNI.setRaw(m_handle, time, (byte[])o, true);
|
||||
NetworkTablesJNI.setRaw(m_handle, time, (byte[]) otherValue, true);
|
||||
return;
|
||||
case kBooleanArray:
|
||||
NetworkTablesJNI.setBooleanArray(m_handle, time, (boolean[])o, true);
|
||||
NetworkTablesJNI.setBooleanArray(m_handle, time, (boolean[]) otherValue, true);
|
||||
return;
|
||||
case kDoubleArray:
|
||||
NetworkTablesJNI.setDoubleArray(m_handle, time, (double[])o, true);
|
||||
NetworkTablesJNI.setDoubleArray(m_handle, time, (double[]) otherValue, true);
|
||||
return;
|
||||
case kStringArray:
|
||||
NetworkTablesJNI.setStringArray(m_handle, time, (String[])o, true);
|
||||
NetworkTablesJNI.setStringArray(m_handle, time, (String[]) otherValue, true);
|
||||
return;
|
||||
case kRpc:
|
||||
// TODO
|
||||
@@ -561,23 +572,23 @@ public final class NetworkTableEntry {
|
||||
return;
|
||||
}
|
||||
} else if (value instanceof Boolean) {
|
||||
forceSetBoolean((Boolean)value);
|
||||
forceSetBoolean((Boolean) value);
|
||||
} else if (value instanceof Number) {
|
||||
forceSetNumber((Number)value);
|
||||
forceSetNumber((Number) value);
|
||||
} else if (value instanceof String) {
|
||||
forceSetString((String)value);
|
||||
forceSetString((String) value);
|
||||
} else if (value instanceof byte[]) {
|
||||
forceSetRaw((byte[])value);
|
||||
forceSetRaw((byte[]) value);
|
||||
} else if (value instanceof boolean[]) {
|
||||
forceSetBooleanArray((boolean[])value);
|
||||
forceSetBooleanArray((boolean[]) value);
|
||||
} else if (value instanceof double[]) {
|
||||
forceSetDoubleArray((double[])value);
|
||||
forceSetDoubleArray((double[]) value);
|
||||
} else if (value instanceof Boolean[]) {
|
||||
forceSetBooleanArray((Boolean[])value);
|
||||
forceSetBooleanArray((Boolean[]) value);
|
||||
} else if (value instanceof Number[]) {
|
||||
forceSetNumberArray((Number[])value);
|
||||
forceSetNumberArray((Number[]) value);
|
||||
} else if (value instanceof String[]) {
|
||||
forceSetStringArray((String[])value);
|
||||
forceSetStringArray((String[]) value);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Value of type " + value.getClass().getName()
|
||||
+ " cannot be put into a table");
|
||||
@@ -731,8 +742,8 @@ public final class NetworkTableEntry {
|
||||
|
||||
/**
|
||||
* Call a RPC function. May be used on either the client or server.
|
||||
* This function is non-blocking. Either {@link RpcCall#GetResult()} or
|
||||
* {@link RpcCall#CancelResult()} must be called on the return value to either
|
||||
* This function is non-blocking. Either {@link RpcCall#getResult()} or
|
||||
* {@link RpcCall#cancelResult()} must be called on the return value to either
|
||||
* get or ignore the result of the call.
|
||||
* @param params parameter
|
||||
* @return RPC call object.
|
||||
@@ -742,7 +753,7 @@ public final class NetworkTableEntry {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a listener for changes to the entry
|
||||
* Add a listener for changes to the entry.
|
||||
* @param listener the listener to add
|
||||
* @param flags bitmask specifying desired notifications
|
||||
* @return listener handle
|
||||
@@ -752,7 +763,7 @@ public final class NetworkTableEntry {
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a listener from receiving entry events
|
||||
* Remove a listener from receiving entry events.
|
||||
* @param listener the listener to be removed
|
||||
*/
|
||||
public void removeListener(int listener) {
|
||||
@@ -760,15 +771,15 @@ public final class NetworkTableEntry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) {
|
||||
public boolean equals(Object other) {
|
||||
if (other == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof NetworkTableEntry)) {
|
||||
if (!(other instanceof NetworkTableEntry)) {
|
||||
return false;
|
||||
}
|
||||
NetworkTableEntry other = (NetworkTableEntry) o;
|
||||
return m_handle == other.m_handle;
|
||||
|
||||
return m_handle == ((NetworkTableEntry) other).m_handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,18 +19,18 @@ import java.util.function.Consumer;
|
||||
/**
|
||||
* NetworkTables Instance.
|
||||
*
|
||||
* Instances are completely independent from each other. Table operations on
|
||||
* <p>Instances are completely independent from each other. Table operations on
|
||||
* one instance will not be visible to other instances unless the instances are
|
||||
* connected via the network. The main limitation on instances is that you
|
||||
* cannot have two servers on the same network port. The main utility of
|
||||
* instances is for unit testing, but they can also enable one program to
|
||||
* connect to two different NetworkTables networks.
|
||||
*
|
||||
* The global "default" instance (as returned by {@link #getDefault()}) is
|
||||
* <p>The global "default" instance (as returned by {@link #getDefault()}) is
|
||||
* always available, and is intended for the common case when there is only
|
||||
* a single NetworkTables instance being used in the program.
|
||||
*
|
||||
* Additional instances can be created with the {@link #create()} function.
|
||||
* <p>Additional instances can be created with the {@link #create()} function.
|
||||
* A reference must be kept to the NetworkTableInstance returned by this
|
||||
* function to keep it from being garbage collected.
|
||||
*/
|
||||
@@ -89,7 +89,7 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
* Get global default instance.
|
||||
* @return Global default instance
|
||||
*/
|
||||
public synchronized static NetworkTableInstance getDefault() {
|
||||
public static synchronized NetworkTableInstance getDefault() {
|
||||
if (s_defaultInstance == null) {
|
||||
s_defaultInstance = new NetworkTableInstance(NetworkTablesJNI.getDefaultInstance());
|
||||
}
|
||||
@@ -131,7 +131,7 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
* only return a subset of all entries.
|
||||
*
|
||||
* @param prefix entry name required prefix; only entries whose name
|
||||
* starts with this string are returned
|
||||
* starts with this string are returned
|
||||
* @param types bitmask of types; 0 is treated as a "don't care"
|
||||
* @return Array of entries.
|
||||
*/
|
||||
@@ -150,7 +150,7 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
* only return a subset of all entries.
|
||||
*
|
||||
* @param prefix entry name required prefix; only entries whose name
|
||||
* starts with this string are returned
|
||||
* starts with this string are returned
|
||||
* @param types bitmask of types; 0 is treated as a "don't care"
|
||||
* @return Array of entry information.
|
||||
*/
|
||||
@@ -203,12 +203,12 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
*/
|
||||
|
||||
private static class EntryConsumer<T> {
|
||||
final NetworkTableEntry entry;
|
||||
final Consumer<T> consumer;
|
||||
final NetworkTableEntry m_entry;
|
||||
final Consumer<T> m_consumer;
|
||||
|
||||
EntryConsumer(NetworkTableEntry entry, Consumer<T> consumer) {
|
||||
this.entry = entry;
|
||||
this.consumer = consumer;
|
||||
m_entry = entry;
|
||||
m_consumer = consumer;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,7 +238,8 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
m_entryListenerLock.unlock();
|
||||
}
|
||||
Thread.currentThread().interrupt();
|
||||
wasInterrupted = true; // don't try to destroy poller, as its handle is likely no longer valid
|
||||
// don't try to destroy poller, as its handle is likely no longer valid
|
||||
wasInterrupted = true;
|
||||
break;
|
||||
}
|
||||
for (EntryNotification event : events) {
|
||||
@@ -250,11 +251,12 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
m_entryListenerLock.unlock();
|
||||
}
|
||||
if (listener != null) {
|
||||
event.entryObject = listener.entry;
|
||||
event.m_entryObject = listener.m_entry;
|
||||
try {
|
||||
listener.consumer.accept(event);
|
||||
listener.m_consumer.accept(event);
|
||||
} catch (Throwable throwable) {
|
||||
System.err.println("Unhandled exception during entry listener callback: " + throwable.toString());
|
||||
System.err.println("Unhandled exception during entry listener callback: "
|
||||
+ throwable.toString());
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -305,7 +307,9 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
* @param flags {@link EntryListenerFlags} bitmask
|
||||
* @return Listener handle
|
||||
*/
|
||||
public int addEntryListener(NetworkTableEntry entry, Consumer<EntryNotification> listener, int flags) {
|
||||
public int addEntryListener(NetworkTableEntry entry,
|
||||
Consumer<EntryNotification> listener,
|
||||
int flags) {
|
||||
if (!equals(entry.getInstance())) {
|
||||
throw new IllegalArgumentException("entry does not belong to this instance");
|
||||
}
|
||||
@@ -315,7 +319,8 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
m_entryListenerPoller = NetworkTablesJNI.createEntryListenerPoller(m_handle);
|
||||
startEntryListenerThread();
|
||||
}
|
||||
int handle = NetworkTablesJNI.addPolledEntryListener(m_entryListenerPoller, entry.getHandle(), flags);
|
||||
int handle = NetworkTablesJNI.addPolledEntryListener(m_entryListenerPoller, entry.getHandle(),
|
||||
flags);
|
||||
m_entryListeners.put(handle, new EntryConsumer<>(entry, listener));
|
||||
return handle;
|
||||
} finally {
|
||||
@@ -354,7 +359,8 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
if (timeout < 0) {
|
||||
m_entryListenerWaitQueueCond.await();
|
||||
} else {
|
||||
return m_entryListenerWaitQueueCond.await((long) (timeout * 1e9), TimeUnit.NANOSECONDS);
|
||||
return m_entryListenerWaitQueueCond.await((long) (timeout * 1e9),
|
||||
TimeUnit.NANOSECONDS);
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
@@ -369,11 +375,13 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
}
|
||||
|
||||
private final ReentrantLock m_connectionListenerLock = new ReentrantLock();
|
||||
private final Map<Integer, Consumer<ConnectionNotification>> m_connectionListeners = new HashMap<>();
|
||||
private final Map<Integer, Consumer<ConnectionNotification>> m_connectionListeners
|
||||
= new HashMap<>();
|
||||
private Thread m_connectionListenerThread;
|
||||
private int m_connectionListenerPoller;
|
||||
private boolean m_connectionListenerWaitQueue;
|
||||
private final Condition m_connectionListenerWaitQueueCond = m_connectionListenerLock.newCondition();
|
||||
private final Condition m_connectionListenerWaitQueueCond
|
||||
= m_connectionListenerLock.newCondition();
|
||||
|
||||
private void startConnectionListenerThread() {
|
||||
m_connectionListenerThread = new Thread(() -> {
|
||||
@@ -394,7 +402,8 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
m_connectionListenerLock.unlock();
|
||||
}
|
||||
Thread.currentThread().interrupt();
|
||||
wasInterrupted = true; // don't try to destroy poller, as its handle is likely no longer valid
|
||||
// don't try to destroy poller, as its handle is likely no longer valid
|
||||
wasInterrupted = true;
|
||||
break;
|
||||
}
|
||||
for (ConnectionNotification event : events) {
|
||||
@@ -409,7 +418,8 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
try {
|
||||
listener.accept(event);
|
||||
} catch (Throwable throwable) {
|
||||
System.err.println("Unhandled exception during connection listener callback: " + throwable.toString());
|
||||
System.err.println("Unhandled exception during connection listener callback: "
|
||||
+ throwable.toString());
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -436,14 +446,16 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
* @param immediateNotify Notify listener of all existing connections
|
||||
* @return Listener handle
|
||||
*/
|
||||
public int addConnectionListener(Consumer<ConnectionNotification> listener, boolean immediateNotify) {
|
||||
public int addConnectionListener(Consumer<ConnectionNotification> listener,
|
||||
boolean immediateNotify) {
|
||||
m_connectionListenerLock.lock();
|
||||
try {
|
||||
if (m_connectionListenerPoller == 0) {
|
||||
m_connectionListenerPoller = NetworkTablesJNI.createConnectionListenerPoller(m_handle);
|
||||
startConnectionListenerThread();
|
||||
}
|
||||
int handle = NetworkTablesJNI.addPolledConnectionListener(m_connectionListenerPoller, immediateNotify);
|
||||
int handle = NetworkTablesJNI.addPolledConnectionListener(m_connectionListenerPoller,
|
||||
immediateNotify);
|
||||
m_connectionListeners.put(handle, listener);
|
||||
return handle;
|
||||
} finally {
|
||||
@@ -488,7 +500,8 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
if (timeout < 0) {
|
||||
m_connectionListenerWaitQueueCond.await();
|
||||
} else {
|
||||
return m_connectionListenerWaitQueueCond.await((long) (timeout * 1e9), TimeUnit.NANOSECONDS);
|
||||
return m_connectionListenerWaitQueueCond.await((long) (timeout * 1e9),
|
||||
TimeUnit.NANOSECONDS);
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
@@ -532,7 +545,8 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
m_rpcCallLock.unlock();
|
||||
}
|
||||
Thread.currentThread().interrupt();
|
||||
wasInterrupted = true; // don't try to destroy poller, as its handle is likely no longer valid
|
||||
// don't try to destroy poller, as its handle is likely no longer valid
|
||||
wasInterrupted = true;
|
||||
break;
|
||||
}
|
||||
for (RpcAnswer event : events) {
|
||||
@@ -544,11 +558,12 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
m_rpcCallLock.unlock();
|
||||
}
|
||||
if (listener != null) {
|
||||
event.entryObject = listener.entry;
|
||||
event.m_entryObject = listener.m_entry;
|
||||
try {
|
||||
listener.consumer.accept(event);
|
||||
listener.m_consumer.accept(event);
|
||||
} catch (Throwable throwable) {
|
||||
System.err.println("Unhandled exception during RPC callback: " + throwable.toString());
|
||||
System.err.println("Unhandled exception during RPC callback: "
|
||||
+ throwable.toString());
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -707,7 +722,7 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a client using the specified server and the default port
|
||||
* Starts a client using the specified server and the default port.
|
||||
*
|
||||
* @param serverName server name
|
||||
*/
|
||||
@@ -716,7 +731,7 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a client using the specified server and port
|
||||
* Starts a client using the specified server and port.
|
||||
*
|
||||
* @param serverName server name
|
||||
* @param port port to communicate over
|
||||
@@ -992,7 +1007,8 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
events = NetworkTablesJNI.pollLogger(this, m_loggerPoller);
|
||||
} catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
wasInterrupted = true; // don't try to destroy poller, as its handle is likely no longer valid
|
||||
// don't try to destroy poller, as its handle is likely no longer valid
|
||||
wasInterrupted = true;
|
||||
break;
|
||||
}
|
||||
for (LogMessage event : events) {
|
||||
@@ -1007,7 +1023,8 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
try {
|
||||
logger.accept(event);
|
||||
} catch (Throwable throwable) {
|
||||
System.err.println("Unhandled exception during logger callback: " + throwable.toString());
|
||||
System.err.println("Unhandled exception during logger callback: "
|
||||
+ throwable.toString());
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -1106,15 +1123,15 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) {
|
||||
public boolean equals(Object other) {
|
||||
if (other == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof NetworkTableInstance)) {
|
||||
if (!(other instanceof NetworkTableInstance)) {
|
||||
return false;
|
||||
}
|
||||
NetworkTableInstance other = (NetworkTableInstance) o;
|
||||
return m_handle == other.m_handle;
|
||||
|
||||
return m_handle == ((NetworkTableInstance) other).m_handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,9 +21,10 @@ public enum NetworkTableType {
|
||||
kStringArray(0x40),
|
||||
kRpc(0x80);
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
private final int value;
|
||||
|
||||
private NetworkTableType(int value) {
|
||||
NetworkTableType(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -31,6 +32,12 @@ public enum NetworkTableType {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from the numerical representation of type to an enum type.
|
||||
*
|
||||
* @param value The numerical representation of kind
|
||||
* @return The kind
|
||||
*/
|
||||
public static NetworkTableType getFromInt(int value) {
|
||||
switch (value) {
|
||||
case 0x01: return kBoolean;
|
||||
|
||||
@@ -133,98 +133,98 @@ public final class NetworkTableValue {
|
||||
|
||||
/**
|
||||
* Get the entry's boolean value.
|
||||
* @throws ClassCastException if the entry value is not of boolean type.
|
||||
* @return The boolean value.
|
||||
* @throws ClassCastException if the entry value is not of boolean type.
|
||||
*/
|
||||
public boolean getBoolean() {
|
||||
if (m_type != NetworkTableType.kBoolean) {
|
||||
throw new ClassCastException("cannot convert " + m_type + " to boolean");
|
||||
}
|
||||
return ((Boolean)m_value).booleanValue();
|
||||
return ((Boolean) m_value).booleanValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry's double value.
|
||||
* @throws ClassCastException if the entry value is not of double type.
|
||||
* @return The double value.
|
||||
* @throws ClassCastException if the entry value is not of double type.
|
||||
*/
|
||||
public double getDouble() {
|
||||
if (m_type != NetworkTableType.kDouble) {
|
||||
throw new ClassCastException("cannot convert " + m_type + " to double");
|
||||
}
|
||||
return ((Number)m_value).doubleValue();
|
||||
return ((Number) m_value).doubleValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry's string value.
|
||||
* @throws ClassCastException if the entry value is not of string type.
|
||||
* @return The string value.
|
||||
* @throws ClassCastException if the entry value is not of string type.
|
||||
*/
|
||||
public String getString() {
|
||||
if (m_type != NetworkTableType.kString) {
|
||||
throw new ClassCastException("cannot convert " + m_type + " to string");
|
||||
}
|
||||
return (String)m_value;
|
||||
return (String) m_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry's raw value.
|
||||
* @throws ClassCastException if the entry value is not of raw type.
|
||||
* @return The raw value.
|
||||
* @throws ClassCastException if the entry value is not of raw type.
|
||||
*/
|
||||
public byte[] getRaw() {
|
||||
if (m_type != NetworkTableType.kRaw) {
|
||||
throw new ClassCastException("cannot convert " + m_type + " to raw");
|
||||
}
|
||||
return (byte[])m_value;
|
||||
return (byte[]) m_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry's rpc definition value.
|
||||
* @throws ClassCastException if the entry value is not of rpc definition type.
|
||||
* @return The rpc definition value.
|
||||
* @throws ClassCastException if the entry value is not of rpc definition type.
|
||||
*/
|
||||
public byte[] getRpc() {
|
||||
if (m_type != NetworkTableType.kRpc) {
|
||||
throw new ClassCastException("cannot convert " + m_type + " to rpc");
|
||||
}
|
||||
return (byte[])m_value;
|
||||
return (byte[]) m_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry's boolean array value.
|
||||
* @throws ClassCastException if the entry value is not of boolean array type.
|
||||
* @return The boolean array value.
|
||||
* @throws ClassCastException if the entry value is not of boolean array type.
|
||||
*/
|
||||
public boolean[] getBooleanArray() {
|
||||
if (m_type != NetworkTableType.kBooleanArray) {
|
||||
throw new ClassCastException("cannot convert " + m_type + " to boolean array");
|
||||
}
|
||||
return (boolean[])m_value;
|
||||
return (boolean[]) m_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry's double array value.
|
||||
* @throws ClassCastException if the entry value is not of double array type.
|
||||
* @return The double array value.
|
||||
* @throws ClassCastException if the entry value is not of double array type.
|
||||
*/
|
||||
public double[] getDoubleArray() {
|
||||
if (m_type != NetworkTableType.kDoubleArray) {
|
||||
throw new ClassCastException("cannot convert " + m_type + " to double array");
|
||||
}
|
||||
return (double[])m_value;
|
||||
return (double[]) m_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entry's string array value.
|
||||
* @throws ClassCastException if the entry value is not of string array type.
|
||||
* @return The string array value.
|
||||
* @throws ClassCastException if the entry value is not of string array type.
|
||||
*/
|
||||
public String[] getStringArray() {
|
||||
if (m_type != NetworkTableType.kStringArray) {
|
||||
throw new ClassCastException("cannot convert " + m_type + " to string array");
|
||||
}
|
||||
return (String[])m_value;
|
||||
return (String[]) m_value;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -422,15 +422,15 @@ public final class NetworkTableValue {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) {
|
||||
public boolean equals(Object other) {
|
||||
if (other == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof NetworkTableValue)) {
|
||||
if (!(other instanceof NetworkTableValue)) {
|
||||
return false;
|
||||
}
|
||||
NetworkTableValue other = (NetworkTableValue) o;
|
||||
return m_type == other.m_type && m_value.equals(other.m_value);
|
||||
NetworkTableValue ntOther = (NetworkTableValue) other;
|
||||
return m_type == ntOther.m_type && m_value.equals(ntOther.m_value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -440,29 +440,33 @@ public final class NetworkTableValue {
|
||||
|
||||
static boolean[] toNative(Boolean[] arr) {
|
||||
boolean[] out = new boolean[arr.length];
|
||||
for (int i = 0; i < arr.length; i++)
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
out[i] = arr[i];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
static double[] toNative(Number[] arr) {
|
||||
double[] out = new double[arr.length];
|
||||
for (int i = 0; i < arr.length; i++)
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
out[i] = arr[i].doubleValue();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
static Boolean[] fromNative(boolean[] arr) {
|
||||
Boolean[] out = new Boolean[arr.length];
|
||||
for (int i = 0; i < arr.length; i++)
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
out[i] = arr[i];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
static Double[] fromNative(double[] arr) {
|
||||
Double[] out = new Double[arr.length];
|
||||
for (int i = 0; i < arr.length; i++)
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
out[i] = arr[i];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,32 +8,35 @@
|
||||
package edu.wpi.first.networktables;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import edu.wpi.first.wpiutil.RuntimeDetector;
|
||||
|
||||
public final class NetworkTablesJNI {
|
||||
static boolean libraryLoaded = false;
|
||||
static File jniLibrary = null;
|
||||
|
||||
static {
|
||||
if (!libraryLoaded) {
|
||||
try {
|
||||
System.loadLibrary("ntcore");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
} catch (UnsatisfiedLinkError linkError) {
|
||||
try {
|
||||
String resname = RuntimeDetector.getLibraryResource("ntcore");
|
||||
InputStream is = NetworkTablesJNI.class.getResourceAsStream(resname);
|
||||
if (is != null) {
|
||||
// create temporary file
|
||||
if (System.getProperty("os.name").startsWith("Windows"))
|
||||
if (System.getProperty("os.name").startsWith("Windows")) {
|
||||
jniLibrary = File.createTempFile("NetworkTablesJNI", ".dll");
|
||||
else if (System.getProperty("os.name").startsWith("Mac"))
|
||||
} else if (System.getProperty("os.name").startsWith("Mac")) {
|
||||
jniLibrary = File.createTempFile("libNetworkTablesJNI", ".dylib");
|
||||
else
|
||||
} else {
|
||||
jniLibrary = File.createTempFile("libNetworkTablesJNI", ".so");
|
||||
}
|
||||
// flag for delete on exit
|
||||
jniLibrary.deleteOnExit();
|
||||
OutputStream os = new FileOutputStream(jniLibrary);
|
||||
|
||||
@@ -10,17 +10,12 @@ package edu.wpi.first.networktables;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* An exception thrown when persistent load/save fails in a {@link NetworkTable}
|
||||
*
|
||||
* An exception thrown when persistent load/save fails in a {@link NetworkTable}.
|
||||
*/
|
||||
public final class PersistentException extends IOException {
|
||||
public static final long serialVersionUID = 0;
|
||||
|
||||
/**
|
||||
* @param message The error message
|
||||
*/
|
||||
public PersistentException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,18 +12,23 @@ package edu.wpi.first.networktables;
|
||||
*/
|
||||
public final class RpcAnswer implements AutoCloseable {
|
||||
/** Entry handle. */
|
||||
@SuppressWarnings("MemberName")
|
||||
public final int entry;
|
||||
|
||||
/** Call handle. */
|
||||
@SuppressWarnings("MemberName")
|
||||
public int call;
|
||||
|
||||
/** Entry name. */
|
||||
@SuppressWarnings("MemberName")
|
||||
public final String name;
|
||||
|
||||
/** Call raw parameters. */
|
||||
@SuppressWarnings("MemberName")
|
||||
public final String params;
|
||||
|
||||
/** Connection that called the RPC. */
|
||||
@SuppressWarnings("MemberName")
|
||||
public final ConnectionInfo conn;
|
||||
|
||||
/** Constructor.
|
||||
@@ -35,8 +40,9 @@ public final class RpcAnswer implements AutoCloseable {
|
||||
* @param params Call raw parameters
|
||||
* @param conn Connection info
|
||||
*/
|
||||
public RpcAnswer(NetworkTableInstance inst, int entry, int call, String name, String params, ConnectionInfo conn) {
|
||||
this.inst = inst;
|
||||
public RpcAnswer(NetworkTableInstance inst, int entry, int call, String name, String params,
|
||||
ConnectionInfo conn) {
|
||||
this.m_inst = inst;
|
||||
this.entry = entry;
|
||||
this.call = call;
|
||||
this.name = name;
|
||||
@@ -79,19 +85,19 @@ public final class RpcAnswer implements AutoCloseable {
|
||||
}
|
||||
|
||||
/* Network table instance. */
|
||||
private final NetworkTableInstance inst;
|
||||
private final NetworkTableInstance m_inst;
|
||||
|
||||
/* Cached entry object. */
|
||||
NetworkTableEntry entryObject;
|
||||
NetworkTableEntry m_entryObject;
|
||||
|
||||
/**
|
||||
* Get the entry as an object.
|
||||
* @return NetworkTableEntry for the RPC.
|
||||
*/
|
||||
NetworkTableEntry getEntry() {
|
||||
if (entryObject == null) {
|
||||
entryObject = new NetworkTableEntry(inst, entry);
|
||||
if (m_entryObject == null) {
|
||||
m_entryObject = new NetworkTableEntry(m_inst, entry);
|
||||
}
|
||||
return entryObject;
|
||||
return m_entryObject;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ package edu.wpi.first.networktables;
|
||||
/**
|
||||
* NetworkTables Remote Procedure Call.
|
||||
*/
|
||||
public final class RpcCall implements AutoCloseable{
|
||||
public final class RpcCall implements AutoCloseable {
|
||||
/** Constructor.
|
||||
* This should generally only be used internally to NetworkTables.
|
||||
* @param entry Entry
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
package edu.wpi.first.networktables;
|
||||
|
||||
/**
|
||||
* A listener that listens to changes in values in a {@link NetworkTable}
|
||||
* A listener that listens to changes in values in a {@link NetworkTable}.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface TableEntryListener extends EntryListenerFlags {
|
||||
@@ -20,7 +20,8 @@ public interface TableEntryListener extends EntryListenerFlags {
|
||||
* @param entry the entry associated with the value that changed
|
||||
* @param value the new value
|
||||
* @param flags update flags; for example, EntryListenerFlags.kNew if the key
|
||||
* did not previously exist in the table
|
||||
* did not previously exist in the table
|
||||
*/
|
||||
void valueChanged(NetworkTable table, String key, NetworkTableEntry entry, NetworkTableValue value, int flags);
|
||||
void valueChanged(NetworkTable table, String key, NetworkTableEntry entry,
|
||||
NetworkTableValue value, int flags);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
package edu.wpi.first.networktables;
|
||||
|
||||
/**
|
||||
* A listener that listens to new tables in a {@link NetworkTable}
|
||||
* A listener that listens to new tables in a {@link NetworkTable}.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface TableListener {
|
||||
|
||||
@@ -7,6 +7,17 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.networktables;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import edu.wpi.first.networktables.ConnectionInfo;
|
||||
import edu.wpi.first.networktables.ConnectionNotification;
|
||||
import edu.wpi.first.networktables.EntryInfo;
|
||||
@@ -21,22 +32,13 @@ import edu.wpi.first.wpilibj.tables.IRemote;
|
||||
import edu.wpi.first.wpilibj.tables.IRemoteConnectionListener;
|
||||
import edu.wpi.first.wpilibj.tables.ITable;
|
||||
import edu.wpi.first.wpilibj.tables.ITableListener;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* A network table that knows its subtable path.
|
||||
* @deprecated Use {@link edu.wpi.first.networktables.NetworkTable} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("checkstyle:all")
|
||||
public class NetworkTable implements ITable, IRemote {
|
||||
/**
|
||||
* The path separator for sub-tables and keys
|
||||
|
||||
@@ -9,10 +9,11 @@ package edu.wpi.first.wpilibj.tables;
|
||||
|
||||
|
||||
/**
|
||||
* Represents an object that has a remote connection
|
||||
* Represents an object that has a remote connection.
|
||||
* @deprecated Use {@link edu.wpi.first.networktables.NetworkTableInstance}.
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("checkstyle:all")
|
||||
public interface IRemote {
|
||||
/**
|
||||
* Register an object to listen for connection and disconnection events
|
||||
|
||||
@@ -10,10 +10,11 @@ package edu.wpi.first.wpilibj.tables;
|
||||
import edu.wpi.first.networktables.ConnectionInfo;
|
||||
|
||||
/**
|
||||
* A listener that listens for connection changes in a {@link IRemote} object
|
||||
* A listener that listens for connection changes in a {@link IRemote} object.
|
||||
* @deprecated Use Consumer<{@link edu.wpi.first.networktables.ConnectionNotification}>.
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("checkstyle:all")
|
||||
public interface IRemoteConnectionListener {
|
||||
/**
|
||||
* Called when an IRemote is connected
|
||||
|
||||
@@ -12,10 +12,11 @@ import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* A table whose values can be read and written to
|
||||
* A table whose values can be read and written to.
|
||||
* @deprecated Use {@link edu.wpi.first.networktables.NetworkTable}.
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("checkstyle:all")
|
||||
public interface ITable {
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,13 +8,14 @@
|
||||
package edu.wpi.first.wpilibj.tables;
|
||||
|
||||
/**
|
||||
* A listener that listens to changes in values in a {@link ITable}
|
||||
* A listener that listens to changes in values in a {@link ITable}.
|
||||
* @deprecated Use Consumer<{@link edu.wpi.first.networktables.EntryNotification}>,
|
||||
* {@link edu.wpi.first.networktables.TableEntryListener}, or
|
||||
* {@link edu.wpi.first.networktables.TableListener} as appropriate.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
@Deprecated
|
||||
@SuppressWarnings("checkstyle:all")
|
||||
public interface ITableListener {
|
||||
/**
|
||||
* Called when a key-value pair is changed in a {@link ITable}
|
||||
|
||||
@@ -9,34 +9,38 @@ package edu.wpi.first.networktables;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class ConnectionListenerTest extends TestCase {
|
||||
NetworkTableInstance serverInst;
|
||||
NetworkTableInstance clientInst;
|
||||
NetworkTableInstance m_serverInst;
|
||||
NetworkTableInstance m_clientInst;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
serverInst = NetworkTableInstance.create();
|
||||
serverInst.setNetworkIdentity("server");
|
||||
m_serverInst = NetworkTableInstance.create();
|
||||
m_serverInst.setNetworkIdentity("server");
|
||||
|
||||
clientInst = NetworkTableInstance.create();
|
||||
clientInst.setNetworkIdentity("client");
|
||||
m_clientInst = NetworkTableInstance.create();
|
||||
m_clientInst.setNetworkIdentity("client");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
clientInst.close();
|
||||
serverInst.close();
|
||||
m_clientInst.close();
|
||||
m_serverInst.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to the server.
|
||||
*/
|
||||
private void connect() {
|
||||
serverInst.startServer("connectionlistenertest.ini", "127.0.0.1", 10000);
|
||||
clientInst.startClient("127.0.0.1", 10000);
|
||||
m_serverInst.startServer("connectionlistenertest.ini", "127.0.0.1", 10000);
|
||||
m_clientInst.startClient("127.0.0.1", 10000);
|
||||
|
||||
// wait for client to report it's started, then wait another 0.1 sec
|
||||
try {
|
||||
while ((clientInst.getNetworkMode() & NetworkTableInstance.kNetModeStarting) != 0) {
|
||||
while ((m_clientInst.getNetworkMode() & NetworkTableInstance.kNetModeStarting) != 0) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
Thread.sleep(100);
|
||||
@@ -45,9 +49,12 @@ public class ConnectionListenerTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the JNI.
|
||||
*/
|
||||
public void testJNI() {
|
||||
// set up the poller
|
||||
int poller = NetworkTablesJNI.createConnectionListenerPoller(serverInst.getHandle());
|
||||
int poller = NetworkTablesJNI.createConnectionListenerPoller(m_serverInst.getHandle());
|
||||
assertTrue("bad poller handle", poller != 0);
|
||||
int handle = NetworkTablesJNI.addPolledConnectionListener(poller, false);
|
||||
assertTrue("bad listener handle", handle != 0);
|
||||
@@ -56,10 +63,10 @@ public class ConnectionListenerTest extends TestCase {
|
||||
connect();
|
||||
|
||||
// get the event
|
||||
assertTrue(serverInst.waitForConnectionListenerQueue(1.0));
|
||||
assertTrue(m_serverInst.waitForConnectionListenerQueue(1.0));
|
||||
ConnectionNotification[] events = null;
|
||||
try {
|
||||
events = NetworkTablesJNI.pollConnectionListenerTimeout(serverInst, poller, 0.0);
|
||||
events = NetworkTablesJNI.pollConnectionListenerTimeout(m_serverInst, poller, 0.0);
|
||||
} catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
fail("unexpected interrupted exception" + ex);
|
||||
@@ -71,7 +78,7 @@ public class ConnectionListenerTest extends TestCase {
|
||||
assertTrue(events[0].connected);
|
||||
|
||||
// trigger a disconnect event
|
||||
clientInst.stopClient();
|
||||
m_clientInst.stopClient();
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException ex) {
|
||||
@@ -79,9 +86,9 @@ public class ConnectionListenerTest extends TestCase {
|
||||
}
|
||||
|
||||
// get the event
|
||||
assertTrue(serverInst.waitForConnectionListenerQueue(1.0));
|
||||
assertTrue(m_serverInst.waitForConnectionListenerQueue(1.0));
|
||||
try {
|
||||
events = NetworkTablesJNI.pollConnectionListenerTimeout(serverInst, poller, 0.0);
|
||||
events = NetworkTablesJNI.pollConnectionListenerTimeout(m_serverInst, poller, 0.0);
|
||||
} catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
fail("unexpected interrupted exception" + ex);
|
||||
@@ -94,24 +101,27 @@ public class ConnectionListenerTest extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test threaded behavior.
|
||||
*/
|
||||
public void testThreaded() {
|
||||
serverInst.startServer("connectionlistenertest.ini", "127.0.0.1", 10000);
|
||||
m_serverInst.startServer("connectionlistenertest.ini", "127.0.0.1", 10000);
|
||||
List<ConnectionNotification> events = new ArrayList<>();
|
||||
int handle = serverInst.addConnectionListener((event) -> events.add(event), false);
|
||||
final int handle = m_serverInst.addConnectionListener(events::add, false);
|
||||
|
||||
// trigger a connect event
|
||||
clientInst.startClient("127.0.0.1", 10000);
|
||||
m_clientInst.startClient("127.0.0.1", 10000);
|
||||
|
||||
// wait for client to report it's started, then wait another 0.1 sec
|
||||
try {
|
||||
while ((clientInst.getNetworkMode() & NetworkTableInstance.kNetModeStarting) != 0) {
|
||||
while ((m_clientInst.getNetworkMode() & NetworkTableInstance.kNetModeStarting) != 0) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException ex) {
|
||||
fail("interrupted while waiting for client to start");
|
||||
}
|
||||
assertTrue(serverInst.waitForConnectionListenerQueue(1.0));
|
||||
assertTrue(m_serverInst.waitForConnectionListenerQueue(1.0));
|
||||
|
||||
// get the event
|
||||
assertEquals(events.size(), 1);
|
||||
@@ -120,7 +130,7 @@ public class ConnectionListenerTest extends TestCase {
|
||||
events.clear();
|
||||
|
||||
// trigger a disconnect event
|
||||
clientInst.stopClient();
|
||||
m_clientInst.stopClient();
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException ex) {
|
||||
@@ -128,7 +138,7 @@ public class ConnectionListenerTest extends TestCase {
|
||||
}
|
||||
|
||||
// get the event
|
||||
assertTrue(serverInst.waitForConnectionListenerQueue(1.0));
|
||||
assertTrue(m_serverInst.waitForConnectionListenerQueue(1.0));
|
||||
assertEquals(events.size(), 1);
|
||||
assertEquals(handle, events.get(0).listener);
|
||||
assertFalse(events.get(0).connected);
|
||||
|
||||
@@ -9,36 +9,37 @@ package edu.wpi.first.networktables;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class EntryListenerTest extends TestCase {
|
||||
NetworkTableInstance serverInst;
|
||||
NetworkTableInstance clientInst;
|
||||
NetworkTableInstance m_serverInst;
|
||||
NetworkTableInstance m_clientInst;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
serverInst = NetworkTableInstance.create();
|
||||
serverInst.setNetworkIdentity("server");
|
||||
m_serverInst = NetworkTableInstance.create();
|
||||
m_serverInst.setNetworkIdentity("server");
|
||||
|
||||
clientInst = NetworkTableInstance.create();
|
||||
clientInst.setNetworkIdentity("client");
|
||||
m_clientInst = NetworkTableInstance.create();
|
||||
m_clientInst.setNetworkIdentity("client");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
clientInst.close();
|
||||
serverInst.close();
|
||||
m_clientInst.close();
|
||||
m_serverInst.close();
|
||||
}
|
||||
|
||||
private void connect() {
|
||||
serverInst.startServer("connectionlistenertest.ini", "127.0.0.1", 10000);
|
||||
clientInst.startClient("127.0.0.1", 10000);
|
||||
m_serverInst.startServer("connectionlistenertest.ini", "127.0.0.1", 10000);
|
||||
m_clientInst.startClient("127.0.0.1", 10000);
|
||||
|
||||
// Use connection listener to ensure we've connected
|
||||
int poller = NetworkTablesJNI.createConnectionListenerPoller(clientInst.getHandle());
|
||||
int poller = NetworkTablesJNI.createConnectionListenerPoller(m_clientInst.getHandle());
|
||||
NetworkTablesJNI.addPolledConnectionListener(poller, false);
|
||||
try {
|
||||
if (NetworkTablesJNI.pollConnectionListenerTimeout(clientInst, poller, 1.0).length == 0) {
|
||||
if (NetworkTablesJNI.pollConnectionListenerTimeout(m_clientInst, poller, 1.0).length == 0) {
|
||||
fail("client didn't connect to server");
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
@@ -47,28 +48,31 @@ public class EntryListenerTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test prefix with a new remote.
|
||||
*/
|
||||
public void testPrefixNewRemote() {
|
||||
connect();
|
||||
List<EntryNotification> events = new ArrayList<>();
|
||||
int handle = serverInst.addEntryListener("/foo", (event) -> events.add(event),
|
||||
final int handle = m_serverInst.addEntryListener("/foo", events::add,
|
||||
EntryListenerFlags.kNew);
|
||||
|
||||
// Trigger an event
|
||||
clientInst.getEntry("/foo/bar").setDouble(1.0);
|
||||
clientInst.getEntry("/baz").setDouble(1.0);
|
||||
clientInst.flush();
|
||||
m_clientInst.getEntry("/foo/bar").setDouble(1.0);
|
||||
m_clientInst.getEntry("/baz").setDouble(1.0);
|
||||
m_clientInst.flush();
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException ex) {
|
||||
fail("interrupted while waiting for entries to update");
|
||||
}
|
||||
|
||||
assertTrue(serverInst.waitForEntryListenerQueue(1.0));
|
||||
assertTrue(m_serverInst.waitForEntryListenerQueue(1.0));
|
||||
|
||||
// Check the event
|
||||
assertEquals(events.size(), 1);
|
||||
assertEquals(events.get(0).listener, handle);
|
||||
assertEquals(events.get(0).getEntry(), serverInst.getEntry("/foo/bar"));
|
||||
assertEquals(events.get(0).getEntry(), m_serverInst.getEntry("/foo/bar"));
|
||||
assertEquals(events.get(0).name, "/foo/bar");
|
||||
assertEquals(events.get(0).value, NetworkTableValue.makeDouble(1.0));
|
||||
assertEquals(events.get(0).flags, EntryListenerFlags.kNew);
|
||||
|
||||
@@ -9,30 +9,34 @@ package edu.wpi.first.networktables;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class LoggerTest extends TestCase {
|
||||
NetworkTableInstance clientInst;
|
||||
NetworkTableInstance m_clientInst;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
clientInst = NetworkTableInstance.create();
|
||||
m_clientInst = NetworkTableInstance.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
clientInst.close();
|
||||
m_clientInst.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the logger.
|
||||
*/
|
||||
public void testLogger() {
|
||||
List<LogMessage> msgs = new ArrayList<>();
|
||||
clientInst.addLogger((msg) -> msgs.add(msg), LogMessage.kInfo, 100);
|
||||
m_clientInst.addLogger(msgs::add, LogMessage.kInfo, 100);
|
||||
|
||||
clientInst.startClient("127.0.0.1", 10000);
|
||||
m_clientInst.startClient("127.0.0.1", 10000);
|
||||
|
||||
// wait for client to report it's started, then wait another 0.1 sec
|
||||
try {
|
||||
while ((clientInst.getNetworkMode() & NetworkTableInstance.kNetModeStarting) != 0) {
|
||||
while ((m_clientInst.getNetworkMode() & NetworkTableInstance.kNetModeStarting) != 0) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
Thread.sleep(100);
|
||||
|
||||
@@ -9,6 +9,7 @@ package edu.wpi.first.networktables;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class NetworkTableTest extends TestCase {
|
||||
|
||||
@@ -60,6 +60,16 @@ module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
|
||||
<property name="ignorePattern"
|
||||
value="^package.*|^import.*|a href|href|http://|https://|ftp://" />
|
||||
</module>
|
||||
<module name="ImportOrder">
|
||||
<property name="option"
|
||||
value="bottom"/>
|
||||
<property name="groups"
|
||||
value="/^java\./,javax,com,org,/^edu\./,*,/^edu\.wpi\./,/^edu\.wpi\.first\.wpilibj\.examples\./"/>
|
||||
<property name="separated"
|
||||
value="true"/>
|
||||
<property name="sortStaticImportsAlphabetically"
|
||||
value="true"/>
|
||||
</module>
|
||||
<module name="AvoidStarImport" />
|
||||
<module name="RedundantImport" />
|
||||
<module name="UnusedImports" />
|
||||
@@ -72,10 +82,7 @@ module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
|
||||
value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH" />
|
||||
</module>
|
||||
<module name="NeedBraces" />
|
||||
<module name="LeftCurly">
|
||||
<property name="maxLineLength"
|
||||
value="100" />
|
||||
</module>
|
||||
<module name="LeftCurly" />
|
||||
<module name="RightCurly" />
|
||||
<module name="RightCurly">
|
||||
<property name="option"
|
||||
@@ -233,6 +240,7 @@ module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
|
||||
<property name="allowSamelineMultipleAnnotations"
|
||||
value="true" />
|
||||
</module>
|
||||
<module name="MissingOverride" />
|
||||
<module name="NonEmptyAtclauseDescription" />
|
||||
<module name="JavadocTagContinuationIndentation" />
|
||||
<module name="SummaryJavadoc">
|
||||
|
||||
@@ -1,290 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE
|
||||
module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
|
||||
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
|
||||
<!--
|
||||
Checkstyle configuration that checks the Google coding conventions from Google Java Style
|
||||
that can be found at https://google.github.io/styleguide/javaguide.html.
|
||||
|
||||
Checkstyle is very configurable. Be sure to read the documentation at
|
||||
http://checkstyle.sf.net (or in your downloaded distribution).
|
||||
|
||||
To completely disable a check, just comment it out or delete it from the file.
|
||||
|
||||
Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov.
|
||||
-->
|
||||
<module name="Checker">
|
||||
<property name="charset"
|
||||
value="UTF-8" />
|
||||
<property name="severity"
|
||||
value="error" />
|
||||
<module name="SuppressionFilter">
|
||||
<property name="file"
|
||||
value="styleguide/suppressions.xml" />
|
||||
</module>
|
||||
<property name="fileExtensions"
|
||||
value="java, properties, xml" />
|
||||
<!-- Checks for whitespace -->
|
||||
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
|
||||
<module name="FileTabCharacter">
|
||||
<property name="eachLine"
|
||||
value="true" />
|
||||
</module>
|
||||
<module name="NewlineAtEndOfFile">
|
||||
<property name="lineSeparator"
|
||||
value="lf" />
|
||||
</module>
|
||||
<module name="SuppressWarningsFilter" />
|
||||
<module name="TreeWalker">
|
||||
<module name="SuppressWarningsHolder" />
|
||||
<module name="OuterTypeFilename" />
|
||||
<module name="IllegalTokenText">
|
||||
<property name="tokens"
|
||||
value="STRING_LITERAL, CHAR_LITERAL" />
|
||||
<property name="format"
|
||||
value="\\u00(08|09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)" />
|
||||
<property name="message"
|
||||
value="Avoid using corresponding octal or Unicode escape." />
|
||||
</module>
|
||||
<module name="AvoidEscapedUnicodeCharacters">
|
||||
<property name="allowEscapesForControlCharacters"
|
||||
value="true" />
|
||||
<property name="allowByTailComment"
|
||||
value="true" />
|
||||
<property name="allowNonPrintableEscapes"
|
||||
value="true" />
|
||||
</module>
|
||||
<module name="LineLength">
|
||||
<property name="max"
|
||||
value="100" />
|
||||
<property name="ignorePattern"
|
||||
value="^package.*|^import.*|a href|href|http://|https://|ftp://" />
|
||||
</module>
|
||||
<module name="AvoidStarImport" />
|
||||
<module name="RedundantImport" />
|
||||
<module name="UnusedImports" />
|
||||
<module name="OneTopLevelClass" />
|
||||
<module name="NoLineWrap" />
|
||||
<module name="EmptyBlock">
|
||||
<property name="option"
|
||||
value="TEXT" />
|
||||
<property name="tokens"
|
||||
value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH" />
|
||||
</module>
|
||||
<module name="NeedBraces" />
|
||||
<module name="LeftCurly">
|
||||
<property name="maxLineLength"
|
||||
value="100" />
|
||||
</module>
|
||||
<module name="RightCurly" />
|
||||
<module name="RightCurly">
|
||||
<property name="option"
|
||||
value="alone" />
|
||||
<property name="tokens"
|
||||
value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO, STATIC_INIT, INSTANCE_INIT" />
|
||||
</module>
|
||||
<module name="WhitespaceAround">
|
||||
<property name="allowEmptyConstructors"
|
||||
value="true" />
|
||||
<property name="allowEmptyMethods"
|
||||
value="true" />
|
||||
<property name="allowEmptyTypes"
|
||||
value="true" />
|
||||
<property name="allowEmptyLoops"
|
||||
value="true" />
|
||||
<message key="ws.notFollowed"
|
||||
value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may only be represented as '{}' when not part of a multi-block statement (4.1.3)" />
|
||||
<message key="ws.notPreceded"
|
||||
value="WhitespaceAround: ''{0}'' is not preceded with whitespace." />
|
||||
</module>
|
||||
<module name="WhitespaceAfter" />
|
||||
<module name="OneStatementPerLine" />
|
||||
<module name="MultipleVariableDeclarations" />
|
||||
<module name="ArrayTypeStyle" />
|
||||
<module name="MissingSwitchDefault" />
|
||||
<module name="FallThrough" />
|
||||
<module name="SimplifyBooleanExpression" />
|
||||
<module name="SimplifyBooleanReturn" />
|
||||
<module name="StringLiteralEquality" />
|
||||
<module name="UnnecessaryParentheses" />
|
||||
<module name="UpperEll" />
|
||||
<module name="ModifierOrder" />
|
||||
<module name="RedundantModifier" />
|
||||
<module name="EmptyLineSeparator">
|
||||
<property name="allowNoEmptyLineBetweenFields"
|
||||
value="true" />
|
||||
</module>
|
||||
<module name="SeparatorWrap">
|
||||
<property name="tokens"
|
||||
value="DOT" />
|
||||
<property name="option"
|
||||
value="nl" />
|
||||
</module>
|
||||
<module name="SeparatorWrap">
|
||||
<property name="tokens"
|
||||
value="COMMA" />
|
||||
<property name="option"
|
||||
value="EOL" />
|
||||
</module>
|
||||
<module name="PackageName">
|
||||
<property name="format"
|
||||
value="^[a-z]+(\.[a-z][a-z0-9]*)*$" />
|
||||
<message key="name.invalidPattern"
|
||||
value="Package name ''{0}'' must match pattern ''{1}''." />
|
||||
</module>
|
||||
<module name="TypeName">
|
||||
<message key="name.invalidPattern"
|
||||
value="Type name ''{0}'' must match pattern ''{1}''." />
|
||||
</module>
|
||||
<module name="MemberName">
|
||||
<property name="format"
|
||||
value="^m_[a-z][a-z0-9][a-zA-Z0-9]*$" />
|
||||
<message key="name.invalidPattern"
|
||||
value="Member name ''{0}'' must match pattern ''{1}''." />
|
||||
</module>
|
||||
<module name="ParameterName">
|
||||
<property name="format"
|
||||
value="^[a-z][a-z0-9][a-zA-Z0-9]*$" />
|
||||
<message key="name.invalidPattern"
|
||||
value="Parameter name ''{0}'' must match pattern ''{1}''." />
|
||||
</module>
|
||||
<module name="CatchParameterName">
|
||||
<property name="format"
|
||||
value="^[a-z][a-z0-9][a-zA-Z0-9]*$" />
|
||||
<message key="name.invalidPattern"
|
||||
value="Catch parameter name ''{0}'' must match pattern ''{1}''." />
|
||||
</module>
|
||||
<module name="LocalVariableName">
|
||||
<property name="tokens"
|
||||
value="VARIABLE_DEF" />
|
||||
<property name="format"
|
||||
value="^[a-z][a-z0-9][a-zA-Z0-9]*$" />
|
||||
<property name="allowOneCharVarInForLoop"
|
||||
value="true" />
|
||||
<message key="name.invalidPattern"
|
||||
value="Local variable name ''{0}'' must match pattern ''{1}''." />
|
||||
</module>
|
||||
<module name="ClassTypeParameterName">
|
||||
<property name="format"
|
||||
value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)" />
|
||||
<message key="name.invalidPattern"
|
||||
value="Class type name ''{0}'' must match pattern ''{1}''." />
|
||||
</module>
|
||||
<module name="MethodTypeParameterName">
|
||||
<property name="format"
|
||||
value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)" />
|
||||
<message key="name.invalidPattern"
|
||||
value="Method type name ''{0}'' must match pattern ''{1}''." />
|
||||
</module>
|
||||
<module name="InterfaceTypeParameterName">
|
||||
<property name="format"
|
||||
value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)" />
|
||||
<message key="name.invalidPattern"
|
||||
value="Interface type name ''{0}'' must match pattern ''{1}''." />
|
||||
</module>
|
||||
<module name="NoFinalizer" />
|
||||
<module name="GenericWhitespace">
|
||||
<message key="ws.followed"
|
||||
value="GenericWhitespace ''{0}'' is followed by whitespace." />
|
||||
<message key="ws.preceded"
|
||||
value="GenericWhitespace ''{0}'' is preceded with whitespace." />
|
||||
<message key="ws.illegalFollow"
|
||||
value="GenericWhitespace ''{0}'' should followed by whitespace." />
|
||||
<message key="ws.notPreceded"
|
||||
value="GenericWhitespace ''{0}'' is not preceded with whitespace." />
|
||||
</module>
|
||||
<module name="Indentation">
|
||||
<property name="basicOffset"
|
||||
value="2" />
|
||||
<property name="braceAdjustment"
|
||||
value="0" />
|
||||
<property name="caseIndent"
|
||||
value="2" />
|
||||
<property name="throwsIndent"
|
||||
value="4" />
|
||||
<property name="lineWrappingIndentation"
|
||||
value="4" />
|
||||
<property name="arrayInitIndent"
|
||||
value="2" />
|
||||
</module>
|
||||
<module name="AbbreviationAsWordInName">
|
||||
<property name="ignoreFinal"
|
||||
value="false" />
|
||||
<property name="allowedAbbreviationLength"
|
||||
value="3" />
|
||||
</module>
|
||||
<module name="OverloadMethodsDeclarationOrder" />
|
||||
<module name="VariableDeclarationUsageDistance">
|
||||
<property name="allowedDistance"
|
||||
value="8" />
|
||||
</module>
|
||||
<module name="MethodParamPad" />
|
||||
<module name="TypecastParenPad" />
|
||||
<module name="OperatorWrap">
|
||||
<property name="option"
|
||||
value="NL" />
|
||||
<property name="tokens"
|
||||
value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR, LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR " />
|
||||
</module>
|
||||
<module name="AnnotationLocation">
|
||||
<property name="tokens"
|
||||
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF" />
|
||||
</module>
|
||||
<module name="AnnotationLocation">
|
||||
<property name="tokens"
|
||||
value="VARIABLE_DEF" />
|
||||
<property name="allowSamelineMultipleAnnotations"
|
||||
value="true" />
|
||||
</module>
|
||||
<module name="NonEmptyAtclauseDescription" />
|
||||
<module name="JavadocTagContinuationIndentation" />
|
||||
<module name="SummaryJavadoc">
|
||||
<property name="forbiddenSummaryFragments"
|
||||
value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )" />
|
||||
</module>
|
||||
<module name="JavadocParagraph" />
|
||||
<module name="AtclauseOrder">
|
||||
<property name="tagOrder"
|
||||
value="@param, @return, @throws, @deprecated" />
|
||||
<property name="target"
|
||||
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF" />
|
||||
</module>
|
||||
<module name="JavadocMethod">
|
||||
<property name="scope"
|
||||
value="public" />
|
||||
<property name="allowMissingParamTags"
|
||||
value="true" />
|
||||
<property name="allowMissingThrowsTags"
|
||||
value="true" />
|
||||
<property name="allowMissingReturnTag"
|
||||
value="true" />
|
||||
<property name="minLineCount"
|
||||
value="2" />
|
||||
<property name="allowedAnnotations"
|
||||
value="Override, Test, Before, After, BeforeClass, AfterClass, Parameters" />
|
||||
<property name="allowUndeclaredRTE"
|
||||
value="true" />
|
||||
<property name="allowThrowsTagsForSubclasses"
|
||||
value="true" />
|
||||
<property name="suppressLoadErrors"
|
||||
value="true" />
|
||||
<property name="tokens"
|
||||
value="METHOD_DEF, ANNOTATION_FIELD_DEF" />
|
||||
</module>
|
||||
<module name="MethodName">
|
||||
<property name="format"
|
||||
value="^[a-z][a-z0-9][a-zA-Z0-9_]*$" />
|
||||
<message key="name.invalidPattern"
|
||||
value="Method name ''{0}'' must match pattern ''{1}''." />
|
||||
</module>
|
||||
<module name="SingleLineJavadoc">
|
||||
<property name="ignoreInlineTags"
|
||||
value="false" />
|
||||
</module>
|
||||
<module name="EmptyCatchBlock">
|
||||
<property name="exceptionVariableName"
|
||||
value="expected" />
|
||||
</module>
|
||||
<module name="CommentsIndentation" />
|
||||
</module>
|
||||
</module>
|
||||
@@ -5,6 +5,8 @@ suppressions PUBLIC "-//Puppy Crawl//DTD Suppressions 1.1//EN"
|
||||
<suppressions>
|
||||
<suppress files=".*sim.*"
|
||||
checks="[a-zA-Z0-9]*" />
|
||||
<suppress files="edu.wpi.first.wpilibj.util.WPILibVersion"
|
||||
checks="[a-zA-Z0-9]*" />
|
||||
<suppress files=".*test.*"
|
||||
checks="JavadocMethod" />
|
||||
<suppress files=".*JNI.*"
|
||||
checks="(LineLength|EmptyLineSeparator|ParameterName)" />
|
||||
</suppressions>
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.networktables.NetworkTablesJNI;
|
||||
import edu.wpi.first.wpiutil.RuntimeDetector;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpiutil.RuntimeDetector;
|
||||
|
||||
public class DevMain {
|
||||
/**
|
||||
|
||||
@@ -9,8 +9,8 @@ package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.AnalogJNI;
|
||||
import edu.wpi.first.wpilibj.hal.FRCNetComm.tResourceType;
|
||||
import edu.wpi.first.wpilibj.sim.AnalogInSim;
|
||||
import edu.wpi.first.wpilibj.hal.HAL;
|
||||
import edu.wpi.first.wpilibj.sim.AnalogInSim;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
|
||||
import edu.wpi.first.wpilibj.util.AllocationException;
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.AnalogJNI;
|
||||
import edu.wpi.first.wpilibj.hal.FRCNetComm.tResourceType;
|
||||
import edu.wpi.first.wpilibj.sim.AnalogOutSim;
|
||||
import edu.wpi.first.wpilibj.hal.HAL;
|
||||
import edu.wpi.first.wpilibj.sim.AnalogOutSim;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
|
||||
|
||||
/**
|
||||
|
||||
@@ -193,7 +193,7 @@ public class Compressor extends SendableBase {
|
||||
@Override
|
||||
public void initSendable(SendableBuilder builder) {
|
||||
builder.setSmartDashboardType("Compressor");
|
||||
builder.addBooleanProperty("Enabled", this::enabled, (value) -> {
|
||||
builder.addBooleanProperty("Enabled", this::enabled, value -> {
|
||||
if (value) {
|
||||
start();
|
||||
} else {
|
||||
|
||||
@@ -12,8 +12,8 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.DigitalGlitchFilterJNI;
|
||||
import edu.wpi.first.wpilibj.hal.FRCNetComm.tResourceType;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
|
||||
import edu.wpi.first.wpilibj.hal.HAL;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
|
||||
|
||||
/**
|
||||
* Class to enable glitch filtering on a set of digital inputs. This class will manage adding and
|
||||
|
||||
@@ -166,7 +166,7 @@ public class DoubleSolenoid extends SolenoidBase {
|
||||
public void initSendable(SendableBuilder builder) {
|
||||
builder.setSmartDashboardType("Double Solenoid");
|
||||
builder.setSafeState(() -> set(Value.kOff));
|
||||
builder.addStringProperty("Value", () -> get().name().substring(1), (value) -> {
|
||||
builder.addStringProperty("Value", () -> get().name().substring(1), value -> {
|
||||
if ("Forward".equals(value)) {
|
||||
set(Value.kForward);
|
||||
} else if ("Reverse".equals(value)) {
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.HAL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.HAL;
|
||||
|
||||
/**
|
||||
* GenericHID Interface.
|
||||
*/
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.FRCNetComm.tResourceType;
|
||||
import edu.wpi.first.wpilibj.hal.HAL;
|
||||
import edu.wpi.first.wpilibj.hal.RelayJNI;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
/**
|
||||
@@ -334,6 +334,6 @@ public class Relay extends SendableBase implements MotorSafety {
|
||||
builder.setSmartDashboardType("Relay");
|
||||
builder.setSafeState(() -> set(Value.kOff));
|
||||
builder.addStringProperty("Value", () -> get().getPrettyValue(),
|
||||
(value) -> set(Value.getValueOf(value).orElse(Value.kOff)));
|
||||
value -> set(Value.getValueOf(value).orElse(Value.kOff)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,11 +183,7 @@ public abstract class Trigger extends SendableBase {
|
||||
@Override
|
||||
public void initSendable(SendableBuilder builder) {
|
||||
builder.setSmartDashboardType("Button");
|
||||
builder.setSafeState(() -> {
|
||||
m_sendablePressed = false;
|
||||
});
|
||||
builder.addBooleanProperty("pressed", this::grab, (value) -> {
|
||||
m_sendablePressed = value;
|
||||
});
|
||||
builder.setSafeState(() -> m_sendablePressed = false);
|
||||
builder.addBooleanProperty("pressed", this::grab, value -> m_sendablePressed = value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -555,7 +555,7 @@ public abstract class Command extends SendableBase {
|
||||
public void initSendable(SendableBuilder builder) {
|
||||
builder.setSmartDashboardType("Command");
|
||||
builder.addStringProperty(".name", this::getName, null);
|
||||
builder.addBooleanProperty("running", this::isRunning, (value) -> {
|
||||
builder.addBooleanProperty("running", this::isRunning, value -> {
|
||||
if (value) {
|
||||
if (!isRunning()) {
|
||||
start();
|
||||
|
||||
@@ -13,9 +13,9 @@ import java.util.Map;
|
||||
import edu.wpi.first.networktables.NetworkTable;
|
||||
import edu.wpi.first.networktables.NetworkTableEntry;
|
||||
import edu.wpi.first.networktables.NetworkTableInstance;
|
||||
import edu.wpi.first.wpilibj.Sendable;
|
||||
import edu.wpi.first.wpilibj.command.Scheduler;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilderImpl;
|
||||
import edu.wpi.first.wpilibj.Sendable;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.livewindow;
|
||||
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
|
||||
import edu.wpi.first.wpilibj.Sendable;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
|
||||
|
||||
/**
|
||||
* Live Window Sendable is a special type of object sendable to the live window.
|
||||
|
||||
@@ -7,14 +7,15 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.smartdashboard;
|
||||
|
||||
import edu.wpi.first.networktables.NetworkTableEntry;
|
||||
import edu.wpi.first.networktables.NetworkTableValue;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.DoubleConsumer;
|
||||
import java.util.function.DoubleSupplier;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import edu.wpi.first.networktables.NetworkTableEntry;
|
||||
import edu.wpi.first.networktables.NetworkTableValue;
|
||||
|
||||
public interface SendableBuilder {
|
||||
/**
|
||||
* Set the string representation of the named data type that will be used
|
||||
|
||||
@@ -7,18 +7,19 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.smartdashboard;
|
||||
|
||||
import edu.wpi.first.networktables.EntryListenerFlags;
|
||||
import edu.wpi.first.networktables.NetworkTable;
|
||||
import edu.wpi.first.networktables.NetworkTableEntry;
|
||||
import edu.wpi.first.networktables.NetworkTableValue;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.DoubleConsumer;
|
||||
import java.util.function.DoubleSupplier;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import edu.wpi.first.networktables.EntryListenerFlags;
|
||||
import edu.wpi.first.networktables.NetworkTable;
|
||||
import edu.wpi.first.networktables.NetworkTableEntry;
|
||||
import edu.wpi.first.networktables.NetworkTableValue;
|
||||
|
||||
public class SendableBuilderImpl implements SendableBuilder {
|
||||
private static class Property {
|
||||
@@ -185,10 +186,10 @@ public class SendableBuilderImpl implements SendableBuilder {
|
||||
public void addBooleanProperty(String key, BooleanSupplier getter, BooleanConsumer setter) {
|
||||
Property property = new Property(m_table, key);
|
||||
if (getter != null) {
|
||||
property.m_update = (entry) -> entry.setBoolean(getter.getAsBoolean());
|
||||
property.m_update = entry -> entry.setBoolean(getter.getAsBoolean());
|
||||
}
|
||||
if (setter != null) {
|
||||
property.m_createListener = (entry) -> entry.addListener((event) -> {
|
||||
property.m_createListener = entry -> entry.addListener(event -> {
|
||||
if (event.value.isBoolean()) {
|
||||
setter.accept(event.value.getBoolean());
|
||||
}
|
||||
@@ -208,10 +209,10 @@ public class SendableBuilderImpl implements SendableBuilder {
|
||||
public void addDoubleProperty(String key, DoubleSupplier getter, DoubleConsumer setter) {
|
||||
Property property = new Property(m_table, key);
|
||||
if (getter != null) {
|
||||
property.m_update = (entry) -> entry.setDouble(getter.getAsDouble());
|
||||
property.m_update = entry -> entry.setDouble(getter.getAsDouble());
|
||||
}
|
||||
if (setter != null) {
|
||||
property.m_createListener = (entry) -> entry.addListener((event) -> {
|
||||
property.m_createListener = entry -> entry.addListener(event -> {
|
||||
if (event.value.isDouble()) {
|
||||
setter.accept(event.value.getDouble());
|
||||
}
|
||||
@@ -231,10 +232,10 @@ public class SendableBuilderImpl implements SendableBuilder {
|
||||
public void addStringProperty(String key, Supplier<String> getter, Consumer<String> setter) {
|
||||
Property property = new Property(m_table, key);
|
||||
if (getter != null) {
|
||||
property.m_update = (entry) -> entry.setString(getter.get());
|
||||
property.m_update = entry -> entry.setString(getter.get());
|
||||
}
|
||||
if (setter != null) {
|
||||
property.m_createListener = (entry) -> entry.addListener((event) -> {
|
||||
property.m_createListener = entry -> entry.addListener(event -> {
|
||||
if (event.value.isString()) {
|
||||
setter.accept(event.value.getString());
|
||||
}
|
||||
@@ -255,10 +256,10 @@ public class SendableBuilderImpl implements SendableBuilder {
|
||||
Consumer<boolean[]> setter) {
|
||||
Property property = new Property(m_table, key);
|
||||
if (getter != null) {
|
||||
property.m_update = (entry) -> entry.setBooleanArray(getter.get());
|
||||
property.m_update = entry -> entry.setBooleanArray(getter.get());
|
||||
}
|
||||
if (setter != null) {
|
||||
property.m_createListener = (entry) -> entry.addListener((event) -> {
|
||||
property.m_createListener = entry -> entry.addListener(event -> {
|
||||
if (event.value.isBooleanArray()) {
|
||||
setter.accept(event.value.getBooleanArray());
|
||||
}
|
||||
@@ -279,10 +280,10 @@ public class SendableBuilderImpl implements SendableBuilder {
|
||||
Consumer<double[]> setter) {
|
||||
Property property = new Property(m_table, key);
|
||||
if (getter != null) {
|
||||
property.m_update = (entry) -> entry.setDoubleArray(getter.get());
|
||||
property.m_update = entry -> entry.setDoubleArray(getter.get());
|
||||
}
|
||||
if (setter != null) {
|
||||
property.m_createListener = (entry) -> entry.addListener((event) -> {
|
||||
property.m_createListener = entry -> entry.addListener(event -> {
|
||||
if (event.value.isDoubleArray()) {
|
||||
setter.accept(event.value.getDoubleArray());
|
||||
}
|
||||
@@ -303,10 +304,10 @@ public class SendableBuilderImpl implements SendableBuilder {
|
||||
Consumer<String[]> setter) {
|
||||
Property property = new Property(m_table, key);
|
||||
if (getter != null) {
|
||||
property.m_update = (entry) -> entry.setStringArray(getter.get());
|
||||
property.m_update = entry -> entry.setStringArray(getter.get());
|
||||
}
|
||||
if (setter != null) {
|
||||
property.m_createListener = (entry) -> entry.addListener((event) -> {
|
||||
property.m_createListener = entry -> entry.addListener(event -> {
|
||||
if (event.value.isStringArray()) {
|
||||
setter.accept(event.value.getStringArray());
|
||||
}
|
||||
@@ -326,10 +327,10 @@ public class SendableBuilderImpl implements SendableBuilder {
|
||||
public void addRawProperty(String key, Supplier<byte[]> getter, Consumer<byte[]> setter) {
|
||||
Property property = new Property(m_table, key);
|
||||
if (getter != null) {
|
||||
property.m_update = (entry) -> entry.setRaw(getter.get());
|
||||
property.m_update = entry -> entry.setRaw(getter.get());
|
||||
}
|
||||
if (setter != null) {
|
||||
property.m_createListener = (entry) -> entry.addListener((event) -> {
|
||||
property.m_createListener = entry -> entry.addListener(event -> {
|
||||
if (event.value.isRaw()) {
|
||||
setter.accept(event.value.getRaw());
|
||||
}
|
||||
@@ -350,10 +351,10 @@ public class SendableBuilderImpl implements SendableBuilder {
|
||||
Consumer<NetworkTableValue> setter) {
|
||||
Property property = new Property(m_table, key);
|
||||
if (getter != null) {
|
||||
property.m_update = (entry) -> entry.setValue(getter.get());
|
||||
property.m_update = entry -> entry.setValue(getter.get());
|
||||
}
|
||||
if (setter != null) {
|
||||
property.m_createListener = (entry) -> entry.addListener((event) -> {
|
||||
property.m_createListener = entry -> entry.addListener(event -> {
|
||||
setter.accept(event.value);
|
||||
}, EntryListenerFlags.kImmediate | EntryListenerFlags.kNew | EntryListenerFlags.kUpdate);
|
||||
}
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.HAL;
|
||||
import edu.wpi.first.wpilibj.util.BaseSystemNotInitializedException;
|
||||
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Ported from the old CrioTest Classes.
|
||||
*/
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Ported from the old CrioTest Classes.
|
||||
*/
|
||||
|
||||
@@ -7,12 +7,13 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Before;
|
||||
//import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ConditionalCommandTest extends AbstractCommandTest {
|
||||
MockConditionalCommand m_command;
|
||||
|
||||
@@ -7,9 +7,10 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
import edu.wpi.first.networktables.NetworkTablesJNI;
|
||||
import org.junit.Test;
|
||||
|
||||
import edu.wpi.first.networktables.NetworkTablesJNI;
|
||||
|
||||
public class JNITest {
|
||||
@Test
|
||||
public void jniNtcoreLinkTest() {
|
||||
|
||||
@@ -7,18 +7,18 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.sim;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import edu.wpi.first.wpilibj.AnalogInput;
|
||||
import edu.wpi.first.wpilibj.hal.HAL;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class AnalogInputSimTest {
|
||||
static class DoubleStore {
|
||||
public boolean wasTriggered = false;
|
||||
public boolean wasCorrectType = false;
|
||||
public double setValue = 0;
|
||||
public boolean m_wasTriggered = false;
|
||||
public boolean m_wasCorrectType = false;
|
||||
public double m_setValue = 0;
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -30,7 +30,7 @@ public class AnalogInputSimTest {
|
||||
|
||||
AnalogInSim inputSim = input.getSimObject();
|
||||
|
||||
for (double i = 0; i < 5.0; i+=0.1) {
|
||||
for (double i = 0; i < 5.0; i += 0.1) {
|
||||
inputSim.setVoltage(0);
|
||||
|
||||
assertEquals(input.getVoltage(), 0, 0.001);
|
||||
|
||||
@@ -7,25 +7,25 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.sim;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import edu.wpi.first.wpilibj.AnalogOutput;
|
||||
import edu.wpi.first.wpilibj.hal.HAL;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class AnalogOutputSimTest {
|
||||
static class DoubleStore {
|
||||
public boolean wasTriggered = false;
|
||||
public boolean wasCorrectType = false;
|
||||
public double setValue = -1;
|
||||
public boolean m_wasTriggered = false;
|
||||
public boolean m_wasCorrectType = false;
|
||||
public double m_setValue = -1;
|
||||
|
||||
public void reset() {
|
||||
wasCorrectType = false;
|
||||
wasTriggered = false;
|
||||
setValue = -1;
|
||||
m_wasCorrectType = false;
|
||||
m_wasTriggered = false;
|
||||
m_setValue = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,27 +41,27 @@ public class AnalogOutputSimTest {
|
||||
|
||||
DoubleStore store = new DoubleStore();
|
||||
|
||||
try (CallbackStore cb = outputSim.registerVoltageCallback((s, v) -> {
|
||||
store.wasTriggered = true;
|
||||
store.wasCorrectType = true;
|
||||
store.setValue = v.getDouble();
|
||||
try (CallbackStore cb = outputSim.registerVoltageCallback((name, value) -> {
|
||||
store.m_wasTriggered = true;
|
||||
store.m_wasCorrectType = true;
|
||||
store.m_setValue = value.getDouble();
|
||||
}, false)) {
|
||||
assertFalse(store.wasTriggered);
|
||||
assertFalse(store.m_wasTriggered);
|
||||
|
||||
for (double i = 0.1; i < 5.0; i+=0.1) {
|
||||
for (double i = 0.1; i < 5.0; i += 0.1) {
|
||||
store.reset();
|
||||
|
||||
output.setVoltage(0);
|
||||
|
||||
assertTrue(store.wasTriggered);
|
||||
assertEquals(store.setValue, 0, 0.001);
|
||||
assertTrue(store.m_wasTriggered);
|
||||
assertEquals(store.m_setValue, 0, 0.001);
|
||||
|
||||
store.reset();
|
||||
|
||||
output.setVoltage(i);
|
||||
|
||||
assertTrue(store.wasTriggered);
|
||||
assertEquals(store.setValue, i, 0.001);
|
||||
assertTrue(store.m_wasTriggered);
|
||||
assertEquals(store.m_setValue, i, 0.001);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,10 +21,6 @@ dependencies {
|
||||
compile project(':cameraserver')
|
||||
}
|
||||
|
||||
checkstyle {
|
||||
configFile = new File(rootDir, "styleguide/checkstyleExamples.xml")
|
||||
}
|
||||
|
||||
pmd {
|
||||
consoleOutput = true
|
||||
reportsDir = file("$project.buildDir/reports/pmd")
|
||||
|
||||
@@ -10,6 +10,9 @@ package edu.wpi.first.wpilibj.commands.commandgroup;
|
||||
import edu.wpi.first.wpilibj.command.CommandGroup;
|
||||
|
||||
public class ReplaceMeCommandGroup extends CommandGroup {
|
||||
/**
|
||||
* Add your docs here.
|
||||
*/
|
||||
public ReplaceMeCommandGroup() {
|
||||
// Add Commands here:
|
||||
// e.g. addSequential(new Command1());
|
||||
|
||||
@@ -13,6 +13,9 @@ import edu.wpi.first.wpilibj.command.InstantCommand;
|
||||
* Add your docs here.
|
||||
*/
|
||||
public class ReplaceMeInstantCommand extends InstantCommand {
|
||||
/**
|
||||
* Add your docs here.
|
||||
*/
|
||||
public ReplaceMeInstantCommand() {
|
||||
super();
|
||||
// Use requires() here to declare subsystem dependencies
|
||||
|
||||
@@ -13,7 +13,9 @@ import edu.wpi.first.wpilibj.command.PIDSubsystem;
|
||||
* Add your docs here.
|
||||
*/
|
||||
public class ReplaceMePIDSubsystem extends PIDSubsystem {
|
||||
// Initialize your subsystem here
|
||||
/**
|
||||
* Add your docs here.
|
||||
*/
|
||||
public ReplaceMePIDSubsystem() {
|
||||
// Intert a subsystem name and PID values here
|
||||
super("SubsystemName", 1, 2, 3);
|
||||
|
||||
@@ -13,6 +13,9 @@ import edu.wpi.first.wpilibj.command.TimedCommand;
|
||||
* Add your docs here.
|
||||
*/
|
||||
public class ReplaceMeTimedCommand extends TimedCommand {
|
||||
/**
|
||||
* Add your docs here.
|
||||
*/
|
||||
public ReplaceMeTimedCommand(double timeout) {
|
||||
super(timeout);
|
||||
// Use requires() here to declare subsystem dependencies
|
||||
|
||||
@@ -7,15 +7,16 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.axiscamera;
|
||||
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
|
||||
import edu.wpi.cscore.AxisCamera;
|
||||
import edu.wpi.cscore.CvSink;
|
||||
import edu.wpi.cscore.CvSource;
|
||||
import edu.wpi.first.wpilibj.CameraServer;
|
||||
import edu.wpi.first.wpilibj.IterativeRobot;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
|
||||
/**
|
||||
* This is a demo program showing the use of OpenCV to do vision processing. The
|
||||
|
||||
@@ -9,6 +9,8 @@ package edu.wpi.first.wpilibj.examples.gearsbot;
|
||||
|
||||
import edu.wpi.first.wpilibj.Joystick;
|
||||
import edu.wpi.first.wpilibj.buttons.JoystickButton;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||
|
||||
import edu.wpi.first.wpilibj.examples.gearsbot.commands.Autonomous;
|
||||
import edu.wpi.first.wpilibj.examples.gearsbot.commands.CloseClaw;
|
||||
import edu.wpi.first.wpilibj.examples.gearsbot.commands.OpenClaw;
|
||||
@@ -17,7 +19,6 @@ import edu.wpi.first.wpilibj.examples.gearsbot.commands.Place;
|
||||
import edu.wpi.first.wpilibj.examples.gearsbot.commands.PrepareToPickup;
|
||||
import edu.wpi.first.wpilibj.examples.gearsbot.commands.SetElevatorSetpoint;
|
||||
import edu.wpi.first.wpilibj.examples.gearsbot.commands.SetWristSetpoint;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||
|
||||
/**
|
||||
* This class is the glue that binds the controls on the physical operator
|
||||
@@ -26,6 +27,9 @@ import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||
public class OI {
|
||||
private Joystick m_joystick = new Joystick(0);
|
||||
|
||||
/**
|
||||
* Construct the OI and all of the buttons on it.
|
||||
*/
|
||||
public OI() {
|
||||
// Put Some buttons on the SmartDashboard
|
||||
SmartDashboard.putData("Elevator Bottom", new SetElevatorSetpoint(0));
|
||||
@@ -41,14 +45,14 @@ public class OI {
|
||||
SmartDashboard.putData("Deliver Soda", new Autonomous());
|
||||
|
||||
// Create some buttons
|
||||
JoystickButton dpadUp = new JoystickButton(m_joystick, 5);
|
||||
JoystickButton dpadRight = new JoystickButton(m_joystick, 6);
|
||||
JoystickButton dpadDown = new JoystickButton(m_joystick, 7);
|
||||
JoystickButton dpadLeft = new JoystickButton(m_joystick, 8);
|
||||
JoystickButton l2 = new JoystickButton(m_joystick, 9);
|
||||
JoystickButton r2 = new JoystickButton(m_joystick, 10);
|
||||
JoystickButton l1 = new JoystickButton(m_joystick, 11);
|
||||
JoystickButton r1 = new JoystickButton(m_joystick, 12);
|
||||
final JoystickButton dpadUp = new JoystickButton(m_joystick, 5);
|
||||
final JoystickButton dpadRight = new JoystickButton(m_joystick, 6);
|
||||
final JoystickButton dpadDown = new JoystickButton(m_joystick, 7);
|
||||
final JoystickButton dpadLeft = new JoystickButton(m_joystick, 8);
|
||||
final JoystickButton l2 = new JoystickButton(m_joystick, 9);
|
||||
final JoystickButton r2 = new JoystickButton(m_joystick, 10);
|
||||
final JoystickButton l1 = new JoystickButton(m_joystick, 11);
|
||||
final JoystickButton r1 = new JoystickButton(m_joystick, 12);
|
||||
|
||||
// Connect the buttons to commands
|
||||
dpadUp.whenPressed(new SetElevatorSetpoint(0.2));
|
||||
|
||||
@@ -13,6 +13,9 @@ import edu.wpi.first.wpilibj.command.CommandGroup;
|
||||
* The main autonomous command to pickup and deliver the soda to the box.
|
||||
*/
|
||||
public class Autonomous extends CommandGroup {
|
||||
/**
|
||||
* Create a new autonomous command.
|
||||
*/
|
||||
public Autonomous() {
|
||||
addSequential(new PrepareToPickup());
|
||||
addSequential(new Pickup());
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
package edu.wpi.first.wpilibj.examples.gearsbot.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj.command.Command;
|
||||
|
||||
import edu.wpi.first.wpilibj.examples.gearsbot.Robot;
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,6 +11,7 @@ import edu.wpi.first.wpilibj.PIDController;
|
||||
import edu.wpi.first.wpilibj.PIDSource;
|
||||
import edu.wpi.first.wpilibj.PIDSourceType;
|
||||
import edu.wpi.first.wpilibj.command.Command;
|
||||
|
||||
import edu.wpi.first.wpilibj.examples.gearsbot.Robot;
|
||||
|
||||
/**
|
||||
@@ -22,6 +23,10 @@ import edu.wpi.first.wpilibj.examples.gearsbot.Robot;
|
||||
public class DriveStraight extends Command {
|
||||
private PIDController m_pid;
|
||||
|
||||
/**
|
||||
* Create a new DriveStraight command.
|
||||
* @param distance The distance to drive
|
||||
*/
|
||||
public DriveStraight(double distance) {
|
||||
requires(Robot.m_drivetrain);
|
||||
m_pid = new PIDController(4, 0, 0, new PIDSource() {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
package edu.wpi.first.wpilibj.examples.gearsbot.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj.command.TimedCommand;
|
||||
|
||||
import edu.wpi.first.wpilibj.examples.gearsbot.Robot;
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,6 +14,9 @@ import edu.wpi.first.wpilibj.command.CommandGroup;
|
||||
* state to drive around.
|
||||
*/
|
||||
public class Pickup extends CommandGroup {
|
||||
/**
|
||||
* Create a new pickup command.
|
||||
*/
|
||||
public Pickup() {
|
||||
addSequential(new CloseClaw());
|
||||
addParallel(new SetWristSetpoint(-45));
|
||||
|
||||
@@ -13,6 +13,9 @@ import edu.wpi.first.wpilibj.command.CommandGroup;
|
||||
* Place a held soda can onto the platform.
|
||||
*/
|
||||
public class Place extends CommandGroup {
|
||||
/**
|
||||
* Create a new place command.
|
||||
*/
|
||||
public Place() {
|
||||
addSequential(new SetElevatorSetpoint(0.25));
|
||||
addSequential(new SetWristSetpoint(0));
|
||||
|
||||
@@ -13,6 +13,9 @@ import edu.wpi.first.wpilibj.command.CommandGroup;
|
||||
* Make sure the robot is in a state to pickup soda cans.
|
||||
*/
|
||||
public class PrepareToPickup extends CommandGroup {
|
||||
/**
|
||||
* Create a new prepare to pickup command.
|
||||
*/
|
||||
public PrepareToPickup() {
|
||||
addParallel(new OpenClaw());
|
||||
addParallel(new SetWristSetpoint(0));
|
||||
|
||||
@@ -11,6 +11,7 @@ import edu.wpi.first.wpilibj.PIDController;
|
||||
import edu.wpi.first.wpilibj.PIDSource;
|
||||
import edu.wpi.first.wpilibj.PIDSourceType;
|
||||
import edu.wpi.first.wpilibj.command.Command;
|
||||
|
||||
import edu.wpi.first.wpilibj.examples.gearsbot.Robot;
|
||||
|
||||
/**
|
||||
@@ -22,6 +23,10 @@ import edu.wpi.first.wpilibj.examples.gearsbot.Robot;
|
||||
public class SetDistanceToBox extends Command {
|
||||
private PIDController m_pid;
|
||||
|
||||
/**
|
||||
* Create a new set distance to box command.
|
||||
* @param distance The distance away from the box to drive to
|
||||
*/
|
||||
public SetDistanceToBox(double distance) {
|
||||
requires(Robot.m_drivetrain);
|
||||
m_pid = new PIDController(-2, 0, 0, new PIDSource() {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
package edu.wpi.first.wpilibj.examples.gearsbot.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj.command.Command;
|
||||
|
||||
import edu.wpi.first.wpilibj.examples.gearsbot.Robot;
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
package edu.wpi.first.wpilibj.examples.gearsbot.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj.command.Command;
|
||||
|
||||
import edu.wpi.first.wpilibj.examples.gearsbot.Robot;
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
package edu.wpi.first.wpilibj.examples.gearsbot.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj.command.Command;
|
||||
|
||||
import edu.wpi.first.wpilibj.examples.gearsbot.Robot;
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,6 +20,9 @@ public class Claw extends Subsystem {
|
||||
private Victor m_motor = new Victor(7);
|
||||
private DigitalInput m_contact = new DigitalInput(5);
|
||||
|
||||
/**
|
||||
* Create a new claw subsystem.
|
||||
*/
|
||||
public Claw() {
|
||||
super();
|
||||
|
||||
|
||||
@@ -16,9 +16,10 @@ import edu.wpi.first.wpilibj.SpeedController;
|
||||
import edu.wpi.first.wpilibj.SpeedControllerGroup;
|
||||
import edu.wpi.first.wpilibj.command.Subsystem;
|
||||
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||
|
||||
import edu.wpi.first.wpilibj.examples.gearsbot.Robot;
|
||||
import edu.wpi.first.wpilibj.examples.gearsbot.commands.TankDriveWithJoystick;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||
|
||||
/**
|
||||
* The DriveTrain subsystem incorporates the sensors and actuators attached to
|
||||
@@ -39,6 +40,9 @@ public class DriveTrain extends Subsystem {
|
||||
private AnalogInput m_rangefinder = new AnalogInput(6);
|
||||
private AnalogGyro m_gyro = new AnalogGyro(1);
|
||||
|
||||
/**
|
||||
* Create a new drive train subsystem.
|
||||
*/
|
||||
public DriveTrain() {
|
||||
super();
|
||||
|
||||
@@ -87,10 +91,8 @@ public class DriveTrain extends Subsystem {
|
||||
/**
|
||||
* Tank style driving for the DriveTrain.
|
||||
*
|
||||
* @param left
|
||||
* Speed in range [-1,1]
|
||||
* @param right
|
||||
* Speed in range [-1,1]
|
||||
* @param left Speed in range [-1,1]
|
||||
* @param right Speed in range [-1,1]
|
||||
*/
|
||||
public void drive(double left, double right) {
|
||||
m_drive.tankDrive(left, right);
|
||||
|
||||
@@ -10,9 +10,10 @@ package edu.wpi.first.wpilibj.examples.gearsbot.subsystems;
|
||||
import edu.wpi.first.wpilibj.AnalogPotentiometer;
|
||||
import edu.wpi.first.wpilibj.Victor;
|
||||
import edu.wpi.first.wpilibj.command.PIDSubsystem;
|
||||
import edu.wpi.first.wpilibj.examples.gearsbot.Robot;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||
|
||||
import edu.wpi.first.wpilibj.examples.gearsbot.Robot;
|
||||
|
||||
/**
|
||||
* The elevator subsystem uses PID to go to a given height. Unfortunately, in
|
||||
* it's current state PID values for simulation are different than in the real
|
||||
@@ -27,6 +28,9 @@ public class Elevator extends PIDSubsystem {
|
||||
private static final double kP_simulation = 18;
|
||||
private static final double kI_simulation = 0.2;
|
||||
|
||||
/**
|
||||
* Create a new elevator subsystem.
|
||||
*/
|
||||
public Elevator() {
|
||||
super(kP_real, kI_real, 0);
|
||||
if (Robot.isSimulation()) { // Check for simulation and update PID values
|
||||
|
||||
@@ -10,9 +10,10 @@ package edu.wpi.first.wpilibj.examples.gearsbot.subsystems;
|
||||
import edu.wpi.first.wpilibj.AnalogPotentiometer;
|
||||
import edu.wpi.first.wpilibj.Victor;
|
||||
import edu.wpi.first.wpilibj.command.PIDSubsystem;
|
||||
import edu.wpi.first.wpilibj.examples.gearsbot.Robot;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||
|
||||
import edu.wpi.first.wpilibj.examples.gearsbot.Robot;
|
||||
|
||||
/**
|
||||
* The wrist subsystem is like the elevator, but with a rotational joint instead
|
||||
* of a linear joint.
|
||||
@@ -24,6 +25,9 @@ public class Wrist extends PIDSubsystem {
|
||||
private static final double kP_real = 1;
|
||||
private static final double kP_simulation = 0.05;
|
||||
|
||||
/**
|
||||
* Create a new wrist subsystem.
|
||||
*/
|
||||
public Wrist() {
|
||||
super(kP_real, 0, 0);
|
||||
if (Robot.isSimulation()) { // Check for simulation and update PID values
|
||||
|
||||
@@ -7,15 +7,16 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.intermediatevision;
|
||||
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
|
||||
import edu.wpi.cscore.CvSink;
|
||||
import edu.wpi.cscore.CvSource;
|
||||
import edu.wpi.cscore.UsbCamera;
|
||||
import edu.wpi.first.wpilibj.CameraServer;
|
||||
import edu.wpi.first.wpilibj.IterativeRobot;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
|
||||
/**
|
||||
* This is a demo program showing the use of OpenCV to do vision processing. The
|
||||
|
||||
@@ -9,8 +9,8 @@ package edu.wpi.first.wpilibj.examples.motorcontrol;
|
||||
|
||||
import edu.wpi.first.wpilibj.IterativeRobot;
|
||||
import edu.wpi.first.wpilibj.Joystick;
|
||||
import edu.wpi.first.wpilibj.SpeedController;
|
||||
import edu.wpi.first.wpilibj.Spark;
|
||||
import edu.wpi.first.wpilibj.SpeedController;
|
||||
|
||||
/**
|
||||
* This sample program shows how to control a motor using a joystick. In the
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.examples.pacgoat;
|
||||
|
||||
import edu.wpi.first.wpilibj.Joystick;
|
||||
import edu.wpi.first.wpilibj.buttons.JoystickButton;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.commands.Collect;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.commands.DriveForward;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.commands.LowGoal;
|
||||
@@ -17,10 +21,6 @@ import edu.wpi.first.wpilibj.examples.pacgoat.subsystems.Collector;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.subsystems.Pivot;
|
||||
import edu.wpi.first.wpilibj.examples.pacgoat.triggers.DoubleButton;
|
||||
|
||||
import edu.wpi.first.wpilibj.Joystick;
|
||||
import edu.wpi.first.wpilibj.buttons.JoystickButton;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||
|
||||
/**
|
||||
* The operator interface of the robot, it has been simplified from the real
|
||||
* robot to allow control with a single PS3 joystick. As a result, not all
|
||||
@@ -29,6 +29,9 @@ import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||
public class OI {
|
||||
public Joystick m_joystick = new Joystick(0);
|
||||
|
||||
/**
|
||||
* Create a new OI and all of the buttons on it.
|
||||
*/
|
||||
public OI() {
|
||||
new JoystickButton(m_joystick, 12).whenPressed(new LowGoal());
|
||||
new JoystickButton(m_joystick, 10).whenPressed(new Collect());
|
||||
|
||||
@@ -16,6 +16,9 @@ import edu.wpi.first.wpilibj.examples.pacgoat.subsystems.Pivot;
|
||||
* Get the robot set to collect balls.
|
||||
*/
|
||||
public class Collect extends CommandGroup {
|
||||
/**
|
||||
* Create a new collect command.
|
||||
*/
|
||||
public Collect() {
|
||||
addSequential(new SetCollectionSpeed(Collector.kForward));
|
||||
addParallel(new CloseClaw());
|
||||
|
||||
@@ -16,6 +16,9 @@ import edu.wpi.first.wpilibj.examples.pacgoat.Robot;
|
||||
* it will wait briefly.
|
||||
*/
|
||||
public class DriveAndShootAutonomous extends CommandGroup {
|
||||
/**
|
||||
* Create a new drive and shoot autonomous.
|
||||
*/
|
||||
public DriveAndShootAutonomous() {
|
||||
addSequential(new CloseClaw());
|
||||
addSequential(new WaitForPressure(), 2);
|
||||
|
||||
@@ -30,6 +30,11 @@ public class DriveForward extends Command {
|
||||
this(dist, 0.5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new drive forward command.
|
||||
* @param dist The distance to drive
|
||||
* @param maxSpeed The maximum speed to drive at
|
||||
*/
|
||||
public DriveForward(double dist, double maxSpeed) {
|
||||
requires(Robot.drivetrain);
|
||||
m_distance = dist;
|
||||
|
||||
@@ -17,6 +17,9 @@ import edu.wpi.first.wpilibj.examples.pacgoat.subsystems.Pivot;
|
||||
* it.
|
||||
*/
|
||||
public class LowGoal extends CommandGroup {
|
||||
/**
|
||||
* Create a new low goal command.
|
||||
*/
|
||||
public LowGoal() {
|
||||
addSequential(new SetPivotSetpoint(Pivot.kLowGoal));
|
||||
addSequential(new SetCollectionSpeed(Collector.kReverse));
|
||||
|
||||
@@ -15,6 +15,9 @@ import edu.wpi.first.wpilibj.examples.pacgoat.subsystems.Collector;
|
||||
* Shoot the ball at the current angle.
|
||||
*/
|
||||
public class Shoot extends CommandGroup {
|
||||
/**
|
||||
* Create a new shoot command.
|
||||
*/
|
||||
public Shoot() {
|
||||
addSequential(new WaitForPressure());
|
||||
addSequential(new SetCollectionSpeed(Collector.kStop));
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user