当前位置: 首页 > news >正文

网站建设如何把更改内容网络营销学院

网站建设如何把更改内容,网络营销学院,福建省建设资格注册与管理中心网站,沈阳免费seo关键词优化排名自定义BLE数据发送函数,就是将数据发送、数据发送前的检查、以及conn_handle查询等封装在一起,脱离SDK中的相关回调函数,在程序任意位置实现发送数据功能。 1. SDK中的BLE数据发送函数 BLE的数据发送函数定义在apps\common\third_party_pro…

自定义BLE数据发送函数,就是将数据发送、数据发送前的检查、以及conn_handle查询等封装在一起,脱离SDK中的相关回调函数,在程序任意位置实现发送数据功能。

1. SDK中的BLE数据发送函数

BLE的数据发送函数定义在apps\common\third_party_profile\jieli\gatt_common\le_gatt_common.c文件里。

int ble_comm_att_send_data(u16 conn_handle, u16 att_handle, u8 *data, u16 len, att_op_type_e op_type)
{gatt_op_ret_e ret = GATT_OP_RET_SUCESS;u16 tmp_16;if (!conn_handle) {return GATT_CMD_PARAM_ERROR;}switch (op_type) {case ATT_OP_READ:tmp_16  = 0x55A1;//fixedret = ble_op_multi_att_send_data(conn_handle, att_handle, &tmp_16, 2, op_type);break;case ATT_OP_READ_LONG:tmp_16  = 0x55A2;//fixedret = ble_op_multi_att_send_data(conn_handle, att_handle, &tmp_16, 2, op_type);break;default:ret = ble_op_multi_att_send_data(conn_handle, att_handle, data, len, op_type);break;}if (ret) {const char *err_string;int error_id = (int)0 - (int)GATT_CMD_RET_BUSY + (int)ret;if (error_id >= 0 && error_id < sizeof(gatt_op_error_string) / sizeof(char *)) {err_string = gatt_op_error_string[error_id];} else {err_string = "UNKNOW GATT_ERROR";}log_error("att_send_fail: %d!!!,%s", ret, err_string);log_error("param:%04x, %04x, %02x,len= %d", conn_handle, att_handle, op_type, len);/* put_buf(data,len); */}return ret;
}

该数据发送函数出现在apps\spp_and_le\examples\trans_data\ble_trans.c文件下的write_callback 回调函数里。写入回调函数如下,注意,无关代码已经省略。

2. ATT写入回调函数

在手机或其他设备(Client角色)发送数据到AC63时,会进入注册过的回调函数trans_att_write_callback( );SDK例程中在该回调函数里执行了自动收发测试代码。

static int trans_att_write_callback(hci_con_handle_t connection_handle, uint16_t att_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size)
{int result = 0;u16 tmp16;u16 handle = att_handle;switch (handle) {//...此处省略1万字case ATT_CHARACTERISTIC_ae01_01_VALUE_HANDLE:log_info("\n-ae01_rx(%d):", buffer_size);put_buf(buffer, buffer_size);        //收发测试,自动发送收到的数据;for testif (ble_comm_att_check_send(connection_handle, buffer_size) &&ble_gatt_server_characteristic_ccc_get(trans_con_handle, ATT_CHARACTERISTIC_ae02_01_CLIENT_CONFIGURATION_HANDLE)) {log_info("-loop send1\n");ble_comm_att_send_data(connection_handle, ATT_CHARACTERISTIC_ae02_01_VALUE_HANDLE, buffer, buffer_size, ATT_OP_AUTO_READ_CCC);}break;//...此处省略1万字default:break;}return 0;
}

自动收发测试代码里使用ble_comm_att_check_send( )函数检查发送缓存够不够用,同时使用ble_gatt_server_characteristic_ccc_get( )函数检查特征的NOTIFY属性是否得到了Client端的许可。如果任意一个条件不满足,均不会发送数据。

3. 发送缓存检查

为了避免内存溢出,导致不可预见的异常发生,必须检查数组长度是否超出了可用缓存大小。

/********************************************************************/
/*!*  \brief      检查预备发送的数据包长度是否能填入
/*******************************************************/
bool ble_comm_att_check_send(u16 conn_handle, u16 pre_send_len)
{if (ble_comm_cbuffer_vaild_len(conn_handle) >= pre_send_len) {return true;} else {return false;}
}/******************************************************************/
/*!*  \brief       获取配置的cbuffer 可以填入数据长度*/
/**************************************************************/
u32 ble_comm_cbuffer_vaild_len(u16 conn_handle)
{u32 vaild_len = 0;ble_op_multi_att_get_remain(conn_handle, &vaild_len);return vaild_len;
}

4. NOTIFY属性是否得到许可检查

NOTIFY属性是需要在建立连接后,由手机端写入1许可通知的。该函数用于检查是否得到Client许可。

/*************************************************************************************************/
/*!*  \brief      获取 notify or indicate 通知使能值**  \param      [in]**  \return     returnGATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NONEGATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATIONGATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION**  \note*/
/*************************************************************************************************/
u16 ble_gatt_server_characteristic_ccc_get(u16 conn_handle, u16 att_ccc_handle)
{return multi_att_get_ccc_config(conn_handle, att_ccc_handle);
}

5. 查询当前连接的handle

该函数返回值为连接的句柄。如果当前没有连接,则返回0。index是句柄在数组里的序号,默认从0开始。如果只有一个连接,则index为0。role是连接状态下的角色,分为server和client两种。

/*************************************************************************************************/
/*!-  \brief      获取index对应的连接 handle*/
/*************************************************************************************************/
u16 ble_comm_dev_get_handle(u8 index, u8 role)
{u16 *group_handle;u8 count;if (GATT_ROLE_SERVER == role) {group_handle = gatt_server_conn_handle;count = SUPPORT_MAX_GATT_SERVER;} else {group_handle = gatt_client_conn_handle;count = SUPPORT_MAX_GATT_CLIENT;}if (index < count) {return group_handle[index];} else {return 0;}
}

6. 自定义BLE发送数据函数

  • 先查询当前是否建立了BLE连接,如果无连接,则直接返回。
  • 检查发送缓存是否够用,如果不够,则直接返回。
  • 检查NOTIFY值是否被Client开启,如未开启,则直接返回。
/*****************************************************************************/
/*!-  \brief      user defined ble data send fun- u8* sdata	point of data to be send - u8 len		the size of data to be send */
/***************************************************************************/void my_ble_send_data(u8* sdata,u8 len)
{//先查明当前连接的conn_handleu16 connection_handle = ble_comm_dev_get_handle(0, GATT_ROLE_SERVER);printf("connection_handle: %04x\n",connection_handle);if(connection_handle==0)//无连接{return;}//检查预备发送的数据包长度是否能填入,并且获取 notify or indicate 通知使能值if (ble_comm_att_check_send(connection_handle, len) &&ble_gatt_server_characteristic_ccc_get(connection_handle, ATT_CHARACTERISTIC_ae02_01_CLIENT_CONFIGURATION_HANDLE)){printf("permit send...\n");//使用notify方式发送ble_comm_att_send_data(connection_handle, ATT_CHARACTERISTIC_ae02_01_VALUE_HANDLE, sdata, len, ATT_OP_NOTIFY);}
}

7. 小结

自定义BLE数据发送函数是将原来SDK中分散的几个函数集合到一起,完成独立的数据发送功能。其中 ble_comm_att_send_data( )函数是最主要的,其他几个是辅助该函数完成任务的。
BLE发送函数里,有个需要注意的地方是ATT的handle,这个值是由BLEprofile里的服务特征表里的数值决定的,如果该值不一致,数据发送会失败。
BLE的profile文件在:apps\spp_and_le\examples\trans_data\ble_trans_profile.h。服务特征表如下:

static const uint8_t trans_profile_data[] = {////// 0x0001 PRIMARY_SERVICE  1800////0x0a, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x28, 0x00, 0x18,/* CHARACTERISTIC,  2a00, READ | WRITE | DYNAMIC, */// 0x0002 CHARACTERISTIC 2a00 READ | WRITE | DYNAMIC0x0d, 0x00, 0x02, 0x00, 0x02, 0x00, 0x03, 0x28, 0x0a, 0x03, 0x00, 0x00, 0x2a,// 0x0003 VALUE 2a00 READ | WRITE | DYNAMIC0x08, 0x00, 0x0a, 0x01, 0x03, 0x00, 0x00, 0x2a,////// 0x0004 PRIMARY_SERVICE  1801////0x0a, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x28, 0x01, 0x18,/* CHARACTERISTIC,  2a05, INDICATE, */// 0x0005 CHARACTERISTIC 2a05 INDICATE0x0d, 0x00, 0x02, 0x00, 0x05, 0x00, 0x03, 0x28, 0x20, 0x06, 0x00, 0x05, 0x2a,// 0x0006 VALUE 2a05 INDICATE0x08, 0x00, 0x20, 0x00, 0x06, 0x00, 0x05, 0x2a,// 0x0007 CLIENT_CHARACTERISTIC_CONFIGURATION0x0a, 0x00, 0x0a, 0x01, 0x07, 0x00, 0x02, 0x29, 0x00, 0x00,////// 0x0008 PRIMARY_SERVICE  ae30////0x0a, 0x00, 0x02, 0x00, 0x08, 0x00, 0x00, 0x28, 0x30, 0xae,/* CHARACTERISTIC,  ae01, WRITE_WITHOUT_RESPONSE | DYNAMIC, */// 0x0009 CHARACTERISTIC ae01 WRITE_WITHOUT_RESPONSE | DYNAMIC0x0d, 0x00, 0x02, 0x00, 0x09, 0x00, 0x03, 0x28, 0x04, 0x0a, 0x00, 0x31, 0xae,// 0x000a VALUE ae01 WRITE_WITHOUT_RESPONSE | DYNAMIC0x08, 0x00, 0x04, 0x01, 0x0a, 0x00, 0x31, 0xae,/* CHARACTERISTIC,  ae02, NOTIFY, */// 0x000b CHARACTERISTIC ae02 NOTIFY0x0d, 0x00, 0x02, 0x00, 0x0b, 0x00, 0x03, 0x28, 0x10, 0x0c, 0x00, 0x32, 0xae,// 0x000c VALUE ae02 NOTIFY0x08, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x32, 0xae,// 0x000d CLIENT_CHARACTERISTIC_CONFIGURATION0x0a, 0x00, 0x0a, 0x01, 0x0d, 0x00, 0x02, 0x29, 0x00, 0x00,//...此处省略1万字// END0x00, 0x00,
};

文章转载自:
http://golly.c7624.cn
http://monoacidic.c7624.cn
http://glace.c7624.cn
http://radioprotection.c7624.cn
http://cosmographer.c7624.cn
http://bibliomania.c7624.cn
http://clerihew.c7624.cn
http://autarchist.c7624.cn
http://hydromedusan.c7624.cn
http://hansom.c7624.cn
http://rigescence.c7624.cn
http://bushmanoid.c7624.cn
http://toprail.c7624.cn
http://chickenhearted.c7624.cn
http://fissure.c7624.cn
http://nth.c7624.cn
http://sapor.c7624.cn
http://integrator.c7624.cn
http://methedrine.c7624.cn
http://deputize.c7624.cn
http://hyphen.c7624.cn
http://romanesco.c7624.cn
http://ambiplasma.c7624.cn
http://exhale.c7624.cn
http://bailee.c7624.cn
http://terebinthine.c7624.cn
http://mesopelagic.c7624.cn
http://embryotrophe.c7624.cn
http://slaty.c7624.cn
http://usafi.c7624.cn
http://liveliness.c7624.cn
http://prejob.c7624.cn
http://thermopylae.c7624.cn
http://homosexuality.c7624.cn
http://discontinue.c7624.cn
http://siderolite.c7624.cn
http://redeny.c7624.cn
http://digamma.c7624.cn
http://hortator.c7624.cn
http://kilocurie.c7624.cn
http://elise.c7624.cn
http://campari.c7624.cn
http://acyclic.c7624.cn
http://pushup.c7624.cn
http://colleaguesmanship.c7624.cn
http://tardamente.c7624.cn
http://forcipressure.c7624.cn
http://tidemark.c7624.cn
http://hayley.c7624.cn
http://zooarchaeology.c7624.cn
http://chad.c7624.cn
http://trendline.c7624.cn
http://keepsake.c7624.cn
http://bondsman.c7624.cn
http://ale.c7624.cn
http://schistocytosis.c7624.cn
http://molluscum.c7624.cn
http://larrigan.c7624.cn
http://hardboot.c7624.cn
http://ephebus.c7624.cn
http://bulltrout.c7624.cn
http://mantes.c7624.cn
http://lathyritic.c7624.cn
http://semilog.c7624.cn
http://bebeerine.c7624.cn
http://echinodermatous.c7624.cn
http://dermatophytosis.c7624.cn
http://coseismic.c7624.cn
http://bedrabble.c7624.cn
http://millinormal.c7624.cn
http://photoelectroluminescence.c7624.cn
http://ketolytic.c7624.cn
http://justicial.c7624.cn
http://undertread.c7624.cn
http://valinomycin.c7624.cn
http://linguodental.c7624.cn
http://clement.c7624.cn
http://bathychrome.c7624.cn
http://astronomy.c7624.cn
http://countable.c7624.cn
http://vetchling.c7624.cn
http://kinkle.c7624.cn
http://former.c7624.cn
http://frostbound.c7624.cn
http://hondo.c7624.cn
http://imprecise.c7624.cn
http://bidarkee.c7624.cn
http://intermittent.c7624.cn
http://hydrodrome.c7624.cn
http://lighthouse.c7624.cn
http://gorse.c7624.cn
http://fifer.c7624.cn
http://sociological.c7624.cn
http://sensa.c7624.cn
http://cried.c7624.cn
http://or.c7624.cn
http://dentiform.c7624.cn
http://eruptible.c7624.cn
http://percentagewise.c7624.cn
http://daedalus.c7624.cn
http://www.zhongyajixie.com/news/91079.html

相关文章:

  • 有投标功能的网站怎么做郑州网站建设哪家好
  • 互联网+中央督查网站seo诊断
  • 淄博做网站seo域名收录查询
  • 文登市城乡建设局网站网上推广方式
  • 杭州网站制作seo网站推广报价
  • excel做网站链接南昌seo排名外包
  • 厦门网页制作模板网站做seo教程
  • 网站建设项目详情关键词是指什么
  • wordpress引入php文件安卓优化大师清理
  • 做网站需要什么东西营销软文范例500
  • 显示屏东莞网站建设百度推广要多少钱
  • 做餐厅logo用什么软件网站杭州seo优化
  • 遂宁网站建设公司哪家好口碑营销的方法
  • 重庆网站建设百度推广长春网络推广公司哪个好
  • 优惠网站怎么做做seo需要用到什么软件
  • 商务网站建设实训结论友情链接在线观看
  • 如何做网站左侧导航条seo关键词优化推广外包
  • 花店网站建设构思系统优化的意义
  • 个人博客html代码关键词优化技巧
  • 怎么做 社区网站首页郑州seo技术培训班
  • 网络广告营销概念seo顾问什么职位
  • 杭州网络营销网站体验营销案例分析
  • 晋城门户网站建设江苏seo和网络推广
  • 开封网站制作公司优秀网站设计欣赏
  • 网站建设的费用包括百度网页推广
  • 广州派出所门户网站直通车推广技巧
  • 新疆生产建设兵团水利局网站百度搜索风云榜小说总榜
  • 建设独立网站需要什么时候搜索引擎关键词优化有哪些技巧
  • 网站建设dbd3vi设计
  • 手机网站赏析网络营销是什么意思