Skip to content

Commit d8d268b

Browse files
maxd-nordicrlubos
authored andcommitted
lib: nrfcloud: add timestamped location request
Add feature to support timestamped location requests to nRF Cloud. Signed-off-by: Maximilian Deubel <[email protected]>
1 parent 27c2654 commit d8d268b

File tree

5 files changed

+67
-4
lines changed

5 files changed

+67
-4
lines changed

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,7 @@ Libraries for networking
740740

741741
* :ref:`lib_nrf_cloud` library:
742742

743+
* Added the :c:func:`nrf_cloud_obj_location_request_create_timestamped` function to make location requests for past cellular or Wi-Fi scans.
743744
* Updated by refactoring the folder structure of the library to separate the different backend implementations.
744745

745746
* :ref:`lib_downloader` library:

include/net/nrf_cloud_codec.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,33 @@ int nrf_cloud_obj_cloud_encoded_free(struct nrf_cloud_obj *const obj);
636636
int nrf_cloud_obj_gnss_msg_create(struct nrf_cloud_obj *const obj,
637637
const struct nrf_cloud_gnss_data * const gnss);
638638

639+
/**
640+
* @brief Create an nRF Cloud Location request message object with a timestamp.
641+
*
642+
* @details If successful, memory is allocated for the provided object.
643+
* The @ref nrf_cloud_obj_free function should be called when finished with the object.
644+
*
645+
* @param[out] obj Uninitialzed object to contain the Location message.
646+
* @param[in] cells_inf Cellular network data, can be NULL if wifi_inf is provided.
647+
* @param[in] wifi_inf Wi-Fi network data, can be NULL if cells_inf is provided.
648+
* @param[in] config Optional configuration of request. If NULL, use cloud defaults.
649+
* @param[in] timestamp Optional UTC timestamp (milliseconds) of request, or 0 to omit.
650+
*
651+
* @retval -EINVAL Invalid parameter.
652+
* @retval -EDOM Too few Wi-Fi networks, see NRF_CLOUD_LOCATION_WIFI_AP_CNT_MIN.
653+
* @retval -EBADF Invalid object type.
654+
* @retval -ENOTEMPTY Object already initialized.
655+
* @retval -ENOMEM Out of memory.
656+
* @retval 0 Success; GNSS message created.
657+
*/
658+
int nrf_cloud_obj_location_request_create_timestamped(
659+
struct nrf_cloud_obj *const obj,
660+
const struct lte_lc_cells_info *const cells_inf,
661+
const struct wifi_scan_info *const wifi_inf,
662+
const struct nrf_cloud_location_config *const config,
663+
int64_t timestamp
664+
);
665+
639666
/**
640667
* @brief Create an nRF Cloud Location request message object.
641668
*

include/net/nrf_cloud_location.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ struct nrf_cloud_location_result {
9191

9292
/** Size of provided buffer */
9393
size_t anchor_buf_sz;
94+
95+
/** Optional timestamp */
96+
int64_t timestamp;
9497
};
9598

9699
/** @brief Location request config */

subsys/net/lib/nrf_cloud/common/src/nrf_cloud_codec.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -945,10 +945,13 @@ int nrf_cloud_obj_modem_pvt_add(struct nrf_cloud_obj *const obj,
945945
}
946946
#endif /* CONFIG_NRF_MODEM */
947947

948-
int nrf_cloud_obj_location_request_create(struct nrf_cloud_obj *const obj,
949-
const struct lte_lc_cells_info *const cells_inf,
950-
const struct wifi_scan_info *const wifi_inf,
951-
const struct nrf_cloud_location_config *const config)
948+
int nrf_cloud_obj_location_request_create_timestamped(
949+
struct nrf_cloud_obj *const obj,
950+
const struct lte_lc_cells_info *const cells_inf,
951+
const struct wifi_scan_info *const wifi_inf,
952+
const struct nrf_cloud_location_config *const config,
953+
int64_t timestamp
954+
)
952955
{
953956
if ((!cells_inf && !wifi_inf) || !obj) {
954957
return -EINVAL;
@@ -1035,6 +1038,10 @@ int nrf_cloud_obj_location_request_create(struct nrf_cloud_obj *const obj,
10351038
}
10361039
/* The data object now belongs to the location request object */
10371040

1041+
if (timestamp) {
1042+
cJSON_AddNumberToObjectCS(obj->json, NRF_CLOUD_MSG_TIMESTAMP_KEY, timestamp);
1043+
}
1044+
10381045
return 0;
10391046

10401047
cleanup:
@@ -1044,6 +1051,16 @@ int nrf_cloud_obj_location_request_create(struct nrf_cloud_obj *const obj,
10441051
return err;
10451052
}
10461053

1054+
int nrf_cloud_obj_location_request_create(struct nrf_cloud_obj *const obj,
1055+
const struct lte_lc_cells_info *const cells_inf,
1056+
const struct wifi_scan_info *const wifi_inf,
1057+
const struct nrf_cloud_location_config *const config)
1058+
{
1059+
return nrf_cloud_obj_location_request_create_timestamped(
1060+
obj, cells_inf, wifi_inf, config, 0
1061+
);
1062+
}
1063+
10471064
#if defined(CONFIG_NRF_CLOUD_PGPS)
10481065
int nrf_cloud_obj_pgps_request_create(struct nrf_cloud_obj *const obj,
10491066
const struct gps_pgps_request *const request)

subsys/net/lib/nrf_cloud/common/src/nrf_cloud_codec_internal.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,6 +2287,19 @@ static bool json_item_string_exists(const cJSON *const obj, const char *const ke
22872287
return (strcmp(str_val, val) == 0);
22882288
}
22892289

2290+
static int64_t get_timestamp(const cJSON *const obj)
2291+
{
2292+
__ASSERT_NO_MSG(obj != NULL);
2293+
2294+
cJSON *item = cJSON_GetObjectItem(obj, NRF_CLOUD_MSG_TIMESTAMP_KEY);
2295+
2296+
if (item) {
2297+
return cJSON_GetNumberValue(item);
2298+
}
2299+
2300+
return 0;
2301+
}
2302+
22902303
static void
22912304
nrf_cloud_parse_location_anchors_json(const cJSON *const loc_obj,
22922305
struct nrf_cloud_location_result *const location_out)
@@ -2476,6 +2489,8 @@ int nrf_cloud_location_response_decode(const char *const buf,
24762489
goto cleanup;
24772490
}
24782491

2492+
result->timestamp = get_timestamp(loc_obj);
2493+
24792494
/* MQTT payload format found, parse the data */
24802495
data_obj = cJSON_GetObjectItem(loc_obj, NRF_CLOUD_JSON_DATA_KEY);
24812496
if (data_obj) {

0 commit comments

Comments
 (0)