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 for the Thread 024 * protocol. 025 * 026 * @since 1.2.1 027 */ 028public enum ThreadAssociationIndicationStatus { 029 030 // Enumeration entries 031 ASSOCIATED(0x00, "Device Associated"), 032 ALREADY_IN_NWK_BEFORE_RESET(0x01, "Device was part of a network before reset"), 033 ATTEMPT_TO_FORM_JOIN_NWK(0x02, "Device is attempting to form/join network"), 034 JOINED_WITHOUT_PARENT(0x03, "Device is joined but without a parent"), 035 JOINED_ATTACHING(0x04, "Device is joined and currently attaching"), 036 COMMISSION_FAILURE_INVALID_PARAM(0xF4, "Commission failure because of invalid parameter"), 037 COMMISSION_FAILURE_ALREADY_IN_NWK(0xF5, "Commission failure because node is already part of a network. Issue a NR before attempting to join again"), 038 JOIN_FAILURE_INVALID_PARAMS(0xF6, "Join failure because of invalid parameters"), 039 JOIN_FAILURE_ALREADY_IN_NWK(0xF7, "Join failure because node is already part of a network. Issue a NR before attempting to join again"), 040 FORM_NWK_FAILURE_SCAN_ALREADY_IN_PROGRESS(0xF8, "Form network failure because a network scan was already in progress"), 041 SECURITY_FAILURE(0xF9, "Security failure"), 042 COMMISSIONING_FAILURE(0xFA, "Commissioning failure"), 043 FAIL_TO_FIND_BEACON(0xFB, "Device failed to find beacon with configured parameters"), 044 FAIL_TO_FORM_NWK_SCAN_FAILURE(0xFC, "Device failed to form network because of a scan failure"), 045 FORM_JOIN_UNKNOWN_REASON_1(0xFD, "Form/Join failure for unknown reason. Retry and if problem persists contact Digi support"), 046 FORM_JOIN_UNKNOWN_REASON_2(0xFE, "Form/Join failure for unknown reason. Retry and if problem persists contact Digi support"), 047 DISASSOCIATED(0xFF, "Disassociated"); 048 049 // Variables 050 private final int value; 051 052 private final String description; 053 054 private final static HashMap<Integer, ThreadAssociationIndicationStatus> lookupTable = new HashMap<Integer, ThreadAssociationIndicationStatus>(); 055 056 static { 057 for (ThreadAssociationIndicationStatus associationIndicationStatus:values()) 058 lookupTable.put(associationIndicationStatus.getValue(), associationIndicationStatus); 059 } 060 061 /** 062 * Class constructor. Instantiates a new 063 * {@code ThreadAssociationIndicationStatus} enumeration entry with the 064 * given parameters. 065 * 066 * @param value Thread association indication status value. 067 * @param description Thread association indication status description. 068 */ 069 ThreadAssociationIndicationStatus(int value, String description) { 070 this.value = value; 071 this.description = description; 072 } 073 074 /** 075 * Returns the Thread association indication status value. 076 * 077 * @return The Thread association indication status value. 078 */ 079 public int getValue() { 080 return value; 081 } 082 083 /** 084 * Returns the Thread association indication status description. 085 * 086 * @return The Thread association indication status description. 087 */ 088 public String getDescription() { 089 return description; 090 } 091 092 /** 093 * Returns the {@code ThreadAssociationIndicationStatus} associated to 094 * the given value. 095 * 096 * @param value Value of the Thread association indication status to 097 * retrieve. 098 * 099 * @return The Thread association indication status of the associated 100 * value, {@code null} if it could not be found in the table. 101 */ 102 public static ThreadAssociationIndicationStatus get(int value) { 103 return lookupTable.get(value); 104 } 105 106 /* 107 * (non-Javadoc) 108 * @see java.lang.Enum#toString() 109 */ 110 @Override 111 public String toString() { 112 return HexUtils.byteToHexString((byte)value) + ": " + description; 113 } 114}