Skip to content

Commit 7126410

Browse files
simensrostadrlubos
authored andcommitted
applications: asset_tracker_v2: Add new Kconfigs to convert RSRP/RSRQ
Depending on the integration, RSRP and RSRQ values need to be provided unconverted or in dB/dBm in the various sample events sent out by the modem module. This is due to the application using different encoding libraries depending on the data that is sent and the configured cloud configuration. This patch deprecated `CONFIG_MODEM_CONVERT_RSRP_AND_RSPQ_TO_DB` Signed-off-by: Simen S. Røstad <[email protected]>
1 parent ea1c55e commit 7126410

File tree

2 files changed

+62
-11
lines changed

2 files changed

+62
-11
lines changed

applications/asset_tracker_v2/src/modules/Kconfig.modem_module

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,40 @@ config MODEM_AUTO_REQUEST_POWER_SAVING_FEATURES
2929
default y
3030

3131
config MODEM_CONVERT_RSRP_AND_RSPQ_TO_DB
32-
bool "Convert RSRP and RSRQ values to dBm and dB, respectively"
33-
default y if AWS_IOT || AZURE_IOT_HUB
32+
bool "Convert RSRP and RSRQ values to dBm and dB, respectively [DEPRECATED]"
33+
select MODEM_DYNAMIC_DATA_CONVERT_RSRP_TO_DBM
34+
select MODEM_NEIGHBOR_CELLS_DATA_CONVERT_RSRP_TO_DBM
35+
select MODEM_NEIGHBOR_CELLS_DATA_CONVERT_RSRQ_TO_DB
3436
help
3537
If this option is enabled, RSRP and RSRQ values are converted to dBm and dB before being
36-
sent out by the module.
38+
sent out by the module. This option is deprecated,
39+
use MODEM_DYNAMIC_DATA_CONVERT_RSRP_TO_DBM, MODEM_NEIGHBOR_CELLS_DATA_CONVERT_RSRP_TO_DBM
40+
and MODEM_NEIGHBOR_CELLS_DATA_CONVERT_RSRQ_TO_DB instead.
41+
42+
config MODEM_DYNAMIC_DATA_CONVERT_RSRP_TO_DBM
43+
bool "Convert RSRP values to dBm for dynamic modem data"
44+
default y
45+
help
46+
If this option is enabled, RSRP values are converted to dBm before being
47+
sent out by the module with the MODEM_EVT_MODEM_DYNAMIC_DATA_READY event.
48+
49+
config MODEM_NEIGHBOR_CELLS_DATA_CONVERT_RSRP_TO_DBM
50+
bool "Convert RSRP values to dBm for neighbor cell measurements"
51+
default y if AWS_IOT || AZURE_IOT_HUB
52+
help
53+
If this option is enabled, RSRP values are converted to dBm before being
54+
sent out by the module with the MODEM_EVT_NEIGHBOR_CELLS_DATA_READY event.
55+
Don't convert RSRP to dBm when building for nRF Cloud, this is handled during encoding
56+
using the nRF Cloud cellular positioning library.
57+
58+
config MODEM_NEIGHBOR_CELLS_DATA_CONVERT_RSRQ_TO_DB
59+
bool "Convert RSRQ values to dB for neighbor cell measurements"
60+
default y if AWS_IOT || AZURE_IOT_HUB
61+
help
62+
If this option is enabled, RSRQ values are converted to dB before being
63+
sent out by the module with the MODEM_EVT_NEIGHBOR_CELLS_DATA_READY event.
64+
Don't convert RSRQ to dB when building for nRF Cloud, this is handled during encoding
65+
using the nRF Cloud cellular positioning library.
3766

3867
endif # MODEM_MODULE
3968

applications/asset_tracker_v2/src/modules/modem_module.c

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ static enum state_type {
6161
STATE_SHUTDOWN,
6262
} state;
6363

64+
/* Enumerator that specifies the data type that is sampled. */
65+
enum sample_type {
66+
NEIGHBOR_CELL,
67+
MODEM_DYNAMIC,
68+
MODEM_STATIC,
69+
BATTERY_VOLTAGE
70+
};
71+
6472
/* Struct that holds data from the modem information module. */
6573
static struct modem_param_info modem_param;
6674

@@ -90,7 +98,7 @@ static void send_cell_update(uint32_t cell_id, uint32_t tac);
9098
static void send_neighbor_cell_update(struct lte_lc_cells_info *cell_info);
9199
static void send_psm_update(int tau, int active_time);
92100
static void send_edrx_update(float edrx, float ptw);
93-
static inline int adjust_rsrp(int input);
101+
static inline int adjust_rsrp(int input, enum sample_type type);
94102
static inline int adjust_rsrq(int input);
95103

96104
/* Convenience functions used in internal state handling. */
@@ -256,7 +264,7 @@ static void modem_rsrp_handler(char rsrp_value)
256264
* This temporarily saves the latest value which are sent to
257265
* the Data module upon a modem data request.
258266
*/
259-
rsrp_value_latest = adjust_rsrp(rsrp_value);
267+
rsrp_value_latest = adjust_rsrp(rsrp_value, MODEM_DYNAMIC);
260268

261269
LOG_DBG("Incoming RSRP status message, RSRP value is %d",
262270
rsrp_value_latest);
@@ -431,18 +439,30 @@ static void send_edrx_update(float edrx, float ptw)
431439
EVENT_SUBMIT(evt);
432440
}
433441

434-
static inline int adjust_rsrp(int input)
442+
static inline int adjust_rsrp(int input, enum sample_type type)
435443
{
436-
if (IS_ENABLED(CONFIG_MODEM_CONVERT_RSRP_AND_RSPQ_TO_DB)) {
437-
return input - 140;
444+
switch (type) {
445+
case NEIGHBOR_CELL:
446+
if (IS_ENABLED(CONFIG_MODEM_NEIGHBOR_CELLS_DATA_CONVERT_RSRP_TO_DBM)) {
447+
return input - 140;
448+
}
449+
break;
450+
case MODEM_DYNAMIC:
451+
if (IS_ENABLED(CONFIG_MODEM_DYNAMIC_DATA_CONVERT_RSRP_TO_DBM)) {
452+
return input - 140;
453+
}
454+
break;
455+
default:
456+
LOG_WRN("Unknown sample type");
457+
break;
438458
}
439459

440460
return input;
441461
}
442462

443463
static inline int adjust_rsrq(int input)
444464
{
445-
if (IS_ENABLED(CONFIG_MODEM_CONVERT_RSRP_AND_RSPQ_TO_DB)) {
465+
if (IS_ENABLED(CONFIG_MODEM_NEIGHBOR_CELLS_DATA_CONVERT_RSRQ_TO_DB)) {
446466
return round(input * 0.5 - 19.5);
447467
}
448468

@@ -464,13 +484,15 @@ static void send_neighbor_cell_update(struct lte_lc_cells_info *cell_info)
464484

465485
/* Convert RSRP to dBm and RSRQ to dB per "nRF91 AT Commands" v1.7. */
466486
evt->data.neighbor_cells.cell_data.current_cell.rsrp =
467-
adjust_rsrp(evt->data.neighbor_cells.cell_data.current_cell.rsrp);
487+
adjust_rsrp(evt->data.neighbor_cells.cell_data.current_cell.rsrp,
488+
NEIGHBOR_CELL);
468489
evt->data.neighbor_cells.cell_data.current_cell.rsrq =
469490
adjust_rsrq(evt->data.neighbor_cells.cell_data.current_cell.rsrq);
470491

471492
for (size_t i = 0; i < evt->data.neighbor_cells.cell_data.ncells_count; i++) {
472493
evt->data.neighbor_cells.neighbor_cells[i].rsrp =
473-
adjust_rsrp(evt->data.neighbor_cells.neighbor_cells[i].rsrp);
494+
adjust_rsrp(evt->data.neighbor_cells.neighbor_cells[i].rsrp,
495+
NEIGHBOR_CELL);
474496
evt->data.neighbor_cells.neighbor_cells[i].rsrq =
475497
adjust_rsrq(evt->data.neighbor_cells.neighbor_cells[i].rsrq);
476498
}

0 commit comments

Comments
 (0)