stella.parameter
Class OneWireMultiSwitch

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by stella.parameter.AbstractParameter
                  extended by stella.parameter.AbstractTrigger
                      extended by stella.parameter.SimpleTrigger
                          extended by stella.parameter.AbstractSwitch
                              extended by stella.parameter.OneWireMultiSwitch
All Implemented Interfaces:
DriverDepending, Cloneable, Parameter, Switch, Trigger, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, Reloadable, ResourceSupplying

public class OneWireMultiSwitch
extends AbstractSwitch
implements DriverDepending, Reloadable

A class providing access to a one-wire switches simultaneously. This means that the ow-bus traffic can be minimized by concurrently switching multiple switches. This means that for each ow-driver a static lookup-table buffering the switch path to the current vote exists and switching is done then using the buffered state. If the KEY_SINGLEON option is set, switching on means that all other switches are off on this address, otherwise we leave the state of the other switches untouched.


Nested Class Summary
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private static boolean DEFINITOFF
          The initial state of the switch.
private static boolean DEFSINGLEON
          The initial state of the switch.
static String KEY_INITOFF
          The key defining initial off.
static String KEY_ONEWIRE
          The name of the one-wire driver to use.
static String KEY_PATH
          The path to the switch board plus channel, e.g '/12.(add)/PIO.A'.
static String KEY_SINGLEON
          If true, there is only a single switch in the on state allowed.
static String KEY_SWITCHBIT
          The integer mask to the switch.
private  OneWireDriver serial
          The serial server to send commands to.
private static Map<OneWireDriver,Map<String,Integer>> table
          The lookuptable for all one-wire multi switches.
 
Fields inherited from class stella.parameter.SimpleTrigger
KEY_INITBOOLEAN
 
Fields inherited from class stella.parameter.AbstractParameter
KEY_FORMAT, KEY_NAME, KEY_PRESERVE, UNKNOWN
 
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 util.PropertySupplying
CONFIG, KEY_CLASS
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Constructor Summary
OneWireMultiSwitch(Map prop)
          Constructs a new light switch trigger.
 
Method Summary
 void init()
          Initializes the one wire switch switch.
protected  boolean off()
          Turn the switch off.
protected  boolean on()
          Turns the switch on.
 String readSerial()
          Reads the switch.
 boolean registerDriver(Driver rs485)
          Registers the driver.
 double rescanned(String key, String old, String newval)
          As any parameter depending instance we fail if the parameter we depend on is now a different one.
protected  String toWrite(int mask)
          Converts the integer to write to the correct string.
private  boolean writeSerial(OneWireDriver bus, int mask)
          Writes to the ow-bus driver the specified int.
 
Methods inherited from class stella.parameter.AbstractSwitch
turnOff, turnOn
 
Methods inherited from class stella.parameter.SimpleTrigger
getLastToggleTime, getTrigger, setTrigger
 
Methods inherited from class stella.parameter.AbstractTrigger
get, getElapsedToggleTime, isTrue, set, toggleTrigger
 
Methods inherited from class stella.parameter.AbstractParameter
createParameter, delivers, exit, getFormatted, getFormatted, getName, getPreserveFile, getString, getString, register, setName, toString
 
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, 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.Reloadable
reload
 
Methods inherited from interface stella.Trigger
getElapsedToggleTime, getLastToggleTime, getTrigger, isTrue, setTrigger, toggleTrigger
 
Methods inherited from interface stella.Parameter
get, getFormatted, getName, getString, set
 
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_ONEWIRE

public static final String KEY_ONEWIRE
The name of the one-wire driver to use.

See Also:
Constant Field Values

KEY_PATH

public static final String KEY_PATH
The path to the switch board plus channel, e.g '/12.(add)/PIO.A'.

See Also:
Constant Field Values

KEY_SWITCHBIT

public static final String KEY_SWITCHBIT
The integer mask to the switch. Bit high means switch is on.

See Also:
Constant Field Values

KEY_SINGLEON

public static final String KEY_SINGLEON
If true, there is only a single switch in the on state allowed.

See Also:
Constant Field Values

KEY_INITOFF

public static final String KEY_INITOFF
The key defining initial off.

See Also:
Constant Field Values

DEFSINGLEON

private static final boolean DEFSINGLEON
The initial state of the switch.

See Also:
Constant Field Values

DEFINITOFF

private static final boolean DEFINITOFF
The initial state of the switch.

See Also:
Constant Field Values

serial

private OneWireDriver serial
The serial server to send commands to.


table

private static Map<OneWireDriver,Map<String,Integer>> table
The lookuptable for all one-wire multi switches.

Constructor Detail

OneWireMultiSwitch

public OneWireMultiSwitch(Map prop)
Constructs a new light switch trigger. As a monitor for notification of cache-cahnged events, this trigger registers itself in the init section.
All additional properties have default values.

Method Detail

init

public void init()
Initializes the one wire switch switch. If the timer class is null, it is defined here.

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

rescanned

public double rescanned(String key,
                        String old,
                        String newval)
As any parameter depending instance we fail if the parameter we depend on is now a different one.

Specified by:
rescanned in interface Reloadable
Overrides:
rescanned in class SimpleTrigger

registerDriver

public boolean registerDriver(Driver rs485)
Registers the driver. First, it is checked for instancy of OneWireDriver. If so, it's name is check to match the KEY_ONEWIRE name. If this, too, is fulfilled, an instance of this server is stored locally to allow sending of commands to the serial server.

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

on

protected boolean on()
Turns the switch on. If the driver/path combintion does not point to a valid state, we write the switch bitmask to the bus and cache it. Otherwise, we infer from the state of the cache if the switch is already on. If not, depending on KEY_SINGLEON, we either or the bitmask into the cached reading and write this to the stream or we write solely the bitmask. Whenever the result of the process is okay, we store the byte in the table cache.

Specified by:
on in class AbstractSwitch
Returns:
True if successful.

off

protected boolean off()
Turn the switch off. If the driver/path combintion does not point to a valid state, zero is writtn to the path. If we have a cached value, we write only if the switch is one by explicetly eresing this switch bit.

Specified by:
off in class AbstractSwitch
Returns:
True if successful.

toWrite

protected String toWrite(int mask)
Converts the integer to write to the correct string. Default implementation convert it using decimal base.


writeSerial

private boolean writeSerial(OneWireDriver bus,
                            int mask)
Writes to the ow-bus driver the specified int. The integer is converted to a string using the protected toWrite(int) method. The default implementation converts the integer at base 10, no leading zeros. If writing was successful, the cache is updated.


readSerial

public String readSerial()
Reads the switch. Pushes through to the ow-bus.