Instruction Manual


Page114 GNAV540UserManual
7430‐0808‐01Rev.B
AppendixB. SamplePacket—ParserCode
Overview
ThissectionincludesanexampleofcodewritteninANSICforparsingpacketsfromdatasentbytheGNAV540
InertialSystems.ThisexampleisforreadingdatadirectlyfromtheGNAV540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.
Table99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
foundtheparserreturnsthevalue0tothecaller.
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