Skip to content

Commit d19ff3e

Browse files
committed
Remove use of modem info and use NCELLMEAS for current cell.
Modem info is accurate anyway since it uses cached data (AT%XMONITOR).
1 parent 544e1b0 commit d19ff3e

3 files changed

Lines changed: 28 additions & 48 deletions

File tree

app/src/sm_at_gnss.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,8 @@ static void agnss_requestor(struct k_work *)
336336
sizeof(agnss_rest_data_buf), 0};
337337
struct lte_lc_cells_info net_info = {0};
338338

339-
err = get_single_cell_info(&net_info.current_cell);
340-
if (err) {
341-
LOG_ERR("Failed to obtain single-cell cellular network information (%d).", err);
339+
scan_cellular_execute(1, &net_info);
340+
if (net_info.current_cell.id == LTE_LC_CELL_EUTRAN_ID_INVALID) {
342341
return;
343342
}
344343
request.net_info = &net_info;

app/src/sm_at_nrfcloud.c

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "nrf_cloud_coap_transport.h"
1616
#include <modem/at_parser.h>
1717
#include <modem/nrf_modem_lib.h>
18-
#include <modem/modem_info.h>
1918
#include "sm_util.h"
2019
#include "sm_at_host.h"
2120
#include "sm_at_nrfcloud.h"
@@ -81,6 +80,11 @@ static struct lte_lc_cells_info *nrfcloud_cell_data;
8180
/* nRF Cloud location request Wi-Fi data. */
8281
static struct wifi_scan_info nrfcloud_wifi_data;
8382

83+
/**
84+
* Waiting time (in seconds) of RRC connection going into idle mode. Because GCI search
85+
* cannot scan GCI cells during RRC connected mode, we will wait for the RRC idle mode before
86+
* initiating GCI search.
87+
*/
8488
#define SCAN_CELLULAR_RRC_IDLE_WAIT_TIME 10
8589

8690
static K_SEM_DEFINE(entered_rrc_idle, 1, 1);
@@ -236,7 +240,7 @@ static int handle_at_nrf_cloud(enum at_parser_cmd_type cmd_type, struct at_parse
236240
k_work_submit_to_queue(&sm_work_q, &nrfcloud_conn_work);
237241
err = 0;
238242
} else {
239-
err = -EINVAL;
243+
err = -EBUSY;
240244
} break;
241245

242246
case AT_PARSER_CMD_TYPE_READ: {
@@ -411,7 +415,7 @@ static int handle_at_nrf_cloud_pos(enum at_parser_cmd_type cmd_type,
411415

412416
nrfcloud_sending_loc_req = true;
413417
if (cell_count >= 1) {
414-
scan_cellular_execute(cell_count);
418+
scan_cellular_execute(cell_count, NULL);
415419
} else {
416420
k_work_submit_to_queue(&sm_work_q, &nrfcloud_loc_req_work);
417421
}
@@ -510,20 +514,22 @@ static void cleanup_nrfcloud_cell_data(void)
510514
nrfcloud_cell_data = NULL;
511515
}
512516

513-
void scan_cellular_execute(uint8_t cell_count)
517+
void scan_cellular_execute(uint8_t cell_count, struct lte_lc_cells_info *cell_data)
514518
{
515519
int err;
516520
uint8_t ncellmeas3_cell_count;
517521

518-
/* Allocate main cell data structure.
519-
* Neighbor cells structure is only allocated when they are found.
520-
*/
521-
nrfcloud_cell_data = calloc(1, sizeof(struct lte_lc_cells_info));
522-
if (nrfcloud_cell_data == NULL) {
523-
LOG_ERR("Failed to allocate memory for the nRF Cloud cell data");
524-
return;
522+
nrfcloud_cell_data = cell_data;
523+
if (cell_data == NULL) {
524+
/* Allocate main cell data structure.
525+
* Neighbor cells structure is only allocated when they are found.
526+
*/
527+
nrfcloud_cell_data = calloc(1, sizeof(struct lte_lc_cells_info));
528+
if (nrfcloud_cell_data == NULL) {
529+
LOG_ERR("Failed to allocate memory for the nRF Cloud cell data");
530+
return;
531+
}
525532
}
526-
527533
nrfcloud_cell_data->current_cell.id = LTE_LC_CELL_EUTRAN_ID_INVALID;
528534
nrfcloud_cell_data->ncells_count = 0;
529535
nrfcloud_cell_data->gci_cells_count = 0;
@@ -640,7 +646,8 @@ void scan_cellular_execute(uint8_t cell_count)
640646
at_monitor_pause(&sm_ncellmeas);
641647
if (err == 0) {
642648
k_work_submit_to_queue(&sm_work_q, &nrfcloud_loc_req_work);
643-
} else {
649+
} else if (cell_data == NULL) {
650+
/* If cell_data is not provided, cleanup the cell data in error cases */
644651
cleanup_nrfcloud_cell_data();
645652
}
646653
k_work_cancel_delayable(&scan_cellular_timeout_backup_work);
@@ -653,31 +660,6 @@ static void scan_cellular_timeout_backup_work_fn(struct k_work *work)
653660
k_sem_reset(&scan_cellular_sem_ncellmeas_evt);
654661
}
655662

656-
/* TODO: Remove use of modem info completely */
657-
int get_single_cell_info(struct lte_lc_cell *const cell_inf)
658-
{
659-
int err;
660-
struct modem_param_info modem_inf;
661-
662-
err = modem_info_params_init(&modem_inf);
663-
if (err) {
664-
LOG_ERR("Could not initialize modem info module, error: %d", err);
665-
return err;
666-
}
667-
err = modem_info_params_get(&modem_inf);
668-
if (err) {
669-
LOG_ERR("Could not obtain information from modem, error: %d", err);
670-
return err;
671-
}
672-
cell_inf->mcc = modem_inf.network.mcc.value;
673-
cell_inf->mnc = modem_inf.network.mnc.value;
674-
cell_inf->tac = modem_inf.network.area_code.value;
675-
cell_inf->id = modem_inf.network.cellid_dec;
676-
cell_inf->rsrp = modem_inf.network.rsrp.value;
677-
678-
return 0;
679-
}
680-
681663
static void nrfcloud_loc_req_work_fn(struct k_work *work)
682664
{
683665
int err = 0;

app/src/sm_at_nrfcloud.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* @{
1414
*/
1515
#include <stdbool.h>
16+
#include <modem/lte_lc.h>
1617

1718
/* Whether the connection to nRF Cloud is ready. */
1819
extern bool sm_nrf_cloud_ready;
@@ -21,15 +22,13 @@ extern bool sm_nrf_cloud_ready;
2122
extern bool sm_nrf_cloud_send_location;
2223

2324
/**
24-
* @brief Get information about the current cell.
25-
* @param[out] cell_inf Cell information structure to be filled.
25+
* @brief Execute cellular positioning.
2626
*
27-
* @retval 0 If the operation was successful.
28-
* Otherwise, a (negative) error code is returned.
27+
* @param[in] cell_count Number of cells to search for.
28+
* @param[in] cell_data Cell data structure to be filled.
29+
* NULL means that the function will allocate the memory.
2930
*/
30-
int get_single_cell_info(struct lte_lc_cell *const cell_inf);
31-
32-
void scan_cellular_execute(uint8_t cell_count);
31+
void scan_cellular_execute(uint8_t cell_count, struct lte_lc_cells_info *cell_data);
3332

3433
/** @} */
3534
#endif /* SM_AT_NRFCLOUD_ */

0 commit comments

Comments
 (0)