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
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) java.util.concurrent.ConcurrentLinkedQueue<jmri.jmrix.tams.TamsTrafficController.PollMessage>
pollQueue
protected boolean
replyBinary
protected int
replyLastByte
protected boolean
replyOneByte
protected char
replyType
-
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 TamsTrafficController()
Create a new TamsTrafficController instance.
-
Method Summary
All Methods Instance Methods Concrete Methods 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()
java.lang.String
getSystemPrefix()
java.lang.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)
java.lang.String
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, warnOnTimeout
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jmri.CommandStation
sendAccSignalDecoderPkt, sendAltAccSignalDecoderPkt
-
Methods inherited from interface jmri.jmrix.tams.TamsInterface
status
-
-
-
-
Field Detail
-
adaptermemo
TamsSystemConnectionMemo adaptermemo
-
pollQueue
java.util.concurrent.ConcurrentLinkedQueue<jmri.jmrix.tams.TamsTrafficController.PollMessage> pollQueue
-
disablePoll
boolean disablePoll
-
replyType
protected char replyType
-
replyBinary
protected boolean replyBinary
-
replyOneByte
protected boolean replyOneByte
-
replyLastByte
protected int replyLastByte
-
myCounter
protected int myCounter
-
groupSize
protected int groupSize
-
endReached
protected boolean endReached
-
numberOfNibbles
protected int numberOfNibbles
-
messageLength
protected int messageLength
-
index
protected int index
-
_dataChars
protected int[] _dataChars
-
_nDataChars
protected int _nDataChars
-
-
Constructor Detail
-
TamsTrafficController
public TamsTrafficController()
Create a new TamsTrafficController instance.
-
-
Method Detail
-
setAdapterMemo
public void setAdapterMemo(TamsSystemConnectionMemo memo)
-
getUserName
public java.lang.String getUserName()
- Specified by:
getUserName
in interfaceCommandStation
-
getSystemPrefix
public java.lang.String getSystemPrefix()
- Specified by:
getSystemPrefix
in interfaceCommandStation
-
addTamsListener
public void addTamsListener(TamsListener l)
- Specified by:
addTamsListener
in interfaceTamsInterface
-
removeTamsListener
public void removeTamsListener(TamsListener l)
- Specified by:
removeTamsListener
in interfaceTamsInterface
-
enterProgModeDelayTime
protected int 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
public boolean sendPacket(byte[] packet, int count)
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
protected void forwardMessage(AbstractMRListener client, AbstractMRMessage m)
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
protected void forwardReply(AbstractMRListener client, AbstractMRReply tr)
Forward a TamsReply to all TamsInterface listeners.- Specified by:
forwardReply
in classAbstractMRTrafficController
- Parameters:
client
- the listener for the TamsInterfacetr
- the message to forward
-
getPollQueueDisabled
public boolean getPollQueueDisabled()
-
setPollQueueDisabled
public void setPollQueueDisabled(boolean poll)
-
addPollMessage
public 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.- Parameters:
tm
- the message to queuetl
- the listener to monitor the message and its reply
-
removePollMessage
public void removePollMessage(TamsMessage tm, TamsListener tl)
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
protected TamsMessage pollMessage()
Check Tams MC for status updates.- Specified by:
pollMessage
in classAbstractMRTrafficController
- Returns:
- the next available message
-
pollReplyHandler
protected AbstractMRListener pollReplyHandler()
- Specified by:
pollReplyHandler
in classAbstractMRTrafficController
-
sendTamsMessage
public void sendTamsMessage(TamsMessage tm, TamsListener tl)
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
protected void forwardToPort(AbstractMRMessage tm, AbstractMRListener reply)
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
protected TamsMessage 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 TamsMessage 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
protected void addTrailerToOutput(byte[] msg, int offset, TamsMessage m)
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
protected int lengthOfByteStream(TamsMessage m)
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
protected TamsReply newReply()
- Specified by:
newReply
in classAbstractMRTrafficController
-
endOfMessage
protected boolean endOfMessage(AbstractMRReply reply)
- Specified by:
endOfMessage
in classAbstractMRTrafficController
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-