Package jmri.jmrix.ecos
Class EcosTrafficController
- java.lang.Object
-
- jmri.jmrix.AbstractMRTrafficController
-
- jmri.jmrix.ecos.EcosTrafficController
-
- All Implemented Interfaces:
EcosInterface
public class EcosTrafficController extends AbstractMRTrafficController implements EcosInterface
Converts Stream-based I/O to/from ECOS messages. The "EcosInterface" side sends/receives message objects.The connection to a EcosPortController is via a pair of *Streams, which then carry sequences of characters for transmission. Note that this processing is handled in an independent thread.
This handles the state transitions, based on the necessary state in each message.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jmri.jmrix.AbstractMRTrafficController
AbstractMRTrafficController.RcvNotifier, AbstractMRTrafficController.XmtNotifier
-
-
Field Summary
Fields Modifier and Type Field Description (package private) EcosSystemConnectionMemo
adaptermemo
protected static EcosTrafficController
self
protected boolean
unsolicitedSensorMessageSeen
-
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, timeoutFlag, timeouts, WAITMSGREPLYSTATE, WAITREPLYINNORMMODESTATE, WAITREPLYINPROGMODESTATE, waitTimePoll, xmtException, xmtRunnable, xmtThread
-
-
Constructor Summary
Constructors Constructor Description EcosTrafficController()
Create a new EcosTrafficController instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEcosListener(EcosListener l)
protected boolean
canReceive()
Override in the system specific code if necessaryprotected boolean
endOfMessage(AbstractMRReply msg)
protected AbstractMRMessage
enterNormalMode()
ECoS doesn't support this function.protected AbstractMRMessage
enterProgMode()
ECoS doesn't support this function.protected int
enterProgModeDelayTime()
Get the delay (wait time) after enabling the programming track.protected void
forwardMessage(AbstractMRListener client, AbstractMRMessage m)
Implement this to forward a specific message type to a protocol-specific listener interface.protected void
forwardReply(AbstractMRListener client, AbstractMRReply r)
Forward a EcosReply to all registered EcosInterface listeners.protected void
forwardToPort(AbstractMRMessage m, AbstractMRListener reply)
Actually transmit the next message to the port.protected AbstractMRReply
newReply()
protected AbstractMRMessage
pollMessage()
Invoked if it's appropriate to do low-priority polling of the command station, this should return the next message to send, or null if the TrafficController should just sleep.protected AbstractMRListener
pollReplyHandler()
void
removeEcosListener(EcosListener l)
void
sendEcosMessage(EcosMessage m, EcosListener reply)
Send a message through the interface.boolean
sendWaitMessage(EcosMessage m, AbstractMRListener reply)
void
setAdapterMemo(EcosSystemConnectionMemo memo)
protected void
terminate()
-
Methods inherited from class jmri.jmrix.AbstractMRTrafficController
addConsoleListener, addHeaderToOutput, addListener, addTrailerToOutput, connectionWarn, connectPort, disconnectPort, distributeReply, getLastSender, getPortName, getSynchronizeRx, handleOneIncomingReply, handleTimeout, hasTimeouts, lengthOfByteStream, loadChars, newRcvNotifier, notifyMessage, notifyReply, portReadyToSend, portWarn, portWarnTCP, programmerIdle, readByteProtected, receiveLoop, recovery, removeListener, reportReceiveLoopException, resetTimeout, sendMessage, setAllowUnexpectedReply, setSynchronizeRx, status, terminateThreads, transmitLoop, transmitWait, unexpectedReplyStateError, waitForStartOfReply, warnOnTimeout
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jmri.jmrix.ecos.EcosInterface
status
-
-
-
-
Field Detail
-
adaptermemo
EcosSystemConnectionMemo adaptermemo
-
unsolicitedSensorMessageSeen
protected boolean unsolicitedSensorMessageSeen
-
self
protected static final EcosTrafficController self
-
-
Constructor Detail
-
EcosTrafficController
public EcosTrafficController()
Create a new EcosTrafficController instance.
-
-
Method Detail
-
setAdapterMemo
public void setAdapterMemo(EcosSystemConnectionMemo memo)
-
addEcosListener
public void addEcosListener(EcosListener l)
- Specified by:
addEcosListener
in interfaceEcosInterface
-
removeEcosListener
public void removeEcosListener(EcosListener l)
- Specified by:
removeEcosListener
in interfaceEcosInterface
-
enterProgModeDelayTime
protected int enterProgModeDelayTime()
Get the delay (wait time) after enabling the programming track. Override in subclass to add a longer delay.- Overrides:
enterProgModeDelayTime
in classAbstractMRTrafficController
- Returns:
- 0 as default delay
-
forwardMessage
protected void forwardMessage(AbstractMRListener client, AbstractMRMessage m)
Implement this to forward a specific message type to a protocol-specific listener interface. This puts the casting into the concrete class. Forward an EcosMessage to all registered EcosInterface listeners.- Specified by:
forwardMessage
in classAbstractMRTrafficController
- Parameters:
client
- abstract listener.m
- message to forward.
-
forwardReply
protected void forwardReply(AbstractMRListener client, AbstractMRReply r)
Forward a EcosReply to all registered EcosInterface listeners.- Specified by:
forwardReply
in classAbstractMRTrafficController
-
pollMessage
protected AbstractMRMessage pollMessage()
Invoked if it's appropriate to do low-priority polling of the command station, this should return the next message to send, or null if the TrafficController should just sleep.- Specified by:
pollMessage
in classAbstractMRTrafficController
- Returns:
- Formatted poll message
-
pollReplyHandler
protected AbstractMRListener pollReplyHandler()
- Specified by:
pollReplyHandler
in classAbstractMRTrafficController
-
sendEcosMessage
public void sendEcosMessage(EcosMessage m, EcosListener reply)
Send a message through the interface.- Specified by:
sendEcosMessage
in interfaceEcosInterface
- Parameters:
m
- Message to be sent.reply
- Listener to be notified of reply.
-
forwardToPort
protected void forwardToPort(AbstractMRMessage m, AbstractMRListener reply)
Actually transmit the next message to the port.- Overrides:
forwardToPort
in classAbstractMRTrafficController
- Parameters:
m
- the message to sendreply
- the Listener sending the message, often provided as 'this'- See Also:
AbstractMRTrafficController.sendMessage(AbstractMRMessage, AbstractMRListener)
-
enterProgMode
protected AbstractMRMessage enterProgMode()
ECoS doesn't support this function.- Specified by:
enterProgMode
in classAbstractMRTrafficController
- Returns:
- any message that needs to be returned to the Command Station to change modes. If no message is needed, returns null.
- See Also:
AbstractMRTrafficController.enterNormalMode()
-
enterNormalMode
protected AbstractMRMessage enterNormalMode()
ECoS doesn't support this function.- Specified by:
enterNormalMode
in classAbstractMRTrafficController
- Returns:
- any message that needs to be returned to the Command Station to change modes. If no message is needed, returns null.
- See Also:
AbstractMRTrafficController.enterProgMode()
-
newReply
protected AbstractMRReply newReply()
- Specified by:
newReply
in classAbstractMRTrafficController
-
canReceive
protected boolean canReceive()
Override in the system specific code if necessary- Overrides:
canReceive
in classAbstractMRTrafficController
- Returns:
- for now, receive always OK
-
endOfMessage
protected boolean endOfMessage(AbstractMRReply msg)
- Specified by:
endOfMessage
in classAbstractMRTrafficController
-
sendWaitMessage
public boolean sendWaitMessage(EcosMessage m, AbstractMRListener reply)
-
terminate
protected void terminate()
- Overrides:
terminate
in classAbstractMRTrafficController
-
-