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  /** A pointer parameter to a method is NULL. */
014  public static final int NULL_PARAMETER = -1005;
015
016  /** Analog module sample rate is too high. */
017  public static final int SAMPLE_RATE_TOO_HIGH = 1001;
018
019  /** Voltage to convert to raw value is out of range [0; 5]. */
020  public static final int VOLTAGE_OUT_OF_RANGE = 1002;
021
022  /** Digital module loop timing is not the expected value. */
023  public static final int LOOP_TIMING_ERROR = 1004;
024
025  /** The operation cannot be completed. */
026  public static final int INCOMPATIBLE_STATE = 1015;
027
028  /** Attempted to read AnalogTrigger pulse output. */
029  public static final int ANALOG_TRIGGER_PULSE_OUTPUT_ERROR = -1011;
030
031  /** No available resources to allocate. */
032  public static final int NO_AVAILABLE_RESOURCES = -104;
033
034  /** A parameter is out of range. */
035  public static final int PARAMETER_OUT_OF_RANGE = -1028;
036
037  /** roboRIO 1.0. */
038  public static final int RUNTIME_ROBORIO = 0;
039
040  /** roboRIO 2.0. */
041  public static final int RUNTIME_ROBORIO2 = 1;
042
043  /** Simulation runtime. */
044  public static final int RUNTIME_SIMULATION = 2;
045
046  /** SystemCore. */
047  public static final int RUNTIME_SYSTEMCORE = 3;
048
049  /**
050   * Returns the FPGA Version number.
051   *
052   * <p>For now, expect this to be competition year.
053   *
054   * @return FPGA Version number.
055   * @see "HAL_GetFPGAVersion"
056   */
057  public static native short getFPGAVersion();
058
059  /**
060   * Returns the FPGA Revision number.
061   *
062   * <p>The format of the revision is 3 numbers. The 12 most significant bits are the Major
063   * Revision. the next 8 bits are the Minor Revision. The 12 least significant bits are the Build
064   * Number.
065   *
066   * @return FPGA Revision number.
067   * @see "HAL_GetFPGARevision"
068   */
069  public static native int getFPGARevision();
070
071  /**
072   * Returns the roboRIO serial number.
073   *
074   * @return The roboRIO serial number.
075   * @see "HAL_GetSerialNumber"
076   */
077  public static native String getSerialNumber();
078
079  /**
080   * Returns the comments from the roboRIO web interface.
081   *
082   * @return The comments string.
083   * @see "HAL_GetComments"
084   */
085  public static native String getComments();
086
087  /**
088   * Returns the team number configured for the robot controller.
089   *
090   * @return team number, or 0 if not found.
091   * @see "HAL_GetTeamNumber"
092   */
093  public static native int getTeamNumber();
094
095  /**
096   * Reads the microsecond-resolution timer on the FPGA.
097   *
098   * @return The current time in microseconds according to the FPGA (since FPGA reset).
099   */
100  public static native long getFPGATime();
101
102  /**
103   * Returns the runtime type of the HAL.
104   *
105   * @return HAL Runtime Type
106   * @see RUNTIME_ROBORIO
107   * @see RUNTIME_ROBORIO2
108   * @see RUNTIME_SIMULATION
109   * @see "HAL_GetRuntimeType"
110   */
111  public static native int getHALRuntimeType();
112
113  /**
114   * Gets the error message for a specific status code.
115   *
116   * @param code the status code
117   * @return the error message for the code. This does not need to be freed.
118   * @see "HAL_GetErrorMessage"
119   */
120  public static native String getHALErrorMessage(int code);
121
122  /**
123   * Get the last HAL error code.
124   *
125   * @return error code
126   */
127  public static native int getHALErrno();
128
129  /**
130   * Returns the textual description of the system error code.
131   *
132   * @param errno errno to get description of
133   * @return description of errno
134   * @see "std:strerror"
135   */
136  public static native String getHALstrerror(int errno);
137
138  /**
139   * Gets the error message for the last HAL error.
140   *
141   * @return the error message for the code.
142   */
143  public static String getHALstrerror() {
144    return getHALstrerror(getHALErrno());
145  }
146
147  private HALUtil() {}
148}