001/**
002 * Copyright 2017-2019, 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 association indication status for the Cellular 
024 * protocol.
025 * 
026 * @since 1.2.0
027 */
028public enum CellularAssociationIndicationStatus {
029
030        // Enumeration entries
031        SUCCESSFULLY_CONNECTED(0x00, "Connected to the Internet."),
032        REGISTERING_CELLULAR_NETWORK(0x22, "Registering to cellular network"),
033        CONNECTING_INTERNET(0x23, "Connecting to the Internet"),
034        MISSING_CORRUPT(0x24, "The cellular component is missing, corrupt, or otherwise in error"),
035        REGISTRATION_DENIED(0x25, "Cellular network registration denied"),
036        AIRPLANE_MODE(0x2A, "Airplane mode"),
037        DIRECT_USB_MODE(0x2B, "Direct USB mode"),
038        PSM_LOW_POWER(0x2C, "The cellular component is in the PSM low-power state"),
039        BYPASS_MODE(0x2F, "Bypass mode active"),
040        INITIALIZING(0xFF, "Initializing"),
041        UNKNOWN(-1, "Unknown");
042        
043        // Variables
044        private final int value;
045        
046        private final String description;
047        
048        private final static HashMap<Integer, CellularAssociationIndicationStatus> lookupTable = new HashMap<Integer, CellularAssociationIndicationStatus>();
049        
050        static {
051                for (CellularAssociationIndicationStatus associationIndicationStatus:values())
052                        lookupTable.put(associationIndicationStatus.getValue(), associationIndicationStatus);
053        }
054        
055        /**
056         * Class constructor. Instantiates a new 
057         * {@code CellularAssociationIndicationStatus} enumeration entry with the 
058         * given parameters.
059         * 
060         * @param value Cellular association indication status value.
061         * @param description Cellular association indication status description.
062         */
063        CellularAssociationIndicationStatus(int value, String description) {
064                this.value = value;
065                this.description = description;
066        }
067        
068        /**
069         * Returns the Cellular association indication status value.
070         * 
071         * @return The Cellular association indication status value.
072         */
073        public int getValue() {
074                return value;
075        }
076        
077        /**
078         * Returns the Cellular association indication status description.
079         * 
080         * @return The Cellular association indication status description.
081         */
082        public String getDescription() {
083                return description;
084        }
085        
086        /**
087         * Returns the {@code CellularAssociationIndicationStatus} associated to 
088         * the given value.
089         * 
090         * @param value Value of the Cellular association indication status to 
091         *              retrieve.
092         * 
093         * @return The Cellular association indication status of the associated 
094         *         value, {@code UNKNOWN} if the identifier is not in the 
095         *         enumeration.
096         */
097        public static CellularAssociationIndicationStatus get(int value) {
098                if (lookupTable.get(value) != null)
099                        return lookupTable.get(value);
100                return UNKNOWN;
101        }
102        
103        /*
104         * (non-Javadoc)
105         * @see java.lang.Enum#toString()
106         */
107        @Override
108        public String toString() {
109                return HexUtils.byteToHexString((byte)value) + ": " + description;
110        }
111}