ble_comm.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. #include "ringframe.h"
  26. // <<< Use Configuration Wizard in Context Menu >>>\r\n
  27. #define APP_BLE_CONN_CFG_TAG 1
  28. // <q> USE_LADDR - 广播名称是否添加地址后缀
  29. #ifndef USE_LADDR
  30. #define USE_LADDR 1
  31. #endif
  32. // <q> USENAMEFR - 扫描是否采用名字匹配
  33. #ifndef USENAMEFR
  34. #define USENAMEFR 1
  35. #endif
  36. // <q> USEMACNAME - 采用mac地址作为蓝牙名称
  37. #ifndef USEMACNAME
  38. #define USEMACNAME 0
  39. #endif
  40. // <q> USEFIFO - 采用FIFO方式发送
  41. #ifndef USEFIFO
  42. #define USEFIFO 1
  43. #endif
  44. #define TARFET_LEN_MAX NRF_BLE_SCAN_NAME_MAX_LEN
  45. // <q> BLE_PRINTF - 调试信息
  46. #ifndef BLE_PRINTF
  47. #define BLE_PRINTF 1
  48. #endif
  49. #if BLE_PRINTF
  50. #define BLE_PRINT(...) SEGGER_RTT_printf(0, __VA_ARGS__)
  51. #else
  52. #define BLE_PRINT(...) ;
  53. #endif
  54. #define APP_ERR_BASE 0
  55. enum
  56. {
  57. APP_SUCCESS = APP_ERR_BASE,
  58. APP_ERR_DISCONN,
  59. APP_ERR_CONNECTED,
  60. APP_ERR_PARAMERR,
  61. APP_ERR_OVERLENGTH,
  62. APP_ERR_BUSY,
  63. };
  64. void err(int err_num);
  65. typedef void (*Ble_receive_handler_t)(unsigned char *, int);
  66. typedef void (*Ble_evt_cb)(void);
  67. unsigned int send_bytes_server(uint8_t *bytes, uint16_t len);
  68. unsigned int send_bytes_client(unsigned char *bytes, uint16_t len);
  69. void host_init(Ble_receive_handler_t receive_handler);
  70. void slave_init(Ble_receive_handler_t receive_handler);
  71. unsigned char slave_isconnect(void);
  72. unsigned char host_isconnect(void);
  73. unsigned int host_set_scan_name(char *name, int len);
  74. unsigned int slave_set_adv_name(char *name, int len);
  75. void slave_get_advname_len(int *len);
  76. void slave_get_advname(char *name, int len);
  77. int Ble_Host_Connectd_Evt_Regist(Ble_evt_cb cb);
  78. int Ble_Host_Disconn_Evt_Regist(Ble_evt_cb cb);
  79. int Ble_Slave_Connectd_Evt_Regist(Ble_evt_cb cb);
  80. int Ble_Slave_Disconn_Evt_Regist(Ble_evt_cb cb);
  81. unsigned int Ble_update_conn_interval(float min_conn_interval, float max_conn_interval);
  82. unsigned int slave_update_conn_interval_request(float min_conn_interval, float max_conn_interval);
  83. void advertising_stop(void);
  84. void advertising_start(void);
  85. void scan_start(void);
  86. //关掉扫描直接调用 void nrf_ble_scan_stop(void);
  87. uint8_t Slave_Get7_5ms_interval(void);
  88. void slave_disconnect(void);
  89. void host_disconnect(void);
  90. void slave_get_conn_params(ble_gap_conn_params_t *p);
  91. void host_get_conn_params(ble_gap_conn_params_t *p);
  92. void slave_adv_init(void);
  93. signed char slave_get_rssi(void);
  94. signed char host_get_rssi(void);
  95. 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);
  96. void IMU_Rec_data(uint8_t* pdat,uint8_t len);
  97. void IMU_Dtalige(void);
  98. void send_bytes_client_pcs(void);
  99. #endif