gps-code restructured, i2c gps now working
This commit is contained in:
parent
bf30092f54
commit
ebc3aac991
@ -55,6 +55,7 @@ extern std::array<uint64_t, 0xff>::iterator it;
|
|||||||
extern std::array<uint64_t, 0xff> beacons;
|
extern std::array<uint64_t, 0xff> beacons;
|
||||||
|
|
||||||
#ifdef HAS_GPS
|
#ifdef HAS_GPS
|
||||||
|
extern TaskHandle_t GpsTask;
|
||||||
#include "gps.h"
|
#include "gps.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
41
src/gps.cpp
41
src/gps.cpp
@ -25,19 +25,23 @@ void gps_loop(void *pvParameters) {
|
|||||||
// initialize and, if needed, configure, GPS
|
// initialize and, if needed, configure, GPS
|
||||||
#if defined GPS_SERIAL
|
#if defined GPS_SERIAL
|
||||||
HardwareSerial GPS_Serial(1);
|
HardwareSerial GPS_Serial(1);
|
||||||
GPS_Serial.begin(GPS_SERIAL); // serial connect to GPS device
|
GPS_Serial.begin(GPS_SERIAL);
|
||||||
|
|
||||||
#elif defined GPS_QUECTEL_L76
|
#elif defined GPS_QUECTEL_L76
|
||||||
|
uint8_t ret;
|
||||||
Wire.begin(GPS_QUECTEL_L76, 400000); // I2C connect to GPS device with 400 KHz
|
Wire.begin(GPS_QUECTEL_L76, 400000); // I2C connect to GPS device with 400 KHz
|
||||||
uint8_t i2c_ret;
|
|
||||||
Wire.beginTransmission(GPS_ADDR);
|
Wire.beginTransmission(GPS_ADDR);
|
||||||
Wire.write(0x00); // dummy write to start read
|
Wire.write(0x00); // dummy write
|
||||||
i2c_ret = Wire.endTransmission(); // check if chip is seen on i2c bus
|
ret = Wire.endTransmission(); // check if chip is seen on i2c bus
|
||||||
|
|
||||||
if (i2c_ret) {
|
if (ret) {
|
||||||
ESP_LOGE(TAG, "Quectel L76 GPS chip not found on i2c bus, bus error %d",
|
ESP_LOGE(TAG,
|
||||||
i2c_ret);
|
"Quectel L76 GPS chip not found on i2c bus, bus error %d. "
|
||||||
return;
|
"Stopping GPS-Task.",
|
||||||
|
ret);
|
||||||
|
vTaskDelete(GpsTask);
|
||||||
|
} else {
|
||||||
|
ESP_LOGI(TAG, "Quectel L76 GPS chip found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -46,31 +50,18 @@ void gps_loop(void *pvParameters) {
|
|||||||
|
|
||||||
if (cfg.gpsmode) {
|
if (cfg.gpsmode) {
|
||||||
#if defined GPS_SERIAL
|
#if defined GPS_SERIAL
|
||||||
|
|
||||||
while (cfg.gpsmode) {
|
|
||||||
// feed GPS decoder with serial NMEA data from GPS device
|
// feed GPS decoder with serial NMEA data from GPS device
|
||||||
while (GPS_Serial.available()) {
|
while (GPS_Serial.available()) {
|
||||||
gps.encode(GPS_Serial.read());
|
gps.encode(GPS_Serial.read());
|
||||||
}
|
}
|
||||||
vTaskDelay(2 / portTICK_PERIOD_MS); // reset watchdog
|
|
||||||
}
|
|
||||||
// after GPS function was disabled, close connect to GPS device
|
|
||||||
GPS_Serial.end();
|
|
||||||
|
|
||||||
#elif defined GPS_QUECTEL_L76
|
#elif defined GPS_QUECTEL_L76
|
||||||
|
Wire.requestFrom(GPS_ADDR, 32); // caution: this is a blocking call
|
||||||
while (cfg.gpsmode) {
|
|
||||||
Wire.requestFrom(GPS_ADDR,
|
|
||||||
128); // 128 is Wire.h buffersize arduino-ESP32
|
|
||||||
while (Wire.available()) {
|
while (Wire.available()) {
|
||||||
gps.encode(Wire.read());
|
gps.encode(Wire.read());
|
||||||
vTaskDelay(2 / portTICK_PERIOD_MS); // delay see L76 datasheet
|
vTaskDelay(2 / portTICK_PERIOD_MS); // 2ms delay according L76 datasheet
|
||||||
}
|
|
||||||
vTaskDelay(2 / portTICK_PERIOD_MS); // reset watchdog
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // GPS Type
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
} // if (cfg.gpsmode)
|
||||||
|
|
||||||
vTaskDelay(2 / portTICK_PERIOD_MS); // reset watchdog
|
vTaskDelay(2 / portTICK_PERIOD_MS); // reset watchdog
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ void get_hard_deveui(uint8_t *pdeveui) {
|
|||||||
i2c_ret = Wire.endTransmission();
|
i2c_ret = Wire.endTransmission();
|
||||||
|
|
||||||
// check if device was seen on i2c bus
|
// check if device was seen on i2c bus
|
||||||
if (ic2_ret == 0) {
|
if (i2c_ret == 0) {
|
||||||
char deveui[32] = "";
|
char deveui[32] = "";
|
||||||
uint8_t data;
|
uint8_t data;
|
||||||
|
|
||||||
|
16
src/main.cpp
16
src/main.cpp
@ -52,6 +52,10 @@ TaskHandle_t LoraTask = NULL;
|
|||||||
QueueHandle_t SPISendQueue;
|
QueueHandle_t SPISendQueue;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAS_GPS
|
||||||
|
TaskHandle_t GpsTask = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
portMUX_TYPE timerMux =
|
portMUX_TYPE timerMux =
|
||||||
portMUX_INITIALIZER_UNLOCKED; // sync main loop and ISR when modifying IRQ
|
portMUX_INITIALIZER_UNLOCKED; // sync main loop and ISR when modifying IRQ
|
||||||
// handler shared variables
|
// handler shared variables
|
||||||
@ -280,7 +284,7 @@ void setup() {
|
|||||||
// (note: arduino main loop runs on core 1, too)
|
// (note: arduino main loop runs on core 1, too)
|
||||||
// https://techtutorialsx.com/2017/05/09/esp32-get-task-execution-core/
|
// https://techtutorialsx.com/2017/05/09/esp32-get-task-execution-core/
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Starting Lora task on core 1");
|
ESP_LOGI(TAG, "Starting Lora...");
|
||||||
xTaskCreatePinnedToCore(lorawan_loop, "loraloop", 2048, (void *)1,
|
xTaskCreatePinnedToCore(lorawan_loop, "loraloop", 2048, (void *)1,
|
||||||
(5 | portPRIVILEGE_BIT), &LoraTask, 1);
|
(5 | portPRIVILEGE_BIT), &LoraTask, 1);
|
||||||
#endif
|
#endif
|
||||||
@ -289,22 +293,20 @@ void setup() {
|
|||||||
// higher priority than wifi channel rotation task since we process serial
|
// higher priority than wifi channel rotation task since we process serial
|
||||||
// streaming NMEA data
|
// streaming NMEA data
|
||||||
#ifdef HAS_GPS
|
#ifdef HAS_GPS
|
||||||
if (cfg.gpsmode) {
|
ESP_LOGI(TAG, "Starting GPS...");
|
||||||
ESP_LOGI(TAG, "Starting GPS task on core 0");
|
xTaskCreatePinnedToCore(gps_loop, "gpsloop", 2048, (void *)1, 2, &GpsTask, 0);
|
||||||
xTaskCreatePinnedToCore(gps_loop, "gpsloop", 2048, (void *)1, 2, NULL, 0);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// start BLE scan callback if BLE function is enabled in NVRAM configuration
|
// start BLE scan callback if BLE function is enabled in NVRAM configuration
|
||||||
#ifdef BLECOUNTER
|
#ifdef BLECOUNTER
|
||||||
if (cfg.blescan) {
|
if (cfg.blescan) {
|
||||||
ESP_LOGI(TAG, "Starting BLE task on core 1");
|
ESP_LOGI(TAG, "Starting Bluetooth...");
|
||||||
start_BLEscan();
|
start_BLEscan();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// start wifi in monitor mode and start channel rotation task on core 0
|
// start wifi in monitor mode and start channel rotation task on core 0
|
||||||
ESP_LOGI(TAG, "Starting Wifi task on core 0");
|
ESP_LOGI(TAG, "Starting Wifi...");
|
||||||
wifi_sniffer_init();
|
wifi_sniffer_init();
|
||||||
// initialize salt value using esp_random() called by random() in
|
// initialize salt value using esp_random() called by random() in
|
||||||
// arduino-esp32 core. Note: do this *after* wifi has started, since
|
// arduino-esp32 core. Note: do this *after* wifi has started, since
|
||||||
|
Loading…
Reference in New Issue
Block a user