DMU380SA Series
User’s Manual
________________________________________________________________________
Doc# 7430-0026 Rev. 01
Page 82
12
Appendix C. Sample Packet-Parser Code
Overview
12.1
This appendix includes sample code written in ANSI C for parsing packets from data sent
by the DMU380SA Series Inertial Systems. This code can be used by a user application
reading data directly from the DMU380SA Series product, or perhaps from a log file.
The sample code contains the actual parser, but also several support functions for CRC
calculation and circular queue access.:
process_xbow_packet
–
for parsing out packets from a queue. Returns these
fields in structure XBOW_PACKET (see below). Checks for CRC errors
calcCRC
–
for calculating CRC on packets.
Initialize - initialize the queue
AddQueue - add item in front of queue
DeleteQueue - return an item from the queue
peekWord - for retrieving 2-bytes from the queue, without popping
peekByte
–
for retrieving a byte from the queue without popping
Pop - discard item(s) from queue
Size
–
returns number of items in queue
Empty
–
return 1 if queue is empty, 0 if not
Full - return 1 if full, 0 if not full
The parser will parse the queue looking for packets. Once a packet is found and the CRC
checks out, the packet’s fields are placed in the XBOW_PACKET structure. The parser
will then return to the caller. When no packets are found the parser will simply return to
the caller with return value 0.
The XBOW_PACKET stucture is defined as follows:
typedef struct xbow_packet
{
unsigned short packet_type;
char
length;
unsigned short crc;
char
data[256];
} XBOW_PACKET;
Typically, the parser would be called within a loop in a separate process, or in some time
triggered environment, reading the queue looking for packets. A separate process might
add data to this queue when it arrives. It is up to the user to ensure circular-queue
integrity by using some sort of mutual exclusion mechanism withing the queue access
funtions.