You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.1 KiB
86 lines
2.1 KiB
#if 1
|
|
#include "board.h"
|
|
#include "nrf_delay.h"
|
|
#include "project_cfg.h"
|
|
#include "sys.h"
|
|
#include "version.h"
|
|
#include "zble_module.h"
|
|
#include "zdatachannel_service.h"
|
|
|
|
#if 0
|
|
void qingfengboard_test(void) {
|
|
// 测试LED
|
|
debug_light_init(15);
|
|
|
|
// 测试BUTTON
|
|
// static uint8_t io_index[] = {ZPIN(0, 5), ZPIN(1, 9)};
|
|
// zbsp_gpio_state_monitor(1000, (uint8_t*)io_index, ZARRAY_SIZE(io_index));
|
|
|
|
// 测试睡眠唤醒
|
|
zbsp_enter_sleep(3000, 5, true);
|
|
}
|
|
#endif
|
|
|
|
ZDATACANNEL_DEF(m_zhrs, 2 /*回调事件优先级*/, 1 /*client num*/);
|
|
|
|
static const char* hex2str(const uint8_t* data, int32_t len) {
|
|
static char rx[64] = {0};
|
|
memset(rx, 0, sizeof(rx));
|
|
for (int32_t i = 0; i < len; i++) {
|
|
sprintf(rx + i * 2, "%02X", data[i]);
|
|
}
|
|
return rx;
|
|
}
|
|
|
|
void zdatachannel_data_handler(zdatachannel_evt_t* p_evt) {
|
|
/**
|
|
* @brief 接收到指令数据
|
|
*/
|
|
if (p_evt->type == ZDATACANNEL_EVT_RX_DATA) {
|
|
ZLOGI("rx:%s", hex2str(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length));
|
|
}
|
|
}
|
|
|
|
static void ble_evt_handler(ble_evt_t const* p_ble_evt, void* p_context) {
|
|
uint32_t err_code;
|
|
switch (p_ble_evt->header.evt_id) {
|
|
case BLE_GAP_EVT_CONNECTED:
|
|
ZLOGI("Connected");
|
|
break;
|
|
|
|
case BLE_GAP_EVT_DISCONNECTED:
|
|
ZLOGI("Disconnected");
|
|
// zble_module_start_adv();
|
|
break;
|
|
}
|
|
}
|
|
|
|
void on_service_init(void) {
|
|
/**
|
|
* @brief 数据通道初始化
|
|
*/
|
|
ZLOGI("init zdatachannel service");
|
|
zdatachannel_init_t zdatachannle_init;
|
|
memset(&zdatachannle_init, 0, sizeof(zdatachannle_init));
|
|
zdatachannle_init.data_handler = zdatachannel_data_handler;
|
|
ZERROR_CHECK(zdatachannel_init(&m_zhrs, &zdatachannle_init));
|
|
}
|
|
|
|
int main(void) {
|
|
zsys_init();
|
|
NRF_LOG_INFO("compile time :%s", __TIME__);
|
|
NRF_LOG_INFO("Version :%d", VERSION);
|
|
NRF_LOG_INFO("Manufacturer :%s", MANUFACTURER_NAME);
|
|
|
|
static zble_module_cfg_t cfg = //
|
|
{
|
|
.deviceName = "iflytop",
|
|
.on_service_init = on_service_init,
|
|
};
|
|
zble_module_init(&cfg);
|
|
NRF_SDH_BLE_OBSERVER(m_ble_observer, 3, ble_evt_handler, NULL);
|
|
|
|
zble_module_start_adv();
|
|
zsys_loop();
|
|
}
|
|
#endif
|