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.

307 lines
9.4 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 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. static uint8_t eepromw_test_data[256];
  46. static uint8_t eepromw_rx_data[256];
  47. for (size_t i = 0; i < 256; i++) {
  48. eepromw_test_data[i] = i;
  49. }
  50. // SingleLeadECG_eeprom_write(0, eepromw_test_data, 256);
  51. SingleLeadECG_eeprom_read(0, eepromw_rx_data, 256);
  52. // for (size_t i = 0; i < 256; i++) {
  53. // ZLOGI("eepromw_rx_data[%d] = %d", i, eepromw_rx_data[i]);
  54. // NRF_LOG_INTERNAL_FLUSH();
  55. // }
  56. }
  57. extern uint32_t g_nrf_log_tx_pin;
  58. APP_TIMER_DEF(m_test_tx_timer);
  59. void main() {
  60. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  61. znordic_init();
  62. // SingleLeadECG_beep_init();
  63. // SingleLeadECG_beep_set_state(false);
  64. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  65. NRF_LOG_INTERNAL_FLUSH();
  66. SingleLeadECG_eeprom_init();
  67. // nrf_delay_ms(20);
  68. // SingleLeadECG_eeprom_read(0, eepromw_rx_data, 256);
  69. // for (size_t i = 0; i < 256; i++) {
  70. // ZLOGI("eepromw_rx_data[%d] = %d", i, eepromw_rx_data[i]);
  71. // NRF_LOG_INTERNAL_FLUSH();
  72. // }
  73. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  74. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
  75. znordic_loop();
  76. }
  77. #endif
  78. /*******************************************************************************
  79. * +LED测试 *
  80. *******************************************************************************/
  81. #if 0
  82. static void test_tx_timer_cb(void* p_context) {
  83. static uint32_t data;
  84. data++;
  85. ZLOGI("test_tx_timer_cb %d", data);
  86. SingleLeadECG_led_green_set_state(data % 2 == 0);
  87. SingleLeadECG_led_blue_set_state(data % 3 == 0);
  88. }
  89. extern uint32_t g_nrf_log_tx_pin;
  90. APP_TIMER_DEF(m_test_tx_timer);
  91. void main() {
  92. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  93. znordic_init();
  94. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  95. NRF_LOG_INTERNAL_FLUSH();
  96. SingleLeadECG_screen_init();
  97. ssd1306_basic_init(SSD1306_INTERFACE_SPI, SSD1306_ADDR_SA0_0);
  98. ssd1306_basic_display_on();
  99. ssd1306_basic_string(0, 0, "123456789123456789123", 21, 0, SSD1306_FONT_12);
  100. ssd1306_basic_string(0, 16, "123456789123456789123", 21, 0, SSD1306_FONT_12);
  101. ssd1306_basic_string(0, 32, "123456789123456789123", 21, 0, SSD1306_FONT_12);
  102. ssd1306_basic_string(0, 48, "123456789123456789123", 21, 0, SSD1306_FONT_12);
  103. SingleLeadECG_led_init();
  104. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  105. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
  106. znordic_loop();
  107. }
  108. #endif
  109. /*******************************************************************************
  110. * ECG *
  111. *******************************************************************************/
  112. #if 0
  113. #define UART_TX_BUF_SIZE 256 /**< UART TX buffer size. */
  114. #define UART_RX_BUF_SIZE 256 /**< UART RX buffer size. */
  115. uint32_t err_code;
  116. app_uart_comm_params_t const comm_params = //
  117. {
  118. .rx_pin_no = UART_PIN_DISCONNECTED,
  119. .tx_pin_no = 41,
  120. .rts_pin_no = UART_PIN_DISCONNECTED,
  121. .cts_pin_no = UART_PIN_DISCONNECTED,
  122. .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
  123. .use_parity = false,
  124. .baud_rate = NRF_UARTE_BAUDRATE_921600,
  125. };
  126. void uart_error_handle(app_uart_evt_t* p_event) {}
  127. void uartinit() {
  128. APP_UART_FIFO_INIT(&comm_params, UART_RX_BUF_SIZE, UART_TX_BUF_SIZE, uart_error_handle, APP_IRQ_PRIORITY_LOWEST, err_code);
  129. APP_ERROR_CHECK(err_code);
  130. }
  131. void zchip_log(const char* fmt, ...) {
  132. static char tx[256] = {0};
  133. va_list args;
  134. va_start(args, fmt);
  135. vsprintf(tx, fmt, args);
  136. for (size_t i = 0; i < strlen(tx); i++) {
  137. app_uart_put(tx[i]);
  138. }
  139. va_end(args);
  140. }
  141. static void test_tx_timer_cb(void* p_context) {
  142. static uint32_t data;
  143. data++;
  144. // SingleLeadECG_ecg_nlod_get_connected_state();
  145. // SingleLeadECG_ecg_plod_get_connected_state();
  146. // SingleLeadECG_ecg_plod_get_ecg_val();
  147. // 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());
  148. // ZLOGI("%d,%d,%d", SingleLeadECG_ecg_nlod_get_connected_state(), SingleLeadECG_ecg_plod_get_connected_state(), SingleLeadECG_ecg_plod_get_ecg_val());
  149. zchip_log("%d,%d,%d\n", SingleLeadECG_ecg_nlod_get_connected_state(), SingleLeadECG_ecg_plod_get_connected_state(), SingleLeadECG_ecg_plod_get_ecg_val());
  150. // app_uart_put('c');
  151. // app_uart_put('c');
  152. // app_uart_put('c');
  153. // app_uart_put('c');
  154. // app_uart_put('c');
  155. // NRF_LOG_INFO("......");
  156. }
  157. extern uint32_t g_nrf_log_tx_pin;
  158. APP_TIMER_DEF(m_test_tx_timer);
  159. void main() {
  160. // g_nrf_log_tx_pin = 41;
  161. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  162. znordic_init();
  163. SingleLeadECG_adc_module_init();
  164. uartinit();
  165. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  166. NRF_LOG_INTERNAL_FLUSH();
  167. SingleLeadECG_ecg_init();
  168. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  169. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(5), NULL));
  170. znordic_loop();
  171. }
  172. #endif
  173. /*******************************************************************************
  174. * *
  175. *******************************************************************************/
  176. #if 0
  177. extern uint32_t g_nrf_log_tx_pin;
  178. APP_TIMER_DEF(m_test_tx_timer);
  179. ZDATACHANNEL_DEF(m_zhrs, 2 /*回调事件优先级*/, 1 /*client num*/);
  180. static const char* hex2str(const uint8_t* data, int32_t len) {
  181. static char rx[64] = {0};
  182. memset(rx, 0, sizeof(rx));
  183. for (int32_t i = 0; i < len; i++) {
  184. sprintf(rx + i * 2, "%02X", data[i]);
  185. }
  186. return rx;
  187. }
  188. static void zdatachannel_data_handler(zdatachannel_evt_t* p_evt) {
  189. /**
  190. * @brief
  191. */
  192. if (p_evt->type == ZDATACHANNEL_EVT_RX_DATA) {
  193. ZLOGI("rx:%s", hex2str(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length));
  194. }
  195. }
  196. static void on_service_init(void) {
  197. /**
  198. * @brief
  199. */
  200. ZLOGI("init zdatachannel service");
  201. zdatachannel_init_t zdatachannle_init;
  202. memset(&zdatachannle_init, 0, sizeof(zdatachannle_init));
  203. zdatachannle_init.data_handler = zdatachannel_data_handler;
  204. ZERROR_CHECK(zdatachannel_init(&m_zhrs, &zdatachannle_init));
  205. }
  206. void main() {
  207. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  208. znordic_init(0, 20);
  209. NRF_LOG_INFO("compile time :%s", __TIME__);
  210. NRF_LOG_INFO("Version :%d", VERSION);
  211. NRF_LOG_INFO("Manufacturer :%s", MANUFACTURER_NAME);
  212. static zble_module_cfg_t cfg = //
  213. {
  214. .deviceName = BLE_NAME,
  215. .on_service_init = on_service_init,
  216. };
  217. zble_module_init(&cfg);
  218. zble_module_start_adv();
  219. znordic_loop();
  220. }
  221. #endif
  222. /*******************************************************************************
  223. * ADCTEST *
  224. *******************************************************************************/
  225. static void test_tx_timer_cb(void* p_context) {
  226. static uint32_t data;
  227. data++;
  228. // ZLOGI("test_tx_timer_cb %d", data);
  229. static uint8_t eepromw_test_data[256];
  230. static uint8_t eepromw_rx_data[256];
  231. for (size_t i = 0; i < 256; i++) {
  232. eepromw_test_data[i] = i;
  233. }
  234. int16_t adc = SingleLeadECG_battery_get_adc_val();
  235. int16_t mv = adc * 1.0 / 4096 * 3.6 * 1000 / 2.0 * 3;
  236. ZLOGI("battery:%d", mv);
  237. }
  238. extern uint32_t g_nrf_log_tx_pin;
  239. APP_TIMER_DEF(m_test_tx_timer);
  240. void main() {
  241. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  242. znordic_init();
  243. SingleLeadECG_adc_module_init();
  244. SingleLeadECG_battery_init();
  245. // SingleLeadECG_beep_init();
  246. // SingleLeadECG_beep_set_state(false);
  247. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  248. NRF_LOG_INTERNAL_FLUSH();
  249. // nrf_delay_ms(20);
  250. // SingleLeadECG_eeprom_read(0, eepromw_rx_data, 256);
  251. // for (size_t i = 0; i < 256; i++) {
  252. // ZLOGI("eepromw_rx_data[%d] = %d", i, eepromw_rx_data[i]);
  253. // NRF_LOG_INTERNAL_FLUSH();
  254. // }
  255. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  256. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
  257. znordic_loop();
  258. }