Skip to content

Commit 1bc8490

Browse files
bjarki-andreasencarlescufi
authored andcommitted
drivers: gnss: match: Change RMC/GGA sync from timeout to UTC
Change the synchronization of RMC and GGA NMEA messages from a timeout to matching their UTC timestamps. Signed-off-by: Bjarki Arge Andreasen <[email protected]>
1 parent f0b4e4c commit 1bc8490

File tree

5 files changed

+31
-52
lines changed

5 files changed

+31
-52
lines changed

drivers/gnss/gnss_nmea0183_match.c

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,22 @@
1010

1111
#include <string.h>
1212

13+
#include "gnss_parse.h"
1314
#include "gnss_nmea0183.h"
1415
#include "gnss_nmea0183_match.h"
1516

16-
static bool gnss_nmea0183_match_timed_out(struct gnss_nmea0183_match_data *data)
17+
static int gnss_nmea0183_match_parse_utc(char **argv, uint16_t argc, uint32_t *utc)
1718
{
18-
int64_t delta;
19+
int64_t i64;
1920

20-
delta = k_uptime_delta(&data->timestamp);
21-
data->timestamp = k_uptime_get();
22-
return ((uint16_t)delta) > data->timeout_ms;
21+
if ((gnss_parse_dec_to_milli(argv[1], &i64) < 0) ||
22+
(i64 < 0) ||
23+
(i64 > UINT32_MAX)) {
24+
return -EINVAL;
25+
}
26+
27+
*utc = (uint32_t)i64;
28+
return 0;
2329
}
2430

2531
#if CONFIG_GNSS_SATELLITES
@@ -30,50 +36,47 @@ static void gnss_nmea0183_match_reset_gsv(struct gnss_nmea0183_match_data *data)
3036
}
3137
#endif
3238

33-
static void gnss_nmea0183_match_reset(struct gnss_nmea0183_match_data *data)
39+
static void gnss_nmea0183_match_publish(struct gnss_nmea0183_match_data *data)
3440
{
35-
data->gga_received = false;
36-
data->rmc_received = false;
41+
if ((data->gga_utc == 0) || (data->rmc_utc == 0)) {
42+
return;
43+
}
44+
45+
if (data->gga_utc == data->rmc_utc) {
46+
gnss_publish_data(data->gnss, &data->data);
47+
}
3748
}
3849

3950
void gnss_nmea0183_match_gga_callback(struct modem_chat *chat, char **argv, uint16_t argc,
4051
void *user_data)
4152
{
4253
struct gnss_nmea0183_match_data *data = user_data;
4354

44-
if (gnss_nmea0183_match_timed_out(data)) {
45-
gnss_nmea0183_match_reset(data);
46-
}
47-
4855
if (gnss_nmea0183_parse_gga((const char **)argv, argc, &data->data) < 0) {
4956
return;
5057
}
5158

52-
data->gga_received = true;
53-
54-
if (data->gga_received && data->rmc_received) {
55-
gnss_publish_data(data->gnss, &data->data);
59+
if (gnss_nmea0183_match_parse_utc(argv, argc, &data->gga_utc) < 0) {
60+
return;
5661
}
62+
63+
gnss_nmea0183_match_publish(data);
5764
}
5865

5966
void gnss_nmea0183_match_rmc_callback(struct modem_chat *chat, char **argv, uint16_t argc,
6067
void *user_data)
6168
{
6269
struct gnss_nmea0183_match_data *data = user_data;
6370

64-
if (gnss_nmea0183_match_timed_out(data)) {
65-
gnss_nmea0183_match_reset(data);
66-
}
67-
6871
if (gnss_nmea0183_parse_rmc((const char **)argv, argc, &data->data) < 0) {
6972
return;
7073
}
7174

72-
data->rmc_received = true;
73-
74-
if (data->gga_received && data->rmc_received) {
75-
gnss_publish_data(data->gnss, &data->data);
75+
if (gnss_nmea0183_match_parse_utc(argv, argc, &data->rmc_utc) < 0) {
76+
return;
7677
}
78+
79+
gnss_nmea0183_match_publish(data);
7780
}
7881

7982
#if CONFIG_GNSS_SATELLITES
@@ -84,10 +87,6 @@ void gnss_nmea0183_match_gsv_callback(struct modem_chat *chat, char **argv, uint
8487
struct gnss_nmea0183_gsv_header header;
8588
int ret;
8689

87-
if (gnss_nmea0183_match_timed_out(data)) {
88-
gnss_nmea0183_match_reset(data);
89-
}
90-
9190
if (gnss_nmea0183_parse_gsv_header((const char **)argv, argc, &header) < 0) {
9291
return;
9392
}
@@ -124,14 +123,13 @@ int gnss_nmea0183_match_init(struct gnss_nmea0183_match_data *data,
124123
const struct gnss_nmea0183_match_config *config)
125124
{
126125
__ASSERT(data != NULL, "data argument must be provided");
127-
__ASSERT(config != NULL, "data argument must be provided");
126+
__ASSERT(config != NULL, "config argument must be provided");
128127

129128
memset(data, 0, sizeof(struct gnss_nmea0183_match_data));
130129
data->gnss = config->gnss;
131130
#if CONFIG_GNSS_SATELLITES
132131
data->satellites = config->satellites;
133132
data->satellites_size = config->satellites_size;
134133
#endif
135-
data->timeout_ms = config->timeout_ms;
136134
return 0;
137135
}

drivers/gnss/gnss_nmea0183_match.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,9 @@ struct gnss_nmea0183_match_data {
4949
uint16_t satellites_size;
5050
uint16_t satellites_length;
5151
#endif
52-
int64_t timestamp;
53-
uint16_t timeout_ms;
54-
uint8_t gga_received : 1;
55-
uint8_t rmc_received : 1;
56-
uint8_t gsv_message_number : 6;
52+
uint32_t gga_utc;
53+
uint32_t rmc_utc;
54+
uint8_t gsv_message_number;
5755
};
5856

5957
/** GNSS NMEA0183 match configuration structure */
@@ -66,8 +64,6 @@ struct gnss_nmea0183_match_config {
6664
/** Number of elements in buffer for parsed satellites */
6765
uint16_t satellites_size;
6866
#endif
69-
/** The maximum time from the first to the last NMEA0183 message of a fix */
70-
uint16_t timeout_ms;
7167
};
7268

7369
/**

drivers/gnss/gnss_nmea_generic.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ LOG_MODULE_REGISTER(gnss_nmea_generic, CONFIG_GNSS_LOG_LEVEL);
2929

3030
struct gnss_nmea_generic_config {
3131
const struct device *uart;
32-
uint16_t nmea_timeout_ms;
3332
};
3433

3534
struct gnss_nmea_generic_data {
@@ -83,7 +82,6 @@ static struct gnss_driver_api gnss_api = {
8382

8483
static int gnss_nmea_generic_init_nmea0183_match(const struct device *dev)
8584
{
86-
const struct gnss_nmea_generic_config *cfg = dev->config;
8785
struct gnss_nmea_generic_data *data = dev->data;
8886

8987
const struct gnss_nmea0183_match_config match_config = {
@@ -92,7 +90,6 @@ static int gnss_nmea_generic_init_nmea0183_match(const struct device *dev)
9290
.satellites = data->satellites,
9391
.satellites_size = ARRAY_SIZE(data->satellites),
9492
#endif
95-
.timeout_ms = cfg->nmea_timeout_ms,
9693
};
9794

9895
return gnss_nmea0183_match_init(&data->match_data, &match_config);
@@ -163,7 +160,6 @@ static int gnss_nmea_generic_init(const struct device *dev)
163160
#define GNSS_NMEA_GENERIC(inst) \
164161
static struct gnss_nmea_generic_config gnss_nmea_generic_cfg_##inst = { \
165162
.uart = DEVICE_DT_GET(DT_INST_BUS(inst)), \
166-
.nmea_timeout_ms = DT_INST_PROP(inst, nmea_timeout_ms), \
167163
}; \
168164
\
169165
static struct gnss_nmea_generic_data gnss_nmea_generic_data_##inst; \

drivers/gnss/gnss_quectel_lcx6g.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,6 @@ static int quectel_lcx6g_init_nmea0183_match(const struct device *dev)
649649
.satellites = data->satellites,
650650
.satellites_size = ARRAY_SIZE(data->satellites),
651651
#endif
652-
.timeout_ms = 50,
653652
};
654653

655654
return gnss_nmea0183_match_init(&data->match_data, &config);

dts/bindings/gnss/gnss-nmea-generic.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,3 @@ compatible: "gnss-nmea-generic"
2020

2121
include:
2222
- uart-device.yaml
23-
24-
properties:
25-
nmea-timeout-ms:
26-
type: int
27-
default: 500
28-
description: |
29-
Synchronization timeout for NMEA sentences. The NMEA parser is expecting
30-
to receive a GGA and RMC sentences within this time frame to publish a
31-
location data. Set accordingly to the UART datarate and location
32-
reporting frequency. Defaults to 500ms if unspecified.

0 commit comments

Comments
 (0)