Package jmri.jmrix.srcp
Class SRCPTrafficController
- java.lang.Object
-
- jmri.jmrix.AbstractMRTrafficController
-
- jmri.jmrix.srcp.SRCPTrafficController
-
- All Implemented Interfaces:
SRCPInterface
public class SRCPTrafficController extends AbstractMRTrafficController implements SRCPInterface
Converts Stream-based I/O to/from SRCP messages. The "SRCPInterface" side sends/receives message objects.The connection to a SRCPPortController is via a pair of *Streams, which then carry sequences of characters for transmission. Note that this processing is handled in an independent thread, which we need to clean up in tests.
This handles the state transitions, based on the necessary state in each message.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
SRCPTrafficController.SRCPRcvNotifier
Internal class to remember the Reply object and destination listener with a reply is received.-
Nested classes/interfaces inherited from class jmri.jmrix.AbstractMRTrafficController
AbstractMRTrafficController.RcvNotifier, AbstractMRTrafficController.XmtNotifier
-
-
Field Summary
Fields Modifier and Type Field Description protected SRCPSystemConnectionMemo
_memo
static int
HANDSHAKEMODE
static int
RUNMODE
(package private) java.lang.Runnable
shutDownTask
-
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 SRCPTrafficController()
Create a new SRCPTrafficController instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addSRCPListener(SRCPListener l)
protected boolean
endOfMessage(AbstractMRReply msg)
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 SRCPMessage to all registered SRCPInterface listeners.protected void
forwardReply(AbstractMRListener client, AbstractMRReply m)
Forward a SRCPReply to all registered SRCPInterface listeners.protected void
forwardReply(AbstractMRListener client, SimpleNode n)
Forward a SRCPReply to all registered SRCPInterface listeners.(package private) SRCPSystemConnectionMemo
getSystemConnectionMemo()
protected AbstractMRReply
newReply()
protected void
notifyReply(SimpleNode r, AbstractMRListener dest)
Forward a "Reply" from layout to registered listeners.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()
void
receiveLoop()
Handle incoming characters.void
removeSRCPListener(SRCPListener l)
void
sendSRCPMessage(SRCPMessage m, SRCPListener reply)
void
setSensorManager(SensorManager m)
(package private) void
setSystemConnectionMemo(SRCPSystemConnectionMemo memo)
void
terminateThreads()
Terminate the SRCP extra threads.-
Methods inherited from class jmri.jmrix.AbstractMRTrafficController
addConsoleListener, addHeaderToOutput, addListener, addTrailerToOutput, canReceive, connectionWarn, connectPort, disconnectPort, distributeReply, enterProgModeDelayTime, forwardToPort, getLastSender, getPortName, getSynchronizeRx, handleOneIncomingReply, handleTimeout, hasTimeouts, lengthOfByteStream, loadChars, newRcvNotifier, notifyMessage, notifyReply, portReadyToSend, portWarn, portWarnTCP, programmerIdle, readByteProtected, recovery, removeListener, reportReceiveLoopException, resetTimeout, sendMessage, setAllowUnexpectedReply, setSynchronizeRx, status, terminate, transmitLoop, 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.srcp.SRCPInterface
status
-
-
-
-
Field Detail
-
_memo
protected SRCPSystemConnectionMemo _memo
-
shutDownTask
final java.lang.Runnable shutDownTask
-
HANDSHAKEMODE
public static int HANDSHAKEMODE
-
RUNMODE
public static int RUNMODE
-
-
Constructor Detail
-
SRCPTrafficController
public SRCPTrafficController()
Create a new SRCPTrafficController instance.
-
-
Method Detail
-
addSRCPListener
public void addSRCPListener(SRCPListener l)
- Specified by:
addSRCPListener
in interfaceSRCPInterface
-
removeSRCPListener
public void removeSRCPListener(SRCPListener l)
- Specified by:
removeSRCPListener
in interfaceSRCPInterface
-
setSystemConnectionMemo
void setSystemConnectionMemo(SRCPSystemConnectionMemo memo)
-
getSystemConnectionMemo
SRCPSystemConnectionMemo getSystemConnectionMemo()
-
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
-
terminateThreads
public void terminateThreads()
Terminate the SRCP extra threads.This is intended to be used only by testing subclasses.
- Overrides:
terminateThreads
in classAbstractMRTrafficController
-
forwardMessage
protected void forwardMessage(AbstractMRListener client, AbstractMRMessage m)
Forward a SRCPMessage to all registered SRCPInterface listeners.- Specified by:
forwardMessage
in classAbstractMRTrafficController
- Parameters:
client
- abstract listener.m
- message to forward.
-
forwardReply
protected void forwardReply(AbstractMRListener client, AbstractMRReply m)
Forward a SRCPReply to all registered SRCPInterface listeners.- Specified by:
forwardReply
in classAbstractMRTrafficController
-
forwardReply
protected void forwardReply(AbstractMRListener client, SimpleNode n)
Forward a SRCPReply to all registered SRCPInterface listeners.- Parameters:
client
- WHo should receive the replyn
- relevant node
-
setSensorManager
public void setSensorManager(SensorManager m)
-
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
-
sendSRCPMessage
public void sendSRCPMessage(SRCPMessage m, SRCPListener reply)
- Specified by:
sendSRCPMessage
in interfaceSRCPInterface
-
enterProgMode
protected AbstractMRMessage enterProgMode()
Description copied from class:AbstractMRTrafficController
Set the system to programming mode.- 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:
- 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()
-
newReply
protected AbstractMRReply newReply()
- Specified by:
newReply
in classAbstractMRTrafficController
-
endOfMessage
protected boolean endOfMessage(AbstractMRReply msg)
- Specified by:
endOfMessage
in classAbstractMRTrafficController
-
notifyReply
protected void notifyReply(SimpleNode r, AbstractMRListener dest)
Forward a "Reply" from layout to registered listeners.- Parameters:
r
- Reply to be forwarded intactdest
- One (optional) listener to be skipped, usually because it's the originating object.
-
-