Package jmri.jmrix.tams
Class TamsTrafficController
java.lang.Object
jmri.jmrix.AbstractMRTrafficController
jmri.jmrix.tams.TamsTrafficController
- All Implemented Interfaces:
CommandStation,TamsInterface
public class TamsTrafficController
extends AbstractMRTrafficController
implements TamsInterface, CommandStation
Converts Stream-based I/O to/from Tams messages. The "TamsInterface" side
sends/receives message objects.
The connection to a TamsPortController is via a pair of Streams, which then carry sequences of characters for transmission. Note that this processing is handled in an independent thread.
This handles the state transitions, based on the necessary state in each message.
Based on work by Bob Jacobsen and Kevin Dickerson With support from Bob Jacobsen for which my thanks
-
Nested Class Summary
Nested classes/interfaces inherited from class jmri.jmrix.AbstractMRTrafficController
AbstractMRTrafficController.RcvNotifier, AbstractMRTrafficController.XmtNotifier -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int[]protected int(package private) TamsSystemConnectionMemo(package private) booleanprotected booleanprotected intprotected intprotected intprotected intprotected int(package private) ConcurrentLinkedQueue<jmri.jmrix.tams.TamsTrafficController.PollMessage>protected booleanprotected intprotected booleanprotected charFields 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 -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPollMessage(TamsMessage tm, TamsListener tl) As we have to poll the Tams MC system to get updates, we put request into a queue and allow the abstract traffic controller to handle requests when it is free.voidprotected voidaddTrailerToOutput(byte[] msg, int offset, TamsMessage m) Add trailer to the outgoing byte stream.protected booleanendOfMessage(AbstractMRReply reply) protected TamsMessageSets the system to normal mode during programming while in IDLESTATE.protected TamsMessageSet the system to programming mode.protected intGet the delay (wait time) after enabling the programming track.protected voidforwardMessage(AbstractMRListener client, AbstractMRMessage m) Forward a TamsMessage to all registered TamsInterface listeners.protected voidforwardReply(AbstractMRListener client, AbstractMRReply tr) Forward a TamsReply to all TamsInterface listeners.protected voidforwardToPort(AbstractMRMessage tm, AbstractMRListener reply) Actually transmit the next message to the port.booleanprotected intDetermine how many bytes the entire message will take, including space for header and trailerprotected TamsReplynewReply()protected TamsMessageCheck Tams MC for status updates.protected AbstractMRListenervoidremovePollMessage(TamsMessage tm, TamsListener tl) Remove a message that is used for polling from the queue.voidbooleansendPacket(byte[] packet, int count) CommandStation implementation.voidsendTamsMessage(TamsMessage tm, TamsListener tl) Forward a pre-formatted message to the actual interface.voidvoidsetPollQueueDisabled(boolean poll) toString()Methods inherited from class jmri.jmrix.AbstractMRTrafficController
addConsoleListener, addHeaderToOutput, addListener, addTrailerToOutput, canReceive, connectionWarn, connectPort, disconnectPort, distributeReply, getLastSender, getPortName, getSynchronizeRx, handleOneIncomingReply, handleTimeout, hasTimeouts, lengthOfByteStream, loadChars, newRcvNotifier, notifyMessage, notifyReply, portReadyToSend, portWarn, portWarnTCP, programmerIdle, readByteProtected, receiveLoop, recovery, removeListener, reportReceiveLoopException, resetTimeout, sendMessage, setAllowUnexpectedReply, setSynchronizeRx, status, terminate, terminateThreads, transmitLoop, transmitWait, unexpectedReplyStateError, waitForStartOfReply, warnOnTimeoutMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface jmri.CommandStation
sendAccSignalDecoderPkt, sendAltAccSignalDecoderPktMethods inherited from interface jmri.jmrix.tams.TamsInterface
status
-
Field Details
-
adaptermemo
-
pollQueue
ConcurrentLinkedQueue<jmri.jmrix.tams.TamsTrafficController.PollMessage> pollQueue -
disablePoll
boolean disablePoll -
replyType
-
replyBinary
-
replyOneByte
-
replyLastByte
-
myCounter
-
groupSize
-
endReached
-
numberOfNibbles
-
messageLength
-
index
-
_dataChars
-
_nDataChars
-
-
Constructor Details
-
TamsTrafficController
public TamsTrafficController()Create a new TamsTrafficController instance.
-
-
Method Details
-
setAdapterMemo
-
getUserName
- Specified by:
getUserNamein interfaceCommandStation
-
getSystemPrefix
- Specified by:
getSystemPrefixin interfaceCommandStation
-
addTamsListener
- Specified by:
addTamsListenerin interfaceTamsInterface
-
removeTamsListener
- Specified by:
removeTamsListenerin interfaceTamsInterface
-
enterProgModeDelayTime
Description copied from class:AbstractMRTrafficControllerGet the delay (wait time) after enabling the programming track. Override in subclass to add a longer delay.- Overrides:
enterProgModeDelayTimein classAbstractMRTrafficController- Returns:
- 0 as default delay
-
sendPacket
CommandStation implementation.- Specified by:
sendPacketin interfaceCommandStation- Parameters:
packet- ignored, but needed for API compatibilitycount- ignored, but needed for API compatibility- Returns:
trueif the operation succeeds,falseotherwise.
-
forwardMessage
Forward a TamsMessage to all registered TamsInterface listeners.- Specified by:
forwardMessagein classAbstractMRTrafficController- Parameters:
client- the listener, may throw an uncaught exception if not a TamsListnerm- the message, may throw an uncaught exception if not a TamsMessage
-
forwardReply
Forward a TamsReply to all TamsInterface listeners.- Specified by:
forwardReplyin classAbstractMRTrafficController- Parameters:
client- the listener for the TamsInterfacetr- the message to forward
-
getPollQueueDisabled
-
setPollQueueDisabled
-
addPollMessage
As we have to poll the Tams MC system to get updates, we put request into a queue and allow the abstract traffic controller to handle requests when it is free.- Parameters:
tm- the message to queuetl- the listener to monitor the message and its reply
-
removePollMessage
Remove a message that is used for polling from the queue.- Parameters:
tm- the message to removetl- the listener waiting for the reply to the message
-
pollMessage
Check Tams MC for status updates.- Specified by:
pollMessagein classAbstractMRTrafficController- Returns:
- the next available message
-
pollReplyHandler
- Specified by:
pollReplyHandlerin classAbstractMRTrafficController
-
sendTamsMessage
Forward a pre-formatted message to the actual interface.- Specified by:
sendTamsMessagein interfaceTamsInterface- Parameters:
tm- the message to forwardtl- the listener for the reply to the messageF
-
forwardToPort
Description copied from class:AbstractMRTrafficControllerActually transmit the next message to the port.- Overrides:
forwardToPortin classAbstractMRTrafficController- Parameters:
tm- the message to sendreply- the Listener sending the message, often provided as 'this'- See Also:
-
enterProgMode
Description copied from class:AbstractMRTrafficControllerSet the system to programming mode.- 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:
-
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:
- any message that needs to be returned to the Command Station to change modes. If no message is needed, returns null.
- See Also:
-
addTrailerToOutput
Add trailer to the outgoing byte stream.- Parameters:
msg- the output byte streamoffset- the first byte not yet usedm- the message in the byte stream
-
lengthOfByteStream
Determine how many bytes the entire message will take, including space for header and trailer- Parameters:
m- The message to be sent- Returns:
- Number of bytes
-
newReply
- Specified by:
newReplyin classAbstractMRTrafficController
-
endOfMessage
- Specified by:
endOfMessagein classAbstractMRTrafficController
-
toString
-