public class UpsDriver extends AbstractDriver implements ExitCleaning
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.| Modifier and Type | Class and Description |
|---|---|
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.
|
| Modifier and Type | Field and Description |
|---|---|
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.
|
KEY_DRIVERNAMEKEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATORCONFIG, KEY_CLASS| Constructor and Description |
|---|
UpsDriver(Map<String,String> prop)
Constructs a new ups-sensor.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
void |
init()
Initializing never fails as all relevant keys have default values.
|
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.
|
createDriver, equals, getDriverName, 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, stringProperties, toStringpublic 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 Timer update
public UpsDriver(Map<String,String> prop)
IllegalArgumentException - If no #KEY_REQUEST property is given.public void init()
init in interface Initializablepublic 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 DriverIOExceptionpublic boolean close()
throws IOException
CMD_LOGIN command, a logout
is performed prior to stopping this thread.close in interface DriverIOExceptionpublic boolean isOpen()
public 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.