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.BlockingFunction;
011 import com.sun.cldc.jna.NativeLibrary;
012
013 /**
014 * Class for communicating with the NetworkCommunication library routines
015 * which check module presence.
016 *
017 * @author pmalmsten
018 */
019 public class ModulePresence {
020
021 public static final int kMaxModuleNumber = 2;
022
023 public static class ModuleType {
024
025 public static final ModuleType kUnknown = new ModuleType(0x00);
026 public static final ModuleType kAnalog = new ModuleType(0x01);
027 public static final ModuleType kDigital = new ModuleType(0x02);
028 public static final ModuleType kSolenoid = new ModuleType(0x03);
029 private final int m_intValue;
030
031 private ModuleType(int value) {
032 m_intValue = value;
033 }
034
035 public int getValue() {
036 return m_intValue;
037 }
038 };
039 private static final BlockingFunction getModulePresenceFn = NativeLibrary.getDefaultInstance().getBlockingFunction("FRC_NetworkCommunication_nLoadOut_getModulePresence");
040
041 /**
042 * Determines whether the module of the given type and number is present.
043 *
044 * This method calls the appropriate C function within the NetworkCommunication
045 * library in order to get the answer.
046 *
047 * @param moduleType The type of the module to be check.
048 * @param moduleNumber The ID for this type of module to check (usually 0 or 1).
049 * @return Whether the given module is present.
050 */
051 public static boolean getModulePresence(ModuleType moduleType, int moduleNumber) {
052 return (getModulePresenceFn.call2(moduleType.getValue(), moduleNumber) == 1);
053 }
054 }