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

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. #if 1
  2. #include "board.h"
  3. #include "nrf_delay.h"
  4. #include "project_cfg.h"
  5. #include "sys.h"
  6. #include "version.h"
  7. #include "zble_module.h"
  8. #include "zdatachannel_service.h"
  9. #if 0
  10. void qingfengboard_test(void) {
  11. // 测试LED
  12. debug_light_init(15);
  13. // 测试BUTTON
  14. // static uint8_t io_index[] = {ZPIN(0, 5), ZPIN(1, 9)};
  15. // zbsp_gpio_state_monitor(1000, (uint8_t*)io_index, ZARRAY_SIZE(io_index));
  16. // 测试睡眠唤醒
  17. zbsp_enter_sleep(3000, 5, true);
  18. }
  19. #endif
  20. ZDATACANNEL_DEF(m_zhrs, 2 /*回调事件优先级*/, 1 /*client num*/);
  21. static const char* hex2str(const uint8_t* data, int32_t len) {
  22. static char rx[64] = {0};
  23. memset(rx, 0, sizeof(rx));
  24. for (int32_t i = 0; i < len; i++) {
  25. sprintf(rx + i * 2, "%02X", data[i]);
  26. }
  27. return rx;
  28. }
  29. void zdatachannel_data_handler(zdatachannel_evt_t* p_evt) {
  30. /**
  31. * @brief
  32. */
  33. if (p_evt->type == ZDATACANNEL_EVT_RX_DATA) {
  34. ZLOGI("rx:%s", hex2str(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length));
  35. }
  36. }
  37. static void ble_evt_handler(ble_evt_t const* p_ble_evt, void* p_context) {
  38. uint32_t err_code;
  39. switch (p_ble_evt->header.evt_id) {
  40. case BLE_GAP_EVT_CONNECTED:
  41. ZLOGI("Connected");
  42. break;
  43. case BLE_GAP_EVT_DISCONNECTED:
  44. ZLOGI("Disconnected");
  45. // zble_module_start_adv();
  46. break;
  47. }
  48. }
  49. void on_service_init(void) {
  50. /**
  51. * @brief
  52. */
  53. ZLOGI("init zdatachannel service");
  54. zdatachannel_init_t zdatachannle_init;
  55. memset(&zdatachannle_init, 0, sizeof(zdatachannle_init));
  56. zdatachannle_init.data_handler = zdatachannel_data_handler;
  57. ZERROR_CHECK(zdatachannel_init(&m_zhrs, &zdatachannle_init));
  58. }
  59. int main(void) {
  60. zsys_init();
  61. NRF_LOG_INFO("compile time :%s", __TIME__);
  62. NRF_LOG_INFO("Version :%d", VERSION);
  63. NRF_LOG_INFO("Manufacturer :%s", MANUFACTURER_NAME);
  64. static zble_module_cfg_t cfg = //
  65. {
  66. .deviceName = "iflytop",
  67. .on_service_init = on_service_init,
  68. };
  69. zble_module_init(&cfg);
  70. NRF_SDH_BLE_OBSERVER(m_ble_observer, 3, ble_evt_handler, NULL);
  71. zble_module_start_adv();
  72. zsys_loop();
  73. }
  74. #endif