⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tsip_8c-source.html

📁 avr应用测试程序
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!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: tsip.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&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div><h1>tsip.c</h1><a href="tsip_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file tsip.c \brief TSIP (Trimble Standard Interface Protocol) function library. */</span>00002 <span class="comment">//*****************************************************************************</span>00003 <span class="comment">//</span>00004 <span class="comment">// File Name    : 'tsip.c'</span>00005 <span class="comment">// Title        : TSIP (Trimble Standard Interface Protocol) function library</span>00006 <span class="comment">// Author       : Pascal Stang - Copyright (C) 2002-2003</span>00007 <span class="comment">// Created      : 2002.08.27</span>00008 <span class="comment">// Revised      : 2003.07.17</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 &lt;avr/io.h&gt;</span>00024 <span class="preprocessor">    #include &lt;avr/pgmspace.h&gt;</span>00025 <span class="preprocessor">    #include &lt;math.h&gt;</span>00026 <span class="preprocessor">    #include &lt;stdlib.h&gt;</span>00027 <span class="preprocessor">#endif</span>00028 <span class="preprocessor"></span>00029 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>00030 <span class="preprocessor">#include "<a class="code" href="buffer_8h.html">buffer.h</a>"</span>00031 <span class="preprocessor">#include "<a class="code" href="rprintf_8h.html">rprintf.h</a>"</span>00032 <span class="preprocessor">#include "<a class="code" href="uart2_8h.html">uart2.h</a>"</span>00033 <span class="preprocessor">#include "<a class="code" href="gps_8h.html">gps.h</a>"</span>00034 00035 <span class="preprocessor">#include "<a class="code" href="tsip_8h.html">tsip.h</a>"</span>00036 00037 <span class="comment">// Program ROM constants</span>00038 00039 <span class="comment">// Global variables</span>00040 <span class="keyword">extern</span> GpsInfoType GpsInfo;00041 <span class="preprocessor">#define BUFFERSIZE 0x40</span>00042 <span class="preprocessor"></span>u08 TsipPacket[BUFFERSIZE];00043 u08 debug;00044 00045 <span class="comment">// function pointer to single byte output routine</span>00046 <span class="keyword">static</span> void (*TsipTxByteFunc)(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c);00047 00048 <span class="keywordtype">void</span> tsipInit(<span class="keywordtype">void</span> (*txbytefunc)(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c))00049 {00050     <span class="comment">// set transmit function</span>00051     <span class="comment">// (this function will be used for all SendPacket commands)</span>00052     TsipTxByteFunc = txbytefunc;00053 00054     <span class="comment">// set debug status</span>00055     debug = 0;00056 00057     <span class="comment">// compose GPS receiver configuration packet</span>00058     u08 packet[4];00059     packet[0] = BV(POS_LLA);00060     packet[1] = BV(VEL_ENU);00061     packet[2] = 0;00062     packet[3] = 0;00063     <span class="comment">// send configuration</span>00064     tsipSendPacket(TSIPTYPE_SET_IO_OPTIONS, 4, packet);00065 }00066 00067 <span class="keywordtype">void</span> tsipSendPacket(u08 tsipType, u08 dataLength, u08* data)00068 {00069     u08 i;00070     u08 dataIdx = 0;00071 00072     <span class="comment">// start of packet</span>00073     TsipPacket[dataIdx++] = DLE;00074     <span class="comment">// packet type</span>00075     TsipPacket[dataIdx++] = tsipType;00076     <span class="comment">// add packet data</span>00077     <span class="keywordflow">for</span>(i=0; i&lt;dataLength; i++)00078     {00079         <span class="keywordflow">if</span>(*data == DLE)00080         {00081             <span class="comment">// do double-DLE escape sequence</span>00082             TsipPacket[dataIdx++] = *data;00083             TsipPacket[dataIdx++] = *data++;00084         }00085         <span class="keywordflow">else</span>00086             TsipPacket[dataIdx++] = *data++;00087     }00088     <span class="comment">// end of packet</span>00089     TsipPacket[dataIdx++] = DLE;00090     TsipPacket[dataIdx++] = ETX;00091 00092     <span class="keywordflow">for</span>(i=0; i&lt;dataIdx; i++)00093         TsipTxByteFunc(TsipPacket[i]);00094 }00095 00096 u08 tsipProcess(<a class="code" href="structstruct__cBuffer.html">cBuffer</a>* rxBuffer)00097 {00098     u08 foundpacket = FALSE;00099     u08 startFlag = FALSE;00100     u08 data;00101     u08 i,j,k;00102 00103     u08 TsipPacketIdx;00104     00105     <span class="comment">// process the receive buffer</span>00106     <span class="comment">// go through buffer looking for packets</span>00107     <span class="keywordflow">while</span>(rxBuffer-&gt;<a class="code" href="structstruct__cBuffer.html#o2">datalength</a> &gt; 1)00108     {00109         <span class="comment">// look for a potential start of TSIP packet</span>00110         <span class="keywordflow">if</span>(<a class="code" href="group__buffer.html#ga4">bufferGetAtIndex</a>(rxBuffer,0) == DLE)00111         {00112             <span class="comment">// make sure the next byte is not DLE or ETX</span>00113             data = <a class="code" href="group__buffer.html#ga4">bufferGetAtIndex</a>(rxBuffer,1);00114             <span class="keywordflow">if</span>((data != DLE) &amp;&amp; (data != ETX))00115             {00116                 <span class="comment">// found potential start</span>00117                 startFlag = TRUE;00118                 <span class="comment">// done looking for start</span>00119                 <span class="keywordflow">break</span>;00120             }00121         }00122         <span class="keywordflow">else</span>00123             <span class="comment">// not DLE, dump character from buffer</span>00124             <a class="code" href="group__buffer.html#ga2">bufferGetFromFront</a>(rxBuffer);00125     }00126     00127     <span class="comment">// if we detected a start, look for end of packet</span>00128     <span class="keywordflow">if</span>(startFlag)00129     {00130         <span class="keywordflow">for</span>(i=1; i&lt;(rxBuffer-&gt;<a class="code" href="structstruct__cBuffer.html#o2">datalength</a>)-1; i++)00131         {00132             <span class="comment">// check for potential end of TSIP packet</span>00133             <span class="keywordflow">if</span>((<a class="code" href="group__buffer.html#ga4">bufferGetAtIndex</a>(rxBuffer,i) == DLE) &amp;&amp; (<a class="code" href="group__buffer.html#ga4">bufferGetAtIndex</a>(rxBuffer,i+1) == ETX))00134             {00135                 <span class="comment">// have a packet end</span>00136                 <span class="comment">// dump initial DLE</span>00137                 <a class="code" href="group__buffer.html#ga2">bufferGetFromFront</a>(rxBuffer);00138                 <span class="comment">// copy data to TsipPacket</span>00139                 TsipPacketIdx = 0;00140                 <span class="keywordflow">for</span>(j=0; j&lt;(i-1); j++)00141                 {00142                     data = <a class="code" href="group__buffer.html#ga2">bufferGetFromFront</a>(rxBuffer);00143                     <span class="keywordflow">if</span>(data == DLE)00144                     {00145                         <span class="keywordflow">if</span>(<a class="code" href="group__buffer.html#ga4">bufferGetAtIndex</a>(rxBuffer,0) == DLE)00146                         {00147                             <span class="comment">// found double-DLE escape sequence, skip one of them</span>00148                             <a class="code" href="group__buffer.html#ga2">bufferGetFromFront</a>(rxBuffer);00149                             j++;00150                         }00151                     }00152                     TsipPacket[TsipPacketIdx++] = data;00153                 }00154                 <span class="comment">// dump ending DLE+ETX</span>00155                 <a class="code" href="group__buffer.html#ga2">bufferGetFromFront</a>(rxBuffer);00156                 <a class="code" href="group__buffer.html#ga2">bufferGetFromFront</a>(rxBuffer);00157 00158                 <span class="comment">// found a packet</span>00159                 <span class="keywordflow">if</span>(debug)00160                 {00161                     rprintf(<span class="stringliteral">"Rx TSIP packet type: 0x%x  len: %d  rawlen: %d\r\n"</span>,00162                         TsipPacket[0],00163                         TsipPacketIdx,00164                         i);00165                     <span class="keywordflow">for</span>(k=0; k&lt;TsipPacketIdx; k++)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -