ble_tps.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /**
  2. * Copyright (c) 2012 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. /** @file
  41. *
  42. * @defgroup ble_tps TX Power Service
  43. * @{
  44. * @ingroup ble_sdk_srv
  45. * @brief TX Power Service module.
  46. *
  47. * @details This module implements the TX Power Service with the TX Power Level characteristic.
  48. * During initialization it adds the TX Power Service and TX Power Level characteristic
  49. * with the specified initial value to the BLE stack database.
  50. *
  51. * It provides a function for letting the application update the TX Power Level
  52. * characteristic.
  53. *
  54. * @note Attention!
  55. * To maintain compliance with Nordic Semiconductor ASA Bluetooth profile
  56. * qualification listings, this section of source code must not be modified.
  57. */
  58. #ifndef BLE_TPS_H__
  59. #define BLE_TPS_H__
  60. #include <stdint.h>
  61. #include "ble.h"
  62. #include "ble_srv_common.h"
  63. #include "nrf_sdh_ble.h"
  64. #ifdef __cplusplus
  65. extern "C" {
  66. #endif
  67. /**@brief Macro for defining a ble_tps instance.
  68. *
  69. * @param _name Name of the instance.
  70. * @hideinitializer
  71. */
  72. #define BLE_TPS_DEF(_name) \
  73. static ble_tps_t _name; \
  74. NRF_SDH_BLE_OBSERVER(_name ## _obs, \
  75. BLE_TPS_BLE_OBSERVER_PRIO, \
  76. ble_tps_on_ble_evt, &_name)
  77. /**@brief TX Power Service init structure. This contains all options and data needed for
  78. * initialization of the service. */
  79. typedef struct
  80. {
  81. int8_t initial_tx_power_level; /**< Initial value of the TX Power Level characteristic (in dBm). */
  82. security_req_t tpl_rd_sec; /**< Security requirement for reading TX Power Level characteristic. */
  83. } ble_tps_init_t;
  84. /**@brief TX Power Service structure. This contains various status information for the service. */
  85. typedef struct
  86. {
  87. uint16_t service_handle; /**< Handle of TX Power Service (as provided by the BLE stack). */
  88. ble_gatts_char_handles_t tx_power_level_handles; /**< Handles related to the TX Power Level characteristic. */
  89. uint16_t conn_handle; /**< Handle of the current connection (as provided by the BLE stack, is BLE_CONN_HANDLE_INVALID if not in a connection). */
  90. } ble_tps_t;
  91. /**@brief Function for initializing the TX Power Service.
  92. *
  93. * @param[out] p_hrs TX Power Service structure. This structure will have to be supplied by
  94. * the application. It will be initialized by this function, and will later
  95. * be used to identify this particular service instance.
  96. * @param[in] p_tps_init Information needed to initialize the service.
  97. *
  98. * @return NRF_SUCCESS on successful initialization of service, otherwise an error code.
  99. */
  100. uint32_t ble_tps_init(ble_tps_t * p_hrs, const ble_tps_init_t * p_tps_init);
  101. /**@brief Function for handling the Application's BLE Stack events.
  102. *
  103. * @details Handles all events from the BLE stack of interest to the TX Power Service.
  104. *
  105. * @param[in] p_ble_evt Event received from the BLE stack.
  106. * @param[in] p_context TX Power Service structure.
  107. */
  108. void ble_tps_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context);
  109. /**@brief Function for setting the value of the TX Power Level characteristic.
  110. *
  111. * @param[in] p_tps TX Power Service structure.
  112. * @param[in] tx_power_level New TX Power Level (unit dBm, range -100 to 20).
  113. *
  114. * @return NRF_SUCCESS on success, otherwise an error code.
  115. */
  116. uint32_t ble_tps_tx_power_level_set(ble_tps_t * p_tps, int8_t tx_power_level);
  117. #ifdef __cplusplus
  118. }
  119. #endif
  120. #endif // BLE_TPS_H__
  121. /** @} */