当前位置:网站首页>DA14580作为server发送数据
DA14580作为server发送数据
2022-04-22 20:23:00 【ydgd118】
DA14580作为server发送数据要使用attmdb_att_set_value()函数和prf_server_send_event()函数。
attmdb_att_set_value()函数,是用来装载更新特征的属性值的,该函数只提供接口,开发者无法看到源码。该函数不会触发任何notify或indication,更新由 GATT 任务处理。下面是该函数的申明。
/** **************************************************************************************** * @brief Update attribute value * * Updating attribute value do not trigger any notification or indication, this shall be * handled by GATT task. * * @param[in] handle Attribute handle. * @param[in] length Size of new attribute value * @param[in] value Attribute value payload * * @return Command status code: * - @ref ATT_ERR_NO_ERROR: If attribute value update succeeds * - @ref ATT_ERR_INVALID_HANDLE: If handle doesn't exist in database * - @ref ATT_ERR_INVALID_ATTRIBUTE_VAL_LEN: If new value length exceeds maximum attribute * value length. **************************************************************************************** */
uint8_t attmdb_att_set_value(uint16_t handle, att_size_t length, uint8_t* value);
//函数内容已固化在芯片ROM,不对开发者开放
prf_server_send_event()函数,用于以触发配对设备有关新属性值修改的事件(notify或indication)。说直白一点,就是每次server更新关于NOTIFY或INDICATION的特征Value时,会把这个消息发出去给client。具体是notify还是indicition,由函数的@param indication 参数决定,如果是1则以indication发出,否则发出notify。区别是notify发出后不需要Client确认回复。
/** **************************************************************************************** * @brief The function is used in a profile server role task to trigger an event to peer * device (indication/notification) about new attribute value modification. * * @param p_env Profile server role task environment * @param indication True if it's an indication, False if it's a notification * @param handle Attribute handle that triggers an event **************************************************************************************** */
void prf_server_send_event(prf_env_struct *p_env, bool indication,
uint16_t handle)
{
// Allocate the GATT notification message
struct gattc_send_evt_cmd *req = KE_MSG_ALLOC(GATTC_SEND_EVT_CMD,
KE_BUILD_ID(TASK_GATTC,p_env->con_info.conidx), p_env->con_info.prf_id,
gattc_send_evt_cmd);
// Fill in the parameter structure
req->req_type = ((indication) ? GATTC_INDICATE : GATTC_NOTIFY);
req->handle = handle;
// Send the event
ke_msg_send(req);
}
在用户回调函数里,加入这2个函数,即可实现DA14580(server)向手机APP(Client)发出消息。下面的回调函数是在上一篇《DA14580BLE点亮LED》的基础上增加了发送Notify功能。当收到APP“开灯”指令后,DA14580会使用另外一个特征以Notify形式发出回复。回复的数据分别是"Open_LED!“和"Close_LED!”。
void user_custs1_led_wr_ind_handler(ke_msg_id_t const msgid,
struct custs1_val_write_ind const *param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
{
uint8_t val = 0;
memcpy(&val, ¶m->value[0], param->length);
if (val == CUSTS1_LED_ON)
{
GPIO_SetActive(GPIO_LED_PORT, GPIO_LED_PIN);
attmdb_att_set_value((custs1_env.shdl+CUST1_IDX_LONG_VALUE_VAL), sizeof("Open_LED!")-1, "Open_LED!");
}
else if (val == CUSTS1_LED_OFF)
{
GPIO_SetInactive(GPIO_LED_PORT, GPIO_LED_PIN);
attmdb_att_set_value((custs1_env.shdl+CUST1_IDX_LONG_VALUE_VAL), sizeof("Close_LED!")-1, "Close_LED!");
}
prf_server_send_event((prf_env_struct *)&(custs1_env.con_info), false,custs1_env.shdl+CUST1_IDX_LONG_VALUE_VAL );//发送出去
}
以上是DA14580作为从机和server时发送消息的一个流程。
版权声明
本文为[ydgd118]所创,转载请带上原文链接,感谢
https://ydgd118.blog.csdn.net/article/details/124344480
边栏推荐
猜你喜欢

分库分表&百亿级数据迁移

Podcasts about the universe

What are the types of documenter examination questions? How to prepare for the documenter examination of the construction department

运维(33) CentOS7.6通过Kubeadm部署Kubernetes集群

Activity result API usage and source code analysis

Module 4 operation

Improving Few-Shot Part Segmentation using Coarse Supervision学习笔记

day29

Markdown learning and Practice

File upload problem record
随机推荐
Adobe series error code solutions summary
【dfs】386. 字典序排数
redis集群6.2.6
Android面试题之屏幕适配+AIDL篇
常类型的使用 常成员函数(设计一个日期类和时间)
Solve the problem that the timeline does not match when the gold warehouse database kingbasees uses -- force rewind to forcibly pull up the standby machine
An error occurs when starting Kingbase stand-alone service: invalid value for parmeter "bindpuplist": "0-95"
Xshell7、Xftp7、Xlpd7-下载与安装教程(亲测可用)
Acrobat Pro DC tutorial, how to use password to protect PDF files?
PHP 零基础入门笔记(11):字符串 String
运维(33) CentOS7.6通过Kubeadm部署Kubernetes集群
KingbaseES中数据库启动安装程序方法
隔壁的wifi,我秒破
Conditions for judging whether plastic deformation occurs: Von Mises yield criterion
Acrobat Pro DC 教程,如何使用密码保护 PDF 文件?
金仓数据库KingbaseES之null和“ ”的区别
【状态机】388. 文件的最长绝对路径
@requestmapping获取请求参数
[unity / C] the game has a regional collapse and a deep international pit
Incorrect string value: ‘\xF0\x9F\x92\x95\’