Package jmri.jmrix.marklin
Class MarklinTrafficController
- java.lang.Object
-
- jmri.jmrix.AbstractMRTrafficController
-
- jmri.jmrix.marklin.MarklinTrafficController
-
- All Implemented Interfaces:
CommandStation,MarklinInterface
- Direct Known Subclasses:
MarklinSimTrafficController
public class MarklinTrafficController extends AbstractMRTrafficController implements MarklinInterface, CommandStation
Converts Stream-based I/O to/from Marklin CS2 messages. The "MarklinInterface" side sends/receives message objects.The connection to a MarklinPortController is via a pair of UDP 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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jmri.jmrix.AbstractMRTrafficController
AbstractMRTrafficController.RcvNotifier, AbstractMRTrafficController.XmtNotifier
-
-
Field Summary
Fields Modifier and Type Field Description (package private) MarklinSystemConnectionMemoadaptermemoprotected java.lang.StringdefaultUserName-
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 MarklinTrafficController()Create a new MarklinTrafficController instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMarklinListener(MarklinListener l)voidaddPollMessage(MarklinMessage mm, MarklinListener ml)As we have to poll the system to get updates we put request into a queue and allow the abstract traffic controller to handle them when it is free.protected booleancanReceive()Override in the system specific code if necessaryvoiddispose()protected booleanendOfMessage(AbstractMRReply msg)protected AbstractMRMessageenterNormalMode()Marklin doesn't support this function.protected AbstractMRMessageenterProgMode()Marklin doesn't support this function.protected intenterProgModeDelayTime()Get the delay (wait time) after enabling the programming track.protected voidforwardMessage(AbstractMRListener client, AbstractMRMessage m)Forward a MarklinMessage to all registered MarklinInterface listeners.protected voidforwardReply(AbstractMRListener client, AbstractMRReply r)Forward a MarklinReply to all registered MarklinInterface listeners.booleangetPollQueueDisabled()java.lang.StringgetSystemPrefix()java.lang.StringgetUserName()protected AbstractMRReplynewReply()protected AbstractMRMessagepollMessage()Check Tams MC for updates.protected AbstractMRListenerpollReplyHandler()voidremoveMarklinListener(MarklinListener l)voidremovePollMessage(MarklinMessage mm, MarklinListener ml)Removes a message that is used for polling from the queue.voidsendMarklinMessage(MarklinMessage m, MarklinListener reply)Forward a preformatted message to the actual interface.booleansendPacket(byte[] packet, int count)CommandStation implementation, not yet supported.voidsetAdapterMemo(MarklinSystemConnectionMemo memo)voidsetPollQueueDisabled(boolean poll)-
Methods inherited from class jmri.jmrix.AbstractMRTrafficController
addConsoleListener, addHeaderToOutput, addListener, addTrailerToOutput, connectionWarn, connectPort, disconnectPort, distributeReply, forwardToPort, 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, toString, wait, wait, wait
-
Methods inherited from interface jmri.CommandStation
sendAccSignalDecoderPkt, sendAltAccSignalDecoderPkt
-
Methods inherited from interface jmri.jmrix.marklin.MarklinInterface
status
-
-
-
-
Field Detail
-
adaptermemo
MarklinSystemConnectionMemo adaptermemo
-
defaultUserName
protected java.lang.String defaultUserName
-
-
Constructor Detail
-
MarklinTrafficController
public MarklinTrafficController()
Create a new MarklinTrafficController instance.
-
-
Method Detail
-
setAdapterMemo
public void setAdapterMemo(MarklinSystemConnectionMemo memo)
-
addMarklinListener
public void addMarklinListener(MarklinListener l)
- Specified by:
addMarklinListenerin interfaceMarklinInterface
-
removeMarklinListener
public void removeMarklinListener(MarklinListener l)
- Specified by:
removeMarklinListenerin interfaceMarklinInterface
-
enterProgModeDelayTime
protected int 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
public boolean sendPacket(byte[] packet, int count)
CommandStation implementation, not yet supported. Send a specific packet to the rails.- Specified by:
sendPacketin interfaceCommandStation- Parameters:
packet- Byte array representing the packet, including the error-correction byte.count- Number of times to repeat the transmission.- Returns:
trueif the operation succeeds,falseotherwise.
-
forwardMessage
protected void forwardMessage(AbstractMRListener client, AbstractMRMessage m)
Forward a MarklinMessage to all registered MarklinInterface listeners.- Specified by:
forwardMessagein classAbstractMRTrafficController- Parameters:
client- abstract listener.m- message to forward.
-
forwardReply
protected void forwardReply(AbstractMRListener client, AbstractMRReply r)
Forward a MarklinReply to all registered MarklinInterface listeners.- Specified by:
forwardReplyin classAbstractMRTrafficController
-
sendMarklinMessage
public void sendMarklinMessage(MarklinMessage m, MarklinListener reply)
Forward a preformatted message to the actual interface. Send a message through the interface.- Specified by:
sendMarklinMessagein interfaceMarklinInterface- Parameters:
m- Message to be sent.reply- Listener to be notified of reply.
-
enterProgMode
protected AbstractMRMessage enterProgMode()
Marklin doesn't support this function.- Specified by:
enterProgModein classAbstractMRTrafficController- Returns:
- empty Marklin Message.
- See Also:
AbstractMRTrafficController.enterNormalMode()
-
enterNormalMode
protected AbstractMRMessage enterNormalMode()
Marklin doesn't support this function.- Specified by:
enterNormalModein classAbstractMRTrafficController- Returns:
- empty Marklin Message.
- See Also:
AbstractMRTrafficController.enterProgMode()
-
newReply
protected AbstractMRReply newReply()
- Specified by:
newReplyin classAbstractMRTrafficController
-
canReceive
protected boolean canReceive()
Description copied from class:AbstractMRTrafficControllerOverride in the system specific code if necessary- Overrides:
canReceivein classAbstractMRTrafficController- Returns:
- true if it is okay to buffer receive characters into a reply message. When false, discard char received
-
endOfMessage
protected boolean endOfMessage(AbstractMRReply msg)
- Specified by:
endOfMessagein classAbstractMRTrafficController
-
getPollQueueDisabled
public boolean getPollQueueDisabled()
-
setPollQueueDisabled
public void setPollQueueDisabled(boolean poll)
-
addPollMessage
public void addPollMessage(MarklinMessage mm, MarklinListener ml)
As we have to poll the system to get updates we put request into a queue and allow the abstract traffic controller to handle them when it is free.- Parameters:
mm- marklin message to add.ml- marklin listener.
-
removePollMessage
public void removePollMessage(MarklinMessage mm, MarklinListener ml)
Removes a message that is used for polling from the queue.- Parameters:
mm- marklin message to remove.ml- marklin listener.
-
pollMessage
protected AbstractMRMessage pollMessage()
Check Tams MC for updates.- Specified by:
pollMessagein classAbstractMRTrafficController- Returns:
- Formatted poll message
-
pollReplyHandler
protected AbstractMRListener pollReplyHandler()
- Specified by:
pollReplyHandlerin classAbstractMRTrafficController
-
getUserName
public java.lang.String getUserName()
- Specified by:
getUserNamein interfaceCommandStation
-
getSystemPrefix
public java.lang.String getSystemPrefix()
- Specified by:
getSystemPrefixin interfaceCommandStation
-
dispose
public void dispose()
-
-