ble_owned.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef BLE_OWNED_H__
  2. #define BLE_OWNED_H__
  3. #include <stdint.h>
  4. #include <stdbool.h>
  5. #include <stdlib.h>
  6. #include "ble.h"
  7. #include "ble_srv_common.h"
  8. #include "nrf_sdh_ble.h"
  9. #include "ble_config.h"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /**@brief Macro for defining a ble_bis instance.
  14. *
  15. * @param _name Name of the instance.
  16. * @hideinitializer
  17. */
  18. #define BLE_OWNED_DEF(_name) \
  19. static ble_owned_t _name; \
  20. NRF_SDH_BLE_OBSERVER(_name ## _obs, \
  21. BLE_OWNED_BLE_OBSERVER_PRIO, \
  22. ble_evt_handler, &_name)
  23. #ifndef BLE_UUID_OWNED_BASE
  24. #ifdef BLE_UUID_WECHAT_SERVICE
  25. #define BLE_UUID_OWNED_BASE BLE_UUID_WECHAT_SERVICE
  26. #else
  27. #define BLE_UUID_OWNED_BASE 0xFEE7
  28. #endif
  29. #endif
  30. #ifndef BLE_UUID_INDICATE_CHARACTERISTICS
  31. #define BLE_UUID_INDICATE_CHARACTERISTICS 0xFECA
  32. #endif
  33. #ifndef BLE_OWNED_MAX_DATA_LEN
  34. #define BLE_OWNED_MAX_DATA_LEN 64
  35. #endif
  36. // Forward declaration of the ble_owned_t type.
  37. typedef struct ble_owned_s ble_owned_t;
  38. typedef bool (*ble_owned_indicate_handler_t) (ble_owned_t * p_owned, ble_evt_t const * p_ble_evt);
  39. /** @brief Owned business Service init structure. This structure contains all options and data needed for
  40. * initialization of the service.*/
  41. typedef struct
  42. {
  43. ble_owned_indicate_handler_t owned_indicate_handler; /**< Event handler to be called when the owned business Characteristic is indicated. */
  44. } ble_owned_init_t;
  45. /**@brief LED Button Service structure. This structure contains various status information for the service. */
  46. struct ble_owned_s
  47. {
  48. uint16_t service_handle; /**< Handle of Owned business Service (as provided by the BLE stack). */
  49. uint16_t conn_handle;
  50. ble_gatts_char_handles_t owned_indicate_handles; /**< Handles related to the owned business Characteristic. */
  51. ble_owned_indicate_handler_t owned_indicate_handler; /**< Event handler to be called when the owned business Characteristic is indicated. */
  52. };
  53. /**@brief Function for initializing the Owned Business Service.
  54. *
  55. * @param[out] p_owned Owned Business Service structure. This structure must be supplied by
  56. * the application. It is initialized by this function and will later
  57. * be used to identify this particular service instance.
  58. * @param[in] p_owned_init Information needed to initialize the service.
  59. *
  60. * @retval NRF_SUCCESS If the service was initialized successfully. Otherwise, an error code is returned.
  61. */
  62. uint32_t ble_owned_init(ble_owned_t * p_owned, ble_owned_init_t const * p_owned_init);
  63. /**@brief Function for handling the application's BLE stack events.
  64. *
  65. * @details This function handles all events from the BLE stack that are of interest to the Owned Service.
  66. *
  67. * @param[in] p_ble_evt Event received from the BLE stack.
  68. * @param[in] p_context Owned Business Service structure.
  69. */
  70. void ble_owned_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context);
  71. /**@brief Function for sending a owned business notification.
  72. *
  73. * @param[in] p_owned Owned Service structure.
  74. * @param[in] data New Data.
  75. * @param[in] len Data length.
  76. *
  77. * @retval NRF_SUCCESS If the notification was sent successfully. Otherwise, an error code is returned.
  78. */
  79. uint32_t ble_owned_indicate_data_chunk(ble_owned_t * p_owned, uint8_t *data,uint16_t len);
  80. #ifdef __cplusplus
  81. }
  82. #endif
  83. #endif // BLE_OWNED_H__
  84. /** @} */