Package jmri.jmrix.dccpp
Class DCCppPacketizer
java.lang.Object
jmri.jmrix.AbstractMRTrafficController
jmri.jmrix.dccpp.DCCppTrafficController
jmri.jmrix.dccpp.DCCppPacketizer
- All Implemented Interfaces:
DCCppInterface
- Direct Known Subclasses:
DCCppOverTcpPacketizer,SerialDCCppPacketizer
Converts Stream-based I/O to/from DCC++ messages. The "DCCppInterface" side
sends/receives DCCppMessage objects. The connection to a DCCppPortController
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/interfaces inherited from class jmri.jmrix.AbstractMRTrafficController
AbstractMRTrafficController.RcvNotifier, AbstractMRTrafficController.XmtNotifier -
Field Summary
Fields inherited from class jmri.jmrix.dccpp.DCCppTrafficController
anyReceived, highPriorityListeners, highPriorityQueue, mCommandStation, mListenerMasks, mMemo, startUpDelayFields 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, xmtThreadFields inherited from interface jmri.jmrix.dccpp.DCCppInterface
ALL, COMMINFO, CONSIST, CS_INFO, FEEDBACK, INTERFACE, PROGRAMMING, THROTTLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected intaddHeaderToOutput(byte[] msg, AbstractMRMessage m) Add header to the outgoing byte stream.protected voidaddTrailerToOutput(byte[] msg, int offset, AbstractMRMessage m) Add trailer to the outgoing byte stream.protected voidloadChars(AbstractMRReply msg, DataInputStream istream) Get characters from the input source, and file a message.booleanCheck to see if PortController object can be sent to. returns true if ready, false otherwise May throw an Exception.voidsendDCCppMessage(DCCppMessage m, DCCppListener reply) Forward a preformatted DCCppMessage to the actual interface.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, transmitLoopMethods 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, terminateThreads, transmitWait, 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.dccpp.DCCppInterface
status
-
Constructor Details
-
DCCppPacketizer
-
-
Method Details
-
sendDCCppMessage
Forward a preformatted DCCppMessage to the actual interface. The message is converted to a byte array and queue for transmission- Specified by:
sendDCCppMessagein interfaceDCCppInterface- Specified by:
sendDCCppMessagein classDCCppTrafficController- Parameters:
m- Message to sendreply- Listener to notify when the reply to the message is received
-
addHeaderToOutput
Add header to the outgoing byte stream.- Overrides:
addHeaderToOutputin classAbstractMRTrafficController- Parameters:
msg- The output byte streamm- ignored- Returns:
- next location in the stream to fill
-
addTrailerToOutput
Add trailer to the outgoing byte stream. This version adds the checksum to the last byte.- Overrides:
addTrailerToOutputin classAbstractMRTrafficController- Parameters:
msg- The output byte streamoffset- the first byte not yet usedm- the message to check
-
portReadyToSend
Check to see if PortController object can be sent to. returns true if ready, false otherwise May throw an Exception.- Overrides:
portReadyToSendin classAbstractMRTrafficController- Parameters:
p- the PortController- Returns:
- true if ready, false otherwise May throw an Exception.
-
loadChars
Get characters from the input source, and file a message.Returns only when the message is complete.
Only used in the Receive thread.
- Overrides:
loadCharsin classAbstractMRTrafficController- Parameters:
msg- message to fillistream- character source.- Throws:
IOException- when presented by the input source.
-