001package edu.wpi.first.wpilibj.hal; 002 003import java.nio.ByteBuffer; 004import java.nio.IntBuffer; 005import edu.wpi.first.wpilibj.DriverStation; 006 007public class HALUtil extends JNIWrapper { 008 public static final int NULL_PARAMETER = -1005; 009 public static final int SAMPLE_RATE_TOO_HIGH = 1001; 010 public static final int VOLTAGE_OUT_OF_RANGE = 1002; 011 public static final int LOOP_TIMING_ERROR = 1004; 012 public static final int INCOMPATIBLE_STATE = 1015; 013 public static final int ANALOG_TRIGGER_PULSE_OUTPUT_ERROR = -1011; 014 public static final int NO_AVAILABLE_RESOURCES = -104; 015 public static final int PARAMETER_OUT_OF_RANGE = -1028; 016 017 //public static final int SEMAPHORE_WAIT_FOREVER = -1; 018 //public static final int SEMAPHORE_Q_PRIORITY = 0x01; 019 020 public static native ByteBuffer initializeMutexNormal(); 021 public static native void deleteMutex(ByteBuffer sem); 022 public static native byte takeMutex(ByteBuffer sem); 023 //public static native ByteBuffer initializeSemaphore(int initialValue); 024 //public static native void deleteSemaphore(ByteBuffer sem); 025 //public static native byte takeSemaphore(ByteBuffer sem, int timeout); 026 public static native ByteBuffer initializeMultiWait(); 027 public static native void deleteMultiWait(ByteBuffer sem); 028 public static native byte takeMultiWait(ByteBuffer sem, ByteBuffer m, int timeOut); 029 public static native short getFPGAVersion(IntBuffer status); 030 public static native int getFPGARevision(IntBuffer status); 031 public static native long getFPGATime(IntBuffer status); 032 public static native boolean getFPGAButton(IntBuffer status); 033 034 public static native String getHALErrorMessage(int code); 035 036 public static native int getHALErrno(); 037 public static native String getHALstrerror(int errno); 038 public static String getHALstrerror(){ 039 return getHALstrerror(getHALErrno()); 040 } 041 042 public static void checkStatus(IntBuffer status) 043 { 044 int s = status.get(0); 045 if (s < 0) 046 { 047 String message = getHALErrorMessage(s); 048 throw new RuntimeException(" Code: " + s + ". " + message); 049 } else if (s > 0) { 050 String message = getHALErrorMessage(s); 051 DriverStation.reportError(message, true); 052 } 053 } 054 055}