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.Stringalgorithm(package private) booleanbscPoll(package private) MeasurementlastPoint(package private) intpollIndex(package private) booleanpolling(package private) intpollingInterval(package private) booleanpollOutstanding(package private) java.lang.ThreadpollThread(package private) java.beans.PropertyChangeSupportprop(package private) Receiver[]receivers(package private) booleanthrottlePoll(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 voidaddPropertyChangeListener(java.beans.PropertyChangeListener p)voiddispose()java.lang.StringgetAlgorithm()booleangetBscPollMode()booleangetDirectPollMode()intgetMaxReceiverNumber()intgetNumTransmitters()intgetOffset()intgetPolledAddress()java.lang.StringgetPolledID()booleangetPolling()intgetPollingInterval()ReceivergetReceiver(int i)javax.vecmath.Point3dgetReceiverPosition(int i)booleangetThrottlePollMode()TransmittergetTransmitter(int i)TransmittergetTransmitterByAddress(int addr)doublegetVSound()static Engineinstance()voidloadAlignment(java.io.File file)(package private) voidloadInitialTransmitters()voidloadPollConfig(java.io.File file)(package private) voidloadValues()voidnotify(Reading r)voidremovePropertyChangeListener(java.beans.PropertyChangeListener p)(package private) voidsaveLastMeasurement(java.lang.String id, Measurement m)(package private) intselectNextPoll()The real core of the polling, this selects the next one to poll. -1 means none selected, try again later.voidsetAlgorithm(java.lang.String algorithm)voidsetBscPollMode()protected voidsetDefaultAlignment()voidsetDirectPollMode()protected voidsetInitialAlignment()voidsetMaxReceiverNumber(int n)Set the maximum receiver number expected.(package private) voidsetOff(int i)voidsetOffset(int offset)(package private) voidsetOn(int i)voidsetPolling(boolean polling)voidsetPollingInterval(int pollingInterval)voidsetReceiver(int address, Receiver receiver)Set a particular receiver by address (starting at 1).voidsetReceiverPosition(int i, javax.vecmath.Point3d p)voidsetThrottlePollMode()voidsetVSound(double v)(package private) voidstartPoll()(package private) voidstopPoll()voidstoreAlignment(java.io.File file)voidstorePollConfig(java.io.File file)(package private) voidwaitBeforeNextPoll(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:
notifyin 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.JDOMExceptionjava.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.JDOMExceptionjava.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)
-
-