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