|
|
#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
ZDATACHANNEL_DEF(m_zhrs, 2 /*回调事件优先级*/, 1 /*client num*/); APP_TIMER_DEF(m_test_tx_timer);
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 == ZDATACHANNEL_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) { 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)); }
static void test_tx_timer_cb(void* p_context) { // static uint32_t data;
// uint16_t txlen = 4;
// data++;
// zdatachannel_data_send((uint8_t*)&data, &txlen);
ZLOGI("adc channel %d %d", adc_module_heart_elect_channel_read_val(), adc_module_battery_channel_read_val()); }
static void board_init() { adc_module_init(); adc_module_battery_channel_init(NRF_SAADC_INPUT_VDD); adc_module_heart_elect_channel_init(NRF_SAADC_INPUT_AIN2); }
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_test_ble", .on_service_init = on_service_init, }; zble_module_init(&cfg); board_init();
NRF_SDH_BLE_OBSERVER(m_ble_observer, 3, ble_evt_handler, NULL);
ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb)); ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
zble_module_start_adv(); zsys_loop(); } #endif
|