\hypertarget{_think_gear_stream_parser_8h}{
\section{neurosky/header/ThinkGearStreamParser.h File Reference}
\label{_think_gear_stream_parser_8h}\index{neurosky/header/ThinkGearStreamParser.h@{neurosky/header/ThinkGearStreamParser.h}}
}
{\ttfamily \#include $<$stdlib.h$>$}\par
\subsection*{Classes}
\begin{DoxyCompactItemize}
\item 
struct \hyperlink{struct___think_gear_stream_parser}{\_\-ThinkGearStreamParser}
\end{DoxyCompactItemize}
\subsection*{Defines}
\begin{DoxyCompactItemize}
\item 
\#define \hyperlink{_think_gear_stream_parser_8h_a994c9bb3cd88e8d56fc94495e87eab73}{PARSER\_\-TYPE\_\-NULL}~0x00
\item 
\#define \hyperlink{_think_gear_stream_parser_8h_ad2b630c6b421f3fc304d4e64b8584b31}{PARSER\_\-TYPE\_\-PACKETS}~0x01
\item 
\#define \hyperlink{_think_gear_stream_parser_8h_af9cc1f3ea6b735d19fb775d287ea896c}{PARSER\_\-TYPE\_\-2BYTERAW}~0x02
\item 
\#define \hyperlink{_think_gear_stream_parser_8h_aec5486eed5903c8bf3735c1866b62e3f}{PARSER\_\-CODE\_\-BATTERY}~0x01
\item 
\#define \hyperlink{_think_gear_stream_parser_8h_a7f4348c55721cedd3833dba89ac3c2a8}{PARSER\_\-CODE\_\-POOR\_\-QUALITY}~0x02
\item 
\#define \hyperlink{_think_gear_stream_parser_8h_ace45448b4a59d457080a099e5d571b48}{PARSER\_\-CODE\_\-ATTENTION}~0x04
\item 
\#define \hyperlink{_think_gear_stream_parser_8h_a4a925017a28f08ee827d2c9ce945bc78}{PARSER\_\-CODE\_\-MEDITATION}~0x05
\item 
\#define \hyperlink{_think_gear_stream_parser_8h_a5f6601437b699d6eac2437d72f28dfd4}{PARSER\_\-CODE\_\-8BITRAW\_\-SIGNAL}~0x06
\item 
\#define \hyperlink{_think_gear_stream_parser_8h_a74e0f4f6023a20fb72860cd203097d59}{PARSER\_\-CODE\_\-RAW\_\-MARKER}~0x07
\item 
\#define \hyperlink{_think_gear_stream_parser_8h_a07c5a3258d7841a7364d2af4fa5d7f55}{PARSER\_\-CODE\_\-RAW\_\-SIGNAL}~0x80
\item 
\#define \hyperlink{_think_gear_stream_parser_8h_a7822f9ff898243bd6f77b5c4dc5fe84e}{PARSER\_\-CODE\_\-EEG\_\-POWERS}~0x81
\item 
\#define \hyperlink{_think_gear_stream_parser_8h_a0a0af370292a9cae01fa27c40a1b70d9}{PARSER\_\-CODE\_\-ASIC\_\-EEG\_\-POWER\_\-INT}~0x83
\end{DoxyCompactItemize}
\subsection*{Typedefs}
\begin{DoxyCompactItemize}
\item 
typedef struct \hyperlink{struct___think_gear_stream_parser}{\_\-ThinkGearStreamParser} \hyperlink{_think_gear_stream_parser_8h_abba187a64c3d078e0d96c084fb802c3e}{ThinkGearStreamParser}
\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
int \hyperlink{_think_gear_stream_parser_8h_a61ff029364ee47988e7c8884d93ec6b9}{THINKGEAR\_\-initParser} (\hyperlink{struct___think_gear_stream_parser}{ThinkGearStreamParser} $\ast$parser, unsigned char parserType, void($\ast$handleDataValueFunc)(unsigned char extendedCodeLevel, unsigned char code, unsigned char numBytes, const unsigned char $\ast$value, void $\ast$customData), void $\ast$customData)
\item 
void \hyperlink{_think_gear_stream_parser_8h_accf9a9364f98ac77596dd1fa32cc6500}{exampleHandleDataValueFunc} (unsigned char extendedCodeLevel, unsigned char code, unsigned char numBytes, const unsigned char $\ast$value, void $\ast$customData)
\item 
int \hyperlink{_think_gear_stream_parser_8h_ac13a82467d15adfca688fccbd65dd699}{THINKGEAR\_\-parseByte} (\hyperlink{struct___think_gear_stream_parser}{ThinkGearStreamParser} $\ast$parser, unsigned char byte)
\end{DoxyCompactItemize}


\subsection{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 \hyperlink{_think_gear_stream_parser_8h_ac13a82467d15adfca688fccbd65dd699}{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).

\begin{DoxyAuthor}{Author}
Kelvin Soo 
\end{DoxyAuthor}
\begin{DoxyVersion}{Version}
2.0 Mar 04, 2008 Kelvin Soo
\begin{DoxyItemize}
\item Renamed to ThinkGearStreamParser from ThinkGearStreamDecoder.
\item Revised to call a callback function instead of stuffing arriving data values into a ThinkGearData object.
\item Renamed symbols according to updated Packet vocabulary. 
\end{DoxyItemize}

1.0 Nov 27, 2007 Kelvin Soo
\begin{DoxyItemize}
\item Initial version (ThinkGearStreamDecoder). 
\end{DoxyItemize}
\end{DoxyVersion}


Definition in file \hyperlink{_think_gear_stream_parser_8h_source}{ThinkGearStreamParser.h}.



\subsection{Define Documentation}
\hypertarget{_think_gear_stream_parser_8h_a5f6601437b699d6eac2437d72f28dfd4}{
\index{ThinkGearStreamParser.h@{ThinkGearStreamParser.h}!PARSER\_\-CODE\_\-8BITRAW\_\-SIGNAL@{PARSER\_\-CODE\_\-8BITRAW\_\-SIGNAL}}
\index{PARSER\_\-CODE\_\-8BITRAW\_\-SIGNAL@{PARSER\_\-CODE\_\-8BITRAW\_\-SIGNAL}!ThinkGearStreamParser.h@{ThinkGearStreamParser.h}}
\subsubsection[{PARSER\_\-CODE\_\-8BITRAW\_\-SIGNAL}]{\setlength{\rightskip}{0pt plus 5cm}\#define PARSER\_\-CODE\_\-8BITRAW\_\-SIGNAL~0x06}}
\label{_think_gear_stream_parser_8h_a5f6601437b699d6eac2437d72f28dfd4}


Definition at line 51 of file ThinkGearStreamParser.h.

\hypertarget{_think_gear_stream_parser_8h_a0a0af370292a9cae01fa27c40a1b70d9}{
\index{ThinkGearStreamParser.h@{ThinkGearStreamParser.h}!PARSER\_\-CODE\_\-ASIC\_\-EEG\_\-POWER\_\-INT@{PARSER\_\-CODE\_\-ASIC\_\-EEG\_\-POWER\_\-INT}}
\index{PARSER\_\-CODE\_\-ASIC\_\-EEG\_\-POWER\_\-INT@{PARSER\_\-CODE\_\-ASIC\_\-EEG\_\-POWER\_\-INT}!ThinkGearStreamParser.h@{ThinkGearStreamParser.h}}
\subsubsection[{PARSER\_\-CODE\_\-ASIC\_\-EEG\_\-POWER\_\-INT}]{\setlength{\rightskip}{0pt plus 5cm}\#define PARSER\_\-CODE\_\-ASIC\_\-EEG\_\-POWER\_\-INT~0x83}}
\label{_think_gear_stream_parser_8h_a0a0af370292a9cae01fa27c40a1b70d9}


Definition at line 56 of file ThinkGearStreamParser.h.

\hypertarget{_think_gear_stream_parser_8h_ace45448b4a59d457080a099e5d571b48}{
\index{ThinkGearStreamParser.h@{ThinkGearStreamParser.h}!PARSER\_\-CODE\_\-ATTENTION@{PARSER\_\-CODE\_\-ATTENTION}}
\index{PARSER\_\-CODE\_\-ATTENTION@{PARSER\_\-CODE\_\-ATTENTION}!ThinkGearStreamParser.h@{ThinkGearStreamParser.h}}
\subsubsection[{PARSER\_\-CODE\_\-ATTENTION}]{\setlength{\rightskip}{0pt plus 5cm}\#define PARSER\_\-CODE\_\-ATTENTION~0x04}}
\label{_think_gear_stream_parser_8h_ace45448b4a59d457080a099e5d571b48}


Definition at line 49 of file ThinkGearStreamParser.h.

\hypertarget{_think_gear_stream_parser_8h_aec5486eed5903c8bf3735c1866b62e3f}{
\index{ThinkGearStreamParser.h@{ThinkGearStreamParser.h}!PARSER\_\-CODE\_\-BATTERY@{PARSER\_\-CODE\_\-BATTERY}}
\index{PARSER\_\-CODE\_\-BATTERY@{PARSER\_\-CODE\_\-BATTERY}!ThinkGearStreamParser.h@{ThinkGearStreamParser.h}}
\subsubsection[{PARSER\_\-CODE\_\-BATTERY}]{\setlength{\rightskip}{0pt plus 5cm}\#define PARSER\_\-CODE\_\-BATTERY~0x01}}
\label{_think_gear_stream_parser_8h_aec5486eed5903c8bf3735c1866b62e3f}


Definition at line 47 of file ThinkGearStreamParser.h.

\hypertarget{_think_gear_stream_parser_8h_a7822f9ff898243bd6f77b5c4dc5fe84e}{
\index{ThinkGearStreamParser.h@{ThinkGearStreamParser.h}!PARSER\_\-CODE\_\-EEG\_\-POWERS@{PARSER\_\-CODE\_\-EEG\_\-POWERS}}
\index{PARSER\_\-CODE\_\-EEG\_\-POWERS@{PARSER\_\-CODE\_\-EEG\_\-POWERS}!ThinkGearStreamParser.h@{ThinkGearStreamParser.h}}
\subsubsection[{PARSER\_\-CODE\_\-EEG\_\-POWERS}]{\setlength{\rightskip}{0pt plus 5cm}\#define PARSER\_\-CODE\_\-EEG\_\-POWERS~0x81}}
\label{_think_gear_stream_parser_8h_a7822f9ff898243bd6f77b5c4dc5fe84e}


Definition at line 55 of file ThinkGearStreamParser.h.

\hypertarget{_think_gear_stream_parser_8h_a4a925017a28f08ee827d2c9ce945bc78}{
\index{ThinkGearStreamParser.h@{ThinkGearStreamParser.h}!PARSER\_\-CODE\_\-MEDITATION@{PARSER\_\-CODE\_\-MEDITATION}}
\index{PARSER\_\-CODE\_\-MEDITATION@{PARSER\_\-CODE\_\-MEDITATION}!ThinkGearStreamParser.h@{ThinkGearStreamParser.h}}
\subsubsection[{PARSER\_\-CODE\_\-MEDITATION}]{\setlength{\rightskip}{0pt plus 5cm}\#define PARSER\_\-CODE\_\-MEDITATION~0x05}}
\label{_think_gear_stream_parser_8h_a4a925017a28f08ee827d2c9ce945bc78}


Definition at line 50 of file ThinkGearStreamParser.h.

\hypertarget{_think_gear_stream_parser_8h_a7f4348c55721cedd3833dba89ac3c2a8}{
\index{ThinkGearStreamParser.h@{ThinkGearStreamParser.h}!PARSER\_\-CODE\_\-POOR\_\-QUALITY@{PARSER\_\-CODE\_\-POOR\_\-QUALITY}}
\index{PARSER\_\-CODE\_\-POOR\_\-QUALITY@{PARSER\_\-CODE\_\-POOR\_\-QUALITY}!ThinkGearStreamParser.h@{ThinkGearStreamParser.h}}
\subsubsection[{PARSER\_\-CODE\_\-POOR\_\-QUALITY}]{\setlength{\rightskip}{0pt plus 5cm}\#define PARSER\_\-CODE\_\-POOR\_\-QUALITY~0x02}}
\label{_think_gear_stream_parser_8h_a7f4348c55721cedd3833dba89ac3c2a8}


Definition at line 48 of file ThinkGearStreamParser.h.

\hypertarget{_think_gear_stream_parser_8h_a74e0f4f6023a20fb72860cd203097d59}{
\index{ThinkGearStreamParser.h@{ThinkGearStreamParser.h}!PARSER\_\-CODE\_\-RAW\_\-MARKER@{PARSER\_\-CODE\_\-RAW\_\-MARKER}}
\index{PARSER\_\-CODE\_\-RAW\_\-MARKER@{PARSER\_\-CODE\_\-RAW\_\-MARKER}!ThinkGearStreamParser.h@{ThinkGearStreamParser.h}}
\subsubsection[{PARSER\_\-CODE\_\-RAW\_\-MARKER}]{\setlength{\rightskip}{0pt plus 5cm}\#define PARSER\_\-CODE\_\-RAW\_\-MARKER~0x07}}
\label{_think_gear_stream_parser_8h_a74e0f4f6023a20fb72860cd203097d59}


Definition at line 52 of file ThinkGearStreamParser.h.

\hypertarget{_think_gear_stream_parser_8h_a07c5a3258d7841a7364d2af4fa5d7f55}{
\index{ThinkGearStreamParser.h@{ThinkGearStreamParser.h}!PARSER\_\-CODE\_\-RAW\_\-SIGNAL@{PARSER\_\-CODE\_\-RAW\_\-SIGNAL}}
\index{PARSER\_\-CODE\_\-RAW\_\-SIGNAL@{PARSER\_\-CODE\_\-RAW\_\-SIGNAL}!ThinkGearStreamParser.h@{ThinkGearStreamParser.h}}
\subsubsection[{PARSER\_\-CODE\_\-RAW\_\-SIGNAL}]{\setlength{\rightskip}{0pt plus 5cm}\#define PARSER\_\-CODE\_\-RAW\_\-SIGNAL~0x80}}
\label{_think_gear_stream_parser_8h_a07c5a3258d7841a7364d2af4fa5d7f55}


Definition at line 54 of file ThinkGearStreamParser.h.

\hypertarget{_think_gear_stream_parser_8h_af9cc1f3ea6b735d19fb775d287ea896c}{
\index{ThinkGearStreamParser.h@{ThinkGearStreamParser.h}!PARSER\_\-TYPE\_\-2BYTERAW@{PARSER\_\-TYPE\_\-2BYTERAW}}
\index{PARSER\_\-TYPE\_\-2BYTERAW@{PARSER\_\-TYPE\_\-2BYTERAW}!ThinkGearStreamParser.h@{ThinkGearStreamParser.h}}
\subsubsection[{PARSER\_\-TYPE\_\-2BYTERAW}]{\setlength{\rightskip}{0pt plus 5cm}\#define PARSER\_\-TYPE\_\-2BYTERAW~0x02}}
\label{_think_gear_stream_parser_8h_af9cc1f3ea6b735d19fb775d287ea896c}


Definition at line 44 of file ThinkGearStreamParser.h.

\hypertarget{_think_gear_stream_parser_8h_a994c9bb3cd88e8d56fc94495e87eab73}{
\index{ThinkGearStreamParser.h@{ThinkGearStreamParser.h}!PARSER\_\-TYPE\_\-NULL@{PARSER\_\-TYPE\_\-NULL}}
\index{PARSER\_\-TYPE\_\-NULL@{PARSER\_\-TYPE\_\-NULL}!ThinkGearStreamParser.h@{ThinkGearStreamParser.h}}
\subsubsection[{PARSER\_\-TYPE\_\-NULL}]{\setlength{\rightskip}{0pt plus 5cm}\#define PARSER\_\-TYPE\_\-NULL~0x00}}
\label{_think_gear_stream_parser_8h_a994c9bb3cd88e8d56fc94495e87eab73}


Definition at line 42 of file ThinkGearStreamParser.h.

\hypertarget{_think_gear_stream_parser_8h_ad2b630c6b421f3fc304d4e64b8584b31}{
\index{ThinkGearStreamParser.h@{ThinkGearStreamParser.h}!PARSER\_\-TYPE\_\-PACKETS@{PARSER\_\-TYPE\_\-PACKETS}}
\index{PARSER\_\-TYPE\_\-PACKETS@{PARSER\_\-TYPE\_\-PACKETS}!ThinkGearStreamParser.h@{ThinkGearStreamParser.h}}
\subsubsection[{PARSER\_\-TYPE\_\-PACKETS}]{\setlength{\rightskip}{0pt plus 5cm}\#define PARSER\_\-TYPE\_\-PACKETS~0x01}}
\label{_think_gear_stream_parser_8h_ad2b630c6b421f3fc304d4e64b8584b31}


Definition at line 43 of file ThinkGearStreamParser.h.



\subsection{Typedef Documentation}
\hypertarget{_think_gear_stream_parser_8h_abba187a64c3d078e0d96c084fb802c3e}{
\index{ThinkGearStreamParser.h@{ThinkGearStreamParser.h}!ThinkGearStreamParser@{ThinkGearStreamParser}}
\index{ThinkGearStreamParser@{ThinkGearStreamParser}!ThinkGearStreamParser.h@{ThinkGearStreamParser.h}}
\subsubsection[{ThinkGearStreamParser}]{\setlength{\rightskip}{0pt plus 5cm}typedef struct {\bf \_\-ThinkGearStreamParser}  {\bf ThinkGearStreamParser}}}
\label{_think_gear_stream_parser_8h_abba187a64c3d078e0d96c084fb802c3e}
The Parser is a state machine that manages the parsing state. 

\subsection{Function Documentation}
\hypertarget{_think_gear_stream_parser_8h_accf9a9364f98ac77596dd1fa32cc6500}{
\index{ThinkGearStreamParser.h@{ThinkGearStreamParser.h}!exampleHandleDataValueFunc@{exampleHandleDataValueFunc}}
\index{exampleHandleDataValueFunc@{exampleHandleDataValueFunc}!ThinkGearStreamParser.h@{ThinkGearStreamParser.h}}
\subsubsection[{exampleHandleDataValueFunc}]{\setlength{\rightskip}{0pt plus 5cm}void exampleHandleDataValueFunc (unsigned char {\em extendedCodeLevel}, \/  unsigned char {\em code}, \/  unsigned char {\em numBytes}, \/  const unsigned char $\ast$ {\em value}, \/  void $\ast$ {\em customData})}}
\label{_think_gear_stream_parser_8h_accf9a9364f98ac77596dd1fa32cc6500}
This is merely an example function prototype for a \hyperlink{scol_think_gear_8h_a282f1b088762b445ae3ea4948135117d}{handleDataValueFunc()} callback function to be passed to \hyperlink{_think_gear_stream_parser_8h_a61ff029364ee47988e7c8884d93ec6b9}{THINKGEAR\_\-initParser()}. The user is expected to actually define a function with this function signature, and pass its name into the \hyperlink{_think_gear_stream_parser_8h_a61ff029364ee47988e7c8884d93ec6b9}{THINKGEAR\_\-initParser()} to create a ThinkGearStreamParser. Then, each time a Data Value is successfully parsed by \hyperlink{_think_gear_stream_parser_8h_ac13a82467d15adfca688fccbd65dd699}{THINKGEAR\_\-parseByte()}, this function gets automatically called, so that the user's application can do whatever it likes with the {\ttfamily value}.

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

The {\ttfamily customData} is a pointer to whatever user-\/defined data was originally passed to \hyperlink{_think_gear_stream_parser_8h_a61ff029364ee47988e7c8884d93ec6b9}{THINKGEAR\_\-initParser()}. \hypertarget{_think_gear_stream_parser_8h_a61ff029364ee47988e7c8884d93ec6b9}{
\index{ThinkGearStreamParser.h@{ThinkGearStreamParser.h}!THINKGEAR\_\-initParser@{THINKGEAR\_\-initParser}}
\index{THINKGEAR\_\-initParser@{THINKGEAR\_\-initParser}!ThinkGearStreamParser.h@{ThinkGearStreamParser.h}}
\subsubsection[{THINKGEAR\_\-initParser}]{\setlength{\rightskip}{0pt plus 5cm}int THINKGEAR\_\-initParser ({\bf ThinkGearStreamParser} $\ast$ {\em parser}, \/  unsigned char {\em parserType}, \/  void($\ast$)(unsigned char extendedCodeLevel, unsigned char code, unsigned char numBytes, const unsigned char $\ast$value, void $\ast$customData) {\em handleDataValueFunc}, \/  void $\ast$ {\em customData})}}
\label{_think_gear_stream_parser_8h_a61ff029364ee47988e7c8884d93ec6b9}

\begin{DoxyParams}{Parameters}
\item[{\em parser}]Pointer to a ThinkGearStreamParser object. \item[{\em parserType}]One of the PARSER\_\-TYPE\_\-$\ast$ constants defined above: PARSER\_\-TYPE\_\-PACKETS or PARSER\_\-TYPE\_\-2BYTERAW. \item[{\em handleDataValueFunc}]A user-\/defined callback function that will be called whenever a data value is parsed from a Packet. \item[{\em customData}]A pointer to any arbitrary data that will also be passed to the handleDataValueFunc whenever a data value is parsed from a Packet.\end{DoxyParams}
\begin{DoxyReturn}{Returns}
-\/1 if {\ttfamily parser} is NULL. 

-\/2 if {\ttfamily parserType} is invalid. 

0 on success. 
\end{DoxyReturn}


Definition at line 54 of file ThinkGearStreamParser.c.

\hypertarget{_think_gear_stream_parser_8h_ac13a82467d15adfca688fccbd65dd699}{
\index{ThinkGearStreamParser.h@{ThinkGearStreamParser.h}!THINKGEAR\_\-parseByte@{THINKGEAR\_\-parseByte}}
\index{THINKGEAR\_\-parseByte@{THINKGEAR\_\-parseByte}!ThinkGearStreamParser.h@{ThinkGearStreamParser.h}}
\subsubsection[{THINKGEAR\_\-parseByte}]{\setlength{\rightskip}{0pt plus 5cm}int THINKGEAR\_\-parseByte ({\bf ThinkGearStreamParser} $\ast$ {\em parser}, \/  unsigned char {\em byte})}}
\label{_think_gear_stream_parser_8h_ac13a82467d15adfca688fccbd65dd699}
Feeds the {\ttfamily byte} into the {\ttfamily parser}. If the {\ttfamily byte} completes a complete, valid parser, then the {\ttfamily parser's} handleDataValue() function is automatically called on each DataRow in the Packet. The return value provides an indication of the state of the {\ttfamily parser} after parsing the byte.


\begin{DoxyParams}{Parameters}
\item[{\em parser}]Pointer to an initialized ThinkGearDataParser object. \item[{\em byte}]The next byte of the data stream.\end{DoxyParams}
\begin{DoxyReturn}{Returns}
-\/1 if {\ttfamily 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 {\ttfamily parser} is somehow in an unrecognized state. 

0 if the {\ttfamily byte} did not yet complete a Packet. 

1 if a Packet was received and parsed successfully. 
\end{DoxyReturn}


Definition at line 89 of file ThinkGearStreamParser.c.

