001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.hal.simulation;
006
007import edu.wpi.first.hal.HALValue;
008import edu.wpi.first.hal.JNIWrapper;
009
010/** JNI for sim device data. */
011public class SimDeviceDataJNI extends JNIWrapper {
012  public static native void setSimDeviceEnabled(String prefix, boolean enabled);
013
014  public static native boolean isSimDeviceEnabled(String name);
015
016  public static native int registerSimDeviceCreatedCallback(
017      String prefix, SimDeviceCallback callback, boolean initialNotify);
018
019  public static native void cancelSimDeviceCreatedCallback(int uid);
020
021  public static native int registerSimDeviceFreedCallback(
022      String prefix, SimDeviceCallback callback, boolean initialNotify);
023
024  public static native void cancelSimDeviceFreedCallback(int uid);
025
026  public static native int getSimDeviceHandle(String name);
027
028  public static native String getSimDeviceName(int handle);
029
030  public static native int getSimValueDeviceHandle(int handle);
031
032  @SuppressWarnings("MemberName")
033  public static class SimDeviceInfo {
034    public String name;
035    public int handle;
036
037    /**
038     * SimDeviceInfo constructor.
039     *
040     * @param name SimDevice name.
041     * @param handle SimDevice handle.
042     */
043    public SimDeviceInfo(String name, int handle) {
044      this.name = name;
045      this.handle = handle;
046    }
047  }
048
049  public static native SimDeviceInfo[] enumerateSimDevices(String prefix);
050
051  public static native int registerSimValueCreatedCallback(
052      int device, SimValueCallback callback, boolean initialNotify);
053
054  public static native void cancelSimValueCreatedCallback(int uid);
055
056  public static native int registerSimValueChangedCallback(
057      int handle, SimValueCallback callback, boolean initialNotify);
058
059  public static native void cancelSimValueChangedCallback(int uid);
060
061  /**
062   * Register a callback for SimDeviceJNI.resetSimValue(). The callback is called with the old
063   * value.
064   *
065   * @param handle simulated value handle
066   * @param callback callback
067   * @param initialNotify ignored (present for consistency)
068   * @return TODO
069   */
070  public static native int registerSimValueResetCallback(
071      int handle, SimValueCallback callback, boolean initialNotify);
072
073  public static native void cancelSimValueResetCallback(int uid);
074
075  public static native int getSimValueHandle(int device, String name);
076
077  @SuppressWarnings("MemberName")
078  public static class SimValueInfo {
079    public String name;
080    public int handle;
081    public int direction;
082    public HALValue value;
083
084    /**
085     * SimValueInfo constructor.
086     *
087     * @param name SimValue name.
088     * @param handle SimValue handle.
089     * @param direction SimValue direction.
090     * @param type SimValue type.
091     * @param value1 Value 1.
092     * @param value2 Value 2.
093     */
094    public SimValueInfo(
095        String name, int handle, int direction, int type, long value1, double value2) {
096      this.name = name;
097      this.handle = handle;
098      this.direction = direction;
099      this.value = HALValue.fromNative(type, value1, value2);
100    }
101  }
102
103  public static native SimValueInfo[] enumerateSimValues(int device);
104
105  public static native String[] getSimValueEnumOptions(int handle);
106
107  public static native double[] getSimValueEnumDoubleValues(int handle);
108
109  public static native void resetSimDeviceData();
110
111  /** Utility class. */
112  private SimDeviceDataJNI() {}
113}