Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ config SM_GNSS
config SM_NRF_CLOUD
bool "nRF Cloud support"
default y
depends on NRF_CLOUD
depends on NRF_CLOUD_COAP
depends on DATE_TIME
select EXPERIMENTAL

if SM_NRF_CLOUD
Expand All @@ -261,6 +264,7 @@ endif # SM_NRF_CLOUD

config SM_NRF_CLOUD_LOCATION
bool "nRF Cloud Location support"
default y
depends on SM_NRF_CLOUD
help
Enable the nRF Cloud Location service for cloud-assisted geolocation.
Expand Down
1 change: 0 additions & 1 deletion app/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ CONFIG_SETTINGS_NVS=y
CONFIG_NVS=y

# nRF Cloud
CONFIG_SM_NRF_CLOUD_LOCATION=y
CONFIG_NRF_CLOUD=y
CONFIG_NRF_CLOUD_COAP=y
CONFIG_NRF_CLOUD_COAP_DOWNLOADS=n
Expand Down
66 changes: 54 additions & 12 deletions app/src/sm_at_gnss.c
Comment thread
trantanen marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ enum sm_gnss_operation {

#if defined(CONFIG_NRF_CLOUD_AGNSS)
static struct k_work agnss_req_work;
#endif

#if defined(CONFIG_SM_NRF_CLOUD_LOCATION)
static K_SEM_DEFINE(agnss_ncellmeas_sem, 0, 1);
static struct lte_lc_cells_info *agnss_net_info;
#endif /* CONFIG_SM_NRF_CLOUD_LOCATION */
#endif /* CONFIG_SM_NRF_CLOUD */

#if defined(CONFIG_NRF_CLOUD_PGPS)
static struct k_work pgps_req_work;
static struct k_work pgps_coap_req_work;
Expand Down Expand Up @@ -317,13 +323,26 @@ static int read_agnss_req(struct nrf_modem_gnss_agnss_data_frame *req)
#endif /* CONFIG_NRF_CLOUD_AGNSS || CONFIG_NRF_CLOUD_PGPS */

#if defined(CONFIG_NRF_CLOUD_AGNSS)

#if defined(CONFIG_SM_NRF_CLOUD_LOCATION)
static void agnss_ncellmeas_done(struct lte_lc_cells_info *cell_data, void *ctx)
{
ARG_UNUSED(ctx);
agnss_net_info = cell_data;
k_sem_give(&agnss_ncellmeas_sem);
}
#endif /* CONFIG_SM_NRF_CLOUD_LOCATION */

static void agnss_requestor(struct k_work *)
{
int err;
struct nrf_modem_gnss_agnss_data_frame req;
struct nrf_cloud_coap_agnss_request request = {
NRF_CLOUD_COAP_AGNSS_REQ_CUSTOM,
&req,
.type = NRF_CLOUD_COAP_AGNSS_REQ_CUSTOM,
.agnss_req = &req,
.net_info = NULL,
.filtered = false,
.mask_angle = 0,
};
char *agnss_rest_data_buf = calloc(1, NRF_CLOUD_AGNSS_MAX_DATA_SIZE);

Expand All @@ -339,20 +358,43 @@ static void agnss_requestor(struct k_work *)
}

struct nrf_cloud_coap_agnss_result result = {
agnss_rest_data_buf,
NRF_CLOUD_AGNSS_MAX_DATA_SIZE,
0
.buf = agnss_rest_data_buf,
.buf_sz = NRF_CLOUD_AGNSS_MAX_DATA_SIZE,
.agnss_sz = 0,
};
struct lte_lc_cells_info net_info = {0};

err = get_single_cell_info(&net_info.current_cell);
if (err) {
LOG_ERR("Failed to obtain single-cell cellular network information (%d).", err);
goto cleanup;
#if defined(CONFIG_SM_NRF_CLOUD_LOCATION)
/* Start async ncellmeas and wait for the result via semaphore.
* agnss_ncellmeas_done() is called from the AT monitor thread
* (not sm_work_q) for the single-phase case, so giving the semaphore
* does not deadlock this work item.
*/
struct lte_lc_cells_info *net_info = NULL;

err = sm_at_nrfcloud_ncellmeas_start(1, false, agnss_ncellmeas_done, NULL);
if (err == 0) {
/* We will wait for 5 seconds for NCELLMEAS to complete. */
k_sem_take(&agnss_ncellmeas_sem, K_SECONDS(5));
net_info = agnss_net_info;
agnss_net_info = NULL;
}
request.net_info = &net_info;

if (net_info != NULL && net_info->current_cell.id != LTE_LC_CELL_EUTRAN_ID_INVALID) {
request.net_info = net_info;
} else {
LOG_WRN("Requesting A-GNSS data without location assistance");
sm_at_nrfcloud_ncellmeas_cleanup(net_info);
net_info = NULL;
}
#else
LOG_INF("Requesting A-GNSS data without location assistance "
"since CONFIG_SM_NRF_CLOUD_LOCATION is not defined");
#endif
err = nrf_cloud_coap_agnss_data_get(&request, &result);
#if defined(CONFIG_SM_NRF_CLOUD_LOCATION)
sm_at_nrfcloud_ncellmeas_cleanup(net_info);
net_info = NULL;
#endif
if (err) {
LOG_ERR("Failed to request A-GNSS data via CoAP (%d).", err);
goto cleanup;
Expand Down
Loading
Loading