    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;
    013
    014import com.digi.xbee.api.connection.IConnectionInterface;
    015import com.digi.xbee.api.connection.serial.SerialPortParameters;
    016import com.digi.xbee.api.exceptions.InterfaceNotOpenException;
    017import com.digi.xbee.api.exceptions.TimeoutException;
    018import com.digi.xbee.api.exceptions.XBeeDeviceException;
    019import com.digi.xbee.api.exceptions.XBeeException;
    020import com.digi.xbee.api.models.AssociationIndicationStatus;
    021import com.digi.xbee.api.models.XBee16BitAddress;
    022import com.digi.xbee.api.models.XBee64BitAddress;
    023import com.digi.xbee.api.models.XBeeProtocol;
    024
    025/**
    026 * This class represents a local ZigBee device.
    027 *
    028 * @see XBeeDevice
    029 * @see DigiMeshDevice
    030 * @see DigiPointDevice
    031 * @see Raw802Device
    032 */
    033public class ZigBeeDevice extends XBeeDevice {
    034
    035        /**
    036         * Class constructor. Instantiates a new {@code ZigBeeDevice} object in the
    037         * given port name and baud rate.
    038         *
    039         * @param port Serial port name where ZigBee device is attached to.
    040         * @param baudRate Serial port baud rate to communicate with the device.
    041         *                 Other connection parameters will be set as default (8
    042         *                 data bits, 1 stop bit, no parity, no flow control).
    043         *
    044         * @throws IllegalArgumentException if {@code baudRate < 0}.
    045         * @throws NullPointerException if {@code port == null}.
    046         */
    047        public ZigBeeDevice(String port, int baudRate) {
    048                this(XBee.createConnectiontionInterface(port, baudRate));
    049        }
    050
    051        /**
    052         * Class constructor. Instantiates a new {@code ZigBeeDevice} object in the
    053         * given serial port name and settings.
    054         *
    055         * @param port Serial port name where ZigBee device is attached to.
    056         * @param baudRate Serial port baud rate to communicate with the device.
    057         * @param dataBits Serial port data bits.
    058         * @param stopBits Serial port data bits.
    059         * @param parity Serial port data bits.
    060         * @param flowControl Serial port data bits.
    061         *
    062         * @throws IllegalArgumentException if {@code baudRate < 0} or
    063         *                                  if {@code dataBits < 0} or
    064         *                                  if {@code stopBits < 0} or
    065         *                                  if {@code parity < 0} or
    066         *                                  if {@code flowControl < 0}.
    067         * @throws NullPointerException if {@code port == null}.
    068         */
    069        public ZigBeeDevice(String port, int baudRate, int dataBits, int stopBits, int parity, int flowControl) {
    070                this(port, new SerialPortParameters(baudRate, dataBits, stopBits, parity, flowControl));
    071        }
    072
    073        /**
    074         * Class constructor. Instantiates a new {@code ZigBeeDevice} object in the
    075         * given serial port name and parameters.
    076         *
    077         * @param port Serial port name where ZigBee device is attached to.
    078         * @param serialPortParameters Object containing the serial port parameters.
    079         *
    080         * @throws NullPointerException if {@code port == null} or
    081         *                              if {@code serialPortParameters == null}.
    082         *
    083         * @see com.digi.xbee.api.connection.serial.SerialPortParameters
    084         */
    085        public ZigBeeDevice(String port, SerialPortParameters serialPortParameters) {
    086                this(XBee.createConnectiontionInterface(port, serialPortParameters));
    087        }
    088
    089        /**
    090         * Class constructor. Instantiates a new {@code ZigBeeDevice} object with the
    091         * given connection interface.
    092         *
    093         * @param connectionInterface The connection interface with the physical
    094         *                            ZigBee device.
    095         *
    096         * @throws NullPointerException if {@code connectionInterface == null}
    097         *
    098         * @see com.digi.xbee.api.connection.IConnectionInterface
    099         */
    100        public ZigBeeDevice(IConnectionInterface connectionInterface) {
    101                super(connectionInterface);
    102        }
    103
    104        /*
    105         * (non-Javadoc)
    106         * @see com.digi.xbee.api.XBeeDevice#open()
    107         */
    108        @Override
    109        public void open() throws XBeeException {
    110                super.open();
    111                if (xbeeProtocol != XBeeProtocol.ZIGBEE)
    112                        throw new XBeeDeviceException("XBee device is not a " + getXBeeProtocol().getDescription() + " device, it is a " + xbeeProtocol.getDescription() + " device.");
    113        }
    114
    115        /*
    116         * (non-Javadoc)
    117         * @see com.digi.xbee.api.XBeeDevice#getNetwork()
    118         */
    119        @Override
    120        public XBeeNetwork getNetwork() {
    121                if (!isOpen())
    122                        throw new InterfaceNotOpenException();
    123                if (network == null)
    124                        network = new ZigBeeNetwork(this);
    125                return network;
    126        }
    127
    128        /*
    129         * (non-Javadoc)
    130         * @see com.digi.xbee.api.XBeeDevice#getXBeeProtocol()
    131         */
    132        @Override
    133        public XBeeProtocol getXBeeProtocol() {
    134                return XBeeProtocol.ZIGBEE;
    135        }
    136
    137        /*
    138         * (non-Javadoc)
    139         * @see com.digi.xbee.api.XBeeDevice#sendDataAsync(com.digi.xbee.api.models.XBee64BitAddress, com.digi.xbee.api.models.XBee16BitAddress, byte[])
    140         */
    141        @Override
    142        public void sendDataAsync(XBee64BitAddress address64Bit, XBee16BitAddress address16bit, byte[] data) throws XBeeException {
    143                super.sendDataAsync(address64Bit, address16bit, data);
    144        }
    145
    146        /*
    147         * (non-Javadoc)
    148         * @see com.digi.xbee.api.XBeeDevice#sendData(com.digi.xbee.api.models.XBee64BitAddress, com.digi.xbee.api.models.XBee16BitAddress, byte[])
    149         */
    150        @Override
    151        public void sendData(XBee64BitAddress address64Bit, XBee16BitAddress address16bit, byte[] data) throws TimeoutException, XBeeException {
    152                super.sendData(address64Bit, address16bit, data);
    153        }
    154
    155        /*
    156         * (non-Javadoc)
    157         * @see com.digi.xbee.api.AbstractXBeeDevice#getAssociationIndicationStatus()
    158         */
    159        @Override
    160        public AssociationIndicationStatus getAssociationIndicationStatus() throws TimeoutException, XBeeException {
    161                return super.getAssociationIndicationStatus();
    162        }
    163
    164        /*
    165         * (non-Javadoc)
    166         * @see com.digi.xbee.api.AbstractXBeeDevice#forceDisassociate()
    167         */
    168        @Override
    169        public void forceDisassociate() throws TimeoutException, XBeeException {
    170                super.forceDisassociate();
    171        }
    172}