Garmin GPS 17HVS Technical Specifications - Page 29

Sample C Code

Page 29 highlights

Sample C Code DLE and ETX bytes: Sample C code to receive the two records should filter DLE and ETX bytes as described below: typedef enum { DAT, DLE, ETX } rx_state_type; /* Declare and initialize static variables */ static char in_que[ 256 ]; static int in_que_ptr = 0; static rx_state_type rx_state = DAT; . . . void add_to_que( char data ) { #define DLE_BYTE 0x10 #define ETX_BYTE 0x03 if ( rx_state == DAT ) { if ( data == DLE_BYTE ) { rx_state = DLE; } else { in_que[ in_que_ptr++ ] = data; } } else if ( rx_state == DLE ) { if ( data == ETX_BYTE ) { rx_state = ETX; } else { rx_state = DAT; in_que[ in_que_ptr++ ] = data; } } else if ( rx_state == ETX ) { if ( data == DLE_BYTE ) { rx_state = DLE; } } if ( in_que_ptr > 255 ) { in_que_ptr = 0; } } 190-00228-21 GPS 16/17 Technical Specifications Page 25 Rev. A

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37

190-00228-21
GPS 16/17 Technical Specifications
Rev. A
Page 25
Sample C Code
DLE and ETX bytes:
Sample C code to receive the two records should filter DLE and ETX bytes as described below:
typedef enum
{
DAT,
DLE,
ETX
} rx_state_type;
/* Declare and initialize static variables */
static char
in_que[ 256 ];
static int
in_que_ptr = 0;
static rx_state_type rx_state = DAT;
.
.
.
void add_to_que( char data )
{
#define DLE_BYTE 0x10
#define ETX_BYTE 0x03
if ( rx_state == DAT )
{
if ( data == DLE_BYTE )
{
rx_state = DLE;
}
else
{
in_que[ in_que_ptr++ ] = data;
}
}
else if ( rx_state == DLE )
{
if ( data == ETX_BYTE )
{
rx_state = ETX;
}
else
{
rx_state = DAT;
in_que[ in_que_ptr++ ] = data;
}
}
else if ( rx_state == ETX )
{
if ( data == DLE_BYTE )
{
rx_state = DLE;
}
}
if ( in_que_ptr > 255 )
{
in_que_ptr = 0;
}
}