Package jmri.jmrix.qsi
Class QsiTrafficController
- java.lang.Object
-
- jmri.jmrix.qsi.QsiTrafficController
-
- All Implemented Interfaces:
java.lang.Runnable
,QsiInterface
public class QsiTrafficController extends java.lang.Object implements QsiInterface, java.lang.Runnable
Converts Stream-based I/O to/from QSI messages. The "QsiInterface" side sends/receives message objects. The connection to a QsiPortController is via a pair of *Streams, which then carry sequences of characters for transmission. Note that this processing is handled in an independent thread.Messages to and from the programmer are in a packet format. In both directions, every message starts with 'S' and ends with 'E'. These are handled automatically, and are not included in the QsiMessage and QsiReply content.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Vector<QsiListener>
cmdListeners
(package private) java.io.DataInputStream
istream
(package private) QsiListener
lastSender
static int
NORMAL
(package private) java.io.OutputStream
ostream
static int
SIIBOOTMODE
static int
V4BOOTMODE
-
Constructor Summary
Constructors Constructor Description QsiTrafficController()
Create a new QsiTrafficController instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addQsiListener(QsiListener l)
void
connectPort(QsiPortController p)
Make connection to existing PortController object.void
disconnectPort(QsiPortController p)
Break connection to existing QsiPortController object.(package private) boolean
endNormalReply(QsiReply msg)
(package private) boolean
endReply(QsiReply msg)
int
getQsiState()
(package private) void
handleOneIncomingReply()
boolean
isNormalMode()
boolean
isSIIBootMode()
boolean
isV4BootMode()
protected void
notifyMessage(QsiMessage m, QsiListener notMe)
Forward a QsiMessage to all registered QsiInterface listeners.protected void
notifyReply(QsiReply r)
void
removeQsiListener(QsiListener l)
void
run()
Handle incoming characters.void
sendQsiMessage(QsiMessage m, QsiListener reply)
Forward a preformatted message to the actual interface.void
setQsiState(int s)
boolean
status()
Test operational status of interface.
-
-
-
Field Detail
-
cmdListeners
protected java.util.Vector<QsiListener> cmdListeners
-
lastSender
QsiListener lastSender
-
NORMAL
public static final int NORMAL
- See Also:
- Constant Field Values
-
SIIBOOTMODE
public static final int SIIBOOTMODE
- See Also:
- Constant Field Values
-
V4BOOTMODE
public static final int V4BOOTMODE
- See Also:
- Constant Field Values
-
istream
java.io.DataInputStream istream
-
ostream
java.io.OutputStream ostream
-
-
Constructor Detail
-
QsiTrafficController
public QsiTrafficController()
Create a new QsiTrafficController instance.
-
-
Method Detail
-
status
public boolean status()
Description copied from interface:QsiInterface
Test operational status of interface.- Specified by:
status
in interfaceQsiInterface
- Returns:
- true is interface implementation is operational
-
addQsiListener
public void addQsiListener(QsiListener l)
- Specified by:
addQsiListener
in interfaceQsiInterface
-
removeQsiListener
public void removeQsiListener(QsiListener l)
- Specified by:
removeQsiListener
in interfaceQsiInterface
-
notifyMessage
protected void notifyMessage(QsiMessage m, QsiListener notMe)
Forward a QsiMessage to all registered QsiInterface listeners.- Parameters:
m
- message to forward.notMe
- Listener to hear the returned status
-
getQsiState
public int getQsiState()
-
setQsiState
public void setQsiState(int s)
-
isNormalMode
public boolean isNormalMode()
-
isSIIBootMode
public boolean isSIIBootMode()
-
isV4BootMode
public boolean isV4BootMode()
-
notifyReply
protected void notifyReply(QsiReply r)
-
sendQsiMessage
public void sendQsiMessage(QsiMessage m, QsiListener reply)
Forward a preformatted message to the actual interface.- Specified by:
sendQsiMessage
in interfaceQsiInterface
- Parameters:
m
- Message to be sent.reply
- Listener to be notified of reply.
-
connectPort
public void connectPort(QsiPortController p)
Make connection to existing PortController object.- Parameters:
p
- the QSI port controller.
-
disconnectPort
public void disconnectPort(QsiPortController p)
Break connection to existing QsiPortController object. Once broken, attempts to send via "message" member will fail.- Parameters:
p
- the QSI port controller.
-
run
public void run()
Handle incoming characters. This is a permanent loop, looking for input messages in character form on the stream connected to the PortController viaconnectPort
. Terminates with the input stream breaking out of the try block.- Specified by:
run
in interfacejava.lang.Runnable
-
handleOneIncomingReply
void handleOneIncomingReply() throws java.io.IOException
- Throws:
java.io.IOException
-
endNormalReply
boolean endNormalReply(QsiReply msg)
-
-