问题描述
似乎我无法为Bluetooth Low Energy中的服务添加新特性。我基于简单外围设备示例进行编程,该示例具有5个特征。我想根据在simple_gatt_profile.c和.h中如何初始化其他5个特征来添加第6个和第7个特征。当我这样做时,代码不再起作用,在main中调用bios_start()之后,它似乎挂在了某个地方。任务不被调用。因此,我创建特征的方式一定存在问题。这是一些代码: 从simple_gatt_profile.h:
// Profile Parameters
#define SIMPLEPROFILE_CHAR1 0 // RW uint8 - Profile Characteristic 1 value
#define SIMPLEPROFILE_CHAR2 1 // RW uint8 - Profile Characteristic 2 value
#define SIMPLEPROFILE_CHAR3 2 // RW uint8 - Profile Characteristic 3 value
#define SIMPLEPROFILE_CHAR4 3 // RW uint8 - Profile Characteristic 4 value
#define SIMPLEPROFILE_CHAR5 4 // RW uint8 - Profile Characteristic 5 value
#define SIMPLEPROFILE_CHAR6 5 // RW uint8 - Profile Characteristic 6 value
#define SIMPLEPROFILE_CHAR7 6 // RW uint8 - Profile Characteristic 7 value
// Simple Profile Service UUID
#define SIMPLEPROFILE_SERV_UUID 0xFFF0
// Key pressed UUID
#define SIMPLEPROFILE_CHAR1_UUID 0xFFF1
#define SIMPLEPROFILE_CHAR2_UUID 0xFFF2
#define SIMPLEPROFILE_CHAR3_UUID 0xFFF3
#define SIMPLEPROFILE_CHAR4_UUID 0xFFF4
#define SIMPLEPROFILE_CHAR5_UUID 0xFFF5
#define SIMPLEPROFILE_CHAR6_UUID 0xFFF6
#define SIMPLEPROFILE_CHAR7_UUID 0xFFF7
// Simple Keys Profile Services bit fields
#define SIMPLEPROFILE_SERVICE 0x00000001
// Length of characteristics in bytes
#define SIMPLEPROFILE_CHAR1_LEN 20
#define SIMPLEPROFILE_CHAR2_LEN 20
#define SIMPLEPROFILE_CHAR3_LEN 20
#define SIMPLEPROFILE_CHAR4_LEN 20
#define SIMPLEPROFILE_CHAR5_LEN 20
#define SIMPLEPROFILE_CHAR6_LEN 20
#define SIMPLEPROFILE_CHAR7_LEN 14
从simple_gatt_profile.c中获取:
// Simple GATT Profile Service UUID: 0xFFF0
CONST uint8 simpleProfileServUUID[ATT_BT_UUID_SIZE] =
{
LO_UINT16(SIMPLEPROFILE_SERV_UUID),HI_UINT16(SIMPLEPROFILE_SERV_UUID)
};
// Characteristic 1 UUID: 0xFFF1
CONST uint8 simpleProfilechar1UUID[ATT_BT_UUID_SIZE] =
{
LO_UINT16(SIMPLEPROFILE_CHAR1_UUID),HI_UINT16(SIMPLEPROFILE_CHAR1_UUID)
};
// Characteristic 2 UUID: 0xFFF2
CONST uint8 simpleProfilechar2UUID[ATT_BT_UUID_SIZE] =
{
LO_UINT16(SIMPLEPROFILE_CHAR2_UUID),HI_UINT16(SIMPLEPROFILE_CHAR2_UUID)
};
// Characteristic 3 UUID: 0xFFF3
CONST uint8 simpleProfilechar3UUID[ATT_BT_UUID_SIZE] =
{
LO_UINT16(SIMPLEPROFILE_CHAR3_UUID),HI_UINT16(SIMPLEPROFILE_CHAR3_UUID)
};
// Characteristic 4 UUID: 0xFFF4
CONST uint8 simpleProfilechar4UUID[ATT_BT_UUID_SIZE] =
{
LO_UINT16(SIMPLEPROFILE_CHAR4_UUID),HI_UINT16(SIMPLEPROFILE_CHAR4_UUID)
};
// Characteristic 5 UUID: 0xFFF5
CONST uint8 simpleProfilechar5UUID[ATT_BT_UUID_SIZE] =
{
LO_UINT16(SIMPLEPROFILE_CHAR5_UUID),HI_UINT16(SIMPLEPROFILE_CHAR5_UUID)
};
// Characteristic 6 UUID: 0xFFF6
CONST uint8 simpleProfilechar6UUID[ATT_BT_UUID_SIZE] =
{
LO_UINT16(SIMPLEPROFILE_CHAR6_UUID),HI_UINT16(SIMPLEPROFILE_CHAR6_UUID)
};
// Characteristic 7 UUID: 0xFFF7
CONST uint8 simpleProfilechar7UUID[ATT_BT_UUID_SIZE] =
{
LO_UINT16(SIMPLEPROFILE_CHAR7_UUID),HI_UINT16(SIMPLEPROFILE_CHAR7_UUID)
};
/*********************************************************************
* EXTERNAL VARIABLES
*/
/*********************************************************************
* EXTERNAL FUNCTIONS
*/
/*********************************************************************
* LOCAL VARIABLES
*/
static simpleProfileCBs_t *simpleProfile_AppCBs = NULL;
/*********************************************************************
* Profile Attributes - variables
*/
// Simple Profile Service attribute
static CONST gattAttrType_t simpleProfileService = { ATT_BT_UUID_SIZE,simpleProfileServUUID };
// Simple Profile Characteristic 1 Properties
static uint8 simpleProfileChar1Props = GATT_PROP_READ | GATT_PROP_WRITE| GATT_PROP_NOTIFY;
// Characteristic 1 Value
static uint8 simpleProfileChar1[SIMPLEPROFILE_CHAR1_LEN] = { 0,0 };
// Simple Profile Characteristic 1 User Description
static uint8 simpleProfileChar1UserDesp[8] = "Amsel 1";
// Simple Profile Characteristic 2 Properties
static uint8 simpleProfileChar2Props = GATT_PROP_READ | GATT_PROP_WRITE| GATT_PROP_NOTIFY;
// Characteristic 2 Value
static uint8 simpleProfileChar2[SIMPLEPROFILE_CHAR2_LEN] = { 0,0 };
// Simple Profile Characteristic 2 User Description
static uint8 simpleProfileChar2UserDesp[8] = "Amsel 2";
// Simple Profile Characteristic 3 Properties
static uint8 simpleProfileChar3Props = GATT_PROP_READ | GATT_PROP_WRITE| GATT_PROP_NOTIFY;
// Characteristic 3 Value
static uint8 simpleProfileChar3[SIMPLEPROFILE_CHAR3_LEN] = { 0,0 };
// Simple Profile Characteristic 3 User Description
static uint8 simpleProfileChar3UserDesp[8] = "Amsel 3";
// Simple Profile Characteristic 4 Properties
static uint8 simpleProfileChar4Props = GATT_PROP_READ | GATT_PROP_WRITE | GATT_PROP_NOTIFY;
// Characteristic 4 Value
static uint8 simpleProfileChar4[SIMPLEPROFILE_CHAR4_LEN] = { 0,0 };
// Simple Profile Characteristic 4 User Description
static uint8 simpleProfileChar4UserDesp[16] = "Amsel 4,Notify";
// Simple Profile Characteristic 5 Properties
static uint8 simpleProfileChar5Props = GATT_PROP_READ | GATT_PROP_WRITE | GATT_PROP_NOTIFY;
// Characteristic 5 Value
static uint8 simpleProfileChar5[SIMPLEPROFILE_CHAR5_LEN] = { 0,0 };
// Simple Profile Characteristic 5 User Description
static uint8 simpleProfileChar5UserDesp[8] = "Dialog1";
// Simple Profile Characteristic 6 Properties
static uint8 simpleProfileChar6Props = GATT_PROP_READ | GATT_PROP_WRITE | GATT_PROP_NOTIFY;
// Characteristic 6 Value
static uint8 simpleProfileChar6[SIMPLEPROFILE_CHAR6_LEN] = { 0,0 };
// Simple Profile Characteristic 6 User Description
static uint8 simpleProfileChar6UserDesp[8] = "Dialog2";
// Simple Profile Characteristic 7 Properties
static uint8 simpleProfileChar7Props = GATT_PROP_READ | GATT_PROP_WRITE | GATT_PROP_NOTIFY;
// Characteristic 7 Value
static uint8 simpleProfileChar7[SIMPLEPROFILE_CHAR7_LEN] = { 0,0 };
// Simple Profile Characteristic 7 User Description
static uint8 simpleProfileChar7UserDesp[8] = "Dialog3";
// Simple Profile Characteristic 4 Configuration Each client has its own
// instantiation of the Client Characteristic Configuration. Reads of the
// Client Characteristic Configuration only shows the configuration for
// that client and writes only affect the configuration of that client.
static gattCharCfg_t *simpleProfileChar1Config;
static gattCharCfg_t *simpleProfileChar2Config;
static gattCharCfg_t *simpleProfileChar3Config;
static gattCharCfg_t *simpleProfileChar4Config;
static gattCharCfg_t *simpleProfileChar5Config;
static gattCharCfg_t *simpleProfileChar6Config;
static gattCharCfg_t *simpleProfileChar7Config;
/*********************************************************************
* Profile Attributes - Table
*/
static gattAttribute_t simpleProfileAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED] =
{
// Simple Profile Service
{
{ ATT_BT_UUID_SIZE,primaryServiceUUID },/* type */
GATT_PERMIT_READ,/* permissions */
0,/* handle */
(uint8 *)&simpleProfileService /* pValue */
},// Characteristic 1 Declaration
{
{ ATT_BT_UUID_SIZE,characterUUID },GATT_PERMIT_READ,&simpleProfileChar1Props
},// Characteristic Value 1
{
{ ATT_BT_UUID_SIZE,simpleProfilechar1UUID },GATT_PERMIT_READ | GATT_PERMIT_WRITE,(uint8 *)&simpleProfileChar1
},// Characteristic 1 configuration
{
{ ATT_BT_UUID_SIZE,clientCharCfgUUID },(uint8 *)&simpleProfileChar1Config
},// Characteristic 1 User Description
{
{ ATT_BT_UUID_SIZE,charUserDescUUID },simpleProfileChar1UserDesp
},// Characteristic 2 Declaration
{
{ ATT_BT_UUID_SIZE,&simpleProfileChar2Props
},// Characteristic Value 2
{
{ ATT_BT_UUID_SIZE,simpleProfilechar2UUID },(uint8 *)&simpleProfileChar2
},// Characteristic 2 configuration
{
{ ATT_BT_UUID_SIZE,(uint8 *)&simpleProfileChar2Config
},// Characteristic 2 User Description
{
{ ATT_BT_UUID_SIZE,simpleProfileChar2UserDesp
},// Characteristic 3 Declaration
{
{ ATT_BT_UUID_SIZE,&simpleProfileChar3Props
},// Characteristic Value 3
{
{ ATT_BT_UUID_SIZE,simpleProfilechar3UUID },(uint8 *)&simpleProfileChar3
},// Characteristic 3 configuration
{
{ ATT_BT_UUID_SIZE,(uint8 *)&simpleProfileChar3Config
},// Characteristic 3 User Description
{
{ ATT_BT_UUID_SIZE,simpleProfileChar3UserDesp
},// Characteristic 4 Declaration
{
{ ATT_BT_UUID_SIZE,GATT_PERMIT_READ| GATT_PERMIT_WRITE,&simpleProfileChar4Props
},// Characteristic Value 4
{
{ ATT_BT_UUID_SIZE,simpleProfilechar4UUID },(uint8 *)&simpleProfileChar4
},// Characteristic 4 configuration
{
{ ATT_BT_UUID_SIZE,(uint8 *)&simpleProfileChar4Config
},// Characteristic 4 User Description
{
{ ATT_BT_UUID_SIZE,simpleProfileChar4UserDesp
},// Characteristic 5 Declaration
{
{ ATT_BT_UUID_SIZE,&simpleProfileChar5Props
},// Characteristic Value 5
{
{ ATT_BT_UUID_SIZE,simpleProfilechar5UUID },(uint8 *)&simpleProfileChar5
},// Characteristic 5 configuration
{
{ ATT_BT_UUID_SIZE,(uint8 *)&simpleProfileChar5Config
},// Characteristic 5 User Description
{
{ ATT_BT_UUID_SIZE,simpleProfileChar5UserDesp
},// Characteristic 6 Declaration
{
{ ATT_BT_UUID_SIZE,&simpleProfileChar6Props
},// Characteristic Value 6
{
{ ATT_BT_UUID_SIZE,(uint8 *)&simpleProfileChar6
},// Characteristic 5 configuration
{
{ ATT_BT_UUID_SIZE,(uint8 *)&simpleProfileChar6Config
},// Characteristic 6 User Description
{
{ ATT_BT_UUID_SIZE,simpleProfileChar6UserDesp
},// Characteristic 7 Declaration
{
{ ATT_BT_UUID_SIZE,&simpleProfileChar7Props
},// Characteristic Value 7
{
{ ATT_BT_UUID_SIZE,simpleProfilechar7UUID },(uint8 *)&simpleProfileChar7
},// Characteristic 7 configuration
{
{ ATT_BT_UUID_SIZE,(uint8 *)&simpleProfileChar7Config
},// Characteristic 7 User Description
{
{ ATT_BT_UUID_SIZE,simpleProfileChar7UserDesp
},};
bStatus_t SimpleProfile_AddService( uint32 services )
{
uint8 status;
// Allocate Client Characteristic Configuration table
simpleProfileChar1Config = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
linkdbnumConns );
if ( simpleProfileChar1Config == NULL )
{
return ( bleMemAllocError );
}
// Initialize Client Characteristic Configuration attributes
GATTServApp_InitCharCfg( INVALID_CONNHANDLE,simpleProfileChar1Config );
simpleProfileChar2Config = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
linkdbnumConns );
if ( simpleProfileChar2Config == NULL )
{
return ( bleMemAllocError );
}
// Initialize Client Characteristic Configuration attributes
GATTServApp_InitCharCfg( INVALID_CONNHANDLE,simpleProfileChar2Config );
simpleProfileChar3Config = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
linkdbnumConns );
if ( simpleProfileChar3Config == NULL )
{
return ( bleMemAllocError );
}
// Initialize Client Characteristic Configuration attributes
GATTServApp_InitCharCfg( INVALID_CONNHANDLE,simpleProfileChar3Config );
simpleProfileChar4Config = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
linkdbnumConns );
if ( simpleProfileChar4Config == NULL )
{
return ( bleMemAllocError );
}
// Initialize Client Characteristic Configuration attributes
GATTServApp_InitCharCfg( INVALID_CONNHANDLE,simpleProfileChar4Config );
simpleProfileChar5Config = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
linkdbnumConns );
if ( simpleProfileChar5Config == NULL )
{
return ( bleMemAllocError );
}
// Initialize Client Characteristic Configuration attributes
GATTServApp_InitCharCfg( INVALID_CONNHANDLE,simpleProfileChar5Config );
simpleProfileChar6Config = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
linkdbnumConns );
if ( simpleProfileChar6Config == NULL )
{
return ( bleMemAllocError );
}
// Initialize Client Characteristic Configuration attributes
GATTServApp_InitCharCfg( INVALID_CONNHANDLE,simpleProfileChar6Config );
// Initialize Client Characteristic Configuration attributes
GATTServApp_InitCharCfg( INVALID_CONNHANDLE,simpleProfileChar7Config );
simpleProfileChar7Config = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
linkdbnumConns );
if ( simpleProfileChar7Config == NULL )
{
return ( bleMemAllocError );
}
// Initialize Client Characteristic Configuration attributes
GATTServApp_InitCharCfg( INVALID_CONNHANDLE,simpleProfileChar7Config );
if ( services & SIMPLEPROFILE_SERVICE )
{
// Register GATT attribute list and CBs with GATT Server App
status = GATTServApp_RegisterService( simpleProfileAttrTbl,GATT_NUM_ATTRS( simpleProfileAttrTbl ),GATT_MAX_ENCRYPT_KEY_SIZE,&simpleProfileCBs );
}
else
{
status = SUCCESS;
}
return ( status );
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)