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

Merge pull request #17834 from haukepetersen/opt_skald_advitvlconfig

net/ble/skald: make advertising interval configurable per context
This commit is contained in:
Martine Lenders 2022-06-21 13:31:57 +02:00 committed by GitHub
commit 03dfad899b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 26 additions and 30 deletions

View File

@ -33,6 +33,7 @@
#define URL "bit.ly/2Ep11dm"
/* calibrated TX power value */
#define TX_PWR (0U)
#define ADV_ITVL_MS 1000U
/* allocate two advertising contexts, one for Eddystone-URL and one for
* Eddystone-URI */
@ -45,10 +46,11 @@ int main(void)
/* advertise the defined URI */
skald_eddystone_uid_t uid = { URI_NAMESPACE, URI_INSTANCE };
skald_eddystone_uid_adv(&_ctx_uid, &uid, TX_PWR);
skald_eddystone_uid_adv(&_ctx_uid, &uid, TX_PWR, ADV_ITVL_MS);
/* also advertise the defined short-URL */
skald_eddystone_url_adv(&_ctx_url, EDDYSTONE_URL_HTTPS, URL, TX_PWR);
skald_eddystone_url_adv(&_ctx_url, EDDYSTONE_URL_HTTPS, URL, TX_PWR,
ADV_ITVL_MS);
return 0;
}

View File

@ -28,6 +28,7 @@
#define MAJOR (0x0023)
#define MINOR (0x0017)
#define TXPOWER (0U)
#define ADV_ITVL_MS 1000U
/* allocate a single advertising context */
static skald_ctx_t _ctx;
@ -38,7 +39,7 @@ int main(void)
/* this will configure the iBeacon and start advertising it */
skald_uuid_t uuid = { UUID };
skald_ibeacon_advertise(&_ctx, &uuid, MAJOR, MINOR, TXPOWER);
skald_ibeacon_advertise(&_ctx, &uuid, MAJOR, MINOR, TXPOWER, ADV_ITVL_MS);
return 0;
}

View File

@ -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;
/**

View File

@ -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
}

View File

@ -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
}

View File

@ -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"

View File

@ -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);

View File

@ -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);
}

View File

@ -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);