初始提交
This commit is contained in:
22
application/samples/bt/sle/CMakeLists.txt
Executable file
22
application/samples/bt/sle/CMakeLists.txt
Executable file
@ -0,0 +1,22 @@
|
||||
#===============================================================================
|
||||
# @brief cmake file
|
||||
# Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
|
||||
#===============================================================================
|
||||
if(DEFINED CONFIG_SAMPLE_SUPPORT_SLE_UUID_SERVER_SAMPLE)
|
||||
add_subdirectory_if_exist(sle_uuid_server)
|
||||
endif()
|
||||
|
||||
if(DEFINED CONFIG_SAMPLE_SUPPORT_SLE_UUID_CLIENT_SAMPLE)
|
||||
add_subdirectory_if_exist(sle_uuid_client)
|
||||
endif()
|
||||
|
||||
if(DEFINED CONFIG_SAMPLE_SUPPORT_SLE_SPEED_SERVER_SAMPLE)
|
||||
add_subdirectory_if_exist(sle_speed_server)
|
||||
endif()
|
||||
|
||||
if(DEFINED CONFIG_SAMPLE_SUPPORT_SLE_SPEED_CLIENT_SAMPLE)
|
||||
add_subdirectory_if_exist(sle_speed_client)
|
||||
endif()
|
||||
|
||||
set(SOURCES "${SOURCES}" PARENT_SCOPE)
|
||||
set(PUBLIC_HEADER "${PUBLIC_HEADER}" PARENT_SCOPE)
|
31
application/samples/bt/sle/Kconfig
Executable file
31
application/samples/bt/sle/Kconfig
Executable file
@ -0,0 +1,31 @@
|
||||
#===============================================================================
|
||||
# @brief Kconfig file.
|
||||
# Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
|
||||
#===============================================================================
|
||||
|
||||
choice
|
||||
prompt "SLE Sample"
|
||||
|
||||
config SAMPLE_SUPPORT_SLE_UUID_SERVER_SAMPLE
|
||||
bool "Support SLE UUID Server Sample."
|
||||
|
||||
config SAMPLE_SUPPORT_SLE_UUID_CLIENT_SAMPLE
|
||||
bool "Support SLE UUID Client Sample."
|
||||
|
||||
config SAMPLE_SUPPORT_SLE_SPEED_SERVER_SAMPLE
|
||||
bool "Support SLE Throughput Server Sample."
|
||||
|
||||
config LARGE_THROUGHPUT_SERVER
|
||||
bool "server large throughput."
|
||||
default y
|
||||
depends on SAMPLE_SUPPORT_SLE_SPEED_SERVER_SAMPLE
|
||||
|
||||
config SAMPLE_SUPPORT_SLE_SPEED_CLIENT_SAMPLE
|
||||
bool "Support SLE Throughput Client Sample."
|
||||
|
||||
config LARGE_THROUGHPUT_CLIENT
|
||||
bool "client large throughput."
|
||||
default y
|
||||
depends on SAMPLE_SUPPORT_SLE_SPEED_CLIENT_SAMPLE
|
||||
|
||||
endchoice
|
8
application/samples/bt/sle/sle_speed_client/CMakeLists.txt
Executable file
8
application/samples/bt/sle/sle_speed_client/CMakeLists.txt
Executable file
@ -0,0 +1,8 @@
|
||||
#===============================================================================
|
||||
# @brief cmake file
|
||||
# Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
|
||||
#===============================================================================
|
||||
add_subdirectory_if_exist(src)
|
||||
|
||||
set(SOURCES "${SOURCES}" PARENT_SCOPE)
|
||||
set(PUBLIC_HEADER "${PUBLIC_HEADER}" "${CMAKE_CURRENT_SOURCE_DIR}/inc" PARENT_SCOPE)
|
54
application/samples/bt/sle/sle_speed_client/inc/sle_speed_client.h
Executable file
54
application/samples/bt/sle/sle_speed_client/inc/sle_speed_client.h
Executable file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2022. All rights reserved.
|
||||
*
|
||||
* Description: SLE private service register sample of client.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup SLE UUID CLIENT API
|
||||
* @ingroup
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef SLE_CLIENT_ADV_H
|
||||
#define SLE_CLIENT_ADV_H
|
||||
|
||||
/**
|
||||
* @if Eng
|
||||
* @brief sle uuid client init.
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS Excute successfully
|
||||
* @retval ERRCODE_SLE_FAIL Execute fail
|
||||
* @par Dependency:
|
||||
* @li NULL
|
||||
* @else
|
||||
* @brief sle uuid客户端初始化。
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS 执行成功
|
||||
* @retval ERRCODE_SLE_FAIL 执行失败
|
||||
* @par 依赖:
|
||||
* @li NULL
|
||||
* @endif
|
||||
*/
|
||||
void sle_client_init(ssapc_notification_callback notification_cb, ssapc_indication_callback indication_cb);
|
||||
|
||||
/**
|
||||
* @if Eng
|
||||
* @brief sle start scan.
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS Excute successfully
|
||||
* @retval ERRCODE_SLE_FAIL Execute fail
|
||||
* @par Dependency:
|
||||
* @li NULL
|
||||
* @else
|
||||
* @brief sle启动扫描。
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS 执行成功
|
||||
* @retval ERRCODE_SLE_FAIL 执行失败
|
||||
* @par 依赖:
|
||||
* @li NULL
|
||||
* @endif
|
||||
*/
|
||||
void sle_start_scan(void);
|
||||
|
||||
#endif
|
7
application/samples/bt/sle/sle_speed_client/src/CMakeLists.txt
Executable file
7
application/samples/bt/sle/sle_speed_client/src/CMakeLists.txt
Executable file
@ -0,0 +1,7 @@
|
||||
#===============================================================================
|
||||
# @brief cmake file
|
||||
# Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
|
||||
#===============================================================================
|
||||
set(SOURCES "${SOURCES}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/sle_speed_client.c"
|
||||
PARENT_SCOPE)
|
376
application/samples/bt/sle/sle_speed_client/src/sle_speed_client.c
Executable file
376
application/samples/bt/sle/sle_speed_client/src/sle_speed_client.c
Executable file
@ -0,0 +1,376 @@
|
||||
/**
|
||||
* Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2022. All rights reserved.
|
||||
*
|
||||
* Description: SLE private service register sample of client.
|
||||
*/
|
||||
#include "app_init.h"
|
||||
#include "systick.h"
|
||||
#include "tcxo.h"
|
||||
#include "los_memory.h"
|
||||
#include "securec.h"
|
||||
#include "soc_osal.h"
|
||||
#include "common_def.h"
|
||||
|
||||
#include "sle_device_discovery.h"
|
||||
#include "sle_connection_manager.h"
|
||||
#include "sle_ssap_client.h"
|
||||
|
||||
#include "sle_speed_client.h"
|
||||
|
||||
#undef THIS_FILE_ID
|
||||
#define THIS_FILE_ID BTH_GLE_SAMPLE_UUID_CLIENT
|
||||
|
||||
#define SLE_MTU_SIZE_DEFAULT 1500
|
||||
#define SLE_SEEK_INTERVAL_DEFAULT 100
|
||||
#define SLE_SEEK_WINDOW_DEFAULT 100
|
||||
#define UUID_16BIT_LEN 2
|
||||
#define UUID_128BIT_LEN 16
|
||||
#define SLE_SPEED_HUNDRED 100 /* 100 */
|
||||
#define SPEED_DEFAULT_CONN_INTERVAL 0x14
|
||||
#define SPEED_DEFAULT_TIMEOUT_MULTIPLIER 0x1f4
|
||||
#define SPEED_DEFAULT_SCAN_INTERVAL 400
|
||||
#define SPEED_DEFAULT_SCAN_WINDOW 20
|
||||
|
||||
static int g_recv_pkt_num = 0;
|
||||
static uint64_t g_count_before_get_us;
|
||||
static uint64_t g_count_after_get_us;
|
||||
|
||||
#ifdef CONFIG_LARGE_THROUGHPUT_CLIENT
|
||||
#define RECV_PKT_CNT 1000
|
||||
#else
|
||||
#define RECV_PKT_CNT 1
|
||||
#endif
|
||||
static int g_rssi_sum = 0;
|
||||
static int g_rssi_number = 0;
|
||||
|
||||
static sle_announce_seek_callbacks_t g_seek_cbk = {0};
|
||||
static sle_connection_callbacks_t g_connect_cbk = {0};
|
||||
static ssapc_callbacks_t g_ssapc_cbk = {0};
|
||||
static sle_addr_t g_remote_addr = {0};
|
||||
static uint16_t g_conn_id = 0;
|
||||
static ssapc_find_service_result_t g_find_service_result = {0};
|
||||
|
||||
void sle_sample_sle_enable_cbk(errcode_t status)
|
||||
{
|
||||
if (status == 0) {
|
||||
sle_start_scan();
|
||||
}
|
||||
}
|
||||
|
||||
void sle_sample_seek_enable_cbk(errcode_t status)
|
||||
{
|
||||
if (status == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void sle_sample_seek_disable_cbk(errcode_t status)
|
||||
{
|
||||
if (status == 0) {
|
||||
sle_connect_remote_device(&g_remote_addr);
|
||||
}
|
||||
}
|
||||
|
||||
void sle_sample_seek_result_info_cbk(sle_seek_result_info_t *seek_result_data)
|
||||
{
|
||||
if (seek_result_data != NULL) {
|
||||
uint8_t mac[SLE_ADDR_LEN] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
|
||||
if (memcmp(seek_result_data->addr.addr, mac, SLE_ADDR_LEN) == 0) {
|
||||
(void)memcpy_s(&g_remote_addr, sizeof(sle_addr_t), &seek_result_data->addr, sizeof(sle_addr_t));
|
||||
sle_stop_seek();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t get_float_int(float in)
|
||||
{
|
||||
return (uint32_t)(((uint64_t)(in * SLE_SPEED_HUNDRED)) / SLE_SPEED_HUNDRED);
|
||||
}
|
||||
|
||||
static uint32_t get_float_dec(float in)
|
||||
{
|
||||
return (uint32_t)(((uint64_t)(in * SLE_SPEED_HUNDRED)) % SLE_SPEED_HUNDRED);
|
||||
}
|
||||
|
||||
static void sle_speed_notification_cb(uint8_t client_id, uint16_t conn_id, ssapc_handle_value_t *data,
|
||||
errcode_t status)
|
||||
{
|
||||
unused(client_id);
|
||||
unused(status);
|
||||
sle_read_remote_device_rssi(conn_id); // 用于统计rssi均值
|
||||
|
||||
if (g_recv_pkt_num == 0) {
|
||||
g_count_before_get_us = uapi_tcxo_get_us();
|
||||
} else if (g_recv_pkt_num == RECV_PKT_CNT) {
|
||||
g_count_after_get_us = uapi_tcxo_get_us();
|
||||
printf("g_count_after_get_us = %llu, g_count_before_get_us = %llu, data_len = %d\r\n",
|
||||
g_count_after_get_us, g_count_before_get_us, data->data_len);
|
||||
float time = (float)(g_count_after_get_us - g_count_before_get_us) / 1000000.0; /* 1s = 1000000.0us */
|
||||
printf("time = %d.%d s\r\n", get_float_int(time), get_float_dec(time));
|
||||
uint16_t len = data->data_len;
|
||||
float speed = len * RECV_PKT_CNT * 8 / time; /* 1B = 8bits */
|
||||
printf("speed = %d.%d bps\r\n", get_float_int(speed), get_float_dec(speed));
|
||||
g_recv_pkt_num = 0;
|
||||
g_count_before_get_us = g_count_after_get_us;
|
||||
}
|
||||
g_recv_pkt_num++;
|
||||
}
|
||||
|
||||
static void sle_speed_indication_cb(uint8_t client_id, uint16_t conn_id, ssapc_handle_value_t *data,
|
||||
errcode_t status)
|
||||
{
|
||||
unused(status);
|
||||
unused(conn_id);
|
||||
unused(client_id);
|
||||
osal_printk("\n sle_speed_indication_cb sle uart recived data : %s\r\n", data->data);
|
||||
}
|
||||
|
||||
void sle_sample_seek_cbk_register(void)
|
||||
{
|
||||
g_seek_cbk.sle_enable_cb = sle_sample_sle_enable_cbk;
|
||||
g_seek_cbk.seek_enable_cb = sle_sample_seek_enable_cbk;
|
||||
g_seek_cbk.seek_disable_cb = sle_sample_seek_disable_cbk;
|
||||
g_seek_cbk.seek_result_cb = sle_sample_seek_result_info_cbk;
|
||||
}
|
||||
|
||||
void sle_sample_connect_state_changed_cbk(uint16_t conn_id, const sle_addr_t *addr,
|
||||
sle_acb_state_t conn_state, sle_pair_state_t pair_state, sle_disc_reason_t disc_reason)
|
||||
{
|
||||
osal_printk("[ssap client] conn state changed conn_id:%d, addr:%02x***%02x%02x\n", conn_id, addr->addr[0],
|
||||
addr->addr[4], addr->addr[5]); /* 0 4 5: addr index */
|
||||
osal_printk("[ssap client] conn state changed disc_reason:0x%x\n", disc_reason);
|
||||
if (conn_state == SLE_ACB_STATE_CONNECTED) {
|
||||
if (pair_state == SLE_PAIR_NONE) {
|
||||
sle_pair_remote_device(&g_remote_addr);
|
||||
}
|
||||
g_conn_id = conn_id;
|
||||
}
|
||||
}
|
||||
|
||||
void sle_sample_pair_complete_cbk(uint16_t conn_id, const sle_addr_t *addr, errcode_t status)
|
||||
{
|
||||
osal_printk("[ssap client] pair complete conn_id:%d, addr:%02x***%02x%02x\n", conn_id, addr->addr[0],
|
||||
addr->addr[4], addr->addr[5]); /* 0 4 5: addr index */
|
||||
if (status == 0) {
|
||||
ssap_exchange_info_t info = {0};
|
||||
info.mtu_size = SLE_MTU_SIZE_DEFAULT;
|
||||
info.version = 1;
|
||||
ssapc_exchange_info_req(1, g_conn_id, &info);
|
||||
}
|
||||
}
|
||||
|
||||
void sle_sample_update_cbk(uint16_t conn_id, errcode_t status, const sle_connection_param_update_evt_t *param)
|
||||
{
|
||||
unused(status);
|
||||
osal_printk("[ssap client] updat state changed conn_id:%d, interval = %02x\n", conn_id, param->interval);
|
||||
}
|
||||
|
||||
void sle_sample_update_req_cbk(uint16_t conn_id, errcode_t status, const sle_connection_param_update_req_t *param)
|
||||
{
|
||||
unused(conn_id);
|
||||
unused(status);
|
||||
osal_printk("[ssap client] sle_sample_update_req_cbk interval_min = %02x, interval_max = %02x\n",
|
||||
param->interval_min, param->interval_max);
|
||||
}
|
||||
|
||||
void sle_sample_read_rssi_cbk(uint16_t conn_id, int8_t rssi, errcode_t status)
|
||||
{
|
||||
unused(conn_id);
|
||||
unused(status);
|
||||
g_rssi_sum = g_rssi_sum + rssi;
|
||||
g_rssi_number++;
|
||||
if (g_rssi_number == RECV_PKT_CNT) {
|
||||
osal_printk("rssi average = %d dbm\r\n", g_rssi_sum / g_rssi_number);
|
||||
g_rssi_sum = 0;
|
||||
g_rssi_number = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void sle_sample_connect_cbk_register(void)
|
||||
{
|
||||
g_connect_cbk.connect_state_changed_cb = sle_sample_connect_state_changed_cbk;
|
||||
g_connect_cbk.pair_complete_cb = sle_sample_pair_complete_cbk;
|
||||
g_connect_cbk.connect_param_update_req_cb = sle_sample_update_req_cbk;
|
||||
g_connect_cbk.connect_param_update_cb = sle_sample_update_cbk;
|
||||
g_connect_cbk.read_rssi_cb = sle_sample_read_rssi_cbk;
|
||||
}
|
||||
|
||||
void sle_sample_exchange_info_cbk(uint8_t client_id, uint16_t conn_id, ssap_exchange_info_t *param,
|
||||
errcode_t status)
|
||||
{
|
||||
osal_printk("[ssap client] pair complete client id:%d status:%d\n", client_id, status);
|
||||
osal_printk("[ssap client] exchange mtu, mtu size: %d, version: %d.\n",
|
||||
param->mtu_size, param->version);
|
||||
|
||||
ssapc_find_structure_param_t find_param = {0};
|
||||
find_param.type = SSAP_FIND_TYPE_PRIMARY_SERVICE;
|
||||
find_param.start_hdl = 1;
|
||||
find_param.end_hdl = 0xFFFF;
|
||||
ssapc_find_structure(0, conn_id, &find_param);
|
||||
}
|
||||
|
||||
void sle_sample_find_structure_cbk(uint8_t client_id, uint16_t conn_id, ssapc_find_service_result_t *service,
|
||||
errcode_t status)
|
||||
{
|
||||
osal_printk("[ssap client] find structure cbk client: %d conn_id:%d status: %d \n",
|
||||
client_id, conn_id, status);
|
||||
osal_printk("[ssap client] find structure start_hdl:[0x%02x], end_hdl:[0x%02x], uuid len:%d\r\n",
|
||||
service->start_hdl, service->end_hdl, service->uuid.len);
|
||||
if (service->uuid.len == UUID_16BIT_LEN) {
|
||||
osal_printk("[ssap client] structure uuid:[0x%02x][0x%02x]\r\n",
|
||||
service->uuid.uuid[14], service->uuid.uuid[15]); /* 14 15: uuid index */
|
||||
} else {
|
||||
for (uint8_t idx = 0; idx < UUID_128BIT_LEN; idx++) {
|
||||
osal_printk("[ssap client] structure uuid[%d]:[0x%02x]\r\n", idx, service->uuid.uuid[idx]);
|
||||
}
|
||||
}
|
||||
g_find_service_result.start_hdl = service->start_hdl;
|
||||
g_find_service_result.end_hdl = service->end_hdl;
|
||||
memcpy_s(&g_find_service_result.uuid, sizeof(sle_uuid_t), &service->uuid, sizeof(sle_uuid_t));
|
||||
}
|
||||
|
||||
void sle_sample_find_structure_cmp_cbk(uint8_t client_id, uint16_t conn_id,
|
||||
ssapc_find_structure_result_t *structure_result, errcode_t status)
|
||||
{
|
||||
osal_printk("[ssap client] find structure cmp cbk client id:%d status:%d type:%d uuid len:%d \r\n",
|
||||
client_id, status, structure_result->type, structure_result->uuid.len);
|
||||
if (structure_result->uuid.len == UUID_16BIT_LEN) {
|
||||
osal_printk("[ssap client] find structure cmp cbk structure uuid:[0x%02x][0x%02x]\r\n",
|
||||
structure_result->uuid.uuid[14], structure_result->uuid.uuid[15]); /* 14 15: uuid index */
|
||||
} else {
|
||||
for (uint8_t idx = 0; idx < UUID_128BIT_LEN; idx++) {
|
||||
osal_printk("[ssap client] find structure cmp cbk structure uuid[%d]:[0x%02x]\r\n", idx,
|
||||
structure_result->uuid.uuid[idx]);
|
||||
}
|
||||
}
|
||||
uint8_t data[] = {0x11, 0x22, 0x33, 0x44};
|
||||
uint8_t len = sizeof(data);
|
||||
ssapc_write_param_t param = {0};
|
||||
param.handle = g_find_service_result.start_hdl;
|
||||
param.type = SSAP_PROPERTY_TYPE_VALUE;
|
||||
param.data_len = len;
|
||||
param.data = data;
|
||||
ssapc_write_req(0, conn_id, ¶m);
|
||||
}
|
||||
|
||||
void sle_sample_find_property_cbk(uint8_t client_id, uint16_t conn_id,
|
||||
ssapc_find_property_result_t *property, errcode_t status)
|
||||
{
|
||||
osal_printk("[ssap client] find property cbk, client id: %d, conn id: %d, operate ind: %d, "
|
||||
"descriptors count: %d status:%d.\n", client_id, conn_id, property->operate_indication,
|
||||
property->descriptors_count, status);
|
||||
for (uint16_t idx = 0; idx < property->descriptors_count; idx++) {
|
||||
osal_printk("[ssap client] find property cbk, descriptors type [%d]: 0x%02x.\n",
|
||||
idx, property->descriptors_type[idx]);
|
||||
}
|
||||
if (property->uuid.len == UUID_16BIT_LEN) {
|
||||
osal_printk("[ssap client] find property cbk, uuid: %02x %02x.\n",
|
||||
property->uuid.uuid[14], property->uuid.uuid[15]); /* 14 15: uuid index */
|
||||
} else if (property->uuid.len == UUID_128BIT_LEN) {
|
||||
for (uint16_t idx = 0; idx < UUID_128BIT_LEN; idx++) {
|
||||
osal_printk("[ssap client] find property cbk, uuid [%d]: %02x.\n",
|
||||
idx, property->uuid.uuid[idx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sle_sample_write_cfm_cbk(uint8_t client_id, uint16_t conn_id, ssapc_write_result_t *write_result,
|
||||
errcode_t status)
|
||||
{
|
||||
osal_printk("[ssap client] write cfm cbk, client id: %d status:%d.\n", client_id, status);
|
||||
ssapc_read_req(0, conn_id, write_result->handle, write_result->type);
|
||||
}
|
||||
|
||||
void sle_sample_read_cfm_cbk(uint8_t client_id, uint16_t conn_id, ssapc_handle_value_t *read_data,
|
||||
errcode_t status)
|
||||
{
|
||||
osal_printk("[ssap client] read cfm cbk client id: %d conn id: %d status: %d\n",
|
||||
client_id, conn_id, status);
|
||||
osal_printk("[ssap client] read cfm cbk handle: %d, type: %d , len: %d\n",
|
||||
read_data->handle, read_data->type, read_data->data_len);
|
||||
for (uint16_t idx = 0; idx < read_data->data_len; idx++) {
|
||||
osal_printk("[ssap client] read cfm cbk[%d] 0x%02x\r\n", idx, read_data->data[idx]);
|
||||
}
|
||||
}
|
||||
|
||||
void sle_sample_ssapc_cbk_register(ssapc_notification_callback notification_cb,
|
||||
ssapc_notification_callback indication_cb)
|
||||
{
|
||||
g_ssapc_cbk.exchange_info_cb = sle_sample_exchange_info_cbk;
|
||||
g_ssapc_cbk.find_structure_cb = sle_sample_find_structure_cbk;
|
||||
g_ssapc_cbk.find_structure_cmp_cb = sle_sample_find_structure_cmp_cbk;
|
||||
g_ssapc_cbk.ssapc_find_property_cbk = sle_sample_find_property_cbk;
|
||||
g_ssapc_cbk.write_cfm_cb = sle_sample_write_cfm_cbk;
|
||||
g_ssapc_cbk.read_cfm_cb = sle_sample_read_cfm_cbk;
|
||||
g_ssapc_cbk.notification_cb = notification_cb;
|
||||
g_ssapc_cbk.indication_cb = indication_cb;
|
||||
}
|
||||
|
||||
void sle_speed_connect_param_init(void)
|
||||
{
|
||||
sle_default_connect_param_t param = {0};
|
||||
param.enable_filter_policy = 0;
|
||||
param.gt_negotiate = 0;
|
||||
param.initiate_phys = 1;
|
||||
param.max_interval = SPEED_DEFAULT_CONN_INTERVAL;
|
||||
param.min_interval = SPEED_DEFAULT_CONN_INTERVAL;
|
||||
param.scan_interval = SPEED_DEFAULT_SCAN_INTERVAL;
|
||||
param.scan_window = SPEED_DEFAULT_SCAN_WINDOW;
|
||||
param.timeout = SPEED_DEFAULT_TIMEOUT_MULTIPLIER;
|
||||
sle_default_connection_param_set(¶m);
|
||||
}
|
||||
|
||||
void sle_client_init(ssapc_notification_callback notification_cb, ssapc_indication_callback indication_cb)
|
||||
{
|
||||
uint8_t local_addr[SLE_ADDR_LEN] = {0x13, 0x67, 0x5c, 0x07, 0x00, 0x51};
|
||||
sle_addr_t local_address;
|
||||
local_address.type = 0;
|
||||
(void)memcpy_s(local_address.addr, SLE_ADDR_LEN, local_addr, SLE_ADDR_LEN);
|
||||
sle_sample_seek_cbk_register();
|
||||
sle_speed_connect_param_init();
|
||||
sle_sample_connect_cbk_register();
|
||||
sle_sample_ssapc_cbk_register(notification_cb, indication_cb);
|
||||
sle_announce_seek_register_callbacks(&g_seek_cbk);
|
||||
sle_connection_register_callbacks(&g_connect_cbk);
|
||||
ssapc_register_callbacks(&g_ssapc_cbk);
|
||||
enable_sle();
|
||||
sle_set_local_addr(&local_address);
|
||||
}
|
||||
|
||||
void sle_start_scan()
|
||||
{
|
||||
sle_seek_param_t param = {0};
|
||||
param.own_addr_type = 0;
|
||||
param.filter_duplicates = 0;
|
||||
param.seek_filter_policy = 0;
|
||||
param.seek_phys = 1;
|
||||
param.seek_type[0] = 0;
|
||||
param.seek_interval[0] = SLE_SEEK_INTERVAL_DEFAULT;
|
||||
param.seek_window[0] = SLE_SEEK_WINDOW_DEFAULT;
|
||||
sle_set_seek_param(¶m);
|
||||
sle_start_seek();
|
||||
}
|
||||
|
||||
int sle_speed_init(void)
|
||||
{
|
||||
osal_msleep(1000); /* sleep 1000ms */
|
||||
sle_client_init(sle_speed_notification_cb, sle_speed_indication_cb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define SLE_SPEED_TASK_PRIO 26
|
||||
#define SLE_SPEED_STACK_SIZE 0x2000
|
||||
static void sle_speed_entry(void)
|
||||
{
|
||||
osal_task *task_handle = NULL;
|
||||
osal_kthread_lock();
|
||||
task_handle = osal_kthread_create((osal_kthread_handler)sle_speed_init, 0, "RadarTask", SLE_SPEED_STACK_SIZE);
|
||||
if (task_handle != NULL) {
|
||||
osal_kthread_set_priority(task_handle, SLE_SPEED_TASK_PRIO);
|
||||
osal_kfree(task_handle);
|
||||
}
|
||||
osal_kthread_unlock();
|
||||
}
|
||||
|
||||
/* Run the blinky_entry. */
|
||||
app_run(sle_speed_entry);
|
8
application/samples/bt/sle/sle_speed_server/CMakeLists.txt
Executable file
8
application/samples/bt/sle/sle_speed_server/CMakeLists.txt
Executable file
@ -0,0 +1,8 @@
|
||||
#===============================================================================
|
||||
# @brief cmake file
|
||||
# Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
|
||||
#===============================================================================
|
||||
add_subdirectory_if_exist(src)
|
||||
|
||||
set(SOURCES "${SOURCES}" PARENT_SCOPE)
|
||||
set(PUBLIC_HEADER "${PUBLIC_HEADER}" "${CMAKE_CURRENT_SOURCE_DIR}/inc" PARENT_SCOPE)
|
89
application/samples/bt/sle/sle_speed_server/inc/sle_speed_server.h
Executable file
89
application/samples/bt/sle/sle_speed_server/inc/sle_speed_server.h
Executable file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2022. All rights reserved.
|
||||
*
|
||||
* Description: SLE UUID Server module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup SLE UUID SERVER API
|
||||
* @ingroup
|
||||
* @{
|
||||
*/
|
||||
#ifndef SLE_UUID_SERVER_H
|
||||
#define SLE_UUID_SERVER_H
|
||||
|
||||
#include "sle_ssap_server.h"
|
||||
|
||||
/* Service UUID */
|
||||
#define SLE_UUID_SERVER_SERVICE 0xABCD
|
||||
|
||||
/* Property UUID */
|
||||
#define SLE_UUID_SERVER_NTF_REPORT 0x1122
|
||||
|
||||
/* Property Property */
|
||||
#define SLE_UUID_TEST_PROPERTIES (SSAP_PERMISSION_READ | SSAP_PERMISSION_WRITE)
|
||||
|
||||
/* Descriptor Property */
|
||||
#define SLE_UUID_TEST_DESCRIPTOR (SSAP_PERMISSION_READ | SSAP_PERMISSION_WRITE)
|
||||
|
||||
/**
|
||||
* @if Eng
|
||||
* @brief SLE uuid server inir.
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS Excute successfully
|
||||
* @retval ERRCODE_SLE_FAIL Execute fail
|
||||
* @par Dependency:
|
||||
* @li sle_ssap_server.h
|
||||
* @else
|
||||
* @brief SLE UUID服务器初始化。
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS 执行成功
|
||||
* @retval ERRCODE_SLE_FAIL 执行失败
|
||||
* @par 依赖:
|
||||
* @li sle_ssap_server.h
|
||||
* @endif
|
||||
*/
|
||||
errcode_t sle_uuid_server_init(void);
|
||||
|
||||
/**
|
||||
* @if Eng
|
||||
* @brief send data to peer device by uuid on uuid server.
|
||||
* @attention NULL
|
||||
* @param [in] value send value.
|
||||
* @param [in] len Length of send value。
|
||||
* @retval ERRCODE_SLE_SUCCESS Excute successfully
|
||||
* @retval ERRCODE_SLE_FAIL Execute fail
|
||||
* @par Dependency:
|
||||
* @li sle_ssap_server.h
|
||||
* @else
|
||||
* @brief 通过uuid server 发送数据给对端。
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS 执行成功
|
||||
* @retval ERRCODE_SLE_FAIL 执行失败
|
||||
* @par 依赖:
|
||||
* @li sle_ssap_server.h
|
||||
* @endif
|
||||
*/
|
||||
errcode_t sle_uuid_server_send_report_by_uuid(uint8_t *data, uint16_t len);
|
||||
|
||||
/**
|
||||
* @if Eng
|
||||
* @brief send data to peer device by handle on uuid server.
|
||||
* @attention NULL
|
||||
* @param [in] value send value.
|
||||
* @param [in] len Length of send value。
|
||||
* @retval ERRCODE_SLE_SUCCESS Excute successfully
|
||||
* @retval ERRCODE_SLE_FAIL Execute fail
|
||||
* @par Dependency:
|
||||
* @li sle_ssap_server.h
|
||||
* @else
|
||||
* @brief 通过uuid server 发送数据给对端。
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS 执行成功
|
||||
* @retval ERRCODE_SLE_FAIL 执行失败
|
||||
* @par 依赖:
|
||||
* @li sle_ssap_server.h
|
||||
* @endif
|
||||
*/
|
||||
errcode_t sle_uuid_server_send_report_by_handle(const uint8_t *data, uint8_t len);
|
||||
#endif
|
91
application/samples/bt/sle/sle_speed_server/inc/sle_speed_server_adv.h
Executable file
91
application/samples/bt/sle/sle_speed_server/inc/sle_speed_server_adv.h
Executable file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023. All rights reserved.
|
||||
*
|
||||
* Description: SLE ADV Config.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup bluetooth_sle_adv API
|
||||
* @ingroup
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef SLE_SERVER_ADV_H
|
||||
#define SLE_SERVER_ADV_H
|
||||
|
||||
/* 广播ID */
|
||||
#define SLE_ADV_HANDLE_DEFAULT 1
|
||||
|
||||
/**
|
||||
* @if Eng
|
||||
* @brief Definitaion of BLE ADV 通用广播结构.
|
||||
* @else
|
||||
* @brief SLE 广播普通数据结构。
|
||||
* @endif
|
||||
*/
|
||||
struct sle_adv_common_value {
|
||||
uint8_t length;
|
||||
uint8_t type;
|
||||
uint8_t value;
|
||||
};
|
||||
|
||||
/**
|
||||
* @if Eng
|
||||
* @brief Definitaion of BLE ADV Channel mapping.
|
||||
* @else
|
||||
* @brief SLE 广播信道映射。
|
||||
* @endif
|
||||
*/
|
||||
typedef enum {
|
||||
SLE_ADV_CHANNEL_MAP_77 = 0x01,
|
||||
SLE_ADV_CHANNEL_MAP_78 = 0x02,
|
||||
SLE_ADV_CHANNEL_MAP_79 = 0x04,
|
||||
SLE_ADV_CHANNEL_MAP_DEFAULT = 0x07
|
||||
} sle_adv_channel_map;
|
||||
|
||||
/**
|
||||
* @if Eng
|
||||
* @brief Definitaion of SLE ADV Data Type.
|
||||
* @else
|
||||
* @brief SLE 广播数据类型
|
||||
* @endif
|
||||
*/
|
||||
typedef enum {
|
||||
SLE_ADV_DATA_TYPE_DISCOVERY_LEVEL = 0x01, /*!< 发现等级 */
|
||||
SLE_ADV_DATA_TYPE_ACCESS_MODE = 0x02, /*!< 接入层能力 */
|
||||
SLE_ADV_DATA_TYPE_SERVICE_DATA_16BIT_UUID = 0x03, /*!< 标准服务数据信息 */
|
||||
SLE_ADV_DATA_TYPE_SERVICE_DATA_128BIT_UUID = 0x04, /*!< 自定义服务数据信息 */
|
||||
SLE_ADV_DATA_TYPE_COMPLETE_LIST_OF_16BIT_SERVICE_UUIDS = 0x05, /*!< 完整标准服务标识列表 */
|
||||
SLE_ADV_DATA_TYPE_COMPLETE_LIST_OF_128BIT_SERVICE_UUIDS = 0x06, /*!< 完整自定义服务标识列表 */
|
||||
SLE_ADV_DATA_TYPE_INCOMPLETE_LIST_OF_16BIT_SERVICE_UUIDS = 0x07, /*!< 部分标准服务标识列表 */
|
||||
SLE_ADV_DATA_TYPE_INCOMPLETE_LIST_OF_128BIT_SERVICE_UUIDS = 0x08, /*!< 部分自定义服务标识列表 */
|
||||
SLE_ADV_DATA_TYPE_SERVICE_STRUCTURE_HASH_VALUE = 0x09, /*!< 服务结构散列值 */
|
||||
SLE_ADV_DATA_TYPE_SHORTENED_LOCAL_NAME = 0x0A, /*!< 设备缩写本地名称 */
|
||||
SLE_ADV_DATA_TYPE_COMPLETE_LOCAL_NAME = 0x0B, /*!< 设备完整本地名称 */
|
||||
SLE_ADV_DATA_TYPE_TX_POWER_LEVEL = 0x0C, /*!< 广播发送功率 */
|
||||
SLE_ADV_DATA_TYPE_SLB_COMMUNICATION_DOMAIN = 0x0D, /*!< SLB通信域域名 */
|
||||
SLE_ADV_DATA_TYPE_SLB_MEDIA_ACCESS_LAYER_ID = 0x0E, /*!< SLB媒体接入层标识 */
|
||||
SLE_ADV_DATA_TYPE_EXTENDED = 0xFE, /*!< 数据类型扩展 */
|
||||
SLE_ADV_DATA_TYPE_MANUFACTURER_SPECIFIC_DATA = 0xFF /*!< 厂商自定义信息 */
|
||||
} sle_adv_data_type;
|
||||
|
||||
|
||||
/**
|
||||
* @if Eng
|
||||
* @brief sle adv data config.
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS Excute successfully
|
||||
* @retval ERRCODE_SLE_FAIL Execute fail
|
||||
* @par Dependency:
|
||||
* @li NULL
|
||||
* @else
|
||||
* @brief sle广播数据配置。
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS 执行成功
|
||||
* @retval ERRCODE_SLE_FAIL 执行失败
|
||||
* @par 依赖:
|
||||
* @li NULL
|
||||
* @endif
|
||||
*/
|
||||
errcode_t sle_uuid_server_adv_init(void);
|
||||
#endif
|
8
application/samples/bt/sle/sle_speed_server/src/CMakeLists.txt
Executable file
8
application/samples/bt/sle/sle_speed_server/src/CMakeLists.txt
Executable file
@ -0,0 +1,8 @@
|
||||
#===============================================================================
|
||||
# @brief cmake file
|
||||
# Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
|
||||
#===============================================================================
|
||||
set(SOURCES "${SOURCES}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/sle_speed_server_adv.c"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/sle_speed_server.c"
|
||||
PARENT_SCOPE)
|
445
application/samples/bt/sle/sle_speed_server/src/sle_speed_server.c
Executable file
445
application/samples/bt/sle/sle_speed_server/src/sle_speed_server.c
Executable file
@ -0,0 +1,445 @@
|
||||
/*
|
||||
* Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023. All rights reserved.
|
||||
* Description: sle uuid server sample.
|
||||
*/
|
||||
#include "app_init.h"
|
||||
#include "watchdog.h"
|
||||
#include "tcxo.h"
|
||||
#include "systick.h"
|
||||
#include "los_memory.h"
|
||||
#include "securec.h"
|
||||
#include "errcode.h"
|
||||
#include "osal_addr.h"
|
||||
#include "soc_osal.h"
|
||||
#include "common_def.h"
|
||||
|
||||
#include "sle_common.h"
|
||||
#include "sle_errcode.h"
|
||||
#include "sle_ssap_server.h"
|
||||
#include "sle_connection_manager.h"
|
||||
#include "sle_device_discovery.h"
|
||||
#include "sle_transmition_manager.h"
|
||||
#include "nv.h"
|
||||
|
||||
#include "sle_speed_server_adv.h"
|
||||
#include "sle_speed_server.h"
|
||||
|
||||
#define OCTET_BIT_LEN 8
|
||||
#define UUID_LEN_2 2
|
||||
#define BT_INDEX_4 4
|
||||
#define BT_INDEX_5 5
|
||||
#define BT_INDEX_0 0
|
||||
extern void send_data_thread_function(void);
|
||||
#define encode2byte_little(_ptr, data) \
|
||||
do { \
|
||||
*(uint8_t *)((_ptr) + 1) = (uint8_t)((data) >> 8); \
|
||||
*(uint8_t *)(_ptr) = (uint8_t)(data); \
|
||||
} while (0)
|
||||
|
||||
/* sle server app uuid for test */
|
||||
static char g_sle_uuid_app_uuid[UUID_LEN_2] = {0x0, 0x0};
|
||||
/* server notify property uuid for test */
|
||||
static char g_sle_property_value[OCTET_BIT_LEN] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
|
||||
/* sle connect acb handle */
|
||||
static uint16_t g_sle_conn_hdl = 0;
|
||||
/* sle server handle */
|
||||
static uint8_t g_server_id = 0;
|
||||
/* sle service handle */
|
||||
static uint16_t g_service_handle = 0;
|
||||
/* sle ntf property handle */
|
||||
static uint16_t g_property_handle = 0;
|
||||
#ifdef SLE_QOS_FLOWCTRL_FUNCTION_SWITCH
|
||||
static sle_link_qos_state_t g_sle_link_state = 0; /* sle link state */
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LARGE_THROUGHPUT_SERVER
|
||||
#define PKT_DATA_LEN 1200
|
||||
#define SPEED_DEFAULT_CONN_INTERVAL 0x14
|
||||
#else
|
||||
#define PKT_DATA_LEN 600
|
||||
#define SPEED_DEFAULT_CONN_INTERVAL 0xA0
|
||||
#endif
|
||||
|
||||
#define SPEED_DEFAULT_KTHREAD_SIZE 0x2000
|
||||
#define SPEED_DEFAULT_KTHREAD_PROI 26
|
||||
#define DEFAULT_SLE_SPEED_DATA_LEN 1500
|
||||
#define DEFAULT_SLE_SPEED_MTU_SIZE 1500
|
||||
#define SPEED_DEFAULT_TIMEOUT_MULTIPLIER 0x1f4
|
||||
#define SPEED_DEFAULT_SCAN_INTERVAL 400
|
||||
#define SPEED_DEFAULT_SCAN_WINDOW 20
|
||||
static unsigned char data[PKT_DATA_LEN];
|
||||
|
||||
static uint8_t sle_uuid_base[] = { 0x37, 0xBE, 0xA8, 0x80, 0xFC, 0x70, 0x11, 0xEA, \
|
||||
0xB7, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
static void sle_uuid_set_base(sle_uuid_t *out)
|
||||
{
|
||||
(void)memcpy_s(out->uuid, SLE_UUID_LEN, sle_uuid_base, SLE_UUID_LEN);
|
||||
out->len = UUID_LEN_2;
|
||||
}
|
||||
|
||||
static void sle_uuid_setu2(uint16_t u2, sle_uuid_t *out)
|
||||
{
|
||||
sle_uuid_set_base(out);
|
||||
out->len = UUID_LEN_2;
|
||||
encode2byte_little(&out->uuid[14], u2);
|
||||
}
|
||||
|
||||
static void ssaps_read_request_cbk(uint8_t server_id, uint16_t conn_id, ssaps_req_read_cb_t *read_cb_para,
|
||||
errcode_t status)
|
||||
{
|
||||
osal_printk("[speed server] ssaps read request cbk server_id:%x, conn_id:%x, handle:%x, status:%x\r\n",
|
||||
server_id, conn_id, read_cb_para->handle, status);
|
||||
osal_task *task_handle = NULL;
|
||||
osal_kthread_lock();
|
||||
task_handle = osal_kthread_create((osal_kthread_handler)send_data_thread_function,
|
||||
0, "RadarTask", SPEED_DEFAULT_KTHREAD_SIZE);
|
||||
osal_kthread_set_priority(task_handle, SPEED_DEFAULT_KTHREAD_PROI + 1);
|
||||
if (task_handle != NULL) {
|
||||
osal_kfree(task_handle);
|
||||
}
|
||||
osal_kthread_unlock();
|
||||
printf("kthread success\r\n");
|
||||
}
|
||||
|
||||
static void ssaps_write_request_cbk(uint8_t server_id, uint16_t conn_id, ssaps_req_write_cb_t *write_cb_para,
|
||||
errcode_t status)
|
||||
{
|
||||
osal_printk("[speed server] ssaps write request cbk server_id:%d, conn_id:%d, handle:%d, status:%d\r\n",
|
||||
server_id, conn_id, write_cb_para->handle, status);
|
||||
}
|
||||
|
||||
static void ssaps_mtu_changed_cbk(uint8_t server_id, uint16_t conn_id, ssap_exchange_info_t *mtu_size,
|
||||
errcode_t status)
|
||||
{
|
||||
osal_printk("[speed server] ssaps write request cbk server_id:%d, conn_id:%d, mtu_size:%d, status:%d\r\n",
|
||||
server_id, conn_id, mtu_size->mtu_size, status);
|
||||
}
|
||||
|
||||
static void ssaps_start_service_cbk(uint8_t server_id, uint16_t handle, errcode_t status)
|
||||
{
|
||||
osal_printk("[speed server] start service cbk server_id:%d, handle:%d, status:%d\r\n",
|
||||
server_id, handle, status);
|
||||
}
|
||||
|
||||
static void sle_ssaps_register_cbks(void)
|
||||
{
|
||||
ssaps_callbacks_t ssaps_cbk = {0};
|
||||
ssaps_cbk.start_service_cb = ssaps_start_service_cbk;
|
||||
ssaps_cbk.mtu_changed_cb = ssaps_mtu_changed_cbk;
|
||||
ssaps_cbk.read_request_cb = ssaps_read_request_cbk;
|
||||
ssaps_cbk.write_request_cb = ssaps_write_request_cbk;
|
||||
ssaps_register_callbacks(&ssaps_cbk);
|
||||
}
|
||||
|
||||
errcode_t sle_uuid_server_send_report_by_handle_id(uint8_t *data, uint16_t len, uint16_t connect_id)
|
||||
{
|
||||
ssaps_ntf_ind_t param = {0};
|
||||
param.handle = g_property_handle;
|
||||
param.type = SSAP_PROPERTY_TYPE_VALUE;
|
||||
param.value = data;
|
||||
param.value_len = len;
|
||||
ssaps_notify_indicate(g_server_id, connect_id, ¶m);
|
||||
return ERRCODE_SLE_SUCCESS;
|
||||
}
|
||||
|
||||
#ifdef SLE_QOS_FLOWCTRL_FUNCTION_SWITCH
|
||||
static void sle_send_data_cbk(uint16_t conn_id, sle_link_qos_state_t link_state)
|
||||
{
|
||||
conn_id = conn_id;
|
||||
g_sle_link_state = link_state;
|
||||
printf("%s enter, gle_tx_acb_data_num_get:%d.\n", __FUNCTION__, link_state);
|
||||
}
|
||||
|
||||
static void sle_transmission_register_cbks(void)
|
||||
{
|
||||
sle_transmission_callbacks_t trans_cbk = {0};
|
||||
trans_cbk.send_data_cb = sle_send_data_cbk;
|
||||
sle_transmission_register_callbacks(&trans_cbk);
|
||||
}
|
||||
#else
|
||||
extern uint8_t gle_tx_acb_data_num_get(void);
|
||||
#endif
|
||||
|
||||
uint8_t sle_flow_ctrl_flag(void)
|
||||
{
|
||||
#ifdef SLE_QOS_FLOWCTRL_FUNCTION_SWITCH
|
||||
return (g_sle_link_state <= SLE_QOS_FLOWCTRL) ? 1 : 0;
|
||||
#else
|
||||
return gle_tx_acb_data_num_get();
|
||||
#endif
|
||||
}
|
||||
|
||||
void send_data_thread_function(void)
|
||||
{
|
||||
sle_set_data_len(g_sle_conn_hdl, DEFAULT_SLE_SPEED_DATA_LEN);
|
||||
#ifdef CONFIG_LARGE_THROUGHPUT_SERVER
|
||||
#define DEFAULT_SLE_SPEED_MCS 10
|
||||
sle_set_phy_t phy_parm = {
|
||||
.tx_format = SLE_RADIO_FRAME_2,
|
||||
.rx_format = SLE_RADIO_FRAME_2,
|
||||
.tx_phy = SLE_PHY_4M,
|
||||
.rx_phy = SLE_PHY_4M,
|
||||
.tx_pilot_density = SLE_PHY_PILOT_DENSITY_16_TO_1,
|
||||
.rx_pilot_density = SLE_PHY_PILOT_DENSITY_16_TO_1,
|
||||
.g_feedback = 0,
|
||||
.t_feedback = 0,
|
||||
};
|
||||
sle_set_phy_param(g_sle_conn_hdl, &phy_parm);
|
||||
sle_set_mcs(g_sle_conn_hdl, DEFAULT_SLE_SPEED_MCS);
|
||||
osal_printk("code: ploar MCS10, PHY 4MHZ, power: 20dbm \r\n");
|
||||
#else
|
||||
osal_printk("code: GFSK, PHY 1MHZ, power: 20dbm \r\n");
|
||||
#endif
|
||||
int i = 0;
|
||||
while (1) {
|
||||
if (sle_flow_ctrl_flag() > 0) {
|
||||
i++;
|
||||
data[0] = (i >> 8) & 0xFF; /* offset 8bits */
|
||||
data[1] = i & 0xFF;
|
||||
sle_uuid_server_send_report_by_handle_id(data, PKT_DATA_LEN, g_sle_conn_hdl);
|
||||
}
|
||||
#ifndef CONFIG_LARGE_THROUGHPUT_SERVER
|
||||
osal_msleep(1000); /* sleep 1000ms */
|
||||
i = 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static errcode_t sle_uuid_server_service_add(void)
|
||||
{
|
||||
errcode_t ret;
|
||||
sle_uuid_t service_uuid = {0};
|
||||
sle_uuid_setu2(SLE_UUID_SERVER_SERVICE, &service_uuid);
|
||||
ret = ssaps_add_service_sync(g_server_id, &service_uuid, 1, &g_service_handle);
|
||||
if (ret != ERRCODE_SLE_SUCCESS) {
|
||||
osal_printk("[speed server] sle uuid add service fail, ret:%x\r\n", ret);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
return ERRCODE_SLE_SUCCESS;
|
||||
}
|
||||
|
||||
static errcode_t sle_uuid_server_property_add(void)
|
||||
{
|
||||
errcode_t ret;
|
||||
ssaps_property_info_t property = {0};
|
||||
ssaps_desc_info_t descriptor = {0};
|
||||
uint8_t ntf_value[] = {0x01, 0x0};
|
||||
|
||||
property.permissions = SLE_UUID_TEST_PROPERTIES;
|
||||
sle_uuid_setu2(SLE_UUID_SERVER_NTF_REPORT, &property.uuid);
|
||||
property.value = osal_vmalloc(sizeof(g_sle_property_value));
|
||||
property.operate_indication = SSAP_OPERATE_INDICATION_BIT_READ | SSAP_OPERATE_INDICATION_BIT_NOTIFY;
|
||||
if (property.value == NULL) {
|
||||
osal_printk("[speed server] sle property mem fail\r\n");
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
if (memcpy_s(property.value, sizeof(g_sle_property_value), g_sle_property_value,
|
||||
sizeof(g_sle_property_value)) != EOK) {
|
||||
osal_vfree(property.value);
|
||||
osal_printk("[speed server] sle property mem cpy fail\r\n");
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
ret = ssaps_add_property_sync(g_server_id, g_service_handle, &property, &g_property_handle);
|
||||
if (ret != ERRCODE_SLE_SUCCESS) {
|
||||
osal_printk("[speed server] sle uuid add property fail, ret:%x\r\n", ret);
|
||||
osal_vfree(property.value);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
descriptor.permissions = SLE_UUID_TEST_DESCRIPTOR;
|
||||
descriptor.operate_indication = SSAP_OPERATE_INDICATION_BIT_READ | SSAP_OPERATE_INDICATION_BIT_WRITE;
|
||||
descriptor.type = SSAP_DESCRIPTOR_USER_DESCRIPTION;
|
||||
descriptor.value = ntf_value;
|
||||
descriptor.value_len = sizeof(ntf_value);
|
||||
|
||||
ret = ssaps_add_descriptor_sync(g_server_id, g_service_handle, g_property_handle, &descriptor);
|
||||
if (ret != ERRCODE_SLE_SUCCESS) {
|
||||
osal_printk("[speed server] sle uuid add descriptor fail, ret:%x\r\n", ret);
|
||||
osal_vfree(property.value);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
osal_vfree(property.value);
|
||||
return ERRCODE_SLE_SUCCESS;
|
||||
}
|
||||
|
||||
static errcode_t sle_uuid_server_add(void)
|
||||
{
|
||||
errcode_t ret;
|
||||
sle_uuid_t app_uuid = {0};
|
||||
|
||||
osal_printk("[speed server] sle uuid add service in\r\n");
|
||||
app_uuid.len = sizeof(g_sle_uuid_app_uuid);
|
||||
if (memcpy_s(app_uuid.uuid, app_uuid.len, g_sle_uuid_app_uuid, sizeof(g_sle_uuid_app_uuid)) != EOK) {
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
ssaps_register_server(&app_uuid, &g_server_id);
|
||||
|
||||
if (sle_uuid_server_service_add() != ERRCODE_SLE_SUCCESS) {
|
||||
ssaps_unregister_server(g_server_id);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
|
||||
if (sle_uuid_server_property_add() != ERRCODE_SLE_SUCCESS) {
|
||||
ssaps_unregister_server(g_server_id);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
osal_printk("[speed server] sle uuid add service, server_id:%x, service_handle:%x, property_handle:%x\r\n",
|
||||
g_server_id, g_service_handle, g_property_handle);
|
||||
ret = ssaps_start_service(g_server_id, g_service_handle);
|
||||
if (ret != ERRCODE_SLE_SUCCESS) {
|
||||
osal_printk("[speed server] sle uuid add service fail, ret:%x\r\n", ret);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
osal_printk("[speed server] sle uuid add service out\r\n");
|
||||
return ERRCODE_SLE_SUCCESS;
|
||||
}
|
||||
|
||||
static void sle_connect_state_changed_cbk(uint16_t conn_id, const sle_addr_t *addr,
|
||||
sle_acb_state_t conn_state, sle_pair_state_t pair_state, sle_disc_reason_t disc_reason)
|
||||
{
|
||||
osal_printk("[speed server] connect state changed conn_id:0x%02x, conn_state:0x%x, pair_state:0x%x, \
|
||||
disc_reason:0x%x\r\n", conn_id, conn_state, pair_state, disc_reason);
|
||||
osal_printk("[speed server] connect state changed addr:%02x:**:**:**:%02x:%02x\r\n",
|
||||
addr->addr[BT_INDEX_0], addr->addr[BT_INDEX_4], addr->addr[BT_INDEX_5]);
|
||||
g_sle_conn_hdl = conn_id;
|
||||
sle_connection_param_update_t parame = {0};
|
||||
parame.conn_id = conn_id;
|
||||
parame.interval_min = SPEED_DEFAULT_CONN_INTERVAL;
|
||||
parame.interval_max = SPEED_DEFAULT_CONN_INTERVAL;
|
||||
parame.max_latency = 0;
|
||||
parame.supervision_timeout = SPEED_DEFAULT_TIMEOUT_MULTIPLIER;
|
||||
if (conn_state == SLE_ACB_STATE_CONNECTED) {
|
||||
sle_update_connect_param(¶me);
|
||||
} else if (conn_state == SLE_ACB_STATE_DISCONNECTED) {
|
||||
sle_start_announce(SLE_ADV_HANDLE_DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
static void sle_pair_complete_cbk(uint16_t conn_id, const sle_addr_t *addr, errcode_t status)
|
||||
{
|
||||
osal_printk("[speed server] pair complete conn_id:%02x, status:%x\r\n",
|
||||
conn_id, status);
|
||||
osal_printk("[speed server] pair complete addr:%02x:**:**:**:%02x:%02x\r\n",
|
||||
addr->addr[BT_INDEX_0], addr->addr[BT_INDEX_4], addr->addr[BT_INDEX_5]);
|
||||
}
|
||||
|
||||
void sle_sample_update_cbk(uint16_t conn_id, errcode_t status, const sle_connection_param_update_evt_t *param)
|
||||
{
|
||||
unused(status);
|
||||
osal_printk("[ssap server] updat state changed conn_id:%d, interval = %02x\n", conn_id, param->interval);
|
||||
}
|
||||
|
||||
void sle_sample_update_req_cbk(uint16_t conn_id, errcode_t status, const sle_connection_param_update_req_t *param)
|
||||
{
|
||||
unused(conn_id);
|
||||
unused(status);
|
||||
osal_printk("[ssap server] sle_sample_update_req_cbk interval_min:%02x, interval_max:%02x\n",
|
||||
param->interval_min, param->interval_max);
|
||||
}
|
||||
|
||||
void sle_sample_rssi_cbk(uint16_t conn_id, int8_t rssi, errcode_t status)
|
||||
{
|
||||
osal_printk("[ssap server] conn_id:%d, rssi = %c, status = %x\n", conn_id, rssi, status);
|
||||
}
|
||||
|
||||
static void sle_conn_register_cbks(void)
|
||||
{
|
||||
sle_connection_callbacks_t conn_cbks = {0};
|
||||
conn_cbks.connect_state_changed_cb = sle_connect_state_changed_cbk;
|
||||
conn_cbks.pair_complete_cb = sle_pair_complete_cbk;
|
||||
conn_cbks.connect_param_update_req_cb = sle_sample_update_req_cbk;
|
||||
conn_cbks.connect_param_update_cb = sle_sample_update_cbk;
|
||||
conn_cbks.read_rssi_cb = sle_sample_rssi_cbk;
|
||||
sle_connection_register_callbacks(&conn_cbks);
|
||||
}
|
||||
|
||||
void sle_ssaps_set_info(void)
|
||||
{
|
||||
ssap_exchange_info_t info = {0};
|
||||
info.mtu_size = DEFAULT_SLE_SPEED_MTU_SIZE;
|
||||
info.version = 1;
|
||||
ssaps_set_info(g_server_id, &info);
|
||||
}
|
||||
|
||||
void sle_speed_connect_param_init(void)
|
||||
{
|
||||
sle_default_connect_param_t param = {0};
|
||||
param.enable_filter_policy = 0;
|
||||
param.gt_negotiate = 0;
|
||||
param.initiate_phys = 1;
|
||||
param.max_interval = SPEED_DEFAULT_CONN_INTERVAL;
|
||||
param.min_interval = SPEED_DEFAULT_CONN_INTERVAL;
|
||||
param.scan_interval = SPEED_DEFAULT_SCAN_INTERVAL;
|
||||
param.scan_window = SPEED_DEFAULT_SCAN_WINDOW;
|
||||
param.timeout = SPEED_DEFAULT_TIMEOUT_MULTIPLIER;
|
||||
sle_default_connection_param_set(¶m);
|
||||
}
|
||||
|
||||
void sle_set_local_addr_init(void)
|
||||
{
|
||||
sle_addr_t addr = {0};
|
||||
uint8_t mac[SLE_ADDR_LEN] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
|
||||
addr.type = 0;
|
||||
memcpy_s(addr.addr, SLE_ADDR_LEN, mac, SLE_ADDR_LEN);
|
||||
sle_set_local_addr(&addr);
|
||||
}
|
||||
|
||||
void sle_speed_server_set_nv(void)
|
||||
{
|
||||
uint16_t nv_value_len = 0;
|
||||
uint8_t nv_value = 0;
|
||||
uapi_nv_read(0x20A0, sizeof(uint16_t), &nv_value_len, &nv_value);
|
||||
if (nv_value != 7) { // 7:btc功率档位
|
||||
nv_value = 7; // 7:btc功率档位
|
||||
uapi_nv_write(0x20A0, (uint8_t *)&(nv_value), sizeof(nv_value));
|
||||
}
|
||||
osal_printk("[speed server] The value of nv is set to %d.\r\n", nv_value);
|
||||
}
|
||||
|
||||
/* 初始化speed server */
|
||||
errcode_t sle_speed_server_init(void)
|
||||
{
|
||||
uapi_watchdog_disable();
|
||||
enable_sle();
|
||||
printf("sle enable\r\n");
|
||||
sle_speed_server_set_nv();
|
||||
sle_conn_register_cbks();
|
||||
sle_ssaps_register_cbks();
|
||||
sle_uuid_server_add();
|
||||
sle_uuid_server_adv_init();
|
||||
sle_ssaps_set_info();
|
||||
#ifdef SLE_QOS_FLOWCTRL_FUNCTION_SWITCH
|
||||
sle_transmission_register_cbks();
|
||||
#endif
|
||||
sle_speed_connect_param_init();
|
||||
sle_set_local_addr_init();
|
||||
osal_printk("[speed server] init ok\r\n");
|
||||
return ERRCODE_SLE_SUCCESS;
|
||||
}
|
||||
|
||||
int sle_speed_init(void)
|
||||
{
|
||||
for (int i = 0; i < PKT_DATA_LEN; i++) {
|
||||
data[i] = 'A';
|
||||
data[PKT_DATA_LEN - 1] = '\0';
|
||||
}
|
||||
osal_msleep(1000); /* sleep 1000ms */
|
||||
sle_speed_server_init();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void sle_speed_entry(void)
|
||||
{
|
||||
osal_task *task_handle1 = NULL;
|
||||
osal_kthread_lock();
|
||||
task_handle1= osal_kthread_create((osal_kthread_handler)sle_speed_init, 0, "speed", SPEED_DEFAULT_KTHREAD_SIZE);
|
||||
if (task_handle1 != NULL) {
|
||||
osal_kthread_set_priority(task_handle1, SPEED_DEFAULT_KTHREAD_PROI);
|
||||
osal_kfree(task_handle1);
|
||||
}
|
||||
osal_kthread_unlock();
|
||||
}
|
||||
|
||||
/* Run the blinky_entry. */
|
||||
app_run(sle_speed_entry);
|
||||
|
203
application/samples/bt/sle/sle_speed_server/src/sle_speed_server_adv.c
Executable file
203
application/samples/bt/sle/sle_speed_server/src/sle_speed_server_adv.c
Executable file
@ -0,0 +1,203 @@
|
||||
/*
|
||||
* Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023. All rights reserved.
|
||||
* Description: sle adv config for sle uuid server.
|
||||
*/
|
||||
#include "securec.h"
|
||||
#include "errcode.h"
|
||||
#include "osal_addr.h"
|
||||
#include "osal_debug.h"
|
||||
#include "sle_common.h"
|
||||
#include "sle_device_discovery.h"
|
||||
#include "sle_connection_manager.h"
|
||||
#include "sle_errcode.h"
|
||||
#include "sle_speed_server_adv.h"
|
||||
|
||||
/* sle device name */
|
||||
#define NAME_MAX_LENGTH 15
|
||||
/* 连接调度间隔12.5ms,单位125us */
|
||||
#define SLE_CONN_INTV_MIN_DEFAULT 0xA
|
||||
/* 连接调度间隔12.5ms,单位125us */
|
||||
#define SLE_CONN_INTV_MAX_DEFAULT 0xA
|
||||
/* 连接调度间隔25ms,单位125us */
|
||||
#define SLE_ADV_INTERVAL_MIN_DEFAULT 0xC8
|
||||
/* 连接调度间隔25ms,单位125us */
|
||||
#define SLE_ADV_INTERVAL_MAX_DEFAULT 0xC8
|
||||
/* 超时时间5000ms,单位10ms */
|
||||
#define SLE_CONN_SUPERVISION_TIMEOUT_DEFAULT 0x1F4
|
||||
/* 超时时间4990ms,单位10ms */
|
||||
#define SLE_CONN_MAX_LATENCY 0x1F3
|
||||
/* 广播发送功率 */
|
||||
#define SLE_ADV_TX_POWER 20
|
||||
/* 最大广播数据长度 */
|
||||
#define SLE_ADV_DATA_LEN_MAX 251
|
||||
|
||||
uint8_t sle_local_name[ NAME_MAX_LENGTH] = "sle_uart_server";
|
||||
|
||||
static uint16_t sle_set_adv_local_name(uint8_t *adv_data, uint16_t max_len)
|
||||
{
|
||||
errno_t ret;
|
||||
uint8_t index = 0;
|
||||
|
||||
uint8_t *local_name = sle_local_name;
|
||||
uint8_t local_name_len = (uint8_t)strlen((char *)local_name);
|
||||
for (uint8_t i = 0; i < local_name_len; i++) {
|
||||
osal_printk("local_name[%d] = 0x%02x\r\n", i, local_name[i]);
|
||||
}
|
||||
|
||||
adv_data[index++] = local_name_len + 1;
|
||||
adv_data[index++] = SLE_ADV_DATA_TYPE_COMPLETE_LOCAL_NAME;
|
||||
ret = memcpy_s(&adv_data[index], max_len - index, local_name, local_name_len);
|
||||
if (ret != EOK) {
|
||||
osal_printk("memcpy fail\r\n");
|
||||
return 0;
|
||||
}
|
||||
return (uint16_t)index + local_name_len;
|
||||
}
|
||||
|
||||
static uint16_t sle_set_adv_data(uint8_t *adv_data)
|
||||
{
|
||||
size_t len = 0;
|
||||
uint16_t idx = 0;
|
||||
errno_t ret = 0;
|
||||
|
||||
len = sizeof(struct sle_adv_common_value);
|
||||
struct sle_adv_common_value adv_disc_level = {
|
||||
.length = len - 1,
|
||||
.type = SLE_ADV_DATA_TYPE_DISCOVERY_LEVEL,
|
||||
.value = SLE_ANNOUNCE_LEVEL_NORMAL,
|
||||
};
|
||||
ret = memcpy_s(&adv_data[idx], SLE_ADV_DATA_LEN_MAX - idx, &adv_disc_level, len);
|
||||
if (ret != EOK) {
|
||||
osal_printk("adv_disc_level memcpy fail\r\n");
|
||||
return 0;
|
||||
}
|
||||
idx += len;
|
||||
|
||||
len = sizeof(struct sle_adv_common_value);
|
||||
struct sle_adv_common_value adv_access_mode = {
|
||||
.length = len - 1,
|
||||
.type = SLE_ADV_DATA_TYPE_ACCESS_MODE,
|
||||
.value = 0,
|
||||
};
|
||||
ret = memcpy_s(&adv_data[idx], SLE_ADV_DATA_LEN_MAX - idx, &adv_access_mode, len);
|
||||
if (ret != EOK) {
|
||||
osal_printk("memcpy fail\r\n");
|
||||
return 0;
|
||||
}
|
||||
idx += len;
|
||||
return idx;
|
||||
}
|
||||
|
||||
static uint16_t sle_set_scan_response_data(uint8_t *scan_rsp_data)
|
||||
{
|
||||
uint16_t idx = 0;
|
||||
errno_t ret;
|
||||
size_t scan_rsp_data_len = sizeof(struct sle_adv_common_value);
|
||||
|
||||
struct sle_adv_common_value tx_power_level = {
|
||||
.length = scan_rsp_data_len - 1,
|
||||
.type = SLE_ADV_DATA_TYPE_TX_POWER_LEVEL,
|
||||
.value = SLE_ADV_TX_POWER,
|
||||
};
|
||||
ret = memcpy_s(scan_rsp_data, SLE_ADV_DATA_LEN_MAX, &tx_power_level, scan_rsp_data_len);
|
||||
if (ret != EOK) {
|
||||
osal_printk("sle scan response data memcpy fail\r\n");
|
||||
return 0;
|
||||
}
|
||||
idx += scan_rsp_data_len;
|
||||
|
||||
/* set local name */
|
||||
idx += sle_set_adv_local_name(&scan_rsp_data[idx], SLE_ADV_DATA_LEN_MAX - idx);
|
||||
return idx;
|
||||
}
|
||||
|
||||
static int sle_set_default_announce_param(void)
|
||||
{
|
||||
sle_announce_param_t param = {0};
|
||||
uint8_t mac[SLE_ADDR_LEN] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
|
||||
param.announce_mode = SLE_ANNOUNCE_MODE_CONNECTABLE_SCANABLE;
|
||||
param.announce_handle = SLE_ADV_HANDLE_DEFAULT;
|
||||
param.announce_gt_role = SLE_ANNOUNCE_ROLE_T_CAN_NEGO;
|
||||
param.announce_level = SLE_ANNOUNCE_LEVEL_NORMAL;
|
||||
param.announce_channel_map = SLE_ADV_CHANNEL_MAP_DEFAULT;
|
||||
param.announce_interval_min = SLE_ADV_INTERVAL_MIN_DEFAULT;
|
||||
param.announce_interval_max = SLE_ADV_INTERVAL_MAX_DEFAULT;
|
||||
param.conn_interval_min = SLE_CONN_INTV_MIN_DEFAULT;
|
||||
param.conn_interval_max = SLE_CONN_INTV_MAX_DEFAULT;
|
||||
param.conn_max_latency = SLE_CONN_MAX_LATENCY;
|
||||
param.conn_supervision_timeout = SLE_CONN_SUPERVISION_TIMEOUT_DEFAULT;
|
||||
param.announce_tx_power = SLE_ADV_TX_POWER;
|
||||
param.own_addr.type = 0;
|
||||
memcpy_s(param.own_addr.addr, SLE_ADDR_LEN, mac, SLE_ADDR_LEN);
|
||||
return sle_set_announce_param(param.announce_handle, ¶m);
|
||||
}
|
||||
|
||||
static int sle_set_default_announce_data(void)
|
||||
{
|
||||
errcode_t ret;
|
||||
uint8_t announce_data_len = 0;
|
||||
uint8_t seek_data_len = 0;
|
||||
sle_announce_data_t data = {0};
|
||||
uint8_t adv_handle = SLE_ADV_HANDLE_DEFAULT;
|
||||
uint8_t announce_data[SLE_ADV_DATA_LEN_MAX] = {0};
|
||||
uint8_t seek_rsp_data[SLE_ADV_DATA_LEN_MAX] = {0};
|
||||
|
||||
osal_printk("set adv data default\r\n");
|
||||
announce_data_len = sle_set_adv_data(announce_data);
|
||||
data.announce_data = announce_data;
|
||||
data.announce_data_len = announce_data_len;
|
||||
|
||||
seek_data_len = sle_set_scan_response_data(seek_rsp_data);
|
||||
data.seek_rsp_data = seek_rsp_data;
|
||||
data.seek_rsp_data_len = seek_data_len;
|
||||
|
||||
ret = sle_set_announce_data(adv_handle, &data);
|
||||
if (ret == ERRCODE_SLE_SUCCESS) {
|
||||
osal_printk("[SLE DD SDK] set announce data success.");
|
||||
} else {
|
||||
osal_printk("[SLE DD SDK] set adv param fail.");
|
||||
}
|
||||
return ERRCODE_SLE_SUCCESS;
|
||||
}
|
||||
|
||||
void sle_announce_enable_cbk(uint32_t announce_id, errcode_t status)
|
||||
{
|
||||
osal_printk("sle announce enable id:%02x, state:%02x\r\n", announce_id, status);
|
||||
}
|
||||
|
||||
void sle_announce_disable_cbk(uint32_t announce_id, errcode_t status)
|
||||
{
|
||||
osal_printk("sle announce disable id:%02x, state:%02x\r\n", announce_id, status);
|
||||
}
|
||||
|
||||
void sle_announce_terminal_cbk(uint32_t announce_id)
|
||||
{
|
||||
osal_printk("sle announce terminal id:%02x\r\n", announce_id);
|
||||
}
|
||||
|
||||
void sle_enable_cbk(errcode_t status)
|
||||
{
|
||||
osal_printk("sle enable status:%02x\r\n", status);
|
||||
}
|
||||
|
||||
void sle_announce_register_cbks(void)
|
||||
{
|
||||
sle_announce_seek_callbacks_t seek_cbks = {0};
|
||||
seek_cbks.announce_enable_cb = sle_announce_enable_cbk;
|
||||
seek_cbks.announce_disable_cb = sle_announce_disable_cbk;
|
||||
seek_cbks.announce_terminal_cb = sle_announce_terminal_cbk;
|
||||
seek_cbks.sle_enable_cb = sle_enable_cbk;
|
||||
sle_announce_seek_register_callbacks(&seek_cbks);
|
||||
}
|
||||
|
||||
errcode_t sle_uuid_server_adv_init(void)
|
||||
{
|
||||
osal_printk("sle_uuid_server_adv_init in\r\n");
|
||||
|
||||
sle_announce_register_cbks();
|
||||
sle_set_default_announce_param();
|
||||
sle_set_default_announce_data();
|
||||
sle_start_announce(SLE_ADV_HANDLE_DEFAULT);
|
||||
osal_printk("sle_uuid_server_adv_init out\r\n");
|
||||
return ERRCODE_SLE_SUCCESS;
|
||||
}
|
8
application/samples/bt/sle/sle_uuid_client/CMakeLists.txt
Executable file
8
application/samples/bt/sle/sle_uuid_client/CMakeLists.txt
Executable file
@ -0,0 +1,8 @@
|
||||
#===============================================================================
|
||||
# @brief cmake file
|
||||
# Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
|
||||
#===============================================================================
|
||||
add_subdirectory_if_exist(src)
|
||||
|
||||
set(SOURCES "${SOURCES}" PARENT_SCOPE)
|
||||
set(PUBLIC_HEADER "${PUBLIC_HEADER}" "${CMAKE_CURRENT_SOURCE_DIR}/inc" PARENT_SCOPE)
|
54
application/samples/bt/sle/sle_uuid_client/inc/sle_uuid_client.h
Executable file
54
application/samples/bt/sle/sle_uuid_client/inc/sle_uuid_client.h
Executable file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2022. All rights reserved.
|
||||
*
|
||||
* Description: SLE private service register sample of client.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup SLE UUID CLIENT API
|
||||
* @ingroup
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef SLE_CLIENT_ADV_H
|
||||
#define SLE_CLIENT_ADV_H
|
||||
|
||||
/**
|
||||
* @if Eng
|
||||
* @brief sle uuid client init.
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS Excute successfully
|
||||
* @retval ERRCODE_SLE_FAIL Execute fail
|
||||
* @par Dependency:
|
||||
* @li NULL
|
||||
* @else
|
||||
* @brief sle uuid客户端初始化。
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS 执行成功
|
||||
* @retval ERRCODE_SLE_FAIL 执行失败
|
||||
* @par 依赖:
|
||||
* @li NULL
|
||||
* @endif
|
||||
*/
|
||||
void sle_client_init(void);
|
||||
|
||||
/**
|
||||
* @if Eng
|
||||
* @brief sle start scan.
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS Excute successfully
|
||||
* @retval ERRCODE_SLE_FAIL Execute fail
|
||||
* @par Dependency:
|
||||
* @li NULL
|
||||
* @else
|
||||
* @brief sle启动扫描。
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS 执行成功
|
||||
* @retval ERRCODE_SLE_FAIL 执行失败
|
||||
* @par 依赖:
|
||||
* @li NULL
|
||||
* @endif
|
||||
*/
|
||||
void sle_start_scan(void);
|
||||
|
||||
#endif
|
7
application/samples/bt/sle/sle_uuid_client/src/CMakeLists.txt
Executable file
7
application/samples/bt/sle/sle_uuid_client/src/CMakeLists.txt
Executable file
@ -0,0 +1,7 @@
|
||||
#===============================================================================
|
||||
# @brief cmake file
|
||||
# Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
|
||||
#===============================================================================
|
||||
set(SOURCES "${SOURCES}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/sle_uuid_client.c"
|
||||
PARENT_SCOPE)
|
249
application/samples/bt/sle/sle_uuid_client/src/sle_uuid_client.c
Executable file
249
application/samples/bt/sle/sle_uuid_client/src/sle_uuid_client.c
Executable file
@ -0,0 +1,249 @@
|
||||
/**
|
||||
* Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2022. All rights reserved.
|
||||
*
|
||||
* Description: SLE private service register sample of client.
|
||||
*/
|
||||
#include "securec.h"
|
||||
#include "soc_osal.h"
|
||||
#include "app_init.h"
|
||||
#include "sle_device_discovery.h"
|
||||
#include "sle_connection_manager.h"
|
||||
#include "sle_ssap_client.h"
|
||||
#include "sle_uuid_client.h"
|
||||
|
||||
#undef THIS_FILE_ID
|
||||
#define THIS_FILE_ID BTH_GLE_SAMPLE_UUID_CLIENT
|
||||
|
||||
#define SLE_MTU_SIZE_DEFAULT 300
|
||||
#define SLE_SEEK_INTERVAL_DEFAULT 100
|
||||
#define SLE_SEEK_WINDOW_DEFAULT 100
|
||||
#define UUID_16BIT_LEN 2
|
||||
#define UUID_128BIT_LEN 16
|
||||
|
||||
sle_announce_seek_callbacks_t g_seek_cbk = {0};
|
||||
sle_connection_callbacks_t g_connect_cbk = {0};
|
||||
ssapc_callbacks_t g_ssapc_cbk = {0};
|
||||
sle_addr_t g_remote_addr = {0};
|
||||
uint16_t g_conn_id = 0;
|
||||
ssapc_find_service_result_t g_find_service_result = {0};
|
||||
|
||||
void sle_sample_sle_enable_cbk(errcode_t status)
|
||||
{
|
||||
if (status == 0) {
|
||||
sle_start_scan();
|
||||
}
|
||||
}
|
||||
|
||||
void sle_sample_seek_enable_cbk(errcode_t status)
|
||||
{
|
||||
if (status == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void sle_sample_seek_disable_cbk(errcode_t status)
|
||||
{
|
||||
if (status == 0) {
|
||||
sle_connect_remote_device(&g_remote_addr);
|
||||
}
|
||||
}
|
||||
|
||||
void sle_sample_seek_result_info_cbk(sle_seek_result_info_t *seek_result_data)
|
||||
{
|
||||
if (seek_result_data != NULL) {
|
||||
(void)memcpy_s(&g_remote_addr, sizeof(sle_addr_t), &seek_result_data->addr, sizeof(sle_addr_t));
|
||||
sle_stop_seek();
|
||||
}
|
||||
}
|
||||
|
||||
void sle_sample_seek_cbk_register(void)
|
||||
{
|
||||
g_seek_cbk.sle_enable_cb = sle_sample_sle_enable_cbk;
|
||||
g_seek_cbk.seek_enable_cb = sle_sample_seek_enable_cbk;
|
||||
g_seek_cbk.seek_disable_cb = sle_sample_seek_disable_cbk;
|
||||
g_seek_cbk.seek_result_cb = sle_sample_seek_result_info_cbk;
|
||||
}
|
||||
|
||||
void sle_sample_connect_state_changed_cbk(uint16_t conn_id, const sle_addr_t *addr,
|
||||
sle_acb_state_t conn_state, sle_pair_state_t pair_state, sle_disc_reason_t disc_reason)
|
||||
{
|
||||
osal_printk("[ssap client] conn state changed conn_id:%d, addr:%02x***%02x%02x\n", conn_id, addr->addr[0],
|
||||
addr->addr[4], addr->addr[5]); /* 0 4 5: addr index */
|
||||
osal_printk("[ssap client] conn state changed disc_reason:0x%x\n", disc_reason);
|
||||
if (conn_state == SLE_ACB_STATE_CONNECTED) {
|
||||
if (pair_state == SLE_PAIR_NONE) {
|
||||
sle_pair_remote_device(&g_remote_addr);
|
||||
}
|
||||
g_conn_id = conn_id;
|
||||
}
|
||||
}
|
||||
|
||||
void sle_sample_pair_complete_cbk(uint16_t conn_id, const sle_addr_t *addr, errcode_t status)
|
||||
{
|
||||
osal_printk("[ssap client] pair complete conn_id:%d, addr:%02x***%02x%02x\n", conn_id, addr->addr[0],
|
||||
addr->addr[4], addr->addr[5]); /* 0 4 5: addr index */
|
||||
if (status == 0) {
|
||||
ssap_exchange_info_t info = {0};
|
||||
info.mtu_size = SLE_MTU_SIZE_DEFAULT;
|
||||
info.version = 1;
|
||||
ssapc_exchange_info_req(1, g_conn_id, &info);
|
||||
}
|
||||
}
|
||||
|
||||
void sle_sample_connect_cbk_register(void)
|
||||
{
|
||||
g_connect_cbk.connect_state_changed_cb = sle_sample_connect_state_changed_cbk;
|
||||
g_connect_cbk.pair_complete_cb = sle_sample_pair_complete_cbk;
|
||||
}
|
||||
|
||||
void sle_sample_exchange_info_cbk(uint8_t client_id, uint16_t conn_id, ssap_exchange_info_t *param,
|
||||
errcode_t status)
|
||||
{
|
||||
osal_printk("[ssap client] pair complete client id:%d status:%d\n", client_id, status);
|
||||
osal_printk("[ssap client] exchange mtu, mtu size: %d, version: %d.\n",
|
||||
param->mtu_size, param->version);
|
||||
|
||||
ssapc_find_structure_param_t find_param = {0};
|
||||
find_param.type = SSAP_FIND_TYPE_PRIMARY_SERVICE;
|
||||
find_param.start_hdl = 1;
|
||||
find_param.end_hdl = 0xFFFF;
|
||||
ssapc_find_structure(0, conn_id, &find_param);
|
||||
}
|
||||
|
||||
void sle_sample_find_structure_cbk(uint8_t client_id, uint16_t conn_id, ssapc_find_service_result_t *service,
|
||||
errcode_t status)
|
||||
{
|
||||
osal_printk("[ssap client] find structure cbk client: %d conn_id:%d status: %d \n",
|
||||
client_id, conn_id, status);
|
||||
osal_printk("[ssap client] find structure start_hdl:[0x%02x], end_hdl:[0x%02x], uuid len:%d\r\n",
|
||||
service->start_hdl, service->end_hdl, service->uuid.len);
|
||||
if (service->uuid.len == UUID_16BIT_LEN) {
|
||||
osal_printk("[ssap client] structure uuid:[0x%02x][0x%02x]\r\n",
|
||||
service->uuid.uuid[14], service->uuid.uuid[15]); /* 14 15: uuid index */
|
||||
} else {
|
||||
for (uint8_t idx = 0; idx < UUID_128BIT_LEN; idx++) {
|
||||
osal_printk("[ssap client] structure uuid[%d]:[0x%02x]\r\n", idx, service->uuid.uuid[idx]);
|
||||
}
|
||||
}
|
||||
g_find_service_result.start_hdl = service->start_hdl;
|
||||
g_find_service_result.end_hdl = service->end_hdl;
|
||||
memcpy_s(&g_find_service_result.uuid, sizeof(sle_uuid_t), &service->uuid, sizeof(sle_uuid_t));
|
||||
}
|
||||
|
||||
void sle_sample_find_structure_cmp_cbk(uint8_t client_id, uint16_t conn_id,
|
||||
ssapc_find_structure_result_t *structure_result, errcode_t status)
|
||||
{
|
||||
osal_printk("[ssap client] find structure cmp cbk client id:%d status:%d type:%d uuid len:%d \r\n",
|
||||
client_id, status, structure_result->type, structure_result->uuid.len);
|
||||
if (structure_result->uuid.len == UUID_16BIT_LEN) {
|
||||
osal_printk("[ssap client] find structure cmp cbk structure uuid:[0x%02x][0x%02x]\r\n",
|
||||
structure_result->uuid.uuid[14], structure_result->uuid.uuid[15]); /* 14 15: uuid index */
|
||||
} else {
|
||||
for (uint8_t idx = 0; idx < UUID_128BIT_LEN; idx++) {
|
||||
osal_printk("[ssap client] find structure cmp cbk structure uuid[%d]:[0x%02x]\r\n", idx,
|
||||
structure_result->uuid.uuid[idx]);
|
||||
}
|
||||
}
|
||||
uint8_t data[] = {0x11, 0x22, 0x33, 0x44};
|
||||
uint8_t len = sizeof(data);
|
||||
ssapc_write_param_t param = {0};
|
||||
param.handle = g_find_service_result.start_hdl;
|
||||
param.type = SSAP_PROPERTY_TYPE_VALUE;
|
||||
param.data_len = len;
|
||||
param.data = data;
|
||||
ssapc_write_req(0, conn_id, ¶m);
|
||||
}
|
||||
|
||||
void sle_sample_find_property_cbk(uint8_t client_id, uint16_t conn_id,
|
||||
ssapc_find_property_result_t *property, errcode_t status)
|
||||
{
|
||||
osal_printk("[ssap client] find property cbk, client id: %d, conn id: %d, operate ind: %d, "
|
||||
"descriptors count: %d status:%d.\n", client_id, conn_id, property->operate_indication,
|
||||
property->descriptors_count, status);
|
||||
for (uint16_t idx = 0; idx < property->descriptors_count; idx++) {
|
||||
osal_printk("[ssap client] find property cbk, descriptors type [%d]: 0x%02x.\n",
|
||||
idx, property->descriptors_type[idx]);
|
||||
}
|
||||
if (property->uuid.len == UUID_16BIT_LEN) {
|
||||
osal_printk("[ssap client] find property cbk, uuid: %02x %02x.\n",
|
||||
property->uuid.uuid[14], property->uuid.uuid[15]); /* 14 15: uuid index */
|
||||
} else if (property->uuid.len == UUID_128BIT_LEN) {
|
||||
for (uint16_t idx = 0; idx < UUID_128BIT_LEN; idx++) {
|
||||
osal_printk("[ssap client] find property cbk, uuid [%d]: %02x.\n",
|
||||
idx, property->uuid.uuid[idx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sle_sample_write_cfm_cbk(uint8_t client_id, uint16_t conn_id, ssapc_write_result_t *write_result,
|
||||
errcode_t status)
|
||||
{
|
||||
osal_printk("[ssap client] write cfm cbk, client id: %d status:%d.\n", client_id, status);
|
||||
ssapc_read_req(0, conn_id, write_result->handle, write_result->type);
|
||||
}
|
||||
|
||||
void sle_sample_read_cfm_cbk(uint8_t client_id, uint16_t conn_id, ssapc_handle_value_t *read_data,
|
||||
errcode_t status)
|
||||
{
|
||||
osal_printk("[ssap client] read cfm cbk client id: %d conn id: %d status: %d\n",
|
||||
client_id, conn_id, status);
|
||||
osal_printk("[ssap client] read cfm cbk handle: %d, type: %d , len: %d\n",
|
||||
read_data->handle, read_data->type, read_data->data_len);
|
||||
for (uint16_t idx = 0; idx < read_data->data_len; idx++) {
|
||||
osal_printk("[ssap client] read cfm cbk[%d] 0x%02x\r\n", idx, read_data->data[idx]);
|
||||
}
|
||||
}
|
||||
|
||||
void sle_sample_ssapc_cbk_register(void)
|
||||
{
|
||||
g_ssapc_cbk.exchange_info_cb = sle_sample_exchange_info_cbk;
|
||||
g_ssapc_cbk.find_structure_cb = sle_sample_find_structure_cbk;
|
||||
g_ssapc_cbk.find_structure_cmp_cb = sle_sample_find_structure_cmp_cbk;
|
||||
g_ssapc_cbk.ssapc_find_property_cbk = sle_sample_find_property_cbk;
|
||||
g_ssapc_cbk.write_cfm_cb = sle_sample_write_cfm_cbk;
|
||||
g_ssapc_cbk.read_cfm_cb = sle_sample_read_cfm_cbk;
|
||||
}
|
||||
|
||||
void sle_client_init()
|
||||
{
|
||||
sle_sample_seek_cbk_register();
|
||||
sle_sample_connect_cbk_register();
|
||||
sle_sample_ssapc_cbk_register();
|
||||
sle_announce_seek_register_callbacks(&g_seek_cbk);
|
||||
sle_connection_register_callbacks(&g_connect_cbk);
|
||||
ssapc_register_callbacks(&g_ssapc_cbk);
|
||||
enable_sle();
|
||||
}
|
||||
|
||||
void sle_start_scan()
|
||||
{
|
||||
sle_seek_param_t param = {0};
|
||||
param.own_addr_type = 0;
|
||||
param.filter_duplicates = 0;
|
||||
param.seek_filter_policy = 0;
|
||||
param.seek_phys = 1;
|
||||
param.seek_type[0] = 0;
|
||||
param.seek_interval[0] = SLE_SEEK_INTERVAL_DEFAULT;
|
||||
param.seek_window[0] = SLE_SEEK_WINDOW_DEFAULT;
|
||||
sle_set_seek_param(¶m);
|
||||
sle_start_seek();
|
||||
}
|
||||
|
||||
#define SLE_UUID_CLIENT_TASK_PRIO 26
|
||||
#define SLE_UUID_CLIENT_STACK_SIZE 0x2000
|
||||
|
||||
static void sle_uuid_client_entry(void)
|
||||
{
|
||||
osal_task *task_handle = NULL;
|
||||
osal_kthread_lock();
|
||||
task_handle= osal_kthread_create((osal_kthread_handler)sle_client_init, 0, "sle_gatt_client",
|
||||
SLE_UUID_CLIENT_STACK_SIZE);
|
||||
if (task_handle != NULL) {
|
||||
osal_kthread_set_priority(task_handle, SLE_UUID_CLIENT_TASK_PRIO);
|
||||
osal_kfree(task_handle);
|
||||
}
|
||||
osal_kthread_unlock();
|
||||
}
|
||||
|
||||
/* Run the app entry. */
|
||||
app_run(sle_uuid_client_entry);
|
8
application/samples/bt/sle/sle_uuid_server/CMakeLists.txt
Executable file
8
application/samples/bt/sle/sle_uuid_server/CMakeLists.txt
Executable file
@ -0,0 +1,8 @@
|
||||
#===============================================================================
|
||||
# @brief cmake file
|
||||
# Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
|
||||
#===============================================================================
|
||||
add_subdirectory_if_exist(src)
|
||||
|
||||
set(SOURCES "${SOURCES}" PARENT_SCOPE)
|
||||
set(PUBLIC_HEADER "${PUBLIC_HEADER}" "${CMAKE_CURRENT_SOURCE_DIR}/inc" PARENT_SCOPE)
|
91
application/samples/bt/sle/sle_uuid_server/inc/sle_server_adv.h
Executable file
91
application/samples/bt/sle/sle_uuid_server/inc/sle_server_adv.h
Executable file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd.. 2023. All rights reserved.
|
||||
*
|
||||
* Description: SLE ADV Config.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup bluetooth_sle_adv API
|
||||
* @ingroup
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef SLE_SERVER_ADV_H
|
||||
#define SLE_SERVER_ADV_H
|
||||
|
||||
/* 广播ID */
|
||||
#define SLE_ADV_HANDLE_DEFAULT 1
|
||||
|
||||
/**
|
||||
* @if Eng
|
||||
* @brief Definitaion of BLE ADV 通用广播结构.
|
||||
* @else
|
||||
* @brief SLE 广播普通数据结构。
|
||||
* @endif
|
||||
*/
|
||||
struct sle_adv_common_value {
|
||||
uint8_t length;
|
||||
uint8_t type;
|
||||
uint8_t value;
|
||||
};
|
||||
|
||||
/**
|
||||
* @if Eng
|
||||
* @brief Definitaion of BLE ADV Channel mapping.
|
||||
* @else
|
||||
* @brief SLE 广播信道映射。
|
||||
* @endif
|
||||
*/
|
||||
typedef enum {
|
||||
SLE_ADV_CHANNEL_MAP_77 = 0x01,
|
||||
SLE_ADV_CHANNEL_MAP_78 = 0x02,
|
||||
SLE_ADV_CHANNEL_MAP_79 = 0x04,
|
||||
SLE_ADV_CHANNEL_MAP_DEFAULT = 0x07
|
||||
} sle_adv_channel_map;
|
||||
|
||||
/**
|
||||
* @if Eng
|
||||
* @brief Definitaion of SLE ADV Data Type.
|
||||
* @else
|
||||
* @brief SLE 广播数据类型
|
||||
* @endif
|
||||
*/
|
||||
typedef enum {
|
||||
SLE_ADV_DATA_TYPE_DISCOVERY_LEVEL = 0x01, /*!< 发现等级 */
|
||||
SLE_ADV_DATA_TYPE_ACCESS_MODE = 0x02, /*!< 接入层能力 */
|
||||
SLE_ADV_DATA_TYPE_SERVICE_DATA_16BIT_UUID = 0x03, /*!< 标准服务数据信息 */
|
||||
SLE_ADV_DATA_TYPE_SERVICE_DATA_128BIT_UUID = 0x04, /*!< 自定义服务数据信息 */
|
||||
SLE_ADV_DATA_TYPE_COMPLETE_LIST_OF_16BIT_SERVICE_UUIDS = 0x05, /*!< 完整标准服务标识列表 */
|
||||
SLE_ADV_DATA_TYPE_COMPLETE_LIST_OF_128BIT_SERVICE_UUIDS = 0x06, /*!< 完整自定义服务标识列表 */
|
||||
SLE_ADV_DATA_TYPE_INCOMPLETE_LIST_OF_16BIT_SERVICE_UUIDS = 0x07, /*!< 部分标准服务标识列表 */
|
||||
SLE_ADV_DATA_TYPE_INCOMPLETE_LIST_OF_128BIT_SERVICE_UUIDS = 0x08, /*!< 部分自定义服务标识列表 */
|
||||
SLE_ADV_DATA_TYPE_SERVICE_STRUCTURE_HASH_VALUE = 0x09, /*!< 服务结构散列值 */
|
||||
SLE_ADV_DATA_TYPE_SHORTENED_LOCAL_NAME = 0x0A, /*!< 设备缩写本地名称 */
|
||||
SLE_ADV_DATA_TYPE_COMPLETE_LOCAL_NAME = 0x0B, /*!< 设备完整本地名称 */
|
||||
SLE_ADV_DATA_TYPE_TX_POWER_LEVEL = 0x0C, /*!< 广播发送功率 */
|
||||
SLE_ADV_DATA_TYPE_SLB_COMMUNICATION_DOMAIN = 0x0D, /*!< SLB通信域域名 */
|
||||
SLE_ADV_DATA_TYPE_SLB_MEDIA_ACCESS_LAYER_ID = 0x0E, /*!< SLB媒体接入层标识 */
|
||||
SLE_ADV_DATA_TYPE_EXTENDED = 0xFE, /*!< 数据类型扩展 */
|
||||
SLE_ADV_DATA_TYPE_MANUFACTURER_SPECIFIC_DATA = 0xFF /*!< 厂商自定义信息 */
|
||||
} sle_adv_data_type;
|
||||
|
||||
|
||||
/**
|
||||
* @if Eng
|
||||
* @brief sle adv data config.
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS Excute successfully
|
||||
* @retval ERRCODE_SLE_FAIL Execute fail
|
||||
* @par Dependency:
|
||||
* @li NULL
|
||||
* @else
|
||||
* @brief sle广播数据配置。
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS 执行成功
|
||||
* @retval ERRCODE_SLE_FAIL 执行失败
|
||||
* @par 依赖:
|
||||
* @li NULL
|
||||
* @endif
|
||||
*/
|
||||
errcode_t sle_uuid_server_adv_init(void);
|
||||
#endif
|
89
application/samples/bt/sle/sle_uuid_server/inc/sle_uuid_server.h
Executable file
89
application/samples/bt/sle/sle_uuid_server/inc/sle_uuid_server.h
Executable file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd.. 2022. All rights reserved.
|
||||
*
|
||||
* Description: SLE UUID Server module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup SLE UUID SERVER API
|
||||
* @ingroup
|
||||
* @{
|
||||
*/
|
||||
#ifndef SLE_UUID_SERVER_H
|
||||
#define SLE_UUID_SERVER_H
|
||||
|
||||
#include "sle_ssap_server.h"
|
||||
|
||||
/* Service UUID */
|
||||
#define SLE_UUID_SERVER_SERVICE 0xABCD
|
||||
|
||||
/* Property UUID */
|
||||
#define SLE_UUID_SERVER_NTF_REPORT 0x1122
|
||||
|
||||
/* Property Property */
|
||||
#define SLE_UUID_TEST_PROPERTIES (SSAP_PERMISSION_READ | SSAP_PERMISSION_WRITE)
|
||||
|
||||
/* Descriptor Property */
|
||||
#define SLE_UUID_TEST_DESCRIPTOR (SSAP_PERMISSION_READ | SSAP_PERMISSION_WRITE)
|
||||
|
||||
/**
|
||||
* @if Eng
|
||||
* @brief SLE uuid server inir.
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS Excute successfully
|
||||
* @retval ERRCODE_SLE_FAIL Execute fail
|
||||
* @par Dependency:
|
||||
* @li sle_ssap_server.h
|
||||
* @else
|
||||
* @brief SLE UUID服务器初始化。
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS 执行成功
|
||||
* @retval ERRCODE_SLE_FAIL 执行失败
|
||||
* @par 依赖:
|
||||
* @li sle_ssap_server.h
|
||||
* @endif
|
||||
*/
|
||||
errcode_t sle_uuid_server_init(void);
|
||||
|
||||
/**
|
||||
* @if Eng
|
||||
* @brief send data to peer device by uuid on uuid server.
|
||||
* @attention NULL
|
||||
* @param [in] value send value.
|
||||
* @param [in] len Length of send value。
|
||||
* @retval ERRCODE_SLE_SUCCESS Excute successfully
|
||||
* @retval ERRCODE_SLE_FAIL Execute fail
|
||||
* @par Dependency:
|
||||
* @li sle_ssap_server.h
|
||||
* @else
|
||||
* @brief 通过uuid server 发送数据给对端。
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS 执行成功
|
||||
* @retval ERRCODE_SLE_FAIL 执行失败
|
||||
* @par 依赖:
|
||||
* @li sle_ssap_server.h
|
||||
* @endif
|
||||
*/
|
||||
errcode_t sle_uuid_server_send_report_by_uuid(const uint8_t *data, uint16_t len);
|
||||
|
||||
/**
|
||||
* @if Eng
|
||||
* @brief send data to peer device by handle on uuid server.
|
||||
* @attention NULL
|
||||
* @param [in] value send value.
|
||||
* @param [in] len Length of send value。
|
||||
* @retval ERRCODE_SLE_SUCCESS Excute successfully
|
||||
* @retval ERRCODE_SLE_FAIL Execute fail
|
||||
* @par Dependency:
|
||||
* @li sle_ssap_server.h
|
||||
* @else
|
||||
* @brief 通过uuid server 发送数据给对端。
|
||||
* @attention NULL
|
||||
* @retval ERRCODE_SLE_SUCCESS 执行成功
|
||||
* @retval ERRCODE_SLE_FAIL 执行失败
|
||||
* @par 依赖:
|
||||
* @li sle_ssap_server.h
|
||||
* @endif
|
||||
*/
|
||||
errcode_t sle_uuid_server_send_report_by_handle(const uint8_t *data, uint8_t len);
|
||||
#endif
|
8
application/samples/bt/sle/sle_uuid_server/src/CMakeLists.txt
Executable file
8
application/samples/bt/sle/sle_uuid_server/src/CMakeLists.txt
Executable file
@ -0,0 +1,8 @@
|
||||
#===============================================================================
|
||||
# @brief cmake file
|
||||
# Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
|
||||
#===============================================================================
|
||||
set(SOURCES "${SOURCES}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/sle_server_adv.c"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/sle_uuid_server.c"
|
||||
PARENT_SCOPE)
|
198
application/samples/bt/sle/sle_uuid_server/src/sle_server_adv.c
Executable file
198
application/samples/bt/sle/sle_uuid_server/src/sle_server_adv.c
Executable file
@ -0,0 +1,198 @@
|
||||
/*
|
||||
* Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd.. 2023. All rights reserved.
|
||||
* Description: sle adv config for sle uuid server.
|
||||
*/
|
||||
#include "securec.h"
|
||||
#include "errcode.h"
|
||||
#include "osal_addr.h"
|
||||
#include "osal_debug.h"
|
||||
#include "sle_common.h"
|
||||
#include "sle_device_discovery.h"
|
||||
#include "sle_errcode.h"
|
||||
#include "sle_server_adv.h"
|
||||
|
||||
/* sle device name */
|
||||
#define NAME_MAX_LENGTH 15
|
||||
/* 连接调度间隔12.5ms,单位125us */
|
||||
#define SLE_CONN_INTV_MIN_DEFAULT 0x64
|
||||
/* 连接调度间隔12.5ms,单位125us */
|
||||
#define SLE_CONN_INTV_MAX_DEFAULT 0x64
|
||||
/* 连接调度间隔25ms,单位125us */
|
||||
#define SLE_ADV_INTERVAL_MIN_DEFAULT 0xC8
|
||||
/* 连接调度间隔25ms,单位125us */
|
||||
#define SLE_ADV_INTERVAL_MAX_DEFAULT 0xC8
|
||||
/* 超时时间5000ms,单位10ms */
|
||||
#define SLE_CONN_SUPERVISION_TIMEOUT_DEFAULT 0x1F4
|
||||
/* 超时时间4990ms,单位10ms */
|
||||
#define SLE_CONN_MAX_LATENCY 0x1F3
|
||||
/* 广播发送功率 */
|
||||
#define SLE_ADV_TX_POWER 10
|
||||
/* 最大广播数据长度 */
|
||||
#define SLE_ADV_DATA_LEN_MAX 251
|
||||
/* 广播名称 */
|
||||
uint8_t sle_local_name[ NAME_MAX_LENGTH] = { 's', 'l', 'e', '_', 'u', 'u', 'i', 'd', '_', 's',
|
||||
'e', 'r', 'v', 'e', 'r' };
|
||||
|
||||
static uint16_t sle_set_adv_local_name(uint8_t *adv_data, uint16_t max_len)
|
||||
{
|
||||
errno_t ret;
|
||||
uint8_t index = 0;
|
||||
|
||||
uint8_t *local_name = sle_local_name;
|
||||
uint8_t local_name_len = (uint8_t)strlen((char *)local_name);
|
||||
for (uint8_t i = 0; i < local_name_len; i++) {
|
||||
osal_printk("local_name[%d] = 0x%02x\r\n", i, local_name[i]);
|
||||
}
|
||||
|
||||
adv_data[index++] = local_name_len + 1;
|
||||
adv_data[index++] = SLE_ADV_DATA_TYPE_COMPLETE_LOCAL_NAME;
|
||||
ret = memcpy_s(&adv_data[index], max_len - index, local_name, local_name_len);
|
||||
if (ret != EOK) {
|
||||
osal_printk("memcpy fail\r\n");
|
||||
return 0;
|
||||
}
|
||||
return (uint16_t)index + local_name_len;
|
||||
}
|
||||
|
||||
static uint16_t sle_set_adv_data(uint8_t *adv_data)
|
||||
{
|
||||
size_t len = 0;
|
||||
uint16_t idx = 0;
|
||||
errno_t ret = 0;
|
||||
|
||||
len = sizeof(struct sle_adv_common_value);
|
||||
struct sle_adv_common_value adv_disc_level = {
|
||||
.length = len - 1,
|
||||
.type = SLE_ADV_DATA_TYPE_DISCOVERY_LEVEL,
|
||||
.value = SLE_ANNOUNCE_LEVEL_NORMAL,
|
||||
};
|
||||
ret = memcpy_s(&adv_data[idx], SLE_ADV_DATA_LEN_MAX - idx, &adv_disc_level, len);
|
||||
if (ret != EOK) {
|
||||
osal_printk("adv_disc_level memcpy fail\r\n");
|
||||
return 0;
|
||||
}
|
||||
idx += len;
|
||||
|
||||
len = sizeof(struct sle_adv_common_value);
|
||||
struct sle_adv_common_value adv_access_mode = {
|
||||
.length = len - 1,
|
||||
.type = SLE_ADV_DATA_TYPE_ACCESS_MODE,
|
||||
.value = 0,
|
||||
};
|
||||
ret = memcpy_s(&adv_data[idx], SLE_ADV_DATA_LEN_MAX - idx, &adv_access_mode, len);
|
||||
if (ret != EOK) {
|
||||
osal_printk("memcpy fail\r\n");
|
||||
return 0;
|
||||
}
|
||||
idx += len;
|
||||
return idx;
|
||||
}
|
||||
|
||||
static uint16_t sle_set_scan_response_data(uint8_t *scan_rsp_data)
|
||||
{
|
||||
uint16_t idx = 0;
|
||||
errno_t ret;
|
||||
size_t scan_rsp_data_len = sizeof(struct sle_adv_common_value);
|
||||
|
||||
struct sle_adv_common_value tx_power_level = {
|
||||
.length = scan_rsp_data_len - 1,
|
||||
.type = SLE_ADV_DATA_TYPE_TX_POWER_LEVEL,
|
||||
.value = SLE_ADV_TX_POWER,
|
||||
};
|
||||
ret = memcpy_s(scan_rsp_data, SLE_ADV_DATA_LEN_MAX, &tx_power_level, scan_rsp_data_len);
|
||||
if (ret != EOK) {
|
||||
osal_printk("sle scan response data memcpy fail\r\n");
|
||||
return 0;
|
||||
}
|
||||
idx += scan_rsp_data_len;
|
||||
|
||||
/* set local name */
|
||||
idx += sle_set_adv_local_name(&scan_rsp_data[idx], SLE_ADV_DATA_LEN_MAX - idx);
|
||||
return idx;
|
||||
}
|
||||
|
||||
static int sle_set_default_announce_param(void)
|
||||
{
|
||||
sle_announce_param_t param = {0};
|
||||
param.announce_mode = SLE_ANNOUNCE_MODE_CONNECTABLE_SCANABLE;
|
||||
param.announce_handle = SLE_ADV_HANDLE_DEFAULT;
|
||||
param.announce_gt_role = SLE_ANNOUNCE_ROLE_T_CAN_NEGO;
|
||||
param.announce_level = SLE_ANNOUNCE_LEVEL_NORMAL;
|
||||
param.announce_channel_map = SLE_ADV_CHANNEL_MAP_DEFAULT;
|
||||
param.announce_interval_min = SLE_ADV_INTERVAL_MIN_DEFAULT;
|
||||
param.announce_interval_max = SLE_ADV_INTERVAL_MAX_DEFAULT;
|
||||
param.conn_interval_min = SLE_CONN_INTV_MIN_DEFAULT;
|
||||
param.conn_interval_max = SLE_CONN_INTV_MAX_DEFAULT;
|
||||
param.conn_max_latency = SLE_CONN_MAX_LATENCY;
|
||||
param.conn_supervision_timeout = SLE_CONN_SUPERVISION_TIMEOUT_DEFAULT;
|
||||
return sle_set_announce_param(param.announce_handle, ¶m);
|
||||
}
|
||||
|
||||
static int sle_set_default_announce_data(void)
|
||||
{
|
||||
errcode_t ret;
|
||||
uint8_t announce_data_len = 0;
|
||||
uint8_t seek_data_len = 0;
|
||||
sle_announce_data_t data = {0};
|
||||
uint8_t adv_handle = SLE_ADV_HANDLE_DEFAULT;
|
||||
uint8_t announce_data[SLE_ADV_DATA_LEN_MAX] = {0};
|
||||
uint8_t seek_rsp_data[SLE_ADV_DATA_LEN_MAX] = {0};
|
||||
|
||||
osal_printk("set adv data default\r\n");
|
||||
announce_data_len = sle_set_adv_data(announce_data);
|
||||
data.announce_data = announce_data;
|
||||
data.announce_data_len = announce_data_len;
|
||||
|
||||
seek_data_len = sle_set_scan_response_data(seek_rsp_data);
|
||||
data.seek_rsp_data = seek_rsp_data;
|
||||
data.seek_rsp_data_len = seek_data_len;
|
||||
|
||||
ret = sle_set_announce_data(adv_handle, &data);
|
||||
if (ret == ERRCODE_SLE_SUCCESS) {
|
||||
osal_printk("[SLE DD SDK] set announce data success.");
|
||||
} else {
|
||||
osal_printk("[SLE DD SDK] set adv param fail.");
|
||||
}
|
||||
return ERRCODE_SLE_SUCCESS;
|
||||
}
|
||||
|
||||
void sle_announce_enable_cbk(uint32_t announce_id, errcode_t status)
|
||||
{
|
||||
osal_printk("sle announce enable id:%02x, state:%02x\r\n", announce_id, status);
|
||||
}
|
||||
|
||||
void sle_announce_disable_cbk(uint32_t announce_id, errcode_t status)
|
||||
{
|
||||
osal_printk("sle announce disable id:%02x, state:%02x\r\n", announce_id, status);
|
||||
}
|
||||
|
||||
void sle_announce_terminal_cbk(uint32_t announce_id)
|
||||
{
|
||||
osal_printk("sle announce terminal id:%02x\r\n", announce_id);
|
||||
}
|
||||
|
||||
void sle_enable_cbk(errcode_t status)
|
||||
{
|
||||
osal_printk("sle enable status:%02x\r\n", status);
|
||||
}
|
||||
|
||||
void sle_announce_register_cbks(void)
|
||||
{
|
||||
sle_announce_seek_callbacks_t seek_cbks = {0};
|
||||
seek_cbks.announce_enable_cb = sle_announce_enable_cbk;
|
||||
seek_cbks.announce_disable_cb = sle_announce_disable_cbk;
|
||||
seek_cbks.announce_terminal_cb = sle_announce_terminal_cbk;
|
||||
seek_cbks.sle_enable_cb = sle_enable_cbk;
|
||||
sle_announce_seek_register_callbacks(&seek_cbks);
|
||||
}
|
||||
|
||||
errcode_t sle_uuid_server_adv_init(void)
|
||||
{
|
||||
osal_printk("sle_uuid_server_adv_init in\r\n");
|
||||
sle_announce_register_cbks();
|
||||
sle_set_default_announce_param();
|
||||
sle_set_default_announce_data();
|
||||
sle_start_announce(SLE_ADV_HANDLE_DEFAULT);
|
||||
osal_printk("sle_uuid_server_adv_init out\r\n");
|
||||
return ERRCODE_SLE_SUCCESS;
|
||||
}
|
297
application/samples/bt/sle/sle_uuid_server/src/sle_uuid_server.c
Executable file
297
application/samples/bt/sle/sle_uuid_server/src/sle_uuid_server.c
Executable file
@ -0,0 +1,297 @@
|
||||
/*
|
||||
* Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd.. 2023. All rights reserved.
|
||||
* Description: sle uuid server sample.
|
||||
*/
|
||||
#include "securec.h"
|
||||
#include "errcode.h"
|
||||
#include "osal_addr.h"
|
||||
#include "soc_osal.h"
|
||||
#include "app_init.h"
|
||||
#include "sle_common.h"
|
||||
#include "sle_errcode.h"
|
||||
#include "sle_ssap_server.h"
|
||||
#include "sle_connection_manager.h"
|
||||
#include "sle_device_discovery.h"
|
||||
#include "sle_server_adv.h"
|
||||
#include "sle_uuid_server.h"
|
||||
|
||||
#define OCTET_BIT_LEN 8
|
||||
#define UUID_LEN_2 2
|
||||
#define BT_INDEX_4 4
|
||||
#define BT_INDEX_5 5
|
||||
#define BT_INDEX_0 0
|
||||
|
||||
#define encode2byte_little(_ptr, data) \
|
||||
do { \
|
||||
*(uint8_t *)((_ptr) + 1) = (uint8_t)((data) >> 8); \
|
||||
*(uint8_t *)(_ptr) = (uint8_t)(data); \
|
||||
} while (0)
|
||||
|
||||
/* sle server app uuid for test */
|
||||
char g_sle_uuid_app_uuid[UUID_LEN_2] = {0x0, 0x0};
|
||||
/* server notify property uuid for test */
|
||||
char g_sle_property_value[OCTET_BIT_LEN] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
|
||||
/* sle connect acb handle */
|
||||
uint16_t g_sle_conn_hdl = 0;
|
||||
/* sle server handle */
|
||||
uint8_t g_server_id = 0;
|
||||
/* sle service handle */
|
||||
uint16_t g_service_handle = 0;
|
||||
/* sle ntf property handle */
|
||||
uint16_t g_property_handle = 0;
|
||||
|
||||
static uint8_t sle_uuid_base[] = { 0x37, 0xBE, 0xA8, 0x80, 0xFC, 0x70, 0x11, 0xEA, \
|
||||
0xB7, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
static void sle_uuid_set_base(sle_uuid_t *out)
|
||||
{
|
||||
(void)memcpy_s(out->uuid, SLE_UUID_LEN, sle_uuid_base, SLE_UUID_LEN);
|
||||
out->len = UUID_LEN_2;
|
||||
}
|
||||
|
||||
static void sle_uuid_setu2(uint16_t u2, sle_uuid_t *out)
|
||||
{
|
||||
sle_uuid_set_base(out);
|
||||
out->len = UUID_LEN_2;
|
||||
encode2byte_little(&out->uuid[14], u2);
|
||||
}
|
||||
|
||||
static void ssaps_read_request_cbk(uint8_t server_id, uint16_t conn_id, ssaps_req_read_cb_t *read_cb_para,
|
||||
errcode_t status)
|
||||
{
|
||||
osal_printk("[uuid server] ssaps read request cbk server_id:%x, conn_id:%x, handle:%x, status:%x\r\n",
|
||||
server_id, conn_id, read_cb_para->handle, status);
|
||||
}
|
||||
|
||||
static void ssaps_write_request_cbk(uint8_t server_id, uint16_t conn_id, ssaps_req_write_cb_t *write_cb_para,
|
||||
errcode_t status)
|
||||
{
|
||||
osal_printk("[uuid server] ssaps write request cbk server_id:%x, conn_id:%x, handle:%x, status:%x\r\n",
|
||||
server_id, conn_id, write_cb_para->handle, status);
|
||||
}
|
||||
|
||||
static void ssaps_mtu_changed_cbk(uint8_t server_id, uint16_t conn_id, ssap_exchange_info_t *mtu_size,
|
||||
errcode_t status)
|
||||
{
|
||||
osal_printk("[uuid server] ssaps write request cbk server_id:%x, conn_id:%x, mtu_size:%x, status:%x\r\n",
|
||||
server_id, conn_id, mtu_size->mtu_size, status);
|
||||
}
|
||||
|
||||
static void ssaps_start_service_cbk(uint8_t server_id, uint16_t handle, errcode_t status)
|
||||
{
|
||||
osal_printk("[uuid server] start service cbk server_id:%x, handle:%x, status:%x\r\n",
|
||||
server_id, handle, status);
|
||||
}
|
||||
|
||||
static void sle_ssaps_register_cbks(void)
|
||||
{
|
||||
ssaps_callbacks_t ssaps_cbk = {0};
|
||||
ssaps_cbk.start_service_cb = ssaps_start_service_cbk;
|
||||
ssaps_cbk.mtu_changed_cb = ssaps_mtu_changed_cbk;
|
||||
ssaps_cbk.read_request_cb = ssaps_read_request_cbk;
|
||||
ssaps_cbk.write_request_cb = ssaps_write_request_cbk;
|
||||
ssaps_register_callbacks(&ssaps_cbk);
|
||||
}
|
||||
|
||||
static errcode_t sle_uuid_server_service_add(void)
|
||||
{
|
||||
errcode_t ret;
|
||||
sle_uuid_t service_uuid = {0};
|
||||
sle_uuid_setu2(SLE_UUID_SERVER_SERVICE, &service_uuid);
|
||||
ret = ssaps_add_service_sync(g_server_id, &service_uuid, 1, &g_service_handle);
|
||||
if (ret != ERRCODE_SLE_SUCCESS) {
|
||||
osal_printk("[uuid server] sle uuid add service fail, ret:%x\r\n", ret);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
return ERRCODE_SLE_SUCCESS;
|
||||
}
|
||||
|
||||
static errcode_t sle_uuid_server_property_add(void)
|
||||
{
|
||||
errcode_t ret;
|
||||
ssaps_property_info_t property = {0};
|
||||
ssaps_desc_info_t descriptor = {0};
|
||||
uint8_t ntf_value[] = {0x01, 0x0};
|
||||
|
||||
property.permissions = SLE_UUID_TEST_PROPERTIES;
|
||||
sle_uuid_setu2(SLE_UUID_SERVER_NTF_REPORT, &property.uuid);
|
||||
property.value = osal_vmalloc(sizeof(g_sle_property_value));
|
||||
if (property.value == NULL) {
|
||||
osal_printk("[uuid server] sle property mem fail\r\n");
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
if (memcpy_s(property.value, sizeof(g_sle_property_value), g_sle_property_value,
|
||||
sizeof(g_sle_property_value)) != EOK) {
|
||||
osal_vfree(property.value);
|
||||
osal_printk("[uuid server] sle property mem cpy fail\r\n");
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
ret = ssaps_add_property_sync(g_server_id, g_service_handle, &property, &g_property_handle);
|
||||
if (ret != ERRCODE_SLE_SUCCESS) {
|
||||
osal_printk("[uuid server] sle uuid add property fail, ret:%x\r\n", ret);
|
||||
osal_vfree(property.value);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
descriptor.permissions = SLE_UUID_TEST_DESCRIPTOR;
|
||||
descriptor.value = osal_vmalloc(sizeof(ntf_value));
|
||||
if (descriptor.value == NULL) {
|
||||
osal_printk("[uuid server] sle descriptor mem fail\r\n");
|
||||
osal_vfree(property.value);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
if (memcpy_s(descriptor.value, sizeof(ntf_value), ntf_value, sizeof(ntf_value)) != EOK) {
|
||||
osal_printk("[uuid server] sle descriptor mem cpy fail\r\n");
|
||||
osal_vfree(property.value);
|
||||
osal_vfree(descriptor.value);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
ret = ssaps_add_descriptor_sync(g_server_id, g_service_handle, g_property_handle, &descriptor);
|
||||
if (ret != ERRCODE_SLE_SUCCESS) {
|
||||
osal_printk("[uuid server] sle uuid add descriptor fail, ret:%x\r\n", ret);
|
||||
osal_vfree(property.value);
|
||||
osal_vfree(descriptor.value);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
osal_vfree(property.value);
|
||||
osal_vfree(descriptor.value);
|
||||
return ERRCODE_SLE_SUCCESS;
|
||||
}
|
||||
|
||||
static errcode_t sle_uuid_server_add(void)
|
||||
{
|
||||
errcode_t ret;
|
||||
sle_uuid_t app_uuid = {0};
|
||||
|
||||
osal_printk("[uuid server] sle uuid add service in\r\n");
|
||||
app_uuid.len = sizeof(g_sle_uuid_app_uuid);
|
||||
if (memcpy_s(app_uuid.uuid, app_uuid.len, g_sle_uuid_app_uuid, sizeof(g_sle_uuid_app_uuid)) != EOK) {
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
ssaps_register_server(&app_uuid, &g_server_id);
|
||||
|
||||
if (sle_uuid_server_service_add() != ERRCODE_SLE_SUCCESS) {
|
||||
ssaps_unregister_server(g_server_id);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
|
||||
if (sle_uuid_server_property_add() != ERRCODE_SLE_SUCCESS) {
|
||||
ssaps_unregister_server(g_server_id);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
osal_printk("[uuid server] sle uuid add service, server_id:%x, service_handle:%x, property_handle:%x\r\n",
|
||||
g_server_id, g_service_handle, g_property_handle);
|
||||
ret = ssaps_start_service(g_server_id, g_service_handle);
|
||||
if (ret != ERRCODE_SLE_SUCCESS) {
|
||||
osal_printk("[uuid server] sle uuid add service fail, ret:%x\r\n", ret);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
osal_printk("[uuid server] sle uuid add service out\r\n");
|
||||
return ERRCODE_SLE_SUCCESS;
|
||||
}
|
||||
|
||||
/* device通过uuid向host发送数据:report */
|
||||
errcode_t sle_uuid_server_send_report_by_uuid(const uint8_t *data, uint16_t len)
|
||||
{
|
||||
ssaps_ntf_ind_by_uuid_t param = {0};
|
||||
param.type = SSAP_PROPERTY_TYPE_VALUE;
|
||||
param.start_handle = g_service_handle;
|
||||
param.end_handle = g_property_handle;
|
||||
param.value_len = len;
|
||||
param.value = osal_vmalloc(len);
|
||||
if (param.value == NULL) {
|
||||
osal_printk("[uuid server] send report new fail\r\n");
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
if (memcpy_s(param.value, param.value_len, data, len) != EOK) {
|
||||
osal_printk("[uuid server] send input report memcpy fail\r\n");
|
||||
osal_vfree(param.value);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
sle_uuid_setu2(SLE_UUID_SERVER_NTF_REPORT, ¶m.uuid);
|
||||
ssaps_notify_indicate_by_uuid(g_server_id, g_sle_conn_hdl, ¶m);
|
||||
osal_vfree(param.value);
|
||||
return ERRCODE_SLE_SUCCESS;
|
||||
}
|
||||
|
||||
/* device通过handle向host发送数据:report */
|
||||
errcode_t sle_uuid_server_send_report_by_handle(const uint8_t *data, uint8_t len)
|
||||
{
|
||||
ssaps_ntf_ind_t param = {0};
|
||||
|
||||
param.handle = g_property_handle;
|
||||
param.type = SSAP_PROPERTY_TYPE_VALUE;
|
||||
param.value = osal_vmalloc(len);
|
||||
param.value_len = len;
|
||||
if (param.value == NULL) {
|
||||
osal_printk("[uuid server] send report new fail\r\n");
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
if (memcpy_s(param.value, param.value_len, data, len) != EOK) {
|
||||
osal_printk("[uuid server] send input report memcpy fail\r\n");
|
||||
osal_vfree(param.value);
|
||||
return ERRCODE_SLE_FAIL;
|
||||
}
|
||||
ssaps_notify_indicate(g_server_id, g_sle_conn_hdl, ¶m);
|
||||
osal_vfree(param.value);
|
||||
return ERRCODE_SLE_SUCCESS;
|
||||
}
|
||||
|
||||
static void sle_connect_state_changed_cbk(uint16_t conn_id, const sle_addr_t *addr,
|
||||
sle_acb_state_t conn_state, sle_pair_state_t pair_state, sle_disc_reason_t disc_reason)
|
||||
{
|
||||
osal_printk("[uuid server] connect state changed conn_id:0x%02x, conn_state:0x%x, pair_state:0x%x, \
|
||||
disc_reason:0x%x\r\n", conn_id, conn_state, pair_state, disc_reason);
|
||||
osal_printk("[uuid server] connect state changed addr:%02x:**:**:**:%02x:%02x\r\n",
|
||||
addr->addr[BT_INDEX_0], addr->addr[BT_INDEX_4], addr->addr[BT_INDEX_5]);
|
||||
g_sle_conn_hdl = conn_id;
|
||||
if (conn_state == SLE_ACB_STATE_DISCONNECTED) {
|
||||
sle_start_announce(SLE_ADV_HANDLE_DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
static void sle_pair_complete_cbk(uint16_t conn_id, const sle_addr_t *addr, errcode_t status)
|
||||
{
|
||||
osal_printk("[uuid server] pair complete conn_id:%02x, status:%x\r\n",
|
||||
conn_id, status);
|
||||
osal_printk("[uuid server] pair complete addr:%02x:**:**:**:%02x:%02x\r\n",
|
||||
addr->addr[BT_INDEX_0], addr->addr[BT_INDEX_4], addr->addr[BT_INDEX_5]);
|
||||
}
|
||||
|
||||
static void sle_conn_register_cbks(void)
|
||||
{
|
||||
sle_connection_callbacks_t conn_cbks = {0};
|
||||
conn_cbks.connect_state_changed_cb = sle_connect_state_changed_cbk;
|
||||
conn_cbks.pair_complete_cb = sle_pair_complete_cbk;
|
||||
sle_connection_register_callbacks(&conn_cbks);
|
||||
}
|
||||
|
||||
/* 初始化uuid server */
|
||||
errcode_t sle_uuid_server_init(void)
|
||||
{
|
||||
enable_sle();
|
||||
sle_conn_register_cbks();
|
||||
sle_ssaps_register_cbks();
|
||||
sle_uuid_server_add();
|
||||
sle_uuid_server_adv_init();
|
||||
osal_printk("[uuid server] init ok\r\n");
|
||||
return ERRCODE_SLE_SUCCESS;
|
||||
}
|
||||
|
||||
#define SLE_UUID_SERVER_TASK_PRIO 26
|
||||
#define SLE_UUID_SERVER_STACK_SIZE 0x2000
|
||||
|
||||
static void sle_uuid_server_entry(void)
|
||||
{
|
||||
osal_task *task_handle = NULL;
|
||||
osal_kthread_lock();
|
||||
task_handle= osal_kthread_create((osal_kthread_handler)sle_uuid_server_init, 0, "sle_uuid_server",
|
||||
SLE_UUID_SERVER_STACK_SIZE);
|
||||
if (task_handle != NULL) {
|
||||
osal_kthread_set_priority(task_handle, SLE_UUID_SERVER_TASK_PRIO);
|
||||
osal_kfree(task_handle);
|
||||
}
|
||||
osal_kthread_unlock();
|
||||
}
|
||||
|
||||
/* Run the app entry. */
|
||||
app_run(sle_uuid_server_entry);
|
Reference in New Issue
Block a user