Package jmri.jmrix.lenz
Class XNetPacketizer
- java.lang.Object
-
- jmri.jmrix.AbstractMRTrafficController
-
- jmri.jmrix.lenz.XNetTrafficController
-
- jmri.jmrix.lenz.XNetPacketizer
-
- All Implemented Interfaces:
XNetInterface
- Direct Known Subclasses:
LI100XNetPacketizer
,LIUSBServerXNetPacketizer
,LIUSBXNetPacketizer
,XnTcpXNetPacketizer
,Z21XNetPacketizer
,ZTC611XNetPacketizer
,ZTC640XNetPacketizer
public class XNetPacketizer extends XNetTrafficController
Converts Stream-based I/O to/from XNet messages. The "XNetInterface" side sends/receives XNetMessage objects. The connection to an XNetPortController 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.lenz.XNetTrafficController
highPriorityListeners, highPriorityQueue, mCommandStation, mListenerMasks, mMemo, self
-
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.lenz.XNetInterface
ALL, COMMINFO, CONSIST, CS_INFO, FEEDBACK, INTERFACE, PROGRAMMING, THROTTLE
-
-
Constructor Summary
Constructors Constructor Description XNetPacketizer(LenzCommandStation pCommandStation)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addTrailerToOutput(byte[] msg, int offset, AbstractMRMessage m)
Add trailer to the outgoing byte stream.boolean
portReadyToSend(AbstractPortController p)
Check if PortController object can be sent to.void
sendXNetMessage(XNetMessage m, XNetListener reply)
Forward a preformatted XNetMessage to the actual interface.-
Methods inherited from class jmri.jmrix.lenz.XNetTrafficController
addXNetListener, connectPort, endOfMessage, enterNormalMode, enterProgMode, forwardMessage, forwardReply, getCommandStation, getFeedbackMessageCache, getSystemConnectionMemo, handleTimeout, hasTimeSlot, loadChars, newReply, notifyMessage, pollMessage, pollReplyHandler, programmerIdle, removeXNetListener, sendHighPriorityXNetMessage, setSystemConnectionMemo
-
Methods inherited from class jmri.jmrix.AbstractMRTrafficController
addConsoleListener, addHeaderToOutput, addListener, canReceive, connectionWarn, disconnectPort, distributeReply, enterProgModeDelayTime, forwardToPort, getLastSender, getPortName, getSynchronizeRx, handleOneIncomingReply, hasTimeouts, lengthOfByteStream, newRcvNotifier, notifyReply, portWarn, portWarnTCP, readByteProtected, receiveLoop, recovery, removeListener, reportReceiveLoopException, resetTimeout, sendMessage, setAllowUnexpectedReply, setSynchronizeRx, status, terminate, terminateThreads, transmitLoop, 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.lenz.XNetInterface
status
-
-
-
-
Constructor Detail
-
XNetPacketizer
public XNetPacketizer(LenzCommandStation pCommandStation)
-
-
Method Detail
-
sendXNetMessage
public void sendXNetMessage(XNetMessage m, XNetListener reply)
Forward a preformatted XNetMessage to the actual interface.Checksum is computed and overwritten here, then the message is converted to a byte array and queue for transmission
- Parameters:
m
- Message to send; will be updated with CRCreply
- sending listener to NOT notify.
-
addTrailerToOutput
protected void addTrailerToOutput(byte[] msg, int offset, AbstractMRMessage m)
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
- output message to extend
-
portReadyToSend
public boolean portReadyToSend(AbstractPortController p)
Check if PortController object can be sent to.- Overrides:
portReadyToSend
in classAbstractMRTrafficController
- Parameters:
p
- the PortController- Returns:
- true if ready, false otherwise May throw an Exception.
-
-