|
@ -5,6 +5,7 @@ |
|
|
#include <stdint.h> |
|
|
#include <stdint.h> |
|
|
#include <string.h> |
|
|
#include <string.h> |
|
|
|
|
|
|
|
|
|
|
|
#include "ble_bas.h" |
|
|
#include "znordic.h" |
|
|
#include "znordic.h" |
|
|
|
|
|
|
|
|
#if BLE_DFU_ENABLED |
|
|
#if BLE_DFU_ENABLED |
|
@ -18,8 +19,7 @@ |
|
|
#define SLAVE_LATENCY 0 /**< Slave latency. */ |
|
|
#define SLAVE_LATENCY 0 /**< Slave latency. */ |
|
|
#define CONN_SUP_TIMEOUT MSEC_TO_UNITS(4000, UNIT_10_MS) /**< Connection supervisory timeout (4 seconds), Supervision Timeout uses 10 ms units. */ |
|
|
#define CONN_SUP_TIMEOUT MSEC_TO_UNITS(4000, UNIT_10_MS) /**< Connection supervisory timeout (4 seconds), Supervision Timeout uses 10 ms units. */ |
|
|
#define NUS_SERVICE_UUID_TYPE BLE_UUID_TYPE_VENDOR_BEGIN /**< UUID type for the Nordic UART Service (vendor specific). */ |
|
|
#define NUS_SERVICE_UUID_TYPE BLE_UUID_TYPE_VENDOR_BEGIN /**< UUID type for the Nordic UART Service (vendor specific). */ |
|
|
static ble_uuid_t m_adv_uuids[] = /**< Universally unique service identifier. */ |
|
|
|
|
|
{{BLE_UUID_NUS_SERVICE, NUS_SERVICE_UUID_TYPE}}; |
|
|
|
|
|
|
|
|
|
|
|
#define APP_ADV_INTERVAL 64 /**< The advertising interval (in units of 0.625 ms. This value corresponds to 40 ms). */ |
|
|
#define APP_ADV_INTERVAL 64 /**< The advertising interval (in units of 0.625 ms. This value corresponds to 40 ms). */ |
|
|
#define APP_ADV_DURATION 18000 /**< The advertising duration (180 seconds) in units of 10 milliseconds. */ |
|
|
#define APP_ADV_DURATION 18000 /**< The advertising duration (180 seconds) in units of 10 milliseconds. */ |
|
|
BLE_ADVERTISING_DEF(m_advertising); /**< Advertising module instance. */ |
|
|
BLE_ADVERTISING_DEF(m_advertising); /**< Advertising module instance. */ |
|
@ -284,6 +284,12 @@ static void ble_dfu_evt_handler(ble_dfu_buttonless_evt_type_t event) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
BLE_BAS_DEF(m_bas); /**< Structure used to identify the Battery Service. */ |
|
|
|
|
|
|
|
|
|
|
|
// static ble_uuid_t m_adv_uuids[] = /**< Universally unique service identifier. */ |
|
|
|
|
|
// {{0x0002, BLE_UUID_TYPE_VENDOR_BEGIN}}; |
|
|
|
|
|
|
|
|
|
|
|
// static ble_uuid_t m_adv_uuids[] = {{BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE}}; |
|
|
|
|
|
|
|
|
void zble_module_init(zble_module_cfg_t* cfg) { |
|
|
void zble_module_init(zble_module_cfg_t* cfg) { |
|
|
/** |
|
|
/** |
|
@ -329,20 +335,6 @@ void zble_module_init(zble_module_cfg_t* cfg) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/******************************************************************************* |
|
|
/******************************************************************************* |
|
|
* 蓝牙服务初始?? * |
|
|
|
|
|
*******************************************************************************/ |
|
|
|
|
|
#if BLE_DFU_ENABLED |
|
|
|
|
|
{ |
|
|
|
|
|
// ble_dfu_buttonless_init_t dfus_init = {0}; |
|
|
|
|
|
// dfus_init.evt_handler = ble_dfu_evt_handler; |
|
|
|
|
|
// ret_code_t err_code = ble_dfu_buttonless_init(&dfus_init); |
|
|
|
|
|
// ZERROR_CHECK(err_code); |
|
|
|
|
|
|
|
|
|
|
|
if (cfg->on_service_init) cfg->on_service_init(); |
|
|
|
|
|
} |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************* |
|
|
|
|
|
* 广播初始?? * |
|
|
* 广播初始?? * |
|
|
*******************************************************************************/ |
|
|
*******************************************************************************/ |
|
|
{ |
|
|
{ |
|
@ -352,12 +344,18 @@ void zble_module_init(zble_module_cfg_t* cfg) { |
|
|
memset(&init, 0, sizeof(init)); |
|
|
memset(&init, 0, sizeof(init)); |
|
|
|
|
|
|
|
|
init.advdata.name_type = BLE_ADVDATA_FULL_NAME; |
|
|
init.advdata.name_type = BLE_ADVDATA_FULL_NAME; |
|
|
init.advdata.include_appearance = false; |
|
|
|
|
|
|
|
|
init.advdata.include_appearance = true; |
|
|
// init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE; |
|
|
// init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE; |
|
|
init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; |
|
|
init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; |
|
|
|
|
|
|
|
|
init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]); |
|
|
|
|
|
init.srdata.uuids_complete.p_uuids = m_adv_uuids; |
|
|
|
|
|
|
|
|
// init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]); |
|
|
|
|
|
// init.srdata.uuids_complete.p_uuids = m_adv_uuids; |
|
|
|
|
|
|
|
|
|
|
|
err_code = sd_ble_gap_appearance_set(BLE_APPEARANCE_GENERIC_HEART_RATE_SENSOR); |
|
|
|
|
|
APP_ERROR_CHECK(err_code); |
|
|
|
|
|
|
|
|
|
|
|
init.srdata.uuids_complete.uuid_cnt = 0; |
|
|
|
|
|
init.srdata.uuids_complete.p_uuids = NULL; |
|
|
|
|
|
|
|
|
init.config.ble_adv_fast_enabled = true; |
|
|
init.config.ble_adv_fast_enabled = true; |
|
|
init.config.ble_adv_fast_interval = APP_ADV_INTERVAL; |
|
|
init.config.ble_adv_fast_interval = APP_ADV_INTERVAL; |
|
@ -369,6 +367,20 @@ void zble_module_init(zble_module_cfg_t* cfg) { |
|
|
|
|
|
|
|
|
ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG); |
|
|
ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************* |
|
|
|
|
|
* 蓝牙服务初始?? * |
|
|
|
|
|
*******************************************************************************/ |
|
|
|
|
|
#if BLE_DFU_ENABLED |
|
|
|
|
|
{ |
|
|
|
|
|
ble_dfu_buttonless_init_t dfus_init = {0}; |
|
|
|
|
|
dfus_init.evt_handler = ble_dfu_evt_handler; |
|
|
|
|
|
ret_code_t err_code = ble_dfu_buttonless_init(&dfus_init); |
|
|
|
|
|
ZERROR_CHECK(err_code); |
|
|
|
|
|
if (cfg->on_service_init) cfg->on_service_init(); |
|
|
|
|
|
} |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
/******************************************************************************* |
|
|
/******************************************************************************* |
|
|
* 连接参数初始?? * |
|
|
* 连接参数初始?? * |
|
|
*******************************************************************************/ |
|
|
*******************************************************************************/ |
|
|