Package jmri.jmrix.sprog
Class SprogTrafficController
- java.lang.Object
-
- jmri.jmrix.sprog.SprogTrafficController
-
- All Implemented Interfaces:
java.lang.Runnable
,SprogInterface
public class SprogTrafficController extends java.lang.Object implements SprogInterface, java.lang.Runnable
Converts Stream-based I/O to/from Sprog messages. The "SprogInterface" side sends/receives message objects. The connection to a SprogPortController is via a pair of *Streams, which then carry sequences of characters for transmission. Note that this processing is handled in an independent thread.Rewritten during 4.11.x series. Create a high priority thread for the tc to move everything off the swing thread. Use a blocking queue to handle asynchronous messages from multiple sources.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Vector<SprogListener>
cmdListeners
(package private) java.io.DataInputStream
istream
(package private) SprogListener
lastSender
(package private) java.io.OutputStream
ostream
protected static SprogTrafficController
self
(package private) java.util.concurrent.BlockingQueue<jmri.jmrix.sprog.SprogTrafficController.MessageTuple>
sendQueue
int
timeout
-
Constructor Summary
Constructors Constructor Description SprogTrafficController(SprogSystemConnectionMemo adaptermemo)
Create a new SprogTrafficController instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addSprogListener(SprogListener l)
void
connectPort(AbstractPortController p)
Make connection to existing PortController object.void
disconnectPort(AbstractPortController p)
Break connection to existing SprogPortController object.void
dispose()
(package private) boolean
endReply(SprogReply msg)
SprogSystemConnectionMemo
getAdapterMemo()
protected SerialDriverAdapter
getController()
Get the port controller, as a SerialDriverAdapter.SprogConstants.SprogState
getSprogState()
void
handleOneIncomingReply()
Handle an incoming reply.boolean
isNormalMode()
boolean
isSIIBootMode()
boolean
isTcThreadAlive()
Check if the Sprog TC Thread ( started on construction of SprogTrafficController ) is alive.boolean
isV4BootMode()
protected void
notifyMessage(SprogMessage m, SprogListener originator)
protected void
notifyReply(SprogReply r)
protected void
notifyReply(SprogReply r, SprogListener lastSender)
void
removeSprogListener(SprogListener l)
void
resetTimeout()
Reset timeout to default depending on current modevoid
run()
Block until a message is available from the queue, send it to the interface and then block until reply is received or a timeout occurs.void
sendSprogMessage(SprogMessage m)
Enqueue a preformatted message to be sent to the actual interfacevoid
sendSprogMessage(SprogMessage m, SprogListener replyTo)
Enqueue a preformatted message to be sent to the actual interfacevoid
sendToInterface(SprogMessage m)
Forward a preformatted message to the interface.void
setAdapterMemo(SprogSystemConnectionMemo adaptermemo)
void
setSprogState(SprogConstants.SprogState s)
void
setTimeout(int t)
boolean
status()
Test operational status of interface.
-
-
-
Field Detail
-
lastSender
SprogListener lastSender
-
timeout
public int timeout
-
cmdListeners
protected java.util.Vector<SprogListener> cmdListeners
-
sendQueue
java.util.concurrent.BlockingQueue<jmri.jmrix.sprog.SprogTrafficController.MessageTuple> sendQueue
-
self
protected static volatile SprogTrafficController self
-
istream
java.io.DataInputStream istream
-
ostream
java.io.OutputStream ostream
-
-
Constructor Detail
-
SprogTrafficController
public SprogTrafficController(SprogSystemConnectionMemo adaptermemo)
Create a new SprogTrafficController instance.- Parameters:
adaptermemo
- the associated SystemConnectionMemo
-
-
Method Detail
-
status
public boolean status()
Description copied from interface:SprogInterface
Test operational status of interface.- Specified by:
status
in interfaceSprogInterface
- Returns:
- true if interface implementation is operational.
-
isTcThreadAlive
public boolean isTcThreadAlive()
Check if the Sprog TC Thread ( started on construction of SprogTrafficController ) is alive. For testing purposes.- Returns:
- true if alive, else false.
-
addSprogListener
public void addSprogListener(SprogListener l)
- Specified by:
addSprogListener
in interfaceSprogInterface
-
removeSprogListener
public void removeSprogListener(SprogListener l)
- Specified by:
removeSprogListener
in interfaceSprogInterface
-
resetTimeout
public void resetTimeout()
Reset timeout to default depending on current mode
-
setTimeout
public void setTimeout(int t)
-
getSprogState
public SprogConstants.SprogState getSprogState()
-
setSprogState
public void setSprogState(SprogConstants.SprogState s)
-
isNormalMode
public boolean isNormalMode()
-
isSIIBootMode
public boolean isSIIBootMode()
-
isV4BootMode
public boolean isV4BootMode()
-
notifyMessage
protected void notifyMessage(SprogMessage m, SprogListener originator)
-
notifyReply
protected void notifyReply(SprogReply r)
-
notifyReply
protected void notifyReply(SprogReply r, SprogListener lastSender)
-
sendSprogMessage
public void sendSprogMessage(SprogMessage m)
Enqueue a preformatted message to be sent to the actual interface- Parameters:
m
- The message to be forwarded
-
sendSprogMessage
public void sendSprogMessage(SprogMessage m, SprogListener replyTo)
Enqueue a preformatted message to be sent to the actual interface- Specified by:
sendSprogMessage
in interfaceSprogInterface
- Parameters:
m
- Message to sendreplyTo
- Who is sending the message
-
run
public void run()
Block until a message is available from the queue, send it to the interface and then block until reply is received or a timeout occurs. This will be a very long timeout to allow for page mode programming operations in SPROG programmer mode.- Specified by:
run
in interfacejava.lang.Runnable
-
sendToInterface
public void sendToInterface(SprogMessage m)
Forward a preformatted message to the interface.- Parameters:
m
- The message to be forwarded
-
connectPort
public void connectPort(AbstractPortController p)
Make connection to existing PortController object.- Parameters:
p
- The port controller
-
getController
protected SerialDriverAdapter getController()
Get the port controller, as a SerialDriverAdapter.- Returns:
- the port controller
-
disconnectPort
public void disconnectPort(AbstractPortController p)
Break connection to existing SprogPortController object.Once broken, attempts to send via "message" member will fail.
- Parameters:
p
- the connection to break
-
setAdapterMemo
public void setAdapterMemo(SprogSystemConnectionMemo adaptermemo)
-
getAdapterMemo
public SprogSystemConnectionMemo getAdapterMemo()
-
endReply
boolean endReply(SprogReply msg)
-
handleOneIncomingReply
public void handleOneIncomingReply()
Handle an incoming reply.
-
dispose
public void dispose()
-
-