99 lines
2.7 KiB
C
99 lines
2.7 KiB
C
#ifdef __cplusplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
|
|
#include "app_config.h"
|
|
#include "app_error.h"
|
|
|
|
#include "ble_advertising.h"
|
|
|
|
#include "nrf_sdh_ble.h"
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
BLE_ADVERTISING_DEF(m_advertising); /**< Advertising module instance. */
|
|
|
|
#define BLE_ADV_UUID \
|
|
{ \
|
|
{ \
|
|
ELITE_UUID, BLE_UUID_TYPE_BLE \
|
|
} \
|
|
}
|
|
|
|
static void le_adv_evt_handler(ble_adv_evt_t const adv_evt)
|
|
{
|
|
switch (adv_evt)
|
|
{
|
|
case BLE_ADV_EVT_IDLE:
|
|
case BLE_ADV_EVT_DIRECTED_HIGH_DUTY:
|
|
case BLE_ADV_EVT_DIRECTED:
|
|
case BLE_ADV_EVT_FAST:
|
|
case BLE_ADV_EVT_SLOW:
|
|
case BLE_ADV_EVT_FAST_WHITELIST:
|
|
case BLE_ADV_EVT_SLOW_WHITELIST:
|
|
case BLE_ADV_EVT_WHITELIST_REQUEST:
|
|
case BLE_ADV_EVT_PEER_ADDR_REQUEST:
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
static void le_adv_error_handler(uint32_t nrf_error)
|
|
{
|
|
// TODO...
|
|
__BKPT(255);
|
|
}
|
|
|
|
void le_adv_init(uint8_t ble_conn_cfg_tag)
|
|
{
|
|
uint32_t err_code;
|
|
ble_advertising_init_t init;
|
|
|
|
memset(&init, 0, sizeof(init));
|
|
|
|
struct
|
|
{
|
|
uint8_t company_code[2];
|
|
uint8_t hw_ver[4];
|
|
uint8_t build_time[2];
|
|
uint8_t bat_str[3];
|
|
uint16_t bat_volt;
|
|
} __PACKED data = {
|
|
.hw_ver = ELITE_HW_VER,
|
|
.build_time = {24, 01},
|
|
.bat_str = "BAT",
|
|
.bat_volt = 0x0C1C,
|
|
};
|
|
|
|
ble_advdata_manuf_data_t manuf_specific_data;
|
|
manuf_specific_data.data.p_data = (uint8_t *)&data;
|
|
manuf_specific_data.data.size = sizeof(data);
|
|
memcpy(&manuf_specific_data.company_identifier, &ELITE_COMPANY_CODE[0], 2);
|
|
memcpy(&data.company_code[0], &ELITE_COMPANY_CODE[2], 2);
|
|
|
|
ble_uuid_t m_adv_uuids[] = BLE_ADV_UUID;
|
|
init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
|
|
init.advdata.uuids_complete.p_uuids = m_adv_uuids;
|
|
init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
|
|
init.srdata.p_manuf_specific_data = &manuf_specific_data;
|
|
init.srdata.name_type = BLE_ADVDATA_FULL_NAME;
|
|
|
|
init.config.ble_adv_fast_enabled = true;
|
|
init.config.ble_adv_fast_interval = MSEC_TO_UNITS(75, UNIT_0_625_MS);
|
|
init.config.ble_adv_fast_timeout = MSEC_TO_UNITS(0, UNIT_10_MS);
|
|
|
|
init.evt_handler = le_adv_evt_handler;
|
|
init.error_handler = le_adv_error_handler;
|
|
|
|
err_code = ble_advertising_init(&m_advertising, &init);
|
|
APP_ERROR_CHECK(err_code);
|
|
|
|
ble_advertising_conn_cfg_tag_set(&m_advertising, ble_conn_cfg_tag);
|
|
|
|
ret_code_t ret = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
|
|
APP_ERROR_CHECK(ret);
|
|
}
|