public abstract class Ups extends WeatherSensor
KEY_PORT, which should alwys be
DEFPORTKEY_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(java.lang.String) 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(java.lang.String) 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(java.lang.String) 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.TimerTaskSensor.SensorReadPropertyResources.Load, PropertyResources.URLResource| Modifier and Type | Field and Description |
|---|---|
private static String |
ANS_ERROR
The leading string for error-replies.
|
private static String |
ANS_LOGIN
The correct answer for login processes.
|
private static String |
ANS_REQUEST
The correct answer for request processes.
|
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_REQUEST
The request command.
|
private static String |
CMD_USER
The username command.
|
private static String |
DEFCR
The default end-of-line string.
|
private static String |
DEFHOST
The default host name where the server is running.
|
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 BufferedReader |
in
The socket reader, a wrapped socket-input stream.
|
private boolean |
islogin
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_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_REQUEST
The key pointing to the end-of-line string sent/received.
|
static String |
KEY_UPSNAME
Key to the UPS-name.
|
static String |
KEY_USER
The key pointing to the end-of-line string sent/received.
|
private BufferedWriter |
out
The socket writer, a wrapped socket-output stream.
|
private Socket |
upsd
The communication socket.
|
KEY_DERIVATIVEINVALID, KEY_DERIVATIVEPARAMETER, KEY_INVERSE, KEY_INVERSEDERIVATIVE, KEY_JUDGEDERIVATIVE, KEY_JUDGEPREDICT, KEY_JUDGERAW, KEY_JUDGESMOOTH, KEY_PREDICTINVALID, KEY_PREDICTPARAMETER, KEY_RAWINVALID, KEY_RAWPARAMETER, KEY_RETARDBADDERIVATIVE, KEY_RETARDBADPREDICT, KEY_RETARDBADRAW, KEY_RETARDBADSMOOTH, KEY_RETARDGOODDERIVATIVE, KEY_RETARDGOODPREDICT, KEY_RETARDGOODRAW, KEY_RETARDGOODSMOOTH, KEY_SMOOTHINVALID, KEY_SMOOTHPARAMETERDEFRAWDERIVATIVE, derive, KEY_DERIVATIVEADVISE, KEY_DERIVE, KEY_PATH, KEY_RAWDERIVATIVE, zf, g, KEY_SMOOTH, KEY_SMOOTHADVISEKEY_CHI, KEY_EXTRAPOLATE, KEY_FUTURE, KEY_PREDICTADVISE, predictKEY_AVERAGE, KEY_MEMORY, KEY_PACKDEFRAWFORMAT, DEFREPORT, DEFSIGMAFORMAT, KEY_RAWFORMAT, KEY_REPORT, KEY_SIGMAFORMATKEY_LOGRAWABOVE, KEY_LOGRAWBELOW, KEY_LOGREADLAG, KEY_RESPAWNKEY_BIND, KEY_BINDNAME, KEY_CONVERT, KEY_DESCRIPTION, KEY_SENSORNAMEALTERNATEHOST, ALTERNATEPORT, KEY_EXPORTPORT, KEY_REGISTRYHOST, KEY_REGISTRYPORTKEY_NOINITONCREATE, POSTFIX_ALPHABET, POSTFIX_BYTES, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_MODTIME, POSTFIX_URLKEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATORNAMING_EXTENSIONCONFIG, KEY_CLASSKEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME| Modifier | Constructor and Description |
|---|---|
protected |
Ups(Map prop)
Constructs a new ups-sensor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
cancel()
Cancels this sensor reading thread.
|
private boolean |
closeSocket()
Closes a client-socket to the ups server.
|
protected void |
errorReceived(String error)
Treats incoming error replies.
|
TimerTask |
initSensorTimerTask()
Initializes the thread the ups-sensor should run in.
|
private boolean |
openSocket()
Opens a client-socket to the ups-server.
|
protected abstract double |
processAnswer(String answer)
Subclasses must provide a body for this method.
|
protected double |
readSensor()
Reads the sensor.
|
private String |
send(String command)
Writes to the socket writer.
|
private String |
sendToSocket(String command)
Opens a socket to the ups-server, writes out a specified command,
reads in the response and closes the socket before returning.
|
addWeatherListener, conductOneMeasure, currentlyClear, currentlyRetarding, generateDataEvent, getMinClearUpTime, getSensorInitInfo, goodFromDerivative, goodFromPredict, goodFromRaw, goodFromSmooth, isDerivativeRetard, isPredictRetard, isRawRetard, isSmoothRetard, judgeWeather, notifyWeatherListener, removeWeatherListener, statusderiveAt, getDerivativeFormat, getDerivativeToggleInfo, getDerivator, getLastDerivative, isDerivativeAdvise, isDeriving, newData, regetDerive, registerDerivatorgetLastSmooth, getSmoother, getSmoothToggleInfo, isSmoothAdvise, isSmoothing, regetSmooth, registerSmoother, smoothOnegetExtrapolation, getLastPredict, getPredictToggleInfo, init, isPredictAdvise, isPredicting, isReliable, predictFrom, regetPredictcumulateOne, getLastRaw, getLastTime, getMaxSize, getMemory, getSizeaddDataListener, addRmiDataListener, exit, getRawFormat, getSigmaFormat, removeDataListener, removeRmiDataListener, reportequals, getRawToggleInfo, getReading, getRespawn, getTimeOfRead, hashCode, isReady, regetRaw, setTimeOfRead, validReadingaddRmiErrorListener, createSensor, getBindName, getConvert, getSensorDescription, getSensorName, notifyErrorListener, removeRmiErrorListener, setConvert, toStringbindToRegistry, bindToRegistry, bindToRegistry, bindToRegistry, bindToRegistry, bindToRegistry, casterExit, casterExit, getBindName, isValid, unbindFromRegistry, unbindFromRegistrycontainsRemoteProperty, getRemoteProperties, getRemoteProperty, setRemotePropertyclone, createFrom, createFrom, createFrom, createInstance, getApplet, getAsResources, getLocate, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, hasLocalURLs, initProperties, keyCreate, keyCreate, reload, setAppletaugment, augment, 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, parseObject, reload, removeProperty, requires, rescanned, setObject, setProperties, setProperty, stringPropertiesfinalize, getClass, notify, notifyAll, wait, wait, waitcumulateOne, getLastRaw, getLastTime, getMaxSize, getSize, getTimeOfRead, regetRawbindToRegistry, isValid, unbindFromRegistryvalidReadingdefaultBoolean, 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, stringPropertiespublic static final String KEY_UPSNAME
public static final String KEY_HOST
public static final String KEY_PORT
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 KEY_REQUEST
private static final String DEFHOST
private static final int DEFPORT
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_REQUEST
private static final String ANS_LOGIN
private static final String ANS_REQUEST
private static final String ANS_ERROR
private boolean islogin
private Socket upsd
private BufferedReader in
private BufferedWriter out
protected Ups(Map prop) throws RemoteException
IllegalArgumentException - If no KEY_REQUEST property
is given.RemoteExceptionpublic TimerTask initSensorTimerTask()
KEY_LOGIN property is true, this sensor logs in at the
upsd-server.initSensorTimerTask in interface TelemeteringinitSensorTimerTask in class TimerTaskSensorTelemetering.getRespawn()public void cancel()
CMD_LOGIN command,
a logout is performed prior to stopping this thread.cancel in interface Telemeteringcancel in class TimerTaskSensorprotected double readSensor()
KEY_REQUEST) to the upsd. The incomming reply is stripped
from the confirmation part and only the variable value is passed to
the processAnswer(java.lang.String) method.readSensor in class TimerTaskSensorConvertToPhysicalprotected abstract double processAnswer(String answer)
WeatherJudging methods should be overridn.private boolean openSocket()
private boolean closeSocket()
private String send(String command)
errorReceived(java.lang.String) 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 sendToSocket(String command)
protected void errorReceived(String error)
error - The error message without the leading ANS_ERROR.