Package jmri.jmrix.grapevine
Class SerialTrafficController
java.lang.Object
jmri.jmrix.AbstractMRTrafficController
jmri.jmrix.AbstractMRNodeTrafficController
jmri.jmrix.grapevine.SerialTrafficController
- All Implemented Interfaces:
SerialInterface
public class SerialTrafficController
extends AbstractMRNodeTrafficController
implements SerialInterface
Convert Stream-based I/O to/from Grapevine serial messages.
The "SerialInterface" side sends/receives message objects.
The connection to a SerialPortController is via a pair of *Streams, which then carry sequences of characters for transmission. Note that this processing is handled in an independent thread.
This handles the state transitions, based on the necessary state in each message.
Handles initialization, polling, output, and input for multiple SerialNodes.
-
Nested Class Summary
Nested classes/interfaces inherited from class jmri.jmrix.AbstractMRTrafficController
AbstractMRTrafficController.RcvNotifier, AbstractMRTrafficController.XmtNotifier -
Field Summary
FieldsModifier and TypeFieldDescription(package private) byte[]protected int(package private) boolean(package private) GrapevineSystemConnectionMemoReference to the system connection memo.(package private) SerialSensorManager(package private) int(package private) intFields inherited from class jmri.jmrix.AbstractMRNodeTrafficController
curSerialNodeIndex, maxNode, minNode, nodeArray, numNodesFields 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 -
Constructor Summary
ConstructorsConstructorDescriptionSerialTrafficController(GrapevineSystemConnectionMemo adaptermemo) Create a new TrafficController instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected intaddHeaderToOutput(byte[] msg, AbstractMRMessage m) Add header to the outgoing byte stream.voidprotected voidaddTrailerToOutput(byte[] msg, int offset, AbstractMRMessage m) Although this protocol doesn't use a trailer, we implement this method to set the expected reply address for this message.voidMake connection to existing PortController (adapter) object.(package private) booleandoNextStep(AbstractMRReply msg, DataInputStream istream) Execute a state machine to parse messages from the input characters.protected booleanprotected AbstractMRMessageSets the system to normal mode during programming while in IDLESTATE.protected AbstractMRMessageSet the system to programming mode.protected voidforwardMessage(AbstractMRListener client, AbstractMRMessage m) Forward a SerialMessage to all registered SerialInterface listeners.protected voidforwardReply(AbstractMRListener client, AbstractMRReply m) Forward a SerialReply to all registered SerialInterface listeners.protected voidforwardToPort(AbstractMRMessage m, AbstractMRListener reply) Actually transmit the next message to the port.intGet minimum address of an Grapevine node as set on this TrafficController.Get access to the system connection memo associated with this traffic controller.protected voidvoidSet up for initialization of a Serial node.protected intDetermine how much many bytes the entire message will take, including space for header and trailerprotected voidprotected voidloadChars(AbstractMRReply msg, DataInputStream istream) Get characters from the input source, and file a message.protected AbstractMRReplynewReply()protected AbstractMRMessageHandle initialization, output and polling for Grapevine from within the running thread.protected AbstractMRListenervoidprotected voidvoidsendSerialMessage(SerialMessage m, SerialListener reply) Forward a preformatted message to the actual interface.voidvoidSet the system connection memo associated with this traffic controller.protected voidwaitForStartOfReply(DataInputStream istream) Dummy routine, to be filled by protocols that have to skip some start-of-message characters.Methods inherited from class jmri.jmrix.AbstractMRNodeTrafficController
deleteNode, getMustInit, getNode, getNodeFromAddress, getNumNodes, init, registerNode, setMustInit, setMustInitMethods inherited from class jmri.jmrix.AbstractMRTrafficController
addConsoleListener, addListener, canReceive, connectionWarn, connectPort, disconnectPort, distributeReply, enterProgModeDelayTime, getLastSender, getPortName, getSynchronizeRx, handleOneIncomingReply, hasTimeouts, newRcvNotifier, notifyMessage, notifyReply, portReadyToSend, portWarn, portWarnTCP, programmerIdle, readByteProtected, receiveLoop, recovery, removeListener, reportReceiveLoopException, sendMessage, setAllowUnexpectedReply, setSynchronizeRx, status, terminate, terminateThreads, transmitLoop, transmitWait, unexpectedReplyStateError, warnOnTimeoutMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jmri.jmrix.grapevine.SerialInterface
status
-
Field Details
-
logDebug
boolean logDebug -
mSensorManager
-
mMemo
Reference to the system connection memo. -
currentAddr
-
nextReplyLen
int nextReplyLen -
buffer
byte[] buffer -
state
int state
-
-
Constructor Details
-
SerialTrafficController
Create a new TrafficController instance.- Parameters:
adaptermemo- the associated SystemConnectionMemo
-
-
Method Details
-
getMinimumNodeAddress
Get minimum address of an Grapevine node as set on this TrafficController.- Returns:
- minimum node address.
-
connectPort
Make connection to existing PortController (adapter) object.- Parameters:
p- the Adapter we're connecting to
-
addSerialListener
- Specified by:
addSerialListenerin interfaceSerialInterface
-
removeSerialListener
- Specified by:
removeSerialListenerin interfaceSerialInterface
-
initializeSerialNode
Set up for initialization of a Serial node.- Parameters:
node- node to initialize.
-
enterProgMode
Description copied from class:AbstractMRTrafficControllerSet the system to programming mode.- Specified by:
enterProgModein classAbstractMRTrafficController- Returns:
- any message that needs to be returned to the Command Station to change modes. If no message is needed, returns null.
- See Also:
-
enterNormalMode
Description copied from class:AbstractMRTrafficControllerSets the system to normal mode during programming while in IDLESTATE. IfAbstractMRTrafficController.programmerIdle()returns true, enterNormalMode() is called after a timeout.- Specified by:
enterNormalModein classAbstractMRTrafficController- Returns:
- any message that needs to be returned to the Command Station to change modes. If no message is needed, returns null.
- See Also:
-
forwardMessage
Forward a SerialMessage to all registered SerialInterface listeners.- Specified by:
forwardMessagein classAbstractMRTrafficController- Parameters:
client- abstract listener.m- message to forward.
-
forwardReply
Forward a SerialReply to all registered SerialInterface listeners.- Specified by:
forwardReplyin classAbstractMRTrafficController
-
setSensorManager
-
pollMessage
Handle initialization, output and polling for Grapevine from within the running thread.- Specified by:
pollMessagein classAbstractMRTrafficController- Returns:
- Formatted poll message
-
handleTimeout
- Overrides:
handleTimeoutin classAbstractMRTrafficController
-
resetTimeout
- Overrides:
resetTimeoutin classAbstractMRTrafficController
-
pollReplyHandler
- Specified by:
pollReplyHandlerin classAbstractMRTrafficController
-
sendSerialMessage
Forward a preformatted message to the actual interface.- Specified by:
sendSerialMessagein interfaceSerialInterface
-
getSystemConnectionMemo
Get access to the system connection memo associated with this traffic controller.- Returns:
- associated systemConnectionMemo object
-
setSystemConnectionMemo
Set the system connection memo associated with this traffic controller.- Parameters:
m- associated systemConnectionMemo object
-
newReply
- Specified by:
newReplyin classAbstractMRTrafficController
-
endOfMessage
- Specified by:
endOfMessagein classAbstractMRTrafficController
-
forwardToPort
Description copied from class:AbstractMRTrafficControllerActually transmit the next message to the port.- Overrides:
forwardToPortin classAbstractMRTrafficController- Parameters:
m- the message to sendreply- the Listener sending the message, often provided as 'this'- See Also:
-
loadChars
Description copied from class:AbstractMRTrafficControllerGet characters from the input source, and file a message.Returns only when the message is complete.
Only used in the Receive thread.
Handles timeouts on read by ignoring zero-length reads.
- Overrides:
loadCharsin classAbstractMRTrafficController- Parameters:
msg- message to fillistream- character source.- Throws:
IOException- when presented by the input source.
-
doNextStep
Execute a state machine to parse messages from the input characters. May consume one or more than one character.- Parameters:
msg- Message to parseistream- Source of data- Returns:
- true when the message has been completely loaded
- Throws:
IOException- from underlying operation
-
loadBuffer
-
waitForStartOfReply
Description copied from class:AbstractMRTrafficControllerDummy routine, to be filled by protocols that have to skip some start-of-message characters.- Overrides:
waitForStartOfReplyin classAbstractMRTrafficController- Parameters:
istream- input source- Throws:
IOException- from underlying operations
-
addHeaderToOutput
Add header to the outgoing byte stream.- Overrides:
addHeaderToOutputin classAbstractMRTrafficController- Parameters:
msg- The output byte streamm- Message results- Returns:
- next location in the stream to fill
-
addTrailerToOutput
Although this protocol doesn't use a trailer, we implement this method to set the expected reply address for this message.- Overrides:
addTrailerToOutputin classAbstractMRTrafficController- Parameters:
msg- The output byte streamoffset- the first byte not yet usedm- the original message
-
lengthOfByteStream
Determine how much many bytes the entire message will take, including space for header and trailer- Overrides:
lengthOfByteStreamin classAbstractMRTrafficController- Parameters:
m- The message to be sent- Returns:
- Number of bytes
-