@@ -225,12 +225,9 @@ void GPSController::update() {
225
225
}
226
226
227
227
// 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 ) {
232
229
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,
234
231
// remove in production!
235
232
wippersnapper_gps_GPSDateTime datetime = _gps_model->CreateGpsDatetime (
236
233
drv->GetAdaGps ()->hour , drv->GetAdaGps ()->minute ,
@@ -243,8 +240,7 @@ void GPSController::update() {
243
240
&drv->GetAdaGps ()->lon , drv->GetAdaGps ()->speed ,
244
241
drv->GetAdaGps ()->angle );
245
242
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 ) {
248
244
WS_DEBUG_PRINT (
249
245
" [gps] Adding GGA to GPSEvent..." ); // TODO: This is for debug,
250
246
// remove in production!
@@ -264,17 +260,21 @@ void GPSController::update() {
264
260
WS_DEBUG_PRINTLN (
265
261
" [gps] WARNING - Parsed sentence is not type RMC or GGA!" );
266
262
}
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
271
271
if (!WsV2.PublishSignal (wippersnapper_signal_DeviceToBroker_gps_event_tag,
272
272
_gps_model->GetGPSEvent ())) {
273
273
WS_DEBUG_PRINTLN (" [gps] ERROR: Failed to publish GPSEvent!" );
274
274
} else {
275
275
WS_DEBUG_PRINTLN (" [gps] GPSEvent published successfully!" );
276
276
}
277
- drv->SetPollPeriodPrv (cur_time);
278
277
}
278
+ drv->SetPollPeriodPrv (cur_time);
279
279
}
280
280
}
0 commit comments