Skip to content

Commit

Permalink
apps/btshell: Add 'silent' option to scan commands
Browse files Browse the repository at this point in the history
This adds option to silent the discovery results. This is useful in case
there is another callback listener registered that handles the scan
results, and the user does not want the default handler to print the
results.
  • Loading branch information
MariuszSkamra committed Feb 27, 2024
1 parent 0c22b8e commit f575f68
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions apps/btshell/src/btshell.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ struct btshell_scan_opts {
uint16_t limit;
uint8_t ignore_legacy : 1;
uint8_t periodic_only : 1;
uint8_t silent : 1;
uint8_t name_filter_len;
char name_filter[NAME_FILTER_LEN_MAX];
};
Expand Down
8 changes: 8 additions & 0 deletions apps/btshell/src/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,7 @@ static struct btshell_scan_opts g_scan_opts = {
.limit = UINT16_MAX,
.ignore_legacy = 0,
.periodic_only = 0,
.silent = 0,
.name_filter_len = 0,
};

Expand All @@ -1136,6 +1137,12 @@ cmd_set_scan_opts(int argc, char **argv)
return rc;
}

g_scan_opts.silent = parse_arg_bool_dflt("silent", 0, &rc);
if (rc != 0) {
console_printf("invalid 'silent' parameter\n");
return rc;
}

g_scan_opts.periodic_only = parse_arg_bool_dflt("periodic_only", 0, &rc);
if (rc != 0) {
console_printf("invalid 'periodic_only' parameter\n");
Expand All @@ -1160,6 +1167,7 @@ static const struct shell_param set_scan_opts_params[] = {
{"decode_limit", "usage: =[0-UINT16_MAX], default: UINT16_MAX"},
{"ignore_legacy", "usage: =[0-1], default: 0"},
{"periodic_only", "usage: =[0-1], default: 0"},
{"silent", "usage: =[0-1], default: 0"},
{"name_filter", "usage: =name, default: {none}"},
{NULL, NULL}
};
Expand Down
19 changes: 16 additions & 3 deletions apps/btshell/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1315,11 +1315,23 @@ btshell_gap_event(struct ble_gap_event *event, void *arg)

return btshell_restart_adv(event);
#if MYNEWT_VAL(BLE_EXT_ADV)
case BLE_GAP_EVENT_EXT_DISC:
btshell_decode_event_type(&event->ext_disc, arg);
case BLE_GAP_EVENT_EXT_DISC: {
struct btshell_scan_opts *scan_opts = arg;

if (!scan_opts->silent) {
btshell_decode_event_type(&event->ext_disc, arg);
}

return 0;
}
#endif
case BLE_GAP_EVENT_DISC:
case BLE_GAP_EVENT_DISC: {
struct btshell_scan_opts *scan_opts = arg;

if (scan_opts->silent) {
return 0;
}

console_printf("received advertisement; event_type=%d rssi=%d "
"addr_type=%d addr=", event->disc.event_type,
event->disc.rssi, event->disc.addr.type);
Expand All @@ -1337,6 +1349,7 @@ btshell_gap_event(struct ble_gap_event *event, void *arg)
btshell_decode_adv_data(event->disc.data, event->disc.length_data, arg);

return 0;
}

case BLE_GAP_EVENT_CONN_UPDATE:
console_printf("connection updated; status=%d ",
Expand Down

0 comments on commit f575f68

Please sign in to comment.