jmri.jmrix.tmcc
Class SerialTrafficController

java.lang.Object
  extended by jmri.jmrix.AbstractMRTrafficController
      extended by jmri.jmrix.tmcc.SerialTrafficController
All Implemented Interfaces:
SerialInterface

public class SerialTrafficController
extends AbstractMRTrafficController
implements SerialInterface

Converts Stream-based I/O to/from TMCC 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 transistions, based on the necessary state in each message.

Handles initialization, polling, output, and input for multiple Serial Nodes.


Nested Class Summary
 
Nested classes/interfaces inherited from class jmri.jmrix.AbstractMRTrafficController
AbstractMRTrafficController.RcvNotifier, AbstractMRTrafficController.XmtNotifier
 
Field Summary
(package private) static org.slf4j.Logger log
           
protected static SerialTrafficController self
           
 
Fields inherited from class jmri.jmrix.AbstractMRTrafficController
allowUnexpectedReply, AUTORETRYSTATE, cmdListeners, controller, flushReceiveChars, IDLESTATE, istream, maxRcvExceptionCount, mCurrentMode, mCurrentState, mLastSender, mWaitBeforePoll, NORMALMODE, NOTIFIEDSTATE, OKSENDMSGSTATE, ostream, POLLSTATE, PROGRAMINGMODE, rcvException, replyInDispatch, WAITMSGREPLYSTATE, WAITREPLYINNORMMODESTATE, WAITREPLYINPROGMODESTATE, waitTimePoll, xmtException, xmtRunnable
 
Constructor Summary
SerialTrafficController()
           
 
Method Summary
protected  int addHeaderToOutput(byte[] msg, AbstractMRMessage m)
          No header needed
 void addSerialListener(SerialListener l)
           
protected  void addTrailerToOutput(byte[] msg, int offset, AbstractMRMessage m)
          Add trailer to the outgoing byte stream.
protected  boolean endOfMessage(AbstractMRReply msg)
           
protected  AbstractMRMessage enterNormalMode()
           
protected  AbstractMRMessage enterProgMode()
           
protected  void forwardMessage(AbstractMRListener client, AbstractMRMessage m)
          Forward a SerialMessage to all registered SerialInterface listeners.
protected  void forwardReply(AbstractMRListener client, AbstractMRReply m)
          Forward a SerialReply to all registered SerialInterface listeners.
protected  void forwardToPort(AbstractMRMessage m, AbstractMRListener reply)
          Actually transmits the next message to the port
static SerialTrafficController instance()
          static function returning the SerialTrafficController instance to use.
protected  int lengthOfByteStream(AbstractMRMessage m)
          Determine how much many bytes the entire message will take, including space for header and trailer
protected  void loadChars(AbstractMRReply msg, DataInputStream istream)
          Get characters from the input source, and file a message.
protected  AbstractMRReply newReply()
           
protected  AbstractMRMessage pollMessage()
          Handles initialization, output and polling for TMCC from within the running thread
protected  AbstractMRListener pollReplyHandler()
           
 void removeSerialListener(SerialListener l)
           
 void sendSerialMessage(SerialMessage m, SerialListener reply)
          Forward a preformatted message to the actual interface.
protected  void setInstance()
           
protected  void waitForStartOfReply(DataInputStream istream)
          Dummy routine, to be filled by protocols that have to skip some start-of-message characters.
 
Methods inherited from class jmri.jmrix.AbstractMRTrafficController
addListener, canReceive, connectionWarn, connectPort, disconnectPort, enterProgModeDelayTime, finalize, getLastSender, getPortName, getSelfLock, handleOneIncomingReply, handleTimeout, hasTimeouts, newRcvNotifier, notifyMessage, notifyReply, portReadyToSend, portWarn, portWarnTCP, programmerIdle, readByteProtected, receiveLoop, removeListener, reportReceiveLoopException, resetTimeout, sendMessage, setAllowUnexpectedReply, status, terminate, transmitWait
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface jmri.jmrix.tmcc.SerialInterface
status
 

Field Detail

self

protected static volatile SerialTrafficController self

log

static org.slf4j.Logger log
Constructor Detail

SerialTrafficController

public SerialTrafficController()
Method Detail

addSerialListener

public void addSerialListener(SerialListener l)
Specified by:
addSerialListener in interface SerialInterface

removeSerialListener

public void removeSerialListener(SerialListener l)
Specified by:
removeSerialListener in interface SerialInterface

enterProgMode

protected AbstractMRMessage enterProgMode()
Specified by:
enterProgMode in class AbstractMRTrafficController

enterNormalMode

protected AbstractMRMessage enterNormalMode()
Specified by:
enterNormalMode in class AbstractMRTrafficController

forwardMessage

protected void forwardMessage(AbstractMRListener client,
                              AbstractMRMessage m)
Forward a SerialMessage to all registered SerialInterface listeners.

Specified by:
forwardMessage in class AbstractMRTrafficController

forwardReply

protected void forwardReply(AbstractMRListener client,
                            AbstractMRReply m)
Forward a SerialReply to all registered SerialInterface listeners.

Specified by:
forwardReply in class AbstractMRTrafficController

pollMessage

protected AbstractMRMessage pollMessage()
Handles initialization, output and polling for TMCC from within the running thread

Specified by:
pollMessage in class AbstractMRTrafficController

pollReplyHandler

protected AbstractMRListener pollReplyHandler()
Specified by:
pollReplyHandler in class AbstractMRTrafficController

sendSerialMessage

public void sendSerialMessage(SerialMessage m,
                              SerialListener reply)
Forward a preformatted message to the actual interface.

Specified by:
sendSerialMessage in interface SerialInterface

instance

public static SerialTrafficController instance()
static function returning the SerialTrafficController instance to use.

Returns:
The registered SerialTrafficController instance for general use, if need be creating one.

setInstance

protected void setInstance()
Specified by:
setInstance in class AbstractMRTrafficController

newReply

protected AbstractMRReply newReply()
Specified by:
newReply in class AbstractMRTrafficController

endOfMessage

protected boolean endOfMessage(AbstractMRReply msg)
Specified by:
endOfMessage in class AbstractMRTrafficController

loadChars

protected void loadChars(AbstractMRReply msg,
                         DataInputStream istream)
                  throws IOException
Description copied from class: AbstractMRTrafficController
Get 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:
loadChars in class AbstractMRTrafficController
Parameters:
msg - message to fill
istream - character source.
Throws:
IOException - when presented by the input source.

waitForStartOfReply

protected void waitForStartOfReply(DataInputStream istream)
                            throws IOException
Description copied from class: AbstractMRTrafficController
Dummy routine, to be filled by protocols that have to skip some start-of-message characters.

Overrides:
waitForStartOfReply in class AbstractMRTrafficController
Throws:
IOException

addHeaderToOutput

protected int addHeaderToOutput(byte[] msg,
                                AbstractMRMessage m)
No header needed

Overrides:
addHeaderToOutput in class AbstractMRTrafficController
Parameters:
msg - The output byte stream
Returns:
next location in the stream to fill

addTrailerToOutput

protected void addTrailerToOutput(byte[] msg,
                                  int offset,
                                  AbstractMRMessage m)
Add trailer to the outgoing byte stream.

Overrides:
addTrailerToOutput in class AbstractMRTrafficController
Parameters:
msg - The output byte stream
offset - the first byte not yet used

lengthOfByteStream

protected int lengthOfByteStream(AbstractMRMessage m)
Determine how much many bytes the entire message will take, including space for header and trailer

Overrides:
lengthOfByteStream in class AbstractMRTrafficController
Parameters:
m - The message to be sent
Returns:
Number of bytes for msg (3) plus preceeding NOP (3)

forwardToPort

protected void forwardToPort(AbstractMRMessage m,
                             AbstractMRListener reply)
Actually transmits the next message to the port

Overrides:
forwardToPort in class AbstractMRTrafficController


Copyright © 1997-2013 JMRI Community.
JMRI, DecoderPro, PanelPro, SoundPro, DispatcherPro and associated logos are our trademarks.

Additional information on copyright, trademarks and licenses is linked here.
Site hosted by: Get JMRI Model Railroad Interface at SourceForge.net. Fast, secure and Free Open Source software downloads