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.DataInputStreamistream(package private) QsiListenerlastSenderstatic intNORMAL(package private) java.io.OutputStreamostreamstatic intSIIBOOTMODEstatic intV4BOOTMODE
-
Constructor Summary
Constructors Constructor Description QsiTrafficController()Create a new QsiTrafficController instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddQsiListener(QsiListener l)voidconnectPort(QsiPortController p)Make connection to existing PortController object.voiddisconnectPort(QsiPortController p)Break connection to existing QsiPortController object.(package private) booleanendNormalReply(QsiReply msg)(package private) booleanendReply(QsiReply msg)intgetQsiState()(package private) voidhandleOneIncomingReply()booleanisNormalMode()booleanisSIIBootMode()booleanisV4BootMode()protected voidnotifyMessage(QsiMessage m, QsiListener notMe)Forward a QsiMessage to all registered QsiInterface listeners.protected voidnotifyReply(QsiReply r)voidremoveQsiListener(QsiListener l)voidrun()Handle incoming characters.voidsendQsiMessage(QsiMessage m, QsiListener reply)Forward a preformatted message to the actual interface.voidsetQsiState(int s)booleanstatus()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:QsiInterfaceTest operational status of interface.- Specified by:
statusin interfaceQsiInterface- Returns:
- true is interface implementation is operational
-
addQsiListener
public void addQsiListener(QsiListener l)
- Specified by:
addQsiListenerin interfaceQsiInterface
-
removeQsiListener
public void removeQsiListener(QsiListener l)
- Specified by:
removeQsiListenerin 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:
sendQsiMessagein 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:
runin interfacejava.lang.Runnable
-
handleOneIncomingReply
void handleOneIncomingReply() throws java.io.IOException
- Throws:
java.io.IOException
-
endNormalReply
boolean endNormalReply(QsiReply msg)
-
-