public class XBeeNetwork extends Object
The network allows the discovery of remote devices in the same network as the local one and stores them.
Modifier and Type | Method and Description |
---|---|
void |
addDiscoveryListener(IDiscoveryListener listener)
Adds the given discovery listener to the list of listeners to be notified
when the discovery process is running.
|
RemoteXBeeDevice |
addRemoteDevice(RemoteXBeeDevice remoteDevice)
Adds the given remote device to the network.
|
List<RemoteXBeeDevice> |
addRemoteDevices(List<RemoteXBeeDevice> list)
Adds the given list of remote devices to the network.
|
void |
clearDeviceList()
Removes all the devices from this network.
|
RemoteXBeeDevice |
discoverDevice(String id)
Discovers and reports the first remote XBee device that matches the
supplied identifier.
|
List<RemoteXBeeDevice> |
discoverDevices(List<String> ids)
Discovers and reports all remote XBee devices that match the supplied
identifiers.
|
RemoteXBeeDevice |
getDevice(String id)
Returns the first remote device that matches the supplied identifier.
|
RemoteXBeeDevice |
getDevice(XBee16BitAddress address)
Returns the remote device already contained in the network whose 16-bit
address matches the given one.
|
RemoteXBeeDevice |
getDevice(XBee64BitAddress address)
Returns the remote device already contained in the network whose 64-bit
address matches the given one.
|
List<RemoteXBeeDevice> |
getDevices()
Returns all remote devices already contained in the network.
|
List<RemoteXBeeDevice> |
getDevices(String id)
Returns all remote devices that match the supplied identifier.
|
int |
getNumberOfDevices()
Returns the number of devices already discovered in this network.
|
boolean |
isDiscoveryRunning()
Retrieves whether the discovery process is running or not.
|
void |
removeDiscoveryListener(IDiscoveryListener listener)
Removes the given discovery listener from the list of discovery
listeners.
|
void |
removeRemoteDevice(RemoteXBeeDevice remoteDevice)
Removes the given remote XBee device from the network.
|
void |
setDiscoveryOptions(Set<DiscoveryOptions> options)
Configures the discovery options (
NO parameter) with the given
value. |
void |
setDiscoveryTimeout(long timeout)
Configures the discovery timeout (
NT parameter) with the given
value. |
void |
startDiscoveryProcess()
Starts the discovery process with the configured timeout and options.
|
void |
stopDiscoveryProcess()
Stops the discovery process if it is running.
|
String |
toString() |
public void addDiscoveryListener(IDiscoveryListener listener)
If the listener has already been included, this method does nothing.
listener
- Listener to be notified when the discovery process is
running.NullPointerException
- if listener == null
.IDiscoveryListener
,
removeDiscoveryListener(IDiscoveryListener)
public RemoteXBeeDevice addRemoteDevice(RemoteXBeeDevice remoteDevice)
Notice that this operation does not join the remote XBee device to the network; it just tells the network that it contains that device. However, the device has only been added to the device list, and may not be physically in the same network.
The way of adding a device to the network is based on the 64-bit address. If it is not configured:
false
as the result of the addition.remoteDevice
- The remote device to be added to the network.null
if
the device could not be successfully added.NullPointerException
- if RemoteDevice == null
.addRemoteDevices(List)
,
removeRemoteDevice(RemoteXBeeDevice)
,
RemoteXBeeDevice
public List<RemoteXBeeDevice> addRemoteDevices(List<RemoteXBeeDevice> list)
Notice that this operation does not join the remote XBee devices to the network; it just tells the network that it contains those devices. However, the devices have only been added to the device list, and may not be physically in the same network.
The way of adding a device to the network is based on the 64-bit address. If it is not configured:
false
as the result of the addition.list
- The list of remote devices to be added to the network.NullPointerException
- if list == null
.addRemoteDevice(RemoteXBeeDevice)
,
RemoteXBeeDevice
public void clearDeviceList()
The network will be empty after this call returns.
Notice that this does not imply removing the XBee devices from the actual XBee network; it just tells the object that the list should be empty now. Next time a discovery is performed, the list could be filled with the remote XBee devices found.
removeRemoteDevice(RemoteXBeeDevice)
public RemoteXBeeDevice discoverDevice(String id) throws XBeeException
This method blocks until the device is discovered or the configured
timeout expires. To configure the discovery timeout, use the method
setDiscoveryTimeout(long)
.
To configure the discovery options, use the
setDiscoveryOptions(Set)
method.
id
- The identifier of the device to be discovered.null
if the timeout expires and the device was not found.IllegalArgumentException
- if id.length() == 0
.InterfaceNotOpenException
- if the device is not open.NullPointerException
- if id == null
.XBeeException
- if there is an error discovering the device.discoverDevices(List)
,
getDevice(String)
,
RemoteXBeeDevice
public List<RemoteXBeeDevice> discoverDevices(List<String> ids) throws XBeeException
This method blocks until the configured timeout expires. To configure
the discovery timeout, use the method setDiscoveryTimeout(long)
.
To configure the discovery options, use the
setDiscoveryOptions(Set)
method.
ids
- List which contains the identifiers of the devices to be
discovered.IllegalArgumentException
- if ids.size() == 0
.InterfaceNotOpenException
- if the device is not open.NullPointerException
- if ids == null
.XBeeException
- if there is an error discovering the devices.discoverDevice(String)
,
RemoteXBeeDevice
public RemoteXBeeDevice getDevice(String id)
Note that this method does not perform a discovery, only returns the device that has been previously discovered.
id
- The identifier of the device to be retrieved.null
if the network does not contain any
device with that Node ID.IllegalArgumentException
- if id.length() == 0
.NullPointerException
- if id == null
.discoverDevice(String)
,
getDevices(String)
,
RemoteXBeeDevice
public RemoteXBeeDevice getDevice(XBee16BitAddress address) throws OperationNotSupportedException
Note that this method does not perform a discovery, only returns the device that has been previously discovered.
address
- The 16-bit address of the device to be retrieved.null
if it is not
found.IllegalArgumentException
- if address.equals(XBee16BitAddress.UNKNOWN_ADDRESS)
.NullPointerException
- if address == null
.OperationNotSupportedException
- if the protocol of the local XBee device is DigiMesh or Point-to-Multipoint.public RemoteXBeeDevice getDevice(XBee64BitAddress address)
Note that this method does not perform a discovery, only returns the device that has been previously discovered.
address
- The 64-bit address of the device to be retrieved.null
if it is not
found.IllegalArgumentException
- if address.equals(XBee64BitAddress.UNKNOWN_ADDRESS)
.NullPointerException
- if address == null
.public List<RemoteXBeeDevice> getDevices()
Note that this method does not perform a discovery, only returns the devices that have been previously discovered.
getDevices(String)
,
RemoteXBeeDevice
public List<RemoteXBeeDevice> getDevices(String id)
Note that this method does not perform a discovery, only returns the devices that have been previously discovered.
id
- The identifier of the devices to be retrieved.IllegalArgumentException
- if id.length() == 0
.NullPointerException
- if id == null
.getDevice(String)
,
RemoteXBeeDevice
public int getNumberOfDevices()
public boolean isDiscoveryRunning()
true
if the discovery process is running, false
otherwise.startDiscoveryProcess()
,
stopDiscoveryProcess()
public void removeDiscoveryListener(IDiscoveryListener listener)
If the listener is not included in the list, this method does nothing.
listener
- Discovery listener to remove.NullPointerException
- if listener == null
.IDiscoveryListener
,
addDiscoveryListener(IDiscoveryListener)
public void removeRemoteDevice(RemoteXBeeDevice remoteDevice)
Notice that this operation does not remove the remote XBee device from the actual XBee network; it just tells the network object that it will no longer contain that device. However, next time a discovery is performed, it could be added again automatically.
This method will check for a device that matches the 64-bit address of the provided one, if found, that device will be removed from the corresponding list. In case the 64-bit address is not defined, it will use the 16-bit address for DigiMesh and ZigBee devices.
remoteDevice
- The remote device to be removed from the network.NullPointerException
- if RemoteDevice == null
.addRemoteDevice(RemoteXBeeDevice)
,
clearDeviceList()
,
RemoteXBeeDevice
public void setDiscoveryOptions(Set<DiscoveryOptions> options) throws TimeoutException, XBeeException
NO
parameter) with the given
value.options
- New discovery options.TimeoutException
- if there is a timeout setting the discovery
options.XBeeException
- if there is any other XBee related exception.setDiscoveryTimeout(long)
,
DiscoveryOptions
public void setDiscoveryTimeout(long timeout) throws TimeoutException, XBeeException
NT
parameter) with the given
value.
Note that in some protocols, the discovery process may take longer than the value set in this method due to the network propagation time.
timeout
- New discovery timeout in milliseconds.TimeoutException
- if there is a timeout setting the discovery
timeout.XBeeException
- if there is any other XBee related exception.setDiscoveryOptions(Set)
public void startDiscoveryProcess()
To be notified every time an XBee device is discovered, add a
IDiscoveryListener
using the
addDiscoveryListener(IDiscoveryListener)
method before starting
the discovery process.
To configure the discovery timeout, use the
setDiscoveryTimeout(long)
method.
To configure the discovery options, use the
setDiscoveryOptions(Set)
method.
IllegalStateException
- if the discovery process is already running.InterfaceNotOpenException
- if the device is not open.addDiscoveryListener(IDiscoveryListener)
,
stopDiscoveryProcess()
public void stopDiscoveryProcess()
Note that DigiMesh/DigiPoint devices are blocked until the discovery time configured (NT parameter) has elapsed, so if you try to get/set any parameter during the discovery process you will receive a timeout exception.
© Copyright 2014–2014 Digi International Inc. All rights reserved.