|
|
4 hafta önce | |
|---|---|---|
| include | 4 hafta önce | |
| CMakeLists.txt | 4 hafta önce | |
| GPS_parser.c | 4 hafta önce | |
| README.md | 4 hafta önce | |
| idf_component.yml | 4 hafta önce |
Componente ESP-IDF para parsear frases NMEA de GPS, diseñado para módulos como el NEO-6M.
GGA y RMCEste componente requiere:
esp_driver_uartesp_timerEstas dependencias ya están declaradas en idf_component.yml.
GPS_parser.c — implementación del parser NMEAinclude/GPS_parser.h — API pública y tipos de datosCMakeLists.txt — registro del componente para ESP-IDFidf_component.yml — metadatos del componenteColoca este directorio dentro de components/ de tu proyecto ESP-IDF o agrégalo a EXTRA_COMPONENT_DIRS.
Luego incluye el header en tu aplicación:
#include "GPS_parser.h"
El componente se registrará automáticamente con idf_component_register.
#include "GPS_parser.h"
static gps_parser_t gps;
void app_main(void)
{
gps_parser_init(&gps);
// Ejemplo: procesar bytes entrantes del GPS
while (true) {
char c = obtener_byte_del_gps(); // leer del UART
if (gps_parser_encode(&gps, c)) {
if (gps_location_is_valid(&gps.location)) {
double lat = gps_location_lat(&gps.location);
double lng = gps_location_lng(&gps.location);
printf("Lat: %.8f, Lng: %.8f\n", lat, lng);
}
if (gps_date_is_valid(&gps.date) && gps_time_is_valid(&gps.time)) {
printf("Fecha: %02u/%02u/%04u Hora: %02u:%02u:%02u\n",
gps_date_day(&gps.date),
gps_date_month(&gps.date),
gps_date_year(&gps.date),
gps_time_hour(&gps.time),
gps_time_minute(&gps.time),
gps_time_second(&gps.time));
}
}
}
}
void gps_parser_init(gps_parser_t *gps);
Inicializa la estructura del parser. Debe llamarse antes de procesar cualquier byte.
bool gps_parser_encode(gps_parser_t *gps, char c);
Procesa un carácter NMEA recibido. Devuelve true cuando una sentencia completa con checksum válido ha sido recibida.
bool gps_location_is_valid(const gps_location_t *location);bool gps_location_is_updated(const gps_location_t *location);uint32_t gps_location_age(const gps_location_t *location);double gps_location_lat(const gps_location_t *location);double gps_location_lng(const gps_location_t *location);char gps_location_fix_quality(const gps_location_t *location);char gps_location_fix_mode(const gps_location_t *location);bool gps_date_is_valid(const gps_date_t *date);uint16_t gps_date_year(const gps_date_t *date);uint8_t gps_date_month(const gps_date_t *date);uint8_t gps_date_day(const gps_date_t *date);bool gps_time_is_valid(const gps_time_t *time);uint8_t gps_time_hour(const gps_time_t *time);uint8_t gps_time_minute(const gps_time_t *time);uint8_t gps_time_second(const gps_time_t *time);uint8_t gps_time_centisecond(const gps_time_t *time);bool gps_decimal_is_valid(const gps_decimal_t *value);int32_t gps_decimal_value(const gps_decimal_t *value);gps_integer_t *gps_get_satellites(gps_parser_t *gps);uint32_t gps_parser_chars_processed(const gps_parser_t *gps);uint32_t gps_parser_sentences_with_fix(const gps_parser_t *gps);uint32_t gps_parser_failed_checksum(const gps_parser_t *gps);uint32_t gps_parser_passed_checksum(const gps_parser_t *gps);Macros disponibles en GPS_parser.h:
GPS_PARSER_MPH_PER_KNOTGPS_PARSER_MPS_PER_KNOTGPS_PARSER_KMPH_PER_KNOTGPS_PARSER_MILES_PER_METERGPS_PARSER_KM_PER_METERGPS_PARSER_FEET_PER_METERGGA y RMC.gps_parser_millis() usa esp_timer_get_time() para calcular el tiempo en milisegundos.