Moog Crossbow NAV440 Series User Manual
Page 110

Page 110
NAV440 User Manual
7430‐0131‐01 Rev. F
user to ensure circular‐queue integrity by using some sort of mutual exclusion mechanism within the queue access
functions.
Code Listing#include <stdio.h>
/* buffer size */
#define MAXQUEUE 500
/*
* circular queue
*/
typedef struct queue_tag
{
int
count;
int
front;
int
rear;
char
entry(MAXQUEUE);
} QUEUE_TYPE;
/*
* Moog Crossbow packet
*/
typedef struct xbow_packet
{
unsigned
short
packet_type;
char
length;
unsigned
short
crc;
char
data(256);
} XBOW_PACKET;
QUEUE_TYPE circ_buf;
/*******************************************************************************
* FUNCTION: process_xbow_packet looks for packets in a queue
* ARGUMENTS: queue_ptr: is pointer to queue to process
*
result: will contain the parsed info when return value is 1
* RETURNS:
0 when failed.
*
1
when
successful
*******************************************************************************/
int process_xbow_packet(QUEUE_TYPE *queue_ptr, XBOW_PACKET *result)
{
unsigned short myCRC = 0, packetCRC = 0, packet_type = 0, numToPop=0, counter=0;
char packet(100), tempchar, dataLength;
if(Empty(queue_ptr))
{
return 0; /* empty buffer */
}
/* find header */
for(numToPop=0; numToPop+1<Size(queue_ptr) ;numToPop+=1)
{
if(0x5555==peekWord(queue_ptr,
numToPop))
break;