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) MarklinSystemConnectionMemo
adaptermemo
protected java.lang.String
defaultUserName
-
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 void
addMarklinListener(MarklinListener l)
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.protected boolean
canReceive()
Override in the system specific code if necessaryvoid
dispose()
protected boolean
endOfMessage(AbstractMRReply msg)
protected AbstractMRMessage
enterNormalMode()
Marklin doesn't support this function.protected AbstractMRMessage
enterProgMode()
Marklin doesn't support this function.protected int
enterProgModeDelayTime()
Get the delay (wait time) after enabling the programming track.protected void
forwardMessage(AbstractMRListener client, AbstractMRMessage m)
Forward a MarklinMessage to all registered MarklinInterface listeners.protected void
forwardReply(AbstractMRListener client, AbstractMRReply r)
Forward a MarklinReply to all registered MarklinInterface listeners.boolean
getPollQueueDisabled()
java.lang.String
getSystemPrefix()
java.lang.String
getUserName()
protected AbstractMRReply
newReply()
protected AbstractMRMessage
pollMessage()
Check Tams MC for updates.protected AbstractMRListener
pollReplyHandler()
void
removeMarklinListener(MarklinListener l)
void
removePollMessage(MarklinMessage mm, MarklinListener ml)
Removes a message that is used for polling from the queue.void
sendMarklinMessage(MarklinMessage m, MarklinListener reply)
Forward a preformatted message to the actual interface.boolean
sendPacket(byte[] packet, int count)
CommandStation implementation, not yet supported.void
setAdapterMemo(MarklinSystemConnectionMemo memo)
void
setPollQueueDisabled(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:
addMarklinListener
in interfaceMarklinInterface
-
removeMarklinListener
public void removeMarklinListener(MarklinListener l)
- Specified by:
removeMarklinListener
in interfaceMarklinInterface
-
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, not yet supported. Send a specific packet to the rails.- Specified by:
sendPacket
in interfaceCommandStation
- Parameters:
packet
- Byte array representing the packet, including the error-correction byte.count
- Number of times to repeat the transmission.- Returns:
true
if the operation succeeds,false
otherwise.
-
forwardMessage
protected void forwardMessage(AbstractMRListener client, AbstractMRMessage m)
Forward a MarklinMessage to all registered MarklinInterface listeners.- Specified by:
forwardMessage
in 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:
forwardReply
in 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:
sendMarklinMessage
in 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:
enterProgMode
in classAbstractMRTrafficController
- Returns:
- empty Marklin Message.
- See Also:
AbstractMRTrafficController.enterNormalMode()
-
enterNormalMode
protected AbstractMRMessage enterNormalMode()
Marklin doesn't support this function.- Specified by:
enterNormalMode
in classAbstractMRTrafficController
- Returns:
- empty Marklin Message.
- See Also:
AbstractMRTrafficController.enterProgMode()
-
newReply
protected AbstractMRReply newReply()
- Specified by:
newReply
in classAbstractMRTrafficController
-
canReceive
protected boolean canReceive()
Description copied from class:AbstractMRTrafficController
Override in the system specific code if necessary- Overrides:
canReceive
in 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:
endOfMessage
in 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:
pollMessage
in classAbstractMRTrafficController
- Returns:
- Formatted poll message
-
pollReplyHandler
protected AbstractMRListener pollReplyHandler()
- Specified by:
pollReplyHandler
in classAbstractMRTrafficController
-
getUserName
public java.lang.String getUserName()
- Specified by:
getUserName
in interfaceCommandStation
-
getSystemPrefix
public java.lang.String getSystemPrefix()
- Specified by:
getSystemPrefix
in interfaceCommandStation
-
dispose
public void dispose()
-
-