Package jmri.jmrix.ieee802154.xbee
Class XBeeTrafficController
- java.lang.Object
-
- jmri.jmrix.AbstractMRTrafficController
-
- jmri.jmrix.AbstractMRNodeTrafficController
-
- jmri.jmrix.ieee802154.IEEE802154TrafficController
-
- jmri.jmrix.ieee802154.xbee.XBeeTrafficController
-
- All Implemented Interfaces:
com.digi.xbee.api.listeners.IDataReceiveListener
,com.digi.xbee.api.listeners.IModemStatusReceiveListener
,com.digi.xbee.api.listeners.IPacketReceiveListener
,IEEE802154Interface
,XBeeInterface
public class XBeeTrafficController extends IEEE802154TrafficController implements com.digi.xbee.api.listeners.IPacketReceiveListener, com.digi.xbee.api.listeners.IModemStatusReceiveListener, com.digi.xbee.api.listeners.IDataReceiveListener, XBeeInterface
Traffic Controller interface for communicating with XBee devices directly using the XBee API.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jmri.jmrix.AbstractMRTrafficController
AbstractMRTrafficController.RcvNotifier, AbstractMRTrafficController.XmtNotifier
-
-
Field Summary
-
Fields inherited from class jmri.jmrix.ieee802154.IEEE802154TrafficController
logDebug
-
Fields inherited from class jmri.jmrix.AbstractMRNodeTrafficController
curSerialNodeIndex, maxNode, minNode, nodeArray, numNodes
-
Fields inherited from class jmri.jmrix.AbstractMRTrafficController
allowUnexpectedReply, AUTORETRYSTATE, cmdListeners, connectionError, controller, flushReceiveChars, IDLESTATE, istream, listenerQueue, maxRcvExceptionCount, mCurrentMode, mCurrentState, mLastSender, msgQueue, mWaitBeforePoll, NORMALMODE, NOTIFIEDSTATE, OKSENDMSGSTATE, ostream, POLLSTATE, PROGRAMINGMODE, rcvException, rcvThread, replyInDispatch, threadStopRequest, timeoutFlag, timeouts, WAITMSGREPLYSTATE, WAITREPLYINNORMMODESTATE, WAITREPLYINPROGMODESTATE, waitTimePoll, xmtException, xmtRunnable, xmtThread
-
-
Constructor Summary
Constructors Constructor Description XBeeTrafficController()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addXBeeListener(XBeeListener l)
void
connectPort(AbstractPortController p)
Make connection to an existing PortController object.void
dataReceived(com.digi.xbee.api.models.XBeeMessage xbm)
void
deleteNode(XBeeNode node)
protected AbstractMRMessage
enterNormalMode()
Sets the system to normal mode during programming while in IDLESTATE.protected AbstractMRMessage
enterProgMode()
Set the system to programming mode.protected void
forwardMessage(AbstractMRListener client, AbstractMRMessage m)
Forward a XBeeMessage to all registered XBeeInterface listeners.protected void
forwardReply(AbstractMRListener client, AbstractMRReply r)
Forward a reply to all registered XBeeInterface listeners.protected void
forwardToPort(AbstractMRMessage m, AbstractMRListener reply)
Actually transmit the next message to the port.IEEE802154Message
getIEEE802154Message(int length)
Get a message of a specific length for filling in.AbstractNode
getNodeFromName(java.lang.String Name)
Public method to identify an XBeeNode from its node identifierAbstractNode
getNodeFromXBeeDevice(com.digi.xbee.api.RemoteXBeeDevice device)
Public method to identify an XBeeNode from its RemoteXBeeDevice object.com.digi.xbee.api.XBeeDevice
getXBee()
void
modemStatusEventReceived(com.digi.xbee.api.models.ModemStatusEvent modemStatusEvent)
IEEE802154Node
newNode()
Build a new IEEE802154 Node.protected AbstractMRReply
newReply()
Get a message of zero length.void
packetReceived(com.digi.xbee.api.packet.XBeePacket response)
protected AbstractMRMessage
pollMessage()
Invoked if it's appropriate to do low-priority polling of the command station, this should return the next message to send, or null if the TC should just sleep.protected AbstractMRListener
pollReplyHandler()
void
receiveLoop()
Handle incoming characters.void
registerNode(AbstractNode node)
Register a node.void
removeXBeeListener(XBeeListener l)
protected void
sendMessage(AbstractMRMessage m, AbstractMRListener reply)
This is invoked with messages to be forwarded to the port.void
sendXBeeMessage(XBeeMessage m, XBeeListener l)
protected void
terminate()
-
Methods inherited from class jmri.jmrix.ieee802154.IEEE802154TrafficController
addIEEE802154Listener, addTrailerToOutput, deleteNode, endOfMessage, enterProgModeDelayTime, getAdapterMemo, getNodeFromAddress, getNodeFromAddress, getNodeFromAddress, removeIEEE802154Listener, sendIEEE802154Message, setAdapterMemo, waitForStartOfReply
-
Methods inherited from class jmri.jmrix.AbstractMRNodeTrafficController
deleteNode, getMustInit, getNode, getNodeFromAddress, getNumNodes, init, setMustInit, setMustInit
-
Methods inherited from class jmri.jmrix.AbstractMRTrafficController
addConsoleListener, addHeaderToOutput, addListener, canReceive, connectionWarn, disconnectPort, distributeReply, getLastSender, getPortName, getSynchronizeRx, handleOneIncomingReply, handleTimeout, hasTimeouts, lengthOfByteStream, loadChars, newRcvNotifier, notifyMessage, notifyReply, portReadyToSend, portWarn, portWarnTCP, programmerIdle, readByteProtected, recovery, removeListener, reportReceiveLoopException, resetTimeout, setAllowUnexpectedReply, setSynchronizeRx, status, terminateThreads, transmitLoop, transmitWait, unexpectedReplyStateError, warnOnTimeout
-
-
-
-
Constructor Detail
-
XBeeTrafficController
public XBeeTrafficController()
-
-
Method Detail
-
getIEEE802154Message
public IEEE802154Message getIEEE802154Message(int length)
Get a message of a specific length for filling in.This is a default, null implementation, which must be overridden in an adapter-specific subclass.
- Overrides:
getIEEE802154Message
in classIEEE802154TrafficController
- Parameters:
length
- length for new message- Returns:
- null since this method should be over-ridden
-
newReply
protected AbstractMRReply newReply()
Get a message of zero length.- Specified by:
newReply
in classAbstractMRTrafficController
-
connectPort
public void connectPort(AbstractPortController p)
Make connection to an existing PortController object.- Overrides:
connectPort
in classAbstractMRTrafficController
- Parameters:
p
- the PortController
-
forwardToPort
protected void forwardToPort(AbstractMRMessage m, AbstractMRListener reply)
Actually transmit the next message to the port.- Overrides:
forwardToPort
in classIEEE802154TrafficController
- Parameters:
m
- the message to sendreply
- the Listener sending the message, often provided as 'this'- See Also:
AbstractMRTrafficController.sendMessage(AbstractMRMessage, AbstractMRListener)
-
pollMessage
protected AbstractMRMessage pollMessage()
Invoked if it's appropriate to do low-priority polling of the command station, this should return the next message to send, or null if the TC should just sleep.- Overrides:
pollMessage
in classIEEE802154TrafficController
- Returns:
- Formatted poll message
-
pollReplyHandler
protected AbstractMRListener pollReplyHandler()
- Overrides:
pollReplyHandler
in classIEEE802154TrafficController
-
enterProgMode
protected AbstractMRMessage enterProgMode()
Description copied from class:AbstractMRTrafficController
Set the system to programming mode.- Overrides:
enterProgMode
in classIEEE802154TrafficController
- Returns:
- any message that needs to be returned to the Command Station to change modes. If no message is needed, returns null.
- See Also:
AbstractMRTrafficController.enterNormalMode()
-
enterNormalMode
protected AbstractMRMessage enterNormalMode()
Description copied from class:AbstractMRTrafficController
Sets the system to normal mode during programming while in IDLESTATE. IfAbstractMRTrafficController.programmerIdle()
returns true, enterNormalMode() is called after a timeout.- Overrides:
enterNormalMode
in classIEEE802154TrafficController
- Returns:
- any message that needs to be returned to the Command Station to change modes. If no message is needed, returns null.
- See Also:
AbstractMRTrafficController.enterProgMode()
-
receiveLoop
public void receiveLoop()
Description copied from class:AbstractMRTrafficController
Handle incoming characters. This is a permanent loop, looking for input messages in character form on the stream connected to the PortController viaAbstractMRTrafficController.connectPort(AbstractPortController)
.Each turn of the loop is the receipt of a single message.
- Overrides:
receiveLoop
in classAbstractMRTrafficController
-
registerNode
public void registerNode(AbstractNode node)
Register a node.- Overrides:
registerNode
in classAbstractMRNodeTrafficController
- Parameters:
node
- the node object to register
-
deleteNode
public void deleteNode(XBeeNode node)
-
packetReceived
public void packetReceived(com.digi.xbee.api.packet.XBeePacket response)
- Specified by:
packetReceived
in interfacecom.digi.xbee.api.listeners.IPacketReceiveListener
-
modemStatusEventReceived
public void modemStatusEventReceived(com.digi.xbee.api.models.ModemStatusEvent modemStatusEvent)
- Specified by:
modemStatusEventReceived
in interfacecom.digi.xbee.api.listeners.IModemStatusReceiveListener
-
dataReceived
public void dataReceived(com.digi.xbee.api.models.XBeeMessage xbm)
- Specified by:
dataReceived
in interfacecom.digi.xbee.api.listeners.IDataReceiveListener
-
newNode
public IEEE802154Node newNode()
Description copied from class:IEEE802154TrafficController
Build a new IEEE802154 Node. Must be implemented by derived classes- Specified by:
newNode
in classIEEE802154TrafficController
- Returns:
- new IEEE802154Node.
-
addXBeeListener
public void addXBeeListener(XBeeListener l)
- Specified by:
addXBeeListener
in interfaceXBeeInterface
-
removeXBeeListener
public void removeXBeeListener(XBeeListener l)
- Specified by:
removeXBeeListener
in interfaceXBeeInterface
-
sendXBeeMessage
public void sendXBeeMessage(XBeeMessage m, XBeeListener l)
- Specified by:
sendXBeeMessage
in interfaceXBeeInterface
-
sendMessage
protected void sendMessage(AbstractMRMessage m, AbstractMRListener reply)
This is invoked with messages to be forwarded to the port. It queues them, then notifies the transmission thread.- Overrides:
sendMessage
in classAbstractMRTrafficController
- Parameters:
m
- the message to sendreply
- the Listener sending the message, often provided as 'this'- See Also:
AbstractMRTrafficController.forwardToPort(AbstractMRMessage, AbstractMRListener)
-
forwardMessage
protected void forwardMessage(AbstractMRListener client, AbstractMRMessage m)
Forward a XBeeMessage to all registered XBeeInterface listeners.- Overrides:
forwardMessage
in classIEEE802154TrafficController
- Parameters:
client
- abstract listener.m
- message to forward.
-
forwardReply
protected void forwardReply(AbstractMRListener client, AbstractMRReply r)
Forward a reply to all registered XBeeInterface listeners.- Overrides:
forwardReply
in classIEEE802154TrafficController
-
getNodeFromName
public AbstractNode getNodeFromName(java.lang.String Name)
Public method to identify an XBeeNode from its node identifier- Parameters:
Name
- the node identifier search string.- Returns:
- the node if found, or null otherwise.
-
getNodeFromXBeeDevice
public AbstractNode getNodeFromXBeeDevice(com.digi.xbee.api.RemoteXBeeDevice device)
Public method to identify an XBeeNode from its RemoteXBeeDevice object.- Parameters:
device
- the RemoteXBeeDevice to search for.- Returns:
- the node if found, or null otherwise.
-
getXBee
public com.digi.xbee.api.XBeeDevice getXBee()
-
terminate
protected void terminate()
- Overrides:
terminate
in classAbstractMRTrafficController
-
-