Line No. | Rev | Author | Line |
---|---|---|---|
1 | 6 | kaklik | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
2 | <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> |
||
3 | <title>Procyon AVRlib: stxetx.h Source File</title> |
||
4 | <link href="dox.css" rel="stylesheet" type="text/css"> |
||
5 | </head><body> |
||
6 | <!-- Generated by Doxygen 1.4.2 --> |
||
7 | <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> |
||
8 | <h1>stxetx.h</h1><a href="stxetx_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file stxetx.h \brief STX/ETX Packet Protocol Implementation Library. */</span> |
||
9 | 00002 <span class="comment">//*****************************************************************************</span> |
||
10 | 00003 <span class="comment">//</span> |
||
11 | 00004 <span class="comment">// File Name : 'stxetx.h'</span> |
||
12 | 00005 <span class="comment">// Title : STX/ETX Packet Protocol Implementation Library</span> |
||
13 | 00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2002-2003</span> |
||
14 | 00007 <span class="comment">// Created : 10/9/2002</span> |
||
15 | 00008 <span class="comment">// Revised : 02/10/2003</span> |
||
16 | 00009 <span class="comment">// Version : 0.1</span> |
||
17 | 00010 <span class="comment">// Target MCU : any</span> |
||
18 | 00011 <span class="comment">// Editor Tabs : 4</span> |
||
19 | 00012 <span class="comment">//</span><span class="comment"></span> |
||
20 | 00013 <span class="comment">/// \ingroup general</span> |
||
21 | 00014 <span class="comment">/// \defgroup stxetx STX/ETX Packet Protocol Library (stxetx.c)</span> |
||
22 | 00015 <span class="comment">/// \code #include "stxetx.h" \endcode</span> |
||
23 | 00016 <span class="comment">/// \par Overview</span> |
||
24 | 00017 <span class="comment">/// This library provides functions needed to transmit and receive STX/ETX</span> |
||
25 | 00018 <span class="comment">/// packets over any interface which can send and receive bytes. STX/ETX is a</span> |
||
26 | 00019 <span class="comment">/// simple packet protocol for serial data streams and offers packetization,</span> |
||
27 | 00020 <span class="comment">/// type tagging, and checksum protection for user data. Common uses of STX/ETX</span> |
||
28 | 00021 <span class="comment">/// might include radio communications were it can improve data reliability over</span> |
||
29 | 00022 <span class="comment">/// lossy channels. STX/ETX may also be used effectively anywhere multiple</span> |
||
30 | 00023 <span class="comment">/// access to the communication medium is required. The packets can be made</span> |
||
31 | 00024 <span class="comment">/// to contain destination addresses or routing information as well as data.</span> |
||
32 | 00025 <span class="comment">///</span> |
||
33 | 00026 <span class="comment">/// \par STX/ETX Details</span> |
||
34 | 00027 <span class="comment">/// STX/ETX is a simple packet protocol that can be wrapped around user</span> |
||
35 | 00028 <span class="comment">/// data for one or more of the following reasons:</span> |
||
36 | 00029 <span class="comment">/// 1. packetization is needed</span> |
||
37 | 00030 <span class="comment">/// - Using packets can be helpful if your data naturally forms </span> |
||
38 | 00031 <span class="comment">/// little "bunches" or if different types of data must be sent</span> |
||
39 | 00032 <span class="comment">/// over the same channel (a serial cable, for example). If your</span> |
||
40 | 00033 <span class="comment">/// data forms "bunches", you can send user data inside STX/ETX</span> |
||
41 | 00034 <span class="comment">/// packets with a predetermined structure, like an array of A/D</span> |
||
42 | 00035 <span class="comment">/// conversion results. If you need a way to tell the receiver</span> |
||
43 | 00036 <span class="comment">/// what kind of data you're sending, you can use the TYPE field</span> |
||
44 | 00037 <span class="comment">/// in the STX/ETX packet.</span> |
||
45 | 00038 <span class="comment">/// 2. error checking is needed</span> |
||
46 | 00039 <span class="comment">/// - STX/ETX packets will add a checksum to your data. This</span> |
||
47 | 00040 <span class="comment">/// allows the receiver to verify that data was received correctly</span> |
||
48 | 00041 <span class="comment">/// and is error-free. Packets which are corrupted in transmission</span> |
||
49 | 00042 <span class="comment">/// and fail the the checksum test are automatically discarded.</span> |
||
50 | 00043 <span class="comment">/// Error checking is especially useful when the data transmission</span> |
||
51 | 00044 <span class="comment">/// channel is unreliable or noisy (examples: radio, infrared, long</span> |
||
52 | 00045 <span class="comment">/// cables, etc)</span> |
||
53 | 00046 <span class="comment">/// </span> |
||
54 | 00047 <span class="comment">/// STX/ETX packets have the following structure:</span> |
||
55 | 00048 <span class="comment">///</span> |
||
56 | 00049 <span class="comment">/// [STX][status][type][length][user data...][checksum][ETX]</span> |
||
57 | 00050 <span class="comment">///</span> |
||
58 | 00051 <span class="comment">/// All fields are 1 byte except for user data which may be 0-255 bytes.</span> |
||
59 | 00052 <span class="comment">/// Uppercase fields are constant (STX=0x02, ETX=0x03), lowercase fields</span> |
||
60 | 00053 <span class="comment">/// vary. The length field is the number of bytes in the user data area.</span> |
||
61 | 00054 <span class="comment">/// The checksum is the 8-bit sum of all bytes between but not including</span> |
||
62 | 00055 <span class="comment">/// STX/ETX.</span> |
||
63 | 00056 <span class="comment"></span><span class="comment">//</span> |
||
64 | 00057 <span class="comment">// This code is distributed under the GNU Public License</span> |
||
65 | 00058 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span> |
||
66 | 00059 <span class="comment">//</span> |
||
67 | 00060 <span class="comment">//*****************************************************************************</span><span class="comment"></span> |
||
68 | 00061 <span class="comment">//@{</span> |
||
69 | 00062 <span class="comment"></span> |
||
70 | 00063 <span class="preprocessor">#ifndef STXETX_H</span> |
||
71 | 00064 <span class="preprocessor"></span><span class="preprocessor">#define STXETX_H</span> |
||
72 | 00065 <span class="preprocessor"></span> |
||
73 | 00066 <span class="preprocessor">#include "<a class="code" href="buffer_8h.html">buffer.h</a>"</span> |
||
74 | 00067 |
||
75 | 00068 <span class="comment">// include project-dependent configuration options</span> |
||
76 | 00069 <span class="preprocessor">#include "<a class="code" href="stxetxconf_8h.html">stxetxconf.h</a>"</span> |
||
77 | 00070 |
||
78 | 00071 <span class="comment">// constants</span> |
||
79 | 00072 <span class="comment">// packet markers</span> |
||
80 | 00073 <span class="preprocessor">#define STX 0x02 // start transmission marker</span> |
||
81 | 00074 <span class="preprocessor"></span><span class="preprocessor">#define ETX 0x03 // end transmission marker</span> |
||
82 | 00075 <span class="preprocessor"></span><span class="comment">// packet length parameters</span> |
||
83 | 00076 <span class="preprocessor">#define STXETX_HEADERLENGTH 4 // number of bytes required for packet header</span> |
||
84 | 00077 <span class="preprocessor"></span><span class="preprocessor">#define STXETX_TRAILERLENGTH 2 // number of bytes required for packet trailer</span> |
||
85 | 00078 <span class="preprocessor"></span><span class="comment">// packet field offsets</span> |
||
86 | 00079 <span class="preprocessor">#define STXETX_STATUSOFFSET 1 // number of bytes from STX to STATUS</span> |
||
87 | 00080 <span class="preprocessor"></span><span class="preprocessor">#define STXETX_TYPEOFFSET 2 // number of bytes from STX to TYPE</span> |
||
88 | 00081 <span class="preprocessor"></span><span class="preprocessor">#define STXETX_LENGTHOFFSET 3 // number of bytes from STX to LENGTH</span> |
||
89 | 00082 <span class="preprocessor"></span><span class="preprocessor">#define STXETX_DATAOFFSET 4 // number of bytes from STX to the data</span> |
||
90 | 00083 <span class="preprocessor"></span><span class="preprocessor">#define STXETX_CHECKSUMOFFSET 4 // number of bytes from STX+[length] to CHECKSUM</span> |
||
91 | 00084 <span class="preprocessor"></span><span class="preprocessor">#define STXETX_NOETXSTXCHECKSUM 3 // number of bytes used by STX,ETX,CHECKSUM</span> |
||
92 | 00085 <span class="preprocessor"></span> |
||
93 | 00086 |
||
94 | 00087 <span class="comment">// function prototypes</span> |
||
95 | 00088 <span class="comment"></span> |
||
96 | 00089 <span class="comment">//! Initialize STX/ETX packet protocol library</span> |
||
97 | 00090 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__stxetx.html#ga0">stxetxInit</a>(<span class="keywordtype">void</span> (*dataout_func)(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> data)); |
||
98 | 00091 <span class="comment"></span> |
||
99 | 00092 <span class="comment">//! Send/Create STX/ETX packet</span> |
||
100 | 00093 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="group__stxetx.html#ga1">stxetxSend</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> status, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> type, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> datalength, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* dataptr); |
||
101 | 00094 <span class="comment"></span> |
||
102 | 00095 <span class="comment">//! Process a buffer containing STX/ETX packets</span> |
||
103 | 00096 <span class="comment"></span><span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="group__stxetx.html#ga2">stxetxProcess</a>(<a class="code" href="structstruct__cBuffer.html">cBuffer</a>* rxBuffer); |
||
104 | 00097 <span class="comment"></span> |
||
105 | 00098 <span class="comment">//! Returns the received packet's status</span> |
||
106 | 00099 <span class="comment"></span><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>); |
||
107 | 00100 <span class="comment"></span> |
||
108 | 00101 <span class="comment">//! Returns the received packet's type</span> |
||
109 | 00102 <span class="comment"></span><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>); |
||
110 | 00103 <span class="comment"></span> |
||
111 | 00104 <span class="comment">//! Returns the received packet's datalength</span> |
||
112 | 00105 <span class="comment"></span><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>); |
||
113 | 00106 <span class="comment"></span> |
||
114 | 00107 <span class="comment">//! Returns pointer to the received packet's data</span> |
||
115 | 00108 <span class="comment"></span><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>); |
||
116 | 00109 |
||
117 | 00110 |
||
118 | 00111 <span class="preprocessor">#endif</span> |
||
119 | 00112 <span class="preprocessor"></span><span class="comment">//@}</span> |
||
120 | </span></pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:07 2006 for Procyon AVRlib by |
||
121 | <a href="http://www.doxygen.org/index.html"> |
||
122 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address> |
||
123 | </body> |
||
124 | </html> |
Powered by WebSVN v2.8.3