camera/NMEA.h

Go to the documentation of this file.
00001 #ifndef _NMEA_H_
00002 #define _NMEA_H_
00003 
00007 /*
00008    NMEA.h - Class encapsulating NMEA message strings.
00009 
00010    The NMEA class is an abstract base class used to represent NMEA sentence (message)
00011    strings. Each different NMEA sentence has an array of Field objects, each 
00012    of which represents one field (token) in the sentence.
00013    NMEA declares methods to set various types of fields, get Fields, 
00014    calculate checksums, and generate the NMEA string (an abstract method).
00015    Subclasses are expected to provide methods for setting their Field members 
00016    (which should enforce type checking and call the setField methods in NMEA),
00017    and implement the toString() method.
00018 
00019    Currently GPGGA and GPRMC message types are implemented.
00020 
00021    NMEA does not currently implement parse methods (to read in NMEA from a 
00022    string), since it was developed to synthesize NMEA strings.
00023 
00024   copyright MBARI 2008 
00025   author k. headley
00026 */
00027 
00028 /****************************************************************************/
00029 /* Copyright (c) 2008 MBARI                                                 */
00030 /* MBARI Proprietary Information. All rights reserved.                      */
00031 /****************************************************************************/
00032 /* Summary  :                                                               */
00033 /* Filename : NMEA.h                                                        */
00034 /* Author   : K Headley                                                     */
00035 /* Project  : Benthic Imaging AUV                                           */
00036 /* Created  : 04/01/2008                                                    */
00037 /****************************************************************************/
00038 /* Modification History:                                                    */
00039 /*  $Id: NMEA.h,v 1.1 2008/07/15 18:39:29 headley Exp $   */
00040 /*  $Name:  $ */
00041 /****************************************************************************/
00042 
00043 #ifdef _QNX
00044 #include <strstream.h>
00045 #include <time.h>
00046 #include <iostream.h>
00047 #include <iomanip.h>
00048 #else
00049 #include <iostream>
00050 #include <iomanip>
00051 #include <sstream>
00052 #include <ctime>
00053 #endif
00054 
00055 #ifndef _QNX
00056 using namespace std;
00057 #endif
00058 
00060 #define MAX_NMEA_NAME 7
00061 
00062 #define MAX_NMEA_FIELDS 32
00063 
00064 #define MAX_NMEA_LEN 128
00065 
00066 
00074 class Field{
00075   friend ostream& operator<<(ostream& output, const Field& n);
00076 public:
00078   typedef enum FIELD_TYPES {INT=0,UINT,DOUBLE,UCHAR,CHAR,PCHAR,TIMET,DATET} FieldType;
00080   Field();
00081   Field(char *value);
00082   Field(char value);
00083   Field(int value);
00084   Field(unsigned int value);
00085   Field(double value);
00086   Field(unsigned char value);
00087   Field(time_t value);
00088   FieldType getType();
00089   char *pcharValue();
00090   int intValue();
00091   unsigned int uintValue();
00092   unsigned char ucharValue();
00093   double doubleValue();
00094   time_t timeValue();
00095   void setValue(int value);
00096   void setValue(unsigned int value);
00097   void setValue(char *value);
00098   void setValue(char value);
00099   void setValue(unsigned char value);
00100   void setValue(double value);
00101   void setValue(time_t value);
00103   const char *toString()const{
00104 #ifdef _QNX
00105     ostrstream outs;
00106     outs << *this <<ends;
00107     return outs.str();
00108 #else
00109     ostringstream outs;
00110     outs << *this;
00111     return outs.str().c_str();
00112 #endif
00113   } 
00114 
00115  private:
00119   FieldType _type;
00121   char*_name;
00123   char *_pcharValue;
00125   char _charValue;
00127   int _intValue;
00129   unsigned int _uintValue;
00131   unsigned char _ucharValue;
00133   double _doubleValue;
00135   time_t _timeValue;
00136 
00137 };/* class Field */
00138 
00142 class InvalidNMEAException {
00143  public:
00145   char *message;
00149   InvalidNMEAException(char *m){message=m;}
00152   const char *msg(){return message;}
00153 };
00154 
00158 class NMEA{
00159 
00160  public:
00176   typedef enum MESSAGE_TYPES {t_GPGGA=0,t_GPRMC,t_GPGLL,
00177                               t_GPGSV,t_GPGSA,t_GPMSS,
00178                               t_GPVTG,tGPZDA,t_UNKNOWN}MessageType;
00186   enum FIELDS {FIELD_0=0,FIELD_1,FIELD_2,FIELD_3,
00187                FIELD_4,FIELD_5,FIELD_6,FIELD_7,
00188                FIELD_8,FIELD_9,FIELD_10,FIELD_11,
00189                FIELD_12,FIELD_13,FIELD_14,FIELD_15,
00190                FIELD_16,FIELD_17,FIELD_18,FIELD_19,
00191                FIELD_20,FIELD_21,FIELD_22,FIELD_23,
00192                FIELD_24,FIELD_25,FIELD_26,FIELD_27,
00193                FIELD_28,FIELD_29,FIELD_30,FIELD_31};
00194 
00195   NMEA();
00196   MessageType getType();
00197   Field *getField(NMEA::FIELDS index);
00198   void setField(NMEA::FIELDS field,int value);
00199   void setField(NMEA::FIELDS field,unsigned int value);
00200   void setField(NMEA::FIELDS field,char *value);
00201   void setField(NMEA::FIELDS field,char value);
00202   void setField(NMEA::FIELDS field,unsigned char value);
00203   void setField(NMEA::FIELDS field,double value);
00204   void setField(NMEA::FIELDS field,time_t value);
00205   //virtual const char *toString()=0;
00212   unsigned short int checksum(const char *nmeaString)const{
00213     const char *cp=nmeaString;//.c_str();
00214     char *bp, *ep;
00215     short unsigned int ret;
00216 
00217     // set begin and end pointers
00218     bp=strstr(cp,"$");
00219     ep=strstr(cp,"*");
00220 
00221     // throw exception if the start or end 
00222     // characters not found
00223     if(bp==NULL || ep==NULL){
00224       throw InvalidNMEAException("Missing delimiter * or $");
00225     }
00226     // start at character after '$'
00227     bp++;
00228     ret=0;
00229     // compute XOR of all bytes until '*'
00230     while(bp<ep){
00231       ret ^= (short unsigned int) (*bp);
00232       bp++;
00233     }
00234     return ret;
00235   }
00236 
00237  protected:
00241   unsigned int _nFields;
00245   MessageType  _type;
00247   Field _fields[MAX_NMEA_FIELDS];
00248   
00249  private:
00250 
00251 };/* class NMEA */
00252 
00274 class GPGGA : public NMEA{
00276   friend ostream& operator<<(ostream& output, const GPGGA& n);
00277 public:
00278 
00284   enum FIELDS {GGAMSG=NMEA::FIELD_0,GGATIME,
00285                GGALATD,GGALATM,GGALATH,
00286                GGALOND,GGALONM,GGALONH,
00287                GGAQUAL,GGASIU,GGAHDOP,
00288                GGAALT,GGAALTU,
00289                GGAGEOH,GGAGEOHU,
00290                GGADUPT,GGADRID,GGACHK};
00291   GPGGA();
00292   int setTIME(time_t time);
00293   int setLATD(int latd);
00294   int setLATM(double latm);
00295   int setLATH(char lath);
00296   int setLOND(int lond);
00297   int setLONM(double lonm);
00298   int setLONH(char lonh);
00299   int setQUAL(int qual);
00300   int setHDOP(double hdop);
00301   int setALT(double alt);
00302   int setALTU(char altu);
00303   int setSIU(int siu);
00304   int setGEOH(double alt);
00305   int setGEOHU(char geohu);
00306   int setDUPT(int dupt);
00307   int setDRID(int drid);
00308   virtual const char *toString();
00309 
00310  private:
00311 
00312 };/* class GPGGA */
00331 class GPRMC : public NMEA{
00333   friend ostream& operator<<(ostream& output, const GPRMC& n);
00334 public:
00341   enum FIELDS {RMCMSG=NMEA::FIELD_0,RMCTIME,RMCSTAT,
00342                RMCLATD,RMCLATM,RMCLATH,
00343                RMCLOND,RMCLONM,RMCLONH,
00344                RMCSOG,RMCCOG,RMCDATE,
00345                RMCMVM,RMCMVD,RMCCHK};
00346 
00347   GPRMC();
00348   int setTIME(time_t time);
00349   int setSTAT(char stat);
00350   int setLATD(int latd);
00351   int setLATM(double latm);
00352   int setLATH(char lath);
00353   int setLOND(int lond);
00354   int setLONM(double lonm);
00355   int setLONH(char lonh);
00356   int setSOG(double sog);
00357   int setCOG(double cog);
00358   int setDATE(time_t date);
00359   int setMVM(double nvn);
00360   int setMVD(char mvd);
00361   virtual const char *toString();
00362 
00363  private:
00364 
00365 };/* class GPRMC */
00366 #endif /*_NMEA_H_*/

Generated on Tue Jul 15 13:10:21 2008 for Benthic Imaging AUV by  doxygen 1.5.4