Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only call GPS Probe commands once per family #6114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fifieldt
Copy link
Contributor

In the GPS probe code we write commands on the serial line and
determine which GPS we have based on the result.

GPS units in the same family sometimes use the same command,
but return different results (eg AG3335 and AG3332 both use $PAIR021*39).
Currently we run the command once per GPS. Instead we should run each command only once per family, record the result, and select the GNSS MODEL
based on the result, which is what this patch does.

Before the change, we put 12 commands on the serial bus. Now we only put 6.

This should markedly improve the speed and reliability of GPS detection.

Fixes #5193

@fifieldt fifieldt force-pushed the gps-one-probe-per-family branch 3 times, most recently from 7f981ab to 205431b Compare February 21, 2025 02:53
@fifieldt fifieldt marked this pull request as draft February 21, 2025 03:45
@fifieldt
Copy link
Contributor Author

Converting to draft - going to test in every chip I have.

@fifieldt
Copy link
Contributor Author

fifieldt commented Feb 21, 2025

Hmm, it looks like the new T1000E GPS detection "improvement" code in GPS::setup slows down the GPS coming up to the extent the new faster detection code here runs before it comes up!

@fifieldt fifieldt force-pushed the gps-one-probe-per-family branch 2 times, most recently from 6f085c3 to a810943 Compare February 21, 2025 06:46
@fifieldt
Copy link
Contributor Author

Example from T1000E

Before:

DEBUG | ??:??:?? 7 [GPS] Trying $PDTINFO (UC6580)...
DEBUG | ??:??:?? 8 [GPS] Trying $PDTINFO (UM600)...
DEBUG | ??:??:?? 8 [GPS] Trying $PCAS06,1*1A (ATGM336H)...
DEBUG | ??:??:?? 9 [GPS] Trying $PCAS06,1*1A (ATGM332D)...
DEBUG | ??:??:?? 9 [GPS] Trying $PAIR021*39 (AG3335)...
INFO | ??:??:?? 9 [GPS] AG3335 detected, using GNSS_MODEL_AG3335 Module```

After:
```DEBUG | ??:??:?? 7 [GPS] Trying $PDTINFO (Unicore Family)...
DEBUG | ??:??:?? 8 [GPS] Trying $PCAS06,1*1A (ATGM33xx Family)...
DEBUG | ??:??:?? 8 [GPS] Trying $PAIR021*39 (Airoha Family)...
INFO | ??:??:?? 8 [GPS] AG3335 detected

@fifieldt
Copy link
Contributor Author

Tested with Tbeam/UBlox 6 - works nicely

@fifieldt
Copy link
Contributor Author

Seeed Wio-WM1110

DEBUG | ??:??:?? 5 [GPS] Trying $PDTINFO (Unicore Family)...
DEBUG | ??:??:?? 5 [GPS] Trying $PCAS06,1*1A (ATGM33xx Family)...
DEBUG | ??:??:?? 6 [GPS] Trying $PAIR021*39 (Airoha Family)...
DEBUG | ??:??:?? 7 [GPS] Trying $PQTMVERNO*58 (LC86)...
DEBUG | ??:??:?? 8 [GPS] Trying $PCAS06,0*1B (L76K)...
INFO | ??:??:?? 8 [GPS] L76K detected```

@fifieldt fifieldt marked this pull request as ready for review February 21, 2025 07:49
In the GPS probe code we write commands on the serial line and
 determine which GPS we have based on the result.

GPS units in the same family sometimes use the same command,
 but return different results (eg AG3335 and AG3332 both use $PAIR021*39).
Currently we run the command once per GPS. Instead we should run each
command only once per family, record the result, and select the GNSS MODEL
 based on the result, which is what this patch does.

Before the change, we put 12 commands on the serial bus.
Now we only put 6.

This should markedly improve the speed and reliability of GPS detection.

Fixes meshtastic#5193
@thebentern
Copy link
Contributor

Hmm, it looks like the new T1000E GPS detection "improvement" code in GPS::setup slows down the GPS coming up to the extent the new faster detection code here runs before it comes up!

Can we set the thread to start up on a delay in the case of the T1000E perhaps? I'm trying to recall if that had other unintended consequences.

@fifieldt
Copy link
Contributor Author

Can we set the thread to start up on a delay in the case of the T1000E perhaps? I'm trying to recall if that had other unintended consequences.

I think I was wrong with my earlier comment. What I've done is set the time for the airoha probe command to 1000 millis, rather than 500, and it seems very happy now!

@mverch67
Copy link
Collaborator

mverch67 commented Feb 21, 2025

Besides the GPS family I'd like to propose another probe optimisation I'd call GPS hinting.
While it's good to have runtime detection of the GPS so it does not need a special build for supporting an attached GPS device the probing is still annoying for a couple of devices with pre-equipped GPS (e.g. T-Deck Plus) as it takes about 25s for the detection and the device is barely operable because of the slowdown.
There are a couple of devices which have a well known GPS equipped. The concept of GPS hinting is quite simple: add a definition for the most common GPS and baudrate for that device into variant.h and in GPS.cpp check if the hinting macros is there and then try that one first. So in the ideal case the GPS is detected immediately and startup is accelerated drastically.
Also, currently it tries the slowest baud rate first but a couple of devices can operate different baud rates, so it should use the fastest and not the slowest.

Macros used in variant.h for GPS hinting:
GPS_BAUDRATE nnnnn # requires line 436: static const int serialSpeeds[] = {GPS_BAUDRATE, 115200, 38400, 9600};
GPS_PROBE PROBE(...) # use the probe macro that most likely succeeds the gps detection for that device;
(for U-blox need to put that related code into another function for simpler selection as a probe)

Remove the GPS_BAUDRATE_FIXED and GPS_BAUDRATE definitions in configuration.h

Example for T-Deck Plus:
Current state (without this PR and/or GPS hinting), takes 26s for detection:

DEBUG | ??:??:?? 3 [GPS] Probe for GPS at 9600
DEBUG | ??:??:?? 3 [GPS] Trying $PDTINFO (UC6580)...
DEBUG | ??:??:?? 4 [GPS] Trying $PDTINFO (UM600)...
DEBUG | ??:??:?? 4 [GPS] Trying $PCAS06,1*1A (ATGM336H)...
DEBUG | ??:??:?? 5 [GPS] Trying $PCAS06,1*1A (ATGM332D)...
DEBUG | ??:??:?? 5 [GPS] Trying $PAIR021*39 (AG3335)...
DEBUG | ??:??:?? 6 [GPS] Trying $PAIR021*39 (AG3352)...
DEBUG | ??:??:?? 6 [GPS] Trying $PQTMVERNO*58 (LC86)...
DEBUG | ??:??:?? 7 [GPS] Trying $PCAS06,0*1B (L76K)...
DEBUG | ??:??:?? 7 [GPS] Trying $PMTK605*31 (L76B)...
DEBUG | ??:??:?? 8 [GPS] Trying $PMTK605*31 (PA1616S)...
DEBUG | ??:??:?? 8 [GPS] Trying $PMTK605*31 (LS20031)...
WARN  | ??:??:?? 10 [GPS] No GNSS Module (baudrate 9600)

DEBUG | ??:??:?? 12 [GPS] Probe for GPS at 115200
DEBUG | ??:??:?? 12 [GPS] Set Baud to 115200
DEBUG | ??:??:?? 12 [GPS] Trying $PDTINFO (UC6580)...
DEBUG | ??:??:?? 12 [GPS] Trying $PDTINFO (UM600)...
DEBUG | ??:??:?? 13 [GPS] Trying $PCAS06,1*1A (ATGM336H)...
DEBUG | ??:??:?? 13 [GPS] Trying $PCAS06,1*1A (ATGM332D)...
DEBUG | ??:??:?? 14 [GPS] Trying $PAIR021*39 (AG3335)...
DEBUG | ??:??:?? 14 [GPS] Trying $PAIR021*39 (AG3352)...
DEBUG | ??:??:?? 15 [GPS] Trying $PQTMVERNO*58 (LC86)...
DEBUG | ??:??:?? 15 [GPS] Trying $PCAS06,0*1B (L76K)...
DEBUG | ??:??:?? 16 [GPS] Trying $PMTK605*31 (L76B)...
DEBUG | ??:??:?? 16 [GPS] Trying $PMTK605*31 (PA1616S)...
DEBUG | ??:??:?? 17 [GPS] Trying $PMTK605*31 (LS20031)...
WARN  | ??:??:?? 18 [GPS] No GNSS Module (baudrate 115200)

DEBUG | ??:??:?? 20 [GPS] Probe for GPS at 38400
DEBUG | ??:??:?? 20 [GPS] Set Baud to 38400
DEBUG | ??:??:?? 20 [GPS] Trying $PDTINFO (UC6580)...
DEBUG | ??:??:?? 21 [GPS] Trying $PDTINFO (UM600)...
DEBUG | ??:??:?? 21 [GPS] Trying $PCAS06,1*1A (ATGM336H)...
DEBUG | ??:??:?? 22 [GPS] Trying $PCAS06,1*1A (ATGM332D)...
DEBUG | ??:??:?? 22 [GPS] Trying $PAIR021*39 (AG3335)...
DEBUG | ??:??:?? 23 [GPS] Trying $PAIR021*39 (AG3352)...
DEBUG | ??:??:?? 23 [GPS] Trying $PQTMVERNO*58 (LC86)...
DEBUG | ??:??:?? 24 [GPS] Trying $PCAS06,0*1B (L76K)...
DEBUG | ??:??:?? 24 [GPS] Trying $PMTK605*31 (L76B)...
DEBUG | ??:??:?? 25 [GPS] Trying $PMTK605*31 (PA1616S)...
DEBUG | ??:??:?? 25 [GPS] Trying $PMTK605*31 (LS20031)...
DEBUG | ??:??:?? 26 [GPS] Module Info : 
DEBUG | ??:??:?? 26 [GPS] Soft version: ROM SPG 5.10 (7b202e)
DEBUG | ??:??:?? 26 [GPS] Hard version: 000A0000
DEBUG | ??:??:?? 26 [GPS] Extensions:5
DEBUG | ??:??:?? 26 [GPS]   FWVER=SPG 5.10
DEBUG | ??:??:?? 26 [GPS]   PROTVER=34.10
DEBUG | ??:??:?? 26 [GPS]   MOD=MIA-M10Q
DEBUG | ??:??:?? 26 [GPS]   GPS;GLO;GAL;BDS
DEBUG | ??:??:?? 26 [GPS]   SBAS;QZSS
DEBUG | ??:??:?? 26 [GPS] Protocol Version:34.10
DEBUG | ??:??:?? 26 [GPS] ProtVer=34
INFO  | ??:??:?? 26 [GPS] U-blox 10 detected, using 10 Module
INFO  | ??:??:?? 36 [GPS] GNSS module configuration saved!
DEBUG | ??:??:?? 36 [GPS] Publish pos@0:2, hasVal=0, Sats=0, GPSlock=0
DEBUG | ??:??:?? 36 [GPS] No GPS lock
DEBUG | ??:??:?? 36 [GPS] onGPSChanged() pos@0 time=0 lat=0 lon=0 alt=0
INFO  | ??:??:?? 36 [GPS] updatePosition LOCAL pos@0 time=0 lat=0 lon=0 alt=0
DEBUG | ??:??:?? 36 [GPS] Set local position: lat=0 lon=0 time=0 timestamp=0

With GPS hinting, takes just 1 second for T-Deck Plus, it's detected immediately:

DEBUG | ??:??:?? 4 [Power] Battery: usbPower=1, isCharging=1, batMv=4922, batPct=100
DEBUG | ??:??:?? 4 [GPS] Probe for GPS at 38400
DEBUG | ??:??:?? 4 [GPS] Set Baud to 38400
DEBUG | ??:??:?? 4 [GPS] Trying $PMTK605*31 (LS20031)...
DEBUG | ??:??:?? 5 [GPS] Module Info : 
DEBUG | ??:??:?? 5 [GPS] Soft version: ROM SPG 5.10 (7b202e)
DEBUG | ??:??:?? 5 [GPS] Hard version: 000A0000
DEBUG | ??:??:?? 5 [GPS] Extensions:5
DEBUG | ??:??:?? 5 [GPS]   FWVER=SPG 5.10
DEBUG | ??:??:?? 5 [GPS]   PROTVER=34.10
DEBUG | ??:??:?? 5 [GPS]   MOD=MIA-M10Q
DEBUG | ??:??:?? 5 [GPS]   GPS;GLO;GAL;BDS
DEBUG | ??:??:?? 5 [GPS]   SBAS;QZSS
DEBUG | ??:??:?? 5 [GPS] Protocol Version:34.10
DEBUG | ??:??:?? 5 [GPS] ProtVer=34
INFO  | ??:??:?? 5 [GPS] U-blox 10 detected, using 10 Module

@fifieldt
Copy link
Contributor Author

add a definition for the most common GPS and baudrate

Set GPS_BAUDRATE in variant.h and you'll get the second part of that straight away :)

@mverch67
Copy link
Collaborator

mverch67 commented Feb 21, 2025

add a definition for the most common GPS and baudrate

Set GPS_BAUDRATE in variant.h and you'll get the second part of that straight away :)

yes, but then it does not do real probing anymore (in case another GPS is equipped for the older T-Deck), but only after removing the mentioned macros definitions in configuration.h

@fifieldt
Copy link
Contributor Author

Ok, perhaps put in a separate feature request for that and I'll take a look?

@fifieldt
Copy link
Contributor Author

fifieldt commented Feb 21, 2025

Example of the speedup for this one from T-beam: 8 seconds to 4 seconds.

I don't have a T-deck, but based on above I would expect this code would detect its GPS in about 15 seconds now.

One of the other optimizations I hope to be able to make is: most GPSes put their version info on the line when they first turn on. If it's possible to catch that we can do detection without sending a single command.

@fifieldt
Copy link
Contributor Author

do detection without sending a single command.

hmm! that was easy. I got the heltec wireless tracker to work in this way. Now to see if that was a fluke.

@fifieldt
Copy link
Contributor Author

Now to see if that was a fluke.

Yeah, sadly. Not ready to add this in yet :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimise GPS probe code - one message per family
3 participants