jmri.jmrix.loconet
Class LnPacketizer

java.lang.Object
  extended by jmri.jmrix.loconet.LnTrafficController
      extended by jmri.jmrix.loconet.LnPacketizer
All Implemented Interfaces:
LocoNetInterface
Direct Known Subclasses:
IBLnPacketizer, LnOverTcpPacketizer, LnPacketizer

public class LnPacketizer
extends LnTrafficController

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.

Author:
Bob Jacobsen Copyright (C) 2001

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

echo

protected boolean echo
true if the external hardware is not echoing messages, so we must


xmtList

public LinkedList xmtList
Synchronized list used as a transmit queue.

This is public to allow access from the internal class(es) when compiling with Java 1.1


xmtHandler

protected Runnable xmtHandler
XmtHandler (a local class) object to implement the transmit thread


rcvHandler

protected Runnable rcvHandler
RcvHandler (a local class) object to implement the receive thread


controller

public LnPortController controller

istream

public DataInputStream istream

ostream

public OutputStream ostream
Constructor Detail

LnPacketizer

public LnPacketizer()
Method Detail

status

public boolean status()
Specified by:
status in interface LocoNetInterface
Specified by:
status in class LnTrafficController

sendLocoNetMessage

public void sendLocoNetMessage(LocoNetMessage m)
Forward a preformatted LocoNetMessage to the actual interface. Checksum is computed and overwritten here, then the message is converted to a byte array and queue for transmission

Specified by:
sendLocoNetMessage in interface LocoNetInterface
Specified by:
sendLocoNetMessage in class LnTrafficController
Parameters:
m - Message to send; will be updated with CRC

isXmtBusy

public boolean isXmtBusy()
Implement abstract method to signal if there's a backlog of information waiting to be sent.

Specified by:
isXmtBusy in class LnTrafficController
Returns:
true if busy, false if nothing waiting to send

connectPort

public void connectPort(LnPortController p)
Make connection to existing LnPortController object.

Parameters:
p - Port controller for connected. Save this for a later disconnect call

disconnectPort

public void disconnectPort(LnPortController p)
Break connection to existing LnPortController object. Once broken, attempts to send via "message" member will fail.

Parameters:
p - previously connected port

readByteProtected

protected byte readByteProtected(DataInputStream istream)
                          throws IOException
Read a single byte, protecting against various timeouts, etc.

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.

Throws:
IOException

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 LnPortController via connectPort. Terminates with the input stream breaking out of the try block.


startThreads

public void startThreads()
Invoked at startup to start the threads needed here.



Copyright © 1997 - 2008 JMRI Community.
JMRI, DecoderPro, PanelPro, SoundPro, DispatcherPro and associated logos are our trademarks.

Additional information on copyright, trademarks and licenses is linked here.
Site hosted by: SourceForge_Logo