📄 nmea_8c-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Procyon AVRlib: nmea.c Source File</title><link href="dox.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.4.2 --><div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a></div><h1>nmea.c</h1><a href="nmea_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file nmea.c \brief NMEA protocol function library. */</span>00002 <span class="comment">//*****************************************************************************</span>00003 <span class="comment">//</span>00004 <span class="comment">// File Name : 'nmea.c'</span>00005 <span class="comment">// Title : NMEA protocol function library</span>00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2002</span>00007 <span class="comment">// Created : 2002.08.27</span>00008 <span class="comment">// Revised : 2002.08.27</span>00009 <span class="comment">// Version : 0.1</span>00010 <span class="comment">// Target MCU : Atmel AVR Series</span>00011 <span class="comment">// Editor Tabs : 4</span>00012 <span class="comment">//</span>00013 <span class="comment">// NOTE: This code is currently below version 1.0, and therefore is considered</span>00014 <span class="comment">// to be lacking in some functionality or documentation, or may not be fully</span>00015 <span class="comment">// tested. Nonetheless, you can expect most functions to work.</span>00016 <span class="comment">//</span>00017 <span class="comment">// This code is distributed under the GNU Public License</span>00018 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span>00019 <span class="comment">//</span>00020 <span class="comment">//*****************************************************************************</span>00021 00022 <span class="preprocessor">#ifndef WIN32</span>00023 <span class="preprocessor"></span><span class="preprocessor"> #include <avr/io.h></span>00024 <span class="preprocessor"> #include <avr/interrupt.h></span>00025 <span class="preprocessor"> #include <avr/pgmspace.h></span>00026 <span class="preprocessor">#endif</span>00027 <span class="preprocessor"></span><span class="preprocessor">#include <string.h></span>00028 <span class="preprocessor">#include <stdlib.h></span>00029 <span class="preprocessor">#include <math.h></span>00030 00031 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>00032 <span class="preprocessor">#include "<a class="code" href="buffer_8h.html">buffer.h</a>"</span>00033 <span class="preprocessor">#include "<a class="code" href="rprintf_8h.html">rprintf.h</a>"</span>00034 <span class="preprocessor">#include "<a class="code" href="gps_8h.html">gps.h</a>"</span>00035 00036 <span class="preprocessor">#include "<a class="code" href="nmea_8h.html">nmea.h</a>"</span>00037 00038 <span class="comment">// Program ROM constants</span>00039 00040 <span class="comment">// Global variables</span>00041 <span class="keyword">extern</span> GpsInfoType GpsInfo;00042 u08 NmeaPacket[NMEA_BUFFERSIZE];00043 00044 <span class="keywordtype">void</span> nmeaInit(<span class="keywordtype">void</span>)00045 {00046 }00047 00048 u08* nmeaGetPacketBuffer(<span class="keywordtype">void</span>)00049 {00050 <span class="keywordflow">return</span> NmeaPacket;00051 }00052 00053 u08 nmeaProcess(<a class="code" href="structstruct__cBuffer.html">cBuffer</a>* rxBuffer)00054 {00055 u08 foundpacket = NMEA_NODATA;00056 u08 startFlag = FALSE;00057 <span class="comment">//u08 data;</span>00058 u16 i,j;00059 00060 <span class="comment">// process the receive buffer</span>00061 <span class="comment">// go through buffer looking for packets</span>00062 <span class="keywordflow">while</span>(rxBuffer-><a class="code" href="structstruct__cBuffer.html#o2">datalength</a>)00063 {00064 <span class="comment">// look for a start of NMEA packet</span>00065 <span class="keywordflow">if</span>(<a class="code" href="group__buffer.html#ga4">bufferGetAtIndex</a>(rxBuffer,0) == <span class="charliteral">'$'</span>)00066 {00067 <span class="comment">// found start</span>00068 startFlag = TRUE;00069 <span class="comment">// when start is found, we leave it intact in the receive buffer</span>00070 <span class="comment">// in case the full NMEA string is not completely received. The</span>00071 <span class="comment">// start will be detected in the next nmeaProcess iteration.</span>00072 00073 <span class="comment">// done looking for start</span>00074 <span class="keywordflow">break</span>;00075 }00076 <span class="keywordflow">else</span>00077 <a class="code" href="group__buffer.html#ga2">bufferGetFromFront</a>(rxBuffer);00078 }00079 00080 <span class="comment">// if we detected a start, look for end of packet</span>00081 <span class="keywordflow">if</span>(startFlag)00082 {00083 <span class="keywordflow">for</span>(i=1; i<(rxBuffer-><a class="code" href="structstruct__cBuffer.html#o2">datalength</a>)-1; i++)00084 {00085 <span class="comment">// check for end of NMEA packet <CR><LF></span>00086 <span class="keywordflow">if</span>((<a class="code" href="group__buffer.html#ga4">bufferGetAtIndex</a>(rxBuffer,i) == <span class="charliteral">'\r'</span>) && (<a class="code" href="group__buffer.html#ga4">bufferGetAtIndex</a>(rxBuffer,i+1) == <span class="charliteral">'\n'</span>))00087 {00088 <span class="comment">// have a packet end</span>00089 <span class="comment">// dump initial '$'</span>00090 <a class="code" href="group__buffer.html#ga2">bufferGetFromFront</a>(rxBuffer);00091 <span class="comment">// copy packet to NmeaPacket</span>00092 <span class="keywordflow">for</span>(j=0; j<(i-1); j++)00093 {00094 <span class="comment">// although NMEA strings should be 80 characters or less,</span>00095 <span class="comment">// receive buffer errors can generate erroneous packets.</span>00096 <span class="comment">// Protect against packet buffer overflow</span>00097 <span class="keywordflow">if</span>(j<(NMEA_BUFFERSIZE-1))00098 NmeaPacket[j] = <a class="code" href="group__buffer.html#ga2">bufferGetFromFront</a>(rxBuffer);00099 <span class="keywordflow">else</span>00100 <a class="code" href="group__buffer.html#ga2">bufferGetFromFront</a>(rxBuffer);00101 }00102 <span class="comment">// null terminate it</span>00103 NmeaPacket[j] = 0;00104 <span class="comment">// dump <CR><LF> from rxBuffer</span>00105 <a class="code" href="group__buffer.html#ga2">bufferGetFromFront</a>(rxBuffer);00106 <a class="code" href="group__buffer.html#ga2">bufferGetFromFront</a>(rxBuffer);00107 00108 <span class="preprocessor"> #ifdef NMEA_DEBUG_PKT</span>00109 <span class="preprocessor"></span> rprintf(<span class="stringliteral">"Rx NMEA packet type: "</span>);00110 <a class="code" href="group__rprintf.html#ga3">rprintfStrLen</a>(NmeaPacket, 0, 5);00111 <a class="code" href="group__rprintf.html#ga3">rprintfStrLen</a>(NmeaPacket, 5, (i-1)-5);00112 <a class="code" href="group__rprintf.html#ga5">rprintfCRLF</a>();00113 <span class="preprocessor"> #endif</span>00114 <span class="preprocessor"></span> <span class="comment">// found a packet</span>00115 <span class="comment">// done with this processing session</span>00116 foundpacket = NMEA_UNKNOWN;00117 <span class="keywordflow">break</span>;00118 }00119 }00120 }00121 00122 <span class="keywordflow">if</span>(foundpacket)00123 {00124 <span class="comment">// check message type and process appropriately</span>00125 <span class="keywordflow">if</span>(!strncmp(NmeaPacket, <span class="stringliteral">"GPGGA"</span>, 5))00126 {00127 <span class="comment">// process packet of this type</span>00128 nmeaProcessGPGGA(NmeaPacket);00129 <span class="comment">// report packet type</span>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -