Main Page | Data Structures | File List | Data Fields | Globals

nmeap.h

Go to the documentation of this file.
00001 /* 00002 Copyright (c) 2005, David M Howard (daveh at dmh2000.com) 00003 All rights reserved. 00004 00005 This product is licensed for use and distribution under the BSD Open Source License. 00006 see the file COPYING for more details. 00007 00008 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00009 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00010 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00011 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00012 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 00013 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00014 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 00015 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 00016 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 00017 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00018 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00019 00020 */ 00021 00022 #ifndef __NMEAP_H__ 00023 #define __NMEAP_H__ 00024 00025 /* 00026 ============================================ 00027 COMPILE TIME CONFIGURATION CONSTANTS 00028 ============================================ 00029 */ 00030 00031 /* these constants affect the size of the context object. tweak them as desired but know what you are doing */ 00032 00033 /** maximum number of sentence parsers supported */ 00034 #define NMEAP_MAX_SENTENCES 8 00035 /** length of sentence name. leave this at 5 unless you really know what you are doing */ 00036 #define NMEAP_MAX_SENTENCE_NAME_LENGTH 5 00037 /** max length of a complete sentence. the standard says 82 bytes, but its probably better to go at least 128 since 00038 * some units don't adhere to the 82 bytes especially for proprietary sentences */ 00039 #define NMEAP_MAX_SENTENCE_LENGTH 255 00040 /** max tokens in one sentence. 24 is enough for any standard sentence */ 00041 #define NMEAP_MAX_TOKENS 24 00042 00043 /* predefined message ID's */ 00044 00045 /* GGA MESSAGE ID */ 00046 #define NMEAP_GPGGA 1 00047 /* RMC MESSAGE ID */ 00048 #define NMEAP_GPRMC 2 00049 00050 /** user defined parsers should make ID numbers using NMEAP_USER as the base value, plus some increment */ 00051 #define NMEAP_USER 100 00052 00053 /* forward references */ 00054 struct nmeap_context; 00055 struct nmeap_sentence; 00056 00057 /* 00058 ============================================ 00059 CALLOUTS 00060 ============================================ 00061 */ 00062 00063 /** 00064 * sentence callout function type 00065 * a callout is fired for each registered sentence type 00066 * the callout gets the object context and a pointer to sentence specific data. 00067 * the callout must cast the 'sentence_data' to the appropriate type for that callout 00068 * @param context nmea object context 00069 * @param sentence_data sentence specific data 00070 */ 00071 typedef void (*nmeap_callout_t)(struct nmeap_context *context,void *sentence_data,void *user_data); 00072 00073 /** 00074 * sentence parser function type 00075 * stored in the object context and called internally when the sentence name matches 00076 * the specified value 00077 * the callout gets the object context and a pointer to sentence specific data. 00078 * the callout must cast the 'sentence_data' to the appropriate type for that callout 00079 * @param context nmea object context 00080 * @param sentence_data sentence specific data 00081 * @return id of sentence (each sentence parser knows its own ID) 00082 */ 00083 typedef int (*nmeap_sentence_parser_t)(struct nmeap_context *context,struct nmeap_sentence *sentence); 00084 00085 00086 /* ==== opaque types === */ 00087 #include "nmeap_def.h" 00088 00089 00090 /* 00091 ============================================ 00092 STANDARD SENTENCE DATA STRUCTURES 00093 ============================================ 00094 */ 00095 00096 /** extracted data from a GGA message */ 00097 struct nmeap_gga { 00098 double latitude; 00099 double longitude; 00100 double altitude; 00101 unsigned long time; 00102 int satellites; 00103 int quality; 00104 double hdop; 00105 double geoid; 00106 }; 00107 typedef struct nmeap_gga nmeap_gga_t; 00108 00109 /** extracted data from an RMC message */ 00110 struct nmeap_rmc { 00111 unsigned long time; 00112 char warn; 00113 double latitude; 00114 double longitude; 00115 double speed; 00116 double course; 00117 unsigned long date; 00118 double magvar; 00119 }; 00120 00121 typedef struct nmeap_rmc nmeap_rmc_t; 00122 00123 /* 00124 ============================================ 00125 METHODS 00126 ============================================ 00127 */ 00128 00129 /** 00130 * initialize an NMEA parser. call this function to initialize a user allocated context object 00131 * @param context nmea object context. allocated by user statically or dynamically. 00132 * @param user_data pointer to user defined data 00133 * @return 0 if ok, -1 if initialization failed 00134 */ 00135 int nmeap_init(nmeap_context_t *context,void *user_data); 00136 00137 /** 00138 * register an NMEA sentence parser 00139 * @param context nmea object context 00140 * @param sentence_name string matching the sentence name for this parser. e.g. "GPGGA". not including the '$' 00141 * @param sentence_parser parser function for this sentence 00142 * @param sentence_callout callout triggered when this sentence is received and parsed. 00143 * if null, no callout is triggered for this sentence 00144 * @param sentence_data user allocated sentence specific data defined by the application. the parser uses 00145 this data item to store the extracted data. This data object needs to persist over the life 00146 of the parser, so be careful if allocated on the stack. 00147 * @return 0 if registered ok, -1 if registration failed 00148 */ 00149 int nmeap_addParser(nmeap_context_t *context, 00150 const char *sentence_name, 00151 nmeap_sentence_parser_t sentence_parser, 00152 nmeap_callout_t sentence_callout, 00153 void *sentence_data 00154 ); 00155 00156 /** 00157 * parse a buffer of nmea data. 00158 * @param context nmea object context 00159 * @param buffer buffer of input characters 00160 * @param length [in,out] pointer to length of buffer. on return, contains number of characters not used for 00161 * the current sentence 00162 * @return -1 if error, 0 if the data did not complete a sentence, sentence code if a sentence was found in the stream 00163 */ 00164 int nmeap_parseBuffer(nmeap_context_t *context,const char *buffer,int *length); 00165 00166 /** 00167 * parse one character of nmea data. 00168 * @param context nmea object context 00169 * @param ch input character 00170 * @return -1 if error, 0 if the data did not complete a sentence, sentence code if a sentence was found in the stream 00171 */ 00172 int nmeap_parse(nmeap_context_t *context,char ch); 00173 00174 00175 /** 00176 * built-in parser for GGA sentences. 00177 * @param context nmea object context 00178 * @param sentence sentence object for this parser 00179 */ 00180 int nmeap_gpgga(nmeap_context_t *context,nmeap_sentence_t *sentence); 00181 00182 /** 00183 * built-in parser for RMC sentences. 00184 * @param context nmea object context 00185 * @param sentence sentence object for this parser 00186 */ 00187 int nmeap_gprmc(nmeap_context_t *context,nmeap_sentence_t *sentence); 00188 00189 /** 00190 * extract latitude from 2 tokens in ddmm.mmmm,h format. 00191 * @param plat pointer to token with numerical latitude 00192 * @param phem pointer to token with hemisphere 00193 * @return latitude in degrees and fractional degrees 00194 */ 00195 double nmeap_latitude(const char *plat,const char *phem); 00196 00197 00198 /** 00199 * extract longitude from 2 tokens in ddmm.mmmm,h format. 00200 * @param plat pointer to token with numerical longitude 00201 * @param phem pointer to token with hemisphere 00202 * @return longitude in degrees and fractional degrees 00203 */ 00204 double nmeap_longitude(const char *plat,const char *phem); 00205 00206 #endif 00207

Generated on Tue May 10 20:02:02 2005 for NMEAP by doxygen 1.3.8