Bluetooth: Mesh: Refactor Health Client into async API

- Add optional callback to receive status messages even when using async
  API
- Split acked and unacked API

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
This commit is contained in:
Michał Narajowski 2021-11-29 16:15:15 +01:00 committed by Christopher Friedt
commit 4c30895a1a
3 changed files with 322 additions and 93 deletions

View file

@ -26,6 +26,49 @@ struct bt_mesh_health_cli {
/** Composition data model entry pointer. */
struct bt_mesh_model *model;
/** @brief Optional callback for Health Period Status messages.
*
* Handles received Health Period Status messages from a Health
* server. The @c divisor param represents the period divisor value.
*
* @param cli Health client that received the status message.
* @param addr Address of the sender.
* @param divisor Health Period Divisor value.
*/
void (*period_status)(struct bt_mesh_health_cli *cli, uint16_t addr,
uint8_t divisor);
/** @brief Optional callback for Health Attention Status messages.
*
* Handles received Health Attention Status messages from a Health
* server. The @c attention param represents the current attention value.
*
* @param cli Health client that received the status message.
* @param addr Address of the sender.
* @param attention Current attention value.
*/
void (*attention_status)(struct bt_mesh_health_cli *cli, uint16_t addr,
uint8_t attention);
/** @brief Optional callback for Health Fault Status messages.
*
* Handles received Health Fault Status messages from a Health
* server. The @c fault array represents all faults that are
* currently present in the server's element.
*
* @see bt_mesh_health_faults
*
* @param cli Health client that received the status message.
* @param addr Address of the sender.
* @param test_id Identifier of a most recently performed test.
* @param cid Company Identifier of the node.
* @param faults Array of faults.
* @param fault_count Number of faults in the fault array.
*/
void (*fault_status)(struct bt_mesh_health_cli *cli, uint16_t addr,
uint8_t test_id, uint16_t cid, uint8_t *faults,
size_t fault_count);
/** @brief Optional callback for Health Current Status messages.
*
* Handles received Health Current Status messages from a Health
@ -49,7 +92,6 @@ struct bt_mesh_health_cli {
struct bt_mesh_msg_ack_ctx ack_ctx;
};
/** @def BT_MESH_MODEL_HEALTH_CLI
*
* @brief Generic Health Client model composition data entry.
@ -82,8 +124,8 @@ int bt_mesh_health_cli_set(struct bt_mesh_model *model);
* @return 0 on success, or (negative) error code on failure.
*/
int bt_mesh_health_fault_get(uint16_t addr, uint16_t app_idx, uint16_t cid,
uint8_t *test_id, uint8_t *faults,
size_t *fault_count);
uint8_t *test_id, uint8_t *faults,
size_t *fault_count);
/** @brief Clear the registered faults for the given Company ID.
*
@ -99,8 +141,21 @@ int bt_mesh_health_fault_get(uint16_t addr, uint16_t app_idx, uint16_t cid,
* @return 0 on success, or (negative) error code on failure.
*/
int bt_mesh_health_fault_clear(uint16_t addr, uint16_t app_idx, uint16_t cid,
uint8_t *test_id, uint8_t *faults,
size_t *fault_count);
uint8_t *test_id, uint8_t *faults,
size_t *fault_count);
/** @brief Clear the registered faults for the given Company ID (unacked).
*
* @see bt_mesh_health_faults
*
* @param addr Target node element address.
* @param app_idx Application index to encrypt with.
* @param cid Company ID to clear the registered faults for.
*
* @return 0 on success, or (negative) error code on failure.
*/
int bt_mesh_health_fault_clear_unack(uint16_t addr, uint16_t app_idx,
uint16_t cid);
/** @brief Invoke a self-test procedure for the given Company ID.
*
@ -114,8 +169,20 @@ int bt_mesh_health_fault_clear(uint16_t addr, uint16_t app_idx, uint16_t cid,
* @return 0 on success, or (negative) error code on failure.
*/
int bt_mesh_health_fault_test(uint16_t addr, uint16_t app_idx, uint16_t cid,
uint8_t test_id, uint8_t *faults,
size_t *fault_count);
uint8_t test_id, uint8_t *faults,
size_t *fault_count);
/** @brief Invoke a self-test procedure for the given Company ID (unacked).
*
* @param addr Target node element address.
* @param app_idx Application index to encrypt with.
* @param cid Company ID to invoke the test for.
* @param test_id Test ID response buffer.
*
* @return 0 on success, or (negative) error code on failure.
*/
int bt_mesh_health_fault_test_unack(uint16_t addr, uint16_t app_idx,
uint16_t cid, uint8_t test_id);
/** @brief Get the target node's Health fast period divisor.
*
@ -133,7 +200,8 @@ int bt_mesh_health_fault_test(uint16_t addr, uint16_t app_idx, uint16_t cid,
*
* @return 0 on success, or (negative) error code on failure.
*/
int bt_mesh_health_period_get(uint16_t addr, uint16_t app_idx, uint8_t *divisor);
int bt_mesh_health_period_get(uint16_t addr, uint16_t app_idx,
uint8_t *divisor);
/** @brief Set the target node's Health fast period divisor.
*
@ -153,7 +221,20 @@ int bt_mesh_health_period_get(uint16_t addr, uint16_t app_idx, uint8_t *divisor)
* @return 0 on success, or (negative) error code on failure.
*/
int bt_mesh_health_period_set(uint16_t addr, uint16_t app_idx, uint8_t divisor,
uint8_t *updated_divisor);
uint8_t *updated_divisor);
/** @brief Set the target node's Health fast period divisor (unacknowledged).
*
* This is an unacknowledged version of this API.
*
* @param addr Target node element address.
* @param app_idx Application index to encrypt with.
* @param divisor New Health period divisor.
*
* @return 0 on success, or (negative) error code on failure.
*/
int bt_mesh_health_period_set_unack(uint16_t addr, uint16_t app_idx,
uint8_t divisor);
/** @brief Get the current attention timer value.
*
@ -163,7 +244,8 @@ int bt_mesh_health_period_set(uint16_t addr, uint16_t app_idx, uint8_t divisor,
*
* @return 0 on success, or (negative) error code on failure.
*/
int bt_mesh_health_attention_get(uint16_t addr, uint16_t app_idx, uint8_t *attention);
int bt_mesh_health_attention_get(uint16_t addr, uint16_t app_idx,
uint8_t *attention);
/** @brief Set the attention timer.
*
@ -175,8 +257,19 @@ int bt_mesh_health_attention_get(uint16_t addr, uint16_t app_idx, uint8_t *atten
*
* @return 0 on success, or (negative) error code on failure.
*/
int bt_mesh_health_attention_set(uint16_t addr, uint16_t app_idx, uint8_t attention,
uint8_t *updated_attention);
int bt_mesh_health_attention_set(uint16_t addr, uint16_t app_idx,
uint8_t attention, uint8_t *updated_attention);
/** @brief Set the attention timer (unacknowledged).
*
* @param addr Target node element address.
* @param app_idx Application index to encrypt with.
* @param attention New attention timer time, in seconds.
*
* @return 0 on success, or (negative) error code on failure.
*/
int bt_mesh_health_attention_set_unack(uint16_t addr, uint16_t app_idx,
uint8_t attention);
/** @brief Get the current transmission timeout value.
*