beautypg.com

NavCom Sapphire Rev.J User Manual

Page 393

background image

Sapphire Technical Reference Manual Rev. J

393

#define BACK_SPACE 0x08

ParseState parser;
char ch;
int mnemonic_len;
int msg_len;
int expected_msg_len;
int crc_count;

parser = GET_LEFT_BRACE; // initial state, look for “[“


LOOP
{
ch = retrieve one byte from receiving port

// Process the next input character based on the current state
switch( parser )
{
case GET_LEFT_BRACE:
if( ch == '[' )
{
parser = GET_MNEMONIC;
mnemonic_len = 0;
msg_len = 0;
}

break;

case GET_MNEMONIC:
if( ch == ']' )
{
// Got a right brace, try to match mnemonic string
if(

mnemonic matches “PVT1B” )

{
msg_body will hold PVT1B message
will process later
}

parser = GET_LEN1;
}
else if( ch is not ascii_char )
{
Error handling here
}
else if( mnemonic_len >= MAX_MNEMONIC_LEN-1 )
{
// Too many characters in the mnemonic
Error handling;
}
else
{
// Save this character on the end of the mnemonic string and
// add null terminator after it.
mnemonic[mnemonic_len] = ch;
mnemonic_len++;
mnemonic[mnemonic_len] = 0;
}
break;