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) 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, WAITMSGREPLYSTATE, WAITREPLYINNORMMODESTATE, WAITREPLYINPROGMODESTATE, waitTimePoll, xmtException, xmtRunnable, xmtThread
-
Constructor Summary
Constructors Constructor Description MarklinTrafficController()
Create a new MarklinTrafficController instance. -
Method Summary
Modifier and Type Method Description void
addMarklinListener(MarklinListener l)
void
addPollMessage(MarklinMessage mm, MarklinListener ml)
As we have to poll the tams 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()
String
getSystemPrefix()
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
addHeaderToOutput, addListener, addTrailerToOutput, connectionWarn, connectPort, disconnectPort, distributeReply, finalize, 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
-
Field Details
-
adaptermemo
-
pollQueue
-
disablePoll
boolean disablePoll
-
-
Constructor Details
-
MarklinTrafficController
public MarklinTrafficController()Create a new MarklinTrafficController instance.
-
-
Method Details
-
setAdapterMemo
-
addMarklinListener
- Specified by:
addMarklinListener
in interfaceMarklinInterface
-
removeMarklinListener
- Specified by:
removeMarklinListener
in interfaceMarklinInterface
-
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, 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
Forward a MarklinMessage to all registered MarklinInterface listeners.- Specified by:
forwardMessage
in classAbstractMRTrafficController
- Parameters:
client
- abstract listener.m
- message to forward.
-
forwardReply
Forward a MarklinReply to all registered MarklinInterface listeners.- Specified by:
forwardReply
in classAbstractMRTrafficController
-
sendMarklinMessage
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
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()
-
newReply
- Specified by:
newReply
in classAbstractMRTrafficController
-
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
- Specified by:
endOfMessage
in classAbstractMRTrafficController
-
getPollQueueDisabled
-
setPollQueueDisabled
-
addPollMessage
As we have to poll the tams 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
Removes a message that is used for polling from the queue.- Parameters:
mm
- marklin message to remove.ml
- marklin listener.
-
pollMessage
Check Tams MC for updates.- Specified by:
pollMessage
in classAbstractMRTrafficController
- Returns:
- Formatted poll message
-
pollReplyHandler
- Specified by:
pollReplyHandler
in classAbstractMRTrafficController
-
getUserName
- Specified by:
getUserName
in interfaceCommandStation
-
getSystemPrefix
- Specified by:
getSystemPrefix
in interfaceCommandStation
-