Package jmri.jmrix.dccpp
Class DCCppTrafficController
- java.lang.Object
-
- jmri.jmrix.AbstractMRTrafficController
-
- jmri.jmrix.dccpp.DCCppTrafficController
-
- All Implemented Interfaces:
DCCppInterface
- Direct Known Subclasses:
DCCppPacketizer
public abstract class DCCppTrafficController extends AbstractMRTrafficController implements DCCppInterface
Abstract base class for implementations of DCCppInterface.This provides just the basic interface, plus the "" static method for locating the local implementation.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jmri.jmrix.AbstractMRTrafficController
AbstractMRTrafficController.RcvNotifier, AbstractMRTrafficController.XmtNotifier
-
-
Field Summary
Fields Modifier and Type Field Description boolean
anyReceived
(package private) java.util.concurrent.LinkedBlockingQueue<DCCppListener>
highPriorityListeners
(package private) java.util.concurrent.LinkedBlockingQueue<DCCppMessage>
highPriorityQueue
(package private) DCCppCommandStation
mCommandStation
Reference to the command station in communication here.protected java.util.HashMap<DCCppListener,java.lang.Integer>
mListenerMasks
(package private) DCCppSystemConnectionMemo
mMemo
Reference to the system connection memo.int
startUpDelay
-
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
-
Fields inherited from interface jmri.jmrix.dccpp.DCCppInterface
ALL, COMMINFO, CONSIST, CS_INFO, FEEDBACK, INTERFACE, PROGRAMMING, THROTTLE
-
-
Constructor Summary
Constructors Constructor Description DCCppTrafficController(DCCppCommandStation pCommandStation)
Create a new DCCppTrafficController instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addDCCppListener(int mask, DCCppListener l)
Request notification of things happening on the DCC++.protected boolean
endOfMessage(AbstractMRReply msg)
protected AbstractMRMessage
enterNormalMode()
Sets the system to normal mode during programming while in IDLESTATE.protected AbstractMRMessage
enterProgMode()
Has to be available, even though it doesn't do anything on DCC++.void
forwardMessage(AbstractMRListener reply, AbstractMRMessage m)
Forward a preformatted DCCppMessage to a specific listener interface.void
forwardReply(AbstractMRListener client, AbstractMRReply m)
Forward a preformatted DCCppMessage to the registered DCCppListeners.DCCppCommandStation
getCommandStation()
Get access to communicating command station object.DCCppSystemConnectionMemo
getSystemConnectionMemo()
Get access to the system connection memo associated with this traffic controller.DCCppTurnoutReplyCache
getTurnoutReplyCache()
protected void
handleTimeout(AbstractMRMessage msg, AbstractMRListener l)
protected int
lengthOfByteStream(AbstractMRMessage m)
Determine how many bytes the entire message will take, including space for header and trailer.protected AbstractMRReply
newReply()
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 TrafficController should just sleep.protected AbstractMRListener
pollReplyHandler()
protected boolean
programmerIdle()
Check to see if the programmer associated with this interface is idle or not.void
removeDCCppListener(int mask, DCCppListener l)
Stop notification of things happening on the XNet.abstract void
sendDCCppMessage(DCCppMessage m, DCCppListener reply)
Forward a preformatted DCCppMessage to the actual interface.void
sendHighPriorityDCCppMessage(DCCppMessage m, DCCppListener reply)
void
setSystemConnectionMemo(DCCppSystemConnectionMemo m)
Set the system connection memo associated with this traffic controller.protected void
transmitLoop()
Permanent loop for the transmit thread.-
Methods inherited from class jmri.jmrix.AbstractMRTrafficController
addConsoleListener, addHeaderToOutput, addListener, addTrailerToOutput, canReceive, connectionWarn, connectPort, disconnectPort, distributeReply, enterProgModeDelayTime, forwardToPort, getLastSender, getPortName, getSynchronizeRx, handleOneIncomingReply, hasTimeouts, loadChars, newRcvNotifier, notifyMessage, notifyReply, portReadyToSend, portWarn, portWarnTCP, readByteProtected, receiveLoop, recovery, removeListener, reportReceiveLoopException, resetTimeout, sendMessage, setAllowUnexpectedReply, setSynchronizeRx, status, terminate, terminateThreads, transmitWait, unexpectedReplyStateError, waitForStartOfReply, warnOnTimeout
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jmri.jmrix.dccpp.DCCppInterface
status
-
-
-
-
Field Detail
-
startUpDelay
public int startUpDelay
-
anyReceived
public volatile boolean anyReceived
-
mListenerMasks
protected java.util.HashMap<DCCppListener,java.lang.Integer> mListenerMasks
-
highPriorityQueue
java.util.concurrent.LinkedBlockingQueue<DCCppMessage> highPriorityQueue
-
highPriorityListeners
java.util.concurrent.LinkedBlockingQueue<DCCppListener> highPriorityListeners
-
mCommandStation
DCCppCommandStation mCommandStation
Reference to the command station in communication here.
-
mMemo
DCCppSystemConnectionMemo mMemo
Reference to the system connection memo.
-
-
Constructor Detail
-
DCCppTrafficController
DCCppTrafficController(DCCppCommandStation pCommandStation)
Create a new DCCppTrafficController instance. Must provide a DCCppCommandStation reference at creation time.- Parameters:
pCommandStation
- reference to associated command station object, preserved for later.
-
-
Method Detail
-
transmitLoop
protected void transmitLoop()
Description copied from class:AbstractMRTrafficController
Permanent loop for the transmit thread.- Overrides:
transmitLoop
in classAbstractMRTrafficController
-
sendDCCppMessage
public abstract void sendDCCppMessage(DCCppMessage m, DCCppListener reply)
Forward a preformatted DCCppMessage to the actual interface.- Specified by:
sendDCCppMessage
in interfaceDCCppInterface
- Parameters:
m
- Message to send; will be updated with CRCreply
- listener to receive replies.
-
lengthOfByteStream
protected int lengthOfByteStream(AbstractMRMessage m)
Description copied from class:AbstractMRTrafficController
Determine how many bytes the entire message will take, including space for header and trailer.- Overrides:
lengthOfByteStream
in classAbstractMRTrafficController
- Parameters:
m
- the message to be sent- Returns:
- number of bytes
-
forwardMessage
public void forwardMessage(AbstractMRListener reply, AbstractMRMessage m)
Forward a preformatted DCCppMessage to a specific listener interface.- Specified by:
forwardMessage
in classAbstractMRTrafficController
- Parameters:
m
- Message to send;reply
- abstract listener.
-
forwardReply
public void forwardReply(AbstractMRListener client, AbstractMRReply m)
Forward a preformatted DCCppMessage to the registered DCCppListeners. NOTE: this drops the packet if the checksum is bad.- Specified by:
forwardReply
in classAbstractMRTrafficController
- Parameters:
client
- Client to send message tom
- Message to send
-
sendHighPriorityDCCppMessage
public void sendHighPriorityDCCppMessage(DCCppMessage m, DCCppListener reply)
-
pollMessage
protected AbstractMRMessage pollMessage()
Description copied from class:AbstractMRTrafficController
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 TrafficController should just sleep.- Specified by:
pollMessage
in classAbstractMRTrafficController
- Returns:
- Formatted poll message
-
pollReplyHandler
protected AbstractMRListener pollReplyHandler()
- Specified by:
pollReplyHandler
in classAbstractMRTrafficController
-
addDCCppListener
public void addDCCppListener(int mask, DCCppListener l)
Description copied from interface:DCCppInterface
Request notification of things happening on the DCC++.The same listener can register multiple times with different masks. (Multiple registrations with a single mask value are equivalent to a single registration) Mask values are defined as class constants. Note that these are bit masks, and should be OR'd, not added, if multiple values are desired.
The event notification contains the received message as source, not this object, so that we can notify of an incoming message to multiple places and then move on.
- Specified by:
addDCCppListener
in interfaceDCCppInterface
- Parameters:
mask
- The OR of the key values of messages to be reported (to reduce traffic, provide for listeners interested in different things)l
- Object to be notified of new messages as they arrive.
-
removeDCCppListener
public void removeDCCppListener(int mask, DCCppListener l)
Description copied from interface:DCCppInterface
Stop notification of things happening on the XNet. Note that mask and XNetListener must match a previous request exactly.- Specified by:
removeDCCppListener
in interfaceDCCppInterface
- Parameters:
mask
- The OR of the key values of messages to be reported (to reduce traffic, provide for listeners interested in different things)l
- Object to be notified of removal.
-
enterProgMode
protected AbstractMRMessage enterProgMode()
Has to be available, even though it doesn't do anything on DCC++.- Specified by:
enterProgMode
in classAbstractMRTrafficController
- 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.- Specified by:
enterNormalMode
in classAbstractMRTrafficController
- Returns:
- the value of getExitProgModeMsg();
- See Also:
AbstractMRTrafficController.enterProgMode()
-
programmerIdle
protected boolean programmerIdle()
Check to see if the programmer associated with this interface is idle or not.- Overrides:
programmerIdle
in classAbstractMRTrafficController
- Returns:
- true if not busy programming
-
endOfMessage
protected boolean endOfMessage(AbstractMRReply msg)
- Specified by:
endOfMessage
in classAbstractMRTrafficController
-
newReply
protected AbstractMRReply newReply()
- Specified by:
newReply
in classAbstractMRTrafficController
-
handleTimeout
protected void handleTimeout(AbstractMRMessage msg, AbstractMRListener l)
- Overrides:
handleTimeout
in classAbstractMRTrafficController
-
getCommandStation
public DCCppCommandStation getCommandStation()
Get access to communicating command station object.- Returns:
- associated Command Station object
-
getSystemConnectionMemo
public DCCppSystemConnectionMemo getSystemConnectionMemo()
Get access to the system connection memo associated with this traffic controller.- Returns:
- associated systemConnectionMemo object
-
setSystemConnectionMemo
public void setSystemConnectionMemo(DCCppSystemConnectionMemo m)
Set the system connection memo associated with this traffic controller.- Parameters:
m
- associated systemConnectionMemo object
-
getTurnoutReplyCache
public DCCppTurnoutReplyCache getTurnoutReplyCache()
- Returns:
- an DCCppTurnoutReplyCache object associated with this traffic controller
-
-