jmri.jmrix.nce
Class NceTrafficController

java.lang.Object
  extended by jmri.jmrix.AbstractMRTrafficController
      extended by jmri.jmrix.nce.NceTrafficController
All Implemented Interfaces:
CommandStation, NceInterface

public class NceTrafficController
extends AbstractMRTrafficController
implements NceInterface, CommandStation

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

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

Author:
Bob Jacobsen Copyright (C) 2001

Nested Class Summary
 
Nested classes/interfaces inherited from class jmri.jmrix.AbstractMRTrafficController
AbstractMRTrafficController.RcvNotifier, AbstractMRTrafficController.XmtNotifier
 
Field Summary
 boolean commandOptionSet
           
static int OPTION_1999
          Create commands compatible with the 1999 EPROM.
static int OPTION_2004
          Create commands compatible with the 2004 EPROM.
static int OPTION_2006
          Create commands compatible with the 2006 EPROM.
static int OPTION_FORCE_ASCII
          Create all commands in the ASCII format.
static int OPTION_FORCE_BINARY
          Create all commands in the binary format.
protected  boolean replyBinary
           
protected  int replyLen
           
protected  boolean unsolicitedSensorMessageSeen
           
static int USB_SYSTEM_NONE
          Default when a NCE USB isn't selected in user system preferences
static int USB_SYSTEM_POWERCAB
          Create commands compatible with a NCE USB connected to a PowerCab
static int USB_SYSTEM_POWERHOUSE
          Create commands compatible with a NCE USB connected to a PowerHouse
static int USB_SYSTEM_SB3
          Create commands compatible with a NCE USB connected to a Smart Booster
 
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
NceTrafficController()
           
 
Method Summary
 void addNceListener(NceListener 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 NceMessage to all registered NceInterface listeners.
protected  void forwardReply(AbstractMRListener client, AbstractMRReply r)
          Forward a NceReply to all registered NceInterface listeners.
protected  void forwardToPort(AbstractMRMessage m, AbstractMRListener reply)
          Actually transmits the next message to the port
 NceSystemConnectionMemo getAdapterMemo()
           
 int getCommandOptions()
          Determine which command format should be used for various commands: ASCII or binary.
 boolean getNceProgMode()
          Gets the state of the command station
 NceSensorManager getSensorManager()
           
 int getUsbSystem()
          Get the type of system the NCE USB is connected to USB_SYSTEM_NONE USB_SYSTEM_POWERCAB USB_SYSTEM_SB3 USB_SYSTEM_POWERHOUSE
static NceTrafficController instance()
          Deprecated. 
protected  AbstractMRReply newReply()
           
protected  AbstractMRMessage pollMessage()
          Check NCE EPROM and start NCE CS accessory memory poll
protected  AbstractMRListener pollReplyHandler()
           
 void removeNceListener(NceListener l)
           
 void sendNceMessage(NceMessage m, NceListener reply)
          Forward a preformatted message to the actual interface.
 void sendPacket(byte[] packet, int count)
          CommandStation implementation
 void setAdapterMemo(NceSystemConnectionMemo adaptermemo)
           
 void setCommandOptions(int val)
          Control which command format should be used for various commands: ASCII or binary.
 void setInstance()
          Deprecated. 
 void setNceProgMode(boolean b)
          Sets the state of the command station
 void setSensorManager(NceSensorManager m)
           
 void setUsbSystem(int val)
          Set the type of system the NCE USB is connected to USB_SYSTEM_NONE USB_SYSTEM_POWERCAB USB_SYSTEM_SB3 USB_SYSTEM_POWERHOUSE
 
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, terminate, 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.nce.NceInterface
status
 

Field Detail

OPTION_FORCE_ASCII

public static final int OPTION_FORCE_ASCII
Create all commands in the ASCII format.

See Also:
Constant Field Values

OPTION_1999

public static final int OPTION_1999
Create commands compatible with the 1999 EPROM.

This is binary for everything except service-mode CV programming operations.

See Also:
Constant Field Values

OPTION_2004

public static final int OPTION_2004
Create commands compatible with the 2004 EPROM.

This is binary for everything except service-mode CV programming operations.

See Also:
Constant Field Values

OPTION_2006

public static final int OPTION_2006
Create commands compatible with the 2006 EPROM.

This is binary for everything, including service-mode CV programming operations.

See Also:
Constant Field Values

OPTION_FORCE_BINARY

public static final int OPTION_FORCE_BINARY
Create all commands in the binary format.

See Also:
Constant Field Values

commandOptionSet

public boolean commandOptionSet

USB_SYSTEM_NONE

public static final int USB_SYSTEM_NONE
Default when a NCE USB isn't selected in user system preferences

See Also:
Constant Field Values

USB_SYSTEM_POWERCAB

public static final int USB_SYSTEM_POWERCAB
Create commands compatible with a NCE USB connected to a PowerCab

See Also:
Constant Field Values

USB_SYSTEM_SB3

public static final int USB_SYSTEM_SB3
Create commands compatible with a NCE USB connected to a Smart Booster

See Also:
Constant Field Values

USB_SYSTEM_POWERHOUSE

public static final int USB_SYSTEM_POWERHOUSE
Create commands compatible with a NCE USB connected to a PowerHouse

See Also:
Constant Field Values

replyLen

protected int replyLen

replyBinary

protected boolean replyBinary

unsolicitedSensorMessageSeen

protected boolean unsolicitedSensorMessageSeen
Constructor Detail

NceTrafficController

public NceTrafficController()
Method Detail

addNceListener

public void addNceListener(NceListener l)
Specified by:
addNceListener in interface NceInterface

removeNceListener

public void removeNceListener(NceListener l)
Specified by:
removeNceListener in interface NceInterface

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 NceMessage to all registered NceInterface listeners.

Specified by:
forwardMessage in class AbstractMRTrafficController

forwardReply

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

Specified by:
forwardReply in class AbstractMRTrafficController

setSensorManager

public void setSensorManager(NceSensorManager m)

getSensorManager

public NceSensorManager getSensorManager()

setCommandOptions

public void setCommandOptions(int val)
Control which command format should be used for various commands: ASCII or binary.

The valid argument values are the class "OPTION" constants, which are interpreted in the various methods to get a particular message.


getCommandOptions

public int getCommandOptions()
Determine which command format should be used for various commands: ASCII or binary.

The valid return values are the class "OPTION" constants, which are interpreted in the various methods to get a particular message.


setUsbSystem

public void setUsbSystem(int val)
Set the type of system the NCE USB is connected to

Parameters:
val -

getUsbSystem

public int getUsbSystem()
Get the type of system the NCE USB is connected to


getNceProgMode

public boolean getNceProgMode()
Gets the state of the command station

Returns:
true if in programming mode

setNceProgMode

public void setNceProgMode(boolean b)
Sets the state of the command station

Parameters:
b - when true, set programming mode

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

sendNceMessage

public void sendNceMessage(NceMessage m,
                           NceListener reply)
Forward a preformatted message to the actual interface.

Specified by:
sendNceMessage in interface NceInterface
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

@Deprecated
public static NceTrafficController instance()
Deprecated. 

static function returning the NceTrafficController instance to use.

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

setAdapterMemo

public void setAdapterMemo(NceSystemConnectionMemo adaptermemo)

getAdapterMemo

public NceSystemConnectionMemo getAdapterMemo()

setInstance

@Deprecated
public void setInstance()
Deprecated. 

instance use of the traffic controller is no longer used for multiple connections

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


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