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.

142 lines
3.9 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. #include "zble_module.h"
  2. #include "zdatachannel_service.h"
  3. #include "znordic.h"
  4. //
  5. #include <stdarg.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. //
  10. #include <math.h>
  11. #include "app_scheduler.h"
  12. #include "znordic.h"
  13. #if defined(UART_PRESENT)
  14. #include "nrf_uart.h"
  15. #endif
  16. #if defined(UARTE_PRESENT)
  17. #include "nrf_uarte.h"
  18. #endif
  19. #if 0
  20. int main() {
  21. one_conduction_main();
  22. return 0;
  23. }
  24. #else
  25. #include "nrfx_timer.h"
  26. ZDATACHANNEL_DEF(m_zhrs, 2 /*���ȼ�*/, 1 /*client num*/); // ��������
  27. static const nrfx_timer_t m_timer = NRFX_TIMER_INSTANCE(1); /**< Timer used for channel sweeps and tx with duty cycle. */
  28. static void zdatachannel_data_handler(zdatachannel_evt_t* p_evt) {
  29. /**
  30. * @brief
  31. */
  32. if (p_evt->type == ZDATACHANNEL_EVT_RX_DATA) {
  33. }
  34. }
  35. static void on_service_init(void) {
  36. ZLOGI("init zdatachannel service");
  37. zdatachannel_init_t zdatachannle_init;
  38. memset(&zdatachannle_init, 0, sizeof(zdatachannle_init));
  39. zdatachannle_init.data_handler = zdatachannel_data_handler;
  40. ZERROR_CHECK(zdatachannel_init(&m_zhrs, &zdatachannle_init));
  41. }
  42. uint16_t adc_val_cache[5] = {0};
  43. int adc_val_index = 0;
  44. void sendpacket_to_pc() {
  45. uint8_t data[255];
  46. // adc_val_cache[0] = 1;
  47. // adc_val_cache[1] = 2;
  48. // adc_val_cache[2] = 3;
  49. // adc_val_cache[3] = 4;
  50. // adc_val_cache[4] = 5;
  51. for (int i = 0; i < adc_val_index; i++) {
  52. data[i * 6 + 0] = 0xA2;
  53. data[i * 6 + 1] = 0x2;
  54. data[i * 6 + 2] = adc_val_cache[i] & 0xff;
  55. data[i * 6 + 3] = adc_val_cache[i] >> 8 & 0xff;
  56. data[i * 6 + 4] = 0x2;
  57. data[i * 6 + 5] = 0xA2;
  58. }
  59. zdatachannel_data_send2(data, 6 * adc_val_index);
  60. }
  61. static void nrfx_timer_event_handler(nrf_timer_event_t event_type, void* p_context) { //
  62. uint16_t val = SingleLeadECG_ecg_plod_get_ecg_val(); // 12bit
  63. /*******************************************************************************
  64. * ʾݼֵ *
  65. *******************************************************************************/
  66. adc_val_cache[adc_val_index] = val;
  67. adc_val_index++;
  68. if (adc_val_index >= 5) {
  69. if (zdatachannel_is_connected()) {
  70. sendpacket_to_pc();
  71. } else {
  72. }
  73. adc_val_index = 0;
  74. }
  75. static int cnt;
  76. static bool state;
  77. cnt++;
  78. if (zdatachannel_is_connected()) {
  79. SingleLeadECG_led_green_set_state(1);
  80. } else {
  81. if (cnt % 500 == 0) {
  82. SingleLeadECG_led_green_set_state(state);
  83. state = !state;
  84. }
  85. }
  86. }
  87. int main() { //
  88. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  89. znordic_init();
  90. NRF_LOG_INFO("compile time :%s", __TIME__);
  91. ztm_t tm;
  92. static zble_module_cfg_t cfg = //
  93. {
  94. .deviceName = "OneLeadTest",
  95. .on_service_init = on_service_init,
  96. };
  97. zble_module_init(&cfg);
  98. SingleLeadECG_adc_module_init();
  99. SingleLeadECG_led_init();
  100. SingleLeadECG_led_green_set_state(0);
  101. zble_module_start_adv();
  102. /*******************************************************************************
  103. * ʱʼ *
  104. *******************************************************************************/
  105. /**
  106. * @brief ʼʱ
  107. */
  108. nrfx_err_t err;
  109. nrfx_timer_config_t timer_cfg = {
  110. .frequency = NRF_TIMER_FREQ_500kHz,
  111. .mode = NRF_TIMER_MODE_TIMER,
  112. .bit_width = NRF_TIMER_BIT_WIDTH_24,
  113. .p_context = NULL,
  114. .interrupt_priority = NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY,
  115. };
  116. err = nrfx_timer_init(&m_timer, &timer_cfg, nrfx_timer_event_handler);
  117. if (err != NRFX_SUCCESS) {
  118. NRF_LOG_ERROR("nrfx_timer_init failed with: %d\n", err);
  119. }
  120. uint32_t timer_ticks = nrfx_timer_ms_to_ticks(&m_timer, 5); // 500HZ
  121. nrfx_timer_extended_compare(&m_timer, NRF_TIMER_CC_CHANNEL0, timer_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
  122. nrfx_timer_enable(&m_timer);
  123. znordic_loop();
  124. }
  125. #endif