mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-21 10:12:50 +00:00
Do slightly better at threading the search for GPS hardware (#8240)
* Do slightly better at threading the search for GPS hardware * Formatting and minor logic fix * Remove now-spam GPS Log messages --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
This commit is contained in:
@@ -506,10 +506,9 @@ bool GPS::setup()
|
|||||||
delay(1000);
|
delay(1000);
|
||||||
#endif
|
#endif
|
||||||
if (probeTries < GPS_PROBETRIES) {
|
if (probeTries < GPS_PROBETRIES) {
|
||||||
LOG_DEBUG("Probe for GPS at %d", serialSpeeds[speedSelect]);
|
|
||||||
gnssModel = probe(serialSpeeds[speedSelect]);
|
gnssModel = probe(serialSpeeds[speedSelect]);
|
||||||
if (gnssModel == GNSS_MODEL_UNKNOWN) {
|
if (gnssModel == GNSS_MODEL_UNKNOWN) {
|
||||||
if (++speedSelect == array_count(serialSpeeds)) {
|
if (currentStep == 0 && ++speedSelect == array_count(serialSpeeds)) {
|
||||||
speedSelect = 0;
|
speedSelect = 0;
|
||||||
++probeTries;
|
++probeTries;
|
||||||
}
|
}
|
||||||
@@ -518,10 +517,9 @@ bool GPS::setup()
|
|||||||
// Rare Serial Speeds
|
// Rare Serial Speeds
|
||||||
#ifndef CONFIG_IDF_TARGET_ESP32C6
|
#ifndef CONFIG_IDF_TARGET_ESP32C6
|
||||||
if (probeTries == GPS_PROBETRIES) {
|
if (probeTries == GPS_PROBETRIES) {
|
||||||
LOG_DEBUG("Probe for GPS at %d", rareSerialSpeeds[speedSelect]);
|
|
||||||
gnssModel = probe(rareSerialSpeeds[speedSelect]);
|
gnssModel = probe(rareSerialSpeeds[speedSelect]);
|
||||||
if (gnssModel == GNSS_MODEL_UNKNOWN) {
|
if (gnssModel == GNSS_MODEL_UNKNOWN) {
|
||||||
if (++speedSelect == array_count(rareSerialSpeeds)) {
|
if (currentStep == 0 && ++speedSelect == array_count(rareSerialSpeeds)) {
|
||||||
LOG_WARN("Give up on GPS probe and set to %d", GPS_BAUDRATE);
|
LOG_WARN("Give up on GPS probe and set to %d", GPS_BAUDRATE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1094,7 +1092,7 @@ int32_t GPS::runOnce()
|
|||||||
return disable();
|
return disable();
|
||||||
}
|
}
|
||||||
if (!setup())
|
if (!setup())
|
||||||
return 2000; // Setup failed, re-run in two seconds
|
return currentDelay; // Setup failed, re-run in two seconds
|
||||||
|
|
||||||
// We have now loaded our saved preferences from flash
|
// We have now loaded our saved preferences from flash
|
||||||
if (config.position.gps_mode != meshtastic_Config_PositionConfig_GpsMode_ENABLED) {
|
if (config.position.gps_mode != meshtastic_Config_PositionConfig_GpsMode_ENABLED) {
|
||||||
@@ -1218,6 +1216,10 @@ static const char *DETECTED_MESSAGE = "%s detected";
|
|||||||
|
|
||||||
GnssModel_t GPS::probe(int serialSpeed)
|
GnssModel_t GPS::probe(int serialSpeed)
|
||||||
{
|
{
|
||||||
|
uint8_t buffer[768] = {0};
|
||||||
|
|
||||||
|
switch (currentStep) {
|
||||||
|
case 0: {
|
||||||
#if defined(ARCH_NRF52) || defined(ARCH_PORTDUINO) || defined(ARCH_STM32WL)
|
#if defined(ARCH_NRF52) || defined(ARCH_PORTDUINO) || defined(ARCH_STM32WL)
|
||||||
_serial_gps->end();
|
_serial_gps->end();
|
||||||
_serial_gps->begin(serialSpeed);
|
_serial_gps->begin(serialSpeed);
|
||||||
@@ -1227,13 +1229,12 @@ GnssModel_t GPS::probe(int serialSpeed)
|
|||||||
_serial_gps->begin(serialSpeed);
|
_serial_gps->begin(serialSpeed);
|
||||||
#else
|
#else
|
||||||
if (_serial_gps->baudRate() != serialSpeed) {
|
if (_serial_gps->baudRate() != serialSpeed) {
|
||||||
LOG_DEBUG("Set Baud to %i", serialSpeed);
|
LOG_DEBUG("Set GPS Baud to %i", serialSpeed);
|
||||||
_serial_gps->updateBaudRate(serialSpeed);
|
_serial_gps->updateBaudRate(serialSpeed);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
memset(&ublox_info, 0, sizeof(ublox_info));
|
memset(&ublox_info, 0, sizeof(ublox_info));
|
||||||
uint8_t buffer[768] = {0};
|
|
||||||
delay(100);
|
delay(100);
|
||||||
|
|
||||||
// Close all NMEA sentences, valid for L76K, ATGM336H (and likely other AT6558 devices)
|
// Close all NMEA sentences, valid for L76K, ATGM336H (and likely other AT6558 devices)
|
||||||
@@ -1248,19 +1249,31 @@ GnssModel_t GPS::probe(int serialSpeed)
|
|||||||
_serial_gps->write("$CFGMSG,0,1,0,1*1B\r\n");
|
_serial_gps->write("$CFGMSG,0,1,0,1*1B\r\n");
|
||||||
_serial_gps->write("$CFGMSG,0,2,0,1*18\r\n");
|
_serial_gps->write("$CFGMSG,0,2,0,1*18\r\n");
|
||||||
_serial_gps->write("$CFGMSG,0,3,0,1*19\r\n");
|
_serial_gps->write("$CFGMSG,0,3,0,1*19\r\n");
|
||||||
delay(20);
|
currentDelay = 20;
|
||||||
|
currentStep = 1;
|
||||||
|
return GNSS_MODEL_UNKNOWN;
|
||||||
|
}
|
||||||
|
case 1: {
|
||||||
|
|
||||||
// Unicore UFirebirdII Series: UC6580, UM620, UM621, UM670A, UM680A, or UM681A,or CM121
|
// Unicore UFirebirdII Series: UC6580, UM620, UM621, UM670A, UM680A, or UM681A,or CM121
|
||||||
std::vector<ChipInfo> unicore = {
|
std::vector<ChipInfo> unicore = {
|
||||||
{"UC6580", "UC6580", GNSS_MODEL_UC6580}, {"UM600", "UM600", GNSS_MODEL_UC6580}, {"CM121", "CM121", GNSS_MODEL_CM121}};
|
{"UC6580", "UC6580", GNSS_MODEL_UC6580}, {"UM600", "UM600", GNSS_MODEL_UC6580}, {"CM121", "CM121", GNSS_MODEL_CM121}};
|
||||||
PROBE_FAMILY("Unicore Family", "$PDTINFO", unicore, 500);
|
PROBE_FAMILY("Unicore Family", "$PDTINFO", unicore, 500);
|
||||||
|
currentDelay = 20;
|
||||||
|
currentStep = 2;
|
||||||
|
return GNSS_MODEL_UNKNOWN;
|
||||||
|
}
|
||||||
|
case 2: {
|
||||||
std::vector<ChipInfo> atgm = {
|
std::vector<ChipInfo> atgm = {
|
||||||
{"ATGM336H", "$GPTXT,01,01,02,HW=ATGM336H", GNSS_MODEL_ATGM336H},
|
{"ATGM336H", "$GPTXT,01,01,02,HW=ATGM336H", GNSS_MODEL_ATGM336H},
|
||||||
/* ATGM332D series (-11(GPS), -21(BDS), -31(GPS+BDS), -51(GPS+GLONASS), -71-0(GPS+BDS+GLONASS)) based on AT6558 */
|
/* ATGM332D series (-11(GPS), -21(BDS), -31(GPS+BDS), -51(GPS+GLONASS), -71-0(GPS+BDS+GLONASS)) based on AT6558 */
|
||||||
{"ATGM332D", "$GPTXT,01,01,02,HW=ATGM332D", GNSS_MODEL_ATGM336H}};
|
{"ATGM332D", "$GPTXT,01,01,02,HW=ATGM332D", GNSS_MODEL_ATGM336H}};
|
||||||
PROBE_FAMILY("ATGM33xx Family", "$PCAS06,1*1A", atgm, 500);
|
PROBE_FAMILY("ATGM33xx Family", "$PCAS06,1*1A", atgm, 500);
|
||||||
|
currentDelay = 20;
|
||||||
|
currentStep = 3;
|
||||||
|
return GNSS_MODEL_UNKNOWN;
|
||||||
|
}
|
||||||
|
case 3: {
|
||||||
/* Airoha (Mediatek) AG3335A/M/S, A3352Q, Quectel L89 2.0, SimCom SIM65M */
|
/* Airoha (Mediatek) AG3335A/M/S, A3352Q, Quectel L89 2.0, SimCom SIM65M */
|
||||||
_serial_gps->write("$PAIR062,2,0*3C\r\n"); // GSA OFF to reduce volume
|
_serial_gps->write("$PAIR062,2,0*3C\r\n"); // GSA OFF to reduce volume
|
||||||
_serial_gps->write("$PAIR062,3,0*3D\r\n"); // GSV OFF to reduce volume
|
_serial_gps->write("$PAIR062,3,0*3D\r\n"); // GSV OFF to reduce volume
|
||||||
@@ -1269,9 +1282,18 @@ GnssModel_t GPS::probe(int serialSpeed)
|
|||||||
{"AG3352", "$PAIR021,AG3352", GNSS_MODEL_AG3352},
|
{"AG3352", "$PAIR021,AG3352", GNSS_MODEL_AG3352},
|
||||||
{"RYS3520", "$PAIR021,REYAX_RYS3520_V2", GNSS_MODEL_AG3352}};
|
{"RYS3520", "$PAIR021,REYAX_RYS3520_V2", GNSS_MODEL_AG3352}};
|
||||||
PROBE_FAMILY("Airoha Family", "$PAIR021*39", airoha, 1000);
|
PROBE_FAMILY("Airoha Family", "$PAIR021*39", airoha, 1000);
|
||||||
|
currentDelay = 20;
|
||||||
|
currentStep = 4;
|
||||||
|
return GNSS_MODEL_UNKNOWN;
|
||||||
|
}
|
||||||
|
case 4: {
|
||||||
PROBE_SIMPLE("LC86", "$PQTMVERNO*58", "$PQTMVERNO,LC86", GNSS_MODEL_AG3352, 500);
|
PROBE_SIMPLE("LC86", "$PQTMVERNO*58", "$PQTMVERNO,LC86", GNSS_MODEL_AG3352, 500);
|
||||||
PROBE_SIMPLE("L76K", "$PCAS06,0*1B", "$GPTXT,01,01,02,SW=", GNSS_MODEL_MTK, 500);
|
PROBE_SIMPLE("L76K", "$PCAS06,0*1B", "$GPTXT,01,01,02,SW=", GNSS_MODEL_MTK, 500);
|
||||||
|
currentDelay = 20;
|
||||||
|
currentStep = 5;
|
||||||
|
return GNSS_MODEL_UNKNOWN;
|
||||||
|
}
|
||||||
|
case 5: {
|
||||||
|
|
||||||
// Close all NMEA sentences, valid for MTK3333 and MTK3339 platforms
|
// Close all NMEA sentences, valid for MTK3333 and MTK3339 platforms
|
||||||
_serial_gps->write("$PMTK514,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*2E\r\n");
|
_serial_gps->write("$PMTK514,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*2E\r\n");
|
||||||
@@ -1282,7 +1304,11 @@ GnssModel_t GPS::probe(int serialSpeed)
|
|||||||
{"L80", "_3339_", GNSS_MODEL_MTK_L76B}};
|
{"L80", "_3339_", GNSS_MODEL_MTK_L76B}};
|
||||||
|
|
||||||
PROBE_FAMILY("MTK Family", "$PMTK605*31", mtk, 500);
|
PROBE_FAMILY("MTK Family", "$PMTK605*31", mtk, 500);
|
||||||
|
currentDelay = 20;
|
||||||
|
currentStep = 6;
|
||||||
|
return GNSS_MODEL_UNKNOWN;
|
||||||
|
}
|
||||||
|
case 6: {
|
||||||
uint8_t cfg_rate[] = {0xB5, 0x62, 0x06, 0x08, 0x00, 0x00, 0x00, 0x00};
|
uint8_t cfg_rate[] = {0xB5, 0x62, 0x06, 0x08, 0x00, 0x00, 0x00, 0x00};
|
||||||
UBXChecksum(cfg_rate, sizeof(cfg_rate));
|
UBXChecksum(cfg_rate, sizeof(cfg_rate));
|
||||||
clearBuffer();
|
clearBuffer();
|
||||||
@@ -1291,6 +1317,8 @@ GnssModel_t GPS::probe(int serialSpeed)
|
|||||||
GPS_RESPONSE response = getACK(0x06, 0x08, 750);
|
GPS_RESPONSE response = getACK(0x06, 0x08, 750);
|
||||||
if (response == GNSS_RESPONSE_NONE) {
|
if (response == GNSS_RESPONSE_NONE) {
|
||||||
LOG_WARN("No GNSS Module (baudrate %d)", serialSpeed);
|
LOG_WARN("No GNSS Module (baudrate %d)", serialSpeed);
|
||||||
|
currentDelay = 2000;
|
||||||
|
currentStep = 0;
|
||||||
return GNSS_MODEL_UNKNOWN;
|
return GNSS_MODEL_UNKNOWN;
|
||||||
} else if (response == GNSS_RESPONSE_FRAME_ERRORS) {
|
} else if (response == GNSS_RESPONSE_FRAME_ERRORS) {
|
||||||
LOG_INFO("UBlox Frame Errors (baudrate %d)", serialSpeed);
|
LOG_INFO("UBlox Frame Errors (baudrate %d)", serialSpeed);
|
||||||
@@ -1374,7 +1402,11 @@ GnssModel_t GPS::probe(int serialSpeed)
|
|||||||
return GNSS_MODEL_UBLOX10;
|
return GNSS_MODEL_UBLOX10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
LOG_WARN("No GNSS Module (baudrate %d)", serialSpeed);
|
LOG_WARN("No GNSS Module (baudrate %d)", serialSpeed);
|
||||||
|
currentDelay = 2000;
|
||||||
|
currentStep = 0;
|
||||||
return GNSS_MODEL_UNKNOWN;
|
return GNSS_MODEL_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -151,6 +151,8 @@ class GPS : private concurrency::OSThread
|
|||||||
TinyGPSPlus reader;
|
TinyGPSPlus reader;
|
||||||
uint8_t fixQual = 0; // fix quality from GPGGA
|
uint8_t fixQual = 0; // fix quality from GPGGA
|
||||||
uint32_t lastChecksumFailCount = 0;
|
uint32_t lastChecksumFailCount = 0;
|
||||||
|
uint8_t currentStep = 0;
|
||||||
|
int32_t currentDelay = 2000;
|
||||||
|
|
||||||
#ifndef TINYGPS_OPTION_NO_CUSTOM_FIELDS
|
#ifndef TINYGPS_OPTION_NO_CUSTOM_FIELDS
|
||||||
// (20210908) TinyGps++ can only read the GPGSA "FIX TYPE" field
|
// (20210908) TinyGps++ can only read the GPGSA "FIX TYPE" field
|
||||||
|
|||||||
Reference in New Issue
Block a user