com.NeuroSky.ThinkGear.Util
Class StreamParser

java.lang.Object
  extended by com.NeuroSky.ThinkGear.Util.StreamParser

public class StreamParser
extends java.lang.Object


Field Summary
static int PARSER_CODE_8BIT_RAW
           
static int PARSER_CODE_ATTENTION
           
static int PARSER_CODE_BATTERY
           
static int PARSER_CODE_EEG_POWERS
           
static int PARSER_CODE_MEDITATION
           
static int PARSER_CODE_POOR_SIGNAL
           
static int PARSER_CODE_RAW
           
static int PARSER_CODE_RAW_MARKER
           
static int PARSER_TYPE_2BYTERAW
           
static int PARSER_TYPE_PACKETS
           
 
Constructor Summary
StreamParser(int parserType, DataListener listener, java.lang.Object listenerData)
          Constructs a ThinkGear parser object of the given @c parserType, and registers the given @c listener.
 
Method Summary
static float bigEndianBytesToFloat(byte[] bytes)
          Assuming the @c bytes array contains the 4 bytes of an IEEE 754 floating point number in network byte order (big-endian), this function returns the corresponding Java floating point number.
 int parseByte(int b)
          Parses the byte @b as part of a ThinkGear data stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PARSER_TYPE_PACKETS

public static final int PARSER_TYPE_PACKETS
See Also:
Constant Field Values

PARSER_TYPE_2BYTERAW

public static final int PARSER_TYPE_2BYTERAW
See Also:
Constant Field Values

PARSER_CODE_BATTERY

public static final int PARSER_CODE_BATTERY
See Also:
Constant Field Values

PARSER_CODE_POOR_SIGNAL

public static final int PARSER_CODE_POOR_SIGNAL
See Also:
Constant Field Values

PARSER_CODE_ATTENTION

public static final int PARSER_CODE_ATTENTION
See Also:
Constant Field Values

PARSER_CODE_MEDITATION

public static final int PARSER_CODE_MEDITATION
See Also:
Constant Field Values

PARSER_CODE_8BIT_RAW

public static final int PARSER_CODE_8BIT_RAW
See Also:
Constant Field Values

PARSER_CODE_RAW_MARKER

public static final int PARSER_CODE_RAW_MARKER
See Also:
Constant Field Values

PARSER_CODE_RAW

public static final int PARSER_CODE_RAW
See Also:
Constant Field Values

PARSER_CODE_EEG_POWERS

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

StreamParser

public StreamParser(int parserType,
                    DataListener listener,
                    java.lang.Object listenerData)
Constructs a ThinkGear parser object of the given @c parserType, and registers the given @c listener.

Parameters:
parserType - One of the PARSER_TYPE_* constants, either: PARSER_TYPE_PACKETS (ThinkGear-EM) PARSER_TYPE_2BYTERAW (legacy 5V support only)
listener - An object that implements the ThinkGearListener interface, which implements the dataValueReceived() event handler (callback method).
listenerData - Any arbitrary object that should be passed to the dataValueReceived() method as well. This parameter is ot really necessary in Java, but is included here for consistency with the C implementation of this StreamParser class.
Method Detail

parseByte

public int parseByte(int b)
Parses the byte @b as part of a ThinkGear data stream.

Parameters:
b - The byte from the ThinkGear data stream to parse.
Returns:
-2 if a complete Packet was received, but the checksum failed.

bigEndianBytesToFloat

public static float bigEndianBytesToFloat(byte[] bytes)
Assuming the @c bytes array contains the 4 bytes of an IEEE 754 floating point number in network byte order (big-endian), this function returns the corresponding Java floating point number.

Parameters:
bytes - An array of 4 bytes corresponding to the 4 bytes of an IEEE 754 floating point number in network byte order (big-endian).
Returns:
The Java floating point number corresponding to the IEEE 754 floating poing number in @c bytes.