Class NceTrafficController
- java.lang.Object
-
- jmri.jmrix.AbstractMRTrafficController
-
- 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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jmri.jmrix.AbstractMRTrafficController
AbstractMRTrafficController.RcvNotifier, AbstractMRTrafficController.XmtNotifier
-
-
Field Summary
Fields Modifier and Type Field Description static long
CMDS_ACCYADDR250
Limit max accy decoder to addr 250static long
CMDS_ALL_SYS
All Connections Support commandsstatic long
CMDS_AUI_READ
Supports read AIU status commands0x9B
static long
CMDS_CLOCK
Support Clock commands0x82 -> 0x87
static long
CMDS_MEM
Supports USB read/write memory commands0xB3 -> 0xB5
static long
CMDS_NONE
Initializer for supported command groupsstatic long
CMDS_NOT_USB
Disable for USB commandsstatic long
CMDS_OPS_PGM
Support Ops Mode Pgm commands0xAE -> 0xAF
static long
CMDS_PROGTRACK
Supports programming track and related commandsstatic long
CMDS_USB
Support USB Interface commands0xB1
boolean
commandOptionSet
NceCmdStationMemory
csm
(package private) boolean
expectReplyEprom
(package private) NceSensorManager
mSensorManager
static int
OPTION_1_28
Create commands compatible with the 1.28 EPROM.static int
OPTION_1_65
Create commands compatible with the 1.65 EPROM.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.static int
OPTION_PH5
Create commands compatible with the PH5.(package private) NceAIUChecker
pollAiuStatus
(package private) NceConnectionStatus
pollEprom
(package private) NceTurnoutMonitor
pollHandler
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_POWERPRO
Create commands compatible with a NCE USB connected to a PowerPro.static int
USB_SYSTEM_SB3
Create commands compatible with a NCE USB connected to a Smart Booster.static int
USB_SYSTEM_SB5
Create commands compatible with a NCE USB with SB5.static int
USB_SYSTEM_TWIN
Create commands compatible with a NCE USB with >=7.* connected to a Twin.-
Fields 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
Constructors Constructor Description NceTrafficController()
Create a new NCE SerialTrafficController instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addNceListener(NceListener l)
protected boolean
canReceive()
Override in the system specific code if necessaryprotected boolean
endOfMessage(AbstractMRReply msg)
protected AbstractMRMessage
enterNormalMode()
Sets the system to normal mode during programming while in IDLESTATE.protected AbstractMRMessage
enterProgMode()
Set the system to programming mode.protected int
enterProgModeDelayTime()
Get the delay (wait time) after enabling the programming track.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 transmit the next message to the port.NceSystemConnectionMemo
getAdapterMemo()
long
getCmdGroups()
Get the types of commands valid for the NCE USB and connected systemCMDS_NONE
CMDS_ACCYADDR250
CMDS_PROGTRACK
CMDS_AUI_READ
CMDS_MEM
CMDS_OPS_PGM
CMDS_CLOCK
CMDS_USB
CMDS_NOT_USB
CMDS_ALL_SYS
int
getCommandOptions()
Determine which command format should be used for various commands: ASCII or binary.boolean
getNceProgMode()
Gets the state of the command stationjava.lang.String
getPwrProVersHexText()
Return the Power Pro firmware version as user-friendly hex text.NceSensorManager
getSensorManager()
java.lang.String
getSystemPrefix()
int
getUsbSystem()
Get the type of system the NCE USB is connected toUSB_SYSTEM_NONE
USB_SYSTEM_POWERCAB
USB_SYSTEM_SB3
USB_SYSTEM_POWERPRO
USB_SYSTEM_TWIN
USB_SYSTEM_SB5
java.lang.String
getUserName()
boolean
isNceEpromMarch2007()
boolean
isPwrProVer060203orLater()
Ask whether Power Pro firmware version is 6.2.3 or later.boolean
isSimulatorRunning()
protected AbstractMRReply
newReply()
protected AbstractMRMessage
pollMessage()
Check NCE EPROM and start NCE CS accessory memory pollprotected AbstractMRListener
pollReplyHandler()
void
removeNceListener(NceListener l)
void
sendNceMessage(NceMessage m, NceListener reply)
Forward a preformatted message to the actual interface.boolean
sendPacket(byte[] packet, int count)
CommandStation implementationvoid
setAdapterMemo(NceSystemConnectionMemo adaptermemo)
void
setCmdGroups(long val)
Set the types of commands valid connected systemCMDS_NONE
CMDS_ACCYADDR250
CMDS_PROGTRACK
CMDS_AUI_READ
CMDS_MEM
CMDS_OPS_PGM
CMDS_CLOCK
CMDS_USB
CMDS_NOT_USB
CMDS_ALL_SYS
void
setCommandOptions(int val)
Control which command format should be used for various commands: ASCII or binary.void
setNceEpromMarch2007(boolean b)
void
setNceProgMode(boolean b)
Sets the state of the command stationvoid
setPwrProVer060203orLater(boolean isTrue)
Specify whether Power Pro firmware version is 6.2.3 or later.void
setPwrProVers(byte VV, byte MM, byte mm)
Store the Power Pro firmware version.void
setSensorManager(NceSensorManager m)
void
setSimulatorRunning(boolean b)
void
setUsbSystem(int val)
Set the type of system the NCE USB is connected toUSB_SYSTEM_NONE
USB_SYSTEM_POWERCAB
USB_SYSTEM_SB3
USB_SYSTEM_POWERPRO
USB_SYSTEM_TWIN
USB_SYSTEM_SB5
-
Methods inherited from class jmri.jmrix.AbstractMRTrafficController
addConsoleListener, addHeaderToOutput, addListener, addTrailerToOutput, connectionWarn, connectPort, disconnectPort, distributeReply, getLastSender, getPortName, getSynchronizeRx, handleOneIncomingReply, handleTimeout, hasTimeouts, lengthOfByteStream, loadChars, newRcvNotifier, notifyMessage, notifyReply, portReadyToSend, portWarn, portWarnTCP, programmerIdle, readByteProtected, receiveLoop, recovery, removeListener, reportReceiveLoopException, resetTimeout, sendMessage, setAllowUnexpectedReply, setSynchronizeRx, status, terminate, terminateThreads, transmitLoop, transmitWait, unexpectedReplyStateError, waitForStartOfReply, warnOnTimeout
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jmri.jmrix.nce.NceInterface
status
-
-
-
-
Field Detail
-
mSensorManager
NceSensorManager mSensorManager
-
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_1_28
public static final int OPTION_1_28
Create commands compatible with the 1.28 EPROM.For PowerCab/SB3 original pre-Nov 2012
- See Also:
- Constant Field Values
-
OPTION_1_65
public static final int OPTION_1_65
Create commands compatible with the 1.65 EPROM.For PowerCab/SB5/Twin update post-Nov 2012
- See Also:
- Constant Field Values
-
OPTION_PH5
public static final int OPTION_PH5
Create commands compatible with the PH5.For PH5
- 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. Also the case when Serial or Simulator is selected.- 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_POWERPRO
public static final int USB_SYSTEM_POWERPRO
Create commands compatible with a NCE USB connected to a PowerPro.- See Also:
- Constant Field Values
-
USB_SYSTEM_TWIN
public static final int USB_SYSTEM_TWIN
Create commands compatible with a NCE USB with >=7.* connected to a Twin.- See Also:
- Constant Field Values
-
USB_SYSTEM_SB5
public static final int USB_SYSTEM_SB5
Create commands compatible with a NCE USB with SB5.- See Also:
- Constant Field Values
-
CMDS_NONE
public static final long CMDS_NONE
Initializer for supported command groups- See Also:
- Constant Field Values
-
CMDS_ACCYADDR250
public static final long CMDS_ACCYADDR250
Limit max accy decoder to addr 250- See Also:
- Constant Field Values
-
CMDS_PROGTRACK
public static final long CMDS_PROGTRACK
Supports programming track and related commands- See Also:
- Constant Field Values
-
CMDS_AUI_READ
public static final long CMDS_AUI_READ
Supports read AIU status commands0x9B
- See Also:
- Constant Field Values
-
CMDS_MEM
public static final long CMDS_MEM
Supports USB read/write memory commands0xB3 -> 0xB5
- See Also:
- Constant Field Values
-
CMDS_OPS_PGM
public static final long CMDS_OPS_PGM
Support Ops Mode Pgm commands0xAE -> 0xAF
- See Also:
- Constant Field Values
-
CMDS_CLOCK
public static final long CMDS_CLOCK
Support Clock commands0x82 -> 0x87
- See Also:
- Constant Field Values
-
CMDS_USB
public static final long CMDS_USB
Support USB Interface commands0xB1
- See Also:
- Constant Field Values
-
CMDS_NOT_USB
public static final long CMDS_NOT_USB
Disable for USB commands- See Also:
- Constant Field Values
-
CMDS_ALL_SYS
public static final long CMDS_ALL_SYS
All Connections Support commands- See Also:
- Constant Field Values
-
pollEprom
NceConnectionStatus pollEprom
-
pollAiuStatus
NceAIUChecker pollAiuStatus
-
pollHandler
NceTurnoutMonitor pollHandler
-
expectReplyEprom
boolean expectReplyEprom
-
replyLen
protected int replyLen
-
replyBinary
protected boolean replyBinary
-
unsolicitedSensorMessageSeen
protected boolean unsolicitedSensorMessageSeen
-
csm
public NceCmdStationMemory csm
-
-
Constructor Detail
-
NceTrafficController
public NceTrafficController()
Create a new NCE SerialTrafficController instance. Simple implementation.
-
-
Method Detail
-
addNceListener
public void addNceListener(NceListener l)
- Specified by:
addNceListener
in interfaceNceInterface
-
removeNceListener
public void removeNceListener(NceListener l)
- Specified by:
removeNceListener
in interfaceNceInterface
-
enterProgModeDelayTime
protected int enterProgModeDelayTime()
Description copied from class:AbstractMRTrafficController
Get the delay (wait time) after enabling the programming track. Override in subclass to add a longer delay.- Overrides:
enterProgModeDelayTime
in classAbstractMRTrafficController
- Returns:
- 0 as default delay
-
sendPacket
public boolean sendPacket(byte[] packet, int count)
CommandStation implementation- Specified by:
sendPacket
in interfaceCommandStation
- Parameters:
packet
- Byte array representing the packet, including the error-correction byte.count
- Number of times to repeat the transmission.- Returns:
true
if the operation succeeds,false
otherwise.
-
forwardMessage
protected void forwardMessage(AbstractMRListener client, AbstractMRMessage m)
Forward a NceMessage to all registered NceInterface listeners.- Specified by:
forwardMessage
in classAbstractMRTrafficController
- Parameters:
client
- abstract listener.m
- message to forward.
-
forwardReply
protected void forwardReply(AbstractMRListener client, AbstractMRReply r)
Forward a NceReply to all registered NceInterface listeners.- Specified by:
forwardReply
in classAbstractMRTrafficController
-
setSensorManager
public void setSensorManager(NceSensorManager m)
-
getSensorManager
public NceSensorManager getSensorManager()
-
getPwrProVersHexText
public java.lang.String getPwrProVersHexText()
Return the Power Pro firmware version as user-friendly hex text.- Returns:
- period-separated firmware version
-
setPwrProVers
public void setPwrProVers(byte VV, byte MM, byte mm)
Store the Power Pro firmware version.- Parameters:
VV
- major versionMM
- intermediate versionmm
- minor version
-
isPwrProVer060203orLater
public boolean isPwrProVer060203orLater()
Ask whether Power Pro firmware version is 6.2.3 or later.- Returns:
true
if it does, otherwisefalse
-
setPwrProVer060203orLater
public void setPwrProVer060203orLater(boolean isTrue)
Specify whether Power Pro firmware version is 6.2.3 or later.- Parameters:
isTrue
-true
if it does, otherwisefalse
-
isNceEpromMarch2007
public boolean isNceEpromMarch2007()
-
setNceEpromMarch2007
public void setNceEpromMarch2007(boolean b)
-
isSimulatorRunning
public boolean isSimulatorRunning()
-
setSimulatorRunning
public void setSimulatorRunning(boolean b)
-
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.
- Parameters:
val
- command station options
-
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.
- Returns:
- command station options value
-
setUsbSystem
public void setUsbSystem(int val)
Set the type of system the NCE USB is connected to- Parameters:
val
- usb command station options
-
getUsbSystem
public int getUsbSystem()
Get the type of system the NCE USB is connected to- Returns:
- usb command station options
-
setCmdGroups
public void setCmdGroups(long val)
Set the types of commands valid connected system- Parameters:
val
- command group supported options
-
getCmdGroups
public long getCmdGroups()
Get the types of commands valid for the NCE USB and connected system- Returns:
- command group supported options
-
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 classAbstractMRTrafficController
- Returns:
- Formatted poll message
-
pollReplyHandler
protected AbstractMRListener pollReplyHandler()
- Specified by:
pollReplyHandler
in classAbstractMRTrafficController
-
sendNceMessage
public void sendNceMessage(NceMessage m, NceListener reply)
Forward a preformatted message to the actual interface.- Specified by:
sendNceMessage
in interfaceNceInterface
- 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 transmit the next message to the port.- Overrides:
forwardToPort
in classAbstractMRTrafficController
- Parameters:
m
- the message to sendreply
- the Listener sending the message, often provided as 'this'- See Also:
AbstractMRTrafficController.sendMessage(AbstractMRMessage, AbstractMRListener)
-
enterProgMode
protected AbstractMRMessage enterProgMode()
Description copied from class:AbstractMRTrafficController
Set the system to programming mode.- Specified by:
enterProgMode
in 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:
AbstractMRTrafficController.enterNormalMode()
-
enterNormalMode
protected AbstractMRMessage enterNormalMode()
Description copied from class:AbstractMRTrafficController
Sets the system to normal mode during programming while in IDLESTATE. IfAbstractMRTrafficController.programmerIdle()
returns true, enterNormalMode() is called after a timeout.- Specified by:
enterNormalMode
in 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:
AbstractMRTrafficController.enterProgMode()
-
setAdapterMemo
public void setAdapterMemo(NceSystemConnectionMemo adaptermemo)
- Parameters:
adaptermemo
- the SystemConnectionMemo to associate with this TrafficController
-
getAdapterMemo
public NceSystemConnectionMemo getAdapterMemo()
-
newReply
protected AbstractMRReply newReply()
- Specified by:
newReply
in classAbstractMRTrafficController
-
canReceive
protected boolean canReceive()
Description copied from class:AbstractMRTrafficController
Override in the system specific code if necessary- Overrides:
canReceive
in classAbstractMRTrafficController
- 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 classAbstractMRTrafficController
-
getUserName
public java.lang.String getUserName()
- Specified by:
getUserName
in interfaceCommandStation
-
getSystemPrefix
public java.lang.String getSystemPrefix()
- Specified by:
getSystemPrefix
in interfaceCommandStation
-
-