public class DataReader extends Thread
Depending on the XBee operating mode, read data is notified as is to the subscribed listeners or is parsed to a packet using the packet parser and then notified to subscribed listeners.
Thread.State, Thread.UncaughtExceptionHandler
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Constructor and Description |
---|
DataReader(IConnectionInterface connectionInterface,
OperatingMode mode,
AbstractXBeeDevice xbeeDevice)
Class constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addBluetoothDataReceiveListener(IBluetoothDataReceiveListener listener)
Adds the given data receive listener to the list of listeners that will
be notified when new data from the Bluetooth interface is received in
a User Data Relay frame.
|
void |
addDataReceiveListener(IDataReceiveListener listener)
Adds the given data receive listener to the list of listeners that will
be notified when XBee data packets are received.
|
void |
addExplicitDataReceiveListener(IExplicitDataReceiveListener listener)
Adds the given explicit data receive listener to the list of listeners
that will be notified when an explicit data packet is received.
|
void |
addIOSampleReceiveListener(IIOSampleReceiveListener listener)
Adds the given IO sample receive listener to the list of listeners that
will be notified when an IO sample packet is received.
|
void |
addIPDataReceiveListener(IIPDataReceiveListener listener)
Adds the given IP data receive listener to the list of listeners
that will be notified when a IP data packet is received.
|
void |
addMicroPythonDataReceiveListener(IMicroPythonDataReceiveListener listener)
Adds the given data receive listener to the list of listeners that will
be notified when new data from the MicroPython interface is received in
a User Data Relay frame.
|
void |
addModemStatusReceiveListener(IModemStatusReceiveListener listener)
Adds the given Modem Status receive listener to the list of listeners
that will be notified when a modem status packet is received.
|
void |
addPacketReceiveListener(IPacketReceiveListener listener)
Adds the given packet receive listener to the list of listeners that will
be notified when any XBee packet is received.
|
void |
addPacketReceiveListener(IPacketReceiveListener listener,
int frameID)
Adds the given packet receive listener to the list of listeners that will
be notified when an XBee packet with the given frame ID is received.
|
void |
addSerialDataReceiveListener(ISerialDataReceiveListener listener)
Adds the given data receive listener to the list of listeners that will
be notified when new data from the serial interface is received in
a User Data Relay frame.
|
void |
addSMSReceiveListener(ISMSReceiveListener listener)
Adds the given SMS receive listener to the list of listeners that will
be notified when an SMS packet is received.
|
void |
addUserDataRelayReceiveListener(IUserDataRelayReceiveListener listener)
Adds the given User Data Relay receive listener to the list of listeners
that will be notified when a User Data Relay packet is received.
|
RemoteXBeeDevice |
getRemoteXBeeDeviceFromPacket(XBeeAPIPacket packet)
Returns the remote XBee device from where the given package was sent
from.
|
XBeePacketsQueue |
getXBeePacketsQueue()
Returns the queue of read XBee packets.
|
boolean |
isRunning()
Returns whether this Data reader is running or not.
|
void |
removeBluetoothDataReceiveListener(IBluetoothDataReceiveListener listener)
Removes the given data receive listener from the list of data receive
listeners for the Bluetooth interface.
|
void |
removeDataReceiveListener(IDataReceiveListener listener)
Removes the given data receive listener from the list of data receive
listeners.
|
void |
removeExplicitDataReceiveListener(IExplicitDataReceiveListener listener)
Removes the given explicit data receive listener from the list of
explicit data receive listeners.
|
void |
removeIOSampleReceiveListener(IIOSampleReceiveListener listener)
Removes the given IO sample receive listener from the list of IO sample
receive listeners.
|
void |
removeIPDataReceiveListener(IIPDataReceiveListener listener)
Removes the given IP data receive listener from the list of
IP data receive listeners.
|
void |
removeMicroPythonDataReceiveListener(IMicroPythonDataReceiveListener listener)
Removes the given data receive listener from the list of data receive
listeners for the MicroPython interface.
|
void |
removeModemStatusReceiveListener(IModemStatusReceiveListener listener)
Removes the given Modem Status receive listener from the list of Modem
Status receive listeners.
|
void |
removePacketReceiveListener(IPacketReceiveListener listener)
Removes the given packet receive listener from the list of XBee packet
receive listeners.
|
void |
removeSerialDataReceiveListener(ISerialDataReceiveListener listener)
Removes the given data receive listener from the list of data receive
listeners for the serial interface.
|
void |
removeSMSReceiveListener(ISMSReceiveListener listener)
Removes the given SMS receive listener from the list of SMS receive
listeners.
|
void |
removeUserDataRelayReceiveListener(IUserDataRelayReceiveListener listener)
Removes the given User Data Relay receive listener from the list of User
Data Relay receive listeners.
|
void |
run() |
void |
setXBeeReaderMode(OperatingMode mode)
Sets the XBee operating mode of this data reader.
|
void |
stopReader()
Stops the Data reader thread.
|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
public DataReader(IConnectionInterface connectionInterface, OperatingMode mode, AbstractXBeeDevice xbeeDevice)
DataReader
object for the
given connection interface using the given XBee operating mode and XBee
device.connectionInterface
- Connection interface to read data from.mode
- XBee operating mode.xbeeDevice
- Reference to the XBee device containing this
DataReader
object.NullPointerException
- if connectionInterface == null
or
mode == null
.IllegalArgumentException
- If xbeeDevice.isRemote() == true
.IConnectionInterface
,
XBeeDevice
,
OperatingMode
public void addBluetoothDataReceiveListener(IBluetoothDataReceiveListener listener)
If the listener has been already added, this method does nothing.
listener
- Listener to be notified when new data from the Bluetooth
interface is received.NullPointerException
- if listener == null
.removeBluetoothDataReceiveListener(IBluetoothDataReceiveListener)
,
IBluetoothDataReceiveListener
public void addDataReceiveListener(IDataReceiveListener listener)
If the listener has been already added, this method does nothing.
listener
- Listener to be notified when new XBee data packets are
received.NullPointerException
- if listener == null
.removeDataReceiveListener(IDataReceiveListener)
,
IDataReceiveListener
public void addExplicitDataReceiveListener(IExplicitDataReceiveListener listener)
If the listener has been already added, this method does nothing.
listener
- Listener to be notified when new explicit data packets
are received.NullPointerException
- if listener == null
.removeExplicitDataReceiveListener(IExplicitDataReceiveListener)
,
IExplicitDataReceiveListener
public void addIOSampleReceiveListener(IIOSampleReceiveListener listener)
If the listener has been already added, this method does nothing.
listener
- Listener to be notified when new IO sample packets are
received.NullPointerException
- if listener == null
.removeIOSampleReceiveListener(IIOSampleReceiveListener)
,
IIOSampleReceiveListener
public void addIPDataReceiveListener(IIPDataReceiveListener listener)
If the listener has been already added, this method does nothing.
listener
- Listener to be notified when new IP data packets
are received.NullPointerException
- if listener == null
.removeIPDataReceiveListener(IIPDataReceiveListener)
,
IIPDataReceiveListener
public void addMicroPythonDataReceiveListener(IMicroPythonDataReceiveListener listener)
If the listener has been already added, this method does nothing.
listener
- Listener to be notified when new data from the
MicroPython interface is received.NullPointerException
- if listener == null
.removeMicroPythonDataReceiveListener(IMicroPythonDataReceiveListener)
,
IMicroPythonDataReceiveListener
public void addModemStatusReceiveListener(IModemStatusReceiveListener listener)
If the listener has been already added, this method does nothing.
listener
- Listener to be notified when new modem status packets are
received.NullPointerException
- if listener == null
.removeModemStatusReceiveListener(IModemStatusReceiveListener)
,
IModemStatusReceiveListener
public void addPacketReceiveListener(IPacketReceiveListener listener)
If the listener has been already added, this method does nothing.
listener
- Listener to be notified when any XBee packet is received.NullPointerException
- if listener == null
.addPacketReceiveListener(IPacketReceiveListener, int)
,
removePacketReceiveListener(IPacketReceiveListener)
,
IPacketReceiveListener
public void addPacketReceiveListener(IPacketReceiveListener listener, int frameID)
If the listener has been already added, this method does nothing.
listener
- Listener to be notified when an XBee packet with the
provided frame ID is received.frameID
- Frame ID for which this listener should be notified and
removed after.
Using ALL_FRAME_IDS
this listener will be
notified always and will be removed only by user request.NullPointerException
- if listener == null
.addPacketReceiveListener(IPacketReceiveListener)
,
removePacketReceiveListener(IPacketReceiveListener)
,
IPacketReceiveListener
public void addSerialDataReceiveListener(ISerialDataReceiveListener listener)
If the listener has been already added, this method does nothing.
listener
- Listener to be notified when new data from the serial
interface is received.NullPointerException
- if listener == null
.removeSerialDataReceiveListener(ISerialDataReceiveListener)
,
ISerialDataReceiveListener
public void addSMSReceiveListener(ISMSReceiveListener listener)
If the listener has been already added, this method does nothing.
listener
- Listener to be notified when new SMS packet is received.NullPointerException
- if listener == null
.removeSMSReceiveListener(ISMSReceiveListener)
,
ISMSReceiveListener
public void addUserDataRelayReceiveListener(IUserDataRelayReceiveListener listener)
If the listener has been already added, this method does nothing.
listener
- Listener to be notified when new User Data Relay packet
is received.NullPointerException
- if listener == null
.removeUserDataRelayReceiveListener(IUserDataRelayReceiveListener)
,
IUserDataRelayReceiveListener
public RemoteXBeeDevice getRemoteXBeeDeviceFromPacket(XBeeAPIPacket packet) throws XBeeException
This is for internal use only.
If the package does not contain information about the source, this
method returns null
(for example, ModemStatusPacket
).
First the device that sent the provided package is looked in the network of the local XBee device. If the remote device is not in the network, it is automatically added only if the packet contains information about the origin of the package.
packet
- The packet sent from the remote device.null
if the packet is not a known frame (see
APIFrameType
) or if it does not contain information of
the source device.NullPointerException
- if packet == null
XBeeException
- if any error occur while adding the device to the
network.public XBeePacketsQueue getXBeePacketsQueue()
XBeePacketsQueue
public boolean isRunning()
true
if the Data reader is running, false
otherwise.stopReader()
public void removeBluetoothDataReceiveListener(IBluetoothDataReceiveListener listener)
If the listener is not included in the list, this method does nothing.
listener
- Data receive listener to remove from the list.addBluetoothDataReceiveListener(IBluetoothDataReceiveListener)
,
IBluetoothDataReceiveListener
public void removeDataReceiveListener(IDataReceiveListener listener)
If the listener is not included in the list, this method does nothing.
listener
- Data receive listener to be remove from the list.addDataReceiveListener(IDataReceiveListener)
,
IDataReceiveListener
public void removeExplicitDataReceiveListener(IExplicitDataReceiveListener listener)
If the listener is not included in the list, this method does nothing.
listener
- Explicit data receive listener to remove from the list.addExplicitDataReceiveListener(IExplicitDataReceiveListener)
,
IExplicitDataReceiveListener
public void removeIOSampleReceiveListener(IIOSampleReceiveListener listener)
If the listener is not included in the list, this method does nothing.
listener
- IO sample receive listener to remove from the list.addIOSampleReceiveListener(IIOSampleReceiveListener)
,
IIOSampleReceiveListener
public void removeIPDataReceiveListener(IIPDataReceiveListener listener)
If the listener is not included in the list, this method does nothing.
listener
- IP data receive listener to remove from the list.addIPDataReceiveListener(IIPDataReceiveListener)
,
IIPDataReceiveListener
public void removeMicroPythonDataReceiveListener(IMicroPythonDataReceiveListener listener)
If the listener is not included in the list, this method does nothing.
listener
- Data receive listener to remove from the list.addMicroPythonDataReceiveListener(IMicroPythonDataReceiveListener)
,
IMicroPythonDataReceiveListener
public void removeModemStatusReceiveListener(IModemStatusReceiveListener listener)
If the listener is not included in the list, this method does nothing.
listener
- Modem Status receive listener to remove from the list.addModemStatusReceiveListener(IModemStatusReceiveListener)
,
IModemStatusReceiveListener
public void removePacketReceiveListener(IPacketReceiveListener listener)
If the listener is not included in the list, this method does nothing.
listener
- Packet receive listener to remove from the list.addPacketReceiveListener(IPacketReceiveListener)
,
addPacketReceiveListener(IPacketReceiveListener, int)
,
IPacketReceiveListener
public void removeSerialDataReceiveListener(ISerialDataReceiveListener listener)
If the listener is not included in the list, this method does nothing.
listener
- Data receive listener to remove from the list.addSerialDataReceiveListener(ISerialDataReceiveListener)
,
ISerialDataReceiveListener
public void removeSMSReceiveListener(ISMSReceiveListener listener)
If the listener is not included in the list, this method does nothing.
listener
- SMS receive listener to remove from the list.addSMSReceiveListener(ISMSReceiveListener)
,
ISMSReceiveListener
public void removeUserDataRelayReceiveListener(IUserDataRelayReceiveListener listener)
If the listener is not included in the list, this method does nothing.
listener
- User Data Relay receive listener to remove from the list.addUserDataRelayReceiveListener(IUserDataRelayReceiveListener)
,
IUserDataRelayReceiveListener
public void setXBeeReaderMode(OperatingMode mode)
mode
- New XBee operating mode.NullPointerException
- if mode == null
.OperatingMode
public void stopReader()
isRunning()
© Copyright 2014 - 2024 Digi International Inc. All rights reserved.