Package jmri.jmrix.lenz.xntcp
Class XnTcpAdapter
- java.lang.Object
-
- jmri.jmrix.AbstractPortController
-
- jmri.jmrix.AbstractNetworkPortController
-
- jmri.jmrix.lenz.XNetNetworkPortController
-
- jmri.jmrix.lenz.xntcp.XnTcpAdapter
-
- All Implemented Interfaces:
XNetPortController
,NetworkPortAdapter
,PortAdapter
public class XnTcpAdapter extends XNetNetworkPortController
Provide access to XpressNet via a XnTcp interface attached on the Ethernet port.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
XnTcpAdapter.OutputTcpStream
Output class, used to count output packets and make sure that they are immediatelly sent.-
Nested classes/interfaces inherited from class jmri.jmrix.AbstractPortController
AbstractPortController.Option
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static int
BROADCAST_TIMEOUT
(package private) static java.lang.String
DEFAULT_IP_ADDRESS
(package private) static int
DEFAULT_TCP_PORT
(package private) static int
DEFAULT_UDP_PORT
(package private) static int
MAX_PENDING_PACKETS
(package private) static int
READ_TIMEOUT
(package private) static int
UDP_LENGTH
-
Fields inherited from class jmri.jmrix.AbstractNetworkPortController
connTimeout, m_HostName, m_port, socketConn
-
Fields inherited from class jmri.jmrix.AbstractPortController
allowConnectionRecovery, manufacturerName, opened, option1Name, option2Name, option3Name, option4Name, options, reconnectinterval, reconnectMaxAttempts, reconnectMaxInterval
-
-
Constructor Summary
Constructors Constructor Description XnTcpAdapter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
configure()
Set up all of the other objects to operate with a XnTcp interface.void
connect()
Open the connection.java.io.DataInputStream
getInputStream()
Get the InputStream from the port.java.util.Vector<java.lang.String>
getInterfaceNames()
(package private) java.lang.String[]
getInterfaces()
java.io.DataOutputStream
getOutputStream()
Get the outputStream to the port.boolean
okToSend()
Can the port accept additional characters?boolean
status()
Check that this object is ready to operate.protected void
xnTcpError()
If an error occurs, either in the input or output thread, set the connection status to disconnected.protected void
xnTcpSetPendingPackets(int s)
TCP/IP stack and the XnTcp interface provide enough buffering to avoid overrun.-
Methods inherited from class jmri.jmrix.lenz.XNetNetworkPortController
dispose, getSystemConnectionMemo, hasTimeSlot, resetupConnection, setOutputBufferEmpty, setTimeSlot
-
Methods inherited from class jmri.jmrix.AbstractNetworkPortController
autoConfigure, closeConnection, connect, getAdvertisementName, getConnectionTimeout, getCurrentPortName, getHostAddress, getHostName, getMdnsConfigure, getPort, getServiceType, reconnectFromLoop, setAdvertisementName, setConnectionTimeout, setHostAddress, setHostName, setMdnsConfigure, setPort, setPort, setServiceType
-
Methods inherited from class jmri.jmrix.AbstractPortController
configureOption1, configureOption2, configureOption3, configureOption4, getDisabled, getManufacturer, getOption1Name, getOption2Name, getOption3Name, getOption4Name, getOptionChoices, getOptionDisplayName, getOptions, getOptionState, getReconnectMaxAttempts, getReconnectMaxInterval, getSystemPrefix, getUserName, isDirty, isOptionAdvanced, isOptionTypePassword, isOptionTypeText, isRestartRequired, purgeStream, reconnect, 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
configureOption1, configureOption2, configureOption3, configureOption4, getDisabled, getManufacturer, getOption1Name, getOption2Name, getOption3Name, getOption4Name, getOptionChoices, getOptionDisplayName, getOptions, getOptionState, getReconnectMaxAttempts, getReconnectMaxInterval, getSystemPrefix, getUserName, isDirty, isOptionAdvanced, isOptionTypePassword, isOptionTypeText, isRestartRequired, recover, setDisabled, setManufacturer, setOptionState, setReconnectMaxAttempts, setReconnectMaxInterval, setSystemConnectionMemo, setSystemPrefix, setUserName
-
-
-
-
Field Detail
-
DEFAULT_UDP_PORT
static final int DEFAULT_UDP_PORT
- See Also:
- Constant Field Values
-
DEFAULT_TCP_PORT
static final int DEFAULT_TCP_PORT
- See Also:
- Constant Field Values
-
DEFAULT_IP_ADDRESS
static final java.lang.String DEFAULT_IP_ADDRESS
- See Also:
- Constant Field Values
-
UDP_LENGTH
static final int UDP_LENGTH
- See Also:
- Constant Field Values
-
BROADCAST_TIMEOUT
static final int BROADCAST_TIMEOUT
- See Also:
- Constant Field Values
-
READ_TIMEOUT
static final int READ_TIMEOUT
- See Also:
- Constant Field Values
-
MAX_PENDING_PACKETS
static final int MAX_PENDING_PACKETS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
XnTcpAdapter
public XnTcpAdapter()
-
-
Method Detail
-
getInterfaces
java.lang.String[] getInterfaces()
-
getInterfaceNames
public java.util.Vector<java.lang.String> getInterfaceNames()
-
connect
public void connect() throws java.io.IOException
Description copied from interface:PortAdapter
Open the connection.- Specified by:
connect
in interfacePortAdapter
- Overrides:
connect
in classAbstractNetworkPortController
- Throws:
java.io.IOException
- if unable to connect
-
xnTcpSetPendingPackets
protected void xnTcpSetPendingPackets(int s)
TCP/IP stack and the XnTcp interface provide enough buffering to avoid overrun. However, queueing commands faster than they can be processed should in general be avoided.To this purpose, a counter is incremented each time a packet is queued and decremented when a reply from the interface is received. When the counter reaches the pre-defined maximum (e.g. 15) queuing of commands is blocked. Owing to broadcasts from the command station, the number of commands received can actually be higher than that of commands sent, but this fact simply implies that we may have a higher number of pending commands for a while, without any negative consequence (the maximum is however arbitrary).
- Parameters:
s
- number to send
-
xnTcpError
protected void xnTcpError()
If an error occurs, either in the input or output thread, set the connection status to disconnected. This status will be reset once a TCP/IP connection is re-established via the reconnection routines defined in the parent classes.
-
okToSend
public boolean okToSend()
Can the port accept additional characters? There is no CTS signal available. We only limit the number of commands queued in TCP/IP stack- Specified by:
okToSend
in interfaceXNetPortController
- Overrides:
okToSend
in classXNetNetworkPortController
- Returns:
- true if OK to send, else false.
-
configure
public void configure()
Set up all of the other objects to operate with a XnTcp interface.
-
getInputStream
public java.io.DataInputStream getInputStream()
Description copied from class:AbstractNetworkPortController
Get the InputStream from the port.- Specified by:
getInputStream
in interfacePortAdapter
- Overrides:
getInputStream
in classAbstractNetworkPortController
- Returns:
- the InputStream from the port
-
getOutputStream
public java.io.DataOutputStream getOutputStream()
Description copied from class:AbstractNetworkPortController
Get the outputStream to the port.- Specified by:
getOutputStream
in interfacePortAdapter
- Overrides:
getOutputStream
in classAbstractNetworkPortController
- Returns:
- the outputStream to the port
-
status
public boolean status()
Description copied from class:XNetNetworkPortController
Check that this object is ready to operate. This is a question of configuration, not transient hardware status.- Specified by:
status
in interfaceNetworkPortAdapter
- Specified by:
status
in interfacePortAdapter
- Specified by:
status
in interfaceXNetPortController
- Specified by:
status
in classXNetNetworkPortController
- Returns:
- true if OK, at least as far as known
-
-