Skip to content

Commit fd3f8cc

Browse files
committed
Misc
1 parent a30bab4 commit fd3f8cc

5 files changed

Lines changed: 43 additions & 34 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: 38 additions & 29 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,11 +510,12 @@ 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;
521517
int rrc_mode;
518+
struct lte_lc_cell *cells = NULL;
522519

523520
nrfcloud_cell_data = cell_data;
524521
if (cell_data == NULL) {
@@ -536,7 +533,7 @@ void scan_cellular_execute(uint8_t cell_count, struct lte_lc_cells_info *cell_da
536533
nrfcloud_cell_data->gci_cells_count = 0;
537534

538535
/* Start backup timeout for 120 seconds to handle missing NCELLMEAS notification. */
539-
k_work_schedule(&scan_cellular_timeout_backup_work, K_SECONDS(120));
536+
k_work_schedule(&ncellmeas_timeout_backup_work, K_SECONDS(120));
540537
at_monitor_resume(&sm_ncellmeas);
541538

542539
LOG_DBG("Triggering cell measurements cell_count=%d", cell_count);
@@ -552,7 +549,7 @@ void scan_cellular_execute(uint8_t cell_count, struct lte_lc_cells_info *cell_da
552549
LOG_ERR("Failed to initiate neighbor cell measurements: %d", err);
553550
goto end;
554551
}
555-
err = k_sem_take(&scan_cellular_sem_ncellmeas_evt, K_FOREVER);
552+
err = k_sem_take(&ncellmeas_sem_ncellmeas_evt, K_FOREVER);
556553
if (err) {
557554
/* Semaphore was reset so stop search procedure */
558555
err = 0;
@@ -596,7 +593,7 @@ void scan_cellular_execute(uint8_t cell_count, struct lte_lc_cells_info *cell_da
596593
LOG_DBG("GCI history search (NCELLMEAS=3,%d)", ncellmeas3_cell_count);
597594

598595
/* Allocate GCI cells structure */
599-
struct lte_lc_cell *cells = calloc(ncellmeas3_cell_count, sizeof(struct lte_lc_cell));
596+
cells = calloc(ncellmeas3_cell_count, sizeof(struct lte_lc_cell));
600597
if (cells == NULL) {
601598
LOG_ERR("Failed to allocate memory for the GCI cells");
602599
goto end;
@@ -614,7 +611,7 @@ void scan_cellular_execute(uint8_t cell_count, struct lte_lc_cells_info *cell_da
614611
err = 0;
615612
goto end;
616613
}
617-
err = k_sem_take(&scan_cellular_sem_ncellmeas_evt, K_FOREVER);
614+
err = k_sem_take(&ncellmeas_sem_ncellmeas_evt, K_FOREVER);
618615
if (err) {
619616
/* Semaphore was reset so stop search procedure */
620617
err = 0;
@@ -644,24 +641,31 @@ void scan_cellular_execute(uint8_t cell_count, struct lte_lc_cells_info *cell_da
644641
err = 0;
645642
goto end;
646643
}
647-
k_sem_take(&scan_cellular_sem_ncellmeas_evt, K_FOREVER);
644+
k_sem_take(&ncellmeas_sem_ncellmeas_evt, K_FOREVER);
648645

649646
end:
650647
at_monitor_pause(&sm_ncellmeas);
651648
if (err == 0) {
652649
k_work_submit_to_queue(&sm_work_q, &nrfcloud_loc_req_work);
653650
} else if (cell_data == NULL) {
654651
/* If cell_data is not provided, cleanup the cell data in error cases */
655-
cleanup_nrfcloud_cell_data();
652+
nrfcloud_cell_data_cleanup();
656653
}
657-
k_work_cancel_delayable(&scan_cellular_timeout_backup_work);
654+
k_work_cancel_delayable(&ncellmeas_timeout_backup_work);
658655
}
659656

660-
static void scan_cellular_timeout_backup_work_fn(struct k_work *work)
657+
static void sm_at_nrfcloud_ncellmeas_work_fn(struct k_work *work)
661658
{
662659
ARG_UNUSED(work);
663660

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

667671
static void nrfcloud_loc_req_work_fn(struct k_work *work)
@@ -683,7 +687,7 @@ static void nrfcloud_loc_req_work_fn(struct k_work *work)
683687
urc_send_to(nrfcloud_pipe, "\r\n#XNRFCLOUDPOS: %d\r\n", err < 0 ? -1 : err);
684688
}
685689

686-
cleanup_nrfcloud_cell_data();
690+
nrfcloud_cell_data_cleanup();
687691
if (nrfcloud_wifi_pos) {
688692
free(nrfcloud_wifi_data.ap_info);
689693
}
@@ -818,7 +822,10 @@ static int parse_ncellmeas_gci(const char *at_response, struct lte_lc_cells_info
818822
__ASSERT_NO_MSG(cells != NULL);
819823
__ASSERT_NO_MSG(cells->gci_cells != NULL);
820824

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

823830
/*
824831
* Response format for GCI search types:
@@ -1169,7 +1176,8 @@ static int parse_ncellmeas(const char *at_response, struct lte_lc_cells_info *ce
11691176
goto clean_exit;
11701177
}
11711178

1172-
cells->neighbor_cells = parse_ncellmeas_neighbors(&parser, cells->ncells_count, &curr_index);
1179+
cells->neighbor_cells = parse_ncellmeas_neighbors(
1180+
&parser, cells->ncells_count, &curr_index);
11731181
if (cells->neighbor_cells == NULL) {
11741182
LOG_ERR("Failed to parse neighbor cells");
11751183
err = -EFAULT;
@@ -1198,13 +1206,14 @@ static void at_handler_ncellmeas(const char *response)
11981206
switch (err) {
11991207
case 0: /* Fall through */
12001208
case 1:
1201-
LOG_DBG("NCELLMEAS parsed successfully, err: %d", err);
1209+
LOG_DBG("NCELLMEAS parsed successfully, err: %d, gci_count: %d, ncells_count: %d",
1210+
err, nrfcloud_cell_data->gci_cells_count, nrfcloud_cell_data->ncells_count);
12021211
break;
12031212
default:
12041213
LOG_ERR("NCELLMEAS parsing failed, err: %d", err);
12051214
break;
12061215
}
12071216

1208-
k_sem_give(&scan_cellular_sem_ncellmeas_evt);
1217+
k_sem_give(&ncellmeas_sem_ncellmeas_evt);
12091218
}
12101219
#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)