Package jmri.jmrix.acela
Class AcelaTrafficController
- java.lang.Object
-
- jmri.jmrix.AbstractMRTrafficController
-
- jmri.jmrix.AbstractMRNodeTrafficController
-
- jmri.jmrix.acela.AcelaTrafficController
-
- All Implemented Interfaces:
AcelaInterface
public class AcelaTrafficController extends AbstractMRNodeTrafficController implements AcelaInterface
Converts Stream-based I/O to/from Acela messages.The "SerialInterface" side sends/receives message objects.
The connection to an AcelaPortController 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.
Handles initialization, polling, output, and input for multiple Serial Nodes.
- See Also:
AbstractMRNodeTrafficController
-
-
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) int
curAcelaNodeIndex
(package private) AcelaSystemConnectionMemo
mMemo
Reference to the system connection memo.(package private) AcelaSensorManager
mSensorManager
(package private) AcelaTurnoutManager
mTurnoutManager
-
Fields inherited from class jmri.jmrix.AbstractMRNodeTrafficController
curSerialNodeIndex, maxNode, minNode, nodeArray, numNodes
-
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 AcelaTrafficController()
Create a new AcelaTrafficController instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAcelaListener(AcelaListener l)
protected boolean
endOfMessage(AbstractMRReply msg)
protected AbstractMRMessage
enterNormalMode()
Sets the system to normal mode during programming while in IDLESTATE.protected AbstractMRMessage
enterProgMode()
Set the system to programming mode.protected void
forwardMessage(AbstractMRListener client, AbstractMRMessage m)
Forward an AcelaMessage to all registered AcelaInterface listeners.protected void
forwardReply(AbstractMRListener client, AbstractMRReply m)
Forward an AcelaReply to all registered AcelaInterface listeners.int
getAcelaSensorInitCount()
boolean
getAcelaSensorsState()
boolean
getAcelaTrafficControllerState()
int
getMaximumNumberOfNodes()
Get maximum number of Acela nodes as set on this TrafficController.int
getMinimumNodeAddress()
Get minimum address of an Acela node as set on this TrafficController.boolean
getNeedToPollNodes()
boolean
getReallyReadyToPoll()
AcelaSystemConnectionMemo
getSystemConnectionMemo()
Get access to the system connection memo associated with this traffic controller.protected void
handleTimeout(AbstractMRMessage m, AbstractMRListener l)
void
incrementAcelaSensorInitCount()
void
initializeAcelaNode(AcelaNode node)
Public method to set up for initialization of an Acela node.protected void
loadChars(AbstractMRReply msg, java.io.DataInputStream istream)
Get characters from the input source, and file a message.int
lookupAcelaNodeAddress(int bitAddress, boolean isSensor)
Public method to identify an AcelaNode from its bit address.protected AbstractMRReply
newReply()
protected AbstractMRMessage
pollMessage()
Handle initialization, output and polling for Acela Nodes from within the running thread.protected AbstractMRListener
pollReplyHandler()
void
registerAcelaNode(AcelaNode node)
Public method to register an Acela node.void
removeAcelaListener(AcelaListener l)
void
resetStartingAddresses()
protected void
resetTimeout(AbstractMRMessage m)
void
sendAcelaMessage(AcelaMessage m, AcelaListener reply)
Forward a pre-formatted message to the actual interface.void
setAcelaSensorsState(boolean newstate)
void
setAcelaTrafficControllerState(boolean newstate)
void
setNeedToPollNodes(boolean newstate)
void
setReallyReadyToPoll(boolean newstate)
void
setSensorManager(AcelaSensorManager m)
void
setSystemConnectionMemo(AcelaSystemConnectionMemo m)
Set the system connection memo associated with this traffic controller.void
setTurnoutManager(AcelaTurnoutManager m)
void
updateSensorsFromPoll(AcelaReply r)
For each sensor node call markChanges.protected void
waitForStartOfReply(java.io.DataInputStream istream)
Dummy routine, to be filled by protocols that have to skip some start-of-message characters.-
Methods inherited from class jmri.jmrix.AbstractMRNodeTrafficController
deleteNode, getMustInit, getNode, getNodeFromAddress, getNumNodes, init, registerNode, setMustInit, setMustInit
-
Methods inherited from class jmri.jmrix.AbstractMRTrafficController
addConsoleListener, addHeaderToOutput, addListener, addTrailerToOutput, canReceive, connectionWarn, connectPort, disconnectPort, distributeReply, enterProgModeDelayTime, forwardToPort, getLastSender, getPortName, getSynchronizeRx, handleOneIncomingReply, hasTimeouts, lengthOfByteStream, newRcvNotifier, notifyMessage, notifyReply, portReadyToSend, portWarn, portWarnTCP, programmerIdle, readByteProtected, receiveLoop, recovery, removeListener, reportReceiveLoopException, sendMessage, setAllowUnexpectedReply, setSynchronizeRx, status, terminate, terminateThreads, transmitLoop, transmitWait, unexpectedReplyStateError, 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.acela.AcelaInterface
status
-
-
-
-
Field Detail
-
curAcelaNodeIndex
transient int curAcelaNodeIndex
-
mMemo
AcelaSystemConnectionMemo mMemo
Reference to the system connection memo.
-
mSensorManager
AcelaSensorManager mSensorManager
-
mTurnoutManager
AcelaTurnoutManager mTurnoutManager
-
-
Constructor Detail
-
AcelaTrafficController
public AcelaTrafficController()
Create a new AcelaTrafficController instance.
-
-
Method Detail
-
addAcelaListener
public void addAcelaListener(AcelaListener l)
- Specified by:
addAcelaListener
in interfaceAcelaInterface
-
removeAcelaListener
public void removeAcelaListener(AcelaListener l)
- Specified by:
removeAcelaListener
in interfaceAcelaInterface
-
getMinimumNodeAddress
public int getMinimumNodeAddress()
Get minimum address of an Acela node as set on this TrafficController.- Returns:
- minimum node address.
-
getMaximumNumberOfNodes
public int getMaximumNumberOfNodes()
Get maximum number of Acela nodes as set on this TrafficController.- Returns:
- max number of nodes.
-
getAcelaTrafficControllerState
public boolean getAcelaTrafficControllerState()
-
setAcelaTrafficControllerState
public void setAcelaTrafficControllerState(boolean newstate)
-
resetStartingAddresses
public void resetStartingAddresses()
-
getAcelaSensorsState
public boolean getAcelaSensorsState()
-
setAcelaSensorsState
public void setAcelaSensorsState(boolean newstate)
-
incrementAcelaSensorInitCount
public void incrementAcelaSensorInitCount()
-
getAcelaSensorInitCount
public int getAcelaSensorInitCount()
-
getNeedToPollNodes
public boolean getNeedToPollNodes()
-
setNeedToPollNodes
public void setNeedToPollNodes(boolean newstate)
-
getReallyReadyToPoll
public boolean getReallyReadyToPoll()
-
setReallyReadyToPoll
public void setReallyReadyToPoll(boolean newstate)
-
getSystemConnectionMemo
public AcelaSystemConnectionMemo getSystemConnectionMemo()
Get access to the system connection memo associated with this traffic controller.- Returns:
- associated systemConnectionMemo object
-
setSystemConnectionMemo
public void setSystemConnectionMemo(AcelaSystemConnectionMemo m)
Set the system connection memo associated with this traffic controller.- Parameters:
m
- associated systemConnectionMemo object
-
registerAcelaNode
public void registerAcelaNode(AcelaNode node)
Public method to register an Acela node.- Parameters:
node
- which node to register.
-
initializeAcelaNode
public void initializeAcelaNode(AcelaNode node)
Public method to set up for initialization of an Acela node.- Parameters:
node
- which node to initialize.
-
lookupAcelaNodeAddress
public int lookupAcelaNodeAddress(int bitAddress, boolean isSensor)
Public method to identify an AcelaNode from its bit address.Note: nodeAddress is numbered from 0
- Parameters:
bitAddress
- address to query.isSensor
- true to use start sensor address, false to use start output address.- Returns:
- '-1' if an AcelaNode with the specified address was not found
-
enterProgMode
protected AbstractMRMessage enterProgMode()
Description copied from class:AbstractMRTrafficController
Set the system to programming mode.- 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()
Description copied from class:AbstractMRTrafficController
Sets the system to normal mode during programming while in IDLESTATE. IfAbstractMRTrafficController.programmerIdle()
returns true, enterNormalMode() is called after a timeout.- 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()
-
forwardMessage
protected void forwardMessage(AbstractMRListener client, AbstractMRMessage m)
Forward an AcelaMessage to all registered AcelaInterface 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
protected void forwardReply(AbstractMRListener client, AbstractMRReply m)
Forward an AcelaReply to all registered AcelaInterface listeners.- Specified by:
forwardReply
in classAbstractMRTrafficController
-
setSensorManager
public void setSensorManager(AcelaSensorManager m)
-
setTurnoutManager
public void setTurnoutManager(AcelaTurnoutManager m)
-
pollMessage
protected AbstractMRMessage pollMessage()
Handle initialization, output and polling for Acela Nodes from within the running thread.- Specified by:
pollMessage
in classAbstractMRTrafficController
- Returns:
- Formatted poll message
-
handleTimeout
protected void handleTimeout(AbstractMRMessage m, AbstractMRListener l)
- Overrides:
handleTimeout
in classAbstractMRTrafficController
-
resetTimeout
protected void resetTimeout(AbstractMRMessage m)
- Overrides:
resetTimeout
in classAbstractMRTrafficController
-
pollReplyHandler
protected AbstractMRListener pollReplyHandler()
- Specified by:
pollReplyHandler
in classAbstractMRTrafficController
-
sendAcelaMessage
public void sendAcelaMessage(AcelaMessage m, AcelaListener reply)
Forward a pre-formatted message to the actual interface.- Specified by:
sendAcelaMessage
in interfaceAcelaInterface
-
newReply
protected AbstractMRReply newReply()
- Specified by:
newReply
in classAbstractMRTrafficController
-
endOfMessage
protected boolean endOfMessage(AbstractMRReply msg)
- Specified by:
endOfMessage
in classAbstractMRTrafficController
-
loadChars
protected void loadChars(AbstractMRReply msg, java.io.DataInputStream istream) throws java.io.IOException
Description copied from class:AbstractMRTrafficController
Get characters from the input source, and file a message.Returns only when the message is complete.
Only used in the Receive thread.
Handles timeouts on read by ignoring zero-length reads.
- Overrides:
loadChars
in classAbstractMRTrafficController
- Parameters:
msg
- message to fillistream
- character source.- Throws:
java.io.IOException
- when presented by the input source.
-
waitForStartOfReply
protected void waitForStartOfReply(java.io.DataInputStream istream) throws java.io.IOException
Description copied from class:AbstractMRTrafficController
Dummy routine, to be filled by protocols that have to skip some start-of-message characters.- Overrides:
waitForStartOfReply
in classAbstractMRTrafficController
- Parameters:
istream
- input source- Throws:
java.io.IOException
- from underlying operations
-
updateSensorsFromPoll
public void updateSensorsFromPoll(AcelaReply r)
For each sensor node call markChanges.- Parameters:
r
- reply to use in sensor update.
-
-