1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

pkg/nimble/autoadv: add shell

This commit is contained in:
Francisco Molina 2022-02-14 10:24:55 +01:00
parent 1de00ba504
commit d474b8ff8a
7 changed files with 112 additions and 5 deletions

View File

@ -165,6 +165,7 @@ PSEUDOMODULES += nimble_phy_coded
PSEUDOMODULES += nimble_phy_2mbit
PSEUDOMODULES += nimble_rpble_ext
PSEUDOMODULES += nimble_statconn_ext
PSEUDOMODULES += nimble_autoadv_shell
PSEUDOMODULES += newlib
PSEUDOMODULES += newlib_gnu_source
PSEUDOMODULES += newlib_nano

View File

@ -23,7 +23,7 @@ else
CFLAGS += -Wno-unused-but-set-variable
endif
IGNORE := nimble_autoconn_% nimble_phy_% nimble_%_ext
IGNORE := nimble_autoconn_% nimble_phy_% nimble_%_ext nimble_autoadv%
SUBMODS := $(filter-out $(IGNORE),$(filter nimble_%,$(USEMODULE)))
.PHONY: all
@ -74,9 +74,6 @@ nimble_drivers_nrf5x:
nimble_addr:
$(QQ)"$(MAKE)" -C $(TDIR)/addr/
nimble_autoadv:
$(QQ)"$(MAKE)" -C $(TDIR)/autoadv
nimble_autoconn:
$(QQ)"$(MAKE)" -C $(TDIR)/autoconn

View File

@ -63,6 +63,10 @@ endif
ifneq (,$(filter nimble_autoadv,$(USEMODULE)))
USEMODULE += bluetil_ad
USEMODULE += bluetil_addr
ifneq (,$(filter shell_commands,$(USEMODULE)))
DEFAULT_MODULE += nimble_autoadv_shell
endif
endif
ifneq (,$(filter nimble_autoconn_ext,$(USEMODULE)))

View File

@ -88,6 +88,7 @@ endif
ifneq (,$(filter nimble_autoadv,$(USEMODULE)))
INCLUDES += -I$(RIOTPKG)/nimble/autoadv/include
DIRS += $(RIOTPKG)/nimble/autoadv
endif
ifneq (,$(filter nimble_autoconn,$(USEMODULE)))

View File

@ -1,3 +1,7 @@
MODULE = nimble_autoadv
SUBMODULES = 1
SRC += nimble_autoadv.c
include $(RIOTBASE)/Makefile.base

View File

@ -236,7 +236,7 @@ void nimble_autoadv_start(ble_addr_t *addr)
#endif
}
int static _ble_gap_stop(void)
static int _ble_gap_stop(void)
{
#if MYNEWT_VAL_BLE_EXT_ADV
if (ble_gap_ext_adv_active(CONFIG_NIMBLE_AUTOADV_INSTANCE)) {

100
pkg/nimble/autoadv/shell.c Normal file
View File

@ -0,0 +1,100 @@
/*
* Copyright (C) 2021 Inria
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup pkg_nimble_autoadv
* @{
*
* @file
* @brief Auto advertisement module shell commands
*
* @author Francisco Molina <francois-xavier.molina@inria.fr>
*
* @}
*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "shell.h"
#include "shell_commands.h"
#include "xfa.h"
#include "nimble_riot.h"
#include "host/ble_hs.h"
#include "host/ble_gap.h"
#include "net/bluetil/ad.h"
#include "net/bluetil/addr.h"
#include "nimble_autoadv.h"
static int _ble_gap_adv_active(void)
{
#if MYNEWT_VAL_BLE_EXT_ADV
return ble_gap_ext_adv_active(nimble_autoadv_get_adv_instance());
#else
return ble_gap_adv_active();
#endif
}
static void _print_usage(void)
{
puts("Usage:");
puts("\tautoadv start [addr]: start NimBLE auto advertisement");
puts("\tautoadv stop: stop NimBLE auto advertisement");
puts("\tautoadv status: print NimBLE auto advertisement status");
}
static int _autoadv_handler(int argc, char **argv)
{
if (argc < 2) {
_print_usage();
return -1;
}
if (!strcmp(argv[1], "start")) {
ble_addr_t *addr_ptr = NULL;
ble_addr_t addr = { .type = nimble_riot_own_addr_type };
if (argc == 3) {
uint8_t addrn[BLE_ADDR_LEN];
if (bluetil_addr_from_str(addrn, argv[2]) != NULL) {
/* NimBLE expects address in little endian, so swap */
bluetil_addr_swapped_cp(addrn, addr.val);
addr_ptr = &addr;
puts("Found BLE address: sending directed advertisements");
}
}
nimble_autoadv_start(addr_ptr);
printf("[autoadv] shell: start advertising on inst=(%d)\n",
nimble_autoadv_get_adv_instance());
return 0;
}
if (!strcmp(argv[1], "stop")) {
nimble_autoadv_stop();
printf("[autoadv] shell: stop advertising on inst=(%d)\n",
nimble_autoadv_get_adv_instance());
return 0;
}
if (!strcmp(argv[1], "status")) {
if (_ble_gap_adv_active()) {
printf("[autoadv] shell: active, inst=(%d)\n",
nimble_autoadv_get_adv_instance());
}
else {
puts("[autoadv] shell: inactive\n");
}
return 0;
}
_print_usage();
return -1;
}
SHELL_COMMAND(autoadv, "NimBLE autoadv", _autoadv_handler);