2018-06-08 22:41:37 +02:00
|
|
|
#ifdef HAS_GPS
|
|
|
|
|
|
|
|
#include "globals.h"
|
|
|
|
|
|
|
|
// Local logging tag
|
|
|
|
static const char TAG[] = "main";
|
2018-06-09 17:59:59 +02:00
|
|
|
|
2018-09-20 13:23:22 +02:00
|
|
|
TinyGPSPlus gps;
|
2018-07-19 21:53:56 +02:00
|
|
|
gpsStatus_t gps_status;
|
|
|
|
|
2018-06-09 22:21:23 +02:00
|
|
|
// read GPS data and cast to global struct
|
2018-06-10 15:34:21 +02:00
|
|
|
void gps_read() {
|
2018-07-21 13:36:49 +02:00
|
|
|
gps_status.latitude = (int32_t)(gps.location.lat() * 1e6);
|
|
|
|
gps_status.longitude = (int32_t)(gps.location.lng() * 1e6);
|
2018-06-12 19:48:21 +02:00
|
|
|
gps_status.satellites = (uint8_t)gps.satellites.value();
|
|
|
|
gps_status.hdop = (uint16_t)gps.hdop.value();
|
2018-07-21 13:36:49 +02:00
|
|
|
gps_status.altitude = (int16_t)gps.altitude.meters();
|
2018-06-09 13:18:59 +02:00
|
|
|
}
|
|
|
|
|
2018-06-09 22:21:23 +02:00
|
|
|
// GPS serial feed FreeRTos Task
|
2018-06-12 19:48:21 +02:00
|
|
|
void gps_loop(void *pvParameters) {
|
|
|
|
|
|
|
|
configASSERT(((uint32_t)pvParameters) == 1); // FreeRTOS check
|
|
|
|
|
|
|
|
// initialize and, if needed, configure, GPS
|
|
|
|
#if defined GPS_SERIAL
|
|
|
|
HardwareSerial GPS_Serial(1);
|
2018-09-20 19:36:32 +02:00
|
|
|
GPS_Serial.begin(GPS_SERIAL);
|
2018-09-20 17:33:52 +02:00
|
|
|
|
2018-06-17 16:25:29 +02:00
|
|
|
#elif defined GPS_QUECTEL_L76
|
2018-09-20 19:36:32 +02:00
|
|
|
uint8_t ret;
|
2018-06-17 19:03:49 +02:00
|
|
|
Wire.begin(GPS_QUECTEL_L76, 400000); // I2C connect to GPS device with 400 KHz
|
2018-09-20 17:33:52 +02:00
|
|
|
Wire.beginTransmission(GPS_ADDR);
|
2018-09-20 19:36:32 +02:00
|
|
|
Wire.write(0x00); // dummy write
|
|
|
|
ret = Wire.endTransmission(); // check if chip is seen on i2c bus
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
ESP_LOGE(TAG,
|
|
|
|
"Quectel L76 GPS chip not found on i2c bus, bus error %d. "
|
|
|
|
"Stopping GPS-Task.",
|
|
|
|
ret);
|
|
|
|
vTaskDelete(GpsTask);
|
|
|
|
} else {
|
|
|
|
ESP_LOGI(TAG, "Quectel L76 GPS chip found.");
|
2018-09-20 17:33:52 +02:00
|
|
|
}
|
|
|
|
|
2018-06-12 19:48:21 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
|
|
|
|
if (cfg.gpsmode) {
|
|
|
|
#if defined GPS_SERIAL
|
2018-09-20 19:36:32 +02:00
|
|
|
// feed GPS decoder with serial NMEA data from GPS device
|
|
|
|
while (GPS_Serial.available()) {
|
|
|
|
gps.encode(GPS_Serial.read());
|
2018-06-12 19:48:21 +02:00
|
|
|
}
|
2018-06-17 16:25:29 +02:00
|
|
|
#elif defined GPS_QUECTEL_L76
|
2018-09-20 19:36:32 +02:00
|
|
|
Wire.requestFrom(GPS_ADDR, 32); // caution: this is a blocking call
|
|
|
|
while (Wire.available()) {
|
|
|
|
gps.encode(Wire.read());
|
|
|
|
vTaskDelay(2 / portTICK_PERIOD_MS); // 2ms delay according L76 datasheet
|
2018-06-12 19:48:21 +02:00
|
|
|
}
|
2018-09-20 19:36:32 +02:00
|
|
|
#endif
|
|
|
|
} // if (cfg.gpsmode)
|
2018-06-12 19:48:21 +02:00
|
|
|
|
2018-09-21 12:25:52 +02:00
|
|
|
vTaskDelay(2 / portTICK_PERIOD_MS); // yield to CPU
|
2018-06-12 19:48:21 +02:00
|
|
|
|
|
|
|
} // end of infinite loop
|
2018-06-09 19:20:34 +02:00
|
|
|
|
|
|
|
} // gps_loop()
|
2018-06-12 19:48:21 +02:00
|
|
|
|
2018-06-08 22:41:37 +02:00
|
|
|
#endif // HAS_GPS
|