INTRODUCTION
Overview
Download and Install
Documentation
Publications

REPOSITORY
Libraries

DEVELOPER
Dev Guide
Dashboard

PEOPLE
Contributors
Users

SourceForge.net Logo
Project
Download
Mailing lists

 

         
nmeasentence.h
1/*
2 * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics
3 * http://gearbox.sf.net/
4 * Copyright (c) 2004-2010 Alex Brooks, Alexei Makarenko, Tobias Kaupp, Duncan Mercer
5 *
6 * This distribution is licensed to you under the terms described in
7 * the LICENSE file included in this distribution.
8 *
9 */
10
11#ifndef GBXGPSUTILACFR_NMEA_H
12#define GBXGPSUTILACFR_NMEA_H
13
14#include <vector>
15#include <string>
16
17/*
18
19for further info:
20
21http://www.kh-gps.de/nmea-faq.htm
22http://vancouver-webpages.com/peter/nmeafaq.txt
23
24NMEA-0183 sentence
25
26$aaccc,c--c*hh<CR><LF>
27|| || || |
28|| || || \________ <CR><LF> - End of sentence (0xOD 0xOA)
29|| || |\__________ hh - Checksum field hexadecimal [optional]
30|| || \___________ * - Checksum delimiter (0x2A) [optional]
31|| |\_______________ c--c - Data sentence block
32|| \________________ , - Field delimiter (0x2c)
33|\_____________________ aaccc - Address field/Command
34\______________________ $ - Start of sentence
35
36 The optional checksum field consists of a "*" and two hex digits
37 representing the exclusive OR of all characters between, but not
38 including, the "$" and "*". A checksum is required on some
39 sentences.
40
41*/
42
43namespace gbxgpsutilacfr {
44
45
46// class SOEXPORT NmeaException : public std::exception
47class NmeaException : public std::exception
48{
49public:
50 NmeaException(const char *message)
51 : message_(message) {}
52
53 NmeaException(const std::string &message)
54 : message_(message) {}
55
56 virtual ~NmeaException() throw() {}
57
58 virtual const char* what() const throw() { return message_.c_str(); }
59
60protected:
61 std::string message_;
62};
63
64
65#define MAX_SENTENCE_LEN 256
66
67// When using class to send data, need to add checksum, when reciving data need to test checksum
68// Checksums are usually optional
69enum NmeaSentenceOptions
70{
71 TestChecksum,
72 AddChecksum,
73 DontTestOrAddChecksum
74};
75
76// class SOEXPORT NmeaSentence{
77class NmeaSentence
78{
79public:
80 NmeaSentence();
81 NmeaSentence(const std::string &sentence, NmeaSentenceOptions addOrTestCheckSum=DontTestOrAddChecksum );
82
83 // Set up the internal data for a sentence.
84 // May throw NmeaException if TestChecksum is specified.
85 void setSentence(const std::string &data, NmeaSentenceOptions addOrTestCheckSum=DontTestOrAddChecksum );
86
87 // Do we have the raw string?
88 bool haveSentence() const { return !sentence_.empty(); };
89
90 // Do we have parsed fields?
91 bool haveTokens() const { return haveTokens_; };
92
93 // Do we have a valid checksum?
94 bool haveValidChecksum() const { return checkSumOK_; };
95
96 // Have we checked the checksum?
97 bool haveTestedChecksum()const { return haveCheckSum_; };
98
99 // calculate the checksum from sentence
100 // May throw NmeaException.
101 bool testChecksumOk();
102
103 // Return the raw sentence string
104 const std::string &sentence() const { return sentence_; };
105
106 // Return a single data token as a string.
107 // Throws an exception if that token is empty (see 'isDataTokenEmpty()')
108 const std::string &getDataToken(int i) const;
109
110 bool isDataTokenEmpty(int i) const;
111
112 // Return the number of fields
113 int numDataTokens() const { return dataTokens_.size(); };
114
115 // Tokenise the string that we received
116 void parseTokens();
117
118private:
119 void init();
120 // May throw NmeaException.
121 void addCheckSum();
122 // Have we parsed data into tokens ?
123 bool haveTokens_;
124 // Have we a checksum and is it valid?
125 bool haveCheckSum_;
126 bool checkSumOK_;
127 // The raw sentence, allow for terminator
128// char sentence_[MAX_SENTENCE_LEN+1];
129 std::string sentence_;
130 // The tokenised data
131 std::vector<std::string> dataTokens_;
132};
133
134}
135
136#endif
 

Generated for GearBox by  doxygen 1.4.5