    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.models;
    013
    014import java.util.HashMap;
    015
    016/**
    017 * Enumerates all the possible states of an AT Command after executing it.
    018 * {@code ATCommadResponse} objects will contain an entry of this enumerator
    019 * indicating the status of the AT Command that was executed.
    020 *
    021 * @see ATCommandResponse
    022 */
    023public enum ATCommandStatus {
    024
    025        // Enumeration elements
    026        OK (0, "Status OK"),
    027        ERROR (1, "Status Error"),
    028        INVALID_COMMAND (2, "Invalid command"),
    029        INVALID_PARAMETER (3, "Invalid parameter"),
    030        TX_FAILURE (4, "TX failure"),
    031        UNKNOWN (64, "Unknown status");
    032
    033        // Variables
    034        private final int id;
    035
    036        private final String description;
    037
    038        private final static HashMap<Integer, ATCommandStatus> lookupTable = new HashMap<Integer, ATCommandStatus>();
    039
    040        static {
    041                for (ATCommandStatus at:values())
    042                        lookupTable.put(at.getId(), at);
    043        }
    044
    045        /**
    046         * Class constructor. Instantiates a new enumeration element of type
    047         * {@code ATCommandStatus} with the given parameters.
    048         *
    049         * @param id AT Command Status ID.
    050         * @param description AT Command Status description.
    051         */
    052        ATCommandStatus(int id, String description) {
    053                this.id = id;
    054                this.description = description;
    055        }
    056
    057        /**
    058         * Returns the AT Command Status ID.
    059         *
    060         * @return The AT Command Status ID.
    061         */
    062        public int getId() {
    063                return id;
    064        }
    065
    066        /**
    067         * Returns the AT Command Status description.
    068         *
    069         * @return AT Command Status description.
    070         */
    071        public String getDescription() {
    072                return description;
    073        }
    074
    075        /**
    076         * Returns the {@code ATCommandStatus} associated to the given ID.
    077         *
    078         * @param id ID to retrieve the corresponding {@code ATCommandStatus}.
    079         *
    080         * @return The {@code ATCommandStatus} associated to the given ID.
    081         */
    082        public static ATCommandStatus get(int id) {
    083                if (lookupTable.get(id) == null)
    084                        return UNKNOWN;
    085                return lookupTable.get(id);
    086        }
    087
    088        /*
    089         * (non-Javadoc)
    090         * @see java.lang.Enum#toString()
    091         */
    092        @Override
    093        public String toString() {
    094                return description;
    095        }
    096}