apps/btshell: Add 'silent' option to scan commands

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.
This commit is contained in:
Mariusz Skamra
2024-02-28 08:36:04 +01:00
committed by Łukasz Rymanowski
parent 56a23bc0fe
commit 6750a13ccb
3 changed files with 25 additions and 3 deletions
+1
View File
@@ -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];
};
+8
View File
@@ -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,
};
@@ -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");
@@ -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}
};
+16 -3
View File
@@ -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);
@@ -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 ",