1.目的
把官方的代码移植到sdk10.0版本
2.分析
由于官方的版本过低,移植到高版本
3.平台:
协议栈版本:SDK10.0.0
编译软件:keil 5.12
硬件平台:nrf51822最小系统
例子:SDK 10.0.0\examples\ble_peripheral\ble_app_uart\pca10028\s110\arm4
4.步骤
需要准备的资料,
一个是微信官方代码,一个是nrfSDK
微信下载地址:http://iot.weixin.qq.com/wiki/new/index.html?page=6-1
首先,添加几个文件夹:
文件夹的内容分别实在微信的对应名字的文件copy出来的,把他们加到SDK10.0.0\examples\ble_peripheral\ble_app_uart\pca10028\s110\arm4工程里面,并添加对应的路径
在main.c里面添加
ble_evt_dispatch()函数变为如下:
services_init()函数变为:
advertising_init()函数变为:
- **@brief Function for initializing the Advertising functionality.
- */
- static void advertising_init(void)
- {
- uint32_t err_code;
- ble_advdata_t advdata;
- //ble_advdata_t scanrsp;
- // uint32_t err_code;
- //ble_advdata_t advdata;
- /**< LE General Discoverable Mode, BR/EDR not supported. */
- uint8_t flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
- ble_uuid_t adv_uuids[] =
- {
- {BLE_UUID_WECHAT_SERVICE, BLE_UUID_TYPE_BLE}
- };
- memset(&advdata, 0, sizeof(advdata));
- advdata.name_type = BLE_ADVDATA_FULL_NAME;
- advdata.include_appearance = false;
- advdata.flags = flags;
- advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
- advdata.uuids_complete.p_uuids = adv_uuids;
- ble_advdata_manuf_data_t manuf_data;
- manuf_data.company_identifier = COMPANY_IDENTIFIER;
- manuf_data.data.size = sizeof(m_addl_adv_manuf_data);
- manuf_data.data.p_data = m_addl_adv_manuf_data;
- advdata.p_manuf_specific_data = &manuf_data;
- err_code = ble_advdata_set(&advdata, NULL);
- APP_ERROR_CHECK(err_code);
- // Initialize advertising parameters (used when starting advertising)
- //memset(&m_adv_params, 0, sizeof(m_adv_params));
- // Build and set advertising data
- // Build advertising data struct to pass into @ref ble_advertising_init.
- // memset(&advdata, 0, sizeof(advdata));
- // advdata.name_type = BLE_ADVDATA_FULL_NAME;
- // advdata.include_appearance = false;
- // advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;
- // memset(&scanrsp, 0, sizeof(scanrsp));
- // scanrsp.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
- // scanrsp.uuids_complete.p_uuids = m_adv_uuids;
- ble_adv_modes_config_t options = {0};
- options.ble_adv_fast_enabled = BLE_ADV_SLOW_ENABLED;
- options.ble_adv_fast_interval = APP_ADV_INTERVAL;
- options.ble_adv_fast_timeout = APP_ADV_TIMEOUT_IN_SECONDS;
- err_code = ble_advertising_init(&advdata, NULL, &options, on_adv_evt, NULL);
- APP_ERROR_CHECK(err_code);
- }
- /****************************************************************************
- ? ?: data_handler_init()
- ? ?: »Øµ÷º¯Êý
- ????: void
- ????: ?
- ****************************************************************************/
- 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);
- }
- }
- /****************************************************************************
- ? ?: register_all_products()
- ? ?: ×¢²á»Øµ÷º¯Êý
- ????: void
- ????: ?
- ****************************************************************************/
- //function for register all products
- void register_all_products(void) {
- REGISTER(mpbledemo2);
- }
- /**@brief Application main function.
- */
- int main(void)
- {
- uint32_t err_code;
- bool erase_bonds;
- uint8_t start_string[] = START_STRING;
- // Initialize.
- APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
- uart_init();
- buttons_leds_init(&erase_bonds);
- ble_stack_init();
- //微信处理
- get_mac_addr(m_addl_adv_manuf_data);
- register_all_products();
- data_handler_init(&m_mpbledemo2_handler, PRODUCT_TYPE_MPBLEDEMO2);
- gap_params_init();
- services_init();
- advertising_init();
- conn_params_init();
- printf("%s",start_string);
- //
- err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
- APP_ERROR_CHECK(err_code);
- // Enter main loop.
- for (;;)
- {
- power_manage();
- m_mpbledemo2_handler->m_data_main_process_func(&m_ble_wechat);
- }
- }
打开#include "ble_wechat_service.h"文件,屏蔽
OK。。。待测试。