Skip to content

Commit 5a5a6e7

Browse files
committed
Decodes init msg
1 parent d6dbda4 commit 5a5a6e7

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

src/Wippersnapper_demo.ino.cpp

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/components/gps/hardware.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,17 @@ bool GPSHardware::Handle_GPSConfig(wippersnapper_gps_GPSConfig *gps_config) {
5555
WS_DEBUG_PRINTLN("[gps] ERROR: No GPSConfig message found!");
5656
return false;
5757
}
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);
5862
// Iterate through the command sentences and send them to the GPS module
5963
// TODO: We may want to break this out into a generic function that supports
6064
// MTK, Ublox, etc...
6165
for (size_t i = 0; i < gps_config->commands_count; i++) {
6266
// Build the PMTK ACK response for the command
6367
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: ");
6569
if (!BuildPmtkAck(gps_config->commands[i], msg_resp)) {
6670
WS_DEBUG_PRINTLN("[gps] ERROR: Failed to build PMTK ACK response!");
6771
return false;
@@ -76,12 +80,27 @@ bool GPSHardware::Handle_GPSConfig(wippersnapper_gps_GPSConfig *gps_config) {
7680
}
7781
WS_DEBUG_PRINT("[gps] Sending command to MediaTek GPS: ");
7882
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!");
7999
// Send the command to the GPS module
80100
_ada_gps->sendCommand(gps_config->commands[i]);
81101
WS_DEBUG_PRINTLN("[gps] Command sent, waiting for response...");
82102
// 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)) {
85104
WS_DEBUG_PRINT("[gps] ERROR: Failed to get response | cmd:");
86105
WS_DEBUG_PRINTLN(gps_config->commands[i]);
87106
return false;

0 commit comments

Comments
 (0)