Bluetooth: Mesh: Introduce helpers to wait for a status message
There was a lot of code duplicated in the Foundation Client Models for waiting on a specific status message. Refactor this into helper functions (one per client model). Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
7e8f9afee5
commit
30d6761396
2 changed files with 49 additions and 171 deletions
|
@ -448,6 +448,21 @@ static int check_cli(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int cli_wait(void *param, u32_t op)
|
||||
{
|
||||
int err;
|
||||
|
||||
cli->op_param = param;
|
||||
cli->op_pending = op;
|
||||
|
||||
err = k_sem_take(&cli->op_sync, msg_timeout);
|
||||
|
||||
cli->op_pending = 0;
|
||||
cli->op_param = NULL;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int bt_mesh_cfg_comp_data_get(u16_t net_idx, u16_t addr, u8_t page,
|
||||
u8_t *status, struct net_buf_simple *comp)
|
||||
{
|
||||
|
@ -478,15 +493,7 @@ int bt_mesh_cfg_comp_data_get(u16_t net_idx, u16_t addr, u8_t page,
|
|||
return err;
|
||||
}
|
||||
|
||||
cli->op_param = ¶m;
|
||||
cli->op_pending = OP_DEV_COMP_DATA_STATUS;
|
||||
|
||||
err = k_sem_take(&cli->op_sync, msg_timeout);
|
||||
|
||||
cli->op_pending = 0;
|
||||
cli->op_param = NULL;
|
||||
|
||||
return err;
|
||||
return cli_wait(¶m, OP_DEV_COMP_DATA_STATUS);
|
||||
}
|
||||
|
||||
static int get_state_u8(u16_t net_idx, u16_t addr, u32_t op, u32_t rsp,
|
||||
|
@ -514,15 +521,7 @@ static int get_state_u8(u16_t net_idx, u16_t addr, u32_t op, u32_t rsp,
|
|||
return err;
|
||||
}
|
||||
|
||||
cli->op_param = val;
|
||||
cli->op_pending = rsp;
|
||||
|
||||
err = k_sem_take(&cli->op_sync, msg_timeout);
|
||||
|
||||
cli->op_pending = 0;
|
||||
cli->op_param = NULL;
|
||||
|
||||
return err;
|
||||
return cli_wait(val, rsp);
|
||||
}
|
||||
|
||||
static int set_state_u8(u16_t net_idx, u16_t addr, u32_t op, u32_t rsp,
|
||||
|
@ -551,15 +550,7 @@ static int set_state_u8(u16_t net_idx, u16_t addr, u32_t op, u32_t rsp,
|
|||
return err;
|
||||
}
|
||||
|
||||
cli->op_param = val;
|
||||
cli->op_pending = rsp;
|
||||
|
||||
err = k_sem_take(&cli->op_sync, msg_timeout);
|
||||
|
||||
cli->op_pending = 0;
|
||||
cli->op_param = NULL;
|
||||
|
||||
return err;
|
||||
return cli_wait(val, rsp);
|
||||
}
|
||||
|
||||
int bt_mesh_cfg_beacon_get(u16_t net_idx, u16_t addr, u8_t *status)
|
||||
|
@ -640,15 +631,7 @@ int bt_mesh_cfg_relay_get(u16_t net_idx, u16_t addr, u8_t *status,
|
|||
return err;
|
||||
}
|
||||
|
||||
cli->op_param = ¶m;
|
||||
cli->op_pending = OP_RELAY_STATUS;
|
||||
|
||||
err = k_sem_take(&cli->op_sync, msg_timeout);
|
||||
|
||||
cli->op_pending = 0;
|
||||
cli->op_param = NULL;
|
||||
|
||||
return err;
|
||||
return cli_wait(¶m, OP_RELAY_STATUS);
|
||||
}
|
||||
|
||||
int bt_mesh_cfg_relay_set(u16_t net_idx, u16_t addr, u8_t new_relay,
|
||||
|
@ -682,15 +665,7 @@ int bt_mesh_cfg_relay_set(u16_t net_idx, u16_t addr, u8_t new_relay,
|
|||
return err;
|
||||
}
|
||||
|
||||
cli->op_param = ¶m;
|
||||
cli->op_pending = OP_RELAY_STATUS;
|
||||
|
||||
err = k_sem_take(&cli->op_sync, msg_timeout);
|
||||
|
||||
cli->op_pending = 0;
|
||||
cli->op_param = NULL;
|
||||
|
||||
return err;
|
||||
return cli_wait(¶m, OP_RELAY_STATUS);
|
||||
}
|
||||
|
||||
int bt_mesh_cfg_app_key_add(u16_t net_idx, u16_t addr, u16_t key_net_idx,
|
||||
|
@ -730,15 +705,7 @@ int bt_mesh_cfg_app_key_add(u16_t net_idx, u16_t addr, u16_t key_net_idx,
|
|||
return 0;
|
||||
}
|
||||
|
||||
cli->op_param = ¶m;
|
||||
cli->op_pending = OP_APP_KEY_STATUS;
|
||||
|
||||
err = k_sem_take(&cli->op_sync, msg_timeout);
|
||||
|
||||
cli->op_pending = 0;
|
||||
cli->op_param = NULL;
|
||||
|
||||
return err;
|
||||
return cli_wait(¶m, OP_APP_KEY_STATUS);
|
||||
}
|
||||
|
||||
static int mod_app_bind(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
||||
|
@ -786,15 +753,7 @@ static int mod_app_bind(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
|||
return 0;
|
||||
}
|
||||
|
||||
cli->op_param = ¶m;
|
||||
cli->op_pending = OP_MOD_APP_STATUS;
|
||||
|
||||
err = k_sem_take(&cli->op_sync, msg_timeout);
|
||||
|
||||
cli->op_pending = 0;
|
||||
cli->op_param = NULL;
|
||||
|
||||
return err;
|
||||
return cli_wait(¶m, OP_MOD_APP_STATUS);
|
||||
}
|
||||
|
||||
int bt_mesh_cfg_mod_app_bind(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
||||
|
@ -860,15 +819,7 @@ static int mod_sub(u32_t op, u16_t net_idx, u16_t addr, u16_t elem_addr,
|
|||
return 0;
|
||||
}
|
||||
|
||||
cli->op_param = ¶m;
|
||||
cli->op_pending = OP_MOD_SUB_STATUS;
|
||||
|
||||
err = k_sem_take(&cli->op_sync, msg_timeout);
|
||||
|
||||
cli->op_pending = 0;
|
||||
cli->op_param = NULL;
|
||||
|
||||
return err;
|
||||
return cli_wait(¶m, OP_MOD_SUB_STATUS);
|
||||
}
|
||||
|
||||
int bt_mesh_cfg_mod_sub_add(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
||||
|
@ -973,15 +924,7 @@ static int mod_pub_get(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
|||
return 0;
|
||||
}
|
||||
|
||||
cli->op_param = ¶m;
|
||||
cli->op_pending = OP_MOD_PUB_STATUS;
|
||||
|
||||
err = k_sem_take(&cli->op_sync, msg_timeout);
|
||||
|
||||
cli->op_pending = 0;
|
||||
cli->op_param = NULL;
|
||||
|
||||
return err;
|
||||
return cli_wait(¶m, OP_MOD_PUB_STATUS);
|
||||
}
|
||||
|
||||
int bt_mesh_cfg_mod_pub_get(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
||||
|
@ -1054,15 +997,7 @@ static int mod_pub_set(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
|||
return 0;
|
||||
}
|
||||
|
||||
cli->op_param = ¶m;
|
||||
cli->op_pending = OP_MOD_PUB_STATUS;
|
||||
|
||||
err = k_sem_take(&cli->op_sync, msg_timeout);
|
||||
|
||||
cli->op_pending = 0;
|
||||
cli->op_param = NULL;
|
||||
|
||||
return err;
|
||||
return cli_wait(¶m, OP_MOD_PUB_STATUS);
|
||||
}
|
||||
|
||||
int bt_mesh_cfg_mod_pub_set(u16_t net_idx, u16_t addr, u16_t elem_addr,
|
||||
|
@ -1121,15 +1056,7 @@ int bt_mesh_cfg_hb_sub_set(u16_t net_idx, u16_t addr,
|
|||
return 0;
|
||||
}
|
||||
|
||||
cli->op_param = ¶m;
|
||||
cli->op_pending = OP_HEARTBEAT_SUB_STATUS;
|
||||
|
||||
err = k_sem_take(&cli->op_sync, msg_timeout);
|
||||
|
||||
cli->op_pending = 0;
|
||||
cli->op_param = NULL;
|
||||
|
||||
return err;
|
||||
return cli_wait(¶m, OP_HEARTBEAT_SUB_STATUS);
|
||||
}
|
||||
|
||||
int bt_mesh_cfg_hb_sub_get(u16_t net_idx, u16_t addr,
|
||||
|
@ -1165,15 +1092,7 @@ int bt_mesh_cfg_hb_sub_get(u16_t net_idx, u16_t addr,
|
|||
return 0;
|
||||
}
|
||||
|
||||
cli->op_param = ¶m;
|
||||
cli->op_pending = OP_HEARTBEAT_SUB_STATUS;
|
||||
|
||||
err = k_sem_take(&cli->op_sync, msg_timeout);
|
||||
|
||||
cli->op_pending = 0;
|
||||
cli->op_param = NULL;
|
||||
|
||||
return err;
|
||||
return cli_wait(¶m, OP_HEARTBEAT_SUB_STATUS);
|
||||
}
|
||||
|
||||
int bt_mesh_cfg_hb_pub_set(u16_t net_idx, u16_t addr,
|
||||
|
@ -1214,15 +1133,7 @@ int bt_mesh_cfg_hb_pub_set(u16_t net_idx, u16_t addr,
|
|||
return 0;
|
||||
}
|
||||
|
||||
cli->op_param = ¶m;
|
||||
cli->op_pending = OP_HEARTBEAT_PUB_STATUS;
|
||||
|
||||
err = k_sem_take(&cli->op_sync, msg_timeout);
|
||||
|
||||
cli->op_pending = 0;
|
||||
cli->op_param = NULL;
|
||||
|
||||
return err;
|
||||
return cli_wait(¶m, OP_HEARTBEAT_PUB_STATUS);
|
||||
}
|
||||
|
||||
int bt_mesh_cfg_hb_pub_get(u16_t net_idx, u16_t addr,
|
||||
|
@ -1258,15 +1169,7 @@ int bt_mesh_cfg_hb_pub_get(u16_t net_idx, u16_t addr,
|
|||
return 0;
|
||||
}
|
||||
|
||||
cli->op_param = ¶m;
|
||||
cli->op_pending = OP_HEARTBEAT_PUB_STATUS;
|
||||
|
||||
err = k_sem_take(&cli->op_sync, msg_timeout);
|
||||
|
||||
cli->op_pending = 0;
|
||||
cli->op_param = NULL;
|
||||
|
||||
return err;
|
||||
return cli_wait(¶m, OP_HEARTBEAT_PUB_STATUS);
|
||||
}
|
||||
|
||||
s32_t bt_mesh_cfg_cli_timeout_get(void)
|
||||
|
|
|
@ -155,6 +155,21 @@ static int check_cli(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int cli_wait(void *param, u32_t op)
|
||||
{
|
||||
int err;
|
||||
|
||||
health_cli->op_param = param;
|
||||
health_cli->op_pending = op;
|
||||
|
||||
err = k_sem_take(&health_cli->op_sync, msg_timeout);
|
||||
|
||||
health_cli->op_pending = 0;
|
||||
health_cli->op_param = NULL;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int bt_mesh_health_period_get(u16_t net_idx, u16_t addr, u16_t app_idx,
|
||||
u8_t *divisor)
|
||||
{
|
||||
|
@ -183,15 +198,7 @@ int bt_mesh_health_period_get(u16_t net_idx, u16_t addr, u16_t app_idx,
|
|||
return err;
|
||||
}
|
||||
|
||||
health_cli->op_param = ¶m;
|
||||
health_cli->op_pending = OP_HEALTH_PERIOD_STATUS;
|
||||
|
||||
err = k_sem_take(&health_cli->op_sync, msg_timeout);
|
||||
|
||||
health_cli->op_pending = 0;
|
||||
health_cli->op_param = NULL;
|
||||
|
||||
return err;
|
||||
return cli_wait(¶m, OP_HEALTH_PERIOD_STATUS);
|
||||
}
|
||||
|
||||
int bt_mesh_health_period_set(u16_t net_idx, u16_t addr, u16_t app_idx,
|
||||
|
@ -232,15 +239,7 @@ int bt_mesh_health_period_set(u16_t net_idx, u16_t addr, u16_t app_idx,
|
|||
return 0;
|
||||
}
|
||||
|
||||
health_cli->op_param = ¶m;
|
||||
health_cli->op_pending = OP_HEALTH_PERIOD_STATUS;
|
||||
|
||||
err = k_sem_take(&health_cli->op_sync, msg_timeout);
|
||||
|
||||
health_cli->op_pending = 0;
|
||||
health_cli->op_param = NULL;
|
||||
|
||||
return err;
|
||||
return cli_wait(¶m, OP_HEALTH_PERIOD_STATUS);
|
||||
}
|
||||
|
||||
int bt_mesh_health_fault_test(u16_t net_idx, u16_t addr, u16_t app_idx,
|
||||
|
@ -286,15 +285,7 @@ int bt_mesh_health_fault_test(u16_t net_idx, u16_t addr, u16_t app_idx,
|
|||
return 0;
|
||||
}
|
||||
|
||||
health_cli->op_param = ¶m;
|
||||
health_cli->op_pending = OP_HEALTH_FAULT_STATUS;
|
||||
|
||||
err = k_sem_take(&health_cli->op_sync, msg_timeout);
|
||||
|
||||
health_cli->op_pending = 0;
|
||||
health_cli->op_param = NULL;
|
||||
|
||||
return err;
|
||||
return cli_wait(¶m, OP_HEALTH_FAULT_STATUS);
|
||||
}
|
||||
|
||||
int bt_mesh_health_fault_clear(u16_t net_idx, u16_t addr, u16_t app_idx,
|
||||
|
@ -339,15 +330,7 @@ int bt_mesh_health_fault_clear(u16_t net_idx, u16_t addr, u16_t app_idx,
|
|||
return 0;
|
||||
}
|
||||
|
||||
health_cli->op_param = ¶m;
|
||||
health_cli->op_pending = OP_HEALTH_FAULT_STATUS;
|
||||
|
||||
err = k_sem_take(&health_cli->op_sync, msg_timeout);
|
||||
|
||||
health_cli->op_pending = 0;
|
||||
health_cli->op_param = NULL;
|
||||
|
||||
return err;
|
||||
return cli_wait(¶m, OP_HEALTH_FAULT_STATUS);
|
||||
}
|
||||
|
||||
int bt_mesh_health_fault_get(u16_t net_idx, u16_t addr, u16_t app_idx,
|
||||
|
@ -383,15 +366,7 @@ int bt_mesh_health_fault_get(u16_t net_idx, u16_t addr, u16_t app_idx,
|
|||
return err;
|
||||
}
|
||||
|
||||
health_cli->op_param = ¶m;
|
||||
health_cli->op_pending = OP_HEALTH_FAULT_STATUS;
|
||||
|
||||
err = k_sem_take(&health_cli->op_sync, msg_timeout);
|
||||
|
||||
health_cli->op_pending = 0;
|
||||
health_cli->op_param = NULL;
|
||||
|
||||
return err;
|
||||
return cli_wait(¶m, OP_HEALTH_FAULT_STATUS);
|
||||
}
|
||||
|
||||
s32_t bt_mesh_health_cli_timeout_get(void)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue