1-Wire Weather Service for Java -- Server API

wxservice.sensor.task
Class WSI603A.ReadTask

java.lang.Object
  extended by java.util.TimerTask
      extended by wxservice.sensor.task.WSI603A.ReadTask
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
WSI603A.AnemometerTask, WSI603A.SolarTask, WSI603A.StatusTask, WSI603A.TemperatureTask, WSI603A.WindvaneTask
Enclosing class:
WSI603A

private abstract class WSI603A.ReadTask
extends java.util.TimerTask

Base class for WSI603A read tasks.


Field Summary
protected  int CHECKSUM_INDEX
          Response buffer checksum index.
protected  int COMMAND_ADDRESS
          Command buffer address.
protected  int COMMAND_INDEX
          Response buffer command index.
protected  int LIGHT_INTENSITY_INDEX
          Response buffer light intensity index.
protected  int LIGHT_STATUS_INDEX
          Response buffer light status index.
private  boolean m_initialize
          Flag to initialize sensor.
protected  java.lang.String m_taskName
          Task name.
protected  int RESPONSE_ADDRESS
          Response buffer address.
protected  int RESPONSE_LENGTH
          Response buffer length.
protected  java.lang.String TIMEOUT_ERROR
          Message format for timeout errors.
protected  java.lang.String VALIDATION_ERROR
          Message format for validation errors.
protected  int VOLTAGE_INDEX
          Response buffer voltage index.
protected  int WIND_DIRECTION_INDEX
          Response buffer wind direction index.
protected  int WIND_SPEED_INDEX
          Response buffer wind speed index.
 
Constructor Summary
WSI603A.ReadTask(java.lang.String taskName)
          Constructs a new instance of Read Task.
 
Method Summary
protected  void checksum(byte[] data, int length, byte checksum)
          Performs a checksum on received data.
protected  void executeCommand(byte[] command)
          Executes a command and spins in a loop waiting for it to complete.
protected abstract  java.lang.Number getData()
          Gets implementation specific data from the sensor task.
protected  void initContainer()
          Initializes the container instance.
protected  void initDevice()
          Initializes the sensor for operation.
protected  byte[] readResponseBuffer()
          Reads the response buffer, performs checksum for validation.
 void run()
          Timer task process.
protected  void writeCommand(byte[] command)
          Writes a command to the device and reads it back for validation.
 
Methods inherited from class java.util.TimerTask
cancel, scheduledExecutionTime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VALIDATION_ERROR

protected final java.lang.String VALIDATION_ERROR
Message format for validation errors.


TIMEOUT_ERROR

protected final java.lang.String TIMEOUT_ERROR
Message format for timeout errors.


COMMAND_ADDRESS

protected final int COMMAND_ADDRESS
Command buffer address.

See Also:
Constant Field Values

RESPONSE_ADDRESS

protected final int RESPONSE_ADDRESS
Response buffer address.

See Also:
Constant Field Values

RESPONSE_LENGTH

protected final int RESPONSE_LENGTH
Response buffer length.

See Also:
Constant Field Values

COMMAND_INDEX

protected final int COMMAND_INDEX
Response buffer command index.

See Also:
Constant Field Values

WIND_SPEED_INDEX

protected final int WIND_SPEED_INDEX
Response buffer wind speed index.

See Also:
Constant Field Values

WIND_DIRECTION_INDEX

protected final int WIND_DIRECTION_INDEX
Response buffer wind direction index.

See Also:
Constant Field Values

LIGHT_STATUS_INDEX

protected final int LIGHT_STATUS_INDEX
Response buffer light status index.

See Also:
Constant Field Values

LIGHT_INTENSITY_INDEX

protected final int LIGHT_INTENSITY_INDEX
Response buffer light intensity index.

See Also:
Constant Field Values

VOLTAGE_INDEX

protected final int VOLTAGE_INDEX
Response buffer voltage index.

See Also:
Constant Field Values

CHECKSUM_INDEX

protected final int CHECKSUM_INDEX
Response buffer checksum index.

See Also:
Constant Field Values

m_taskName

protected java.lang.String m_taskName
Task name.


m_initialize

private boolean m_initialize
Flag to initialize sensor.

Constructor Detail

WSI603A.ReadTask

WSI603A.ReadTask(java.lang.String taskName)
Constructs a new instance of Read Task.

Parameters:
taskName - to identify this task when posting data.
Method Detail

run

public void run()
Timer task process. Gets the implementation specific read task data from the WSI603A and posts it to the data exchange.

Specified by:
run in interface java.lang.Runnable
Specified by:
run in class java.util.TimerTask

initDevice

protected void initDevice()
                   throws com.dalsemi.onewire.OneWireException,
                          ServiceException
Initializes the sensor for operation.

Throws:
com.dalsemi.onewire.OneWireException - if 1-Wire communication fails.
ServiceException - if initialization fails.

initContainer

protected void initContainer()
                      throws com.dalsemi.onewire.OneWireException,
                             ServiceException
Initializes the container instance.

Throws:
com.dalsemi.onewire.OneWireException - if 1-Wire communication fails.
ServiceException - if initialization fails.

executeCommand

protected void executeCommand(byte[] command)
                       throws com.dalsemi.onewire.OneWireException,
                              ServiceException
Executes a command and spins in a loop waiting for it to complete.

Parameters:
command - to execute.
Throws:
com.dalsemi.onewire.OneWireException - if 1-Wire communication fails.
ServiceException - if validation fails.

writeCommand

protected void writeCommand(byte[] command)
                     throws com.dalsemi.onewire.OneWireException,
                            ServiceException
Writes a command to the device and reads it back for validation.

Parameters:
command - the command to write.
Throws:
com.dalsemi.onewire.OneWireException - if 1-Wire communication fails.
ServiceException - if validation fails.

readResponseBuffer

protected byte[] readResponseBuffer()
                             throws com.dalsemi.onewire.OneWireException,
                                    ServiceException
Reads the response buffer, performs checksum for validation.

Returns:
the response buffer.
Throws:
com.dalsemi.onewire.OneWireException - if 1-Wire communication fails.
ServiceException - if validation fails.

checksum

protected void checksum(byte[] data,
                        int length,
                        byte checksum)
                 throws ServiceException
Performs a checksum on received data.

Parameters:
data - to check, including the checksum.
length - of the data
checksum - value the data sum should equal.
Throws:
ServiceException - if validation fails.

getData

protected abstract java.lang.Number getData()
                                     throws com.dalsemi.onewire.OneWireException,
                                            ServiceException
Gets implementation specific data from the sensor task. Individual tasks override this to get the appropriate data.

Returns:
the requested data.
Throws:
com.dalsemi.onewire.OneWireException - if 1-Wire communication fails.
ServiceException - if validation fails.

Copyright © 2005-2009 Karl Uppiano