From f10a28a7f76f643c702d6fe02306bdbdf9dc4eb9 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Mon, 21 Mar 2022 22:23:53 +0100 Subject: [PATCH] net/ble/skald: let itvl be configured per context --- sys/include/net/skald.h | 14 +------------- sys/include/net/skald/eddystone.h | 8 ++++++-- sys/include/net/skald/ibeacon.h | 4 +++- sys/net/ble/skald/Kconfig | 7 ------- sys/net/ble/skald/skald.c | 2 +- sys/net/ble/skald/skald_eddystone.c | 8 ++++++-- sys/net/ble/skald/skald_ibeacon.c | 4 +++- 7 files changed, 20 insertions(+), 27 deletions(-) diff --git a/sys/include/net/skald.h b/sys/include/net/skald.h index e523965c70..91c3cbfa0f 100644 --- a/sys/include/net/skald.h +++ b/sys/include/net/skald.h @@ -54,19 +54,6 @@ extern "C" { #endif -/** - * @defgroup net_skald_conf Skald compile configurations - * @ingroup config - * @{ - */ -/** - * @brief Advertising interval in microseconds - */ -#ifndef CONFIG_SKALD_INTERVAL_MS -#define CONFIG_SKALD_INTERVAL_MS (1000U) -#endif -/** @} */ - /** * @brief List of advertising channels */ @@ -89,6 +76,7 @@ typedef struct { ztimer_t timer; /**< timer for scheduling advertising events */ ztimer_now_t last; /**< last timer trigger (for offset compensation) */ uint8_t cur_chan; /**< keep track of advertising channels */ + uint32_t adv_itvl_ms; /**< advertising interval [ms] */ } skald_ctx_t; /** diff --git a/sys/include/net/skald/eddystone.h b/sys/include/net/skald/eddystone.h index f45cccd2c3..4778240909 100644 --- a/sys/include/net/skald/eddystone.h +++ b/sys/include/net/skald/eddystone.h @@ -58,9 +58,11 @@ typedef struct __attribute__((packed)) { * @param[out] ctx advertising context * @param[in] uid UID to advertise * @param[in] tx_pwr calibrated TX power to be advertised by the beacon + * @param[in] adv_itvl_ms advertising interval [ms] */ void skald_eddystone_uid_adv(skald_ctx_t *ctx, - const skald_eddystone_uid_t *uid, uint8_t tx_pwr); + const skald_eddystone_uid_t *uid, uint8_t tx_pwr, + uint32_t adv_itvl_ms); /** * @brief Advertise Eddystone-URL data @@ -71,9 +73,11 @@ void skald_eddystone_uid_adv(skald_ctx_t *ctx, * @param[in] scheme encoded URL scheme prefix * @param[in] url (short) url as \0 terminated string * @param[in] tx_pwr calibrated TX power to be advertised by the beacon + * @param[in] adv_itvl_ms advertising interval [ms] */ void skald_eddystone_url_adv(skald_ctx_t *ctx, - uint8_t scheme, const char *url, uint8_t tx_pwr); + uint8_t scheme, const char *url, uint8_t tx_pwr, + uint32_t adv_itvl_ms); #ifdef __cplusplus } diff --git a/sys/include/net/skald/ibeacon.h b/sys/include/net/skald/ibeacon.h index 174a192978..f3a82df4b4 100644 --- a/sys/include/net/skald/ibeacon.h +++ b/sys/include/net/skald/ibeacon.h @@ -42,9 +42,11 @@ extern "C" { * @param[in] major the iBeacon's major number * @param[in] minor the iBeacon's minor number * @param[in] txpower calibrated TX power to be advertised by the beacon + * @param[in] adv_itvl_ms advertising interval [ms] */ void skald_ibeacon_advertise(skald_ctx_t *ctx, const skald_uuid_t *uuid, - uint16_t major, uint16_t minor, uint8_t txpower); + uint16_t major, uint16_t minor, uint8_t txpower, + uint32_t adv_itvl_ms); #ifdef __cplusplus } diff --git a/sys/net/ble/skald/Kconfig b/sys/net/ble/skald/Kconfig index d8b21e535c..49c2a6ab6c 100644 --- a/sys/net/ble/skald/Kconfig +++ b/sys/net/ble/skald/Kconfig @@ -12,13 +12,6 @@ menuconfig KCONFIG_USEMODULE_SKALD if KCONFIG_USEMODULE_SKALD -config SKALD_INTERVAL_MS - int "Advertising interval in microseconds" - default 1000 - help - Configure advertising interval in milliseconds. Default value is 1 - second which is 1000 milliseconds. - config SKALD_ADV_CHANNELS string "Advertising channels" default "37, 38, 39" diff --git a/sys/net/ble/skald/skald.c b/sys/net/ble/skald/skald.c index 8433991af6..0219673557 100644 --- a/sys/net/ble/skald/skald.c +++ b/sys/net/ble/skald/skald.c @@ -63,7 +63,7 @@ static void _stop_radio(void) static void _sched_next(skald_ctx_t *ctx) { - ctx->last += CONFIG_SKALD_INTERVAL_MS; + ctx->last += ctx->adv_itvl_ms; /* schedule next advertising event, adding a random jitter between * 0ms and 10ms (see spec v5.0-vol6-b-4.4.2.2.1) */ ctx->last += random_uint32_range(JITTER_MIN, JITTER_MAX); diff --git a/sys/net/ble/skald/skald_eddystone.c b/sys/net/ble/skald/skald_eddystone.c index cb55df2f33..2f2a53793c 100644 --- a/sys/net/ble/skald/skald_eddystone.c +++ b/sys/net/ble/skald/skald_eddystone.c @@ -71,7 +71,8 @@ static void _init_pre(pre_t *data, uint8_t type, uint8_t len) } void skald_eddystone_uid_adv(skald_ctx_t *ctx, - const skald_eddystone_uid_t *uid, uint8_t tx_pwr) + const skald_eddystone_uid_t *uid, uint8_t tx_pwr, + uint32_t adv_itvl_ms) { assert(ctx && uid); @@ -85,11 +86,13 @@ void skald_eddystone_uid_adv(skald_ctx_t *ctx, /* start advertising */ ctx->pkt.len = sizeof(eddy_uid_t); + ctx->adv_itvl_ms = adv_itvl_ms; skald_adv_start(ctx); } void skald_eddystone_url_adv(skald_ctx_t *ctx, - uint8_t scheme, const char *url, uint8_t tx_pwr) + uint8_t scheme, const char *url, uint8_t tx_pwr, + uint32_t adv_itvl_ms) { assert(url && ctx); size_t len = strlen(url); @@ -105,5 +108,6 @@ void skald_eddystone_url_adv(skald_ctx_t *ctx, /* start advertising */ ctx->pkt.len = (sizeof(pre_t) + 2 + len); + ctx->adv_itvl_ms = adv_itvl_ms; skald_adv_start(ctx); } diff --git a/sys/net/ble/skald/skald_ibeacon.c b/sys/net/ble/skald/skald_ibeacon.c index 966b5a6b38..0936f46549 100644 --- a/sys/net/ble/skald/skald_ibeacon.c +++ b/sys/net/ble/skald/skald_ibeacon.c @@ -43,12 +43,14 @@ static const uint8_t prefix[PREFIX_LEN] = { 0x02, 0x01, 0x06, 0x1a, 0xff, 0x4c, 0x00, 0x02, 0x15 }; void skald_ibeacon_advertise(skald_ctx_t *ctx, const skald_uuid_t *uuid, - uint16_t major, uint16_t minor, uint8_t txpower) + uint16_t major, uint16_t minor, uint8_t txpower, + uint32_t adv_itvl_ms) { /* configure the iBeacon PDU */ ibeacon_t *pdu = (ibeacon_t *)ctx->pkt.pdu; ctx->pkt.len = (uint8_t)sizeof(ibeacon_t); + ctx->adv_itvl_ms = adv_itvl_ms; skald_generate_random_addr(pdu->txadd); memcpy(pdu->prefix, prefix, PREFIX_LEN);