001/** 002 * Copyright 2017, Digi International Inc. 003 * 004 * This Source Code Form is subject to the terms of the Mozilla Public 005 * License, v. 2.0. If a copy of the MPL was not distributed with this 006 * file, you can obtain one at http://mozilla.org/MPL/2.0/. 007 * 008 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 009 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 010 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 011 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 012 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 013 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 014 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 015 */ 016package com.digi.xbee.api.models; 017 018import java.util.HashMap; 019 020import com.digi.xbee.api.utils.HexUtils; 021 022/** 023 * Enumerates the different API output modes. The API output mode establishes 024 * the way data will be output through the serial interface of an XBee device. 025 */ 026public enum APIOutputMode { 027 028 // Enumeration entries 029 MODE_NATIVE(0x00, "Native"), 030 MODE_EXPLICIT(0x01, "Explicit"), 031 MODE_EXPLICIT_ZDO_PASSTHRU(0x03, "Explicit with ZDO Passthru"); 032 033 // Variables 034 private final int value; 035 036 private final String description; 037 038 private final static HashMap<Integer, APIOutputMode> lookupTable = new HashMap<Integer, APIOutputMode>(); 039 040 static { 041 for (APIOutputMode apiOutputMode:values()) 042 lookupTable.put(apiOutputMode.getValue(), apiOutputMode); 043 } 044 045 /** 046 * Class constructor. Instantiates a new {@code APIOutputMode} enumeration 047 * entry with the given parameters. 048 * 049 * @param value API output mode value 050 * @param description API output mode description. 051 */ 052 private APIOutputMode(int value, String description) { 053 this.value = value; 054 this.description = description; 055 } 056 057 /** 058 * Returns the API output mode value. 059 * 060 * @return The API output mode value. 061 */ 062 public int getValue() { 063 return value; 064 } 065 066 /** 067 * Returns the API output mode description. 068 * 069 * @return The API output mode description. 070 */ 071 public String getDescription() { 072 return description; 073 } 074 075 /** 076 * Returns the {@code APIOutputMode} entry associated to the given value. 077 * 078 * @param value Value of the {@code APIOutputMode} to retrieve. 079 * 080 * @return The {@code APIOutputMode} entry associated to the given value, 081 * {@code null} if the value could not be found in the 082 * list. 083 */ 084 public static APIOutputMode get(int value) { 085 APIOutputMode apiOutputMode = lookupTable.get(value); 086 if (apiOutputMode != null) 087 return apiOutputMode; 088 return null; 089 } 090 091 /* 092 * (non-Javadoc) 093 * @see java.lang.Enum#toString() 094 */ 095 @Override 096 public String toString() { 097 return HexUtils.byteToHexString((byte)value) + ": " + description; 098 } 099}