Skip to content

Commit 61e45a7

Browse files
committed
GPS - Full implementation of GPSConfig Handler
1 parent 4b6666a commit 61e45a7

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

src/components/gps/controller.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,29 @@ GPSController::~GPSController() {
4747
* Pointer to a pb_istream_t object.
4848
* @returns True if the message was handled successfully, False otherwise.
4949
*/
50-
bool GPSController::Handle_GPSConfig(pb_istream_t *stream) {
50+
bool GPSController::Handle_GPSConfig(wippersnapper_gps_GPSConfig *gps_config) {
5151
// 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-
5952
if (_driver_type == GPS_DRV_MTK) {
6053
// handle commands for mtk driver
6154
WS_DEBUG_PRINTLN("[gps] Handling GPSConfig for MediaTek driver...");
62-
wippersnapper_gps_GPSConfig *gps_config = _gps_model->GetGPSConfigMsg();
6355
if (gps_config == nullptr) {
6456
WS_DEBUG_PRINTLN("[gps] ERROR: No GPSConfig message found!");
6557
return false;
6658
}
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
6860
for (size_t i = 0; i < gps_config->commands_count; i++) {
6961
WS_DEBUG_PRINT("[gps] Sending command to MediaTek GPS: ");
7062
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
7165
_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+
}
7273
}
7374
} else {
7475
WS_DEBUG_PRINTLN("[gps] ERROR: Unsupported GPS driver type!");
@@ -168,7 +169,7 @@ bool GPSController::DetectMediatek() {
168169
_hw_serial->flush();
169170
_hw_serial->println(CMD_MTK_QUERY_FW);
170171
// Wait for response
171-
uint16_t timeout = 1000; // 1 second timeout
172+
uint16_t timeout = 2000; // 1 second timeout
172173
while (_hw_serial->available() < MAX_NEMA_SENTENCE_LEN && timeout--) {
173174
delay(1);
174175
}
@@ -181,7 +182,7 @@ bool GPSController::DetectMediatek() {
181182

182183
// We found a response, let's verify that it's the expected PMTK_DK_RELEASE
183184
// 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
185186
char buffer[buf_len];
186187
size_t available = _hw_serial->available();
187188
size_t bytes_to_read = min(available, buf_len - 1);

src/components/gps/controller.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class GPSController {
5757
bool QueryModuleType();
5858
bool DetectMediatek();
5959
// Protobuf API methods
60-
bool Handle_GPSConfig(pb_istream_t *stream);
60+
bool Handle_GPSConfig(wippersnapper_gps_GPSConfig *gps_config);
6161

6262
private:
6363
GPSModel *_gps_model; ///< GPS model

src/components/uart/controller.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ bool UARTController::Handle_UartAdd(pb_istream_t *stream) {
152152
did_begin = drv_uart_gps->begin();
153153
if (did_begin) {
154154
WS_DEBUG_PRINTLN("[uart] GPS controller initialized successfully!");
155+
WS_DEBUG_PRINTLN("[uart] Sending commands...");
156+
if (!drv_uart_gps->Handle_GPSConfig(&cfg_device.config.gps)) {
157+
WS_DEBUG_PRINTLN("[uart] ERROR: Failed to handle GPS config!");
158+
delete drv_uart_gps; // cleanup
159+
return false;
160+
}
161+
WS_DEBUG_PRINTLN("[uart] GPS config handled successfully!");
155162
_uart_drivers_gps.push_back(drv_uart_gps);
156163
} else {
157164
WS_DEBUG_PRINTLN("[uart] ERROR: Failed to initialize GPS controller!");

0 commit comments

Comments
 (0)