102 lines
2.7 KiB
C
102 lines
2.7 KiB
C
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
|
|
#include "app_config.h"
|
|
#include "apply_old_config.h"
|
|
#include "sdk_config.h"
|
|
|
|
#include "nrf_log.h"
|
|
#include "nrf_log_ctrl.h"
|
|
#include "nrf_log_default_backends.h"
|
|
|
|
#include "nrf_delay.h"
|
|
#include "nrf_gpio.h"
|
|
|
|
#include "nrf_sdh.h"
|
|
#include "nrf_sdh_ble.h"
|
|
#include "nrf_sdh_freertos.h"
|
|
|
|
#include "ble_advdata.h"
|
|
#include "ble_advertising.h"
|
|
#include "ble_srv_common.h"
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
BLE_ADVERTISING_DEF(m_advertising); /**< Advertising module instance. */
|
|
|
|
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));
|
|
|
|
extern uint16_t bas_volt_read(void);
|
|
struct
|
|
{
|
|
const uint8_t company_code[5];
|
|
const uint8_t hw_ver[4];
|
|
uint16_t bat_volt;
|
|
} __PACKED data = {
|
|
.company_code = ELITE_COMPANY_CODE,
|
|
.hw_ver = ELITE_HW_VER,
|
|
.bat_volt = bas_volt_read(),
|
|
};
|
|
|
|
ble_advdata_manuf_data_t manuf_specific_data;
|
|
manuf_specific_data.data.p_data = (uint8_t *)&data;
|
|
manuf_specific_data.data.size = sizeof(data);
|
|
manuf_specific_data.company_identifier = 0xFFFF;
|
|
init.advdata.p_manuf_specific_data = &manuf_specific_data;
|
|
init.advdata.name_type = BLE_ADVDATA_FULL_NAME;
|
|
init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
|
|
|
|
init.config.ble_adv_fast_enabled = true;
|
|
init.config.ble_adv_fast_interval = MSEC_TO_UNITS(25, UNIT_0_625_MS);
|
|
init.config.ble_adv_fast_timeout = MSEC_TO_UNITS(3000, UNIT_10_MS);
|
|
init.config.ble_adv_slow_enabled = true;
|
|
init.config.ble_adv_slow_interval = MSEC_TO_UNITS(250, UNIT_0_625_MS);
|
|
init.config.ble_adv_slow_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);
|
|
}
|