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