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.

255 lines
7.8 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 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. #include "basic/zble_module.h"
  2. #include "basic/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 "app_uart.h"
  11. #include "basic/ssd1306/driver_ssd1306_basic.h"
  12. #include "one_conduction/one_conduction_board.h"
  13. #include "three_lead\three_lead_board.h"
  14. #if defined(UART_PRESENT)
  15. #include "nrf_uart.h"
  16. #endif
  17. #if defined(UARTE_PRESENT)
  18. #include "nrf_uarte.h"
  19. #endif
  20. #if 0
  21. static void test_tx_timer_cb(void* p_context) {
  22. ZLOGI("test_tx_timer_cb");
  23. ThreeLeadECG_sdcard_mount();
  24. uint32_t data;
  25. data = 1;
  26. }
  27. extern uint32_t g_nrf_log_tx_pin;
  28. APP_TIMER_DEF(m_test_tx_timer);
  29. void main() {
  30. g_nrf_log_tx_pin = 2;
  31. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  32. znordic_init();
  33. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  34. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_SINGLE_SHOT, test_tx_timer_cb));
  35. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
  36. znordic_loop();
  37. }
  38. #endif
  39. // EEPROM_TEST
  40. #if 0
  41. static void test_tx_timer_cb(void* p_context) {
  42. static uint32_t data;
  43. data++;
  44. // ZLOGI("test_tx_timer_cb %d", data);
  45. }
  46. extern uint32_t g_nrf_log_tx_pin;
  47. APP_TIMER_DEF(m_test_tx_timer);
  48. void main() {
  49. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  50. znordic_init();
  51. // SingleLeadECG_beep_init();
  52. // SingleLeadECG_beep_set_state(false);
  53. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  54. NRF_LOG_INTERNAL_FLUSH();
  55. SingleLeadECG_eeprom_init();
  56. static uint8_t eepromw_test_data[256];
  57. static uint8_t eepromw_rx_data[256];
  58. for (size_t i = 0; i < 256; i++) {
  59. eepromw_test_data[i] = i;
  60. }
  61. SingleLeadECG_eeprom_write(0, eepromw_test_data, 256);
  62. // nrf_delay_ms(20);
  63. // SingleLeadECG_eeprom_read(0, eepromw_rx_data, 256);
  64. // for (size_t i = 0; i < 256; i++) {
  65. // ZLOGI("eepromw_rx_data[%d] = %d", i, eepromw_rx_data[i]);
  66. // NRF_LOG_INTERNAL_FLUSH();
  67. // }
  68. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  69. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
  70. znordic_loop();
  71. }
  72. #endif
  73. /*******************************************************************************
  74. * +LED测试 *
  75. *******************************************************************************/
  76. #if 0
  77. static void test_tx_timer_cb(void* p_context) {
  78. static uint32_t data;
  79. data++;
  80. ZLOGI("test_tx_timer_cb %d", data);
  81. SingleLeadECG_led_green_set_state(data % 2 == 0);
  82. SingleLeadECG_led_blue_set_state(data % 3 == 0);
  83. }
  84. extern uint32_t g_nrf_log_tx_pin;
  85. APP_TIMER_DEF(m_test_tx_timer);
  86. void main() {
  87. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  88. znordic_init();
  89. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  90. NRF_LOG_INTERNAL_FLUSH();
  91. SingleLeadECG_screen_init();
  92. ssd1306_basic_init(SSD1306_INTERFACE_SPI, SSD1306_ADDR_SA0_0);
  93. ssd1306_basic_display_on();
  94. ssd1306_basic_string(0, 0, "123456789123456789123", 21, 0, SSD1306_FONT_12);
  95. ssd1306_basic_string(0, 16, "123456789123456789123", 21, 0, SSD1306_FONT_12);
  96. ssd1306_basic_string(0, 32, "123456789123456789123", 21, 0, SSD1306_FONT_12);
  97. ssd1306_basic_string(0, 48, "123456789123456789123", 21, 0, SSD1306_FONT_12);
  98. SingleLeadECG_led_init();
  99. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  100. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
  101. znordic_loop();
  102. }
  103. #endif
  104. /*******************************************************************************
  105. * ECG *
  106. *******************************************************************************/
  107. #if 1
  108. #define UART_TX_BUF_SIZE 256 /**< UART TX buffer size. */
  109. #define UART_RX_BUF_SIZE 256 /**< UART RX buffer size. */
  110. uint32_t err_code;
  111. app_uart_comm_params_t const comm_params = //
  112. {
  113. .rx_pin_no = UART_PIN_DISCONNECTED,
  114. .tx_pin_no = 41,
  115. .rts_pin_no = UART_PIN_DISCONNECTED,
  116. .cts_pin_no = UART_PIN_DISCONNECTED,
  117. .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
  118. .use_parity = false,
  119. .baud_rate = NRF_UARTE_BAUDRATE_921600,
  120. };
  121. void uart_error_handle(app_uart_evt_t* p_event) {}
  122. void uartinit() {
  123. APP_UART_FIFO_INIT(&comm_params, UART_RX_BUF_SIZE, UART_TX_BUF_SIZE, uart_error_handle, APP_IRQ_PRIORITY_LOWEST, err_code);
  124. APP_ERROR_CHECK(err_code);
  125. }
  126. void zchip_log(const char* fmt, ...) {
  127. static char tx[256] = {0};
  128. va_list args;
  129. va_start(args, fmt);
  130. vsprintf(tx, fmt, args);
  131. for (size_t i = 0; i < strlen(tx); i++) {
  132. app_uart_put(tx[i]);
  133. }
  134. va_end(args);
  135. }
  136. static void test_tx_timer_cb(void* p_context) {
  137. static uint32_t data;
  138. data++;
  139. // SingleLeadECG_ecg_nlod_get_connected_state();
  140. // SingleLeadECG_ecg_plod_get_connected_state();
  141. // SingleLeadECG_ecg_plod_get_ecg_val();
  142. // ZLOGI("%d nlod %d plod %d ecg:%d", data, SingleLeadECG_ecg_nlod_get_connected_state(), SingleLeadECG_ecg_plod_get_connected_state(), SingleLeadECG_ecg_plod_get_ecg_val());
  143. // ZLOGI("%d,%d,%d", SingleLeadECG_ecg_nlod_get_connected_state(), SingleLeadECG_ecg_plod_get_connected_state(), SingleLeadECG_ecg_plod_get_ecg_val());
  144. zchip_log("%d,%d,%d\n", SingleLeadECG_ecg_nlod_get_connected_state(), SingleLeadECG_ecg_plod_get_connected_state(), SingleLeadECG_ecg_plod_get_ecg_val());
  145. // app_uart_put('c');
  146. // app_uart_put('c');
  147. // app_uart_put('c');
  148. // app_uart_put('c');
  149. // app_uart_put('c');
  150. // NRF_LOG_INFO("......");
  151. }
  152. extern uint32_t g_nrf_log_tx_pin;
  153. APP_TIMER_DEF(m_test_tx_timer);
  154. void main() {
  155. // g_nrf_log_tx_pin = 41;
  156. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  157. znordic_init();
  158. SingleLeadECG_adc_module_init();
  159. uartinit();
  160. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  161. NRF_LOG_INTERNAL_FLUSH();
  162. SingleLeadECG_ecg_init();
  163. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  164. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(5), NULL));
  165. znordic_loop();
  166. }
  167. #endif
  168. /*******************************************************************************
  169. * *
  170. *******************************************************************************/
  171. #if 0
  172. extern uint32_t g_nrf_log_tx_pin;
  173. APP_TIMER_DEF(m_test_tx_timer);
  174. ZDATACHANNEL_DEF(m_zhrs, 2 /*回调事件优先级*/, 1 /*client num*/);
  175. static const char* hex2str(const uint8_t* data, int32_t len) {
  176. static char rx[64] = {0};
  177. memset(rx, 0, sizeof(rx));
  178. for (int32_t i = 0; i < len; i++) {
  179. sprintf(rx + i * 2, "%02X", data[i]);
  180. }
  181. return rx;
  182. }
  183. static void zdatachannel_data_handler(zdatachannel_evt_t* p_evt) {
  184. /**
  185. * @brief
  186. */
  187. if (p_evt->type == ZDATACHANNEL_EVT_RX_DATA) {
  188. ZLOGI("rx:%s", hex2str(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length));
  189. }
  190. }
  191. static void on_service_init(void) {
  192. /**
  193. * @brief
  194. */
  195. ZLOGI("init zdatachannel service");
  196. zdatachannel_init_t zdatachannle_init;
  197. memset(&zdatachannle_init, 0, sizeof(zdatachannle_init));
  198. zdatachannle_init.data_handler = zdatachannel_data_handler;
  199. ZERROR_CHECK(zdatachannel_init(&m_zhrs, &zdatachannle_init));
  200. }
  201. void main() {
  202. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  203. znordic_init(0, 20);
  204. NRF_LOG_INFO("compile time :%s", __TIME__);
  205. NRF_LOG_INFO("Version :%d", VERSION);
  206. NRF_LOG_INFO("Manufacturer :%s", MANUFACTURER_NAME);
  207. static zble_module_cfg_t cfg = //
  208. {
  209. .deviceName = BLE_NAME,
  210. .on_service_init = on_service_init,
  211. };
  212. zble_module_init(&cfg);
  213. zble_module_start_adv();
  214. znordic_loop();
  215. }
  216. #endif