    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
    016import com.digi.xbee.api.utils.HexUtils;
    017
    018/**
    019 * Enumerates the different modem status events. This enumeration list is
    020 * intended to be used within the
    021 * {@link com.digi.xbee.api.packet.common.ModemStatusPacket} packet.
    022 */
    023public enum ModemStatusEvent {
    024
    025        // Enumeration elements
    026        STATUS_HARDWARE_RESET (0, "Device was reset"),
    027        STATUS_WATCHDOG_TIMER_RESET (1, "Watchdog timer was reset"),
    028        STATUS_JOINED_NETWORK (2, "Device joined to network"),
    029        STATUS_DISASSOCIATED (3, "Device disassociated"),
    030        STATUS_ERROR_SYNCHRONIZATION_LOST (4, "Configuration error/synchronization lost"),
    031        STATUS_COORDINATOR_REALIGNMENT (5, "Coordinator realignment"),
    032        STATUS_COORDINATOR_STARTED (6, "The coordinator started"),
    033        STATUS_NETWORK_SECURITY_KEY_UPDATED (7, "Network security key was updated"),
    034        STATUS_NETWORK_WOKE_UP (0x0B, "Network Woke Up"),
    035        STATUS_NETWORK_WENT_TO_SLEEP (0x0C, "Network Went To Sleep"),
    036        STATUS_VOLTAGE_SUPPLY_LIMIT_EXCEEDED (0x0D, "Voltage supply limit exceeded"),
    037        STATUS_MODEM_CONFIG_CHANGED_WHILE_JOINING (0x11, " Modem configuration changed while joining"),
    038        STATUS_ERROR_STACK (0x80, "Stack error"),
    039        STATUS_ERROR_AP_NOT_CONNECTED (0x82, "Send/join command issued without connecting from AP"),
    040        STATUS_ERROR_AP_NOT_FOUND (0x83, "Access point not found"),
    041        STATUS_ERROR_PSK_NOT_CONFIGURED (0x84, "PSK not configured"),
    042        STATUS_ERROR_SSID_NOT_FOUND (0x87, "SSID not found"),
    043        STATUS_ERROR_FAILED_JOIN_SECURITY (0x88, "Failed to join with security enabled"),
    044        STATUS_ERROR_INVALID_CHANNEL (0x8A, "Invalid channel"),
    045        STATUS_ERROR_FAILED_JOIN_AP (0x8E, "Failed to join access point"),
    046        STATUS_UNKNOWN (0xFF, "UNKNOWN");
    047
    048        // Variables
    049        private final int id;
    050
    051        private final String description;
    052
    053        private final static HashMap<Integer, ModemStatusEvent> lookupTable = new HashMap<Integer, ModemStatusEvent>();
    054
    055        static {
    056                for (ModemStatusEvent at:values())
    057                        lookupTable.put(at.getId(), at);
    058        }
    059
    060        /**
    061         * Class constructor. Instantiates a new {@code ModemStatusEvent}
    062         * enumeration entry  with the given parameters.
    063         *
    064         * @param id Modem status ID.
    065         * @param description Modem status description.
    066         */
    067        ModemStatusEvent(int id, String description) {
    068                this.id = id;
    069                this.description = description;
    070        }
    071
    072        /**
    073         * Returns the modem status ID.
    074         *
    075         * @return The modem status ID.
    076         */
    077        public int getId() {
    078                return id;
    079        }
    080
    081        /**
    082         * Returns the modem status description.
    083         *
    084         * @return Modem status description.
    085         */
    086        public String getDescription() {
    087                return description;
    088        }
    089
    090        /**
    091         * Returns the {@code ModemStatusEvent} associated to the given ID.
    092         *
    093         * @param id ID of the {@code ModemStatusEvent} to retrieve.
    094         * @return The {@code ModemStatusEvent} associated with the given ID.
    095         */
    096        public static ModemStatusEvent get(int id) {
    097                ModemStatusEvent status = lookupTable.get(id);
    098                if (status != null)
    099                        return status;
    100                return STATUS_UNKNOWN;
    101        }
    102
    103        /*
    104         * (non-Javadoc)
    105         * @see java.lang.Enum#toString()
    106         */
    107        @Override
    108        public String toString() {
    109                return HexUtils.byteToHexString((byte)id) + ": " + description;
    110        }
    111}