Package jmri.jmrix.zimo
Class Mx1Packetizer
- java.lang.Object
-
- jmri.jmrix.zimo.Mx1TrafficController
-
- jmri.jmrix.zimo.Mx1Packetizer
-
- All Implemented Interfaces:
Mx1Interface
public class Mx1Packetizer extends Mx1TrafficController
Access to Zimo Mx1 messages via stream-based I/O. The "Mx1Interface" * side sends/receives Mx1Message objects. The connection to a Mx1PortController 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:
- RcvHandler - at highest available priority
- XmtHandler - down one, which is assumed to be above the GUI
- (everything else)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
Mx1Packetizer.MessageQueued
(package private) class
Mx1Packetizer.RcvHandler
Handle incoming characters.(package private) class
Mx1Packetizer.RetryHandler
Class to handle the re-transmission of messages that have not had a Level 1 response from the command station.(package private) class
Mx1Packetizer.XmtHandler
Captive class to handle transmission
-
Field Summary
Fields Modifier and Type Field Description (package private) int[]
crc8bit_table
(package private) static int
DLE
(package private) static int
EOT
(package private) java.io.DataInputStream
istream
(package private) byte
lastSequence
(package private) java.io.OutputStream
ostream
(package private) Mx1Packetizer.RcvHandler
rcvHandler
RcvHandler (a local class) object to implement the receive thread(package private) Mx1Packetizer.RetryHandler
retryHandler
XmtHandler (a local class) object to implement the transmit thread(package private) static int
SOH
(package private) Mx1Packetizer.XmtHandler
xmtHandler
XmtHandler (a local class) object to implement the transmit thread(package private) java.util.LinkedList<byte[]>
xmtList
Synchronized list used as a transmit queue(package private) java.util.concurrent.ConcurrentHashMap<java.lang.Integer,Mx1Packetizer.MessageQueued>
xmtPackets
-
Fields inherited from class jmri.jmrix.zimo.Mx1TrafficController
adaptermemo, ASCII, BINARY, listeners, mCommandStation, protocol
-
Fields inherited from interface jmri.jmrix.zimo.Mx1Interface
ALL, POWER, PROGRAMMING, SENSORS, SLOTINFO, TURNOUTS
-
-
Constructor Summary
Constructors Constructor Description Mx1Packetizer(Mx1CommandStation pCommandStation, boolean prot)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
connectPort(Mx1PortController p)
Make connection to existing Mx1PortController object.void
disconnectPort(Mx1PortController p)
Break connection to existing LnPortController object.(package private) void
formatByteToPacket(byte b, java.util.ArrayList<java.lang.Byte> message)
int
get16BitCRC(Mx1Message m)
(package private) byte
get8BitCRC(Mx1Message m)
(package private) byte
getNextSequenceNo()
(package private) void
isAckReplyRequired(Mx1Message m)
(package private) void
l1AckPacket(Mx1Message m)
(package private) void
l2AckPacket(Mx1Message m)
(package private) void
notifyLater(Mx1Message m, Mx1Listener reply)
(package private) void
processPacketForSending(Mx1Message m)
protected byte
readByteProtected(java.io.DataInputStream istream)
Read a single byte, protecting against various timeouts, etc.void
sendMx1Message(Mx1Message m, Mx1Listener reply)
Forward a preformatted Mx1Message to the actual interface.void
startThreads()
Invoked at startup to start the threads needed here.boolean
status()
-
Methods inherited from class jmri.jmrix.zimo.Mx1TrafficController
addMx1Listener, getAdapterMemo, getCommandStation, getProtocol, getSystemPrefix, getUserName, notify, removeMx1Listener, setAdapterMemo
-
-
-
-
Field Detail
-
xmtList
java.util.LinkedList<byte[]> xmtList
Synchronized list used as a transmit queue
-
xmtPackets
java.util.concurrent.ConcurrentHashMap<java.lang.Integer,Mx1Packetizer.MessageQueued> xmtPackets
-
xmtHandler
Mx1Packetizer.XmtHandler xmtHandler
XmtHandler (a local class) object to implement the transmit thread
-
retryHandler
Mx1Packetizer.RetryHandler retryHandler
XmtHandler (a local class) object to implement the transmit thread
-
rcvHandler
Mx1Packetizer.RcvHandler rcvHandler
RcvHandler (a local class) object to implement the receive thread
-
istream
java.io.DataInputStream istream
-
ostream
java.io.OutputStream ostream
-
lastSequence
byte lastSequence
-
SOH
static final int SOH
- See Also:
- Constant Field Values
-
EOT
static final int EOT
- See Also:
- Constant Field Values
-
DLE
static final int DLE
- See Also:
- Constant Field Values
-
crc8bit_table
final int[] crc8bit_table
-
-
Constructor Detail
-
Mx1Packetizer
public Mx1Packetizer(Mx1CommandStation pCommandStation, boolean prot)
-
-
Method Detail
-
status
public boolean status()
- Specified by:
status
in interfaceMx1Interface
- Specified by:
status
in classMx1TrafficController
-
sendMx1Message
public void sendMx1Message(Mx1Message m, Mx1Listener reply)
Forward a preformatted Mx1Message to the actual interface. End of Message is added here, then the message is converted to a byte array and queued for transmission- Specified by:
sendMx1Message
in interfaceMx1Interface
- Specified by:
sendMx1Message
in classMx1TrafficController
- Parameters:
m
- Message to send; will be updated with CRCreply
- the listener to notify of a response
-
getNextSequenceNo
byte getNextSequenceNo()
-
processPacketForSending
void processPacketForSending(Mx1Message m)
-
formatByteToPacket
void formatByteToPacket(byte b, java.util.ArrayList<java.lang.Byte> message)
-
connectPort
public void connectPort(Mx1PortController p)
Make connection to existing Mx1PortController object.- Parameters:
p
- Port controller for connected. Save this for a later disconnect call
-
disconnectPort
public void disconnectPort(Mx1PortController 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(java.io.DataInputStream istream) throws java.io.IOException
Read a single byte, protecting against various timeouts, etc.When a 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.
- Parameters:
istream
- the input stream- Returns:
- the first byte in the stream
- Throws:
java.io.IOException
- if unable to read istream
-
notifyLater
void notifyLater(Mx1Message m, Mx1Listener reply)
-
isAckReplyRequired
void isAckReplyRequired(Mx1Message m)
-
l1AckPacket
void l1AckPacket(Mx1Message m)
-
l2AckPacket
void l2AckPacket(Mx1Message m)
-
startThreads
public void startThreads()
Invoked at startup to start the threads needed here.
-
get16BitCRC
public int get16BitCRC(Mx1Message m)
-
get8BitCRC
byte get8BitCRC(Mx1Message m)
-
-