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

Support for ATGM336H GPS modules #3610

Merged
merged 2 commits into from
Apr 16, 2024

Conversation

titan098
Copy link
Contributor

@titan098 titan098 commented Apr 13, 2024

Support for ATGM336H GPS modules (GPS module using an AT6558 SOC).

An ATGM336H module will happily current work with the current GNSS_MODEL_MTK code, however I found using CASIC commands the module gives a better overall experience.

  • GPS::CASChecksum to calculate CASIC checksums for message payloads
  • GPS::makeCASPacket to construct CASIC packets using the same UBXscratch buffer that already exists
  • GPS::getACKCAS to parse CASIC MSG-ACK/NACK responses
  • Identification of ATGM336H modules
  • Module configuration via CASIC messages
  • Factory reset via CASIC messages
  • Minor update to RedirectablePrint::hexDump for better debugging display of constructed messages

Without GPS_DEBUG enabled:

DEBUG | ??:??:?? 1 [GPS] Probing for GPS at 9600 
INFO  | ??:??:?? 2 [GPS] ATGM336H GNSS init succeeded, using ATGM336H Module
INFO  | ??:??:?? 2 [RangeTestModule] Range Test Module - Disabled
...
DEBUG | 11:21:12 5 [GPS] New GPS pos@661a6aaa:3 lat=xxx, lon=xxx, alt=56, pdop=1.69, track=345.09, speed=0.02, sats=12
DEBUG | 11:21:12 5 [GPS] onGPSChanged() pos@661a6aaa, time=1713007272, lat=xxx, lon=xxx, alt=56
INFO  | 11:21:12 5 [GPS] updatePosition LOCAL pos@661a6aaa, time=1713007272, latI=xxx, lonI=xxx, alt=56
DEBUG | 11:21:12 5 [GPS] Setting local position: latitude=xxx, longitude=xxx, time=1713007272
DEBUG | 11:21:12 5 [GPS] Node status update: 1 online, 1 total

With GPS_DEBUG enabled:

DEBUG | ??:??:?? 5 [GPS] ATGM336H GNSS init succeeded, using ATGM336H Module
DEBUG | ??:??:?? 5 [GPS] Constructed CAS packet: 
DEBUG | ??:??:?? 5 [GPS]     +------------------------------------------------+ +----------------+
DEBUG | ??:??:?? 5 [GPS]     |.0 .1 .2 .3 .4 .5 .6 .7 .8 .9 .a .b .c .d .e .f | |      ASCII     |
DEBUG | ??:??:?? 5 [GPS]     +------------------------------------------------+ +----------------+
DEBUG | ??:??:?? 5 [GPS]  00.|ba ce 2c 00 06 07 03 01 00 00 03 03 00 00 00 00 | |..,.............|
DEBUG | ??:??:?? 5 [GPS]  01.|00 00 00 07 00 00 00 00 00 00 00 00 00 00 00 00 | |................|
DEBUG | ??:??:?? 5 [GPS]  02.|00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | |................|
DEBUG | ??:??:?? 5 [GPS]  03.|00 00 32 0b 06 07                               | |..2...          |
DEBUG | ??:??:?? 5 [GPS]     +------------------------------------------------+ +----------------+
INFO  | ??:??:?? 5 [GPS] Got ACK for class 06 message 07 in 71 millis.
DEBUG | ??:??:?? 5 [GPS] Constructed CAS packet: 
DEBUG | ??:??:?? 5 [GPS]     +------------------------------------------------+ +----------------+
DEBUG | ??:??:?? 5 [GPS]     |.0 .1 .2 .3 .4 .5 .6 .7 .8 .9 .a .b .c .d .e .f | |      ASCII     |
DEBUG | ??:??:?? 5 [GPS]     +------------------------------------------------+ +----------------+
DEBUG | ??:??:?? 5 [GPS]  00.|ba ce 04 00 06 04 e8 03 00 00 ec 03 06 04       | |..............  |
DEBUG | ??:??:?? 5 [GPS]     +------------------------------------------------+ +----------------+
INFO  | ??:??:?? 5 [GPS] Got ACK for class 06 message 04 in 29 millis.
DEBUG | ??:??:?? 5 [GPS] Constructed CAS packet: 
DEBUG | ??:??:?? 5 [GPS]     +------------------------------------------------+ +----------------+
DEBUG | ??:??:?? 5 [GPS]     |.0 .1 .2 .3 .4 .5 .6 .7 .8 .9 .a .b .c .d .e .f | |      ASCII     |
DEBUG | ??:??:?? 5 [GPS]     +------------------------------------------------+ +----------------+
DEBUG | ??:??:?? 5 [GPS]  00.|ba ce 04 00 06 01 4e 04 01 00 52 04 07 01       | |......N...R...  |
DEBUG | ??:??:?? 5 [GPS]     +------------------------------------------------+ +----------------+
INFO  | ??:??:?? 5 [GPS] Got ACK for class 06 message 01 in 100 millis.
DEBUG | ??:??:?? 5 [GPS] Constructed CAS packet: 
DEBUG | ??:??:?? 5 [GPS]     +------------------------------------------------+ +----------------+
DEBUG | ??:??:?? 5 [GPS]     |.0 .1 .2 .3 .4 .5 .6 .7 .8 .9 .a .b .c .d .e .f | |      ASCII     |
DEBUG | ??:??:?? 5 [GPS]     +------------------------------------------------+ +----------------+
DEBUG | ??:??:?? 5 [GPS]  00.|ba ce 04 00 06 01 4e 00 01 00 52 00 07 01       | |......N...R...  |
DEBUG | ??:??:?? 5 [GPS]     +------------------------------------------------+ +----------------+
INFO  | ??:??:?? 5 [GPS] Got ACK for class 06 message 01 in 30 millis.
...
DEBUG | 11:14:21 7 [GPS] New GPS pos@661a690d:3 lat=xxx, lon=xxx, alt=56, pdop=5.92, track=19.72, speed=0.00, sats=8
DEBUG | 11:14:21 7 [GPS] onGPSChanged() pos@661a690d, time=1713006861, lat=xxx, lon=xxx, alt=56
INFO  | 11:14:21 7 [GPS] updatePosition LOCAL pos@661a690d, time=1713006861, latI=-xxx, lonI=xxx, alt=56
DEBUG | 11:14:21 7 [GPS] Setting local position: latitude=xxx, longitude=xxx, time=1713006861
DEBUG | 11:14:21 7 [GPS] Node status update: 1 online, 1 total
INFO  | 11:14:21 7 [GPS] Sending smart pos@661a690d:6 to mesh (distanceTraveled=4227558.000000m, minDistanceThreshold=100m, timeElapsed=7037ms)
DEBUG | 11:14:21 7 [GPS] Sending location with precision 32
INFO  | 11:14:21 7 [GPS] Providing time to mesh 1713006861
INFO  | 11:14:21 7 [GPS] Position reply: time=1713006861, latI=xxx, lonI=xxx
...

References:

@GPSFan
Copy link
Contributor

GPSFan commented Apr 13, 2024

This looks like a good step forward in adding some of the popular CN GNSS receivers that are available on Alli/Amazon/Temu etc.
Here is an English version of the Casic protocol spec:
https://espruino.microcosm.app/api/v1/files/68b597874e0a617692ebebc6a878032f76b34272.pdf
Looking ahead, there probably should be support for the AllyStar Tau1202, U-Blox F10 and maybe a few others. The AllyStar uses a sloppy copy of the u-blox protocol, with different header bytes and packet lengths, but in general the commands are similar.

@titan098 titan098 marked this pull request as ready for review April 13, 2024 13:20
@titan098
Copy link
Contributor Author

titan098 commented Apr 15, 2024

@GPSFan, given the comments above this could be updated to more broadly identify AT6558 devices rather than ATGM336H specifically using:

    _serial_gps->write("$PCAS06,6*1D\r\n");
    if (getACK("$GPTXT,01,01,02,IC=AT6558", 500) == GNSS_RESPONSE_OK) {
...

What are your thoughts?

@GPSFan
Copy link
Contributor

GPSFan commented Apr 15, 2024

The code in GPS.cpp mis-represents the L76K as an MTK chip, the real MTK variant from Quectel is the L76B, which is now supported and recognized. Meshtastic "discovers" which type GPS chip it is running with in two ways, First is via the variant.h file where may be a #define GPS_XXXX statement, and the second is in GPS.cpp where an attempt is made to query the chip itself at various baud rates.
Together, both of these methods get the job done, but can result in a long wait, as the baud rates are run through, and chips are queried with the wrong commands.
IMHO, (maybe for Meshtastic V3) A more consistent way of identifying GNSS chips should be implemented.
As the GNSS chip market evolves, there will be more types with more and different protocols. Most chip protocols support some type of versioning and respond to a query from the host with an ID string.
Of course the easy way out would be to require a #define GPS_XXXX in each variant.h file.

@titan098
Copy link
Contributor Author

Thanks @GPSFan - i will leave the current proposed PR as is for now and it can always be revised at a later stage with a broader set of improvements.

@thebentern thebentern merged commit 55c9c3b into meshtastic:master Apr 16, 2024
66 checks passed
Copy link
Contributor

🤖 Pull request artifacts

empty string

file commit
firmware-2.3.6.1eef4d6.zip 1eef4d6

thebentern added a commit to meshtastic/artifacts that referenced this pull request Apr 16, 2024
@titan098 titan098 deleted the atgm336h_gps_module_support branch April 16, 2024 18:15
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.

3 participants