Skip to content

Commit 0105b77

Browse files
committed
Review fixes ¤1
1 parent ffd9d7a commit 0105b77

3 files changed

Lines changed: 39 additions & 24 deletions

File tree

app/src/sm_at_nrfcloud.c

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@ static char nrfcloud_device_id[NRF_CLOUD_CLIENT_ID_MAX_LEN];
2929
bool sm_nrf_cloud_ready;
3030
bool sm_nrf_cloud_send_location;
3131

32+
static void nrfcloud_conn_work_fn(struct k_work *work);
33+
K_WORK_DEFINE(nrfcloud_conn_work, nrfcloud_conn_work_fn);
34+
3235
#if defined(CONFIG_SM_NRF_CLOUD_LOCATION)
3336

37+
#define NRFCLOUDPOS_TIMEOUT_SEC 120
38+
3439
/* NCELLMEAS notification parameters */
3540
#define AT_NCELLMEAS_STATUS_INDEX 1
3641
#define AT_NCELLMEAS_CELL_ID_INDEX 2
@@ -59,15 +64,13 @@ static bool nrfcloud_wifi_pos;
5964
/* Whether a location request is currently being sent to nRF Cloud. */
6065
static bool nrfcloud_sending_loc_req;
6166

62-
static uint8_t search_type;
63-
static uint8_t gci_count;
67+
static uint8_t ncellmeas_search_type;
68+
static uint8_t ncellmeas_gci_count;
6469

65-
static void nrfcloud_conn_work_fn(struct k_work *work);
6670
static void nrfcloud_loc_req_work_fn(struct k_work *work);
6771
static void sm_at_nrfcloud_ncellmeas_work_fn(struct k_work *work);
6872
static void ncellmeas_timeout_backup_work_fn(struct k_work *work);
6973

70-
K_WORK_DEFINE(nrfcloud_conn_work, nrfcloud_conn_work_fn);
7174
K_WORK_DEFINE(nrfcloud_loc_req_work, nrfcloud_loc_req_work_fn);
7275
K_WORK_DEFINE(sm_at_nrfcloud_ncellmeas_work, sm_at_nrfcloud_ncellmeas_work_fn);
7376
K_WORK_DELAYABLE_DEFINE(ncellmeas_timeout_backup_work, ncellmeas_timeout_backup_work_fn);
@@ -265,15 +268,20 @@ static void sm_at_nrfcloud_init(int ret, void *ctx)
265268
if (initialized) {
266269
return;
267270
}
268-
initialized = true;
269271

270272
err = nrf_cloud_coap_init();
271273
if (err) {
272274
LOG_ERR("Failed to initialize nRF Cloud CoAP library: %d", err);
273275
return;
274276
}
275277

276-
nrf_cloud_client_id_get(nrfcloud_device_id, sizeof(nrfcloud_device_id));
278+
err = nrf_cloud_client_id_get(nrfcloud_device_id, sizeof(nrfcloud_device_id));
279+
if (err) {
280+
LOG_ERR("Failed to get nRF Cloud client ID: %d", err);
281+
return;
282+
}
283+
284+
initialized = true;
277285
}
278286
NRF_MODEM_LIB_ON_INIT(sm_nrfcloud_init_hook, sm_at_nrfcloud_init, NULL);
279287

@@ -538,7 +546,7 @@ void sm_at_nrfcloud_ncellmeas(uint8_t cell_count, struct lte_lc_cells_info *cell
538546
nrfcloud_cell_data->gci_cells_count = 0;
539547

540548
/* Start backup timeout for 120 seconds to handle missing NCELLMEAS notification. */
541-
k_work_schedule(&ncellmeas_timeout_backup_work, K_SECONDS(120));
549+
k_work_schedule(&ncellmeas_timeout_backup_work, K_SECONDS(NRFCLOUDPOS_TIMEOUT_SEC));
542550
at_monitor_resume(&sm_ncellmeas);
543551

544552
LOG_DBG("Triggering cell measurements cell_count=%d", cell_count);
@@ -548,13 +556,13 @@ void sm_at_nrfcloud_ncellmeas(uint8_t cell_count, struct lte_lc_cells_info *cell
548556
* In addition neighbor cells are received.
549557
*/
550558
LOG_DBG("Normal neighbor search (NCELLMEAS=1)");
551-
search_type = 1;
559+
ncellmeas_search_type = 1;
552560
err = sm_util_at_printf("AT%%NCELLMEAS=1");
553561
if (err) {
554562
LOG_ERR("Failed to initiate neighbor cell measurements: %d", err);
555563
goto end;
556564
}
557-
err = k_sem_take(&ncellmeas_sem_ncellmeas_evt, K_FOREVER);
565+
err = k_sem_take(&ncellmeas_sem_ncellmeas_evt, K_SECONDS(NRFCLOUDPOS_TIMEOUT_SEC));
558566
if (err) {
559567
/* Semaphore was reset so stop search procedure */
560568
err = 0;
@@ -588,7 +596,6 @@ void sm_at_nrfcloud_ncellmeas(uint8_t cell_count, struct lte_lc_cells_info *cell
588596
}
589597
}
590598

591-
592599
/*****
593600
* 2nd: GCI history search to get GCI cells we can quickly search and measure.
594601
* Because history search is quick and very power efficient, we request
@@ -605,8 +612,8 @@ void sm_at_nrfcloud_ncellmeas(uint8_t cell_count, struct lte_lc_cells_info *cell
605612
}
606613
nrfcloud_cell_data->gci_cells = cells;
607614

608-
search_type = 3;
609-
gci_count = ncellmeas3_cell_count;
615+
ncellmeas_search_type = 3;
616+
ncellmeas_gci_count = ncellmeas3_cell_count;
610617
err = sm_util_at_printf("AT%%NCELLMEAS=3,%d", ncellmeas3_cell_count);
611618
if (err) {
612619
LOG_WRN("Failed to initiate GCI cell measurements: %d", err);
@@ -616,7 +623,7 @@ void sm_at_nrfcloud_ncellmeas(uint8_t cell_count, struct lte_lc_cells_info *cell
616623
err = 0;
617624
goto end;
618625
}
619-
err = k_sem_take(&ncellmeas_sem_ncellmeas_evt, K_FOREVER);
626+
err = k_sem_take(&ncellmeas_sem_ncellmeas_evt, K_SECONDS(NRFCLOUDPOS_TIMEOUT_SEC));
620627
if (err) {
621628
/* Semaphore was reset so stop search procedure */
622629
err = 0;
@@ -635,8 +642,8 @@ void sm_at_nrfcloud_ncellmeas(uint8_t cell_count, struct lte_lc_cells_info *cell
635642
*/
636643
LOG_DBG("GCI regional search (NCELLMEAS=4,%d)", cell_count);
637644

638-
search_type = 4;
639-
gci_count = cell_count;
645+
ncellmeas_search_type = 4;
646+
ncellmeas_gci_count = cell_count;
640647
err = sm_util_at_printf("AT%%NCELLMEAS=4,%d", cell_count);
641648
if (err) {
642649
LOG_WRN("Failed to initiate GCI cell measurements: %d", err);
@@ -646,7 +653,7 @@ void sm_at_nrfcloud_ncellmeas(uint8_t cell_count, struct lte_lc_cells_info *cell
646653
err = 0;
647654
goto end;
648655
}
649-
k_sem_take(&ncellmeas_sem_ncellmeas_evt, K_FOREVER);
656+
k_sem_take(&ncellmeas_sem_ncellmeas_evt, K_SECONDS(NRFCLOUDPOS_TIMEOUT_SEC));
650657

651658
end:
652659
at_monitor_pause(&sm_ncellmeas);
@@ -688,7 +695,11 @@ static void nrfcloud_loc_req_work_fn(struct k_work *work)
688695
const struct nrf_cloud_coap_location_request request = {
689696
.config = NULL,
690697
.cell_info = nrfcloud_cell_count ? nrfcloud_cell_data : NULL,
691-
.wifi_info = nrfcloud_wifi_pos ? &nrfcloud_wifi_data : NULL};
698+
.wifi_info = nrfcloud_wifi_pos ? &nrfcloud_wifi_data : NULL
699+
};
700+
701+
// TODO: Check if we ncellmeas failed and no wifi aps.
702+
//urc_send_to(nrfcloud_pipe, "\r\n#XNRFCLOUDPOS: -1\r\n");
692703

693704
err = nrf_cloud_coap_location_get(&request, &result);
694705
if (err == 0) {
@@ -883,7 +894,7 @@ static int parse_ncellmeas_gci(const char *at_response, struct lte_lc_cells_info
883894

884895
/* Go through the cells */
885896
for (i = 0; curr_index < (param_count - (AT_NCELLMEAS_GCI_CELL_PARAMS_COUNT + 1)) &&
886-
i < gci_count;
897+
i < ncellmeas_gci_count;
887898
i++) {
888899
struct lte_lc_cell parsed_cell;
889900
bool is_serving_cell;
@@ -1021,7 +1032,7 @@ static int parse_ncellmeas_gci(const char *at_response, struct lte_lc_cells_info
10211032
if (is_serving_cell) {
10221033
/* This the current/serving cell.
10231034
* In practice the <neighbor_count> is always 0 for other than
1024-
* the serving cell, i.e. no neigbour cell list is available.
1035+
* the serving cell, i.e. no neigbor cell list is available.
10251036
* Thus, handle neighbor cells only for the serving cell.
10261037
*/
10271038
cells->current_cell = parsed_cell;
@@ -1213,7 +1224,7 @@ static void at_handler_ncellmeas(const char *response)
12131224
return;
12141225
}
12151226

1216-
if (search_type > 2) {
1227+
if (ncellmeas_search_type > 2) {
12171228
err = parse_ncellmeas_gci(response, nrfcloud_cell_data);
12181229
} else {
12191230
err = parse_ncellmeas(response, nrfcloud_cell_data);
@@ -1231,4 +1242,5 @@ static void at_handler_ncellmeas(const char *response)
12311242

12321243
k_sem_give(&ncellmeas_sem_ncellmeas_evt);
12331244
}
1245+
12341246
#endif /* CONFIG_SM_NRF_CLOUD_LOCATION */

app/src/sm_at_nrfcloud.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extern bool sm_nrf_cloud_send_location;
2525
* @brief Execute cellular neighbor cell measurements.
2626
*
2727
* @param[in] cell_count Number of cells to search for.
28-
* @param[in] cell_data Cell data structure to be filled.
28+
* @param[in,out] cell_data Cell data structure to be filled.
2929
* NULL means that the function will allocate the memory.
3030
*/
3131
void sm_at_nrfcloud_ncellmeas(uint8_t cell_count, struct lte_lc_cells_info *cell_data);

doc/app/at_nrfcloud.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ Syntax
203203

204204
Since the |SM| uses the ``AT%NCELLMEAS`` command internally, the host must not use the ``AT%NCELLMEAS`` command during ``#XNRFCLOUDPOS`` command execution.
205205
You may still use ``AT%NCELLMEAS`` command before or after ``#XNRFCLOUDPOS`` command execution for your own purposes.
206+
You will also see ``%NCELLMEAS`` notifications, which you can ignore, during the ``#XNRFCLOUDPOS`` command execution.
206207

207208
* The ``<wifi_pos>`` parameter can have the following integer values:
208209

@@ -269,14 +270,16 @@ Example
269270
OK
270271

271272
#XNRFCLOUDPOS: 0,35.455833,139.626111,1094
272-
AT%NCELLMEAS
273+
274+
AT#XNRFCLOUDPOS=5,0
273275

274276
OK
275277

276278
%NCELLMEAS: 0,"0199F10A","44020","107E",65535,3750,5,49,27,107504,3750,251,33,4,0,475,107,26,14,25,475,58,26,17,25,475,277,24,9,25,475,51,18,1,25
277-
AT#XNRFCLOUDPOS=2,0
278279

279-
OK
280+
%NCELLMEAS: 0,"01234567","44020","0340",50,175456,3400,34,5,24,1775066,1,0,"00143FAE","44020","0140",65535,0,6200,47,40,14,1775066,0,0
281+
282+
%NCELLMEAS: 0,"00987654","44020","0240",50,1754746,5500,44,4,4,1463457,1,0,"002F4344","44020","0140",65535,0,6200,47,40,14,1775066,0,0,"001C0502","44013","5A00",65535,0,6400,130,29,18,1775124,0,0,"00136107","44013","5A00",65535,0,3600,202,26,13,234533,0,0
280283

281284
#XNRFCLOUDPOS: 1,35.455833,139.626111,1094
282285
AT#XNRFCLOUDPOS=0,1,"40:9b:cd:c1:5a:40","00:90:fe:eb:4f:42"

0 commit comments

Comments
 (0)