jmri.jmrix.ecos
Class EcosTrafficController

java.lang.Object
  extended by jmri.jmrix.AbstractMRTrafficController
      extended by jmri.jmrix.ecos.EcosTrafficController
All Implemented Interfaces:
CommandStation, EcosInterface

public class EcosTrafficController
extends AbstractMRTrafficController
implements EcosInterface, CommandStation

Converts Stream-based I/O to/from ECOS messages. The "EcosInterface" side sends/receives message objects.

The connection to a EcosPortController 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.

Author:
Bob Jacobsen Copyright (C) 2001

Nested Class Summary
 
Nested classes/interfaces inherited from class jmri.jmrix.AbstractMRTrafficController
AbstractMRTrafficController.RcvNotifier, AbstractMRTrafficController.XmtNotifier
 
Field Summary
protected static EcosTrafficController self
           
protected  boolean unsolicitedSensorMessageSeen
           
 
Fields inherited from class jmri.jmrix.AbstractMRTrafficController
allowUnexpectedReply, AUTORETRYSTATE, cmdListeners, controller, flushReceiveChars, IDLESTATE, istream, mCurrentMode, mCurrentState, mLastSender, mWaitBeforePoll, NORMALMODE, NOTIFIEDSTATE, OKSENDMSGSTATE, ostream, POLLSTATE, PROGRAMINGMODE, rcvException, replyInDispatch, WAITMSGREPLYSTATE, WAITREPLYINNORMMODESTATE, WAITREPLYINPROGMODESTATE, waitTimePoll, xmtException, xmtRunnable
 
Constructor Summary
EcosTrafficController()
           
 
Method Summary
 void addEcosListener(EcosListener l)
           
protected  boolean canReceive()
          Override in the system specific code if necessary
protected  boolean endOfMessage(AbstractMRReply msg)
           
protected  AbstractMRMessage enterNormalMode()
           
protected  AbstractMRMessage enterProgMode()
           
protected  int enterProgModeDelayTime()
           
protected  void forwardMessage(AbstractMRListener client, AbstractMRMessage m)
          Forward a EcosMessage to all registered EcosInterface listeners.
protected  void forwardReply(AbstractMRListener client, AbstractMRReply r)
          Forward a EcosReply to all registered EcosInterface listeners.
protected  void forwardToPort(AbstractMRMessage m, AbstractMRListener reply)
          Actually transmits the next message to the port
static EcosTrafficController instance()
          static function returning the EcosTrafficController instance to use.
protected  AbstractMRReply newReply()
           
protected  AbstractMRMessage pollMessage()
          Check NCE EPROM and start NCE CS accessory memory poll
protected  AbstractMRListener pollReplyHandler()
           
 void removeEcosListener(EcosListener l)
           
 void sendEcosMessage(EcosMessage m, EcosListener reply)
          Forward a preformatted message to the actual interface.
 void sendPacket(byte[] packet, int count)
          CommandStation implementation
 boolean sendWaitMessage(EcosMessage m, AbstractMRListener reply)
           
 void setAdapterMemo(EcosSystemConnectionMemo memo)
           
 void setInstance()
           
protected  void terminate()
           
 
Methods inherited from class jmri.jmrix.AbstractMRTrafficController
addHeaderToOutput, addListener, addTrailerToOutput, connectionWarn, connectPort, disconnectPort, finalize, getLastSender, getPortName, getSelfLock, handleOneIncomingReply, handleTimeout, hasTimeouts, lengthOfByteStream, loadChars, newRcvNotifier, notifyMessage, notifyReply, portReadyToSend, portWarn, portWarnTCP, programmerIdle, readByteProtected, receiveLoop, removeListener, reportReceiveLoopException, resetTimeout, sendMessage, setAllowUnexpectedReply, status, transmitWait, waitForStartOfReply
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface jmri.jmrix.ecos.EcosInterface
status
 

Field Detail

unsolicitedSensorMessageSeen

protected boolean unsolicitedSensorMessageSeen

self

protected static final EcosTrafficController self
Constructor Detail

EcosTrafficController

public EcosTrafficController()
Method Detail

setAdapterMemo

public void setAdapterMemo(EcosSystemConnectionMemo memo)

addEcosListener

public void addEcosListener(EcosListener l)
Specified by:
addEcosListener in interface EcosInterface

removeEcosListener

public void removeEcosListener(EcosListener l)
Specified by:
removeEcosListener in interface EcosInterface

enterProgModeDelayTime

protected int enterProgModeDelayTime()
Overrides:
enterProgModeDelayTime in class AbstractMRTrafficController

sendPacket

public void sendPacket(byte[] packet,
                       int count)
CommandStation implementation

Specified by:
sendPacket in interface CommandStation
Parameters:
packet - Byte array representing the packet, including the error-correction byte. Must not be null.
count - Number of times to repeat the transmission.

forwardMessage

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

Specified by:
forwardMessage in class AbstractMRTrafficController

forwardReply

protected void forwardReply(AbstractMRListener client,
                            AbstractMRReply r)
Forward a EcosReply to all registered EcosInterface listeners.

Specified by:
forwardReply in class AbstractMRTrafficController

pollMessage

protected AbstractMRMessage pollMessage()
Check NCE EPROM and start NCE CS accessory memory poll

Specified by:
pollMessage in class AbstractMRTrafficController

pollReplyHandler

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

sendEcosMessage

public void sendEcosMessage(EcosMessage m,
                            EcosListener reply)
Forward a preformatted message to the actual interface.

Specified by:
sendEcosMessage in interface EcosInterface
Parameters:
m - Message to be sent.
reply - Listener to be notified of reply.

forwardToPort

protected void forwardToPort(AbstractMRMessage m,
                             AbstractMRListener reply)
Description copied from class: AbstractMRTrafficController
Actually transmits the next message to the port

Overrides:
forwardToPort in class AbstractMRTrafficController

enterProgMode

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

enterNormalMode

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

instance

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

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

setInstance

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

newReply

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

canReceive

protected boolean canReceive()
Description copied from class: AbstractMRTrafficController
Override in the system specific code if necessary

Overrides:
canReceive in class AbstractMRTrafficController
Returns:
true if it is okay to buffer receive characters into a reply message. When false, discard char received

endOfMessage

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

sendWaitMessage

public boolean sendWaitMessage(EcosMessage m,
                               AbstractMRListener reply)

terminate

protected void terminate()
Overrides:
terminate in class AbstractMRTrafficController


Copyright © 1997 - 2011 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