📄 stxetx_8c-source.html
字号:
00110 {00111 <span class="comment">// if this is a start, then get the length</span>00112 length = <a class="code" href="group__buffer.html#ga4">bufferGetAtIndex</a>(rxBuffer, STXETX_LENGTHOFFSET);00113 00114 <span class="comment">// now we must have at least STXETX_HEADERLENGTH+length+STXETX_TRAILERLENGTH in buffer to continue</span>00115 <span class="keywordflow">if</span>(rxBuffer-><a class="code" href="structstruct__cBuffer.html#o2">datalength</a> >= ((u16)STXETX_HEADERLENGTH+length+(u16)STXETX_TRAILERLENGTH))00116 {00117 <span class="comment">// check to see if ETX is in the right position</span>00118 <span class="keywordflow">if</span>(<a class="code" href="group__buffer.html#ga4">bufferGetAtIndex</a>(rxBuffer, STXETX_HEADERLENGTH+length+STXETX_TRAILERLENGTH-1) == ETX)00119 {00120 <span class="comment">// found potential packet</span>00121 <span class="comment">// test checksum</span>00122 checksum = 0;00123 <span class="comment">// sum data between STX and ETX, not including checksum itself</span>00124 <span class="comment">// (u16) casting needed to avoid unsigned/signed mismatch</span>00125 <span class="keywordflow">for</span>(i = 0; i<((u16)STXETX_HEADERLENGTH+length+(u16)STXETX_TRAILERLENGTH-(u16)STXETX_NOETXSTXCHECKSUM); i++)00126 {00127 checksum += <a class="code" href="group__buffer.html#ga4">bufferGetAtIndex</a>(rxBuffer, i+STXETX_STATUSOFFSET);00128 }00129 <span class="comment">// compare checksums</span>00130 <span class="keywordflow">if</span>(checksum == <a class="code" href="group__buffer.html#ga4">bufferGetAtIndex</a>(rxBuffer, STXETX_CHECKSUMOFFSET+length))00131 {00132 <span class="comment">//we have a packet!</span>00133 foundpacket = TRUE;00134 00135 <span class="comment">// copy data to buffer</span>00136 <span class="comment">// (don't copy STX, ETX, or CHECKSUM)</span>00137 <span class="keywordflow">for</span>(i = 0; i < ((u16)STXETX_HEADERLENGTH+length-1); i++)00138 {00139 stxetxRxPacket[i] = <a class="code" href="group__buffer.html#ga4">bufferGetAtIndex</a>(rxBuffer, i+1);00140 }00141 00142 <span class="comment">// debug</span>00143 <span class="comment">//rprintf("STXETX Received packet type: 0x%x\n", bufferGetAtIndex(rxBuffer, STXETX_TYPEOFFSET));</span>00144 00145 <span class="comment">// dump this packet from the</span>00146 <a class="code" href="group__buffer.html#ga3">bufferDumpFromFront</a>(rxBuffer, STXETX_HEADERLENGTH+length+STXETX_TRAILERLENGTH);00147 00148 <span class="comment">// done with this processing session</span>00149 <span class="keywordflow">break</span>;00150 }00151 <span class="keywordflow">else</span>00152 {00153 <span class="comment">// checksum bad</span>00154 <span class="comment">//rprintf("STXETX Received packet with bad checksum\r\n");</span>00155 <span class="comment">// for now, we dump these</span>00156 <span class="comment">// dump this STX</span>00157 <a class="code" href="group__buffer.html#ga2">bufferGetFromFront</a>(rxBuffer);00158 }00159 }00160 <span class="keywordflow">else</span>00161 {00162 <span class="comment">// no ETX or ETX in wrong position</span>00163 <span class="comment">// dump this STX</span>00164 <a class="code" href="group__buffer.html#ga2">bufferGetFromFront</a>(rxBuffer);00165 }00166 }00167 <span class="keywordflow">else</span>00168 {00169 <span class="comment">// not enough data in buffer to decode pending packet</span>00170 <span class="comment">// wait until next time</span>00171 <span class="keywordflow">break</span>;00172 }00173 }00174 <span class="keywordflow">else</span>00175 {00176 <span class="comment">// this is not a start, dump it</span>00177 <a class="code" href="group__buffer.html#ga2">bufferGetFromFront</a>(rxBuffer);00178 }00179 }00180 00181 <span class="comment">// check if receive buffer is full with no packets decoding</span>00182 <span class="comment">// (ie. deadlocked on garbage data or packet that exceeds buffer size)</span>00183 <span class="keywordflow">if</span>(!<a class="code" href="group__buffer.html#ga6">bufferIsNotFull</a>(rxBuffer))00184 {00185 <span class="comment">// dump receive buffer contents to relieve deadlock</span>00186 <a class="code" href="group__buffer.html#ga7">bufferFlush</a>(rxBuffer);00187 }00188 00189 <span class="keywordflow">return</span> foundpacket;00190 }00191 <a name="l00192"></a><a class="code" href="group__stxetx.html#ga3">00192</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="group__stxetx.html#ga3">stxetxGetRxPacketStatus</a>(<span class="keywordtype">void</span>)00193 {00194 <span class="comment">// return the packet's status</span>00195 <span class="comment">// (subtract 1 from the offset because the STX has already been discarded)</span>00196 <span class="keywordflow">return</span> stxetxRxPacket[STXETX_STATUSOFFSET-1];00197 }00198 <a name="l00199"></a><a class="code" href="group__stxetx.html#ga4">00199</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="group__stxetx.html#ga4">stxetxGetRxPacketType</a>(<span class="keywordtype">void</span>)00200 {00201 <span class="comment">// return the packet's type</span>00202 <span class="comment">// (subtract 1 from the offset because the STX has already been discarded)</span>00203 <span class="keywordflow">return</span> stxetxRxPacket[STXETX_TYPEOFFSET-1];00204 }00205 <a name="l00206"></a><a class="code" href="group__stxetx.html#ga5">00206</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="group__stxetx.html#ga5">stxetxGetRxPacketDatalength</a>(<span class="keywordtype">void</span>)00207 {00208 <span class="comment">// return the packet's datalength</span>00209 <span class="comment">// (subtract 1 from the offset because the STX has already been discarded)</span>00210 <span class="keywordflow">return</span> stxetxRxPacket[STXETX_LENGTHOFFSET-1];00211 }00212 <a name="l00213"></a><a class="code" href="group__stxetx.html#ga6">00213</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* <a class="code" href="group__stxetx.html#ga6">stxetxGetRxPacketData</a>(<span class="keywordtype">void</span>)00214 {00215 <span class="comment">// return a pointer to the packet's data payload</span>00216 <span class="comment">// (subtract 1 from the offset because the STX has already been discarded)</span>00217 <span class="keywordflow">return</span> stxetxRxPacket+STXETX_DATAOFFSET-1;00218 }</pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:07 2006 for Procyon AVRlib by <a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -