Skip to content

Commit 8934031

Browse files
jtguggedalrlubos
authored andcommitted
applications: asset_tracker_v2: Unify data type checks
The checks for requested data types are unified into one common function to avoid code repetition and ease maintanance. Signed-off-by: Jan Tore Guggedal <[email protected]>
1 parent 95b02cd commit 8934031

File tree

1 file changed

+16
-47
lines changed

1 file changed

+16
-47
lines changed

applications/asset_tracker_v2/src/modules/modem_module.c

Lines changed: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -689,47 +689,12 @@ static int dynamic_modem_data_get(void)
689689
return 0;
690690
}
691691

692-
static bool static_modem_data_requested(enum app_module_data_type *data_list,
693-
size_t count)
692+
static bool data_type_is_requested(enum app_module_data_type *data_list,
693+
size_t count,
694+
enum app_module_data_type type)
694695
{
695696
for (size_t i = 0; i < count; i++) {
696-
if (data_list[i] == APP_DATA_MODEM_STATIC) {
697-
return true;
698-
}
699-
}
700-
701-
return false;
702-
}
703-
704-
static bool dynamic_modem_data_requested(enum app_module_data_type *data_list,
705-
size_t count)
706-
{
707-
for (size_t i = 0; i < count; i++) {
708-
if (data_list[i] == APP_DATA_MODEM_DYNAMIC) {
709-
return true;
710-
}
711-
}
712-
713-
return false;
714-
}
715-
716-
static bool battery_data_requested(enum app_module_data_type *data_list,
717-
size_t count)
718-
{
719-
for (size_t i = 0; i < count; i++) {
720-
if (data_list[i] == APP_DATA_BATTERY) {
721-
return true;
722-
}
723-
}
724-
725-
return false;
726-
}
727-
728-
static bool neighbor_cells_data_requested(enum app_module_data_type *data_list,
729-
size_t count)
730-
{
731-
for (size_t i = 0; i < count; i++) {
732-
if (data_list[i] == APP_DATA_NEIGHBOR_CELLS) {
697+
if (data_list[i] == type) {
733698
return true;
734699
}
735700
}
@@ -939,8 +904,9 @@ static void on_all_states(struct modem_msg_data *msg)
939904
}
940905

941906
if (IS_EVENT(msg, app, APP_EVT_DATA_GET)) {
942-
if (static_modem_data_requested(msg->module.app.data_list,
943-
msg->module.app.count)) {
907+
if (data_type_is_requested(msg->module.app.data_list,
908+
msg->module.app.count,
909+
APP_DATA_MODEM_STATIC)) {
944910

945911
int err;
946912

@@ -951,8 +917,9 @@ static void on_all_states(struct modem_msg_data *msg)
951917
}
952918
}
953919

954-
if (dynamic_modem_data_requested(msg->module.app.data_list,
955-
msg->module.app.count)) {
920+
if (data_type_is_requested(msg->module.app.data_list,
921+
msg->module.app.count,
922+
APP_DATA_MODEM_DYNAMIC)) {
956923

957924
int err;
958925

@@ -963,8 +930,9 @@ static void on_all_states(struct modem_msg_data *msg)
963930
}
964931
}
965932

966-
if (battery_data_requested(msg->module.app.data_list,
967-
msg->module.app.count)) {
933+
if (data_type_is_requested(msg->module.app.data_list,
934+
msg->module.app.count,
935+
APP_DATA_BATTERY)) {
968936

969937
int err;
970938

@@ -975,8 +943,9 @@ static void on_all_states(struct modem_msg_data *msg)
975943
}
976944
}
977945

978-
if (neighbor_cells_data_requested(msg->module.app.data_list,
979-
msg->module.app.count)) {
946+
if (data_type_is_requested(msg->module.app.data_list,
947+
msg->module.app.count,
948+
APP_DATA_NEIGHBOR_CELLS)) {
980949
int err;
981950

982951
err = neighbor_cells_measurement_start();

0 commit comments

Comments
 (0)