ble_central.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #ifndef BLE_CENTRAL_H__
  2. #define BLE_CENTRAL_H__
  3. #include <stdint.h>
  4. #include <string.h>
  5. #include "nordic_common.h"
  6. #include "nrf.h"
  7. #include "ble_advdata.h"
  8. #include "ble_advertising.h"
  9. #include "ble_conn_params.h"
  10. #include "nrf_sdh.h"
  11. #include "nrf_sdh_soc.h"
  12. #include "nrf_sdh_ble.h"
  13. #include "nrf_ble_gatt.h"
  14. #include "nrf_ble_qwr.h"
  15. #include "app_timer.h"
  16. #include "app_error.h"
  17. #include "ble.h"
  18. #include "ble_err.h"
  19. #include "ble_hci.h"
  20. #include "ble_srv_common.h"
  21. #include "define.h"
  22. #include "app_button.h"
  23. #include "nrf_pwr_mgmt.h"
  24. #include "nrf_log.h"
  25. #include "nrf_log_ctrl.h"
  26. #include "nrf_log_default_backends.h"
  27. #include "ble_owned_c.h"
  28. #include "ble_conn_state.h"
  29. #include "nrf_ble_scan.h"
  30. #include "ble_db_discovery.h"
  31. #include "ble_config.h"
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. #ifndef BLE_DEVICE_NAME
  36. #define BLE_DEVICE_NAME NRF_BLE_ADV_NAME // 设备名称字符串
  37. #endif
  38. #ifndef APP_BLE_OBSERVER_PRIO
  39. #define APP_BLE_OBSERVER_PRIO 3 //应用程序BLE事件监视者优先级,应用程序不能修改该数值
  40. #endif
  41. #ifndef APP_BLE_CONN_CFG_TAG
  42. #define APP_BLE_CONN_CFG_TAG 1 //SoftDevice BLE配置标志
  43. #endif
  44. typedef void (* ble_central_wr_handler_t)(uint8_t *data,uint16_t len);
  45. typedef bool (* ble_central_scan_adv_handler_t)(const ble_gap_evt_adv_report_t * p_adv_report);
  46. typedef void (* ble_central_scan_timeout_t)(void);
  47. typedef void (* ble_central_scan_connect_t)(bool stat);
  48. typedef void (* ble_central_scan_disconnect_t)(void);
  49. typedef struct
  50. {
  51. ble_central_wr_handler_t wr_evt_handler;
  52. ble_central_scan_adv_handler_t scan_adv_evt_handler;
  53. ble_central_scan_timeout_t scan_timeout_handler;
  54. ble_central_scan_connect_t scan_connect_handler;
  55. ble_central_scan_disconnect_t scan_disconnect_handler;
  56. nrf_ble_scan_filter_type_t filter_type;
  57. void const * p_data;
  58. }ble_central_s;
  59. void on_ble_central_evt(ble_evt_t const * p_ble_evt);
  60. void Ble_Central_Scan_Filter_Init(bool stat);
  61. void Ble_Scan_Start(void);
  62. void Ble_Central_Init(void);
  63. int8_t get_Handle_Idx(uint16_t handle);
  64. uint32_t Ble_Send_ToDev(uint8_t idx,uint8_t *data,uint8_t len);
  65. void Ble_Central_Set_Wr_Evt_Handler(ble_central_wr_handler_t evt_handler);
  66. void Ble_Central_Set_Scan_Adv_Evt_Handler(ble_central_scan_adv_handler_t evt_handler);
  67. void Ble_Central_Set_Scan_Timeout_Evt_Handler(ble_central_scan_timeout_t evt_handler);
  68. void Ble_Central_Set_Scan_Connect_Evt_Handler(ble_central_scan_connect_t evt_handler);
  69. void Ble_Central_Set_Filter_Type(nrf_ble_scan_filter_type_t type,void const * p_data);
  70. void Ble_Central_Disconnect(int idx);
  71. extern int8_t adv_rssi[];
  72. extern uint16_t m_center_handle[];
  73. extern uint8_t m_target_periph_addr[BLE_CENTRAL_LINK_MAXCOUNT][BLE_GAP_ADDR_LEN];
  74. #ifdef __cplusplus
  75. }
  76. #endif
  77. #endif // BLE_CENTRAL_H__
  78. /** @} */