public class PythonClient extends AbstractDriver implements ExitCleaning, OneWireDriver
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.| Modifier and Type | Class and Description |
|---|---|
static class |
PythonClient.Test
A test class.
|
| Modifier and Type | Field and Description |
|---|---|
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
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.
|
KEY_DRIVERNAMEKEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATORINVALID, OK, VALIDCONFIG, KEY_CLASS| Constructor and Description |
|---|
PythonClient(Map prop)
Constructs a new python driver.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
void |
init()
Initializing never fails as all relevant keys have default values.
|
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.
|
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, toStringfinalize, getClass, notify, notifyAll, wait, wait, waitgetDriverNamepublic 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 BufferedReader in
private BufferedWriter out
private boolean stalled
public PythonClient(Map prop)
KEY_SENSORPATH are sent to the python
server.public void init()
init in interface Initializablepublic 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 DriverIOExceptionprivate boolean openSocket()
throws IOException
IOExceptionprivate boolean closeSocket()
throws IOException
IOExceptionpublic boolean isOpen()
public boolean close()
public 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()