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
020/**
021 * Enumerates the different modem status events. This enumeration list is 
022 * intended to be used within the 
023 * {@link com.digi.xbee.api.packet.common.ModemStatusPacket} packet.
024 */
025public enum ModemStatusEvent {
026
027        // Enumeration elements
028        STATUS_HARDWARE_RESET (0, "Hardware reset"),
029        STATUS_WATCHDOG_TIMER_RESET (1, "Watchdog reset"),
030        STATUS_JOINED_NETWORK (2, "Device associated"),
031        STATUS_DISASSOCIATED (3, "Device disassociated"),
032        STATUS_ERROR_SYNCHRONIZATION_LOST (4, "Configuration error/synchronization lost"),
033        STATUS_COORDINATOR_REALIGNMENT (5, "Coordinator realignment"),
034        STATUS_COORDINATOR_STARTED (6, "The coordinator started"),
035        STATUS_NETWORK_SECURITY_KEY_UPDATED (7, "Network security key was updated"),
036        /** @since 1.3.0 */
037        STATUS_SYNCH_SENT (8, "Reserved, see twiki"),
038        /** @since 1.3.0 */
039        STATUS_SYNCH_RX (9, "Reserved, see twiki"),
040        /** @since 1.3.0 */
041        STATUS_SYNCH_MISS (0x0A, "Reserved, see twiki"),
042        STATUS_NETWORK_WOKE_UP (0x0B, "Network Woke Up"),
043        STATUS_NETWORK_WENT_TO_SLEEP (0x0C, "Network Went To Sleep"),
044        STATUS_VOLTAGE_SUPPLY_LIMIT_EXCEEDED (0x0D, "Overvoltage"),
045        /** @since 1.2.0 */
046        STATUS_DEVICE_CLOUD_CONNECTED (0x0E, "Device Cloud connected"),
047        /** @since 1.2.0 */
048        STATUS_DEVICE_CLOUD_DISCONNECTED (0x0F, "Device Cloud disconnected"),
049        /** @since 1.3.0 */
050        STATUS_MODEM_KEY_ESTABLISHMT_DONE (0x10, "Modem key established"),
051        STATUS_MODEM_CONFIG_CHANGED_WHILE_JOINING (0x11, "Modem configuration changed while joining"),
052        /** @since 1.3.0 */
053        STATUS_ACESS_FAULT (0x12, "Access fault"),
054        /** @since 1.3.0 */
055        STATUS_FATAL_STACK_ERROR (0x13, "Fatal stack error"),
056        /** @since 1.3.0 */
057        STATUS_MODEM_PLKE_INITIATED (0x14, "PLKE table initiated"),
058        /** @since 1.3.0 */
059        STATUS_MODEM_PLKE_SUCCESS (0x15, "PLKE table success"),
060        /** @since 1.3.0 */
061        STATUS_MODEM_PLKE_TABLE_FULL (0x16, "PLKE table is full"),
062        /** @since 1.3.0 */
063        STATUS_MODEM_PLKE_NOT_AUTHORIZED (0x17, "PLKE Not authorized"),
064        /** @since 1.3.0 */
065        STATUS_MODEM_PLKE_INVALID_TC_REQ (0x18, "PLKE Invalid Trust Center Request"),
066        /** @since 1.3.0 */
067        STATUS_MODEM_PLKE_TC_UPDATE_FAIL (0x19, "PLKE Trust Center update fail"),
068        /** @since 1.3.0 */
069        STATUS_MODEM_PLKE_BAD_EUI64 (0x1A, "PLKE Bad EUI address"),
070        /** @since 1.3.0 */
071        STATUS_MODEM_PLKE_LK_REJECTED (0x1B, "PLKE Link Key rejected"),
072        /** @since 1.3.0 */
073        STATUS_MODEM_PLKE_UPDATE (0x1C, "PLKE update occurred"),
074        /** @since 1.3.0 */
075        STATUS_MODEM_PLKE_CLEAR_LK_TABLE (0x1D, "PLKE Link Key table clear"),
076        /** @since 1.3.0 */
077        STATUS_MODEM_FREQUENCY_AGILITY (0x1E, "Zigbee Frequency agility has requested channel change"),
078        /** @since 1.3.0 */
079        STATUS_MODEM_FR_NOASSOC (0x1F, "Zigbee special case execute ATFR when there's no joinable beacon responses after 60 seconds"),
080        /** @since 1.3.0 */
081        STATUS_MODEM_TOKENS_RECOVERED (0x20, "Zigbee tokens space recovered"),
082        /** @since 1.3.0 */
083        STATUS_MODEM_TOKENS_UNRECOVERABLE (0x21, "Zigbee tokens space unrecoverable"),
084        /** @since 1.3.0 */
085        STATUS_MODEM_TOKENS_CORRUPTED (0x22, "Zigbee tokens space corrupted"),
086        /** @since 1.3.0 */
087        STATUS_MODEM_METAFRAME_ERROR (0x30, "Zigbee Dual Mode metaframe error"),
088        /** @since 1.3.0 */
089        STATUS_BLE_CONNECT (0x32, "BLE Connect"),
090        /** @since 1.3.0 */
091        STATUS_BLE_DISCONNECT (0x33, "BLE Disconnect"),
092        /** @since 1.3.0 */
093        STATUS_BANDMASK_CONFIG_FAILED (0x34, "Bandmask Configuration Failed"),
094        STATUS_ERROR_STACK (0x80, "Stack reset"),
095        /** @since 1.3.0 */
096        STATUS_FIB_BOOTLOADER_RESET (0x81, "FIB Bootloader reset"),
097        STATUS_ERROR_AP_NOT_CONNECTED (0x82, "Send/join command issued without connecting from AP"),
098        STATUS_ERROR_AP_NOT_FOUND (0x83, "Access point not found"),
099        STATUS_ERROR_PSK_NOT_CONFIGURED (0x84, "PSK not configured"),
100        STATUS_ERROR_SSID_NOT_FOUND (0x87, "SSID not found"),
101        STATUS_ERROR_FAILED_JOIN_SECURITY (0x88, "Failed to join with security enabled"),
102        /** @since 1.3.0 */
103        STATUS_CORE_LOCKUP_FAILURE (0x89, "Core lockup or crystal failure reset"),
104        STATUS_ERROR_INVALID_CHANNEL (0x8A, "Invalid channel"),
105        /** @since 1.3.0 */
106        STATUS_LOW_VCC_RESET (0x8B, "Low Vcc reset"),
107        STATUS_ERROR_FAILED_JOIN_AP (0x8E, "Failed to join access point"),
108        STATUS_UNKNOWN (0xFF, "UNKNOWN");
109        
110        // Variables
111        private final int id;
112        
113        private final String description;
114        
115        private final static HashMap<Integer, ModemStatusEvent> lookupTable = new HashMap<Integer, ModemStatusEvent>();
116        
117        static {
118                for (ModemStatusEvent at:values())
119                        lookupTable.put(at.getId(), at);
120        }
121        
122        /**
123         * Class constructor. Instantiates a new {@code ModemStatusEvent} 
124         * enumeration entry  with the given parameters.
125         * 
126         * @param id Modem status ID.
127         * @param description Modem status description.
128         */
129        ModemStatusEvent(int id, String description) {
130                this.id = id;
131                this.description = description;
132        }
133        
134        /**
135         * Returns the modem status ID.
136         * 
137         * @return The modem status ID.
138         */
139        public int getId() {
140                return id;
141        }
142        
143        /**
144         * Returns the modem status description.
145         * 
146         * @return Modem status description.
147         */
148        public String getDescription() {
149                return description;
150        }
151        
152        /**
153         * Returns the {@code ModemStatusEvent} associated to the given ID.
154         * 
155         * @param id ID of the {@code ModemStatusEvent} to retrieve.
156         * @return The {@code ModemStatusEvent} associated with the given ID.
157         */
158        public static ModemStatusEvent get(int id) {
159                ModemStatusEvent status = lookupTable.get(id);
160                if (status != null)
161                        return status;
162                return STATUS_UNKNOWN;
163        }
164        
165        /*
166         * (non-Javadoc)
167         * @see java.lang.Enum#toString()
168         */
169        @Override
170        public String toString() {
171                return String.format("0x%02X: %s", id, description);
172        }
173}