Class MrcPacketizer
- All Implemented Interfaces:
MrcInterface
This is based upon the Packetizer used for LocoNet Connections due to its speed and efficiency to handle messages. This also takes some code from the AbstractMRTrafficController, when dealing with handling replies to messages sent. The MRC Command Station sends out a poll message to each handset which then has approximately 20ms to initially respond with a request. Otherwise the Command Station will poll the next handset.
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)
Some of the message formats used in this class are Copyright MRC, 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 Mrc Inc for separate permission.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class(package private) static class(package private) classCaptive class to handle incoming characters.(package private) classCaptive class to handle transmission -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final int(package private) static final int(package private) int(package private) static final intprotected booleantrue if the external hardware is not echoing messages, so we must(package private) static final int(package private) int(package private) static final int(package private) final MrcMessage(package private) final byte[]protected RunnableRcvHandler (a local class) object to implement the receive thread(package private) static final Object(package private) static final intprotected RunnableXmtHandler (a local class) object to implement the transmit threadSynchronized list used as a transmit queue.Fields inherited from class jmri.jmrix.mrc.MrcTrafficController
adaptermemo, cabAddress, receivedByteCount, receivedMsgCount, trafficListeners, transmittedMsgCountFields inherited from interface jmri.jmrix.mrc.MrcInterface
ALL, CLOCK, POLL, POWER, PROGRAMMING, SENSORS, THROTTLEINFO, TURNOUTS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidMake connection to existing MrcPortController object.voidBreak connection to existing MrcPortController object.booleanImplement abstract method to signal if there's a backlog of information waiting to be sent.protected voidprotected voidWhen a message is finally transmitted, forward it to listeners if echoing is needed.protected bytereadByteProtected(DataInputStream istream) Read a single byte, protecting against various timeouts, etc.voidForward a preformatted MrcMessage to the actual interface.voidInvoked at startup to start the threads needed here.booleanstatus()protected voidtransmitWait(int waitTime, int state, String InterruptMessage, int x) Methods inherited from class jmri.jmrix.mrc.MrcTrafficController
addTrafficListener, changeTrafficListener, getAdapterMemo, getCabNumber, getReceivedByteCount, getReceivedMsgCount, getSystemPrefix, getTransmittedMsgCount, getUserName, notifyRcv, notifyXmit, removeTrafficListener, resetStatistics, setAdapterMemo, setCabNumber
-
Field Details
-
echo
true if the external hardware is not echoing messages, so we must -
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
XmtHandler (a local class) object to implement the transmit thread -
rcvHandler
RcvHandler (a local class) object to implement the receive thread -
controller
-
istream
-
ostream
-
IDLESTATE
- See Also:
-
WAITFORCMDRECEIVED
- See Also:
-
DOUBLELOCOCONTROL
- See Also:
-
MISSEDPOLL
- See Also:
-
BADCOMMAND
- See Also:
-
CONFIRMATIONONLY
- See Also:
-
mCurrentState
int mCurrentState -
consecutiveMissedPolls
-
noData
-
noDataMsg
-
transmitLock
-
-
Constructor Details
-
MrcPacketizer
public MrcPacketizer()
-
-
Method Details
-
status
- Specified by:
statusin interfaceMrcInterface- Specified by:
statusin classMrcTrafficController
-
sendMrcMessage
Forward a preformatted MrcMessage to the actual interface. The message is converted to a byte array and queue for transmission- Specified by:
sendMrcMessagein interfaceMrcInterface- Specified by:
sendMrcMessagein classMrcTrafficController- Parameters:
m- Message to send;
-
isXmtBusy
Implement abstract method to signal if there's a backlog of information waiting to be sent.- Specified by:
isXmtBusyin classMrcTrafficController- Returns:
- true if busy, false if nothing waiting to send
-
connectPort
Make connection to existing MrcPortController object.- Parameters:
p- Port controller for connected. Save this for a later disconnect call
-
disconnectPort
Break connection to existing MrcPortController 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- data input stream from layout- Returns:
- byte stream from interface
- Throws:
IOException- from read errors
-
transmitWait
-
messageFailed
-
messageTransmitted
When a message is finally transmitted, forward it to listeners if echoing is needed.- Parameters:
msg- message to tag a transmitted message
-
startThreads
Invoked at startup to start the threads needed here.
-