org.openuat.sensors
Class WiTiltRawReader

java.lang.Object
  extended by org.openuat.sensors.SamplesSource
      extended by org.openuat.sensors.AsciiLineReaderBase
          extended by org.openuat.sensors.WiTiltRawReader

public class WiTiltRawReader
extends AsciiLineReaderBase

This class implements a reader for the "RAW" data format generated by Spark Fun Electronics WiTilt v2.5 sensors. It is a simple ASCII-based format in the form: X=526 Y=473 Z=741 X=522 Y=481 Z=753 X=514 Y=480 Z=747 X=518 Y=474 Z=748 X=521 Y=481 Z=745 This class depends on the devices being pre-configured appropriately, e.g. to sample all 3 axises and with the correct sampling rate. They also need to be configured to generate their "RAW" data stream. There are two ways to connect to a WiTilt device: - With a (virtual) serial port. This can be used then the WiTilt device is connected to a physical serial port via its Debug port or with the operating system RFCOMM emulation, e.g. the /dev/rfommX devices unter Linux or COMX devices under Windows. To use this method, use the method

Version:
1.0
Author:
Rene Mayrhofer
See Also:
- Directly from Java with a JSR82 implementation. To use this method, use the method @see #openBluetooth(String, boolean). Additionally, this class can be used either with the original firmware, which displays the menu of the WiTilt device when connecting to it, or with a modified firmware that goes directly into sampling mode after connecting. This can be controlled by the boolean parameters given to the open methods.

Field Summary
static int VALUE_RANGE
           
 
Fields inherited from class org.openuat.sensors.AsciiLineReaderBase
port, reader, reopenStreamFrom
 
Fields inherited from class org.openuat.sensors.SamplesSource
maxNumLines
 
Constructor Summary
WiTiltRawReader()
          Initializes the WiTilt RAW reader object, but does not open a connection.
 
Method Summary
 void dispose()
          This closes the serial port or Bluetooth channel properly.
 TimeSeries_Int.Parameters getParameters_Int()
          Instead of to [-1;1], these integer parameters map to [-1024;1024], i.e.
 TimeSeries.Parameters getParameters()
          Provides appropriate parameters for interpreting the values to normalize to the [-1;1] range.
static void main(java.lang.String[] args)
           
 void openBluetooth(java.lang.String deviceAddress, boolean usingMenu)
          Opens a connection to the WiTilt device via an RFCOMM channel with JSR82.
 void openSerial(java.lang.String serialPortName, boolean usingMenu)
          Opens a connection to the WiTilt device via a (virtual) serial port.
protected  void parseLine(java.lang.String line)
          A helper function to parse single line of the format produced by parport-pulsewidth.
 
Methods inherited from class org.openuat.sensors.AsciiLineReaderBase
handleSample
 
Methods inherited from class org.openuat.sensors.SamplesSource
addSink, addSink, emitSample, emitSample, getMaxNumLines, removeSink_Int, removeSink, simulateSampling, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VALUE_RANGE

public static final int VALUE_RANGE
See Also:
Constant Field Values
Constructor Detail

WiTiltRawReader

public WiTiltRawReader()
Initializes the WiTilt RAW reader object, but does not open a connection.

See Also:
openSerial(String, boolean), openBluetooth(String, boolean)
Method Detail

openSerial

public void openSerial(java.lang.String serialPortName,
                       boolean usingMenu)
                throws java.io.IOException
Opens a connection to the WiTilt device via a (virtual) serial port. It only saves the passed parameters and opens the InputStream to read from the specified file, and thus implicitly to check if the file exists and can be opened.

Parameters:
serialPortName - The serial port to read from. It will be opened and initialized with the correct parameters.
usingMenu - Set to true when the Witilt device runs the original firmware and we need to interact with its menu during initialization. Set to false when using the modified firmware that goes directly into sampling mode.
Throws:
InternalApplicationException
java.io.FileNotFoundException - When filename does not exist or can not be opened.
java.io.IOException

openBluetooth

public void openBluetooth(java.lang.String deviceAddress,
                          boolean usingMenu)
                   throws java.io.IOException
Opens a connection to the WiTilt device via an RFCOMM channel with JSR82. It saves the passed parameters, tries to connect to the RFCOMM channel, and opens the InputStream to read from the specified port.

Parameters:
deviceAddress - The Bluetooth MAC address of the WiTilt sensor to connect to, in the format "AABBCCDDEEFF";
usingMenu - Set to true when the Witilt device runs the original firmware and we need to interact with its menu during initialization. Set to false when using the modified firmware that goes directly into sampling mode.
Throws:
java.io.IOException

dispose

public void dispose()
This closes the serial port or Bluetooth channel properly. It should not be called manually!

Overrides:
dispose in class AsciiLineReaderBase

parseLine

protected void parseLine(java.lang.String line)
A helper function to parse single line of the format produced by parport-pulsewidth. This method creates the samples and emits events.

Specified by:
parseLine in class AsciiLineReaderBase
Parameters:
line - The line to parse.

getParameters

public TimeSeries.Parameters getParameters()
Provides appropriate parameters for interpreting the values to normalize to the [-1;1] range.

Specified by:
getParameters in class SamplesSource

getParameters_Int

public TimeSeries_Int.Parameters getParameters_Int()
Instead of to [-1;1], these integer parameters map to [-1024;1024], i.e. MAXIMUM_RANGE in TimeSeries_Int.

Specified by:
getParameters_Int in class SamplesSource

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Throws:
java.io.IOException


2005-2006, Rene Mayrhofer.