From c6d1dfc8f412867d0234be448dfcd3320aa3db42 Mon Sep 17 00:00:00 2001 From: Tommi Kangas Date: Thu, 3 Aug 2023 13:28:36 +0300 Subject: [PATCH] samples: cellular: gnss: GNSS QZSS assistance support Added support for QZSS assistance. Signed-off-by: Tommi Kangas --- samples/cellular/gnss/src/assistance.c | 34 ++++++++++++++++++++----- samples/cellular/gnss/src/main.c | 35 +++++++++++++++++++++++--- 2 files changed, 59 insertions(+), 10 deletions(-) diff --git a/samples/cellular/gnss/src/assistance.c b/samples/cellular/gnss/src/assistance.c index daa6ece48006..a06a673dfb3e 100644 --- a/samples/cellular/gnss/src/assistance.c +++ b/samples/cellular/gnss/src/assistance.c @@ -203,6 +203,25 @@ static void pgps_event_handler(struct nrf_cloud_pgps_event *event) } #endif /* CONFIG_NRF_CLOUD_PGPS */ +#if defined(CONFIG_NRF_CLOUD_AGPS) +static const char *get_system_string(uint8_t system_id) +{ + switch (system_id) { + case NRF_MODEM_GNSS_SYSTEM_INVALID: + return "invalid"; + + case NRF_MODEM_GNSS_SYSTEM_GPS: + return "GPS"; + + case NRF_MODEM_GNSS_SYSTEM_QZSS: + return "QZSS"; + + default: + return "unknown"; + } +} +#endif /* CONFIG_NRF_CLOUD_AGPS */ + int assistance_init(struct k_work_q *assistance_work_q) { work_q = assistance_work_q; @@ -242,9 +261,9 @@ int assistance_request(struct nrf_modem_gnss_agnss_data_frame *agnss_request) return 0; } - /* P-GPS will handle ephemerides, so skip those. */ + /* P-GPS will handle GPS ephemerides, so skip those. */ agnss_request->system[0].sv_mask_ephe = 0; - /* Almanacs are not needed with P-GPS, so skip those. */ + /* GPS almanacs are not needed with P-GPS, so skip those. */ agnss_request->system[0].sv_mask_alm = 0; #endif /* CONFIG_NRF_CLOUD_AGPS */ #endif /* CONFIG_NRF_CLOUD_PGPS */ @@ -307,10 +326,13 @@ int assistance_request(struct nrf_modem_gnss_agnss_data_frame *agnss_request) request.net_info = &net_info; } - LOG_INF("Requesting A-GPS data, ephe 0x%08x, alm 0x%08x, flags 0x%02x", - (uint32_t)agnss_request->system[0].sv_mask_ephe, - (uint32_t)agnss_request->system[0].sv_mask_alm, - agnss_request->data_flags); + LOG_INF("Requesting A-GNSS data: data_flags: 0x%02x", agnss_request->data_flags); + for (int i = 0; i < agnss_request->system_count; i++) { + LOG_INF("Requesting A-GNSS data: %s ephe: 0x%llx, alm: 0x%llx", + get_system_string(agnss_request->system[i].system_id), + agnss_request->system[i].sv_mask_ephe, + agnss_request->system[i].sv_mask_alm); + } err = nrf_cloud_rest_agps_data_get(&rest_ctx, &request, &result); if (err) { diff --git a/samples/cellular/gnss/src/main.c b/samples/cellular/gnss/src/main.c index b6b627e4f590..a966e37415d3 100644 --- a/samples/cellular/gnss/src/main.c +++ b/samples/cellular/gnss/src/main.c @@ -232,6 +232,23 @@ void lte_disconnect(void) } #endif /* CONFIG_GNSS_SAMPLE_LTE_ON_DEMAND */ +static const char *get_system_string(uint8_t system_id) +{ + switch (system_id) { + case NRF_MODEM_GNSS_SYSTEM_INVALID: + return "invalid"; + + case NRF_MODEM_GNSS_SYSTEM_GPS: + return "GPS"; + + case NRF_MODEM_GNSS_SYSTEM_QZSS: + return "QZSS"; + + default: + return "unknown"; + } +} + static void agnss_data_get_work_fn(struct k_work *item) { ARG_UNUSED(item); @@ -268,12 +285,22 @@ static void agnss_data_get_work_fn(struct k_work *item) } #endif /* CONFIG_GNSS_SAMPLE_ASSISTANCE_MINIMAL */ + if (last_agnss.data_flags == 0 && + last_agnss.system[0].sv_mask_ephe == 0 && + last_agnss.system[0].sv_mask_alm == 0) { + LOG_INF("Ignoring assistance request because only QZSS data is requested"); + return; + } + requesting_assistance = true; - LOG_INF("Assistance data needed, ephe 0x%08x, alm 0x%08x, flags 0x%02x", - (uint32_t)last_agnss.system[0].sv_mask_ephe, - (uint32_t)last_agnss.system[0].sv_mask_alm, - last_agnss.data_flags); + LOG_INF("Assistance data needed: data_flags: 0x%02x", last_agnss.data_flags); + for (int i = 0; i < last_agnss.system_count; i++) { + LOG_INF("Assistance data needed: %s ephe: 0x%llx, alm: 0x%llx", + get_system_string(last_agnss.system[i].system_id), + last_agnss.system[i].sv_mask_ephe, + last_agnss.system[i].sv_mask_alm); + } #if defined(CONFIG_GNSS_SAMPLE_LTE_ON_DEMAND) lte_connect();