@@ -240,16 +240,16 @@ GPS_RESPONSE GPS::getACK(const char *message, uint32_t waitMillis)
240240 buffer[bytesRead] = b;
241241 bytesRead++;
242242 if ((bytesRead == 767 ) || (b == ' \r ' )) {
243+ #ifdef GPS_DEBUG
244+ LOG_DEBUG (debugmsg.c_str ());
245+ #endif
243246 if (strnstr ((char *)buffer, message, bytesRead) != nullptr ) {
244247#ifdef GPS_DEBUG
245248 LOG_DEBUG (" Found: %s" , message); // Log the found message
246249#endif
247250 return GNSS_RESPONSE_OK;
248251 } else {
249252 bytesRead = 0 ;
250- #ifdef GPS_DEBUG
251- LOG_DEBUG (debugmsg.c_str ());
252- #endif
253253 }
254254 }
255255 }
@@ -1275,6 +1275,24 @@ GnssModel_t GPS::probe(int serialSpeed)
12751275 memset (&ublox_info, 0 , sizeof (ublox_info));
12761276 delay (100 );
12771277
1278+ #if defined(PIN_GPS_RESET) && PIN_GPS_RESET != -1
1279+ digitalWrite (PIN_GPS_RESET, GPS_RESET_MODE); // assert for 10ms
1280+ delay (10 );
1281+ digitalWrite (PIN_GPS_RESET, !GPS_RESET_MODE);
1282+
1283+ // attempt to detect the chip based on boot messages
1284+ std::vector<ChipInfo> passive_detect = {
1285+ {" AG3335" , " $PAIR021,AG3335" , GNSS_MODEL_AG3335},
1286+ {" AG3352" , " $PAIR021,AG3352" , GNSS_MODEL_AG3352},
1287+ {" RYS3520" , " $PAIR021,REYAX_RYS3520_V2" , GNSS_MODEL_AG3352},
1288+ {" UC6580" , " UC6580" , GNSS_MODEL_UC6580},
1289+ // as L76K is sort of a last ditch effort, we won't attempt to detect it by startup messages for now.
1290+ /* {"L76K", "SW=URANUS", GNSS_MODEL_MTK}*/ };
1291+ GnssModel_t detectedDriver = getProbeResponse (500 , passive_detect, serialSpeed);
1292+ if (detectedDriver != GNSS_MODEL_UNKNOWN) {
1293+ return detectedDriver;
1294+ }
1295+ #endif
12781296 // Close all NMEA sentences, valid for L76K, ATGM336H (and likely other AT6558 devices)
12791297 _serial_gps->write (" $PCAS03,0,0,0,0,0,0,0,0,0,0,,,0,0*02\r\n " );
12801298 delay (20 );
@@ -1473,19 +1491,22 @@ GnssModel_t GPS::getProbeResponse(unsigned long timeout, const std::vector<ChipI
14731491 }
14741492
14751493 if (c == ' ,' || (responseLen >= 2 && response[responseLen - 2 ] == ' \r ' && response[responseLen - 1 ] == ' \n ' )) {
1476- #ifdef GPS_DEBUG
1477- LOG_DEBUG (response);
1478- #endif
14791494 // check if we can see our chips
14801495 for (const auto &chipInfo : responseMap) {
14811496 if (strstr (response, chipInfo.detectionString .c_str ()) != nullptr ) {
1497+ #ifdef GPS_DEBUG
1498+ LOG_DEBUG (response);
1499+ #endif
14821500 LOG_INFO (" %s detected" , chipInfo.chipName .c_str ());
14831501 delete[] response; // Cleanup before return
14841502 return chipInfo.driver ;
14851503 }
14861504 }
14871505 }
14881506 if (responseLen >= 2 && response[responseLen - 2 ] == ' \r ' && response[responseLen - 1 ] == ' \n ' ) {
1507+ #ifdef GPS_DEBUG
1508+ LOG_DEBUG (response);
1509+ #endif
14891510 // Reset the response buffer for the next potential message
14901511 responseLen = 0 ;
14911512 response[0 ] = ' \0 ' ;
@@ -1572,8 +1593,6 @@ GPS *GPS::createGps()
15721593
15731594#ifdef PIN_GPS_RESET
15741595 pinMode (PIN_GPS_RESET, OUTPUT);
1575- digitalWrite (PIN_GPS_RESET, GPS_RESET_MODE); // assert for 10ms
1576- delay (10 );
15771596 digitalWrite (PIN_GPS_RESET, !GPS_RESET_MODE);
15781597#endif
15791598
0 commit comments