001/**
002 * Copyright (c) 2014 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
016/**
017 * Enumerates the different transmit status. Transmit status field is part of 
018 * the {@code TransmitStatusPacket} indicating the status of the transmission.
019 * 
020 * @see com.digi.xbee.api.packet.common.TransmitStatusPacket
021 */
022public enum XBeeTransmitStatus {
023
024        // Enumeration types
025        SUCCESS (0x00, "Success"),
026        NO_ACK (0x01, "No acknowledgement received"),
027        CCA_FAILURE (0x02, "CCA failure"),
028        PURGED (0x03, "Transmission purged, it was attempted before stack was up"),
029        WIFI_PHYSICAL_ERROR (0x04, "Physical error occurred on the interface with the WiFi transceiver"),
030        INVALID_DESTINATION (0x15, "Invalid destination endpoint"),
031        NETWORK_ACK_FAILURE (0x21, "Network ACK Failure"),
032        NOT_JOINED_NETWORK (0x22, "Not joined to network"),
033        SELF_ADDRESSED (0x23, "Self-addressed"),
034        ADDRESS_NOT_FOUND (0x24, "Address not found"),
035        ROUTE_NOT_FOUND (0x25, "Route not found"),
036        BROADCAST_FAILED (0x26, "Broadcast source failed to hear a neighbor relay the message"),
037        INVALID_BINDING_TABLE_INDEX (0x2B, "Invalid binding table index"),
038        RESOURCE_ERROR (0x2C, "Resource error lack of free buffers, timers, etc."),
039        BROADCAST_ERROR_APS (0x2D, "Attempted broadcast with APS transmission"),
040        BROADCAST_ERROR_APS_EE0 (0x2E, "Attempted broadcast with APS transmission, but EE=0"),
041        RESOURCE_ERROR_BIS (0x32, "Resource error lack of free buffers, timers, etc."),
042        PAYLOAD_TOO_LARGE (0x74, "Data payload too large"),
043        SOCKET_CREATION_FAILED (0x76, "Attempt to create a client socket failed"),
044        INDIRECT_MESSAGE_UNREUESTED (0x75, "Indirect message unrequested");
045        
046        // Variables
047        private final int id;
048        
049        private final String description;
050        
051        private static final HashMap<Integer, XBeeTransmitStatus> lookupTable = new HashMap<Integer, XBeeTransmitStatus>();
052        
053        static {
054                for (XBeeTransmitStatus ts:values())
055                        lookupTable.put(ts.getId(), ts);
056        }
057        
058        /**
059         * Class constructor. Instantiates a new {@code XBeeTransmitStatus} entry 
060         * with the given parameters.
061         * 
062         * @param id XBee transmit status ID.
063         * @param description XBee transmit status description.
064         */
065        private XBeeTransmitStatus(int id, String description) {
066                this.id = id;
067                this.description = description;
068        }
069        
070        /**
071         * Returns the XBee transmit status ID.
072         * 
073         * @return XBee transmit status ID.
074         */
075        public int getId() {
076                return id;
077        }
078        
079        /**
080         * Returns the XBee transmit status description.
081         * 
082         * @return XBee transmit status description.
083         */
084        public String getDescription() {
085                return description;
086        }
087        
088        /**
089         * Returns the {@code XBeeTransmitStatus} associated to the given ID.
090         * 
091         * @param id ID of the {@code XBeeTransmitStatus} to retrieve.
092         * 
093         * @return The {@code XBeeTransmitStatus} associated to the given ID.
094         */
095        public static XBeeTransmitStatus get(int id) {
096                return lookupTable.get(id);
097        }
098        
099        /*
100         * (non-Javadoc)
101         * @see java.lang.Enum#toString()
102         */
103        @Override
104        public String toString() {
105                if (id != 0)
106                        return "Error: " + description;
107                else
108                        return description;
109        }
110}