@@ -47,28 +47,29 @@ GPSController::~GPSController() {
47
47
* Pointer to a pb_istream_t object.
48
48
* @returns True if the message was handled successfully, False otherwise.
49
49
*/
50
- bool GPSController::Handle_GPSConfig (pb_istream_t *stream ) {
50
+ bool GPSController::Handle_GPSConfig (wippersnapper_gps_GPSConfig *gps_config ) {
51
51
// Attempt to decode the GPSConfig message
52
- WS_DEBUG_PRINTLN (" [gps] Decoding GPSConfig message..." );
53
- if (!_gps_model->DecodeGPSConfig (stream)) {
54
- WS_DEBUG_PRINTLN (" [gps] ERROR: Failed to decode GPSConfig message!" );
55
- return false ;
56
- }
57
- WS_DEBUG_PRINTLN (" [gps] GPSConfig message decoded successfully!" );
58
-
59
52
if (_driver_type == GPS_DRV_MTK) {
60
53
// handle commands for mtk driver
61
54
WS_DEBUG_PRINTLN (" [gps] Handling GPSConfig for MediaTek driver..." );
62
- wippersnapper_gps_GPSConfig *gps_config = _gps_model->GetGPSConfigMsg ();
63
55
if (gps_config == nullptr ) {
64
56
WS_DEBUG_PRINTLN (" [gps] ERROR: No GPSConfig message found!" );
65
57
return false ;
66
58
}
67
- // Iterate through the commands and send them to the GPS module
59
+ // Iterate through the command sentences and send them to the GPS module
68
60
for (size_t i = 0 ; i < gps_config->commands_count ; i++) {
69
61
WS_DEBUG_PRINT (" [gps] Sending command to MediaTek GPS: " );
70
62
WS_DEBUG_PRINTLN (gps_config->commands [i]);
63
+ _hw_serial->flush (); // Flush the serial buffer before sending
64
+ // Send the command to the GPS module
71
65
_ada_gps->sendCommand (gps_config->commands [i]);
66
+ // and wait for the corresponding response from the GPS module
67
+ if (!_ada_gps->waitForSentence (gps_config->responses [i])) {
68
+ WS_DEBUG_PRINT (
69
+ " [gps] ERROR: Failed to get response from MediaTek for cmd:" );
70
+ WS_DEBUG_PRINTLN (gps_config->commands [i]);
71
+ return false ;
72
+ }
72
73
}
73
74
} else {
74
75
WS_DEBUG_PRINTLN (" [gps] ERROR: Unsupported GPS driver type!" );
@@ -168,7 +169,7 @@ bool GPSController::DetectMediatek() {
168
169
_hw_serial->flush ();
169
170
_hw_serial->println (CMD_MTK_QUERY_FW);
170
171
// Wait for response
171
- uint16_t timeout = 1000 ; // 1 second timeout
172
+ uint16_t timeout = 2000 ; // 1 second timeout
172
173
while (_hw_serial->available () < MAX_NEMA_SENTENCE_LEN && timeout--) {
173
174
delay (1 );
174
175
}
@@ -181,7 +182,7 @@ bool GPSController::DetectMediatek() {
181
182
182
183
// We found a response, let's verify that it's the expected PMTK_DK_RELEASE
183
184
// command by reading out the NMEA sentence string into a buffer
184
- size_t buf_len = MAX_NEMA_SENTENCE_LEN + 3 ; // +3 for \r\n and null terminator
185
+ size_t buf_len = MAX_NEMA_SENTENCE_LEN * 4 ; // +3 for \r\n and null terminator
185
186
char buffer[buf_len];
186
187
size_t available = _hw_serial->available ();
187
188
size_t bytes_to_read = min (available, buf_len - 1 );
0 commit comments