ble/nimble: add addr helper module
This commit is contained in:
parent
2e0203eb3e
commit
310cdab3d3
@ -64,4 +64,7 @@ nimble_controller:
|
|||||||
nimble_drivers_nrf52:
|
nimble_drivers_nrf52:
|
||||||
"$(MAKE)" -C $(PDIR)/nimble/drivers/nrf52/src/ -f $(TDIR)/drivers.nrf52.mk
|
"$(MAKE)" -C $(PDIR)/nimble/drivers/nrf52/src/ -f $(TDIR)/drivers.nrf52.mk
|
||||||
|
|
||||||
|
# additional, RIOT specific nimble modules
|
||||||
|
nimble_addr:
|
||||||
|
"$(MAKE)" -C $(TDIR)/addr/
|
||||||
include $(RIOTBASE)/pkg/pkg.mk
|
include $(RIOTBASE)/pkg/pkg.mk
|
||||||
|
|||||||
@ -30,3 +30,7 @@ ifneq (,$(filter nimble_controller,$(USEMODULE)))
|
|||||||
USEMODULE += nimble_drivers_nrf52
|
USEMODULE += nimble_drivers_nrf52
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifneq (,$(filter nimble_addr,$(USEMODULE)))
|
||||||
|
USEMODULE += bluetil_addr
|
||||||
|
endif
|
||||||
|
|||||||
@ -68,3 +68,8 @@ endif
|
|||||||
ifneq (,$(filter nimble_svc_tps,$(USEMODULE)))
|
ifneq (,$(filter nimble_svc_tps,$(USEMODULE)))
|
||||||
INCLUDES += $(NIMIBASE)/nimble/host/services/tps/include
|
INCLUDES += $(NIMIBASE)/nimble/host/services/tps/include
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# include additional headers for RIOT specific NimBLE submodules
|
||||||
|
ifneq (,$(filter nimble_addr,$(USEMODULE)))
|
||||||
|
INCLUDES += -I$(RIOTPKG)/nimble/addr/include
|
||||||
|
endif
|
||||||
|
|||||||
3
pkg/nimble/addr/Makefile
Normal file
3
pkg/nimble/addr/Makefile
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
MODULE = nimble_addr
|
||||||
|
|
||||||
|
include $(RIOTBASE)/Makefile.base
|
||||||
58
pkg/nimble/addr/include/nimble_addr.h
Normal file
58
pkg/nimble/addr/include/nimble_addr.h
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 Freie Universität Berlin
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup ble_nimble_addr Address helper for NimBLE
|
||||||
|
* @ingroup ble_nimble
|
||||||
|
* @brief NimBLE specific helper functions for handling addresses
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file
|
||||||
|
* @brief Interface for NimBLE specific address helper functions
|
||||||
|
*
|
||||||
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NIMBLE_ADDR_H
|
||||||
|
#define NIMBLE_ADDR_H
|
||||||
|
|
||||||
|
#include "nimble/ble.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Length of an address string in byte, including `\0` termination
|
||||||
|
*/
|
||||||
|
#define NIMBLE_ADDR_STRLEN (28U)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Print the given address on STDIO
|
||||||
|
*
|
||||||
|
* @param[in] addr address to print
|
||||||
|
*/
|
||||||
|
void nimble_addr_print(const ble_addr_t *addr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Write the string representation of the given address into a buffer
|
||||||
|
*
|
||||||
|
* The resulting string written to @p buf is `\0` terminated and is always
|
||||||
|
* 28 bytes (NIMBLE_ADDR_STRLEN) long.
|
||||||
|
*
|
||||||
|
* @param[out] buf buffer
|
||||||
|
* @param[in] addr addre to convert
|
||||||
|
*/
|
||||||
|
void nimble_addr_sprint(char *buf, const ble_addr_t *addr);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* NIMBLE_ADDR_H */
|
||||||
|
/** @} */
|
||||||
47
pkg/nimble/addr/nimble_addr.c
Normal file
47
pkg/nimble/addr/nimble_addr.c
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 Freie Universität Berlin
|
||||||
|
*
|
||||||
|
* 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 ble_nimble_addr
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file
|
||||||
|
* @brief NimBLE specific BLE address helper functions
|
||||||
|
*
|
||||||
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||||
|
*
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "nimble_addr.h"
|
||||||
|
#include "net/bluetil/addr.h"
|
||||||
|
|
||||||
|
void nimble_addr_print(const ble_addr_t *addr)
|
||||||
|
{
|
||||||
|
char tmp[NIMBLE_ADDR_STRLEN];
|
||||||
|
nimble_addr_sprint(tmp, addr);
|
||||||
|
printf("%s", tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nimble_addr_sprint(char *buf, const ble_addr_t *addr)
|
||||||
|
{
|
||||||
|
bluetil_addr_sprint(buf, addr->val);
|
||||||
|
const char *type;
|
||||||
|
switch (addr->type) {
|
||||||
|
case BLE_ADDR_PUBLIC: type = " (public) "; break;
|
||||||
|
case BLE_ADDR_RANDOM: type = " (random) "; break;
|
||||||
|
case BLE_ADDR_PUBLIC_ID: type = " (id_pub) "; break;
|
||||||
|
case BLE_ADDR_RANDOM_ID: type = " (id_rand)"; break;
|
||||||
|
default: type = " (unknown)"; break;
|
||||||
|
}
|
||||||
|
memcpy(&buf[BLUETIL_ADDR_STRLEN - 1], type, 10);
|
||||||
|
buf[BLUETIL_ADDR_STRLEN - 1] = '\0';
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user