public abstract class SensorTask
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected com.dalsemi.onewire.adapter.DSPortAdapter |
adapter
1-Wire port adapter.
|
protected java.lang.String |
address
Configured device address.
|
protected boolean |
cancel
Flag to cancel the task.
|
static java.lang.String |
CFG_DEVICE_ADDRESS_KEY
Device address configuration sensor-name.key suffix.
|
static java.lang.String |
CFG_DEVICE_CHANNEL_KEY
Device-specific channel address sensor-name.key suffix.
|
static java.lang.String |
CFG_DEVICE_OFFSET_KEY
Calibration offset configuration sensor-name.key suffix.
|
static java.lang.String |
CFG_DEVICE_SCALE_KEY
Calibration scale configuration sensor-name.key suffix.
|
static java.lang.String |
CFG_SAMPLING_INTERVAL_KEY
Sampling interval (milliseconds) configuration sensor-name.key suffix.
|
protected java.util.Properties |
config
Configuration properties.
|
protected IDataExchange |
dataExchange
Data Exchange to notify with new data.
|
protected static java.util.logging.Logger |
LOGGER
Logger for this class.
|
protected java.lang.String |
name
Task and dataset name.
|
protected static long |
ONE_WIRE_TIMEOUT
Timeout value for 1-Wire access in nanoseconds (10 seconds).
|
protected int |
population
Sample size for standard deviation calculations.
|
protected static long |
SENSOR_TIMEOUT
Timeout value for sensor commands in nanoseconds (100 seconds).
|
Constructor and Description |
---|
SensorTask(java.lang.String name,
com.dalsemi.onewire.adapter.DSPortAdapter adapter,
java.util.Properties config,
IDataExchange dataExchange)
Creates a new instance of SensorTask.
|
Modifier and Type | Method and Description |
---|---|
protected void |
beginExclusive()
Mutex for exclusive access to the 1-Wire network.
|
protected double |
curveFit(double value,
double[] coeffs)
Scales sensor value according to the curve fit coefficients.
|
protected void |
doADConvertEFT(com.dalsemi.onewire.container.ADContainer device,
boolean[] channels,
byte[] state)
Encapsulates exclusive fault tolerant access to A/D conversions.
|
protected void |
doADConvertEFT(com.dalsemi.onewire.container.ADContainer device,
int channel,
byte[] state)
Encapsulates exclusive fault tolerant access to A/D conversions.
|
protected void |
doTemperatureConvertEFT(com.dalsemi.onewire.container.TemperatureContainer device,
byte[] state)
Encapsulates exclusive fault tolerant access to temperature conversions.
|
protected void |
endExclusive()
Mutex for exclusive access to the 1-Wire network.
|
private com.dalsemi.onewire.container.OneWireContainer |
findContainer(byte[] address,
byte[] family)
Finds a specific device by address for this task.
|
private com.dalsemi.onewire.container.OneWireContainer |
findContainer(java.lang.String address,
byte[] family)
Finds or discovers a suitable device by address for this task.
|
private com.dalsemi.onewire.container.OneWireContainer |
findContainer(java.lang.String address,
java.lang.String name,
byte[] family)
Finds a device by file or address for this task.
|
protected com.dalsemi.onewire.container.OneWireContainer |
findContainerEFT(byte[] address,
byte[] family)
Finds a specific device by address for this task.
|
protected com.dalsemi.onewire.container.OneWireContainer |
findContainerEFT(java.lang.String address,
byte[] family)
Finds or discovers a suitable device by address for this task.
|
protected com.dalsemi.onewire.container.OneWireContainer |
findContainerEFT(java.lang.String address,
java.lang.String name,
byte[] family)
Finds a device by file or address for this task.
|
protected double[] |
getADVoltageEFT(com.dalsemi.onewire.container.ADContainer device,
byte[] state)
Encapsulates exclusive fault tolerant access to reading A/D conversion
results.
|
protected double |
getADVoltageEFT(com.dalsemi.onewire.container.ADContainer device,
int channel,
byte[] state)
Encapsulates exclusive fault tolerant access to reading A/D conversion
results.
|
protected double |
getTemperatureEFT(com.dalsemi.onewire.container.TemperatureContainer device,
byte[] state)
Encapsulates exclusive fault tolerant access to read temperature.
|
private com.dalsemi.onewire.container.OneWireContainer |
initSpeed(com.dalsemi.onewire.container.OneWireContainer cont)
Initialize container speed.
|
protected byte[] |
readBytesEFT(com.dalsemi.onewire.container.OneWireContainer30 device,
int address,
int length)
Encapsulates exclusive fault tolerant access to read bytes from a DS2760.
|
protected long |
readCounterEFT(com.dalsemi.onewire.container.OneWireContainer1D device,
int page)
Encapsulates exclusive fault tolerant access to reading a device counter.
|
protected byte[] |
readDeviceEFT(com.dalsemi.onewire.container.OneWireSensor device)
Encapsulates exclusive fault tolerant access to reading a device.
|
protected void |
readFileEFT(com.dalsemi.onewire.container.OneWireContainer device,
java.lang.String fileName,
byte[] data)
Encapsulates exclusive fault tolerant access to reading a file.
|
protected void |
setMaxTemperatureResolutionEFT(com.dalsemi.onewire.container.TemperatureContainer device,
byte[] state)
Encapsulates exclusive fault tolerant access to setting the maximum
device resolution.
|
protected double |
stdDev(double[] values)
Calculates the standard deviation of the given values.
|
protected java.lang.String |
toHexString(byte[] array)
Returns a text representation of a byte array in hex format.
|
java.lang.String |
toString()
Returns a text representation of this object.
|
protected void |
writeByteEFT(com.dalsemi.onewire.container.OneWireContainer30 device,
int address,
byte data)
Encapsulates exclusive fault tolerant access to write a byte to a DS2760.
|
protected void |
writeDeviceEFT(com.dalsemi.onewire.container.OneWireSensor device,
byte[] data)
Encapsulates exclusive fault tolerant access to writing a device.
|
public static final java.lang.String CFG_SAMPLING_INTERVAL_KEY
public static final java.lang.String CFG_DEVICE_ADDRESS_KEY
public static final java.lang.String CFG_DEVICE_OFFSET_KEY
public static final java.lang.String CFG_DEVICE_SCALE_KEY
public static final java.lang.String CFG_DEVICE_CHANNEL_KEY
protected static final long ONE_WIRE_TIMEOUT
protected static final long SENSOR_TIMEOUT
protected int population
protected java.lang.String name
protected java.lang.String address
protected static final java.util.logging.Logger LOGGER
protected java.util.Properties config
protected com.dalsemi.onewire.adapter.DSPortAdapter adapter
protected IDataExchange dataExchange
protected boolean cancel
public SensorTask(java.lang.String name, com.dalsemi.onewire.adapter.DSPortAdapter adapter, java.util.Properties config, IDataExchange dataExchange)
name
- of this sensor task.adapter
- 1-Wire adapter.config
- configuration properties.dataExchange
- to notify with new data.protected com.dalsemi.onewire.container.OneWireContainer findContainerEFT(java.lang.String address, byte[] family) throws com.dalsemi.onewire.OneWireException, ServiceException
address
- of the device required for this task.family
- code narrows the search to a particular family of devices.com.dalsemi.onewire.OneWireException
- if a communication error occurs.ServiceException
- if no suitable device is found.protected com.dalsemi.onewire.container.OneWireContainer findContainerEFT(byte[] address, byte[] family) throws com.dalsemi.onewire.OneWireException, ServiceException
address
- of the device required for this task.family
- code narrows the search to a particular family of devices.com.dalsemi.onewire.OneWireException
- if a communication error occurs.ServiceException
- if no suitable device is found.protected com.dalsemi.onewire.container.OneWireContainer findContainerEFT(java.lang.String address, java.lang.String name, byte[] family) throws com.dalsemi.onewire.OneWireException, ServiceException
address
- of the device required for this task.name
- of the file to find.family
- code narrows the search to a particular family of devices.com.dalsemi.onewire.OneWireException
- if a communication error occurs.ServiceException
- if no suitable device is found.protected void readFileEFT(com.dalsemi.onewire.container.OneWireContainer device, java.lang.String fileName, byte[] data) throws java.io.IOException, com.dalsemi.onewire.OneWireException
device
- to read.fileName
- to read.data
- buffer output.java.io.IOException
- if the operation retry timeout expires.com.dalsemi.onewire.OneWireException
- if exclusive access fails.protected void writeDeviceEFT(com.dalsemi.onewire.container.OneWireSensor device, byte[] data) throws com.dalsemi.onewire.OneWireException
device
- to write.data
- to write.com.dalsemi.onewire.OneWireException
- if the operation retry timeout expires.protected byte[] readDeviceEFT(com.dalsemi.onewire.container.OneWireSensor device) throws com.dalsemi.onewire.OneWireException
device
- to read.com.dalsemi.onewire.OneWireException
- if the operation retry timeout expires.protected long readCounterEFT(com.dalsemi.onewire.container.OneWireContainer1D device, int page) throws com.dalsemi.onewire.OneWireException
device
- to read.page
- of the counter to read.com.dalsemi.onewire.OneWireException
- if the operation retry timeout expires.protected void doADConvertEFT(com.dalsemi.onewire.container.ADContainer device, boolean[] channels, byte[] state) throws com.dalsemi.onewire.OneWireException
device
- to perform the conversion.channels
- to convert.state
- of the device.com.dalsemi.onewire.OneWireException
- if the operation retry timeout expires.protected void doADConvertEFT(com.dalsemi.onewire.container.ADContainer device, int channel, byte[] state) throws com.dalsemi.onewire.OneWireException
device
- to perform the conversion.channel
- to convert.state
- of the device.com.dalsemi.onewire.OneWireException
- if the operation retry timeout expires.protected double[] getADVoltageEFT(com.dalsemi.onewire.container.ADContainer device, byte[] state) throws com.dalsemi.onewire.OneWireException
device
- to read.state
- of the device.com.dalsemi.onewire.OneWireException
- if the operation retry timeout expires.protected double getADVoltageEFT(com.dalsemi.onewire.container.ADContainer device, int channel, byte[] state) throws com.dalsemi.onewire.OneWireException
device
- to read.channel
- to read.state
- of the device.com.dalsemi.onewire.OneWireException
- if the operation retry timeout expires.protected void setMaxTemperatureResolutionEFT(com.dalsemi.onewire.container.TemperatureContainer device, byte[] state) throws com.dalsemi.onewire.OneWireException
device
- to set.state
- of the device.com.dalsemi.onewire.OneWireException
- if the operation retry timeout expires.protected void doTemperatureConvertEFT(com.dalsemi.onewire.container.TemperatureContainer device, byte[] state) throws com.dalsemi.onewire.OneWireException
device
- to perform the conversion.state
- of the device.com.dalsemi.onewire.OneWireException
- if the operation retry timeout expires.protected double getTemperatureEFT(com.dalsemi.onewire.container.TemperatureContainer device, byte[] state) throws com.dalsemi.onewire.OneWireException
device
- to read.state
- of the device.com.dalsemi.onewire.OneWireException
- if the operation retry timeout expires.protected void writeByteEFT(com.dalsemi.onewire.container.OneWireContainer30 device, int address, byte data) throws com.dalsemi.onewire.OneWireException
device
- to write.address
- in memory to write.data
- to write.com.dalsemi.onewire.OneWireException
- if 1-Wire communication fails.protected byte[] readBytesEFT(com.dalsemi.onewire.container.OneWireContainer30 device, int address, int length) throws com.dalsemi.onewire.OneWireException
device
- to read.address
- in memory to read.length
- number of bytes to read.com.dalsemi.onewire.OneWireException
- if 1-Wire communication fails.protected double curveFit(double value, double[] coeffs)
value
- raw sensor value.coeffs
- coefficients.protected double stdDev(double[] values)
values
- to evaluate.protected void beginExclusive() throws com.dalsemi.onewire.OneWireException
com.dalsemi.onewire.OneWireException
- if exclusive access fails.protected void endExclusive()
public java.lang.String toString()
toString
in class java.lang.Object
protected java.lang.String toHexString(byte[] array)
array
- to convert to a string.private com.dalsemi.onewire.container.OneWireContainer findContainer(byte[] address, byte[] family) throws com.dalsemi.onewire.OneWireException, ServiceException
address
- of the device required for this task.family
- code narrows the search to a particular family of devices.com.dalsemi.onewire.OneWireException
- if a communication error occurs.ServiceException
- if no suitable device is found.private com.dalsemi.onewire.container.OneWireContainer findContainer(java.lang.String address, byte[] family) throws com.dalsemi.onewire.OneWireException, ServiceException
address
- of the device required for this task.family
- code narrows the search to a particular family of devices.com.dalsemi.onewire.OneWireException
- if a communication error occurs.ServiceException
- if no suitable device is found.private com.dalsemi.onewire.container.OneWireContainer findContainer(java.lang.String address, java.lang.String name, byte[] family) throws com.dalsemi.onewire.OneWireException, ServiceException
address
- of the device required for this task.name
- of the file to find.family
- code narrows the search to a particular family of devices.com.dalsemi.onewire.OneWireException
- if a communication error occurs.ServiceException
- if no suitable device is found.private com.dalsemi.onewire.container.OneWireContainer initSpeed(com.dalsemi.onewire.container.OneWireContainer cont) throws com.dalsemi.onewire.OneWireException
cont
- 1-Wire container.com.dalsemi.onewire.OneWireException
- if initialization fails.