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.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.listeners.IExplicitDataReceiveListener; 021import com.digi.xbee.api.models.APIOutputMode; 022import com.digi.xbee.api.models.ExplicitXBeeMessage; 023import com.digi.xbee.api.models.XBee64BitAddress; 024import com.digi.xbee.api.models.XBeeProtocol; 025 026/** 027 * This class represents a local DigiMesh device. 028 * 029 * @see XBeeDevice 030 * @see DigiPointDevice 031 * @see Raw802Device 032 * @see ZigBeeDevice 033 */ 034public class DigiMeshDevice extends XBeeDevice { 035 036 /** 037 * Class constructor. Instantiates a new {@code DigiMeshDevice} object in the 038 * given port name and baud rate. 039 * 040 * @param port Serial port name where DigiMesh device is attached to. 041 * @param baudRate Serial port baud rate to communicate with the device. 042 * Other connection parameters will be set as default (8 043 * data bits, 1 stop bit, no parity, no flow control). 044 * 045 * @throws IllegalArgumentException if {@code baudRate < 0}. 046 * @throws NullPointerException if {@code port == null}. 047 */ 048 public DigiMeshDevice(String port, int baudRate) { 049 this(XBee.createConnectiontionInterface(port, baudRate)); 050 } 051 052 /** 053 * Class constructor. Instantiates a new {@code DigiMeshDevice} object in the 054 * given serial port name and settings. 055 * 056 * @param port Serial port name where DigiMesh device is attached to. 057 * @param baudRate Serial port baud rate to communicate with the device. 058 * @param dataBits Serial port data bits. 059 * @param stopBits Serial port data bits. 060 * @param parity Serial port data bits. 061 * @param flowControl Serial port data bits. 062 * 063 * @throws IllegalArgumentException if {@code baudRate < 0} or 064 * if {@code dataBits < 0} or 065 * if {@code stopBits < 0} or 066 * if {@code parity < 0} or 067 * if {@code flowControl < 0}. 068 * @throws NullPointerException if {@code port == null}. 069 */ 070 public DigiMeshDevice(String port, int baudRate, int dataBits, int stopBits, int parity, int flowControl) { 071 this(port, new SerialPortParameters(baudRate, dataBits, stopBits, parity, flowControl)); 072 } 073 074 /** 075 * Class constructor. Instantiates a new {@code DigiMeshDevice} object in the 076 * given serial port name and parameters. 077 * 078 * @param port Serial port name where DigiMesh device is attached to. 079 * @param serialPortParameters Object containing the serial port parameters. 080 * 081 * @throws NullPointerException if {@code port == null} or 082 * if {@code serialPortParameters == null}. 083 * 084 * @see SerialPortParameters 085 */ 086 public DigiMeshDevice(String port, SerialPortParameters serialPortParameters) { 087 this(XBee.createConnectiontionInterface(port, serialPortParameters)); 088 } 089 090 /** 091 * Class constructor. Instantiates a new {@code DigiMeshDevice} object with the 092 * given connection interface. 093 * 094 * @param connectionInterface The connection interface with the physical 095 * DigiMesh device. 096 * 097 * @throws NullPointerException if {@code connectionInterface == null} 098 * 099 * @see IConnectionInterface 100 */ 101 public DigiMeshDevice(IConnectionInterface connectionInterface) { 102 super(connectionInterface); 103 } 104 105 /* 106 * (non-Javadoc) 107 * @see com.digi.xbee.api.XBeeDevice#open() 108 */ 109 @Override 110 public void open() throws XBeeException { 111 super.open(); 112 if (xbeeProtocol != XBeeProtocol.DIGI_MESH) 113 throw new XBeeDeviceException("XBee device is not a " + getXBeeProtocol().getDescription() + " device, it is a " + xbeeProtocol.getDescription() + " device."); 114 } 115 116 /* 117 * (non-Javadoc) 118 * @see com.digi.xbee.api.XBeeDevice#getNetwork() 119 */ 120 @Override 121 public XBeeNetwork getNetwork() { 122 if (!isOpen()) 123 throw new InterfaceNotOpenException(); 124 if (network == null) 125 network = new DigiMeshNetwork(this); 126 return network; 127 } 128 129 /* 130 * (non-Javadoc) 131 * @see com.digi.xbee.api.XBeeDevice#getXBeeProtocol() 132 */ 133 @Override 134 public XBeeProtocol getXBeeProtocol() { 135 return XBeeProtocol.DIGI_MESH; 136 } 137 138 /* 139 * (non-Javadoc) 140 * @see com.digi.xbee.api.XBeeDevice#sendDataAsync(com.digi.xbee.api.models.XBee64BitAddress, byte[]) 141 */ 142 @Override 143 public void sendDataAsync(XBee64BitAddress address, byte[] data) throws XBeeException { 144 super.sendDataAsync(address, data); 145 } 146 147 /* 148 * (non-Javadoc) 149 * @see com.digi.xbee.api.XBeeDevice#sendData(com.digi.xbee.api.models.XBee64BitAddress, byte[]) 150 */ 151 @Override 152 public void sendData(XBee64BitAddress address, byte[] data) throws TimeoutException, XBeeException { 153 super.sendData(address, data); 154 } 155 156 /* 157 * (non-Javadoc) 158 * @see com.digi.xbee.api.XBeeDevice#readExplicitData() 159 */ 160 @Override 161 public ExplicitXBeeMessage readExplicitData() { 162 return super.readExplicitData(); 163 } 164 165 /* 166 * (non-Javadoc) 167 * @see com.digi.xbee.api.XBeeDevice#readExplicitData(int) 168 */ 169 @Override 170 public ExplicitXBeeMessage readExplicitData(int timeout) { 171 return super.readExplicitData(timeout); 172 } 173 174 /* 175 * (non-Javadoc) 176 * @see com.digi.xbee.api.XBeeDevice#readExplicitDataFrom(com.digi.xbee.api.RemoteXBeeDevice) 177 */ 178 @Override 179 public ExplicitXBeeMessage readExplicitDataFrom(RemoteXBeeDevice remoteXBeeDevice) { 180 return super.readExplicitDataFrom(remoteXBeeDevice); 181 } 182 183 /* 184 * (non-Javadoc) 185 * @see com.digi.xbee.api.XBeeDevice#readExplicitDataFrom(com.digi.xbee.api.RemoteXBeeDevice, int) 186 */ 187 @Override 188 public ExplicitXBeeMessage readExplicitDataFrom( 189 RemoteXBeeDevice remoteXBeeDevice, int timeout) { 190 return super.readExplicitDataFrom(remoteXBeeDevice, timeout); 191 } 192 193 /* 194 * (non-Javadoc) 195 * @see com.digi.xbee.api.AbstractXBeeDevice#addExplicitDataListener(com.digi.xbee.api.listeners.IExplicitDataReceiveListener) 196 */ 197 @Override 198 public void addExplicitDataListener(IExplicitDataReceiveListener listener) { 199 super.addExplicitDataListener(listener); 200 } 201 202 /* 203 * (non-Javadoc) 204 * @see com.digi.xbee.api.AbstractXBeeDevice#removeExplicitDataListener(com.digi.xbee.api.listeners.IExplicitDataReceiveListener) 205 */ 206 @Override 207 public void removeExplicitDataListener(IExplicitDataReceiveListener listener) { 208 super.removeExplicitDataListener(listener); 209 } 210 211 /* 212 * (non-Javadoc) 213 * @see com.digi.xbee.api.XBeeDevice#getAPIOutputMode() 214 */ 215 @Override 216 public APIOutputMode getAPIOutputMode() throws TimeoutException, XBeeException { 217 return super.getAPIOutputMode(); 218 } 219 220 /* 221 * (non-Javadoc) 222 * @see com.digi.xbee.api.XBeeDevice#setAPIOutputMode(com.digi.xbee.api.models.APIOutputMode) 223 */ 224 @Override 225 public void setAPIOutputMode(APIOutputMode apiOutputMode) throws TimeoutException, XBeeException { 226 super.setAPIOutputMode(apiOutputMode); 227 } 228 229 /* 230 * (non-Javadoc) 231 * @see com.digi.xbee.api.XBeeDevice#sendExplicitData(com.digi.xbee.api.RemoteXBeeDevice, int, int, int, int, byte[]) 232 */ 233 @Override 234 public void sendExplicitData(RemoteXBeeDevice remoteXBeeDevice, int sourceEndpoint, int destEndpoint, int clusterID, 235 int profileID, byte[] data) throws TimeoutException, XBeeException { 236 super.sendExplicitData(remoteXBeeDevice, sourceEndpoint, destEndpoint, clusterID, profileID, data); 237 } 238 239 /* 240 * (non-Javadoc) 241 * @see com.digi.xbee.api.XBeeDevice#sendExplicitData(com.digi.xbee.api.models.XBee64BitAddress, int, int, int, int, byte[]) 242 */ 243 @Override 244 public void sendExplicitData(XBee64BitAddress address, int sourceEndpoint, int destEndpoint, int clusterID, 245 int profileID, byte[] data) throws TimeoutException, XBeeException { 246 super.sendExplicitData(address, sourceEndpoint, destEndpoint, clusterID, profileID, data); 247 } 248 249 /* 250 * (non-Javadoc) 251 * @see com.digi.xbee.api.XBeeDevice#sendBroadcastExplicitData(int, int, int, int, byte[]) 252 */ 253 @Override 254 public void sendBroadcastExplicitData(int sourceEndpoint, int destEndpoint, int clusterID, int profileID, 255 byte[] data) throws TimeoutException, XBeeException { 256 super.sendBroadcastExplicitData(sourceEndpoint, destEndpoint, clusterID, profileID, data); 257 } 258 259 /* 260 * (non-Javadoc) 261 * @see com.digi.xbee.api.XBeeDevice#sendExplicitDataAsync(com.digi.xbee.api.RemoteXBeeDevice, int, int, int, int, byte[]) 262 */ 263 @Override 264 public void sendExplicitDataAsync(RemoteXBeeDevice xbeeDevice, int sourceEndpoint, int destEndpoint, int clusterID, 265 int profileID, byte[] data) throws XBeeException { 266 super.sendExplicitDataAsync(xbeeDevice, sourceEndpoint, destEndpoint, clusterID, profileID, data); 267 } 268 269 /* 270 * (non-Javadoc) 271 * @see com.digi.xbee.api.XBeeDevice#sendExplicitDataAsync(com.digi.xbee.api.models.XBee64BitAddress, int, int, int, int, byte[]) 272 */ 273 @Override 274 public void sendExplicitDataAsync(XBee64BitAddress address, int sourceEndpoint, int destEndpoint, int clusterID, 275 int profileID, byte[] data) throws XBeeException { 276 super.sendExplicitDataAsync(address, sourceEndpoint, destEndpoint, clusterID, profileID, data); 277 } 278}