Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

# STX/ETX Packet Protocol Library (stxetx.c)
[General Libraries]

## Detailed Description

     #include "stxetx.h"

Overview
  This library provides functions needed to transmit and receive STX/ETX packets over any interface which can send and receive bytes. STX/ETX is a simple packet protocol for serial data streams and offers packetization, type tagging, and checksum protection for user data. Common uses of STX/ETX might include radio communications were it can improve data reliability over lossy channels. STX/ETX may also be used effectively anywhere multiple access to the communication medium is required. The packets can be made to contain destination addresses or routing information as well as data.

STX/ETX Details
  STX/ETX is a simple packet protocol that can be wrapped around user data for one or more of the following reasons: 1. packetization is needed
  - Using packets can be helpful if your data naturally forms little "bunches" or if different types of data must be sent over the same channel (a serial cable, for example). If your data forms "bunches", you can send user data inside STX/ETX packets with a predetermined structure, like an array of A/D conversion results. If you need a way to tell the receiver what kind of data you're sending, you can use the TYPE field in the STX/ETX packet. 2. error checking is needed
  - STX/ETX packets will add a checksum to your data. This allows the receiver to verify that data was received correctly and is error-free. Packets which are corrupted in transmission and fail the the checksum test are automatically discarded. Error checking is especially useful when the data transmission channel is unreliable or noisy (examples: radio, infrared, long cables, etc)

STX/ETX packets have the following structure:

[STX][status][type][length][user data...][checksum][ETX]

All fields are 1 byte except for user data which may be 0-255 bytes. Uppercase fields are constant (STX=0x02, ETX=0x03), lowercase fields vary. The length field is the number of bytes in the user data area. The checksum is the 8-bit sum of all bytes between but not including STX/ETX.

## Defines
#define | STX 0x02
#define | ETX 0x03
#define | STXETX_HEADERLENGTH 4
#define | STXETX_TRAILERLENGTH 2
#define | STXETX_STATUSOFFSET 1
#define | STXETX_TYPEOFFSET 2
#define | STXETX_LENGTHOFFSET 3
#define | STXETX_DATAOFFSET 4
#define | STXETX_CHECKSUMOFFSET 4
#define | STXETX_NOETXSTXCHECKSUM 3
## Functions
void | stxetxInit (void(*dataout_func)(unsigned char data))
| Initialize STX/ETX packet protocol library.
void | stxetxSend (unsigned char status, unsigned char type, unsigned char datalength, unsigned char *dataptr)
| Send/Create STX/ETX packet.
unsigned char | stxetxProcess (cBuffer *rxBuffer)
| Process a buffer containing STX/ETX packets.
unsigned char | stxetxGetRxPacketStatus (void)
| Returns the received packet's status.
unsigned char | stxetxGetRxPacketType (void)
| Returns the received packet's type.
unsigned char | stxetxGetRxPacketDatalength (void)
| Returns the received packet's datalength.
unsigned char * | stxetxGetRxPacketData (void)
| Returns pointer to the received packet's data.