Class AbstractSensor
- java.lang.Object
-
- jmri.implementation.AbstractNamedBean
-
- jmri.implementation.AbstractSensor
-
- All Implemented Interfaces:
java.lang.Comparable<NamedBean>,PropertyChangeProvider,DigitalIO,NamedBean,Sensor
- Direct Known Subclasses:
AcelaSensor,BiDiBSensor,CbusSensor,Dcc4PcSensor,DCCppSensor,EcosSensor,IpocsSensor,JMRIClientSensor,LnSensor,MarklinSensor,MqttSensor,NceSensor,OlcbSensor,RaspberryPiSensor,RfidSensor,RpsSensor,SerialSensor,SerialSensor,SerialSensor,SerialSensor,SerialSensor,SerialSensor,SRCPSensor,TamsSensor,XBeeSensor,XNetSensor,Z21CanSensor,Z21RMBusSensor
public abstract class AbstractSensor extends AbstractNamedBean implements Sensor
Abstract class providing the basic logic of the Sensor interface.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jmri.NamedBean
NamedBean.BadNameException, NamedBean.BadSystemNameException, NamedBean.BadUserNameException, NamedBean.DisplayOptions, NamedBean.DuplicateSystemNameException
-
Nested classes/interfaces inherited from interface jmri.Sensor
Sensor.PullResistance
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean_invertedprotected int_knownStateprotected int_rawStateprotected java.lang.Runnabler(package private) Reporterreporter(package private) intrestartcountprotected longsensorDebounceGoingActiveprotected longsensorDebounceGoingInActiveprotected java.lang.Threadthrprotected booleanuseDefaultTimerSettings-
Fields inherited from class jmri.implementation.AbstractNamedBean
listenerRefs, mSystemName, register
-
Fields inherited from interface jmri.NamedBean
DISPLAY_NAME_FORMAT, INCONSISTENT, PROPERTY_COMMENT, PROPERTY_ENABLED, PROPERTY_KNOWN_STATE, PROPERTY_STATE, PROPERTY_USERNAME, QUOTED_NAME_FORMAT, UNKNOWN
-
Fields inherited from interface jmri.Sensor
ACTIVE, INACTIVE, MAX_DEBOUNCE, PROPERTY_ACTIVE_TIMER, PROPERTY_GLOBAL_TIMER, PROPERTY_INACTIVE_TIMER, PROPERTY_SENSOR_INVERTED
-
-
Constructor Summary
Constructors Constructor Description AbstractSensor(java.lang.String systemName)AbstractSensor(java.lang.String systemName, java.lang.String userName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanInvert()By default, all implementations based on this can invertjava.lang.StringdescribeState(int state)Provide human-readable, localized version of state value.voiddispose()Deactivate this object, so that it releases as many resources as possible and no longer effects others.java.lang.StringgetBeanType()For instances in the code where we are dealing with just a bean and a message needs to be passed to the user or in a log.booleangetInverted()Get the inverted state.intgetKnownState()Query the known state.Sensor.PullResistancegetPullResistance()Get the pull resistance.intgetRawState()Used to return the Raw state of a sensor prior to the known state of a sensor being set.ReportergetReporter()Retrieve the reporter associated with this sensor if there is one.longgetSensorDebounceGoingActiveTimer()Get the active debounce delay.longgetSensorDebounceGoingInActiveTimer()Get the inactive debounce delay.intgetState()Implement a shorter name for getKnownState.booleangetUseDefaultTimerSettings()Does this sensor use the default timers values?protected voidsensorDebounce()Before going active or inactive or checking that we can go active, we will wait for sensorDebounceGoing(In)Active for things to settle down to help prevent a race condition.voidsetInverted(boolean inverted)Control whether the actual sensor input is considered to be inverted, e.g. the normal electrical signal that results in an ACTIVE state now results in an INACTIVE state.voidsetKnownState(int newState)Perform setKnownState(int) for implementations that can't actually do it on the layout.voidsetOwnState(int s)Set our internal state information, and notify bean listeners.voidsetPullResistance(Sensor.PullResistance r)Set the pull resistancevoidsetReporter(Reporter er)Some sensor boards also serve the function of being able to report back train identities via such methods as RailCom.voidsetSensorDebounceGoingActiveTimer(long time)Set the active debounce delay.voidsetSensorDebounceGoingInActiveTimer(long time)Set the inactive debounce delay.voidsetState(int s)Implement a shorter name for setKnownState.voidsetUseDefaultTimerSettings(boolean boo)Use the timers specified in theSensorManagerfor the debounce delay.protected booleanstateChangeCheck(int newState)Preprocess a Sensor state change request for specific implementations ofsetKnownState(int)-
Methods inherited from class jmri.implementation.AbstractNamedBean
addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListener, compareSystemNameSuffix, equals, firePropertyChange, getComment, getDisplayName, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeListenersByReference, getPropertyKeys, getSystemName, getUserName, hashCode, removeProperty, removePropertyChangeListener, removePropertyChangeListener, setComment, setProperty, setUserName, toString, toStringSuffix, updateListenerRef, vetoableChange
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jmri.DigitalIO
requestUpdateFromLayout
-
Methods inherited from interface jmri.NamedBean
addPropertyChangeListener, addPropertyChangeListener, compareSystemNameSuffix, compareTo, getComment, getDisplayName, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListenersByReference, getPropertyKeys, getRecommendedToolTip, getSystemName, getUsageReport, getUserName, removeProperty, setComment, setProperty, setUserName, toString, updateListenerRef, vetoableChange
-
Methods inherited from interface jmri.beans.PropertyChangeProvider
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
Methods inherited from interface jmri.Sensor
getCommandedState, isConsistentState, setCommandedState
-
-
-
-
Field Detail
-
sensorDebounceGoingActive
protected long sensorDebounceGoingActive
-
sensorDebounceGoingInActive
protected long sensorDebounceGoingInActive
-
useDefaultTimerSettings
protected boolean useDefaultTimerSettings
-
thr
protected java.lang.Thread thr
-
r
protected java.lang.Runnable r
-
restartcount
int restartcount
-
_inverted
protected boolean _inverted
-
_knownState
protected int _knownState
-
_rawState
protected int _rawState
-
-
Constructor Detail
-
AbstractSensor
public AbstractSensor(java.lang.String systemName)
-
AbstractSensor
public AbstractSensor(java.lang.String systemName, java.lang.String userName)
-
-
Method Detail
-
getBeanType
@Nonnull public java.lang.String getBeanType()
Description copied from interface:NamedBeanFor instances in the code where we are dealing with just a bean and a message needs to be passed to the user or in a log.- Specified by:
getBeanTypein interfaceNamedBean- Returns:
- a string of the bean type, eg Turnout, Sensor etc
-
getKnownState
public int getKnownState()
Description copied from interface:DigitalIOQuery the known state. This is a bound parameter, so you can also register a listener to be informed of changes. A result is always returned; if no other feedback method is available, the commanded state will be used.- Specified by:
getKnownStatein interfaceDigitalIO- Returns:
- the known state
-
setSensorDebounceGoingActiveTimer
public void setSensorDebounceGoingActiveTimer(long time)
Set the active debounce delay.- Specified by:
setSensorDebounceGoingActiveTimerin interfaceSensor- Parameters:
time- delay in milliseconds; set to zero to de-activate debounce
-
getSensorDebounceGoingActiveTimer
public long getSensorDebounceGoingActiveTimer()
Get the active debounce delay.- Specified by:
getSensorDebounceGoingActiveTimerin interfaceSensor- Returns:
- delay in milliseconds
-
setSensorDebounceGoingInActiveTimer
public void setSensorDebounceGoingInActiveTimer(long time)
Set the inactive debounce delay.- Specified by:
setSensorDebounceGoingInActiveTimerin interfaceSensor- Parameters:
time- delay in milliseconds; set to zero to de-activate debounce
-
getSensorDebounceGoingInActiveTimer
public long getSensorDebounceGoingInActiveTimer()
Get the inactive debounce delay.- Specified by:
getSensorDebounceGoingInActiveTimerin interfaceSensor- Returns:
- delay in milliseconds
-
setUseDefaultTimerSettings
public void setUseDefaultTimerSettings(boolean boo)
Description copied from interface:SensorUse the timers specified in theSensorManagerfor the debounce delay.- Specified by:
setUseDefaultTimerSettingsin interfaceSensor- Parameters:
boo- true to set to current defaults if not previously true
-
getUseDefaultTimerSettings
public boolean getUseDefaultTimerSettings()
Description copied from interface:SensorDoes this sensor use the default timers values? (A remarkably unfortunate name given the one above)- Specified by:
getUseDefaultTimerSettingsin interfaceSensor- Returns:
- true if using default debounce values from the
SensorManager
-
sensorDebounce
protected void sensorDebounce()
Before going active or inactive or checking that we can go active, we will wait for sensorDebounceGoing(In)Active for things to settle down to help prevent a race condition.
-
describeState
@Nonnull @CheckReturnValue public java.lang.String describeState(int state)
Description copied from class:AbstractNamedBeanProvide human-readable, localized version of state value.This method is intended for use when presenting to a human operator.
- Specified by:
describeStatein interfaceNamedBean- Overrides:
describeStatein classAbstractNamedBean- Parameters:
state- the state to describe- Returns:
- the state in localized form
-
setKnownState
public void setKnownState(int newState) throws JmriException
Perform setKnownState(int) for implementations that can't actually do it on the layout. Not intended for use by implementations that can.- Specified by:
setKnownStatein interfaceSensor- Parameters:
newState- the state to set- Throws:
JmriException- if unable to set the state
-
stateChangeCheck
protected boolean stateChangeCheck(int newState) throws java.lang.IllegalArgumentException
Preprocess a Sensor state change request for specific implementations ofsetKnownState(int)- Parameters:
newState- the Sensor state command value passed- Returns:
- true if a Sensor.ACTIVE was requested and Sensor is not set to _inverted
- Throws:
java.lang.IllegalArgumentException- when needed
-
setOwnState
public void setOwnState(int s)
Set our internal state information, and notify bean listeners.- Parameters:
s- the new state
-
getRawState
public int getRawState()
Description copied from interface:SensorUsed to return the Raw state of a sensor prior to the known state of a sensor being set. The raw state value can be different from the known state when the sensor debounce option is used.- Specified by:
getRawStatein interfaceSensor- Returns:
- raw state value
-
setState
public void setState(int s) throws JmriException
Implement a shorter name for setKnownState.This generally shouldn't be used by Java code; use setKnownState instead. The is provided to make Jython script access easier to read.
- Specified by:
setStatein interfaceNamedBean- Parameters:
s- the state- Throws:
JmriException- general error when setting the state fails
-
getState
public int getState()
Implement a shorter name for getKnownState.This generally shouldn't be used by Java code; use getKnownState instead. The is provided to make Jython script access easier to read.
-
setInverted
public void setInverted(boolean inverted)
Control whether the actual sensor input is considered to be inverted, e.g. the normal electrical signal that results in an ACTIVE state now results in an INACTIVE state.- Specified by:
setInvertedin interfaceSensor- Parameters:
inverted- true if the sensor should be inverted; false otherwise
-
getInverted
public final boolean getInverted()
Get the inverted state. If true, the electrical signal that results in an ACTIVE state now results in an INACTIVE state.Used in polling loops in system-specific code, so made final to allow optimization.
- Specified by:
getInvertedin interfaceSensor- Returns:
- true if the electrical signal that normally results in an ACTIVE state now results in an INACTIVE state; false otherwise
-
canInvert
public boolean canInvert()
By default, all implementations based on this can invert
-
setReporter
public void setReporter(Reporter er)
Some sensor boards also serve the function of being able to report back train identities via such methods as RailCom. The setting and creation of the reporter against the sensor should be done when the sensor is created. This information is not saved.- Specified by:
setReporterin interfaceSensor- Parameters:
er- the reporter to set
-
getReporter
public Reporter getReporter()
Description copied from interface:SensorRetrieve the reporter associated with this sensor if there is one.- Specified by:
getReporterin interfaceSensor- Returns:
- the reporter or null if there is no associated reporter
-
setPullResistance
public void setPullResistance(Sensor.PullResistance r)
Set the pull resistanceIn this default implementation, the input value is ignored.
- Specified by:
setPullResistancein interfaceSensor- Parameters:
r- PullResistance value to use.
-
getPullResistance
public Sensor.PullResistance getPullResistance()
Get the pull resistance.- Specified by:
getPullResistancein interfaceSensor- Returns:
- the currently set PullResistance value. In this default implementation, PullResistance.PULL_OFF is always returned.
-
dispose
public void dispose()
Description copied from class:AbstractNamedBeanDeactivate this object, so that it releases as many resources as possible and no longer effects others.For example, if this object has listeners, after a call to this method it should no longer notify those listeners. Any native or system-wide resources it maintains should be released, including threads, files, etc.
It is an error to invoke any other methods on this object once dispose() has been called. Note, however, that there is no guarantee about behavior in that case.
Afterwards, references to this object may still exist elsewhere, preventing its garbage collection. But it's formally dead, and shouldn't be keeping any other objects alive. Therefore, this method should null out any references to other objects that this NamedBean contained.
-
-