\hypertarget{_think_gear_stream_parser_8c}{
\section{neurosky/src/ThinkGearStreamParser.c File Reference}
\label{_think_gear_stream_parser_8c}\index{neurosky/src/ThinkGearStreamParser.c@{neurosky/src/ThinkGearStreamParser.c}}
}
{\ttfamily \#include \char`\"{}ThinkGearStreamParser.h\char`\"{}}\par
{\ttfamily \#include $<$stdio.h$>$}\par
\subsection*{Defines}
\begin{DoxyCompactItemize}
\item 
\#define \hyperlink{_think_gear_stream_parser_8c_af83e356370c60a7b838fcec5207306c2}{PARSER\_\-STATE\_\-NULL}~0x00
\item 
\#define \hyperlink{_think_gear_stream_parser_8c_aa38cc7542c48f5c04a341f7ff8ca6419}{PARSER\_\-STATE\_\-SYNC}~0x01
\item 
\#define \hyperlink{_think_gear_stream_parser_8c_aa29000e880fe048ae06fbe253055841d}{PARSER\_\-STATE\_\-SYNC\_\-CHECK}~0x02
\item 
\#define \hyperlink{_think_gear_stream_parser_8c_a698d4439498e9ad12f91e0e5c79c0fd5}{PARSER\_\-STATE\_\-PAYLOAD\_\-LENGTH}~0x03
\item 
\#define \hyperlink{_think_gear_stream_parser_8c_abec8bb1c4df683e8e1ccfa72886003d9}{PARSER\_\-STATE\_\-PAYLOAD}~0x04
\item 
\#define \hyperlink{_think_gear_stream_parser_8c_a8f6093f706206f01f53d21205ca5168f}{PARSER\_\-STATE\_\-CHKSUM}~0x05
\item 
\#define \hyperlink{_think_gear_stream_parser_8c_a5e53794042d6d233a045f0262f99d625}{PARSER\_\-STATE\_\-WAIT\_\-HIGH}~0x06
\item 
\#define \hyperlink{_think_gear_stream_parser_8c_a9cfda5a2d7541f4dbeaa18af02eb769d}{PARSER\_\-STATE\_\-WAIT\_\-LOW}~0x07
\item 
\#define \hyperlink{_think_gear_stream_parser_8c_a61eb52a76f9d43980a3df273e78b1943}{PARSER\_\-SYNC\_\-BYTE}~0xAA
\item 
\#define \hyperlink{_think_gear_stream_parser_8c_a98bd2e1c3baf2a74c74c0ac4dc5e67c4}{PARSER\_\-EXCODE\_\-BYTE}~0x55
\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
int \hyperlink{_think_gear_stream_parser_8c_acd042d7e82171c89b040f75bc92913a5}{parsePacketPayload} (\hyperlink{struct___think_gear_stream_parser}{ThinkGearStreamParser} $\ast$parser)
\item 
int \hyperlink{_think_gear_stream_parser_8c_a9ee4a2ee7a5a3da4a02003d6fd04dd7a}{parseDataRow} (\hyperlink{struct___think_gear_stream_parser}{ThinkGearStreamParser} $\ast$parser, unsigned char $\ast$rowPtr)
\item 
int \hyperlink{_think_gear_stream_parser_8c_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 
int \hyperlink{_think_gear_stream_parser_8c_ac13a82467d15adfca688fccbd65dd699}{THINKGEAR\_\-parseByte} (\hyperlink{struct___think_gear_stream_parser}{ThinkGearStreamParser} $\ast$parser, unsigned char byte)
\end{DoxyCompactItemize}


\subsection{Detailed Description}
\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_8c_source}{ThinkGearStreamParser.c}.



\subsection{Define Documentation}
\hypertarget{_think_gear_stream_parser_8c_a98bd2e1c3baf2a74c74c0ac4dc5e67c4}{
\index{ThinkGearStreamParser.c@{ThinkGearStreamParser.c}!PARSER\_\-EXCODE\_\-BYTE@{PARSER\_\-EXCODE\_\-BYTE}}
\index{PARSER\_\-EXCODE\_\-BYTE@{PARSER\_\-EXCODE\_\-BYTE}!ThinkGearStreamParser.c@{ThinkGearStreamParser.c}}
\subsubsection[{PARSER\_\-EXCODE\_\-BYTE}]{\setlength{\rightskip}{0pt plus 5cm}\#define PARSER\_\-EXCODE\_\-BYTE~0x55}}
\label{_think_gear_stream_parser_8c_a98bd2e1c3baf2a74c74c0ac4dc5e67c4}


Definition at line 42 of file ThinkGearStreamParser.c.

\hypertarget{_think_gear_stream_parser_8c_a8f6093f706206f01f53d21205ca5168f}{
\index{ThinkGearStreamParser.c@{ThinkGearStreamParser.c}!PARSER\_\-STATE\_\-CHKSUM@{PARSER\_\-STATE\_\-CHKSUM}}
\index{PARSER\_\-STATE\_\-CHKSUM@{PARSER\_\-STATE\_\-CHKSUM}!ThinkGearStreamParser.c@{ThinkGearStreamParser.c}}
\subsubsection[{PARSER\_\-STATE\_\-CHKSUM}]{\setlength{\rightskip}{0pt plus 5cm}\#define PARSER\_\-STATE\_\-CHKSUM~0x05}}
\label{_think_gear_stream_parser_8c_a8f6093f706206f01f53d21205ca5168f}


Definition at line 34 of file ThinkGearStreamParser.c.

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


Definition at line 29 of file ThinkGearStreamParser.c.

\hypertarget{_think_gear_stream_parser_8c_abec8bb1c4df683e8e1ccfa72886003d9}{
\index{ThinkGearStreamParser.c@{ThinkGearStreamParser.c}!PARSER\_\-STATE\_\-PAYLOAD@{PARSER\_\-STATE\_\-PAYLOAD}}
\index{PARSER\_\-STATE\_\-PAYLOAD@{PARSER\_\-STATE\_\-PAYLOAD}!ThinkGearStreamParser.c@{ThinkGearStreamParser.c}}
\subsubsection[{PARSER\_\-STATE\_\-PAYLOAD}]{\setlength{\rightskip}{0pt plus 5cm}\#define PARSER\_\-STATE\_\-PAYLOAD~0x04}}
\label{_think_gear_stream_parser_8c_abec8bb1c4df683e8e1ccfa72886003d9}


Definition at line 33 of file ThinkGearStreamParser.c.

\hypertarget{_think_gear_stream_parser_8c_a698d4439498e9ad12f91e0e5c79c0fd5}{
\index{ThinkGearStreamParser.c@{ThinkGearStreamParser.c}!PARSER\_\-STATE\_\-PAYLOAD\_\-LENGTH@{PARSER\_\-STATE\_\-PAYLOAD\_\-LENGTH}}
\index{PARSER\_\-STATE\_\-PAYLOAD\_\-LENGTH@{PARSER\_\-STATE\_\-PAYLOAD\_\-LENGTH}!ThinkGearStreamParser.c@{ThinkGearStreamParser.c}}
\subsubsection[{PARSER\_\-STATE\_\-PAYLOAD\_\-LENGTH}]{\setlength{\rightskip}{0pt plus 5cm}\#define PARSER\_\-STATE\_\-PAYLOAD\_\-LENGTH~0x03}}
\label{_think_gear_stream_parser_8c_a698d4439498e9ad12f91e0e5c79c0fd5}


Definition at line 32 of file ThinkGearStreamParser.c.

\hypertarget{_think_gear_stream_parser_8c_aa38cc7542c48f5c04a341f7ff8ca6419}{
\index{ThinkGearStreamParser.c@{ThinkGearStreamParser.c}!PARSER\_\-STATE\_\-SYNC@{PARSER\_\-STATE\_\-SYNC}}
\index{PARSER\_\-STATE\_\-SYNC@{PARSER\_\-STATE\_\-SYNC}!ThinkGearStreamParser.c@{ThinkGearStreamParser.c}}
\subsubsection[{PARSER\_\-STATE\_\-SYNC}]{\setlength{\rightskip}{0pt plus 5cm}\#define PARSER\_\-STATE\_\-SYNC~0x01}}
\label{_think_gear_stream_parser_8c_aa38cc7542c48f5c04a341f7ff8ca6419}


Definition at line 30 of file ThinkGearStreamParser.c.

\hypertarget{_think_gear_stream_parser_8c_aa29000e880fe048ae06fbe253055841d}{
\index{ThinkGearStreamParser.c@{ThinkGearStreamParser.c}!PARSER\_\-STATE\_\-SYNC\_\-CHECK@{PARSER\_\-STATE\_\-SYNC\_\-CHECK}}
\index{PARSER\_\-STATE\_\-SYNC\_\-CHECK@{PARSER\_\-STATE\_\-SYNC\_\-CHECK}!ThinkGearStreamParser.c@{ThinkGearStreamParser.c}}
\subsubsection[{PARSER\_\-STATE\_\-SYNC\_\-CHECK}]{\setlength{\rightskip}{0pt plus 5cm}\#define PARSER\_\-STATE\_\-SYNC\_\-CHECK~0x02}}
\label{_think_gear_stream_parser_8c_aa29000e880fe048ae06fbe253055841d}


Definition at line 31 of file ThinkGearStreamParser.c.

\hypertarget{_think_gear_stream_parser_8c_a5e53794042d6d233a045f0262f99d625}{
\index{ThinkGearStreamParser.c@{ThinkGearStreamParser.c}!PARSER\_\-STATE\_\-WAIT\_\-HIGH@{PARSER\_\-STATE\_\-WAIT\_\-HIGH}}
\index{PARSER\_\-STATE\_\-WAIT\_\-HIGH@{PARSER\_\-STATE\_\-WAIT\_\-HIGH}!ThinkGearStreamParser.c@{ThinkGearStreamParser.c}}
\subsubsection[{PARSER\_\-STATE\_\-WAIT\_\-HIGH}]{\setlength{\rightskip}{0pt plus 5cm}\#define PARSER\_\-STATE\_\-WAIT\_\-HIGH~0x06}}
\label{_think_gear_stream_parser_8c_a5e53794042d6d233a045f0262f99d625}


Definition at line 37 of file ThinkGearStreamParser.c.

\hypertarget{_think_gear_stream_parser_8c_a9cfda5a2d7541f4dbeaa18af02eb769d}{
\index{ThinkGearStreamParser.c@{ThinkGearStreamParser.c}!PARSER\_\-STATE\_\-WAIT\_\-LOW@{PARSER\_\-STATE\_\-WAIT\_\-LOW}}
\index{PARSER\_\-STATE\_\-WAIT\_\-LOW@{PARSER\_\-STATE\_\-WAIT\_\-LOW}!ThinkGearStreamParser.c@{ThinkGearStreamParser.c}}
\subsubsection[{PARSER\_\-STATE\_\-WAIT\_\-LOW}]{\setlength{\rightskip}{0pt plus 5cm}\#define PARSER\_\-STATE\_\-WAIT\_\-LOW~0x07}}
\label{_think_gear_stream_parser_8c_a9cfda5a2d7541f4dbeaa18af02eb769d}


Definition at line 38 of file ThinkGearStreamParser.c.

\hypertarget{_think_gear_stream_parser_8c_a61eb52a76f9d43980a3df273e78b1943}{
\index{ThinkGearStreamParser.c@{ThinkGearStreamParser.c}!PARSER\_\-SYNC\_\-BYTE@{PARSER\_\-SYNC\_\-BYTE}}
\index{PARSER\_\-SYNC\_\-BYTE@{PARSER\_\-SYNC\_\-BYTE}!ThinkGearStreamParser.c@{ThinkGearStreamParser.c}}
\subsubsection[{PARSER\_\-SYNC\_\-BYTE}]{\setlength{\rightskip}{0pt plus 5cm}\#define PARSER\_\-SYNC\_\-BYTE~0xAA}}
\label{_think_gear_stream_parser_8c_a61eb52a76f9d43980a3df273e78b1943}


Definition at line 41 of file ThinkGearStreamParser.c.



\subsection{Function Documentation}
\hypertarget{_think_gear_stream_parser_8c_a9ee4a2ee7a5a3da4a02003d6fd04dd7a}{
\index{ThinkGearStreamParser.c@{ThinkGearStreamParser.c}!parseDataRow@{parseDataRow}}
\index{parseDataRow@{parseDataRow}!ThinkGearStreamParser.c@{ThinkGearStreamParser.c}}
\subsubsection[{parseDataRow}]{\setlength{\rightskip}{0pt plus 5cm}int parseDataRow ({\bf ThinkGearStreamParser} $\ast$ {\em parser}, \/  unsigned char $\ast$ {\em rowPtr})}}
\label{_think_gear_stream_parser_8c_a9ee4a2ee7a5a3da4a02003d6fd04dd7a}
\hypertarget{_think_gear_stream_parser_8c_acd042d7e82171c89b040f75bc92913a5}{
\index{ThinkGearStreamParser.c@{ThinkGearStreamParser.c}!parsePacketPayload@{parsePacketPayload}}
\index{parsePacketPayload@{parsePacketPayload}!ThinkGearStreamParser.c@{ThinkGearStreamParser.c}}
\subsubsection[{parsePacketPayload}]{\setlength{\rightskip}{0pt plus 5cm}int parsePacketPayload ({\bf ThinkGearStreamParser} $\ast$ {\em parser})}}
\label{_think_gear_stream_parser_8c_acd042d7e82171c89b040f75bc92913a5}
Parses each row of data from the {\ttfamily packet's} Data\mbox{[}\mbox{]} block, updating the fields of {\ttfamily data} as appropriate. 

Definition at line 203 of file ThinkGearStreamParser.c.

\hypertarget{_think_gear_stream_parser_8c_a61ff029364ee47988e7c8884d93ec6b9}{
\index{ThinkGearStreamParser.c@{ThinkGearStreamParser.c}!THINKGEAR\_\-initParser@{THINKGEAR\_\-initParser}}
\index{THINKGEAR\_\-initParser@{THINKGEAR\_\-initParser}!ThinkGearStreamParser.c@{ThinkGearStreamParser.c}}
\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_8c_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_8c_ac13a82467d15adfca688fccbd65dd699}{
\index{ThinkGearStreamParser.c@{ThinkGearStreamParser.c}!THINKGEAR\_\-parseByte@{THINKGEAR\_\-parseByte}}
\index{THINKGEAR\_\-parseByte@{THINKGEAR\_\-parseByte}!ThinkGearStreamParser.c@{ThinkGearStreamParser.c}}
\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_8c_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.

