Skip to content

Commit a869025

Browse files
plskeggsmbolivar-nordic
authored andcommitted
lib: location: support combining A-GPS and P-GPS
When both A-GPS and P-GPS are enabled, pass the ephemerides assistance request to P-GPS, and not that or almanac assistance to A-GPS. In REST mode, if both A-GPS and P-GPS are enabled, invoke the P-GPS notify work function once A-GPS data has been received and processed. Utilize the current prediction if included with the PGPS_EVT_READY event. Rely on P-GPS library defaults to enable using a dedicated P-GPS partition instead of requiring reuse of the MCUboot secondary partition. Call nrf_cloud_pgps_notify_prediction() after processing P-GPS response, so prediction gets injected when available. Signed-off-by: Pete Skeggs <[email protected]>
1 parent 0e3155a commit a869025

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

lib/location/method_gnss.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#if defined(CONFIG_NRF_CLOUD_PGPS)
2323
#include <net/nrf_cloud_rest.h>
2424
#include <net/nrf_cloud_pgps.h>
25-
#include <pm_config.h>
2625
#endif
2726

2827
LOG_MODULE_DECLARE(location, CONFIG_LOCATION_LOG_LEVEL);
@@ -90,6 +89,7 @@ static K_SEM_DEFINE(entered_rrc_idle, 0, 1);
9089

9190
#if defined(CONFIG_NRF_CLOUD_AGPS) || defined(CONFIG_NRF_CLOUD_PGPS)
9291
static struct nrf_modem_gnss_agps_data_frame agps_request;
92+
static struct nrf_modem_gnss_agps_data_frame pgps_agps_request;
9393
#if defined(CONFIG_NRF_CLOUD_REST) && !defined(CONFIG_NRF_CLOUD_MQTT)
9494
#if defined(CONFIG_NRF_CLOUD_PGPS) || !defined(CONFIG_LOCATION_METHOD_GNSS_AGPS_EXTERNAL)
9595
static char rest_api_recv_buf[CONFIG_NRF_CLOUD_REST_FRAGMENT_SIZE +
@@ -117,7 +117,7 @@ static void method_gnss_manage_pgps(struct k_work *work)
117117

118118
LOG_DBG("Sending prediction to modem...");
119119

120-
err = nrf_cloud_pgps_inject(prediction, &agps_request);
120+
err = nrf_cloud_pgps_inject(prediction, &pgps_agps_request);
121121
if (err) {
122122
LOG_ERR("Unable to send prediction to modem: %d", err);
123123
}
@@ -132,7 +132,8 @@ void method_gnss_pgps_handler(struct nrf_cloud_pgps_event *event)
132132
{
133133
LOG_DBG("P-GPS event type: %d", event->type);
134134

135-
if (event->type == PGPS_EVT_AVAILABLE) {
135+
if ((event->type == PGPS_EVT_AVAILABLE) ||
136+
((event->type == PGPS_EVT_READY) && (event->prediction != NULL))) {
136137
prediction = event->prediction;
137138
k_work_submit_to_queue(location_core_work_queue_get(),
138139
&method_gnss_manage_pgps_work);
@@ -280,6 +281,12 @@ static void method_gnss_agps_request_work_fn(struct k_work *item)
280281
}
281282

282283
LOG_DBG("A-GPS data processed");
284+
285+
#if defined(CONFIG_NRF_CLOUD_PGPS)
286+
k_work_submit_to_queue(
287+
location_core_work_queue_get(),
288+
&method_gnss_notify_pgps_work);
289+
#endif
283290
}
284291
#endif /* #elif defined(CONFIG_NRF_CLOUD_REST) */
285292
#endif /* defined(CONFIG_NRF_CLOUD_AGPS) && !defined(CONFIG_LOCATION_METHOD_GNSS_AGPS_EXTERNAL) */
@@ -325,6 +332,13 @@ static void method_gnss_pgps_request_work_fn(struct k_work *item)
325332
}
326333

327334
LOG_DBG("P-GPS data processed");
335+
336+
err = nrf_cloud_pgps_notify_prediction();
337+
if (err) {
338+
LOG_ERR("GNSS: Failed to request current prediction, error: %d", err);
339+
} else {
340+
LOG_DBG("P-GPS prediction requested");
341+
}
328342
}
329343
#endif
330344

@@ -384,6 +398,13 @@ static void method_gnss_request_assistance(void)
384398
return;
385399
}
386400

401+
if (IS_ENABLED(CONFIG_NRF_CLOUD_PGPS)) {
402+
/* ephemerides come from P-GPS; almanacs not desired in this configuration */
403+
pgps_agps_request.sv_mask_ephe = agps_request.sv_mask_ephe;
404+
agps_request.sv_mask_ephe = 0;
405+
agps_request.sv_mask_alm = 0;
406+
}
407+
387408
LOG_DBG("A-GPS request from modem (ephe: 0x%08x alm: 0x%08x flags: 0x%02x)",
388409
agps_request.sv_mask_ephe,
389410
agps_request.sv_mask_alm,
@@ -738,8 +759,10 @@ int method_gnss_location_get(const struct location_method_config *config)
738759
if (!initialized) {
739760
struct nrf_cloud_pgps_init_param param = {
740761
.event_handler = method_gnss_pgps_handler,
741-
.storage_base = PM_MCUBOOT_SECONDARY_ADDRESS,
742-
.storage_size = PM_MCUBOOT_SECONDARY_SIZE};
762+
/* storage is defined by CONFIG_NRF_CLOUD_PGPS_STORAGE */
763+
.storage_base = 0u,
764+
.storage_size = 0u
765+
};
743766

744767
err = nrf_cloud_pgps_init(&param);
745768
if (err) {

samples/nrf9160/location/overlay-pgps.conf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
CONFIG_NRF_CLOUD_REST=y
1111
CONFIG_NRF_CLOUD_PGPS=y
1212
CONFIG_NRF_CLOUD_PGPS_REPLACEMENT_THRESHOLD=4
13-
CONFIG_NRF_CLOUD_PGPS_REQUEST_UPON_INIT=n
1413

1514
# Storage for P-GPS
1615
CONFIG_STREAM_FLASH=y
@@ -24,10 +23,5 @@ CONFIG_MPU_ALLOW_FLASH_WRITE=y
2423
# P-GPS needs more heap
2524
CONFIG_HEAP_MEM_POOL_SIZE=8192
2625

27-
# MCUBOOT - for partition containing PM_MCUBOOT_SECONDARY_ADDRESS
28-
CONFIG_BOOTLOADER_MCUBOOT=y
29-
CONFIG_IMG_MANAGER=y
30-
CONFIG_MCUBOOT_IMG_MANAGER=y
31-
3226
# Download client library stack size needs to be increased with P-GPS
3327
CONFIG_DOWNLOAD_CLIENT_STACK_SIZE=1280

0 commit comments

Comments
 (0)