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 longCMDS_ACCYADDR250Limit max accy decoder to addr 250static longCMDS_ALL_SYSAll Connections Support commandsstatic longCMDS_AUI_READSupports read AIU status commands0x9Bstatic longCMDS_CLOCKSupport Clock commands0x82 -> 0x87static longCMDS_MEMSupports USB read/write memory commands0xB3 -> 0xB5static longCMDS_NONEInitializer for supported command groupsstatic longCMDS_NOT_USBDisable for USB commandsstatic longCMDS_OPS_PGMSupport Ops Mode Pgm commands0xAE -> 0xAFstatic longCMDS_PROGTRACKSupports programming track and related commandsstatic longCMDS_USBSupport USB Interface commands0xB1booleancommandOptionSetNceCmdStationMemorycsm(package private) booleanexpectReplyEprom(package private) NceSensorManagermSensorManagerstatic intOPTION_1_28Create commands compatible with the 1.28 EPROM.static intOPTION_1_65Create commands compatible with the 1.65 EPROM.static intOPTION_1999Create commands compatible with the 1999 EPROM.static intOPTION_2004Create commands compatible with the 2004 EPROM.static intOPTION_2006Create commands compatible with the 2006 EPROM.static intOPTION_FORCE_ASCIICreate all commands in the ASCII format.static intOPTION_FORCE_BINARYCreate all commands in the binary format.static intOPTION_PH5Create commands compatible with the PH5.(package private) NceAIUCheckerpollAiuStatus(package private) NceConnectionStatuspollEprom(package private) NceTurnoutMonitorpollHandlerprotected booleanreplyBinaryprotected intreplyLenprotected booleanunsolicitedSensorMessageSeenstatic intUSB_SYSTEM_NONEDefault when a NCE USB isn't selected in user system preferences.static intUSB_SYSTEM_POWERCABCreate commands compatible with a NCE USB connected to a PowerCab.static intUSB_SYSTEM_POWERPROCreate commands compatible with a NCE USB connected to a PowerPro.static intUSB_SYSTEM_SB3Create commands compatible with a NCE USB connected to a Smart Booster.static intUSB_SYSTEM_SB5Create commands compatible with a NCE USB with SB5.static intUSB_SYSTEM_TWINCreate 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 voidaddNceListener(NceListener l)protected booleancanReceive()Override in the system specific code if necessaryprotected booleanendOfMessage(AbstractMRReply msg)protected AbstractMRMessageenterNormalMode()Sets the system to normal mode during programming while in IDLESTATE.protected AbstractMRMessageenterProgMode()Set the system to programming mode.protected intenterProgModeDelayTime()Get the delay (wait time) after enabling the programming track.protected voidforwardMessage(AbstractMRListener client, AbstractMRMessage m)Forward a NceMessage to all registered NceInterface listeners.protected voidforwardReply(AbstractMRListener client, AbstractMRReply r)Forward a NceReply to all registered NceInterface listeners.protected voidforwardToPort(AbstractMRMessage m, AbstractMRListener reply)Actually transmit the next message to the port.NceSystemConnectionMemogetAdapterMemo()longgetCmdGroups()Get the types of commands valid for the NCE USB and connected systemCMDS_NONECMDS_ACCYADDR250CMDS_PROGTRACKCMDS_AUI_READCMDS_MEMCMDS_OPS_PGMCMDS_CLOCKCMDS_USBCMDS_NOT_USBCMDS_ALL_SYSintgetCommandOptions()Determine which command format should be used for various commands: ASCII or binary.booleangetNceProgMode()Gets the state of the command stationjava.lang.StringgetPwrProVersHexText()Return the Power Pro firmware version as user-friendly hex text.NceSensorManagergetSensorManager()java.lang.StringgetSystemPrefix()intgetUsbSystem()Get the type of system the NCE USB is connected toUSB_SYSTEM_NONEUSB_SYSTEM_POWERCABUSB_SYSTEM_SB3USB_SYSTEM_POWERPROUSB_SYSTEM_TWINUSB_SYSTEM_SB5java.lang.StringgetUserName()booleanisNceEpromMarch2007()booleanisPwrProVer060203orLater()Ask whether Power Pro firmware version is 6.2.3 or later.booleanisSimulatorRunning()protected AbstractMRReplynewReply()protected AbstractMRMessagepollMessage()Check NCE EPROM and start NCE CS accessory memory pollprotected AbstractMRListenerpollReplyHandler()voidremoveNceListener(NceListener l)voidsendNceMessage(NceMessage m, NceListener reply)Forward a preformatted message to the actual interface.booleansendPacket(byte[] packet, int count)CommandStation implementationvoidsetAdapterMemo(NceSystemConnectionMemo adaptermemo)voidsetCmdGroups(long val)Set the types of commands valid connected systemCMDS_NONECMDS_ACCYADDR250CMDS_PROGTRACKCMDS_AUI_READCMDS_MEMCMDS_OPS_PGMCMDS_CLOCKCMDS_USBCMDS_NOT_USBCMDS_ALL_SYSvoidsetCommandOptions(int val)Control which command format should be used for various commands: ASCII or binary.voidsetNceEpromMarch2007(boolean b)voidsetNceProgMode(boolean b)Sets the state of the command stationvoidsetPwrProVer060203orLater(boolean isTrue)Specify whether Power Pro firmware version is 6.2.3 or later.voidsetPwrProVers(byte VV, byte MM, byte mm)Store the Power Pro firmware version.voidsetSensorManager(NceSensorManager m)voidsetSimulatorRunning(boolean b)voidsetUsbSystem(int val)Set the type of system the NCE USB is connected toUSB_SYSTEM_NONEUSB_SYSTEM_POWERCABUSB_SYSTEM_SB3USB_SYSTEM_POWERPROUSB_SYSTEM_TWINUSB_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.CommandStation
sendAccSignalDecoderPkt, sendAltAccSignalDecoderPkt
-
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:
addNceListenerin interfaceNceInterface
-
removeNceListener
public void removeNceListener(NceListener l)
- Specified by:
removeNceListenerin interfaceNceInterface
-
enterProgModeDelayTime
protected int enterProgModeDelayTime()
Description copied from class:AbstractMRTrafficControllerGet the delay (wait time) after enabling the programming track. Override in subclass to add a longer delay.- Overrides:
enterProgModeDelayTimein classAbstractMRTrafficController- Returns:
- 0 as default delay
-
sendPacket
public boolean sendPacket(byte[] packet, int count)
CommandStation implementation- Specified by:
sendPacketin interfaceCommandStation- Parameters:
packet- Byte array representing the packet, including the error-correction byte.count- Number of times to repeat the transmission.- Returns:
trueif the operation succeeds,falseotherwise.
-
forwardMessage
protected void forwardMessage(AbstractMRListener client, AbstractMRMessage m)
Forward a NceMessage to all registered NceInterface listeners.- Specified by:
forwardMessagein 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:
forwardReplyin 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:
trueif it does, otherwisefalse
-
setPwrProVer060203orLater
public void setPwrProVer060203orLater(boolean isTrue)
Specify whether Power Pro firmware version is 6.2.3 or later.- Parameters:
isTrue-trueif 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:
pollMessagein classAbstractMRTrafficController- Returns:
- Formatted poll message
-
pollReplyHandler
protected AbstractMRListener pollReplyHandler()
- Specified by:
pollReplyHandlerin classAbstractMRTrafficController
-
sendNceMessage
public void sendNceMessage(NceMessage m, NceListener reply)
Forward a preformatted message to the actual interface.- Specified by:
sendNceMessagein 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:AbstractMRTrafficControllerActually transmit the next message to the port.- Overrides:
forwardToPortin 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:AbstractMRTrafficControllerSet the system to programming mode.- Specified by:
enterProgModein 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:AbstractMRTrafficControllerSets the system to normal mode during programming while in IDLESTATE. IfAbstractMRTrafficController.programmerIdle()returns true, enterNormalMode() is called after a timeout.- Specified by:
enterNormalModein 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:
newReplyin classAbstractMRTrafficController
-
canReceive
protected boolean canReceive()
Description copied from class:AbstractMRTrafficControllerOverride in the system specific code if necessary- Overrides:
canReceivein 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:
endOfMessagein classAbstractMRTrafficController
-
getUserName
public java.lang.String getUserName()
- Specified by:
getUserNamein interfaceCommandStation
-
getSystemPrefix
public java.lang.String getSystemPrefix()
- Specified by:
getSystemPrefixin interfaceCommandStation
-
-