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.

657 lines
23 KiB

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 "basic\zdatachannel_service.h"
  13. #include "one_conduction/one_conduction_board.h"
  14. #include "three_lead\three_lead_board.h"
  15. #if defined(UART_PRESENT)
  16. #include "nrf_uart.h"
  17. #endif
  18. #if defined(UARTE_PRESENT)
  19. #include "nrf_uarte.h"
  20. #endif
  21. #if 0
  22. static void test_tx_timer_cb(void* p_context) {
  23. static uint32_t data;
  24. data++;
  25. ZLOGI("tim cb %d", data);
  26. // ThreeLeadECG_sdcard_connect2_ext_usb_sdcard_driver_ic_reset();
  27. }
  28. extern uint32_t g_nrf_log_tx_pin;
  29. APP_TIMER_DEF(m_test_tx_timer);
  30. void main() {
  31. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  32. ThreeLeadECG_beep_init();
  33. ThreeLeadECG_sdcard_base_init();
  34. znordic_init();
  35. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  36. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  37. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(3000), NULL));
  38. znordic_loop();
  39. }
  40. #endif
  41. // EEPROM_TEST
  42. #if 0
  43. static void test_tx_timer_cb(void* p_context) {
  44. static uint32_t data;
  45. data++;
  46. // ZLOGI("test_tx_timer_cb %d", data);
  47. static uint8_t eepromw_test_data[256];
  48. static uint8_t eepromw_rx_data[256];
  49. for (size_t i = 0; i < 256; i++) {
  50. eepromw_test_data[i] = i;
  51. }
  52. // SingleLeadECG_eeprom_write(0, eepromw_test_data, 256);
  53. SingleLeadECG_eeprom_read(0, eepromw_rx_data, 256);
  54. // for (size_t i = 0; i < 256; i++) {
  55. // ZLOGI("eepromw_rx_data[%d] = %d", i, eepromw_rx_data[i]);
  56. // NRF_LOG_INTERNAL_FLUSH();
  57. // }
  58. }
  59. extern uint32_t g_nrf_log_tx_pin;
  60. APP_TIMER_DEF(m_test_tx_timer);
  61. void main() {
  62. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  63. znordic_init();
  64. // SingleLeadECG_beep_init();
  65. // SingleLeadECG_beep_set_state(false);
  66. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  67. NRF_LOG_INTERNAL_FLUSH();
  68. SingleLeadECG_eeprom_init();
  69. // nrf_delay_ms(20);
  70. // SingleLeadECG_eeprom_read(0, eepromw_rx_data, 256);
  71. // for (size_t i = 0; i < 256; i++) {
  72. // ZLOGI("eepromw_rx_data[%d] = %d", i, eepromw_rx_data[i]);
  73. // NRF_LOG_INTERNAL_FLUSH();
  74. // }
  75. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  76. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
  77. znordic_loop();
  78. }
  79. #endif
  80. /*******************************************************************************
  81. * +LED测试 *
  82. *******************************************************************************/
  83. #if 1
  84. const unsigned char gImage_0[1024] = { /* 0X02,0X01,0X80,0X00,0X40,0X00, */
  85. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  86. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  87. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  88. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  89. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  90. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  91. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  92. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  93. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X0F,
  94. 0X1F,0X3F,0X78,0X70,0X70,0X70,0X78,0X3F,0X1F,0X0F,0X00,0X00,0X00,0X00,0X00,0X00,
  95. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  96. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  97. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  98. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  99. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  100. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  101. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X80,
  102. 0XC0,0XE0,0XF0,0X70,0X70,0X70,0XF0,0XE0,0XC0,0X80,0X00,0X00,0X00,0X00,0X00,0X00,
  103. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  104. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  105. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  106. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  107. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  108. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  109. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  110. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  111. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  112. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  113. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  114. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  115. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  116. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  117. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  118. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  119. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  120. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  121. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  122. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  123. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  124. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  125. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  126. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  127. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  128. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  129. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  130. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  131. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  132. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  133. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  134. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  135. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  136. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  137. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  138. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  139. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  140. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  141. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  142. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  143. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  144. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  145. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  146. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  147. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  148. 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
  149. };
  150. static void test_tx_timer_cb(void* p_context) {
  151. static uint32_t data;
  152. data++;
  153. ZLOGI("test_tx_timer_cb %d", data);
  154. SingleLeadECG_led_green_set_state(data % 2 == 0);
  155. SingleLeadECG_led_blue_set_state(data % 3 == 0);
  156. }
  157. extern uint32_t g_nrf_log_tx_pin;
  158. APP_TIMER_DEF(m_test_tx_timer);
  159. void main() {
  160. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  161. znordic_init();
  162. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  163. NRF_LOG_INTERNAL_FLUSH();
  164. SingleLeadECG_screen_init();
  165. ssd1306_basic_init(SSD1306_INTERFACE_SPI, SSD1306_ADDR_SA0_0);
  166. ssd1306_basic_display_on();
  167. ssd1306_basic_string(0, 0, "123456789123456789123", 21, 0, SSD1306_FONT_12);
  168. ssd1306_basic_string(0, 16, "123456789123456789123", 21, 0, SSD1306_FONT_12);
  169. ssd1306_basic_string(0, 32, "123456789123456789123", 21, 0, SSD1306_FONT_12);
  170. ssd1306_basic_string(0, 48, "123456789123456789123", 21, 0, SSD1306_FONT_12);
  171. SingleLeadECG_led_init();
  172. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  173. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
  174. znordic_loop();
  175. }
  176. #endif
  177. /*******************************************************************************
  178. * ECG *
  179. *******************************************************************************/
  180. #if 0
  181. #define UART_TX_BUF_SIZE 256 /**< UART TX buffer size. */
  182. #define UART_RX_BUF_SIZE 256 /**< UART RX buffer size. */
  183. uint32_t err_code;
  184. app_uart_comm_params_t const comm_params = //
  185. {
  186. .rx_pin_no = UART_PIN_DISCONNECTED,
  187. .tx_pin_no = 41,
  188. .rts_pin_no = UART_PIN_DISCONNECTED,
  189. .cts_pin_no = UART_PIN_DISCONNECTED,
  190. .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
  191. .use_parity = false,
  192. .baud_rate = NRF_UARTE_BAUDRATE_921600,
  193. };
  194. void uart_error_handle(app_uart_evt_t* p_event) {}
  195. void uartinit() {
  196. APP_UART_FIFO_INIT(&comm_params, UART_RX_BUF_SIZE, UART_TX_BUF_SIZE, uart_error_handle, APP_IRQ_PRIORITY_LOWEST, err_code);
  197. APP_ERROR_CHECK(err_code);
  198. }
  199. void zchip_log(const char* fmt, ...) {
  200. static char tx[256] = {0};
  201. va_list args;
  202. va_start(args, fmt);
  203. vsprintf(tx, fmt, args);
  204. for (size_t i = 0; i < strlen(tx); i++) {
  205. app_uart_put(tx[i]);
  206. }
  207. va_end(args);
  208. }
  209. static void test_tx_timer_cb(void* p_context) {
  210. static uint32_t data;
  211. data++;
  212. // SingleLeadECG_ecg_nlod_get_connected_state();
  213. // SingleLeadECG_ecg_plod_get_connected_state();
  214. // SingleLeadECG_ecg_plod_get_ecg_val();
  215. // 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());
  216. // ZLOGI("%d,%d,%d", SingleLeadECG_ecg_nlod_get_connected_state(), SingleLeadECG_ecg_plod_get_connected_state(), SingleLeadECG_ecg_plod_get_ecg_val());
  217. zchip_log("%d,%d,%d\n", SingleLeadECG_ecg_nlod_get_connected_state(), SingleLeadECG_ecg_plod_get_connected_state(), SingleLeadECG_ecg_plod_get_ecg_val());
  218. // app_uart_put('c');
  219. // app_uart_put('c');
  220. // app_uart_put('c');
  221. // app_uart_put('c');
  222. // app_uart_put('c');
  223. // NRF_LOG_INFO("......");
  224. }
  225. extern uint32_t g_nrf_log_tx_pin;
  226. APP_TIMER_DEF(m_test_tx_timer);
  227. void main() {
  228. // g_nrf_log_tx_pin = 41;
  229. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  230. znordic_init();
  231. SingleLeadECG_adc_module_init();
  232. uartinit();
  233. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  234. NRF_LOG_INTERNAL_FLUSH();
  235. SingleLeadECG_ecg_init();
  236. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  237. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(5), NULL));
  238. znordic_loop();
  239. }
  240. #endif
  241. /*******************************************************************************
  242. * *
  243. *******************************************************************************/
  244. #if 0
  245. extern uint32_t g_nrf_log_tx_pin;
  246. APP_TIMER_DEF(m_test_tx_timer);
  247. ZDATACHANNEL_DEF(m_zhrs, 2 /*回调事件优先级*/, 1 /*client num*/);
  248. static const char* hex2str(const uint8_t* data, int32_t len) {
  249. static char rx[64] = {0};
  250. memset(rx, 0, sizeof(rx));
  251. for (int32_t i = 0; i < len; i++) {
  252. sprintf(rx + i * 2, "%02X", data[i]);
  253. }
  254. return rx;
  255. }
  256. static void zdatachannel_data_handler(zdatachannel_evt_t* p_evt) {
  257. /**
  258. * @brief
  259. */
  260. if (p_evt->type == ZDATACHANNEL_EVT_RX_DATA) {
  261. ZLOGI("rx:%s", hex2str(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length));
  262. }
  263. }
  264. static void on_service_init(void) {
  265. /**
  266. * @brief
  267. */
  268. ZLOGI("init zdatachannel service");
  269. zdatachannel_init_t zdatachannle_init;
  270. memset(&zdatachannle_init, 0, sizeof(zdatachannle_init));
  271. zdatachannle_init.data_handler = zdatachannel_data_handler;
  272. ZERROR_CHECK(zdatachannel_init(&m_zhrs, &zdatachannle_init));
  273. }
  274. void main() {
  275. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  276. ThreeLeadECG_sdcard_base_init();
  277. znordic_init(0, 20);
  278. NRF_LOG_INFO("compile time :%s", __TIME__);
  279. NRF_LOG_INFO("Version :%d", VERSION);
  280. NRF_LOG_INFO("Manufacturer :%s", MANUFACTURER_NAME);
  281. static zble_module_cfg_t cfg = //
  282. {
  283. .deviceName = BLE_NAME,
  284. .on_service_init = on_service_init,
  285. };
  286. zble_module_init(&cfg);
  287. zble_module_start_adv();
  288. znordic_loop();
  289. }
  290. #endif
  291. #if 0
  292. /*******************************************************************************
  293. * ADCTEST *
  294. *******************************************************************************/
  295. static void test_tx_timer_cb(void* p_context) {
  296. static uint32_t data;
  297. data++;
  298. // ZLOGI("test_tx_timer_cb %d", data);
  299. static uint8_t eepromw_test_data[256];
  300. static uint8_t eepromw_rx_data[256];
  301. for (size_t i = 0; i < 256; i++) {
  302. eepromw_test_data[i] = i;
  303. }
  304. int16_t adc = SingleLeadECG_battery_get_adc_val();
  305. int16_t mv = adc * 1.0 / 4096 * 3.6 * 1000 / 2.0 * 3;
  306. ZLOGI("battery:%d", mv);
  307. }
  308. extern uint32_t g_nrf_log_tx_pin;
  309. APP_TIMER_DEF(m_test_tx_timer);
  310. void main() {
  311. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  312. znordic_init();
  313. SingleLeadECG_adc_module_init();
  314. SingleLeadECG_battery_init();
  315. // SingleLeadECG_beep_init();
  316. // SingleLeadECG_beep_set_state(false);
  317. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  318. NRF_LOG_INTERNAL_FLUSH();
  319. // nrf_delay_ms(20);
  320. // SingleLeadECG_eeprom_read(0, eepromw_rx_data, 256);
  321. // for (size_t i = 0; i < 256; i++) {
  322. // ZLOGI("eepromw_rx_data[%d] = %d", i, eepromw_rx_data[i]);
  323. // NRF_LOG_INTERNAL_FLUSH();
  324. // }
  325. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  326. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
  327. znordic_loop();
  328. }
  329. #endif
  330. #if 0
  331. /*******************************************************************************
  332. * 3-ADS1293- *
  333. *******************************************************************************/
  334. extern uint32_t g_nrf_log_tx_pin;
  335. APP_TIMER_DEF(m_test_tx_timer);
  336. static void zdatachanel_send_log(const char* fmt, ...) {
  337. static char tx[256] = {0};
  338. static uint16_t len = 0;
  339. va_list args;
  340. va_start(args, fmt);
  341. len = vsprintf(tx, fmt, args);
  342. zdatachannel_data_send((uint8_t*)tx, &len);
  343. va_end(args);
  344. }
  345. static const char* dumplodstate(uint16_t lodstate) {
  346. static char buf[64];
  347. memset(buf, 0, sizeof(buf));
  348. /**
  349. * @brief
  350. * 1111_0000_0000_0000
  351. */
  352. sprintf(buf, "%d%d%d%d_%d%d%d%d_%d%d%d%d_%d%d%d%d", //
  353. lodstate >> 15 & 0x1, lodstate >> 14 & 0x1, lodstate >> 13 & 0x1, lodstate >> 12 & 0x1, //
  354. lodstate >> 11 & 0x1, lodstate >> 10 & 0x1, lodstate >> 9 & 0x1, lodstate >> 8 & 0x1, //
  355. lodstate >> 7 & 0x1, lodstate >> 6 & 0x1, lodstate >> 5 & 0x1, lodstate >> 4 & 0x1, //
  356. lodstate >> 3 & 0x1, lodstate >> 2 & 0x1, lodstate >> 1 & 0x1, lodstate >> 0 & 0x1);
  357. return buf;
  358. }
  359. static void test_tx_timer_cb(void* p_context) {
  360. static uint32_t data;
  361. data++;
  362. uint16_t val;
  363. ThreeLeadECG_ads1293_get_lod_state(&val);
  364. #if 0
  365. uint32_t sample0;
  366. uint32_t sample1;
  367. uint32_t sample2;
  368. ThreeLeadECG_ads1293_sample(&sample0, &sample1, &sample2);
  369. zdatachanel_send_log("%d,%d,%d\n", sample0, sample1, sample2);
  370. #endif
  371. uint32_t sample0;
  372. uint32_t sample1;
  373. uint32_t sample2;
  374. uint32_t sample10;
  375. uint32_t sample11;
  376. uint32_t sample12;
  377. ThreeLeadECG_ads1293_sample_all(&sample0, &sample1, &sample2, &sample10, &sample11, &sample12);
  378. zdatachanel_send_log("%d,%d,%d,%d,%d,%d\n", sample0, sample1, sample2, sample10, sample11, sample12);
  379. // zdatachanel_send_log("%d,%d,%d\n", data, data, data);
  380. // zdatachanel_send_log("%d %d %s\n", ThreeLeadECG_ready_pin_state_get(), ThreeLeadECG_LineInputDet_get_state(), dumplodstate(val));
  381. // zdatachannel_data_send(tx, &p_length);
  382. }
  383. ZDATACHANNEL_DEF(m_zhrs, 2 /*回调事件优先级*/, 1 /*client num*/);
  384. static const char* hex2str(const uint8_t* data, int32_t len) {
  385. static char rx[64] = {0};
  386. memset(rx, 0, sizeof(rx));
  387. for (int32_t i = 0; i < len; i++) {
  388. sprintf(rx + i * 2, "%02X", data[i]);
  389. }
  390. return rx;
  391. }
  392. // void cmd_remove_note(char* input, int inputlen) {
  393. // bool detect_note = false;
  394. // for (int i = 0; i < inputlen; i++) {
  395. // if (!detect_note && input[i] == '#') {
  396. // detect_note = true;
  397. // }
  398. // if (detect_note) {
  399. // input[i] = 0;
  400. // }
  401. // }
  402. // }
  403. // void cmd_prase_cmd(char* input, int inputlen, int32_t* argc, char* argv[]) {
  404. // for (int i = 0; input[i] == 0 || i < inputlen; i++) {
  405. // if (input[i] == ' ' || input[i] == '\r' || input[i] == '\n') {
  406. // input[i] = 0;
  407. // }
  408. // }
  409. // int j = 0;
  410. // for (int i = 0; input[i] == 0 || i < inputlen; i++) {
  411. // if (input[i] != 0 && j == 0) {
  412. // argv[*argc] = &input[i];
  413. // j = 1;
  414. // *argc = *argc + 1;
  415. // continue;
  416. // }
  417. // if (input[i] == 0 && j == 1) {
  418. // j = 0;
  419. // continue;
  420. // }
  421. // }
  422. // }
  423. char cmdcache[256] = {0};
  424. static void zdatachannel_data_handler(zdatachannel_evt_t* p_evt) {
  425. /**
  426. * @brief
  427. */
  428. if (p_evt->type == ZDATACHANNEL_EVT_RX_DATA) {
  429. }
  430. }
  431. static void on_service_init(void) {
  432. /**
  433. * @brief
  434. */
  435. ZLOGI("init zdatachannel service");
  436. zdatachannel_init_t zdatachannle_init;
  437. memset(&zdatachannle_init, 0, sizeof(zdatachannle_init));
  438. zdatachannle_init.data_handler = zdatachannel_data_handler;
  439. ZERROR_CHECK(zdatachannel_init(&m_zhrs, &zdatachannle_init));
  440. }
  441. void main() {
  442. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  443. ThreeLeadECG_sdcard_base_init();
  444. znordic_init(0, 20);
  445. NRF_LOG_INFO("compile time :%s", __TIME__);
  446. NRF_LOG_INFO("Version :%d", VERSION);
  447. NRF_LOG_INFO("Manufacturer :%s", MANUFACTURER_NAME);
  448. static zble_module_cfg_t cfg = //
  449. {
  450. .deviceName = BLE_NAME,
  451. .on_service_init = on_service_init,
  452. };
  453. zble_module_init(&cfg);
  454. ThreeLeadECG_ecg_init();
  455. ThreeLeadECG_LineInputDet_init();
  456. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  457. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(5), NULL));
  458. zble_module_start_adv();
  459. znordic_loop();
  460. }
  461. #endif
  462. #if 0
  463. /*******************************************************************************
  464. * 3-led测试 *
  465. *******************************************************************************/
  466. static void test_tx_timer_cb(void* p_context) {
  467. static uint32_t data;
  468. data++;
  469. ZLOGI("test_tx_timer_cb %d", data);
  470. ThreeLeadECG_led_green_set_state(data % 2 == 0);
  471. }
  472. extern uint32_t g_nrf_log_tx_pin;
  473. APP_TIMER_DEF(m_test_tx_timer);
  474. void main() {
  475. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  476. znordic_init();
  477. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  478. NRF_LOG_INTERNAL_FLUSH();
  479. ThreeLeadECG_led_init();
  480. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  481. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
  482. znordic_loop();
  483. }
  484. #endif
  485. #if 0
  486. /*******************************************************************************
  487. * 3- *
  488. *******************************************************************************/
  489. static void test_tx_timer_cb(void* p_context) {
  490. static uint32_t data;
  491. data++;
  492. int16_t mv = ThreeLeadECG_battery_get_adc_val() * 1.0 / 4096 * 3.3 * 1000 / 2.0 * 3;
  493. ZLOGI("battery:%d", mv);
  494. }
  495. extern uint32_t g_nrf_log_tx_pin;
  496. APP_TIMER_DEF(m_test_tx_timer);
  497. void main() {
  498. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  499. znordic_init();
  500. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  501. NRF_LOG_INTERNAL_FLUSH();
  502. ThreeLeadECG_adc_module_init();
  503. ThreeLeadECG_battery_init();
  504. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  505. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
  506. znordic_loop();
  507. }
  508. #endif
  509. #if 0
  510. /*******************************************************************************
  511. * 3-flash测试 *
  512. *******************************************************************************/
  513. static void test_tx_timer_cb(void* p_context) {
  514. static uint32_t data;
  515. data++;
  516. }
  517. extern uint32_t g_nrf_log_tx_pin;
  518. APP_TIMER_DEF(m_test_tx_timer);
  519. void main() {
  520. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  521. znordic_init();
  522. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  523. NRF_LOG_INTERNAL_FLUSH();
  524. ThreeLeadECG_sdcard_base_init();
  525. ThreeLeadECG_sdcard_mount();
  526. ThreeLeadECG_sdcard_umount();
  527. ThreeLeadECG_sdcard_mount();
  528. ThreeLeadECG_sdcard_umount();
  529. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  530. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
  531. znordic_loop();
  532. }
  533. #endif
  534. #if 0
  535. /*******************************************************************************
  536. * 3-flash测试 *
  537. *******************************************************************************/
  538. static void test_tx_timer_cb(void* p_context) {
  539. static uint32_t data;
  540. data++;
  541. ZLOGI("button %d", ThreeLeadECG_button_get_state());
  542. }
  543. extern uint32_t g_nrf_log_tx_pin;
  544. APP_TIMER_DEF(m_test_tx_timer);
  545. void main() {
  546. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  547. znordic_init();
  548. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  549. NRF_LOG_INTERNAL_FLUSH();
  550. ThreeLeadECG_button_init();
  551. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  552. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(300), NULL));
  553. znordic_loop();
  554. }
  555. #endif