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.packet; 013 014import java.util.HashMap; 015 016import com.digi.xbee.api.utils.ByteUtils; 017import com.digi.xbee.api.utils.HexUtils; 018 019/** 020 * This enumeration lists all the available frame types used in any XBee 021 * protocol. 022 */ 023public enum APIFrameType { 024 025 // Enumeration elements. 026 UNKNOWN (-1, "Unknown packet"), 027 TX_64 (0x00, "TX (Transmit) Request 64-bit address"), 028 TX_16 (0x01, "TX (Transmit) Request 16-bit address"), 029 AT_COMMAND (0x08, "AT Command"), 030 AT_COMMAND_QUEUE (0x09, "AT Command Queue"), 031 TRANSMIT_REQUEST (0x10, "Transmit Request"), 032 EXPLICIT_ADDRESSING_COMMAND_FRAME (0x11, "Explicit Addressing Command Frame"), 033 REMOTE_AT_COMMAND_REQUEST (0x17, "Remote AT Command Request"), 034 RX_64 (0x80, "RX (Receive) Packet 64-bit Address"), 035 RX_16 (0x81, "RX (Receive) Packet 16-bit Address"), 036 RX_IO_64 (0x82, "IO Data Sample RX 64-bit Address Indicator"), 037 RX_IO_16 (0x83, "IO Data Sample RX 16-bit Address Indicator"), 038 AT_COMMAND_RESPONSE (0x88, "AT Command Response"), 039 TX_STATUS (0x89, "TX (Transmit) Status"), 040 MODEM_STATUS (0x8A, "Modem Status"), 041 TRANSMIT_STATUS (0x8B, "Transmit Status"), 042 RECEIVE_PACKET (0x90, "Receive Packet"), 043 EXPLICIT_RX_INDICATOR (0x91, "Explicit RX Indicator"), 044 IO_DATA_SAMPLE_RX_INDICATOR (0x92, "IO Data Sample RX Indicator"), 045 REMOTE_AT_COMMAND_RESPONSE (0x97, "Remote Command Response"), 046 GENERIC (0xFF, "Generic"); 047 048 // Variables. 049 private final int idValue; 050 051 private final String name; 052 053 private static final HashMap<Integer, APIFrameType> lookupTable = new HashMap<Integer, APIFrameType>(); 054 055 static { 056 for (APIFrameType type:values()) 057 lookupTable.put(type.getValue(), type); 058 } 059 060 /** 061 * Class constructor. Instantiates a new {@code APIFrameType} object with 062 * the given value and name. 063 * 064 * @param idValue Frame type value. 065 * @param name Frame type name. 066 */ 067 APIFrameType(int idValue, String name) { 068 this.idValue = idValue; 069 this.name = name; 070 } 071 072 /** 073 * Returns the {@code APIFrameType} associated with the given ID value. 074 * 075 * @param value ID value to retrieve {@code APIFrameType}. 076 * 077 * @return The {@code APIFrameType} for the given ID value, {@code #UNKNOWN} 078 * if it does not supported. 079 */ 080 public static APIFrameType get(int value) { 081 APIFrameType type = lookupTable.get(value); 082 if (type == null) 083 return UNKNOWN; 084 return type; 085 } 086 087 /** 088 * Returns the API frame type value. 089 * 090 * @return The API frame type value. 091 */ 092 public int getValue() { 093 return idValue; 094 } 095 096 /** 097 * Returns the API frame type name. 098 * 099 * @return API frame type name. 100 */ 101 public String getName() { 102 return name; 103 } 104 105 /* 106 * (non-Javadoc) 107 * @see java.lang.Enum#toString() 108 */ 109 @Override 110 public String toString() { 111 return "(" + HexUtils.byteArrayToHexString(ByteUtils.intToByteArray(idValue)) + ") " + name; 112 } 113}