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