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
public class DCCppPacketizer extends DCCppTrafficController
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
highPriorityListeners, highPriorityQueue, mCommandStation, mListenerMasks, mMemo
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, 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 DCCppPacketizer(DCCppCommandStation pCommandStation)
-
Method Summary
Modifier and Type Method Description protected int
addHeaderToOutput(byte[] msg, AbstractMRMessage m)
Add header to the outgoing byte stream.protected void
addTrailerToOutput(byte[] msg, int offset, AbstractMRMessage m)
Add trailer to the outgoing byte stream.protected void
loadChars(AbstractMRReply msg, DataInputStream istream)
Get characters from the input source, and file a message.boolean
portReadyToSend(AbstractPortController p)
Check to see if PortController object can be sent to. returns true if ready, false otherwise May throw an Exception.void
sendDCCppMessage(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, transmitLoop
Methods inherited from class jmri.jmrix.AbstractMRTrafficController
addListener, canReceive, connectionWarn, connectPort, disconnectPort, distributeReply, enterProgModeDelayTime, finalize, 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
-
Constructor Details
-
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:
sendDCCppMessage
in interfaceDCCppInterface
- Specified by:
sendDCCppMessage
in 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:
addHeaderToOutput
in 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:
addTrailerToOutput
in 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:
portReadyToSend
in 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:
loadChars
in classAbstractMRTrafficController
- Parameters:
msg
- message to fillistream
- character source.- Throws:
IOException
- when presented by the input source.
-