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