|
||||||||||
| 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.ow.PythonClient
public class PythonClient
This is a work-around to get the one-wire sensors to work. The python client
talks via socket to a python server that is responible for issuing the
one-wire commands. It uses a very simple ASCII-protocol that understands
only three commands, LIST, READ, WRITE, or STOP.
On startup, the client connects to the server on port
KEY_PYTHONPORT and keeps the connection open until closed. On
init, it sends a list of readable sensors to the server. During normal
operation, i.e. when sensors query the client, a read command is issued
and the python server returns in plain ascii the most current value of
the sensor it has in its cache. If the path issued to the python server
was not sent to it previously with a list command, this method returns
OneWireDriver.INVALID. Writing of the one-wire switches is accomplished in a
similar way by issuing a write command to the python server. These write
commands are normally not cached, but forwarded driectly to the underlying
onw-wire system. The result returned is writtn by the python server to this
python client. Protocol (\n means new-line):
OneWireDriver.INVALID is returned.
| Nested Class Summary | |
|---|---|
static class |
PythonClient.Test
A test class. |
| Nested classes/interfaces inherited from class util.PropertyResources |
|---|
PropertyResources.URLResource |
| Field Summary | |
|---|---|
static String |
ADD
The add command string. |
private static String |
COMMANDSEPARATOR
The separator string between multi-part commands. |
private static long |
DEFCOOLDOWN
The default cooldown in ms. |
private static String |
DEFDRIVERNAME
The default python driver name, a serial port name under linux |
private static String |
DEFPYTHONHOST
The default one-wire server name, a serial port name under linux |
private static int |
DEFPYTHONPORT
The default python server's listening port. |
private static String |
DEFSENSORPATH
The default list of sensors. |
private static long |
DEFTIMEOUT
The default timeout in ms. |
private BufferedReader |
in
The input reader derived from the client socket. |
static String |
KEY_COOLDOWN
The default time-out after writing in ms |
static String |
KEY_PYTHONHOST
The name of the host the python server runs on. |
static String |
KEY_PYTHONPORT
The port the python server is listening at. |
static String |
KEY_SENSORPATH
The default list of sensor devices to read as a comma-separated list. |
static String |
KEY_TIMEOUT
The default time-out for reading in ms |
static String |
LIST
The list command string. |
private Socket |
open
The client socket opened on PropertyResources.init(). |
private BufferedWriter |
out
The output writer derived from the client socket. |
static String |
READ
The read command string. |
private boolean |
stalled
Gets true if reading produced a time-out. |
static String |
STOP
The stop command string. |
static String |
WRITE
The write command string. |
| 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.ow.OneWireDriver |
|---|
INVALID, OK, VALID |
| 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 | |
|---|---|
PythonClient(Map prop)
Constructs a new python driver. |
|
| Method Summary | |
|---|---|
boolean |
close()
Closes the driver. |
private boolean |
closeSocket()
Closes the socket without sending a stop to the Python server. |
void |
exit()
On exit we close the client socket to the server and do not care about any possible failures. |
boolean |
isOpen()
Checks if the connection is open. |
int |
issue(String sensorpath,
String what)
Sends a write command to the python server. |
boolean |
open()
Initializes the driver. |
private boolean |
openSocket()
Opens the socket connetion, but does not send any sensor lists. |
private String |
readLine()
Reads a line from the input stream, and blocks if no bytes are available. |
String |
retrieve(String sensorpath)
Send a read command to the python server. |
boolean |
sendList(List sensorlist)
Send a list to the python server. |
boolean |
sendStop()
Sends the stop command. |
private boolean |
writeLine(String what)
Sends the given line to the socket's output stream. |
| 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 io.Driver |
|---|
getDriverName |
| 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_PYTHONHOST
public static final String KEY_PYTHONPORT
public static final String KEY_SENSORPATH
public static final String KEY_COOLDOWN
public static final String KEY_TIMEOUT
private static final String DEFDRIVERNAME
private static final String DEFPYTHONHOST
private static final int DEFPYTHONPORT
private static final String DEFSENSORPATH
private static final long DEFCOOLDOWN
private static final long DEFTIMEOUT
public static final String LIST
public static final String ADD
public static final String READ
public static final String WRITE
public static final String STOP
private static final String COMMANDSEPARATOR
private Socket open
PropertyResources.init().
private BufferedReader in
private BufferedWriter out
private boolean stalled
| Constructor Detail |
|---|
public PythonClient(Map prop)
KEY_SENSORPATH are sent to the python
server.
| Method Detail |
|---|
public boolean open()
throws IOException
KEY_PYTHONPORT. If the open is successful, we parse the
initial list of sensors to query and send it to the server.
open in interface DriverIOException
private boolean openSocket()
throws IOException
IOException
private boolean closeSocket()
throws IOException
IOExceptionpublic boolean isOpen()
isOpen in interface Driverpublic boolean close()
close in interface Driverpublic void exit()
exit in interface ExitCleaningpublic boolean sendList(List sensorlist)
public String retrieve(String sensorpath)
retrieve in interface OneWireDriversensorpath - The path to the one-wire sensor.
public int issue(String sensorpath,
String what)
issue in interface OneWireDriversensorpath - The path to the one-wire sensor.what - The command to send to the one-wire sensor.public boolean sendStop()
private boolean writeLine(String what)
KEY_COOLDOWN time to ensure that
reading the line is possible immediately as the write returns. This is no
elegant solution, but there is actually no case where we write and
not read immediately afterwards.
We had mysterious dissappearance of sensor threads, which I believe is
a buffer overflow in the out stream. Thus, on occasions where
we're stalled, we re-open the connection, not really hoping for a
cure, but trying to keep the thing alive.
private String readLine()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||