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) boolean(package private) Dcc4PcMessage(package private) Dcc4PcMessage(package private) boolean(package private) SerialPort(package private) booleanstatic final intprotected 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 AbstractMRListenervoidvoidsendDcc4PcMessage(Dcc4PcMessage m, Dcc4PcListener reply) Forward a preformatted message to the actual interface.voidprotected 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, lengthOfByteStream, newRcvNotifier, notifyMessage, notifyReply, portReadyToSend, portWarn, portWarnTCP, programmerIdle, readByteProtected, receiveLoop, recovery, removeListener, reportReceiveLoopException, resetTimeout, sendMessage, setAllowUnexpectedReply, setSynchronizeRx, status, terminate, terminateThreads, 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
-
mLastMessage
-
mLastSentMessage
-
port
-
lastIncomplete
-
waitingForMore
boolean waitingForMore -
loading
boolean loading -
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:
-
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
-
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
-