001/** 002 * Copyright (c) 2014-2015 Digi International Inc., 003 * All rights not expressly granted are reserved. 004 * 005 * This Source Code Form is subject to the terms of the Mozilla Public 006 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 007 * You can obtain one at http://mozilla.org/MPL/2.0/. 008 * 009 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343 010 * ======================================================================= 011 */ 012package com.digi.xbee.api.models; 013 014import java.util.HashMap; 015 016import com.digi.xbee.api.utils.HexUtils; 017 018/** 019 * Enumerates the different API output modes. The API output mode establishes 020 * the way data will be output through the serial interface of an XBee device. 021 */ 022public enum APIOutputMode { 023 024 // Enumeration entries 025 MODE_NATIVE(0x00, "Native"), 026 MODE_EXPLICIT(0x01, "Explicit"), 027 MODE_EXPLICIT_ZDO_PASSTHRU(0x03, "Explicit with ZDO Passthru"); 028 029 // Variables 030 private final int value; 031 032 private final String description; 033 034 private final static HashMap<Integer, APIOutputMode> lookupTable = new HashMap<Integer, APIOutputMode>(); 035 036 static { 037 for (APIOutputMode apiOutputMode:values()) 038 lookupTable.put(apiOutputMode.getValue(), apiOutputMode); 039 } 040 041 /** 042 * Class constructor. Instantiates a new {@code APIOutputMode} enumeration 043 * entry with the given parameters. 044 * 045 * @param value API output mode value 046 * @param description API output mode description. 047 */ 048 private APIOutputMode(int value, String description) { 049 this.value = value; 050 this.description = description; 051 } 052 053 /** 054 * Returns the API output mode value. 055 * 056 * @return The API output mode value. 057 */ 058 public int getValue() { 059 return value; 060 } 061 062 /** 063 * Returns the API output mode description. 064 * 065 * @return The API output mode description. 066 */ 067 public String getDescription() { 068 return description; 069 } 070 071 /** 072 * Returns the {@code APIOutputMode} entry associated to the given value. 073 * 074 * @param value Value of the {@code APIOutputMode} to retrieve. 075 * 076 * @return The {@code APIOutputMode} entry associated to the given value, 077 * {@code null} if the value could not be found in the 078 * list. 079 */ 080 public static APIOutputMode get(int value) { 081 APIOutputMode apiOutputMode = lookupTable.get(value); 082 if (apiOutputMode != null) 083 return apiOutputMode; 084 return null; 085 } 086 087 /* 088 * (non-Javadoc) 089 * @see java.lang.Enum#toString() 090 */ 091 @Override 092 public String toString() { 093 return HexUtils.byteToHexString((byte)value) + ": " + description; 094 } 095}