stella.io
Class WatchdogRS485Server

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by io.AbstractDriver
                  extended by io.AbstractSerialDriver
                      extended by stella.io.RS485Server
                          extended by stella.io.CastingRS485Server
                              extended by stella.io.WatchdogRS485Server
All Implemented Interfaces:
Driver, Cloneable, Remote, RmiSerialCaster, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying, RmiCaster
Direct Known Subclasses:
PollingRS485Server

public class WatchdogRS485Server
extends CastingRS485Server

A class that adds watchdog capabilities to a RS485 server. Any address found in the comma-separated list pointed to by the KEY_WATCHDOG is matched to it's safety state pointed to by the KEY_SAFETY key. The order of the addresses in KEY_WATCHDOG must match the KEY_SAFETY order.

The watchdog is set once, during the CastingRS485Server.init() phase. The KEY_HOSTOK command is sent via a fixed-delay timer task. The time-out of the watchdog is given with the KEY_WATCHTIME key. The frequency of the host-ok writes is stated as a multipl of the watchdog time, regulated with the KEY_OKTIME key. Note that the watchdog time is given in milliseconds, but the resolution as supported by the NuDam modules restricts it to multiples of 100ms, at max 25.5 sec.

Since writing the host-ok to the serial line does not return any answer from the modules, writing of the host-ok delays the execution for a KEY_COOLDOWN-time. This should prevent too-early releases on the serial-lock that may happen if a CastingRS485Server.writeCommand(java.lang.String) is concurrently writing to the serial line.


Nested Class Summary
 
Nested classes/interfaces inherited from class stella.io.RS485Server
RS485Server.Checksum, RS485Server.Command, RS485Server.Info, RS485Server.Scan
 
Nested classes/interfaces inherited from class io.AbstractSerialDriver
AbstractSerialDriver.Available
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private static boolean DEFCASTOK
          The default casting behavior for host-ok.
private static long DEFCOOLDOWN
          The default cool-down time.
private static String DEFHOSTOK
          The default host-ok string.
private static int DEFINCREMENT
          The default watchdog timeout.
private static double DEFOKTIME
          The default multiplier to the watchdog time for host-ok sends.
private static boolean DEFRESETONCLOSE
          The default watchdog reset on normal close.
private static int DEFWATCHTIME
          The default watchdog timeout.
protected static Timer hosttimer
          The timer associated with scheduling the host-ok sends.
private  TimerTask isok
          The timer task of sending host-ok.
static String KEY_CASTOK
          The key whether to cast host-ok to the listeners.
static String KEY_COOLDOWN
          The key to the cool-down time after a no-result write.
static String KEY_HOSTOK
          The host-ok string.
static String KEY_INCREMENT
          The key to the watchdog time-out increase per module, in ms.
static String KEY_OKTIME
          A multiplier to the watchdog time-out for host-ok sends.
static String KEY_RESETONCLOSE
          True if watchdog should be reset on normal close.
static String KEY_SAFETY
          The modules safety values.
static String KEY_WATCHDOG
          The key to the module address where watchdogs should be enabled.
static String KEY_WATCHTIME
          The key to the watchdog time-out, in ms.
private  boolean watchon
          If true, watchdogs are running.
 
Fields inherited from class stella.io.CastingRS485Server
KEY_BIND
 
Fields inherited from class stella.io.RS485Server
KEY_CHECKCHAR, KEY_CHECKSUM, KEY_CLOSE, KEY_CR, KEY_ECHO, KEY_FAILTIME, KEY_FAILURES, KEY_INVALID, KEY_MAXBUFFER, KEY_MAXBUSY, KEY_QUERYTIME, KEY_REINIT, KEY_RESPONDTIME, KEY_STARTUP, KEY_TIMEBUSY, lock
 
Fields inherited from class io.AbstractSerialDriver
inport, KEY_BAUDRATE, KEY_CLOSETIMEOUT, KEY_DATABIT, KEY_FLOWCONTROL, KEY_INBUFFER, KEY_NOTIFYCOOLDOWN, KEY_OUTBUFFER, KEY_PARITYBIT, KEY_PORTNAME, KEY_RECEIVEFRAMING, KEY_RECEIVETHRESHOLD, KEY_RECEIVETIMEOUT, KEY_STOPBIT, KEY_TIMEOUT, outport, staticlock
 
Fields inherited from class io.AbstractDriver
KEY_DRIVERNAME
 
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.RmiSerialCaster
NAMING_EXTENSION
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Constructor Summary
WatchdogRS485Server(Map prop)
          Constructs a new watchdog-enabled RS485-server.
 
Method Summary
 boolean close()
          Closes the serial server.
private static String hexTime(int timeout)
          Convert a time in ms into the hex-string used for the watchdog timeout.
 boolean resetWatchdog()
          Resets the watchdog functionality of the modules.
 boolean startWatchdog()
          Stars the watch-dog functionality on modules listed in KEY_WATCHDOG key.
 
Methods inherited from class stella.io.CastingRS485Server
addRmiSerialListener, bindToRegistry, exit, init, isValid, notifyListeners, removeRmiSerialListener, unbindFromRegistry, writeCommand, writeCommand, writeString
 
Methods inherited from class stella.io.RS485Server
deferCommand, ensureCommand, getCheckSum, getCheckSumming, isReading, open, readString, setCheckSumming, toString, writeString
 
Methods inherited from class io.AbstractSerialDriver
createPortEventListener, createPortEventListener, deregisterSoleEventListener, disableEvent, enableEvent, getDriverName, isOpen, registerSoleEventListener, resetOriginalParameters
 
Methods inherited from class io.AbstractDriver
createDriver, equals, hashCode
 
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
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 
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
 

Field Detail

KEY_WATCHDOG

public static final String KEY_WATCHDOG
The key to the module address where watchdogs should be enabled.

See Also:
Constant Field Values

KEY_SAFETY

public static final String KEY_SAFETY
The modules safety values. Order must match the watchdog key.

See Also:
Constant Field Values

KEY_WATCHTIME

public static final String KEY_WATCHTIME
The key to the watchdog time-out, in ms.

See Also:
Constant Field Values

KEY_INCREMENT

public static final String KEY_INCREMENT
The key to the watchdog time-out increase per module, in ms.

See Also:
Constant Field Values

KEY_OKTIME

public static final String KEY_OKTIME
A multiplier to the watchdog time-out for host-ok sends.

See Also:
Constant Field Values

KEY_HOSTOK

public static final String KEY_HOSTOK
The host-ok string.

See Also:
Constant Field Values

KEY_RESETONCLOSE

public static final String KEY_RESETONCLOSE
True if watchdog should be reset on normal close.

See Also:
Constant Field Values

KEY_COOLDOWN

public static final String KEY_COOLDOWN
The key to the cool-down time after a no-result write.

See Also:
Constant Field Values

KEY_CASTOK

public static final String KEY_CASTOK
The key whether to cast host-ok to the listeners.

See Also:
Constant Field Values

DEFWATCHTIME

private static final int DEFWATCHTIME
The default watchdog timeout.

See Also:
Constant Field Values

DEFINCREMENT

private static final int DEFINCREMENT
The default watchdog timeout.

See Also:
Constant Field Values

DEFOKTIME

private static final double DEFOKTIME
The default multiplier to the watchdog time for host-ok sends.

See Also:
Constant Field Values

DEFHOSTOK

private static final String DEFHOSTOK
The default host-ok string.

See Also:
Constant Field Values

DEFRESETONCLOSE

private static final boolean DEFRESETONCLOSE
The default watchdog reset on normal close.

See Also:
Constant Field Values

DEFCOOLDOWN

private static final long DEFCOOLDOWN
The default cool-down time.

See Also:
Constant Field Values

DEFCASTOK

private static final boolean DEFCASTOK
The default casting behavior for host-ok.

See Also:
Constant Field Values

hosttimer

protected static Timer hosttimer
The timer associated with scheduling the host-ok sends.


isok

private TimerTask isok
The timer task of sending host-ok.


watchon

private boolean watchon
If true, watchdogs are running.

Constructor Detail

WatchdogRS485Server

public WatchdogRS485Server(Map prop)
Constructs a new watchdog-enabled RS485-server. The watchdog functionality of the NuDam modules is not set until the CastingRS485Server.init() method is called. Use of this constructer sets default values for the KEY_WATCHTIME, KEY_OKTIME, and the KEY_HOSTOK, if these keys are not present in the properties handed over to this constructor.

Method Detail

startWatchdog

public boolean startWatchdog()
Stars the watch-dog functionality on modules listed in KEY_WATCHDOG key. If at least one module was found, a timer is constructed and a timer-task sending host-ok is scheduled for fixed-delay execution at a period defined with the KEY_WATCHTIME and the KEY_OKTIME keys.

Returns:
True, if watchdogs were enabled or are already running.

resetWatchdog

public boolean resetWatchdog()
Resets the watchdog functionality of the modules. Used on close() if the KEY_RESETONCLOSE property is true.

Returns:
True, if watch-dog functionality is reset.

close

public boolean close()
              throws IOException
Closes the serial server. If the KEY_RESETONCLOSE key points to true, the watchdog functionality is reset on close.

Specified by:
close in interface Driver
Overrides:
close in class AbstractSerialDriver
Returns:
True if clean-up was successful.
Throws:
IOException

hexTime

private static final String hexTime(int timeout)
Convert a time in ms into the hex-string used for the watchdog timeout.