ble_comm.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #ifndef __BLE_COMM__
  2. #define __BLE_COMM__
  3. #include "sdk_common.h"
  4. #include "ble_db_discovery.h"
  5. #include "sdk_errors.h"
  6. #include "app_error.h"
  7. #include "app_util.h"
  8. #include "bsp_btn_ble.h"
  9. #include "ble.h"
  10. #include "ble_gap.h"
  11. #include "ble_hci.h"
  12. #include "nrf_sdh.h"
  13. #include "nrf_sdh_ble.h"
  14. #include "nrf_sdh_soc.h"
  15. #include "ble_nus_c.h"
  16. #include "nrf_ble_gatt.h"
  17. #include "nrf_pwr_mgmt.h"
  18. #include "nrf_ble_scan.h"
  19. #include "app_timer.h"
  20. #include "ble_conn_state.h"
  21. #include "SEGGER_RTT.h"
  22. #include "nrf_delay.h"
  23. #include "main.h"
  24. #include "queue.h"
  25. // <<< Use Configuration Wizard in Context Menu >>>\r\n
  26. #define APP_BLE_CONN_CFG_TAG 1
  27. // <q> USE_LADDR - 广播名称是否添加地址后缀
  28. #ifndef USE_LADDR
  29. #define USE_LADDR 1
  30. #endif
  31. // <q> USENAMEFR - 扫描是否采用名字匹配
  32. #ifndef USENAMEFR
  33. #define USENAMEFR 1
  34. #endif
  35. // <q> USEMACNAME - 采用mac地址作为蓝牙名称
  36. #ifndef USEMACNAME
  37. #define USEMACNAME 1
  38. #endif
  39. #define TARFET_LEN_MAX NRF_BLE_SCAN_NAME_MAX_LEN
  40. // <q> BLE_PRINTF - 调试信息
  41. #ifndef BLE_PRINTF
  42. #define BLE_PRINTF 0
  43. #endif
  44. #if BLE_PRINTF
  45. #define BLE_PRINT(...) SEGGER_RTT_printf(0, __VA_ARGS__)
  46. #else
  47. #define BLE_PRINT(...) ;
  48. #endif
  49. #define APP_ERR_BASE 0
  50. enum
  51. {
  52. APP_SUCCESS = APP_ERR_BASE,
  53. APP_ERR_DISCONN,
  54. APP_ERR_CONNECTED,
  55. APP_ERR_PARAMERR,
  56. APP_ERR_OVERLENGTH,
  57. APP_ERR_BUSY,
  58. };
  59. void err(int err_num);
  60. typedef void (*Ble_receive_handler_t)(unsigned char *, int);
  61. typedef void (*Ble_evt_cb)(void);
  62. unsigned int send_bytes_server(uint8_t *bytes, uint16_t len);
  63. unsigned int send_bytes_client(unsigned char *bytes, uint16_t len);
  64. void host_init(Ble_receive_handler_t receive_handler);
  65. void slave_init(Ble_receive_handler_t receive_handler);
  66. unsigned char slave_isconnect(void);
  67. unsigned char host_isconnect(void);
  68. unsigned int host_set_scan_name(char *name, int len);
  69. unsigned int slave_set_adv_name(char *name, int len);
  70. void slave_get_advname_len(int *len);
  71. void slave_get_advname(char *name, int len);
  72. int Ble_Host_Connectd_Evt_Regist(Ble_evt_cb cb);
  73. int Ble_Host_Disconn_Evt_Regist(Ble_evt_cb cb);
  74. int Ble_Slave_Connectd_Evt_Regist(Ble_evt_cb cb);
  75. int Ble_Slave_Disconn_Evt_Regist(Ble_evt_cb cb);
  76. unsigned int Ble_update_conn_interval(float min_conn_interval, float max_conn_interval);
  77. unsigned int slave_update_conn_interval_request(float min_conn_interval, float max_conn_interval);
  78. void advertising_stop(void);
  79. void advertising_start(void);
  80. void scan_start(void);
  81. //关掉扫描直接调用 void nrf_ble_scan_stop(void);
  82. uint8_t Slave_Get7_5ms_interval(void);
  83. void slave_disconnect(void);
  84. void host_disconnect(void);
  85. void slave_get_conn_params(ble_gap_conn_params_t *p);
  86. void host_get_conn_params(ble_gap_conn_params_t *p);
  87. void slave_adv_init(void);
  88. signed char slave_get_rssi(void);
  89. signed char host_get_rssi(void);
  90. void IMU_Process_motion_queue(uint8_t IS_HOST, int32_t time_stamp, int16_t* _acc,int16_t* _gry, int16_t* front_mag, int16_t* back_mag, uint8_t _rssi);
  91. void IMU_Rec_data(uint8_t* pdat,uint8_t len);
  92. void IMU_Dtalige(void);
  93. #endif