001/**
002 * Copyright 2017, 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.
024 */
025public enum AssociationIndicationStatus {
026
027        // Enumeration entries
028        SUCCESSFULLY_JOINED(0x00, "Successfully formed or joined a network."),
029        AS_TIMEOUT(0x01, "Active Scan Timeout."),
030        AS_NO_PANS_FOUND(0x02, "Active Scan found no PANs."),
031        AS_ASSOCIATION_NOT_ALLOED(0x03, "Active Scan found PAN, but the CoordinatorAllowAssociation bit is not set."),
032        AS_BEACONS_NOT_SUPPORTED(0x04, "Active Scan found PAN, but Coordinator and End Device are not configured to support beacons."),
033        AS_ID_DOESNT_MATCH(0x05, "Active Scan found PAN, but the Coordinator ID parameter does not match the ID parameter of the End Device."),
034        AS_CHANNEL_DOESNT_MATCH(0x06, "Active Scan found PAN, but the Coordinator CH parameter does not match the CH parameter of the End Device."),
035        ENERGY_SCAN_TIMEOUT(0x07, "Energy Scan Timeout."),
036        COORDINATOR_START_REQUEST_FAILED(0x08, "Coordinator start request failed."),
037        COORDINATOR_INVALID_PARAMETER(0x09, "Coordinator could not start due to invalid parameter."),
038        COORDINATOR_REALIGNMENT(0x0A, "Coordinator Realignment is in progress."),
039        AR_NOT_SENT(0x0B, "Association Request not sent."),
040        AR_TIMED_OUT(0x0C, "Association Request timed out - no reply was received."),
041        AR_INVALID_PARAMETER(0x0D, "Association Request had an Invalid Parameter."),
042        AR_CHANNEL_ACCESS_FAILURE(0x0E, "Association Request Channel Access Failure. Request was not transmitted - CCA failure."),
043        AR_COORDINATOT_ACK_WASNT_RECEIVED(0x0F, "Remote Coordinator did not send an ACK after Association Request was sent."),
044        AR_COORDINATOT_DIDNT_REPLY(0x10, "Remote Coordinator did not reply to the Association Request, but an ACK was received after sending the request."),
045        SYNCHRONIZATION_LOST(0x12, "Sync-Loss - Lost synchronization with a Beaconing Coordinator."),
046        DISSASOCIATED(0x13, " Disassociated - No longer associated to Coordinator."),
047        NO_PANS_FOUND(0x21, "Scan found no PANs."),
048        NO_PANS_WITH_ID_FOUND(0x22, "Scan found no valid PANs based on current SC and ID settings."),
049        NJ_EXPIRED(0x23, "Valid Coordinator or Routers found, but they are not allowing joining (NJ expired)."),
050        NO_JOINABLE_BEACONS_FOUND(0x24, "No joinable beacons were found."),
051        UNEXPECTED_STATE(0x25, "Unexpected state, node should not be attempting to join at this time."),
052        JOIN_FAILED(0x27, "Node Joining attempt failed (typically due to incompatible security settings)."),
053        COORDINATOR_START_FAILED(0x2A, "Coordinator Start attempt failed."),
054        CHECKING_FOR_COORDINATOR(0x2B, "Checking for an existing coordinator."),
055        NETWORK_LEAVE_FAILED(0x2C, "Attempt to leave the network failed."),
056        DEVICE_DIDNT_RESPOND(0xAB, "Attempted to join a device that did not respond."),
057        UNSECURED_KEY_RECEIVED(0xAC, "Secure join error - network security key received unsecured."),
058        KEY_NOT_RECEIVED(0xAD, "Secure join error - network security key not received."),
059        INVALID_SECURITY_KEY(0xAF, "Secure join error - joining device does not have the right preconfigured link key."),
060        SCANNING_NETWORK(0xFF, "Scanning for a network/Attempting to associate.");
061        
062        // Variables
063        private final int value;
064        
065        private final String description;
066        
067        private final static HashMap<Integer, AssociationIndicationStatus> lookupTable = new HashMap<Integer, AssociationIndicationStatus>();
068        
069        static {
070                for (AssociationIndicationStatus associationIndicationStatus:values())
071                        lookupTable.put(associationIndicationStatus.getValue(), associationIndicationStatus);
072        }
073        
074        /**
075         * Class constructor. Instantiates a new {@code AssociationIndicationStatus} 
076         * enumeration entry with the given parameters.
077         * 
078         * @param value Association indication status value.
079         * @param description Association indication status description.
080         */
081        AssociationIndicationStatus(int value, String description) {
082                this.value = value;
083                this.description = description;
084        }
085        
086        /**
087         * Returns the association indication status value.
088         * 
089         * @return The association indication status value.
090         */
091        public int getValue() {
092                return value;
093        }
094        
095        /**
096         * Returns the association indication status description.
097         * 
098         * @return The association indication status description.
099         */
100        public String getDescription() {
101                return description;
102        }
103        
104        /**
105         * Returns the {@code AssociationIndicationStatus} associated to the 
106         * given value.
107         * 
108         * @param value Value of the association indication status to retrieve.
109         * @return The association indication status of the associated value, {@code null} 
110         *         if it could not be found in the table.
111         */
112        public static AssociationIndicationStatus get(int value) {
113                return lookupTable.get(value);
114        }
115        
116        /*
117         * (non-Javadoc)
118         * @see java.lang.Enum#toString()
119         */
120        @Override
121        public String toString() {
122                return HexUtils.byteToHexString((byte)value) + ": " + description;
123        }
124}