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.9 KiB
86 lines
2.9 KiB
#include "znordic.h"
|
|
//
|
|
#include <stdarg.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
//
|
|
#include "aproject_config/config.h"
|
|
#include "app_basic_service/device_version_info_mgr.h"
|
|
#include "app_basic_service/zapp.h"
|
|
#include "zble_module.h"
|
|
#include "zdatachannel_service.h"
|
|
#include "one_conduction_main.h"
|
|
//
|
|
ZDATACHANNEL_DEF(m_zhrs, 2 /*优先级*/, 1 /*client num*/); // 蓝牙服务
|
|
/**
|
|
* @brief 蓝牙消息解析
|
|
*/
|
|
void zdatachannel_data_handler(zdatachannel_evt_t *p_evt) {
|
|
if (p_evt->type == ZDATACHANNEL_EVT_RX_DATA) {
|
|
one_conduction_process_rx_packet((uint8_t *)p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);
|
|
}
|
|
}
|
|
void on_service_init(void) {
|
|
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));
|
|
}
|
|
|
|
/*lint -save -e14 */
|
|
/**
|
|
* Function is implemented as weak so that it can be overwritten by custom application error handler
|
|
* when needed.
|
|
*/
|
|
void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info) {
|
|
__disable_irq();
|
|
NRF_LOG_FINAL_FLUSH();
|
|
|
|
switch (id) {
|
|
case NRF_FAULT_ID_SDK_ASSERT: {
|
|
assert_info_t *p_info = (assert_info_t *)info;
|
|
NRF_LOG_ERROR("ASSERTION FAILED at %s:%u", p_info->p_file_name, p_info->line_num);
|
|
break;
|
|
}
|
|
case NRF_FAULT_ID_SDK_ERROR: {
|
|
error_info_t *p_info = (error_info_t *)info;
|
|
NRF_LOG_ERROR("ERROR %u [%s] at %s:%u\r\nPC at: 0x%08x", p_info->err_code, nrf_strerror_get(p_info->err_code), p_info->p_file_name, p_info->line_num, pc);
|
|
NRF_LOG_ERROR("End of error report");
|
|
break;
|
|
}
|
|
default:
|
|
NRF_LOG_ERROR("UNKNOWN FAULT at 0x%08X", pc);
|
|
break;
|
|
}
|
|
|
|
NRF_BREAKPOINT_COND;
|
|
// On assert, the system can only recover with a reset.
|
|
|
|
NRF_LOG_WARNING("System reset");
|
|
NVIC_SystemReset();
|
|
}
|
|
|
|
int main() {
|
|
zapp_early_init();
|
|
znordic_init_without_wd();
|
|
zapp_init();
|
|
|
|
/*******************************************************************************
|
|
* 蓝牙服务初始化 *
|
|
*******************************************************************************/
|
|
static zble_module_cfg_t cfg;
|
|
cfg.deviceName = device_info_read_sn_str();
|
|
cfg.on_service_init = on_service_init;
|
|
zble_module_init(&cfg);
|
|
/*******************************************************************************
|
|
* 设备控制服务初始化 *
|
|
*******************************************************************************/
|
|
one_conduction_main();
|
|
/*******************************************************************************
|
|
* LOOP *
|
|
*******************************************************************************/
|
|
zapp_start_schedule();
|
|
znordic_loop();
|
|
}
|