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

net/ble/skald: let itvl be configured per context

This commit is contained in:
Hauke Petersen 2022-03-21 22:23:53 +01:00
parent 078bced8e1
commit f10a28a7f7
7 changed files with 20 additions and 27 deletions

View File

@ -54,19 +54,6 @@
extern "C" { extern "C" {
#endif #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 * @brief List of advertising channels
*/ */
@ -89,6 +76,7 @@ typedef struct {
ztimer_t timer; /**< timer for scheduling advertising events */ ztimer_t timer; /**< timer for scheduling advertising events */
ztimer_now_t last; /**< last timer trigger (for offset compensation) */ ztimer_now_t last; /**< last timer trigger (for offset compensation) */
uint8_t cur_chan; /**< keep track of advertising channels */ uint8_t cur_chan; /**< keep track of advertising channels */
uint32_t adv_itvl_ms; /**< advertising interval [ms] */
} skald_ctx_t; } skald_ctx_t;
/** /**

View File

@ -58,9 +58,11 @@ typedef struct __attribute__((packed)) {
* @param[out] ctx advertising context * @param[out] ctx advertising context
* @param[in] uid UID to advertise * @param[in] uid UID to advertise
* @param[in] tx_pwr calibrated TX power to be advertised by the beacon * @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, 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 * @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] scheme encoded URL scheme prefix
* @param[in] url (short) url as \0 terminated string * @param[in] url (short) url as \0 terminated string
* @param[in] tx_pwr calibrated TX power to be advertised by the beacon * @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, 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 #ifdef __cplusplus
} }

View File

@ -42,9 +42,11 @@ extern "C" {
* @param[in] major the iBeacon's major number * @param[in] major the iBeacon's major number
* @param[in] minor the iBeacon's minor number * @param[in] minor the iBeacon's minor number
* @param[in] txpower calibrated TX power to be advertised by the beacon * @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, 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 #ifdef __cplusplus
} }

View File

@ -12,13 +12,6 @@ menuconfig KCONFIG_USEMODULE_SKALD
if 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 config SKALD_ADV_CHANNELS
string "Advertising channels" string "Advertising channels"
default "37, 38, 39" default "37, 38, 39"

View File

@ -63,7 +63,7 @@ static void _stop_radio(void)
static void _sched_next(skald_ctx_t *ctx) 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 /* schedule next advertising event, adding a random jitter between
* 0ms and 10ms (see spec v5.0-vol6-b-4.4.2.2.1) */ * 0ms and 10ms (see spec v5.0-vol6-b-4.4.2.2.1) */
ctx->last += random_uint32_range(JITTER_MIN, JITTER_MAX); 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, 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); assert(ctx && uid);
@ -85,11 +86,13 @@ void skald_eddystone_uid_adv(skald_ctx_t *ctx,
/* start advertising */ /* start advertising */
ctx->pkt.len = sizeof(eddy_uid_t); ctx->pkt.len = sizeof(eddy_uid_t);
ctx->adv_itvl_ms = adv_itvl_ms;
skald_adv_start(ctx); skald_adv_start(ctx);
} }
void skald_eddystone_url_adv(skald_ctx_t *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); assert(url && ctx);
size_t len = strlen(url); size_t len = strlen(url);
@ -105,5 +108,6 @@ void skald_eddystone_url_adv(skald_ctx_t *ctx,
/* start advertising */ /* start advertising */
ctx->pkt.len = (sizeof(pre_t) + 2 + len); ctx->pkt.len = (sizeof(pre_t) + 2 + len);
ctx->adv_itvl_ms = adv_itvl_ms;
skald_adv_start(ctx); 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 }; 0x4c, 0x00, 0x02, 0x15 };
void skald_ibeacon_advertise(skald_ctx_t *ctx, const skald_uuid_t *uuid, 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 */ /* configure the iBeacon PDU */
ibeacon_t *pdu = (ibeacon_t *)ctx->pkt.pdu; ibeacon_t *pdu = (ibeacon_t *)ctx->pkt.pdu;
ctx->pkt.len = (uint8_t)sizeof(ibeacon_t); ctx->pkt.len = (uint8_t)sizeof(ibeacon_t);
ctx->adv_itvl_ms = adv_itvl_ms;
skald_generate_random_addr(pdu->txadd); skald_generate_random_addr(pdu->txadd);
memcpy(pdu->prefix, prefix, PREFIX_LEN); memcpy(pdu->prefix, prefix, PREFIX_LEN);