Skip to content

Commit 43abe81

Browse files
committed
GPS - GPSEvent sent
1 parent 6589b40 commit 43abe81

File tree

1 file changed

+75
-75
lines changed

1 file changed

+75
-75
lines changed

src/components/gps/controller.cpp

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -224,89 +224,89 @@ void GPSController::update() {
224224

225225
// if (drv->GetIfaceType() == GPS_IFACE_UART_HW) {
226226

227-
// Unset the RX flag
228-
WS_DEBUG_PRINT("[gps] Unsetting RX flag...");
227+
// Unset the RX flag
228+
WS_DEBUG_PRINT("[gps] Unsetting RX flag...");
229+
if (ada_gps->newNMEAreceived()) {
230+
ada_gps->lastNMEA();
231+
}
232+
WS_DEBUG_PRINT("ok");
233+
234+
// Let's attempt to get a sentence from the GPS module
235+
// Read from the GPS module for update_rate milliseconds
236+
WS_DEBUG_PRINT("[gps] GetNmeaUpdateRate...");
237+
ulong update_rate = 1000 / drv->GetNmeaUpdateRate();
238+
ulong start_time = millis();
239+
WS_DEBUG_PRINT("ok");
240+
241+
WS_DEBUG_PRINT("[gps] Reading GPS data for ");
242+
WS_DEBUG_PRINT(update_rate);
243+
WS_DEBUG_PRINTLN(" ms...");
244+
while (millis() - start_time < update_rate) {
245+
char c = ada_gps->read();
246+
// Check if we have a new NMEA sentence
229247
if (ada_gps->newNMEAreceived()) {
230-
ada_gps->lastNMEA();
231-
}
232-
WS_DEBUG_PRINT("ok");
233-
234-
// Let's attempt to get a sentence from the GPS module
235-
// Read from the GPS module for update_rate milliseconds
236-
WS_DEBUG_PRINT("[gps] GetNmeaUpdateRate...");
237-
ulong update_rate = 1000 / drv->GetNmeaUpdateRate();
238-
ulong start_time = millis();
239-
WS_DEBUG_PRINT("ok");
240-
241-
WS_DEBUG_PRINT("[gps] Reading GPS data for ");
242-
WS_DEBUG_PRINT(update_rate);
243-
WS_DEBUG_PRINTLN(" ms...");
244-
while (millis() - start_time < update_rate) {
245-
char c = ada_gps->read();
246-
// Check if we have a new NMEA sentence
247-
if (ada_gps->newNMEAreceived()) {
248-
// If we have a new sentence, push it to the buffer
249-
char *last_nmea = ada_gps->lastNMEA();
250-
NmeaBufPush(ada_gps->lastNMEA());
251-
}
248+
// If we have a new sentence, push it to the buffer
249+
char *last_nmea = ada_gps->lastNMEA();
250+
NmeaBufPush(ada_gps->lastNMEA());
252251
}
252+
}
253253

254-
// Parse each NMEA sentence in the buffer
255-
char nmea_sentence[MAX_LEN_NMEA_SENTENCE];
256-
bool has_gps_event = false;
257-
while (NmeaBufPop(nmea_sentence) != -1) {
258-
// Parse the NMEA sentence
259-
WS_DEBUG_PRINT("[gps] Parsing NMEA sentence: ");
260-
WS_DEBUG_PRINTLN(nmea_sentence);
261-
if (!ada_gps->parse(nmea_sentence)) {
262-
continue; // Skip parsing this sentence if parsing failed
263-
} else {
264-
_gps_model->CreateGPSEvent();
265-
has_gps_event = true;
266-
}
267-
268-
// Build the GPSEvent message from the sentence
269-
wippersnapper_gps_GPSDateTime datetime = _gps_model->CreateGpsDatetime(
270-
ada_gps->hour, ada_gps->minute, ada_gps->seconds,
271-
ada_gps->milliseconds, ada_gps->day, ada_gps->month, ada_gps->year);
272-
if (strncmp(nmea_sentence, "$GPRMC", 6) == 0) {
273-
_gps_model->AddGpsEventRMC(datetime, ada_gps->fix, ada_gps->latitude,
274-
&ada_gps->lat, ada_gps->longitude,
275-
&ada_gps->lon, ada_gps->speed,
276-
ada_gps->angle);
277-
} else if (strncmp(nmea_sentence, "$GPGGA", 6) == 0) {
278-
_gps_model->AddGpsEventGGA(
279-
datetime, ada_gps->fix, ada_gps->latitude, &ada_gps->lat,
280-
ada_gps->longitude, &ada_gps->lon, ada_gps->satellites,
281-
ada_gps->HDOP, ada_gps->altitude, ada_gps->geoidheight);
282-
} else {
283-
WS_DEBUG_PRINTLN(
284-
"[gps] WARNING - Parsed sentence is not type RMC or GGA!");
285-
}
254+
// Parse each NMEA sentence in the buffer
255+
char nmea_sentence[MAX_LEN_NMEA_SENTENCE];
256+
bool has_gps_event = false;
257+
while (NmeaBufPop(nmea_sentence) != -1) {
258+
// Parse the NMEA sentence
259+
WS_DEBUG_PRINT("[gps] Parsing NMEA sentence: ");
260+
WS_DEBUG_PRINTLN(nmea_sentence);
261+
if (!ada_gps->parse(nmea_sentence)) {
262+
continue; // Skip parsing this sentence if parsing failed
263+
} else {
264+
_gps_model->CreateGPSEvent();
265+
has_gps_event = true;
286266
}
287267

288-
// We did not create a GPSEvent because the NMEA sentences were not
289-
// GGA/RMC or parsed correctly
290-
if (!has_gps_event) {
291-
WS_DEBUG_PRINTLN("[gps] No GPSEvent created from NMEA sentences!");
292-
continue;
268+
// Build the GPSEvent message from the sentence
269+
wippersnapper_gps_GPSDateTime datetime = _gps_model->CreateGpsDatetime(
270+
ada_gps->hour, ada_gps->minute, ada_gps->seconds,
271+
ada_gps->milliseconds, ada_gps->day, ada_gps->month, ada_gps->year);
272+
if (strncmp(nmea_sentence, "$GPRMC", 6) == 0 ||
273+
strncmp(nmea_sentence, "$GNRMC", 6) == 0) {
274+
_gps_model->AddGpsEventRMC(
275+
datetime, ada_gps->fix, ada_gps->latitude, &ada_gps->lat,
276+
ada_gps->longitude, &ada_gps->lon, ada_gps->speed, ada_gps->angle);
277+
} else if (strncmp(nmea_sentence, "$GPGGA", 6) == 0 ||
278+
strncmp(nmea_sentence, "$GNGGA", 6) == 0) {
279+
_gps_model->AddGpsEventGGA(
280+
datetime, ada_gps->fix, ada_gps->latitude, &ada_gps->lat,
281+
ada_gps->longitude, &ada_gps->lon, ada_gps->satellites,
282+
ada_gps->HDOP, ada_gps->altitude, ada_gps->geoidheight);
283+
} else {
284+
WS_DEBUG_PRINTLN(
285+
"[gps] WARNING - Parsed sentence is not type RMC or GGA!");
293286
}
287+
}
294288

295-
// Encode and publish to IO
296-
WS_DEBUG_PRINT("[gps] Encoding and publishing GPSEvent to IO...");
297-
bool did_encode = _gps_model->EncodeGPSEvent();
298-
if (!did_encode) {
299-
WS_DEBUG_PRINTLN("[gps] ERROR: Failed to encode GPSEvent!");
289+
// We did not create a GPSEvent because the NMEA sentences were not
290+
// GGA/RMC or parsed correctly
291+
if (!has_gps_event) {
292+
WS_DEBUG_PRINTLN("[gps] No GPSEvent created from NMEA sentences!");
293+
continue;
294+
}
295+
296+
// Encode and publish to IO
297+
WS_DEBUG_PRINT("[gps] Encoding and publishing GPSEvent to IO...");
298+
bool did_encode = _gps_model->EncodeGPSEvent();
299+
if (!did_encode) {
300+
WS_DEBUG_PRINTLN("[gps] ERROR: Failed to encode GPSEvent!");
301+
} else {
302+
// Publish the GPSEvent to IO
303+
if (!WsV2.PublishSignal(wippersnapper_signal_DeviceToBroker_gps_event_tag,
304+
_gps_model->GetGPSEvent())) {
305+
WS_DEBUG_PRINTLN("[gps] ERROR: Failed to publish GPSEvent!");
300306
} else {
301-
// Publish the GPSEvent to IO
302-
if (!WsV2.PublishSignal(
303-
wippersnapper_signal_DeviceToBroker_gps_event_tag,
304-
_gps_model->GetGPSEvent())) {
305-
WS_DEBUG_PRINTLN("[gps] ERROR: Failed to publish GPSEvent!");
306-
} else {
307-
WS_DEBUG_PRINTLN("[gps] GPSEvent published successfully!");
308-
}
307+
WS_DEBUG_PRINTLN("[gps] GPSEvent published successfully!");
309308
}
310-
drv->SetPollPeriodPrv(cur_time);
309+
}
310+
drv->SetPollPeriodPrv(cur_time);
311311
}
312312
}

0 commit comments

Comments
 (0)