    001/**
    002 * Copyright (c) 2014 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        TX_64 (0x00, "TX (Transmit) Request 64-bit address"),
    027        TX_16 (0x01, "TX (Transmit) Request 16-bit address"),
    028        AT_COMMAND (0x08, "AT Command"),
    029        AT_COMMAND_QUEUE (0x09, "AT Command Queue"),
    030        TRANSMIT_REQUEST (0x10, "Transmit Request"),
    031        REMOTE_AT_COMMAND_REQUEST (0x17, "Remote AT Command Request"),
    032        RX_64 (0x80, "RX (Receive) Packet 64-bit Address"),
    033        RX_16 (0x81, "RX (Receive) Packet 16-bit Address"),
    034        RX_IO_64 (0x82, "IO Data Sample RX 64-bit Address Indicator"),
    035        RX_IO_16 (0x83, "IO Data Sample RX 16-bit Address Indicator"),
    036        AT_COMMAND_RESPONSE (0x88, "AT Command Response"),
    037        TX_STATUS (0x89, "TX (Transmit) Status"),
    038        MODEM_STATUS (0x8A, "Modem Status"),
    039        TRANSMIT_STATUS (0x8B, "Transmit Status"),
    040        RECEIVE_PACKET (0x90, "Receive Packet"),
    041        IO_DATA_SAMPLE_RX_INDICATOR (0x92, "IO Data Sample RX Indicator"),
    042        REMOTE_AT_COMMAND_RESPONSE (0x97, "Remote Command Response"),
    043        GENERIC (0xFF, "Generic");
    044
    045        // Variables.
    046        private final int idValue;
    047
    048        private final String name;
    049
    050        private static final HashMap<Integer, APIFrameType> lookupTable = new HashMap<Integer, APIFrameType>();
    051
    052        static {
    053                for (APIFrameType type:values())
    054                        lookupTable.put(type.getValue(), type);
    055        }
    056
    057        /**
    058         * Class constructor. Instantiates a new {@code APIFrameType} object with
    059         * the given value and name.
    060         *
    061         * @param idValue Frame type value.
    062         * @param name Frame type name.
    063         */
    064        APIFrameType(int idValue, String name) {
    065                this.idValue = idValue;
    066                this.name = name;
    067        }
    068
    069        /**
    070         * Returns the {@code APIFrameType} associated with the given ID value.
    071         *
    072         * @param value ID value to retrieve {@code APIFrameType}.
    073         *
    074         * @return The {@code APIFrameType} for the given ID value, {@code null} if
    075         *         it does not exist.
    076         */
    077        public static APIFrameType get(int value) {
    078                APIFrameType type = lookupTable.get(value);
    079                return type;
    080        }
    081
    082        /**
    083         * Returns the API frame type value.
    084         *
    085         * @return The API frame type value.
    086         */
    087        public int getValue() {
    088                return idValue;
    089        }
    090
    091        /**
    092         * Returns the API frame type name.
    093         *
    094         * @return API frame type name.
    095         */
    096        public String getName() {
    097                return name;
    098        }
    099
    100        /*
    101         * (non-Javadoc)
    102         * @see java.lang.Enum#toString()
    103         */
    104        @Override
    105        public String toString() {
    106                return "(" + HexUtils.byteArrayToHexString(ByteUtils.intToByteArray(idValue)) + ") " + name;
    107        }
    108}