001 /*----------------------------------------------------------------------------*/
002 /* Copyright (c) FIRST 2008-2012. All Rights Reserved. */
003 /* Open Source Software - may be modified and shared by FRC teams. The code */
004 /* must be accompanied by the FIRST BSD license file in the root directory of */
005 /* the project. */
006 /*----------------------------------------------------------------------------*/
007
008 package edu.wpi.first.wpilibj.communication;
009
010 import com.sun.cldc.jna.*;
011 import com.sun.squawk.VM;
012
013 /**
014 * Class for obtaining a RIO handle.
015 * @author jhersh
016 */
017 public class BumARioHandle
018 {
019
020 // UINT32 FRC_NetworkCommunication_nBumARioHandle_bum(INT32 *status);
021 private static Function bumFn;
022 private static Function invalidateFn;
023
024 static {
025 try {
026 bumFn = NativeLibrary.getDefaultInstance().getFunction("FRC_NetworkCommunication_nBumARioHandle_bum");
027 invalidateFn = NativeLibrary.getDefaultInstance().getFunction("FRC_NetworkCommunication_nBumARioHandle_invalidate");
028 } catch (Exception e){
029 bumFn = null;
030 invalidateFn = null;
031 throw new RuntimeException("Communication functions are missing. Make sure that you are using the latest version of the communication library and FPGA, downloaded from file releases on sourceforge.wpi.edu");
032 }
033 }
034
035 /**
036 * Obtain a RIO handle.
037 * @param pStatus The current status.
038 * @return A RIOHandle
039 */
040 public static int bum(int pStatus)
041 {
042 return bumFn.call1(pStatus);
043 }
044
045 static {
046 invalidateFn.call0();
047 VM.addShutdownHook(new Thread(new Runnable() {
048 public void run() {
049 invalidateFn.call0();
050 }
051 }));
052 }
053 }