public class PollingRS485Server extends WatchdogRS485Server implements CacheChangedCaster, PollerQuery, Initializable
KEY_ACTIVEREAD and KEY_PASSIVEREAD, respectively, which
points to a comma-separated list of command strings. These list can be
altered during the live-time of the poller only with a call to the property
container's PropertyContainer.setProperty(java.lang.String, java.lang.String) command followed by an appropriate
switch-state command. In one cycle all of these strings are then sent as
commands to the underlying serial port, the actual list used depending on the
state of the poller, see setActive() and setPassive(). The
incomming replies (i.e. the channel values) are stored in a hashtable for
later retrieval. Users of this class can query the results with calls to the
servers readChannel(java.lang.String) method. They must provide the correct read
string otherwise lookup will fail.
Note that during the recurrent reading operations, no commands can be written
to the serial port. Write commands are delayed until reading the channels has
completed. To avoid dead-lock situations the polling intervall
KEY_POLLBASE should not be set too small.
Two different polling states are distinguished, active and passive. As the
name implies, active polling is meant for phases with rapid changes in the
read-cache, like during roof movement. The passive phase is intended for
low-resolution serial querying, e.g. during weather-only phases. For the
read-list, at least one of the two read-keys, KEY_ACTIVEREAD or
KEY_PASSIVEREAD must be given.
| Modifier and Type | Class and Description |
|---|---|
static class |
PollingRS485Server.CacheDump
Dumps the poller cache of a remote polling rs485.
|
static class |
PollingRS485Server.ConcurrentTest
Test concurrent access to the serial line by polling and additionally
using the
CastingRS485Server.writeCommand(java.lang.String) method to additionally write commands and
retrieve replies from the serial line. |
static class |
PollingRS485Server.Interleave
Writes the second argument on the command line to the polling rs 485
server bound to the registry with the name of the first command line
argument.
|
protected class |
PollingRS485Server.Poller
The polling timer task.
|
static class |
PollingRS485Server.Test
Testing purpose.
|
RS485Server.Checksum, RS485Server.Command, RS485Server.Info, RS485Server.ScanAbstractSerialDriver.Available| Modifier and Type | Field and Description |
|---|---|
protected Map |
cache
The hashtable linking read-commands to results.
|
protected Map |
cachelisten
The hashtable matching keys to registered cache changed listeners.
|
private static boolean |
DEFCASTPOLL
The default value for casting polling commands (false).
|
private static int |
DEFDROP
The default dropping rate.
|
private static long |
DEFPOLLBASE
The default polling base time, 100 ms.
|
private static int |
DEFRESPONDMAX
Maximum number of cycles for blocked reading.
|
private static boolean |
DEFSTARTOPEN
The default value for starting polling at port open (true).
|
private boolean |
isactive
The poller state.
|
static String |
KEY_ACTIVEDROP
The key to the number of steps dropped on active reads.
|
static String |
KEY_ACTIVEREAD
The key linked to the commands sent to the serial port.
|
static String |
KEY_CASTPOLL
The key defining event-casting for polling commands.
|
static String |
KEY_PASSIVEDROP
The key to the number of steps dropped on passive reads.
|
static String |
KEY_PASSIVEREAD
The key linked to the commands sent to the serial port.
|
static String |
KEY_POLLBASE
The key for the basic polling time.
|
static String |
KEY_RESPONDMAX
The key for the response-reading timeout (ms).
|
static String |
KEY_STARTOPEN
Points to true if polling should start after opening of the port.
|
private PollingRS485Server.Poller |
poll
The polling thread.
|
protected Map<String,Long> |
timecurrent
The hashtable linking read-commands to last read-times.
|
protected Map<String,Long> |
timemax
The hashtable linking read-commands to read-time maxima.
|
protected Map<String,Long> |
timemin
The hashtable linking read-commands to read-time minima.
|
protected Map |
validcache
The hashtable linking read-commands to validity of results.
|
hosttimer, KEY_CASTOK, KEY_COOLDOWN, KEY_HOSTOK, KEY_INCREMENT, KEY_OKTIME, KEY_RESETONCLOSE, KEY_SAFETY, KEY_WATCHDOG, KEY_WATCHTIMEKEY_BINDKEY_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, lockinport, 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, LOCK, outport, STATICLOCKKEY_DRIVERNAMEKEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATORNAMING_EXTENSIONCONFIG, KEY_CLASS| Constructor and Description |
|---|
PollingRS485Server(Map prop)
Construct a new polling server.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addCacheChangedListener(CacheChangedListener ear,
String key)
Adds a new cache changed listener to this polling instance.
|
String |
blockChannel(String command)
Blocks until data is available on a certain channel.
|
boolean |
close()
Closes the port.
|
void |
exit()
Stops polling before closing the serial port.
|
String |
getPollerCache()
Dumps the current content of the polling cache to a string.
|
void |
init()
Opens the serial port.
|
protected void |
initCache(Set list)
Constructs a hashtable matching read commands to their actual results.
|
String |
interleaveCommand(String cmd)
Writes an arbitrary command to the serial port.
|
boolean |
isActive()
Returns the state of the poller, true if active, false if passive.
|
boolean |
isPolling()
Tests if this server is actually polling.
|
boolean |
open()
Start polling after opening the serial port, if requested.
|
String |
readChannel(String command)
Returns the value of the queried channel.
|
void |
removeCacheChangedListener(CacheChangedListener ear,
String key)
Removes a cache changed listener from this polling instance.
|
boolean |
setActive()
Sets the poller in the active state.
|
boolean |
setPassive()
Sets the poller to passive state.
|
boolean |
startPolling()
Starts the polling.
|
void |
stopPolling()
Stops polling.
|
String |
toString()
Returns the driver name.
|
boolean |
validChannel(String command)
Returns true if the cache value associated with the command is valid.
|
resetWatchdog, startWatchdogaddRmiSerialListener, bindToRegistry, isValid, notifyListeners, removeRmiSerialListener, unbindFromRegistry, writeCommand, writeCommand, writeStringdeferCommand, ensureCommand, getCheckSum, getCheckSumming, isReading, readString, setCheckSumming, writeStringcreatePortEventListener, createPortEventListener, deregisterSoleEventListener, disableEvent, enableEvent, getDriverName, isOpen, registerSoleEventListener, resetOriginalParameterscreateDriver, equals, hashCodeaugment, augment, augment, augment, augment, clone, 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, initProperties, isNew, parseObject, parseObject, reload, reload, removeProperty, requires, rescanned, setObject, setProperties, setProperty, stringPropertiespublic static final String KEY_POLLBASE
public static final String KEY_ACTIVEREAD
public static final String KEY_PASSIVEREAD
public static final String KEY_ACTIVEDROP
public static final String KEY_PASSIVEDROP
public static final String KEY_STARTOPEN
public static final String KEY_CASTPOLL
public static final String KEY_RESPONDMAX
private static final long DEFPOLLBASE
private static final int DEFDROP
private static final boolean DEFSTARTOPEN
private static final boolean DEFCASTPOLL
private static final int DEFRESPONDMAX
protected Map cache
protected Map validcache
protected Map<String,Long> timecurrent
protected Map cachelisten
private PollingRS485Server.Poller poll
private boolean isactive
public PollingRS485Server(Map prop)
initCache(java.util.Set) is called at the
end of the construction phase which sets up the cache hashtable.
The polling itself is started after open() or with
startPolling(). Polling is always started in the passive phase.
The following proerties get defaults if not preset:
KEY_POLLBASE: DEFPOLLBASEKEY_STARTOPEN: DEFSTARTOPENKEY_CASTPOLL:DEFCASTPOLLKEY_ACTIVEREAD: The value of KEY_PASSIVEREAD. If
both are undefined, construction fails.KEY_PASSIVEREAD: The value of KEY_ACTIVEREAD. If
both are undefined, construction fails.public void init()
KEY_STARTOPEN is enabled polling is
started after opening was successful.init in interface Initializableinit in class CastingRS485Serverpublic boolean open()
throws IOException
open in interface Driveropen in class RS485ServerIOExceptionpublic void exit()
exit in interface ExitCleaningexit in class CastingRS485Serverprotected void initCache(Set list)
Additionally, a lookup-table matching the read commands to their reply length is constructed. The table is filled with the matches of the read-commands to integers in the polling server's properties. If for a given read command no match can be found zero is asumed which is interpreted as an unspecified number of reply bytes.
public boolean startPolling()
If either the port is not open or the I/O streams are not opened or ready this method returns silently.
public void stopPolling()
readChannel(java.lang.String) though they
return out-of-date values. A call to startPolling() restarts the
polling mechanism.public boolean isPolling()
throws RemoteException
isPolling in interface PollerQueryRemoteExceptionpublic boolean setActive()
KEY_ACTIVEDROP value and changing the
command list to KEY_ACTIVEREAD. If the poller is alive, this
method first synchronizes on the poller cache to avoid concurrent acces
to the poller list and/or poller time.public boolean setPassive()
KEY_PASSIVEDROP value and changing the
command list to KEY_PASSIVEREAD. If the poller is alive, this
method first synchronizes on the poller cache to avoid concurrent acces
to the poller list and/or poller time.public boolean isActive()
public String blockChannel(String command)
This method checks the mapping of the given key in the cache. As long as this mapping points to the empty String, this method falls into a sleep loop, sleeping period equal to the poller's polling interval.
public String getPollerCache() throws RemoteException
getPollerCache in interface PollerQueryRemoteExceptionpublic String readChannel(String command)
isPolling()) data retrieval, though outdated, is still possible.
public boolean validChannel(String command)
public String interleaveCommand(String cmd) throws RemoteException
interleaveCommand in interface PollerQueryRemoteExceptionpublic boolean close()
throws IOException
close in interface Driverclose in class WatchdogRS485ServerIOExceptionpublic void addCacheChangedListener(CacheChangedListener ear, String key)
addCacheChangedListener in interface CacheChangedCasterear - The listener to be notified when the cache value changes.key - The serial command this listenr is interested in.public void removeCacheChangedListener(CacheChangedListener ear, String key)
removeCacheChangedListener in interface CacheChangedCasterear - The listener to be notified when the cache value changes.key - The serial command this listenr is interested in.public String toString()
toString in class RS485Server