GPS NMEA protocol parser.
More...
Detailed Description
Files: nmea.h & nmea.c
- See also:
- http://en.wikipedia.org/wiki/NMEA_0183
Function Documentation
- Parameters:
-
| tx_byte | Pointer to a function that will be called to transmit a byte. |
| on_valid_str | Pointer to a function that will be called when a valid NMEA string has been received. |
| on_valid_gps_data | Pointer to a function that will be called when the data structure has been completely polulated with valid data. |
Definition at line 402 of file nmea.c.
00405 {
00406
00407 nmea_tx_byte_fn = tx_byte;
00408 nmea_on_valid_str_fn = on_valid_str;
00409 nmea_on_valid_gps_data_fn = on_valid_gps_data;
00410
00411
00412 nmea_rx_state = NMEA_RX_STATE_START;
00413 nmea_rx_index = 0;
00414 nmea_data.gga_valid_flag = FALSE;
00415 nmea_data.vtg_valid_flag = FALSE;
00416 }
| void nmea_on_rx_byte |
( |
u8_t |
data |
) |
|
- Parameters:
-
| [in] | data | received 8-bit data |
Definition at line 418 of file nmea.c.
00419 {
00420 switch(nmea_rx_state)
00421 {
00422 case NMEA_RX_STATE_START :
00423 {
00424
00425 if(data != '$')
00426 {
00427 break;
00428 }
00429 nmea_rx_state = NMEA_RX_STATE_PAYLOAD;
00430
00431 nmea_rx_checksum = 0;
00432 nmea_rx_index = 0;
00433 return;
00434 }
00435 case NMEA_RX_STATE_PAYLOAD :
00436 {
00437
00438 if( (data == '$' )
00439 ||(data == '\r')
00440 ||(data == '\n')
00441 ||(data >= 0x80) )
00442 {
00443 break;
00444 }
00445
00446 if(data == '*')
00447 {
00448 nmea_rx_state = NMEA_RX_STATE_CHECKSUM1;
00449 return;
00450 }
00451
00452 nmea_rx_checksum ^= data;
00453
00454 nmea_rx_buffer[nmea_rx_index] = data;
00455
00456 if (++nmea_rx_index >= (NMEA_BUFFER_SIZE-1))
00457 {
00458 break;
00459 }
00460 return;
00461 }
00462 case NMEA_RX_STATE_CHECKSUM1 :
00463 {
00464
00465 if(!nmea_cmp_nibble_with_hex_ascii(((nmea_rx_checksum>>4)&0x0f), data))
00466 {
00467 break;
00468 }
00469
00470 nmea_rx_state = NMEA_RX_STATE_CHECKSUM2;
00471 return;
00472 }
00473 case NMEA_RX_STATE_CHECKSUM2 :
00474 {
00475
00476 if(!nmea_cmp_nibble_with_hex_ascii((nmea_rx_checksum&0x0f),data))
00477 {
00478 break;
00479 }
00480
00481 nmea_rx_state = NMEA_RX_STATE_END_CR;
00482 return;
00483 }
00484 case NMEA_RX_STATE_END_CR :
00485 {
00486
00487 if(data != '\r')
00488 {
00489 break;
00490 }
00491 nmea_rx_state = NMEA_RX_STATE_END_LF;
00492 return;
00493 }
00494 case NMEA_RX_STATE_END_LF:
00495 {
00496
00497 if(data != '\n')
00498 {
00499 break;
00500 }
00501
00502 nmea_rx_buffer[nmea_rx_index] = '\0';
00503
00504 nmea_on_rx_frame((char*)nmea_rx_buffer);
00505 break;
00506 }
00507 }
00508
00509 nmea_rx_state = NMEA_RX_STATE_START;
00510 }
| void nmea_tx_frame |
( |
char * |
frame |
) |
|
- Parameters:
-
| frame | Pointer to zero terminated string. |
Definition at line 512 of file nmea.c.
00513 {
00514 u8_t data;
00515 u8_t checksum = '$';
00516
00517
00518 while(*frame)
00519 {
00520 data = *frame++;
00521 checksum ^= data;
00522 nmea_tx_byte(data);
00523 }
00524
00525
00526 nmea_tx_byte('*');
00527
00528 if(checksum<0xA0)
00529 {
00530 nmea_tx_byte(((checksum>>4)&0x0f)+'0');
00531 }
00532 else
00533 {
00534 nmea_tx_byte(((checksum>>4)&0x0f)+('A'-10));
00535 }
00536
00537 checksum &=0x0f;
00538 if(checksum<0x0A)
00539 {
00540 nmea_tx_byte(checksum+'0');
00541 }
00542 else
00543 {
00544 nmea_tx_byte(checksum+('A'-10));
00545 }
00546
00547
00548 nmea_tx_byte('\r');
00549 nmea_tx_byte('\n');
00550 }