Package jmri.jmrix.rps
Class Engine
- java.lang.Object
-
- jmri.jmrix.rps.Engine
-
- All Implemented Interfaces:
ReadingListener
public class Engine extends java.lang.Object implements ReadingListener
Engine does basic computations of RPS system.Holds all the alignment info. Receivers are indexed by their RPS receiver number in all cases.
Gets a reading from the Distributor and passes back a Measurement
Bound properties:
- vSound - velocity of sound, in whatever units are in use
This class maintains a collection of "Transmitter" objects representing the RPS-equipped rolling stock (usually engines) on the layout. This is an extension to the common Roster, and every entry in this class's collection must be present in the Roster.
-
-
Field Summary
Fields Modifier and Type Field Description protected static Engine
_instance
(package private) java.lang.String
algorithm
(package private) boolean
bscPoll
(package private) Measurement
lastPoint
(package private) int
pollIndex
(package private) boolean
polling
(package private) int
pollingInterval
(package private) boolean
pollOutstanding
(package private) java.lang.Thread
pollThread
(package private) java.beans.PropertyChangeSupport
prop
(package private) Receiver[]
receivers
(package private) boolean
throttlePoll
(package private) java.util.ArrayList<Transmitter>
transmitters
-
Constructor Summary
Constructors Constructor Description Engine()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPropertyChangeListener(java.beans.PropertyChangeListener p)
void
dispose()
java.lang.String
getAlgorithm()
boolean
getBscPollMode()
boolean
getDirectPollMode()
int
getMaxReceiverNumber()
int
getNumTransmitters()
int
getOffset()
int
getPolledAddress()
java.lang.String
getPolledID()
boolean
getPolling()
int
getPollingInterval()
Receiver
getReceiver(int i)
javax.vecmath.Point3d
getReceiverPosition(int i)
boolean
getThrottlePollMode()
Transmitter
getTransmitter(int i)
Transmitter
getTransmitterByAddress(int addr)
double
getVSound()
static Engine
instance()
void
loadAlignment(java.io.File file)
(package private) void
loadInitialTransmitters()
void
loadPollConfig(java.io.File file)
(package private) void
loadValues()
void
notify(Reading r)
void
removePropertyChangeListener(java.beans.PropertyChangeListener p)
(package private) void
saveLastMeasurement(java.lang.String id, Measurement m)
(package private) int
selectNextPoll()
The real core of the polling, this selects the next one to poll. -1 means none selected, try again later.void
setAlgorithm(java.lang.String algorithm)
void
setBscPollMode()
protected void
setDefaultAlignment()
void
setDirectPollMode()
protected void
setInitialAlignment()
void
setMaxReceiverNumber(int n)
Set the maximum receiver number expected.(package private) void
setOff(int i)
void
setOffset(int offset)
(package private) void
setOn(int i)
void
setPolling(boolean polling)
void
setPollingInterval(int pollingInterval)
void
setReceiver(int address, Receiver receiver)
Set a particular receiver by address (starting at 1).void
setReceiverPosition(int i, javax.vecmath.Point3d p)
void
setThrottlePollMode()
void
setVSound(double v)
(package private) void
startPoll()
(package private) void
stopPoll()
void
storeAlignment(java.io.File file)
void
storePollConfig(java.io.File file)
(package private) void
waitBeforeNextPoll(int pollingInterval)
Wait before sending next poll.
-
-
-
Field Detail
-
lastPoint
Measurement lastPoint
-
algorithm
java.lang.String algorithm
-
pollingInterval
int pollingInterval
-
polling
boolean polling
-
transmitters
java.util.ArrayList<Transmitter> transmitters
-
pollIndex
int pollIndex
-
bscPoll
boolean bscPoll
-
throttlePoll
boolean throttlePoll
-
pollThread
java.lang.Thread pollThread
-
pollOutstanding
boolean pollOutstanding
-
prop
java.beans.PropertyChangeSupport prop
-
-
Constructor Detail
-
Engine
public Engine()
-
-
Method Detail
-
loadValues
void loadValues()
-
dispose
public void dispose()
-
setVSound
public void setVSound(double v)
-
getVSound
public double getVSound()
-
setOffset
public void setOffset(int offset)
-
getOffset
public int getOffset()
-
setMaxReceiverNumber
public void setMaxReceiverNumber(int n)
Set the maximum receiver number expected.If the highest value in the hardware is 5, that's what's needed here.
- Parameters:
n
- max receivers.
-
getMaxReceiverNumber
public int getMaxReceiverNumber()
-
setReceiver
public void setReceiver(int address, Receiver receiver)
Set a particular receiver by address (starting at 1).- Parameters:
address
- the receiver address.receiver
- the receiver.
-
getReceiver
public Receiver getReceiver(int i)
-
setReceiverPosition
public void setReceiverPosition(int i, javax.vecmath.Point3d p)
-
getReceiverPosition
public javax.vecmath.Point3d getReceiverPosition(int i)
-
setAlgorithm
public void setAlgorithm(java.lang.String algorithm)
-
getAlgorithm
public java.lang.String getAlgorithm()
-
notify
public void notify(Reading r)
- Specified by:
notify
in interfaceReadingListener
-
saveLastMeasurement
void saveLastMeasurement(java.lang.String id, Measurement m)
-
storeAlignment
public void storeAlignment(java.io.File file) throws java.io.IOException
- Throws:
java.io.IOException
-
loadAlignment
public void loadAlignment(java.io.File file) throws org.jdom2.JDOMException, java.io.IOException
- Throws:
org.jdom2.JDOMException
java.io.IOException
-
setInitialAlignment
protected void setInitialAlignment()
-
setDefaultAlignment
protected void setDefaultAlignment()
-
setPollingInterval
public void setPollingInterval(int pollingInterval)
-
getPollingInterval
public int getPollingInterval()
-
setPolling
public void setPolling(boolean polling)
-
getPolling
public boolean getPolling()
-
loadInitialTransmitters
void loadInitialTransmitters()
-
storePollConfig
public void storePollConfig(java.io.File file) throws java.io.IOException
- Throws:
java.io.IOException
-
loadPollConfig
public void loadPollConfig(java.io.File file) throws org.jdom2.JDOMException, java.io.IOException
- Throws:
org.jdom2.JDOMException
java.io.IOException
-
getTransmitterByAddress
public Transmitter getTransmitterByAddress(int addr)
-
getTransmitter
public Transmitter getTransmitter(int i)
-
getNumTransmitters
public int getNumTransmitters()
-
getPolledID
public java.lang.String getPolledID()
-
getPolledAddress
public int getPolledAddress()
-
selectNextPoll
int selectNextPoll()
The real core of the polling, this selects the next one to poll. -1 means none selected, try again later.- Returns:
- index to poll next
-
setBscPollMode
public void setBscPollMode()
-
setDirectPollMode
public void setDirectPollMode()
-
setThrottlePollMode
public void setThrottlePollMode()
-
getBscPollMode
public boolean getBscPollMode()
-
getThrottlePollMode
public boolean getThrottlePollMode()
-
getDirectPollMode
public boolean getDirectPollMode()
-
startPoll
void startPoll()
-
waitBeforeNextPoll
void waitBeforeNextPoll(int pollingInterval) throws java.lang.InterruptedException
Wait before sending next poll.Waits specified time, and then checks to see if response has been returned. If not, it waits again (twice) by 1/2 the interval, then finally polls anyway.
- Parameters:
pollingInterval
- in milliseconds- Throws:
java.lang.InterruptedException
- in theory, but not in practice.
-
stopPoll
void stopPoll()
-
setOn
void setOn(int i)
-
setOff
void setOff(int i)
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener p)
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener p)
-
-