Package jmri.jmrix.dcc4pc
Class Dcc4PcTrafficController
- java.lang.Object
-
- jmri.jmrix.AbstractMRTrafficController
-
- jmri.jmrix.dcc4pc.Dcc4PcTrafficController
-
- All Implemented Interfaces:
Dcc4PcInterface
public class Dcc4PcTrafficController extends AbstractMRTrafficController implements 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
Fields Modifier and Type Field Description (package private) Dcc4PcSystemConnectionMemoadaptermemo(package private) intGETMOREDATA(package private) Dcc4PcReplylastIncomplete(package private) booleanloading(package private) Dcc4PcMessagemLastMessage(package private) Dcc4PcMessagemLastSentMessage(package private) booleannormalFlushReceiveChars(package private) SerialPortport(package private) booleanreadingDatastatic intRETRIEVINGDATAprotected booleanunsolicitedSensorMessageSeen(package private) booleanwaitingForMore-
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 Dcc4PcTrafficController()Create a new DccPcTrafficController instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDcc4PcListener(Dcc4PcListener l)protected voidaddTrailerToOutput(byte[] msg, int offset, AbstractMRMessage m)Add trailer to the outgoing byte stream.protected booleancanReceive()Override in the system specific code if necessaryvoidconnectPort(AbstractPortController p)Make connection to an existing PortController object.protected booleanendOfMessage(AbstractMRReply msg)protected AbstractMRMessageenterNormalMode()Sets the system to normal mode during programming while in IDLESTATE.protected AbstractMRMessageenterProgMode()Set 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.voidhandleOneIncomingReply()Handle each reply when complete.protected voidhandleTimeout(AbstractMRMessage msg, AbstractMRListener l)protected voidloadChars(AbstractMRReply msg, java.io.DataInputStream istream)Get characters from the input source, and file a message.protected AbstractMRReplynewReply()protected AbstractMRMessagepollMessage()Invoked 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 AbstractMRListenerpollReplyHandler()voidremoveDcc4PcListener(Dcc4PcListener l)voidsendDcc4PcMessage(Dcc4PcMessage m, Dcc4PcListener reply)Forward a preformatted message to the actual interface.voidsetAdapterMemo(Dcc4PcSystemConnectionMemo memo)protected voidtransmitWait(int waitTime, int state, java.lang.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, warnOnTimeout
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jmri.jmrix.dcc4pc.Dcc4PcInterface
status
-
-
-
-
Field Detail
-
adaptermemo
Dcc4PcSystemConnectionMemo adaptermemo
-
RETRIEVINGDATA
public static final int RETRIEVINGDATA
- See Also:
- Constant Field Values
-
unsolicitedSensorMessageSeen
protected boolean unsolicitedSensorMessageSeen
-
mLastMessage
Dcc4PcMessage mLastMessage
-
mLastSentMessage
Dcc4PcMessage mLastSentMessage
-
port
SerialPort port
-
lastIncomplete
Dcc4PcReply lastIncomplete
-
waitingForMore
boolean waitingForMore
-
loading
boolean loading
-
GETMOREDATA
final int GETMOREDATA
- See Also:
- Constant Field Values
-
normalFlushReceiveChars
boolean normalFlushReceiveChars
-
readingData
boolean readingData
-
-
Constructor Detail
-
Dcc4PcTrafficController
public Dcc4PcTrafficController()
Create a new DccPcTrafficController instance.
-
-
Method Detail
-
setAdapterMemo
public void setAdapterMemo(Dcc4PcSystemConnectionMemo memo)
-
addDcc4PcListener
public void addDcc4PcListener(Dcc4PcListener l)
- Specified by:
addDcc4PcListenerin interfaceDcc4PcInterface
-
removeDcc4PcListener
public void removeDcc4PcListener(Dcc4PcListener l)
- Specified by:
removeDcc4PcListenerin interfaceDcc4PcInterface
-
forwardMessage
protected void forwardMessage(AbstractMRListener client, AbstractMRMessage m)
Forward a Dcc4PcMessage to all registered Dcc4PcInterface listeners.- Specified by:
forwardMessagein classAbstractMRTrafficController- Parameters:
client- abstract listener.m- message to forward.
-
forwardReply
protected void forwardReply(AbstractMRListener client, AbstractMRReply r)
Forward a Dcc4PcReply to all registered Dcc4PcInterface listeners.- Specified by:
forwardReplyin classAbstractMRTrafficController
-
pollMessage
protected AbstractMRMessage 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
protected AbstractMRListener pollReplyHandler()
- Specified by:
pollReplyHandlerin classAbstractMRTrafficController
-
sendDcc4PcMessage
public void sendDcc4PcMessage(Dcc4PcMessage m, Dcc4PcListener reply)
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
protected AbstractMRMessage 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:
AbstractMRTrafficController.enterNormalMode()
-
enterNormalMode
protected AbstractMRMessage 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:
AbstractMRTrafficController.enterProgMode()
-
addTrailerToOutput
protected void addTrailerToOutput(byte[] msg, int offset, AbstractMRMessage m)
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
protected void forwardToPort(AbstractMRMessage m, AbstractMRListener reply)
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:
AbstractMRTrafficController.sendMessage(AbstractMRMessage, AbstractMRListener)
-
connectPort
public void connectPort(AbstractPortController p)
Description copied from class:AbstractMRTrafficControllerMake connection to an existing PortController object.- Overrides:
connectPortin classAbstractMRTrafficController- Parameters:
p- the PortController
-
newReply
protected AbstractMRReply newReply()
- Specified by:
newReplyin classAbstractMRTrafficController
-
canReceive
protected boolean 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
protected boolean endOfMessage(AbstractMRReply msg)
- Specified by:
endOfMessagein classAbstractMRTrafficController
-
handleTimeout
protected void handleTimeout(AbstractMRMessage msg, AbstractMRListener l)
- Overrides:
handleTimeoutin classAbstractMRTrafficController
-
handleOneIncomingReply
public void handleOneIncomingReply() throws java.io.IOException
Handle each reply when complete.(This is public for testing purposes) Runs in the "Receive" thread.
- Overrides:
handleOneIncomingReplyin classAbstractMRTrafficController- Throws:
java.io.IOException- on error.
-
loadChars
protected void loadChars(AbstractMRReply msg, java.io.DataInputStream istream) throws java.io.IOException
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:
java.io.IOException- when presented by the input source.
-
transmitWait
protected void transmitWait(int waitTime, int state, java.lang.String InterruptMessage)
- Overrides:
transmitWaitin classAbstractMRTrafficController
-
-