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 * Reads the microsecond-resolution timer on the FPGA. 066 * 067 * @return The current time in microseconds according to the FPGA (since FPGA reset). 068 */ 069 public static native long getFPGATime(); 070 071 /** 072 * Returns the runtime type of the HAL. 073 * 074 * @return HAL Runtime Type 075 * @see RUNTIME_ROBORIO 076 * @see RUNTIME_ROBORIO2 077 * @see RUNTIME_SIMULATION 078 * @see "HAL_GetRuntimeType" 079 */ 080 public static native int getHALRuntimeType(); 081 082 /** 083 * Gets the state of the "USER" button on the roboRIO. 084 * 085 * @return true if the button is currently pressed down 086 * @see "HAL_GetFPGAButton" 087 */ 088 public static native boolean getFPGAButton(); 089 090 /** 091 * Gets the error message for a specific status code. 092 * 093 * @param code the status code 094 * @return the error message for the code. This does not need to be freed. 095 * @see "HAL_GetErrorMessage" 096 */ 097 public static native String getHALErrorMessage(int code); 098 099 /** 100 * Get the last HAL error code. 101 * 102 * @return error code 103 */ 104 public static native int getHALErrno(); 105 106 /** 107 * Returns the textual description of the system error code. 108 * 109 * @param errno errno to get description of 110 * @return description of errno 111 * @see "std:strerror" 112 */ 113 public static native String getHALstrerror(int errno); 114 115 /** 116 * Gets the error message for the last HAL error. 117 * 118 * @return the error message for the code. 119 */ 120 public static String getHALstrerror() { 121 return getHALstrerror(getHALErrno()); 122 } 123 124 private HALUtil() {} 125}