Package jmri.implementation
Class AbstractSensor
java.lang.Object
jmri.implementation.AbstractNamedBean
jmri.implementation.AbstractSensor
- All Implemented Interfaces:
Comparable<NamedBean>
,PropertyChangeProvider
,DigitalIO
,NamedBean
,Sensor
- Direct Known Subclasses:
AcelaSensor
,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
-
Field Summary
Fields Modifier and Type Field Description protected boolean
_inverted
protected int
_knownState
protected int
_rawState
protected Runnable
r
(package private) Reporter
reporter
(package private) int
restartcount
protected long
sensorDebounceGoingActive
protected long
sensorDebounceGoingInActive
protected Thread
thr
protected boolean
useDefaultTimerSettings
Fields inherited from class jmri.implementation.AbstractNamedBean
listenerRefs, mSystemName, register
Fields inherited from interface jmri.NamedBean
DISPLAY_NAME_FORMAT, INCONSISTENT, PROPERTY_STATE, QUOTED_NAME_FORMAT, UNKNOWN
-
Constructor Summary
Constructors Constructor Description AbstractSensor(String systemName)
AbstractSensor(String systemName, String userName)
-
Method Summary
Modifier and Type Method Description boolean
canInvert()
By default, all implementations based on this can invertString
describeState(int state)
Provide human-readable, localized version of state value.String
getBeanType()
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.boolean
getInverted()
Get the inverted state.int
getKnownState()
Query the known state.Sensor.PullResistance
getPullResistance()
Get the pull resistance.int
getRawState()
Used to return the Raw state of a sensor prior to the known state of a sensor being set.Reporter
getReporter()
Retrieve the reporter associated with this sensor if there is one.long
getSensorDebounceGoingActiveTimer()
Get the active debounce delay.long
getSensorDebounceGoingInActiveTimer()
Get the inactive debounce delay.int
getState()
Implement a shorter name for getKnownState.boolean
getUseDefaultTimerSettings()
Does this sensor use the default timers values?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.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.void
setKnownState(int newState)
Perform setKnownState(int) for implementations that can't actually do it on the layout.void
setOwnState(int s)
Set our internal state information, and notify bean listeners.void
setPullResistance(Sensor.PullResistance r)
Set the pull resistancevoid
setReporter(Reporter er)
Some sensor boards also serve the function of being able to report back train identities via such methods as RailCom.void
setSensorDebounceGoingActiveTimer(long time)
Set the active debounce delay.void
setSensorDebounceGoingInActiveTimer(long time)
Set the inactive debounce delay.void
setState(int s)
Implement a shorter name for setKnownState.void
setUseDefaultTimerSettings(boolean boo)
Use the timers specified in theSensorManager
for the debounce delay.protected boolean
stateChangeCheck(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, dispose, equals, firePropertyChange, getComment, getDisplayName, getDisplayName, getFullyFormattedDisplayName, getFullyFormattedDisplayName, 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.NamedBean
addPropertyChangeListener, addPropertyChangeListener, compareSystemNameSuffix, compareTo, getComment, getDisplayName, getDisplayName, getFullyFormattedDisplayName, getFullyFormattedDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListenersByReference, getPropertyKeys, 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
dispose, getCommandedState, isConsistentState, setCommandedState
-
Field Details
-
Constructor Details
-
Method Details
-
getBeanType
Description copied from interface:NamedBean
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.- Specified by:
getBeanType
in interfaceNamedBean
- Returns:
- a string of the bean type, eg Turnout, Sensor etc
-
getKnownState
Description copied from interface:DigitalIO
Query 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:
getKnownState
in interfaceDigitalIO
- Returns:
- the known state
-
setSensorDebounceGoingActiveTimer
Set the active debounce delay.- Specified by:
setSensorDebounceGoingActiveTimer
in interfaceSensor
- Parameters:
time
- delay in milliseconds; set to zero to de-activate debounce
-
getSensorDebounceGoingActiveTimer
Get the active debounce delay.- Specified by:
getSensorDebounceGoingActiveTimer
in interfaceSensor
- Returns:
- delay in milliseconds
-
setSensorDebounceGoingInActiveTimer
Set the inactive debounce delay.- Specified by:
setSensorDebounceGoingInActiveTimer
in interfaceSensor
- Parameters:
time
- delay in milliseconds; set to zero to de-activate debounce
-
getSensorDebounceGoingInActiveTimer
Get the inactive debounce delay.- Specified by:
getSensorDebounceGoingInActiveTimer
in interfaceSensor
- Returns:
- delay in milliseconds
-
setUseDefaultTimerSettings
Description copied from interface:Sensor
Use the timers specified in theSensorManager
for the debounce delay.- Specified by:
setUseDefaultTimerSettings
in interfaceSensor
- Parameters:
boo
- true to set to current defaults if not previously true
-
getUseDefaultTimerSettings
Description copied from interface:Sensor
Does this sensor use the default timers values? (A remarkably unfortunate name given the one above)- Specified by:
getUseDefaultTimerSettings
in interfaceSensor
- Returns:
- true if using default debounce values from the
SensorManager
-
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
Description copied from interface:NamedBean
Provide human-readable, localized version of state value.This method is intended for use when presenting to a human operator.
- Specified by:
describeState
in interfaceNamedBean
- Overrides:
describeState
in classAbstractNamedBean
- Parameters:
state
- the state to describe- Returns:
- the state in localized form
-
setKnownState
Perform setKnownState(int) for implementations that can't actually do it on the layout. Not intended for use by implementations that can.- Specified by:
setKnownState
in interfaceSensor
- Parameters:
newState
- the state to set- Throws:
JmriException
- if unable to set the state
-
stateChangeCheck
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:
IllegalArgumentException
-
setOwnState
Set our internal state information, and notify bean listeners.- Parameters:
s
- the new state
-
getRawState
Description copied from interface:Sensor
Used 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:
getRawState
in interfaceSensor
- Returns:
- raw state value
-
setState
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:
setState
in interfaceNamedBean
- Parameters:
s
- the state- Throws:
JmriException
- general error when setting the state fails
-
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
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:
setInverted
in interfaceSensor
- Parameters:
inverted
- true if the sensor should be inverted; false otherwise
-
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:
getInverted
in interfaceSensor
- Returns:
- true if the electrical signal that normally results in an ACTIVE state now results in an INACTIVE state; false otherwise
-
canInvert
By default, all implementations based on this can invert -
setReporter
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:
setReporter
in interfaceSensor
- Parameters:
er
- the reporter to set
-
getReporter
Description copied from interface:Sensor
Retrieve the reporter associated with this sensor if there is one.- Specified by:
getReporter
in interfaceSensor
- Returns:
- the reporter or null if there is no associated reporter
-
setPullResistance
Set the pull resistanceIn this default implementation, the input value is ignored.
- Specified by:
setPullResistance
in interfaceSensor
- Parameters:
r
- PullResistance value to use.
-
getPullResistance
Get the pull resistance.- Specified by:
getPullResistance
in interfaceSensor
- Returns:
- the currently set PullResistance value. In this default implementation, PullResistance.PULL_OFF is always returned.
-