public class ServerClient extends AbstractSocketDriver implements OneWireDriver, Resettable
OWFS is an open source project developed by Paul Alfille and hosted at http://www.owfs.org
Based on the original OWNet code from Paul Alfille. This is a one-wire driver that allow switching and reading sensors.| Modifier and Type | Class and Description |
|---|---|
static class |
ServerClient.Sensor
Tries to read a single temperature sensor.
|
static class |
ServerClient.Swi
Tries to set a single switch.
|
static class |
ServerClient.Switch
Tries to set a single switch.
|
| Modifier and Type | Field and Description |
|---|---|
private static Map<String,String> |
cache
A cache for diverse path's.
|
private static Map<String,Long> |
cachetime
The attached time cache.
|
private static long |
DEFBUSCOOLDOWN
Default retries for write.
|
private static long |
DEFCACHETIME
Default retries for write.
|
private static int |
DEFDATALENGTH
Datalength.
|
private static int |
DEFFORMATFLAGS
Formatting flags.
|
private static int |
DEFMAXNULLREAD
Maximum number of allowed null payload reads before throwing IOExc.
|
private static boolean |
DEFPERSISTENT
Datalength.
|
private static int |
DEFREADRETRY
Default retries for write.
|
private static long |
DEFRESETCADENCE
Default timeout allowed for the reset.
|
private static long |
DEFRESETTIMEOUT
Default timeout allowed for the reset.
|
private static long |
DEFRETRYCOOLDOWN
Default retries for write.
|
private static int |
DEFSOCKETPORT
Port of the server.
|
private static int |
DEFSOCKETTIMEOUT
Timeout.
|
private static int |
DEFWRITERETRY
Default retries for write.
|
private DataInputStream |
indata
The input stream of the socket is wrapped into a data input stream.
|
static String |
KEY_BUSCOOLDOWN
Before and after any bus operation cooldown.
|
static String |
KEY_CACHETIME
Cache-valid for A/D convert operations.
|
static String |
KEY_DATALENGTH
Datalength.
|
static String |
KEY_FORMATFLAGS
Formatting flags.
|
static String |
KEY_MAXNULLREAD
Problems with hanging servers always reporting OK, but never end.
|
static String |
KEY_OWRESET
Points to the path of an executable script that resets the server.
|
static String |
KEY_PERSISTENT
Datalength.
|
static String |
KEY_READRETRY
Read retries on I/O Errors.
|
static String |
KEY_RESETCADENCE
The time-out in ms allowed for successive resets.
|
static String |
KEY_RESETTIMEOUT
The time-out in ms allowed for the reset.
|
static String |
KEY_RETRYCOOLDOWN
I/O Errors retry cooldown.
|
static String |
KEY_WRITERETRY
Write retries on I/O Errors.
|
private Date |
lastfail
Last read failure, cleared on success.
|
private Date |
lastreset
Last successful reset.
|
private Object |
LOCK
As a very last resort, a global lock.
|
private DataOutputStream |
outdata
The output stream of the socket is wrapped into a data output stream.
|
static int |
OWNET_FLAG_D_F_I
format as f.i (10.67C6697351FF)
|
static int |
OWNET_FLAG_D_F_I_C
format as f.i.c (10.67C6697351FF.8D)
|
static int |
OWNET_FLAG_D_F_IC
format as f.ic (10.67C6697351FF8D)
|
static int |
OWNET_FLAG_D_FI
format as fi (1067C6697351FF)
|
static int |
OWNET_FLAG_D_FI_C
format as fi.c (1067C6697351FF.8D)
|
static int |
OWNET_FLAG_D_FIC
format as fic (1067C6697351FF8D)
|
private static int |
OWNET_FLAG_PERSIST |
static int |
OWNET_FLAG_T_C
Temperature format: (C) Centigrade
|
static int |
OWNET_FLAG_T_F
Temperature format: (F) Fahrenheit
|
static int |
OWNET_FLAG_T_K
Temperature format: (K) Kelvin
|
static int |
OWNET_FLAG_T_R
Temperature format: (R) Rankine
|
private static int |
OWNET_MSG_DIR |
private static int |
OWNET_MSG_DIRALL |
private static int |
OWNET_MSG_ERROR |
private static int |
OWNET_MSG_GET |
private static int |
OWNET_MSG_NOP |
private static int |
OWNET_MSG_PRESENCE |
private static int |
OWNET_MSG_READ |
private static int |
OWNET_MSG_READ_ANY |
private static int |
OWNET_MSG_SIZE |
private static int |
OWNET_MSG_WRITE |
private static int |
OWNET_PROT_DATALEN |
private static int |
OWNET_PROT_FLAGS |
private static int |
OWNET_PROT_FUNCTION |
private static int |
OWNET_PROT_OFFSET |
private static int |
OWNET_PROT_PAYLOAD |
private static int |
OWNET_PROT_RETVALUE |
private static int |
OWNET_PROT_STRUCT_SIZE |
private static int |
OWNET_PROT_VERSION |
private boolean |
persistent
If true, connection is configured to be persistent.
|
KEY_CLOSETIMEOUT, KEY_SOCKETPORT, KEY_SOCKETSERVER, KEY_SOCKETTIMEOUTKEY_DRIVERNAMEKEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATORINVALID, OK, VALIDCONFIG, KEY_CLASS| Constructor and Description |
|---|
ServerClient(Map<String,String> prop)
Create a new instance of OWNet
OWNet autoconnects to remote server when requested.
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
authenticate()
On authenticate, we wrap our in/output stream.
|
private int[] |
getPacket()
Get a ownet message packet
|
private String |
getPacketData(int[] packetHeader)
Get a data packet from remote server
|
boolean |
isOpen()
Returns true if we are not persistent, otherwise we return the super
value.
|
int |
issue(String path,
String value)
Issuses a command.
|
boolean |
open()
Connect to remote host.
|
private List |
owDir(String path,
boolean dirall)
Internal method to get directory list from server (multipacket mode)
|
private boolean |
owPresence(String path)
Internal method to get presence state from server
|
private String |
owRead(String path)
Internal method to read from server, using default excpected datalen
|
private String |
owRead(String path,
int expectedDataLen)
Internal method to read from server
|
private boolean |
owWrite(String path,
String value)
Internal method to write to server
|
boolean |
reset()
Resets the owserver by issuing a script.
|
String |
retrieve(String path)
The interface method for retrieving a sensor reading.
|
private String |
retrieveCacheless(String path)
Returns path without cache lookup.
|
private void |
sendCString(String str,
boolean termzero)
Transmit a Java String as a C-String (null terminated)
|
private void |
sendPacket(int function,
int payloadlen,
int datalen)
Send a ownet message packet
|
close, exit, getInputStream, getOutputStream, getSocket, init, setTimeoutcreateDriver, 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, waitclose, getDriverNameinitpublic static final String KEY_OWRESET
public static final String KEY_RESETTIMEOUT
public static final String KEY_RESETCADENCE
public static final String KEY_FORMATFLAGS
public static final String KEY_DATALENGTH
public static final String KEY_PERSISTENT
public static final String KEY_WRITERETRY
public static final String KEY_READRETRY
public static final String KEY_RETRYCOOLDOWN
public static final String KEY_BUSCOOLDOWN
public static final String KEY_CACHETIME
public static final String KEY_MAXNULLREAD
private static final int DEFSOCKETPORT
private static final int DEFFORMATFLAGS
private static final int DEFSOCKETTIMEOUT
private static final int DEFDATALENGTH
private static final boolean DEFPERSISTENT
private static final int DEFWRITERETRY
private static final int DEFREADRETRY
private static final long DEFRETRYCOOLDOWN
private static final long DEFBUSCOOLDOWN
private static final long DEFCACHETIME
private static final int DEFMAXNULLREAD
private static final long DEFRESETTIMEOUT
private static final long DEFRESETCADENCE
private static final int OWNET_MSG_ERROR
private static final int OWNET_MSG_NOP
private static final int OWNET_MSG_READ
private static final int OWNET_MSG_WRITE
private static final int OWNET_MSG_DIR
private static final int OWNET_MSG_SIZE
private static final int OWNET_MSG_PRESENCE
private static final int OWNET_MSG_DIRALL
private static final int OWNET_MSG_GET
private static final int OWNET_MSG_READ_ANY
private static final int OWNET_PROT_STRUCT_SIZE
private static final int OWNET_PROT_VERSION
private static final int OWNET_PROT_PAYLOAD
private static final int OWNET_PROT_FUNCTION
private static final int OWNET_PROT_RETVALUE
private static final int OWNET_PROT_FLAGS
private static final int OWNET_PROT_DATALEN
private static final int OWNET_PROT_OFFSET
public static final int OWNET_FLAG_D_F_I
public static final int OWNET_FLAG_D_FI
public static final int OWNET_FLAG_D_F_I_C
public static final int OWNET_FLAG_D_F_IC
public static final int OWNET_FLAG_D_FI_C
public static final int OWNET_FLAG_D_FIC
public static final int OWNET_FLAG_T_C
public static final int OWNET_FLAG_T_F
public static final int OWNET_FLAG_T_K
public static final int OWNET_FLAG_T_R
private static final int OWNET_FLAG_PERSIST
private DataInputStream indata
private DataOutputStream outdata
private boolean persistent
private final Object LOCK
private Date lastfail
private Date lastreset
public ServerClient(Map<String,String> prop)
public boolean reset()
throws IOException
KEY_OWRESETreset in interface ResettableIOExceptionpublic boolean open()
throws IOException
open in interface Driveropen in class AbstractSocketDriverIOException - Exception to throw on connection errorpublic boolean isOpen()
isOpen in interface DriverisOpen in class AbstractSocketDriverprotected boolean authenticate()
throws IOException
authenticate in class AbstractSocketDriverIOExceptionpublic String retrieve(String path)
retrieve in interface OneWireDriverpath - The path to the one-wire sensor.public int issue(String path, String value)
issue in interface OneWireDriverpath - The path to the one-wire sensor.value - The command to send to the one-wire sensor.private void sendPacket(int function,
int payloadlen,
int datalen)
throws IOException
function - ownet's header fieldpayloadlen - ownet's header fielddatalen - ownet's header fieldIOException - Exception to throw, when something is wrongprivate int[] getPacket()
throws IOException
IOException - Exception to throw, when something is wrongprivate String getPacketData(int[] packetHeader) throws IOException
packetHeader - ownet's header msg packet to use for receiving
auxilary dataIOException - Exception to throw, when something is wrongprivate void sendCString(String str, boolean termzero) throws IOException
str - string to transmitIOException - Exception to throw, when something is wrongprivate String owRead(String path, int expectedDataLen) throws IOException
path - attribute's pathexpectedDataLen - expected length of data to receiveIOException - Exception to throw, when something is wrongprivate String owRead(String path) throws IOException
path - attribute's pathIOException - Exception to throw, when something is wrongprivate boolean owWrite(String path, String value) throws IOException
path - attribute's pathvalue - value to setIOException - Exception to throw, when something is wrongprivate boolean owPresence(String path) throws IOException
path - element to checkIOException - Exception to throw, when something is wrongprivate List owDir(String path, boolean dirall) throws IOException
path - directory to listIOException - Exception to throw, when something is wrong