Class GcTrafficController
java.lang.Object
jmri.jmrix.AbstractMRTrafficController
jmri.jmrix.can.AbstractCanTrafficController
jmri.jmrix.can.TrafficController
jmri.jmrix.can.adapters.gridconnect.GcTrafficController
- All Implemented Interfaces:
CanInterface
- Direct Known Subclasses:
MergTrafficController
public class GcTrafficController extends TrafficController
Traffic controller for the GridConnect protocol.
GridConnect uses messages transmitted as an ASCII string of up to 24 characters of the form: :ShhhhNd0d1d2d3d4d5d6d7;
The S indicates a standard CAN frame hhhh is the two byte header (11 useful bits) N or R indicates a normal or remote frame d0 - d7 are the (up to) 8 data bytes
-
Nested Class Summary
Nested classes/interfaces inherited from class jmri.jmrix.AbstractMRTrafficController
AbstractMRTrafficController.RcvNotifier, AbstractMRTrafficController.XmtNotifier
-
Field Summary
Fields inherited from class jmri.jmrix.AbstractMRTrafficController
allowUnexpectedReply, AUTORETRYSTATE, cmdListeners, connectionError, controller, flushReceiveChars, IDLESTATE, istream, listenerQueue, maxRcvExceptionCount, mCurrentMode, mCurrentState, mLastSender, msgQueue, mWaitBeforePoll, NORMALMODE, NOTIFIEDSTATE, OKSENDMSGSTATE, ostream, POLLSTATE, PROGRAMINGMODE, rcvException, rcvThread, replyInDispatch, threadStopRequest, WAITMSGREPLYSTATE, WAITREPLYINNORMMODESTATE, WAITREPLYINPROGMODESTATE, waitTimePoll, xmtException, xmtRunnable, xmtThread
-
Constructor Summary
Constructors Constructor Description GcTrafficController()
Create new GridConnect Traffic Controller. -
Method Summary
Modifier and Type Method Description protected void
addTrailerToOutput(byte[] msg, int offset, AbstractMRMessage m)
Does nothing.CanReply
decodeFromHardware(AbstractMRReply m)
Make a CanReply from a GridConnect reply.AbstractMRMessage
encodeForHardware(CanMessage m)
Encode a CanMessage for the hardware.(package private) boolean
endNormalReply(AbstractMRReply r)
Detect if the reply buffer ends with ";".protected boolean
endOfMessage(AbstractMRReply r)
protected void
forwardMessage(AbstractMRListener client, AbstractMRMessage m)
Forward a CanMessage to all registered CanInterface listeners.protected void
forwardReply(AbstractMRListener client, AbstractMRReply r)
Forward a CanReply to all registered CanInterface listeners.int
getgcState()
Get the GridConnect State.boolean
isBootMode()
Get if GcTC is in Boot Mode.protected int
lengthOfByteStream(AbstractMRMessage m)
Determine how much many bytes the entire message will take, including space for header and trailer.protected void
loadChars(AbstractMRReply msg, DataInputStream istream)
Get characters from the input source, and file a message.protected AbstractMRMessage
newMessage()
Get new message for hardware protocol.protected AbstractMRReply
newReply()
New reply from hardware.void
sendCanMessage(CanMessage m, CanListener reply)
Forward a preformatted message to the actual interface.void
sendCanReply(CanReply r, CanListener reply)
Forward a preformatted reply to the actual interface.void
setgcState(int state)
Set the GridConnect State.Methods inherited from class jmri.jmrix.can.AbstractCanTrafficController
addCanListener, distributeOneReply, enterNormalMode, enterProgMode, forwardToPort, handleOneIncomingReply, pollMessage, pollReplyHandler, removeCanListener
Methods inherited from class jmri.jmrix.AbstractMRTrafficController
addHeaderToOutput, addListener, canReceive, connectionWarn, connectPort, disconnectPort, distributeReply, enterProgModeDelayTime, finalize, getLastSender, getPortName, getSynchronizeRx, handleTimeout, hasTimeouts, newRcvNotifier, notifyMessage, notifyReply, portReadyToSend, portWarn, portWarnTCP, programmerIdle, readByteProtected, receiveLoop, recovery, removeListener, reportReceiveLoopException, resetTimeout, sendMessage, setAllowUnexpectedReply, setSynchronizeRx, status, terminate, terminateThreads, transmitLoop, transmitWait, unexpectedReplyStateError, waitForStartOfReply
-
Field Details
-
NORMAL
- See Also:
- Constant Field Values
-
BOOTMODE
- See Also:
- Constant Field Values
-
-
Constructor Details
-
GcTrafficController
public GcTrafficController()Create new GridConnect Traffic Controller.
-
-
Method Details
-
forwardMessage
Forward a CanMessage to all registered CanInterface listeners. Implement this to forward a specific message type to a protocol-specific listener interface. This puts the casting into the concrete class.- Specified by:
forwardMessage
in classAbstractMRTrafficController
- Parameters:
client
- abstract listener.m
- message to forward.
-
forwardReply
Forward a CanReply to all registered CanInterface listeners.- Specified by:
forwardReply
in classAbstractMRTrafficController
-
getgcState
Get the GridConnect State.- Returns:
- NORMAL or BOOTMODE
-
setgcState
Set the GridConnect State.- Parameters:
state
- NORMAL or BOOTMODE
-
isBootMode
Get if GcTC is in Boot Mode.- Returns:
- true if in Boot Mode, else False.
-
sendCanMessage
Forward a preformatted message to the actual interface. Send a message through the interface.- Parameters:
m
- Message to be sent.reply
- Listener to be notified of reply.
-
sendCanReply
Forward a preformatted reply to the actual interface. Send a reply through the interface.- Parameters:
r
- Reply to be sent.reply
- Listener to be notified of reply.
-
addTrailerToOutput
Does nothing. Add trailer to the outgoing byte stream.- Overrides:
addTrailerToOutput
in classAbstractMRTrafficController
- Parameters:
msg
- the output byte streamoffset
- the first byte not yet usedm
- output message to extend
-
lengthOfByteStream
Determine how much many bytes the entire message will take, including space for header and trailer.- Overrides:
lengthOfByteStream
in classAbstractMRTrafficController
- Parameters:
m
- The message to be sent- Returns:
- Number of bytes
-
newMessage
Get new message for hardware protocol.- Specified by:
newMessage
in classAbstractCanTrafficController
- Returns:
- New GridConnect Message.
-
decodeFromHardware
Make a CanReply from a GridConnect reply.- Specified by:
decodeFromHardware
in classAbstractCanTrafficController
-
encodeForHardware
Encode a CanMessage for the hardware.- Specified by:
encodeForHardware
in classAbstractCanTrafficController
-
newReply
New reply from hardware.- Specified by:
newReply
in classAbstractMRTrafficController
-
endOfMessage
- Specified by:
endOfMessage
in classAbstractMRTrafficController
-
endNormalReply
Detect if the reply buffer ends with ";".- Parameters:
r
- Reply- Returns:
- true if contais end, else false.
-
loadChars
Get characters from the input source, and file a message.Returns only when the message is complete.
This is over-ridden from AbstractMRTrafficController so we can add suppression of the characters before ':'. We can't use waitForStartOfReply() because that strips the 1st character also.
Handles timeouts on read by ignoring zero-length reads.
- Overrides:
loadChars
in classAbstractMRTrafficController
- Parameters:
msg
- message to fillistream
- character source.- Throws:
IOException
- when presented by the input source.
-