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 booleananyReceived(package private) java.util.concurrent.LinkedBlockingQueue<DCCppListener>highPriorityListeners(package private) java.util.concurrent.LinkedBlockingQueue<DCCppMessage>highPriorityQueue(package private) DCCppCommandStationmCommandStationReference to the command station in communication here.protected java.util.HashMap<DCCppListener,java.lang.Integer>mListenerMasks(package private) DCCppSystemConnectionMemomMemoReference to the system connection memo.intstartUpDelay-
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 voidaddDCCppListener(int mask, DCCppListener l)Request notification of things happening on the DCC++.protected booleanendOfMessage(AbstractMRReply msg)protected AbstractMRMessageenterNormalMode()Sets the system to normal mode during programming while in IDLESTATE.protected AbstractMRMessageenterProgMode()Has to be available, even though it doesn't do anything on DCC++.voidforwardMessage(AbstractMRListener reply, AbstractMRMessage m)Forward a preformatted DCCppMessage to a specific listener interface.voidforwardReply(AbstractMRListener client, AbstractMRReply m)Forward a preformatted DCCppMessage to the registered DCCppListeners.DCCppCommandStationgetCommandStation()Get access to communicating command station object.DCCppSystemConnectionMemogetSystemConnectionMemo()Get access to the system connection memo associated with this traffic controller.DCCppTurnoutReplyCachegetTurnoutReplyCache()protected voidhandleTimeout(AbstractMRMessage msg, AbstractMRListener l)protected intlengthOfByteStream(AbstractMRMessage m)Determine how many bytes the entire message will take, including space for header and trailer.protected AbstractMRReplynewReply()protected AbstractMRMessagepollMessage()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 AbstractMRListenerpollReplyHandler()protected booleanprogrammerIdle()Check to see if the programmer associated with this interface is idle or not.voidremoveDCCppListener(int mask, DCCppListener l)Stop notification of things happening on the XNet.abstract voidsendDCCppMessage(DCCppMessage m, DCCppListener reply)Forward a preformatted DCCppMessage to the actual interface.voidsendHighPriorityDCCppMessage(DCCppMessage m, DCCppListener reply)voidsetSystemConnectionMemo(DCCppSystemConnectionMemo m)Set the system connection memo associated with this traffic controller.protected voidtransmitLoop()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:AbstractMRTrafficControllerPermanent loop for the transmit thread.- Overrides:
transmitLoopin classAbstractMRTrafficController
-
sendDCCppMessage
public abstract void sendDCCppMessage(DCCppMessage m, DCCppListener reply)
Forward a preformatted DCCppMessage to the actual interface.- Specified by:
sendDCCppMessagein 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:AbstractMRTrafficControllerDetermine how many bytes the entire message will take, including space for header and trailer.- Overrides:
lengthOfByteStreamin 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:
forwardMessagein 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:
forwardReplyin 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:AbstractMRTrafficControllerInvoked 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:
pollMessagein classAbstractMRTrafficController- Returns:
- Formatted poll message
-
pollReplyHandler
protected AbstractMRListener pollReplyHandler()
- Specified by:
pollReplyHandlerin classAbstractMRTrafficController
-
addDCCppListener
public void addDCCppListener(int mask, DCCppListener l)
Description copied from interface:DCCppInterfaceRequest 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:
addDCCppListenerin 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:DCCppInterfaceStop notification of things happening on the XNet. Note that mask and XNetListener must match a previous request exactly.- Specified by:
removeDCCppListenerin 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:
enterProgModein 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:AbstractMRTrafficControllerSets the system to normal mode during programming while in IDLESTATE. IfAbstractMRTrafficController.programmerIdle()returns true, enterNormalMode() is called after a timeout.- Specified by:
enterNormalModein 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:
programmerIdlein classAbstractMRTrafficController- Returns:
- true if not busy programming
-
endOfMessage
protected boolean endOfMessage(AbstractMRReply msg)
- Specified by:
endOfMessagein classAbstractMRTrafficController
-
newReply
protected AbstractMRReply newReply()
- Specified by:
newReplyin classAbstractMRTrafficController
-
handleTimeout
protected void handleTimeout(AbstractMRMessage msg, AbstractMRListener l)
- Overrides:
handleTimeoutin 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
-
-