@@ -55,13 +55,17 @@ bool GPSHardware::Handle_GPSConfig(wippersnapper_gps_GPSConfig *gps_config) {
55
55
WS_DEBUG_PRINTLN (" [gps] ERROR: No GPSConfig message found!" );
56
56
return false ;
57
57
}
58
+
59
+ // Delay for two seconds to allow the GPS module to initialize
60
+ WS_DEBUG_PRINTLN (" [gps] Delaying for 1 second" );
61
+ delay (1000 );
58
62
// Iterate through the command sentences and send them to the GPS module
59
63
// TODO: We may want to break this out into a generic function that supports
60
64
// MTK, Ublox, etc...
61
65
for (size_t i = 0 ; i < gps_config->commands_count ; i++) {
62
66
// Build the PMTK ACK response for the command
63
67
char msg_resp[MAX_NEMA_SENTENCE_LEN];
64
- WS_DEBUG_PRINT (" [gps] Building PMTK ACK response for command : " );
68
+ WS_DEBUG_PRINT (" [gps] Building PMTK ACK response: " );
65
69
if (!BuildPmtkAck (gps_config->commands [i], msg_resp)) {
66
70
WS_DEBUG_PRINTLN (" [gps] ERROR: Failed to build PMTK ACK response!" );
67
71
return false ;
@@ -76,12 +80,27 @@ bool GPSHardware::Handle_GPSConfig(wippersnapper_gps_GPSConfig *gps_config) {
76
80
}
77
81
WS_DEBUG_PRINT (" [gps] Sending command to MediaTek GPS: " );
78
82
WS_DEBUG_PRINTLN (gps_config->commands [i]);
83
+ // Clear the tx and rx buffer before sending the command
84
+ WS_DEBUG_PRINT (" [gps] Clearing buffer before sending command..." );
85
+ // Clear any pending GPS data
86
+ uint8_t buf[32 ];
87
+ int maxReads = 10 ; // Prevent infinite loop
88
+ while (maxReads-- > 0 ) {
89
+ Wire.requestFrom (PA1010D_I2C_ADDRESS, 32 );
90
+ if (Wire.available () == 0 )
91
+ break ; // No more data
92
+
93
+ while (Wire.available ()) {
94
+ Wire.read (); // Discard
95
+ }
96
+ delay (10 ); // Give GPS time to refill buffer
97
+ }
98
+ WS_DEBUG_PRINTLN (" cleared!" );
79
99
// Send the command to the GPS module
80
100
_ada_gps->sendCommand (gps_config->commands [i]);
81
101
WS_DEBUG_PRINTLN (" [gps] Command sent, waiting for response..." );
82
102
// and wait for the corresponding response from the GPS module
83
- if (!_ada_gps->waitForSentence (
84
- " $PMTK705,AXN_5.1.7_3333_19020118,0027,PA1010D,1.0*76" )) {
103
+ if (!_ada_gps->waitForSentence (msg_resp, 100 )) {
85
104
WS_DEBUG_PRINT (" [gps] ERROR: Failed to get response | cmd:" );
86
105
WS_DEBUG_PRINTLN (gps_config->commands [i]);
87
106
return false ;
0 commit comments