mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
skald_bthome_saul: add message fragmentation
This commit is contained in:
parent
7d0d41a10a
commit
5d6f27b54c
@ -167,6 +167,24 @@ struct skald_bthome_ctx {
|
|||||||
*/
|
*/
|
||||||
uint8_t encrypt;
|
uint8_t encrypt;
|
||||||
#endif
|
#endif
|
||||||
|
#if IS_USED(MODULE_SKALD_BTHOME_SAUL) || defined(DOXYGEN)
|
||||||
|
/**
|
||||||
|
* @brief The index of the last device sent in skald_bthome_ctx_t::devs.
|
||||||
|
*
|
||||||
|
* Will be updated on each periodic advertisement to allow for fragmenting
|
||||||
|
* different measurement readings across multiple advertisements (in case all
|
||||||
|
* measurements from skald_bthome_ctx_t::devs are too large for one
|
||||||
|
* advertisement). Is initialized to 0.
|
||||||
|
*
|
||||||
|
* If a single reading is too big to fit into an advertisement,
|
||||||
|
* the skald_ctx_t::update_pkt() callback will just return (i.e. BTHome
|
||||||
|
* payload may be left empty) and skald_bthome_ctx_t::last_dev_sent will
|
||||||
|
* be reset to 0.
|
||||||
|
* This can e.g. happen with a @ref BTHOME_ID_TEXT or @ref BTHOME_ID_RAW record
|
||||||
|
* if the appended bytes are larger than a BLE advertisement.
|
||||||
|
*/
|
||||||
|
uint8_t last_dev_sent;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -160,8 +160,11 @@ int skald_bthome_add_measurement(
|
|||||||
uint16_t exp_size = ctx->skald.pkt.len + sizeof(obj_id) + data_len + data_contains_length;
|
uint16_t exp_size = ctx->skald.pkt.len + sizeof(obj_id) + data_len + data_contains_length;
|
||||||
uint8_t offset = ctx->skald.pkt.len;
|
uint8_t offset = ctx->skald.pkt.len;
|
||||||
|
|
||||||
|
#ifdef MODULE_SKALD_BTHOME_ENCRYPT
|
||||||
|
exp_size += 8;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (exp_size >= NETDEV_BLE_PDU_MAXLEN) {
|
if (exp_size >= NETDEV_BLE_PDU_MAXLEN) {
|
||||||
assert(exp_size < NETDEV_BLE_PDU_MAXLEN);
|
|
||||||
return -EMSGSIZE;
|
return -EMSGSIZE;
|
||||||
}
|
}
|
||||||
ctx->skald.pkt.pdu[offset++] = (uint8_t)obj_id;
|
ctx->skald.pkt.pdu[offset++] = (uint8_t)obj_id;
|
||||||
|
@ -423,32 +423,50 @@ static void _reset_hdr(skald_bthome_ctx_t *ctx)
|
|||||||
static void _update_saul_measurements(skald_ctx_t *skald_ctx)
|
static void _update_saul_measurements(skald_ctx_t *skald_ctx)
|
||||||
{
|
{
|
||||||
skald_bthome_ctx_t *ctx = container_of(skald_ctx, skald_bthome_ctx_t, skald);
|
skald_bthome_ctx_t *ctx = container_of(skald_ctx, skald_bthome_ctx_t, skald);
|
||||||
|
uint8_t dev_idx = 0;
|
||||||
|
uint8_t orig_last_dev_sent = ctx->last_dev_sent;
|
||||||
|
|
||||||
_reset_hdr(ctx);
|
_reset_hdr(ctx);
|
||||||
skald_bthome_saul_t *ptr = ctx->devs;
|
skald_bthome_saul_t *ptr = ctx->devs;
|
||||||
while (ptr) {
|
while (ptr) {
|
||||||
int dim = 1;
|
if ((ctx->last_dev_sent == 0) ||
|
||||||
phydat_t data = { 0 };
|
(dev_idx > ctx->last_dev_sent)) {
|
||||||
|
int dim = 1;
|
||||||
|
int res = 0;
|
||||||
|
phydat_t data = { 0 };
|
||||||
|
|
||||||
if (ptr->saul.driver) {
|
if (ptr->saul.driver) {
|
||||||
dim = saul_reg_read(&ptr->saul, &data);
|
dim = saul_reg_read(&ptr->saul, &data);
|
||||||
if (dim <= 0) {
|
if (dim <= 0) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
for (uint8_t i = 0; i < dim; i++) {
|
||||||
for (uint8_t i = 0; i < dim; i++) {
|
if ((res = ptr->add_measurement(ctx, ptr->obj_id, &data, i)) < 0) {
|
||||||
if (ptr->add_measurement(ctx, ptr->obj_id, &data, i) < 0) {
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((res == -EMSGSIZE) && (dev_idx > 0)) {
|
||||||
|
ctx->last_dev_sent = dev_idx - 1;
|
||||||
|
}
|
||||||
|
if (res < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr = container_of(
|
ptr = container_of(
|
||||||
ptr->saul.next, skald_bthome_saul_t, saul
|
ptr->saul.next, skald_bthome_saul_t, saul
|
||||||
);
|
);
|
||||||
|
dev_idx++;
|
||||||
}
|
}
|
||||||
#if IS_USED(MODULE_SKALD_BTHOME_ENCRYPT)
|
#if IS_USED(MODULE_SKALD_BTHOME_ENCRYPT)
|
||||||
skald_bthome_encrypt(ctx);
|
skald_bthome_encrypt(ctx);
|
||||||
#endif
|
#endif
|
||||||
|
if ((ptr == NULL) ||
|
||||||
|
/* or value just too big */
|
||||||
|
(orig_last_dev_sent == ctx->last_dev_sent)) {
|
||||||
|
/* reset device train */
|
||||||
|
ctx->last_dev_sent = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int skald_bthome_saul_add(skald_bthome_ctx_t *ctx, skald_bthome_saul_t *saul)
|
int skald_bthome_saul_add(skald_bthome_ctx_t *ctx, skald_bthome_saul_t *saul)
|
||||||
|
Loading…
Reference in New Issue
Block a user