|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectutil.PropertyContainer
util.PropertyResources
util.PropertyBundles
io.AbstractDriver
stella.nut.UpsDriver
public class UpsDriver
A class to represent an ups. This requires the following things to be set up:
KEY_PORT, which should alwys be
DEFPORT#KEY_UPSNAMEKEY_LOGIN
should point to true.KEY_USER and KEY_PASSWORD should be present
in the properties. Note that the password will be given in plain ASCII.#KEY_REQUEST key. The answer retrieved is
passed to the abstract method #processAnswer which should
return a double that equals the current sensor value. If the answer is
connected with a weather-event, the resolution must also be done within
this method.RmiErrorCaster functionality. These errors can be
trapped by an appropriate error handler.
KEY_LOGIN property is true.KEY_HOST is
established, using the port name specified with the KEY_PORT
key. This port should always be DEFPORT. The host key should
point to a valid host name.#processAnswer method.#cancel method performs a logout from
the upsd if the KEY_LOGIN property is set and login was
completed successfully at the sensor's construction.#processAnswer method. Any weather-event related issues must also
be solved within this method. This is particularily true for delayed
weather events. To not interfere with this weather-event generation, the
standard methods used by the weather sensor will always return true.
| Nested Class Summary | |
|---|---|
static class |
UpsDriver.Client
A test class. |
private class |
UpsDriver.UpsRefresh
The task that queries the UPS demon for all served variables at certain time intervalls. |
| Nested classes/interfaces inherited from class util.PropertyResources |
|---|
PropertyResources.URLResource |
| Field Summary | |
|---|---|
private static String |
ANS_ERROR
The leading string for error-replies. |
private static String |
ANS_OK
The correct answer for login processes. |
private static String |
CMD_DESC
The description command. |
private static String |
CMD_GET
The request command. |
private static String |
CMD_LOGIN
The login command. |
private static String |
CMD_LOGOUT
The logout command. |
private static String |
CMD_PASSWORD
The password command. |
private static String |
CMD_USER
The username command. |
private static String |
CMD_VAR
The variable command. |
private static String |
DEFCR
The default end-of-line string. |
static String |
DEFDRIVERNAME
The default ups name |
private static String |
DEFHOST
The default host name where the server is running. |
private static String |
DEFLIST
The default list of served variables. |
private static boolean |
DEFLOGIN
The default port number for the communication to the server. |
private static int |
DEFPORT
The default port number for the communication to the server. |
private static long |
DEFREFRESH
The default refresh interval in ms. |
private Map<String,String> |
describe
The look-up table of variable description. |
private Set<String> |
fails
The set of commands currently failed. |
private BufferedReader |
in
The socket reader, a wrapped socket-input stream. |
private boolean |
islogin
True, if socket is connected and ready for IO. |
private boolean |
isopen
True, if sensor logged in at upsd as a power-drawing unit. |
static String |
KEY_CR
The key pointing to the end-of-line string sent/received. |
static String |
KEY_HOST
The key to the host name of the ups-server. |
static String |
KEY_LIST
The key to the list of variables served. |
static String |
KEY_LOGIN
The key pointing to the end-of-line string sent/received. |
static String |
KEY_PASSWORD
The key pointing to the end-of-line string sent/received. |
static String |
KEY_PORT
The key to the communications port to the ups-server. |
static String |
KEY_REFRESH
The key to the cache-refresh interval. |
static String |
KEY_USER
The key pointing to the end-of-line string sent/received. |
private Map<String,String> |
lookup
The look-up table for caching. |
private BufferedWriter |
out
The socket writer, a wrapped socket-output stream. |
private static String |
SEPARATOR
The separation between commands and instructions. |
private Timer |
update
The timer for updating ups-values. |
private Socket |
upsd
The communication socket. |
| 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 util.ResourceSupplying |
|---|
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME |
| Fields inherited from interface util.PropertySupplying |
|---|
CONFIG, KEY_CLASS |
| Constructor Summary | |
|---|---|
UpsDriver(Map<String,String> prop)
Constructs a new ups-sensor. |
|
| Method Summary | |
|---|---|
boolean |
close()
Cancels this sensor reading thread. |
void |
exit()
Exits, not caring about failures. |
String |
getDescription(String key)
Reads the description of the sensor as provided by the underlying ups daemon. |
boolean |
isOpen()
Returns true if we can send to the socket. |
boolean |
open()
Initializes the driver. |
private String |
parseResponse(String query,
String response)
Parses a response by skipping over the upsname and the variable and deleting any \" from the reply. |
private String |
queryString(String com,
String var)
Constructs a query string from a variable name and a desired action. |
String |
readCache(String key)
Reads the sensor. |
private String |
sendToSocket(String command)
Writes to the socket writer. |
| Methods inherited from class io.AbstractDriver |
|---|
createDriver, equals, getDriverName, 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, init, 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, toString |
| 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 |
| Methods inherited from interface util.Initializable |
|---|
init |
| Field Detail |
|---|
public static final String KEY_HOST
public static final String KEY_PORT
public static final String KEY_LIST
public static final String KEY_REFRESH
public static final String KEY_CR
public static final String KEY_LOGIN
public static final String KEY_USER
public static final String KEY_PASSWORD
public static final String DEFDRIVERNAME
private static final String DEFHOST
private static final int DEFPORT
private static final String DEFLIST
private static final long DEFREFRESH
private static final boolean DEFLOGIN
private static final String DEFCR
private static final String CMD_LOGIN
private static final String CMD_LOGOUT
private static final String CMD_USER
private static final String CMD_PASSWORD
private static final String CMD_GET
private static final String CMD_VAR
private static final String CMD_DESC
private static final String ANS_OK
private static final String ANS_ERROR
private static final String SEPARATOR
private boolean isopen
private boolean islogin
private Socket upsd
private BufferedReader in
private BufferedWriter out
private Map<String,String> lookup
private Map<String,String> describe
private Timer update
private Set<String> fails
| Constructor Detail |
|---|
public UpsDriver(Map<String,String> prop)
IllegalArgumentException - If no #KEY_REQUEST property
is given.| Method Detail |
|---|
public boolean open()
throws IOException
KEY_HOST and
KEY_PORT.KEY_LOGIN key, the
login name KEY_LOGIN and the password KEY_PASSWORD
are sent.KEY_LIST into
served variable names. The description table is set up by immediately
issuing a GET DESC
open in interface DriverIOException
public boolean close()
throws IOException
CMD_LOGIN command,
a logout is performed prior to stopping this thread.
close in interface DriverIOExceptionpublic boolean isOpen()
isOpen in interface Driverpublic void exit()
exit in interface ExitCleaningpublic String readCache(String key)
#KEY_REQUEST) to the upsd. The incomming reply is stripped
from the confirmation part and only the variable value is passed to
the #processAnswer method.
public String getDescription(String key)
private String sendToSocket(String command)
#errorReceived method, after the leading
ANS_ERROR code has been stripped from the response.This method expects the streams to be open, no further checks are made.
private String queryString(String com,
String var)
CMD_GET. On
response, this is the starting for successful responses.
private String parseResponse(String query,
String response)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||