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 org.wpilib.hardware.hal; 006 007/** 008 * Hardware Abstraction Layer (HAL) Utilities JNI Functions. 009 * 010 * @see "wpi/hal/HAL.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 /** Voltage to convert to raw value is out of range [0; 5]. */ 017 public static final int VOLTAGE_OUT_OF_RANGE = 1002; 018 019 /** The operation cannot be completed. */ 020 public static final int INCOMPATIBLE_STATE = 1015; 021 022 /** No available resources to allocate. */ 023 public static final int NO_AVAILABLE_RESOURCES = -1004; 024 025 /** A parameter is out of range. */ 026 public static final int PARAMETER_OUT_OF_RANGE = -1028; 027 028 /** Systemcore runtime. */ 029 public static final int RUNTIME_SYSTEMCORE = 0; 030 031 /** Simulation runtime. */ 032 public static final int RUNTIME_SIMULATION = 1; 033 034 /** 035 * Returns the roboRIO serial number. 036 * 037 * @return The roboRIO serial number. 038 * @see "HAL_GetSerialNumber" 039 */ 040 public static native String getSerialNumber(); 041 042 /** 043 * Returns the comments from the roboRIO web interface. 044 * 045 * @return The comments string. 046 * @see "HAL_GetComments" 047 */ 048 public static native String getComments(); 049 050 /** 051 * Returns the team number configured for the robot controller. 052 * 053 * @return team number, or 0 if not found. 054 * @see "HAL_GetTeamNumber" 055 */ 056 public static native int getTeamNumber(); 057 058 /** 059 * Reads the microsecond-resolution monotonic timer. 060 * 061 * @return The current monotonic time in microseconds. 062 */ 063 public static native long getMonotonicTime(); 064 065 /** 066 * Returns the runtime type of the HAL. 067 * 068 * @return HAL Runtime Type 069 * @see #RUNTIME_SYSTEMCORE 070 * @see #RUNTIME_SIMULATION 071 * @see "HAL_GetRuntimeType" 072 */ 073 public static native int getHALRuntimeType(); 074 075 /** 076 * Gets the error message for a specific status code. 077 * 078 * @param code the status code 079 * @return the error message for the code. This does not need to be freed. 080 * @see "HAL_GetErrorMessage" 081 */ 082 public static native String getHALErrorMessage(int code); 083 084 /** 085 * Get the last HAL error code. 086 * 087 * @return error code 088 */ 089 public static native int getHALErrno(); 090 091 /** 092 * Returns the textual description of the system error code. 093 * 094 * @param errno errno to get description of 095 * @return description of errno 096 * @see "std::strerror" 097 */ 098 public static native String getHALstrerror(int errno); 099 100 /** 101 * Gets the error message for the last HAL error. 102 * 103 * @return the error message for the code. 104 */ 105 public static String getHALstrerror() { 106 return getHALstrerror(getHALErrno()); 107 } 108 109 private HALUtil() {} 110}