Skip to content

Commit bd39dd1

Browse files
committed
Misc
1 parent a30bab4 commit bd39dd1

5 files changed

Lines changed: 39 additions & 32 deletions

File tree

app/src/sm_at_gnss.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ 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-
scan_cellular_execute(1, &net_info);
339+
sm_at_nrfcloud_ncellmeas(1, &net_info);
340340
if (net_info.current_cell.id == LTE_LC_CELL_EUTRAN_ID_INVALID) {
341341
return;
342342
}

app/src/sm_at_nrfcloud.c

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,15 @@ static bool nrfcloud_sending_loc_req;
6060
static uint8_t search_type;
6161
static uint8_t gci_count;
6262

63-
static void nrfcloud_loc_req_work_fn(struct k_work *work);
6463
static void nrfcloud_conn_work_fn(struct k_work *work);
64+
static void nrfcloud_loc_req_work_fn(struct k_work *work);
65+
static void sm_at_nrfcloud_ncellmeas_work_fn(struct k_work *work);
6566

66-
K_WORK_DEFINE(nrfcloud_loc_req_work, nrfcloud_loc_req_work_fn);
6767
K_WORK_DEFINE(nrfcloud_conn_work, nrfcloud_conn_work_fn);
68+
K_WORK_DEFINE(nrfcloud_loc_req_work, nrfcloud_loc_req_work_fn);
69+
K_WORK_DEFINE(sm_at_nrfcloud_ncellmeas_work, sm_at_nrfcloud_ncellmeas_work_fn);
6870
/* Signals completion of an AT%NCELLMEAS measurement (%NCELLMEAS URC). */
69-
K_SEM_DEFINE(scan_cellular_sem_ncellmeas_evt, 0, 1);
71+
K_SEM_DEFINE(ncellmeas_sem_ncellmeas_evt, 0, 1);
7072

7173
/* Parameters saved before submitting connection work. */
7274
static bool nrfcloud_connect;
@@ -80,17 +82,10 @@ static struct lte_lc_cells_info *nrfcloud_cell_data;
8082
/* nRF Cloud location request Wi-Fi data. */
8183
static struct wifi_scan_info nrfcloud_wifi_data;
8284

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-
*/
88-
#define SCAN_CELLULAR_RRC_IDLE_WAIT_TIME 10
89-
9085
static K_SEM_DEFINE(entered_rrc_idle, 1, 1);
9186

92-
static void scan_cellular_timeout_backup_work_fn(struct k_work *work);
93-
K_WORK_DELAYABLE_DEFINE(scan_cellular_timeout_backup_work, scan_cellular_timeout_backup_work_fn);
87+
static void ncellmeas_timeout_backup_work_fn(struct k_work *work);
88+
K_WORK_DELAYABLE_DEFINE(ncellmeas_timeout_backup_work, ncellmeas_timeout_backup_work_fn);
9489

9590
#endif /* CONFIG_SM_NRF_CLOUD_LOCATION */
9691

@@ -415,7 +410,8 @@ static int handle_at_nrf_cloud_pos(enum at_parser_cmd_type cmd_type,
415410

416411
nrfcloud_sending_loc_req = true;
417412
if (cell_count >= 1) {
418-
scan_cellular_execute(cell_count, NULL);
413+
/* To workqueue to avoid blocking the AT pipe and return OK */
414+
k_work_submit_to_queue(&sm_work_q, &sm_at_nrfcloud_ncellmeas_work);
419415
} else {
420416
k_work_submit_to_queue(&sm_work_q, &nrfcloud_loc_req_work);
421417
}
@@ -500,7 +496,7 @@ static int plmn_param_string_to_mcc_mnc(struct at_parser *parser, size_t idx, in
500496

501497
AT_MONITOR(sm_ncellmeas, "NCELLMEAS", at_handler_ncellmeas, PAUSED);
502498

503-
static void cleanup_nrfcloud_cell_data(void)
499+
static void nrfcloud_cell_data_cleanup(void)
504500
{
505501
if (nrfcloud_cell_data == NULL) {
506502
return;
@@ -514,7 +510,7 @@ static void cleanup_nrfcloud_cell_data(void)
514510
nrfcloud_cell_data = NULL;
515511
}
516512

517-
void scan_cellular_execute(uint8_t cell_count, struct lte_lc_cells_info *cell_data)
513+
void sm_at_nrfcloud_ncellmeas(uint8_t cell_count, struct lte_lc_cells_info *cell_data)
518514
{
519515
int err;
520516
uint8_t ncellmeas3_cell_count;
@@ -536,7 +532,7 @@ void scan_cellular_execute(uint8_t cell_count, struct lte_lc_cells_info *cell_da
536532
nrfcloud_cell_data->gci_cells_count = 0;
537533

538534
/* Start backup timeout for 120 seconds to handle missing NCELLMEAS notification. */
539-
k_work_schedule(&scan_cellular_timeout_backup_work, K_SECONDS(120));
535+
k_work_schedule(&ncellmeas_timeout_backup_work, K_SECONDS(120));
540536
at_monitor_resume(&sm_ncellmeas);
541537

542538
LOG_DBG("Triggering cell measurements cell_count=%d", cell_count);
@@ -552,7 +548,7 @@ void scan_cellular_execute(uint8_t cell_count, struct lte_lc_cells_info *cell_da
552548
LOG_ERR("Failed to initiate neighbor cell measurements: %d", err);
553549
goto end;
554550
}
555-
err = k_sem_take(&scan_cellular_sem_ncellmeas_evt, K_FOREVER);
551+
err = k_sem_take(&ncellmeas_sem_ncellmeas_evt, K_FOREVER);
556552
if (err) {
557553
/* Semaphore was reset so stop search procedure */
558554
err = 0;
@@ -614,7 +610,7 @@ void scan_cellular_execute(uint8_t cell_count, struct lte_lc_cells_info *cell_da
614610
err = 0;
615611
goto end;
616612
}
617-
err = k_sem_take(&scan_cellular_sem_ncellmeas_evt, K_FOREVER);
613+
err = k_sem_take(&ncellmeas_sem_ncellmeas_evt, K_FOREVER);
618614
if (err) {
619615
/* Semaphore was reset so stop search procedure */
620616
err = 0;
@@ -644,24 +640,31 @@ void scan_cellular_execute(uint8_t cell_count, struct lte_lc_cells_info *cell_da
644640
err = 0;
645641
goto end;
646642
}
647-
k_sem_take(&scan_cellular_sem_ncellmeas_evt, K_FOREVER);
643+
k_sem_take(&ncellmeas_sem_ncellmeas_evt, K_FOREVER);
648644

649645
end:
650646
at_monitor_pause(&sm_ncellmeas);
651647
if (err == 0) {
652648
k_work_submit_to_queue(&sm_work_q, &nrfcloud_loc_req_work);
653649
} else if (cell_data == NULL) {
654650
/* If cell_data is not provided, cleanup the cell data in error cases */
655-
cleanup_nrfcloud_cell_data();
651+
nrfcloud_cell_data_cleanup();
656652
}
657-
k_work_cancel_delayable(&scan_cellular_timeout_backup_work);
653+
k_work_cancel_delayable(&ncellmeas_timeout_backup_work);
658654
}
659655

660-
static void scan_cellular_timeout_backup_work_fn(struct k_work *work)
656+
static void sm_at_nrfcloud_ncellmeas_work_fn(struct k_work *work)
661657
{
662658
ARG_UNUSED(work);
663659

664-
k_sem_reset(&scan_cellular_sem_ncellmeas_evt);
660+
sm_at_nrfcloud_ncellmeas(nrfcloud_cell_count, nrfcloud_cell_data);
661+
}
662+
663+
static void ncellmeas_timeout_backup_work_fn(struct k_work *work)
664+
{
665+
ARG_UNUSED(work);
666+
667+
k_sem_reset(&ncellmeas_sem_ncellmeas_evt);
665668
}
666669

667670
static void nrfcloud_loc_req_work_fn(struct k_work *work)
@@ -683,7 +686,7 @@ static void nrfcloud_loc_req_work_fn(struct k_work *work)
683686
urc_send_to(nrfcloud_pipe, "\r\n#XNRFCLOUDPOS: %d\r\n", err < 0 ? -1 : err);
684687
}
685688

686-
cleanup_nrfcloud_cell_data();
689+
nrfcloud_cell_data_cleanup();
687690
if (nrfcloud_wifi_pos) {
688691
free(nrfcloud_wifi_data.ap_info);
689692
}
@@ -818,7 +821,10 @@ static int parse_ncellmeas_gci(const char *at_response, struct lte_lc_cells_info
818821
__ASSERT_NO_MSG(cells != NULL);
819822
__ASSERT_NO_MSG(cells->gci_cells != NULL);
820823

821-
/* We don't want to clear old current cell or GCI cell info */
824+
/* We don't want to clear old current cell since it's not always returned but
825+
* we want to overwrite old GCI cells.
826+
*/
827+
cells->gci_cells_count = 0;
822828

823829
/*
824830
* Response format for GCI search types:
@@ -1169,7 +1175,8 @@ static int parse_ncellmeas(const char *at_response, struct lte_lc_cells_info *ce
11691175
goto clean_exit;
11701176
}
11711177

1172-
cells->neighbor_cells = parse_ncellmeas_neighbors(&parser, cells->ncells_count, &curr_index);
1178+
cells->neighbor_cells = parse_ncellmeas_neighbors(
1179+
&parser, cells->ncells_count, &curr_index);
11731180
if (cells->neighbor_cells == NULL) {
11741181
LOG_ERR("Failed to parse neighbor cells");
11751182
err = -EFAULT;
@@ -1205,6 +1212,6 @@ static void at_handler_ncellmeas(const char *response)
12051212
break;
12061213
}
12071214

1208-
k_sem_give(&scan_cellular_sem_ncellmeas_evt);
1215+
k_sem_give(&ncellmeas_sem_ncellmeas_evt);
12091216
}
12101217
#endif /* CONFIG_SM_NRF_CLOUD_LOCATION */

app/src/sm_at_nrfcloud.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ extern bool sm_nrf_cloud_ready;
2222
extern bool sm_nrf_cloud_send_location;
2323

2424
/**
25-
* @brief Execute cellular positioning.
25+
* @brief Execute cellular neighbor cell measurements.
2626
*
2727
* @param[in] cell_count Number of cells to search for.
2828
* @param[in] cell_data Cell data structure to be filled.
2929
* NULL means that the function will allocate the memory.
3030
*/
31-
void scan_cellular_execute(uint8_t cell_count, struct lte_lc_cells_info *cell_data);
31+
void sm_at_nrfcloud_ncellmeas(uint8_t cell_count, struct lte_lc_cells_info *cell_data);
3232

3333
/** @} */
3434
#endif /* SM_AT_NRFCLOUD_ */

doc/releases/migration_notes_ncs_slm_v3.1.x.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ Other changes
355355

356356
* ``AT#XNRFCLOUDPOS``:
357357

358-
* Changed ``<cell_pos>`` parameter to ``<cell_count>``. The meaning changes from no cell positioning, single-cell or multi-cell to the number of cells to beincluded in the location request.
358+
* Changed ``<cell_pos>`` parameter to ``<cell_count>``. The meaning changes from no cell positioning, single-cell or multi-cell to the number of cells to be included in the location request.
359359
``0`` means that cellular positioning is not requested at all.
360360
* The ``AT#XNRFCLOUDPOS`` command has been updated to use the ``AT%NCELLMEAS`` command internally so the host must not use it anymore.
361361

doc/releases/migration_notes_v2.0.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ The following changes are mandatory to make your application work in the same wa
2525

2626
* ``AT#XNRFCLOUDPOS``:
2727

28-
* Changed ``<cell_pos>`` parameter to ``<cell_count>``. The meaning changes from no cell positioning, single-cell or multi-cell to the number of cells to beincluded in the location request.
28+
* Changed ``<cell_pos>`` parameter to ``<cell_count>``. The meaning changes from no cell positioning, single-cell or multi-cell to the number of cells to be included in the location request.
2929
``0`` means that cellular positioning is not requested at all.
3030
* The ``AT#XNRFCLOUDPOS`` command has been updated to use the ``AT%NCELLMEAS`` command internally so the host must not use it anymore.
3131

0 commit comments

Comments
 (0)