Package jmri.jmrix.zimo
Class Mx1Packetizer
java.lang.Object
jmri.jmrix.zimo.Mx1TrafficController
jmri.jmrix.zimo.Mx1Packetizer
- All Implemented Interfaces:
Mx1Interface
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 ClassesModifier and TypeClassDescription(package private) static class(package private) classHandle incoming characters.(package private) classClass to handle the re-transmission of messages that have not had a Level 1 response from the command station.(package private) classCaptive class to handle transmission -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final int[](package private) static final int(package private) static final int(package private) DataInputStream(package private) byte(package private) OutputStream(package private) Mx1Packetizer.RcvHandlerRcvHandler (a local class) object to implement the receive thread(package private) Mx1Packetizer.RetryHandlerXmtHandler (a local class) object to implement the transmit thread(package private) static final int(package private) Mx1Packetizer.XmtHandlerXmtHandler (a local class) object to implement the transmit thread(package private) LinkedList<byte[]>Synchronized list used as a transmit queue(package private) ConcurrentHashMap<Integer,Mx1Packetizer.MessageQueued> Fields inherited from class jmri.jmrix.zimo.Mx1TrafficController
adaptermemo, ASCII, BINARY, listeners, mCommandStation, protocolFields inherited from interface jmri.jmrix.zimo.Mx1Interface
ALL, POWER, PROGRAMMING, SENSORS, SLOTINFO, TURNOUTS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidMake connection to existing Mx1PortController object.voidBreak connection to existing LnPortController object.(package private) voidformatByteToPacket(byte b, ArrayList<Byte> message) int(package private) byte(package private) byte(package private) void(package private) void(package private) void(package private) voidnotifyLater(Mx1Message m, Mx1Listener reply) (package private) voidprotected bytereadByteProtected(DataInputStream istream) Read a single byte, protecting against various timeouts, etc.voidsendMx1Message(Mx1Message m, Mx1Listener reply) Forward a preformatted Mx1Message to the actual interface.voidInvoked at startup to start the threads needed here.booleanstatus()Methods inherited from class jmri.jmrix.zimo.Mx1TrafficController
addMx1Listener, getAdapterMemo, getCommandStation, getProtocol, getSystemPrefix, getUserName, notify, removeMx1Listener, setAdapterMemo
-
Field Details
-
xmtList
LinkedList<byte[]> xmtListSynchronized list used as a transmit queue -
xmtPackets
-
xmtHandler
XmtHandler (a local class) object to implement the transmit thread -
retryHandler
XmtHandler (a local class) object to implement the transmit thread -
rcvHandler
RcvHandler (a local class) object to implement the receive thread -
istream
-
ostream
-
lastSequence
byte lastSequence -
SOH
- See Also:
-
EOT
- See Also:
-
DLE
- See Also:
-
crc8bit_table
-
-
Constructor Details
-
Mx1Packetizer
-
-
Method Details
-
status
- Specified by:
statusin interfaceMx1Interface- Specified by:
statusin classMx1TrafficController
-
sendMx1Message
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:
sendMx1Messagein interfaceMx1Interface- Specified by:
sendMx1Messagein classMx1TrafficController- Parameters:
m- Message to send; will be updated with CRCreply- the listener to notify of a response
-
getNextSequenceNo
byte getNextSequenceNo() -
processPacketForSending
-
formatByteToPacket
-
connectPort
Make connection to existing Mx1PortController object.- Parameters:
p- Port controller for connected. Save this for a later disconnect call
-
disconnectPort
Break connection to existing LnPortController object. Once broken, attempts to send via "message" member will fail.- Parameters:
p- previously connected port
-
readByteProtected
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:
IOException- if unable to read istream
-
notifyLater
-
isAckReplyRequired
-
l1AckPacket
-
l2AckPacket
-
startThreads
Invoked at startup to start the threads needed here. -
get16BitCRC
-
get8BitCRC
-