Skip to content

Commit 9fa8f41

Browse files
committed
Review fixes #4
1 parent 29667c1 commit 9fa8f41

4 files changed

Lines changed: 73 additions & 23 deletions

File tree

app/src/sm_at_nrfcloud.c

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,9 @@ STATIC int handle_at_nrf_cloud_pos(enum at_parser_cmd_type cmd_type,
430430
return 0;
431431
}
432432

433+
/* This function has been copied from sdk-nrf nrf/lib/lte_link_control library
434+
* with version v3.4.0-rc1.
435+
*/
433436
static int string_to_int(const char *str_buf, int base, int *output)
434437
{
435438
int temp;
@@ -450,11 +453,14 @@ static int string_to_int(const char *str_buf, int base, int *output)
450453
return 0;
451454
}
452455

456+
/* This function has been copied from sdk-nrf lte_link_control library
457+
* with version v3.4.0-rc1.
458+
*/
453459
static int string_param_to_int(struct at_parser *parser, size_t idx, int *output, int base)
454460
{
455461
int err;
456462
char str_buf[16];
457-
size_t len = sizeof(str_buf);
463+
size_t len = sizeof(str_buf) - 1;
458464

459465
__ASSERT_NO_MSG(parser != NULL);
460466
__ASSERT_NO_MSG(output != NULL);
@@ -463,6 +469,7 @@ static int string_param_to_int(struct at_parser *parser, size_t idx, int *output
463469
if (err) {
464470
return err;
465471
}
472+
str_buf[len] = '\0';
466473

467474
if (string_to_int(str_buf, base, output)) {
468475
return -ENODATA;
@@ -471,6 +478,9 @@ static int string_param_to_int(struct at_parser *parser, size_t idx, int *output
471478
return 0;
472479
}
473480

481+
/* This function has been copied from sdk-nrf lte_link_control library
482+
* with version v3.4.0-rc1.
483+
*/
474484
static int plmn_param_string_to_mcc_mnc(struct at_parser *parser, size_t idx, int *mcc, int *mnc)
475485
{
476486
int err;
@@ -522,6 +532,9 @@ static void nrfcloud_cell_data_cleanup(void)
522532
nrfcloud_cell_data = NULL;
523533
}
524534

535+
/* This function has been copied from sdk-nrf location library scan_cellular_execute() function
536+
* with version v3.4.0-rc1.
537+
*/
525538
struct lte_lc_cells_info *sm_at_nrfcloud_ncellmeas(uint8_t cell_count, bool send_loc_req)
526539
{
527540
int err;
@@ -569,7 +582,6 @@ struct lte_lc_cells_info *sm_at_nrfcloud_ncellmeas(uint8_t cell_count, bool send
569582
err = k_sem_take(&ncellmeas_sem_ncellmeas_evt, K_SECONDS(NRFCLOUDPOS_TIMEOUT_SEC));
570583
if (err) {
571584
/* Semaphore was reset so stop search procedure */
572-
err = 0;
573585
goto end;
574586
}
575587

@@ -624,13 +636,11 @@ struct lte_lc_cells_info *sm_at_nrfcloud_ncellmeas(uint8_t cell_count, bool send
624636
/* Clearing 'err' because previous neighbor search has succeeded
625637
* so those are still valid and positioning can proceed with that data
626638
*/
627-
err = 0;
628639
goto end;
629640
}
630641
err = k_sem_take(&ncellmeas_sem_ncellmeas_evt, K_SECONDS(NRFCLOUDPOS_TIMEOUT_SEC));
631642
if (err) {
632643
/* Semaphore was reset so stop search procedure */
633-
err = 0;
634644
goto end;
635645
}
636646

@@ -651,10 +661,9 @@ struct lte_lc_cells_info *sm_at_nrfcloud_ncellmeas(uint8_t cell_count, bool send
651661
err = sm_util_at_printf("AT%%NCELLMEAS=4,%d", cell_count);
652662
if (err) {
653663
LOG_WRN("Failed to initiate GCI cell measurements: %d", err);
654-
/* Clearing 'err' because previous neighbor search has succeeded
664+
/* Clearing 'err' because previous neighbor nrfcloud_wifi_possearch has succeeded
655665
* so those are still valid and positioning can proceed with that data
656666
*/
657-
err = 0;
658667
goto end;
659668
}
660669
k_sem_take(&ncellmeas_sem_ncellmeas_evt, K_SECONDS(NRFCLOUDPOS_TIMEOUT_SEC));
@@ -697,18 +706,30 @@ static void nrfcloud_loc_req_work_fn(struct k_work *work)
697706
.wifi_info = nrfcloud_wifi_pos ? &nrfcloud_wifi_data : NULL
698707
};
699708

700-
// TODO: Check if ncellmeas failed and no wifi aps were found.
701-
//urc_send_to(nrfcloud_pipe, "\r\n#XNRFCLOUDPOS: -1\r\n");
709+
/* Check if ncellmeas was requested but there are no results */
710+
if (nrfcloud_cell_count > 0) {
711+
if (nrfcloud_cell_data == NULL ||
712+
nrfcloud_cell_data->current_cell.id == LTE_LC_CELL_EUTRAN_ID_INVALID) {
713+
if (nrfcloud_wifi_pos) {
714+
LOG_WRN("NCELLMEAS failed but Wi-Fi APs are available");
715+
/* Continue to send Wi-Fi APs to cloud*/
716+
} else {
717+
urc_send_to(nrfcloud_pipe, "\r\n#XNRFCLOUDPOS: -2\r\n");
718+
goto clean_exit;
719+
}
720+
}
721+
}
702722

703723
err = nrf_cloud_coap_location_get(&request, &result);
704724
if (err == 0) {
705-
urc_send_to(nrfcloud_pipe, "\r\n#XNRFCLOUDPOS: %d,%lf,%lf,%d\r\n",
725+
urc_send_to(nrfcloud_pipe, "\r\n#XNRFCLOUDPOS: 0,%d,%lf,%lf,%d\r\n",
706726
result.type, result.lat, result.lon, result.unc);
707727
} else {
708728
LOG_ERR("Failed to request nRF Cloud location (%d).", err);
709729
urc_send_to(nrfcloud_pipe, "\r\n#XNRFCLOUDPOS: %d\r\n", err < 0 ? -1 : err);
710730
}
711731

732+
clean_exit:
712733
nrfcloud_cell_data_cleanup();
713734
if (nrfcloud_wifi_pos) {
714735
free(nrfcloud_wifi_data.ap_info);
@@ -823,6 +844,9 @@ static struct lte_lc_ncell *parse_ncellmeas_neighbors(
823844
return NULL;
824845
}
825846

847+
/* This function has been copied from sdk-nrf lte_link_control library
848+
* with version v3.4.0-rc1.
849+
*/
826850
static int parse_ncellmeas_gci(const char *at_response, struct lte_lc_cells_info *cells)
827851
{
828852
struct at_parser parser;
@@ -1041,13 +1065,15 @@ static int parse_ncellmeas_gci(const char *at_response, struct lte_lc_cells_info
10411065
*/
10421066
free(cells->neighbor_cells);
10431067
cells->neighbor_cells = NULL;
1068+
cells->ncells_count = 0;
10441069
cells->neighbor_cells = parse_ncellmeas_neighbors(
10451070
&parser, parsed_ncells_count, &curr_index);
10461071
if (cells->neighbor_cells == NULL) {
10471072
LOG_ERR("Failed to parse neighbor cells");
10481073
err = -EFAULT;
10491074
goto clean_exit;
10501075
}
1076+
cells->ncells_count = parsed_ncells_count;
10511077
}
10521078
} else {
10531079
cells->gci_cells[k] = parsed_cell;
@@ -1060,6 +1086,9 @@ static int parse_ncellmeas_gci(const char *at_response, struct lte_lc_cells_info
10601086
return err;
10611087
}
10621088

1089+
/* This function has been copied from sdk-nrf lte_link_control library
1090+
* with version v3.4.0-rc1.
1091+
*/
10631092
static int parse_ncellmeas(const char *at_response, struct lte_lc_cells_info *cells)
10641093
{
10651094
int err, status, tmp;
@@ -1212,6 +1241,13 @@ static int parse_ncellmeas(const char *at_response, struct lte_lc_cells_info *ce
12121241
return err;
12131242
}
12141243

1244+
/* This function has been copied from sdk-nrf lte_link_control library
1245+
* with version v3.4.0-rc1.
1246+
* The structure has been modified from lte_link_control library as follows:
1247+
* - parse_ncellmeas_gci is called in this handler and not from parse_ncellmeas() function.
1248+
* - New parse_ncellmeas_neighbors() function handles neighbors parsing for
1249+
* both GCI and non-GCI search types.
1250+
*/
12151251
static void at_handler_ncellmeas(const char *response)
12161252
{
12171253
int err;
@@ -1228,12 +1264,13 @@ static void at_handler_ncellmeas(const char *response)
12281264
} else {
12291265
err = parse_ncellmeas(response, nrfcloud_cell_data);
12301266
}
1267+
12311268
switch (err) {
12321269
case 0: /* Fall through */
1233-
case 1:
12341270
LOG_DBG("NCELLMEAS parsed successfully, err: %d, gci_count: %d, ncells_count: %d",
12351271
err, nrfcloud_cell_data->gci_cells_count, nrfcloud_cell_data->ncells_count);
12361272
break;
1273+
/* case 1: NCELLMEAS failed */
12371274
default:
12381275
LOG_ERR("NCELLMEAS parsing failed, err: %d", err);
12391276
break;

doc/app/at_nrfcloud.rst

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -225,17 +225,14 @@ Unsolicited notification
225225

226226
::
227227

228-
#XNRFCLOUDPOS: <error>
228+
#XNRFCLOUDPOS: <status>[,<type>,<latitude>,<longitude>,<uncertainty>]
229229

230-
This is emitted when the location request failed, either when sending it or receiving its response.
231-
No notification containing location data will be emitted.
230+
* The ``<status>`` parameter indicates the status of the location request.
232231

233-
* The ``<error>`` parameter indicates the error that happened.
234-
It is one of the :c:enum:`nrf_cloud_error` values.
235-
236-
::
237-
238-
#XNRFCLOUDPOS: <type>,<latitude>,<longitude>,<uncertainty>
232+
* ``0`` - Successful request. Other parameters are also present.
233+
* ``-1`` - Requesting location from the cloud failed.
234+
* ``-2`` - Neighbor cell measurements failed.
235+
* ``<positive integer>`` - Requesting location from the cloud failed with cloud error as defined in :c:enum:`nrf_cloud_error` values.
239236

240237
This is emitted when a successful response to a sent location request is received.
241238

@@ -269,7 +266,7 @@ Example
269266

270267
OK
271268

272-
#XNRFCLOUDPOS: 0,35.455833,139.626111,1094
269+
#XNRFCLOUDPOS: 0,0,35.455833,139.626111,1094
273270

274271
AT#XNRFCLOUDPOS=5,0
275272

@@ -281,17 +278,17 @@ Example
281278

282279
%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
283280

284-
#XNRFCLOUDPOS: 1,35.455833,139.626111,1094
281+
#XNRFCLOUDPOS: 0,1,35.455833,139.626111,1094
285282
AT#XNRFCLOUDPOS=0,1,"40:9b:cd:c1:5a:40","00:90:fe:eb:4f:42"
286283

287284
OK
288285

289-
#XNRFCLOUDPOS: 2,35.457335,139.624443,60
286+
#XNRFCLOUDPOS: 0,2,35.457335,139.624443,60
290287
AT#XNRFCLOUDPOS=0,1,"40:9b:cd:c1:5a:40",-40,"00:90:fe:eb:4f:42",-69
291288

292289
OK
293290

294-
#XNRFCLOUDPOS: 2,35.457346,139.624449,20
291+
#XNRFCLOUDPOS: 0,2,35.457346,139.624449,20
295292

296293
Read command
297294
------------

doc/releases/migration_notes_ncs_slm_v3.1.x.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,15 @@ Other changes
358358
* 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.
361+
* ``#XNRFCLOUDPOS`` notification now includes the status of the location request.
362+
The syntax has changed from:
363+
::
364+
#XNRFCLOUDPOS: <error>
365+
#XNRFCLOUDPOS: <type>,<latitude>,<longitude>,<uncertainty>
366+
367+
to:
368+
::
369+
#XNRFCLOUDPOS: <status>[,<type>,<latitude>,<longitude>,<uncertainty>]
361370

362371
Removed features
363372
****************

doc/releases/migration_notes_v2.0.0.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ The following changes are mandatory to make your application work in the same wa
2828
* 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.
31+
* ``#XNRFCLOUDPOS`` notification now includes the status of the location request. The syntax has changed from:
32+
::
33+
#XNRFCLOUDPOS: <error>
34+
#XNRFCLOUDPOS: <type>,<latitude>,<longitude>,<uncertainty>
35+
to:
36+
::
37+
#XNRFCLOUDPOS: <status>[,<type>,<latitude>,<longitude>,<uncertainty>]
3138

3239
Informational changes
3340
*********************

0 commit comments

Comments
 (0)