Owner's manual


NAV440UserManual
7430‐0131‐01Rev.F
Page109
AppendixC. SamplePacket—ParserCode
Overview
ThissectionincludesanexampleofcodewritteninANSICforparsingpacketsfromdatasentbythe440Series
InertialSystems.Thisexampleisforreadingdatadirectlyfromthe440Seriesunitorfromalogfile.
SampleCode
ThesamplecodecontainstheactualparseraswellasseveralsupportfunctionsforCRCcalculationandcircular
queueaccess.
Table104CodeFunctions
Function Description
process_xbow_packet
Parseoutpacketsfromaqu
XBOW_PACKET(seebelow
eue.Returnsthesefieldsinstructure
).ChecksforCRCerrors
calcCRC CalculateCRConpackets.
Initialize Initializethequeue
AddQueue Additeminfrontofqueue
DeleteQueue Returnanitemfromthequeue
peekWord Retrieve2‐bytesfromthequeue,withoutpopping
peekByte Retrieveabytefromthequeuewithoutpopping
Pop Discarditem(s)fromqueue
Size Return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
returnvalue0.
foundtheparserwillsimplyreturntothecallerwith
TheXBOW_PACKETstructure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