neurosky/header/ThinkGearStreamParser.h File Reference

#include <stdlib.h>

Go to the source code of this file.

Classes

struct  _ThinkGearStreamParser

Defines

#define PARSER_TYPE_NULL   0x00
#define PARSER_TYPE_PACKETS   0x01
#define PARSER_TYPE_2BYTERAW   0x02
#define PARSER_CODE_BATTERY   0x01
#define PARSER_CODE_POOR_QUALITY   0x02
#define PARSER_CODE_ATTENTION   0x04
#define PARSER_CODE_MEDITATION   0x05
#define PARSER_CODE_8BITRAW_SIGNAL   0x06
#define PARSER_CODE_RAW_MARKER   0x07
#define PARSER_CODE_RAW_SIGNAL   0x80
#define PARSER_CODE_EEG_POWERS   0x81
#define PARSER_CODE_ASIC_EEG_POWER_INT   0x83

Typedefs

typedef struct
_ThinkGearStreamParser 
ThinkGearStreamParser

Functions

int THINKGEAR_initParser (ThinkGearStreamParser *parser, unsigned char parserType, void(*handleDataValueFunc)(unsigned char extendedCodeLevel, unsigned char code, unsigned char numBytes, const unsigned char *value, void *customData), void *customData)
void exampleHandleDataValueFunc (unsigned char extendedCodeLevel, unsigned char code, unsigned char numBytes, const unsigned char *value, void *customData)
int THINKGEAR_parseByte (ThinkGearStreamParser *parser, unsigned char byte)

Detailed Description

The ThinkGear Stream Parser is used to parse bytes of ThinkGear data streamed from any source. Each arriving byte is fed into the Parser using the THINKGEAR_parseByte() function, and a user supplied callback function is called whenever DataRows are decoded from complete ThinkGear Packets. Each Parser can be initialized to recognize either: streams of ThinkGear Packets, or streams of 2-byte raw values (the old 5V ThinkGear stream format).

Author:
Kelvin Soo
Version:
2.0 Mar 04, 2008 Kelvin Soo
  • Renamed to ThinkGearStreamParser from ThinkGearStreamDecoder.
  • Revised to call a callback function instead of stuffing arriving data values into a ThinkGearData object.
  • Renamed symbols according to updated Packet vocabulary.
1.0 Nov 27, 2007 Kelvin Soo
  • Initial version (ThinkGearStreamDecoder).

Definition in file ThinkGearStreamParser.h.


Define Documentation

#define PARSER_CODE_8BITRAW_SIGNAL   0x06

Definition at line 51 of file ThinkGearStreamParser.h.

#define PARSER_CODE_ASIC_EEG_POWER_INT   0x83

Definition at line 56 of file ThinkGearStreamParser.h.

#define PARSER_CODE_ATTENTION   0x04

Definition at line 49 of file ThinkGearStreamParser.h.

#define PARSER_CODE_BATTERY   0x01

Definition at line 47 of file ThinkGearStreamParser.h.

#define PARSER_CODE_EEG_POWERS   0x81

Definition at line 55 of file ThinkGearStreamParser.h.

#define PARSER_CODE_MEDITATION   0x05

Definition at line 50 of file ThinkGearStreamParser.h.

#define PARSER_CODE_POOR_QUALITY   0x02

Definition at line 48 of file ThinkGearStreamParser.h.

#define PARSER_CODE_RAW_MARKER   0x07

Definition at line 52 of file ThinkGearStreamParser.h.

#define PARSER_CODE_RAW_SIGNAL   0x80

Definition at line 54 of file ThinkGearStreamParser.h.

#define PARSER_TYPE_2BYTERAW   0x02

Definition at line 44 of file ThinkGearStreamParser.h.

#define PARSER_TYPE_NULL   0x00

Definition at line 42 of file ThinkGearStreamParser.h.

#define PARSER_TYPE_PACKETS   0x01

Definition at line 43 of file ThinkGearStreamParser.h.


Typedef Documentation

The Parser is a state machine that manages the parsing state.


Function Documentation

void exampleHandleDataValueFunc ( unsigned char  extendedCodeLevel,
unsigned char  code,
unsigned char  numBytes,
const unsigned char *  value,
void *  customData 
)

This is merely an example function prototype for a handleDataValueFunc() callback function to be passed to THINKGEAR_initParser(). The user is expected to actually define a function with this function signature, and pass its name into the THINKGEAR_initParser() to create a ThinkGearStreamParser. Then, each time a Data Value is successfully parsed by THINKGEAR_parseByte(), this function gets automatically called, so that the user's application can do whatever it likes with the value.

The extendedCodeLevel and code together tells the application what type of Data Value was received. The numBytes indicates the number of bytes in the value[] array.

The customData is a pointer to whatever user-defined data was originally passed to THINKGEAR_initParser().

int THINKGEAR_initParser ( ThinkGearStreamParser parser,
unsigned char  parserType,
void(*)(unsigned char extendedCodeLevel, unsigned char code, unsigned char numBytes, const unsigned char *value, void *customData)  handleDataValueFunc,
void *  customData 
)
Parameters:
parser Pointer to a ThinkGearStreamParser object.
parserType One of the PARSER_TYPE_* constants defined above: PARSER_TYPE_PACKETS or PARSER_TYPE_2BYTERAW.
handleDataValueFunc A user-defined callback function that will be called whenever a data value is parsed from a Packet.
customData A pointer to any arbitrary data that will also be passed to the handleDataValueFunc whenever a data value is parsed from a Packet.
Returns:
-1 if parser is NULL.
-2 if parserType is invalid.
0 on success.

Definition at line 54 of file ThinkGearStreamParser.c.

int THINKGEAR_parseByte ( ThinkGearStreamParser parser,
unsigned char  byte 
)

Feeds the byte into the parser. If the byte completes a complete, valid parser, then the parser's handleDataValue() function is automatically called on each DataRow in the Packet. The return value provides an indication of the state of the parser after parsing the byte.

Parameters:
parser Pointer to an initialized ThinkGearDataParser object.
byte The next byte of the data stream.
Returns:
-1 if parser is NULL.
-2 if a complete Packet was received, but the checksum failed.
-3 if an invalid Packet with PLENGTH > 170 was detected.
-4 if an invalid Packet with PLENGTH == 170 was detected.
-5 if the parser is somehow in an unrecognized state.
0 if the byte did not yet complete a Packet.
1 if a Packet was received and parsed successfully.

Definition at line 89 of file ThinkGearStreamParser.c.

 All Classes Namespaces Files Functions Variables Typedefs Defines
Generated on Sat May 15 15:11:27 2010 for NeuroSky by  doxygen 1.6.3