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 transmit status. Transmit status field is part of 022 * the {@code TransmitStatusPacket} and {@code TXStatusPacket} indicating the 023 * status of the transmission. 024 * 025 * @see com.digi.xbee.api.packet.common.TransmitStatusPacket 026 * @see com.digi.xbee.api.packet.raw.TXStatusPacket 027 */ 028public enum XBeeTransmitStatus { 029 030 // Enumeration types 031 SUCCESS (0x00, "Success"), 032 NO_ACK (0x01, "No acknowledgement received"), 033 CCA_FAILURE (0x02, "CCA failure"), 034 PURGED (0x03, "Transmission purged, it was attempted before stack was up"), 035 WIFI_PHYSICAL_ERROR (0x04, "Physical error occurred on the interface with the WiFi transceiver"), 036 INVALID_DESTINATION (0x15, "Invalid destination endpoint"), 037 NO_BUFFERS (0x18, "No buffers"), 038 NETWORK_ACK_FAILURE (0x21, "Network ACK Failure"), 039 NOT_JOINED_NETWORK (0x22, "Not joined to network"), 040 SELF_ADDRESSED (0x23, "Self-addressed"), 041 ADDRESS_NOT_FOUND (0x24, "Address not found"), 042 ROUTE_NOT_FOUND (0x25, "Route not found"), 043 BROADCAST_FAILED (0x26, "Broadcast source failed to hear a neighbor relay the message"), 044 INVALID_BINDING_TABLE_INDEX (0x2B, "Invalid binding table index"), 045 INVALID_ENDPOINT (0x2C, "Invalid endpoint"), 046 BROADCAST_ERROR_APS (0x2D, "Attempted broadcast with APS transmission"), 047 BROADCAST_ERROR_APS_EE0 (0x2E, "Attempted broadcast with APS transmission, but EE=0"), 048 SOFTWARE_ERROR (0x31, "A software error occurred"), 049 RESOURCE_ERROR (0x32, "Resource error lack of free buffers, timers, etc."), 050 /** @since 1.3.0 */ 051 COAP_URI_LENGTH (0x40, "CoAP message URI requires a nonzero length URI string terminated with a zero byte"), 052 /** @since 1.3.0 */ 053 UNRECOGNIZED_DIGI_FRAME (0x41, "Unrecognized Digi API Frame type"), 054 /** @since 1.3.0 */ 055 BADLY_COAP_REQUEST (0x42, "Client made a badly formed CoAP request"), 056 /** @since 1.3.0 */ 057 SERVER_FAILED_COAP (0x43, "Server failed to handle CoAP request, perhaps due to a lack of internal resources. The client may try again"), 058 /** @since 1.3.0 */ 059 COAP_INVALID_STATUS (0x44, "CoAP Invalid Status"), 060 /** @since 1.3.0 */ 061 COAP_MESSAGE_TIMEOUT (0x45, "CoAP Message Timeout, Server did not respond within the expected time"), 062 /** @since 1.3.0 */ 063 COAP_MESSAGE_RESET (0x46, "CoAP Message Reset"), 064 PAYLOAD_TOO_LARGE (0x74, "Data payload too large"), 065 INDIRECT_MESSAGE_UNREQUESTED (0x75, "Indirect message unrequested"), 066 SOCKET_CREATION_FAILED (0x76, "Attempt to create a client socket failed"), 067 IP_PORT_NOT_EXIST (0x77, "TCP connection to given IP address and port doesn't exist. Source port is non-zero so that a new connection is not attempted"), 068 /** @deprecated Use {@link #INVALID_UDP_PORT} instead. */ 069 UDP_SRC_PORT_NOT_MATCH_LISTENING_PORT (0x78, "Source port on a UDP transmission doesn't match a listening port on the transmitting module."), 070 /** @since 1.2.0 */ 071 INVALID_UDP_PORT(0x78, "Invalid UDP port"), 072 /** @since 1.2.0 */ 073 INVALID_TCP_PORT(0x79, "Invalid TCP port"), 074 /** @since 1.2.0 */ 075 INVALID_HOST(0x7A, "Invalid host"), 076 /** @since 1.2.0 */ 077 INVALID_DATA_MODE(0x7B, "Invalid data mode"), 078 /** @since 1.3.0 */ 079 INVALID_INTERFACE(0x7C, "Invalid interface"), 080 /** @since 1.3.0 */ 081 NOT_ACCEPT_FRAMES(0x7D, "Interface not accepting frames"), 082 /** @since 1.2.0 */ 083 CONNECTION_REFUSED(0x80, "Connection refused"), 084 /** @since 1.2.0 */ 085 CONNECTION_LOST(0x81, "Connection lost"), 086 /** @since 1.2.0 */ 087 NO_SERVER(0x82, "No server"), 088 /** @since 1.2.0 */ 089 SOCKET_CLOSED(0x83, "Socket closed"), 090 /** @since 1.2.0 */ 091 UNKNOWN_SERVER(0x84, "Unknown server"), 092 /** @since 1.2.0 */ 093 UNKNOWN_ERROR(0x85, "Unknown error"), 094 /** @since 1.3.0 */ 095 INVALID_TLS_CONFIGURATION(0x86, "Invalid TLS configuration"), 096 KEY_NOT_AUTHORIZED (0xBB, "Key not authorized"), 097 UNKNOWN (255, "Unknown"); 098 099 // Variables 100 private final int id; 101 102 private final String description; 103 104 private static final HashMap<Integer, XBeeTransmitStatus> lookupTable = new HashMap<Integer, XBeeTransmitStatus>(); 105 106 static { 107 for (XBeeTransmitStatus ts:values()) 108 lookupTable.put(ts.getId(), ts); 109 } 110 111 /** 112 * Class constructor. Instantiates a new {@code XBeeTransmitStatus} entry 113 * with the given parameters. 114 * 115 * @param id Transmit status identifier. 116 * @param description Transmit status description. 117 */ 118 private XBeeTransmitStatus(int id, String description) { 119 this.id = id; 120 this.description = description; 121 } 122 123 /** 124 * Returns the numeric value of the transmit status identifier. 125 * 126 * @return Transmit status identifier. 127 */ 128 public int getId() { 129 return id; 130 } 131 132 /** 133 * Returns the transmit status description. 134 * 135 * @return Transmit status description. 136 */ 137 public String getDescription() { 138 return description; 139 } 140 141 /** 142 * Returns the {@code XBeeTransmitStatus} associated to the given 143 * identifier. 144 * 145 * Returns {@code UNKNOWN} if the identifier is not in the enumeration. 146 * 147 * @param id Identifier of the {@code XBeeTransmitStatus} to retrieve. 148 * 149 * @return The {@code XBeeTransmitStatus} associated to the given 150 * identifier. 151 * {@code UNKNOWN} if the identifier is not in the enumeration. 152 */ 153 public static XBeeTransmitStatus get(int id) { 154 XBeeTransmitStatus status = lookupTable.get(id); 155 if (status != null) 156 return status; 157 return UNKNOWN; 158 } 159 160 /* 161 * (non-Javadoc) 162 * @see java.lang.Enum#toString() 163 */ 164 @Override 165 public String toString() { 166 if (id != SUCCESS.getId()) 167 return String.format("Error: %s (0x%02X)", description, id); 168 else 169 return String.format("%s (0x%02X)", description, id); 170 } 171}