Package jmri.jmrix.dccpp.serial
Class SerialDCCppPacketizer
- java.lang.Object
-
- jmri.jmrix.AbstractMRTrafficController
-
- jmri.jmrix.dccpp.DCCppTrafficController
-
- jmri.jmrix.dccpp.DCCppPacketizer
-
- jmri.jmrix.dccpp.serial.SerialDCCppPacketizer
-
- All Implemented Interfaces:
DCCppInterface
- Direct Known Subclasses:
DCCppEthernetPacketizer
public class SerialDCCppPacketizer extends DCCppPacketizer
This is an extension of the DCCppPacketizer to handle the device specific requirements of the DCC++.In particular, SerialDCCppPacketizer adds functions to add and remove the "<" and ">" bytes that appear around any message read in. Note that the bracket-adding could be pushed up to DCCppPacketizer, as it is a protocol thing, not an interface implementation thing. We'll come back to that later. What is however interface specific is the background refresh of functions. DCC++ sends the DCC commands exactly once. A background thread will repeat the last seen function commands to compensate for any momentary power loss or to recover from power off / power on events. It only makes sense to do this on the actual serial interface as it will be transparent for the network clients.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
SerialDCCppPacketizer.RefreshAction
-
Nested classes/interfaces inherited from class jmri.jmrix.AbstractMRTrafficController
AbstractMRTrafficController.RcvNotifier, AbstractMRTrafficController.XmtNotifier
-
-
Field Summary
Fields Modifier and Type Field Description (package private) boolean
activeBackgroundRefresh
(package private) java.util.concurrent.DelayQueue<DCCppMessage>
resendFunctions
-
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 SerialDCCppPacketizer(DCCppCommandStation pCommandStation)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearRefreshQueue()
Clear the background refresh queue.int
getQueueLength()
Check how many entries are in the background refresh queueboolean
isActiveRefresh()
Check if the background function refresh thread is active or notprotected int
lengthOfByteStream(AbstractMRMessage m)
Determine how many bytes the entire message will take, including space for header and trailervoid
sendDCCppMessage(DCCppMessage m, DCCppListener reply)
Forward a preformatted DCCppMessage to the actual interface.boolean
setActiveRefresh(boolean activeState)
Enable or disable the background refresh thread-
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, 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, terminateThreads, 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
-
resendFunctions
final java.util.concurrent.DelayQueue<DCCppMessage> resendFunctions
-
activeBackgroundRefresh
boolean activeBackgroundRefresh
-
-
Constructor Detail
-
SerialDCCppPacketizer
public SerialDCCppPacketizer(DCCppCommandStation pCommandStation)
-
-
Method Detail
-
lengthOfByteStream
protected int lengthOfByteStream(AbstractMRMessage m)
Determine how many bytes the entire message will take, including space for header and trailer- Overrides:
lengthOfByteStream
in classDCCppTrafficController
- Parameters:
m
- The message to be sent- Returns:
- Number of bytes
-
sendDCCppMessage
public void sendDCCppMessage(DCCppMessage m, DCCppListener reply)
Description copied from class:DCCppPacketizer
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
- Overrides:
sendDCCppMessage
in classDCCppPacketizer
- Parameters:
m
- Message to sendreply
- Listener to notify when the reply to the message is received
-
clearRefreshQueue
public void clearRefreshQueue()
Clear the background refresh queue. The state is still kept in JMRI.
-
getQueueLength
public int getQueueLength()
Check how many entries are in the background refresh queue- Returns:
- number of queued function groups
-
setActiveRefresh
public boolean setActiveRefresh(boolean activeState)
Enable or disable the background refresh thread- Parameters:
activeState
-true
to keep refreshing the functions,false
to disable this functionality.- Returns:
- the previous active state of the background refresh thread
-
isActiveRefresh
public boolean isActiveRefresh()
Check if the background function refresh thread is active or not- Returns:
- the background refresh status,
true
for active,false
if disabled.
-
-