NavCom Sapphire Rev.J User Manual

Page 394

Advertising
background image

Sapphire Technical Reference Manual Rev. J

394



case GET_LEN1:
msg_body[0] = ch;
msg_len = 1;
parser = GET_LEN2;
break;

case GET_LEN2:
msg_body[1] = ch;
msg_len = 2;

expected_msg_len = (int)(msg_body[0] | ((unsigned int)ch<<8));

if ( expected_msg_len > MAX_INPUT_MSG_BODY_LEN)
{
Error handling;
}
// Message length includes the 2 length field, so minimum value is 2
else if (expected_msg_len < 3)
{
parser = GET_CRC16_START;
}
else
{
parser = GET_MSG_BODY;
}
break;

case GET_MSG_BODY:
msg_body[msg_len] = ch;
msg_len++;
if (msg_len >= expected_msg_len)
parser = GET_CRC16_START;
break;

case GET_CRC16_START:
if (ch == '*')
{
parser = GET_CRC16;

crc_count = 0;
}
break;
case GET_CRC16:
if( ch == CARRIAGE_RETURN && crc_count == 4)
{
// check crc

Set flag “PARSE_COMPLETED_OK” if crc is correct

}
else if( ch == BACK_SPACE )
{
// Got a backspace, delete last arg string character
if( crc_count > 0 )
{
crc_count--;
crc_str[crc_count] = 0;

Advertising