|
@ -25,6 +25,7 @@ |
|
|
|
|
|
|
|
|
static bleuart_t *s_module; |
|
|
static bleuart_t *s_module; |
|
|
static blerxcb_t s_cb; |
|
|
static blerxcb_t s_cb; |
|
|
|
|
|
static blesetmotorcb_t s_set_motor_cb; |
|
|
static uint16_t table_conn_id_m; |
|
|
static uint16_t table_conn_id_m; |
|
|
static esp_gatt_if_t table_gatts_if_m; |
|
|
static esp_gatt_if_t table_gatts_if_m; |
|
|
static uint16_t table_handle_m; |
|
|
static uint16_t table_handle_m; |
|
@ -171,8 +172,8 @@ static const uint8_t spp_data_notify_val[20] = {0x00}; |
|
|
static const uint8_t spp_data_notify_ccc[2] = {0x00, 0x00}; |
|
|
static const uint8_t spp_data_notify_ccc[2] = {0x00, 0x00}; |
|
|
|
|
|
|
|
|
/// SPP Service - command characteristic, read&write without response |
|
|
/// SPP Service - command characteristic, read&write without response |
|
|
// static const uint16_t spp_command_uuid = ESP_GATT_UUID_SPP_COMMAND_RECEIVE; |
|
|
|
|
|
// static const uint8_t spp_command_val[10] = {0x00}; |
|
|
|
|
|
|
|
|
static const uint16_t spp_command_uuid = ESP_GATT_UUID_SPP_COMMAND_RECEIVE; |
|
|
|
|
|
static const uint8_t spp_command_val[10] = {0x00}; |
|
|
|
|
|
|
|
|
/// SPP Service - status characteristic, notify&read |
|
|
/// SPP Service - status characteristic, notify&read |
|
|
// static const uint16_t spp_status_uuid = ESP_GATT_UUID_SPP_COMMAND_NOTIFY; |
|
|
// static const uint16_t spp_status_uuid = ESP_GATT_UUID_SPP_COMMAND_NOTIFY; |
|
@ -214,13 +215,13 @@ static const esp_gatts_attr_db_t spp_gatt_db[SPP_IDX_NB] = { |
|
|
{ESP_UUID_LEN_128, (uint8_t *)&spp_char_uuid128_tx, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, SPP_DATA_MAX_LEN, sizeof(spp_data_receive_val), |
|
|
{ESP_UUID_LEN_128, (uint8_t *)&spp_char_uuid128_tx, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, SPP_DATA_MAX_LEN, sizeof(spp_data_receive_val), |
|
|
(uint8_t *)spp_data_receive_val}}, |
|
|
(uint8_t *)spp_data_receive_val}}, |
|
|
|
|
|
|
|
|
// // SPP - command characteristic Declaration |
|
|
|
|
|
// [SPP_IDX_SPP_COMMAND_CHAR] = {{ESP_GATT_AUTO_RSP}, |
|
|
|
|
|
// {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ, CHAR_DECLARATION_SIZE, CHAR_DECLARATION_SIZE, (uint8_t *)&char_prop_read_write}}, |
|
|
|
|
|
|
|
|
// SPP - command characteristic Declaration |
|
|
|
|
|
[SPP_IDX_SPP_COMMAND_CHAR] = {{ESP_GATT_AUTO_RSP}, |
|
|
|
|
|
{ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ, CHAR_DECLARATION_SIZE, CHAR_DECLARATION_SIZE, (uint8_t *)&char_prop_read_write}}, |
|
|
|
|
|
|
|
|
// // SPP - command characteristic Value |
|
|
|
|
|
// [SPP_IDX_SPP_COMMAND_VAL] = {{ESP_GATT_AUTO_RSP}, |
|
|
|
|
|
// {ESP_UUID_LEN_16, (uint8_t *)&spp_command_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, SPP_CMD_MAX_LEN, sizeof(spp_command_val), (uint8_t *)spp_command_val}}, |
|
|
|
|
|
|
|
|
// SPP - command characteristic Value |
|
|
|
|
|
[SPP_IDX_SPP_COMMAND_VAL] = {{ESP_GATT_AUTO_RSP}, |
|
|
|
|
|
{ESP_UUID_LEN_16, (uint8_t *)&spp_command_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, SPP_CMD_MAX_LEN, sizeof(spp_command_val), (uint8_t *)spp_command_val}}, |
|
|
|
|
|
|
|
|
// // SPP - status characteristic Declaration |
|
|
// // SPP - status characteristic Declaration |
|
|
// [SPP_IDX_SPP_STATUS_CHAR] = {{ESP_GATT_AUTO_RSP}, |
|
|
// [SPP_IDX_SPP_STATUS_CHAR] = {{ESP_GATT_AUTO_RSP}, |
|
@ -545,6 +546,17 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_ |
|
|
// uart_write_bytes(UART_NUM_0, (char *)(p_data->write.value), p_data->write.len); |
|
|
// uart_write_bytes(UART_NUM_0, (char *)(p_data->write.value), p_data->write.len); |
|
|
blerxprocess(p_data->write.value, p_data->write.len); |
|
|
blerxprocess(p_data->write.value, p_data->write.len); |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
} else if (res == SPP_IDX_SPP_COMMAND_VAL) { |
|
|
|
|
|
ESP_LOGI("Finny", "command:%s", p_data->write.value); |
|
|
|
|
|
if (strcmp((char *)p_data->write.value, "setPosition180") == 0) { |
|
|
|
|
|
ESP_LOGI("Finny", "setPosition180 ok!,command:%s", p_data->write.value); |
|
|
|
|
|
s_set_motor_cb(1, 180, 0); |
|
|
|
|
|
} |
|
|
|
|
|
if (strcmp((char *)p_data->write.value, "setPosition360") == 0) { |
|
|
|
|
|
ESP_LOGI("Finny", "setPosition360 ok!,command:%s", p_data->write.value); |
|
|
|
|
|
s_set_motor_cb(1, 360, 0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
// TODO: |
|
|
// TODO: |
|
|
} |
|
|
} |
|
@ -654,6 +666,7 @@ static void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void bleuart_reg_cb(blerxcb_t cb) { s_cb = cb; } |
|
|
void bleuart_reg_cb(blerxcb_t cb) { s_cb = cb; } |
|
|
|
|
|
void ble_set_motor_reg_cb(blesetmotorcb_t cb) { s_set_motor_cb = cb; } |
|
|
|
|
|
|
|
|
void bleuart_init(bleuart_t *bleuart) { |
|
|
void bleuart_init(bleuart_t *bleuart) { |
|
|
esp_err_t ret; |
|
|
esp_err_t ret; |
|
|