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 roboRIO serial number. 051 * 052 * @return The roboRIO serial number. 053 * @see "HAL_GetSerialNumber" 054 */ 055 public static native String getSerialNumber(); 056 057 /** 058 * Returns the comments from the roboRIO web interface. 059 * 060 * @return The comments string. 061 * @see "HAL_GetComments" 062 */ 063 public static native String getComments(); 064 065 /** 066 * Returns the team number configured for the robot controller. 067 * 068 * @return team number, or 0 if not found. 069 * @see "HAL_GetTeamNumber" 070 */ 071 public static native int getTeamNumber(); 072 073 /** 074 * Reads the microsecond-resolution timer on the FPGA. 075 * 076 * @return The current time in microseconds according to the FPGA (since FPGA reset). 077 */ 078 public static native long getFPGATime(); 079 080 /** 081 * Returns the runtime type of the HAL. 082 * 083 * @return HAL Runtime Type 084 * @see RUNTIME_ROBORIO 085 * @see RUNTIME_ROBORIO2 086 * @see RUNTIME_SIMULATION 087 * @see "HAL_GetRuntimeType" 088 */ 089 public static native int getHALRuntimeType(); 090 091 /** 092 * Gets the error message for a specific status code. 093 * 094 * @param code the status code 095 * @return the error message for the code. This does not need to be freed. 096 * @see "HAL_GetErrorMessage" 097 */ 098 public static native String getHALErrorMessage(int code); 099 100 /** 101 * Get the last HAL error code. 102 * 103 * @return error code 104 */ 105 public static native int getHALErrno(); 106 107 /** 108 * Returns the textual description of the system error code. 109 * 110 * @param errno errno to get description of 111 * @return description of errno 112 * @see "std:strerror" 113 */ 114 public static native String getHALstrerror(int errno); 115 116 /** 117 * Gets the error message for the last HAL error. 118 * 119 * @return the error message for the code. 120 */ 121 public static String getHALstrerror() { 122 return getHALstrerror(getHALErrno()); 123 } 124 125 private HALUtil() {} 126}