kopia lustrzana https://github.com/espressif/esp-idf
component/bt : change gap btc args to union
1. change gap btc args to union to decrease the dram occupied by btc args 2. actually use individual args for every action is the best way(decrease the dram occupy), but for writing code easily and the style, use union 3. gatt server/client should do the same workpull/111/merge
rodzic
db007fbb2e
commit
6cae05d058
|
@ -43,7 +43,7 @@ esp_err_t esp_ble_gap_config_adv_data(esp_ble_adv_data_t *adv_data)
|
|||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = BTC_GAP_BLE_ACT_CFG_ADV_DATA;
|
||||
memcpy(&arg.adv_data, adv_data, sizeof(esp_ble_adv_data_t));
|
||||
memcpy(&arg.cfg_adv_data.adv_data, adv_data, sizeof(esp_ble_adv_data_t));
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), btc_gap_ble_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
|
||||
|
@ -62,7 +62,7 @@ esp_err_t esp_ble_gap_set_scan_params(esp_ble_scan_params_t *scan_params)
|
|||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = BTC_GAP_BLE_ACT_SET_SCAN_PARAM;
|
||||
memcpy(&arg.scan_params, scan_params, sizeof(esp_ble_scan_params_t));
|
||||
memcpy(&arg.set_scan_param.scan_params, scan_params, sizeof(esp_ble_scan_params_t));
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ esp_err_t esp_ble_gap_start_scanning(uint32_t duration)
|
|||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = BTC_GAP_BLE_ACT_START_SCAN;
|
||||
arg.duration = duration;
|
||||
arg.start_scan.duration = duration;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ esp_err_t esp_ble_gap_stop_scanning(void)
|
|||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = BTC_GAP_BLE_ACT_STOP_SCAN;
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gap_start_advertising(esp_ble_adv_params_t *adv_params)
|
||||
|
@ -100,7 +100,7 @@ esp_err_t esp_ble_gap_start_advertising(esp_ble_adv_params_t *adv_params)
|
|||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = BTC_GAP_BLE_ACT_START_ADV;
|
||||
memcpy(&arg.adv_params, adv_params, sizeof(esp_ble_adv_params_t));
|
||||
memcpy(&arg.start_adv.adv_params, adv_params, sizeof(esp_ble_adv_params_t));
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ esp_err_t esp_ble_gap_update_conn_params(esp_ble_conn_update_params_t *params)
|
|||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = BTC_GAP_BLE_ACT_UPDATE_CONN_PARAM;
|
||||
memcpy(&arg.conn_params, params, sizeof(esp_ble_conn_update_params_t));
|
||||
memcpy(&arg.conn_update_params.conn_params, params, sizeof(esp_ble_conn_update_params_t));
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
@ -138,8 +138,8 @@ esp_err_t esp_ble_gap_set_pkt_data_len(esp_bd_addr_t remote_device, uint16_t tx_
|
|||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = BTC_GAP_BLE_ACT_SET_PKT_DATA_LEN;
|
||||
arg.tx_data_length = tx_data_length;
|
||||
memcpy(arg.remote_device, remote_device, ESP_BD_ADDR_LEN);
|
||||
arg.set_pkt_data_len.tx_data_length = tx_data_length;
|
||||
memcpy(arg.set_pkt_data_len.remote_device, remote_device, ESP_BD_ADDR_LEN);
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ esp_err_t esp_ble_gap_set_rand_addr(esp_bd_addr_t rand_addr)
|
|||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = BTC_GAP_BLE_ACT_SET_RAND_ADDRESS;
|
||||
memcpy(arg.rand_addr, rand_addr, ESP_BD_ADDR_LEN);
|
||||
memcpy(arg.set_rand_addr.rand_addr, rand_addr, ESP_BD_ADDR_LEN);
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ esp_err_t esp_ble_gap_config_local_privacy (bool privacy_enable)
|
|||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY;
|
||||
arg.privacy_enable = privacy_enable;
|
||||
arg.cfg_local_privacy.privacy_enable = privacy_enable;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ esp_err_t esp_ble_gap_set_device_name(char *name)
|
|||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = BTC_GAP_BLE_ACT_SET_DEV_NAME;
|
||||
strcpy(arg.device_name, name);
|
||||
strcpy(arg.set_dev_name.device_name, name);
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
|
|
@ -616,20 +616,20 @@ void btc_gap_ble_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
|
|||
btc_ble_gap_args_t *src = (btc_ble_gap_args_t *)p_src;
|
||||
btc_ble_gap_args_t *dst = (btc_ble_gap_args_t*) p_dest;
|
||||
|
||||
if (src->adv_data.p_manufacturer_data) {
|
||||
dst->adv_data.p_manufacturer_data = GKI_getbuf(src->adv_data.manufacturer_len);
|
||||
memcpy(dst->adv_data.p_manufacturer_data, src->adv_data.p_manufacturer_data,
|
||||
src->adv_data.manufacturer_len);
|
||||
if (src->cfg_adv_data.adv_data.p_manufacturer_data) {
|
||||
dst->cfg_adv_data.adv_data.p_manufacturer_data = GKI_getbuf(src->cfg_adv_data.adv_data.manufacturer_len);
|
||||
memcpy(dst->cfg_adv_data.adv_data.p_manufacturer_data, src->cfg_adv_data.adv_data.p_manufacturer_data,
|
||||
src->cfg_adv_data.adv_data.manufacturer_len);
|
||||
}
|
||||
|
||||
if (src->adv_data.p_service_data) {
|
||||
dst->adv_data.p_service_data = GKI_getbuf(src->adv_data.service_data_len);
|
||||
memcpy(dst->adv_data.p_service_data, src->adv_data.p_service_data, src->adv_data.service_data_len);
|
||||
if (src->cfg_adv_data.adv_data.p_service_data) {
|
||||
dst->cfg_adv_data.adv_data.p_service_data = GKI_getbuf(src->cfg_adv_data.adv_data.service_data_len);
|
||||
memcpy(dst->cfg_adv_data.adv_data.p_service_data, src->cfg_adv_data.adv_data.p_service_data, src->cfg_adv_data.adv_data.service_data_len);
|
||||
}
|
||||
|
||||
if (src->adv_data.p_service_uuid) {
|
||||
dst->adv_data.p_service_uuid = GKI_getbuf(src->adv_data.service_uuid_len);
|
||||
memcpy(dst->adv_data.p_service_uuid, src->adv_data.p_service_uuid, src->adv_data.service_uuid_len);
|
||||
if (src->cfg_adv_data.adv_data.p_service_uuid) {
|
||||
dst->cfg_adv_data.adv_data.p_service_uuid = GKI_getbuf(src->cfg_adv_data.adv_data.service_uuid_len);
|
||||
memcpy(dst->cfg_adv_data.adv_data.p_service_uuid, src->cfg_adv_data.adv_data.p_service_uuid, src->cfg_adv_data.adv_data.service_uuid_len);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -644,7 +644,7 @@ static void btc_gap_ble_arg_deep_free(btc_msg_t *msg)
|
|||
LOG_DEBUG("%s \n", __func__);
|
||||
switch (msg->act) {
|
||||
case BTC_GAP_BLE_ACT_CFG_ADV_DATA: {
|
||||
esp_ble_adv_data_t *adv = &((btc_ble_gap_args_t *)msg->arg)->adv_data;
|
||||
esp_ble_adv_data_t *adv = &((btc_ble_gap_args_t *)msg->arg)->cfg_adv_data.adv_data;
|
||||
if (adv->p_service_data)
|
||||
GKI_freebuf(adv->p_service_data);
|
||||
|
||||
|
@ -670,43 +670,46 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
|
|||
switch (msg->act) {
|
||||
case BTC_GAP_BLE_ACT_CFG_ADV_DATA:
|
||||
{
|
||||
if(arg->adv_data.set_scan_rsp == false){
|
||||
btc_ble_set_adv_data(&arg->adv_data, btc_adv_data_callback);
|
||||
if(arg->cfg_adv_data.adv_data.set_scan_rsp == false){
|
||||
btc_ble_set_adv_data(&arg->cfg_adv_data.adv_data, btc_adv_data_callback);
|
||||
}else{
|
||||
btc_ble_set_adv_data(&arg->adv_data, btc_scan_rsp_data_callback);
|
||||
btc_ble_set_adv_data(&arg->cfg_adv_data.adv_data, btc_scan_rsp_data_callback);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_GAP_BLE_ACT_SET_SCAN_PARAM:
|
||||
btc_ble_set_scan_param(&arg->scan_params, btc_set_scan_param_callback);
|
||||
btc_ble_set_scan_param(&arg->set_scan_param.scan_params, btc_set_scan_param_callback);
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_START_SCAN:
|
||||
btc_ble_start_scanning(arg->duration, btc_search_callback);
|
||||
btc_ble_start_scanning(arg->start_scan.duration, btc_search_callback);
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_STOP_SCAN:
|
||||
btc_ble_stop_scanning();
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_START_ADV:
|
||||
btc_ble_start_advertising(&arg->adv_params);
|
||||
btc_ble_start_advertising(&arg->start_adv.adv_params);
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_STOP_ADV:
|
||||
btc_ble_stop_advertising();
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_UPDATE_CONN_PARAM:
|
||||
btc_ble_update_conn_params(arg->conn_params.bda, arg->conn_params.min_int,
|
||||
arg->conn_params.max_int, arg->conn_params.latency, arg->conn_params.timeout);
|
||||
btc_ble_update_conn_params(arg->conn_update_params.conn_params.bda,
|
||||
arg->conn_update_params.conn_params.min_int,
|
||||
arg->conn_update_params.conn_params.max_int,
|
||||
arg->conn_update_params.conn_params.latency,
|
||||
arg->conn_update_params.conn_params.timeout);
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_SET_PKT_DATA_LEN:
|
||||
btc_ble_set_pkt_data_len(arg->remote_device, arg->tx_data_length);
|
||||
btc_ble_set_pkt_data_len(arg->set_pkt_data_len.remote_device, arg->set_pkt_data_len.tx_data_length);
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_SET_RAND_ADDRESS:
|
||||
btc_ble_set_rand_addr(arg->rand_addr);
|
||||
btc_ble_set_rand_addr(arg->set_rand_addr.rand_addr);
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY:
|
||||
btc_ble_config_local_privacy(arg->privacy_enable);
|
||||
btc_ble_config_local_privacy(arg->cfg_local_privacy.privacy_enable);
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_SET_DEV_NAME:
|
||||
BTA_DmSetDeviceName(arg->device_name);
|
||||
BTA_DmSetDeviceName(arg->set_dev_name.device_name);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -19,18 +19,47 @@ typedef enum {
|
|||
} btc_gap_ble_act_t;
|
||||
|
||||
/* btc_ble_gap_args_t */
|
||||
typedef struct {
|
||||
esp_ble_adv_data_t adv_data;
|
||||
esp_ble_adv_params_t adv_params;
|
||||
esp_ble_scan_params_t scan_params;
|
||||
esp_ble_conn_update_params_t conn_params;
|
||||
esp_bd_addr_t remote_device;
|
||||
esp_bd_addr_t rand_addr;
|
||||
uint32_t duration;
|
||||
uint16_t tx_data_length;
|
||||
bool privacy_enable;
|
||||
typedef union {
|
||||
//BTC_GAP_BLE_ACT_CFG_ADV_DATA = 0,
|
||||
struct config_adv_data_args {
|
||||
esp_ble_adv_data_t adv_data;
|
||||
} cfg_adv_data;
|
||||
//BTC_GAP_BLE_ACT_SET_SCAN_PARAM,
|
||||
struct set_scan_params_args {
|
||||
esp_ble_scan_params_t scan_params;
|
||||
} set_scan_param;
|
||||
//BTC_GAP_BLE_ACT_START_SCAN,
|
||||
struct start_scan_args {
|
||||
uint32_t duration;
|
||||
} start_scan;
|
||||
//BTC_GAP_BLE_ACT_STOP_SCAN, no args
|
||||
//BTC_GAP_BLE_ACT_START_ADV,
|
||||
struct start_adv_args {
|
||||
esp_ble_adv_params_t adv_params;
|
||||
} start_adv;
|
||||
//BTC_GAP_BLE_ACT_STOP_ADV, no args
|
||||
//BTC_GAP_BLE_ACT_UPDATE_CONN_PARAM,
|
||||
struct conn_update_params_args {
|
||||
esp_ble_conn_update_params_t conn_params;
|
||||
} conn_update_params;
|
||||
//BTC_GAP_BLE_ACT_SET_PKT_DATA_LEN
|
||||
struct set_pkt_data_len_args {
|
||||
esp_bd_addr_t remote_device;
|
||||
uint16_t tx_data_length;
|
||||
} set_pkt_data_len;
|
||||
//BTC_GAP_BLE_ACT_SET_RAND_ADDRESS,
|
||||
struct set_rand_addr_args {
|
||||
esp_bd_addr_t rand_addr;
|
||||
} set_rand_addr;
|
||||
//BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY,
|
||||
struct cfg_local_privacy_args {
|
||||
bool privacy_enable;
|
||||
} cfg_local_privacy;
|
||||
//BTC_GAP_BLE_ACT_SET_DEV_NAME,
|
||||
struct set_dev_name_args {
|
||||
#define ESP_GAP_DEVICE_NAME_MAX (32)
|
||||
char device_name[ESP_GAP_DEVICE_NAME_MAX+1];
|
||||
char device_name[ESP_GAP_DEVICE_NAME_MAX+1];
|
||||
} set_dev_name;
|
||||
} btc_ble_gap_args_t;
|
||||
|
||||
void btc_gap_ble_call_handler(btc_msg_t *msg);
|
||||
|
|
Ładowanie…
Reference in New Issue