Skip to content

Commit 528ff03

Browse files
committed
GPS - Fix bug, publishing multiple messages instead of one GPSevent
1 parent bc7d5ce commit 528ff03

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/components/gps/controller.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,9 @@ void GPSController::update() {
225225
}
226226

227227
// now, let's build the model from the sentence
228-
// $GPGGA
229-
// $GPRMC
230-
if (strncmp(nmea_sentence, "$GPRMC", 7)) {
231-
// parse GPRMC into event
228+
if (strncmp(nmea_sentence, "$GPRMC", 6) == 0) {
232229
WS_DEBUG_PRINT(
233-
"[gps] Adding GGA to GPSEvent..."); // TODO: This is for debug,
230+
"[gps] Adding RMC to GPSEvent..."); // TODO: This is for debug,
234231
// remove in production!
235232
wippersnapper_gps_GPSDateTime datetime = _gps_model->CreateGpsDatetime(
236233
drv->GetAdaGps()->hour, drv->GetAdaGps()->minute,
@@ -243,8 +240,7 @@ void GPSController::update() {
243240
&drv->GetAdaGps()->lon, drv->GetAdaGps()->speed,
244241
drv->GetAdaGps()->angle);
245242
WS_DEBUG_PRINTLN("added!"); // TODO: THIS IS FOR DEBUG, REMOVE IN PROD
246-
} else if (strncmp(nmea_sentence, "$GPRMC", 7)) {
247-
// parse GPGGA into event
243+
} else if (strncmp(nmea_sentence, "$GPGGA", 6) == 0) {
248244
WS_DEBUG_PRINT(
249245
"[gps] Adding GGA to GPSEvent..."); // TODO: This is for debug,
250246
// remove in production!
@@ -264,17 +260,21 @@ void GPSController::update() {
264260
WS_DEBUG_PRINTLN(
265261
"[gps] WARNING - Parsed sentence is not type RMC or GGA!");
266262
}
267-
WS_DEBUG_PRINTLN("[gps] Finished processing NMEA sentences.");
268-
_gps_model->EncodeGPSEvent();
269-
270-
// TODO: Publish out to IO
263+
}
264+
// Encode and publish to IO
265+
WS_DEBUG_PRINT("[gps] Encoding and publishing GPSEvent to IO...");
266+
bool did_encode = _gps_model->EncodeGPSEvent();
267+
if (!did_encode) {
268+
WS_DEBUG_PRINTLN("[gps] ERROR: Failed to encode GPSEvent!");
269+
} else {
270+
// Publish the GPSEvent to IO
271271
if (!WsV2.PublishSignal(wippersnapper_signal_DeviceToBroker_gps_event_tag,
272272
_gps_model->GetGPSEvent())) {
273273
WS_DEBUG_PRINTLN("[gps] ERROR: Failed to publish GPSEvent!");
274274
} else {
275275
WS_DEBUG_PRINTLN("[gps] GPSEvent published successfully!");
276276
}
277-
drv->SetPollPeriodPrv(cur_time);
278277
}
278+
drv->SetPollPeriodPrv(cur_time);
279279
}
280280
}

0 commit comments

Comments
 (0)