?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 6

Line No. Rev Author Line
1 6 kaklik /*! \file stxetx.h \brief STX/ETX Packet Protocol Implementation Library. */
2 //*****************************************************************************
3 //
4 // File Name : 'stxetx.h'
5 // Title : STX/ETX Packet Protocol Implementation Library
6 // Author : Pascal Stang - Copyright (C) 2002-2003
7 // Created : 10/9/2002
8 // Revised : 02/10/2003
9 // Version : 0.1
10 // Target MCU : any
11 // Editor Tabs : 4
12 //
13 /// \ingroup general
14 /// \defgroup stxetx STX/ETX Packet Protocol Library (stxetx.c)
15 /// \code #include "stxetx.h" \endcode
16 /// \par Overview
17 /// This library provides functions needed to transmit and receive STX/ETX
18 /// packets over any interface which can send and receive bytes.  STX/ETX is a
19 /// simple packet protocol for serial data streams and offers packetization,
20 /// type tagging, and checksum protection for user data.  Common uses of STX/ETX
21 /// might include radio communications were it can improve data reliability over
22 /// lossy channels.  STX/ETX may also be used effectively anywhere multiple
23 /// access to the communication medium is required.  The packets can be made
24 /// to contain destination addresses or routing information as well as data.
25 ///
26 /// \par STX/ETX Details
27 /// STX/ETX is a simple packet protocol that can be wrapped around user
28 /// data for one or more of the following reasons:
29 /// 1. packetization is needed
30 /// - Using packets can be helpful if your data naturally forms
31 /// little "bunches" or if different types of data must be sent
32 /// over the same channel (a serial cable, for example). If your
33 /// data forms "bunches", you can send user data inside STX/ETX
34 /// packets with a predetermined structure, like an array of A/D
35 /// conversion results. If you need a way to tell the receiver
36 /// what kind of data you're sending, you can use the TYPE field
37 /// in the STX/ETX packet.
38 /// 2. error checking is needed
39 /// - STX/ETX packets will add a checksum to your data. This
40 /// allows the receiver to verify that data was received correctly
41 /// and is error-free. Packets which are corrupted in transmission
42 /// and fail the the checksum test are automatically discarded.
43 /// Error checking is especially useful when the data transmission
44 /// channel is unreliable or noisy (examples: radio, infrared, long
45 /// cables, etc)
46 ///
47 /// STX/ETX packets have the following structure:
48 ///
49 /// [STX][status][type][length][user data...][checksum][ETX]
50 ///
51 /// All fields are 1 byte except for user data which may be 0-255 bytes.
52 /// Uppercase fields are constant (STX=0x02, ETX=0x03), lowercase fields
53 /// vary. The length field is the number of bytes in the user data area.
54 /// The checksum is the 8-bit sum of all bytes between but not including
55 /// STX/ETX.
56 //
57 // This code is distributed under the GNU Public License
58 // which can be found at http://www.gnu.org/licenses/gpl.txt
59 //
60 //*****************************************************************************
61 //@{
62  
63 #ifndef STXETX_H
64 #define STXETX_H
65  
66 #include "buffer.h"
67  
68 // include project-dependent configuration options
69 #include "stxetxconf.h"
70  
71 // constants
72 // packet markers
73 #define STX 0x02 // start transmission marker
74 #define ETX 0x03 // end transmission marker
75 // packet length parameters
76 #define STXETX_HEADERLENGTH 4 // number of bytes required for packet header
77 #define STXETX_TRAILERLENGTH 2 // number of bytes required for packet trailer
78 // packet field offsets
79 #define STXETX_STATUSOFFSET 1 // number of bytes from STX to STATUS
80 #define STXETX_TYPEOFFSET 2 // number of bytes from STX to TYPE
81 #define STXETX_LENGTHOFFSET 3 // number of bytes from STX to LENGTH
82 #define STXETX_DATAOFFSET 4 // number of bytes from STX to the data
83 #define STXETX_CHECKSUMOFFSET 4 // number of bytes from STX+[length] to CHECKSUM
84 #define STXETX_NOETXSTXCHECKSUM 3 // number of bytes used by STX,ETX,CHECKSUM
85  
86  
87 // function prototypes
88  
89 //! Initialize STX/ETX packet protocol library
90 void stxetxInit(void (*dataout_func)(unsigned char data));
91  
92 //! Send/Create STX/ETX packet
93 void stxetxSend(unsigned char status, unsigned char type, unsigned char datalength, unsigned char* dataptr);
94  
95 //! Process a buffer containing STX/ETX packets
96 unsigned char stxetxProcess(cBuffer* rxBuffer);
97  
98 //! Returns the received packet's status
99 unsigned char stxetxGetRxPacketStatus(void);
100  
101 //! Returns the received packet's type
102 unsigned char stxetxGetRxPacketType(void);
103  
104 //! Returns the received packet's datalength
105 unsigned char stxetxGetRxPacketDatalength(void);
106  
107 //! Returns pointer to the received packet's data
108 unsigned char* stxetxGetRxPacketData(void);
109  
110  
111 #endif
112 //@}
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3