stella.sensor
Class RS485RainSensor

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by util.rmi.RmiPropertyContainer
                  extended by util.rmi.AbstractRmiCaster
                      extended by stella.sensor.AbstractSensor
                          extended by stella.sensor.RS485RainSensor
All Implemented Interfaces:
DriverDepending, Cloneable, Remote, EventListener, Caster, DataCaster, CacheChangedListener, RmiDataCaster, RmiErrorCaster, Telemetering, WeatherJudging, WeatherCaster, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying, RmiCaster, RmiPropertyBearing

public class RS485RainSensor
extends AbstractSensor
implements DataCaster, RmiDataCaster, WeatherCaster, WeatherJudging, CacheChangedListener, DriverDepending

A representation of a digital rain sensor. This sensor does not deliver a value like 'number of raindrops' but provides a simple yes/no decision.
This class does not extend the RS485Sensor class but is a thread-less sensor. It acts as a cache listener and is therefore more immediate in its response. Additionally, as immediate response is always intended, no retardation time in case of bad-weather events (i.e. rain) is implemented.
This sensor is based on a NuDam 6050 module. The command issued for reading digital input reads as $(Add)6, the returned string has the form !(DataOut)(DataIn)00, where the data section correspond to the two-hex character string representing the status of the appropriate I/O bits. In particular, for the weather station only the data input is used, the channel number provided in the properties points to the channel of the digital input (numbering starts with zero, as always).


Nested Class Summary
private  class RS485RainSensor.RainTimerTask
          The timer task used for notification of good weather.
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private  Timer data
          The timer bound to data-event generating and weather reports.
private  List datalist
          The registered data-listeners.
private static int DEFCHANNEL
          The default read channel.
private static long DEFDATARATE
          The default read channel.
private static DecimalFormat DEFFORMAT
          The format string for value and raw reading.
private static long DEFRETARD
          The default retard time for changes to good weather.
private static String DEFUNIT
          The unit string of the rain sensor.
private  NumberFormat format
          The raw and value formatter.
private  Trigger goodweather
          The weather toggle.
static String KEY_CHANNEL
          The key for the channel number this sensor link to on the module.
static String KEY_DATARATE
          The key linked to the data-event generating rate.
static String KEY_FORMAT
          The key to the value formatter.
static String KEY_READ
          The key linked to the channel-read command of the Nudam module.
static String KEY_RETARD
          The key pointing to a retard time for weather changes bad->good.
static String KEY_SERVER
          The key linked to the polling instance to read from.
static String KEY_UNIT
          The key to the 'unit' of the digital reain sensor.
private  Date lastchange
          The last cache-changed event received date.
private  String lastread
          The last cache-changed event, value key.
private  RS485RainSensor.RainTimerTask retard
          The timer task for good-weather retards.
private  PollingRS485Server serial
          The poller this rain sensor listens to.
private  List weatherlist
          The registered weather-listeners.
 
Fields inherited from class stella.sensor.AbstractSensor
KEY_BIND, KEY_BINDNAME, KEY_CONVERT, KEY_DESCRIPTION, KEY_SENSORNAME
 
Fields inherited from class util.rmi.AbstractRmiCaster
ALTERNATEHOST, ALTERNATEPORT, KEY_EXPORTPORT, KEY_REGISTRYHOST, KEY_REGISTRYPORT
 
Fields inherited from class util.PropertyBundles
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES
 
Fields inherited from class util.PropertyResources
KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR
 
Fields inherited from interface stella.rmi.RmiDataCaster
NAMING_EXTENSION
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Constructor Summary
RS485RainSensor(Map prop)
          Constructs a new RS485 sensor.
 
Method Summary
 void addDataListener(DataListener ear)
          Adds a DataListener to the registered listeners.
 void addRmiDataListener(RmiDataListener ear)
          Adds a DataListener to the registered listeners.
 void addWeatherListener(WeatherListener ear)
          Adds a WeatherListener to the registered listeners.
 void cancel()
          Cancels the rain sensor.
 boolean currentlyClear()
          The main functionality of the rain sensor is to act as a weather sensor.
 boolean currentlyRetarding()
          Returns true, if we were bad and still recovering.
 void exit()
          Exists the rain sensor.
 long getMinClearUpTime()
          Estimates bad time.
 double getReading()
          Reads the sensor value.
 String getSensorInitInfo()
          Returns a string description of the sensor.
 Date getTimeOfRead()
          Returns the date of the last received cache-changed event.
 void init()
          Initializes the sensor.
 void newValue(CacheChangedEvent cce)
          Indicates a new cache-reading on the rain sensor.
protected  void notifyDataListener(DataEvent de)
          Parses through the list of registered weather listeners and passes the argumental weather event to all of them.
protected  void notifyWeatherListener(WeatherEvent we)
          Parses through the list of registered weather listeners and passes the argumental weather event to all of them.
 boolean registerDriver(Driver poller)
          Registers the serial server to this sensor.
 void removeDataListener(DataListener ear)
          Removes a DataListener from the registered listeners.
 void removeRmiDataListener(RmiDataListener ear)
          Removes a DataListener from the registered listeners.
 void removeWeatherListener(WeatherListener ear)
          Removes a WeatherListener from the registered listeners.
private  double retrieveValue(String read)
          Converts the input string into a sensor value.
 String status()
          The current status of the rain sensor.
 boolean validReading()
          The rain sensor is valid if the polling server was able to read the last rain-sensor switch.
 
Methods inherited from class stella.sensor.AbstractSensor
addRmiErrorListener, createSensor, getBindName, getConvert, getRespawn, getSensorDescription, getSensorName, initSensorTimerTask, notifyErrorListener, removeRmiErrorListener, setConvert, toString
 
Methods inherited from class util.rmi.AbstractRmiCaster
bindAlternate, bindToRegistry, bindToRegistry, bindToRegistry, casterExit, casterExit, getBindName, isValid, unbindFromRegistry, unbindFromRegistry
 
Methods inherited from class util.rmi.RmiPropertyContainer
containsRemoteProperty, getRemoteProperties, getRemoteProperty, setRemoteProperty
 
Methods inherited from class util.PropertyBundles
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource
 
Methods inherited from class util.PropertyResources
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, keyCreate, keyCreate, reload, setApplet
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, reload, removeProperty, rescanned, setObject, setProperties, setProperty, stringProperties
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.rmi.RmiCaster
bindToRegistry, isValid, unbindFromRegistry
 
Methods inherited from interface util.PropertySupplying
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 

Field Detail

KEY_DATARATE

public static final String KEY_DATARATE
The key linked to the data-event generating rate.

See Also:
Constant Field Values

KEY_SERVER

public static final String KEY_SERVER
The key linked to the polling instance to read from.

See Also:
Constant Field Values

KEY_READ

public static final String KEY_READ
The key linked to the channel-read command of the Nudam module.

See Also:
Constant Field Values

KEY_CHANNEL

public static final String KEY_CHANNEL
The key for the channel number this sensor link to on the module.

See Also:
Constant Field Values

KEY_RETARD

public static final String KEY_RETARD
The key pointing to a retard time for weather changes bad->good.

See Also:
Constant Field Values

KEY_UNIT

public static final String KEY_UNIT
The key to the 'unit' of the digital reain sensor.

See Also:
Constant Field Values

KEY_FORMAT

public static final String KEY_FORMAT
The key to the value formatter.

See Also:
Constant Field Values

DEFDATARATE

private static final long DEFDATARATE
The default read channel.

See Also:
Constant Field Values

DEFCHANNEL

private static final int DEFCHANNEL
The default read channel.

See Also:
Constant Field Values

DEFRETARD

private static final long DEFRETARD
The default retard time for changes to good weather.

See Also:
Constant Field Values

DEFUNIT

private static final String DEFUNIT
The unit string of the rain sensor.

See Also:
Constant Field Values

DEFFORMAT

private static final DecimalFormat DEFFORMAT
The format string for value and raw reading.


lastread

private String lastread
The last cache-changed event, value key.


lastchange

private Date lastchange
The last cache-changed event received date.


goodweather

private Trigger goodweather
The weather toggle.


data

private Timer data
The timer bound to data-event generating and weather reports.


retard

private RS485RainSensor.RainTimerTask retard
The timer task for good-weather retards.


format

private NumberFormat format
The raw and value formatter.


serial

private transient PollingRS485Server serial
The poller this rain sensor listens to.


datalist

private List datalist
The registered data-listeners.


weatherlist

private List weatherlist
The registered weather-listeners.

Constructor Detail

RS485RainSensor

public RS485RainSensor(Map prop)
                throws RemoteException
Constructs a new RS485 sensor. The properties are checked for the presence of the KEY_READ and the KEY_CHANNEL keys. Construction fails if these keys are not present.

Throws:
IllegalArgumentException - If the necessary properties are not set.
NumberFormatException - If the channel number is not an int.
RemoteException
Method Detail

init

public void init()
Initializes the sensor. The data-generator timer is initialized and a data-event generating timer-task is assigned to it.

Specified by:
init in interface Initializable
Overrides:
init in class AbstractSensor

registerDriver

public boolean registerDriver(Driver poller)
Registers the serial server to this sensor. This method adds this rain sensor as a CacheChangedListener to the driver, if the driver is a PollingRS485Server and has the correct name. Note that this method returns false only if the driver handed over is not of the appropriate type, i.e. a PollingRS485Server.

Specified by:
registerDriver in interface DriverDepending
Returns:
True if registering at the driver was successful.

cancel

public void cancel()
Cancels the rain sensor. This includes deregistering from the cache caster and canceling of the timer used for scheduling data events.

Specified by:
cancel in interface Telemetering

exit

public void exit()
Exists the rain sensor. Cancels it and does a caster exit on registered listeners before calling the super method.

Specified by:
exit in interface ExitCleaning
Overrides:
exit in class AbstractSensor

getReading

public double getReading()
Reads the sensor value. If no serial server was registered to this sensor or the server is not reading the sensor's input, NaN is returned. Otherwise the serial server is queried for the value of its channel, PollingRS485Server.readChannel(java.lang.String), whose return value is then fed, along with the channel number, to the retrieveValue(java.lang.String) method of the sensor. If no cache-event has been received, 1 for bad weather is returned.

Specified by:
getReading in interface Telemetering
Returns:
0/1 for no rain/rain.

validReading

public boolean validReading()
The rain sensor is valid if the polling server was able to read the last rain-sensor switch.

Specified by:
validReading in interface Telemetering

getTimeOfRead

public Date getTimeOfRead()
Returns the date of the last received cache-changed event.

Specified by:
getTimeOfRead in interface Telemetering

currentlyClear

public boolean currentlyClear()
The main functionality of the rain sensor is to act as a weather sensor. This method returns true if the argument value is below 0.5.

Specified by:
currentlyClear in interface WeatherJudging

newValue

public void newValue(CacheChangedEvent cce)
Indicates a new cache-reading on the rain sensor.

Specified by:
newValue in interface CacheChangedListener

currentlyRetarding

public boolean currentlyRetarding()
Returns true, if we were bad and still recovering. No retard if we get bad.

Specified by:
currentlyRetarding in interface WeatherJudging

getMinClearUpTime

public long getMinClearUpTime()
Estimates bad time.

Specified by:
getMinClearUpTime in interface WeatherJudging

getSensorInitInfo

public String getSensorInitInfo()
Returns a string description of the sensor. The name is returned plus the serial server it listens to. The key properties of the switching behaviour, i.e. the toggling instance is reported, too.

Specified by:
getSensorInitInfo in interface Telemetering
Overrides:
getSensorInitInfo in class AbstractSensor

status

public String status()
The current status of the rain sensor.

Specified by:
status in interface Telemetering
Overrides:
status in class AbstractSensor

addWeatherListener

public void addWeatherListener(WeatherListener ear)
Adds a WeatherListener to the registered listeners. If the argument is null, nothing is changed.

Specified by:
addWeatherListener in interface WeatherCaster
Parameters:
ear - The listener to add.

removeWeatherListener

public void removeWeatherListener(WeatherListener ear)
Removes a WeatherListener from the registered listeners. If the argument is null, nothing is changed.

Specified by:
removeWeatherListener in interface WeatherCaster
Parameters:
ear - The listener to remove.

addDataListener

public void addDataListener(DataListener ear)
Adds a DataListener to the registered listeners. If the argument is null, nothing is changed.

Specified by:
addDataListener in interface DataCaster
Parameters:
ear - The listener to add.

removeDataListener

public void removeDataListener(DataListener ear)
Removes a DataListener from the registered listeners. If the argument is null, nothing is changed.

Specified by:
removeDataListener in interface DataCaster
Parameters:
ear - The listener to remove.

addRmiDataListener

public void addRmiDataListener(RmiDataListener ear)
                        throws RemoteException
Adds a DataListener to the registered listeners. If the argument is null, nothing is changed.

Specified by:
addRmiDataListener in interface RmiDataCaster
Parameters:
ear - The listener to add.
Throws:
RemoteException

removeRmiDataListener

public void removeRmiDataListener(RmiDataListener ear)
                           throws RemoteException
Removes a DataListener from the registered listeners. If the argument is null, nothing is changed.

Specified by:
removeRmiDataListener in interface RmiDataCaster
Parameters:
ear - The listener to remove.
Throws:
RemoteException

notifyDataListener

protected void notifyDataListener(DataEvent de)
Parses through the list of registered weather listeners and passes the argumental weather event to all of them. Synchronizes on the list of weather event listeners.


notifyWeatherListener

protected void notifyWeatherListener(WeatherEvent we)
Parses through the list of registered weather listeners and passes the argumental weather event to all of them. Synchronizes on the list of weather event listeners.


retrieveValue

private double retrieveValue(String read)
Converts the input string into a sensor value. If the appropriate bit is set it is interpreted as rain. In the latter case the returned sensor value is one, zero otherwise.

Parameters:
read - The string read in from the serial line
nr - The channel number (0-6) of the digital input.
Returns:
1 if raining, 0 for good weather. -1 if invalid.