Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for GNSS API assistance usage #106

Merged
merged 13 commits into from
Aug 24, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ struct cloud_data_agps_request {
/** Area Code. */
uint32_t area;
/** AGPS request types */
struct nrf_modem_gnss_agps_data_frame request;
struct nrf_modem_gnss_agnss_data_frame request;
/** Flag signifying that the data entry is to be encoded. */
bool queued : 1;
};
Expand Down
22 changes: 14 additions & 8 deletions applications/asset_tracker_v2/src/cloud/cloud_codec/json_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ int json_common_agps_request_data_add(cJSON *parent,
return -ENOMEM;
}

if (data->request.data_flags & NRF_MODEM_GNSS_AGPS_GPS_UTC_REQUEST) {
if (data->request.data_flags & NRF_MODEM_GNSS_AGNSS_GPS_UTC_REQUEST) {
err = json_add_number_to_array(agps_types,
DATA_AGPS_REQUEST_TYPE_UTC_PARAMETERS);
if (err) {
Expand All @@ -829,7 +829,13 @@ int json_common_agps_request_data_add(cJSON *parent,
}
}

if (data->request.sv_mask_ephe) {
/* GPS data need is always expected to be present and first in list. */
__ASSERT(data->request.system_count > 0,
"GNSS system data need not found");
__ASSERT(data->request.system[0].system_id == NRF_MODEM_GNSS_SYSTEM_GPS,
"GPS data need not found");

if (data->request.system[0].sv_mask_ephe) {
err = json_add_number_to_array(agps_types,
DATA_AGPS_REQUEST_TYPE_EPHEMERIDES);
if (err) {
Expand All @@ -838,7 +844,7 @@ int json_common_agps_request_data_add(cJSON *parent,
}
}

if (data->request.sv_mask_alm) {
if (data->request.system[0].sv_mask_alm) {
err = json_add_number_to_array(agps_types,
DATA_AGPS_REQUEST_TYPE_ALMANAC);
if (err) {
Expand All @@ -847,7 +853,7 @@ int json_common_agps_request_data_add(cJSON *parent,
}
}

if (data->request.data_flags & NRF_MODEM_GNSS_AGPS_KLOBUCHAR_REQUEST) {
if (data->request.data_flags & NRF_MODEM_GNSS_AGNSS_KLOBUCHAR_REQUEST) {
err = json_add_number_to_array(agps_types,
DATA_AGPS_REQUEST_TYPE_KLOBUCHAR_CORRECTION);
if (err) {
Expand All @@ -856,7 +862,7 @@ int json_common_agps_request_data_add(cJSON *parent,
}
}

if (data->request.data_flags & NRF_MODEM_GNSS_AGPS_NEQUICK_REQUEST) {
if (data->request.data_flags & NRF_MODEM_GNSS_AGNSS_NEQUICK_REQUEST) {
err = json_add_number_to_array(agps_types,
DATA_AGPS_REQUEST_TYPE_NEQUICK_CORRECTION);
if (err) {
Expand All @@ -865,7 +871,7 @@ int json_common_agps_request_data_add(cJSON *parent,
}
}

if (data->request.data_flags & NRF_MODEM_GNSS_AGPS_SYS_TIME_AND_SV_TOW_REQUEST) {
if (data->request.data_flags & NRF_MODEM_GNSS_AGNSS_GPS_SYS_TIME_AND_SV_TOW_REQUEST) {
err = json_add_number_to_array(agps_types,
DATA_AGPS_REQUEST_TYPE_GPS_TOWS);
if (err) {
Expand All @@ -881,7 +887,7 @@ int json_common_agps_request_data_add(cJSON *parent,
}
}

if (data->request.data_flags & NRF_MODEM_GNSS_AGPS_POSITION_REQUEST) {
if (data->request.data_flags & NRF_MODEM_GNSS_AGNSS_POSITION_REQUEST) {
err = json_add_number_to_array(agps_types,
DATA_AGPS_REQUEST_TYPE_LOCATION);
if (err) {
Expand All @@ -890,7 +896,7 @@ int json_common_agps_request_data_add(cJSON *parent,
}
}

if (data->request.data_flags & NRF_MODEM_GNSS_AGPS_INTEGRITY_REQUEST) {
if (data->request.data_flags & NRF_MODEM_GNSS_AGNSS_INTEGRITY_REQUEST) {
err = json_add_number_to_array(agps_types,
DATA_AGPS_REQUEST_TYPE_INTEGRITY);
if (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ enum location_module_event_type {
LOCATION_MODULE_EVT_SHUTDOWN_READY,

/** The location library has reported that it needs GPS assistance data.
* The event has associated payload of the type ``struct nrf_modem_gnss_agps_data_frame``
* The event has associated payload of the type ``struct nrf_modem_gnss_agnss_data_frame``
* in the event struct member ``data.agps_request``, which contains the types
* of A-GPS data that the modem needs.
*/
Expand Down Expand Up @@ -184,7 +184,7 @@ struct location_module_event {
/** Data for event LOCATION_MODULE_EVT_CLOUD_LOCATION_DATA_READY. */
struct location_module_cloud_location cloud_location;
/** Data for event LOCATION_MODULE_EVT_AGPS_NEEDED. */
struct nrf_modem_gnss_agps_data_frame agps_request;
struct nrf_modem_gnss_agnss_data_frame agps_request;
#if defined(CONFIG_NRF_CLOUD_PGPS)
/** Data for event LOCATION_MODULE_EVT_PGPS_NEEDED. */
struct gps_pgps_request pgps_request;
Expand Down
35 changes: 14 additions & 21 deletions applications/asset_tracker_v2/src/modules/data_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ enum coneval_supported_data_type {
bool agps_request_buffered;

/* Buffered A-GPS request. */
struct nrf_modem_gnss_agps_data_frame agps_request_buffer;
struct nrf_modem_gnss_agnss_data_frame agps_request_buffer;

/* Data module message queue. */
#define DATA_QUEUE_ENTRY_COUNT 10
Expand Down Expand Up @@ -704,7 +704,7 @@ static int get_modem_info(struct modem_param_info *const modem_info)
*
* @return 0 on success, otherwise a negative error code indicating reason of failure.
*/
static int agps_request_encode(struct nrf_modem_gnss_agps_data_frame *incoming_request)
static int agps_request_encode(struct nrf_modem_gnss_agnss_data_frame *incoming_request)
{
int err;
struct cloud_codec_data codec = {0};
Expand All @@ -720,15 +720,16 @@ static int agps_request_encode(struct nrf_modem_gnss_agps_data_frame *incoming_r
const uint32_t mask = IS_ENABLED(CONFIG_NRF_CLOUD_PGPS) ? 0u : 0xFFFFFFFFu;

LOG_DBG("Requesting all A-GPS elements");
cloud_agps_request.request.sv_mask_ephe = mask,
cloud_agps_request.request.sv_mask_alm = mask,
cloud_agps_request.request.data_flags =
NRF_MODEM_GNSS_AGPS_GPS_UTC_REQUEST |
NRF_MODEM_GNSS_AGPS_KLOBUCHAR_REQUEST |
NRF_MODEM_GNSS_AGPS_NEQUICK_REQUEST |
NRF_MODEM_GNSS_AGPS_SYS_TIME_AND_SV_TOW_REQUEST |
NRF_MODEM_GNSS_AGPS_POSITION_REQUEST |
NRF_MODEM_GNSS_AGPS_INTEGRITY_REQUEST;
NRF_MODEM_GNSS_AGNSS_GPS_UTC_REQUEST |
NRF_MODEM_GNSS_AGNSS_KLOBUCHAR_REQUEST |
NRF_MODEM_GNSS_AGNSS_NEQUICK_REQUEST |
NRF_MODEM_GNSS_AGNSS_GPS_SYS_TIME_AND_SV_TOW_REQUEST |
NRF_MODEM_GNSS_AGNSS_POSITION_REQUEST |
NRF_MODEM_GNSS_AGNSS_INTEGRITY_REQUEST;
cloud_agps_request.request.system_count = 1;
cloud_agps_request.request.system[0].sv_mask_ephe = mask;
cloud_agps_request.request.system[0].sv_mask_alm = mask;
} else {
cloud_agps_request.request = *incoming_request;
}
Expand Down Expand Up @@ -1055,25 +1056,17 @@ static void new_config_handle(struct cloud_data_cfg *new_config)
* requested by the modem. If incoming_request is NULL, all A-GPS data
* types are requested.
*/
static void agps_request_handle(struct nrf_modem_gnss_agps_data_frame *incoming_request)
static void agps_request_handle(struct nrf_modem_gnss_agnss_data_frame *incoming_request)
{
int err;

#if defined(CONFIG_NRF_CLOUD_AGPS)
struct nrf_modem_gnss_agps_data_frame request;

if (incoming_request != NULL) {
request.sv_mask_ephe = incoming_request->sv_mask_ephe;
request.sv_mask_alm = incoming_request->sv_mask_alm;
request.data_flags = incoming_request->data_flags;
}

#if defined(CONFIG_NRF_CLOUD_MQTT)
/* If CONFIG_NRF_CLOUD_MQTT is enabled, the nRF Cloud MQTT transport library will be used
* to send the request.
*/
err = (incoming_request == NULL) ? nrf_cloud_agps_request_all() :
nrf_cloud_agps_request(&request);
nrf_cloud_agps_request(incoming_request);
if (err) {
LOG_WRN("Failed to request A-GPS data, error: %d", err);
LOG_DBG("This is expected to fail if we are not in a connected state");
Expand All @@ -1091,7 +1084,7 @@ static void agps_request_handle(struct nrf_modem_gnss_agps_data_frame *incoming_
* up and send to the cloud that is currently used.
*/
err = (incoming_request == NULL) ? agps_request_encode(NULL) :
agps_request_encode(&request);
agps_request_encode(incoming_request);
if (err) {
LOG_WRN("Failed to request A-GPS data, error: %d", err);
} else {
Expand Down
14 changes: 7 additions & 7 deletions applications/serial_lte_modem/src/gnss/slm_at_gnss.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ static int gnss_shutdown(void)
}

#if defined(CONFIG_NRF_CLOUD_AGPS) || defined(CONFIG_NRF_CLOUD_PGPS)
static int read_agps_req(struct nrf_modem_gnss_agps_data_frame *req)
static int read_agps_req(struct nrf_modem_gnss_agnss_data_frame *req)
{
int err;

err = nrf_modem_gnss_read((void *)req, sizeof(*req),
NRF_MODEM_GNSS_DATA_AGPS_REQ);
NRF_MODEM_GNSS_DATA_AGNSS_REQ);
if (err) {
LOG_ERR("Failed to read GNSS AGPS req, error %d", err);
return -EAGAIN;
Expand All @@ -169,7 +169,7 @@ static int read_agps_req(struct nrf_modem_gnss_agps_data_frame *req)
static void agps_req_wk(struct k_work *work)
{
int err;
struct nrf_modem_gnss_agps_data_frame req;
struct nrf_modem_gnss_agnss_data_frame req;

ARG_UNUSED(work);

Expand Down Expand Up @@ -221,10 +221,10 @@ static void pgps_event_handler(struct nrf_cloud_pgps_event *event)
break;
/* A P-GPS prediction is available now for the current date and time. */
case PGPS_EVT_AVAILABLE: {
struct nrf_modem_gnss_agps_data_frame req;
struct nrf_modem_gnss_agnss_data_frame req;

LOG_INF("PGPS_EVT_AVAILABLE");
/* read out previous NRF_MODEM_GNSS_EVT_AGPS_REQ */
/* read out previous NRF_MODEM_GNSS_EVT_AGNSS_REQ */
err = read_agps_req(&req);
if (err) {
/* Ephemerides assistance only */
Expand Down Expand Up @@ -458,8 +458,8 @@ static void gnss_event_handler(int event)
on_gnss_evt_nmea();
}
break;
case NRF_MODEM_GNSS_EVT_AGPS_REQ:
LOG_INF("GNSS_EVT_AGPS_REQ");
case NRF_MODEM_GNSS_EVT_AGNSS_REQ:
LOG_INF("GNSS_EVT_AGNSS_REQ");
on_gnss_evt_agps_req();
break;
case NRF_MODEM_GNSS_EVT_BLOCKED:
Expand Down
2 changes: 1 addition & 1 deletion include/modem/location.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ struct location_event_data {
* A-GPS notification data frame used by GNSS to let the application know it
* needs new assistance data, used with event LOCATION_EVT_GNSS_ASSISTANCE_REQUEST.
*/
struct nrf_modem_gnss_agps_data_frame agps_request;
struct nrf_modem_gnss_agnss_data_frame agps_request;
tokangas marked this conversation as resolved.
Show resolved Hide resolved
#endif
#if defined(CONFIG_LOCATION_SERVICE_EXTERNAL) && defined(CONFIG_NRF_CLOUD_PGPS)
/**
Expand Down
2 changes: 1 addition & 1 deletion include/net/lwm2m_client_utils_location.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void location_assistance_set_result_code_cb(location_assistance_result_code_cb_t
* @return Returns a negative error code (errno.h) indicating
* reason of failure or 0 for success.
*/
int location_assistance_agps_set_mask(const struct nrf_modem_gnss_agps_data_frame *agps_req);
int location_assistance_agps_set_mask(const struct nrf_modem_gnss_agnss_data_frame *agps_req);

/**
* @brief Send the A-GPS assistance request to LwM2M server
Expand Down
4 changes: 2 additions & 2 deletions include/net/nrf_cloud_agps.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extern "C" {
* @retval -EACCES Cloud connection is not established; wait for @ref NRF_CLOUD_EVT_READY.
* @return A negative value indicates an error.
*/
int nrf_cloud_agps_request(const struct nrf_modem_gnss_agps_data_frame *request);
int nrf_cloud_agps_request(const struct nrf_modem_gnss_agnss_data_frame *request);

/** @brief Requests all available A-GPS data from nRF Cloud via MQTT.
*
Expand Down Expand Up @@ -63,7 +63,7 @@ int nrf_cloud_agps_process(const char *buf, size_t buf_len);
* @param received_elements return copy of requested elements received
* since A-GPS request was made
*/
void nrf_cloud_agps_processed(struct nrf_modem_gnss_agps_data_frame *received_elements);
void nrf_cloud_agps_processed(struct nrf_modem_gnss_agnss_data_frame *received_elements);

/** @brief Query whether A-GPS data has been requested from cloud
*
Expand Down
4 changes: 2 additions & 2 deletions include/net/nrf_cloud_pgps.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#if defined(CONFIG_NRF_MODEM)
#include <nrf_modem_gnss.h>
#else
struct nrf_modem_gnss_agps_data_frame;
struct nrf_modem_gnss_agnss_data_frame;
#endif
#include "nrf_cloud_agps_schema_v1.h"

Expand Down Expand Up @@ -330,7 +330,7 @@ int nrf_cloud_pgps_process(const char *buf, size_t buf_len);
* @return 0 if successful, otherwise a (negative) error code.
*/
int nrf_cloud_pgps_inject(struct nrf_cloud_pgps_prediction *p,
const struct nrf_modem_gnss_agps_data_frame *request);
const struct nrf_modem_gnss_agnss_data_frame *request);

/** @brief Find out if P-GPS update is in progress
*
Expand Down
4 changes: 2 additions & 2 deletions include/net/nrf_cloud_rest.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ enum nrf_cloud_rest_agps_req_type {
NRF_CLOUD_REST_AGPS_REQ_ASSISTANCE,
/** Request only location (NRF_CLOUD_AGPS_LOCATION) */
NRF_CLOUD_REST_AGPS_REQ_LOCATION,
/** Request the data specified by nrf_modem_gnss_agps_data_frame */
/** Request the data specified by nrf_modem_gnss_agnss_data_frame */
NRF_CLOUD_REST_AGPS_REQ_CUSTOM
};

Expand Down Expand Up @@ -131,7 +131,7 @@ struct nrf_cloud_rest_location_request {
struct nrf_cloud_rest_agps_request {
enum nrf_cloud_rest_agps_req_type type;
/** Required for custom request type (NRF_CLOUD_REST_AGPS_REQ_CUSTOM) */
struct nrf_modem_gnss_agps_data_frame *agps_req;
struct nrf_modem_gnss_agnss_data_frame *agnss_req;
/** Optional; provide network info or set to NULL. The cloud cannot
* provide location assistance data if network info is NULL.
*/
Expand Down
6 changes: 3 additions & 3 deletions include/supl_os_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
*
* @brief Start a SUPL session
*
* @param[in] agps_request This contain the information about the AGPS data
* that the GNSS module is requesting from the server.
* @param[in] agnss_request This contain the information about the A-GNSS data
* that the GNSS module is requesting from the server.
*
* @return 0 SUPL session was successful.
* <0 SUPL session failed.
*/
int supl_session(const struct nrf_modem_gnss_agps_data_frame *const agps_request);
int supl_session(const struct nrf_modem_gnss_agnss_data_frame *const agnss_request);

/**
* @brief Setup the API and the buffers required by
Expand Down
7 changes: 7 additions & 0 deletions lib/location/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ config LOCATION_METHOD_GNSS_VISIBILITY_DETECTION_SAT_LIMIT
when A-GPS is used. Without assistance, the value should probably be adjusted, because
GNSS acquires satellites more slowly.

config LOCATION_METHOD_GNSS_PRIORITIZE_QZSS_ASSISTANCE
bool "Allow A-GNSS data request when only QZSS assistance is needed"
help
By default, QZSS assistance data is only requested when some other assistance data is
needed at the same time. Enabling this option allows A-GNSS data request to be sent also
when only QZSS assistance data (usually ephemerides) is needed.

endif # LOCATION_METHOD_GNSS

if LOCATION_METHOD_WIFI
Expand Down
6 changes: 3 additions & 3 deletions lib/location/location_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,13 +505,13 @@ void location_core_event_cb_timeout(void)
}

#if defined(CONFIG_LOCATION_SERVICE_EXTERNAL) && defined(CONFIG_NRF_CLOUD_AGPS)
void location_core_event_cb_agps_request(const struct nrf_modem_gnss_agps_data_frame *request)
void location_core_event_cb_agps_request(const struct nrf_modem_gnss_agnss_data_frame *request)
{
struct location_event_data agps_request_event_data;

LOG_DBG("Request A-GPS data from application: ephe 0x%08x, alm 0x%08x, data_flags 0x%02x",
request->sv_mask_ephe,
request->sv_mask_alm,
(uint32_t)request->system[0].sv_mask_ephe,
(uint32_t)request->system[0].sv_mask_alm,
request->data_flags);

agps_request_event_data.id = LOCATION_EVT_GNSS_ASSISTANCE_REQUEST;
Expand Down
2 changes: 1 addition & 1 deletion lib/location/location_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void location_core_event_cb(const struct location_data *location);
void location_core_event_cb_error(void);
void location_core_event_cb_timeout(void);
#if defined(CONFIG_LOCATION_SERVICE_EXTERNAL) && defined(CONFIG_NRF_CLOUD_AGPS)
void location_core_event_cb_agps_request(const struct nrf_modem_gnss_agps_data_frame *request);
void location_core_event_cb_agps_request(const struct nrf_modem_gnss_agnss_data_frame *request);
#endif
#if defined(CONFIG_LOCATION_SERVICE_EXTERNAL) && defined(CONFIG_NRF_CLOUD_PGPS)
void location_core_event_cb_pgps_request(const struct gps_pgps_request *request);
Expand Down
Loading