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