Package jmri.jmrix.roco.z21
Class Z21TrafficController
- java.lang.Object
-
- jmri.jmrix.AbstractMRTrafficController
-
- jmri.jmrix.roco.z21.Z21TrafficController
-
- All Implemented Interfaces:
Z21Interface
public class Z21TrafficController extends AbstractMRTrafficController implements Z21Interface
Abstract base for TrafficControllers in a Message/Reply protocol.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jmri.jmrix.AbstractMRTrafficController
AbstractMRTrafficController.RcvNotifier, AbstractMRTrafficController.XmtNotifier
-
-
Field Summary
-
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 Z21TrafficController()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddz21Listener(Z21Listener l)voidconnectPort(AbstractPortController p)Make connection to existing PortController object.voiddisconnectPort(AbstractPortController p)Break connection to existing PortController object.protected booleanendOfMessage(AbstractMRReply r)protected Z21MessageenterNormalMode()enterProgMode() and enterNormalMode() return any message that needs to be returned to the command station to change modes.protected Z21MessageenterProgMode()enterProgMode() and enterNormalMode() return any message that needs to be returned to the command station to change modes.protected voidforwardMessage(AbstractMRListener client, AbstractMRMessage m)Implement this to forward a specific message type to a protocol-specific listener interface.protected voidforwardReply(AbstractMRListener client, AbstractMRReply m)Implement this to forward a specific Reply type to a protocol-specific listener interface.protected voidforwardToPort(AbstractMRMessage m, AbstractMRListener reply)Actually transmits the next message to the port.voidhandleOneIncomingReply()Handle each reply when complete.protected Z21ReplynewReply()protected Z21MessagepollMessage()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 Z21ListenerpollReplyHandler()voidremovez21Listener(Z21Listener l)voidsendz21Message(Z21Message m, Z21Listener reply)Forward a preformatted message to the actual interface.booleanstatus()protected voidterminate()voidterminateThreads()Terminate the receive and transmit threads.-
Methods inherited from class jmri.jmrix.AbstractMRTrafficController
addConsoleListener, addHeaderToOutput, addListener, addTrailerToOutput, canReceive, connectionWarn, distributeReply, enterProgModeDelayTime, getLastSender, getPortName, getSynchronizeRx, handleTimeout, hasTimeouts, lengthOfByteStream, loadChars, newRcvNotifier, notifyMessage, notifyReply, portReadyToSend, portWarn, portWarnTCP, programmerIdle, readByteProtected, receiveLoop, recovery, removeListener, reportReceiveLoopException, resetTimeout, sendMessage, setAllowUnexpectedReply, setSynchronizeRx, transmitLoop, transmitWait, unexpectedReplyStateError, waitForStartOfReply, warnOnTimeout
-
-
-
-
Constructor Detail
-
Z21TrafficController
public Z21TrafficController()
-
-
Method Detail
-
forwardMessage
protected void forwardMessage(AbstractMRListener client, AbstractMRMessage m)
Implement this to forward a specific message type to a protocol-specific listener interface. This puts the casting into the concrete class.- Specified by:
forwardMessagein classAbstractMRTrafficController- Parameters:
client- abstract listener.m- message to forward.
-
forwardReply
protected void forwardReply(AbstractMRListener client, AbstractMRReply m)
Implement this to forward a specific Reply type to a protocol-specific listener interface. This puts the casting into the concrete class.- Specified by:
forwardReplyin classAbstractMRTrafficController
-
pollMessage
protected Z21Message 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.- Specified by:
pollMessagein classAbstractMRTrafficController- Returns:
- Formatted poll message
-
pollReplyHandler
protected Z21Listener pollReplyHandler()
- Specified by:
pollReplyHandlerin classAbstractMRTrafficController
-
enterProgMode
protected Z21Message enterProgMode()
enterProgMode() and enterNormalMode() return any message that needs to be returned to the command station to change modes.- Specified by:
enterProgModein classAbstractMRTrafficController- Returns:
- if no message is needed, you may return null. If the programmerIdle() function returns true, enterNormalMode() is called after a timeout while in IDLESTATE during programming to return the system to normal mode.
- See Also:
enterNormalMode()
-
enterNormalMode
protected Z21Message enterNormalMode()
enterProgMode() and enterNormalMode() return any message that needs to be returned to the command station to change modes.- Specified by:
enterNormalModein classAbstractMRTrafficController- Returns:
- if no message is needed, you may return null.
- See Also:
enterProgMode()
-
forwardToPort
protected void forwardToPort(AbstractMRMessage m, AbstractMRListener reply)
Actually transmits the next message to the port.- Overrides:
forwardToPortin classAbstractMRTrafficController- Parameters:
m- the message to sendreply- the Listener sending the message, often provided as 'this'- See Also:
AbstractMRTrafficController.sendMessage(AbstractMRMessage, AbstractMRListener)
-
status
public boolean status()
- Overrides:
statusin classAbstractMRTrafficController
-
connectPort
public void connectPort(AbstractPortController p)
Make connection to existing PortController object.- Overrides:
connectPortin classAbstractMRTrafficController- Parameters:
p- the PortController
-
disconnectPort
public void disconnectPort(AbstractPortController p)
Break connection to existing PortController object. Once broken, attempts to send via "message" member will fail.- Overrides:
disconnectPortin classAbstractMRTrafficController- Parameters:
p- the PortController
-
newReply
protected Z21Reply newReply()
- Specified by:
newReplyin classAbstractMRTrafficController
-
endOfMessage
protected boolean endOfMessage(AbstractMRReply r)
- Specified by:
endOfMessagein classAbstractMRTrafficController
-
handleOneIncomingReply
public void handleOneIncomingReply() throws java.io.IOException
Handle each reply when complete.(This is public for testing purposes) Runs in the "Receive" thread.
- Overrides:
handleOneIncomingReplyin classAbstractMRTrafficController- Throws:
java.io.IOException- on error.
-
terminate
protected void terminate()
- Overrides:
terminatein classAbstractMRTrafficController
-
terminateThreads
public void terminateThreads()
Terminate the receive and transmit threads.This is intended to be used only by testing subclasses.
- Overrides:
terminateThreadsin classAbstractMRTrafficController
-
addz21Listener
public void addz21Listener(Z21Listener l)
- Specified by:
addz21Listenerin interfaceZ21Interface
-
removez21Listener
public void removez21Listener(Z21Listener l)
- Specified by:
removez21Listenerin interfaceZ21Interface
-
sendz21Message
public void sendz21Message(Z21Message m, Z21Listener reply)
Forward a preformatted message to the actual interface.- Specified by:
sendz21Messagein interfaceZ21Interface
-
-