int carmen_gps_parse_data( char * line, int num_chars ) { if (num_chars >= 6) { if ((strncmp("$GPGGA", line, 6) == 0) || (strncmp("$GNGGA", line, 6) == 0)) { return(gps_parse_gga(line, num_chars)); } else if (strncmp("$GPHDT", line, 6) == 0) { return(gps_parse_hdt(line, num_chars)); } else if ((strncmp("$GPRMC", line, 6) == 0) || (strncmp("$GNRMC", line, 6) == 0)) { return(gps_parse_rmc(line, num_chars)); } } return(FALSE); }
void gps_task(void *pArg) { char rx_sentence[200]; char *data_ptr; uint32_t len; uint32_t notificationValue; PRINTF("from gps task...\r\n"); /* Use Task Notification to sychronize between UART Rx handler and GPS task */ xGpsTaskHandle = xTaskGetCurrentTaskHandle(); /* Initialize UART driver with given parameters */ UART_Init(GPS_UART_BASE, &gps_uart_config, GPS_UART_SRCCLK); /* Initialize UART driver and install our own handler for UART Rx data, which is called by the ISR */ UART_TransferCreateHandle(GPS_UART_BASE, &gps_uart_handle, gps_uart_rx_handler, NULL); /* Set receive buffer pointer explicitly for custom handling */ gps_uart_handle.rxData = gps_rx_buf; gps_uart_handle.rxDataSize = 1; /* Enable RX interrupt (start reception of bytes from GPS module) */ UART_EnableInterrupts(GPS_UART_BASE, kUART_RxDataRegFullInterruptEnable | kUART_RxOverrunInterruptEnable); /* Turn on RED LED */ while (1) { /* Wait for notification from UART Rx handler */ if((notificationValue = ulTaskNotifyTake(pdTRUE, portMAX_DELAY)) == 1) { /* Copy the received sentence */ len = gps_rx_len; memcpy((void *) rx_sentence, (void *) gps_rx_sentence, len); /* Parse the received sentence to update gps_info structure */ if (NULL != strstr(rx_sentence, "GPGGA")) { data_ptr = &rx_sentence[6]; gps_parse_gga(data_ptr, &gps_info); } if ((NULL != strstr(rx_sentence, "GPRMC")) || (NULL != strstr(rx_sentence, "GNRMC"))) { data_ptr = &rx_sentence[6]; gps_parse_rmc(data_ptr, &gps_info); } } /* Check for GPS Fix */ if (NO_FIX != gps_info.fix) { /* Turn on GREEN LED */ LED_GREEN_ON(); } else { /* Turn off GREEN LED */ LED_GREEN_OFF(); } } }
void gps_parse(Usart * c_uart) { uint8_t c = c_uart->Read(); // DEBUG("%c", c); switch (gps_parser_state) { case(GPS_IDLE): if (c == '$') { gps_parser_buffer_index = 0; gps_checksum = 0; gps_parser_state = GPS_DATA; } // else // { // gps_parser_buffer_index++; // if (gps_parser_buffer_index > 10) // { // gps_set_baudrate(); // gps_change_uart_baudrate(); // gps_parser_buffer_index = 0; // } // } break; case(GPS_DATA): if (c == '*') { gps_parser_buffer[gps_parser_buffer_index] = c; gps_parser_buffer_index++; gps_parser_state = GPS_CRC; } else { gps_checksum ^= c; gps_parser_buffer[gps_parser_buffer_index] = c; gps_parser_buffer_index++; } if (gps_parser_buffer_index >= NMEA_MAX_LEN) { assert(0); gps_parser_buffer_index = 0; gps_parser_state = GPS_IDLE; } break; case(GPS_CRC): gps_rx_checksum = hex_to_num(c) << 4; gps_parser_buffer[gps_parser_buffer_index] = c; gps_parser_buffer_index++; gps_parser_state = GPS_END; break; case(GPS_END): gps_rx_checksum += hex_to_num(c); gps_parser_buffer[gps_parser_buffer_index] = c; gps_parser_buffer[gps_parser_buffer_index + 1] = '\n'; gps_parser_buffer[gps_parser_buffer_index + 2] = '\0'; gps_parser_buffer_index = 0; gps_parser_state = GPS_IDLE; // DEBUG(">>%s<<\n", gps_parser_buffer); if (gps_rx_checksum == gps_checksum) { if (cmpn_p(gps_parser_buffer, PSTR("GP"), 2)) { gps_parser_ptr = gps_parser_buffer + 2; if (cmpn_p(gps_parser_ptr, PSTR("RMC"), 3)) gps_parse_rmc(); if (cmpn_p(gps_parser_ptr, PSTR("GGA"), 3)) gps_parse_gga(); if (cmpn_p(gps_parser_ptr, PSTR("GSA"), 3)) gps_parse_gsa(); if (cmpn_p(gps_parser_ptr, PSTR("GSV"), 3)) gps_parse_gsv(); } else if (cmpn_p(gps_parser_buffer, PSTR("PMTK"), 4)) { gps_parser_ptr = gps_parser_buffer + 4; if (cmpn_p(gps_parser_ptr, PSTR("011"), 3)) gps_parse_hello(); if (cmpn_p(gps_parser_ptr, PSTR("010"), 3)) gps_parse_sys(); } } else { DEBUG(">>%s<<\n", gps_parser_buffer); DEBUG("GPS CHECKSUM IS WRONG! %02X %02X\n", gps_rx_checksum, gps_checksum); } break; } }