Bluetooth: Mesh: Use dedicated struct for heartbeat publication
This simplifies the API since there is no-longer a need to pass a huge number of function arguments around. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
a18a22524f
commit
d4365e16f9
|
@ -108,13 +108,20 @@ int bt_mesh_cfg_hb_sub_get(u16_t net_idx, u16_t addr, u16_t *src, u16_t *dst,
|
|||
u8_t *period, u8_t *count, u8_t *min, u8_t *max,
|
||||
u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_hb_pub_set(u16_t net_idx, u16_t addr, u16_t pub_dst,
|
||||
u8_t count, u8_t period, u8_t ttl, u16_t feat,
|
||||
u16_t pub_net_idx, u8_t *status);
|
||||
struct bt_mesh_cfg_hb_pub {
|
||||
u16_t dst;
|
||||
u8_t count;
|
||||
u8_t period;
|
||||
u8_t ttl;
|
||||
u16_t feat;
|
||||
u16_t net_idx;
|
||||
};
|
||||
|
||||
int bt_mesh_cfg_hb_pub_get(u16_t net_idx, u16_t addr, u16_t *pub_dst,
|
||||
u8_t *count, u8_t *period, u8_t *ttl, u16_t *feat,
|
||||
u16_t *pub_net_idx, u8_t *status);
|
||||
int bt_mesh_cfg_hb_pub_set(u16_t net_idx, u16_t addr,
|
||||
const struct bt_mesh_cfg_hb_pub *pub, u8_t *status);
|
||||
|
||||
int bt_mesh_cfg_hb_pub_get(u16_t net_idx, u16_t addr,
|
||||
struct bt_mesh_cfg_hb_pub *pub, u8_t *status);
|
||||
|
||||
s32_t bt_mesh_cfg_cli_timeout_get(void);
|
||||
void bt_mesh_cfg_cli_timeout_set(s32_t timeout);
|
||||
|
|
|
@ -159,9 +159,19 @@ static void configure(void)
|
|||
MOD_INTEL, CID_INTEL, NULL);
|
||||
|
||||
#if defined(NODE_ADDR) && NODE_ADDR == PROV_ADDR
|
||||
bt_mesh_cfg_hb_pub_set(net_idx, addr, GROUP_ADDR, 0xff, 0x05, 0x07,
|
||||
0, net_idx, NULL);
|
||||
printk("Publishing heartbeat messages\n");
|
||||
{
|
||||
struct bt_mesh_cfg_hb_pub pub = {
|
||||
.dst = GROUP_ADDR,
|
||||
.count = 0xff,
|
||||
.period = 0x05,
|
||||
.ttl = 0x07,
|
||||
.feat = 0,
|
||||
.net_idx = net_idx,
|
||||
};
|
||||
|
||||
bt_mesh_cfg_hb_pub_set(net_idx, addr, &pub, NULL);
|
||||
printk("Publishing heartbeat messages\n");
|
||||
}
|
||||
#else
|
||||
/* Heartbeat subscription */
|
||||
bt_mesh_cfg_hb_sub_set(net_idx, addr, PROV_ADDR, GROUP_ADDR, 0x10,
|
||||
|
|
|
@ -389,13 +389,8 @@ static void hb_sub_status(struct bt_mesh_model *model,
|
|||
}
|
||||
|
||||
struct hb_pub_param {
|
||||
u8_t *status;
|
||||
u16_t *dst;
|
||||
u8_t *count;
|
||||
u8_t *period;
|
||||
u8_t *ttl;
|
||||
u16_t *feat;
|
||||
u16_t *net_idx;
|
||||
u8_t *status;
|
||||
struct bt_mesh_cfg_hb_pub *pub;
|
||||
};
|
||||
|
||||
static void hb_pub_status(struct bt_mesh_model *model,
|
||||
|
@ -413,13 +408,18 @@ static void hb_pub_status(struct bt_mesh_model *model,
|
|||
return;
|
||||
}
|
||||
|
||||
param = cli->op_param;
|
||||
|
||||
*param->status = net_buf_simple_pull_u8(buf);
|
||||
*param->dst = net_buf_simple_pull_le16(buf);
|
||||
*param->count = net_buf_simple_pull_u8(buf);
|
||||
*param->period = net_buf_simple_pull_u8(buf);
|
||||
*param->ttl = net_buf_simple_pull_u8(buf);
|
||||
*param->feat = net_buf_simple_pull_u8(buf);
|
||||
*param->net_idx = net_buf_simple_pull_u8(buf);
|
||||
|
||||
if (param->pub) {
|
||||
param->pub->dst = net_buf_simple_pull_le16(buf);
|
||||
param->pub->count = net_buf_simple_pull_u8(buf);
|
||||
param->pub->period = net_buf_simple_pull_u8(buf);
|
||||
param->pub->ttl = net_buf_simple_pull_u8(buf);
|
||||
param->pub->feat = net_buf_simple_pull_u8(buf);
|
||||
param->pub->net_idx = net_buf_simple_pull_u8(buf);
|
||||
}
|
||||
|
||||
k_sem_give(&cli->op_sync);
|
||||
}
|
||||
|
@ -1150,9 +1150,8 @@ int bt_mesh_cfg_hb_sub_get(u16_t net_idx, u16_t addr, u16_t *src, u16_t *dst,
|
|||
return err;
|
||||
}
|
||||
|
||||
int bt_mesh_cfg_hb_pub_set(u16_t net_idx, u16_t addr, u16_t pub_dst,
|
||||
u8_t count, u8_t period, u8_t ttl, u16_t feat,
|
||||
u16_t pub_net_idx, u8_t *status)
|
||||
int bt_mesh_cfg_hb_pub_set(u16_t net_idx, u16_t addr,
|
||||
const struct bt_mesh_cfg_hb_pub *pub, u8_t *status)
|
||||
{
|
||||
struct net_buf_simple *msg = NET_BUF_SIMPLE(2 + 9 + 4);
|
||||
struct bt_mesh_msg_ctx ctx = {
|
||||
|
@ -1163,12 +1162,6 @@ int bt_mesh_cfg_hb_pub_set(u16_t net_idx, u16_t addr, u16_t pub_dst,
|
|||
};
|
||||
struct hb_pub_param param = {
|
||||
.status = status,
|
||||
.dst = &pub_dst,
|
||||
.count = &count,
|
||||
.period = &period,
|
||||
.ttl = &ttl,
|
||||
.feat = &feat,
|
||||
.net_idx = &pub_net_idx,
|
||||
};
|
||||
int err;
|
||||
|
||||
|
@ -1178,12 +1171,12 @@ int bt_mesh_cfg_hb_pub_set(u16_t net_idx, u16_t addr, u16_t pub_dst,
|
|||
}
|
||||
|
||||
bt_mesh_model_msg_init(msg, OP_HEARTBEAT_PUB_SET);
|
||||
net_buf_simple_add_le16(msg, pub_dst);
|
||||
net_buf_simple_add_u8(msg, count);
|
||||
net_buf_simple_add_u8(msg, period);
|
||||
net_buf_simple_add_u8(msg, ttl);
|
||||
net_buf_simple_add_le16(msg, feat);
|
||||
net_buf_simple_add_le16(msg, pub_net_idx);
|
||||
net_buf_simple_add_le16(msg, pub->dst);
|
||||
net_buf_simple_add_u8(msg, pub->count);
|
||||
net_buf_simple_add_u8(msg, pub->period);
|
||||
net_buf_simple_add_u8(msg, pub->ttl);
|
||||
net_buf_simple_add_le16(msg, pub->feat);
|
||||
net_buf_simple_add_le16(msg, pub->net_idx);
|
||||
|
||||
err = bt_mesh_model_send(cli->model, &ctx, msg, NULL, NULL);
|
||||
if (err) {
|
||||
|
@ -1206,9 +1199,8 @@ int bt_mesh_cfg_hb_pub_set(u16_t net_idx, u16_t addr, u16_t pub_dst,
|
|||
return err;
|
||||
}
|
||||
|
||||
int bt_mesh_cfg_hb_pub_get(u16_t net_idx, u16_t addr, u16_t *pub_dst,
|
||||
u8_t *count, u8_t *period, u8_t *ttl, u16_t *feat,
|
||||
u16_t *pub_net_idx, u8_t *status)
|
||||
int bt_mesh_cfg_hb_pub_get(u16_t net_idx, u16_t addr,
|
||||
struct bt_mesh_cfg_hb_pub *pub, u8_t *status)
|
||||
{
|
||||
struct net_buf_simple *msg = NET_BUF_SIMPLE(2 + 0 + 4);
|
||||
struct bt_mesh_msg_ctx ctx = {
|
||||
|
@ -1219,12 +1211,7 @@ int bt_mesh_cfg_hb_pub_get(u16_t net_idx, u16_t addr, u16_t *pub_dst,
|
|||
};
|
||||
struct hb_pub_param param = {
|
||||
.status = status,
|
||||
.dst = pub_dst,
|
||||
.count = count,
|
||||
.period = period,
|
||||
.ttl = ttl,
|
||||
.feat = feat,
|
||||
.net_idx = pub_net_idx,
|
||||
.pub = pub,
|
||||
};
|
||||
int err;
|
||||
|
||||
|
|
|
@ -866,13 +866,11 @@ static int cmd_hb_sub(int argc, char *argv[])
|
|||
|
||||
static int hb_pub_get(int argc, char *argv[])
|
||||
{
|
||||
u8_t status, count, period, ttl;
|
||||
u16_t pub_dst, feat, pub_net_idx;
|
||||
struct bt_mesh_cfg_hb_pub pub;
|
||||
u8_t status;
|
||||
int err;
|
||||
|
||||
err = bt_mesh_cfg_hb_pub_get(net.net_idx, net.dst, &pub_dst, &count,
|
||||
&period, &ttl, &feat, &pub_net_idx,
|
||||
&status);
|
||||
err = bt_mesh_cfg_hb_pub_get(net.net_idx, net.dst, &pub, &status);
|
||||
if (err) {
|
||||
printk("Heartbeat Publication Get failed (err %d)\n", err);
|
||||
return 0;
|
||||
|
@ -886,28 +884,27 @@ static int hb_pub_get(int argc, char *argv[])
|
|||
|
||||
printk("Heartbeat publication:\n");
|
||||
printk("\tdst 0x%04x count 0x%02x period 0x%02x\n",
|
||||
pub_dst, count, period);
|
||||
pub.dst, pub.count, pub.period);
|
||||
printk("\tttl 0x%02x feat 0x%04x net_idx 0x%04x\n",
|
||||
ttl, feat, pub_net_idx);
|
||||
pub.ttl, pub.feat, pub.net_idx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int hb_pub_set(int argc, char *argv[])
|
||||
{
|
||||
u8_t status, count, period, ttl;
|
||||
u16_t pub_dst, feat, pub_net_idx;
|
||||
struct bt_mesh_cfg_hb_pub pub;
|
||||
u8_t status;
|
||||
int err;
|
||||
|
||||
pub_dst = strtoul(argv[1], NULL, 0);
|
||||
count = strtoul(argv[2], NULL, 0);
|
||||
period = strtoul(argv[3], NULL, 0);
|
||||
ttl = strtoul(argv[4], NULL, 0);
|
||||
feat = strtoul(argv[5], NULL, 0);
|
||||
pub_net_idx = strtoul(argv[5], NULL, 0);
|
||||
pub.dst = strtoul(argv[1], NULL, 0);
|
||||
pub.count = strtoul(argv[2], NULL, 0);
|
||||
pub.period = strtoul(argv[3], NULL, 0);
|
||||
pub.ttl = strtoul(argv[4], NULL, 0);
|
||||
pub.feat = strtoul(argv[5], NULL, 0);
|
||||
pub.net_idx = strtoul(argv[5], NULL, 0);
|
||||
|
||||
err = bt_mesh_cfg_hb_pub_set(net.net_idx, net.dst, pub_dst, count,
|
||||
period, ttl, feat, pub_net_idx, &status);
|
||||
err = bt_mesh_cfg_hb_pub_set(net.net_idx, net.dst, &pub, &status);
|
||||
if (err) {
|
||||
printk("Heartbeat Publication Set failed (err %d)\n", err);
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue