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 802.15.4 device. 029 * 030 * @see RemoteDigiMeshDevice 031 * @see RemoteDigiPointDevice 032 * @see RemoteThreadDevice 033 * @see RemoteXBeeDevice 034 * @see RemoteZigBeeDevice 035 */ 036public class RemoteRaw802Device extends RemoteXBeeDevice { 037 038 // Constants 039 private static final String OPERATION_EXCEPTION = "Operation not supported in 802.15.4 protocol."; 040 041 /** 042 * Class constructor. Instantiates a new {@code RemoteRaw802Device} object 043 * with the given local {@code Raw802Device} which contains the connection 044 * interface to be used. 045 * 046 * @param localXBeeDevice The local 802.15.4 device that will behave as 047 * connection interface to communicate with this 048 * remote 802.15.4 device. 049 * @param addr64 The 64-bit address to identify this remote 802.15.4 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 RemoteRaw802Device(Raw802Device localXBeeDevice, XBee64BitAddress addr64) { 058 super(localXBeeDevice, addr64); 059 } 060 061 /** 062 * Class constructor. Instantiates a new {@code RemoteRaw802Device} 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 802.15.4 device. 069 * @param addr64 The 64-bit address to identify this remote 802.15.4 device. 070 * @param addr16 The 16-bit address to identify this remote 802.15.4 device. 071 * It might be {@code null}. 072 * @param id The node identifier of this remote 802.15.4 device. It might be 073 * {@code null}. 074 * 075 * @throws IllegalArgumentException if {@code localXBeeDevice.isRemote() == true} or 076 * if {@code localXBeeDevice.getXBeeProtocol() != XBeeProtocol.RAW_802_15_4} 077 * @throws NullPointerException if {@code localXBeeDevice == null} or 078 * if {@code addr64 == null}. 079 * 080 * @see com.digi.xbee.api.models.XBee16BitAddress 081 * @see com.digi.xbee.api.models.XBee64BitAddress 082 */ 083 public RemoteRaw802Device(AbstractXBeeDevice localXBeeDevice, XBee64BitAddress addr64, 084 XBee16BitAddress addr16, String id) { 085 super(localXBeeDevice, addr64, addr16, id); 086 087 // Verify the local device has 802.15.4 protocol. 088 if (localXBeeDevice.getXBeeProtocol() != XBeeProtocol.RAW_802_15_4) 089 throw new IllegalArgumentException("The protocol of the local XBee device is not " + XBeeProtocol.RAW_802_15_4.getDescription() + "."); 090 } 091 092 /** 093 * Class constructor. Instantiates a new {@code RemoteRaw802Device} object 094 * with the given local {@code Raw802Device} which contains the connection 095 * interface to be used. 096 * 097 * @param localXBeeDevice The local 802.15.4 device that will behave as 098 * connection interface to communicate with this 099 * remote 802.15.4 device. 100 * @param addr16 The 16-bit address to identify this remote 802.15.4 101 * device. 102 * 103 * @throws NullPointerException if {@code localXBeeDevice == null} or 104 * if {@code addr16 == null}. 105 * 106 * @see com.digi.xbee.api.models.XBee16BitAddress 107 */ 108 public RemoteRaw802Device(Raw802Device localXBeeDevice, XBee16BitAddress addr16) { 109 super(localXBeeDevice, XBee64BitAddress.UNKNOWN_ADDRESS); 110 111 this.xbee16BitAddress = addr16; 112 } 113 114 /** 115 * Class constructor. Instantiates a new {@code RemoteRaw802Device} object 116 * interface to be used. 117 * 118 * @param localXBeeDevice The local 802.15.4 device that will behave as 119 * connection interface to communicate with this 120 * remote 802.15.4 device. 121 * @param addr16 The 16-bit address to identify this remote 802.15.4 122 * device. 123 * 124 * @throws IllegalArgumentException if {@code localXBeeDevice.getXBeeProtocol() != XBeeProtocol.RAW_802_15_4}. 125 * @throws NullPointerException if {@code localXBeeDevice == null} or 126 * if {@code addr16 == null}. 127 * 128 * @see com.digi.xbee.api.models.XBee16BitAddress 129 */ 130 public RemoteRaw802Device(AbstractXBeeDevice localXBeeDevice, XBee16BitAddress addr16) { 131 super(localXBeeDevice, XBee64BitAddress.UNKNOWN_ADDRESS); 132 133 // Verify the local device has 802.15.4 protocol. 134 if (localXBeeDevice.getXBeeProtocol() != XBeeProtocol.RAW_802_15_4) 135 throw new IllegalArgumentException("The protocol of the local XBee device is not " + XBeeProtocol.RAW_802_15_4.getDescription() + "."); 136 137 this.xbee16BitAddress = addr16; 138 } 139 140 /** 141 * Sets the XBee64BitAddress of this remote 802.15.4 device. 142 * 143 * @param addr64 The 64-bit address to be set to the device. 144 * 145 * @see com.digi.xbee.api.models.XBee64BitAddress 146 */ 147 public void set64BitAddress(XBee64BitAddress addr64) { 148 this.xbee64BitAddress = addr64; 149 } 150 151 /* 152 * (non-Javadoc) 153 * @see com.digi.xbee.api.AbstractXBeeDevice#getXBeeProtocol() 154 */ 155 @Override 156 public XBeeProtocol getXBeeProtocol() { 157 return XBeeProtocol.RAW_802_15_4; 158 } 159 160 /* 161 * (non-Javadoc) 162 * @see com.digi.xbee.api.AbstractXBeeDevice#set16BitAddress(com.digi.xbee.api.models.XBee16BitAddress) 163 */ 164 @Override 165 public void set16BitAddress(XBee16BitAddress xbee16BitAddress) throws TimeoutException, XBeeException { 166 super.set16BitAddress(xbee16BitAddress); 167 } 168 169 /* 170 * (non-Javadoc) 171 * @see com.digi.xbee.api.AbstractXBeeDevice#getAssociationIndicationStatus() 172 */ 173 @Override 174 public AssociationIndicationStatus getAssociationIndicationStatus() throws TimeoutException, XBeeException { 175 return super.getAssociationIndicationStatus(); 176 } 177 178 /** 179 * @deprecated 802.15.4 protocol does not have an associated IPv6 address. 180 */ 181 @Override 182 public Inet6Address getIPv6Address() { 183 // 802.15.4 protocol does not have IPv6 address. 184 return null; 185 } 186 187 /** 188 * @deprecated Operation not supported in 802.15.4 protocol. This method 189 * will raise an {@link UnsupportedOperationException}. 190 */ 191 @Override 192 public Inet6Address getIPv6DestinationAddress() 193 throws TimeoutException, XBeeException { 194 // Not supported in 802.15.4. 195 throw new UnsupportedOperationException(OPERATION_EXCEPTION); 196 } 197 198 /** 199 * @deprecated Operation not supported in 802.15.4 protocol. This method 200 * will raise an {@link UnsupportedOperationException}. 201 */ 202 @Override 203 public void setIPv6DestinationAddress(Inet6Address ipv6Address) 204 throws TimeoutException, XBeeException { 205 // Not supported in 802.15.4. 206 throw new UnsupportedOperationException(OPERATION_EXCEPTION); 207 } 208}