component/bt : move blufi to new architecture btc task

1. move blufi to new architecture
2. delete some log trace
This commit is contained in:
Tian Hao
2016-11-16 22:11:59 +08:00
parent 9691fe9dae
commit aafaebefb4
14 changed files with 414 additions and 277 deletions

View File

@@ -26,65 +26,42 @@
#include <stdbool.h>
#include <stdio.h>
#include "bta_api.h"
#include "bta_gatt_api.h"
#include "controller.h"
#include "gatt_int.h"
#include "bt_trace.h"
#include "btm_api.h"
#include "bt_types.h"
#include "blufi_prf.h"
#include "blufi.h"
#include "blufi_adv.h"
#include "esp_bt_defs.h"
#include "esp_bt_main.h"
#include "esp_blufi_api.h"
static void BlufiDataCallBack(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *p_data);
struct dm_evt {
tBTA_DM_SEC_EVT event;
tBTA_DM_SEC* p_data;
};
extern void wifi_set_blue_config(char *ssid, char *passwd);
#define HEADER_SSID "ssid"
#define HEADER_PASSWD "passwd"
#define HEADER_CONFIRM "confirm"
extern void wifi_set_blue_config(char *ssid, char *passwd);
static char tmp_ssid[33];
static char tmp_passwd[33];
static void BlufiDataCallBack(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *p_data)
static char tmp_ssid[32 + 1];
static char tmp_passwd[64 + 1];
static void blufi_data_recv(uint8_t *data, int len)
{
char *p = NULL;
LOG_DEBUG("the data is:%s\n", p_data);
#if 0
switch(event)
{
case RECEIVE_NET_PASSWD_EVT:
LOG_ERROR("Received the network passwork");
break;
case RECEIVE_NET_SSD_EVT:
LOG_ERROR("Received the network SSID");
break;
default:
break;
}
#endif
p = strstr(p_data, HEADER_SSID);
LOG_DEBUG("the data is:%s\n", data);
p = strstr(data, HEADER_SSID);
if (p) {
LOG_ERROR("SSID: %s\n", p+strlen(HEADER_SSID)+1);
strcpy(tmp_ssid, p+strlen(HEADER_SSID)+1);
}
p = strstr(p_data, HEADER_PASSWD);
p = strstr(data, HEADER_PASSWD);
if (p) {
LOG_ERROR("PASSWORD: %s\n", p+strlen(HEADER_PASSWD)+1);
strcpy(tmp_passwd, p+strlen(HEADER_PASSWD)+1);
}
p = strstr(p_data, HEADER_CONFIRM);
p = strstr(data, HEADER_CONFIRM);
if (p) {
LOG_ERROR("CONFIRM\n");
wifi_set_blue_config(tmp_ssid, tmp_passwd);
@@ -92,32 +69,42 @@ static void BlufiDataCallBack(UINT8 app_id, UINT8 event, UINT8 len, UINT8 *p_dat
}
static esp_err_t blufi_dm_upstreams_evt(void *arg)
static void blufi_callback(uint32_t event, void *param)
{
/* actually, should post to blufi_task handle the procedure,
* now, as a demo, we do simplely */
switch (event) {
case ESP_BLUFI_EVENT_INIT_FINISH:
LOG_ERROR("blufi init finish\n");
break;
case ESP_BLUFI_EVENT_RECV_DATA: {
LOG_DEBUG("blufi recv data\n");
esp_blufi_cb_param_t *blufi_param = (esp_blufi_cb_param_t *)param;
blufi_data_recv(blufi_param->recv_data.data, blufi_param->recv_data.data_len);
break;
}
default:
break;
}
}
static esp_err_t blufi_startup_in_blufi_task(void *arg)
{
/*set connectable,discoverable, pairable and paired only modes of local device*/
tBTA_DM_DISC disc_mode = BTA_DM_BLE_GENERAL_DISCOVERABLE;
tBTA_DM_CONN conn_mode = BTA_DM_BLE_CONNECTABLE;
BTA_DmSetVisibility(disc_mode, conn_mode, (uint8_t)BTA_DM_NON_PAIRABLE, (uint8_t)BTA_DM_CONN_ALL );
BTA_DmSetVisibility(disc_mode, conn_mode, (uint8_t)BTA_DM_NON_PAIRABLE, (uint8_t)BTA_DM_CONN_ALL);
#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
/* Enable local privacy */
//BTA_DmBleConfigLocalPrivacy(BLE_LOCAL_PRIVACY_ENABLED);
do {
const controller_t *controller = controller_get_interface();
char bdstr[18];
bdaddr_to_string(controller->get_address(), bdstr, sizeof(bdstr));
LOG_DEBUG("BDA is: %s\n", bdstr);
} while (0);
#endif
blufi_profile_init(BlufiDataCallBack);
esp_blufi_register_callback(blufi_callback);
esp_blufi_profile_init();
return ESP_OK;
}
void blufi_bte_dm_evt(void)
static void blufi_startup(void)
{
blufi_transfer_context(blufi_dm_upstreams_evt, NULL);
blufi_transfer_context(blufi_startup_in_blufi_task, NULL);
}
esp_err_t blufi_enable(void *arg)
@@ -131,7 +118,7 @@ esp_err_t blufi_enable(void *arg)
LOG_ERROR("%s failed\n", __func__);
return err;
}
blufi_bte_dm_evt();
blufi_startup();
vTaskDelay(1000 / portTICK_PERIOD_MS);
return err;

View File

@@ -93,8 +93,8 @@ static void blufi_task_deinit(void)
static void blufi_task_init(void)
{
xBlufiTaskQueue = xQueueCreate(10, sizeof(BtTaskEvt_t));
xTaskCreate(blufi_task, "BlUFI", 8192, NULL, configMAX_PRIORITIES - 3, xBlufiTaskHandle);
xBlufiTaskQueue = xQueueCreate(5, sizeof(BtTaskEvt_t));
xTaskCreate(blufi_task, "BlUFI", 4096, NULL, configMAX_PRIORITIES - 3, xBlufiTaskHandle);
}
void blufi_init(void) {

View File

@@ -26,6 +26,7 @@
#include "bt.h"
#include "bta_api.h"
#include "esp_blufi_api.h"
#include "esp_bt_defs.h"
#include "esp_bt_main.h"
#include "blufi.h"
@@ -42,7 +43,6 @@ const int CONNECTED_BIT = BIT0;
static wifi_scan_config_t scan_config;
static wifi_config_t sta_config;
static char tmp_ssid[33];
@@ -59,8 +59,6 @@ void wifi_set_blue_config(char *ssid, char *passwd)
LOG_DEBUG("confirm true\n");
}
extern void blufi_config_failed(void);
extern void blufi_config_success(void);
static esp_err_t event_handler(void *ctx, system_event_t *event)
{
switch(event->event_id) {
@@ -69,7 +67,7 @@ static esp_err_t event_handler(void *ctx, system_event_t *event)
break;
case SYSTEM_EVENT_STA_GOT_IP:
xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
blufi_config_success();
esp_blufi_send_config_state(ESP_BLUFI_CONFIG_OK);
esp_disable_bluetooth(); //close bluetooth function
//esp_deinit_bluetooth(); //free bluetooth resource
break;
@@ -98,7 +96,6 @@ static void initialise_wifi(void)
}
static int loop = 0;
void wifiTestTask(void *pvParameters)
{
esp_err_t ret;
@@ -119,7 +116,7 @@ void wifiTestTask(void *pvParameters)
ret = esp_wifi_connect();
if (ret != ESP_OK) {
LOG_ERROR("esp_wifi connect failed\n");
blufi_config_failed();
esp_blufi_send_config_state(ESP_BLUFI_CONFIG_FAILED);
}
}
}