Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
fix: update from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Feb 17, 2023
1 parent c199c59 commit 5116d04
Show file tree
Hide file tree
Showing 32 changed files with 304 additions and 416 deletions.
7 changes: 5 additions & 2 deletions doc/location_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ The location module receives configuration updates as payload in the following t

The module sends the following events based on the outcome of the location request:
* ``LOCATION_MODULE_EVT_GNSS_DATA_READY``: GNSS position has been acquired
* ``LOCATION_MODULE_EVT_NEIGHBOR_CELLS_DATA_READY``: neighbor cell measurements have been obtained
* ``LOCATION_MODULE_EVT_WIFI_ACCESS_POINTS_DATA_READY``: Wi-Fi access points have been obtained
* ``LOCATION_MODULE_EVT_CLOUD_LOCATION_DATA_READY``: neighbor cell measurements or Wi-Fi access points (or both) have been obtained
* ``LOCATION_MODULE_EVT_DATA_NOT_READY``: Location request failed
* ``LOCATION_MODULE_EVT_TIMEOUT``: Timeout occurred
* ``LOCATION_MODULE_EVT_AGPS_NEEDED``: A-GPS request should be sent to cloud
Expand Down Expand Up @@ -98,6 +97,10 @@ In this sense, it differs from many other modules.

All incoming events from other modules are handled in the context of the Application Event Manager callback, because they all complete fast enough to not require a separate thread.

The :ref:`lib_location` library handles cellular and Wi-Fi positioning together when the location request method list has them next to each other.
This means that LTE neighbor cell measurements and Wi-Fi scanning results are combined into the same ``LOCATION_EVT_CLOUD_LOCATION_EXT_REQUEST`` event.
The location module responds to the :ref:`lib_location` library with unknown location resolution, because it does not request the location back from cloud service.

Configuration options
*********************

Expand Down
2 changes: 1 addition & 1 deletion src/cloud/aws_iot_integration.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ int cloud_wrap_ui_send(char *buf, size_t len, bool ack, uint32_t id,
return 0;
}

int cloud_wrap_neighbor_cells_send(char *buf, size_t len, bool ack, uint32_t id)
int cloud_wrap_cloud_location_send(char *buf, size_t len, bool ack, uint32_t id)
{
int err;
struct aws_iot_data msg = {
Expand Down
2 changes: 1 addition & 1 deletion src/cloud/azure_iot_hub_integration.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ int cloud_wrap_ui_send(char *buf, size_t len, bool ack, uint32_t id,
return 0;
}

int cloud_wrap_neighbor_cells_send(char *buf, size_t len, bool ack, uint32_t id)
int cloud_wrap_cloud_location_send(char *buf, size_t len, bool ack, uint32_t id)
{
int err;
struct azure_iot_hub_msg msg = {
Expand Down
22 changes: 10 additions & 12 deletions src/cloud/cloud_codec/aws_iot/aws_iot_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ int cloud_codec_init(struct cloud_data_cfg *cfg, cloud_codec_evt_handler_t event
return 0;
}

int cloud_codec_encode_neighbor_cells(struct cloud_codec_data *output,
struct cloud_data_neighbor_cells *neighbor_cells)
int cloud_codec_encode_cloud_location(
struct cloud_codec_data *output,
struct cloud_data_cloud_location *cloud_location)
{
int err;
char *buffer;

__ASSERT_NO_MSG(output != NULL);
__ASSERT_NO_MSG(neighbor_cells != NULL);
__ASSERT_NO_MSG(cloud_location != NULL);

cJSON *root_obj = cJSON_CreateObject();

Expand All @@ -74,7 +75,12 @@ int cloud_codec_encode_neighbor_cells(struct cloud_codec_data *output,
return -ENOMEM;
}

err = json_common_neighbor_cells_data_add(root_obj, neighbor_cells,
if (!cloud_location->neighbor_cells_valid) {
err = -ENODATA;
goto exit;
}

err = json_common_neighbor_cells_data_add(root_obj, &cloud_location->neighbor_cells,
JSON_COMMON_ADD_DATA_TO_OBJECT);
if (err) {
goto exit;
Expand All @@ -100,14 +106,6 @@ int cloud_codec_encode_neighbor_cells(struct cloud_codec_data *output,
return err;
}

#if defined(CONFIG_LOCATION_METHOD_WIFI)
int cloud_codec_encode_wifi_access_points(struct cloud_codec_data *output,
struct cloud_data_wifi_access_points *wifi_access_points)
{
return -ENOTSUP;
}
#endif

int cloud_codec_encode_agps_request(struct cloud_codec_data *output,
struct cloud_data_agps_request *agps_request)
{
Expand Down
22 changes: 10 additions & 12 deletions src/cloud/cloud_codec/azure_iot_hub/azure_iot_hub_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,28 @@ int cloud_codec_init(struct cloud_data_cfg *cfg, cloud_codec_evt_handler_t event
return 0;
}

int cloud_codec_encode_neighbor_cells(struct cloud_codec_data *output,
struct cloud_data_neighbor_cells *neighbor_cells)
int cloud_codec_encode_cloud_location(
struct cloud_codec_data *output,
struct cloud_data_cloud_location *cloud_location)
{
int err;
char *buffer;

__ASSERT_NO_MSG(output != NULL);
__ASSERT_NO_MSG(neighbor_cells != NULL);
__ASSERT_NO_MSG(cloud_location != NULL);

cJSON *root_obj = cJSON_CreateObject();

if (root_obj == NULL) {
return -ENOMEM;
}

err = json_common_neighbor_cells_data_add(root_obj, neighbor_cells,
if (!cloud_location->neighbor_cells_valid) {
err = -ENODATA;
goto exit;
}

err = json_common_neighbor_cells_data_add(root_obj, &cloud_location->neighbor_cells,
JSON_COMMON_ADD_DATA_TO_OBJECT);
if (err) {
goto exit;
Expand All @@ -70,14 +76,6 @@ int cloud_codec_encode_neighbor_cells(struct cloud_codec_data *output,
return err;
}

#if defined(CONFIG_LOCATION_METHOD_WIFI)
int cloud_codec_encode_wifi_access_points(struct cloud_codec_data *output,
struct cloud_data_wifi_access_points *wifi_access_points)
{
return -ENOTSUP;
}
#endif

int cloud_codec_encode_agps_request(struct cloud_codec_data *output,
struct cloud_data_agps_request *agps_request)
{
Expand Down
47 changes: 22 additions & 25 deletions src/cloud/cloud_codec/cloud_codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,23 @@ struct cloud_data_wifi_access_points {
};
#endif

struct cloud_data_cloud_location {
/** Neighbor cell information is valid. */
bool neighbor_cells_valid;
/** Neighbor cells. */
struct cloud_data_neighbor_cells neighbor_cells;
#if defined(CONFIG_LOCATION_METHOD_WIFI)
/** Wi-Fi access point information is valid. */
bool wifi_access_points_valid;
/** Wi-Fi access points. */
struct cloud_data_wifi_access_points wifi_access_points;
#endif
/** Cloud location info timestamp. UNIX milliseconds. */
int64_t ts;
/** Flag signifying that the data entry is to be encoded. */
bool queued : 1;
};

struct cloud_data_agps_request {
/** Mobile Country Code. */
int mcc;
Expand Down Expand Up @@ -283,44 +300,24 @@ typedef void (*cloud_codec_evt_handler_t)(const struct cloud_codec_evt *evt);
int cloud_codec_init(struct cloud_data_cfg *cfg, cloud_codec_evt_handler_t event_handler);

/**
* @brief Encode cloud codec neighbor cells data.
*
* @note LwM2M builds: This function does not output a list of objects, unlike other
* functions in this API. The object references that are required to update
* neighbor cell measurements are kept internal in the LwM2M utils library.
*
* @param[out] output String buffer for encoding result.
* @param[in] neighbor_cells Neighbor cells data.
*
* @retval 0 on success.
* @retval -ENODATA if data object is not marked valid.
* @retval -ENOMEM if codec couldn't allocate memory.
* @retval -EINVAL if the data is invalid.
* @retval -ENOTSUP if the function is not supported by the encoding backend.
*/
int cloud_codec_encode_neighbor_cells(struct cloud_codec_data *output,
struct cloud_data_neighbor_cells *neighbor_cells);

#if defined(CONFIG_LOCATION_METHOD_WIFI)
/**
* @brief Encode cloud codec Wi-Fi access points data.
* @brief Encode cloud codec cloud location data.
*
* @note LwM2M builds: This function does not output a list of objects, unlike other
* functions in this API. The object references that are required to update
* Wi-Fi access points are kept internal in the LwM2M utils library.
*
* @param[out] output String buffer for encoding result.
* @param[in] wifi_access_points Wi-Fi access points.
* @param[in] cloud_location Cloud location data.
*
* @retval 0 on success.
* @retval -ENODATA if data object is not marked valid.
* @retval -ENOMEM if codec could not allocate memory.
* @retval -EINVAL if the data is invalid.
* @retval -ENOTSUP if the function is not supported by the encoding backend.
*/
int cloud_codec_encode_wifi_access_points(struct cloud_codec_data *output,
struct cloud_data_wifi_access_points *wifi_access_points);
#endif
int cloud_codec_encode_cloud_location(
struct cloud_codec_data *output,
struct cloud_data_cloud_location *cloud_location);

/**
* @brief Encode cloud codec A-GPS request.
Expand Down
16 changes: 4 additions & 12 deletions src/cloud/cloud_codec/lwm2m/lwm2m_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,30 +85,22 @@ int cloud_codec_init(struct cloud_data_cfg *cfg, cloud_codec_evt_handler_t event
return 0;
}

int cloud_codec_encode_neighbor_cells(struct cloud_codec_data *output,
struct cloud_data_neighbor_cells *neighbor_cells)
int cloud_codec_encode_cloud_location(struct cloud_codec_data *output,
struct cloud_data_cloud_location *cloud_location)
{
ARG_UNUSED(output);

int err;

err = lwm2m_codec_helpers_set_neighbor_cell_data(neighbor_cells);
err = lwm2m_codec_helpers_set_neighbor_cell_data(&cloud_location->neighbor_cells);
if (err) {
return err;
}

neighbor_cells->queued = false;
cloud_location->queued = false;
return 0;
}

#if defined(CONFIG_LOCATION_METHOD_WIFI)
int cloud_codec_encode_wifi_access_points(struct cloud_codec_data *output,
struct cloud_data_wifi_access_points *wifi_access_points)
{
return -ENOTSUP;
}
#endif

int cloud_codec_encode_agps_request(struct cloud_codec_data *output,
struct cloud_data_agps_request *agps_request)
{
Expand Down
4 changes: 1 addition & 3 deletions src/cloud/cloud_codec/lwm2m/lwm2m_codec_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,9 +920,7 @@ int lwm2m_codec_helpers_set_neighbor_cell_data(struct cloud_data_neighbor_cells
cells->ncells_count = neighbor_cells->cell_data.ncells_count;

err = lwm2m_update_signal_meas_objects((const struct lte_lc_cells_info *)cells);
if (err == -ENODATA) {
LOG_DBG("No neighboring cells available");
} else if (err) {
if (err) {
return err;
}

Expand Down
83 changes: 26 additions & 57 deletions src/cloud/cloud_codec/nrf_cloud/nrf_cloud_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,77 +695,47 @@ int cloud_codec_init(struct cloud_data_cfg *cfg, cloud_codec_evt_handler_t event
return 0;
}

int cloud_codec_encode_neighbor_cells(struct cloud_codec_data *output,
struct cloud_data_neighbor_cells *neighbor_cells)
int cloud_codec_encode_cloud_location(
struct cloud_codec_data *output,
struct cloud_data_cloud_location *cloud_location)
{
#if defined(CONFIG_NRF_CLOUD_LOCATION)
#if defined(CONFIG_NRF_CLOUD_LOCATION)
int err;
char *buffer;
cJSON *root_obj = NULL;

__ASSERT_NO_MSG(output != NULL);
__ASSERT_NO_MSG(neighbor_cells != NULL);

struct lte_lc_cells_info info = neighbor_cells->cell_data;
__ASSERT_NO_MSG(cloud_location != NULL);

info.neighbor_cells = neighbor_cells->neighbor_cells;
struct lte_lc_cells_info cell_info;

if (!neighbor_cells->queued) {
return -ENODATA;
if (cloud_location->neighbor_cells_valid) {
cell_info = cloud_location->neighbor_cells.cell_data;
cell_info.neighbor_cells = cloud_location->neighbor_cells.neighbor_cells;
}

err = nrf_cloud_location_request_json_get(&info, NULL, true, &root_obj);
if (err) {
LOG_ERR("nrf_cloud_location_request_json_get, error: %d", err);
return -ENOMEM;
}

buffer = cJSON_PrintUnformatted(root_obj);
if (buffer == NULL) {
LOG_ERR("Failed to allocate memory for JSON string");

err = -ENOMEM;
goto exit;
}

if (IS_ENABLED(CONFIG_CLOUD_CODEC_LOG_LEVEL_DBG)) {
json_print_obj("Encoded message:\n", root_obj);
}

output->buf = buffer;
output->len = strlen(buffer);

exit:
neighbor_cells->queued = false;
cJSON_Delete(root_obj);
return err;
#endif /* CONFIG_NRF_CLOUD_LOCATION */

return -ENOTSUP;
}

#if defined(CONFIG_LOCATION_METHOD_WIFI)
int cloud_codec_encode_wifi_access_points(struct cloud_codec_data *output,
struct cloud_data_wifi_access_points *wifi_access_points)
{
#if defined(CONFIG_NRF_CLOUD_LOCATION)
int err;
char *buffer;
cJSON *root_obj = NULL;
struct wifi_scan_info wifi_info;

__ASSERT_NO_MSG(output != NULL);
__ASSERT_NO_MSG(wifi_access_points != NULL);

struct wifi_scan_info info = {
.ap_info = wifi_access_points->ap_info,
.cnt = wifi_access_points->cnt
};
if (cloud_location->wifi_access_points_valid) {
wifi_info.ap_info = cloud_location->wifi_access_points.ap_info;
wifi_info.cnt = cloud_location->wifi_access_points.cnt;
}
#endif

if (!wifi_access_points->queued) {
if (!cloud_location->queued) {
return -ENODATA;
}

err = nrf_cloud_location_request_json_get(NULL, &info, true, &root_obj);
err = nrf_cloud_location_request_json_get(
cloud_location->neighbor_cells_valid ? &cell_info : NULL,
#if defined(CONFIG_LOCATION_METHOD_WIFI)
cloud_location->wifi_access_points_valid ? &wifi_info : NULL,
#else
NULL,
#endif
true,
&root_obj);
if (err) {
LOG_ERR("nrf_cloud_location_request_json_get, error: %d", err);
return -ENOMEM;
Expand All @@ -787,14 +757,13 @@ int cloud_codec_encode_wifi_access_points(struct cloud_codec_data *output,
output->len = strlen(buffer);

exit:
wifi_access_points->queued = false;
cloud_location->queued = false;
cJSON_Delete(root_obj);
return err;
#endif /* CONFIG_NRF_CLOUD_LOCATION */

return -ENOTSUP;
}
#endif /* CONFIG_LOCATION_METHOD_WIFI */

int cloud_codec_encode_agps_request(struct cloud_codec_data *output,
struct cloud_data_agps_request *agps_request)
Expand Down
Loading

0 comments on commit 5116d04

Please sign in to comment.