jmri.jmrix.oaktree
Class SerialTrafficController

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

public class SerialTrafficController
extends AbstractMRNodeTrafficController
implements SerialInterface

Converts Stream-based I/O to/from Oak Tree 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.

Author:
Bob Jacobsen Copyright (C) 2003, 2006, Bob Jacobsen, Dave Duchamp, multiNode extensions, 2004

Nested Class Summary
 
Nested classes/interfaces inherited from class jmri.jmrix.AbstractMRTrafficController
AbstractMRTrafficController.RcvNotifier, AbstractMRTrafficController.XmtNotifier
 
Field Summary
protected  int currentAddr
           
protected  int incomingLength
           
protected static SerialTrafficController self
           
 
Fields inherited from class jmri.jmrix.AbstractMRNodeTrafficController
maxNode, minNode
 
Fields inherited from class jmri.jmrix.AbstractMRTrafficController
allowUnexpectedReply, cmdListeners, controller, flushReceiveChars, IDLESTATE, istream, mCurrentMode, mCurrentState, mLastSender, mWaitBeforePoll, NORMALMODE, NOTIFIEDSTATE, OKSENDMSGSTATE, ostream, PROGRAMINGMODE, replyInDispatch, WAITMSGREPLYSTATE, WAITREPLYINNORMMODESTATE, WAITREPLYINPROGMODESTATE, xmtRunnable
 
Constructor Summary
SerialTrafficController()
           
 
Method Summary
protected  int addHeaderToOutput(byte[] msg, AbstractMRMessage m)
          Add header to the outgoing byte stream.
 void addSerialListener(SerialListener l)
           
protected  void addTrailerToOutput(byte[] msg, int offset, AbstractMRMessage m)
          Although this protocol doesn't use a trailer, we implement this method to set the expected reply length and address for this message.
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 handleTimeout(AbstractMRMessage m)
           
 void initializeSerialNode(SerialNode node)
          Public method to set up for initialization of a Serial node
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 Oak Tree from within the running thread
protected  AbstractMRListener pollReplyHandler()
           
 void removeSerialListener(SerialListener l)
           
protected  void resetTimeout(AbstractMRMessage m)
           
 void sendSerialMessage(SerialMessage m, SerialListener reply)
          Forward a preformatted message to the actual interface.
protected  void setInstance()
           
 void setSensorManager(SerialSensorManager m)
           
 void setSerialOutput(String systemName, boolean state)
          Public method to set a Oak Tree Serial Output bit Note: systemName is of format CNnnnBxxxx where "nnn" is the serial node number (0 - 127) "xxxx' is the bit number within that node (1 thru number of defined bits) state is 'true' for 0, 'false' for 1 The bit is transmitted to the Oak Tree hardware immediately before the next poll packet is sent.
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.AbstractMRNodeTrafficController
deleteNode, getMustInit, getNode, getNodeFromAddress, getNumNodes, init, registerNode, setMustInit, setMustInit
 
Methods inherited from class jmri.jmrix.AbstractMRTrafficController
addListener, canReceive, connectionWarn, connectPort, disconnectPort, enterProgModeDelayTime, finalize, forwardToPort, getPortName, handleOneIncomingReply, hasTimeouts, newRcvNotifier, notifyMessage, notifyReply, portReadyToSend, portWarn, programmerIdle, readByteProtected, receiveLoop, removeListener, reportReceiveLoopException, sendMessage, setAllowUnexpectedReply, status
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface jmri.jmrix.oaktree.SerialInterface
status
 

Field Detail

self

protected static SerialTrafficController self

currentAddr

protected int currentAddr

incomingLength

protected int incomingLength
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

setSerialOutput

public void setSerialOutput(String systemName,
                            boolean state)
Public method to set a Oak Tree Serial Output bit Note: systemName is of format CNnnnBxxxx where "nnn" is the serial node number (0 - 127) "xxxx' is the bit number within that node (1 thru number of defined bits) state is 'true' for 0, 'false' for 1 The bit is transmitted to the Oak Tree hardware immediately before the next poll packet is sent.


initializeSerialNode

public void initializeSerialNode(SerialNode node)
Public method to set up for initialization of a Serial node


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

setSensorManager

public void setSensorManager(SerialSensorManager m)

pollMessage

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

Specified by:
pollMessage in class AbstractMRTrafficController

handleTimeout

protected void handleTimeout(AbstractMRMessage m)
Overrides:
handleTimeout in class AbstractMRTrafficController

resetTimeout

protected void resetTimeout(AbstractMRMessage m)
Overrides:
resetTimeout 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)
Add header to the outgoing byte stream.

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)
Although this protocol doesn't use a trailer, we implement this method to set the expected reply length and address for this message.

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

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


Copyright © 1997 - 2008 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: SourceForge_Logo