?? tsip_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: tsip.c Source File</title><link href="dox.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.6 --><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="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a></div><h1>tsip.c</h1><a href="tsip_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre>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 <avr/io.h></span>00024 <span class="preprocessor"> #include <avr/pgmspace.h></span>00025 <span class="preprocessor"> #include <math.h></span>00026 <span class="preprocessor"> #include <stdlib.h></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<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<dataIdx; i++)00093 TsipTxByteFunc(TsipPacket[i]);00094 }00095 00096 u08 tsipProcess(cBuffer* 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->datalength > 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="buffer_8h.html#a4">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="buffer_8h.html#a4">bufferGetAtIndex</a>(rxBuffer,1);00114 <span class="keywordflow">if</span>((data != DLE) && (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="buffer_8h.html#a2">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<(rxBuffer->datalength)-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="buffer_8h.html#a4">bufferGetAtIndex</a>(rxBuffer,i) == DLE) && (<a class="code" href="buffer_8h.html#a4">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="buffer_8h.html#a2">bufferGetFromFront</a>(rxBuffer);00138 <span class="comment">// copy data to TsipPacket</span>00139 TsipPacketIdx = 0;00140 <span class="keywordflow">for</span>(j=0; j<(i-1); j++)00141 {00142 data = <a class="code" href="buffer_8h.html#a2">bufferGetFromFront</a>(rxBuffer);00143 <span class="keywordflow">if</span>(data == DLE)00144 {00145 <span class="keywordflow">if</span>(<a class="code" href="buffer_8h.html#a4">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="buffer_8h.html#a2">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="buffer_8h.html#a2">bufferGetFromFront</a>(rxBuffer);00156 <a class="code" href="buffer_8h.html#a2">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<TsipPacketIdx; k++)00166 {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -