文章目录
此内容接上一篇文章 才能看懂。
1、判断微信协议handle(uuid)相关处理
微信UUID
微信CMD_ID
void Bt_BleCallBack(uint8_t dataPtr, uint16_t len)
在蓝牙回调函数判断各种handle,作相关处理
第一个框框 是连接成功后微信协议返回的 indicae(FEC8_EN->Client Characteristic Configuration客户端特征配置)即APP请求获取客户端特征配置(暂时这样理解),就要开始发 10001 注册包。
第二个框框 else是负责接收到FEC7等handle的 数据包。(接收APP下发的数据就在这里!!!)*
再看看*void Ble_RecivedData_Process( uint16_t handle,uint8_t Recived_data,uint8_t recived_len)函数里面的code.(在Blue_recived_send.c里面)
此部分 上图第2个框框(即下面这个函数,接下来也会具体分析这个函数里面调用的每一层)这个函数里面会返回wechat_cmd_id,然后根据这个判断是否收到20001(ECI_resp_auth),再发10003 给APP,再接收20003(不需要再返回了),这样就完成微信4个包,我没用到10002和20002。 或判断是否收到30001(ECI_push_recvData)数据包,这个就要厂商协议组包解包了。
如下图数据框框的数据流。·
再具体详细了解怎样解包得到的是resp20001或30001,然后组包返回数据
Blue_recived_send.c里面
wechat_cmd_id = wechat_recivedpushdata_process(comm_info_var.frameinfo,&comm_info_var.rec_info_bytes,
&comm_info_var.frameinfo[WECHAT_SEND_DATA_INFO_OFF],&comm_info_var.send_info_bytes);
里面嵌套:
wechar_etc_service.c 里面
uint16_t wechat_recivedpushdata_process(uint8_t *bleRecdata,uint8_t *bleRecLen,uint8_t *pbuff,uint8_t *plen)
里面调用:
error_code = wechat_packfun_handler->m_epb_unPackWechatData_func(p_data, recvlen,pbuff,plen);
再来看看wechat_packfun_handler->m_epb_unPackWechatData_func(p_data, recvlen,pbuff,plen)具体放在哪里
首先在ble_wechat_util.h一个结构体内定义可以看到
ble_wechat_util 的意思应该是 微信功能函数指针定义地方
ctrl+shift+f 再找找~~~
原来初始化的时候调用void register_all_products(void) (函数在epb_pack.c里面),
然后给这个m_epb_unPackWechatData_func 赋了 epb_unPackWechatData_func
的指针函数。
最后函数在这里epb_pack.c,哈啊。
//epb_pack.c 负责放 微信的功能函数。
下图是组 授权包 或者 初始化包的函数。 在 epb_pack.c
ps:
epb_MmBp.c 和crc32.c一般是作为被 Epb_pack.c调用
epb.c 一般是作为被 epb_MmBp.c 调用
这样微信里面的嵌套就基本懂了
2、main()初始化微信各个函数
2.1给wechat_packfun_handler指针赋值微信处理各个函数入口地址。
register_all_products();
//function for register all products
void register_all_products(void)
{
wechat_packfun_inithandler.m_product_type = *PRODUCT_TYPE_MPBLEDEMO2*,
wechat_packfun_inithandler.m_epb_packTypeDataProduce_func = &epb_packTypeDataProduce_func,
wechat_packfun_inithandler.m_data_free_func = &wechat_data_free_func,
wechat_packfun_inithandler.m_epb_unPackWechatData_func = &epb_unPackWechatData_func,
wechat_packfun_inithandler.m_data_error_func = &wechat_errorResetVariable,
wechat_packfun_inithandler.m_data_produce_args = &m_info,
wechat_packfun_inithandler.next = NULL;
REGISTER(wechat_packfun_inithandler);
}
data_handler_init(&wechat_packfun_handler, PRODUCT_TYPE_MPBLEDEMO2);
2.2重定向
这个函数也就把 wechat_packfun_inithandler 的赋值又给了wechat_packfun_handler,可以看到工程都是调用wechat_packfun_handler
data_handler_init(&wechat_packfun_handler, PRODUCT_TYPE_MPBLEDEMO2);
//---------------- comsource ------------------//
void data_handler_init(data_handler** p_data_handler, uint8_t product_type)
{
if (*p_data_handler == NULL)
{
*p_data_handler = get_handler_by_type(product_type);
}
}
2.3 初始化各个狀態变量
wechat_variableInit()
void wechat_variableInit(void)
{
wechatpackSta.auth_send = false;
wechatpackSta.auth_state = false;
wechatpackSta.indication_state = false;
wechatpackSta.init_send = false;
wechatpackSta.init_state = false;
wechatpackSta.send_data_seq = 0;
wechatpackSta.push_data_seq = 0;
wechatpackSta.seq = 0;
}