private class Barometer.ReadTask
extends java.lang.Object
implements java.lang.Runnable
The TAI8570 contains a pair of DS2406 dual addressable switches to clock data into and out of the Intersema MS5534A Barometer Module serial interface. The task must send and receive every data bit as a separate MicroLan transaction. Both switches are independent devices on the MicroLan. A file on one switch contains the address of the other associated switch. The write switch has VCC power supplied, whereas the read switch does not (however, they both use parasitic power). This power scheme is how TAI chose to identify the switch function.
Modifier and Type | Field and Description |
---|---|
private int |
c1
Pressure sensitivity calibration constant.
|
private int |
c2
Pressure offset calibration constant.
|
private int |
c3
Pressure sensitivity temperature coefficient calibration constant.
|
private int |
c4
Pressure offset temperature coefficient calibration constant.
|
private int |
c5
Reference temperature calibration constant.
|
private int |
c6
Temperature sensor coefficient calibration constant.
|
private int |
CLOCK
DS2406 clock channel address.
|
private boolean[] |
CMD_CALIBRATE1
MS5534A read calibration word 1 command.
|
private boolean[] |
CMD_CALIBRATE2
MS5534A read calibration word 2 command.
|
private boolean[] |
CMD_CALIBRATE3
MS5534A read calibration word 3 command.
|
private boolean[] |
CMD_CALIBRATE4
MS5534A read calibration word 4 command.
|
private boolean[] |
CMD_PRESSURE
MS5534A pressure convert command.
|
private boolean[] |
CMD_RESET
MS5534A reset command.
|
private boolean[] |
CMD_TEMPERATURE
MS5534A temperature convert command.
|
private long |
CONVERSION_TIMEOUT
MS5534A A/D conversion timeout (10x 33 msec).
|
private int |
DATA
DS2406 data channel address.
|
private boolean |
HH
DS2406 open-drain latch output high (non-conducting) state.
|
private boolean |
initialize
Flag to initialize sensor.
|
private boolean |
LL
DS2406 open-drain latch output low (conducting) state.
|
private java.lang.String |
PRESSURE_NAME
Data name for pressure.
|
private byte[] |
stateRx
DS2406 dual addressable switch state buffer.
|
private byte[] |
stateTx
DS2406 dual addressable switch state buffer.
|
private double |
temperature
Temperature value that was used to calculate pressure (celsius).
|
private java.lang.String |
TEMPERATURE_NAME
Data name for temperature.
|
private int |
ut
Derived temperature calibration constant.
|
Modifier | Constructor and Description |
---|---|
private |
ReadTask() |
Modifier and Type | Method and Description |
---|---|
private void |
calibrate()
Reads the internal calibration constants from the MS5534A.
|
private void |
configure()
Configures 1-Wire parameters.
|
private int |
doADConvert(boolean[] command)
Writes the MS5534A convert command sequence; reads the result.
|
private double |
getPressure()
Calculates the current atmospheric pressure.
|
private double |
getTemperature()
Reads the compensated temperature value that was used in the
calculation to get pressure.
|
private void |
identifyDevices(java.lang.String cfgAddress,
java.lang.String cfgFileName)
Finds the device that has the file containing the address of the
other device and reads the file.
|
private void |
initDevice()
Initializes the TAI8570 Pressure SensorTask for operation.
|
private boolean |
pollMS5534A()
Polls the MS5534A serial data output.
|
private int |
readCalibration(boolean[] command)
Reads a single calibration value from the MS5534A.
|
private boolean |
readMS5534A()
Clocks a data bit out of the MS5534A serial data output.
|
private int |
readWord()
Clocks 16 data bits from the MS5534A serial data output.
|
private void |
resetDS2406()
Resets the DS2406 switches.
|
private void |
resetMS5534A()
Sends the reset command to the MS5534A.
|
void |
run()
Initializes the TAI8570 if necessary, then gets the pressure and
temperature values from the TAI8570 and posts them to the data
exchange.
|
private double |
toSeaLevel(double pressure)
Corrects local barometric pressure to sea level.
|
private void |
waitForADConvertComplete(long timeout)
Reads the device to provide one additional clock pulse following the
write convert command, to initiate the conversion.
|
private void |
writeCommand(boolean[] command)
Clocks command data bit sequence into the MS5534A serial data input.
|
private void |
writeMS5534A(boolean data)
Writes a data bit to the MS5534A serial data input.
|
private final java.lang.String PRESSURE_NAME
private final java.lang.String TEMPERATURE_NAME
private final int CLOCK
private final int DATA
private final boolean HH
private final boolean LL
private final boolean[] CMD_PRESSURE
private final boolean[] CMD_TEMPERATURE
private final boolean[] CMD_CALIBRATE1
private final boolean[] CMD_CALIBRATE2
private final boolean[] CMD_CALIBRATE3
private final boolean[] CMD_CALIBRATE4
private final boolean[] CMD_RESET
private final long CONVERSION_TIMEOUT
private byte[] stateTx
private byte[] stateRx
private boolean initialize
private int c1
private int c2
private int c3
private int c4
private int c5
private int c6
private int ut
private double temperature
public void run()
run
in interface java.lang.Runnable
private void initDevice() throws com.dalsemi.onewire.OneWireException, ServiceException, com.dalsemi.onewire.application.file.OWFileNotFoundException, java.io.IOException
com.dalsemi.onewire.OneWireException
- if a 1-Wire communication error occurs.ServiceException
- if no suitable device is found.com.dalsemi.onewire.application.file.OWFileNotFoundException
- if file does not exist on the 1-Wire
device.java.io.IOException
- if a file read attempt fails.private void configure() throws com.dalsemi.onewire.OneWireException, ServiceException, com.dalsemi.onewire.application.file.OWFileNotFoundException, java.io.IOException
com.dalsemi.onewire.OneWireException
- if a 1-Wire communication error occurs.ServiceException
- if no suitable device is found.com.dalsemi.onewire.application.file.OWFileNotFoundException
- if file does not exist on the 1-Wire
device.java.io.IOException
- if a file read attempt fails.private void identifyDevices(java.lang.String cfgAddress, java.lang.String cfgFileName) throws com.dalsemi.onewire.OneWireException, ServiceException, com.dalsemi.onewire.application.file.OWFileNotFoundException, java.io.IOException
cfgAddress
- address from wxservice.properties.cfgFileName
- file name from wxservice.properties.com.dalsemi.onewire.OneWireException
- if a communication error occurs.ServiceException
- if no suitable device is found.com.dalsemi.onewire.application.file.OWFileNotFoundException
- if file does not exist on the 1-Wire
device.java.io.IOException
- if a file read attempt fails.private void resetDS2406() throws com.dalsemi.onewire.OneWireException
com.dalsemi.onewire.OneWireException
- if a 1-Wire communication error occurs.private void resetMS5534A() throws com.dalsemi.onewire.OneWireException, StatusException
com.dalsemi.onewire.OneWireException
- if a 1-Wire communication error occurs.StatusException
- if the operation does not end with serial
data output status high.private void calibrate() throws com.dalsemi.onewire.OneWireException, StatusException
w1 = readCalibration(CMD_CALIBRATE1); w2 = readCalibration(CMD_CALIBRATE2); w3 = readCalibration(CMD_CALIBRATE3); w4 = readCalibration(CMD_CALIBRATE4); c1 = (w1 >> 1) & 0x00007fff; c2 = ((w3 << 6) & 0x00000fc0) | (w4 & 0x0000003f); c3 = (w4 >> 6) & 0x000003ff; c4 = (w3 >> 6) & 0x000003ff; c5 = ((w1 << 11) & 0x00000400) | ((w2 >> 6) & 0x000003ff); c6 = w2 & 0x00000003f; ut = 8 * c5 + 20224;where
com.dalsemi.onewire.OneWireException
- if a 1-Wire communication error occurs.StatusException
- if the operation does not end with serial
data output status high.private double getPressure() throws com.dalsemi.onewire.OneWireException, StatusException, ValueException
d1 = doADConvert(CMD_PRESSURE); d2 = doADConvert(CMD_TEMPERATURE); dt = d2 - ut; t1 = 200 + dt * (c6 + 50) / 1024; off = c2 * 4 + ((c4 - 512) * dt) / 4096; sens = c1 + (c3 * dt) / 1024 + 24576; x = (sens * (d1 - 7168)) / 16384 - off; p1 = x / 32 + 250; t2 = (t1 <200) ? (11 * (c6 + 24) * (200 - t1) * (200 - t1) / 1048576) : 0; p2 = (t1 <200) ? (3 * t2 * (p1 - 3500) / 16384) : 0; temp = (t1 - t2) / 10; pres = (p1 - p2);where
com.dalsemi.onewire.OneWireException
- if a 1-Wire communication error occurs.StatusException
- if the operation does not end with serial
data output status high.ValueException
- if the value is out of range, forcing a
recalibration.private double getTemperature()
private int readCalibration(boolean[] command) throws com.dalsemi.onewire.OneWireException, StatusException
command
- one of the command calibrate constants.com.dalsemi.onewire.OneWireException
- if a 1-Wire communication error occurs.StatusException
- if the operation does not end with serial
data output status high.private int doADConvert(boolean[] command) throws com.dalsemi.onewire.OneWireException, StatusException
command
- one of the command convert constants.com.dalsemi.onewire.OneWireException
- if a 1-Wire communication error occurs.StatusException
- if the operation does not end with serial
data output status high.private void waitForADConvertComplete(long timeout) throws com.dalsemi.onewire.OneWireException, StatusException
timeout
- for command to complete. Polls the device once more
after the timeout expires in case the conversion completed during the
time check.com.dalsemi.onewire.OneWireException
- if a 1-Wire communication error occurs.StatusException
- if polling times out without serial data
output status going low.private void writeCommand(boolean[] command) throws com.dalsemi.onewire.OneWireException, StatusException
command
- data bit sequence to write.com.dalsemi.onewire.OneWireException
- if a 1-Wire communication error occursStatusException
- if the operation does not end with serial
data output status high.private int readWord() throws com.dalsemi.onewire.OneWireException, StatusException
com.dalsemi.onewire.OneWireException
- if a 1-Wire communication error occurs.StatusException
- if the operation does not end with serial
data output status high.private void writeMS5534A(boolean data) throws com.dalsemi.onewire.OneWireException
data
- bit to write.com.dalsemi.onewire.OneWireException
- if a 1-Wire communication error occurs.private boolean readMS5534A() throws com.dalsemi.onewire.OneWireException
com.dalsemi.onewire.OneWireException
- if a 1-Wire communication error occurs.private boolean pollMS5534A() throws com.dalsemi.onewire.OneWireException
com.dalsemi.onewire.OneWireException
- if a 1-Wire communication error occurs.private double toSeaLevel(double pressure) throws ValueException
pressure
- local value to correct to sea level.ValueException
- if the corrected value is not within 800 to
1100 millibars, forcing a recalibration.
Based on
Atmospheric pressure From Wikipedia, the free encyclopedia:
The highest recorded atmospheric pressure, 108.6 kPa (1086 mbar or 32.06 inches of mercury), occurred at Tosontsengel, Mongolia, 19 December 2001.
The lowest recorded non-tornadic atmospheric pressure, 87.0 kPa (870 mbar or 25.69 inHg), occurred in the Western Pacific during Typhoon Tip on 12 October 1979. The record for the Atlantic ocean was 88.2 kPa (882 mbar or 26.04 inHg) during Hurricane Wilma on 19 October 2005.