Package jmri.jmrix.dcc4pc
Class Dcc4PcTrafficController
java.lang.Object
jmri.jmrix.AbstractMRTrafficController
jmri.jmrix.dcc4pc.Dcc4PcTrafficController
- All Implemented Interfaces:
Dcc4PcInterface
Converts Stream-based I/O to/from DCC4PC messages. The "Dcc4PcInterface" side
sends/receives message objects.
The connection to a Dcc4PcPortController 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.
-
Nested Class Summary
Nested classes/interfaces inherited from class jmri.jmrix.AbstractMRTrafficController
AbstractMRTrafficController.RcvNotifier, AbstractMRTrafficController.XmtNotifier -
Field Summary
FieldsModifier and TypeFieldDescription(package private) Dcc4PcSystemConnectionMemo(package private) final int(package private) Dcc4PcReply(package private) long(package private) boolean(package private) static final longLongest wait between attempts to reopen a port that is listed but won't open.(package private) static final intLongest a single reply sequence may hold up the transmit thread.(package private) static final intQuiet time between the end of one transaction and the start of the next.(package private) Dcc4PcMessage(package private) Dcc4PcMessage(package private) boolean(package private) SerialPort(package private) boolean(package private) booleanTrue from a port failure until the port has been reopened.(package private) longHow often to check whether the port is back.static final int(package private) boolean(package private) static final longA write that hasn't finished after this long means the USB link has jammed.protected boolean(package private) booleanFields 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 -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected voidaddTrailerToOutput(byte[] msg, int offset, AbstractMRMessage m) Add trailer to the outgoing byte stream.protected booleanOverride in the system specific code if necessaryvoidMake connection to an existing PortController object.protected booleanprotected AbstractMRMessageSets the system to normal mode during programming while in IDLESTATE.protected AbstractMRMessageSet the system to programming mode.protected voidforwardMessage(AbstractMRListener client, AbstractMRMessage m) Forward a Dcc4PcMessage to all registered Dcc4PcInterface listeners.protected voidforwardReply(AbstractMRListener client, AbstractMRReply r) Forward a Dcc4PcReply to all registered Dcc4PcInterface listeners.protected voidforwardToPort(AbstractMRMessage m, AbstractMRListener reply) Actually transmit the next message to the port.voidHandle each reply when complete.protected voidprotected voidloadChars(AbstractMRReply msg, DataInputStream istream) Get characters from the input source, and file a message.protected AbstractMRReplynewReply()protected AbstractMRMessageInvoked if it's appropriate to do low-priority polling of the command station, this should return the next message to send, or null if the TrafficController should just sleep.protected AbstractMRListenervoidLike the base class's loop, but a failed port doesn't end it: the port is reopened (seeportFailed(java.lang.String)) and reading carries on.voidvoidsendDcc4PcMessage(Dcc4PcMessage m, Dcc4PcListener reply) Forward a preformatted message to the actual interface.voidvoidsetReconnectHandler(Runnable handler) protected voidAt shutdown, put every board and the interface back to 8 kbps so other programs can talk to them.voidTerminate the receive and transmit threads.protected voidtransmitWait(int waitTime, int state, String InterruptMessage) Methods inherited from class jmri.jmrix.AbstractMRTrafficController
addConsoleListener, addHeaderToOutput, addListener, connectionWarn, disconnectPort, distributeReply, enterProgModeDelayTime, getLastSender, getPortName, getSynchronizeRx, hasTimeouts, isAtRest, lengthOfByteStream, newRcvNotifier, notifyMessage, notifyReply, portReadyToSend, portWarn, portWarnTCP, programmerIdle, readByteProtected, recovery, removeListener, reportReceiveLoopException, resetTimeout, sendMessage, setAllowUnexpectedReply, setSynchronizeRx, status, transmitLoop, unexpectedReplyStateError, waitForStartOfReply, warnOnTimeoutMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jmri.jmrix.dcc4pc.Dcc4PcInterface
status
-
Field Details
-
adaptermemo
-
RETRIEVINGDATA
- See Also:
-
unsolicitedSensorMessageSeen
-
STUCK_WRITE_MILLIS
A write that hasn't finished after this long means the USB link has jammed.- See Also:
-
recovering
True from a port failure until the port has been reopened. -
recoveryPollMillis
long recoveryPollMillisHow often to check whether the port is back. -
MAX_REOPEN_DELAY
Longest wait between attempts to reopen a port that is listed but won't open.- See Also:
-
mLastMessage
-
mLastSentMessage
-
MIN_GAP_MS
Quiet time between the end of one transaction and the start of the next. Sending each Get Response straight after the last reply ended jammed the interface's USB link after a few minutes of polling with two locos; our standalone tools always leave about this long, and ran for minutes without a jam.- See Also:
-
lastTransactionEnd
-
port
-
lastIncomplete
-
waitingForMore
boolean waitingForMore -
loading
boolean loading -
sequenceInProgress
-
MAX_SEQUENCE_TIME
Longest a single reply sequence may hold up the transmit thread.- See Also:
-
GETMOREDATA
- See Also:
-
normalFlushReceiveChars
boolean normalFlushReceiveChars -
readingData
boolean readingData
-
-
Constructor Details
-
Dcc4PcTrafficController
public Dcc4PcTrafficController()Create a new DccPcTrafficController instance.
-
-
Method Details
-
setAdapterMemo
-
addDcc4PcListener
- Specified by:
addDcc4PcListenerin interfaceDcc4PcInterface
-
removeDcc4PcListener
- Specified by:
removeDcc4PcListenerin interfaceDcc4PcInterface
-
forwardMessage
Forward a Dcc4PcMessage to all registered Dcc4PcInterface listeners.- Specified by:
forwardMessagein classAbstractMRTrafficController- Parameters:
client- abstract listener.m- message to forward.
-
forwardReply
Forward a Dcc4PcReply to all registered Dcc4PcInterface listeners.- Specified by:
forwardReplyin classAbstractMRTrafficController
-
pollMessage
Description copied from class:AbstractMRTrafficControllerInvoked if it's appropriate to do low-priority polling of the command station, this should return the next message to send, or null if the TrafficController should just sleep.- Specified by:
pollMessagein classAbstractMRTrafficController- Returns:
- Formatted poll message
-
pollReplyHandler
- Specified by:
pollReplyHandlerin classAbstractMRTrafficController
-
sendDcc4PcMessage
Forward a preformatted message to the actual interface.- Specified by:
sendDcc4PcMessagein interfaceDcc4PcInterface- Parameters:
m- Message to be sent.reply- Listener to be notified of reply.
-
enterProgMode
Description copied from class:AbstractMRTrafficControllerSet the system to programming mode.- Specified by:
enterProgModein 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:
-
enterNormalMode
Description copied from class:AbstractMRTrafficControllerSets the system to normal mode during programming while in IDLESTATE. IfAbstractMRTrafficController.programmerIdle()returns true, enterNormalMode() is called after a timeout.- Specified by:
enterNormalModein 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:
-
terminate
At shutdown, put every board and the interface back to 8 kbps so other programs can talk to them. The next JMRI start resets the speed anyway.- Overrides:
terminatein classAbstractMRTrafficController
-
terminateThreads
Terminate the receive and transmit threads.This is intended to be used only by testing subclasses.
- Overrides:
terminateThreadsin classAbstractMRTrafficController
-
setReconnectHandler
-
addTrailerToOutput
Description copied from class:AbstractMRTrafficControllerAdd trailer to the outgoing byte stream.- Overrides:
addTrailerToOutputin classAbstractMRTrafficController- Parameters:
msg- the output byte streamoffset- the first byte not yet usedm- output message to extend
-
forwardToPort
Description copied from class:AbstractMRTrafficControllerActually transmit the next message to the port.- Overrides:
forwardToPortin classAbstractMRTrafficController- Parameters:
m- the message to sendreply- the Listener sending the message, often provided as 'this'- See Also:
-
connectPort
Description copied from class:AbstractMRTrafficControllerMake connection to an existing PortController object.- Overrides:
connectPortin classAbstractMRTrafficController- Parameters:
p- the PortController
-
receiveLoop
Like the base class's loop, but a failed port doesn't end it: the port is reopened (seeportFailed(java.lang.String)) and reading carries on.- Overrides:
receiveLoopin classAbstractMRTrafficController
-
newReply
- Specified by:
newReplyin classAbstractMRTrafficController
-
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
- Specified by:
endOfMessagein classAbstractMRTrafficController
-
handleTimeout
- Overrides:
handleTimeoutin classAbstractMRTrafficController
-
handleOneIncomingReply
Handle each reply when complete.(This is public for testing purposes) Runs in the "Receive" thread.
- Overrides:
handleOneIncomingReplyin classAbstractMRTrafficController- Throws:
IOException- on error.
-
loadChars
Description copied from class:AbstractMRTrafficControllerGet characters from the input source, and file a message.Returns only when the message is complete.
Only used in the Receive thread.
Handles timeouts on read by ignoring zero-length reads.
- Overrides:
loadCharsin classAbstractMRTrafficController- Parameters:
msg- message to fillistream- character source.- Throws:
IOException- when presented by the input source.
-
transmitWait
- Overrides:
transmitWaitin classAbstractMRTrafficController
-