|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjmri.jmrix.loconet.LnTrafficController
jmri.jmrix.loconet.LnPacketizer
public class LnPacketizer
Converts Stream-based I/O to/from LocoNet messages. The "LocoNetInterface" side sends/receives LocoNetMessage objects. The connection to a LnPortController is via a pair of *Streams, which then carry sequences of characters for transmission.
Messages come to this via the main GUI thread, and are forwarded back to listeners in that same thread. Reception and transmission are handled in dedicated threads by RcvHandler and XmtHandler objects. Those are internal classes defined here. The thread priorities are:
Some of the message formats used in this class are Copyright Digitrax, Inc. and used with permission as part of the JMRI project. That permission does not extend to uses in other software products. If you wish to use this code, algorithm or these message formats outside of JMRI, please contact Digitrax Inc for separate permission.
| Field Summary | |
|---|---|
LnPortController |
controller
|
protected boolean |
echo
true if the external hardware is not echoing messages, so we must |
DataInputStream |
istream
|
OutputStream |
ostream
|
protected Runnable |
rcvHandler
RcvHandler (a local class) object to implement the receive thread |
protected Runnable |
xmtHandler
XmtHandler (a local class) object to implement the transmit thread |
LinkedList |
xmtList
Synchronized list used as a transmit queue. |
| Fields inherited from class jmri.jmrix.loconet.LnTrafficController |
|---|
listeners, receivedByteCount, receivedMsgCount, self, transmittedMsgCount |
| Fields inherited from interface jmri.jmrix.loconet.LocoNetInterface |
|---|
ALL, POWER, PROGRAMMING, SENSORS, SLOTINFO, TURNOUTS |
| Constructor Summary | |
|---|---|
LnPacketizer()
|
|
| Method Summary | |
|---|---|
void |
connectPort(LnPortController p)
Make connection to existing LnPortController object. |
void |
disconnectPort(LnPortController p)
Break connection to existing LnPortController object. |
boolean |
isXmtBusy()
Implement abstract method to signal if there's a backlog of information waiting to be sent. |
protected byte |
readByteProtected(DataInputStream istream)
Read a single byte, protecting against various timeouts, etc. |
void |
run()
Handle incoming characters. |
void |
sendLocoNetMessage(LocoNetMessage m)
Forward a preformatted LocoNetMessage to the actual interface. |
void |
startThreads()
Invoked at startup to start the threads needed here. |
boolean |
status()
|
| Methods inherited from class jmri.jmrix.loconet.LnTrafficController |
|---|
addLocoNetListener, getReceivedByteCount, getReceivedMsgCount, getTransmittedMsgCount, instance, notify, removeLocoNetListener, resetStatistics |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected boolean echo
public LinkedList xmtList
This is public to allow access from the internal class(es) when compiling with Java 1.1
protected Runnable xmtHandler
protected Runnable rcvHandler
public LnPortController controller
public DataInputStream istream
public OutputStream ostream
| Constructor Detail |
|---|
public LnPacketizer()
| Method Detail |
|---|
public boolean status()
status in interface LocoNetInterfacestatus in class LnTrafficControllerpublic void sendLocoNetMessage(LocoNetMessage m)
sendLocoNetMessage in interface LocoNetInterfacesendLocoNetMessage in class LnTrafficControllerm - Message to send; will be updated with CRCpublic boolean isXmtBusy()
isXmtBusy in class LnTrafficControllerpublic void connectPort(LnPortController p)
p - Port controller for connected. Save this for a later
disconnect callpublic void disconnectPort(LnPortController p)
p - previously connected port
protected byte readByteProtected(DataInputStream istream)
throws IOException
When a javax.comm port is set to have a receive timeout (via the enableReceiveTimeout() method), some will return zero bytes or an EOFException at the end of the timeout. In that case, the read should be repeated to get the next real character.
IOExceptionpublic void run()
connectPort.
Terminates with the input stream breaking out of the try block.
public void startThreads()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||