Package jmri.jmrix.marklin
Class MarklinTrafficController
- java.lang.Object
-
- jmri.jmrix.AbstractMRTrafficController
-
- jmri.jmrix.marklin.MarklinTrafficController
-
- All Implemented Interfaces:
CommandStation
,MarklinInterface
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 Modifier and Type Class Description (package private) static class
MarklinTrafficController.PollMessage
-
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
(package private) boolean
disablePoll
(package private) java.util.concurrent.ConcurrentLinkedQueue<MarklinTrafficController.PollMessage>
pollQueue
-
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 abstrct traffic controller to handle them when it is free.protected boolean
canReceive()
Override in the system specific code if necessaryprotected boolean
endOfMessage(AbstractMRReply msg)
protected AbstractMRMessage
enterNormalMode()
Sets the system to normal mode during programming while in IDLESTATE.protected AbstractMRMessage
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 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
-
pollQueue
java.util.concurrent.ConcurrentLinkedQueue<MarklinTrafficController.PollMessage> pollQueue
-
disablePoll
boolean disablePoll
-
-
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.- 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.- Specified by:
sendMarklinMessage
in interfaceMarklinInterface
- Parameters:
m
- Message to be sent.reply
- Listener to be notified of reply.
-
enterProgMode
protected AbstractMRMessage 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 AbstractMRMessage 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()
-
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 abstrct 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
-
-