From 485b4fb2f04ce0e837df390bb4a19dc4f4b88bc9 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 9 Jun 2018 22:21:23 +0200 Subject: [PATCH] GPS support (experimental) --- src/globals.h | 2 +- src/gpsread.cpp | 16 +++++++--------- src/lorawan.cpp | 2 +- src/main.cpp | 6 +++++- src/rcommand.cpp | 6 ++---- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/globals.h b/src/globals.h index 711f0bd9..cb7b720f 100644 --- a/src/globals.h +++ b/src/globals.h @@ -53,8 +53,8 @@ typedef struct { typedef struct { float latitude; float longitude; - float hdop; uint8_t satellites; + uint16_t hdop; uint16_t altitude; } gpsStatus_t; extern gpsStatus_t gps_status; // struct for storing gps data diff --git a/src/gpsread.cpp b/src/gpsread.cpp index 6669b80b..99c3b02e 100644 --- a/src/gpsread.cpp +++ b/src/gpsread.cpp @@ -5,18 +5,16 @@ // Local logging tag static const char TAG[] = "main"; -// GPS read data to global struct +// read GPS data and cast to global struct void gps_read(){ - gps_status.latitude = (float) gps.location.lat(); - gps_status.longitude = (float) gps.location.lng(); - gps_status.satellites = (uint8_t) gps.satellites.value(); - gps_status.hdop = (float) gps.hdop.value(); - gps_status.altitude = (uint16_t) gps.altitude.meters(); - ESP_LOGI(TAG, "Lat: %f / Lon: %f", gps_status.latitude, gps_status.longitude); - ESP_LOGI(TAG, "Sats: %d / HDOP: %f / Alti: %d", gps_status.satellites, gps_status.hdop, gps_status.altitude); + gps_status.latitude = (float) gps.location.lat(); + gps_status.longitude = (float) gps.location.lng(); + gps_status.satellites = (uint8_t) gps.satellites.value(); + gps_status.hdop = (uint16_t) gps.hdop.value(); + gps_status.altitude = (uint16_t) gps.altitude.meters(); } -/// GPS serial feed FreeRTos Task +// GPS serial feed FreeRTos Task void gps_loop(void * pvParameters) { configASSERT( ( ( uint32_t ) pvParameters ) == 1 ); // FreeRTOS check diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 24f7cb1d..c2565e22 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -138,7 +138,7 @@ void do_send(osjob_t* j){ if (cfg.gpsmode && gps.location.isValid()) { gps_read(); LMIC_setTxData2(GPSPORT, (byte*)&gps_status, sizeof(gps_status), (cfg.countermode & 0x02)); - ESP_LOGI(TAG, "HDOP=%d, SATS=%d, LAT=%d, LON=%d", gps_status.hdop, gps_status.satellites, gps_status.latitude, gps_status.longitude ); + ESP_LOGI(TAG, "HDOP=%d, SATS=%d, LAT=%f, LON=%f", gps_status.hdop, gps_status.satellites, gps_status.latitude, gps_status.longitude ); } #endif diff --git a/src/main.cpp b/src/main.cpp index 4ab492d5..e722ad72 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -470,6 +470,10 @@ void setup() { ESP_LOGI(TAG, "ESP32 SDK: %s", ESP.getSdkVersion()); #endif +#ifdef HAS_GPS + ESP_LOGI(TAG, "TinyGPS+ version %s", TinyGPSPlus::libraryVersion()); +#endif + // read settings from NVRAM loadConfig(); // includes initialize if necessary @@ -583,7 +587,7 @@ xTaskCreatePinnedToCore(sniffer_loop, "wifisniffer", 2048, ( void * ) 1, 1, NULL #ifdef HAS_GPS if (cfg.gpsmode) { ESP_LOGI(TAG, "Starting GPS task on core 0"); - xTaskCreatePinnedToCore(gps_loop, "gpsreader", 2048, ( void * ) 1, 1, NULL, 0); + xTaskCreatePinnedToCore(gps_loop, "gpsfeed", 2048, ( void * ) 1, 1, NULL, 0); } #endif diff --git a/src/rcommand.cpp b/src/rcommand.cpp index 926795a5..de2ec09a 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -262,14 +262,12 @@ void get_gps (uint8_t val) { #ifdef HAS_GPS gps_read(); transmit((byte*)&gps_status, sizeof(gps_status)); - ESP_LOGI(TAG, "HDOP=%d, SATS=%d, LAT=%d, LON=%d", gps_status.hdop, gps_status.satellites, gps_status.latitude, gps_status.longitude ); + ESP_LOGI(TAG, "HDOP=%d, SATS=%d, LAT=%f, LON=%f", gps_status.hdop, gps_status.satellites, gps_status.latitude, gps_status.longitude ); #else - ESP_LOGE(TAG, "No GPS device present"); + ESP_LOGE(TAG, "GPS not present"); #endif - }; - // assign previously defined functions to set of numeric remote commands // format: opcode, function, flag (1 = do make settings persistent / 0 = don't) //