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 Modifier and Type Class Description (package private) static class
TamsTrafficController.PollMessage
Poll Message Handler.Nested classes/interfaces inherited from class jmri.jmrix.AbstractMRTrafficController
AbstractMRTrafficController.RcvNotifier, AbstractMRTrafficController.XmtNotifier
-
Field Summary
Fields Modifier and Type Field Description protected int[]
_dataChars
protected int
_nDataChars
(package private) TamsSystemConnectionMemo
adaptermemo
(package private) boolean
disablePoll
protected boolean
endReached
protected int
groupSize
protected int
index
protected int
messageLength
protected int
myCounter
protected int
numberOfNibbles
(package private) ConcurrentLinkedQueue<TamsTrafficController.PollMessage>
pollQueue
protected static boolean
replyBinary
protected static int
replyLastByte
protected static boolean
replyOneByte
protected static char
replyType
protected static TamsTrafficController
self
protected static boolean
unsolicitedSensorMessageSeen
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, WAITMSGREPLYSTATE, WAITREPLYINNORMMODESTATE, WAITREPLYINPROGMODESTATE, waitTimePoll, xmtException, xmtRunnable, xmtThread
-
Constructor Summary
Constructors Constructor Description TamsTrafficController()
Create a new TamsTrafficController instance. -
Method Summary
Modifier and Type Method Description void
addPollMessage(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.void
addTamsListener(TamsListener l)
protected void
addTrailerToOutput(byte[] msg, int offset, TamsMessage m)
Add trailer to the outgoing byte stream.protected boolean
endOfMessage(AbstractMRReply reply)
protected TamsMessage
enterNormalMode()
Sets the system to normal mode during programming while in IDLESTATE.protected TamsMessage
enterProgMode()
Set the system to programming mode.protected int
enterProgModeDelayTime()
Get the delay (wait time) after enabling the programming track.protected void
forwardMessage(AbstractMRListener client, AbstractMRMessage m)
Forward a TamsMessage to all registered TamsInterface listeners.protected void
forwardReply(AbstractMRListener client, AbstractMRReply tr)
Forward a TamsReply to all TamsInterface listeners.protected void
forwardToPort(AbstractMRMessage tm, AbstractMRListener reply)
Actually transmit the next message to the port.boolean
getPollQueueDisabled()
String
getSystemPrefix()
String
getUserName()
protected int
lengthOfByteStream(TamsMessage m)
Determine how many bytes the entire message will take, including space for header and trailerprotected TamsReply
newReply()
protected TamsMessage
pollMessage()
Check Tams MC for status updates.protected AbstractMRListener
pollReplyHandler()
void
removePollMessage(TamsMessage tm, TamsListener tl)
Remove a message that is used for polling from the queue.void
removeTamsListener(TamsListener l)
boolean
sendPacket(byte[] packet, int count)
CommandStation implementation.void
sendTamsMessage(TamsMessage tm, TamsListener tl)
Forward a pre-formatted message to the actual interface.void
setAdapterMemo(TamsSystemConnectionMemo memo)
void
setPollQueueDisabled(boolean poll)
String
toString()
Methods inherited from class jmri.jmrix.AbstractMRTrafficController
addHeaderToOutput, addListener, addTrailerToOutput, canReceive, connectionWarn, connectPort, disconnectPort, distributeReply, finalize, 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
-
Field Details
-
Constructor Details
-
TamsTrafficController
public TamsTrafficController()Create a new TamsTrafficController instance.
-
-
Method Details
-
setAdapterMemo
-
getUserName
- Specified by:
getUserName
in interfaceCommandStation
-
getSystemPrefix
- Specified by:
getSystemPrefix
in interfaceCommandStation
-
addTamsListener
- Specified by:
addTamsListener
in interfaceTamsInterface
-
removeTamsListener
- Specified by:
removeTamsListener
in interfaceTamsInterface
-
enterProgModeDelayTime
Description copied from class:AbstractMRTrafficController
Get the delay (wait time) after enabling the programming track. Override in subclass to add a longer delay.- Overrides:
enterProgModeDelayTime
in classAbstractMRTrafficController
- Returns:
- 0 as default delay
-
sendPacket
CommandStation implementation.- Specified by:
sendPacket
in interfaceCommandStation
- Parameters:
packet
- ignored, but needed for API compatibilitycount
- ignored, but needed for API compatibility- Returns:
true
if the operation succeeds,false
otherwise.
-
forwardMessage
Forward a TamsMessage to all registered TamsInterface listeners.- Specified by:
forwardMessage
in 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:
forwardReply
in 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:
pollMessage
in classAbstractMRTrafficController
- Returns:
- the next available message
-
pollReplyHandler
- Specified by:
pollReplyHandler
in classAbstractMRTrafficController
-
sendTamsMessage
Forward a pre-formatted message to the actual interface.- Specified by:
sendTamsMessage
in interfaceTamsInterface
- Parameters:
tm
- the message to forwardtl
- the listener for the reply to the messageF
-
forwardToPort
Description copied from class:AbstractMRTrafficController
Actually transmit the next message to the port.- Overrides:
forwardToPort
in classAbstractMRTrafficController
- Parameters:
tm
- the message to sendreply
- the Listener sending the message, often provided as 'this'- See Also:
AbstractMRTrafficController.sendMessage(AbstractMRMessage, AbstractMRListener)
-
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
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()
-
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:
newReply
in classAbstractMRTrafficController
-
endOfMessage
- Specified by:
endOfMessage
in classAbstractMRTrafficController
-
toString
-