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;
017
018import java.net.Inet6Address;
019
020import com.digi.xbee.api.exceptions.TimeoutException;
021import com.digi.xbee.api.exceptions.XBeeException;
022import com.digi.xbee.api.models.AssociationIndicationStatus;
023import com.digi.xbee.api.models.XBee16BitAddress;
024import com.digi.xbee.api.models.XBee64BitAddress;
025import com.digi.xbee.api.models.XBeeProtocol;
026
027/**
028 * This class represents a remote ZigBee device.
029 * 
030 * @see RemoteDigiMeshDevice
031 * @see RemoteDigiPointDevice
032 * @see RemoteRaw802Device
033 * @see RemoteThreadDevice
034 * @see RemoteXBeeDevice
035 */
036public class RemoteZigBeeDevice extends RemoteXBeeDevice {
037
038        // Constants
039        private static final String OPERATION_EXCEPTION = "Operation not supported in ZigBee protocol.";
040        
041        /**
042         * Class constructor. Instantiates a new {@code RemoteZigBeeDevice} object 
043         * with the given local {@code ZigBeeDevice} which contains the connection 
044         * interface to be used.
045         * 
046         * @param localXBeeDevice The local ZigBee device that will behave as 
047         *                        connection interface to communicate with this 
048         *                        remote ZigBee device.
049         * @param addr64 The 64-bit address to identify this remote ZigBee device.
050         * 
051         * @throws IllegalArgumentException if {@code localXBeeDevice.isRemote() == true}.
052         * @throws NullPointerException if {@code localXBeeDevice == null} or
053         *                              if {@code addr64 == null}.
054         * 
055         * @see com.digi.xbee.api.models.XBee64BitAddress
056         */
057        public RemoteZigBeeDevice(ZigBeeDevice localXBeeDevice, XBee64BitAddress addr64) {
058                super(localXBeeDevice, addr64);
059        }
060        
061        /**
062         * Class constructor. Instantiates a new {@code RemoteZigBeeDevice} object 
063         * with the given local {@code XBeeDevice} which contains the connection 
064         * interface to be used.
065         * 
066         * @param localXBeeDevice The local XBee device that will behave as 
067         *                        connection interface to communicate with this 
068         *                        remote ZigBee device.
069         * @param addr64 The 64-bit address to identify this remote ZigBee device.
070         * 
071         * @throws IllegalArgumentException if {@code localXBeeDevice.isRemote() == true} or 
072         *                                  if {@code localXBeeDevice.getXBeeProtocol() != XBeeProtocol.ZIGBEE}.
073         * @throws NullPointerException if {@code localXBeeDevice == null} or
074         *                              if {@code addr64 == null}.
075         * 
076         * @see com.digi.xbee.api.models.XBee64BitAddress
077         */
078        public RemoteZigBeeDevice(AbstractXBeeDevice localXBeeDevice, XBee64BitAddress addr64) {
079                super(localXBeeDevice, addr64);
080                
081                // Verify the local device has ZigBee protocol.
082                if (localXBeeDevice.getXBeeProtocol() != XBeeProtocol.ZIGBEE)
083                        throw new IllegalArgumentException("The protocol of the local XBee device is not " + XBeeProtocol.ZIGBEE.getDescription() + ".");
084        }
085        
086        /**
087         * Class constructor. Instantiates a new {@code RemoteZigBeeDevice} object 
088         * with the given local {@code XBeeDevice} which contains the connection 
089         * interface to be used.
090         * 
091         * @param localXBeeDevice The local XBee device that will behave as 
092         *                        connection interface to communicate with this 
093         *                        remote ZigBee device.
094         * @param addr64 The 64-bit address to identify this remote ZigBee device.
095         * @param addr16 The 16-bit address to identify this remote ZigBee device. 
096         *               It might be {@code null}.
097         * @param ni The node identifier of this remote ZigBee device. It might be 
098         *           {@code null}.
099         * 
100         * @throws IllegalArgumentException if {@code localXBeeDevice.isRemote() == true} or 
101         *                                  if {@code localXBeeDevice.getXBeeProtocol() != XBeeProtocol.ZIGBEE}.
102         * @throws NullPointerException if {@code localXBeeDevice == null} or
103         *                              if {@code addr64 == null}.
104         * 
105         * @see com.digi.xbee.api.models.XBee16BitAddress
106         * @see com.digi.xbee.api.models.XBee64BitAddress
107         */
108        public RemoteZigBeeDevice(AbstractXBeeDevice localXBeeDevice, XBee64BitAddress addr64, 
109                        XBee16BitAddress addr16, String ni) {
110                super(localXBeeDevice, addr64, addr16, ni);
111                
112                // Verify the local device has ZigBee protocol.
113                if (localXBeeDevice.getXBeeProtocol() != XBeeProtocol.ZIGBEE)
114                        throw new IllegalArgumentException("The protocol of the local XBee device is not " + XBeeProtocol.ZIGBEE.getDescription() + ".");
115        }
116        
117        /*
118         * (non-Javadoc)
119         * @see com.digi.xbee.api.AbstractXBeeDevice#getXBeeProtocol()
120         */
121        @Override
122        public XBeeProtocol getXBeeProtocol() {
123                return XBeeProtocol.ZIGBEE;
124        }
125        
126        /*
127         * (non-Javadoc)
128         * @see com.digi.xbee.api.AbstractXBeeDevice#getAssociationIndicationStatus()
129         */
130        @Override
131        public AssociationIndicationStatus getAssociationIndicationStatus() throws TimeoutException, XBeeException {
132                return super.getAssociationIndicationStatus();
133        }
134        
135        /*
136         * (non-Javadoc)
137         * @see com.digi.xbee.api.AbstractXBeeDevice#forceDisassociate()
138         */
139        @Override
140        public void forceDisassociate() throws TimeoutException, XBeeException {
141                super.forceDisassociate();
142        }
143        
144        /**
145         * @deprecated ZigBee protocol does not have an associated IPv6 address.
146         */
147        @Override
148        public Inet6Address getIPv6Address() {
149                // ZigBee protocol does not have IPv6 address.
150                return null;
151        }
152        
153        /**
154         * @deprecated Operation not supported in ZigBee protocol. This method
155         *             will raise an {@link UnsupportedOperationException}.
156         */
157        @Override
158        public Inet6Address getIPv6DestinationAddress()
159                        throws TimeoutException, XBeeException {
160                // Not supported in ZigBee.
161                throw new UnsupportedOperationException(OPERATION_EXCEPTION);
162        }
163        
164        /**
165         * @deprecated Operation not supported in ZigBee protocol. This method
166         *             will raise an {@link UnsupportedOperationException}.
167         */
168        @Override
169        public void setIPv6DestinationAddress(Inet6Address ipv6Address)
170                        throws TimeoutException, XBeeException {
171                // Not supported in ZigBee.
172                throw new UnsupportedOperationException(OPERATION_EXCEPTION);
173        }
174}