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.

541 lines
16 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 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 "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 0
  84. static void test_tx_timer_cb(void* p_context) {
  85. static uint32_t data;
  86. data++;
  87. ZLOGI("test_tx_timer_cb %d", data);
  88. SingleLeadECG_led_green_set_state(data % 2 == 0);
  89. SingleLeadECG_led_blue_set_state(data % 3 == 0);
  90. }
  91. extern uint32_t g_nrf_log_tx_pin;
  92. APP_TIMER_DEF(m_test_tx_timer);
  93. void main() {
  94. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  95. znordic_init();
  96. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  97. NRF_LOG_INTERNAL_FLUSH();
  98. SingleLeadECG_screen_init();
  99. ssd1306_basic_init(SSD1306_INTERFACE_SPI, SSD1306_ADDR_SA0_0);
  100. ssd1306_basic_display_on();
  101. ssd1306_basic_string(0, 0, "123456789123456789123", 21, 0, SSD1306_FONT_12);
  102. ssd1306_basic_string(0, 16, "123456789123456789123", 21, 0, SSD1306_FONT_12);
  103. ssd1306_basic_string(0, 32, "123456789123456789123", 21, 0, SSD1306_FONT_12);
  104. ssd1306_basic_string(0, 48, "123456789123456789123", 21, 0, SSD1306_FONT_12);
  105. SingleLeadECG_led_init();
  106. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  107. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
  108. znordic_loop();
  109. }
  110. #endif
  111. /*******************************************************************************
  112. * ECG *
  113. *******************************************************************************/
  114. #if 0
  115. #define UART_TX_BUF_SIZE 256 /**< UART TX buffer size. */
  116. #define UART_RX_BUF_SIZE 256 /**< UART RX buffer size. */
  117. uint32_t err_code;
  118. app_uart_comm_params_t const comm_params = //
  119. {
  120. .rx_pin_no = UART_PIN_DISCONNECTED,
  121. .tx_pin_no = 41,
  122. .rts_pin_no = UART_PIN_DISCONNECTED,
  123. .cts_pin_no = UART_PIN_DISCONNECTED,
  124. .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
  125. .use_parity = false,
  126. .baud_rate = NRF_UARTE_BAUDRATE_921600,
  127. };
  128. void uart_error_handle(app_uart_evt_t* p_event) {}
  129. void uartinit() {
  130. APP_UART_FIFO_INIT(&comm_params, UART_RX_BUF_SIZE, UART_TX_BUF_SIZE, uart_error_handle, APP_IRQ_PRIORITY_LOWEST, err_code);
  131. APP_ERROR_CHECK(err_code);
  132. }
  133. void zchip_log(const char* fmt, ...) {
  134. static char tx[256] = {0};
  135. va_list args;
  136. va_start(args, fmt);
  137. vsprintf(tx, fmt, args);
  138. for (size_t i = 0; i < strlen(tx); i++) {
  139. app_uart_put(tx[i]);
  140. }
  141. va_end(args);
  142. }
  143. static void test_tx_timer_cb(void* p_context) {
  144. static uint32_t data;
  145. data++;
  146. // SingleLeadECG_ecg_nlod_get_connected_state();
  147. // SingleLeadECG_ecg_plod_get_connected_state();
  148. // SingleLeadECG_ecg_plod_get_ecg_val();
  149. // 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());
  150. // ZLOGI("%d,%d,%d", SingleLeadECG_ecg_nlod_get_connected_state(), SingleLeadECG_ecg_plod_get_connected_state(), SingleLeadECG_ecg_plod_get_ecg_val());
  151. zchip_log("%d,%d,%d\n", SingleLeadECG_ecg_nlod_get_connected_state(), SingleLeadECG_ecg_plod_get_connected_state(), SingleLeadECG_ecg_plod_get_ecg_val());
  152. // app_uart_put('c');
  153. // app_uart_put('c');
  154. // app_uart_put('c');
  155. // app_uart_put('c');
  156. // app_uart_put('c');
  157. // NRF_LOG_INFO("......");
  158. }
  159. extern uint32_t g_nrf_log_tx_pin;
  160. APP_TIMER_DEF(m_test_tx_timer);
  161. void main() {
  162. // g_nrf_log_tx_pin = 41;
  163. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  164. znordic_init();
  165. SingleLeadECG_adc_module_init();
  166. uartinit();
  167. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  168. NRF_LOG_INTERNAL_FLUSH();
  169. SingleLeadECG_ecg_init();
  170. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  171. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(5), NULL));
  172. znordic_loop();
  173. }
  174. #endif
  175. /*******************************************************************************
  176. * *
  177. *******************************************************************************/
  178. #if 0
  179. extern uint32_t g_nrf_log_tx_pin;
  180. APP_TIMER_DEF(m_test_tx_timer);
  181. ZDATACHANNEL_DEF(m_zhrs, 2 /*回调事件优先级*/, 1 /*client num*/);
  182. static const char* hex2str(const uint8_t* data, int32_t len) {
  183. static char rx[64] = {0};
  184. memset(rx, 0, sizeof(rx));
  185. for (int32_t i = 0; i < len; i++) {
  186. sprintf(rx + i * 2, "%02X", data[i]);
  187. }
  188. return rx;
  189. }
  190. static void zdatachannel_data_handler(zdatachannel_evt_t* p_evt) {
  191. /**
  192. * @brief
  193. */
  194. if (p_evt->type == ZDATACHANNEL_EVT_RX_DATA) {
  195. ZLOGI("rx:%s", hex2str(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length));
  196. }
  197. }
  198. static void on_service_init(void) {
  199. /**
  200. * @brief
  201. */
  202. ZLOGI("init zdatachannel service");
  203. zdatachannel_init_t zdatachannle_init;
  204. memset(&zdatachannle_init, 0, sizeof(zdatachannle_init));
  205. zdatachannle_init.data_handler = zdatachannel_data_handler;
  206. ZERROR_CHECK(zdatachannel_init(&m_zhrs, &zdatachannle_init));
  207. }
  208. void main() {
  209. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  210. ThreeLeadECG_sdcard_base_init();
  211. znordic_init(0, 20);
  212. NRF_LOG_INFO("compile time :%s", __TIME__);
  213. NRF_LOG_INFO("Version :%d", VERSION);
  214. NRF_LOG_INFO("Manufacturer :%s", MANUFACTURER_NAME);
  215. static zble_module_cfg_t cfg = //
  216. {
  217. .deviceName = BLE_NAME,
  218. .on_service_init = on_service_init,
  219. };
  220. zble_module_init(&cfg);
  221. zble_module_start_adv();
  222. znordic_loop();
  223. }
  224. #endif
  225. #if 0
  226. /*******************************************************************************
  227. * ADCTEST *
  228. *******************************************************************************/
  229. static void test_tx_timer_cb(void* p_context) {
  230. static uint32_t data;
  231. data++;
  232. // ZLOGI("test_tx_timer_cb %d", data);
  233. static uint8_t eepromw_test_data[256];
  234. static uint8_t eepromw_rx_data[256];
  235. for (size_t i = 0; i < 256; i++) {
  236. eepromw_test_data[i] = i;
  237. }
  238. int16_t adc = SingleLeadECG_battery_get_adc_val();
  239. int16_t mv = adc * 1.0 / 4096 * 3.6 * 1000 / 2.0 * 3;
  240. ZLOGI("battery:%d", mv);
  241. }
  242. extern uint32_t g_nrf_log_tx_pin;
  243. APP_TIMER_DEF(m_test_tx_timer);
  244. void main() {
  245. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  246. znordic_init();
  247. SingleLeadECG_adc_module_init();
  248. SingleLeadECG_battery_init();
  249. // SingleLeadECG_beep_init();
  250. // SingleLeadECG_beep_set_state(false);
  251. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  252. NRF_LOG_INTERNAL_FLUSH();
  253. // nrf_delay_ms(20);
  254. // SingleLeadECG_eeprom_read(0, eepromw_rx_data, 256);
  255. // for (size_t i = 0; i < 256; i++) {
  256. // ZLOGI("eepromw_rx_data[%d] = %d", i, eepromw_rx_data[i]);
  257. // NRF_LOG_INTERNAL_FLUSH();
  258. // }
  259. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  260. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
  261. znordic_loop();
  262. }
  263. #endif
  264. #if 1
  265. /*******************************************************************************
  266. * 3-ADS1293- *
  267. *******************************************************************************/
  268. #if 0
  269. static void test_tx_timer_cb(void* p_context) {
  270. static uint32_t data;
  271. data++;
  272. ZLOGI("tim cb %d :%d %d", data, ThreeLeadECG_ready_pin_state_get(), ThreeLeadECG_LineInputDet_get_state());
  273. // ThreeLeadECG_sdcard_connect2_ext_usb_sdcard_driver_ic_reset();
  274. }
  275. extern uint32_t g_nrf_log_tx_pin;
  276. APP_TIMER_DEF(m_test_tx_timer);
  277. void main() {
  278. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  279. // ThreeLeadECG_sdcard_base_init();
  280. znordic_init();
  281. ThreeLeadECG_ecg_init();
  282. ThreeLeadECG_LineInputDet_init();
  283. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  284. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  285. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(3000), NULL));
  286. znordic_loop();
  287. }
  288. #endif
  289. extern uint32_t g_nrf_log_tx_pin;
  290. APP_TIMER_DEF(m_test_tx_timer);
  291. static void zdatachanel_send_log(const char* fmt, ...) {
  292. static char tx[256] = {0};
  293. static uint16_t len = 0;
  294. va_list args;
  295. va_start(args, fmt);
  296. len = vsprintf(tx, fmt, args);
  297. zdatachannel_data_send((uint8_t*)tx, &len);
  298. va_end(args);
  299. }
  300. static void test_tx_timer_cb(void* p_context) {
  301. static uint32_t data;
  302. data++;
  303. zdatachanel_send_log("%d,%d,%d\n", data, data, data);
  304. // static uint8_t tx[9] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09};
  305. // uint16_t p_length = 9;
  306. // zdatachannel_data_send(tx, &p_length);
  307. }
  308. ZDATACHANNEL_DEF(m_zhrs, 2 /*回调事件优先级*/, 1 /*client num*/);
  309. static const char* hex2str(const uint8_t* data, int32_t len) {
  310. static char rx[64] = {0};
  311. memset(rx, 0, sizeof(rx));
  312. for (int32_t i = 0; i < len; i++) {
  313. sprintf(rx + i * 2, "%02X", data[i]);
  314. }
  315. return rx;
  316. }
  317. static void zdatachannel_data_handler(zdatachannel_evt_t* p_evt) {
  318. /**
  319. * @brief
  320. */
  321. if (p_evt->type == ZDATACHANNEL_EVT_RX_DATA) {
  322. ZLOGI("rx:%s", hex2str(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length));
  323. }
  324. }
  325. static void on_service_init(void) {
  326. /**
  327. * @brief
  328. */
  329. ZLOGI("init zdatachannel service");
  330. zdatachannel_init_t zdatachannle_init;
  331. memset(&zdatachannle_init, 0, sizeof(zdatachannle_init));
  332. zdatachannle_init.data_handler = zdatachannel_data_handler;
  333. ZERROR_CHECK(zdatachannel_init(&m_zhrs, &zdatachannle_init));
  334. }
  335. void main() {
  336. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  337. ThreeLeadECG_sdcard_base_init();
  338. znordic_init(0, 20);
  339. NRF_LOG_INFO("compile time :%s", __TIME__);
  340. NRF_LOG_INFO("Version :%d", VERSION);
  341. NRF_LOG_INFO("Manufacturer :%s", MANUFACTURER_NAME);
  342. static zble_module_cfg_t cfg = //
  343. {
  344. .deviceName = BLE_NAME,
  345. .on_service_init = on_service_init,
  346. };
  347. zble_module_init(&cfg);
  348. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  349. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(5), NULL));
  350. zble_module_start_adv();
  351. znordic_loop();
  352. }
  353. #endif
  354. #if 0
  355. /*******************************************************************************
  356. * 3-led测试 *
  357. *******************************************************************************/
  358. static void test_tx_timer_cb(void* p_context) {
  359. static uint32_t data;
  360. data++;
  361. ZLOGI("test_tx_timer_cb %d", data);
  362. ThreeLeadECG_led_green_set_state(data % 2 == 0);
  363. }
  364. extern uint32_t g_nrf_log_tx_pin;
  365. APP_TIMER_DEF(m_test_tx_timer);
  366. void main() {
  367. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  368. znordic_init();
  369. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  370. NRF_LOG_INTERNAL_FLUSH();
  371. ThreeLeadECG_led_init();
  372. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  373. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
  374. znordic_loop();
  375. }
  376. #endif
  377. #if 0
  378. /*******************************************************************************
  379. * 3- *
  380. *******************************************************************************/
  381. static void test_tx_timer_cb(void* p_context) {
  382. static uint32_t data;
  383. data++;
  384. int16_t mv = ThreeLeadECG_battery_get_adc_val() * 1.0 / 4096 * 3.3 * 1000 / 2.0 * 3;
  385. ZLOGI("battery:%d", mv);
  386. }
  387. extern uint32_t g_nrf_log_tx_pin;
  388. APP_TIMER_DEF(m_test_tx_timer);
  389. void main() {
  390. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  391. znordic_init();
  392. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  393. NRF_LOG_INTERNAL_FLUSH();
  394. ThreeLeadECG_adc_module_init();
  395. ThreeLeadECG_battery_init();
  396. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  397. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
  398. znordic_loop();
  399. }
  400. #endif
  401. #if 0
  402. /*******************************************************************************
  403. * 3-flash测试 *
  404. *******************************************************************************/
  405. static void test_tx_timer_cb(void* p_context) {
  406. static uint32_t data;
  407. data++;
  408. }
  409. extern uint32_t g_nrf_log_tx_pin;
  410. APP_TIMER_DEF(m_test_tx_timer);
  411. void main() {
  412. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  413. znordic_init();
  414. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  415. NRF_LOG_INTERNAL_FLUSH();
  416. ThreeLeadECG_sdcard_base_init();
  417. ThreeLeadECG_sdcard_mount();
  418. ThreeLeadECG_sdcard_umount();
  419. ThreeLeadECG_sdcard_mount();
  420. ThreeLeadECG_sdcard_umount();
  421. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  422. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(100), NULL));
  423. znordic_loop();
  424. }
  425. #endif
  426. #if 0
  427. /*******************************************************************************
  428. * 3-flash测试 *
  429. *******************************************************************************/
  430. static void test_tx_timer_cb(void* p_context) {
  431. static uint32_t data;
  432. data++;
  433. ZLOGI("button %d", ThreeLeadECG_button_get_state());
  434. }
  435. extern uint32_t g_nrf_log_tx_pin;
  436. APP_TIMER_DEF(m_test_tx_timer);
  437. void main() {
  438. APP_SCHED_INIT(APP_TIMER_SCHED_EVENT_DATA_SIZE, 20);
  439. znordic_init();
  440. NRF_LOG_INFO("compile time :%s %d", __TIME__, APP_TIMER_TICKS(100));
  441. NRF_LOG_INTERNAL_FLUSH();
  442. ThreeLeadECG_button_init();
  443. ZERROR_CHECK(app_timer_create(&m_test_tx_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
  444. ZERROR_CHECK(app_timer_start(m_test_tx_timer, APP_TIMER_TICKS(300), NULL));
  445. znordic_loop();
  446. }
  447. #endif