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;
006
007/**
008 * Hardware Abstraction Layer (HAL) Utilities JNI Functions.
009 *
010 * @see "hal/HALBase.h"
011 */
012public final class HALUtil extends JNIWrapper {
013  public static final int NULL_PARAMETER = -1005;
014  public static final int SAMPLE_RATE_TOO_HIGH = 1001;
015  public static final int VOLTAGE_OUT_OF_RANGE = 1002;
016  public static final int LOOP_TIMING_ERROR = 1004;
017  public static final int INCOMPATIBLE_STATE = 1015;
018  public static final int ANALOG_TRIGGER_PULSE_OUTPUT_ERROR = -1011;
019  public static final int NO_AVAILABLE_RESOURCES = -104;
020  public static final int PARAMETER_OUT_OF_RANGE = -1028;
021
022  public static final int RUNTIME_ROBORIO = 0;
023  public static final int RUNTIME_ROBORIO2 = 1;
024  public static final int RUNTIME_SIMULATION = 2;
025
026  /**
027   * Returns the FPGA Version number.
028   *
029   * <p>For now, expect this to be competition year.
030   *
031   * @return FPGA Version number.
032   * @see "HAL_GetFPGAVersion"
033   */
034  public static native short getFPGAVersion();
035
036  /**
037   * Returns the FPGA Revision number.
038   *
039   * <p>The format of the revision is 3 numbers. The 12 most significant bits are the Major
040   * Revision. the next 8 bits are the Minor Revision. The 12 least significant bits are the Build
041   * Number.
042   *
043   * @return FPGA Revision number.
044   * @see "HAL_GetFPGARevision"
045   */
046  public static native int getFPGARevision();
047
048  /**
049   * Returns the roboRIO serial number.
050   *
051   * @return The roboRIO serial number.
052   * @see "HAL_GetSerialNumber"
053   */
054  public static native String getSerialNumber();
055
056  /**
057   * Returns the comments from the roboRIO web interface.
058   *
059   * @return The comments string.
060   * @see "HAL_GetComments"
061   */
062  public static native String getComments();
063
064  /**
065   * Returns the team number configured for the robot controller.
066   *
067   * @return team number, or 0 if not found.
068   * @see "HAL_GetTeamNumber"
069   */
070  public static native int getTeamNumber();
071
072  /**
073   * Reads the microsecond-resolution timer on the FPGA.
074   *
075   * @return The current time in microseconds according to the FPGA (since FPGA reset).
076   */
077  public static native long getFPGATime();
078
079  /**
080   * Returns the runtime type of the HAL.
081   *
082   * @return HAL Runtime Type
083   * @see RUNTIME_ROBORIO
084   * @see RUNTIME_ROBORIO2
085   * @see RUNTIME_SIMULATION
086   * @see "HAL_GetRuntimeType"
087   */
088  public static native int getHALRuntimeType();
089
090  /**
091   * Gets the state of the "USER" button on the roboRIO.
092   *
093   * @return true if the button is currently pressed down
094   * @see "HAL_GetFPGAButton"
095   */
096  public static native boolean getFPGAButton();
097
098  /**
099   * Gets the error message for a specific status code.
100   *
101   * @param code the status code
102   * @return the error message for the code. This does not need to be freed.
103   * @see "HAL_GetErrorMessage"
104   */
105  public static native String getHALErrorMessage(int code);
106
107  /**
108   * Get the last HAL error code.
109   *
110   * @return error code
111   */
112  public static native int getHALErrno();
113
114  /**
115   * Returns the textual description of the system error code.
116   *
117   * @param errno errno to get description of
118   * @return description of errno
119   * @see "std:strerror"
120   */
121  public static native String getHALstrerror(int errno);
122
123  /**
124   * Gets the error message for the last HAL error.
125   *
126   * @return the error message for the code.
127   */
128  public static String getHALstrerror() {
129    return getHALstrerror(getHALErrno());
130  }
131
132  private HALUtil() {}
133}