|
|
@ -6,27 +6,16 @@ |
|
|
|
#include "freertos/task.h" |
|
|
|
#include "nvs_flash.h" |
|
|
|
#include "string.h" |
|
|
|
|
|
|
|
// |
|
|
|
#include "ble_spp_server_demo.h" |
|
|
|
#include "timer_u.h" |
|
|
|
|
|
|
|
#define GATTS_TABLE_TAG "GATTS_SPP_DEMO" |
|
|
|
|
|
|
|
uint16_t table_conn_id_m; |
|
|
|
esp_gatt_if_t table_gatts_if_m; |
|
|
|
uint16_t table_handle_m; |
|
|
|
#define MAIN_TAG "MAIN" |
|
|
|
|
|
|
|
static char bluetooth_tx_buffer[profile_b_buffer_size] = {0}; |
|
|
|
|
|
|
|
char bluetooth_rx_buffer[profile_b_buffer_size] = {0}; |
|
|
|
|
|
|
|
// ble_gatts_str_t ble_gatts_a_str = { |
|
|
|
// .attr_handle = 0, |
|
|
|
// .send_conn_id = 0, |
|
|
|
// .send_gatts_if = 0, |
|
|
|
// }; |
|
|
|
|
|
|
|
void receipt_json_set_position(); |
|
|
|
void receipt_json_get_status(); |
|
|
|
void bluetooth_rx_buffer_format_receipt(); |
|
|
@ -53,27 +42,24 @@ bluetooth_processer_t s_bluetooth_processer = { |
|
|
|
.deviceException = 0, |
|
|
|
.deviceExceptionInfo = "noexception", |
|
|
|
|
|
|
|
.table_conn_id_m = 0, |
|
|
|
.table_gatts_if_m = 0, |
|
|
|
.table_handle_m = 0, |
|
|
|
|
|
|
|
.cmd_flag = false, |
|
|
|
.actively_report_flag = false, |
|
|
|
}; |
|
|
|
|
|
|
|
void app_main(void) { |
|
|
|
constructor_bluetooth_processer(&s_bluetooth_processer); |
|
|
|
// ble_spp_server_demo_app_main(&table_conn_id_m, &table_gatts_if_m, &table_handle_m); |
|
|
|
// table_conn_id_m = |
|
|
|
// char temp_buffer[5] = {'1', '2', '3', '4', '5'}; |
|
|
|
|
|
|
|
// while (true) { |
|
|
|
// if (table_handle_m != 0) { |
|
|
|
// ets_delay_us(1000000); |
|
|
|
// esp_ble_gatts_send_indicate(table_gatts_if_m, table_conn_id_m, table_handle_m, 5, (uint8_t *)temp_buffer, false); |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
bluetooth_rx_buffer_format_receipt(); |
|
|
|
ble_spp_server_demo_app_main(&table_conn_id_m, &table_gatts_if_m, &table_handle_m, &s_bluetooth_processer); |
|
|
|
ble_spp_server_demo_app_main(&s_bluetooth_processer); |
|
|
|
timer_group_init(TIMER_GROUP_0, TIMER_0, false, timer_group0_interval_num, timer_interval_ms); |
|
|
|
while (true) { |
|
|
|
if (s_bluetooth_processer.table_handle_m != 0) { |
|
|
|
bluetooth_rx_buffer_send_indicate(); |
|
|
|
} |
|
|
|
bluetooth_gatts_try_process_data(); |
|
|
|
if (s_bluetooth_processer.actively_report_flag) { |
|
|
|
receipt_json_get_status(); |
|
|
@ -109,19 +95,7 @@ void receipt_json_set_position() { |
|
|
|
char *szJson = cJSON_Print(pRoot); |
|
|
|
|
|
|
|
if (szJson != NULL) { |
|
|
|
ESP_LOGI(GATTS_TABLE_TAG, "%s", szJson); |
|
|
|
|
|
|
|
// esp_gatt_rsp_t rsp; |
|
|
|
// memset(&rsp, 0, sizeof(esp_gatt_rsp_t)); |
|
|
|
// rsp.attr_value.handle = constructor_param->read.handle; |
|
|
|
// rsp.attr_value.len = 4; |
|
|
|
// rsp.attr_value.value[0] = 0x11; |
|
|
|
// rsp.attr_value.value[1] = 0x22; |
|
|
|
// rsp.attr_value.value[2] = 0x33; |
|
|
|
// rsp.attr_value.value[3] = 0x44; |
|
|
|
|
|
|
|
// esp_ble_gatts_send_response(constructor_gatts_if, constructor_param->read.conn_id, |
|
|
|
// constructor_param->read.trans_id, ESP_GATT_OK, &rsp); |
|
|
|
ESP_LOGI(MAIN_TAG, "%s", szJson); |
|
|
|
|
|
|
|
free(szJson); |
|
|
|
} |
|
|
@ -145,7 +119,7 @@ void receipt_json_get_status() { |
|
|
|
char *szJson = cJSON_Print(pRoot); |
|
|
|
|
|
|
|
if (szJson != NULL) { |
|
|
|
ESP_LOGI(GATTS_TABLE_TAG, "%s", szJson); |
|
|
|
ESP_LOGI(MAIN_TAG, "%s", szJson); |
|
|
|
free(szJson); |
|
|
|
} |
|
|
|
|
|
|
@ -153,8 +127,8 @@ void receipt_json_get_status() { |
|
|
|
} |
|
|
|
|
|
|
|
void bluetooth_rx_buffer_format_receipt() { |
|
|
|
sprintf(bluetooth_tx_buffer, "{ \"order\": \"receipt\", \"index\": %d, \"speedLevel\": %d, \"position\": %.2lf, \"direction\": %d }", s_bluetooth_processer.index, s_bluetooth_processer.speedLevel, |
|
|
|
s_bluetooth_processer.position, s_bluetooth_processer.direction); |
|
|
|
sprintf(bluetooth_tx_buffer, "{ \"order\": \"receipt\", \"index\": %d, \"speedLevel\": %d, \"position\": %.2lf, \"direction\": %d }", // |
|
|
|
s_bluetooth_processer.index, s_bluetooth_processer.speedLevel, s_bluetooth_processer.position, s_bluetooth_processer.direction); |
|
|
|
} |
|
|
|
|
|
|
|
void bluetooth_rx_buffer_send_indicate() { |
|
|
@ -175,11 +149,13 @@ void bluetooth_rx_buffer_send_indicate() { |
|
|
|
|
|
|
|
for (i = 0; i < temp_count_total; i++) { |
|
|
|
string_copy_by_num(temp_buffer, bluetooth_tx_buffer, i, 15); |
|
|
|
esp_ble_gatts_send_indicate(table_gatts_if_m, table_conn_id_m, table_handle_m, strlen(temp_buffer), (uint8_t *)temp_buffer, false); |
|
|
|
esp_ble_gatts_send_indicate(s_bluetooth_processer.table_gatts_if_m, s_bluetooth_processer.table_conn_id_m, // |
|
|
|
s_bluetooth_processer.table_handle_m, strlen(temp_buffer), (uint8_t *)temp_buffer, false); |
|
|
|
} |
|
|
|
if (temp_last_count_not_15 == true) { |
|
|
|
string_copy_by_num(temp_buffer, bluetooth_tx_buffer, temp_count_total, temp_count_remainder); |
|
|
|
esp_ble_gatts_send_indicate(table_gatts_if_m, table_conn_id_m, table_handle_m, strlen(temp_buffer), (uint8_t *)temp_buffer, false); |
|
|
|
esp_ble_gatts_send_indicate(s_bluetooth_processer.table_gatts_if_m, s_bluetooth_processer.table_conn_id_m, // |
|
|
|
s_bluetooth_processer.table_handle_m, strlen(temp_buffer), (uint8_t *)temp_buffer, false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -188,7 +164,7 @@ void string_copy_by_num(char *dest, const char *src, uint8_t count, uint8_t num) |
|
|
|
memset(dest, '\0', 15); |
|
|
|
if (dest == NULL || src == NULL || num == 0) { |
|
|
|
/* code */ |
|
|
|
ESP_LOGW(GATTS_TABLE_TAG, "string_copy_by_num function parameter is empty"); |
|
|
|
ESP_LOGW(MAIN_TAG, "string_copy_by_num function parameter is empty"); |
|
|
|
} |
|
|
|
|
|
|
|
for (i = 0; i < num; i++) { |
|
|
|