health_cli.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /** @file
  2. * @brief Health Client Model APIs.
  3. */
  4. /*
  5. * Copyright (c) 2017 Intel Corporation
  6. *
  7. * SPDX-License-Identifier: Apache-2.0
  8. */
  9. #ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_HEALTH_CLI_H_
  10. #define ZEPHYR_INCLUDE_BLUETOOTH_MESH_HEALTH_CLI_H_
  11. /**
  12. * @brief Health Client Model
  13. * @defgroup bt_mesh_health_cli Health Client Model
  14. * @ingroup bt_mesh
  15. * @{
  16. */
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /** Health Client Model Context */
  21. struct bt_mesh_health_cli {
  22. /** Composition data model entry pointer. */
  23. struct bt_mesh_model *model;
  24. /** @brief Optional callback for Health Current Status messages.
  25. *
  26. * Handles received Health Current Status messages from a Health
  27. * server. The @c fault array represents all faults that are
  28. * currently present in the server's element.
  29. *
  30. * @see bt_mesh_health_faults
  31. *
  32. * @param cli Health client that received the status message.
  33. * @param addr Address of the sender.
  34. * @param test_id Identifier of a most recently performed test.
  35. * @param cid Company Identifier of the node.
  36. * @param faults Array of faults.
  37. * @param fault_count Number of faults in the fault array.
  38. */
  39. void (*current_status)(struct bt_mesh_health_cli *cli, uint16_t addr,
  40. uint8_t test_id, uint16_t cid, uint8_t *faults,
  41. size_t fault_count);
  42. /* Internal parameters for tracking message responses. */
  43. struct bt_mesh_msg_ack_ctx ack_ctx;
  44. };
  45. /** @def BT_MESH_MODEL_HEALTH_CLI
  46. *
  47. * @brief Generic Health Client model composition data entry.
  48. *
  49. * @param cli_data Pointer to a @ref bt_mesh_health_cli instance.
  50. */
  51. #define BT_MESH_MODEL_HEALTH_CLI(cli_data) \
  52. BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_HEALTH_CLI, bt_mesh_health_cli_op, \
  53. NULL, cli_data, &bt_mesh_health_cli_cb)
  54. /** @brief Set Health client model instance to use for communication.
  55. *
  56. * @param model Health Client model instance from the composition data.
  57. *
  58. * @return 0 on success, or (negative) error code on failure.
  59. */
  60. int bt_mesh_health_cli_set(struct bt_mesh_model *model);
  61. /** @brief Get the registered fault state for the given Company ID.
  62. *
  63. * @see bt_mesh_health_faults
  64. *
  65. * @param addr Target node element address.
  66. * @param app_idx Application index to encrypt with.
  67. * @param cid Company ID to get the registered faults of.
  68. * @param test_id Test ID response buffer.
  69. * @param faults Fault array response buffer.
  70. * @param fault_count Fault count response buffer.
  71. *
  72. * @return 0 on success, or (negative) error code on failure.
  73. */
  74. int bt_mesh_health_fault_get(uint16_t addr, uint16_t app_idx, uint16_t cid,
  75. uint8_t *test_id, uint8_t *faults,
  76. size_t *fault_count);
  77. /** @brief Clear the registered faults for the given Company ID.
  78. *
  79. * @see bt_mesh_health_faults
  80. *
  81. * @param addr Target node element address.
  82. * @param app_idx Application index to encrypt with.
  83. * @param cid Company ID to clear the registered faults for.
  84. * @param test_id Test ID response buffer.
  85. * @param faults Fault array response buffer.
  86. * @param fault_count Fault count response buffer.
  87. *
  88. * @return 0 on success, or (negative) error code on failure.
  89. */
  90. int bt_mesh_health_fault_clear(uint16_t addr, uint16_t app_idx, uint16_t cid,
  91. uint8_t *test_id, uint8_t *faults,
  92. size_t *fault_count);
  93. /** @brief Invoke a self-test procedure for the given Company ID.
  94. *
  95. * @param addr Target node element address.
  96. * @param app_idx Application index to encrypt with.
  97. * @param cid Company ID to invoke the test for.
  98. * @param test_id Test ID response buffer.
  99. * @param faults Fault array response buffer.
  100. * @param fault_count Fault count response buffer.
  101. *
  102. * @return 0 on success, or (negative) error code on failure.
  103. */
  104. int bt_mesh_health_fault_test(uint16_t addr, uint16_t app_idx, uint16_t cid,
  105. uint8_t test_id, uint8_t *faults,
  106. size_t *fault_count);
  107. /** @brief Get the target node's Health fast period divisor.
  108. *
  109. * The health period divisor is used to increase the publish rate when a fault
  110. * is registered. Normally, the Health server will publish with the period in
  111. * the configured publish parameters. When a fault is registered, the publish
  112. * period is divided by (1 << divisor). For example, if the target node's
  113. * Health server is configured to publish with a period of 16 seconds, and the
  114. * Health fast period divisor is 5, the Health server will publish with an
  115. * interval of 500 ms when a fault is registered.
  116. *
  117. * @param addr Target node element address.
  118. * @param app_idx Application index to encrypt with.
  119. * @param divisor Health period divisor response buffer.
  120. *
  121. * @return 0 on success, or (negative) error code on failure.
  122. */
  123. int bt_mesh_health_period_get(uint16_t addr, uint16_t app_idx, uint8_t *divisor);
  124. /** @brief Set the target node's Health fast period divisor.
  125. *
  126. * The health period divisor is used to increase the publish rate when a fault
  127. * is registered. Normally, the Health server will publish with the period in
  128. * the configured publish parameters. When a fault is registered, the publish
  129. * period is divided by (1 << divisor). For example, if the target node's
  130. * Health server is configured to publish with a period of 16 seconds, and the
  131. * Health fast period divisor is 5, the Health server will publish with an
  132. * interval of 500 ms when a fault is registered.
  133. *
  134. * @param addr Target node element address.
  135. * @param app_idx Application index to encrypt with.
  136. * @param divisor New Health period divisor.
  137. * @param updated_divisor Health period divisor response buffer.
  138. *
  139. * @return 0 on success, or (negative) error code on failure.
  140. */
  141. int bt_mesh_health_period_set(uint16_t addr, uint16_t app_idx, uint8_t divisor,
  142. uint8_t *updated_divisor);
  143. /** @brief Get the current attention timer value.
  144. *
  145. * @param addr Target node element address.
  146. * @param app_idx Application index to encrypt with.
  147. * @param attention Attention timer response buffer, measured in seconds.
  148. *
  149. * @return 0 on success, or (negative) error code on failure.
  150. */
  151. int bt_mesh_health_attention_get(uint16_t addr, uint16_t app_idx, uint8_t *attention);
  152. /** @brief Set the attention timer.
  153. *
  154. * @param addr Target node element address.
  155. * @param app_idx Application index to encrypt with.
  156. * @param attention New attention timer time, in seconds.
  157. * @param updated_attention Attention timer response buffer, measured in
  158. * seconds.
  159. *
  160. * @return 0 on success, or (negative) error code on failure.
  161. */
  162. int bt_mesh_health_attention_set(uint16_t addr, uint16_t app_idx, uint8_t attention,
  163. uint8_t *updated_attention);
  164. /** @brief Get the current transmission timeout value.
  165. *
  166. * @return The configured transmission timeout in milliseconds.
  167. */
  168. int32_t bt_mesh_health_cli_timeout_get(void);
  169. /** @brief Set the transmission timeout value.
  170. *
  171. * @param timeout The new transmission timeout.
  172. */
  173. void bt_mesh_health_cli_timeout_set(int32_t timeout);
  174. /** @cond INTERNAL_HIDDEN */
  175. extern const struct bt_mesh_model_op bt_mesh_health_cli_op[];
  176. extern const struct bt_mesh_model_cb bt_mesh_health_cli_cb;
  177. /** @endcond */
  178. #ifdef __cplusplus
  179. }
  180. #endif
  181. /**
  182. * @}
  183. */
  184. #endif /* ZEPHYR_INCLUDE_BLUETOOTH_MESH_HEALTH_CLI_H_ */