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 void
addz21Listener(Z21Listener l)
void
connectPort(AbstractPortController p)
Make connection to existing PortController object.void
disconnectPort(AbstractPortController p)
Break connection to existing PortController object.protected boolean
endOfMessage(AbstractMRReply r)
protected Z21Message
enterNormalMode()
enterProgMode() and enterNormalMode() return any message that needs to be returned to the command station to change modes.protected Z21Message
enterProgMode()
enterProgMode() and enterNormalMode() return any message that needs to be returned to the command station to change modes.protected void
forwardMessage(AbstractMRListener client, AbstractMRMessage m)
Implement this to forward a specific message type to a protocol-specific listener interface.protected void
forwardReply(AbstractMRListener client, AbstractMRReply m)
Implement this to forward a specific Reply type to a protocol-specific listener interface.protected void
forwardToPort(AbstractMRMessage m, AbstractMRListener reply)
Actually transmits the next message to the port.void
handleOneIncomingReply()
Handle each reply when complete.protected Z21Reply
newReply()
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.protected Z21Listener
pollReplyHandler()
void
removez21Listener(Z21Listener l)
void
sendz21Message(Z21Message m, Z21Listener reply)
Forward a preformatted message to the actual interface.boolean
status()
protected void
terminate()
void
terminateThreads()
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:
forwardMessage
in 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:
forwardReply
in 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:
pollMessage
in classAbstractMRTrafficController
- Returns:
- Formatted poll message
-
pollReplyHandler
protected Z21Listener pollReplyHandler()
- Specified by:
pollReplyHandler
in 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:
enterProgMode
in 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:
enterNormalMode
in 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:
forwardToPort
in 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:
status
in classAbstractMRTrafficController
-
connectPort
public void connectPort(AbstractPortController p)
Make connection to existing PortController object.- Overrides:
connectPort
in 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:
disconnectPort
in classAbstractMRTrafficController
- Parameters:
p
- the PortController
-
newReply
protected Z21Reply newReply()
- Specified by:
newReply
in classAbstractMRTrafficController
-
endOfMessage
protected boolean endOfMessage(AbstractMRReply r)
- Specified by:
endOfMessage
in 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:
handleOneIncomingReply
in classAbstractMRTrafficController
- Throws:
java.io.IOException
- on error.
-
terminate
protected void terminate()
- Overrides:
terminate
in classAbstractMRTrafficController
-
terminateThreads
public void terminateThreads()
Terminate the receive and transmit threads.This is intended to be used only by testing subclasses.
- Overrides:
terminateThreads
in classAbstractMRTrafficController
-
addz21Listener
public void addz21Listener(Z21Listener l)
- Specified by:
addz21Listener
in interfaceZ21Interface
-
removez21Listener
public void removez21Listener(Z21Listener l)
- Specified by:
removez21Listener
in interfaceZ21Interface
-
sendz21Message
public void sendz21Message(Z21Message m, Z21Listener reply)
Forward a preformatted message to the actual interface.- Specified by:
sendz21Message
in interfaceZ21Interface
-
-