private class Anemometer.ReadTask
extends java.lang.Object
implements java.lang.Runnable
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
DATA_NAME
Data name.
|
private boolean |
initialize
Flag to initialize sensor.
|
private long |
MAX_ACCESS
Maximum 1-wire access interval (60 milliseconds in nanoseconds).
|
private long |
maxInterval
Maximum timing interval (ten times the nominal sampling interval in
nanoseconds).
|
private long |
minInterval
Minimum timing interval (half the nominal sampling interval in
nanoseconds).
|
private long |
prevCount
Count from the previous sample of counter.
|
private long |
prevTime
Time of the previous sample.
|
private java.lang.String |
TIMING_ACCESS_ERROR
Timing access error message format.
|
private java.lang.String |
TIMING_TOLERANCE_ERROR
Timing tolerance error message format.
|
private java.lang.String |
VALUE_ERROR_1
Message format for extreme rate anomalies.
|
Modifier | Constructor and Description |
---|---|
private |
ReadTask() |
Modifier and Type | Method and Description |
---|---|
private double |
calculateRPS(long count,
long time)
Calculates the current sensor revolutions per second.
|
private double |
getSpeedE()
Reads the anemometer spin counter and calculates the wind speed with
exclusive device access.
|
private double |
getSpeedEFT()
Encapsulates exclusive fault tolerant access to wind speed.
|
private void |
initDevice()
Initializes the sensor for operation.
|
void |
run()
Gets the anemometer wind speed from the DS2423 anemometer and posts
it to the data exchange.
|
private final java.lang.String DATA_NAME
private final java.lang.String VALUE_ERROR_1
private final java.lang.String TIMING_ACCESS_ERROR
private final java.lang.String TIMING_TOLERANCE_ERROR
private final long MAX_ACCESS
private final long minInterval
private final long maxInterval
private boolean initialize
private long prevTime
private long prevCount
public void run()
run
in interface java.lang.Runnable
private void initDevice() throws com.dalsemi.onewire.OneWireException, ServiceException
com.dalsemi.onewire.OneWireException
- if 1-Wire communication fails.ServiceException
- if initialization fails.private double getSpeedEFT() throws com.dalsemi.onewire.OneWireException, TimingException, ValueException
com.dalsemi.onewire.OneWireException
- if a communication error occurs.TimingException
- if time1 - time0 > MAX_ACCESS
indicating an unresponsive sensor or a delayed thread, or
diffTime < MIN_INTERVAL || diffTime > MAX_INTERVAL
causing poor accuracy.ValueException
- if count < prevCount
indicating non-monotonic count progression.private double getSpeedE() throws com.dalsemi.onewire.OneWireException, TimingException, ValueException
1-Wire Signalling Protocol (regular speed) Reset master reset 480usec + device presence 480usec + 15usec transition = 975usec Send or receive a bit tslot 120usec (max) + recovery time 1usec (min) = 128usec (typ) Device select (match ROM) 72 bits send, 72 bits receive = 18.5msec The DS2423 read counter command consists of reset + match ROM + send 112 bits + recv 112 bits = 48msecWe read the system nano time to bracket the device access time. The two calls to nano time total about 4usec, which is negligible for this application. However, the task thread can be suspended during execution, introducing severe timing uncertainty. Experimental data indicate the average access time is 49.7msec, with a typical maximum access time of 55.4msec, but much longer access times do occur randomly. Therefore, we retry the operation if it takes longer than 60 msec.
com.dalsemi.onewire.OneWireException
- if a communication error occurs.TimingException
- if time1 - time0 > MAX_ACCESS
indicating an unresponsive sensor or a delayed thread, or
diffTime < MIN_INTERVAL || diffTime > MAX_INTERVAL
causing poor accuracy.ValueException
- if count < prevCount
indicating non-monotonic count progression.private double calculateRPS(long count, long time) throws TimingException, ValueException
count
- anemometer spin count.time
- in nanoseconds at the current sample.TimingException
- if
diffTime < interval / 2 || diffTime > interval * 2
causing poor accuracy.ValueException
- if count < prevCount
indicating non-monotonic count progression.