health_srv.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /** @file
  2. * @brief Health Server 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_SRV_H_
  10. #define ZEPHYR_INCLUDE_BLUETOOTH_MESH_HEALTH_SRV_H_
  11. /**
  12. * @brief Health Server Model
  13. * @defgroup bt_mesh_health_srv Health Server Model
  14. * @ingroup bt_mesh
  15. * @{
  16. */
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /** Callback function for the Health Server model */
  21. struct bt_mesh_health_srv_cb {
  22. /** @brief Callback for fetching current faults.
  23. *
  24. * Fault values may either be defined by the specification, or by a
  25. * vendor. Vendor specific faults should be interpreted in the context
  26. * of the accompanying Company ID. Specification defined faults may be
  27. * reported for any Company ID, and the same fault may be presented
  28. * for multiple Company IDs.
  29. *
  30. * All faults shall be associated with at least one Company ID,
  31. * representing the device vendor or some other vendor whose vendor
  32. * specific fault values are used.
  33. *
  34. * If there are multiple Company IDs that have active faults,
  35. * return only the faults associated with one of them at the time.
  36. * To report faults for multiple Company IDs, interleave which Company
  37. * ID is reported for each call.
  38. *
  39. * @param model Health Server model instance to get faults of.
  40. * @param test_id Test ID response buffer.
  41. * @param company_id Company ID response buffer.
  42. * @param faults Array to fill with current faults.
  43. * @param fault_count The number of faults the fault array can fit.
  44. * Should be updated to reflect the number of faults
  45. * copied into the array.
  46. *
  47. * @return 0 on success, or (negative) error code otherwise.
  48. */
  49. int (*fault_get_cur)(struct bt_mesh_model *model, uint8_t *test_id,
  50. uint16_t *company_id, uint8_t *faults,
  51. uint8_t *fault_count);
  52. /** @brief Callback for fetching all registered faults.
  53. *
  54. * Registered faults are all past and current faults since the last
  55. * call to @c fault_clear. Only faults associated with the given
  56. * Company ID should be reported.
  57. *
  58. * Fault values may either be defined by the specification, or by a
  59. * vendor. Vendor specific faults should be interpreted in the context
  60. * of the accompanying Company ID. Specification defined faults may be
  61. * reported for any Company ID, and the same fault may be presented
  62. * for multiple Company IDs.
  63. *
  64. * @param model Health Server model instance to get faults of.
  65. * @param company_id Company ID to get faults for.
  66. * @param test_id Test ID response buffer.
  67. * @param faults Array to fill with registered faults.
  68. * @param fault_count The number of faults the fault array can fit.
  69. * Should be updated to reflect the number of faults
  70. * copied into the array.
  71. *
  72. * @return 0 on success, or (negative) error code otherwise.
  73. */
  74. int (*fault_get_reg)(struct bt_mesh_model *model, uint16_t company_id,
  75. uint8_t *test_id, uint8_t *faults,
  76. uint8_t *fault_count);
  77. /** @brief Clear all registered faults associated with the given Company
  78. * ID.
  79. *
  80. * @param model Health Server model instance to clear faults of.
  81. * @param company_id Company ID to clear faults for.
  82. *
  83. * @return 0 on success, or (negative) error code otherwise.
  84. */
  85. int (*fault_clear)(struct bt_mesh_model *model, uint16_t company_id);
  86. /** @brief Run a self-test.
  87. *
  88. * The Health server may support up to 256 self-tests for each Company
  89. * ID. The behavior for all test IDs are vendor specific, and should be
  90. * interpreted based on the accompanying Company ID. Test failures
  91. * should result in changes to the fault array.
  92. *
  93. * @param model Health Server model instance to run test for.
  94. * @param test_id Test ID to run.
  95. * @param company_id Company ID to run test for.
  96. *
  97. * @return 0 if the test execution was started successfully, or
  98. * (negative) error code otherwise. Note that the fault array will not
  99. * be reported back to the client if the test execution didn't start.
  100. */
  101. int (*fault_test)(struct bt_mesh_model *model, uint8_t test_id,
  102. uint16_t company_id);
  103. /** @brief Start calling attention to the device.
  104. *
  105. * The attention state is used to map an element address to a
  106. * physical device. When this callback is called, the device should
  107. * start some physical procedure meant to call attention to itself,
  108. * like blinking, buzzing, vibrating or moving. If there are multiple
  109. * Health server instances on the device, the attention state should
  110. * also help identify the specific element the server is in.
  111. *
  112. * The attention calling behavior should continue until the @c attn_off
  113. * callback is called.
  114. *
  115. * @param model Health Server model to start the attention state of.
  116. */
  117. void (*attn_on)(struct bt_mesh_model *model);
  118. /** @brief Stop the attention state.
  119. *
  120. * Any physical activity started to call attention to the device should
  121. * be stopped.
  122. *
  123. * @param model
  124. */
  125. void (*attn_off)(struct bt_mesh_model *model);
  126. };
  127. /** @def BT_MESH_HEALTH_PUB_DEFINE
  128. *
  129. * A helper to define a health publication context
  130. *
  131. * @param _name Name given to the publication context variable.
  132. * @param _max_faults Maximum number of faults the element can have.
  133. */
  134. #define BT_MESH_HEALTH_PUB_DEFINE(_name, _max_faults) \
  135. BT_MESH_MODEL_PUB_DEFINE(_name, NULL, (1 + 3 + (_max_faults)))
  136. /** Mesh Health Server Model Context */
  137. struct bt_mesh_health_srv {
  138. /** Composition data model entry pointer. */
  139. struct bt_mesh_model *model;
  140. /** Optional callback struct */
  141. const struct bt_mesh_health_srv_cb *cb;
  142. /** Attention Timer state */
  143. struct k_work_delayable attn_timer;
  144. };
  145. /** @def BT_MESH_MODEL_HEALTH_SRV
  146. *
  147. * Define a new health server model. Note that this API needs to be
  148. * repeated for each element that the application wants to have a
  149. * health server model on. Each instance also needs a unique
  150. * bt_mesh_health_srv and bt_mesh_model_pub context.
  151. *
  152. * @param srv Pointer to a unique struct bt_mesh_health_srv.
  153. * @param pub Pointer to a unique struct bt_mesh_model_pub.
  154. *
  155. * @return New mesh model instance.
  156. */
  157. #define BT_MESH_MODEL_HEALTH_SRV(srv, pub) \
  158. BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_HEALTH_SRV, bt_mesh_health_srv_op, \
  159. pub, srv, &bt_mesh_health_srv_cb)
  160. /** @brief Notify the stack that the fault array state of the given element has
  161. * changed.
  162. *
  163. * This prompts the Health server on this element to publish the current fault
  164. * array if periodic publishing is disabled.
  165. *
  166. * @param elem Element to update the fault state of.
  167. *
  168. * @return 0 on success, or (negative) error code otherwise.
  169. */
  170. int bt_mesh_fault_update(struct bt_mesh_elem *elem);
  171. /** @cond INTERNAL_HIDDEN */
  172. extern const struct bt_mesh_model_op bt_mesh_health_srv_op[];
  173. extern const struct bt_mesh_model_cb bt_mesh_health_srv_cb;
  174. /** @endcond */
  175. #ifdef __cplusplus
  176. }
  177. #endif
  178. /**
  179. * @}
  180. */
  181. #endif /* ZEPHYR_INCLUDE_BLUETOOTH_MESH_HEALTH_SRV_H_ */