You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.1 KiB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "freertos/FreeRTOS.h"
  5. #include "freertos/task.h"
  6. #include "freertos/event_groups.h"
  7. #include "esp_system.h"
  8. #include "esp_log.h"
  9. #include "nvs_flash.h"
  10. #include "esp_bt.h"
  11. #include "driver/timer.h"
  12. #include "cJSON.h"
  13. #include "cJSON_Utils.h"
  14. #include "esp_gap_ble_api.h"
  15. #include "esp_gatts_api.h"
  16. #include "esp_bt_defs.h"
  17. #include "esp_bt_main.h"
  18. #include "esp_gatt_common_api.h"
  19. #include "sdkconfig.h"
  20. #define GATTS_TAG "GATTS_DEMO"
  21. #define GATTS_SERVICE_UUID_TEST_A 0x00FF
  22. #define GATTS_CHAR_UUID_TEST_A 0xFF01
  23. #define GATTS_DESCR_UUID_TEST_A 0x3333
  24. #define GATTS_NUM_HANDLE_TEST_A 4
  25. #define GATTS_SERVICE_UUID_TEST_B 0x00EE
  26. #define GATTS_CHAR_UUID_TEST_B 0xEE01
  27. #define GATTS_DESCR_UUID_TEST_B 0x2222
  28. #define GATTS_NUM_HANDLE_TEST_B 4
  29. #define TEST_DEVICE_NAME "ESP_GATTS_DEMO"
  30. #define TEST_MANUFACTURER_DATA_LEN 17
  31. #define GATTS_DEMO_CHAR_VAL_LEN_MAX 0x40
  32. #define PREPARE_BUF_MAX_SIZE 1024
  33. #define adv_config_flag (1 << 0)
  34. #define scan_rsp_config_flag (1 << 1)
  35. #define PROFILE_NUM 2
  36. #define PROFILE_A_APP_ID 0
  37. #define PROFILE_B_APP_ID 1
  38. struct gatts_profile_inst
  39. {
  40. esp_gatts_cb_t gatts_cb;
  41. uint16_t gatts_if;
  42. uint16_t app_id;
  43. uint16_t conn_id;
  44. uint16_t service_handle;
  45. esp_gatt_srvc_id_t service_id;
  46. uint16_t char_handle;
  47. esp_bt_uuid_t char_uuid;
  48. esp_gatt_perm_t perm;
  49. esp_gatt_char_prop_t property;
  50. uint16_t descr_handle;
  51. esp_bt_uuid_t descr_uuid;
  52. };
  53. typedef struct
  54. {
  55. uint8_t *prepare_buf;
  56. int prepare_len;
  57. } prepare_type_env_t;
  58. typedef struct ble_gatts_str
  59. {
  60. uint8_t send_gatts_if;
  61. uint16_t send_conn_id;
  62. uint16_t attr_handle;
  63. } ble_gatts_str_t;
  64. void example_write_event_env(esp_gatt_if_t gatts_if, prepare_type_env_t *prepare_write_env, esp_ble_gatts_cb_param_t *param);
  65. void example_exec_write_event_env(prepare_type_env_t *prepare_write_env, esp_ble_gatts_cb_param_t *param);
  66. void esp_ble_gatts_init(ble_gatts_str_t* ble_gatts_a_str);
  67. void gatts_profile_a_constructor(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param);