VRUT::PacketParser Class Reference

PacketParser class extends textParser to be ready for parsing DTrack -ASCII format UDP packet. More...

#include <pparser.h>

List of all members.

Public Member Functions

 PacketParser (const char *input=NULL)
 Constructor.
 ~PacketParser ()
 destructor
bool Parse ()
 main parsing method
void SetPacket (char *packet)
 sets new packet to parse
int FrameCounter ()
 returns Frame Counter value of a last parsed packet
float TimeStamp ()
 returns Timestamp value of a last parsed packet
int CalibratedDevices ()
 returns number of calibrated devices
int ParsedDevices ()
 returns number of devices that were found during last succesful parsing
void SetQueue (bodyqueue *queue)
 Sets the pointer to queue where tu put parsed devices.
 PacketParser (const char *input=NULL)
 Constructor.
 ~PacketParser ()
 destructor
bool Parse ()
 main parsing method
void SetPacket (char *packet)
 sets new packet to parse
int FrameCounter ()
 returns Frame Counter value of a last parsed packet
float TimeStamp ()
 returns Timestamp value of a last parsed packet
int CalibratedDevices ()
 returns number of calibrated devices
int ParsedDevices ()
 returns number of devices that were found during last succesful parsing
void SetQueue (bodyqueue *queue)
 Sets the pointer to queue where tu put parsed devices.

Private Member Functions

bool parse6D ()
 parse 6DOF devices. Returns true if all devices succesful.
bool parse6DF ()
 parse Flystick devices. Returns true if all devices of type succesful.
bool parse6DF2 ()
 parse Flystick2 devices. Returns true if all devices of type succesful.
bool parse6DMT ()
 parse Measurement tools. Returns true if all devices of type succesful.
bool parseGL ()
 parse Fingertracking hands. Returns true if all devices of type succesful.
bool parse3D ()
 parse 3DOF devices. Returns true if all devices of type succesful.
bool parseFinger (Finger *finger)
 parse finger - a part of the glove and put data into structure Finger
bool parseInt (int *target)
 parse Integer and skip separators
bool parseFloat (float *target)
 parse Float and skip separators
size_t parseVector (float *target, size_t dimension)
 parse vector and skip separators
bool parse6D ()
 parse 6DOF devices. Returns true if all devices succesful.
bool parse6DF ()
 parse Flystick devices. Returns true if all devices of type succesful.
bool parse6DF2 ()
 parse Flystick2 devices. Returns true if all devices of type succesful.
bool parse6DMT ()
 parse Measurement tools. Returns true if all devices of type succesful.
bool parseGL ()
 parse Fingertracking hands. Returns true if all devices of type succesful.
bool parse3D ()
 parse 3DOF devices. Returns true if all devices of type succesful.
bool parseFinger (Finger *finger)
 parse finger - a part of the glove and put data into structure Finger
bool parseInt (int *target)
 parse Integer and skip separators
bool parseFloat (float *target)
 parse Float and skip separators
size_t parseVector (float *target, size_t dimension)
 parse vector and skip separators

Private Attributes

bodyqueuebQueue
 extern queue where to put parsed devices
TextParsertextparser
 textparser enables to easily go through the packet data
int frameCounter
 a Frame counter information of last parsed packet (information from packet)
int calibDevs
 number of calibrated devices (information from packet data)
int devicesCount
 number of devices found in last packet
float timeStamp
 a timestamp of the packet (information from packet data)a
bodyqueuebQueue
 extern queue where to put parsed devices
TextParsertextparser
 textparser enables to easily go through the packet data

Static Private Attributes

static const char separators []
 enumeration of separators used in DTrack packet
static const char * tags []
 enumeratiion of tags used in Dtrack packet
static const char * tags []
 enumeratiion of tags used in Dtrack packet


Detailed Description

PacketParser class extends textParser to be ready for parsing DTrack -ASCII format UDP packet.

Definition at line 15 of file pparser.h.


Constructor & Destructor Documentation

PacketParser::PacketParser ( const char *  input = NULL  ) 

Constructor.

Parameters:
input -packet

Definition at line 23 of file pparser.cpp.

00024 {
00025        bQueue = NULL;
00026        frameCounter = 0;
00027        timeStamp = -1.0;
00028        textparser = NULL;
00029 }

PacketParser::~PacketParser (  ) 

destructor

Definition at line 30 of file pparser.cpp.

00031 {
00032        if (textparser != NULL)
00033        {
00034               delete textparser;
00035        }
00036 }

VRUT::PacketParser::PacketParser ( const char *  input = NULL  ) 

Constructor.

Parameters:
input -packet

VRUT::PacketParser::~PacketParser (  ) 

destructor


Member Function Documentation

bool PacketParser::parse6D (  )  [private]

parse 6DOF devices. Returns true if all devices succesful.

Definition at line 207 of file pparser.cpp.

00208 {
00209        int devs; // number of devices of type 3D
00210        if(!parseInt(&devs)) return false;
00211        devicesCount += devs;
00212        for (int i = 0 ; i < devs; i++)
00213        {
00214               int id;
00215               float qu;
00216               float s[6];
00217               float b[9];
00218               if (!parseInt(&id))        return false;
00219               if (!parseFloat(&qu))      return false;
00220               if (6 != parseVector(s,6)) return false;
00221               if (9 != parseVector(b,9)) return false;
00222               Body * b6d = new Body(id,qu,Body::B6D,s,b);
00223               bQueue->push(b6d);
00224        }
00225        return true;
00226 }

bool PacketParser::parse6DF (  )  [private]

parse Flystick devices. Returns true if all devices of type succesful.

Definition at line 227 of file pparser.cpp.

00228 {
00229        int devs; // number of devices of type 3D
00230        if(!parseInt(&devs)) return false;
00231        devicesCount += devs;
00232        for (int i = 0 ; i < devs; i++)
00233        {
00234               int id;
00235               float qu;
00236               int bt;
00237               float s[6];
00238               float b[9]; // pouzt datovou strukturu
00239               if (!parseInt(&id))        return false;
00240               if (!parseFloat(&qu))      return false;
00241               if (!parseInt(&bt))        return false;
00242               if (6 != parseVector(s,6)) return false;
00243               if (9 != parseVector(b,9)) return false;
00244               FlyStick1 * fs1;
00245               if (qu != -1) fs1 = new FlyStick1(id, qu, bt, s, b);
00246               else fs1 = new FlyStick1(id,qu, bt);
00247               bQueue->push(fs1);
00248        }
00249        return true;
00250 }

bool PacketParser::parse6DF2 (  )  [private]

parse Flystick2 devices. Returns true if all devices of type succesful.

Definition at line 251 of file pparser.cpp.

00252 {
00253        int dev_s; // number of devices of type Flystick2 registered
00254        int devs; // number of followed on the line
00255        if(!parseInt(&dev_s)) return false;
00256        if(!parseInt(&devs))  return false;
00257        devicesCount += devs;
00258        for (int i = 0 ; i < devs; i++)
00259        {
00260               int id;
00261               float qu;
00262               int nbt;
00263               int nct;
00264               float s[3];
00265               float b[9]; // pouzit datovou strukturu
00266               if (!parseInt(&id))        return false;
00267               if (!parseFloat(&qu))      return false;
00268               if (!parseInt(&nbt))       return false;
00269               if (!parseInt(&nct))       return false;
00270               if (3 != parseVector(s,3)) return false;
00271               if (9 != parseVector(b,9)) return false;
00272               FlyStick2 * fs2 = NULL;
00273               if (qu != -1) fs2 = new FlyStick2(id, qu, nbt, nct, s, b);
00274               else FlyStick2(id, qu, nbt, nct);
00275               int intNum = nbt /32;
00276               if ((nbt%32) != 0) intNum += 1;
00277               int butt;
00278               float control;
00279               for (int j = 0; j < intNum; j++)
00280               {
00281                      if (!parseInt(&butt))
00282                      {
00283                             delete fs2;
00284                             return false;
00285                      }
00286                      else
00287                      {
00288                             fs2->addButtons(j, butt);
00289                      }
00290               }
00291               for (int j = 0; j < nct; j++)
00292               {
00293                      if(!parseFloat(&control))
00294                      {
00295                             delete fs2;
00296                             return false;
00297                      }
00298                      else
00299                      {
00300                             fs2->addControls(j,control);
00301                      }
00302               }
00303               bQueue->push(fs2);
00304        }
00305        return true;
00306 }

bool PacketParser::parse6DMT (  )  [private]

parse Measurement tools. Returns true if all devices of type succesful.

Definition at line 307 of file pparser.cpp.

00308 {
00309        int devs; // number of devices of type 3D
00310        if(!parseInt(&devs)) return false;
00311        devicesCount += devs;
00312        for (int i = 0 ; i < devs; i++)
00313        {
00314               int id;
00315               float qu;
00316               int bt;
00317               float s[3];
00318               float b[9];
00319               if (!parseInt(&id))        return false;
00320               if (!parseFloat(&qu))      return false;
00321               if (!parseInt(&bt))        return false;
00322               if (3 != parseVector(s,3)) return false;
00323               if (9 != parseVector(b,9)) return false;
00324               Measurer * dmt;
00325               if (qu != -1)dmt = new Measurer(id, qu, bt, s, b);
00326               else dmt = new Measurer(id, qu, bt);
00327               bQueue->push(dmt);
00328        }
00329        return true;
00330 }

bool PacketParser::parseGL (  )  [private]

parse Fingertracking hands. Returns true if all devices of type succesful.

Definition at line 331 of file pparser.cpp.

00332 {
00333        int devs; // number of devices of type 3D
00334        if(!textparser->ParseInt(&devs, separators)) return false;
00335        devicesCount += devs;
00336        for (int i = 0 ; i < devs; i++)
00337        {
00338               int id;
00339               float qu;
00340               int hand; // left or right
00341               int nf;   // number of fingers
00342               float s[3]; // misto techto 3 pouzit uz datove struktury
00343               float b[9];
00344               if (!parseInt(&id))        return false;
00345               if (!parseFloat(&qu))      return false;
00346               if (!parseInt(&hand))      return false;
00347               if (!parseInt(&nf))        return false;
00348               if (3 != parseVector(s,3)) return false;
00349               if (9 != parseVector(b,9)) return false;
00350               bool leftH;
00351               if (nf == 0) leftH = true; else leftH = false;
00352               BodyGlove * gl = new BodyGlove(id,qu, nf,leftH,s,b);
00353               Finger fgrs;
00354               for (int j = 0 ; j < nf; j++)
00355               {
00356                      if(!parseFinger(&fgrs))
00357                      {
00358                             delete gl;
00359                             return false;
00360                      }
00361                      else gl->addFinger(j, fgrs);
00362               }
00363               bQueue->push(gl);
00364        }
00365        return true;
00366 }

bool PacketParser::parse3D (  )  [private]

parse 3DOF devices. Returns true if all devices of type succesful.

Definition at line 189 of file pparser.cpp.

00190 {
00191        int devs; // number of devices of type 3D
00192        if(!parseInt(&devs)) return false;
00193        devicesCount += devs;
00194        for (int i = 0 ; i < devs; i++)
00195        {
00196               int id;
00197               float qu;
00198               float s[3];
00199               if (!parseInt(&id))        return false;
00200               if (!parseFloat(&qu))      return false;
00201               if (3 != parseVector(s,3)) return false;
00202               Body * b3d = new Body(id,qu,Body::B3D,s);
00203               bQueue->push(b3d);
00204        }
00205        return true;
00206 }

bool PacketParser::parseFinger ( Finger finger  )  [private]

parse finger - a part of the glove and put data into structure Finger

Parameters:
finger a pointer to data structure where to store a information about finger
returns true if succesful

Definition at line 367 of file pparser.cpp.

00368 {
00369        if (3 != parseVector(finger->Position, 3)) return false;
00370        if (9 != parseVector(finger->Matrix, 9))   return false;
00371        if (!parseFloat(&finger->Radius))          return false;
00372        if (!parseFloat(&(finger->Length[0])))     return false;
00373        if (!parseFloat(&(finger->Angle[0])))      return false;
00374        if (!parseFloat(&(finger->Length[1])))     return false;
00375        if (!parseFloat(&(finger->Angle[1])))      return false;
00376        if (!parseFloat(&(finger->Length[2])))     return false;
00377        return true;
00378 }

bool PacketParser::parseInt ( int *  target  )  [inline, private]

parse Integer and skip separators

Parameters:
target a pointer to an integer where to put a value
returns true if succesful

Definition at line 171 of file pparser.cpp.

00172 {
00173        if (!textparser->ParseInt(target, separators)) return false;
00174        textparser->SkipCharsAndComments(separators);
00175        return true;
00176 }

bool PacketParser::parseFloat ( float *  target  )  [inline, private]

parse Float and skip separators

Parameters:
target a pointer to a float where to put a value
returns true if succesful

Definition at line 177 of file pparser.cpp.

00178 {
00179        if (!textparser->ParseFloat(target, separators)) return false;
00180        textparser->SkipCharsAndComments(separators);
00181        return true;
00182 }

size_t PacketParser::parseVector ( float *  target,
size_t  dimension 
) [inline, private]

parse vector and skip separators

Parameters:
target a pointer to a float where to put a value
dimension - the nuber of floats to be read (length of target array) returns the number of vector values read

Definition at line 183 of file pparser.cpp.

00184 {
00185        size_t read = textparser->ParseVector(target, dimension, true, separators);
00186        textparser->SkipCharsAndComments(separators);
00187        return read;
00188 }

bool PacketParser::Parse (  ) 

main parsing method

returns true if parsing succesful (input data matching packet format)

Definition at line 58 of file pparser.cpp.

00059 {
00060        if (NULL == bQueue)
00061        {
00062               LOGERROR(wxT("<Tracking> No Queue is set, where to save devices. Parsing unsuccesful!"));
00063               return false;
00064        }
00065        calibDevs = 0;
00066        devicesCount = 0;
00067        while(!textparser->IsEmpty())
00068        {
00069               switch (textparser->KeywordsSwitch(tags, separators))
00070               {
00071               case 0: // fr
00072                      {
00073                             int fCounter;
00074                             if (!textparser->ParseInt(&fCounter, separators))
00075                             {
00076                                    LOGERROR(wxT("<Tracking>Unexpected chunks while parsing fr"));
00077                                    //frameCounter = 0;
00078                                    return false;
00079                             }
00080                             if (fCounter <= frameCounter) LOGWARNING(wxT("<Tracking>Packet order varied"));
00081                             frameCounter = fCounter;
00082                             break;
00083                      }
00084               case 1: // ts
00085                      {
00086                             if(!textparser->ParseFloat(&timeStamp,separators))
00087                             {
00088                                    LOGERROR(wxT("<Tracking>Unexpected chunks while parsing ts"));
00089                                    //timeStamp = 0;
00090                                    return false;
00091                             }
00092                             break;
00093                      }
00094               case 2: // 6d
00095                      {
00096                             if (!parse6D())
00097                             {
00098                                    LOGERROR(wxT("<tracking>Unexpected chunks while parsing 6d"));
00099                                    return false;
00100                             }
00101                             break;
00102                      }
00103               case 3: // 6df
00104                      {
00105                             if (!parse6DF())
00106                             {
00107                                    LOGERROR(wxT("<tracking>Unexpected chunks while parsing 6df"));
00108                                    return false;
00109                             }
00110                             break;
00111                      }
00112               case 4: // 6df2
00113                      {
00114                             if (!parse6DF2())
00115                             {
00116                                    LOGERROR(wxT("<tracking>Unexpected chunks while parsing 6df2"));
00117                                    return false;
00118                             }
00119                             break;
00120                      }
00121               case 5: // 6dmt
00122                      {
00123                             if (!parse6DMT())
00124                             {
00125                                    LOGERROR(wxT("<tracking>Unexpected chunks while parsing 6dmt"));
00126                                    return false;
00127                             }
00128                             break;
00129                      }
00130               case 6: // gl
00131                      {
00132                             if (!parseGL())
00133                             {
00134                                    LOGERROR(wxT("<tracking>Unexpected chunks while parsing gl"));
00135                                    return false;
00136                             }
00137                             break;
00138                      }
00139               case 7: // 3d
00140                      {
00141                             if (!parse3D())
00142                             {
00143                                    LOGERROR(wxT("<tracking>Unexpected chunks while parsing 3d"));
00144                                    return false;
00145                             }
00146                             break;
00147                      }
00148               case 8: // 6dcal
00149                      {
00150                             if(!textparser->ParseInt(&calibDevs,separators))
00151                             {
00152                                    LOGERROR(wxT("<Tracking>Unexpected chunks while parsing 6dcal"));
00153                                    return false;
00154                             }
00155                             break;
00156                      }
00157               default: // bad hit
00158                      {
00159                             wxString aaa = wxT("<Tracking> Unexpected token while parsing tag: ") + textparser->GetWxLine();
00160                             LOGERROR(aaa);
00161                             // resit co kdyz bylo nacteno nejake zarizeni, ale pak nastala chyba...
00162                             // >>> otazka, jestli transformovat behem parsovani, nebo ukladat do fronty a pak postupne obsluhovat frontu
00163                             return false;
00164                             break;
00165                      }
00166               }
00167        }
00168        return true; // ujisti se, jestli byl fr parsovany
00169 }

void PacketParser::SetPacket ( char *  packet  ) 

sets new packet to parse

Definition at line 37 of file pparser.cpp.

00038 {
00039        if (textparser != NULL) delete textparser;
00040        textparser = new TextParser(packet);
00041 }

int PacketParser::FrameCounter (  ) 

returns Frame Counter value of a last parsed packet

Definition at line 46 of file pparser.cpp.

00047 {
00048        return frameCounter;
00049 }

float PacketParser::TimeStamp (  ) 

returns Timestamp value of a last parsed packet

Note that this information is only available when it is included in packet data. Dummy value is returned if it is not included.

Definition at line 42 of file pparser.cpp.

00043 {
00044        return timeStamp;
00045 }

int PacketParser::CalibratedDevices (  ) 

returns number of calibrated devices

Note, this is a number that is carried with UDP packet, so be sure that this information is included before using this! If it is not 0 is returned!

Definition at line 50 of file pparser.cpp.

00051 {
00052        return calibDevs;
00053 }

int PacketParser::ParsedDevices (  ) 

returns number of devices that were found during last succesful parsing

Note that if last parsing was unsuccesful, dummy value is returned!

Definition at line 54 of file pparser.cpp.

00055 {
00056        return devicesCount;
00057 }

void PacketParser::SetQueue ( VRUT::bodyqueue queue  ) 

Sets the pointer to queue where tu put parsed devices.

Definition at line 380 of file pparser.cpp.

00381 {
00382        this->bQueue = queue;
00383 }

bool VRUT::PacketParser::parse6D (  )  [private]

parse 6DOF devices. Returns true if all devices succesful.

bool VRUT::PacketParser::parse6DF (  )  [private]

parse Flystick devices. Returns true if all devices of type succesful.

bool VRUT::PacketParser::parse6DF2 (  )  [private]

parse Flystick2 devices. Returns true if all devices of type succesful.

bool VRUT::PacketParser::parse6DMT (  )  [private]

parse Measurement tools. Returns true if all devices of type succesful.

bool VRUT::PacketParser::parseGL (  )  [private]

parse Fingertracking hands. Returns true if all devices of type succesful.

bool VRUT::PacketParser::parse3D (  )  [private]

parse 3DOF devices. Returns true if all devices of type succesful.

bool VRUT::PacketParser::parseFinger ( Finger finger  )  [private]

parse finger - a part of the glove and put data into structure Finger

Parameters:
finger a pointer to data structure where to store a information about finger
returns true if succesful

bool VRUT::PacketParser::parseInt ( int *  target  )  [inline, private]

parse Integer and skip separators

Parameters:
target a pointer to an integer where to put a value
returns true if succesful

bool VRUT::PacketParser::parseFloat ( float *  target  )  [inline, private]

parse Float and skip separators

Parameters:
target a pointer to a float where to put a value
returns true if succesful

size_t VRUT::PacketParser::parseVector ( float *  target,
size_t  dimension 
) [inline, private]

parse vector and skip separators

Parameters:
target a pointer to a float where to put a value
dimension - the nuber of floats to be read (length of target array) returns the number of vector values read

bool VRUT::PacketParser::Parse (  ) 

main parsing method

returns true if parsing succesful (input data matching packet format)

void VRUT::PacketParser::SetPacket ( char *  packet  ) 

sets new packet to parse

int VRUT::PacketParser::FrameCounter (  ) 

returns Frame Counter value of a last parsed packet

float VRUT::PacketParser::TimeStamp (  ) 

returns Timestamp value of a last parsed packet

Note that this information is only available when it is included in packet data. Dummy value is returned if it is not included.

int VRUT::PacketParser::CalibratedDevices (  ) 

returns number of calibrated devices

Note, this is a number that is carried with UDP packet, so be sure that this information is included before using this! If it is not 0 is returned!

int VRUT::PacketParser::ParsedDevices (  ) 

returns number of devices that were found during last succesful parsing

Note that if last parsing was unsuccesful, dummy value is returned!

void VRUT::PacketParser::SetQueue ( bodyqueue queue  ) 

Sets the pointer to queue where tu put parsed devices.


Member Data Documentation

extern queue where to put parsed devices

Definition at line 19 of file pparser.h.

static const char VRUT::PacketParser::separators [static, private]

Initial value:

{
       '[', 
       ']', 
       ' '  
}
enumeration of separators used in DTrack packet

Definition at line 22 of file pparser.h.

const char * PacketParser::tags [static, private]

Initial value:

{
       "fr",   
       "ts",   
       "6d",   
       "6df",  
       "6df2", 
       "6dmt", 
       "gl",   
       "3d",   
       "6dcal",
       "" 
}
enumeratiion of tags used in Dtrack packet

Definition at line 24 of file pparser.h.

textparser enables to easily go through the packet data

Definition at line 26 of file pparser.h.

a Frame counter information of last parsed packet (information from packet)

Definition at line 28 of file pparser.h.

number of calibrated devices (information from packet data)

Definition at line 30 of file pparser.h.

number of devices found in last packet

Definition at line 32 of file pparser.h.

a timestamp of the packet (information from packet data)a

Definition at line 34 of file pparser.h.

extern queue where to put parsed devices

Definition at line 19 of file pparser.h.

const char* VRUT::PacketParser::tags[] [static, private]

enumeratiion of tags used in Dtrack packet

Definition at line 24 of file pparser.h.

textparser enables to easily go through the packet data

Definition at line 26 of file pparser.h.


The documentation for this class was generated from the following files:

Generated on Tue Mar 10 14:41:50 2009 for VRUT by  doxygen 1.5.5