mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[docs] Build with JavaDoc 17 and add missing docs (#6220)
Co-authored-by: Sam Carlberg <sam.carlberg@gmail.com>
This commit is contained in:
2
.github/workflows/comment-command.yml
vendored
2
.github/workflows/comment-command.yml
vendored
@@ -41,7 +41,7 @@ jobs:
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: 'zulu'
|
||||
java-version: 11
|
||||
java-version: 17
|
||||
- name: Install wpiformat
|
||||
run: pip3 install wpiformat
|
||||
- name: Run wpiformat
|
||||
|
||||
2
.github/workflows/gradle.yml
vendored
2
.github/workflows/gradle.yml
vendored
@@ -174,7 +174,7 @@ jobs:
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: 'zulu'
|
||||
java-version: 13
|
||||
java-version: 17
|
||||
- name: Set release environment variable
|
||||
run: echo "EXTRA_GRADLE_ARGS=-PreleaseMode" >> $GITHUB_ENV
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
|
||||
2
.github/workflows/lint-format.yml
vendored
2
.github/workflows/lint-format.yml
vendored
@@ -108,6 +108,6 @@ jobs:
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: 'zulu'
|
||||
java-version: 13
|
||||
java-version: 17
|
||||
- name: Build with Gradle
|
||||
run: ./gradlew docs:zipDocs -PbuildServer -PdocWarningsAsErrors ${{ env.EXTRA_GRADLE_ARGS }}
|
||||
|
||||
@@ -74,18 +74,62 @@ public class CameraServerCvJNI {
|
||||
libraryLoaded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a CV source.
|
||||
*
|
||||
* @param name Name.
|
||||
* @param pixelFormat OpenCV pixel format.
|
||||
* @param width Image width.
|
||||
* @param height Image height.
|
||||
* @param fps Frames per second.
|
||||
* @return CV source.
|
||||
*/
|
||||
public static native int createCvSource(
|
||||
String name, int pixelFormat, int width, int height, int fps);
|
||||
|
||||
/**
|
||||
* Put source frame.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @param imageNativeObj Image native object handle.
|
||||
*/
|
||||
public static native void putSourceFrame(int source, long imageNativeObj);
|
||||
|
||||
/**
|
||||
* Creates a CV sink.
|
||||
*
|
||||
* @param name Name.
|
||||
* @param pixelFormat OpenCV pixel format.
|
||||
* @return CV sink handle.
|
||||
*/
|
||||
public static native int createCvSink(String name, int pixelFormat);
|
||||
|
||||
// /**
|
||||
// * Creates a CV sink callback.
|
||||
// *
|
||||
// * @param name Name.
|
||||
// * @param processFrame Process frame callback.
|
||||
// */
|
||||
// public static native int createCvSinkCallback(String name,
|
||||
// void (*processFrame)(long time));
|
||||
|
||||
/**
|
||||
* Returns sink frame handle.
|
||||
*
|
||||
* @param sink Sink handle.
|
||||
* @param imageNativeObj Image native object handle.
|
||||
* @return Sink frame handle.
|
||||
*/
|
||||
public static native long grabSinkFrame(int sink, long imageNativeObj);
|
||||
|
||||
/**
|
||||
* Returns sink frame timeout in microseconds.
|
||||
*
|
||||
* @param sink Sink handle.
|
||||
* @param imageNativeObj Image native object handle.
|
||||
* @param timeout Timeout in seconds.
|
||||
* @return Sink frame timeout in microseconds.
|
||||
*/
|
||||
public static native long grabSinkFrameTimeout(int sink, long imageNativeObj, double timeout);
|
||||
|
||||
/** Utility class. */
|
||||
|
||||
@@ -77,140 +77,521 @@ public class CameraServerJNI {
|
||||
//
|
||||
// Property Functions
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns property kind.
|
||||
*
|
||||
* @param property Property handle.
|
||||
* @return Property kind.
|
||||
*/
|
||||
public static native int getPropertyKind(int property);
|
||||
|
||||
/**
|
||||
* Returns property name.
|
||||
*
|
||||
* @param property Property handle.
|
||||
* @return Property name.
|
||||
*/
|
||||
public static native String getPropertyName(int property);
|
||||
|
||||
/**
|
||||
* Returns property value.
|
||||
*
|
||||
* @param property Property handle.
|
||||
* @return Property value.
|
||||
*/
|
||||
public static native int getProperty(int property);
|
||||
|
||||
/**
|
||||
* Sets property value.
|
||||
*
|
||||
* @param property Property handle.
|
||||
* @param value Property value.
|
||||
*/
|
||||
public static native void setProperty(int property, int value);
|
||||
|
||||
/**
|
||||
* Returns property minimum.
|
||||
*
|
||||
* @param property Property handle.
|
||||
* @return Property minimum.
|
||||
*/
|
||||
public static native int getPropertyMin(int property);
|
||||
|
||||
/**
|
||||
* Returns property maximum.
|
||||
*
|
||||
* @param property Property handle.
|
||||
* @return Property maximum.
|
||||
*/
|
||||
public static native int getPropertyMax(int property);
|
||||
|
||||
/**
|
||||
* Returns property step.
|
||||
*
|
||||
* @param property Property handle.
|
||||
* @return Property step.
|
||||
*/
|
||||
public static native int getPropertyStep(int property);
|
||||
|
||||
/**
|
||||
* Returns property default value.
|
||||
*
|
||||
* @param property Property handle.
|
||||
* @return Property default value.
|
||||
*/
|
||||
public static native int getPropertyDefault(int property);
|
||||
|
||||
/**
|
||||
* Returns property value as a string.
|
||||
*
|
||||
* @param property Property handle.
|
||||
* @return Property value as a string.
|
||||
*/
|
||||
public static native String getStringProperty(int property);
|
||||
|
||||
/**
|
||||
* Sets property value to a string.
|
||||
*
|
||||
* @param property Property handle.
|
||||
* @param value Property value string.
|
||||
*/
|
||||
public static native void setStringProperty(int property, String value);
|
||||
|
||||
/**
|
||||
* Returns enum of possible property value strings.
|
||||
*
|
||||
* @param property Property handle.
|
||||
* @return Enum of possible property value strings.
|
||||
*/
|
||||
public static native String[] getEnumPropertyChoices(int property);
|
||||
|
||||
//
|
||||
// Source Creation Functions
|
||||
//
|
||||
|
||||
/**
|
||||
* Creates a new USB camera by device.
|
||||
*
|
||||
* @param name USB camera name.
|
||||
* @param dev USB camera device number.
|
||||
* @return USB camera handle.
|
||||
*/
|
||||
public static native int createUsbCameraDev(String name, int dev);
|
||||
|
||||
/**
|
||||
* Creates a new USB camera by path.
|
||||
*
|
||||
* @param name USB camera name.
|
||||
* @param path USB camera path.
|
||||
* @return USB camera handle.
|
||||
*/
|
||||
public static native int createUsbCameraPath(String name, String path);
|
||||
|
||||
/**
|
||||
* Creates an HTTP camera.
|
||||
*
|
||||
* @param name HTTP camera name.
|
||||
* @param url HTTP camera stream URL.
|
||||
* @param kind HTTP camera kind.
|
||||
* @return HTTP camera handle.
|
||||
*/
|
||||
public static native int createHttpCamera(String name, String url, int kind);
|
||||
|
||||
/**
|
||||
* Creates an HTTP camera from multiple URLs.
|
||||
*
|
||||
* @param name HTTP camera name.
|
||||
* @param urls HTTP camera stream URLs.
|
||||
* @param kind HTTP camera kind.
|
||||
* @return HTTP camera handle.
|
||||
*/
|
||||
public static native int createHttpCameraMulti(String name, String[] urls, int kind);
|
||||
|
||||
/**
|
||||
* Creates a raw source.
|
||||
*
|
||||
* @param name Source name.
|
||||
* @param pixelFormat Pixel format.
|
||||
* @param width Image width.
|
||||
* @param height Image height.
|
||||
* @param fps Source frames per second.
|
||||
* @return Raw source handle.
|
||||
*/
|
||||
public static native int createRawSource(
|
||||
String name, int pixelFormat, int width, int height, int fps);
|
||||
|
||||
//
|
||||
// Source Functions
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns source kind.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @return Source kind.
|
||||
*/
|
||||
public static native int getSourceKind(int source);
|
||||
|
||||
/**
|
||||
* Returns source name.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @return Source name.
|
||||
*/
|
||||
public static native String getSourceName(int source);
|
||||
|
||||
/**
|
||||
* Returns source description.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @return Source description.
|
||||
*/
|
||||
public static native String getSourceDescription(int source);
|
||||
|
||||
/**
|
||||
* Returns source's last frame time.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @return Source's last frame time.
|
||||
*/
|
||||
public static native long getSourceLastFrameTime(int source);
|
||||
|
||||
/**
|
||||
* Sets source connection strategy.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @param strategy Connection strategy.
|
||||
*/
|
||||
public static native void setSourceConnectionStrategy(int source, int strategy);
|
||||
|
||||
/**
|
||||
* Returns true if source is connected.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @return True if source is connected.
|
||||
*/
|
||||
public static native boolean isSourceConnected(int source);
|
||||
|
||||
/**
|
||||
* Returns true if source is enabled.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @return True if source is enabled.
|
||||
*/
|
||||
public static native boolean isSourceEnabled(int source);
|
||||
|
||||
/**
|
||||
* Returns source property.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @param name Source property name.
|
||||
* @return Source property.
|
||||
*/
|
||||
public static native int getSourceProperty(int source, String name);
|
||||
|
||||
/**
|
||||
* Returns list of source property handles.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @return List of source property handles.
|
||||
*/
|
||||
public static native int[] enumerateSourceProperties(int source);
|
||||
|
||||
/**
|
||||
* Returns source video mode.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @return Source video mode.
|
||||
*/
|
||||
public static native VideoMode getSourceVideoMode(int source);
|
||||
|
||||
/**
|
||||
* Sets source video mode.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @param pixelFormat Pixel format.
|
||||
* @param width Image width.
|
||||
* @param height Image height.
|
||||
* @param fps Source frames per second.
|
||||
* @return True if set succeeded.
|
||||
*/
|
||||
public static native boolean setSourceVideoMode(
|
||||
int source, int pixelFormat, int width, int height, int fps);
|
||||
|
||||
/**
|
||||
* Sets source pixel format.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @param pixelFormat Source pixel format.
|
||||
* @return True if set succeeded.
|
||||
*/
|
||||
public static native boolean setSourcePixelFormat(int source, int pixelFormat);
|
||||
|
||||
/**
|
||||
* Sets source resolution.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @param width Image width.
|
||||
* @param height Image height.
|
||||
* @return True if set succeeded.
|
||||
*/
|
||||
public static native boolean setSourceResolution(int source, int width, int height);
|
||||
|
||||
/**
|
||||
* Sets source FPS.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @param fps Source frames per second.
|
||||
* @return True if set succeeded.
|
||||
*/
|
||||
public static native boolean setSourceFPS(int source, int fps);
|
||||
|
||||
/**
|
||||
* Sets source configuration JSON.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @param config Configuration JSON.
|
||||
* @return True if set succeeded.
|
||||
*/
|
||||
public static native boolean setSourceConfigJson(int source, String config);
|
||||
|
||||
/**
|
||||
* Returns source configuration JSON.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @return Source configuration JSON.
|
||||
*/
|
||||
public static native String getSourceConfigJson(int source);
|
||||
|
||||
/**
|
||||
* Returns list of source's supported video modes.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @return List of source's supported video modes.
|
||||
*/
|
||||
public static native VideoMode[] enumerateSourceVideoModes(int source);
|
||||
|
||||
/**
|
||||
* Returns list of source sinks.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @return List of source sinks.
|
||||
*/
|
||||
public static native int[] enumerateSourceSinks(int source);
|
||||
|
||||
/**
|
||||
* Copies source.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @return New source handle.
|
||||
*/
|
||||
public static native int copySource(int source);
|
||||
|
||||
/**
|
||||
* Releases source.
|
||||
*
|
||||
* @param source Source handle.
|
||||
*/
|
||||
public static native void releaseSource(int source);
|
||||
|
||||
//
|
||||
// Camera Source Common Property Functions
|
||||
//
|
||||
|
||||
/**
|
||||
* Sets camera brightness.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @param brightness Brightness.
|
||||
*/
|
||||
public static native void setCameraBrightness(int source, int brightness);
|
||||
|
||||
/**
|
||||
* Returns camera brightness.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @return Camera brightness.
|
||||
*/
|
||||
public static native int getCameraBrightness(int source);
|
||||
|
||||
/**
|
||||
* Sets camera white balance to auto.
|
||||
*
|
||||
* @param source Source handle.
|
||||
*/
|
||||
public static native void setCameraWhiteBalanceAuto(int source);
|
||||
|
||||
/**
|
||||
* Sets camera white balance to "hold current".
|
||||
*
|
||||
* @param source Source handle.
|
||||
*/
|
||||
public static native void setCameraWhiteBalanceHoldCurrent(int source);
|
||||
|
||||
/**
|
||||
* Sets camera white balance to the given value.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @param value White balance.
|
||||
*/
|
||||
public static native void setCameraWhiteBalanceManual(int source, int value);
|
||||
|
||||
/**
|
||||
* Sets camera exposure to auto.
|
||||
*
|
||||
* @param source Source handle.
|
||||
*/
|
||||
public static native void setCameraExposureAuto(int source);
|
||||
|
||||
/**
|
||||
* Sets camera exposure to "hold current".
|
||||
*
|
||||
* @param source Source handle.
|
||||
*/
|
||||
public static native void setCameraExposureHoldCurrent(int source);
|
||||
|
||||
/**
|
||||
* Sets camera exposure to the given value.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @param value Exposure.
|
||||
*/
|
||||
public static native void setCameraExposureManual(int source, int value);
|
||||
|
||||
//
|
||||
// UsbCamera Source Functions
|
||||
//
|
||||
|
||||
/**
|
||||
* Sets USB camera path.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @param path USB camera path.
|
||||
*/
|
||||
public static native void setUsbCameraPath(int source, String path);
|
||||
|
||||
/**
|
||||
* Returns USB camera path.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @return USB camera path.
|
||||
*/
|
||||
public static native String getUsbCameraPath(int source);
|
||||
|
||||
/**
|
||||
* Returns USB camera info.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @return USB camera info.
|
||||
*/
|
||||
public static native UsbCameraInfo getUsbCameraInfo(int source);
|
||||
|
||||
//
|
||||
// HttpCamera Source Functions
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns HTTP camera kind.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @return HTTP camera kind.
|
||||
*/
|
||||
public static native int getHttpCameraKind(int source);
|
||||
|
||||
/**
|
||||
* Sets HTTP camera URLs.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @param urls HTTP camera URLs.
|
||||
*/
|
||||
public static native void setHttpCameraUrls(int source, String[] urls);
|
||||
|
||||
/**
|
||||
* Returns HTTP camera URLs.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @return HTTP camera URLs.
|
||||
*/
|
||||
public static native String[] getHttpCameraUrls(int source);
|
||||
|
||||
//
|
||||
// Image Source Functions
|
||||
//
|
||||
|
||||
/**
|
||||
* Puts raw frame into source.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @param frame Frame handle.
|
||||
*/
|
||||
public static native void putRawSourceFrame(int source, long frame);
|
||||
|
||||
/**
|
||||
* Puts raw frame into source.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @param data Frame byte buffer.
|
||||
* @param size Frame size.
|
||||
* @param width Frame width.
|
||||
* @param height Frame height.
|
||||
* @param stride Frame stride.
|
||||
* @param pixelFormat Frame pixel format.
|
||||
*/
|
||||
public static native void putRawSourceFrameBB(
|
||||
int source, ByteBuffer data, int size, int width, int height, int stride, int pixelFormat);
|
||||
|
||||
/**
|
||||
* Puts raw frame into source.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @param data Frame handle.
|
||||
* @param size Frame size.
|
||||
* @param width Frame width.
|
||||
* @param height Frame height.
|
||||
* @param stride Frame stride.
|
||||
* @param pixelFormat Frame pixel format.
|
||||
*/
|
||||
public static native void putRawSourceFrameData(
|
||||
int source, long data, int size, int width, int height, int stride, int pixelFormat);
|
||||
|
||||
/**
|
||||
* Notify source error.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @param msg Error message.
|
||||
*/
|
||||
public static native void notifySourceError(int source, String msg);
|
||||
|
||||
/**
|
||||
* Sets whether source is connected.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @param connected True if source is connected.
|
||||
*/
|
||||
public static native void setSourceConnected(int source, boolean connected);
|
||||
|
||||
/**
|
||||
* Sets source description.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @param description Source description.
|
||||
*/
|
||||
public static native void setSourceDescription(int source, String description);
|
||||
|
||||
/**
|
||||
* Creates a source property.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @param name Property name.
|
||||
* @param kind Property kind.
|
||||
* @param minimum Property minimum.
|
||||
* @param maximum Property maximum.
|
||||
* @param step Property step.
|
||||
* @param defaultValue Property default value.
|
||||
* @param value Property value.
|
||||
* @return Source property handle.
|
||||
*/
|
||||
public static native int createSourceProperty(
|
||||
int source,
|
||||
String name,
|
||||
@@ -221,88 +602,288 @@ public class CameraServerJNI {
|
||||
int defaultValue,
|
||||
int value);
|
||||
|
||||
/**
|
||||
* Sets list of possible property values.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @param property Property handle.
|
||||
* @param choices List of possible property values.
|
||||
*/
|
||||
public static native void setSourceEnumPropertyChoices(
|
||||
int source, int property, String[] choices);
|
||||
|
||||
//
|
||||
// Sink Creation Functions
|
||||
//
|
||||
|
||||
/**
|
||||
* Creates an MJPEG server.
|
||||
*
|
||||
* @param name MJPEG server name.
|
||||
* @param listenAddress IP address at which server should listen.
|
||||
* @param port Port on which server should listen.
|
||||
* @return MJPEG server handle.
|
||||
*/
|
||||
public static native int createMjpegServer(String name, String listenAddress, int port);
|
||||
|
||||
/**
|
||||
* Creates a raw sink.
|
||||
*
|
||||
* @param name Sink name.
|
||||
* @return Raw sink handle.
|
||||
*/
|
||||
public static native int createRawSink(String name);
|
||||
|
||||
//
|
||||
// Sink Functions
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns sink kind.
|
||||
*
|
||||
* @param sink Sink handle.
|
||||
* @return Sink kind.
|
||||
*/
|
||||
public static native int getSinkKind(int sink);
|
||||
|
||||
/**
|
||||
* Returns sink name.
|
||||
*
|
||||
* @param sink Sink handle.
|
||||
* @return Sink name.
|
||||
*/
|
||||
public static native String getSinkName(int sink);
|
||||
|
||||
/**
|
||||
* Returns sink description.
|
||||
*
|
||||
* @param sink Sink handle.
|
||||
* @return Sink description.
|
||||
*/
|
||||
public static native String getSinkDescription(int sink);
|
||||
|
||||
/**
|
||||
* Returns sink property.
|
||||
*
|
||||
* @param sink Sink handle.
|
||||
* @param name Property name.
|
||||
* @return Sink property handle.
|
||||
*/
|
||||
public static native int getSinkProperty(int sink, String name);
|
||||
|
||||
/**
|
||||
* Returns list of sink property handles.
|
||||
*
|
||||
* @param sink Sink handle.
|
||||
* @return List of sink property handles.
|
||||
*/
|
||||
public static native int[] enumerateSinkProperties(int sink);
|
||||
|
||||
/**
|
||||
* Sets sink configuration JSON.
|
||||
*
|
||||
* @param sink Sink handle.
|
||||
* @param config Configuration JSON.
|
||||
* @return True if set succeeded.
|
||||
*/
|
||||
public static native boolean setSinkConfigJson(int sink, String config);
|
||||
|
||||
/**
|
||||
* Returns sink configuration JSON.
|
||||
*
|
||||
* @param sink Sink handle.
|
||||
* @return Sink configuration JSON.
|
||||
*/
|
||||
public static native String getSinkConfigJson(int sink);
|
||||
|
||||
/**
|
||||
* Sets sink source.
|
||||
*
|
||||
* @param sink Sink handle.
|
||||
* @param source Source handle.
|
||||
*/
|
||||
public static native void setSinkSource(int sink, int source);
|
||||
|
||||
/**
|
||||
* Returns sink source property.
|
||||
*
|
||||
* @param sink Sink handle.
|
||||
* @param name Property name.
|
||||
* @return Sink source property handle.
|
||||
*/
|
||||
public static native int getSinkSourceProperty(int sink, String name);
|
||||
|
||||
/**
|
||||
* Returns sink source.
|
||||
*
|
||||
* @param sink Sink handle.
|
||||
* @return Sink source handle.
|
||||
*/
|
||||
public static native int getSinkSource(int sink);
|
||||
|
||||
/**
|
||||
* Copies sink.
|
||||
*
|
||||
* @param sink Sink handle.
|
||||
* @return New sink handle.
|
||||
*/
|
||||
public static native int copySink(int sink);
|
||||
|
||||
/**
|
||||
* Releases sink.
|
||||
*
|
||||
* @param sink Sink handle.
|
||||
*/
|
||||
public static native void releaseSink(int sink);
|
||||
|
||||
//
|
||||
// MjpegServer Sink Functions
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns MJPEG server listen address.
|
||||
*
|
||||
* @param sink Sink handle.
|
||||
* @return MJPEG server listen address.
|
||||
*/
|
||||
public static native String getMjpegServerListenAddress(int sink);
|
||||
|
||||
/**
|
||||
* Returns MJPEG server port.
|
||||
*
|
||||
* @param sink Sink handle.
|
||||
* @return MJPEG server port.
|
||||
*/
|
||||
public static native int getMjpegServerPort(int sink);
|
||||
|
||||
//
|
||||
// Image Sink Functions
|
||||
//
|
||||
|
||||
/**
|
||||
* Sets sink description.
|
||||
*
|
||||
* @param sink Sink handle.
|
||||
* @param description Sink description.
|
||||
*/
|
||||
public static native void setSinkDescription(int sink, String description);
|
||||
|
||||
/**
|
||||
* Returns raw sink frame.
|
||||
*
|
||||
* @param sink Sink handle.
|
||||
* @param frame Raw frame.
|
||||
* @param nativeObj Native object.
|
||||
* @return Raw sink frame handle.
|
||||
*/
|
||||
public static native long grabRawSinkFrame(int sink, RawFrame frame, long nativeObj);
|
||||
|
||||
/**
|
||||
* Returns raw sink frame timeout.
|
||||
*
|
||||
* @param sink Sink handle.
|
||||
* @param frame Raw frame.
|
||||
* @param nativeObj Native object.
|
||||
* @param timeout Timeout in seconds.
|
||||
* @return Raw sink frame timeout.
|
||||
*/
|
||||
public static native long grabRawSinkFrameTimeout(
|
||||
int sink, RawFrame frame, long nativeObj, double timeout);
|
||||
|
||||
/**
|
||||
* Returns sink error message.
|
||||
*
|
||||
* @param sink Sink handle.
|
||||
* @return Sink error message.
|
||||
*/
|
||||
public static native String getSinkError(int sink);
|
||||
|
||||
/**
|
||||
* Sets sink enable.
|
||||
*
|
||||
* @param sink Sink handle.
|
||||
* @param enabled True if sink should be enabled.
|
||||
*/
|
||||
public static native void setSinkEnabled(int sink, boolean enabled);
|
||||
|
||||
//
|
||||
// Listener Functions
|
||||
//
|
||||
|
||||
/**
|
||||
* Adds listener.
|
||||
*
|
||||
* @param listener Video event callback.
|
||||
* @param eventMask Event mask.
|
||||
* @param immediateNotify True to immediately notify on event.
|
||||
* @return Listener handle.
|
||||
*/
|
||||
public static native int addListener(
|
||||
Consumer<VideoEvent> listener, int eventMask, boolean immediateNotify);
|
||||
|
||||
/**
|
||||
* Removes listener.
|
||||
*
|
||||
* @param handle Listener handle.
|
||||
*/
|
||||
public static native void removeListener(int handle);
|
||||
|
||||
/**
|
||||
* Creates listener poller.
|
||||
*
|
||||
* @return Listener poller handle.
|
||||
*/
|
||||
public static native int createListenerPoller();
|
||||
|
||||
/**
|
||||
* Destroys listener poller.
|
||||
*
|
||||
* @param poller Listener poller handle.
|
||||
*/
|
||||
public static native void destroyListenerPoller(int poller);
|
||||
|
||||
/**
|
||||
* Add polled listener.
|
||||
*
|
||||
* @param poller Poller handle.
|
||||
* @param eventMask Event mask.
|
||||
* @param immediateNotify True to immediately notify on event.
|
||||
* @return Polled listener handle.
|
||||
*/
|
||||
public static native int addPolledListener(int poller, int eventMask, boolean immediateNotify);
|
||||
|
||||
/**
|
||||
* Polls listener.
|
||||
*
|
||||
* @param poller Poller handle.
|
||||
* @return List of video events.
|
||||
* @throws InterruptedException if polling was interrupted.
|
||||
*/
|
||||
public static native VideoEvent[] pollListener(int poller) throws InterruptedException;
|
||||
|
||||
/**
|
||||
* Polls listener with timeout.
|
||||
*
|
||||
* @param poller Poller handle.
|
||||
* @param timeout Timeout in seconds.
|
||||
* @return List of video events.
|
||||
* @throws InterruptedException if polling was interrupted.
|
||||
*/
|
||||
public static native VideoEvent[] pollListenerTimeout(int poller, double timeout)
|
||||
throws InterruptedException;
|
||||
|
||||
/**
|
||||
* Cancels poll listener.
|
||||
*
|
||||
* @param poller Poller handle.
|
||||
*/
|
||||
public static native void cancelPollListener(int poller);
|
||||
|
||||
//
|
||||
// Telemetry Functions
|
||||
//
|
||||
|
||||
/** Telemetry kind. */
|
||||
public enum TelemetryKind {
|
||||
/** kSourceBytesReceived. */
|
||||
kSourceBytesReceived(1),
|
||||
@@ -315,23 +896,66 @@ public class CameraServerJNI {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns telemetry kind value.
|
||||
*
|
||||
* @return Telemetry kind value.
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets telemetry period.
|
||||
*
|
||||
* @param seconds Telemetry period in seconds.
|
||||
*/
|
||||
public static native void setTelemetryPeriod(double seconds);
|
||||
|
||||
/**
|
||||
* Returns telemetry elapsed time.
|
||||
*
|
||||
* @return Telemetry elapsed time.
|
||||
*/
|
||||
public static native double getTelemetryElapsedTime();
|
||||
|
||||
/**
|
||||
* Returns telemetry value.
|
||||
*
|
||||
* @param handle Telemetry handle.
|
||||
* @param kind Telemetry kind.
|
||||
* @return Telemetry value.
|
||||
*/
|
||||
public static native long getTelemetryValue(int handle, int kind);
|
||||
|
||||
/**
|
||||
* Returns telemetry value.
|
||||
*
|
||||
* @param handle Telemetry handle.
|
||||
* @param kind Telemetry kind.
|
||||
* @return Telemetry value.
|
||||
*/
|
||||
public static long getTelemetryValue(int handle, TelemetryKind kind) {
|
||||
return getTelemetryValue(handle, kind.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns telemetry average value.
|
||||
*
|
||||
* @param handle Telemetry handle.
|
||||
* @param kind Telemetry kind.
|
||||
* @return Telemetry average value.
|
||||
*/
|
||||
public static native double getTelemetryAverageValue(int handle, int kind);
|
||||
|
||||
/**
|
||||
* Returns telemetry average value.
|
||||
*
|
||||
* @param handle Telemetry handle.
|
||||
* @param kind Telemetry kind.
|
||||
* @return Telemetry average value.
|
||||
*/
|
||||
public static double getTelemetryAverageValue(int handle, TelemetryKind kind) {
|
||||
return getTelemetryAverageValue(handle, kind.getValue());
|
||||
}
|
||||
@@ -339,30 +963,80 @@ public class CameraServerJNI {
|
||||
//
|
||||
// Logging Functions
|
||||
//
|
||||
|
||||
/** Logger functional interface. */
|
||||
@FunctionalInterface
|
||||
public interface LoggerFunction {
|
||||
/**
|
||||
* Log a string.
|
||||
*
|
||||
* @param level Log level.
|
||||
* @param file Log file.
|
||||
* @param line Line number.
|
||||
* @param msg Log message.
|
||||
*/
|
||||
void apply(int level, String file, int line, String msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets logger.
|
||||
*
|
||||
* @param func Logger function.
|
||||
* @param minLevel Minimum logging level.
|
||||
*/
|
||||
public static native void setLogger(LoggerFunction func, int minLevel);
|
||||
|
||||
//
|
||||
// Utility Functions
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns list of USB cameras.
|
||||
*
|
||||
* @return List of USB cameras.
|
||||
*/
|
||||
public static native UsbCameraInfo[] enumerateUsbCameras();
|
||||
|
||||
/**
|
||||
* Returns list of sources.
|
||||
*
|
||||
* @return List of sources.
|
||||
*/
|
||||
public static native int[] enumerateSources();
|
||||
|
||||
/**
|
||||
* Returns list of sinks.
|
||||
*
|
||||
* @return List of sinks.
|
||||
*/
|
||||
public static native int[] enumerateSinks();
|
||||
|
||||
/**
|
||||
* Returns hostname.
|
||||
*
|
||||
* @return Hostname.
|
||||
*/
|
||||
public static native String getHostname();
|
||||
|
||||
/**
|
||||
* Returns list of network interfaces.
|
||||
*
|
||||
* @return List of network interfaces.
|
||||
*/
|
||||
public static native String[] getNetworkInterfaces();
|
||||
|
||||
/** Runs main run loop. */
|
||||
public static native void runMainRunLoop();
|
||||
|
||||
/**
|
||||
* Runs main run loop with timeout.
|
||||
*
|
||||
* @param timeoutSeconds Timeout in seconds.
|
||||
* @return 3 on timeout, 2 on signal, 1 on other.
|
||||
*/
|
||||
public static native int runMainRunLoopTimeout(double timeoutSeconds);
|
||||
|
||||
/** Stops main run loop. */
|
||||
public static native void stopMainRunLoop();
|
||||
|
||||
/** Utility class. */
|
||||
|
||||
@@ -6,6 +6,7 @@ package edu.wpi.first.cscore;
|
||||
|
||||
/** A source that represents a MJPEG-over-HTTP (IP) camera. */
|
||||
public class HttpCamera extends VideoCamera {
|
||||
/** HTTP camera kind. */
|
||||
public enum HttpCameraKind {
|
||||
/** Unknown camera kind. */
|
||||
kUnknown(0),
|
||||
@@ -22,6 +23,11 @@ public class HttpCamera extends VideoCamera {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns HttpCameraKind value.
|
||||
*
|
||||
* @return HttpCameraKind value.
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,13 @@
|
||||
|
||||
package edu.wpi.first.cscore;
|
||||
|
||||
/** A base class for single image reading sinks. */
|
||||
public abstract class ImageSink extends VideoSink {
|
||||
/**
|
||||
* Constructs an ImageSink.
|
||||
*
|
||||
* @param handle The image sink handle.
|
||||
*/
|
||||
protected ImageSink(int handle) {
|
||||
super(handle);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,13 @@
|
||||
|
||||
package edu.wpi.first.cscore;
|
||||
|
||||
/** A base class for single image providing sources. */
|
||||
public abstract class ImageSource extends VideoSource {
|
||||
/**
|
||||
* Constructs an ImageSource.
|
||||
*
|
||||
* @param handle The image source handle.
|
||||
*/
|
||||
protected ImageSource(int handle) {
|
||||
super(handle);
|
||||
}
|
||||
|
||||
@@ -6,17 +6,32 @@ package edu.wpi.first.cscore;
|
||||
|
||||
/** A source that represents a video camera. */
|
||||
public class VideoCamera extends VideoSource {
|
||||
/** White balance. */
|
||||
public static class WhiteBalance {
|
||||
/** Fixed indoor white balance. */
|
||||
public static final int kFixedIndoor = 3000;
|
||||
|
||||
/** Fixed outdoor white balance 1. */
|
||||
public static final int kFixedOutdoor1 = 4000;
|
||||
|
||||
/** Fixed outdoor white balance 2. */
|
||||
public static final int kFixedOutdoor2 = 5000;
|
||||
|
||||
/** Fixed fluorescent white balance 1. */
|
||||
public static final int kFixedFluorescent1 = 5100;
|
||||
|
||||
/** Fixed fluorescent white balance 2. */
|
||||
public static final int kFixedFlourescent2 = 5200;
|
||||
|
||||
/** Default constructor. */
|
||||
public WhiteBalance() {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a VideoCamera.
|
||||
*
|
||||
* @param handle The video camera handle.
|
||||
*/
|
||||
protected VideoCamera(int handle) {
|
||||
super(handle);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ package edu.wpi.first.cscore;
|
||||
/** Video event. */
|
||||
@SuppressWarnings("MemberName")
|
||||
public class VideoEvent {
|
||||
/** VideoEvent kind. */
|
||||
public enum Kind {
|
||||
/** Unknown video event. */
|
||||
kUnknown(0x0000),
|
||||
@@ -57,6 +58,11 @@ public class VideoEvent {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the kind value.
|
||||
*
|
||||
* @return The kind value.
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
@@ -139,39 +145,67 @@ public class VideoEvent {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
/** The video event kind. */
|
||||
public Kind kind;
|
||||
|
||||
// Valid for kSource* and kSink* respectively
|
||||
/**
|
||||
* The source handle.
|
||||
*
|
||||
* <p>Valid for kSource* and kSink* respectively.
|
||||
*/
|
||||
public int sourceHandle;
|
||||
|
||||
/** The sink handle. */
|
||||
public int sinkHandle;
|
||||
|
||||
// Source/sink/property name
|
||||
/** Source/sink/property name. */
|
||||
public String name;
|
||||
|
||||
// Fields for kSourceVideoModeChanged event
|
||||
// Fields for kSourceVideoModeChanged event.
|
||||
|
||||
/** New source video mode. */
|
||||
public VideoMode mode;
|
||||
|
||||
// Fields for kSourceProperty* events
|
||||
// Fields for kSourceProperty* events.
|
||||
|
||||
/** Source property handle. */
|
||||
public int propertyHandle;
|
||||
|
||||
/** Source property kind. */
|
||||
public VideoProperty.Kind propertyKind;
|
||||
|
||||
/** Event value. */
|
||||
public int value;
|
||||
|
||||
/** Event value as a string. */
|
||||
public String valueStr;
|
||||
|
||||
// Listener that was triggered
|
||||
/** Listener that was triggered. */
|
||||
public int listener;
|
||||
|
||||
/**
|
||||
* Returns the source associated with the event (if any).
|
||||
*
|
||||
* @return The source associated with the event (if any).
|
||||
*/
|
||||
public VideoSource getSource() {
|
||||
return new VideoSource(CameraServerJNI.copySource(sourceHandle));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sink associated with the event (if any).
|
||||
*
|
||||
* @return The sink associated with the event (if any).
|
||||
*/
|
||||
public VideoSink getSink() {
|
||||
return new VideoSink(CameraServerJNI.copySink(sinkHandle));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the property associated with the event (if any).
|
||||
*
|
||||
* @return The property associated with the event (if any).
|
||||
*/
|
||||
public VideoProperty getProperty() {
|
||||
return new VideoProperty(propertyHandle, propertyKind);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,11 @@ package edu.wpi.first.cscore;
|
||||
public class VideoException extends RuntimeException {
|
||||
private static final long serialVersionUID = -9155939328084105145L;
|
||||
|
||||
/**
|
||||
* Constructs the exception with the given message.
|
||||
*
|
||||
* @param msg The exception message.
|
||||
*/
|
||||
public VideoException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
@@ -51,6 +51,11 @@ public class VideoListener implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the video listener handle is valid.
|
||||
*
|
||||
* @return True if the video listener handle is valid.
|
||||
*/
|
||||
public boolean isValid() {
|
||||
return m_handle != 0;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,11 @@ public class VideoProperty {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Kind value.
|
||||
*
|
||||
* @return The Kind value.
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
@@ -51,69 +56,152 @@ public class VideoProperty {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns property name.
|
||||
*
|
||||
* @return Property name.
|
||||
*/
|
||||
public String getName() {
|
||||
return CameraServerJNI.getPropertyName(m_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns property kind.
|
||||
*
|
||||
* @return Property kind.
|
||||
*/
|
||||
public Kind getKind() {
|
||||
return m_kind;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if property is valid.
|
||||
*
|
||||
* @return True if property is valid.
|
||||
*/
|
||||
public boolean isValid() {
|
||||
return m_kind != Kind.kNone;
|
||||
}
|
||||
|
||||
// Kind checkers
|
||||
/**
|
||||
* Returns true if property is a boolean.
|
||||
*
|
||||
* @return True if property is a boolean.
|
||||
*/
|
||||
public boolean isBoolean() {
|
||||
return m_kind == Kind.kBoolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if property is an integer.
|
||||
*
|
||||
* @return True if property is an integer.
|
||||
*/
|
||||
public boolean isInteger() {
|
||||
return m_kind == Kind.kInteger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if property is a string.
|
||||
*
|
||||
* @return True if property is a string.
|
||||
*/
|
||||
public boolean isString() {
|
||||
return m_kind == Kind.kString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if property is an enum.
|
||||
*
|
||||
* @return True if property is an enum.
|
||||
*/
|
||||
public boolean isEnum() {
|
||||
return m_kind == Kind.kEnum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns property value.
|
||||
*
|
||||
* @return Property value.
|
||||
*/
|
||||
public int get() {
|
||||
return CameraServerJNI.getProperty(m_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets property value.
|
||||
*
|
||||
* @param value Property value.
|
||||
*/
|
||||
public void set(int value) {
|
||||
CameraServerJNI.setProperty(m_handle, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns property minimum value.
|
||||
*
|
||||
* @return Property minimum value.
|
||||
*/
|
||||
public int getMin() {
|
||||
return CameraServerJNI.getPropertyMin(m_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns property maximum value.
|
||||
*
|
||||
* @return Property maximum value.
|
||||
*/
|
||||
public int getMax() {
|
||||
return CameraServerJNI.getPropertyMax(m_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns property step size.
|
||||
*
|
||||
* @return Property step size.
|
||||
*/
|
||||
public int getStep() {
|
||||
return CameraServerJNI.getPropertyStep(m_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns property default value.
|
||||
*
|
||||
* @return Property default value.
|
||||
*/
|
||||
public int getDefault() {
|
||||
return CameraServerJNI.getPropertyDefault(m_handle);
|
||||
}
|
||||
|
||||
// String-specific functions
|
||||
/**
|
||||
* Returns the string property value.
|
||||
*
|
||||
* <p>This function is string-specific.
|
||||
*
|
||||
* @return The string property value.
|
||||
*/
|
||||
public String getString() {
|
||||
return CameraServerJNI.getStringProperty(m_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the string property value.
|
||||
*
|
||||
* <p>This function is string-specific.
|
||||
*
|
||||
* @param value String property value.
|
||||
*/
|
||||
public void setString(String value) {
|
||||
CameraServerJNI.setStringProperty(m_handle, value);
|
||||
}
|
||||
|
||||
// Enum-specific functions
|
||||
/**
|
||||
* Returns the possible values for the enum property value.
|
||||
*
|
||||
* <p>This function is enum-specific.
|
||||
*
|
||||
* @return The possible values for the enum property value.
|
||||
*/
|
||||
public String[] getChoices() {
|
||||
return CameraServerJNI.getEnumPropertyChoices(m_handle);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,11 @@ public class VideoSink implements AutoCloseable {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Kind value.
|
||||
*
|
||||
* @return The Kind value.
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
@@ -48,6 +53,11 @@ public class VideoSink implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a VideoSink.
|
||||
*
|
||||
* @param handle The video sink handle.
|
||||
*/
|
||||
protected VideoSink(int handle) {
|
||||
m_handle = handle;
|
||||
}
|
||||
@@ -60,10 +70,20 @@ public class VideoSink implements AutoCloseable {
|
||||
m_handle = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the VideoSink is valid.
|
||||
*
|
||||
* @return True if the VideoSink is valid.
|
||||
*/
|
||||
public boolean isValid() {
|
||||
return m_handle != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the video sink handle.
|
||||
*
|
||||
* @return The video sink handle.
|
||||
*/
|
||||
public int getHandle() {
|
||||
return m_handle;
|
||||
}
|
||||
@@ -222,5 +242,6 @@ public class VideoSink implements AutoCloseable {
|
||||
return rv;
|
||||
}
|
||||
|
||||
/** The VideoSink handle. */
|
||||
protected int m_handle;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import edu.wpi.first.util.PixelFormat;
|
||||
* (e.g. from a stereo or depth camera); these are called channels.
|
||||
*/
|
||||
public class VideoSource implements AutoCloseable {
|
||||
/** Video source kind. */
|
||||
public enum Kind {
|
||||
/** Unknown video source. */
|
||||
kUnknown(0),
|
||||
@@ -29,6 +30,11 @@ public class VideoSource implements AutoCloseable {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Kind value.
|
||||
*
|
||||
* @return The Kind value.
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
@@ -56,6 +62,11 @@ public class VideoSource implements AutoCloseable {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ConnectionStrategy value.
|
||||
*
|
||||
* @return The ConnectionStrategy value.
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
@@ -80,6 +91,11 @@ public class VideoSource implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a VideoSource.
|
||||
*
|
||||
* @param handle The video source handle.
|
||||
*/
|
||||
protected VideoSource(int handle) {
|
||||
m_handle = handle;
|
||||
}
|
||||
@@ -92,10 +108,20 @@ public class VideoSource implements AutoCloseable {
|
||||
m_handle = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the VideoSource is valid.
|
||||
*
|
||||
* @return True if the VideoSource is valid.
|
||||
*/
|
||||
public boolean isValid() {
|
||||
return m_handle != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the video source handle.
|
||||
*
|
||||
* @return The video source handle.
|
||||
*/
|
||||
public int getHandle() {
|
||||
return m_handle;
|
||||
}
|
||||
@@ -379,5 +405,6 @@ public class VideoSource implements AutoCloseable {
|
||||
return rv;
|
||||
}
|
||||
|
||||
/** Video source handle. */
|
||||
protected int m_handle;
|
||||
}
|
||||
|
||||
@@ -58,33 +58,139 @@ class VideoProperty {
|
||||
|
||||
VideoProperty() = default;
|
||||
|
||||
/**
|
||||
* Returns property name.
|
||||
*
|
||||
* @return Property name.
|
||||
*/
|
||||
std::string GetName() const;
|
||||
|
||||
/**
|
||||
* Returns property kind.
|
||||
*
|
||||
* @return Property kind.
|
||||
*/
|
||||
Kind GetKind() const { return m_kind; }
|
||||
|
||||
/**
|
||||
* Returns true if property is valid.
|
||||
*
|
||||
* @return True if property is valid.
|
||||
*/
|
||||
explicit operator bool() const { return m_kind != kNone; }
|
||||
|
||||
// Kind checkers
|
||||
/**
|
||||
* Returns true if property is a boolean.
|
||||
*
|
||||
* @return True if property is a boolean.
|
||||
*/
|
||||
bool IsBoolean() const { return m_kind == kBoolean; }
|
||||
|
||||
/**
|
||||
* Returns true if property is an integer.
|
||||
*
|
||||
* @return True if property is an integer.
|
||||
*/
|
||||
bool IsInteger() const { return m_kind == kInteger; }
|
||||
|
||||
/**
|
||||
* Returns true if property is a string.
|
||||
*
|
||||
* @return True if property is a string.
|
||||
*/
|
||||
bool IsString() const { return m_kind == kString; }
|
||||
|
||||
/**
|
||||
* Returns true if property is an enum.
|
||||
*
|
||||
* @return True if property is an enum.
|
||||
*/
|
||||
bool IsEnum() const { return m_kind == kEnum; }
|
||||
|
||||
/**
|
||||
* Returns property value.
|
||||
*
|
||||
* @return Property value.
|
||||
*/
|
||||
int Get() const;
|
||||
|
||||
/**
|
||||
* Sets property value.
|
||||
*
|
||||
* @param value Property value.
|
||||
*/
|
||||
void Set(int value);
|
||||
|
||||
/**
|
||||
* Returns property minimum value.
|
||||
*
|
||||
* @return Property minimum value.
|
||||
*/
|
||||
int GetMin() const;
|
||||
|
||||
/**
|
||||
* Returns property maximum value.
|
||||
*
|
||||
* @return Property maximum value.
|
||||
*/
|
||||
int GetMax() const;
|
||||
|
||||
/**
|
||||
* Returns property step size.
|
||||
*
|
||||
* @return Property step size.
|
||||
*/
|
||||
int GetStep() const;
|
||||
|
||||
/**
|
||||
* Returns property default value.
|
||||
*
|
||||
* @return Property default value.
|
||||
*/
|
||||
int GetDefault() const;
|
||||
|
||||
// String-specific functions
|
||||
/**
|
||||
* Returns the string property value.
|
||||
*
|
||||
* <p>This function is string-specific.
|
||||
*
|
||||
* @return The string property value.
|
||||
*/
|
||||
std::string GetString() const;
|
||||
|
||||
/**
|
||||
* Returns the string property value as a reference to the given buffer.
|
||||
*
|
||||
* This function is string-specific.
|
||||
*
|
||||
* @param buf The backing storage to which to write the property value.
|
||||
* @return The string property value as a reference to the given buffer.
|
||||
*/
|
||||
std::string_view GetString(wpi::SmallVectorImpl<char>& buf) const;
|
||||
|
||||
/**
|
||||
* Sets the string property value.
|
||||
*
|
||||
* This function is string-specific.
|
||||
*
|
||||
* @param value String property value.
|
||||
*/
|
||||
void SetString(std::string_view value);
|
||||
|
||||
// Enum-specific functions
|
||||
/**
|
||||
* Returns the possible values for the enum property value.
|
||||
*
|
||||
* This function is enum-specific.
|
||||
*
|
||||
* @return The possible values for the enum property value.
|
||||
*/
|
||||
std::vector<std::string> GetChoices() const;
|
||||
|
||||
/**
|
||||
* Returns the last status.
|
||||
*
|
||||
* @return The last status.
|
||||
*/
|
||||
CS_Status GetLastStatus() const { return m_status; }
|
||||
|
||||
private:
|
||||
@@ -104,6 +210,9 @@ class VideoSource {
|
||||
friend class VideoSink;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Video source kind.
|
||||
*/
|
||||
enum Kind {
|
||||
/// Unknown video source.
|
||||
kUnknown = CS_SOURCE_UNKNOWN,
|
||||
@@ -359,6 +468,8 @@ class VideoSource {
|
||||
explicit VideoSource(CS_Source handle) : m_handle(handle) {}
|
||||
|
||||
mutable CS_Status m_status = 0;
|
||||
|
||||
/// Video source handle.
|
||||
CS_Source m_handle{0};
|
||||
};
|
||||
|
||||
@@ -367,11 +478,19 @@ class VideoSource {
|
||||
*/
|
||||
class VideoCamera : public VideoSource {
|
||||
public:
|
||||
/**
|
||||
* White balance.
|
||||
*/
|
||||
enum WhiteBalance {
|
||||
/// Fixed indoor white balance.
|
||||
kFixedIndoor = 3000,
|
||||
/// Fixed outdoor white balance 1.
|
||||
kFixedOutdoor1 = 4000,
|
||||
/// Fixed outdoor white balance 2.
|
||||
kFixedOutdoor2 = 5000,
|
||||
/// Fixed fluorescent white balance 1.
|
||||
kFixedFluorescent1 = 5100,
|
||||
/// Fixed fluorescent white balance 2.
|
||||
kFixedFlourescent2 = 5200
|
||||
};
|
||||
|
||||
@@ -479,6 +598,9 @@ class UsbCamera : public VideoCamera {
|
||||
*/
|
||||
class HttpCamera : public VideoCamera {
|
||||
public:
|
||||
/**
|
||||
* HTTP camera kind.
|
||||
*/
|
||||
enum HttpCameraKind {
|
||||
/// Unknown camera kind.
|
||||
kUnknown = CS_HTTP_UNKNOWN,
|
||||
@@ -743,8 +865,18 @@ class VideoSink {
|
||||
VideoSink& operator=(VideoSink other) noexcept;
|
||||
~VideoSink();
|
||||
|
||||
/**
|
||||
* Returns true if the VideoSink is valid.
|
||||
*
|
||||
* @return True if the VideoSink is valid.
|
||||
*/
|
||||
explicit operator bool() const { return m_handle != 0; }
|
||||
|
||||
/**
|
||||
* Returns the VideoSink handle.
|
||||
*
|
||||
* @return The VideoSink handle.
|
||||
*/
|
||||
int GetHandle() const { return m_handle; }
|
||||
|
||||
bool operator==(const VideoSink& other) const {
|
||||
@@ -988,17 +1120,23 @@ class ImageSink : public VideoSink {
|
||||
class VideoEvent : public RawEvent {
|
||||
public:
|
||||
/**
|
||||
* Get the source associated with the event (if any).
|
||||
* Returns the source associated with the event (if any).
|
||||
*
|
||||
* @return The source associated with the event (if any).
|
||||
*/
|
||||
VideoSource GetSource() const;
|
||||
|
||||
/**
|
||||
* Get the sink associated with the event (if any).
|
||||
* Returns the sink associated with the event (if any).
|
||||
*
|
||||
* @return The sink associated with the event (if any).
|
||||
*/
|
||||
VideoSink GetSink() const;
|
||||
|
||||
/**
|
||||
* Get the property associated with the event (if any).
|
||||
* Returns the property associated with the event (if any).
|
||||
*
|
||||
* @return The property associated with the event (if any).
|
||||
*/
|
||||
VideoProperty GetProperty() const;
|
||||
};
|
||||
|
||||
@@ -213,7 +213,13 @@ task generateJavaDocs(type: Javadoc) {
|
||||
options.links("https://docs.oracle.com/en/java/javase/17/docs/api/")
|
||||
options.links("https://docs.opencv.org/4.x/javadoc/")
|
||||
options.addStringOption("tag", "pre:a:Pre-Condition")
|
||||
options.addBooleanOption("Xdoclint/package:-edu.wpi.first.math.proto," +
|
||||
options.addBooleanOption("Xdoclint/package:" +
|
||||
// TODO: v Document these, then remove them from the list
|
||||
"-edu.wpi.first.hal," +
|
||||
"-edu.wpi.first.hal.can," +
|
||||
"-edu.wpi.first.hal.simulation," +
|
||||
// TODO: ^ Document these, then remove them from the list
|
||||
"-edu.wpi.first.math.proto," +
|
||||
"-edu.wpi.first.math.controller.proto," +
|
||||
"-edu.wpi.first.math.controller.struct," +
|
||||
"-edu.wpi.first.math.geometry.proto," +
|
||||
|
||||
@@ -7,6 +7,9 @@ package edu.wpi.first.hal.can;
|
||||
import edu.wpi.first.hal.communication.NIRioStatus;
|
||||
import edu.wpi.first.hal.util.UncleanStatusException;
|
||||
|
||||
/**
|
||||
* Checks the status of a CAN message and throws an exception of the appropriate type if necessary.
|
||||
*/
|
||||
public final class CANExceptionFactory {
|
||||
// FRC Error codes
|
||||
static final int ERR_CANSessionMux_InvalidBuffer = -44086;
|
||||
|
||||
@@ -16,11 +16,16 @@ import java.nio.IntBuffer;
|
||||
*/
|
||||
@SuppressWarnings("MethodName")
|
||||
public class CANJNI extends JNIWrapper {
|
||||
/** Flag for sending a CAN message once. */
|
||||
public static final int CAN_SEND_PERIOD_NO_REPEAT = 0;
|
||||
|
||||
/** Flag for stopping periodic CAN message sends. */
|
||||
public static final int CAN_SEND_PERIOD_STOP_REPEATING = -1;
|
||||
|
||||
/* Flags in the upper bits of the messageID */
|
||||
/** Mask for "is frame remote" in message ID. */
|
||||
public static final int CAN_IS_FRAME_REMOTE = 0x80000000;
|
||||
|
||||
/** Mask for "is frame 11 bits" in message ID. */
|
||||
public static final int CAN_IS_FRAME_11BIT = 0x40000000;
|
||||
|
||||
/** Default constructor. */
|
||||
|
||||
@@ -4,13 +4,24 @@
|
||||
|
||||
package edu.wpi.first.hal.communication;
|
||||
|
||||
/** NI RIO status. */
|
||||
public class NIRioStatus {
|
||||
/** RIO status offset. */
|
||||
public static final int kRioStatusOffset = -63000;
|
||||
|
||||
/** Success. */
|
||||
public static final int kRioStatusSuccess = 0;
|
||||
|
||||
/** Buffer invalid size. */
|
||||
public static final int kRIOStatusBufferInvalidSize = kRioStatusOffset - 80;
|
||||
|
||||
/** Operation timed out. */
|
||||
public static final int kRIOStatusOperationTimedOut = -52007;
|
||||
|
||||
/** Feature not supported. */
|
||||
public static final int kRIOStatusFeatureNotSupported = kRioStatusOffset - 193;
|
||||
|
||||
/** Resource not initialized. */
|
||||
public static final int kRIOStatusResourceNotInitialized = -52010;
|
||||
|
||||
/** Default constructor. */
|
||||
|
||||
@@ -14,11 +14,24 @@
|
||||
|
||||
// These are copies of defines located in CANSessionMux.h prepended with HAL_
|
||||
|
||||
/**
|
||||
* Flag for sending a CAN message once.
|
||||
*/
|
||||
#define HAL_CAN_SEND_PERIOD_NO_REPEAT 0
|
||||
|
||||
/**
|
||||
* Flag for stopping periodic CAN message sends.
|
||||
*/
|
||||
#define HAL_CAN_SEND_PERIOD_STOP_REPEATING -1
|
||||
|
||||
/* Flags in the upper bits of the messageID */
|
||||
/**
|
||||
* Mask for "is frame remote" in message ID.
|
||||
*/
|
||||
#define HAL_CAN_IS_FRAME_REMOTE 0x80000000
|
||||
|
||||
/**
|
||||
* Mask for "is frame 11 bits" in message ID.
|
||||
*/
|
||||
#define HAL_CAN_IS_FRAME_11BIT 0x40000000
|
||||
|
||||
#define HAL_ERR_CANSessionMux_InvalidBuffer -44086
|
||||
|
||||
@@ -236,6 +236,12 @@ public interface GenericPublisher extends Publisher, Consumer<NetworkTableValue>
|
||||
boolean setDefault{{ t.TypeName }}({{ t.java.ValueType }} defaultValue);
|
||||
{% endif -%}
|
||||
{% if t.java.WrapValueType %}
|
||||
/**
|
||||
* Sets the entry's value if it does not exist.
|
||||
*
|
||||
* @param defaultValue the default value to set
|
||||
* @return False if the entry exists with a different type
|
||||
*/
|
||||
boolean setDefault{{ t.TypeName }}({{ t.java.WrapValueType }} defaultValue);
|
||||
{% endif -%}
|
||||
{% endfor %}
|
||||
|
||||
@@ -68,6 +68,11 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the network mode value.
|
||||
*
|
||||
* @return The network mode value.
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.util.EnumSet;
|
||||
import java.util.OptionalLong;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/** NetworkTables JNI. */
|
||||
public final class NetworkTablesJNI {
|
||||
static boolean libraryLoaded = false;
|
||||
static RuntimeLoader<NetworkTablesJNI> loader = null;
|
||||
@@ -82,139 +83,494 @@ public final class NetworkTablesJNI {
|
||||
return new PubSubOptions(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns default instance handle.
|
||||
*
|
||||
* @return Default instance handle.
|
||||
*/
|
||||
public static native int getDefaultInstance();
|
||||
|
||||
/**
|
||||
* Creates an NT instance.
|
||||
*
|
||||
* @return NT instance handle.
|
||||
*/
|
||||
public static native int createInstance();
|
||||
|
||||
/**
|
||||
* Destroys an NT instance.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
*/
|
||||
public static native void destroyInstance(int inst);
|
||||
|
||||
/**
|
||||
* Returns NT instance from handle.
|
||||
*
|
||||
* @param handle NT instance handle.
|
||||
* @return NT instance.
|
||||
*/
|
||||
public static native int getInstanceFromHandle(int handle);
|
||||
|
||||
private static native int getEntryImpl(
|
||||
int topic, int type, String typeStr, PubSubOptions options);
|
||||
|
||||
/**
|
||||
* Returns NT entry handle.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
* @param key NT entry key.
|
||||
* @return NT entry handle.
|
||||
*/
|
||||
public static native int getEntry(int inst, String key);
|
||||
|
||||
/**
|
||||
* Returns NT entry handle.
|
||||
*
|
||||
* @param topic NT entry topic.
|
||||
* @param type NT entry type.
|
||||
* @param typeStr NT entry type as a string.
|
||||
* @param options NT entry pubsub options.
|
||||
* @return NT entry handle.
|
||||
*/
|
||||
public static int getEntry(
|
||||
int topic, int type, String typeStr, PubSubOptions options) {
|
||||
return getEntryImpl(topic, type, typeStr, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns NT entry handle.
|
||||
*
|
||||
* @param topic NT entry topic.
|
||||
* @param type NT entry type.
|
||||
* @param typeStr NT entry type as a string.
|
||||
* @param options NT entry pubsub options.
|
||||
* @return NT entry handle.
|
||||
*/
|
||||
public static int getEntry(
|
||||
int topic, int type, String typeStr, PubSubOption... options) {
|
||||
return getEntryImpl(topic, type, typeStr, buildOptions(options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns NT entry name.
|
||||
*
|
||||
* @param entry NT entry handle.
|
||||
* @return NT entry name.
|
||||
*/
|
||||
public static native String getEntryName(int entry);
|
||||
|
||||
/**
|
||||
* Returns NT entry last change time in microseconds.
|
||||
*
|
||||
* @param entry NT entry handle.
|
||||
* @return NT entry last change time in microseconds.
|
||||
*/
|
||||
public static native long getEntryLastChange(int entry);
|
||||
|
||||
/**
|
||||
* Returns NT entry type.
|
||||
*
|
||||
* @param entry NT entry handle.
|
||||
* @return NT entry type.
|
||||
*/
|
||||
public static native int getType(int entry);
|
||||
|
||||
/* Topic functions */
|
||||
|
||||
/**
|
||||
* Returns list of topic handles.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
* @param prefix Topic prefix.
|
||||
* @param types Topic types.
|
||||
* @return List of topic handles.
|
||||
*/
|
||||
public static native int[] getTopics(int inst, String prefix, int types);
|
||||
|
||||
/**
|
||||
* Returns list of topic handles.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
* @param prefix Topic prefix.
|
||||
* @param types Topic types as strings.
|
||||
* @return List of topic handles.
|
||||
*/
|
||||
public static native int[] getTopicsStr(int inst, String prefix, String[] types);
|
||||
|
||||
/**
|
||||
* Returns list of topic infos.
|
||||
*
|
||||
* @param instObject NT instance.
|
||||
* @param inst NT instance handle.
|
||||
* @param prefix Topic prefix.
|
||||
* @param types Topic types.
|
||||
* @return List of topic infos.
|
||||
*/
|
||||
public static native TopicInfo[] getTopicInfos(
|
||||
NetworkTableInstance instObject, int inst, String prefix, int types);
|
||||
|
||||
/**
|
||||
* Returns list of topic infos.
|
||||
*
|
||||
* @param instObject NT instance.
|
||||
* @param inst NT instance handle.
|
||||
* @param prefix Topic prefix.
|
||||
* @param types Topic types as strings.
|
||||
* @return List of topic infos.
|
||||
*/
|
||||
public static native TopicInfo[] getTopicInfosStr(
|
||||
NetworkTableInstance instObject, int inst, String prefix, String[] types);
|
||||
|
||||
/**
|
||||
* Returns Topic handle.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
* @param name Topic name.
|
||||
* @return Topic handle.
|
||||
*/
|
||||
public static native int getTopic(int inst, String name);
|
||||
|
||||
/**
|
||||
* Returns topic name.
|
||||
*
|
||||
* @param topic Topic handle.
|
||||
* @return Topic name.
|
||||
*/
|
||||
public static native String getTopicName(int topic);
|
||||
|
||||
/**
|
||||
* Returns topic type.
|
||||
*
|
||||
* @param topic Topic handle.
|
||||
* @return Topic type.
|
||||
*/
|
||||
public static native int getTopicType(int topic);
|
||||
|
||||
/**
|
||||
* Sets topic persistency.
|
||||
*
|
||||
* @param topic Topic handle.
|
||||
* @param value True if topic should be persistent.
|
||||
*/
|
||||
public static native void setTopicPersistent(int topic, boolean value);
|
||||
|
||||
/**
|
||||
* Returns true if topic is persistent.
|
||||
*
|
||||
* @param topic Topic handle.
|
||||
* @return True if topic is persistent.
|
||||
*/
|
||||
public static native boolean getTopicPersistent(int topic);
|
||||
|
||||
/**
|
||||
* Sets whether topic is retained.
|
||||
*
|
||||
* @param topic Topic handle.
|
||||
* @param value True if topic should be retained.
|
||||
*/
|
||||
public static native void setTopicRetained(int topic, boolean value);
|
||||
|
||||
/**
|
||||
* Returns true if topic is retained.
|
||||
*
|
||||
* @param topic Topic handle.
|
||||
* @return True if topic is retained.
|
||||
*/
|
||||
public static native boolean getTopicRetained(int topic);
|
||||
|
||||
/**
|
||||
* Sets topic caching.
|
||||
*
|
||||
* @param topic Topic handle.
|
||||
* @param value True if topic should be cached.
|
||||
*/
|
||||
public static native void setTopicCached(int topic, boolean value);
|
||||
|
||||
/**
|
||||
* Returns true if topic is cached.
|
||||
*
|
||||
* @param topic Topic handle.
|
||||
* @return True if topic is cached.
|
||||
*/
|
||||
public static native boolean getTopicCached(int topic);
|
||||
|
||||
/**
|
||||
* Returns topic type as string.
|
||||
*
|
||||
* @param topic Topic handle.
|
||||
* @return Topic type as string.
|
||||
*/
|
||||
public static native String getTopicTypeString(int topic);
|
||||
|
||||
/**
|
||||
* Returns true if topic exists.
|
||||
*
|
||||
* @param topic Topic handle.
|
||||
* @return True if topic exists.
|
||||
*/
|
||||
public static native boolean getTopicExists(int topic);
|
||||
|
||||
/**
|
||||
* Returns topic property.
|
||||
*
|
||||
* @param topic Topic handle.
|
||||
* @param name Property name.
|
||||
* @return Topic property.
|
||||
*/
|
||||
public static native String getTopicProperty(int topic, String name);
|
||||
|
||||
/**
|
||||
* Sets topic property.
|
||||
*
|
||||
* @param topic Topic handle.
|
||||
* @param name Property name.
|
||||
* @param value Property value.
|
||||
*/
|
||||
public static native void setTopicProperty(int topic, String name, String value);
|
||||
|
||||
/**
|
||||
* Deletes topic property.
|
||||
*
|
||||
* @param topic Topic handle.
|
||||
* @param name Property name.
|
||||
*/
|
||||
public static native void deleteTopicProperty(int topic, String name);
|
||||
|
||||
/**
|
||||
* Returns topic properties.
|
||||
*
|
||||
* @param topic Topic handle.
|
||||
* @return Topic properties.
|
||||
*/
|
||||
public static native String getTopicProperties(int topic);
|
||||
|
||||
/**
|
||||
* Sets topic properties.
|
||||
*
|
||||
* @param topic Topic handle.
|
||||
* @param properties Topic properties.
|
||||
*/
|
||||
public static native void setTopicProperties(int topic, String properties);
|
||||
|
||||
/**
|
||||
* Subscribes to topic.
|
||||
*
|
||||
* @param topic Topic handle.
|
||||
* @param type Topic type.
|
||||
* @param typeStr Topic type as a string.
|
||||
* @param options Pubsub options.
|
||||
* @return Subscriber handle.
|
||||
*/
|
||||
public static native int subscribe(
|
||||
int topic, int type, String typeStr, PubSubOptions options);
|
||||
|
||||
/**
|
||||
* Subscribes to topic.
|
||||
*
|
||||
* @param topic Topic handle.
|
||||
* @param type Topic type.
|
||||
* @param typeStr Topic type as a string.
|
||||
* @param options Pubsub options.
|
||||
* @return Subscriber handle.
|
||||
*/
|
||||
public static int subscribe(
|
||||
int topic, int type, String typeStr, PubSubOption... options) {
|
||||
return subscribe(topic, type, typeStr, buildOptions(options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsubscribes from topic.
|
||||
*
|
||||
* @param sub Subscriber handle.
|
||||
*/
|
||||
public static native void unsubscribe(int sub);
|
||||
|
||||
/**
|
||||
* Publishes topic.
|
||||
*
|
||||
* @param topic Topic handle.
|
||||
* @param type Topic type.
|
||||
* @param typeStr Topic type as a string.
|
||||
* @param options Pubsub options.
|
||||
* @return Publish handle.
|
||||
*/
|
||||
public static native int publish(
|
||||
int topic, int type, String typeStr, PubSubOptions options);
|
||||
|
||||
/**
|
||||
* Publishes topic.
|
||||
*
|
||||
* @param topic Topic handle.
|
||||
* @param type Topic type.
|
||||
* @param typeStr Topic type as a string.
|
||||
* @param options Pubsub options.
|
||||
* @return Publish handle.
|
||||
*/
|
||||
public static int publish(
|
||||
int topic, int type, String typeStr, PubSubOption... options) {
|
||||
return publish(topic, type, typeStr, buildOptions(options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Publishes topic.
|
||||
*
|
||||
* @param topic Topic handle.
|
||||
* @param type Topic type.
|
||||
* @param typeStr Topic type as a string.
|
||||
* @param properties Topic properties.
|
||||
* @param options Pubsub options.
|
||||
* @return Publish handle.
|
||||
*/
|
||||
public static native int publishEx(
|
||||
int topic, int type, String typeStr, String properties, PubSubOptions options);
|
||||
|
||||
/**
|
||||
* Publishes topic.
|
||||
*
|
||||
* @param topic Topic handle.
|
||||
* @param type Topic type.
|
||||
* @param typeStr Topic type as a string.
|
||||
* @param properties Topic properties.
|
||||
* @param options Pubsub options.
|
||||
* @return Publish handle.
|
||||
*/
|
||||
public static int publishEx(
|
||||
int topic, int type, String typeStr, String properties, PubSubOption... options) {
|
||||
return publishEx(topic, type, typeStr, properties, buildOptions(options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpublishes topic.
|
||||
*
|
||||
* @param pubentry Publish entry handle.
|
||||
*/
|
||||
public static native void unpublish(int pubentry);
|
||||
|
||||
/**
|
||||
* Releases NT entry.
|
||||
*
|
||||
* @param entry NT entry handle.
|
||||
*/
|
||||
public static native void releaseEntry(int entry);
|
||||
|
||||
/**
|
||||
* Relesaes pubsub entry.
|
||||
*
|
||||
* @param pubsubentry Pubsub entry handle.
|
||||
*/
|
||||
public static native void release(int pubsubentry);
|
||||
|
||||
/**
|
||||
* Returns topic from pubsub entry handle.
|
||||
*
|
||||
* @param pubsubentry Pubsub entry handle.
|
||||
* @return Topic handle.
|
||||
*/
|
||||
public static native int getTopicFromHandle(int pubsubentry);
|
||||
|
||||
/**
|
||||
* Subscribes to multiple topics.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
* @param prefixes List of topic prefixes.
|
||||
* @param options Pubsub options.
|
||||
* @return Subscribe handle.
|
||||
*/
|
||||
public static native int subscribeMultiple(int inst, String[] prefixes, PubSubOptions options);
|
||||
|
||||
/**
|
||||
* Subscribes to multiple topics.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
* @param prefixes List of topic prefixes.
|
||||
* @param options Pubsub options.
|
||||
* @return Subscribe handle.
|
||||
*/
|
||||
public static int subscribeMultiple(int inst, String[] prefixes, PubSubOption... options) {
|
||||
return subscribeMultiple(inst, prefixes, buildOptions(options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsubscribes from multiple topics.
|
||||
*
|
||||
* @param sub Subscribe handle.
|
||||
*/
|
||||
public static native void unsubscribeMultiple(int sub);
|
||||
{% for t in types %}
|
||||
/**
|
||||
* Returns timestamped topic value as an atomic {{ t.TypeName }}.
|
||||
*
|
||||
* @param subentry Subentry handle.
|
||||
* @param defaultValue Default value.
|
||||
* @return Timestamped topic value.
|
||||
*/
|
||||
public static native Timestamped{{ t.TypeName }} getAtomic{{ t.TypeName }}(
|
||||
int subentry, {{ t.java.ValueType }} defaultValue);
|
||||
|
||||
/**
|
||||
* Returns queued timestamped topic values.
|
||||
*
|
||||
* @param subentry Subentry handle.
|
||||
* @return List of timestamped topic values.
|
||||
*/
|
||||
public static native Timestamped{{ t.TypeName }}[] readQueue{{ t.TypeName }}(int subentry);
|
||||
|
||||
/**
|
||||
* Returns queued topic values.
|
||||
*
|
||||
* @param subentry Subentry handle.
|
||||
* @return List of topic values.
|
||||
*/
|
||||
public static native {{ t.java.ValueType }}[] readQueueValues{{ t.TypeName }}(int subentry);
|
||||
{% if t.TypeName == "Raw" %}
|
||||
/**
|
||||
* Sets raw topic value.
|
||||
*
|
||||
* @param entry Entry handle.
|
||||
* @param time Time in microseconds.
|
||||
* @param value Raw value buffer.
|
||||
* @return True if set succeeded.
|
||||
*/
|
||||
public static boolean setRaw(int entry, long time, byte[] value) {
|
||||
return setRaw(entry, time, value, 0, value.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets raw topic value.
|
||||
*
|
||||
* @param entry Entry handle.
|
||||
* @param time Time in microseconds.
|
||||
* @param value Raw value buffer.
|
||||
* @param start Value's offset into buffer.
|
||||
* @param len Length of value in buffer.
|
||||
* @return True if set succeeded.
|
||||
*/
|
||||
public static native boolean setRaw(int entry, long time, byte[] value, int start, int len);
|
||||
|
||||
/**
|
||||
* Sets raw topic value.
|
||||
*
|
||||
* @param entry Entry handle.
|
||||
* @param time Time in microseconds.
|
||||
* @param value Raw value buffer.
|
||||
* @return True if set succeeded.
|
||||
*/
|
||||
public static boolean setRaw(int entry, long time, ByteBuffer value) {
|
||||
int pos = value.position();
|
||||
return setRaw(entry, time, value, pos, value.capacity() - pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets raw topic value.
|
||||
*
|
||||
* @param entry Entry handle.
|
||||
* @param time Time in microseconds.
|
||||
* @param value Raw value buffer.
|
||||
* @param start Value's offset into buffer.
|
||||
* @param len Length of value in buffer.
|
||||
* @return True if set succeeded.
|
||||
*/
|
||||
public static boolean setRaw(int entry, long time, ByteBuffer value, int start, int len) {
|
||||
if (value.isDirect()) {
|
||||
if (start < 0) {
|
||||
@@ -234,23 +590,84 @@ public final class NetworkTablesJNI {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets raw topic value buffer.
|
||||
*
|
||||
* @param entry Entry handle.
|
||||
* @param time Time in microseconds.
|
||||
* @param value Raw value buffer.
|
||||
* @param start Value's offset into buffer.
|
||||
* @param len Length of value in buffer.
|
||||
* @return True if set succeeded.
|
||||
*/
|
||||
private static native boolean setRawBuffer(int entry, long time, ByteBuffer value, int start, int len);
|
||||
{% else %}
|
||||
/**
|
||||
* Sets topic value.
|
||||
*
|
||||
* @param entry Entry handle.
|
||||
* @param time Time in microseconds.
|
||||
* @param value Topic value.
|
||||
* @return True if set succeeded.
|
||||
*/
|
||||
public static native boolean set{{ t.TypeName }}(int entry, long time, {{ t.java.ValueType }} value);
|
||||
{% endif %}
|
||||
/**
|
||||
* Returns topic value.
|
||||
*
|
||||
* @param entry Entry handle.
|
||||
* @param defaultValue Default value.
|
||||
* @return Topic value.
|
||||
*/
|
||||
public static native {{ t.java.ValueType }} get{{ t.TypeName }}(int entry, {{ t.java.ValueType }} defaultValue);
|
||||
{% if t.TypeName == "Raw" %}
|
||||
/**
|
||||
* Sets default raw topic value.
|
||||
*
|
||||
* @param entry Entry handle.
|
||||
* @param time Time in microseconds.
|
||||
* @param defaultValue Default value.
|
||||
* @return True if set succeeded.
|
||||
*/
|
||||
public static boolean setDefaultRaw(int entry, long time, byte[] defaultValue) {
|
||||
return setDefaultRaw(entry, time, defaultValue, 0, defaultValue.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets default raw topic value.
|
||||
*
|
||||
* @param entry Entry handle.
|
||||
* @param time Time in microseconds.
|
||||
* @param defaultValue Default value.
|
||||
* @param start Value's offset into buffer.
|
||||
* @param len Length of value in buffer.
|
||||
* @return True if set succeeded.
|
||||
*/
|
||||
public static native boolean setDefaultRaw(int entry, long time, byte[] defaultValue, int start, int len);
|
||||
|
||||
/**
|
||||
* Sets default raw topic value.
|
||||
*
|
||||
* @param entry Entry handle.
|
||||
* @param time Time in microseconds.
|
||||
* @param defaultValue Default value.
|
||||
* @return True if set succeeded.
|
||||
*/
|
||||
public static boolean setDefaultRaw(int entry, long time, ByteBuffer defaultValue) {
|
||||
int pos = defaultValue.position();
|
||||
return setDefaultRaw(entry, time, defaultValue, pos, defaultValue.limit() - pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets default raw topic value.
|
||||
*
|
||||
* @param entry Entry handle.
|
||||
* @param time Time in microseconds.
|
||||
* @param defaultValue Default value.
|
||||
* @param start Value's offset into buffer.
|
||||
* @param len Length of value in buffer.
|
||||
* @return True if set succeeded.
|
||||
*/
|
||||
public static boolean setDefaultRaw(int entry, long time, ByteBuffer defaultValue, int start, int len) {
|
||||
if (defaultValue.isDirect()) {
|
||||
if (start < 0) {
|
||||
@@ -270,25 +687,91 @@ public final class NetworkTablesJNI {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets default raw topic value buffer.
|
||||
*
|
||||
* @param entry Entry handle.
|
||||
* @param time Time in microseconds.
|
||||
* @param defaultValue Default value.
|
||||
* @param start Value's offset into buffer.
|
||||
* @param len Length of value in buffer.
|
||||
* @return True if set succeeded.
|
||||
*/
|
||||
private static native boolean setDefaultRawBuffer(int entry, long time, ByteBuffer defaultValue, int start, int len);
|
||||
{% else %}
|
||||
/**
|
||||
* Sets default topic value.
|
||||
*
|
||||
* @param entry Entry handle.
|
||||
* @param time Time in microseconds.
|
||||
* @param defaultValue Default value.
|
||||
* @return True if set succeeded.
|
||||
*/
|
||||
public static native boolean setDefault{{ t.TypeName }}(int entry, long time, {{ t.java.ValueType }} defaultValue);
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
/**
|
||||
* Returns queued subentry values.
|
||||
*
|
||||
* @param subentry Subentry handle.
|
||||
* @return List of queued subentry values.
|
||||
*/
|
||||
public static native NetworkTableValue[] readQueueValue(int subentry);
|
||||
|
||||
/**
|
||||
* Returns entry's NT value.
|
||||
*
|
||||
* @param entry Entry handle.
|
||||
* @return Entry's NT value.
|
||||
*/
|
||||
public static native NetworkTableValue getValue(int entry);
|
||||
|
||||
/**
|
||||
* Sets entry flags.
|
||||
*
|
||||
* @param entry Entry handle.
|
||||
* @param flags Entry flags.
|
||||
*/
|
||||
public static native void setEntryFlags(int entry, int flags);
|
||||
|
||||
/**
|
||||
* Returns entry flags.
|
||||
*
|
||||
* @param entry Entry handle.
|
||||
* @return Entry flags.
|
||||
*/
|
||||
public static native int getEntryFlags(int entry);
|
||||
|
||||
/**
|
||||
* Returns topic info.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
* @param topic Topic handle.
|
||||
* @return Topic info.
|
||||
*/
|
||||
public static native TopicInfo getTopicInfo(NetworkTableInstance inst, int topic);
|
||||
|
||||
/**
|
||||
* Creates a listener poller.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
* @return Listener poller handle.
|
||||
*/
|
||||
public static native int createListenerPoller(int inst);
|
||||
|
||||
/**
|
||||
* Destroys listener poller.
|
||||
*
|
||||
* @param poller Listener poller handle.
|
||||
*/
|
||||
public static native void destroyListenerPoller(int poller);
|
||||
|
||||
/**
|
||||
* Converts NT event kinds to mask.
|
||||
*
|
||||
* @param kinds Enum set of NT event kinds.
|
||||
* @return NT event mask.
|
||||
*/
|
||||
private static int kindsToMask(EnumSet<NetworkTableEvent.Kind> kinds) {
|
||||
int mask = 0;
|
||||
for (NetworkTableEvent.Kind kind : kinds) {
|
||||
@@ -297,80 +780,316 @@ public final class NetworkTablesJNI {
|
||||
return mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds listener.
|
||||
*
|
||||
* @param poller Listener poller handle.
|
||||
* @param prefixes Topic prefixes.
|
||||
* @param kinds Enum set of NT event kinds.
|
||||
* @return Listener handle.
|
||||
*/
|
||||
public static int addListener(int poller, String[] prefixes, EnumSet<NetworkTableEvent.Kind> kinds) {
|
||||
return addListener(poller, prefixes, kindsToMask(kinds));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds listener.
|
||||
*
|
||||
* @param poller Listener poller handle.
|
||||
* @param handle Topic handle.
|
||||
* @param kinds Enum set of NT event kinds.
|
||||
* @return Listener handle.
|
||||
*/
|
||||
public static int addListener(int poller, int handle, EnumSet<NetworkTableEvent.Kind> kinds) {
|
||||
return addListener(poller, handle, kindsToMask(kinds));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds listener.
|
||||
*
|
||||
* @param poller Listener poller handle.
|
||||
* @param prefixes Topic prefixes.
|
||||
* @param mask NT event mask.
|
||||
* @return Listener handle.
|
||||
*/
|
||||
public static native int addListener(int poller, String[] prefixes, int mask);
|
||||
|
||||
/**
|
||||
* Adds listener.
|
||||
*
|
||||
* @param poller Listener poller handle.
|
||||
* @param handle Topic handle.
|
||||
* @param mask NT event mask.
|
||||
* @return Listener handle.
|
||||
*/
|
||||
public static native int addListener(int poller, int handle, int mask);
|
||||
|
||||
/**
|
||||
* Returns NT events from listener queue.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
* @param poller Listener poller handle.
|
||||
* @return List of NT events.
|
||||
*/
|
||||
public static native NetworkTableEvent[] readListenerQueue(
|
||||
NetworkTableInstance inst, int poller);
|
||||
|
||||
/**
|
||||
* Removes listener.
|
||||
*
|
||||
* @param listener Listener handle.
|
||||
*/
|
||||
public static native void removeListener(int listener);
|
||||
|
||||
/**
|
||||
* Returns network mode.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
* @return Network mode.
|
||||
*/
|
||||
public static native int getNetworkMode(int inst);
|
||||
|
||||
/**
|
||||
* Starts local-only operation. Prevents calls to startServer or startClient from taking effect.
|
||||
* Has no effect if startServer or startClient has already been called.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
*/
|
||||
public static native void startLocal(int inst);
|
||||
|
||||
/**
|
||||
* Stops local-only operation. startServer or startClient can be called after this call to start
|
||||
* a server or client.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
*/
|
||||
public static native void stopLocal(int inst);
|
||||
|
||||
/**
|
||||
* Starts a server using the specified filename, listening address, and port.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
* @param persistFilename the name of the persist file to use
|
||||
* @param listenAddress the address to listen on, or empty to listen on any address
|
||||
* @param port3 port to communicate over (NT3)
|
||||
* @param port4 port to communicate over (NT4)
|
||||
*/
|
||||
public static native void startServer(
|
||||
int inst, String persistFilename, String listenAddress, int port3, int port4);
|
||||
|
||||
/**
|
||||
* Stops the server if it is running.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
*/
|
||||
public static native void stopServer(int inst);
|
||||
|
||||
/**
|
||||
* Starts a NT3 client. Use SetServer or SetServerTeam to set the server name and port.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
* @param identity network identity to advertise (cannot be empty string)
|
||||
*/
|
||||
public static native void startClient3(int inst, String identity);
|
||||
|
||||
/**
|
||||
* Starts a NT4 client. Use SetServer or SetServerTeam to set the server name and port.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
* @param identity network identity to advertise (cannot be empty string)
|
||||
*/
|
||||
public static native void startClient4(int inst, String identity);
|
||||
|
||||
/**
|
||||
* Stops the client if it is running.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
*/
|
||||
public static native void stopClient(int inst);
|
||||
|
||||
/**
|
||||
* Sets server address and port for client (without restarting client).
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
* @param serverName server name
|
||||
* @param port port to communicate over
|
||||
*/
|
||||
public static native void setServer(int inst, String serverName, int port);
|
||||
|
||||
/**
|
||||
* Sets server addresses and ports for client (without restarting client). The client will
|
||||
* attempt to connect to each server in round robin fashion.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
* @param serverNames array of server names
|
||||
* @param ports array of port numbers (0=default)
|
||||
*/
|
||||
public static native void setServer(int inst, String[] serverNames, int[] ports);
|
||||
|
||||
/**
|
||||
* Sets server addresses and port for client (without restarting client). Connects using commonly
|
||||
* known robot addresses for the specified team.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
* @param team team number
|
||||
* @param port port to communicate over
|
||||
*/
|
||||
public static native void setServerTeam(int inst, int team, int port);
|
||||
|
||||
/**
|
||||
* Disconnects the client if it's running and connected. This will automatically start
|
||||
* reconnection attempts to the current server list.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
*/
|
||||
public static native void disconnect(int inst);
|
||||
|
||||
/**
|
||||
* Starts requesting server address from Driver Station. This connects to the Driver Station
|
||||
* running on localhost to obtain the server IP address.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
* @param port server port to use in combination with IP from DS
|
||||
*/
|
||||
public static native void startDSClient(int inst, int port);
|
||||
|
||||
/**
|
||||
* Stops requesting server address from Driver Station.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
*/
|
||||
public static native void stopDSClient(int inst);
|
||||
|
||||
/**
|
||||
* Flushes all updated values immediately to the local client/server. This does not flush to the
|
||||
* network.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
*/
|
||||
public static native void flushLocal(int inst);
|
||||
|
||||
/**
|
||||
* Flushes all updated values immediately to the network. Note: This is rate-limited to protect
|
||||
* the network from flooding. This is primarily useful for synchronizing network updates with
|
||||
* user code.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
*/
|
||||
public static native void flush(int inst);
|
||||
|
||||
/**
|
||||
* Gets information on the currently established network connections. If operating as a client,
|
||||
* this will return either zero or one values.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
* @return array of connection information
|
||||
*/
|
||||
public static native ConnectionInfo[] getConnections(int inst);
|
||||
|
||||
/**
|
||||
* Return whether or not the instance is connected to another node.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
* @return True if connected.
|
||||
*/
|
||||
public static native boolean isConnected(int inst);
|
||||
|
||||
/**
|
||||
* Get the time offset between server time and local time. Add this value to local time to get
|
||||
* the estimated equivalent server time. In server mode, this always returns 0. In client mode,
|
||||
* this returns the time offset only if the client and server are connected and have exchanged
|
||||
* synchronization messages. Note the time offset may change over time as it is periodically
|
||||
* updated; to receive updates as events, add a listener to the "time sync" event.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
* @return Time offset in microseconds (optional)
|
||||
*/
|
||||
public static native OptionalLong getServerTimeOffset(int inst);
|
||||
|
||||
/**
|
||||
* Returns the current timestamp in microseconds.
|
||||
*
|
||||
* @return The current timestsamp in microseconds.
|
||||
*/
|
||||
public static native long now();
|
||||
|
||||
/**
|
||||
* Starts logging entry changes to a DataLog.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
* @param log data log handle; lifetime must extend until StopEntryDataLog is called or the
|
||||
* instance is destroyed
|
||||
* @param prefix only store entries with names that start with this prefix; the prefix is not
|
||||
* included in the data log entry name
|
||||
* @param logPrefix prefix to add to data log entry names
|
||||
* @return Data logger handle
|
||||
*/
|
||||
private static native int startEntryDataLog(int inst, long log, String prefix, String logPrefix);
|
||||
|
||||
/**
|
||||
* Starts logging entry changes to a DataLog.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
* @param log data log object; lifetime must extend until StopEntryDataLog is called or the
|
||||
* instance is destroyed
|
||||
* @param prefix only store entries with names that start with this prefix; the prefix is not
|
||||
* included in the data log entry name
|
||||
* @param logPrefix prefix to add to data log entry names
|
||||
* @return Data logger handle
|
||||
*/
|
||||
public static int startEntryDataLog(int inst, DataLog log, String prefix, String logPrefix) {
|
||||
return startEntryDataLog(inst, log.getImpl(), prefix, logPrefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops logging entry changes to a DataLog.
|
||||
*
|
||||
* @param logger data logger handle
|
||||
*/
|
||||
public static native void stopEntryDataLog(int logger);
|
||||
|
||||
/**
|
||||
* Starts logging connection changes to a DataLog.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
* @param log data log handle; lifetime must extend until StopConnectionDataLog is called or the
|
||||
* instance is destroyed
|
||||
* @param name data log entry name
|
||||
* @return Data logger handle
|
||||
*/
|
||||
private static native int startConnectionDataLog(int inst, long log, String name);
|
||||
|
||||
/**
|
||||
* Starts logging connection changes to a DataLog.
|
||||
*
|
||||
* @param inst NT instance handle.
|
||||
* @param log data log object; lifetime must extend until StopConnectionDataLog is called or the
|
||||
* instance is destroyed
|
||||
* @param name data log entry name
|
||||
* @return Data logger handle
|
||||
*/
|
||||
public static int startConnectionDataLog(int inst, DataLog log, String name) {
|
||||
return startConnectionDataLog(inst, log.getImpl(), name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops logging connection changes to a DataLog.
|
||||
*
|
||||
* @param logger data logger handle
|
||||
*/
|
||||
public static native void stopConnectionDataLog(int logger);
|
||||
|
||||
/**
|
||||
* Add logger callback function. By default, log messages are sent to stderr; this function sends
|
||||
* log messages with the specified levels to the provided callback function instead. The callback
|
||||
* function will only be called for log messages with level greater than or equal to minLevel and
|
||||
* less than or equal to maxLevel; messages outside this range will be silently ignored.
|
||||
*
|
||||
* @param poller Listener poller handle.
|
||||
* @param minLevel minimum log level
|
||||
* @param maxLevel maximum log level
|
||||
* @return Listener handle
|
||||
*/
|
||||
public static native int addLogger(int poller, int minLevel, int maxLevel);
|
||||
|
||||
/** Utility class. */
|
||||
|
||||
@@ -517,6 +517,12 @@ public interface GenericPublisher extends Publisher, Consumer<NetworkTableValue>
|
||||
*/
|
||||
boolean setDefaultBooleanArray(boolean[] defaultValue);
|
||||
|
||||
/**
|
||||
* Sets the entry's value if it does not exist.
|
||||
*
|
||||
* @param defaultValue the default value to set
|
||||
* @return False if the entry exists with a different type
|
||||
*/
|
||||
boolean setDefaultBooleanArray(Boolean[] defaultValue);
|
||||
|
||||
|
||||
@@ -528,6 +534,12 @@ public interface GenericPublisher extends Publisher, Consumer<NetworkTableValue>
|
||||
*/
|
||||
boolean setDefaultIntegerArray(long[] defaultValue);
|
||||
|
||||
/**
|
||||
* Sets the entry's value if it does not exist.
|
||||
*
|
||||
* @param defaultValue the default value to set
|
||||
* @return False if the entry exists with a different type
|
||||
*/
|
||||
boolean setDefaultIntegerArray(Long[] defaultValue);
|
||||
|
||||
|
||||
@@ -539,6 +551,12 @@ public interface GenericPublisher extends Publisher, Consumer<NetworkTableValue>
|
||||
*/
|
||||
boolean setDefaultFloatArray(float[] defaultValue);
|
||||
|
||||
/**
|
||||
* Sets the entry's value if it does not exist.
|
||||
*
|
||||
* @param defaultValue the default value to set
|
||||
* @return False if the entry exists with a different type
|
||||
*/
|
||||
boolean setDefaultFloatArray(Float[] defaultValue);
|
||||
|
||||
|
||||
@@ -550,6 +568,12 @@ public interface GenericPublisher extends Publisher, Consumer<NetworkTableValue>
|
||||
*/
|
||||
boolean setDefaultDoubleArray(double[] defaultValue);
|
||||
|
||||
/**
|
||||
* Sets the entry's value if it does not exist.
|
||||
*
|
||||
* @param defaultValue the default value to set
|
||||
* @return False if the entry exists with a different type
|
||||
*/
|
||||
boolean setDefaultDoubleArray(Double[] defaultValue);
|
||||
|
||||
|
||||
|
||||
@@ -68,6 +68,11 @@ public final class NetworkTableInstance implements AutoCloseable {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the network mode value.
|
||||
*
|
||||
* @return The network mode value.
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -40,5 +40,6 @@ public abstract class EntryBase implements Subscriber, Publisher {
|
||||
return NetworkTablesJNI.getEntryLastChange(m_handle);
|
||||
}
|
||||
|
||||
/** NetworkTables handle. */
|
||||
protected int m_handle;
|
||||
}
|
||||
|
||||
@@ -7,16 +7,31 @@ package edu.wpi.first.networktables;
|
||||
/** NetworkTables log message. */
|
||||
@SuppressWarnings("MemberName")
|
||||
public final class LogMessage {
|
||||
/** Logging levels. */
|
||||
/** Critical logging level. */
|
||||
public static final int kCritical = 50;
|
||||
|
||||
/** Error logging level. */
|
||||
public static final int kError = 40;
|
||||
|
||||
/** Warning log level. */
|
||||
public static final int kWarning = 30;
|
||||
|
||||
/** Info log level. */
|
||||
public static final int kInfo = 20;
|
||||
|
||||
/** Debug log level. */
|
||||
public static final int kDebug = 10;
|
||||
|
||||
/** Debug log level 1. */
|
||||
public static final int kDebug1 = 9;
|
||||
|
||||
/** Debug log level 2. */
|
||||
public static final int kDebug2 = 8;
|
||||
|
||||
/** Debug log level 3. */
|
||||
public static final int kDebug3 = 7;
|
||||
|
||||
/** Debug log level 4. */
|
||||
public static final int kDebug4 = 6;
|
||||
|
||||
/** Log level of the message. */
|
||||
|
||||
@@ -6,6 +6,7 @@ package edu.wpi.first.networktables;
|
||||
|
||||
import edu.wpi.first.util.sendable.SendableBuilder;
|
||||
|
||||
/** Helper class for building Sendable dashboard representations for NetworkTables. */
|
||||
public interface NTSendableBuilder extends SendableBuilder {
|
||||
/**
|
||||
* Set the function that should be called to update the network table for things other than
|
||||
|
||||
@@ -12,6 +12,7 @@ package edu.wpi.first.networktables;
|
||||
*/
|
||||
@SuppressWarnings("MemberName")
|
||||
public final class NetworkTableEvent {
|
||||
/** NetworkTable event kind. */
|
||||
public enum Kind {
|
||||
/**
|
||||
* Initial listener addition. Set this to receive immediate notification of matches to other
|
||||
@@ -61,6 +62,11 @@ public final class NetworkTableEvent {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the NetworkTable event kind value.
|
||||
*
|
||||
* @return The NetworkTable event kind value.
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -39,10 +39,20 @@ public enum NetworkTableType {
|
||||
m_valueStr = valueStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the NetworkTable type value.
|
||||
*
|
||||
* @return The NetworkTable type value.
|
||||
*/
|
||||
public int getValue() {
|
||||
return m_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the NetworkTable type value as as string.
|
||||
*
|
||||
* @return The NetworkTable type value as a string.
|
||||
*/
|
||||
public String getValueStr() {
|
||||
return m_valueStr;
|
||||
}
|
||||
|
||||
@@ -153,6 +153,11 @@ public final class ProtobufTopic<T> extends Topic {
|
||||
false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the protobuf.
|
||||
*
|
||||
* @return The protobuf.
|
||||
*/
|
||||
public Protobuf<T, ?> getProto() {
|
||||
return m_proto;
|
||||
}
|
||||
|
||||
@@ -153,6 +153,11 @@ public final class StructArrayTopic<T> extends Topic {
|
||||
false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the struct.
|
||||
*
|
||||
* @return The struct.
|
||||
*/
|
||||
public Struct<T> getStruct() {
|
||||
return m_struct;
|
||||
}
|
||||
|
||||
@@ -152,6 +152,11 @@ public final class StructTopic<T> extends Topic {
|
||||
false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the struct.
|
||||
*
|
||||
* @return The struct.
|
||||
*/
|
||||
public Struct<T> getStruct() {
|
||||
return m_struct;
|
||||
}
|
||||
|
||||
@@ -336,6 +336,9 @@ public class Topic {
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
/** NetworkTables instance. */
|
||||
protected NetworkTableInstance m_inst;
|
||||
|
||||
/** NetworkTables handle. */
|
||||
protected int m_handle;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,10 @@
|
||||
|
||||
namespace nt {
|
||||
|
||||
/**
|
||||
* Helper class for building Sendable dashboard representations for
|
||||
* NetworkTables.
|
||||
*/
|
||||
class NTSendableBuilder : public wpi::SendableBuilder {
|
||||
public:
|
||||
/**
|
||||
|
||||
@@ -396,6 +396,7 @@ class Publisher {
|
||||
Publisher() = default;
|
||||
explicit Publisher(NT_Publisher handle) : m_pubHandle{handle} {}
|
||||
|
||||
/// NetworkTables handle.
|
||||
NT_Publisher m_pubHandle{0};
|
||||
};
|
||||
|
||||
|
||||
@@ -54,14 +54,21 @@ public class MulticastServiceAnnouncer implements AutoCloseable {
|
||||
m_cleanable.clean();
|
||||
}
|
||||
|
||||
/** Starts multicast service announcer. */
|
||||
public void start() {
|
||||
WPINetJNI.startMulticastServiceAnnouncer(m_handle);
|
||||
}
|
||||
|
||||
/** Stops multicast service announcer. */
|
||||
public void stop() {
|
||||
WPINetJNI.stopMulticastServiceAnnouncer(m_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if there's a multicast service announcer implementation.
|
||||
*
|
||||
* @return True if there's a multicast service announcer implementation.
|
||||
*/
|
||||
public boolean hasImplementation() {
|
||||
return WPINetJNI.getMulticastServiceAnnouncerHasImplementation(m_handle);
|
||||
}
|
||||
|
||||
@@ -32,22 +32,39 @@ public class MulticastServiceResolver implements AutoCloseable {
|
||||
m_cleanable.clean();
|
||||
}
|
||||
|
||||
/** Starts multicast service resolver. */
|
||||
public void start() {
|
||||
WPINetJNI.startMulticastServiceResolver(m_handle);
|
||||
}
|
||||
|
||||
/** Stops multicast service resolver. */
|
||||
public void stop() {
|
||||
WPINetJNI.stopMulticastServiceResolver(m_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if there's a multicast service resolver implementation.
|
||||
*
|
||||
* @return True if there's a multicast service resolver implementation.
|
||||
*/
|
||||
public boolean hasImplementation() {
|
||||
return WPINetJNI.getMulticastServiceResolverHasImplementation(m_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns event handle.
|
||||
*
|
||||
* @return Event handle.
|
||||
*/
|
||||
public int getEventHandle() {
|
||||
return WPINetJNI.getMulticastServiceResolverEventHandle(m_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns multicast service resolver data.
|
||||
*
|
||||
* @return Multicast service resolver data.
|
||||
*/
|
||||
public ServiceData[] getData() {
|
||||
return WPINetJNI.getMulticastServiceResolverData(m_handle);
|
||||
}
|
||||
|
||||
@@ -38,22 +38,47 @@ public class ServiceData {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns service data payload.
|
||||
*
|
||||
* @return Service data payload.
|
||||
*/
|
||||
public Map<String, String> getTxt() {
|
||||
return m_txt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns host name.
|
||||
*
|
||||
* @return Host name.
|
||||
*/
|
||||
public String getHostName() {
|
||||
return m_hostName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns service name.
|
||||
*
|
||||
* @return Service name.
|
||||
*/
|
||||
public String getServiceName() {
|
||||
return m_serviceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns port number.
|
||||
*
|
||||
* @return Port number.
|
||||
*/
|
||||
public int getPort() {
|
||||
return m_port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns IPv4 address.
|
||||
*
|
||||
* @return IPv4 address.
|
||||
*/
|
||||
public long getIpv4Address() {
|
||||
return m_ipv4Address;
|
||||
}
|
||||
|
||||
@@ -86,29 +86,99 @@ public class WPINetJNI {
|
||||
*/
|
||||
public static native void removePortForwarder(int port);
|
||||
|
||||
/**
|
||||
* Creates a MulticastServiceAnnouncer.
|
||||
*
|
||||
* @param serviceName service name
|
||||
* @param serviceType service type
|
||||
* @param port port
|
||||
* @param keys keys
|
||||
* @param values values
|
||||
* @return MulticastServiceAnnouncer handle.
|
||||
*/
|
||||
public static native int createMulticastServiceAnnouncer(
|
||||
String serviceName, String serviceType, int port, String[] keys, String[] values);
|
||||
|
||||
/**
|
||||
* Frees a MulticastServiceAnnouncer.
|
||||
*
|
||||
* @param handle MulticastServiceAnnouncer handle.
|
||||
*/
|
||||
public static native void freeMulticastServiceAnnouncer(int handle);
|
||||
|
||||
/**
|
||||
* Starts MulticastServiceAnnouncer.
|
||||
*
|
||||
* @param handle MulticastServiceAnnouncer handle.
|
||||
*/
|
||||
public static native void startMulticastServiceAnnouncer(int handle);
|
||||
|
||||
/**
|
||||
* Stops MulticastServiceAnnouncer.
|
||||
*
|
||||
* @param handle MulticastServiceAnnouncer handle.
|
||||
*/
|
||||
public static native void stopMulticastServiceAnnouncer(int handle);
|
||||
|
||||
/**
|
||||
* Returns true if MulticastServiceAnnouncer has an implementation.
|
||||
*
|
||||
* @param handle MulticastServiceAnnouncer handle.
|
||||
* @return True if MulticastServiceAnnouncer has an implementation.
|
||||
*/
|
||||
public static native boolean getMulticastServiceAnnouncerHasImplementation(int handle);
|
||||
|
||||
/**
|
||||
* Creates a MulticastServiceResolver.
|
||||
*
|
||||
* @param serviceType Service type.
|
||||
* @return MulticastServiceResolver handle.
|
||||
*/
|
||||
public static native int createMulticastServiceResolver(String serviceType);
|
||||
|
||||
/**
|
||||
* Frees MulticastServiceResolver.
|
||||
*
|
||||
* @param handle MulticastServiceResolver handle.
|
||||
*/
|
||||
public static native void freeMulticastServiceResolver(int handle);
|
||||
|
||||
/**
|
||||
* Starts MulticastServiceResolver.
|
||||
*
|
||||
* @param handle MulticastServiceResolver handle.
|
||||
*/
|
||||
public static native void startMulticastServiceResolver(int handle);
|
||||
|
||||
/**
|
||||
* Stops MulticastServiceResolver.
|
||||
*
|
||||
* @param handle MulticastServiceResolver handle.
|
||||
*/
|
||||
public static native void stopMulticastServiceResolver(int handle);
|
||||
|
||||
/**
|
||||
* Returns true if MulticastServiceResolver has an implementation.
|
||||
*
|
||||
* @param handle MulticastServiceResolver handle.
|
||||
* @return True if MulticastServiceResolver has an implementation.
|
||||
*/
|
||||
public static native boolean getMulticastServiceResolverHasImplementation(int handle);
|
||||
|
||||
/**
|
||||
* Returns event handle for MulticastServiceResolver.
|
||||
*
|
||||
* @param handle MulticastServiceResolver handle.
|
||||
* @return Event handle for MulticastServiceResolver.
|
||||
*/
|
||||
public static native int getMulticastServiceResolverEventHandle(int handle);
|
||||
|
||||
/**
|
||||
* Returns service data for MulticastServiceResolver.
|
||||
*
|
||||
* @param handle MulticastServiceResolver handle.
|
||||
* @return Service data for MulticastServiceResolver.
|
||||
*/
|
||||
public static native ServiceData[] getMulticastServiceResolverData(int handle);
|
||||
|
||||
/** Utility class. */
|
||||
|
||||
@@ -15,17 +15,51 @@
|
||||
namespace wpi {
|
||||
class MulticastServiceAnnouncer {
|
||||
public:
|
||||
/**
|
||||
* Creates a MulticastServiceAnnouncer.
|
||||
*
|
||||
* @param serviceName service name
|
||||
* @param serviceType service type
|
||||
* @param port port
|
||||
* @param txt txt
|
||||
*/
|
||||
MulticastServiceAnnouncer(
|
||||
std::string_view serviceName, std::string_view serviceType, int port,
|
||||
std::span<const std::pair<std::string, std::string>> txt);
|
||||
/**
|
||||
* Creates a MulticastServiceAnnouncer.
|
||||
*
|
||||
* @param serviceName service name
|
||||
* @param serviceType service type
|
||||
* @param port port
|
||||
* @param txt txt
|
||||
*/
|
||||
MulticastServiceAnnouncer(
|
||||
std::string_view serviceName, std::string_view serviceType, int port,
|
||||
std::span<const std::pair<std::string_view, std::string_view>> txt);
|
||||
/**
|
||||
* Creates a MulticastServiceAnnouncer.
|
||||
*
|
||||
* @param serviceName service name
|
||||
* @param serviceType service type
|
||||
* @param port port
|
||||
*/
|
||||
MulticastServiceAnnouncer(std::string_view serviceName,
|
||||
std::string_view serviceType, int port);
|
||||
~MulticastServiceAnnouncer() noexcept;
|
||||
/**
|
||||
* Starts multicast service announcer.
|
||||
*/
|
||||
void Start();
|
||||
/**
|
||||
* Stops multicast service announcer.
|
||||
*/
|
||||
void Stop();
|
||||
/**
|
||||
* Returns true if there's a multicast service announcer implementation.
|
||||
*
|
||||
* @return True if there's a multicast service announcer implementation.
|
||||
*/
|
||||
bool HasImplementation() const;
|
||||
struct Impl;
|
||||
|
||||
|
||||
@@ -21,15 +21,36 @@ class MulticastServiceResolver {
|
||||
explicit MulticastServiceResolver(std::string_view serviceType);
|
||||
~MulticastServiceResolver() noexcept;
|
||||
struct ServiceData {
|
||||
/// IPv4 address.
|
||||
unsigned int ipv4Address;
|
||||
/// Port number.
|
||||
int port;
|
||||
/// Service name.
|
||||
std::string serviceName;
|
||||
/// Host name.
|
||||
std::string hostName;
|
||||
/// Service data payload.
|
||||
std::vector<std::pair<std::string, std::string>> txt;
|
||||
};
|
||||
/**
|
||||
* Starts multicast service resolver.
|
||||
*/
|
||||
void Start();
|
||||
/**
|
||||
* Stops multicast service resolver.
|
||||
*/
|
||||
void Stop();
|
||||
/**
|
||||
* Returns event handle.
|
||||
*
|
||||
* @return Event handle.
|
||||
*/
|
||||
WPI_EventHandle GetEventHandle() const { return event.GetHandle(); }
|
||||
/**
|
||||
* Returns multicast service resolver data.
|
||||
*
|
||||
* @return Multicast service resolver data.
|
||||
*/
|
||||
std::vector<ServiceData> GetData() {
|
||||
std::scoped_lock lock{mutex};
|
||||
event.Reset();
|
||||
@@ -40,6 +61,11 @@ class MulticastServiceResolver {
|
||||
queue.swap(ret);
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
* Returns true if there's a multicast service resolver implementation.
|
||||
*
|
||||
* @return True if there's a multicast service resolver implementation.
|
||||
*/
|
||||
bool HasImplementation() const;
|
||||
struct Impl;
|
||||
|
||||
@@ -55,6 +81,9 @@ class MulticastServiceResolver {
|
||||
std::unique_ptr<Impl> pImpl;
|
||||
};
|
||||
} // namespace wpi
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
@@ -23,6 +23,17 @@ public class Current extends Unit<Current> {
|
||||
super(Current.class, toBaseConverter, fromBaseConverter, name, symbol);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a unit of power equivalent to this unit of electrical current multiplied by another
|
||||
* unit of voltage. For example, {@code Amps.times(Volts)} will return a unit of power equivalent
|
||||
* to one Watt; {@code Amps.times(Millivolts)} will return a unit of power equivalent to a
|
||||
* milliwatt, and so on.
|
||||
*
|
||||
* @param voltage the voltage unit to multiply by
|
||||
* @param name the name of the resulting unit of power
|
||||
* @param symbol the symbol used to represent the unit of power
|
||||
* @return the power unit
|
||||
*/
|
||||
public Power times(Unit<Voltage> voltage, String name, String symbol) {
|
||||
return new Power(this.toBaseUnits(1) * voltage.toBaseUnits(1), name, symbol);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public class Dimensionless extends Unit<Dimensionless> {
|
||||
* @param name the name of the unit
|
||||
* @param symbol the symbol of the unit
|
||||
*/
|
||||
protected Dimensionless(double baseUnitEquivalent, String name, String symbol) {
|
||||
Dimensionless(double baseUnitEquivalent, String name, String symbol) {
|
||||
super(Dimensionless.class, baseUnitEquivalent, name, symbol);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,12 +14,12 @@ package edu.wpi.first.units;
|
||||
* {@link Units} class.
|
||||
*/
|
||||
public class Energy extends Unit<Energy> {
|
||||
protected Energy(
|
||||
Energy(
|
||||
UnaryFunction toBaseConverter, UnaryFunction fromBaseConverter, String name, String symbol) {
|
||||
super(Energy.class, toBaseConverter, fromBaseConverter, name, symbol);
|
||||
}
|
||||
|
||||
protected Energy(double baseUnitEquivalent, String name, String symbol) {
|
||||
Energy(double baseUnitEquivalent, String name, String symbol) {
|
||||
super(Energy.class, baseUnitEquivalent, name, symbol);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,9 @@ import edu.wpi.first.units.collections.LongToObjectHashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* A combinatory unit type that is equivalent to the product of two other others.
|
||||
* A combinatory unit type that is equivalent to the product of two other others. Note that
|
||||
* algebraic reduction is not possible in Java's generic type system, so {@code Mult<A, B>} is not
|
||||
* type-compatible with {@code Mult<B, A>}!
|
||||
*
|
||||
* @param <A> the type of the first unit in the result
|
||||
* @param <B> the type of the second unit in the result
|
||||
@@ -20,6 +22,14 @@ public class Mult<A extends Unit<A>, B extends Unit<B>> extends Unit<Mult<A, B>>
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final LongToObjectHashMap<Mult> cache = new LongToObjectHashMap<>();
|
||||
|
||||
/**
|
||||
* Creates a new product unit. Consider using {@link #combine} instead of manually calling this
|
||||
* constructor.
|
||||
*
|
||||
* @param baseType the base type representing the unit product
|
||||
* @param a the first unit of the product
|
||||
* @param b the second unit of the product
|
||||
*/
|
||||
protected Mult(Class<? extends Mult<A, B>> baseType, A a, B b) {
|
||||
super(
|
||||
baseType,
|
||||
@@ -58,10 +68,20 @@ public class Mult<A extends Unit<A>, B extends Unit<B>> extends Unit<Mult<A, B>>
|
||||
return mult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the first unit of the product.
|
||||
*
|
||||
* @return the first unit
|
||||
*/
|
||||
public A unitA() {
|
||||
return m_unitA;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the second unit of the product.
|
||||
*
|
||||
* @return the second unit
|
||||
*/
|
||||
public B unitB() {
|
||||
return m_unitB;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@ import java.util.Objects;
|
||||
* Generic combinatory unit type that represents the proportion of one unit to another, such as
|
||||
* Meters per Second or Radians per Celsius.
|
||||
*
|
||||
* <p>Note: {@link Velocity} is used to represent the velocity dimension.
|
||||
* <p>Note: {@link Velocity} is used to represent the velocity dimension, rather than {@code
|
||||
* Per<Distance, Time>}.
|
||||
*
|
||||
* @param <N> the type of the numerator unit
|
||||
* @param <D> the type of the denominator unit
|
||||
@@ -27,6 +28,14 @@ public class Per<N extends Unit<N>, D extends Unit<D>> extends Unit<Per<N, D>> {
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final LongToObjectHashMap<Per> cache = new LongToObjectHashMap<>();
|
||||
|
||||
/**
|
||||
* Creates a new proportional unit derived from the ratio of one unit to another. Consider using
|
||||
* {@link #combine} instead of manually calling this constructor.
|
||||
*
|
||||
* @param baseType the base type representing the unit ratio
|
||||
* @param numerator the numerator unit
|
||||
* @param denominator the denominator unit
|
||||
*/
|
||||
protected Per(Class<Per<N, D>> baseType, N numerator, D denominator) {
|
||||
super(
|
||||
baseType,
|
||||
@@ -70,10 +79,20 @@ public class Per<N extends Unit<N>, D extends Unit<D>> extends Unit<Per<N, D>> {
|
||||
return newUnit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the numerator unit. For a {@code Per<A, B>}, this will return the {@code A} unit.
|
||||
*
|
||||
* @return the numerator unit
|
||||
*/
|
||||
public N numerator() {
|
||||
return m_numerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the denominator unit. For a {@code Per<A, B>}, this will return the {@code B} unit.
|
||||
*
|
||||
* @return the denominator unit
|
||||
*/
|
||||
public D denominator() {
|
||||
return m_denominator;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,13 @@ package edu.wpi.first.units;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* A function that accepts a single {@code double} and returns a {@code double} result. This is used
|
||||
* to represent arbitrary mapping functions for converting units to and from a base unit
|
||||
* representation. Temperature units, in particular, typically have an offset from a value in Kelvin
|
||||
* and may have a multiplication factor added in, which means that units cannot always be
|
||||
* represented as simple ratios of their base units.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface UnaryFunction {
|
||||
/**
|
||||
|
||||
@@ -20,6 +20,12 @@ public final class UnitBuilder<U extends Unit<U>> {
|
||||
private String m_name;
|
||||
private String m_symbol;
|
||||
|
||||
/**
|
||||
* Creates a new unit builder object, building off of a base unit. The base unit does not have to
|
||||
* be <i>the</i> base unit of its unit system; furlongs work just as well here as meters.
|
||||
*
|
||||
* @param base the unit to base the new unit off of
|
||||
*/
|
||||
public UnitBuilder(U base) {
|
||||
this.m_base = Objects.requireNonNull(base, "Base unit cannot be null");
|
||||
}
|
||||
|
||||
@@ -14,91 +14,247 @@ public final class Units {
|
||||
|
||||
// Pseudo-classes describing the more common units of measure.
|
||||
|
||||
/**
|
||||
* Used as an internal placeholder value when a specific unit type cannot be determined. Do not
|
||||
* use this directly.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static final Unit AnonymousBaseUnit = new Dimensionless(1, "<?>", "<?>");
|
||||
|
||||
// Distance
|
||||
/** The base unit of distance. */
|
||||
public static final Distance Meters = BaseUnits.Distance;
|
||||
|
||||
/** 1/1000 of a {@link #Meters Meter}. */
|
||||
public static final Distance Millimeters = Milli(Meters, "Millimeter", "mm");
|
||||
|
||||
/** 1/100 of a {@link #Meters Meter}. */
|
||||
public static final Distance Centimeters =
|
||||
derive(Meters).splitInto(100).named("Centimeter").symbol("cm").make();
|
||||
|
||||
/** 25.4/1000 of a {@link #Meters Meter} and 1/12 of a {@link #Feet Foot}. */
|
||||
public static final Distance Inches =
|
||||
derive(Millimeters).aggregate(25.4).named("Inch").symbol("in").make();
|
||||
|
||||
/** 304.8/1000 of a {@link #Meters Meter}, or 12 {@link #Inches}. */
|
||||
public static final Distance Feet =
|
||||
derive(Inches).aggregate(12).named("Foot").symbol("ft").make();
|
||||
|
||||
// Time
|
||||
/** The base unit of time. */
|
||||
public static final Time Seconds = BaseUnits.Time;
|
||||
|
||||
/** Alias for {@link #Seconds} to make combined unit definitions read more smoothly. */
|
||||
public static final Time Second = Seconds; // singularized alias
|
||||
|
||||
/** 1/1000 of a {@link #Seconds Second}. */
|
||||
public static final Time Milliseconds = Milli(Seconds);
|
||||
|
||||
/** Alias for {@link #Milliseconds} to make combined unit definitions read more smoothly. */
|
||||
public static final Time Millisecond = Milliseconds; // singularized alias
|
||||
|
||||
/** 1/1,000,000 of a {@link #Seconds Second}. */
|
||||
public static final Time Microseconds = Micro(Seconds);
|
||||
|
||||
/** Alias for {@link #Microseconds} to make combined unit definitions read more smoothly. */
|
||||
public static final Time Microsecond = Microseconds; // singularized alias
|
||||
|
||||
/** 60 {@link #Seconds}. */
|
||||
public static final Time Minutes =
|
||||
derive(Seconds).aggregate(60).named("Minute").symbol("min").make();
|
||||
|
||||
/** Alias for {@link #Minutes} to make combined unit definitions read more smoothly. */
|
||||
public static final Time Minute = Minutes; // singularized alias
|
||||
|
||||
// Angle
|
||||
/**
|
||||
* The base SI unit of angle, represented by the distance that the radius of a unit circle can
|
||||
* wrap around its circumference.
|
||||
*/
|
||||
public static final Angle Radians = BaseUnits.Angle;
|
||||
|
||||
/**
|
||||
* A single turn of an object around an external axis. Numerically equivalent to {@link
|
||||
* #Rotations}, but may be semantically more expressive in certain scenarios.
|
||||
*/
|
||||
public static final Angle Revolutions = new Angle(2 * Math.PI, "Revolution", "R");
|
||||
|
||||
/**
|
||||
* A single turn of an object around an internal axis. Numerically equivalent to {@link
|
||||
* #Revolutions}, but may be semantically more expressive in certain scenarios.
|
||||
*/
|
||||
public static final Angle Rotations = new Angle(2 * Math.PI, "Rotation", "R"); // alias revolution
|
||||
|
||||
/** 1/360 of a turn around a circle, or 1/57.3 {@link #Radians}. */
|
||||
public static final Angle Degrees =
|
||||
derive(Revolutions).splitInto(360).named("Degree").symbol("°").make();
|
||||
|
||||
// Velocity
|
||||
/**
|
||||
* The standard SI unit of linear velocity, equivalent to travelling at a rate of one {@link
|
||||
* #Meters Meter} per {@link #Second}.
|
||||
*/
|
||||
public static final Velocity<Distance> MetersPerSecond = Meters.per(Second);
|
||||
|
||||
/**
|
||||
* A unit of linear velocity equivalent to travelling at a rate one {@link #Feet Foot} per {@link
|
||||
* #Second}.
|
||||
*/
|
||||
public static final Velocity<Distance> FeetPerSecond = Feet.per(Second);
|
||||
|
||||
/**
|
||||
* A unit of linear velocity equivalent to travelling at a rate of one {@link #Inches Inch} per
|
||||
* {@link #Second}.
|
||||
*/
|
||||
public static final Velocity<Distance> InchesPerSecond = Inches.per(Second);
|
||||
|
||||
/**
|
||||
* A unit of angular velocity equivalent to spinning at a rate of one {@link #Revolutions
|
||||
* Revolution} per {@link #Second}.
|
||||
*/
|
||||
public static final Velocity<Angle> RevolutionsPerSecond = Revolutions.per(Second);
|
||||
|
||||
/**
|
||||
* A unit of angular velocity equivalent to spinning at a rate of one {@link #Rotations Rotation}
|
||||
* per {@link #Second}.
|
||||
*/
|
||||
public static final Velocity<Angle> RotationsPerSecond = Rotations.per(Second);
|
||||
|
||||
/**
|
||||
* A unit of angular velocity equivalent to spinning at a rate of one {@link #Rotations Rotation}
|
||||
* per {@link #Minute}. Motor spec sheets often list maximum speeds in terms of RPM.
|
||||
*/
|
||||
public static final Velocity<Angle> RPM = Rotations.per(Minute);
|
||||
|
||||
/**
|
||||
* The standard SI unit of angular velocity, equivalent to spinning at a rate of one {@link
|
||||
* #Radians Radian} per {@link #Second}.
|
||||
*/
|
||||
public static final Velocity<Angle> RadiansPerSecond = Radians.per(Second);
|
||||
|
||||
/**
|
||||
* A unit of angular velocity equivalent to spinning at a rate of one {@link #Degrees Degree} per
|
||||
* {@link #Second}.
|
||||
*/
|
||||
public static final Velocity<Angle> DegreesPerSecond = Degrees.per(Second);
|
||||
|
||||
// Acceleration
|
||||
/**
|
||||
* The standard SI unit of linear acceleration, equivalent to accelerating at a rate of one {@link
|
||||
* #Meters Meter} per {@link #Second} every second.
|
||||
*/
|
||||
public static final Velocity<Velocity<Distance>> MetersPerSecondPerSecond =
|
||||
MetersPerSecond.per(Second);
|
||||
|
||||
/**
|
||||
* A unit of acceleration equivalent to the pull of gravity on an object at sea level on Earth.
|
||||
*/
|
||||
public static final Velocity<Velocity<Distance>> Gs =
|
||||
derive(MetersPerSecondPerSecond).aggregate(9.80665).named("G").symbol("G").make();
|
||||
|
||||
// Mass
|
||||
/** The base SI unit of mass. */
|
||||
public static final Mass Kilograms = BaseUnits.Mass;
|
||||
|
||||
/** 1/1000 of a {@link #Kilograms Kilogram}. */
|
||||
public static final Mass Grams = Milli(Kilograms, "Gram", "g");
|
||||
|
||||
/**
|
||||
* A unit of mass equivalent to approximately 453 {@link #Grams}. This is <i>not</i> equivalent to
|
||||
* pounds-force, which is the amount of force required to accelerate an object with one pound of
|
||||
* mass at a rate of one {@link #Gs G}.
|
||||
*/
|
||||
public static final Mass Pounds =
|
||||
derive(Grams).aggregate(453.592).named("Pound").symbol("lb.").make();
|
||||
|
||||
/** 1/16 of a {@link #Pounds Pound}. */
|
||||
public static final Mass Ounces =
|
||||
derive(Pounds).splitInto(16).named("Ounce").symbol("oz.").make();
|
||||
|
||||
// Unitless
|
||||
/** A dimensionless unit that performs no scaling whatsoever. */
|
||||
public static final Dimensionless Value = BaseUnits.Value;
|
||||
|
||||
/**
|
||||
* A dimensionless unit equal to to 1/100th of a {@link #Value}. A measurement of {@code
|
||||
* Percent.of(42)} would be equivalent to {@code Value.of(0.42)}.
|
||||
*/
|
||||
public static final Dimensionless Percent =
|
||||
derive(Value).splitInto(100).named("Percent").symbol("%").make();
|
||||
|
||||
// Voltage
|
||||
/** The base unit of electric potential. */
|
||||
public static final Voltage Volts = BaseUnits.Voltage;
|
||||
|
||||
/**
|
||||
* 1/1000 of a {@link #Volts Volt}. Useful when dealing with low-voltage applications like LED
|
||||
* drivers or low-power circuits.
|
||||
*/
|
||||
public static final Voltage Millivolts = Milli(Volts);
|
||||
|
||||
// Current
|
||||
/** The base unit of electrical current. */
|
||||
public static final Current Amps = BaseUnits.Current;
|
||||
|
||||
/**
|
||||
* A unit equal to 1/1000 of an {@link #Amps Amp}. Useful when dealing with low-current
|
||||
* applications like LED drivers or low-power circuits.
|
||||
*/
|
||||
public static final Current Milliamps = Milli(Amps);
|
||||
|
||||
// Energy
|
||||
/** The base unit of energy. */
|
||||
public static final Energy Joules = BaseUnits.Energy;
|
||||
|
||||
/**
|
||||
* A unit equal to 1/1000 of a {@link #Joules Joule}. Useful when dealing with lower-power
|
||||
* applications.
|
||||
*/
|
||||
public static final Energy Millijoules = Milli(Joules);
|
||||
|
||||
/**
|
||||
* A unit equal to 1,000 {@link #Joules}. Useful when dealing with higher-level robot energy
|
||||
* usage.
|
||||
*/
|
||||
public static final Energy Kilojoules = Kilo(Joules);
|
||||
|
||||
// Power
|
||||
/** The base unit of power. Equivalent to one {@link #Joules Joule} per {@link #Second}. */
|
||||
public static final Power Watts = BaseUnits.Power;
|
||||
|
||||
/**
|
||||
* A unit equal to 1/1000 of a {@link #Watts Watt}. Useful when dealing with lower-power
|
||||
* applications.
|
||||
*/
|
||||
public static final Power Milliwatts = Milli(Watts);
|
||||
|
||||
/**
|
||||
* A unit equal to 745.7 {@link #Watts}. May be useful when dealing with high-power gearboxes and
|
||||
* motors.
|
||||
*/
|
||||
public static final Power Horsepower =
|
||||
derive(Watts).aggregate(745.7).named("Horsepower").symbol("HP").make();
|
||||
|
||||
// Temperature
|
||||
/**
|
||||
* The base unit of temperature, where a value of 0 corresponds with absolutely zero energy in the
|
||||
* measured system. Not particularly useful for robots unless you're cooling motors with liquid
|
||||
* helium.
|
||||
*/
|
||||
public static final Temperature Kelvin = BaseUnits.Temperature;
|
||||
|
||||
/**
|
||||
* The base SI unit of temperature, where a value of 0 roughly corresponds to the freezing point
|
||||
* of water and a value of 100 corresponds to the boiling point. Electronics tend to exhibit
|
||||
* degraded performance or damage above 90 degrees Celsius.
|
||||
*/
|
||||
public static final Temperature Celsius =
|
||||
derive(Kelvin).offset(+273.15).named("Celsius").symbol("°C").make();
|
||||
|
||||
/**
|
||||
* The base imperial (American) unit of temperature, where a value of 32 roughly corresponds to
|
||||
* the freezing point of water and a value of 212 corresponds to the boiling point.
|
||||
*/
|
||||
public static final Temperature Fahrenheit =
|
||||
derive(Celsius)
|
||||
.mappingInputRange(0, 100)
|
||||
@@ -109,13 +265,31 @@ public final class Units {
|
||||
|
||||
// Standard feedforward units for kV and kA.
|
||||
// kS and kG are just volts, which is already defined earlier
|
||||
/**
|
||||
* A standard unit for measuring linear mechanisms' feedforward voltages based on a model of the
|
||||
* system and a desired commanded linear velocity.
|
||||
*/
|
||||
public static final Per<Voltage, Velocity<Distance>> VoltsPerMeterPerSecond =
|
||||
Volts.per(MetersPerSecond);
|
||||
|
||||
/**
|
||||
* A standard unit for measuring linear mechanisms' feedforward voltages based on a model of the
|
||||
* system and a desired commanded linear acceleration.
|
||||
*/
|
||||
public static final Per<Voltage, Velocity<Velocity<Distance>>> VoltsPerMeterPerSecondSquared =
|
||||
Volts.per(MetersPerSecondPerSecond);
|
||||
|
||||
/**
|
||||
* A standard unit for measuring angular mechanisms' feedforward voltages based on a model of the
|
||||
* system and a desired commanded angular velocity.
|
||||
*/
|
||||
public static final Per<Voltage, Velocity<Angle>> VoltsPerRadianPerSecond =
|
||||
Volts.per(RadiansPerSecond);
|
||||
|
||||
/**
|
||||
* A standard unit for measuring angular mechanisms' feedforward voltages based on a model of the
|
||||
* system and a desired commanded angular acceleration.
|
||||
*/
|
||||
public static final Per<Voltage, Velocity<Velocity<Angle>>> VoltsPerRadianPerSecondSquared =
|
||||
Volts.per(RadiansPerSecond.per(Second));
|
||||
|
||||
@@ -201,11 +375,26 @@ public final class Units {
|
||||
baseUnit, "Kilo" + baseUnit.name().toLowerCase(Locale.ROOT), "K" + baseUnit.symbol());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new unit builder object based on a given input unit. The builder can be used to
|
||||
* fluently describe a new unit in terms of its relation to the base unit.
|
||||
*
|
||||
* @param unit the base unit from which to derive a new unit
|
||||
* @param <U> the dimension of the unit to derive
|
||||
* @return a builder object
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <U extends Unit<U>> UnitBuilder<U> derive(Unit<U> unit) {
|
||||
return new UnitBuilder<>((U) unit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an anonymous unit for use when a specific unit type is not known. Do not use this
|
||||
* directly.
|
||||
*
|
||||
* @param <U> the dimension of the desired anonymous unit
|
||||
* @return the anonymous unit
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <U extends Unit<U>> U anonymous() {
|
||||
return (U) AnonymousBaseUnit;
|
||||
|
||||
@@ -23,6 +23,17 @@ public class Voltage extends Unit<Voltage> {
|
||||
super(Voltage.class, toBaseConverter, fromBaseConverter, name, symbol);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a unit of power equivalent to this unit of voltage multiplied by another unit of
|
||||
* electrical current. For example, {@code Volts.times(Amps)} will return a unit of power
|
||||
* equivalent to one Watt; {@code Volts.times(Milliams)} will return a unit of power equivalent to
|
||||
* a milliwatt, and so on.
|
||||
*
|
||||
* @param current the current unit to multiply by
|
||||
* @param name the name of the resulting unit of power
|
||||
* @param symbol the symbol used to represent the unit of power
|
||||
* @return the power unit
|
||||
*/
|
||||
public Power times(Unit<Current> current, String name, String symbol) {
|
||||
return new Power(toBaseUnits(1) * current.toBaseUnits(1), name, symbol);
|
||||
}
|
||||
|
||||
@@ -225,8 +225,19 @@ public class LongToObjectHashMap<V> {
|
||||
return List.copyOf(values); // return a readonly copy
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for map iterator function.
|
||||
*
|
||||
* @param <V> Value type.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface IteratorFunction<V> {
|
||||
/**
|
||||
* Accepts a key-value pair from the map.
|
||||
*
|
||||
* @param key The key.
|
||||
* @param value The value.
|
||||
*/
|
||||
void accept(long key, V value);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user