heartbeat.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /** @file
  2. * @brief Heartbeat APIs.
  3. */
  4. /*
  5. * Copyright (c) 2020 Nordic Semiconductor ASA
  6. *
  7. * SPDX-License-Identifier: Apache-2.0
  8. */
  9. #ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_HEARTBEAT_H_
  10. #define ZEPHYR_INCLUDE_BLUETOOTH_MESH_HEARTBEAT_H_
  11. #include <sys/slist.h>
  12. /**
  13. * @brief Heartbeat
  14. * @defgroup bt_mesh_heartbeat Heartbeat
  15. * @ingroup bt_mesh
  16. * @{
  17. */
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /** Heartbeat Publication parameters */
  22. struct bt_mesh_hb_pub {
  23. /** Destination address. */
  24. uint16_t dst;
  25. /** Remaining publish count. */
  26. uint16_t count;
  27. /** Time To Live value. */
  28. uint8_t ttl;
  29. /**
  30. * Bitmap of features that trigger a Heartbeat publication if
  31. * they change. Legal values are @ref BT_MESH_FEAT_RELAY,
  32. * @ref BT_MESH_FEAT_PROXY, @ref BT_MESH_FEAT_FRIEND and
  33. * @ref BT_MESH_FEAT_LOW_POWER.
  34. */
  35. uint16_t feat;
  36. /** Network index used for publishing. */
  37. uint16_t net_idx;
  38. /** Publication period in seconds. */
  39. uint32_t period;
  40. };
  41. /** Heartbeat Subscription parameters. */
  42. struct bt_mesh_hb_sub {
  43. /** Subscription period in seconds. */
  44. uint32_t period;
  45. /** Remaining subscription time in seconds. */
  46. uint32_t remaining;
  47. /** Source address to receive Heartbeats from. */
  48. uint16_t src;
  49. /** Destination address to received Heartbeats on. */
  50. uint16_t dst;
  51. /** The number of received Heartbeat messages so far. */
  52. uint16_t count;
  53. /**
  54. * Minimum hops in received messages, ie the shortest registered
  55. * path from the publishing node to the subscribing node. A
  56. * Heartbeat received from an immediate neighbor has hop
  57. * count = 1.
  58. */
  59. uint8_t min_hops;
  60. /**
  61. * Maximum hops in received messages, ie the longest registered
  62. * path from the publishing node to the subscribing node. A
  63. * Heartbeat received from an immediate neighbor has hop
  64. * count = 1.
  65. */
  66. uint8_t max_hops;
  67. };
  68. /** Heartbeat callback structure */
  69. struct bt_mesh_hb_cb {
  70. /** @brief Receive callback for heartbeats.
  71. *
  72. * Gets called on every received Heartbeat that matches the current
  73. * Heartbeat subscription parameters.
  74. *
  75. * @param sub Current Heartbeat subscription parameters.
  76. * @param hops The number of hops the Heartbeat was received
  77. * with.
  78. * @param feat The feature set of the publishing node. The
  79. * value is a bitmap of @ref BT_MESH_FEAT_RELAY,
  80. * @ref BT_MESH_FEAT_PROXY,
  81. * @ref BT_MESH_FEAT_FRIEND and
  82. * @ref BT_MESH_FEAT_LOW_POWER.
  83. */
  84. void (*recv)(const struct bt_mesh_hb_sub *sub, uint8_t hops,
  85. uint16_t feat);
  86. /** @brief Subscription end callback for heartbeats.
  87. *
  88. * Gets called when the subscription period ends, providing a summary
  89. * of the received heartbeat messages.
  90. *
  91. * @param sub Current Heartbeat subscription parameters.
  92. */
  93. void (*sub_end)(const struct bt_mesh_hb_sub *sub);
  94. };
  95. /** @def BT_MESH_HB_CB_DEFINE
  96. *
  97. * @brief Register a callback structure for Heartbeat events.
  98. *
  99. * Registers a callback structure that will be called whenever Heartbeat
  100. * events occur
  101. *
  102. * @param _name Name of callback structure.
  103. */
  104. #define BT_MESH_HB_CB_DEFINE(_name) \
  105. static const STRUCT_SECTION_ITERABLE(bt_mesh_hb_cb, _name)
  106. /** @brief Get the current Heartbeat publication parameters.
  107. *
  108. * @param get Heartbeat publication parameters return buffer.
  109. */
  110. void bt_mesh_hb_pub_get(struct bt_mesh_hb_pub *get);
  111. /** @brief Get the current Heartbeat subscription parameters.
  112. *
  113. * @param get Heartbeat subscription parameters return buffer.
  114. */
  115. void bt_mesh_hb_sub_get(struct bt_mesh_hb_sub *get);
  116. #ifdef __cplusplus
  117. }
  118. #endif
  119. /**
  120. * @}
  121. */
  122. #endif /* ZEPHYR_INCLUDE_BLUETOOTH_MESH_HEARTBEAT_H_ */