7 posts / 0 new
Last post
z20121202038
Offline
Last seen:3 years 10 months ago
Joined:2016-03-30 12:51
关于在服务下自定义属性的问题

你好,
1)在某一服务下定义新的属性,比如电池服务,新增上报频率等等新的属性,发现手机端看到新增属性,只有我定义的UUID,而没有具体属性名(或称之为描述),请问这个是不是该手机端定义的?
/// Full BAS Database Description - Used to add attributes into the database
const struct attm_desc bas_att_db[BAS_IDX_NB] =
{
// Battery Service Declaration
[BAS_IDX_SVC] = {ATT_DECL_PRIMARY_SERVICE, PERM(RD, ENABLE), sizeof(bas_svc),
sizeof(bas_svc), (uint8_t *)&bas_svc},

// Battery Level Characteristic Declaration
[BAS_IDX_BATT_LVL_CHAR] = {ATT_DECL_CHARACTERISTIC, PERM(RD, ENABLE), sizeof(bas_batt_level_char),
sizeof(bas_batt_level_char), (uint8_t *)&bas_batt_level_char},
// Battery Level Characteristic Value
[BAS_IDX_BATT_LVL_VAL] = {ATT_CHAR_BATTERY_LEVEL, PERM(RD, ENABLE), sizeof(uint8_t),
0, NULL},
// Battery Level Characteristic - Client Characteristic Configuration Descriptor
[BAS_IDX_BATT_LVL_NTF_CFG] = {ATT_DESC_CLIENT_CHAR_CFG, PERM(RD, ENABLE)|PERM(WR, ENABLE), sizeof(uint16_t),
0, NULL},
// Battery Level Characteristic - Characteristic Presentation Format Descriptor
[BAS_IDX_BATT_LVL_PRES_FMT] = {ATT_DESC_CHAR_PRES_FORMAT, PERM(RD, ENABLE), sizeof(struct prf_char_pres_fmt),
0, NULL},
};

2)我增加属性超过16个,发现通过手机去访问我新增的部分属性,APP会停止工作,这种情况一般是什么原因?因为我同事新建了很多,但并不是都异常,只是部分异常。我阅读这个为属性分配DB的代码解释,发现最多是可以支持32种属性的。那这可能还有哪些原因呢?
/**
****************************************************************************************
* @brief Function use to ease service database creation.
*
* Use @see attmdb_add_service function of attmdb module to create service database,
* then use @see attmdb_add_attribute function of attmdb module to create attributes
* according to database description array given in parameter.
*
* @note: database description array shall be const to reduce memory consuption (only ROM)
* @note: It supports only 16 bits UUIDs
*
* @param[in|out] shdl Service start handle.
* @param[in|out] cfg_flag Configuration Flag, each bit matches with an attribute of
* att_db (Max: 32 attributes); if the bit is set to 1, the
* attribute will be added in the service.
* @param[in] max_nb_att Number of attributes in the service
* @param[in|out] att_tbl Array which will be fulfilled with the difference between
* each characteristic handle and the service start handle.
* This array is useful if several characteristics are optional
* within the service, can be set to NULL if not needed.
* @param[in] dest_id Task ID linked to the service. This task will be notified
* each time the service content is modified by a peer device.
* @param[in|out] att_db Table containing all attributes information
*
* @return Command status code:
* - @ref ATT_ERR_NO_ERROR: If database creation succeeds.
* - @ref ATT_ERR_INVALID_HANDLE: If start_hdl given in parameter + nb of attribute override
* some existing services handles.
* - @ref ATT_ERR_INSUFF_RESOURCE: There is not enough memory to allocate service buffer.
* or of new attribute cannot be added because all expected
* attributes already added or buffer overflow detected during
* allocation
****************************************************************************************
*/
uint8_t attm_svc_create_db(uint16_t *shdl, uint8_t *cfg_flag, uint8_t max_nb_att,
uint8_t *att_tbl, ke_task_id_t const dest_id,
const struct attm_desc *att_db);

谢谢,如果能提供一些自定义属性的例子就更好了。

Keywords:
Device:
z20121202038
Offline
Last seen:3 years 10 months ago
Joined:2016-03-30 12:51
问题已查明,流程上应该是先创建DB

问题已查明,流程上应该是先创建DB,建立连接之后要调用使能处理函数对DB的元素进行赋值,然后对端设备才能识别。

roc0106
Offline
Last seen:5 months 2 weeks ago
Joined:2016-08-31 01:55
能不能发个你的例子,我学学!我现在还不会添加

能不能发个你的例子,我学学!我现在还不会添加

snowdream1
Offline
Last seen:6 months 1 week ago
Staff
Joined:2014-08-17 14:25
上传了一个例子,里面有针对read,write

上传了一个例子,里面有针对read,write,notification,indication的简单示例,可以参考。你说的手机端显示的说明,也需要在代码里定义相关的属性。

z20121202038
Offline
Last seen:3 years 10 months ago
Joined:2016-03-30 12:51
有没有SDK3的啊,最好是比对文件:

有没有SDK3的啊,最好是比对文件:
比如电池服务下的一个属性,用BLE DEVICE LIST看,叫“Battery Level”,对应的UUID是2A19,但是代码里面我找不到这个名字的定义啊,难道这个名字也是我们传到手机的,我理解我们是不是只传了UUID啊?

snowdream1
Offline
Last seen:6 months 1 week ago
Staff
Joined:2014-08-17 14:25
因为只是SIG标准规定的默认属性,手机那里就直接显示了

因为只是SIG标准规定的默认属性,手机那里就直接显示了。SDK3的属性例子,你可以查看Accel_task.c里的accel_att_db数组。关于属性说明,查看ATT_DESC_CHAR_USER_DESCRIPTION对应项。

roc0106
Offline
Last seen:5 months 2 weeks ago
Joined:2016-08-31 01:55
我也在弄这个,什么也出不来!能不能发个例子看看,学学!

我也在弄这个,什么也出不来!能不能发个例子看看,学学!