Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BLE GAP Service 添加多个特性出错 #13

Open
DaZeng1995 opened this issue Feb 23, 2021 · 0 comments
Open

BLE GAP Service 添加多个特性出错 #13

DaZeng1995 opened this issue Feb 23, 2021 · 0 comments

Comments

@DaZeng1995
Copy link

默认BLE GAP Service中只有一个device name特性,于是我按照Battery Service添加了一个appearance。但是添加之后手机连接蓝牙显示GAP Service为空,也就是出错了。添加代码如下:
图片

//------------------------bt_gatt.c--------------------------------------------------------
uint8_t gatt_gap_uuid[] = {BT_LE_U16_TO_ARRAY(BT_UUID_SERVCLASS_GAP_SERVER)};
uint8_t gatt_gap_characteristic[] = {GATT_CHAR_PROP_BIT_READ,BT_LE_U16_TO_ARRAY(GATT_GAP_NAME_HANDLE),BT_LE_U16_TO_ARRAY(GATT_UUID_GAP_DEVICE_NAME)};

uint8_t gatt_gap_icon_characteristic[] = {GATT_CHAR_PROP_BIT_READ,BT_LE_U16_TO_ARRAY(GATT_GAP_ICON_HANDLE),BT_LE_U16_TO_ARRAY(GATT_UUID_GAP_ICON)};
uint8_t gatt_gap_appearance[] = {0,0};

gatt_server_service_t gap_service[] =
{
{ GATT_GAP_SERVICE_HANDLE,GATT_UUID_PRI_SERVICE,
gatt_gap_uuid,sizeof(gatt_gap_uuid),GATT_PERM_READ,NULL},

{ GATT_GAP_CHARACTERISTIC_HANDLE,GATT_UUID_CHAR_DECLARE,
	gatt_gap_characteristic,sizeof(gatt_gap_characteristic),GATT_PERM_READ,NULL},
	
{ GATT_GAP_NAME_HANDLE,GATT_UUID_GAP_DEVICE_NAME,
	(uint8_t*)GATT_GAP_NAME,sizeof(GATT_GAP_NAME),GATT_PERM_READ,NULL},
	
	{ GATT_GAP_ICON_CHARACTERISTIC_HANDLE,GATT_UUID_CHAR_DECLARE,
	gatt_gap_icon_characteristic,sizeof(gatt_gap_icon_characteristic),GATT_PERM_READ,NULL},
	 
	 { GATT_GAP_ICON_HANDLE,GATT_UUID_GAP_ICON,
		gatt_server_change,sizeof(gatt_server_change),GATT_PERM_READ,NULL},

};

err_t gatt_server_init(void)
{
gatt_server_add_pri_service(gap_service,GATT_GAP_SERVICE_HANDLE,GATT_GAP_ICON_HANDLE,sizeof(gap_service)/sizeof(gatt_server_service_t),BT_UUID_SERVCLASS_GAP_SERVER);
gatt_server_add_pri_service(gatt_service,GATT_SERVICE_HANLE,GATT_SRV_CHGD_CLIENT_CHARA_CONF_HANDLE,sizeof(gatt_service)/sizeof(gatt_server_service_t),BT_UUID_SERVCLASS_GATT_SERVER);

return BT_ERR_OK;

}
//--------------------------bt_config.h------------------------------------------------------
#define GATT_PRI_SERVICE_MAX_COUNT 15
#define GATT_BLE_MTU_SIZE 23
#define GATT_GAP_SERVICE_HANDLE 0x0001
#define GATT_GAP_CHARACTERISTIC_HANDLE 0x0002
#define GATT_GAP_NAME_HANDLE 0x0003
#define GATT_GAP_ICON_CHARACTERISTIC_HANDLE 0x0004
#define GATT_GAP_ICON_HANDLE 0x0005

#define GATT_SERVICE_HANLE 0x0006
#define GATT_SRV_CHGD_CHAR_HANDLE 0x0007
#define GATT_SERVICE_CHGD_HANLE 0x0008
#define GATT_SRV_CHGD_CLIENT_CHARA_CONF_HANDLE 0x0009

#define GATT_GAP_NAME BT_LOCAL_NAME
#define GATT_BAS_SERVICE_HANDLE 0x000A
#define GATT_BAS_CHARACTERISTIC_HANDLE 0x000B
#define GATT_BAS_LEVEL_HANDLE 0x000C
#define GATT_BAS_CLIENT_CHARA_CONF_HANDLE 0x000D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant