Package jmri.jmrix.nce.simulator
Class SimulatorAdapter
- java.lang.Object
-
- jmri.jmrix.AbstractPortController
-
- jmri.jmrix.AbstractSerialPortController
-
- jmri.jmrix.nce.NcePortController
-
- jmri.jmrix.nce.simulator.SimulatorAdapter
-
- All Implemented Interfaces:
java.lang.Runnable
,PortAdapter
,SerialPortAdapter
public class SimulatorAdapter extends NcePortController implements java.lang.Runnable
The following was copied from the NCE Power Pro System Reference Manual. It provides the background for the various NCE command that are simulated by this implementation.Implements a Command Station Simulator for the NCE system.
BINARY COMMAND SET
The RS-232 port binary commands are designed to work in a computer friendly way. Command format is:
<command number> <data> <data> ...
Commands range from 0x80 to 0xBF
Commands and formats supported: Commands 0xAD to 0xBF are not used and return '0'
Errors returned: '0'= command not supported '1'= loco address out of range '2'= cab address out of range '3'= data out of range '4'= byte count out of range '!'= command completed successfully
For a complete description of Binary Commands see: www.ncecorporation.com/pdf/bincmds.pdf
Command Description (#bytes rtn) Responses 0x80 NOP, dummy instruction (1) ! 0x81 xx xx yy assign loco xxxx to cab cc (1) !, 1,2 0x82 read clock (2) <hours><minutes> 0x83 Clock stop (1) ! 0x84 Clock start (1) ! 0x85 xx xx Set clock hr./min (1) !,3 0x86 xx Set clock 12/24 (1) !,3 0x87 xx Set clock ratio (1) !,3 0x88 xxxx Dequeue packet by loco addr (1) !, 1,2 0x89 Enable main trk, kill prog (1) ! 0x8A yy Return status of AIU yy (4) <current hi byte> <current lo byte> <change hi byte> <change lo byte> 0x8B Kill main trk, enable prog (1) ! 0x8C dummy inst. returns "!" followed CR/LF(3) !, 0x0D, 0x0A 0x8D xxxx mm Set speed mode of loco xxxx to mode mm, 1=14, 2=28, 3=128 (1) !, 1,3<speed mode, 0 to 3> 0x8E aaaa nn<16 data bytes> Write nn bytes, start at aaaa Must have 16 data bytes, pad them out to 16 if necessary (1) !,4 0x8F aaaa Read 16 bytes, start at aaaa(16) 16 bytes 0x90 cc xx... Send 16 char message to Cab ccLCD line 3. xx = 16 ASCII char (1) ! ,2 0x91 cc xx Send 16 char message to cab cc LCD line 4. xx=16 ASCII (1) !,2 0x92 cc xx Send 8 char message to cab cc LCD line 2 right xx=8 char (1) !,2 0x93 ss<3 byte packet> Queue 3 byte packet to temp _Q send ss times (1) ! 0x94 ss<4 byte packet> Queue 4 byte packet to temp _Q send ss times (1) ! 0x95 ss<5 byte packet> Queue 5 byte packet to temp_Q send ss times (1) ! 0x96 ss<6 byte packet> Queue 6 byte packet to temp _Q send ss times (1) ! 0x97 aaaa xx Write 1 byte to aaaa (1) ! 0x98 aaaa xx xxWrite 2 bytes to aaaa (1) ! 0x99 aaaa<4 data bytes> Write 4 bytes to aaaa (1) ! 0x9A aaaa<8 data bytes> Write 8 bytes to aaaa (1) ! 0x9B yy Return status of AIU yy (short form of command 0x8A) (2) <current hi byte><current lo byte><br> 0x9C xx Execute macro number xx (1) !, 0,3 0x9D aaaa Read 1 byte from aaaa (1) 1 byte 0x9E Enter programming track mode(1) !=success 3=short circuit 0x9F Exit programming track mode (1) !=success 0xA0 aaaa xx Program CV aa with data xx in paged mode (1) !=success 0=program track 0xA1 aaaa Read CV aaaa in paged mode Note: cv data followed by ! for OK. 0xFF followed by 3 for can't read CV (2) !, 0,3 0xA2<4 data bytes> Locomotive control command (1) !,1 0xA3<3 bytepacket> Queue 3 byte packet to TRK _Q (replaces any packet with same address if it exists) (1) !,1 0xA4<4 byte packet> Queue 4 byte packet to TRK _Q (1) !,1 0xA5<5 byte packet> Queue 5 byte packet to TRK _Q (1) !,1 0xA6 rr dd Program register rr with dd (1) !=success 0=no program track 0xA7 rr Read register rr. Note: cv data followed by ! for OK. 0xFF followed by 3 for can't read CV (2) !,3 0=no program track 0xA8 aaaa dd Program CV aaaa with dd in direct mode. (1) !=success 0=no program track 0xA9 aaaa Read CV aaaa in direct mode. Note: cv data followed by ! for OK. 0xFF followed by 3 for can't read CV (2) !,3 0xAA Return software revision number. Format: VV.MM.mm (3) 3 data bytes 0xAB Perform soft reset of command station (like cycling power) (0) Returns nothing 0xAC Perform hard reset of command station. Reset to factory defaults (Note: will change baud rate to 9600)(0) Returns nothing 0xAD <4 data bytes>Accy/signal and macro commands (1) !,1
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jmri.jmrix.AbstractSerialPortController
AbstractSerialPortController.Blocking, AbstractSerialPortController.FlowControl
-
Nested classes/interfaces inherited from class jmri.jmrix.AbstractPortController
AbstractPortController.Option
-
-
Field Summary
Fields Modifier and Type Field Description (package private) byte[]
consistMemory
(package private) int
epromRevision
(package private) byte[]
macroMemory
(package private) char
NCE_BYTE_OUT_OF_RANGE
(package private) char
NCE_CAB_OUT_OF_RANGE
(package private) char
NCE_DATA_OUT_OF_RANGE
(package private) char
NCE_ERROR
(package private) char
NCE_LOCO_OUT_OF_RANGE
(package private) char
NCE_OKAY
(package private) java.lang.String[]
option1Values
(package private) NceTrafficController
tc
(package private) byte[]
turnoutMemory
-
Fields inherited from class jmri.jmrix.AbstractSerialPortController
currentSerialPort, mBaudRate, mPort
-
Fields inherited from class jmri.jmrix.AbstractPortController
allowConnectionRecovery, manufacturerName, opened, option1Name, option2Name, option3Name, option4Name, options, reconnectinterval, reconnectMaxAttempts, reconnectMaxInterval
-
-
Constructor Summary
Constructors Constructor Description SimulatorAdapter()
Create a new SimulatorAdapter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
configure()
Set up all of the other objects to simulate operation with an NCE command station.java.lang.String
getCurrentBaudRate()
java.lang.String
getCurrentPortName()
Overridden in simulator adapter classes to return "";java.io.DataInputStream
getInputStream()
Get the InputStream from the port.java.io.DataOutputStream
getOutputStream()
Get the outputStream to the port.java.lang.String
openPort(java.lang.String portName, java.lang.String appName)
Open a specified port.void
run()
boolean
status()
Query the status of this connection.int[]
validBaudNumbers()
Get an array of valid baud rate numbers; used to store/load adapter speed option.java.lang.String[]
validBaudRates()
Get an array of valid baud rate strings; used to display valid options in Connections Preferences.-
Methods inherited from class jmri.jmrix.nce.NcePortController
getSystemConnectionMemo
-
Methods inherited from class jmri.jmrix.AbstractSerialPortController
activatePort, activatePort, activatePort, closeConnection, closeSerialPort, configureBaudRate, configureBaudRateFromIndex, configureBaudRateFromNumber, configureLeads, configureLeadsAndFlowControl, configureLeadsAndFlowControl, connect, currentBaudNumber, defaultBaudIndex, getActualPortNames, getCurrentBaudIndex, getCurrentBaudNumber, getFlowControl, getPortSettingsString, handlePortBusy, handlePortNotFound, handlePortNotFound, isPortOpen, replacePortWithFakePort, reportPortStatus, resetupConnection, setBaudRate, setComPortTimeouts, setDataListener, setFlowControl, setPort
-
Methods inherited from class jmri.jmrix.AbstractPortController
configureOption1, configureOption2, configureOption3, configureOption4, dispose, getDisabled, getManufacturer, getOption1Name, getOption2Name, getOption3Name, getOption4Name, getOptionChoices, getOptionDisplayName, getOptions, getOptionState, getReconnectMaxAttempts, getReconnectMaxInterval, getSystemPrefix, getUserName, isDirty, isOptionAdvanced, isOptionTypePassword, isOptionTypeText, isRestartRequired, purgeStream, reconnect, reconnectFromLoop, recover, safeSleep, setClosed, setDisabled, setManufacturer, setOpened, setOptionState, setReconnectMaxAttempts, setReconnectMaxInterval, setSystemConnectionMemo, setSystemPrefix, setUserName
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jmri.jmrix.PortAdapter
dispose, getDisabled, getOption1Name, getOption2Name, getOption3Name, getOption4Name, getOptionChoices, getOptionDisplayName, getOptions, getOptionState, getReconnectMaxAttempts, getReconnectMaxInterval, getSystemPrefix, getUserName, isDirty, isOptionAdvanced, isOptionTypePassword, isOptionTypeText, isRestartRequired, recover, setDisabled, setOptionState, setReconnectMaxAttempts, setReconnectMaxInterval, setSystemConnectionMemo, setSystemPrefix, setUserName
-
Methods inherited from interface jmri.jmrix.SerialPortAdapter
configureOption1, configureOption2, configureOption3, configureOption4, getManufacturer, getPortNames, setManufacturer
-
-
-
-
Field Detail
-
NCE_OKAY
char NCE_OKAY
-
NCE_ERROR
char NCE_ERROR
-
NCE_LOCO_OUT_OF_RANGE
char NCE_LOCO_OUT_OF_RANGE
-
NCE_CAB_OUT_OF_RANGE
char NCE_CAB_OUT_OF_RANGE
-
NCE_DATA_OUT_OF_RANGE
char NCE_DATA_OUT_OF_RANGE
-
NCE_BYTE_OUT_OF_RANGE
char NCE_BYTE_OUT_OF_RANGE
-
option1Values
java.lang.String[] option1Values
-
epromRevision
int epromRevision
-
turnoutMemory
byte[] turnoutMemory
-
macroMemory
byte[] macroMemory
-
consistMemory
byte[] consistMemory
-
-
Constructor Detail
-
SimulatorAdapter
public SimulatorAdapter()
Create a new SimulatorAdapter.
-
-
Method Detail
-
openPort
public java.lang.String openPort(java.lang.String portName, java.lang.String appName)
Open a specified port. Simulated input/output pipes.- Specified by:
openPort
in interfaceSerialPortAdapter
- Parameters:
portName
- name tu use for this portappName
- provided to the underlying OS during startup so that it can show on status displays, etc.- Returns:
- null indicates OK return, else error message.
-
configure
public void configure()
Set up all of the other objects to simulate operation with an NCE command station.- Specified by:
configure
in interfacePortAdapter
- Specified by:
configure
in interfaceSerialPortAdapter
-
getInputStream
public java.io.DataInputStream getInputStream()
Get the InputStream from the port.- Specified by:
getInputStream
in interfacePortAdapter
- Overrides:
getInputStream
in classAbstractSerialPortController
- Returns:
- the InputStream from the port
-
getOutputStream
public java.io.DataOutputStream getOutputStream()
Get the outputStream to the port.- Specified by:
getOutputStream
in interfacePortAdapter
- Overrides:
getOutputStream
in classAbstractSerialPortController
- Returns:
- the outputStream to the port
-
status
public boolean status()
Query the status of this connection. This is a question of configuration, not transient hardware status.- Specified by:
status
in interfacePortAdapter
- Specified by:
status
in interfaceSerialPortAdapter
- Overrides:
status
in classAbstractPortController
- Returns:
- true if OK, at least as far as known
-
validBaudRates
public java.lang.String[] validBaudRates()
Get an array of valid baud rate strings; used to display valid options in Connections Preferences.- Specified by:
validBaudRates
in interfaceSerialPortAdapter
- Overrides:
validBaudRates
in classAbstractSerialPortController
- Returns:
- null
-
validBaudNumbers
public int[] validBaudNumbers()
Get an array of valid baud rate numbers; used to store/load adapter speed option.- Specified by:
validBaudNumbers
in interfaceSerialPortAdapter
- Overrides:
validBaudNumbers
in classAbstractSerialPortController
- Returns:
- null
-
getCurrentBaudRate
public java.lang.String getCurrentBaudRate()
Description copied from class:AbstractSerialPortController
- Specified by:
getCurrentBaudRate
in interfaceSerialPortAdapter
- Overrides:
getCurrentBaudRate
in classAbstractSerialPortController
-
getCurrentPortName
public java.lang.String getCurrentPortName()
Description copied from class:AbstractSerialPortController
Overridden in simulator adapter classes to return "";- Specified by:
getCurrentPortName
in interfacePortAdapter
- Specified by:
getCurrentPortName
in interfaceSerialPortAdapter
- Overrides:
getCurrentPortName
in classAbstractSerialPortController
-
run
public void run()
- Specified by:
run
in interfacejava.lang.Runnable
-
-