Package jmri.jmrix.dccpp.dccppovertcp
Class DCCppOverTcpPacketizer
- java.lang.Object
-
- jmri.jmrix.AbstractMRTrafficController
-
- jmri.jmrix.dccpp.DCCppTrafficController
-
- jmri.jmrix.dccpp.DCCppPacketizer
-
- jmri.jmrix.dccpp.dccppovertcp.DCCppOverTcpPacketizer
-
- All Implemented Interfaces:
DCCppInterface
public class DCCppOverTcpPacketizer extends DCCppPacketizer
Converts Stream-based I/O to/from DCC++ messages. The "DCCppInterface" side sends/receives DCCppMessage objects. The connection to a DCCppPortnetworkController is via a pair of *Streams, which then carry sequences of characters for transmission.Messages come to this via the main GUI thread, and are forwarded back to listeners in that same thread. Reception and transmission are handled in dedicated threads by RcvHandler and XmtHandler objects. Those are internal classes defined here. The thread priorities are:
- RcvHandler - at highest available priority
- XmtHandler - down one, which is assumed to be above the GUI
- (everything else)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
DCCppOverTcpPacketizer.RcvHandler
Captive class to handle incoming characters.(package private) class
DCCppOverTcpPacketizer.XmtHandler
Captive class to handle transmission.-
Nested classes/interfaces inherited from class jmri.jmrix.AbstractMRTrafficController
AbstractMRTrafficController.RcvNotifier, AbstractMRTrafficController.XmtNotifier
-
-
Field Summary
Fields Modifier and Type Field Description protected java.io.BufferedReader
istreamReader
DCCppNetworkPortController
networkController
(package private) static java.lang.String
NEW_SERVER_VERSION_STRING
(package private) static java.lang.String
OLD_RECEIVE_PREFIX
(package private) static java.lang.String
OLD_SEND_PREFIX
(package private) static java.lang.String
OLD_SERVER_VERSION_STRING
protected java.lang.Runnable
rcvHandler
RcvHandler (a local class) object to implement the receive thread(package private) static java.lang.String
RECEIVE_PREFIX
(package private) static java.lang.String
SEND_PREFIX
(package private) boolean
useOldPrefix
protected java.lang.Runnable
xmtHandler
XmtHandler (a local class) object to implement the transmit threadprotected java.util.LinkedList<DCCppMessage>
xmtList
Synchronized list used as a transmit queue.-
Fields inherited from class jmri.jmrix.dccpp.DCCppTrafficController
anyReceived, mListenerMasks, startUpDelay
-
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
-
Fields inherited from interface jmri.jmrix.dccpp.DCCppInterface
ALL, COMMINFO, CONSIST, CS_INFO, FEEDBACK, INTERFACE, PROGRAMMING, THROTTLE
-
-
Constructor Summary
Constructors Constructor Description DCCppOverTcpPacketizer(DCCppCommandStation cs)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
connectPort(DCCppNetworkPortController p)
Make connection to existing DCCppNetworkPortController object.void
disconnectPort(DCCppNetworkPortController p)
Break connection to existing DCCppNetworkPortController object.boolean
isXmtBusy()
void
sendDCCppMessage(DCCppMessage m, DCCppListener reply)
Forward a preformatted DCCppMessage to the actual interface.void
startThreads()
Invoked at startup to start the threads needed here.void
terminateThreads()
Terminate the receive and transmit threads.-
Methods inherited from class jmri.jmrix.dccpp.DCCppPacketizer
addHeaderToOutput, addTrailerToOutput, loadChars, portReadyToSend
-
Methods inherited from class jmri.jmrix.dccpp.DCCppTrafficController
addDCCppListener, endOfMessage, enterNormalMode, enterProgMode, forwardMessage, forwardReply, getCommandStation, getSystemConnectionMemo, getTurnoutReplyCache, handleTimeout, lengthOfByteStream, newReply, pollMessage, pollReplyHandler, programmerIdle, removeDCCppListener, sendHighPriorityDCCppMessage, setSystemConnectionMemo, transmitLoop
-
Methods inherited from class jmri.jmrix.AbstractMRTrafficController
addConsoleListener, addListener, canReceive, connectionWarn, connectPort, disconnectPort, distributeReply, enterProgModeDelayTime, forwardToPort, getLastSender, getPortName, getSynchronizeRx, handleOneIncomingReply, hasTimeouts, newRcvNotifier, notifyMessage, notifyReply, portWarn, portWarnTCP, readByteProtected, receiveLoop, recovery, removeListener, reportReceiveLoopException, resetTimeout, sendMessage, setAllowUnexpectedReply, setSynchronizeRx, status, terminate, 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.jmrix.dccpp.DCCppInterface
status
-
-
-
-
Field Detail
-
OLD_RECEIVE_PREFIX
static final java.lang.String OLD_RECEIVE_PREFIX
- See Also:
- Constant Field Values
-
OLD_SEND_PREFIX
static final java.lang.String OLD_SEND_PREFIX
- See Also:
- Constant Field Values
-
RECEIVE_PREFIX
static final java.lang.String RECEIVE_PREFIX
- See Also:
- Constant Field Values
-
SEND_PREFIX
static final java.lang.String SEND_PREFIX
- See Also:
- Constant Field Values
-
OLD_SERVER_VERSION_STRING
static final java.lang.String OLD_SERVER_VERSION_STRING
- See Also:
- Constant Field Values
-
NEW_SERVER_VERSION_STRING
static final java.lang.String NEW_SERVER_VERSION_STRING
- See Also:
- Constant Field Values
-
useOldPrefix
boolean useOldPrefix
-
istreamReader
protected java.io.BufferedReader istreamReader
-
xmtHandler
protected final java.lang.Runnable xmtHandler
XmtHandler (a local class) object to implement the transmit thread
-
rcvHandler
protected java.lang.Runnable rcvHandler
RcvHandler (a local class) object to implement the receive thread
-
xmtList
protected java.util.LinkedList<DCCppMessage> xmtList
Synchronized list used as a transmit queue.
-
networkController
public DCCppNetworkPortController networkController
-
-
Constructor Detail
-
DCCppOverTcpPacketizer
public DCCppOverTcpPacketizer(DCCppCommandStation cs)
-
-
Method Detail
-
isXmtBusy
public boolean isXmtBusy()
-
connectPort
public void connectPort(DCCppNetworkPortController p)
Make connection to existing DCCppNetworkPortController object.- Parameters:
p
- Port networkController for connected. Save this for a later disconnect call
-
disconnectPort
public void disconnectPort(DCCppNetworkPortController p)
Break connection to existing DCCppNetworkPortController object. Once broken, attempts to send via "message" member will fail.- Parameters:
p
- previously connected port
-
sendDCCppMessage
public void sendDCCppMessage(DCCppMessage m, DCCppListener reply)
Forward a preformatted DCCppMessage to the actual interface. Checksum is computed and overwritten here, then the message is converted to a byte array and queue for transmission- Specified by:
sendDCCppMessage
in interfaceDCCppInterface
- Overrides:
sendDCCppMessage
in classDCCppPacketizer
- Parameters:
m
- Message to send; will be updated with CRCreply
- Listener to notify when the reply to the message is received
-
startThreads
public void startThreads()
Invoked at startup to start the threads needed here.
-
terminateThreads
public void terminateThreads()
Terminate the receive and transmit threads.This is intended to be used only by testing subclasses.
- Overrides:
terminateThreads
in classAbstractMRTrafficController
-
-