INTRODUCTION
Overview
Download and Install
Documentation
Publications

REPOSITORY
Libraries

DEVELOPER
Dev Guide
Dashboard

PEOPLE
Contributors
Users

SourceForge.net Logo
Project
Download
Mailing lists

 

         

nmea.h

00001 /*
00002  * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics
00003  *               http://gearbox.sf.net/
00004  * Copyright (c) 2004-2008  Alex Brooks, Alexei Makarenko, Tobias Kaupp, Duncan Mercer
00005  *
00006  * This distribution is licensed to you under the terms described in
00007  * the LICENSE file included in this distribution.
00008  *
00009  */
00010 
00011 #ifndef GBXGPSUTILACFR_NMEA_H
00012 #define GBXGPSUTILACFR_NMEA_H
00013 
00014 #include <vector>
00015 #include <string>
00016 
00017 /*
00018 
00019 for further info:
00020 
00021 http://www.kh-gps.de/nmea-faq.htm
00022 http://vancouver-webpages.com/peter/nmeafaq.txt
00023 
00024 NMEA-0183 sentence
00025 
00026 $aaccc,c--c*hh<CR><LF>
00027 ||    ||   || |
00028 ||    ||   || \________ <CR><LF> - End of sentence (0xOD 0xOA)
00029 ||    ||   |\__________ hh    - Checksum field hexadecimal [optional]
00030 ||    ||   \___________ *     - Checksum delimiter (0x2A) [optional]
00031 ||    |\_______________ c--c  - Data sentence block
00032 ||    \________________ ,     - Field delimiter (0x2c)
00033 |\_____________________ aaccc - Address field/Command
00034 \______________________ $     - Start of sentence
00035 
00036         The optional checksum field consists of a "*" and two hex digits
00037         representing the exclusive OR of all characters between, but not
00038         including, the "$" and "*".  A checksum is required on some
00039         sentences.
00040 
00041 */
00042 
00043 namespace gbxgpsutilacfr {
00044 
00045 
00046 // class SOEXPORT NmeaException : public std::exception
00047 class NmeaException : public std::exception
00048 {
00049 public:
00050     NmeaException(const char *message)
00051         : message_(message) {}
00052 
00053     NmeaException(const std::string &message)
00054         : message_(message) {}
00055 
00056     virtual ~NmeaException() throw() {}
00057 
00058     virtual const char* what() const throw() { return message_.c_str(); }
00059 
00060 protected:
00061     std::string  message_;
00062 };
00063 
00064 
00065 #define MAX_SENTENCE_LEN 256
00066 
00067 // When using class to send data, need to add checksum, when reciving data need to test checksum
00068 // Checksums are usually optional 
00069 enum NmeaMessageOptions
00070 {
00071     TestChecksum, 
00072     AddChecksum, 
00073     DontTestOrAddChecksum
00074 };
00075 
00076 //     class SOEXPORT NmeaMessage{
00077 class NmeaMessage
00078 {
00079 public:
00080     NmeaMessage();
00081     NmeaMessage(const char *sentence, int testCheckSum=DontTestOrAddChecksum );
00082 
00083     // Set up the internal data for a sentence.
00084     // May throw NmeaException if TestChecksum is specified.
00085     void setSentence(const char *data, int testCheckSum=DontTestOrAddChecksum );
00086 
00087     // Do we only have the raw string?
00088     bool haveSentence() const { return haveSentence_; };
00089 
00090     // Do we have parsed fields?
00091     bool haveTokens() const { return haveTokens_; };
00092 
00093     // Do we have a valid checksum?
00094     bool haveValidChecksum() const { return checkSumOK_; };  
00095   
00096     // Have we checked the checksum?
00097     bool haveTestedChecksum()const { return haveCheckSum_; };  
00098   
00099     // calculate the checksum from sentence
00100     // May throw NmeaException.
00101     bool testChecksumOk();
00102 
00103     // Return the raw sentence string
00104     const char* sentence() { return sentence_; };
00105 
00106     // Return a single data token as a string
00107     std::string& getDataToken(int i) { return dataTokens_[i]; };
00108 
00109     // Return the number of fields
00110     int numDataTokens() const { return dataTokens_.size(); };
00111 
00112     //Tokenise the string that we received
00113     void parseTokens();
00114 
00115 private:
00116     void init();
00117     // May throw NmeaException.
00118     void addCheckSum();
00119     // Do we only have the raw string ?
00120     bool haveSentence_;
00121     // Have we parsed data into tokens ?
00122     bool haveTokens_;
00123     // Have we a checksum and is it valid?
00124     bool haveCheckSum_;
00125     bool checkSumOK_;
00126     // The raw sentence, allow for terminator
00127     char sentence_[MAX_SENTENCE_LEN+1];
00128     // The tokenised data
00129     std::vector<std::string> dataTokens_;
00130 };
00131 
00132 }
00133 
00134 #endif
 

Generated for GearBox by  doxygen 1.4.5