#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) |
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).
Definition in file ThinkGearStreamParser.h.
| #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 struct _ThinkGearStreamParser ThinkGearStreamParser |
The Parser is a state machine that manages the parsing state.
| 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 | |||
| ) |
| 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. |
parser is NULL. parserType is invalid. 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.
| parser | Pointer to an initialized ThinkGearDataParser object. | |
| byte | The next byte of the data stream. |
parser is NULL. parser is somehow in an unrecognized state. byte did not yet complete a Packet. Definition at line 89 of file ThinkGearStreamParser.c.
1.6.3