From d48cec34d8fc1e18f654cc3f76977c73c53fd832 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sat, 4 May 2024 11:31:08 +0800 Subject: [PATCH] recode --- .vscode/settings.json | 5 +- app/app.uvoptx | 468 +++++------------ app/app.uvprojx | 262 ++-------- app/src/app_basic_service/basic/event.h | 33 ++ app/src/app_basic_service/basic/gstate.h | 10 + app/src/app_basic_service/basic/state.h | 48 ++ .../app_basic_service/device_version_info_mgr.c | 29 ++ .../app_basic_service/device_version_info_mgr.h | 16 + app/src/app_basic_service/zapp.c | 82 +++ app/src/app_basic_service/zapp.h | 37 ++ app/src/app_service/adc_mgr.c | 37 ++ app/src/app_service/adc_mgr.h | 14 + app/src/app_service/battery_mgr_service.c | 46 ++ app/src/app_service/battery_mgr_service.h | 17 + .../ble_cmd_processer/ble_cmd_process_service.c | 261 ++++++++++ .../ble_cmd_processer/ble_cmd_process_service.h | 17 + app/src/bakservice/display_mgr/display_manager.c | 443 ++++++++++++++++ app/src/bakservice/display_mgr/display_manager.h | 81 +++ app/src/bakservice/display_mgr/font.h | 275 ++++++++++ .../heart_ware_sample_data_mgr.c | 107 ++++ .../heart_ware_sample_data_mgr.h | 9 + .../heart_wave_sample_data_pre_process.c | 12 + .../heart_wave_sample_data_pre_process.h | 9 + .../heart_wave_sample_service.c | 77 +++ .../heart_wave_sample_service.h | 22 + app/src/bakservice/storage/sample_data_manager.c | 92 ++++ app/src/bakservice/storage/sample_data_manager.h | 46 ++ app/src/bakservice/storage/storage_service.h | 3 + app/src/bakservice/storage/zeeprom_fs.c | 572 +++++++++++++++++++++ app/src/bakservice/storage/zeeprom_fs.h | 108 ++++ app/src/basic_service/app_event.h | 77 --- app/src/basic_service/app_event_distribute.c | 23 - app/src/basic_service/app_event_distribute.h | 15 - app/src/basic_service/device_state.c | 64 --- app/src/basic_service/device_state.h | 29 -- app/src/basic_service/device_version_info_mgr.c | 29 -- app/src/basic_service/device_version_info_mgr.h | 16 - app/src/main.c | 15 +- app/src/one_conduction_main.c | 495 +++++------------- app/src/one_conduction_main.h | 3 +- .../ble_cmd_processer/ble_cmd_process_service.c | 503 ------------------ .../ble_cmd_processer/ble_cmd_process_service.h | 17 - app/src/service/display_mgr/display_manager.c | 443 ---------------- app/src/service/display_mgr/display_manager.h | 81 --- app/src/service/display_mgr/font.h | 275 ---------- .../heart_ware_sample_data_mgr.c | 107 ---- .../heart_ware_sample_data_mgr.h | 9 - .../heart_wave_sample_data_pre_process.c | 12 - .../heart_wave_sample_data_pre_process.h | 9 - .../heart_wave_sample_service.c | 77 --- .../heart_wave_sample_service.h | 22 - app/src/service/storage/sample_data_manager.c | 92 ---- app/src/service/storage/sample_data_manager.h | 46 -- app/src/service/storage/storage_service.h | 3 - app/src/service/storage/zeeprom_fs.c | 572 --------------------- app/src/service/storage/zeeprom_fs.h | 108 ---- 56 files changed, 2807 insertions(+), 3573 deletions(-) create mode 100644 app/src/app_basic_service/basic/event.h create mode 100644 app/src/app_basic_service/basic/gstate.h create mode 100644 app/src/app_basic_service/basic/state.h create mode 100644 app/src/app_basic_service/device_version_info_mgr.c create mode 100644 app/src/app_basic_service/device_version_info_mgr.h create mode 100644 app/src/app_basic_service/zapp.c create mode 100644 app/src/app_basic_service/zapp.h create mode 100644 app/src/app_service/adc_mgr.c create mode 100644 app/src/app_service/adc_mgr.h create mode 100644 app/src/app_service/battery_mgr_service.c create mode 100644 app/src/app_service/battery_mgr_service.h create mode 100644 app/src/bakservice/ble_cmd_processer/ble_cmd_process_service.c create mode 100644 app/src/bakservice/ble_cmd_processer/ble_cmd_process_service.h create mode 100644 app/src/bakservice/display_mgr/display_manager.c create mode 100644 app/src/bakservice/display_mgr/display_manager.h create mode 100644 app/src/bakservice/display_mgr/font.h create mode 100644 app/src/bakservice/heart_wave_sample_service/heart_ware_sample_data_mgr.c create mode 100644 app/src/bakservice/heart_wave_sample_service/heart_ware_sample_data_mgr.h create mode 100644 app/src/bakservice/heart_wave_sample_service/heart_wave_sample_data_pre_process.c create mode 100644 app/src/bakservice/heart_wave_sample_service/heart_wave_sample_data_pre_process.h create mode 100644 app/src/bakservice/heart_wave_sample_service/heart_wave_sample_service.c create mode 100644 app/src/bakservice/heart_wave_sample_service/heart_wave_sample_service.h create mode 100644 app/src/bakservice/storage/sample_data_manager.c create mode 100644 app/src/bakservice/storage/sample_data_manager.h create mode 100644 app/src/bakservice/storage/storage_service.h create mode 100644 app/src/bakservice/storage/zeeprom_fs.c create mode 100644 app/src/bakservice/storage/zeeprom_fs.h delete mode 100644 app/src/basic_service/app_event.h delete mode 100644 app/src/basic_service/app_event_distribute.c delete mode 100644 app/src/basic_service/app_event_distribute.h delete mode 100644 app/src/basic_service/device_state.c delete mode 100644 app/src/basic_service/device_state.h delete mode 100644 app/src/basic_service/device_version_info_mgr.c delete mode 100644 app/src/basic_service/device_version_info_mgr.h delete mode 100644 app/src/service/ble_cmd_processer/ble_cmd_process_service.c delete mode 100644 app/src/service/ble_cmd_processer/ble_cmd_process_service.h delete mode 100644 app/src/service/display_mgr/display_manager.c delete mode 100644 app/src/service/display_mgr/display_manager.h delete mode 100644 app/src/service/display_mgr/font.h delete mode 100644 app/src/service/heart_wave_sample_service/heart_ware_sample_data_mgr.c delete mode 100644 app/src/service/heart_wave_sample_service/heart_ware_sample_data_mgr.h delete mode 100644 app/src/service/heart_wave_sample_service/heart_wave_sample_data_pre_process.c delete mode 100644 app/src/service/heart_wave_sample_service/heart_wave_sample_data_pre_process.h delete mode 100644 app/src/service/heart_wave_sample_service/heart_wave_sample_service.c delete mode 100644 app/src/service/heart_wave_sample_service/heart_wave_sample_service.h delete mode 100644 app/src/service/storage/sample_data_manager.c delete mode 100644 app/src/service/storage/sample_data_manager.h delete mode 100644 app/src/service/storage/storage_service.h delete mode 100644 app/src/service/storage/zeeprom_fs.c delete mode 100644 app/src/service/storage/zeeprom_fs.h diff --git a/.vscode/settings.json b/.vscode/settings.json index 4b2f85b..a0a0f36 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -204,7 +204,10 @@ "ads129x.h": "c", "ads129x_if_impl.h": "c", "ads129x_type.h": "c", - "app_board.h": "c" + "app_board.h": "c", + "zapp.h": "c", + "adc_mgr.h": "c", + "battery_mgr_service.h": "c" }, "files.encoding": "gbk" } \ No newline at end of file diff --git a/app/app.uvoptx b/app/app.uvoptx index 5f30502..5d0a12b 100644 --- a/app/app.uvoptx +++ b/app/app.uvoptx @@ -410,284 +410,20 @@ 0 0 0 - .\src\board\board_beep_ctrl.c - board_beep_ctrl.c - 0 - 0 - - - 1 - 5 - 1 - 0 - 0 - 0 - .\src\board\board_adc_module_ctrl.c - board_adc_module_ctrl.c - 0 - 0 - - - 1 - 6 - 1 - 0 - 0 - 0 - .\src\board\board_battery_state.c - board_battery_state.c - 0 - 0 - - - 1 - 7 - 1 - 0 - 0 - 0 - .\src\board\board_ecg_sensor.c - board_ecg_sensor.c - 0 - 0 - - - 1 - 8 - 1 - 0 - 0 - 0 - .\src\board\board_light_ctrl.c - board_light_ctrl.c - 0 - 0 - - - 1 - 9 - 1 - 0 - 0 - 0 - .\src\board\board_ssd1306_interface.c - board_ssd1306_interface.c - 0 - 0 - - - 1 - 10 - 1 - 0 - 0 - 0 - .\src\board\board_eeprom_driver.c - board_eeprom_driver.c - 0 - 0 - - - 1 - 11 - 1 - 0 - 0 - 0 - .\src\board\board_power_mgr.c - board_power_mgr.c - 0 - 0 - - - 1 - 12 - 1 - 0 - 0 - 0 - .\src\basic_service\device_state.c - device_state.c - 0 - 0 - - - 1 - 13 - 1 - 0 - 0 - 0 - .\src\basic_service\device_version_info_mgr.c + .\src\app_basic_service\device_version_info_mgr.c device_version_info_mgr.c 0 0 1 - 14 - 1 - 0 - 0 - 0 - .\src\board\ssd1306\driver_ssd1306.c - driver_ssd1306.c - 0 - 0 - - - 1 - 15 - 1 - 0 - 0 - 0 - .\src\board\ssd1306\driver_ssd1306_basic.c - driver_ssd1306_basic.c - 0 - 0 - - - 1 - 16 - 1 - 0 - 0 - 0 - .\src\board\ssd1306\fontlib.c - fontlib.c - 0 - 0 - - - 1 - 17 - 1 - 0 - 0 - 0 - .\src\board\ssd1306\wave_drawer.c - wave_drawer.c - 0 - 0 - - - 1 - 18 - 1 - 0 - 0 - 0 - .\src\service\ble_cmd_processer\ble_cmd_process_service.c - ble_cmd_process_service.c - 0 - 0 - - - 1 - 19 - 1 - 0 - 0 - 0 - .\src\service\display_mgr\display_manager.c - display_manager.c - 0 - 0 - - - 1 - 20 - 1 - 0 - 0 - 0 - .\src\service\heart_wave_sample_service\heart_ware_sample_data_mgr.c - heart_ware_sample_data_mgr.c - 0 - 0 - - - 1 - 21 - 1 - 0 - 0 - 0 - .\src\service\heart_wave_sample_service\heart_wave_sample_data_pre_process.c - heart_wave_sample_data_pre_process.c - 0 - 0 - - - 1 - 22 - 1 - 0 - 0 - 0 - .\src\service\heart_wave_sample_service\heart_wave_sample_service.c - heart_wave_sample_service.c - 0 - 0 - - - 1 - 23 - 1 - 0 - 0 - 0 - .\src\service\storage\sample_data_manager.c - sample_data_manager.c - 0 - 0 - - - 1 - 24 - 1 - 0 - 0 - 0 - .\src\service\storage\zeeprom_fs.c - zeeprom_fs.c - 0 - 0 - - - 1 - 25 - 1 - 0 - 0 - 0 - .\src\basic_service\app_event_distribute.c - app_event_distribute.c - 0 - 0 - - - 1 - 26 - 1 - 0 - 0 - 0 - .\src\board\ads129x\ads129x.c - ads129x.c - 0 - 0 - - - 1 - 27 + 5 1 0 0 0 - .\src\board\app_board.c - app_board.c + .\src\app_basic_service\zapp.c + zapp.c 0 0 @@ -701,7 +437,7 @@ 0 2 - 28 + 6 1 0 0 @@ -721,7 +457,7 @@ 0 3 - 29 + 7 1 0 0 @@ -733,7 +469,7 @@ 3 - 30 + 8 1 0 0 @@ -753,7 +489,7 @@ 0 4 - 31 + 9 1 0 0 @@ -773,7 +509,7 @@ 0 5 - 32 + 10 1 0 0 @@ -785,7 +521,7 @@ 5 - 33 + 11 1 0 0 @@ -797,7 +533,7 @@ 5 - 34 + 12 1 0 0 @@ -809,7 +545,7 @@ 5 - 35 + 13 1 0 0 @@ -821,7 +557,7 @@ 5 - 36 + 14 1 0 0 @@ -833,7 +569,7 @@ 5 - 37 + 15 1 0 0 @@ -845,7 +581,7 @@ 5 - 38 + 16 1 0 0 @@ -857,7 +593,7 @@ 5 - 39 + 17 1 0 0 @@ -877,7 +613,7 @@ 0 6 - 40 + 18 1 0 0 @@ -891,13 +627,13 @@ nRF_Drivers - 1 + 0 0 0 0 7 - 41 + 19 1 0 0 @@ -909,7 +645,7 @@ 7 - 42 + 20 1 0 0 @@ -921,7 +657,7 @@ 7 - 43 + 21 1 0 0 @@ -933,7 +669,7 @@ 7 - 44 + 22 1 0 0 @@ -945,7 +681,7 @@ 7 - 45 + 23 1 0 0 @@ -957,7 +693,7 @@ 7 - 46 + 24 1 0 0 @@ -969,7 +705,7 @@ 7 - 47 + 25 1 0 0 @@ -981,7 +717,7 @@ 7 - 48 + 26 1 0 0 @@ -993,7 +729,7 @@ 7 - 49 + 27 1 0 0 @@ -1005,7 +741,7 @@ 7 - 50 + 28 1 0 0 @@ -1017,7 +753,7 @@ 7 - 51 + 29 1 0 0 @@ -1029,7 +765,7 @@ 7 - 52 + 30 1 0 0 @@ -1041,7 +777,7 @@ 7 - 53 + 31 1 0 0 @@ -1053,7 +789,7 @@ 7 - 54 + 32 1 0 0 @@ -1065,7 +801,7 @@ 7 - 55 + 33 1 0 0 @@ -1077,7 +813,7 @@ 7 - 56 + 34 1 0 0 @@ -1089,7 +825,7 @@ 7 - 57 + 35 1 0 0 @@ -1101,7 +837,7 @@ 7 - 58 + 36 1 0 0 @@ -1113,7 +849,7 @@ 7 - 59 + 37 1 0 0 @@ -1125,7 +861,7 @@ 7 - 60 + 38 1 0 0 @@ -1145,7 +881,7 @@ 0 8 - 61 + 39 1 0 0 @@ -1157,7 +893,7 @@ 8 - 62 + 40 1 0 0 @@ -1169,7 +905,7 @@ 8 - 63 + 41 1 0 0 @@ -1181,7 +917,7 @@ 8 - 64 + 42 1 0 0 @@ -1193,7 +929,7 @@ 8 - 65 + 43 1 0 0 @@ -1205,7 +941,7 @@ 8 - 66 + 44 1 0 0 @@ -1217,7 +953,7 @@ 8 - 67 + 45 1 0 0 @@ -1229,7 +965,7 @@ 8 - 68 + 46 1 0 0 @@ -1241,7 +977,7 @@ 8 - 69 + 47 1 0 0 @@ -1253,7 +989,7 @@ 8 - 70 + 48 1 0 0 @@ -1265,7 +1001,7 @@ 8 - 71 + 49 1 0 0 @@ -1277,7 +1013,7 @@ 8 - 72 + 50 1 0 0 @@ -1289,7 +1025,7 @@ 8 - 73 + 51 1 0 0 @@ -1301,7 +1037,7 @@ 8 - 74 + 52 1 0 0 @@ -1313,7 +1049,7 @@ 8 - 75 + 53 1 0 0 @@ -1325,7 +1061,7 @@ 8 - 76 + 54 1 0 0 @@ -1337,7 +1073,7 @@ 8 - 77 + 55 1 0 0 @@ -1349,7 +1085,7 @@ 8 - 78 + 56 1 0 0 @@ -1361,7 +1097,7 @@ 8 - 79 + 57 1 0 0 @@ -1373,7 +1109,7 @@ 8 - 80 + 58 1 0 0 @@ -1385,7 +1121,7 @@ 8 - 81 + 59 1 0 0 @@ -1397,7 +1133,7 @@ 8 - 82 + 60 1 0 0 @@ -1409,7 +1145,7 @@ 8 - 83 + 61 1 0 0 @@ -1421,7 +1157,7 @@ 8 - 84 + 62 1 0 0 @@ -1433,7 +1169,7 @@ 8 - 85 + 63 1 0 0 @@ -1445,7 +1181,7 @@ 8 - 86 + 64 1 0 0 @@ -1457,7 +1193,7 @@ 8 - 87 + 65 1 0 0 @@ -1477,7 +1213,7 @@ 0 9 - 88 + 66 1 0 0 @@ -1489,7 +1225,7 @@ 9 - 89 + 67 1 0 0 @@ -1501,7 +1237,7 @@ 9 - 90 + 68 1 0 0 @@ -1513,7 +1249,7 @@ 9 - 91 + 69 1 0 0 @@ -1525,7 +1261,7 @@ 9 - 92 + 70 1 0 0 @@ -1537,7 +1273,7 @@ 9 - 93 + 71 1 0 0 @@ -1557,7 +1293,7 @@ 0 10 - 94 + 72 1 0 0 @@ -1569,7 +1305,7 @@ 10 - 95 + 73 1 0 0 @@ -1581,7 +1317,7 @@ 10 - 96 + 74 1 0 0 @@ -1601,7 +1337,7 @@ 0 11 - 97 + 75 1 0 0 @@ -1613,7 +1349,7 @@ 11 - 98 + 76 1 0 0 @@ -1625,7 +1361,7 @@ 11 - 99 + 77 1 0 0 @@ -1645,7 +1381,7 @@ 0 12 - 100 + 78 1 0 0 @@ -1657,7 +1393,7 @@ 12 - 101 + 79 1 0 0 @@ -1669,7 +1405,7 @@ 12 - 102 + 80 1 0 0 @@ -1689,7 +1425,7 @@ 0 13 - 103 + 81 1 0 0 @@ -1701,7 +1437,7 @@ 13 - 104 + 82 1 0 0 @@ -1721,7 +1457,7 @@ 0 14 - 105 + 83 1 0 0 @@ -1733,7 +1469,7 @@ 14 - 106 + 84 1 0 0 @@ -1745,7 +1481,7 @@ 14 - 107 + 85 1 0 0 @@ -1757,7 +1493,7 @@ 14 - 108 + 86 1 0 0 @@ -1770,6 +1506,38 @@ + app_service + 1 + 0 + 0 + 0 + + 15 + 87 + 1 + 0 + 0 + 0 + .\src\app_service\battery_mgr_service.c + battery_mgr_service.c + 0 + 0 + + + 15 + 88 + 1 + 0 + 0 + 0 + .\src\app_service\adc_mgr.c + adc_mgr.c + 0 + 0 + + + + ::CMSIS 0 0 diff --git a/app/app.uvprojx b/app/app.uvprojx index 13cc01b..180d424 100644 --- a/app/app.uvprojx +++ b/app/app.uvprojx @@ -399,124 +399,14 @@ .\src\main.c - board_beep_ctrl.c - 1 - .\src\board\board_beep_ctrl.c - - - board_adc_module_ctrl.c - 1 - .\src\board\board_adc_module_ctrl.c - - - board_battery_state.c - 1 - .\src\board\board_battery_state.c - - - board_ecg_sensor.c - 1 - .\src\board\board_ecg_sensor.c - - - board_light_ctrl.c - 1 - .\src\board\board_light_ctrl.c - - - board_ssd1306_interface.c - 1 - .\src\board\board_ssd1306_interface.c - - - board_eeprom_driver.c - 1 - .\src\board\board_eeprom_driver.c - - - board_power_mgr.c - 1 - .\src\board\board_power_mgr.c - - - device_state.c - 1 - .\src\basic_service\device_state.c - - device_version_info_mgr.c 1 - .\src\basic_service\device_version_info_mgr.c - - - driver_ssd1306.c - 1 - .\src\board\ssd1306\driver_ssd1306.c - - - driver_ssd1306_basic.c - 1 - .\src\board\ssd1306\driver_ssd1306_basic.c - - - fontlib.c - 1 - .\src\board\ssd1306\fontlib.c - - - wave_drawer.c - 1 - .\src\board\ssd1306\wave_drawer.c - - - ble_cmd_process_service.c - 1 - .\src\service\ble_cmd_processer\ble_cmd_process_service.c - - - display_manager.c - 1 - .\src\service\display_mgr\display_manager.c - - - heart_ware_sample_data_mgr.c - 1 - .\src\service\heart_wave_sample_service\heart_ware_sample_data_mgr.c - - - heart_wave_sample_data_pre_process.c - 1 - .\src\service\heart_wave_sample_service\heart_wave_sample_data_pre_process.c - - - heart_wave_sample_service.c - 1 - .\src\service\heart_wave_sample_service\heart_wave_sample_service.c - - - sample_data_manager.c - 1 - .\src\service\storage\sample_data_manager.c + .\src\app_basic_service\device_version_info_mgr.c - zeeprom_fs.c + zapp.c 1 - .\src\service\storage\zeeprom_fs.c - - - app_event_distribute.c - 1 - .\src\basic_service\app_event_distribute.c - - - ads129x.c - 1 - .\src\board\ads129x\ads129x.c - - - app_board.c - 1 - .\src\board\app_board.c + .\src\app_basic_service\zapp.c @@ -3898,6 +3788,21 @@ + app_service + + + battery_mgr_service.c + 1 + .\src\app_service\battery_mgr_service.c + + + adc_mgr.c + 1 + .\src\app_service\adc_mgr.c + + + + ::CMSIS @@ -4298,124 +4203,14 @@ .\src\main.c - board_beep_ctrl.c - 1 - .\src\board\board_beep_ctrl.c - - - board_adc_module_ctrl.c - 1 - .\src\board\board_adc_module_ctrl.c - - - board_battery_state.c - 1 - .\src\board\board_battery_state.c - - - board_ecg_sensor.c - 1 - .\src\board\board_ecg_sensor.c - - - board_light_ctrl.c - 1 - .\src\board\board_light_ctrl.c - - - board_ssd1306_interface.c - 1 - .\src\board\board_ssd1306_interface.c - - - board_eeprom_driver.c - 1 - .\src\board\board_eeprom_driver.c - - - board_power_mgr.c - 1 - .\src\board\board_power_mgr.c - - - device_state.c - 1 - .\src\basic_service\device_state.c - - device_version_info_mgr.c 1 - .\src\basic_service\device_version_info_mgr.c - - - driver_ssd1306.c - 1 - .\src\board\ssd1306\driver_ssd1306.c - - - driver_ssd1306_basic.c - 1 - .\src\board\ssd1306\driver_ssd1306_basic.c - - - fontlib.c - 1 - .\src\board\ssd1306\fontlib.c - - - wave_drawer.c - 1 - .\src\board\ssd1306\wave_drawer.c - - - ble_cmd_process_service.c - 1 - .\src\service\ble_cmd_processer\ble_cmd_process_service.c - - - display_manager.c - 1 - .\src\service\display_mgr\display_manager.c - - - heart_ware_sample_data_mgr.c - 1 - .\src\service\heart_wave_sample_service\heart_ware_sample_data_mgr.c - - - heart_wave_sample_data_pre_process.c - 1 - .\src\service\heart_wave_sample_service\heart_wave_sample_data_pre_process.c - - - heart_wave_sample_service.c - 1 - .\src\service\heart_wave_sample_service\heart_wave_sample_service.c - - - sample_data_manager.c - 1 - .\src\service\storage\sample_data_manager.c + .\src\app_basic_service\device_version_info_mgr.c - zeeprom_fs.c + zapp.c 1 - .\src\service\storage\zeeprom_fs.c - - - app_event_distribute.c - 1 - .\src\basic_service\app_event_distribute.c - - - ads129x.c - 1 - .\src\board\ads129x\ads129x.c - - - app_board.c - 1 - .\src\board\app_board.c + .\src\app_basic_service\zapp.c @@ -7797,6 +7592,21 @@ + app_service + + + battery_mgr_service.c + 1 + .\src\app_service\battery_mgr_service.c + + + adc_mgr.c + 1 + .\src\app_service\adc_mgr.c + + + + ::CMSIS diff --git a/app/src/app_basic_service/basic/event.h b/app/src/app_basic_service/basic/event.h new file mode 100644 index 0000000..9a3d33d --- /dev/null +++ b/app/src/app_basic_service/basic/event.h @@ -0,0 +1,33 @@ +#pragma once +#include +#include + +#include "aproject_config/config.h" +typedef enum { + kplod_connected_event = 0, // 导联连接事件 + kplod_disconnected_event, // 导联断开事件 + kplod_connecting_event, // 导联连接中事件 + + kbattery_start_charge_event, // 充电事件 + kbattery_end_charge_event, // 充电结束事件 + + kevent_tmr_scheduler_event, // 定时器调度事件 + + kevent_capture_256data_event, // 采样数据回调 + kevent_capture_little_data_block_event, // 单次采样数据回调 +} app_event_type_t; + +typedef int32_t one_frame_t; + +typedef struct { + app_event_type_t eventType; + union { + uint32_t plod_connected_accumulation_time; // 导联连接累计时间 + uint8_t* capture_data_cache; // 实时采样数据,数据长度为256字节 + struct { + uint32_t frameIndex; + uint32_t timestamp; + one_frame_t data[LITTLE_DATA_BLOCK_FRAME_NUM]; + } little_data_block; + } val; +} app_event_t; \ No newline at end of file diff --git a/app/src/app_basic_service/basic/gstate.h b/app/src/app_basic_service/basic/gstate.h new file mode 100644 index 0000000..957b765 --- /dev/null +++ b/app/src/app_basic_service/basic/gstate.h @@ -0,0 +1,10 @@ +#pragma once +#include +#include + +#include "aproject_config/config.h" + +typedef struct { + bool sample_capture_state_is_over30s; // 采样是否超过30s + bool is_preview; // 当前是否正在预览 +} gstate_t; diff --git a/app/src/app_basic_service/basic/state.h b/app/src/app_basic_service/basic/state.h new file mode 100644 index 0000000..9fec6cb --- /dev/null +++ b/app/src/app_basic_service/basic/state.h @@ -0,0 +1,48 @@ +#pragma once +#include +#include + +#include "aproject_config/config.h" +typedef enum { + // 待机 + kdevice_state_standby = 0, + // 充电中 + kdevice_state_charging, + // 开机 + kdevice_state_poweron, + // 首页 + kdevice_state_home, + // 提示用户保持静止 + kdevice_state_keep_still, + // 采集中 + kdevice_state_sampling, + // 采集完成 + kdevice_state_sampling_complete, + // 采集异常 + kdevice_state_sampling_error, + // 测试模式 + kdevice_state_test_mode, +} device_state_t; + +static const char* device_state_to_str(device_state_t ds) { + switch (ds) { + case kdevice_state_standby: + return "standby"; + case kdevice_state_poweron: + return "poweron"; + case kdevice_state_home: + return "home"; + case kdevice_state_keep_still: + return "keep_still"; + case kdevice_state_sampling: + return "sampling"; + case kdevice_state_sampling_complete: + return "sampling_complete"; + case kdevice_state_sampling_error: + return "sampling_error"; + case kdevice_state_charging: + return "charging"; + default: + return "unknow"; + } +} diff --git a/app/src/app_basic_service/device_version_info_mgr.c b/app/src/app_basic_service/device_version_info_mgr.c new file mode 100644 index 0000000..1b8d268 --- /dev/null +++ b/app/src/app_basic_service/device_version_info_mgr.c @@ -0,0 +1,29 @@ +#include "device_version_info_mgr.h" + +#include "aproject_config/config.h" +#include "zble_module.h" +// +#include "znordic.h" +void device_info_read_sn(sn_t *sn) { + uint32_t lot = NRF_UICR->CUSTOMER[0]; + uint32_t id = NRF_UICR->CUSTOMER[1]; + static char sn_str[15]; + if (lot == 0 || id == 0 || lot == 0xffffffff || id == 0xffffffff) { + sprintf(sn_str, "%s-%s","iflytop",CATEGORY); + } else { + sprintf(sn_str, "%s%04d%05d", CATEGORY, lot, id); + } + + memcpy(sn->sn, sn_str, sizeof(sn->sn)); +} + +const char *device_info_read_sn_str() { + static char sn_str[15]; + device_info_read_sn((sn_t *)sn_str); + return sn_str; +} + +uint16_t device_info_read_blestack_version(void) { return BLESTACK_VERSION; } +uint16_t device_info_read_bootloader_version(void) { return BOOTLOADER_VERSION; } +uint16_t device_info_read_firmware_version(void) { return FIRMWARE_VERSION; } +uint16_t device_info_read_hardware_version(void) { return HARDWARE_VERSION; } \ No newline at end of file diff --git a/app/src/app_basic_service/device_version_info_mgr.h b/app/src/app_basic_service/device_version_info_mgr.h new file mode 100644 index 0000000..00f9abb --- /dev/null +++ b/app/src/app_basic_service/device_version_info_mgr.h @@ -0,0 +1,16 @@ +#pragma once +#include "znordic.h" + + + +typedef struct { + uint8_t sn[14]; +} sn_t; + +void device_info_read_sn(sn_t *sn); +const char *device_info_read_sn_str(); + +uint16_t device_info_read_blestack_version(void); +uint16_t device_info_read_bootloader_version(void); +uint16_t device_info_read_firmware_version(void); +uint16_t device_info_read_hardware_version(void); \ No newline at end of file diff --git a/app/src/app_basic_service/zapp.c b/app/src/app_basic_service/zapp.c new file mode 100644 index 0000000..ce9e09d --- /dev/null +++ b/app/src/app_basic_service/zapp.c @@ -0,0 +1,82 @@ +#include "zapp.h" + +#include "znordic.h" + +typedef struct { + app_event_listener_t cbfunc; +} AppEventListener; + +static device_state_t m_device_state = kdevice_state_standby; // 设备状态 +static uint32_t m_change_to_cur_state_tp = 0; // 切换到当前状态的时间戳 +static on_state_change_t m_onstate_change; +static AppEventListener m_listener[10]; +static int m_listener_num = 0; + +APP_TIMER_DEF(m_state_machine_driver_tmr); // 状态机驱动定时器 +#define SCHED_MAX_EVENT_DATA_SIZE MAX(sizeof(app_event_t), APP_TIMER_SCHED_EVENT_DATA_SIZE) + +/*********************************************************************************************************************** + * CALL BAK * + ***********************************************************************************************************************/ +static void state_machine_driver_tmr_cb(void* p_context) { // + static app_event_t appevent; + appevent.eventType = kevent_tmr_scheduler_event; + wd_feed(); + zapp_ebus_push_event(&appevent); +} + +static void app_event_process_cb(void* p_event_data, uint16_t event_size) { + for (int i = 0; i < m_listener_num; i++) { + if (m_listener[i].cbfunc) { + m_listener[i].cbfunc(p_event_data, event_size); + } + } +} + +/*********************************************************************************************************************** + * EXTERN * + ***********************************************************************************************************************/ +void zapp_early_init() { APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, 20); } +void zapp_init() { ZERROR_CHECK(app_timer_create(&m_state_machine_driver_tmr, APP_TIMER_MODE_REPEATED, state_machine_driver_tmr_cb)); } +void zapp_start_schedule() { ZERROR_CHECK(app_timer_start(m_state_machine_driver_tmr, APP_TIMER_TICKS(300), NULL)); } + +/*********************************************************************************************************************** + * state_machine * + ***********************************************************************************************************************/ +void zapp_state_machine_reg_state_change_listener(on_state_change_t listener) { m_onstate_change = listener; } +void zapp_state_machine_change_state(device_state_t tostate) { + ZLOGI("change state from %s to %s", device_state_to_str(m_device_state), device_state_to_str(tostate)); + device_state_t nowstate = m_device_state; + + m_device_state = tostate; + if (m_onstate_change) { + m_onstate_change(nowstate, m_device_state); + } + m_change_to_cur_state_tp = znordic_getpower_on_ms(); +} +device_state_t zapp_state_machine_now_state() { return m_device_state; } +uint32_t zapp_state_machine_haspassed_ms() { return znordic_haspassed_ms(m_change_to_cur_state_tp); } + +/*********************************************************************************************************************** + * EBUS * + ***********************************************************************************************************************/ +void zapp_ebus_push_event(app_event_t* event) { app_event_process_cb(event, sizeof(app_event_t)); } +void zapp_ebus_reg_event_listener(app_event_listener_t listener) { + ZASSERT(m_listener_num < 10); + m_listener[m_listener_num++].cbfunc = listener; +} + +/*********************************************************************************************************************** + * GSTATE * + ***********************************************************************************************************************/ +static gstate_t gstate; +gstate_t* zapp_get_gstate() { return &gstate; } + +void zapp_gstate_set_is_over30s(bool over30s) { + gstate_t* p_gstate = zapp_get_gstate(); + p_gstate->sample_capture_state_is_over30s = over30s; +} +void zapp_gstate_set_preview_state(bool is_preview) { + gstate_t* p_gstate = zapp_get_gstate(); + p_gstate->is_preview = is_preview; +} diff --git a/app/src/app_basic_service/zapp.h b/app/src/app_basic_service/zapp.h new file mode 100644 index 0000000..b6ac5db --- /dev/null +++ b/app/src/app_basic_service/zapp.h @@ -0,0 +1,37 @@ +#pragma once +#include +#include + +#include "aproject_config/config.h" +#include "basic/event.h" +#include "basic/gstate.h" +#include "basic/state.h" + +typedef void (*on_state_change_t)(device_state_t from, device_state_t to); +typedef void (*app_event_listener_t)(void* p_event_data, uint16_t event_size); + +void zapp_early_init(); +void zapp_init(); +void zapp_start_schedule(); + +/*********************************************************************************************************************** + * StateMachine * + ***********************************************************************************************************************/ +void zapp_state_machine_reg_state_change_listener(on_state_change_t listener); +void zapp_state_machine_change_state(device_state_t tostate); +device_state_t zapp_state_machine_now_state(); +device_state_t zapp_state_machine_now_state(); +uint32_t zapp_state_machine_haspassed_ms(); + +/*********************************************************************************************************************** + * event bus * + ***********************************************************************************************************************/ +void zapp_ebus_push_event(app_event_t* event); +void zapp_ebus_reg_event_listener(app_event_listener_t listener); + +/*********************************************************************************************************************** + * GSTATE * + ***********************************************************************************************************************/ +gstate_t* zapp_get_gstate(); +void zapp_gstate_set_is_over30s(bool over30s); +void zapp_gstate_set_preview_state(bool is_preview); diff --git a/app/src/app_service/adc_mgr.c b/app/src/app_service/adc_mgr.c new file mode 100644 index 0000000..4034d22 --- /dev/null +++ b/app/src/app_service/adc_mgr.c @@ -0,0 +1,37 @@ + +#include "adc_mgr.h" + +/******************************************************************************* + * ADC * + *******************************************************************************/ + +static uint8_t m_now_adc_channel = 0xff; + +void adc_mgr_set_ch(uint8_t ch) { + if (m_now_adc_channel != ch) { + if (m_now_adc_channel != 0xff) nrfx_saadc_channel_uninit(m_now_adc_channel); + if (ch == BATTERY_ADC_CHANNEL) { + nrf_saadc_channel_config_t channel_config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(BATTERY_ADC_PIN); + channel_config.acq_time = NRF_SAADC_ACQTIME_40US; + ZERROR_CHECK(nrfx_saadc_channel_init(BATTERY_ADC_CHANNEL, &channel_config)); + } + } + m_now_adc_channel = ch; +} + +void adc_mgr_init() {} + +void adc_mgr_load() { + nrf_drv_saadc_config_t adccfg = NRFX_SAADC_DEFAULT_CONFIG; + adccfg.resolution = NRF_SAADC_RESOLUTION_12BIT; // 4096 等于满采样率 + ZERROR_CHECK(nrf_drv_saadc_init(&adccfg, NULL)); +} +void adc_mgr_unload() { + adc_mgr_set_ch(0xff); + nrf_drv_saadc_uninit(); +} + +int16_t adc_mgr_get_val(uint8_t ch) { + adc_mgr_set_ch(ch); + return znrf_adc_channel_read_val(ch); +} diff --git a/app/src/app_service/adc_mgr.h b/app/src/app_service/adc_mgr.h new file mode 100644 index 0000000..bdae805 --- /dev/null +++ b/app/src/app_service/adc_mgr.h @@ -0,0 +1,14 @@ +#pragma once + +#include +#include + +#include "aproject_config/config.h" +#include "znordic.h" + +void adc_mgr_init(); + +void adc_mgr_load(); +void adc_mgr_unload(); + +int16_t adc_mgr_get_val(uint8_t ch); diff --git a/app/src/app_service/battery_mgr_service.c b/app/src/app_service/battery_mgr_service.c new file mode 100644 index 0000000..4f22cda --- /dev/null +++ b/app/src/app_service/battery_mgr_service.c @@ -0,0 +1,46 @@ +#include "battery_mgr_service.h" + +#include "adc_mgr.h" +#include "app_basic_service/zapp.h" + +APP_TIMER_DEF(battery_state_detect_tmr); // +static bool m_battery_is_chargeing = false; // + +static bool battery_get_chargeing_state() { return !nrf_gpio_pin_read(BATTERY_CHARGE_DETECT_PIN); } +static void module_tmr_cb(void *context) { // + bool chargeing_state = battery_get_chargeing_state(); + if (chargeing_state != m_battery_is_chargeing) { + app_event_t event; + memset(&event, 0, sizeof(event)); + if (chargeing_state) { + ZLOGI("battery is charging"); + event.eventType = kbattery_start_charge_event; + } else { + ZLOGI("battery end charging"); + event.eventType = kbattery_end_charge_event; + } + zapp_ebus_push_event(&event); + } + m_battery_is_chargeing = chargeing_state; +} + +/*********************************************************************************************************************** + * extern * + ***********************************************************************************************************************/ +void BatteryMgrService_init() { + adc_mgr_init(); + /** + * @brief 500ms启动定时器500ms检查一次当前是否正在充电 + */ + nrf_gpio_cfg_sense_input(BATTERY_CHARGE_DETECT_PIN, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_NOSENSE); + app_timer_create(&battery_state_detect_tmr, APP_TIMER_MODE_REPEATED, module_tmr_cb); + app_timer_start(battery_state_detect_tmr, APP_TIMER_TICKS(500), NULL); +} + +void BatteryMgrService_load() { adc_mgr_load(); } +void BatteryMgrService_unload() { + // adc是公共资源,在最上层进行unload +} + +int16_t BatteryMgrService_get_battery_level() { return 30; } +int16_t BatteryMgrService_get_charging_state() { return !nrf_gpio_pin_read(BATTERY_CHARGE_DETECT_PIN); } \ No newline at end of file diff --git a/app/src/app_service/battery_mgr_service.h b/app/src/app_service/battery_mgr_service.h new file mode 100644 index 0000000..d327358 --- /dev/null +++ b/app/src/app_service/battery_mgr_service.h @@ -0,0 +1,17 @@ +#pragma once + +#include +#include + +#include "aproject_config/config.h" +#include "adc_mgr.h" +#include "znordic.h" + +void BatteryMgrService_init(); + +void BatteryMgrService_load(); +void BatteryMgrService_unload(); + + +int16_t BatteryMgrService_get_battery_level(); +int16_t BatteryMgrService_get_charging_state(); diff --git a/app/src/bakservice/ble_cmd_processer/ble_cmd_process_service.c b/app/src/bakservice/ble_cmd_processer/ble_cmd_process_service.c new file mode 100644 index 0000000..ea9e6fd --- /dev/null +++ b/app/src/bakservice/ble_cmd_processer/ble_cmd_process_service.c @@ -0,0 +1,261 @@ +#include "ble_cmd_process_service.h" + +#include "aproject_config/config.h" +// +#include "ify_hrs_protocol/heart_rate_sensor_protocol.h" +// +#include "basic_service/device_version_info_mgr.h" +#include "board/board_battery_state.h" +#include "board/board_ecg_sensor.h" +#include "service/storage/storage_service.h" +// +#include "zble_module.h" +#include "zdatachannel_service.h" + +APP_TIMER_DEF(m_record_upload_tmr); // 数据上报定时器 +APP_TIMER_DEF(m_record_upload_finish_packet_report_tmr); // 数据上报完成上报定时器 +static uint8_t txbuf[250]; +static uint8_t reportbuf[250]; +static int m_upload_record_state = 0; +static uint32_t m_upload_data_state_enter_tp = 0; + +static bool m_ble_cmder_is_inited = false; +static uint32_t m_report_data_sumcheckcode = 0; + +static void record_upload_tmr_cb(void* p_context); +static void record_upload_finish_packet_report_tmr_cb(void* p_context); +int ble_stop_upload_record(); +/******************************************************************************* + * 广播控制 * + *******************************************************************************/ +void ble_cmder_start_adv() { + global_state_set_preview_state(false); + zble_module_start_adv(); +} +void ble_cmder_stop_adv() { + zble_module_stop_adv(); + global_state_set_preview_state(false); +} + +/******************************************************************************* + * 模块初始化 * + *******************************************************************************/ +void ble_cmder_init() { + if (!m_ble_cmder_is_inited) { + ZERROR_CHECK(app_timer_create(&m_record_upload_tmr, APP_TIMER_MODE_REPEATED, record_upload_tmr_cb)); + ZERROR_CHECK(app_timer_create(&m_record_upload_finish_packet_report_tmr, APP_TIMER_MODE_SINGLE_SHOT, record_upload_finish_packet_report_tmr_cb)); + } + m_ble_cmder_is_inited = true; +} +void ble_cmder_uninit() {} + +/******************************************************************************* + * 实时上报控制 * + *******************************************************************************/ + +void ble_cmder_try_report_one_sample_data(app_event_t* event) { + heartrate_report_packet_t* reportpacket = (heartrate_report_packet_t*)reportbuf; + reportpacket->cmd = ify_hrs_report_heartrate_data; + reportpacket->frame_index = 0; + reportpacket->frame_type = kifyhrs_pt_report; + reportpacket->sample_data_index = event->val.little_data_block.frameIndex; + + for (int i = 0; i < LITTLE_DATA_BLOCK_FRAME_NUM; i++) { + reportpacket->data[i * 4] = (event->val.little_data_block.data[i] >> 0) & 0xFF; + reportpacket->data[i * 4 + 1] = (event->val.little_data_block.data[i] >> 8) & 0xFF; + reportpacket->data[i * 4 + 2] = (event->val.little_data_block.data[i] >> 16) & 0xFF; + reportpacket->data[i * 4 + 3] = (event->val.little_data_block.data[i] >> 24) & 0xFF; + } + reportpacket->data[LITTLE_DATA_BLOCK_FRAME_NUM * 4] = (event->val.little_data_block.timestamp >> 0) & 0xFF; + reportpacket->data[LITTLE_DATA_BLOCK_FRAME_NUM * 4 + 1] = (event->val.little_data_block.timestamp >> 8) & 0xFF; + reportpacket->data[LITTLE_DATA_BLOCK_FRAME_NUM * 4 + 2] = (event->val.little_data_block.timestamp >> 16) & 0xFF; + reportpacket->data[LITTLE_DATA_BLOCK_FRAME_NUM * 4 + 3] = (event->val.little_data_block.timestamp >> 24) & 0xFF; + + STATIC_ASSERT(sizeof(one_frame_t) == 4); + + // reportpacket->data[2] = (data1 >> 0) & 0xFF; // 第二帧数据 + // reportpacket->data[3] = (data1 >> 8) & 0xFF; // 第二帧数据 + // reportpacket->data[4] = (data2 >> 0) & 0xFF; // 第三帧数据 + // reportpacket->data[5] = (data2 >> 8) & 0xFF; // 第三帧数据 + // reportpacket->data[6] = (data3 >> 0) & 0xFF; // 第四帧数据 + // reportpacket->data[7] = (data3 >> 8) & 0xFF; // 第四帧数据 + // reportpacket->data[8] = (data4 >> 0) & 0xFF; // 第五帧数据 + // reportpacket->data[9] = (data4 >> 8) & 0xFF; // 第五帧数据 + + uint16_t sendlen = sizeof(heartrate_report_packet_t) + LITTLE_DATA_BLOCK_FRAME_NUM * 4 + 4; + zdatachannel_data_send2(reportbuf, sendlen); + return; +} + +void ble_cmder_try_report_sensor_drop_event(uint8_t dropstate0, uint8_t dropstate1) { + sensor_drop_event_report_packet_t* reportpacket = (sensor_drop_event_report_packet_t*)reportbuf; + reportpacket->cmd = ify_hrs_report_sensor_drop_detect; + reportpacket->frame_index = 0; + reportpacket->frame_type = kifyhrs_pt_report; + reportpacket->drop_state0 = dropstate0; + reportpacket->drop_state1 = dropstate1; + + uint16_t sendlen = sizeof(sensor_drop_event_report_packet_t); + zdatachannel_data_send2(reportbuf, sendlen); + return; +} +void ble_cmder_report_upload_finish_event(uint32_t sumcheckcode) { + ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)txbuf; + uint16_t sendlen = sizeof(ify_hrs_packet_t) + 4; + + txheader->cmd = ify_hrs_report_record_upload_end; // 6A + txheader->frame_index = 0; + txheader->frame_type = kifyhrs_pt_report; + + // txheader->data[0] = errorcode; + *(uint32_t*)txheader->data = sumcheckcode; + + zdatachannel_data_send2(txbuf, sendlen); + return; +} + +void ble_cmder_report_sample_finish_event() { + ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)txbuf; + uint16_t sendlen = sizeof(ify_hrs_packet_t); + + txheader->cmd = ify_hrs_report_sample_finish_end; + txheader->frame_index = 0; + txheader->frame_type = kifyhrs_pt_report; + + zdatachannel_data_send2(txbuf, sendlen); + return; +} + +/******************************************************************************* + * 上传数据控制 * + *******************************************************************************/ +static int m_upload_fd; +static uint8_t datacache[256]; +static int m_remaindatalen = 0; +/** + * @brief 数据上报定时器回调 + * + * @param p_context + */ +static void record_upload_finish_packet_report_tmr_cb(void* p_context) { // + ble_cmder_report_upload_finish_event(m_report_data_sumcheckcode); +} + +static void record_upload_tmr_cb(void* p_context) { // + + if (m_upload_record_state == 0) return; + + if (m_upload_record_state == 1) { + if (m_remaindatalen == 0) { + memset(datacache, 0, sizeof(datacache)); + int32_t rdsize = sample_data_mgr_read(m_upload_fd, datacache, sizeof(datacache)); + if (rdsize <= 0) { + ZLOGI("read file end,stop upload"); + m_upload_record_state = 2; + m_upload_data_state_enter_tp = znordic_getpower_on_ms(); + return; + } + m_remaindatalen = rdsize; + } + if (m_remaindatalen == 0) { + return; + } + + int32_t mtusize = zble_module_get_mtu_size(); + mtusize = mtusize < 128 ? mtusize : 128; + + uint8_t* data = datacache + (sizeof(datacache) - m_remaindatalen); + int len = m_remaindatalen > mtusize ? mtusize : m_remaindatalen; + + ZLOGI("upload %d %d %d", len, m_remaindatalen, mtusize); + if (!zdatachannel_is_connected()) { + ZLOGI("ble is disconnected,stop upload"); + ble_stop_upload_record(); + return; + } + + uint32_t suc = zdatachannel_block_data_send2(data, len); + if (suc != NRF_SUCCESS) { + if (suc == NRF_ERROR_INVALID_STATE) { + // 未使能notify + ZLOGI("ble unenable notify,stop upload"); + ble_stop_upload_record(); + return; + } else if (suc == NRF_ERROR_BUSY || suc == NRF_ERROR_RESOURCES) { + // 等待下次发送 + return; + } else { + ZLOGI("ble send error,stop upload %x", suc); + ble_stop_upload_record(); + return; + } + } + for (uint32_t i = 0; i < len; i++) { + m_report_data_sumcheckcode += data[i]; + } + m_remaindatalen -= len; + } else { + if (znordic_haspassed_ms(m_upload_data_state_enter_tp) > 30) { + ble_cmder_report_upload_finish_event(m_report_data_sumcheckcode); + ble_stop_upload_record(); + return; + } + } +} + +int ble_start_upload_record(sample_data_filename_t* recordid) { + // + // 启动 + // + if (ds_now_state() != kdevice_state_home && ds_now_state() != kdevice_state_charging) { + return kifyhrs_ecode_device_busy; + } + + m_upload_fd = sample_data_mgr_open(recordid, kwrflag_read_only); + if (m_upload_fd <= 0) { + return kifyhrs_ecode_no_record_find; + } + + ZERROR_CHECK(app_timer_start(m_record_upload_tmr, APP_TIMER_TICKS(15), NULL)); + m_upload_record_state = 1; + m_remaindatalen = 0; + m_report_data_sumcheckcode = 0; + return 0; +} +int ble_stop_upload_record() { + m_upload_record_state = 0; + app_timer_stop(m_record_upload_tmr); + if (m_upload_fd > 0) { + sample_data_mgr_close(m_upload_fd); + m_upload_fd = 0; + } + return 0; +} +bool ble_is_upload_record() { return m_upload_record_state != 0; } + +/******************************************************************************* + * UTILS * + *******************************************************************************/ +static void send_error_receipt(ify_hrs_packet_t* rxpacket, int32_t errorcode) { + ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)txbuf; + error_receipt_t* receipt = (error_receipt_t*)txheader->data; + uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(error_receipt_t); + + txheader->cmd = rxpacket->cmd; + txheader->frame_index = rxpacket->frame_index; + txheader->frame_type = kifyhrs_pt_error_receipt; + receipt->errorcode = errorcode; + zdatachannel_data_send2(txbuf, sendlen); +} + +static void send_success_receipt(ify_hrs_packet_t* rxpacket, int32_t emptydatasize) { + ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)txbuf; + uint16_t sendlen = sizeof(ify_hrs_packet_t) + emptydatasize; + + txheader->cmd = rxpacket->cmd; + txheader->frame_index = rxpacket->frame_index; + txheader->frame_type = kifyhrs_pt_cmd_receipt; + + zdatachannel_data_send2(txbuf, sendlen); +} + diff --git a/app/src/bakservice/ble_cmd_processer/ble_cmd_process_service.h b/app/src/bakservice/ble_cmd_processer/ble_cmd_process_service.h new file mode 100644 index 0000000..ce20220 --- /dev/null +++ b/app/src/bakservice/ble_cmd_processer/ble_cmd_process_service.h @@ -0,0 +1,17 @@ +#pragma once + +#include "basic_service/device_state.h" + +void ble_cmder_init(); +void ble_cmder_uninit(); + +void ble_cmder_process_rx(uint8_t* rx, int len); +void ble_cmder_start_adv(); +void ble_cmder_stop_adv(); + +void ble_cmder_try_report_one_sample_data(app_event_t* event); +void ble_cmder_try_report_sensor_drop_event(uint8_t dropstate0, uint8_t dropstate1); +void ble_cmder_report_upload_finish_event(uint32_t sumcheckcode); +void ble_cmder_report_sample_finish_event(); +bool ble_is_upload_record(); +int ble_stop_upload_record(); diff --git a/app/src/bakservice/display_mgr/display_manager.c b/app/src/bakservice/display_mgr/display_manager.c new file mode 100644 index 0000000..a886363 --- /dev/null +++ b/app/src/bakservice/display_mgr/display_manager.c @@ -0,0 +1,443 @@ +#include "display_manager.h" + +#include "../../../screen_res/logo_mono.c" +// +#include + +#include "board/board_battery_state.h" +#include "board/board_ssd1306_interface.h" +#include "aproject_config/config.h" +#include "font.h" +PageState_t g_pageState; + +void dsp_mgr_change_to_page(page_t page) { // + g_pageState.page = page; + g_pageState.last_page = page; + g_pageState.page_change_to_page_time = znordic_getpower_on_s(); + + g_pageState.in_prompt = false; + memset(g_pageState.prompt, 0, sizeof(g_pageState.prompt)); +} + +uint32_t dsp_mgr_get_page_elapsed_time_s(void) { // + return znordic_getpower_on_s() - g_pageState.page_change_to_page_time; +} + +void dsp_mgr_schedule(void) {} + +PageState_t* dsp_mgr_get_state(void) { return NULL; } + +int compute_x_pos_by_center(int16_t x, int16_t width) { return x - width / 2; } +int compute_y_pos_by_center(int16_t y, int16_t height) { return y - height / 2; } + +#define SCREEN_CENTER_X 64 +#define SCREEN_CENTER_Y 32 + +#define CHARGE_BATTERY_WIDTH (12 * 1.2) +#define CHARGE_BATTERY_HEIGHT (22 * 1.2) + +#define MAIN_PAGE_BATTERY_WIDTH (12) // 首页电池宽度 +#define MAIN_PAGE_BATTERY_HEIGHT (22) // 首页电池高度 + +/******************************************************************************* + * 充电页面 * + *******************************************************************************/ +/** + * 显示元素: + * 1.电池电量 + * --------------- + * | _ | + * | | | | + * | | + * --------------- + * + * 动画效果: + * 1. 电池电量变化 + * + */ + +static uint32_t m_nowshowbatterylevel; // 当前显示的电池电量 + +void dsp_mgr_change_to_chargingPage() { + ssd1306_basic_clear(); + uint8_t x = compute_x_pos_by_center(SCREEN_CENTER_X, CHARGE_BATTERY_WIDTH); + uint8_t y = compute_y_pos_by_center(SCREEN_CENTER_Y, CHARGE_BATTERY_HEIGHT); + uint8_t xchange, ychange; + ssd1306_basic_draw_battery_level(x, y, &xchange, &ychange, BoardBattery_get_battery_level(), CHARGE_BATTERY_WIDTH, CHARGE_BATTERY_HEIGHT); + m_nowshowbatterylevel = BoardBattery_get_battery_level(); + ssd1306_basic_gram_update(); + dsp_mgr_change_to_page(kPage_chargingPage); +} + +void chargingPage_set_batteryLevel(int batteryLevel) { + uint8_t x = compute_x_pos_by_center(SCREEN_CENTER_X, CHARGE_BATTERY_WIDTH); + uint8_t y = compute_y_pos_by_center(SCREEN_CENTER_Y, CHARGE_BATTERY_HEIGHT); + uint8_t xchange, ychange; + ssd1306_basic_draw_battery_level(x, y, &xchange, &ychange, batteryLevel, CHARGE_BATTERY_WIDTH, CHARGE_BATTERY_HEIGHT); + ssd1306_basic_gram_update(); +} + +void chargingPage_schedule() { // + static uint32_t last_update_time = 0; + if (znordic_haspassed_ms(last_update_time) < 300) { + return; + } + + last_update_time = znordic_getpower_on_ms(); + m_nowshowbatterylevel += 5; + if (m_nowshowbatterylevel > 100) { + m_nowshowbatterylevel = BoardBattery_get_battery_level(); + } + chargingPage_set_batteryLevel(m_nowshowbatterylevel); +} + +/******************************************************************************* + * 欢迎页面 * + *******************************************************************************/ +void dsp_mgr_change_to_welcome() { + /** + * @brief 切换到欢迎界面 + * 1. 加载屏幕外设 + * 2. 打开屏幕电源 + * 3. 初始化开机页面 + */ + + // ssd1306_basic_string(0, 0, "123456789123456789123", 21, 0, SSD1306_FONT_12); + ssd1306_basic_draw_screen((const char*)gImage_logo_mono); + ssd1306_basic_gram_update(); + dsp_mgr_change_to_page(kPage_welcome); +} + +void welcomePage_schedule() {} + +/******************************************************************************* + * 首页 * + *******************************************************************************/ +static bool m_main_page_colon_state = false; + +void mainPage_show(bool colon_state) { + static ztm_t now; + int16_t batterylevel; + uint8_t xchange, ychange; + uint8_t x, y; + x = compute_x_pos_by_center(SCREEN_CENTER_X, fontclocklib.widthPixel * 5 + MAIN_PAGE_BATTERY_WIDTH); + y = compute_y_pos_by_center(SCREEN_CENTER_Y, fontclocklib.heightPixel + 1); + znordic_rtc_gettime(&now); + batterylevel = BoardBattery_get_battery_level(); + + ssd1306_basic_clear_gram(); + + // ZLOGI("mainPage_show %d %d", colon_state, x, y); + + ssd1306_basic_draw_str(x, y, &xchange, &ychange, fmt("%02d:%02d", now.tm_hour, now.tm_min), &fontclocklib); + x = x + 6 + xchange; + ssd1306_basic_draw_battery_level(x, y, &xchange, &ychange, batterylevel, MAIN_PAGE_BATTERY_WIDTH, MAIN_PAGE_BATTERY_HEIGHT); + ssd1306_basic_gram_update(); + m_main_page_colon_state = colon_state; + dsp_mgr_change_to_page(kPage_main); +} + +void dsp_mgr_change_to_main() { mainPage_show(true); } +void mainPage_updateState() { mainPage_show(!m_main_page_colon_state); } +void mainPage_schedule() { + static uint32_t last_update_time = 0; + if (znordic_haspassed_ms(last_update_time) < 300) { + return; + } + last_update_time = znordic_getpower_on_ms(); + mainPage_updateState(); +} + +/******************************************************************************* + * 保持静止页面 * + *******************************************************************************/ +static int m_prepare_page_progress = 0; +void PreparePage_show(int progress) { + m_prepare_page_progress = progress; + ssd1306_basic_clear_gram(); + uint8_t x = 0; + uint8_t y = 0; + uint8_t xchange, ychange; + + x = compute_x_pos_by_center(SCREEN_CENTER_X, font24x24_zh_lib.widthPixel * 4); + y = compute_y_pos_by_center(SCREEN_CENTER_Y, font24x24_zh_lib.heightPixel); + + ssd1306_basic_draw_str(x, y, &xchange, &ychange, "保持静止", &font24x24_zh_lib); + + if (progress == 0) { + ssd1306_basic_draw_str(x - font8x8_xo_lib.widthPixel, y - font8x8_xo_lib.heightPixel, &xchange, &ychange, "xxxx", &font8x8_xo_lib); + } else if (progress == 1) { + ssd1306_basic_draw_str(x - font8x8_xo_lib.widthPixel, y - font8x8_xo_lib.heightPixel, &xchange, &ychange, "oxxx", &font8x8_xo_lib); + } else if (progress == 2) { + ssd1306_basic_draw_str(x - font8x8_xo_lib.widthPixel, y - font8x8_xo_lib.heightPixel, &xchange, &ychange, "ooxx", &font8x8_xo_lib); + } else if (progress == 3) { + ssd1306_basic_draw_str(x - font8x8_xo_lib.widthPixel, y - font8x8_xo_lib.heightPixel, &xchange, &ychange, "ooox", &font8x8_xo_lib); + } else if (progress == 4) { + ssd1306_basic_draw_str(x - font8x8_xo_lib.widthPixel, y - font8x8_xo_lib.heightPixel, &xchange, &ychange, "oooo", &font8x8_xo_lib); + } + + ssd1306_basic_gram_update(); +} + +void dsp_mgr_change_to_preparePage() { + PreparePage_show(0); + dsp_mgr_change_to_page(kPage_preparePage); +} +void dsp_mgr_preparePage_set_progress(int progress) { PreparePage_show(progress); } +int dsp_mgr_preparePage_get_progress() { return m_prepare_page_progress; } + +void PreparePage_schedule() {} + +/******************************************************************************* + * 采样页面 * + *******************************************************************************/ + +#define SMAPLE_PAGE_START_X 1 +#define SMAPLE_PAGE_START_Y 1 + +typedef struct { + wave_drawer_t wave_drawer; + + int wave_drawser_x; + int wave_drawser_y; + int wave_drawser_hight; + int wave_drawser_width; + + int progress_x; + int progress_y; + + int progress_width; + int progress_hight; + + int heartrate_x; + int heartrate_y; +} sample_page_state_t; +sample_page_state_t m_sample_page_state; +#if 0 +void dsp_mgr_change_to_sampling(int progress_s, int heartrate) { // + sample_page_state_t* sps = &m_sample_page_state; + + sps->wave_drawser_x = SMAPLE_PAGE_START_X; + sps->wave_drawser_y = SMAPLE_PAGE_START_Y; + sps->wave_drawser_hight = 40; + sps->wave_drawser_width = 120; + + sps->progress_x = SMAPLE_PAGE_START_X + 1; + sps->progress_y = SMAPLE_PAGE_START_Y + sps->wave_drawser_hight + 3 + 4; + sps->progress_width = 80; + sps->progress_hight = 8; + + sps->heartrate_x = sps->progress_x + sps->progress_width + 2; + sps->heartrate_y = sps->progress_y - 4; + + int progress = progress_s / SAMPLE_MIN_TIME_S * 25; + + ssd1306_basic_clear_gram(); + + wave_drawer_init(&sps->wave_drawer, sps->wave_drawser_x, sps->wave_drawser_y, sps->wave_drawser_width, sps->wave_drawser_hight); + wave_drawer_draw_border(&sps->wave_drawer); + uint8_t xchange, ychange; + ssd1306_basic_draw_progress(sps->progress_x, sps->progress_y, sps->progress_width, sps->progress_hight, 25, progress); + if (heartrate <= 0) { + ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y, &xchange, &ychange, "<>-- ", &font_asicc16x8_lib); + } else { + ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y, &xchange, &ychange, fmt("<>%3d", heartrate), &font_asicc16x8_lib); + } + ssd1306_basic_gram_update(); + dsp_mgr_change_to_page(kPage_sampling); +} + +void samplePage_update_state(int progress_s, int wave_y, int heartrate, bool update_screen) { // + + sample_page_state_t* sps = &m_sample_page_state; + uint8_t xchange, ychange; + + int progress = progress_s / SAMPLE_MIN_TIME_S * 25; + + if (progress_s / 10 == 0) { + ssd1306_basic_draw_str(sps->progress_x, sps->progress_y - 8, &xchange, &ychange, "xxx", &font8x8_xo_lib); + } else if (progress_s / 10 == 1) { + ssd1306_basic_draw_str(sps->progress_x, sps->progress_y - 8, &xchange, &ychange, "oxx", &font8x8_xo_lib); + } else if (progress_s / 10 == 2) { + ssd1306_basic_draw_str(sps->progress_x, sps->progress_y - 8, &xchange, &ychange, "oox", &font8x8_xo_lib); + } else if (progress_s / 10 == 3) { + ssd1306_basic_draw_str(sps->progress_x, sps->progress_y - 8, &xchange, &ychange, "ooo", &font8x8_xo_lib); + } + + wave_drawer_draw_next_point(&sps->wave_drawer, wave_y); + ssd1306_basic_draw_progress(sps->progress_x, sps->progress_y, sps->progress_width, sps->progress_hight, 25, progress); + if (heartrate <= 0) { + ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y, &xchange, &ychange, "<>-- ", &font_asicc16x8_lib); + } else { + ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y, &xchange, &ychange, fmt("<>%3d", heartrate), &font_asicc16x8_lib); + } + if (update_screen) ssd1306_basic_gram_update(); +} +#endif +void dsp_mgr_change_to_sampling(int progress_s, int heartrate) { // + sample_page_state_t* sps = &m_sample_page_state; + + sps->progress_x = SMAPLE_PAGE_START_X + 10; + sps->progress_y = SMAPLE_PAGE_START_Y + 3; + sps->progress_width = 100; + sps->progress_hight = 8; + + sps->wave_drawser_x = SMAPLE_PAGE_START_X + 5; + sps->wave_drawser_y = SMAPLE_PAGE_START_Y + sps->progress_hight + 5; + sps->wave_drawser_hight = 45; + sps->wave_drawser_width = 85; + + sps->heartrate_x = sps->wave_drawser_x + sps->wave_drawser_width + 1; + sps->heartrate_y = sps->wave_drawser_y + 5; + + int progress = progress_s / SAMPLE_MIN_TIME_S * 25; + uint8_t xchange, ychange; + + ssd1306_basic_clear_gram(); + /** + * @brief + * ================= + * | | 心 + * | wave | + * | | 心率 + */ + ssd1306_basic_draw_progress(sps->progress_x, sps->progress_y, sps->progress_width, sps->progress_hight, 25, progress); + // ssd1306_basic_draw_str(sps->progress_x + sps->progress_width + 2, sps->progress_y, &xchange, &ychange, "x", &font8x8_xo_lib); + + wave_drawer_init(&sps->wave_drawer, sps->wave_drawser_x, sps->wave_drawser_y, sps->wave_drawser_width, sps->wave_drawser_hight); + // wave_drawer_draw_border(&sps->wave_drawer); + + ssd1306_basic_draw_str(sps->heartrate_x + 2, sps->heartrate_y, &xchange, &ychange, "<>", &font_asicc16x8_lib); + ssd1306_basic_draw_str(sps->heartrate_x + 4, sps->heartrate_y + 20, &xchange, &ychange, "-- ", &font_asicc16x8_lib); + ssd1306_basic_gram_update(); + dsp_mgr_change_to_page(kPage_sampling); +} + +void samplePage_update_state(int progress_s, int wave_y, int heartrate, bool updateHeart, bool update_screen) { // + + sample_page_state_t* sps = &m_sample_page_state; + uint8_t xchange, ychange; + static bool heart_logo_state = false; + + int progress = progress_s / SAMPLE_MIN_TIME_S * 25; + + ssd1306_basic_draw_progress(sps->progress_x, sps->progress_y, sps->progress_width, sps->progress_hight, 25, progress); + // if (progress_s / 10 >= 3) { + // ssd1306_basic_draw_str(sps->progress_x + sps->progress_width + 2, sps->progress_y, &xchange, &ychange, "o", &font8x8_xo_lib); + // } else { + // ssd1306_basic_draw_str(sps->progress_x + sps->progress_width + 2, sps->progress_y, &xchange, &ychange, "x", &font8x8_xo_lib); + // } + if (update_screen && updateHeart) { + if (heart_logo_state) { + ssd1306_basic_draw_str(sps->heartrate_x + 2, sps->heartrate_y, &xchange, &ychange, "<>", &font_asicc16x8_lib); + } else { + ssd1306_basic_draw_str(sps->heartrate_x + 2, sps->heartrate_y, &xchange, &ychange, " ", &font_asicc16x8_lib); + } + heart_logo_state = !heart_logo_state; + } + + if (heartrate <= 0) { + ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y + 20, &xchange, &ychange, " ", &font_asicc16x8_lib); + ssd1306_basic_draw_str(sps->heartrate_x + 4, sps->heartrate_y + 20, &xchange, &ychange, "-- ", &font_asicc16x8_lib); + } else { + if (heartrate >= 100) { + ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y + 20, &xchange, &ychange, " ", &font_asicc16x8_lib); + ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y + 20, &xchange, &ychange, fmt("%d", heartrate), &font_asicc16x8_lib); + } else { + ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y + 20, &xchange, &ychange, " ", &font_asicc16x8_lib); + ssd1306_basic_draw_str(sps->heartrate_x + 4, sps->heartrate_y + 20, &xchange, &ychange, fmt("%d", heartrate), &font_asicc16x8_lib); + } + } + wave_drawer_draw_next_point(&sps->wave_drawer, wave_y); + if (update_screen) ssd1306_basic_gram_update(); +} + +void samplePage_schedule() { + static int count = 0; + count++; + int capturetime = hwss_has_captured_time_ms(); + int wave_y = (int)hwss_read_val(); + int heartrate = (int)hwss_read_heart_rate(); + // ZLOGI("samplePage_schedule %d %d %d", capturetime, wave_y, heartrate); + samplePage_update_state(capturetime / 1000, wave_y, hwss_read_heart_rate(), count % 30 == 0, count % 10 == 0); +} + +/******************************************************************************* + * samplingError * + *******************************************************************************/ +void dsp_mgr_change_to_samplingError() { + /** + * @brief + * 不足30秒[X] + */ + ssd1306_basic_clear_gram(); + + uint8_t x; + uint8_t y; + + x = compute_x_pos_by_center(SCREEN_CENTER_X, font24x24_zh_lib.widthPixel * 3 + font12x24_asiic_lib.widthPixel * 2); + y = compute_y_pos_by_center(SCREEN_CENTER_Y, font24x24_zh_lib.heightPixel); + + uint8_t xchange, ychange; + ssd1306_basic_draw_str(x, y, &xchange, &ychange, "不足", &font24x24_zh_lib); + x = x + xchange; + ssd1306_basic_draw_str(x, y, &xchange, &ychange, "30", &font12x24_asiic_lib); + x = x + xchange; + ssd1306_basic_draw_str(x, y, &xchange, &ychange, "秒", &font24x24_zh_lib); + x = x + xchange; + ssd1306_basic_gram_update(); + dsp_mgr_change_to_page(kPage_samplingError); +} + +void dsp_mgr_change_to_sampleSuc() { + /** + * @brief + * 1.进度条 + * 2.提示信息 + */ + ssd1306_basic_clear(); + uint8_t x = 0; + uint8_t y = 0; + + uint8_t xchange, ychange; + x = compute_x_pos_by_center(SCREEN_CENTER_X, font24x24_zh_lib.widthPixel * 4); + y = compute_y_pos_by_center(SCREEN_CENTER_Y, font24x24_zh_lib.heightPixel); + + ssd1306_basic_draw_str(x, y, &xchange, &ychange, "采集完成", &font24x24_zh_lib); + ssd1306_basic_gram_update(); + dsp_mgr_change_to_page(kPage_storagingSuc); +} + +/******************************************************************************* + * SCHEDULE * + *******************************************************************************/ + +APP_TIMER_DEF(m_dsp_mgr_schedule_tmr); +static void dsp_mgr_schedule_tmr_cb(void* p_context) { // + if (g_pageState.page == kPage_chargingPage) { + chargingPage_schedule(); + } else if (g_pageState.page == kPage_welcome) { + welcomePage_schedule(); + } else if (g_pageState.page == kPage_main) { + mainPage_schedule(); + } else if (g_pageState.page == kPage_preparePage) { + PreparePage_schedule(); + } else if (g_pageState.page == kPage_sampling) { + samplePage_schedule(); + } +} + +void dsp_mgr_init(void) { + static bool timer_inited = false; + board_screen_init(); + if (!timer_inited) { + ZERROR_CHECK(app_timer_create(&m_dsp_mgr_schedule_tmr, APP_TIMER_MODE_REPEATED, dsp_mgr_schedule_tmr_cb)); + } + // 此处周期决定采样一个页面显示的宽度 + ZERROR_CHECK(app_timer_start(m_dsp_mgr_schedule_tmr, APP_TIMER_TICKS(12), NULL)); + timer_inited = true; +} +void dsp_mgr_uninit(void) { + app_timer_stop(m_dsp_mgr_schedule_tmr); + board_screen_deinit(); +} diff --git a/app/src/bakservice/display_mgr/display_manager.h b/app/src/bakservice/display_mgr/display_manager.h new file mode 100644 index 0000000..0553b77 --- /dev/null +++ b/app/src/bakservice/display_mgr/display_manager.h @@ -0,0 +1,81 @@ +#pragma once + +#include "znordic.h" +// +#include "app_timer.h" +#include "diskio_blkdev.h" +#include "ff.h" +#include "nrf_block_dev_sdc.h" +#include "nrf_delay.h" +#include "nrf_drv_pwm.h" +#include "nrf_drv_saadc.h" +#include "nrf_drv_twi.h" +#include "nrf_drv_wdt.h" +#include "nrf_gpio.h" + +/** + * @brief + * 页面流转 + * + * close <--------------------- + * | + * button ---> welcome ---> main ---> preparePage ---> sampling ---> storaging ---> storagingSuc + * ^ ---> samplingError | + * |-------------------------------------------| | + * |-----------------------------------------------------------| + * + */ + +typedef enum { + kPage_poweroff, + kPage_welcome, + kPage_main, + kPage_preparePage, + kPage_sampling, + kPage_samplingError, + kPage_storaging, + kPage_storagingSuc, + kPage_chargingPage, +} page_t; + +typedef struct { + /** + * @brief 页面状态 + */ + page_t page; // 当前页面 + page_t last_page; // 上一个页面 + uint32_t page_change_to_page_time; // 当前页面持续的时间 + + bool in_prompt; // 是否在提示状态 + char prompt[32]; // 提示内容 + + /** + * @brief + */ + +} PageState_t; + +void dsp_mgr_init(void); +void dsp_mgr_uninit(void); +void dsp_mgr_schedule(void); + +PageState_t* dsp_mgr_get_state(void); +uint32_t dsp_mgr_get_page_elapsed_time_s(void); + +void dsp_mgr_change_to_poweroff(); +void dsp_mgr_change_to_welcome(); +void dsp_mgr_change_to_main(); +void dsp_mgr_change_to_chargingPage(); + +// 保持静止页面 +void dsp_mgr_change_to_preparePage(); +void dsp_mgr_preparePage_set_progress(int progress); +int dsp_mgr_preparePage_get_progress(); + +// 采样中页面 +void dsp_mgr_change_to_sampling(int progress_s, int heartrate); + +// 采样出错页面 +void dsp_mgr_change_to_samplingError(); +// 采样成功页面 +void dsp_mgr_change_to_sampleSuc(); \ No newline at end of file diff --git a/app/src/bakservice/display_mgr/font.h b/app/src/bakservice/display_mgr/font.h new file mode 100644 index 0000000..179ea34 --- /dev/null +++ b/app/src/bakservice/display_mgr/font.h @@ -0,0 +1,275 @@ +// https://www.23bei.com/tool-965.html + +#include +#if 0 +const uint8_t fontclocklib_code[] = { + 0x00, 0x00, 0x00, 0x00, 0x7F, 0x80, 0x01, 0xFF, 0xE0, 0x03, 0xFF, 0xF0, 0x07, 0x80, 0x78, 0x06, // + 0x00, 0x18, 0x04, 0x00, 0x08, 0x06, 0x00, 0x18, 0x07, 0x80, 0x78, 0x03, 0xFF, 0xF0, 0x01, 0xFF, // + 0xE0, 0x00, 0x7F, 0x80, // + 0x00, 0x00, 0x00, 0x02, 0x00, 0x10, 0x02, 0x00, 0x10, 0x02, 0x00, 0x10, 0x07, 0xFF, 0xF0, 0x0F, // + 0xFF, 0xF0, 0x0F, 0xFF, 0xF0, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, // + 0x00, 0x00, 0x00, 0x00, // + 0x03, 0x80, 0x70, 0x07, 0x80, 0xF0, 0x0D, 0x81, 0xB0, 0x08, 0x03, 0x30, 0x08, 0x06, 0x30, 0x08, // + 0x0C, 0x30, 0x0C, 0x38, 0x30, 0x0F, 0xF8, 0x30, 0x07, 0xF1, 0xF0, 0x03, 0xC1, 0xF0, 0x00, 0x00, // + 0x00, 0x00, 0x00, 0x00, // + 0x03, 0x81, 0xC0, 0x07, 0x81, 0xE0, 0x0F, 0x81, 0xF0, 0x08, 0x10, 0x10, 0x08, 0x10, 0x10, 0x0C, // + 0x30, 0x10, 0x0F, 0xF8, 0x30, 0x07, 0xEF, 0xF0, 0x03, 0xCF, 0xE0, 0x00, 0x03, 0xC0, 0x00, 0x00, // + 0x00, 0x00, 0x00, 0x00, // + 0x00, 0x06, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x3A, 0x00, 0x00, 0xE2, 0x00, 0x01, 0xC2, 0x10, 0x07, // + 0x02, 0x10, 0x0F, 0xFF, 0xF0, 0x1F, 0xFF, 0xF0, 0x1F, 0xFF, 0xF0, 0x00, 0x02, 0x10, 0x00, 0x02, // + 0x10, 0x00, 0x00, 0x00, // + 0x00, 0x01, 0xC0, 0x0F, 0xF9, 0xE0, 0x0F, 0xF9, 0xB0, 0x0C, 0x30, 0x10, 0x0C, 0x20, 0x10, 0x0C, // + 0x20, 0x10, 0x0C, 0x30, 0x70, 0x0C, 0x3F, 0xF0, 0x0C, 0x1F, 0xE0, 0x0C, 0x0F, 0x80, 0x00, 0x00, // + 0x00, 0x00, 0x00, 0x00, // + 0x00, 0x7F, 0x00, 0x03, 0xFF, 0xC0, 0x07, 0xFF, 0xE0, 0x07, 0x18, 0x70, 0x0C, 0x30, 0x30, 0x08, // + 0x20, 0x10, 0x08, 0x20, 0x10, 0x0E, 0x30, 0x30, 0x0E, 0x3F, 0xE0, 0x06, 0x1F, 0xE0, 0x00, 0x0F, // + 0x80, 0x00, 0x00, 0x00, // + 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x0F, 0x80, 0x00, 0x0E, 0x00, 0x00, 0x0C, 0x01, 0xF0, 0x0C, // + 0x0F, 0xF0, 0x0C, 0x3F, 0xF0, 0x0D, 0xF0, 0x00, 0x0F, 0xC0, 0x00, 0x0E, 0x00, 0x00, 0x0C, 0x00, // + 0x00, 0x00, 0x00, 0x00, // + 0x03, 0xC3, 0xC0, 0x07, 0xEF, 0xE0, 0x0F, 0xEF, 0xE0, 0x0C, 0x78, 0x30, 0x08, 0x30, 0x10, 0x08, // + 0x38, 0x10, 0x08, 0x18, 0x10, 0x0C, 0x3C, 0x30, 0x0F, 0xEF, 0xF0, 0x07, 0xE7, 0xE0, 0x03, 0x83, // + 0xC0, 0x00, 0x00, 0x00, // + 0x01, 0xF0, 0x00, 0x07, 0xF8, 0x60, 0x07, 0xFC, 0x70, 0x0E, 0x0C, 0x70, 0x08, 0x04, 0x10, 0x08, // + 0x04, 0x10, 0x08, 0x0C, 0x30, 0x0E, 0x19, 0xE0, 0x07, 0xFF, 0xE0, 0x03, 0xFF, 0x80, 0x00, 0xFE, // + 0x00, 0x00, 0x00, 0x00, // + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x70, 0x00, // + 0xE0, 0x70, 0x00, 0xE0, 0x70, 0x00, 0xE0, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // + 0x00, 0x00, 0x00, 0x00, // +}; + +static FontLibrary_t fontclocklib = { + .font = fontclocklib_code, + .fontIndex = "0123456789:", + .fontIndexLen = 12, + .fontCode = kgbk, + .isAscii = true, + .widthPixel = 24, + .heightPixel = 24, +}; +#endif + +// DB 00H 00H 07H F0H 0FH F8H 18H 0CH 10H 04H 18H 0CH 0FH F8H 07H F0H;"0",0 +// DB 10H 08H 10H 08H 3FH F8H 3FH F8H 00H 08H 00H 08H 00H 00H 00H 00H;"1",1 +// DB 1CH 18H 3CH 38H 20H 68H 20H C8H 23H 88H 3FH 18H 1CH 18H 00H 00H;"2",2 +// DB 18H 30H 38H 38H 22H 08H 22H 08H 27H 18H 3DH F0H 18H E0H 00H 00H;"3",3 +// DB 01H C0H 07H C0H 0EH 48H 18H 48H 3FH F8H 3FH F8H 00H 48H 00H 00H;"4",4 +// DB 3FH 30H 3FH 38H 23H 08H 22H 08H 23H 18H 21H F0H 20H E0H 00H 00H;"5",5 +// DB 0FH E0H 1FH F0H 33H 18H 22H 08H 33H 18H 31H F0H 00H E0H 00H 00H;"6",6 +// DB 38H 00H 38H 00H 21H F8H 27H F8H 3EH 00H 38H 00H 20H 00H 00H 00H;"7",7 +// DB 1CH 70H 3EH F8H 23H 88H 21H 08H 23H 88H 3EH F8H 1CH 70H 00H 00H;"8",8 +// DB 0EH 00H 1FH 18H 31H 98H 20H 88H 31H 98H 1FH F0H 0FH E0H 00H 00H;"9",9 +// DB 00H 00H 00H 00H 06H 18H 06H 18H 06H 18H 00H 00H 00H 00H 00H 00H;":",10 + +#if 0 +//32*32 +const uint8_t fontclocklib_code[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x40, 0x40, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFE, 0xFF, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0xFF, 0xFE, 0xF0, + 0x00, 0x00, 0x1F, 0xFF, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x06, 0x04, 0x04, 0x06, 0x07, 0x03, 0x01, 0x00, 0x00, /*"0",0*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x06, 0x07, 0x07, 0x07, 0x06, 0x04, 0x04, 0x04, 0x00, 0x00, /*"1",1*/ + 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0x40, 0x40, 0x40, 0x40, 0xC0, 0xC0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x1F, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC1, 0xFF, 0x7F, 0x3E, 0x00, + 0x00, 0x00, 0x00, 0x80, 0xC0, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x01, 0x00, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x07, 0x07, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x07, 0x07, 0x01, 0x00, /*"2",2*/ + 0x00, 0x00, 0x00, 0x80, 0x80, 0xC0, 0x40, 0x40, 0x40, 0xC0, 0xC0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x80, 0x80, 0x80, 0xC0, 0xE1, 0x7F, 0x3F, 0x1E, 0x00, 0x00, + 0x00, 0x00, 0xE0, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0xFF, 0xFE, 0x78, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x06, 0x04, 0x04, 0x04, 0x04, 0x06, 0x03, 0x03, 0x01, 0x00, 0x00, /*"3",3*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x70, 0x3C, 0x0E, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, + 0x00, 0x10, 0x1C, 0x1E, 0x13, 0x11, 0x10, 0x10, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x0F, 0x0F, 0x0F, 0x0F, 0x08, 0x08, 0x08, /*"4",4*/ + 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF, 0xC7, 0x60, 0x20, 0x20, 0x20, 0x60, 0xE0, 0xC0, 0x80, 0x00, 0x00, + 0x00, 0x00, 0xE0, 0xE1, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x7E, 0x00, 0x00, 0x00, 0x01, 0x03, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, 0x06, 0x03, 0x03, 0x01, 0x00, 0x00, /*"5",5*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x40, 0x40, 0x40, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFC, 0xFE, 0x8F, 0x81, 0xC0, 0x40, 0x40, 0x40, 0xC0, 0xC3, 0x83, 0x03, 0x00, + 0x00, 0x00, 0x3F, 0xFF, 0xFF, 0xC3, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x06, 0x04, 0x04, 0x04, 0x06, 0x03, 0x03, 0x01, 0x00, /*"6",6*/ + 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x03, 0x01, 0x00, 0x00, 0x80, 0xE0, 0x78, 0x1E, 0x07, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFC, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"7",7*/ + 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x40, 0x40, 0x40, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x3F, 0x7F, 0xF1, 0xE0, 0xC0, 0x80, 0x80, 0x80, 0xE1, 0x7F, 0x3F, 0x1E, 0x00, + 0x00, 0xF8, 0xFC, 0xFE, 0x07, 0x03, 0x01, 0x01, 0x01, 0x03, 0x07, 0x0F, 0xFE, 0xFC, 0xF8, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x06, 0x04, 0x04, 0x04, 0x04, 0x06, 0x03, 0x03, 0x01, 0x00, 0x00, /*"8",8*/ + 0x00, 0x00, 0x00, 0x80, 0x80, 0xC0, 0x40, 0x40, 0x40, 0x40, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0xFF, 0xFE, 0xF8, 0x00, + 0x00, 0x00, 0x81, 0x83, 0x87, 0x06, 0x04, 0x04, 0x04, 0x06, 0x83, 0xF3, 0xFF, 0x7F, 0x0F, 0x00, 0x00, 0x00, 0x03, 0x03, 0x07, 0x04, 0x04, 0x04, 0x06, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, /*"9",9*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xE0, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x81, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x07, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, /*":",10*/ +}; +static FontLibrary_t fontclocklib = { + .font = fontclocklib_code, + .fontIndex = "0123456789:", + .fontIndexLen = 12, + .fontCode = kgbk, + .isAscii = true, + .widthPixel = 16, + .heightPixel = 32, +}; +#endif + +// 24*24 +const uint8_t fontclocklib_code[] = { + + 0x00, 0x00, 0x80, 0xC0, 0xE0, 0x60, 0x20, 0x60, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFE, 0x00, 0x01, 0x07, 0x0F, 0x1E, 0x18, 0x10, 0x18, 0x1E, 0x0F, 0x07, 0x01, /*"0",0*/ + 0x00, 0x00, 0x80, 0x80, 0x80, 0xC0, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x1F, 0x1F, 0x1F, 0x10, 0x10, 0x10, 0x00, /*"1",1*/ + 0x00, 0x80, 0xC0, 0x60, 0x20, 0x20, 0x20, 0x60, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x03, 0x03, 0x03, 0x80, 0xC0, 0x60, 0x38, 0x3F, 0x1F, 0x07, 0x00, 0x00, 0x1C, 0x1E, 0x1B, 0x19, 0x18, 0x18, 0x18, 0x18, 0x1F, 0x1F, 0x00, /*"2",2*/ + 0x00, 0x80, 0xC0, 0xE0, 0x20, 0x20, 0x60, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x10, 0x10, 0x18, 0x3F, 0xEF, 0xE7, 0x80, 0x00, 0x00, 0x07, 0x0F, 0x1F, 0x10, 0x10, 0x10, 0x18, 0x1F, 0x0F, 0x07, 0x00, /*"3",3*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0xC0, 0xF0, 0xB8, 0x8E, 0x87, 0x81, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x1F, 0x1F, 0x1F, 0x10, 0x10, /*"4",4*/ + 0x00, 0x00, 0xE0, 0xE0, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, 0x00, 0x00, 0x3F, 0x3F, 0x18, 0x08, 0x08, 0x18, 0xF8, 0xF0, 0xE0, 0x00, 0x00, 0x07, 0x0F, 0x1B, 0x10, 0x10, 0x10, 0x1C, 0x1F, 0x0F, 0x03, 0x00, /*"5",5*/ + 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x60, 0x20, 0x20, 0xE0, 0xE0, 0xC0, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x31, 0x18, 0x08, 0x08, 0x18, 0xF8, 0xF0, 0xE0, 0x00, 0x01, 0x07, 0x0F, 0x1C, 0x18, 0x10, 0x10, 0x18, 0x0F, 0x0F, 0x03, /*"6",6*/ + 0x00, 0x00, 0xC0, 0xE0, 0xE0, 0x60, 0x60, 0x60, 0x60, 0xE0, 0xE0, 0x60, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0xE0, 0xF8, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x00, /*"7",7*/ + 0x00, 0x80, 0xC0, 0xE0, 0x60, 0x20, 0x20, 0x20, 0x60, 0xE0, 0xC0, 0x80, 0x00, 0x87, 0xEF, 0xEF, 0x3C, 0x18, 0x38, 0x30, 0x78, 0xEF, 0xCF, 0x83, 0x00, 0x07, 0x0F, 0x0F, 0x18, 0x10, 0x10, 0x10, 0x18, 0x1F, 0x0F, 0x07, /*"8",8*/ + 0x00, 0x00, 0xC0, 0xC0, 0xE0, 0x20, 0x20, 0x20, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x1F, 0x3F, 0x7F, 0x60, 0x40, 0x40, 0x60, 0x30, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x0C, 0x1C, 0x1C, 0x10, 0x10, 0x18, 0x0F, 0x0F, 0x03, 0x00, /*"9",9*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x0E, 0x0E, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x1C, 0x1C, 0x1C, 0x00, 0x00, 0x00, /*":",10*/ + +}; +static FontLibrary_t fontclocklib = { + .font = fontclocklib_code, + .fontIndex = "0123456789:", + .fontIndexLen = 12, + .fontCode = kgbk, + .isAscii = true, + .widthPixel = 12, + .heightPixel = 24, +}; + +const uint8_t font8x8_xo_code[] = { + 0x00, 0x3C, 0x7E, 0x7E, 0x7E, 0x7E, 0x3C, 0x00, /*实心圆,代表完成*/ + 0x00, 0x3C, 0x42, 0x42, 0x42, 0x42, 0x3C, 0x00, /*空心圆,代表未完成*/ + +}; + +static FontLibrary_t font8x8_xo_lib = { + .font = font8x8_xo_code, + .fontIndex = "ox", + .fontIndexLen = 2, + .fontCode = kgbk, + .isAscii = true, + .widthPixel = 8, + .heightPixel = 8, +}; + +const uint8_t font12x24_asiic_code[] = { + + 0x00, 0x00, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x60, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFE, 0x00, 0x00, 0x01, 0x07, 0x0E, 0x0C, 0x18, 0x18, 0x0C, 0x0F, 0x07, 0x00, 0x00, /*"0",0*/ + 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, /*"1",1*/ + 0x00, 0x80, 0xE0, 0x60, 0x30, 0x30, 0x30, 0x70, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x80, 0xC0, 0xE0, 0x38, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x08, 0x0E, 0x0F, 0x0B, 0x09, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, /*"2",2*/ + 0x00, 0x80, 0xC0, 0x60, 0x30, 0x30, 0x30, 0x30, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x18, 0x18, 0x38, 0x7F, 0xE7, 0x80, 0x00, 0x00, 0x03, 0x07, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x0E, 0x07, 0x01, 0x00, /*"3",3*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xF0, 0xB8, 0x8E, 0x87, 0x81, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x0F, 0x0F, 0x01, 0x01, 0x01, /*"4",4*/ + 0x00, 0x00, 0xE0, 0xE0, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x1C, 0x1F, 0x0D, 0x04, 0x04, 0x0C, 0x0C, 0x3C, 0xF8, 0xC0, 0x00, 0x01, 0x07, 0x0E, 0x08, 0x18, 0x18, 0x18, 0x0C, 0x0F, 0x07, 0x00, 0x00, /*"5",5*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF0, 0x30, 0x10, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xF8, 0x1E, 0x0F, 0x0D, 0x0C, 0x0C, 0x18, 0xF8, 0xF0, 0x00, 0x00, 0x03, 0x07, 0x0C, 0x18, 0x18, 0x18, 0x18, 0x0C, 0x0F, 0x03, 0x00, /*"6",6*/ + 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xA0, 0xE0, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xF8, 0x1E, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"7",7*/ + 0x00, 0x80, 0xE0, 0x60, 0x30, 0x30, 0x30, 0x20, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0xE3, 0xFF, 0x3C, 0x18, 0x18, 0x18, 0x3C, 0x3F, 0xE7, 0xC0, 0x00, 0x00, 0x07, 0x0F, 0x0C, 0x18, 0x18, 0x18, 0x18, 0x0C, 0x07, 0x03, 0x00, /*"8",8*/ + 0x00, 0xC0, 0xE0, 0x60, 0x30, 0x30, 0x30, 0x60, 0xE0, 0xC0, 0x00, 0x00, 0x02, 0x1F, 0x3D, 0x30, 0x60, 0x60, 0xE0, 0xF0, 0x7F, 0x1F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10, 0x1C, 0x0F, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, /*"9",9*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x0C, 0x1C, 0xF0, 0xE0, 0xE0, 0x38, 0x1C, 0x04, 0x00, 0x00, 0x00, 0x10, 0x1C, 0x0E, 0x03, 0x01, 0x03, 0x07, 0x0E, 0x18, 0x10, 0x00, /*"x",10*/ + 0x00, 0x30, 0xF0, 0xE0, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x70, 0x10, 0x00, 0x00, 0x00, 0x00, 0x83, 0xEF, 0x7C, 0x7E, 0xE7, 0x81, 0x00, 0x00, 0x00, 0x10, 0x1C, 0x1F, 0x07, 0x01, 0x00, 0x00, 0x01, 0x0F, 0x1E, 0x18, 0x00, /*"X",11*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, /*"[",12*/ + 0x00, 0x0C, 0x0C, 0x0C, 0x0C, 0xFC, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x60, 0x60, 0x7F, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, + /*"]",13*/}; + +static FontLibrary_t font12x24_asiic_lib = { + .font = font12x24_asiic_code, + .fontIndex = "0123456789xX[]", + .fontIndexLen = 15, + .fontCode = kgbk, + .isAscii = true, + .widthPixel = 12, + .heightPixel = 24, +}; + +const uint8_t font24x24_zh_code[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xF8, 0x38, 0x10, 0x10, 0xF0, 0x90, 0x10, 0x10, 0x10, 0x88, 0xF8, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x10, 0x0C, 0x06, 0xE7, 0x1C, 0x10, 0x10, 0x10, 0x10, 0x93, + 0x71, 0xFF, 0x39, 0x49, 0x89, 0x08, 0x08, 0x0C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x04, 0x02, 0x01, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x03, 0x07, 0x06, 0x06, 0x04, 0x04, 0x00, /*"保",0*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFC, 0xFC, 0xC0, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xC2, 0x63, 0x33, 0xFF, 0x0D, 0x09, 0x08, 0x48, + 0x48, 0x49, 0x48, 0x47, 0x4F, 0xFC, 0x24, 0x24, 0x26, 0x06, 0x04, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x08, 0x38, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x20, 0x60, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"持",1*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0xFC, 0x20, 0xA0, 0x20, 0x00, 0x80, 0x60, 0x3C, 0x2C, 0xA0, 0x70, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x0C, 0x94, 0x75, 0x55, 0x57, 0x15, 0xF4, 0x02, 0x90, + 0x92, 0x92, 0x92, 0xFF, 0x92, 0x8A, 0x49, 0x3F, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0F, 0x02, 0x01, 0x09, 0x18, 0x0F, 0x00, 0x00, 0x00, 0x20, 0x60, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"静",2*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xF8, 0x00, 0x00, 0x00, + 0xFF, 0x0F, 0x08, 0x08, 0x08, 0x0C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x18, 0x08, 0x08, 0x08, 0x0F, 0x08, 0x08, 0x0C, 0x0F, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, /*"止",3*/ + 0x00, 0x00, 0x00, 0x00, 0x40, 0x60, 0x60, 0x60, 0x20, 0x20, 0x20, 0x20, 0xA0, 0xE0, 0x30, 0x30, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0x60, 0x30, 0x0D, 0xFF, + 0x03, 0x00, 0x00, 0x10, 0x20, 0x60, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, /*"不",4*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xE0, 0x20, 0x20, 0x10, 0x10, 0x10, 0xF8, 0xF8, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x70, 0x61, 0x87, 0x82, 0x06, 0xFE, + 0x12, 0x11, 0x11, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x04, 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x02, 0x06, 0x0C, 0x0C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x10, 0x00, 0x00, /*"足",5*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0xE0, 0x30, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0xC4, 0x64, 0x1A, 0xFF, 0x12, 0x32, 0x00, 0x18, + 0x0F, 0x00, 0x00, 0x1F, 0x80, 0xE0, 0x3C, 0x08, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x40, 0x20, 0x30, 0x18, 0x0C, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"秒",6*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x20, 0x20, 0x38, 0xF8, 0x20, 0x20, 0x20, 0x60, 0x9C, 0x24, 0x10, 0x10, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x67, 0x7E, 0x00, + 0x10, 0x8C, 0x9B, 0xB9, 0xE4, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x23, 0x3F, 0x11, 0x13, 0x1D, 0x11, 0x1D, 0x17, 0x10, 0x18, 0x1F, 0x11, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, /*"蓝",7*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x10, 0x10, 0x10, 0x10, 0x10, 0xF0, 0x18, 0x18, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0F, 0x04, 0x84, 0x64, 0x34, 0x1E, + 0x06, 0xFF, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x02, 0x01, 0x00, 0x00, 0x10, 0x20, 0x70, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"牙",8*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x10, 0xF0, 0x70, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x0E, 0x08, 0x08, 0x08, 0x04, 0x04, 0x07, + 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x08, 0x08, 0x18, 0x18, 0x18, 0x10, 0x18, 0x18, 0x18, 0x18, 0x08, 0x08, 0x0C, 0x0E, 0x07, 0x00, 0x00, 0x00, /*"已",9*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x30, 0x10, 0xC0, 0xC0, 0x00, 0x00, 0x40, 0x20, 0x20, 0xA0, 0xF0, 0x30, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x67, 0x74, 0x2C, 0x26, 0x01, 0x00, 0x10, 0x50, + 0x48, 0x44, 0xC3, 0xC3, 0x62, 0x24, 0x2C, 0x0C, 0x18, 0x10, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x06, 0x02, 0x02, 0x01, 0x10, 0x18, 0x08, 0x08, 0x08, 0x0F, 0x0B, 0x08, 0x08, 0x08, 0x0C, 0x0C, 0x08, 0x00, 0x00, /*"经",10*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xC0, 0x00, 0x00, 0x40, 0x40, 0xC0, 0xE0, 0x5C, 0x2C, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x08, 0xF8, 0x08, 0x00, 0x40, 0x48, 0x4E, 0x4B, + 0x44, 0x45, 0xFF, 0x24, 0x24, 0x24, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0C, 0x04, 0x07, 0x04, 0x04, 0x08, 0x08, 0x08, 0x08, 0x10, 0x10, 0x17, 0x30, 0x30, 0x30, 0x30, 0x30, 0x10, 0x10, 0x00, 0x00, /*"连",11*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x88, 0x98, 0xD0, 0xC0, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x82, 0xC2, 0x62, 0xFF, 0x11, 0x91, 0x80, 0x80, 0x90, + 0x92, 0xF4, 0xB0, 0x98, 0x97, 0x89, 0x48, 0x48, 0x48, 0x40, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x18, 0x3F, 0x0F, 0x00, 0x00, 0x20, 0x20, 0x13, 0x12, 0x0C, 0x06, 0x0F, 0x08, 0x18, 0x30, 0x20, 0x00, 0x00, 0x00, /*"接",12*/ + 0x00, 0x00, 0x00, 0xE0, 0x40, 0x40, 0x80, 0x00, 0xF8, 0x88, 0x40, 0x20, 0x00, 0x80, 0x80, 0x40, 0x40, 0x20, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x80, 0x40, 0x25, 0x1A, 0xFF, 0x12, 0x12, 0x12, + 0x00, 0xE0, 0x3F, 0x08, 0x04, 0xFC, 0xFC, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x04, 0x02, 0x02, 0x02, 0x03, 0x02, 0x12, 0x08, 0x06, 0x01, 0x00, 0x00, 0x00, 0x7F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, /*"断",13*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x60, 0x60, 0xE0, 0x20, 0x20, 0x20, 0x20, 0xF0, 0x30, 0x30, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0xE8, 0x3F, 0x08, 0x08, + 0x04, 0x04, 0xFF, 0x04, 0x04, 0x04, 0x04, 0x04, 0x06, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x08, 0x04, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"开",14*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9C, 0xF8, 0x80, 0x80, 0x80, 0x80, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x7F, 0x81, 0x89, 0x49, 0xC8, 0xFF, 0x4C, + 0x44, 0x44, 0x40, 0x3C, 0x0F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0F, 0x18, 0x10, 0x10, 0x30, 0x30, 0x30, 0x10, 0x10, 0x1A, 0x1C, 0x00, 0x00, 0x00, /*"电",15*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x78, 0xA8, 0xA8, 0xA8, 0xA8, 0x88, 0xE4, 0x7C, 0x18, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x14, 0xF4, 0x94, 0x14, 0x52, 0xF2, + 0xAA, 0xAA, 0x8A, 0xFA, 0x3A, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x24, 0x25, 0x25, 0x25, 0x3F, 0x24, 0x24, 0x27, 0x30, 0x30, 0x30, 0x30, 0x20, 0x00, 0x00, 0x00, 0x00, /*"量",16*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0xC0, 0xC6, 0xFC, 0xA0, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x10, 0x08, 0x24, 0xE6, 0xA3, 0xA1, 0x94, 0xAF, + 0x10, 0x11, 0xF3, 0xF6, 0x2C, 0x0C, 0x18, 0x18, 0x18, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x21, 0x27, 0x24, 0x24, 0x34, 0x12, 0x16, 0x13, 0x10, 0x10, 0x10, 0x10, 0x30, 0x00, 0x00, 0x00, 0x00, /*"查",17*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x90, 0x90, 0xF0, 0xB8, 0x88, 0x8C, 0xCC, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0xC8, 0x78, 0xFC, 0xA7, 0xA4, + 0xA4, 0xA4, 0x14, 0x14, 0xF2, 0x22, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x10, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00, 0x00, 0x3F, 0x14, 0x14, 0x14, 0x12, 0x10, 0x30, 0x7F, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"看",18*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x60, 0x38, 0x10, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x38, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xC6, 0x65, 0x3C, 0x2C, 0x23, 0x01, 0x80, 0x02, + 0x22, 0x22, 0x22, 0x22, 0x3F, 0x91, 0x91, 0x91, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x04, 0x0C, 0x04, 0x06, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x03, 0x1F, 0x09, 0x09, 0x09, 0x08, 0x08, 0x0F, 0x01, 0x00, 0x00, 0x00, /*"结",19*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x30, 0xF0, 0x10, 0x90, 0x90, 0xF0, 0xF0, 0xD0, 0x10, 0x88, 0xF8, 0x78, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x60, 0x21, 0x27, 0xA4, 0x64, 0xFF, + 0x52, 0x92, 0x12, 0x13, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x10, 0x08, 0x04, 0x06, 0x03, 0x01, 0x00, 0x7F, 0x00, 0x00, 0x01, 0x02, 0x06, 0x0C, 0x18, 0x18, 0x18, 0x10, 0x00, 0x00, /*"果",20*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0xD0, 0x90, 0x18, 0x0C, 0x88, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x60, 0x20, 0x20, 0x20, 0x22, 0x22, 0x33, 0x11, + 0xFF, 0x11, 0x11, 0x11, 0x11, 0x10, 0x18, 0x18, 0x18, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x20, 0x60, 0x78, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"手",21*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x86, 0xC2, 0x32, 0x0F, 0xFF, 0x21, 0x61, 0x01, 0x01, + 0xFF, 0x01, 0x01, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x04, 0x02, 0x01, 0x00, 0x00, 0x3F, 0x0F, 0x00, 0x08, 0x04, 0x03, 0x01, 0x00, 0x00, 0x00, 0x07, 0x06, 0x0C, 0x0C, 0x0C, 0x0F, 0x06, 0x00, /*"机",22*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x20, 0x20, 0x50, 0xD0, 0x88, 0x0C, 0x8C, 0x40, 0x70, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x11, 0xD0, 0x70, 0x32, 0xFC, 0x30, + 0x48, 0x88, 0x88, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x04, 0x02, 0x01, 0x00, 0x00, 0x30, 0x7F, 0x00, 0x00, 0x00, 0x01, 0x03, 0x06, 0x06, 0x0C, 0x0C, 0x04, 0x08, 0x00, 0x00, /*"采",23*/ + 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0xF0, 0x0C, 0x24, 0xA0, 0xA4, 0xEC, 0xE8, 0x90, 0x50, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xBF, 0x90, 0x90, 0xD2, 0xF2, + 0xCF, 0x4B, 0x4A, 0x49, 0x48, 0x48, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x10, 0x10, 0x08, 0x04, 0x06, 0x03, 0x01, 0x7F, 0x00, 0x01, 0x02, 0x04, 0x0C, 0x18, 0x18, 0x18, 0x10, 0x10, 0x00, 0x00, /*"集",24*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x7C, 0xC0, 0x80, 0x80, 0x88, 0x98, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xFE, 0x42, 0x42, 0x22, 0x22, 0xE1, 0x21, + 0x03, 0x1F, 0x70, 0x80, 0xE0, 0x3C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x08, 0x06, 0x03, 0x00, 0x04, 0x08, 0x1C, 0x07, 0x00, 0x08, 0x04, 0x02, 0x01, 0x07, 0x0C, 0x18, 0x30, 0x70, 0x78, 0x00, 0x00, /*"成",25*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x81, 0x81, 0xC1, 0x7F, 0x20, 0x20, 0x20, 0x12, + 0x82, 0xE2, 0x3E, 0x07, 0x02, 0x01, 0x01, 0xFF, 0x0F, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x10, 0x10, 0x08, 0x04, 0x03, 0x01, 0x00, 0x04, 0x08, 0x38, 0x1C, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x00, /*"功",26*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x80, 0x80, 0x40, 0x48, 0x58, 0x50, 0x40, 0x20, 0x20, 0xA0, 0xE0, 0xC0, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x01, 0x40, 0x60, 0x24, 0xE4, 0x26, 0x22, + 0xF2, 0x12, 0x10, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x08, 0x04, 0x06, 0x03, 0x00, 0x00, 0x00, 0x1F, 0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x30, 0x3E, 0x10, 0x00, 0x00, /*"完",27*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x78, 0x10, 0x00, 0x80, 0x80, 0x40, 0x40, 0xA0, 0x38, 0x18, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x18, 0x0C, 0x03, 0xFD, 0x00, 0x00, 0x00, 0xE1, 0xFF, + 0x10, 0x88, 0x0F, 0x3C, 0xE4, 0x84, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x1F, 0x00, 0x00, 0x04, 0x0F, 0x03, 0x01, 0x00, 0x04, 0x0C, 0x00, 0x01, 0x06, 0x0C, 0x18, 0x3E, 0x30, 0x00, /*"低",28*/ +}; +static FontLibrary_t font24x24_zh_lib = { + .font = font24x24_zh_code, + .fontIndex = "保持静止不足秒蓝牙已经连接断开电量查看结果手机采集成功完低", + .fontIndexLen = 88, + .fontCode = kgbk, + .isAscii = false, + .widthPixel = 24, + .heightPixel = 24, +}; + +#if 0 +// const unsigned char gImage_heart_16x16[] = { +// /* 0X22,0X01,0X10,0X00,0X10,0X00, */ +// 0X00, 0XF8, 0XFC, 0XFE, 0XFE, 0XFE, 0XFE, 0XFC, 0XFC, 0XFE, 0XFE, 0XFE, 0XFE, 0XFC, 0XF8, 0X00, 0X00, 0X00, 0X03, 0X07, 0X0F, 0X1F, 0X3F, 0X7F, 0X7F, 0X3F, 0X1F, 0X0F, 0X07, 0X03, 0X00, 0X00, +// }; +#endif + +const unsigned char font_asicc_code_16x8[] = { + 0x00, 0xF0, 0x18, 0x08, 0x08, 0x18, 0xE0, 0x00, 0x00, 0x0F, 0x10, 0x20, 0x30, 0x18, 0x0F, 0x00, /*"0",0*/ + 0x00, 0x60, 0x20, 0xF0, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x3F, 0x00, 0x00, 0x00, /*"1",1*/ + 0x00, 0x30, 0x18, 0x08, 0x08, 0xD8, 0x70, 0x00, 0x00, 0x30, 0x38, 0x34, 0x33, 0x31, 0x30, 0x00, /*"2",2*/ + 0x00, 0x30, 0x18, 0x08, 0x88, 0xD8, 0x70, 0x00, 0x00, 0x18, 0x10, 0x20, 0x21, 0x13, 0x0E, 0x00, /*"3",3*/ + 0x00, 0x00, 0x80, 0x60, 0x30, 0xF8, 0x00, 0x00, 0x04, 0x07, 0x05, 0x04, 0x04, 0x3F, 0x04, 0x04, /*"4",4*/ + 0x00, 0xF0, 0x98, 0xC8, 0x88, 0x88, 0x08, 0x00, 0x08, 0x19, 0x30, 0x20, 0x30, 0x19, 0x0F, 0x00, /*"5",5*/ + 0x00, 0x80, 0xC0, 0xF0, 0x98, 0x80, 0x00, 0x00, 0x00, 0x1F, 0x31, 0x20, 0x20, 0x30, 0x1F, 0x06, /*"6",6*/ + 0x00, 0x08, 0x08, 0x08, 0x88, 0xE8, 0x38, 0x00, 0x00, 0x00, 0x30, 0x3E, 0x03, 0x00, 0x00, 0x00, /*"7",7*/ + 0x00, 0xF0, 0x88, 0x88, 0x88, 0xD8, 0x70, 0x00, 0x04, 0x1F, 0x31, 0x21, 0x21, 0x31, 0x1E, 0x00, /*"8",8*/ + 0xE0, 0xF0, 0x08, 0x08, 0x08, 0x98, 0xF0, 0x00, 0x00, 0x01, 0x23, 0x3A, 0x0F, 0x03, 0x00, 0x00, /*"9",9*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, /*"-",10*/ + 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0x11, 0x00, 0x00, 0x00, /*":",10*/ + + 0X00, 0XF8, 0XFC, 0XFE, 0XFE, 0XFE, 0XFE, 0XFC, 0X00, 0X00, 0X03, 0X07, 0X0F, 0X1F, 0X3F, 0X7F, /*?右半*/ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*" "*/ +}; + +static FontLibrary_t font_asicc16x8_lib = { + .font = font_asicc_code_16x8, + .fontIndex = "0123456789-:<> ", // <> 这两个符号是心形的左右半边 + .fontIndexLen = 16, + .fontCode = kgbk, + .isAscii = true, + .widthPixel = 8, + .heightPixel = 16, +}; diff --git a/app/src/bakservice/heart_wave_sample_service/heart_ware_sample_data_mgr.c b/app/src/bakservice/heart_wave_sample_service/heart_ware_sample_data_mgr.c new file mode 100644 index 0000000..ecf7ab1 --- /dev/null +++ b/app/src/bakservice/heart_wave_sample_service/heart_ware_sample_data_mgr.c @@ -0,0 +1,107 @@ +#include "basic_service/app_event.h" +#include "basic_service/app_event_distribute.h" +#include "board/board_ecg_sensor.h" +#include "nrfx_timer.h" + +static uint32_t m_frame_index = 0; // 帧绝对序号 +/*********************************************************************************************************************** + * ab buffer * + ***********************************************************************************************************************/ +#define FRAME_BUFFER_SIZE (256 / sizeof(one_frame_t)) + +static one_frame_t m_capture_buffer_a[FRAME_BUFFER_SIZE]; +static one_frame_t m_capture_buffer_b[FRAME_BUFFER_SIZE]; +static one_frame_t* m_capture_buffer; +static one_frame_t m_capture_buffer_index = 0; + +static void eeprom_cache_buffer_swap() { + if (m_capture_buffer == NULL) { + m_capture_buffer = m_capture_buffer_a; + m_capture_buffer_index = 0; + return; + } + + if (m_capture_buffer == m_capture_buffer_a) { + m_capture_buffer = m_capture_buffer_b; + } else { + m_capture_buffer = m_capture_buffer_a; + } + m_capture_buffer_index = 0; + return; +} + +/*********************************************************************************************************************** + * littlebuffer * + ***********************************************************************************************************************/ +static one_frame_t m_prepare_data_cache[LITTLE_DATA_BLOCK_FRAME_NUM]; +static uint32_t m_prepare_data_cache_index; + +static inline void preview_data_cache_push_data(one_frame_t data) { + if (m_prepare_data_cache_index >= LITTLE_DATA_BLOCK_FRAME_NUM) { + return; + } + m_prepare_data_cache[m_prepare_data_cache_index] = data; + m_prepare_data_cache_index++; +} + +static inline bool preview_data_cache_is_full(void) { + if (m_prepare_data_cache_index >= LITTLE_DATA_BLOCK_FRAME_NUM) { + return true; + } + return false; +} +static inline void preview_data_cache_clear(void) { m_prepare_data_cache_index = 0; } +static inline void preview_data_trigger_event() { + static app_event_t event; + event.eventType = kevent_capture_little_data_block_event; + for (uint32_t i = 0; i < LITTLE_DATA_BLOCK_FRAME_NUM; i++) { + event.val.little_data_block.data[i] = m_prepare_data_cache[i]; + } + event.val.little_data_block.timestamp = znordic_getpower_on_ms(); + event.val.little_data_block.frameIndex = m_frame_index - LITTLE_DATA_BLOCK_FRAME_NUM; + AppEvent_pushEvent(&event); +} + +/*********************************************************************************************************************** + * EXT * + ***********************************************************************************************************************/ + +void hwsd_mgr_push_one_frame(one_frame_t data) { + m_frame_index++; + + /*********************************************************************************************************************** + * EEPROM数据采样存储 * + ***********************************************************************************************************************/ + if (m_capture_buffer == NULL) eeprom_cache_buffer_swap(); + + if (m_capture_buffer_index < FRAME_BUFFER_SIZE) { + m_capture_buffer[m_capture_buffer_index++] = data; + } + + if (m_capture_buffer_index == FRAME_BUFFER_SIZE) { + app_event_t evt; + evt.eventType = kevent_capture_256data_event; + evt.val.capture_data_cache = (uint8_t*)m_capture_buffer; + eeprom_cache_buffer_swap(); + AppEvent_pushEvent(&evt); + } + + /******************************************************************************* + * 实时采样数据事件上报 * + *******************************************************************************/ + /** + * @brief 缓存数据,并触发小数据块事件 + */ + preview_data_cache_push_data(data); + if (preview_data_cache_is_full()) { + preview_data_trigger_event(); + preview_data_cache_clear(); + } +} + +void hwsd_mgr_reset_buffer(){ + m_frame_index = 0; + m_capture_buffer = NULL; + m_capture_buffer_index = 0; + preview_data_cache_clear(); +} diff --git a/app/src/bakservice/heart_wave_sample_service/heart_ware_sample_data_mgr.h b/app/src/bakservice/heart_wave_sample_service/heart_ware_sample_data_mgr.h new file mode 100644 index 0000000..71c04f3 --- /dev/null +++ b/app/src/bakservice/heart_wave_sample_service/heart_ware_sample_data_mgr.h @@ -0,0 +1,9 @@ +#pragma once +#include + +#include "basic_service/app_event.h" +#include "basic_service/app_event_distribute.h" +#include "nrfx_timer.h" + +void hwsd_mgr_push_one_frame(one_frame_t data); +void hwsd_mgr_reset_buffer(); \ No newline at end of file diff --git a/app/src/bakservice/heart_wave_sample_service/heart_wave_sample_data_pre_process.c b/app/src/bakservice/heart_wave_sample_service/heart_wave_sample_data_pre_process.c new file mode 100644 index 0000000..39d3fbc --- /dev/null +++ b/app/src/bakservice/heart_wave_sample_service/heart_wave_sample_data_pre_process.c @@ -0,0 +1,12 @@ +#include "heart_wave_sample_data_pre_process.h" +static one_frame_t m_datacache; +static one_frame_t m_displaydata; + +void hwsd_pre_processer_init() {} +void hwsd_pre_processer_process(one_frame_t framdata) { // + m_datacache = framdata; + m_displaydata = framdata; +} + +one_frame_t hwsd_pre_processer_get_display_data() { return m_displaydata; } +one_frame_t hwsd_pre_processer_get_storage_data() { return m_datacache; } diff --git a/app/src/bakservice/heart_wave_sample_service/heart_wave_sample_data_pre_process.h b/app/src/bakservice/heart_wave_sample_service/heart_wave_sample_data_pre_process.h new file mode 100644 index 0000000..a188a77 --- /dev/null +++ b/app/src/bakservice/heart_wave_sample_service/heart_wave_sample_data_pre_process.h @@ -0,0 +1,9 @@ +#pragma once +#include + +#include "basic_service/app_event.h" + +void hwsd_pre_processer_init(); +void hwsd_pre_processer_process(one_frame_t framdata); +one_frame_t hwsd_pre_processer_get_display_data(); +one_frame_t hwsd_pre_processer_get_storage_data(); diff --git a/app/src/bakservice/heart_wave_sample_service/heart_wave_sample_service.c b/app/src/bakservice/heart_wave_sample_service/heart_wave_sample_service.c new file mode 100644 index 0000000..41b0742 --- /dev/null +++ b/app/src/bakservice/heart_wave_sample_service/heart_wave_sample_service.c @@ -0,0 +1,77 @@ +#include "heart_wave_sample_service.h" + +#include "basic_service/app_event.h" +#include "basic_service/app_event_distribute.h" +#include "board/ads129x/ads129x.h" +#include "board/app_board.h" +#include "board/board_ecg_sensor.h" +#include "heart_ware_sample_data_mgr.h" +#include "heart_wave_sample_data_pre_process.h" +#include "nrfx_timer.h" + +typedef enum { + kidle, + kprepare, + kcapture, +} capture_state_t; + +static capture_state_t m_prepare_capture_state = kidle; +static uint32_t m_start_capture_tp; + +/** + * @brief 处理ads129x数据,并上报 + * + * @param event + */ +static void on_ads129x_ready_irq(app_board_irq_event_t event) { +#if 1 + static ads129x_capture_data_t capture_data; + ads129x_read_data(&capture_data); + hwsd_mgr_push_one_frame(capture_data.ch1data); +#else + static int32_t data; + data += 1000; + if (data >= 60000) { + data = -60000; + } + hwsd_mgr_push_one_frame(data); +#endif +} + +void hwss_init(void) { // + app_board_reg_irq_listener(kon_irq_ads1291_ready_pin, on_ads129x_ready_irq); +} + +void hwss_start_prepare_capture(void) { + m_start_capture_tp = znordic_getpower_on_s(); + m_prepare_capture_state = kprepare; + hwsd_pre_processer_init(); + hwsd_mgr_reset_buffer(); + + ads129x_start_capture(false); +} +void hwss_start_capture(void) { + m_start_capture_tp = znordic_getpower_on_s(); + m_prepare_capture_state = kcapture; +} +void hwss_stop_capture(void) { + m_prepare_capture_state = kidle; + hwsd_mgr_reset_buffer(); + ads129x_stop_capture(); +} + +float hwss_read_val(void) { + __disable_irq(); + float val = hwsd_pre_processer_get_display_data(); + __enable_irq(); + return val; +} +float hwss_read_heart_rate(void) { // + return 0; +} +int hwss_has_captured_time_ms() { return (znordic_getpower_on_s() - m_start_capture_tp) * 1000; } + +bool hwss_lead_get_state_connected_state() { return true; } + +void hwss_subic_write_reg(uint8_t addr, uint8_t val) { ads129x_write_reg(addr, val); } +uint8_t hwss_subic_read_reg(uint8_t addr) { return ads129x_read_reg(addr); } \ No newline at end of file diff --git a/app/src/bakservice/heart_wave_sample_service/heart_wave_sample_service.h b/app/src/bakservice/heart_wave_sample_service/heart_wave_sample_service.h new file mode 100644 index 0000000..1e631fb --- /dev/null +++ b/app/src/bakservice/heart_wave_sample_service/heart_wave_sample_service.h @@ -0,0 +1,22 @@ +#pragma once +#include +#include + +// 每256个字节触发一次回调 +typedef void (*heart_wave_sample_service_callback_t)(uint16_t *p_data, uint16_t length); + +void hwss_init(void); + +void hwss_start_capture(void); +void hwss_start_prepare_capture(void); +void hwss_stop_capture(void); +void hwss_subic_write_reg(uint8_t addr, uint8_t val); +uint8_t hwss_subic_read_reg(uint8_t addr); + + + + +float hwss_read_val(void); +float hwss_read_heart_rate(void); +int hwss_has_captured_time_ms(); +bool hwss_lead_get_state_connected_state(); \ No newline at end of file diff --git a/app/src/bakservice/storage/sample_data_manager.c b/app/src/bakservice/storage/sample_data_manager.c new file mode 100644 index 0000000..6e90080 --- /dev/null +++ b/app/src/bakservice/storage/sample_data_manager.c @@ -0,0 +1,92 @@ +#include "sample_data_manager.h" + +#include + +#include "zeeprom_fs.h" +#include "znordic.h" +#include "aproject_config/config.h" + +static sample_data_fileinfo_t fileinfocache[MAX_FILE_NUM * 2]; +static uint8_t fileinfocache_count = 0; + +void sample_data_mgr_init() { zeeprom_fs_init(); } +void sample_data_mgr_uninit() { zeeprom_fs_uinit(); } + +sample_data_fileinfo_list_t* sample_data_mgr_get_fileinfo_list() { // + static sample_data_fileinfo_list_t fileinfo_list; + memset(&fileinfo_list, 0, sizeof(fileinfo_list)); + fileinfocache_count = 0; + + // 读取所有记录信息 + zeeprom_header_t* header = zeeprom_fs_get_header(); + + for (uint16_t i = 0; i < ZARRAY_SIZE(header->sectorinfos); i++) { + zeeprom_sector_info_t* sectorinfo = &header->sectorinfos[i]; + if (sectorinfo->usage == 1 && sectorinfo->sector_index_in_file == 0) { + // 读取文件信息 + if (fileinfocache_count >= ZARRAY_SIZE(fileinfocache)) { + ZLOGE("fileinfocache_count >= MAX_FILE_NUM"); + break; + } + + sample_data_fileinfo_t* fileinfo = &fileinfocache[fileinfocache_count]; + fileinfo->fileuuid = sectorinfo->fileuuid; + memcpy(fileinfo->filename, sectorinfo->filename, sizeof(fileinfo->filename)); + fileinfo->size = zeeprom_fs_get_filesize_by_fileuuid(fileinfo->fileuuid); + fileinfo->checksum = zeeprom_fs_get_checksum_by_fileuuid(fileinfo->fileuuid); + + fileinfo_list.fileinfo[fileinfo_list.count] = fileinfo; + fileinfo_list.count++; + fileinfocache_count++; + } + } + // 根据文件uuid排序,uuid最大的排在最前面 + for (uint16_t i = 0; i < fileinfo_list.count; i++) { + for (uint16_t j = i + 1; j < fileinfo_list.count; j++) { + if (fileinfo_list.fileinfo[i]->fileuuid < fileinfo_list.fileinfo[j]->fileuuid) { + sample_data_fileinfo_t* tmp = fileinfo_list.fileinfo[i]; + fileinfo_list.fileinfo[i] = fileinfo_list.fileinfo[j]; + fileinfo_list.fileinfo[j] = tmp; + } + } + } + return &fileinfo_list; +} + +bool sample_data_mgr_storage_is_full() { return zeeprom_fs_get_file_num() >= MAX_FILE_NUM; } +int32_t sample_data_mgr_get_file_num() { return zeeprom_fs_get_file_num(); } + +#if 1 +static const char* filename2str(uint8_t* filename) { + static char filename_str[32]; + sprintf(filename_str, "%02x%02x%02x%02x%02x%02x%02x%02x", filename[0], filename[1], filename[2], filename[3], filename[4], filename[5], filename[6], filename[7]); + return filename_str; +} +#endif + +void sample_data_mgr_dump_fileinfo_list() { + zeeprom_fs_dump_sector_state(); + sample_data_fileinfo_list_t* fileinfo_list = sample_data_mgr_get_fileinfo_list(); + ZLOGI_BLOCK("fileinfo_list->count=%d\n", fileinfo_list->count); + for (uint16_t i = 0; i < fileinfo_list->count; i++) { + sample_data_fileinfo_t* fileinfo = fileinfo_list->fileinfo[i]; + ZLOGI_BLOCK("[%d]: filename=%s, fileuuid=%d, size=%d", i, filename2str(fileinfo->filename), fileinfo->fileuuid, fileinfo->size); + } +} + +int32_t sample_data_mgr_open(sample_data_filename_t* filename, wrflag_t flag) { + /** + * @brief 查看文件数量 + */ + if (flag == kwrflag_write_only) { + if (zeeprom_fs_get_file_num() >= MAX_FILE_NUM) { + zeeprom_fs_delete_the_oldest_file(); + } + } + return zeeprom_fs_open((uint8_t*)filename, flag); +} +int32_t sample_data_mgr_close(int32_t fd) { return zeeprom_fs_close(fd); } +int32_t sample_data_mgr_write(int32_t fd, const uint8_t* data, int32_t size) { return zeeprom_fs_write(fd, data, size); } +int32_t sample_data_mgr_read(int32_t fd, uint8_t* data, int32_t size) { return zeeprom_fs_read(fd, data, size); } +int32_t sample_data_mgr_get_file_size_by_fd(int32_t fd) { return zeeprom_fs_get_filesize_by_fd(fd); } +int32_t sample_data_mgr_delete_file(sample_data_filename_t* filename) { return zeeprom_fs_delete_by_name((uint8_t*)filename); } diff --git a/app/src/bakservice/storage/sample_data_manager.h b/app/src/bakservice/storage/sample_data_manager.h new file mode 100644 index 0000000..3a70e22 --- /dev/null +++ b/app/src/bakservice/storage/sample_data_manager.h @@ -0,0 +1,46 @@ +#pragma once +#include +#include + +#include "aproject_config/config.h" +#include "zeeprom_fs.h" + +void sample_data_mgr_init(); + +typedef struct { + uint8_t year; + uint8_t month; + uint8_t day; + uint8_t hour; + uint8_t min; + uint8_t sec; + uint8_t placeholder[2]; +} sample_data_filename_t; + +typedef struct { + uint8_t filename[8]; + int32_t fileuuid; + int32_t size; + uint32_t checksum; +} sample_data_fileinfo_t; + +typedef struct { + sample_data_fileinfo_t* fileinfo[MAX_FILE_NUM]; + int count; +} sample_data_fileinfo_list_t; + +void sample_data_mgr_init(); +void sample_data_mgr_uninit(); + +sample_data_fileinfo_list_t* sample_data_mgr_get_fileinfo_list(); +bool sample_data_mgr_storage_is_full(); +int32_t sample_data_mgr_get_file_num(); + +int32_t sample_data_mgr_open(sample_data_filename_t* filename, wrflag_t flag); +int32_t sample_data_mgr_close(int32_t fd); + +int32_t sample_data_mgr_write(int32_t fd, const uint8_t* data, int32_t size); +int32_t sample_data_mgr_read(int32_t fd, uint8_t* data, int32_t size); +int32_t sample_data_mgr_get_file_size_by_fd(int32_t fd); + +int32_t sample_data_mgr_delete_file(sample_data_filename_t* filename); diff --git a/app/src/bakservice/storage/storage_service.h b/app/src/bakservice/storage/storage_service.h new file mode 100644 index 0000000..895d343 --- /dev/null +++ b/app/src/bakservice/storage/storage_service.h @@ -0,0 +1,3 @@ +#pragma once +#include "sample_data_manager.h" +#include "zeeprom_fs.h" diff --git a/app/src/bakservice/storage/zeeprom_fs.c b/app/src/bakservice/storage/zeeprom_fs.c new file mode 100644 index 0000000..1c6594a --- /dev/null +++ b/app/src/bakservice/storage/zeeprom_fs.c @@ -0,0 +1,572 @@ +#include "zeeprom_fs.h" + +#include "board/board_eeprom_driver.h" + +static zeeprom_header_t m_eeprom_header; +static bool m_is_init = false; + +static filehandler_t m_filehandler[2]; +static int m_fd_off; + +/******************************************************************************* + * 函数声明 * + *******************************************************************************/ + +static filehandler_t* filehandler_find(int fd); +static filehandler_t* filehandler_alloc(); +static void filehandler_rlease(int fd); + +static int32_t sector_mgr_find_earliest_file_created_index(); +static int32_t sector_mgr_free_sector(int32_t fileuuid); +static zeeprom_sector_info_t* sector_mgr_find_idle_sector(); +static bool sector_mgr_sector_is_open(int32_t fileuuid); +static zeeprom_sector_info_t* sector_mgr_force_find_idle_sector(); +static void sector_mgr_open_sector(int32_t fileuuid); +static void sector_mgr_close_sector(int32_t fileuuid); +// static zeeprom_sector_info_t* sector_mgr_find_fileheader(int32_t fileuuid); +static zeeprom_sector_info_t* sector_mgr_find_end_sector(int32_t fileuuid); +static zeeprom_sector_info_t* sector_mgr_find_sector(int32_t fileuuid, int32_t sector_index_in_file); +static int32_t sector_mgr_file_get_size(int32_t fileuuid); + +static zeeprom_sector_info_t* sector_mgr_find_fileheader_by_filename(uint8_t* fileid); +static int32_t sector_mgr_get_sector_offset(zeeprom_sector_info_t* sector); +static int32_t sector_mgr_get_sector_rom_add(zeeprom_sector_info_t* sector); +static int32_t sector_mgr_file_get_checksum(int32_t fileuuid); + +static void zeeprom_read(int32_t add, uint8_t* data, uint16_t len); +static void zeeprom_write(int32_t add, const uint8_t* data, uint16_t len); +static uint32_t compute_checksum(const uint8_t* data, uint16_t len); + +/******************************************************************************* + * CODE * + *******************************************************************************/ + +static bool m_eeprom_header_inited = false; +int zeeprom_fs_init() { // + board_eeprom_init(); + if (!m_eeprom_header_inited) { + zeeprom_read(0, (uint8_t*)&m_eeprom_header, sizeof(m_eeprom_header)); + uint32_t checksum_val = compute_checksum((uint8_t*)&m_eeprom_header, sizeof(m_eeprom_header) - sizeof(m_eeprom_header.sector_info_headers_checksum)); + if (checksum_val != m_eeprom_header.sector_info_headers_checksum) { + memset(&m_eeprom_header, 0, sizeof(m_eeprom_header)); + } + } + m_is_init = true; + m_eeprom_header_inited = true; + return 0; +} +int zeeprom_fs_uinit() { // + // zeeprom_write(0, (uint8_t*)&m_eeprom_header, sizeof(m_eeprom_header)); + board_eeprom_uninit(); + m_is_init = false; + return 0; +} + +zeeprom_header_t* zeeprom_fs_get_header() { return &m_eeprom_header; } + +int zeeprom_fs_open(uint8_t* filename, wrflag_t wrflag) { + ZASSERT(m_is_init); + /** + * @brief + * 1. 如果文件已经存在,则打开文件 + * 2. 如果文件不存在, 则创建文件 + * + * 创建文件: + * 1. 找到一个空闲扇区 + * 2. 初始化文件头 + */ + + filehandler_t* fileHander = filehandler_alloc(); + if (!fileHander) { + ZLOGI("fileHander_alloc fail"); + return -1; + } + + if (wrflag == kwrflag_write_only) { + /******************************************************************************* + * 写文件 * + *******************************************************************************/ + zeeprom_sector_info_t* sectorHeaderInfo = NULL; + zeeprom_fs_delete_by_name(filename); + + sectorHeaderInfo = sector_mgr_force_find_idle_sector(); + if (!sectorHeaderInfo) { + ZLOGE("sector_mgr_force_find_idle_sector fail"); + filehandler_rlease(fileHander->fd); + return -1; + } + + memset(sectorHeaderInfo, 0, sizeof(zeeprom_sector_info_t)); + sectorHeaderInfo->usage = 1; + sectorHeaderInfo->opened = 1; + memcpy(sectorHeaderInfo->filename, filename, 8); + sectorHeaderInfo->sector_index_in_file = 0; + sectorHeaderInfo->datalen = 0; + sectorHeaderInfo->sector_data_checksum = 0; + sectorHeaderInfo->fileuuid = m_eeprom_header.fileuuid_cnt++; + fileHander->fileuuid = sectorHeaderInfo->fileuuid; + fileHander->sector_header = sectorHeaderInfo; + fileHander->file_offset = 0; + fileHander->file_size = 0; + fileHander->checksum = 0; + return fileHander->fd; + + } else { + /******************************************************************************* + * 读文件 * + *******************************************************************************/ + zeeprom_sector_info_t* sectorHeaderInfo = sector_mgr_find_fileheader_by_filename(filename); + if (sectorHeaderInfo) { + fileHander->fileuuid = sectorHeaderInfo->fileuuid; + fileHander->file_offset = 0; + fileHander->fd = fileHander->fd; + fileHander->sector_header = sectorHeaderInfo; + fileHander->file_size = sector_mgr_file_get_size(fileHander->fileuuid); + fileHander->checksum = sector_mgr_file_get_checksum(fileHander->fileuuid); + ZLOGI("filesize:%d", fileHander->file_size); + memcpy(fileHander->filename, filename, 8); + memcpy(fileHander->usrdata, sectorHeaderInfo->usrdata, sizeof(sectorHeaderInfo->usrdata)); + sector_mgr_open_sector(fileHander->fileuuid); + return fileHander->fd; + } else { + filehandler_rlease(fileHander->fd); + return -1; + } + } +} + +int zeeprom_fs_write(int fileid, const uint8_t* data, int32_t size) { + ZASSERT(m_is_init); + + filehandler_t* fileHander = NULL; + zeeprom_sector_info_t* header_sinfo = NULL; + zeeprom_sector_info_t* endsector = NULL; + int32_t wadd = 0; + + ZASSERT(size == EEPROM_SECTOR_MIN_WR_SIZE); + + fileHander = filehandler_find(fileid); + if (!fileHander) { + ZLOGE("fileHander_find fail"); + return -1; + } + + header_sinfo = fileHander->sector_header; + if (!header_sinfo) { + ZLOGE("header_sinfo fail"); + return -1; + } + + endsector = sector_mgr_find_end_sector(fileHander->fileuuid); + if (!endsector) { + ZLOGE("sector_mgr_find_end_sector fail"); + return -1; + } + + if (endsector->datalen + size > EEPROM_SECTOR_SIZE) { + ZLOGE("endsector->datalen + size > EEPROM_SECTOR_SIZE"); + return -1; + } + + wadd = sector_mgr_get_sector_rom_add(endsector); + if (wadd < 0) { + ZLOGE("sector_mgr_get_sector_rom_add fail"); + return -1; + } + ZASSERT(wadd % EEPROM_SECTOR_MIN_WR_SIZE == 0); + ZASSERT(wadd >= EEPROM_SECTOR_SIZE); + zeeprom_write(wadd + endsector->datalen, data, size); + + endsector->datalen = endsector->datalen + size; + endsector->sector_data_checksum += compute_checksum(data, size); + fileHander->file_offset += size; + fileHander->file_size += size; + fileHander->checksum += compute_checksum(data, size); + + if (endsector->datalen == EEPROM_SECTOR_SIZE) { + zeeprom_sector_info_t* newsector = sector_mgr_force_find_idle_sector(); + if (!newsector) { + ZLOGE("sector_mgr_force_find_idle_sector fail"); + return -1; + } + + memset(newsector, 0, sizeof(zeeprom_sector_info_t)); + newsector->usage = 1; + newsector->opened = 1; + newsector->sector_data_checksum = 0; + memcpy(newsector->filename, header_sinfo->filename, 8); + newsector->sector_index_in_file = endsector->sector_index_in_file + 1; + newsector->datalen = 0; + newsector->fileuuid = header_sinfo->fileuuid; + } + return size; +} + +int zeeprom_fs_close(int fileid) { + ZASSERT(m_is_init); + + filehandler_t* fileHander = filehandler_find(fileid); + if (!fileHander) { + ZLOGE("zeeprom_fs_close fileHander_find fail"); + return -1; + } + + sector_mgr_close_sector(fileHander->fileuuid); + uint32_t checksum_val = compute_checksum((uint8_t*)&m_eeprom_header, sizeof(m_eeprom_header) - sizeof(m_eeprom_header.sector_info_headers_checksum)); + m_eeprom_header.sector_info_headers_checksum = checksum_val; + // zeeprom_write(0, (uint8_t*)&m_eeprom_header, sizeof(m_eeprom_header)); + + filehandler_rlease(fileid); + return 0; +} + +int zeeprom_fs_get_filesize_by_fd(int fd) { + ZASSERT(m_is_init); + filehandler_t* fileHander = filehandler_find(fd); + if (!fileHander) return 0; + return fileHander->file_size; +} + +int zeeprom_fs_read(int fileid, uint8_t* data, int32_t size) { + ZASSERT(m_is_init); + + /** + * @brief + * 找到当前扇区 + */ + ZASSERT(size == EEPROM_SECTOR_MIN_WR_SIZE); + filehandler_t* fileHander = filehandler_find(fileid); + if (!fileHander) return -1; + + if (fileHander->file_offset + size > fileHander->file_size) { + return -1; + } + + zeeprom_sector_info_t* header_sinfo = fileHander->sector_header; + if (!header_sinfo) { + return -1; + } + + int32_t sector_idx = fileHander->file_offset / EEPROM_SECTOR_SIZE; + int32_t sector_off = fileHander->file_offset % EEPROM_SECTOR_SIZE; + + zeeprom_sector_info_t* sector = sector_mgr_find_sector(fileHander->fileuuid, sector_idx); + if (!sector) { + return -1; + } + + int32_t radd = sector_mgr_get_sector_rom_add(sector); + ZASSERT(radd % EEPROM_SECTOR_MIN_WR_SIZE == 0); + radd += sector_off; + + zeeprom_read(radd, data, size); + fileHander->file_offset += size; + return size; +} + +int zeeprom_fs_delete(int32_t fileuuid) { + ZASSERT(m_is_init); + + sector_mgr_free_sector(fileuuid); + return 0; +} +int zeeprom_fs_delete_by_name(uint8_t* filename) { + ZASSERT(m_is_init); + + zeeprom_sector_info_t* sectorHeaderInfo = sector_mgr_find_fileheader_by_filename(filename); + if (sectorHeaderInfo) { + sector_mgr_free_sector(sectorHeaderInfo->fileuuid); + } + return 0; +} + +int zeeprom_fs_get_file_num() { + ZASSERT(m_is_init); + + int count = 0; + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + if (sinfo->usage == 1 && sinfo->sector_index_in_file == 0) { + count++; + } + } + return count; +} +int zeeprom_fs_delete_the_oldest_file() { + ZASSERT(m_is_init); + + int32_t earliest_file_created_index = sector_mgr_find_earliest_file_created_index(); + sector_mgr_free_sector(earliest_file_created_index); + return 0; +} + +int zeeprom_fs_get_filesize_by_fileuuid(int32_t fileuuid) { + ZASSERT(m_is_init); + return sector_mgr_file_get_size(fileuuid); +} + +int zeeprom_fs_get_checksum_by_fileuuid(int32_t fileuuid) { + ZASSERT(m_is_init); + return sector_mgr_file_get_checksum(fileuuid); +} + +static void zeeprom_read(int32_t add, uint8_t* data, uint16_t len) { // + int wrsize = EEPROM_SECTOR_MIN_WR_SIZE; + + int readTimes = len / wrsize; + int readRemain = len % wrsize; + + for (int i = 0; i < readTimes; i++) { + board_eeprom_read(add + i * wrsize, data + i * wrsize, wrsize); + } + if (readRemain > 0) { + board_eeprom_read(add + readTimes * wrsize, data + readTimes * wrsize, readRemain); + } +} +static void zeeprom_write(int32_t add, const uint8_t* data, uint16_t len) { + int wrsize = EEPROM_SECTOR_MIN_WR_SIZE; + + int writeTimes = len / wrsize; + int writeRemain = len % wrsize; + + for (int i = 0; i < writeTimes; i++) { + // int pageoff = add / wrsize + i; + int32_t writeadd = add + i * wrsize; + board_eeprom_write(writeadd, data + i * wrsize, wrsize); + } + if (writeRemain > 0) { + int32_t writeadd = add + writeTimes * wrsize; + board_eeprom_write(writeadd, data + writeTimes * wrsize, writeRemain); + } +} + +static uint32_t compute_checksum(const uint8_t* data, uint16_t len) { + uint32_t sum = 0; + for (int i = 0; i < len; i++) { + sum += data[i]; + } + return sum; +} +/******************************************************************************* + * filehandler * + *******************************************************************************/ +static filehandler_t* filehandler_find(int fd) { + for (int i = 0; i < ZARRAY_SIZE(m_filehandler); i++) { + if (m_filehandler[i].fd == fd) { + return &m_filehandler[i]; + } + } + return NULL; +} +static filehandler_t* filehandler_alloc() { + for (int i = 0; i < ZARRAY_SIZE(m_filehandler); i++) { + if (m_filehandler[i].fd == 0) { + m_filehandler[i].fd = ++m_fd_off; + return &m_filehandler[i]; + } + } + return NULL; +} +static void filehandler_rlease(int fd) { + for (int i = 0; i < ZARRAY_SIZE(m_filehandler); i++) { + if (m_filehandler[i].fd == fd) { + m_filehandler[i].fd = 0; + return; + } + } +} +/******************************************************************************* + * sector_mgr * + *******************************************************************************/ + +// 查找最早创建的文件的file_created_index +static int32_t sector_mgr_find_earliest_file_created_index() { + int32_t earliest_file_created_index = INT32_MAX; + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + if (sinfo->usage == 1) { + if (sinfo->fileuuid < earliest_file_created_index) { + earliest_file_created_index = sinfo->fileuuid; + } + } + } + return earliest_file_created_index; +} +// 删除文件 +static int32_t sector_mgr_free_sector(int32_t fileuuid) { + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { + sinfo->usage = 0; + } + } + return 0; +} +// +static zeeprom_sector_info_t* sector_mgr_find_idle_sector() { + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + if (sinfo->usage == 0) { + return sinfo; + } + } + return NULL; +} +static bool sector_mgr_sector_is_open(int32_t fileuuid) { + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { + return sinfo->opened; + } + } + return false; +} + +static zeeprom_sector_info_t* sector_mgr_force_find_idle_sector() { + /** + * @brief 查找空闲扇区 + */ + zeeprom_sector_info_t* ret_sinfo = sector_mgr_find_idle_sector(); + if (ret_sinfo) return ret_sinfo; + /** + * @brief 查找最早创建的文件 + */ + int32_t earliest_file_created_index = sector_mgr_find_earliest_file_created_index(); + if (sector_mgr_sector_is_open(earliest_file_created_index)) { + return NULL; + } + + /** + * @brief 删除最早创建的文件 + */ + sector_mgr_free_sector(earliest_file_created_index); + + /** + * @brief 重新查找空闲扇区 + */ + ret_sinfo = sector_mgr_find_idle_sector(); + if (ret_sinfo) return ret_sinfo; + + return NULL; +} + +static void sector_mgr_open_sector(int32_t fileuuid) { + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { + sinfo->opened = true; + } + } +} + +static void sector_mgr_close_sector(int32_t fileuuid) { + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { + sinfo->opened = false; + } + } +} + +// static zeeprom_sector_info_t* sector_mgr_find_fileheader(int32_t fileuuid) { +// for (int i = 0; i < MAX_SECTOR_NUM; i++) { +// zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; +// if (sinfo->usage == 1 && sinfo->sector_index_in_file == 0 && sinfo->fileuuid == fileuuid) { +// return sinfo; +// } +// } +// return NULL; +// } + +static zeeprom_sector_info_t* sector_mgr_find_sector(int32_t fileuuid, int32_t sector_index_in_file) { + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + if (sinfo->usage == 1 && sinfo->sector_index_in_file == sector_index_in_file && sinfo->fileuuid == fileuuid) { + return sinfo; + } + } + return NULL; +} + +static zeeprom_sector_info_t* sector_mgr_find_end_sector(int32_t fileuuid) { + int32_t maxsectorindex = 0; + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { + if (sinfo->sector_index_in_file >= maxsectorindex) { + maxsectorindex = sinfo->sector_index_in_file; + } + } + } + return sector_mgr_find_sector(fileuuid, maxsectorindex); +} + +static zeeprom_sector_info_t* sector_mgr_find_fileheader_by_filename(uint8_t* fileid) { + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + if (sinfo->usage == 1 && sinfo->sector_index_in_file == 0 && memcmp(sinfo->filename, fileid, 8) == 0) { + return sinfo; + } + } + return NULL; +} + +static int32_t sector_mgr_get_sector_offset(zeeprom_sector_info_t* sector) { + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + if (sinfo == sector) { + return i; + } + } + return -1; +} + +static int32_t sector_mgr_get_sector_rom_add(zeeprom_sector_info_t* sector) { + int32_t offset = sector_mgr_get_sector_offset(sector); + if (offset < 0) return -1; + return (offset + 1) * EEPROM_SECTOR_SIZE; +} + +static int32_t sector_mgr_file_get_size(int32_t fileuuid) { + int32_t filesize = 0; + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + + if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { + filesize += sinfo->datalen; + } + } + return filesize; +} + +static int32_t sector_mgr_file_get_checksum(int32_t fileuuid) { + int32_t checksum = 0; + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + + if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { + checksum += sinfo->sector_data_checksum; + } + } + return checksum; +} + +static const char* filename2str(uint8_t* filename) { + static char filename_str[32]; + sprintf(filename_str, "%02x%02x%02x%02x%02x%02x%02x%02x", filename[0], filename[1], filename[2], filename[3], filename[4], filename[5], filename[6], filename[7]); + return filename_str; +} + +int zeeprom_fs_dump_sector_state() { + ZLOGI_BLOCK("zeeprom_fs_dump_sector_state\n"); + for (int i = 0; i < MAX_SECTOR_NUM; i++) { + zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; + if (sinfo->usage == 1) { + ZLOGI_BLOCK("[%d]: usage=%d opened=%d", i, sinfo->usage, sinfo->opened); + ZLOGI_BLOCK(" fname=%s, index_in_file=%d, datalen=%d, fileuuid=%d", filename2str(sinfo->filename), sinfo->sector_index_in_file, sinfo->datalen, sinfo->fileuuid); + } else { + ZLOGI_BLOCK("[%d]: usage=%d", i, sinfo->usage); + } + } + return 0; +} diff --git a/app/src/bakservice/storage/zeeprom_fs.h b/app/src/bakservice/storage/zeeprom_fs.h new file mode 100644 index 0000000..642a53f --- /dev/null +++ b/app/src/bakservice/storage/zeeprom_fs.h @@ -0,0 +1,108 @@ +#pragma once +#include +/** + * @brief EEPROM简易文件系统代码框架 + * + * 整个存储区域分为两个区 [扇区头][文件数据区] + * + * ----------------- + * | | + * | 扇区头 | 8K * 1 + * | | + * ----------------- + * | | + * | N*数据扇区 | 8K * 31 + * | | + * ----------------- + * + * 扇区头存储 31* zeeprom_sector_info_t个结构体 + * 结构体:zeeprom_sector_info_t * 31 + * uint8_t usage; // 0:空闲 1:已使用 + * uint8_t opened; // 0:未打开 1:已打开 + * uint8_t filename[8]; // 文件名 + * int32_t sector_index_in_file; // 当前扇区中文件数据的起始地址 + * int32_t datalen; // 当前扇区中文件数据的长度 + * uint32_t checksum; // 文件数据的校验和 + * int32_t fileuuid; // 递增,根据这个index判断文件创建的先后顺序,同时也相当于文件唯一标识 + * uint8_t usrdata[20]; // 用户数据 + * + * + * 文件的概念: + * 1.一个文件由一个或多个扇区组成,每个扇区的大小为8K, + * 2.同一个文件依靠fileuuid进行判定 + * 3.如果想要读取文件大小,只需计算相同fileuuid的所有zeeprom_sector_info_t.datalen的和即可。 + * 4.文件顺序依靠sector_index_in_file进行判断 + * 5.文件名保存在sector_index_in_file为0的zeeprom_sector_info_t结构体中 + * + * 扇区头的特殊性: + * 1. 扇区头常驻内存中 + * 2. 如果期望掉电丢弃数据,扇区头不保存导flash中即可 + * + */ + +#define EEPROM_SIZE (256 * 1024) +#define EEPROM_SECTOR_MIN_WR_SIZE (256) +#define EEPROM_SECTOR_SIZE (8 * 1024) +#define MAX_SECTOR_NUM (EEPROM_SIZE / EEPROM_SECTOR_SIZE - 1) +#define EEPROM_FILE_SIZE (EEPROM_SECTOR_SIZE * MAX_SECTOR_NUM) + +// +#pragma pack(1) +typedef struct { + uint8_t usage; + uint8_t opened; + uint8_t filename[8]; // 注意文件名为固定八个字节的二进制数据,不是字符串 + int32_t sector_index_in_file; // 当前扇区中文件数据的起始地址 + int32_t datalen; // 当前扇区中文件数据的长度 + uint32_t sector_data_checksum; // 文件数据的校验和 + int32_t fileuuid; // 递增,根据这个index判断文件创建的先后顺序,同时也相当于文件唯一标识 + uint8_t usrdata[20]; +} zeeprom_sector_info_t; + +typedef struct { + uint8_t filename[8]; + uint8_t usrdata[20]; + + zeeprom_sector_info_t* sector_header; + int32_t file_offset; + int32_t file_size; + uint32_t checksum; + + int fd; + int32_t fileuuid; +} filehandler_t; + +typedef struct { + zeeprom_sector_info_t sectorinfos[MAX_SECTOR_NUM]; + int32_t fileuuid_cnt; // 递增,新创建文件时使用 + uint32_t sector_info_headers_checksum; // 扇区头的校验和 +} zeeprom_header_t; +#pragma pack() + +int zeeprom_fs_init(); +int zeeprom_fs_uinit(); + +typedef enum { + kwrflag_read_only, + kwrflag_write_only, +} wrflag_t; + +zeeprom_header_t* zeeprom_fs_get_header(); + +int zeeprom_fs_open(uint8_t* filename, wrflag_t flag); + +int zeeprom_fs_close(int fd); + +int zeeprom_fs_write(int fd, const uint8_t* data, int32_t size); +int zeeprom_fs_read(int fd, uint8_t* data, int32_t size); + +int zeeprom_fs_get_filesize_by_fd(int fd); + +int zeeprom_fs_get_file_num(); +int zeeprom_fs_delete_the_oldest_file(); +int zeeprom_fs_delete(int32_t fileuuid); +int zeeprom_fs_delete_by_name(uint8_t* filename); + +int zeeprom_fs_dump_sector_state(); +int zeeprom_fs_get_filesize_by_fileuuid(int32_t fileuuid); +int zeeprom_fs_get_checksum_by_fileuuid(int32_t fileuuid); diff --git a/app/src/basic_service/app_event.h b/app/src/basic_service/app_event.h deleted file mode 100644 index 793b18a..0000000 --- a/app/src/basic_service/app_event.h +++ /dev/null @@ -1,77 +0,0 @@ -#pragma once -#include -#include - -#include "aproject_config/config.h" -typedef enum { - kplod_connected_event = 0, // 导联连接事件 - kplod_disconnected_event, // 导联断开事件 - kplod_connecting_event, // 导联连接中事件 - - kbattery_start_charge_event, // 充电事件 - kbattery_end_charge_event, // 充电结束事件 - - kevent_tmr_scheduler_event, // 定时器调度事件 - - kevent_capture_256data_event, // 采样数据回调 - kevent_capture_little_data_block_event, // 单次采样数据回调 -} app_event_type_t; - -typedef int32_t one_frame_t; - -typedef struct { - app_event_type_t eventType; - union { - uint32_t plod_connected_accumulation_time; // 导联连接累计时间 - uint8_t* capture_data_cache; // 实时采样数据,数据长度为256字节 - struct { - uint32_t frameIndex; - uint32_t timestamp; - one_frame_t data[LITTLE_DATA_BLOCK_FRAME_NUM]; - } little_data_block; - } val; -} app_event_t; - -typedef enum { - // 待机 - kdevice_state_standby = 0, - // 充电中 - kdevice_state_charging, - // 开机 - kdevice_state_poweron, - // 首页 - kdevice_state_home, - // 提示用户保持静止 - kdevice_state_keep_still, - // 采集中 - kdevice_state_sampling, - // 采集完成 - kdevice_state_sampling_complete, - // 采集异常 - kdevice_state_sampling_error, - // 测试模式 - kdevice_state_test_mode, -} device_state_t; - -static const char* device_state_to_str(device_state_t ds) { - switch (ds) { - case kdevice_state_standby: - return "standby"; - case kdevice_state_poweron: - return "poweron"; - case kdevice_state_home: - return "home"; - case kdevice_state_keep_still: - return "keep_still"; - case kdevice_state_sampling: - return "sampling"; - case kdevice_state_sampling_complete: - return "sampling_complete"; - case kdevice_state_sampling_error: - return "sampling_error"; - case kdevice_state_charging: - return "charging"; - default: - return "unknow"; - } -} diff --git a/app/src/basic_service/app_event_distribute.c b/app/src/basic_service/app_event_distribute.c deleted file mode 100644 index a30938e..0000000 --- a/app/src/basic_service/app_event_distribute.c +++ /dev/null @@ -1,23 +0,0 @@ -#include "basic_service/app_event_distribute.h" - -#include "basic_service/app_event.h" -#include "app_scheduler.h" - -static AppEventListener m_listener[10]; -static int m_listener_num = 0; - -static void app_event_process_cb(void* p_event_data, uint16_t event_size) { - for (int i = 0; i < m_listener_num; i++) { - if (m_listener[i].cbfunc) { - m_listener[i].cbfunc(p_event_data, event_size); - } - } -} - -void AppEvent_regListener(app_event_listener_t listener) { // - m_listener[m_listener_num++].cbfunc = listener; -} - -void AppEvent_pushEvent(app_event_t* event) { // - app_sched_event_put(event, sizeof(app_event_t), app_event_process_cb); -} diff --git a/app/src/basic_service/app_event_distribute.h b/app/src/basic_service/app_event_distribute.h deleted file mode 100644 index 2a004ae..0000000 --- a/app/src/basic_service/app_event_distribute.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#include -#include - -#include "basic_service/app_event.h" - - -typedef void (*app_event_listener_t)(void* p_event_data, uint16_t event_size); - -typedef struct { - app_event_listener_t cbfunc; -} AppEventListener; - -void AppEvent_regListener(app_event_listener_t listener); -void AppEvent_pushEvent(app_event_t* event); diff --git a/app/src/basic_service/device_state.c b/app/src/basic_service/device_state.c deleted file mode 100644 index 0791c4e..0000000 --- a/app/src/basic_service/device_state.c +++ /dev/null @@ -1,64 +0,0 @@ - -#include "device_state.h" - -#include "basic_service/app_event_distribute.h" -#include "znordic.h" -/*********************************************************************************************************************** - * 状态机 * - ***********************************************************************************************************************/ -static device_state_t m_device_state = kdevice_state_standby; // 设备状态 -static uint32_t m_change_to_cur_state_tp = 0; // 切换到当前状态的时间戳 -static on_state_change_t m_onstate_change; -APP_TIMER_DEF(m_state_machine_driver_tmr); // 状态机驱动定时器 -// static zapp_timer_context m_state_machine_driver_tmr_context; - -static void state_machine_driver_tmr_cb(void* p_context) { // - static app_event_t appevent; - appevent.eventType = kevent_tmr_scheduler_event; - wd_feed(); - AppEvent_pushEvent(&appevent); -} - -void ds_change_to_state(device_state_t tostate) { - ZLOGI("change state from %s to %s", device_state_to_str(m_device_state), device_state_to_str(tostate)); - device_state_t nowstate = m_device_state; - - m_device_state = tostate; - if (m_onstate_change) { - m_onstate_change(nowstate, m_device_state); - } - m_change_to_cur_state_tp = znordic_getpower_on_ms(); -} - -uint32_t ds_cur_state_haspassed_ms() { return znordic_haspassed_ms(m_change_to_cur_state_tp); } -device_state_t ds_now_state() { return m_device_state; } - -void ds_init(on_state_change_t onstate_change) { - m_onstate_change = onstate_change; - ZERROR_CHECK(app_timer_create(&m_state_machine_driver_tmr, APP_TIMER_MODE_REPEATED, state_machine_driver_tmr_cb)); - ZERROR_CHECK(app_timer_start(m_state_machine_driver_tmr, APP_TIMER_TICKS(300), NULL)); -} - -/*********************************************************************************************************************** - * sample_capture_state * - ***********************************************************************************************************************/ -static sample_capture_state_t m_sample_capture_state; - -sample_capture_state_t* sample_capture_state_get() { // - return &m_sample_capture_state; -} -void sample_capture_state_reset() { // - m_sample_capture_state.is_over30s = false; -}; -void sample_capture_state_set_is_over30s(bool over30s) { // - m_sample_capture_state.is_over30s = over30s; -} - -/*********************************************************************************************************************** - * global_state * - ***********************************************************************************************************************/ - -global_state_t m_global_state; -global_state_t* global_state_get() { return &m_global_state; } -void global_state_set_preview_state(bool is_preview) { m_global_state.preivew_state = is_preview; } - diff --git a/app/src/basic_service/device_state.h b/app/src/basic_service/device_state.h deleted file mode 100644 index 872cfae..0000000 --- a/app/src/basic_service/device_state.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once -#include -#include - -#include "aproject_config/config.h" -#include "basic_service/app_event.h" - -typedef void (*on_state_change_t)(device_state_t from, device_state_t to); - -void ds_init(on_state_change_t onstate_change); -void ds_change_to_state(device_state_t state); -uint32_t ds_cur_state_haspassed_ms(); -device_state_t ds_now_state(); - -typedef struct { - bool is_over30s; -} sample_capture_state_t; - -sample_capture_state_t* sample_capture_state_get(); - -void sample_capture_state_reset(); -void sample_capture_state_set_is_over30s(bool over30s); - -typedef struct { - bool preivew_state; -} global_state_t; - -global_state_t* global_state_get(); -void global_state_set_preview_state(bool is_preview); \ No newline at end of file diff --git a/app/src/basic_service/device_version_info_mgr.c b/app/src/basic_service/device_version_info_mgr.c deleted file mode 100644 index 1b8d268..0000000 --- a/app/src/basic_service/device_version_info_mgr.c +++ /dev/null @@ -1,29 +0,0 @@ -#include "device_version_info_mgr.h" - -#include "aproject_config/config.h" -#include "zble_module.h" -// -#include "znordic.h" -void device_info_read_sn(sn_t *sn) { - uint32_t lot = NRF_UICR->CUSTOMER[0]; - uint32_t id = NRF_UICR->CUSTOMER[1]; - static char sn_str[15]; - if (lot == 0 || id == 0 || lot == 0xffffffff || id == 0xffffffff) { - sprintf(sn_str, "%s-%s","iflytop",CATEGORY); - } else { - sprintf(sn_str, "%s%04d%05d", CATEGORY, lot, id); - } - - memcpy(sn->sn, sn_str, sizeof(sn->sn)); -} - -const char *device_info_read_sn_str() { - static char sn_str[15]; - device_info_read_sn((sn_t *)sn_str); - return sn_str; -} - -uint16_t device_info_read_blestack_version(void) { return BLESTACK_VERSION; } -uint16_t device_info_read_bootloader_version(void) { return BOOTLOADER_VERSION; } -uint16_t device_info_read_firmware_version(void) { return FIRMWARE_VERSION; } -uint16_t device_info_read_hardware_version(void) { return HARDWARE_VERSION; } \ No newline at end of file diff --git a/app/src/basic_service/device_version_info_mgr.h b/app/src/basic_service/device_version_info_mgr.h deleted file mode 100644 index 00f9abb..0000000 --- a/app/src/basic_service/device_version_info_mgr.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once -#include "znordic.h" - - - -typedef struct { - uint8_t sn[14]; -} sn_t; - -void device_info_read_sn(sn_t *sn); -const char *device_info_read_sn_str(); - -uint16_t device_info_read_blestack_version(void); -uint16_t device_info_read_bootloader_version(void); -uint16_t device_info_read_firmware_version(void); -uint16_t device_info_read_hardware_version(void); \ No newline at end of file diff --git a/app/src/main.c b/app/src/main.c index 18bfdad..c78e27b 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -6,20 +6,19 @@ #include // #include "aproject_config/config.h" -#include "basic_service/app_event.h" -#include "basic_service/app_event_distribute.h" -#include "basic_service/device_version_info_mgr.h" +#include "app_basic_service/device_version_info_mgr.h" +#include "app_basic_service/zapp.h" #include "zble_module.h" #include "zdatachannel_service.h" +#include "one_conduction_main.h" // -#define SCHED_MAX_EVENT_DATA_SIZE MAX(sizeof(app_event_t), APP_TIMER_SCHED_EVENT_DATA_SIZE) ZDATACHANNEL_DEF(m_zhrs, 2 /*优先级*/, 1 /*client num*/); // 蓝牙服务 /** * @brief 蓝牙消息解析 */ void zdatachannel_data_handler(zdatachannel_evt_t *p_evt) { if (p_evt->type == ZDATACHANNEL_EVT_RX_DATA) { - ble_cmder_process_rx((uint8_t *)p_evt->params.rx_data.p_data, p_evt->params.rx_data.length); + one_conduction_process_rx_packet((uint8_t *)p_evt->params.rx_data.p_data, p_evt->params.rx_data.length); } } void on_service_init(void) { @@ -29,7 +28,6 @@ void on_service_init(void) { zdatachannle_init.data_handler = zdatachannel_data_handler; ZERROR_CHECK(zdatachannel_init(&m_zhrs, &zdatachannle_init)); } -extern void one_conduction_main(); /*lint -save -e14 */ /** @@ -65,8 +63,9 @@ void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info) { } int main() { - APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, 20); + zapp_early_init(); znordic_init_without_wd(); + zapp_init(); /******************************************************************************* * 蓝牙服务初始化 * @@ -75,7 +74,6 @@ int main() { cfg.deviceName = device_info_read_sn_str(); cfg.on_service_init = on_service_init; zble_module_init(&cfg); - ble_cmder_init(); /******************************************************************************* * 设备控制服务初始化 * *******************************************************************************/ @@ -83,5 +81,6 @@ int main() { /******************************************************************************* * LOOP * *******************************************************************************/ + zapp_start_schedule(); znordic_loop(); } diff --git a/app/src/one_conduction_main.c b/app/src/one_conduction_main.c index 6a830f7..67bee27 100644 --- a/app/src/one_conduction_main.c +++ b/app/src/one_conduction_main.c @@ -1,400 +1,179 @@ #include +#include -#include "basic_service/app_event.h" -#include "basic_service/app_event_distribute.h" -#include "basic_service/device_version_info_mgr.h" -// -#include "board/board_adc_module_ctrl.h" -#include "board/board_battery_state.h" -#include "board/board_beep_ctrl.h" -#include "board/board_ecg_sensor.h" -#include "board/board_light_ctrl.h" -#include "board/board_power_mgr.h" -// -#include "board/ads129x/ads129x.h" -#include "board/app_board.h" -#include "service/ble_cmd_processer/ble_cmd_process_service.h" -#include "service/display_mgr/display_manager.h" -#include "service/heart_wave_sample_service/heart_wave_sample_service.h" -#include "service/storage/storage_service.h" -#include "zble_module.h" +#include "app_basic_service/device_version_info_mgr.h" +#include "app_basic_service/zapp.h" +#include "app_service/battery_mgr_service.h" +#include "aproject_config/config.h" +#include "ify_hrs_protocol/heart_rate_sensor_protocol.h" #include "zdatachannel_service.h" -#include "znordic.h" +/*********************************************************************************************************************** + * GLOBAL * + ***********************************************************************************************************************/ + +static uint8_t bletxbuf[255]; +static uint8_t blereportbuf[255]; /******************************************************************************* - * GLOBAL * + * UTILS * *******************************************************************************/ +static void send_error_receipt(ify_hrs_packet_t* rxpacket, int32_t errorcode) { + ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)bletxbuf; + error_receipt_t* receipt = (error_receipt_t*)txheader->data; + uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(error_receipt_t); + + txheader->cmd = rxpacket->cmd; + txheader->frame_index = rxpacket->frame_index; + txheader->frame_type = kifyhrs_pt_error_receipt; + receipt->errorcode = errorcode; + zdatachannel_data_send2(bletxbuf, sendlen); +} -static int m_cur_fd; -static sample_data_filename_t sampledata_file_name; +static void send_success_receipt(ify_hrs_packet_t* rxpacket, int32_t emptydatasize) { + ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)bletxbuf; + uint16_t sendlen = sizeof(ify_hrs_packet_t) + emptydatasize; -#define SCHED_MAX_EVENT_DATA_SIZE MAX(sizeof(app_event_t), APP_TIMER_SCHED_EVENT_DATA_SIZE) + txheader->cmd = rxpacket->cmd; + txheader->frame_index = rxpacket->frame_index; + txheader->frame_type = kifyhrs_pt_cmd_receipt; -/******************************************************************************* - * 事件处理 * - *******************************************************************************/ -void ENTER_DEEP_SLEEP() { - // 进入深度睡眠前,使能唤醒引脚 - BoardBattery_sence_gpio_init_before_sleep(); - // nrf_sdh_disable_request(); - app_timer_pause(); - nrf_sdh_suspend(); - sd_power_system_off(); - NVIC_SystemReset(); + zdatachannel_data_send2(bletxbuf, sendlen); } /******************************************************************************* - * 状态切换方法 * + * 下发消息处理 * *******************************************************************************/ - -static void on_state_change(device_state_t from, device_state_t to) { - /** - * @brief 开关机控制 - */ - if (from == kdevice_state_standby && to != kdevice_state_standby) { - /** - * @brief 切换到工作状态 - */ - BoardBeepCtrl_load(); - BoardLight_load(); - - sample_data_mgr_init(); - dsp_mgr_init(); - ble_cmder_init(); - ble_cmder_start_adv(); - - app_board_change_state(kapp_power_state_working); - - } else if (to == kdevice_state_standby) { - /** - * @brief 切换到待机模式 - * - */ - dsp_mgr_uninit(); - sample_data_mgr_uninit(); - - BoardLight_unload(); - - BoardBeepCtrl_unload(); - ble_stop_upload_record(); - zble_module_disconnect(); - for (size_t i = 0; i < 100; i++) { - nrf_delay_ms(10); - if (!zble_module_is_connected()) { - break; - } - } - ble_cmder_stop_adv(); - ble_cmder_uninit(); - board_power_mgr_main_power_supply_set(false); - app_board_change_state(kapp_power_state_standby); +void one_conduction_process_rx_packet(uint8_t* rx, int len) { + if (len < sizeof(ify_hrs_packet_t)) { + ZLOGI("rx len error:%d", len); + return; } - /*********************************************************************************************************************** - * 切换状态 附带操作 * - ***********************************************************************************************************************/ - if (to == kdevice_state_home) { - dsp_mgr_change_to_main(); - } else if (to == kdevice_state_poweron) { - dsp_mgr_change_to_welcome(); - } else if (to == kdevice_state_charging) { - dsp_mgr_change_to_chargingPage(); - } -} + ify_hrs_packet_t* rxheader = (ify_hrs_packet_t*)rx; + ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)bletxbuf; + ify_hrs_cmd_t cmd = (ify_hrs_cmd_t)rxheader->cmd; + memset(bletxbuf, 0, sizeof(bletxbuf)); -static void app_event_listener(void* p_event_data, uint16_t event_size) { - if (!p_event_data) return; - app_event_t* p_event = (app_event_t*)p_event_data; + txheader->cmd = rxheader->cmd; + txheader->frame_index = rxheader->frame_index; + txheader->frame_type = kifyhrs_pt_cmd_receipt; - if (ds_now_state() != kdevice_state_standby && // - ds_now_state() != kdevice_state_charging && // - ds_now_state() != kdevice_state_poweron // - ) { - if (zdatachannel_is_connected()) { - BoardLight_setGreenLightEffect(kLightEffect_slowFlash); - } else { - BoardLight_setGreenLightEffect(kLightEffect_quickFlash); - } - } + ZLOGI("rx cmd:%d index:%d datalen:%d", cmd, rxheader->frame_index, len - sizeof(ify_hrs_packet_t)); + NRF_LOG_HEXDUMP_INFO(rx, len); - /******************************************************************************* - * 待机状态 * - *******************************************************************************/ - static uint32_t lasttrypoweron_time = 0; + if (cmd == ify_hrs_cmd_read_device_version) { + device_version_info_receipt_t* receipt = (device_version_info_receipt_t*)txheader->data; + uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(device_version_info_receipt_t); - if (ds_now_state() == kdevice_state_standby) { - // 充电事件触发 --> 切换到充电页面 - if (BoardBattery_get_charging_state()) { - ds_change_to_state(kdevice_state_charging); - } + receipt->blestack_version = device_info_read_blestack_version(); + receipt->bootloader_version = device_info_read_bootloader_version(); + receipt->firmware_version = device_info_read_firmware_version(); + receipt->hardware_version = device_info_read_hardware_version(); + zdatachannel_data_send2(bletxbuf, sendlen); + } - // 导联连接事件触发 --> 切换到开机中页面 + else if (cmd == ify_hrs_cmd_read_sensor_info) { + sensor_info_receipt_t* receipt = (sensor_info_receipt_t*)txheader->data; + uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(sensor_info_receipt_t); - else if (hwss_lead_get_state_connected_state() && znordic_haspassed_ms(lasttrypoweron_time) >= LOW_BATTERY_REMINDER_DELAY_MS) { - lasttrypoweron_time = znordic_getpower_on_ms(); - // if (BoardBattery_get_battery_level() > APP_WORK_BATTERY_LEVEL) { - // TODO: 检查电池地量 - if (true) { - ds_change_to_state(kdevice_state_poweron); - } else { - BoardLight_load(); - BoardLight_blockFlash(3, 100); - BoardLight_unload(); - } - } + receipt->sensor_num = 1; + receipt->sensor_precision = SAMPLE_PRECISION; + receipt->sensor_sample_rate = SAMPLE_RATE / 10; + receipt->sensor0_pos = kifyhrs_sensor_pos_none; + receipt->sensor1_pos = kifyhrs_sensor_pos_none; + receipt->sensor2_pos = kifyhrs_sensor_pos_none; - /** - * @brief - * TODO: - * 1. 永远不进入超低功耗状态,直到电池电量低于一定程度 - * 2. 如果RTC未被设置,则重置设备状态 - * 3. 在每次从待机状态切换到开机状态,如果RTC未被设置,则清空已经存储的波形数据 - */ - else if (ds_cur_state_haspassed_ms() >= 10000) { - if (!znordic_rtc_has_setted()) { - } - } + zdatachannel_data_send2(bletxbuf, sendlen); } - /******************************************************************************* - * 充电状态 * - *******************************************************************************/ - else if (ds_now_state() == kdevice_state_charging) { - if (!BoardBattery_get_charging_state()) { - ds_change_to_state(kdevice_state_standby); - } + else if (cmd == ify_hrs_cmd_read_sn) { + read_sn_receipt_t* receipt = (read_sn_receipt_t*)txheader->data; + uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(read_sn_receipt_t); + device_info_read_sn((sn_t*)&receipt->sn); + zdatachannel_data_send2(bletxbuf, sendlen); } - /******************************************************************************* - * 开机中 * - *******************************************************************************/ - - else if (ds_now_state() == kdevice_state_poweron) { - if (ds_cur_state_haspassed_ms() >= 1500) { - ds_change_to_state(kdevice_state_home); - } + else if (cmd == ify_hrs_cmd_reset) { + NVIC_SystemReset(); } - /******************************************************************************* - * 首页 * - *******************************************************************************/ - - else if (ds_now_state() == kdevice_state_home) { - // 如果用户长时间不操作,自动切换到待机状态 - if (!zdatachannel_is_connected() && // - !hwss_lead_get_state_connected_state() && // - ds_cur_state_haspassed_ms() >= AUTOMATIC_SLEEP_TIME) { - ds_change_to_state(kdevice_state_standby); - } - // 如果用户继续保持静止,切换到采集页面 - else if (hwss_lead_get_state_connected_state() && ds_cur_state_haspassed_ms() > 1500) { - // dsp_mgr_change_to_preparePage - if (!BoardBattery_get_charging_state()) { - ds_change_to_state(kdevice_state_keep_still); - dsp_mgr_change_to_preparePage(); - hwss_start_prepare_capture(); - if (ble_is_upload_record()) { - ble_stop_upload_record(); - } - } - } -#if 0 - //TODO:使能 - // 低电量,设备进入待机模式 - else if (BoardBattery_get_battery_level() < APP_AUTO_STANDY_BATTERY_LEVEL && ds_cur_state_haspassed_ms() > 3000) { - ds_change_to_state(kdevice_state_standby); - } // -#endif - - else if (!ble_is_upload_record() && zble_module_is_connected() && zdatachannel_last_rx_data_haspassed_s() >= BLE_UNCONNECTED_OVERTIME_S) { - ZLOGI("auto sleep because ble unconnected"); - ds_change_to_state(kdevice_state_standby); - } - - else if (BoardBattery_get_charging_state()) { - // BoardLight_setGreenLightEffect(kLightEffect_close); - ds_change_to_state(kdevice_state_standby); - } + else if (cmd == ify_hrs_cmd_read_time) { + read_time_receipt_t* receipt = (read_time_receipt_t*)txheader->data; + uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(read_time_receipt_t); + static ztm_t ztm; + znordic_rtc_gettime(&ztm); + + receipt->year = (ztm.tm_year + 1900 - 2000); + receipt->month = ztm.tm_mon + 1; + receipt->day = ztm.tm_mday; + receipt->hour = ztm.tm_hour; + receipt->minute = ztm.tm_min; + receipt->second = ztm.tm_sec; + zdatachannel_data_send2(bletxbuf, sendlen); } - /******************************************************************************* - * 保持静止页面 * - *******************************************************************************/ - else if (ds_now_state() == kdevice_state_keep_still) { - if (!hwss_lead_get_state_connected_state()) { - // 如果用户未保持静止,切换到首页 - ds_change_to_state(kdevice_state_home); - hwss_stop_capture(); - } else { - /******************************************************************************* - * 页面加载中 * - *******************************************************************************/ - if (ds_cur_state_haspassed_ms() >= (KEEP_STILL_OVERTIME_MS_1P5 * 5)) { - /** - * @brief - * - * 1. 启动采样定时器 - * 2. 切换状态 - * 3. 切换页面 - */ - ds_change_to_state(kdevice_state_sampling); - dsp_mgr_change_to_sampling(0, 0); - hwss_start_capture(); - static ztm_t tm; - memset(&sampledata_file_name, 0, sizeof(sampledata_file_name)); - znordic_rtc_gettime(&tm); - sample_capture_state_reset(); - - sampledata_file_name.year = tm.tm_year + 1900 - 2000; - sampledata_file_name.month = tm.tm_mon + 1; - sampledata_file_name.day = tm.tm_mday; - sampledata_file_name.hour = tm.tm_hour; - sampledata_file_name.min = tm.tm_min; - sampledata_file_name.sec = tm.tm_sec; - m_cur_fd = sample_data_mgr_open(&sampledata_file_name, kwrflag_write_only); - BoardBeepCtrl_setEffect(kBoardBeepEffect_oneShortBeep); + else if (cmd == ify_hrs_cmd_sync_time) { + sync_time_cmd_t* cmd = (sync_time_cmd_t*)rxheader->data; + uint16_t sendlen = sizeof(ify_hrs_packet_t); - } else if (ds_cur_state_haspassed_ms() >= (KEEP_STILL_OVERTIME_MS_1P5 * 4)) { - if (dsp_mgr_preparePage_get_progress() != 4) { - dsp_mgr_preparePage_set_progress(4); - } - } else if (ds_cur_state_haspassed_ms() >= (KEEP_STILL_OVERTIME_MS_1P5 * 3)) { - if (dsp_mgr_preparePage_get_progress() != 3) { - dsp_mgr_preparePage_set_progress(3); - } - } else if (ds_cur_state_haspassed_ms() >= (KEEP_STILL_OVERTIME_MS_1P5 * 2)) { - if (dsp_mgr_preparePage_get_progress() != 2) { - dsp_mgr_preparePage_set_progress(2); - } - } else if (ds_cur_state_haspassed_ms() >= (KEEP_STILL_OVERTIME_MS_1P5 * 1)) { - if (dsp_mgr_preparePage_get_progress() != 1) { - dsp_mgr_preparePage_set_progress(1); - } - } - } + znordic_rtc_settime(cmd->year + 2000, cmd->month, cmd->day, cmd->hour, cmd->minute, cmd->second); + zdatachannel_data_send2(bletxbuf, sendlen); } - /******************************************************************************* - * 采样页面逻辑 * - *******************************************************************************/ - - else if (ds_now_state() == kdevice_state_sampling) { - /******************************************************************************* - * 采样数据存储 * - *******************************************************************************/ - if (p_event->eventType == kevent_capture_256data_event) { - // if (hwss_has_captured_time_ms() <= (MAX_STORAGE_TIMEOUT_S * 1000)) { - // sample_data_mgr_write(m_cur_fd, p_event->val.capture_data_cache, 256); - // } - } - /******************************************************************************* - * 实时采样数据上报 * - *******************************************************************************/ - if (p_event->eventType == kevent_capture_little_data_block_event) { - // 单帧实时上报 - if (global_state_get()->preivew_state) ble_cmder_try_report_one_sample_data(p_event); - } - - /******************************************************************************* - * 采样足30秒事件捕获 * - *******************************************************************************/ - if (hwss_has_captured_time_ms() >= (SAMPLE_MIN_TIME_S * 1000)) { - if (!sample_capture_state_get()->is_over30s) { - BoardBeepCtrl_setEffect(kBoardBeepEffect_oneShortBeep); - sample_capture_state_set_is_over30s(true); - } - } - - /******************************************************************************* - * 采样结束判定 * - *******************************************************************************/ - bool capture_end = false; - if (hwss_has_captured_time_ms() >= (MAX_STORAGE_TIMEOUT_S * 1000)) { - capture_end = true; - } else if (p_event->eventType == kplod_disconnected_event) { - ble_cmder_try_report_sensor_drop_event(0x01, 0); - capture_end = true; - } + /*********************************************************************************************************************** + * 基础指令 * + ***********************************************************************************************************************/ - if (capture_end) { - if (sample_capture_state_get()->is_over30s) { - sample_data_mgr_close(m_cur_fd); - dsp_mgr_change_to_sampleSuc(); - BoardBeepCtrl_setEffect(kBoardBeepEffect_oneShortBeep); - ds_change_to_state(kdevice_state_sampling_complete); - hwss_stop_capture(); + else if (cmd == ify_hrs_cmd_read_device_state) { + device_state_receipt_t* receipt = (device_state_receipt_t*)txheader->data; + uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(device_state_receipt_t); - } else { - // 采样不足三十秒 + receipt->drop_state0 = (0); + receipt->drop_state1 = 0x00; + receipt->device_state0.sampling_state = (zapp_state_machine_now_state() == kdevice_state_sampling); + receipt->device_state0.preview_state = zapp_get_gstate()->is_preview; + receipt->device_state0.low_battery = (BatteryMgrService_get_battery_level() < APP_LOW_BATTERY_WARNING_LIMIT); + receipt->device_state0.full_storge = false; - // 停止采样 - hwss_stop_capture(); - // 关闭文件 - sample_data_mgr_close(m_cur_fd); - // 删除文件 - sample_data_mgr_delete_file(&sampledata_file_name); - // 切换到采集出错页面 - dsp_mgr_change_to_samplingError(); - BoardBeepCtrl_setEffect(kBoardBeepEffect_threeShortBeep); - ds_change_to_state(kdevice_state_sampling_error); - } - } + receipt->device_state1 = 0; + receipt->powerlevel = BatteryMgrService_get_battery_level(); + receipt->storage_item_num = 0; + zdatachannel_data_send2(bletxbuf, sendlen); } - /******************************************************************************* - * 采样完成页面 * - *******************************************************************************/ - else if (ds_now_state() == kdevice_state_sampling_complete) { - if (ds_cur_state_haspassed_ms() >= 3000) { - ZLOGI("ds_cur_state_haspassed_ms() %d> 3000", ds_cur_state_haspassed_ms()); - ds_change_to_state(kdevice_state_home); - ble_cmder_report_sample_finish_event(); - } - } - /******************************************************************************* - * 采样错误页面 * - *******************************************************************************/ - else if (ds_now_state() == kdevice_state_sampling_error) { - if ((ds_cur_state_haspassed_ms() >= 3000) || // - (ds_cur_state_haspassed_ms() >= 1000 && hwss_lead_get_state_connected_state())) { - ZLOGI("ds_cur_state_haspassed_ms() %d> 3000", ds_cur_state_haspassed_ms()); - ds_change_to_state(kdevice_state_home); - ble_cmder_report_sample_finish_event(); - } - } - - /****************************************************************************************************************** - * 测试模式 * - ******************************************************************************************************************/ - - else if (ds_now_state() == kdevice_state_test_mode) { - /** - * @brief 测试模式下永远不退出,当前模式 - */ - - if (p_event->eventType == kevent_capture_little_data_block_event) { - ble_cmder_try_report_one_sample_data(p_event); - } + /*********************************************************************************************************************** + * 测试指令 * + ***********************************************************************************************************************/ + // void hwss_start_capture(void); + // void hwss_start_prepare_capture(void); + // void hwss_stop_capture(void); + + // void hwss_subic_write_reg(uint8_t addr, uint8_t val); + // uint8_t hwss_subic_read_reg(uint8_t addr); + + // else if (cmd == ify_hrs_test_cmd_start_capture) { + // hwss_start_prepare_capture(); + // hwss_start_capture(); + // send_success_receipt(rxheader, 0); + // } else if (cmd == ify_hrs_test_cmd_stop_capture) { + // hwss_stop_capture(); + // send_success_receipt(rxheader, 0); + // } else if (cmd == ify_hrs_test_cmd_read_reg) { + // uint8_t regadd = rxheader->data[0]; + // uint8_t regval = hwss_subic_read_reg(regadd); + // txheader->data[0] = regval; + // send_success_receipt(rxheader, 1); + // } else if (cmd == ify_hrs_test_cmd_write_reg) { + // uint8_t regadd = rxheader->data[0]; + // uint8_t regval = rxheader->data[1]; + // hwss_subic_write_reg(regadd, regval); + // send_success_receipt(rxheader, 0); + // } + // + else { + send_error_receipt(rxheader, kifyhrs_ecode_cmd_not_support); } } -/******************************************************************************* - * MAIN_CODE * - *******************************************************************************/ - -void one_conduction_main() { - ZLOGI("one_conduction_main"); - AppEvent_regListener(app_event_listener); - app_board_init(); - BoardBeepCtrl_init(); - BoardLight_Init(); - /** - * @brief 服务初始化 - */ - hwss_init(); - ds_init(on_state_change); - - ds_change_to_state(kdevice_state_test_mode); - znordic_loop(); -} +void one_conduction_main() { ZLOGI("one_conduction_main"); } diff --git a/app/src/one_conduction_main.h b/app/src/one_conduction_main.h index e245aa9..2323c0c 100644 --- a/app/src/one_conduction_main.h +++ b/app/src/one_conduction_main.h @@ -1,4 +1,5 @@ #pragma once - +#include void one_conduction_main(); +void one_conduction_process_rx_packet(uint8_t* rx, int len); diff --git a/app/src/service/ble_cmd_processer/ble_cmd_process_service.c b/app/src/service/ble_cmd_processer/ble_cmd_process_service.c deleted file mode 100644 index 903749c..0000000 --- a/app/src/service/ble_cmd_processer/ble_cmd_process_service.c +++ /dev/null @@ -1,503 +0,0 @@ -#include "ble_cmd_process_service.h" - -#include "aproject_config/config.h" -// -#include "ify_hrs_protocol/heart_rate_sensor_protocol.h" -// -#include "basic_service/device_version_info_mgr.h" -#include "board/board_battery_state.h" -#include "board/board_ecg_sensor.h" -#include "service/storage/storage_service.h" -// -#include "zble_module.h" -#include "zdatachannel_service.h" - -APP_TIMER_DEF(m_record_upload_tmr); // 数据上报定时器 -APP_TIMER_DEF(m_record_upload_finish_packet_report_tmr); // 数据上报完成上报定时器 -static uint8_t txbuf[250]; -static uint8_t reportbuf[250]; -static int m_upload_record_state = 0; -static uint32_t m_upload_data_state_enter_tp = 0; - -static bool m_ble_cmder_is_inited = false; -static uint32_t m_report_data_sumcheckcode = 0; - -static void record_upload_tmr_cb(void* p_context); -static void record_upload_finish_packet_report_tmr_cb(void* p_context); -int ble_stop_upload_record(); -/******************************************************************************* - * 广播控制 * - *******************************************************************************/ -void ble_cmder_start_adv() { - global_state_set_preview_state(false); - zble_module_start_adv(); -} -void ble_cmder_stop_adv() { - zble_module_stop_adv(); - global_state_set_preview_state(false); -} - -/******************************************************************************* - * 模块初始化 * - *******************************************************************************/ -void ble_cmder_init() { - if (!m_ble_cmder_is_inited) { - ZERROR_CHECK(app_timer_create(&m_record_upload_tmr, APP_TIMER_MODE_REPEATED, record_upload_tmr_cb)); - ZERROR_CHECK(app_timer_create(&m_record_upload_finish_packet_report_tmr, APP_TIMER_MODE_SINGLE_SHOT, record_upload_finish_packet_report_tmr_cb)); - } - m_ble_cmder_is_inited = true; -} -void ble_cmder_uninit() {} - -/******************************************************************************* - * 实时上报控制 * - *******************************************************************************/ - -void ble_cmder_try_report_one_sample_data(app_event_t* event) { - heartrate_report_packet_t* reportpacket = (heartrate_report_packet_t*)reportbuf; - reportpacket->cmd = ify_hrs_report_heartrate_data; - reportpacket->frame_index = 0; - reportpacket->frame_type = kifyhrs_pt_report; - reportpacket->sample_data_index = event->val.little_data_block.frameIndex; - - for (int i = 0; i < LITTLE_DATA_BLOCK_FRAME_NUM; i++) { - reportpacket->data[i * 4] = (event->val.little_data_block.data[i] >> 0) & 0xFF; - reportpacket->data[i * 4 + 1] = (event->val.little_data_block.data[i] >> 8) & 0xFF; - reportpacket->data[i * 4 + 2] = (event->val.little_data_block.data[i] >> 16) & 0xFF; - reportpacket->data[i * 4 + 3] = (event->val.little_data_block.data[i] >> 24) & 0xFF; - } - reportpacket->data[LITTLE_DATA_BLOCK_FRAME_NUM * 4] = (event->val.little_data_block.timestamp >> 0) & 0xFF; - reportpacket->data[LITTLE_DATA_BLOCK_FRAME_NUM * 4 + 1] = (event->val.little_data_block.timestamp >> 8) & 0xFF; - reportpacket->data[LITTLE_DATA_BLOCK_FRAME_NUM * 4 + 2] = (event->val.little_data_block.timestamp >> 16) & 0xFF; - reportpacket->data[LITTLE_DATA_BLOCK_FRAME_NUM * 4 + 3] = (event->val.little_data_block.timestamp >> 24) & 0xFF; - - STATIC_ASSERT(sizeof(one_frame_t) == 4); - - // reportpacket->data[2] = (data1 >> 0) & 0xFF; // 第二帧数据 - // reportpacket->data[3] = (data1 >> 8) & 0xFF; // 第二帧数据 - // reportpacket->data[4] = (data2 >> 0) & 0xFF; // 第三帧数据 - // reportpacket->data[5] = (data2 >> 8) & 0xFF; // 第三帧数据 - // reportpacket->data[6] = (data3 >> 0) & 0xFF; // 第四帧数据 - // reportpacket->data[7] = (data3 >> 8) & 0xFF; // 第四帧数据 - // reportpacket->data[8] = (data4 >> 0) & 0xFF; // 第五帧数据 - // reportpacket->data[9] = (data4 >> 8) & 0xFF; // 第五帧数据 - - uint16_t sendlen = sizeof(heartrate_report_packet_t) + LITTLE_DATA_BLOCK_FRAME_NUM * 4 + 4; - zdatachannel_data_send2(reportbuf, sendlen); - return; -} - -void ble_cmder_try_report_sensor_drop_event(uint8_t dropstate0, uint8_t dropstate1) { - sensor_drop_event_report_packet_t* reportpacket = (sensor_drop_event_report_packet_t*)reportbuf; - reportpacket->cmd = ify_hrs_report_sensor_drop_detect; - reportpacket->frame_index = 0; - reportpacket->frame_type = kifyhrs_pt_report; - reportpacket->drop_state0 = dropstate0; - reportpacket->drop_state1 = dropstate1; - - uint16_t sendlen = sizeof(sensor_drop_event_report_packet_t); - zdatachannel_data_send2(reportbuf, sendlen); - return; -} -void ble_cmder_report_upload_finish_event(uint32_t sumcheckcode) { - ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)txbuf; - uint16_t sendlen = sizeof(ify_hrs_packet_t) + 4; - - txheader->cmd = ify_hrs_report_record_upload_end; // 6A - txheader->frame_index = 0; - txheader->frame_type = kifyhrs_pt_report; - - // txheader->data[0] = errorcode; - *(uint32_t*)txheader->data = sumcheckcode; - - zdatachannel_data_send2(txbuf, sendlen); - return; -} - -void ble_cmder_report_sample_finish_event() { - ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)txbuf; - uint16_t sendlen = sizeof(ify_hrs_packet_t); - - txheader->cmd = ify_hrs_report_sample_finish_end; - txheader->frame_index = 0; - txheader->frame_type = kifyhrs_pt_report; - - zdatachannel_data_send2(txbuf, sendlen); - return; -} - -/******************************************************************************* - * 上传数据控制 * - *******************************************************************************/ -static int m_upload_fd; -static uint8_t datacache[256]; -static int m_remaindatalen = 0; -/** - * @brief 数据上报定时器回调 - * - * @param p_context - */ -static void record_upload_finish_packet_report_tmr_cb(void* p_context) { // - ble_cmder_report_upload_finish_event(m_report_data_sumcheckcode); -} - -static void record_upload_tmr_cb(void* p_context) { // - - if (m_upload_record_state == 0) return; - - if (m_upload_record_state == 1) { - if (m_remaindatalen == 0) { - memset(datacache, 0, sizeof(datacache)); - int32_t rdsize = sample_data_mgr_read(m_upload_fd, datacache, sizeof(datacache)); - if (rdsize <= 0) { - ZLOGI("read file end,stop upload"); - m_upload_record_state = 2; - m_upload_data_state_enter_tp = znordic_getpower_on_ms(); - return; - } - m_remaindatalen = rdsize; - } - if (m_remaindatalen == 0) { - return; - } - - int32_t mtusize = zble_module_get_mtu_size(); - mtusize = mtusize < 128 ? mtusize : 128; - - uint8_t* data = datacache + (sizeof(datacache) - m_remaindatalen); - int len = m_remaindatalen > mtusize ? mtusize : m_remaindatalen; - - ZLOGI("upload %d %d %d", len, m_remaindatalen, mtusize); - if (!zdatachannel_is_connected()) { - ZLOGI("ble is disconnected,stop upload"); - ble_stop_upload_record(); - return; - } - - uint32_t suc = zdatachannel_block_data_send2(data, len); - if (suc != NRF_SUCCESS) { - if (suc == NRF_ERROR_INVALID_STATE) { - // 未使能notify - ZLOGI("ble unenable notify,stop upload"); - ble_stop_upload_record(); - return; - } else if (suc == NRF_ERROR_BUSY || suc == NRF_ERROR_RESOURCES) { - // 等待下次发送 - return; - } else { - ZLOGI("ble send error,stop upload %x", suc); - ble_stop_upload_record(); - return; - } - } - for (uint32_t i = 0; i < len; i++) { - m_report_data_sumcheckcode += data[i]; - } - m_remaindatalen -= len; - } else { - if (znordic_haspassed_ms(m_upload_data_state_enter_tp) > 30) { - ble_cmder_report_upload_finish_event(m_report_data_sumcheckcode); - ble_stop_upload_record(); - return; - } - } -} - -int ble_start_upload_record(sample_data_filename_t* recordid) { - // - // 启动 - // - if (ds_now_state() != kdevice_state_home && ds_now_state() != kdevice_state_charging) { - return kifyhrs_ecode_device_busy; - } - - m_upload_fd = sample_data_mgr_open(recordid, kwrflag_read_only); - if (m_upload_fd <= 0) { - return kifyhrs_ecode_no_record_find; - } - - ZERROR_CHECK(app_timer_start(m_record_upload_tmr, APP_TIMER_TICKS(15), NULL)); - m_upload_record_state = 1; - m_remaindatalen = 0; - m_report_data_sumcheckcode = 0; - return 0; -} -int ble_stop_upload_record() { - m_upload_record_state = 0; - app_timer_stop(m_record_upload_tmr); - if (m_upload_fd > 0) { - sample_data_mgr_close(m_upload_fd); - m_upload_fd = 0; - } - return 0; -} -bool ble_is_upload_record() { return m_upload_record_state != 0; } - -/******************************************************************************* - * UTILS * - *******************************************************************************/ -static void send_error_receipt(ify_hrs_packet_t* rxpacket, int32_t errorcode) { - ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)txbuf; - error_receipt_t* receipt = (error_receipt_t*)txheader->data; - uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(error_receipt_t); - - txheader->cmd = rxpacket->cmd; - txheader->frame_index = rxpacket->frame_index; - txheader->frame_type = kifyhrs_pt_error_receipt; - receipt->errorcode = errorcode; - zdatachannel_data_send2(txbuf, sendlen); -} - -static void send_success_receipt(ify_hrs_packet_t* rxpacket, int32_t emptydatasize) { - ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)txbuf; - uint16_t sendlen = sizeof(ify_hrs_packet_t) + emptydatasize; - - txheader->cmd = rxpacket->cmd; - txheader->frame_index = rxpacket->frame_index; - txheader->frame_type = kifyhrs_pt_cmd_receipt; - - zdatachannel_data_send2(txbuf, sendlen); -} - -/******************************************************************************* - * 下发消息处理 * - *******************************************************************************/ -void ble_cmder_process_rx(uint8_t* rx, int len) { - if (len < sizeof(ify_hrs_packet_t)) { - ZLOGI("rx len error:%d", len); - return; - } - - ify_hrs_packet_t* rxheader = (ify_hrs_packet_t*)rx; - ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)txbuf; - ify_hrs_cmd_t cmd = (ify_hrs_cmd_t)rxheader->cmd; - memset(txbuf, 0, sizeof(txbuf)); - - txheader->cmd = rxheader->cmd; - txheader->frame_index = rxheader->frame_index; - txheader->frame_type = kifyhrs_pt_cmd_receipt; - - ZLOGI("rx cmd:%d index:%d datalen:%d", cmd, rxheader->frame_index, len - sizeof(ify_hrs_packet_t)); - NRF_LOG_HEXDUMP_INFO(rx, len); - - if (cmd == ify_hrs_cmd_read_device_version) { - device_version_info_receipt_t* receipt = (device_version_info_receipt_t*)txheader->data; - uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(device_version_info_receipt_t); - - receipt->blestack_version = device_info_read_blestack_version(); - receipt->bootloader_version = device_info_read_bootloader_version(); - receipt->firmware_version = device_info_read_firmware_version(); - receipt->hardware_version = device_info_read_hardware_version(); - zdatachannel_data_send2(txbuf, sendlen); - } - - else if (cmd == ify_hrs_cmd_read_sensor_info) { - sensor_info_receipt_t* receipt = (sensor_info_receipt_t*)txheader->data; - uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(sensor_info_receipt_t); - - receipt->sensor_num = 1; - receipt->sensor_precision = SAMPLE_PRECISION; - receipt->sensor_sample_rate = SAMPLE_RATE / 10; - receipt->sensor0_pos = kifyhrs_sensor_pos_none; - receipt->sensor1_pos = kifyhrs_sensor_pos_none; - receipt->sensor2_pos = kifyhrs_sensor_pos_none; - - zdatachannel_data_send2(txbuf, sendlen); - } - - else if (cmd == ify_hrs_cmd_read_device_state) { - device_state_receipt_t* receipt = (device_state_receipt_t*)txheader->data; - uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(device_state_receipt_t); - - receipt->drop_state0 = (0); - receipt->drop_state1 = 0x00; - receipt->device_state0.sampling_state = (ds_now_state() == kdevice_state_sampling); - receipt->device_state0.report_state = global_state_get()->preivew_state; - receipt->device_state0.low_battery = (BoardBattery_get_battery_level() < APP_LOW_BATTERY_WARNING_LIMIT); - receipt->device_state0.full_storge = (sample_data_mgr_storage_is_full()); - - receipt->device_state1 = 0; - receipt->powerlevel = BoardBattery_get_battery_level(); - receipt->storage_item_num = sample_data_mgr_get_file_num(); - - zdatachannel_data_send2(txbuf, sendlen); - } - - else if (cmd == ify_hrs_cmd_read_time) { - read_time_receipt_t* receipt = (read_time_receipt_t*)txheader->data; - uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(read_time_receipt_t); - static ztm_t ztm; - znordic_rtc_gettime(&ztm); - - receipt->year = (ztm.tm_year + 1900 - 2000); - receipt->month = ztm.tm_mon + 1; - receipt->day = ztm.tm_mday; - receipt->hour = ztm.tm_hour; - receipt->minute = ztm.tm_min; - receipt->second = ztm.tm_sec; - zdatachannel_data_send2(txbuf, sendlen); - } - - else if (cmd == ify_hrs_cmd_sync_time) { - sync_time_cmd_t* cmd = (sync_time_cmd_t*)rxheader->data; - uint16_t sendlen = sizeof(ify_hrs_packet_t); - - znordic_rtc_settime(cmd->year + 2000, cmd->month, cmd->day, cmd->hour, cmd->minute, cmd->second); - zdatachannel_data_send2(txbuf, sendlen); - } - - else if (cmd == ify_hrs_cmd_start_upload_record) { - send_error_receipt(rxheader, kifyhrs_ecode_cmd_not_support); - } - - else if (cmd == ify_hrs_cmd_stop_upload_record) { - send_error_receipt(rxheader, kifyhrs_ecode_cmd_not_support); - } - - else if (cmd == ify_hrs_cmd_start_realtime_preview) { - global_state_set_preview_state(true); - send_success_receipt(rxheader, 0); - } - - else if (cmd == ify_hrs_cmd_stop_realtime_preview) { - global_state_set_preview_state(false); - send_success_receipt(rxheader, 0); - } - - else if (cmd == ify_hrs_cmd_read_records_info) { - // 指令 10-读取采样记录头部信息 - read_record_info_cmd_t* cmd = (read_record_info_cmd_t*)rxheader->data; - read_record_info_receipt_t* receipt = (read_record_info_receipt_t*)txheader->data; - uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(read_record_info_receipt_t); - - uint8_t recordoff = cmd->record_index; - - // 采样时不支持 - if (ds_now_state() != kdevice_state_home) { - send_error_receipt(rxheader, kifyhrs_ecode_device_busy); - return; - } - - sample_data_fileinfo_list_t* recordlist = sample_data_mgr_get_fileinfo_list(); - if (recordoff >= recordlist->count) { - send_error_receipt(rxheader, kifyhrs_ecode_no_record_find); - return; - } - - sample_data_fileinfo_t* fileinfo = recordlist->fileinfo[recordoff]; - memcpy(receipt->record_id, fileinfo->filename, 6); - receipt->frameNum = fileinfo->size / 2; // 2byte per frame - receipt->dataSize = fileinfo->size; - receipt->sensorNum = 1; - receipt->captureRate = SAMPLE_RATE / 10; - receipt->capturePrecision = SAMPLE_PRECISION; - receipt->compressAlgorithm = 0; - receipt->checksum = fileinfo->checksum; - zdatachannel_data_send2(txbuf, sendlen); - - } - - else if (cmd == ify_hrs_cmd_del_record) { - // 指令 11-删除采样记录 - del_record_cmd_t* cmd = (del_record_cmd_t*)rxheader->data; - - static sample_data_filename_t filename; - memset(&filename, 0, sizeof(filename)); - memcpy(&filename, cmd->record_id, sizeof(cmd->record_id)); - - // 采样时不支持 - if (ds_now_state() != kdevice_state_home) { - send_error_receipt(rxheader, kifyhrs_ecode_device_busy); - return; - } - - int ecode = sample_data_mgr_delete_file(&filename); - if (ecode == 0) { - send_success_receipt(rxheader, 0); - } else { - send_error_receipt(rxheader, kifyhrs_ecode_unkown_error); - } - } - - else if (cmd == ify_hrs_cmd_start_upload_record) { // 12 0x0C - // 指令 12-上传采集记录 - start_upload_record_cmd_t* cmd = (start_upload_record_cmd_t*)rxheader->data; - - static sample_data_filename_t filename; - memset(&filename, 0, sizeof(filename)); - memcpy(&filename, cmd->record_id, sizeof(cmd->record_id)); - - // 采样时不支持 - if (ds_now_state() != kdevice_state_home) { - send_error_receipt(rxheader, kifyhrs_ecode_device_busy); - return; - } - - int ecode = ble_start_upload_record(&filename); - if (ecode == 0) { - ify_hrs_packet_t* txheader = (ify_hrs_packet_t*)txbuf; - uint16_t sendlen = sizeof(ify_hrs_packet_t) + 1; // 凑齐4BYTE,方便调试 - txheader->cmd = rxheader->cmd; - txheader->frame_index = rxheader->frame_index; - txheader->frame_type = kifyhrs_pt_cmd_receipt; - - zdatachannel_data_send2(txbuf, sendlen); - } else { - send_error_receipt(rxheader, ecode); - } - } - - else if (cmd == ify_hrs_cmd_stop_upload_record) { - ble_stop_upload_record(); - send_success_receipt(rxheader, 0); - } - - else if (cmd == ify_hrs_cmd_enter_ota) { - send_error_receipt(rxheader, kifyhrs_ecode_cmd_not_support); - } - - else if (cmd == ify_hrs_cmd_read_sn) { - read_sn_receipt_t* receipt = (read_sn_receipt_t*)txheader->data; - uint16_t sendlen = sizeof(ify_hrs_packet_t) + sizeof(read_sn_receipt_t); - device_info_read_sn((sn_t*)&receipt->sn); - zdatachannel_data_send2(txbuf, sendlen); - } - - else if (cmd == ify_hrs_cmd_reset) { - NVIC_SystemReset(); - } - - /*********************************************************************************************************************** - * 测试指令 * - ***********************************************************************************************************************/ - - // void hwss_start_capture(void); - // void hwss_start_prepare_capture(void); - // void hwss_stop_capture(void); - - // void hwss_subic_write_reg(uint8_t addr, uint8_t val); - // uint8_t hwss_subic_read_reg(uint8_t addr); - - // else if (cmd == ify_hrs_test_cmd_start_capture) { - // hwss_start_prepare_capture(); - // hwss_start_capture(); - // send_success_receipt(rxheader, 0); - // } else if (cmd == ify_hrs_test_cmd_stop_capture) { - // hwss_stop_capture(); - // send_success_receipt(rxheader, 0); - // } else if (cmd == ify_hrs_test_cmd_read_reg) { - // uint8_t regadd = rxheader->data[0]; - // uint8_t regval = hwss_subic_read_reg(regadd); - // txheader->data[0] = regval; - // send_success_receipt(rxheader, 1); - // } else if (cmd == ify_hrs_test_cmd_write_reg) { - // uint8_t regadd = rxheader->data[0]; - // uint8_t regval = rxheader->data[1]; - // hwss_subic_write_reg(regadd, regval); - // send_success_receipt(rxheader, 0); - // } - // - else { - send_error_receipt(rxheader, kifyhrs_ecode_cmd_not_support); - } -} diff --git a/app/src/service/ble_cmd_processer/ble_cmd_process_service.h b/app/src/service/ble_cmd_processer/ble_cmd_process_service.h deleted file mode 100644 index ce20220..0000000 --- a/app/src/service/ble_cmd_processer/ble_cmd_process_service.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "basic_service/device_state.h" - -void ble_cmder_init(); -void ble_cmder_uninit(); - -void ble_cmder_process_rx(uint8_t* rx, int len); -void ble_cmder_start_adv(); -void ble_cmder_stop_adv(); - -void ble_cmder_try_report_one_sample_data(app_event_t* event); -void ble_cmder_try_report_sensor_drop_event(uint8_t dropstate0, uint8_t dropstate1); -void ble_cmder_report_upload_finish_event(uint32_t sumcheckcode); -void ble_cmder_report_sample_finish_event(); -bool ble_is_upload_record(); -int ble_stop_upload_record(); diff --git a/app/src/service/display_mgr/display_manager.c b/app/src/service/display_mgr/display_manager.c deleted file mode 100644 index a886363..0000000 --- a/app/src/service/display_mgr/display_manager.c +++ /dev/null @@ -1,443 +0,0 @@ -#include "display_manager.h" - -#include "../../../screen_res/logo_mono.c" -// -#include - -#include "board/board_battery_state.h" -#include "board/board_ssd1306_interface.h" -#include "aproject_config/config.h" -#include "font.h" -PageState_t g_pageState; - -void dsp_mgr_change_to_page(page_t page) { // - g_pageState.page = page; - g_pageState.last_page = page; - g_pageState.page_change_to_page_time = znordic_getpower_on_s(); - - g_pageState.in_prompt = false; - memset(g_pageState.prompt, 0, sizeof(g_pageState.prompt)); -} - -uint32_t dsp_mgr_get_page_elapsed_time_s(void) { // - return znordic_getpower_on_s() - g_pageState.page_change_to_page_time; -} - -void dsp_mgr_schedule(void) {} - -PageState_t* dsp_mgr_get_state(void) { return NULL; } - -int compute_x_pos_by_center(int16_t x, int16_t width) { return x - width / 2; } -int compute_y_pos_by_center(int16_t y, int16_t height) { return y - height / 2; } - -#define SCREEN_CENTER_X 64 -#define SCREEN_CENTER_Y 32 - -#define CHARGE_BATTERY_WIDTH (12 * 1.2) -#define CHARGE_BATTERY_HEIGHT (22 * 1.2) - -#define MAIN_PAGE_BATTERY_WIDTH (12) // 首页电池宽度 -#define MAIN_PAGE_BATTERY_HEIGHT (22) // 首页电池高度 - -/******************************************************************************* - * 充电页面 * - *******************************************************************************/ -/** - * 显示元素: - * 1.电池电量 - * --------------- - * | _ | - * | | | | - * | | - * --------------- - * - * 动画效果: - * 1. 电池电量变化 - * - */ - -static uint32_t m_nowshowbatterylevel; // 当前显示的电池电量 - -void dsp_mgr_change_to_chargingPage() { - ssd1306_basic_clear(); - uint8_t x = compute_x_pos_by_center(SCREEN_CENTER_X, CHARGE_BATTERY_WIDTH); - uint8_t y = compute_y_pos_by_center(SCREEN_CENTER_Y, CHARGE_BATTERY_HEIGHT); - uint8_t xchange, ychange; - ssd1306_basic_draw_battery_level(x, y, &xchange, &ychange, BoardBattery_get_battery_level(), CHARGE_BATTERY_WIDTH, CHARGE_BATTERY_HEIGHT); - m_nowshowbatterylevel = BoardBattery_get_battery_level(); - ssd1306_basic_gram_update(); - dsp_mgr_change_to_page(kPage_chargingPage); -} - -void chargingPage_set_batteryLevel(int batteryLevel) { - uint8_t x = compute_x_pos_by_center(SCREEN_CENTER_X, CHARGE_BATTERY_WIDTH); - uint8_t y = compute_y_pos_by_center(SCREEN_CENTER_Y, CHARGE_BATTERY_HEIGHT); - uint8_t xchange, ychange; - ssd1306_basic_draw_battery_level(x, y, &xchange, &ychange, batteryLevel, CHARGE_BATTERY_WIDTH, CHARGE_BATTERY_HEIGHT); - ssd1306_basic_gram_update(); -} - -void chargingPage_schedule() { // - static uint32_t last_update_time = 0; - if (znordic_haspassed_ms(last_update_time) < 300) { - return; - } - - last_update_time = znordic_getpower_on_ms(); - m_nowshowbatterylevel += 5; - if (m_nowshowbatterylevel > 100) { - m_nowshowbatterylevel = BoardBattery_get_battery_level(); - } - chargingPage_set_batteryLevel(m_nowshowbatterylevel); -} - -/******************************************************************************* - * 欢迎页面 * - *******************************************************************************/ -void dsp_mgr_change_to_welcome() { - /** - * @brief 切换到欢迎界面 - * 1. 加载屏幕外设 - * 2. 打开屏幕电源 - * 3. 初始化开机页面 - */ - - // ssd1306_basic_string(0, 0, "123456789123456789123", 21, 0, SSD1306_FONT_12); - ssd1306_basic_draw_screen((const char*)gImage_logo_mono); - ssd1306_basic_gram_update(); - dsp_mgr_change_to_page(kPage_welcome); -} - -void welcomePage_schedule() {} - -/******************************************************************************* - * 首页 * - *******************************************************************************/ -static bool m_main_page_colon_state = false; - -void mainPage_show(bool colon_state) { - static ztm_t now; - int16_t batterylevel; - uint8_t xchange, ychange; - uint8_t x, y; - x = compute_x_pos_by_center(SCREEN_CENTER_X, fontclocklib.widthPixel * 5 + MAIN_PAGE_BATTERY_WIDTH); - y = compute_y_pos_by_center(SCREEN_CENTER_Y, fontclocklib.heightPixel + 1); - znordic_rtc_gettime(&now); - batterylevel = BoardBattery_get_battery_level(); - - ssd1306_basic_clear_gram(); - - // ZLOGI("mainPage_show %d %d", colon_state, x, y); - - ssd1306_basic_draw_str(x, y, &xchange, &ychange, fmt("%02d:%02d", now.tm_hour, now.tm_min), &fontclocklib); - x = x + 6 + xchange; - ssd1306_basic_draw_battery_level(x, y, &xchange, &ychange, batterylevel, MAIN_PAGE_BATTERY_WIDTH, MAIN_PAGE_BATTERY_HEIGHT); - ssd1306_basic_gram_update(); - m_main_page_colon_state = colon_state; - dsp_mgr_change_to_page(kPage_main); -} - -void dsp_mgr_change_to_main() { mainPage_show(true); } -void mainPage_updateState() { mainPage_show(!m_main_page_colon_state); } -void mainPage_schedule() { - static uint32_t last_update_time = 0; - if (znordic_haspassed_ms(last_update_time) < 300) { - return; - } - last_update_time = znordic_getpower_on_ms(); - mainPage_updateState(); -} - -/******************************************************************************* - * 保持静止页面 * - *******************************************************************************/ -static int m_prepare_page_progress = 0; -void PreparePage_show(int progress) { - m_prepare_page_progress = progress; - ssd1306_basic_clear_gram(); - uint8_t x = 0; - uint8_t y = 0; - uint8_t xchange, ychange; - - x = compute_x_pos_by_center(SCREEN_CENTER_X, font24x24_zh_lib.widthPixel * 4); - y = compute_y_pos_by_center(SCREEN_CENTER_Y, font24x24_zh_lib.heightPixel); - - ssd1306_basic_draw_str(x, y, &xchange, &ychange, "保持静止", &font24x24_zh_lib); - - if (progress == 0) { - ssd1306_basic_draw_str(x - font8x8_xo_lib.widthPixel, y - font8x8_xo_lib.heightPixel, &xchange, &ychange, "xxxx", &font8x8_xo_lib); - } else if (progress == 1) { - ssd1306_basic_draw_str(x - font8x8_xo_lib.widthPixel, y - font8x8_xo_lib.heightPixel, &xchange, &ychange, "oxxx", &font8x8_xo_lib); - } else if (progress == 2) { - ssd1306_basic_draw_str(x - font8x8_xo_lib.widthPixel, y - font8x8_xo_lib.heightPixel, &xchange, &ychange, "ooxx", &font8x8_xo_lib); - } else if (progress == 3) { - ssd1306_basic_draw_str(x - font8x8_xo_lib.widthPixel, y - font8x8_xo_lib.heightPixel, &xchange, &ychange, "ooox", &font8x8_xo_lib); - } else if (progress == 4) { - ssd1306_basic_draw_str(x - font8x8_xo_lib.widthPixel, y - font8x8_xo_lib.heightPixel, &xchange, &ychange, "oooo", &font8x8_xo_lib); - } - - ssd1306_basic_gram_update(); -} - -void dsp_mgr_change_to_preparePage() { - PreparePage_show(0); - dsp_mgr_change_to_page(kPage_preparePage); -} -void dsp_mgr_preparePage_set_progress(int progress) { PreparePage_show(progress); } -int dsp_mgr_preparePage_get_progress() { return m_prepare_page_progress; } - -void PreparePage_schedule() {} - -/******************************************************************************* - * 采样页面 * - *******************************************************************************/ - -#define SMAPLE_PAGE_START_X 1 -#define SMAPLE_PAGE_START_Y 1 - -typedef struct { - wave_drawer_t wave_drawer; - - int wave_drawser_x; - int wave_drawser_y; - int wave_drawser_hight; - int wave_drawser_width; - - int progress_x; - int progress_y; - - int progress_width; - int progress_hight; - - int heartrate_x; - int heartrate_y; -} sample_page_state_t; -sample_page_state_t m_sample_page_state; -#if 0 -void dsp_mgr_change_to_sampling(int progress_s, int heartrate) { // - sample_page_state_t* sps = &m_sample_page_state; - - sps->wave_drawser_x = SMAPLE_PAGE_START_X; - sps->wave_drawser_y = SMAPLE_PAGE_START_Y; - sps->wave_drawser_hight = 40; - sps->wave_drawser_width = 120; - - sps->progress_x = SMAPLE_PAGE_START_X + 1; - sps->progress_y = SMAPLE_PAGE_START_Y + sps->wave_drawser_hight + 3 + 4; - sps->progress_width = 80; - sps->progress_hight = 8; - - sps->heartrate_x = sps->progress_x + sps->progress_width + 2; - sps->heartrate_y = sps->progress_y - 4; - - int progress = progress_s / SAMPLE_MIN_TIME_S * 25; - - ssd1306_basic_clear_gram(); - - wave_drawer_init(&sps->wave_drawer, sps->wave_drawser_x, sps->wave_drawser_y, sps->wave_drawser_width, sps->wave_drawser_hight); - wave_drawer_draw_border(&sps->wave_drawer); - uint8_t xchange, ychange; - ssd1306_basic_draw_progress(sps->progress_x, sps->progress_y, sps->progress_width, sps->progress_hight, 25, progress); - if (heartrate <= 0) { - ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y, &xchange, &ychange, "<>-- ", &font_asicc16x8_lib); - } else { - ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y, &xchange, &ychange, fmt("<>%3d", heartrate), &font_asicc16x8_lib); - } - ssd1306_basic_gram_update(); - dsp_mgr_change_to_page(kPage_sampling); -} - -void samplePage_update_state(int progress_s, int wave_y, int heartrate, bool update_screen) { // - - sample_page_state_t* sps = &m_sample_page_state; - uint8_t xchange, ychange; - - int progress = progress_s / SAMPLE_MIN_TIME_S * 25; - - if (progress_s / 10 == 0) { - ssd1306_basic_draw_str(sps->progress_x, sps->progress_y - 8, &xchange, &ychange, "xxx", &font8x8_xo_lib); - } else if (progress_s / 10 == 1) { - ssd1306_basic_draw_str(sps->progress_x, sps->progress_y - 8, &xchange, &ychange, "oxx", &font8x8_xo_lib); - } else if (progress_s / 10 == 2) { - ssd1306_basic_draw_str(sps->progress_x, sps->progress_y - 8, &xchange, &ychange, "oox", &font8x8_xo_lib); - } else if (progress_s / 10 == 3) { - ssd1306_basic_draw_str(sps->progress_x, sps->progress_y - 8, &xchange, &ychange, "ooo", &font8x8_xo_lib); - } - - wave_drawer_draw_next_point(&sps->wave_drawer, wave_y); - ssd1306_basic_draw_progress(sps->progress_x, sps->progress_y, sps->progress_width, sps->progress_hight, 25, progress); - if (heartrate <= 0) { - ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y, &xchange, &ychange, "<>-- ", &font_asicc16x8_lib); - } else { - ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y, &xchange, &ychange, fmt("<>%3d", heartrate), &font_asicc16x8_lib); - } - if (update_screen) ssd1306_basic_gram_update(); -} -#endif -void dsp_mgr_change_to_sampling(int progress_s, int heartrate) { // - sample_page_state_t* sps = &m_sample_page_state; - - sps->progress_x = SMAPLE_PAGE_START_X + 10; - sps->progress_y = SMAPLE_PAGE_START_Y + 3; - sps->progress_width = 100; - sps->progress_hight = 8; - - sps->wave_drawser_x = SMAPLE_PAGE_START_X + 5; - sps->wave_drawser_y = SMAPLE_PAGE_START_Y + sps->progress_hight + 5; - sps->wave_drawser_hight = 45; - sps->wave_drawser_width = 85; - - sps->heartrate_x = sps->wave_drawser_x + sps->wave_drawser_width + 1; - sps->heartrate_y = sps->wave_drawser_y + 5; - - int progress = progress_s / SAMPLE_MIN_TIME_S * 25; - uint8_t xchange, ychange; - - ssd1306_basic_clear_gram(); - /** - * @brief - * ================= - * | | 心 - * | wave | - * | | 心率 - */ - ssd1306_basic_draw_progress(sps->progress_x, sps->progress_y, sps->progress_width, sps->progress_hight, 25, progress); - // ssd1306_basic_draw_str(sps->progress_x + sps->progress_width + 2, sps->progress_y, &xchange, &ychange, "x", &font8x8_xo_lib); - - wave_drawer_init(&sps->wave_drawer, sps->wave_drawser_x, sps->wave_drawser_y, sps->wave_drawser_width, sps->wave_drawser_hight); - // wave_drawer_draw_border(&sps->wave_drawer); - - ssd1306_basic_draw_str(sps->heartrate_x + 2, sps->heartrate_y, &xchange, &ychange, "<>", &font_asicc16x8_lib); - ssd1306_basic_draw_str(sps->heartrate_x + 4, sps->heartrate_y + 20, &xchange, &ychange, "-- ", &font_asicc16x8_lib); - ssd1306_basic_gram_update(); - dsp_mgr_change_to_page(kPage_sampling); -} - -void samplePage_update_state(int progress_s, int wave_y, int heartrate, bool updateHeart, bool update_screen) { // - - sample_page_state_t* sps = &m_sample_page_state; - uint8_t xchange, ychange; - static bool heart_logo_state = false; - - int progress = progress_s / SAMPLE_MIN_TIME_S * 25; - - ssd1306_basic_draw_progress(sps->progress_x, sps->progress_y, sps->progress_width, sps->progress_hight, 25, progress); - // if (progress_s / 10 >= 3) { - // ssd1306_basic_draw_str(sps->progress_x + sps->progress_width + 2, sps->progress_y, &xchange, &ychange, "o", &font8x8_xo_lib); - // } else { - // ssd1306_basic_draw_str(sps->progress_x + sps->progress_width + 2, sps->progress_y, &xchange, &ychange, "x", &font8x8_xo_lib); - // } - if (update_screen && updateHeart) { - if (heart_logo_state) { - ssd1306_basic_draw_str(sps->heartrate_x + 2, sps->heartrate_y, &xchange, &ychange, "<>", &font_asicc16x8_lib); - } else { - ssd1306_basic_draw_str(sps->heartrate_x + 2, sps->heartrate_y, &xchange, &ychange, " ", &font_asicc16x8_lib); - } - heart_logo_state = !heart_logo_state; - } - - if (heartrate <= 0) { - ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y + 20, &xchange, &ychange, " ", &font_asicc16x8_lib); - ssd1306_basic_draw_str(sps->heartrate_x + 4, sps->heartrate_y + 20, &xchange, &ychange, "-- ", &font_asicc16x8_lib); - } else { - if (heartrate >= 100) { - ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y + 20, &xchange, &ychange, " ", &font_asicc16x8_lib); - ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y + 20, &xchange, &ychange, fmt("%d", heartrate), &font_asicc16x8_lib); - } else { - ssd1306_basic_draw_str(sps->heartrate_x, sps->heartrate_y + 20, &xchange, &ychange, " ", &font_asicc16x8_lib); - ssd1306_basic_draw_str(sps->heartrate_x + 4, sps->heartrate_y + 20, &xchange, &ychange, fmt("%d", heartrate), &font_asicc16x8_lib); - } - } - wave_drawer_draw_next_point(&sps->wave_drawer, wave_y); - if (update_screen) ssd1306_basic_gram_update(); -} - -void samplePage_schedule() { - static int count = 0; - count++; - int capturetime = hwss_has_captured_time_ms(); - int wave_y = (int)hwss_read_val(); - int heartrate = (int)hwss_read_heart_rate(); - // ZLOGI("samplePage_schedule %d %d %d", capturetime, wave_y, heartrate); - samplePage_update_state(capturetime / 1000, wave_y, hwss_read_heart_rate(), count % 30 == 0, count % 10 == 0); -} - -/******************************************************************************* - * samplingError * - *******************************************************************************/ -void dsp_mgr_change_to_samplingError() { - /** - * @brief - * 不足30秒[X] - */ - ssd1306_basic_clear_gram(); - - uint8_t x; - uint8_t y; - - x = compute_x_pos_by_center(SCREEN_CENTER_X, font24x24_zh_lib.widthPixel * 3 + font12x24_asiic_lib.widthPixel * 2); - y = compute_y_pos_by_center(SCREEN_CENTER_Y, font24x24_zh_lib.heightPixel); - - uint8_t xchange, ychange; - ssd1306_basic_draw_str(x, y, &xchange, &ychange, "不足", &font24x24_zh_lib); - x = x + xchange; - ssd1306_basic_draw_str(x, y, &xchange, &ychange, "30", &font12x24_asiic_lib); - x = x + xchange; - ssd1306_basic_draw_str(x, y, &xchange, &ychange, "秒", &font24x24_zh_lib); - x = x + xchange; - ssd1306_basic_gram_update(); - dsp_mgr_change_to_page(kPage_samplingError); -} - -void dsp_mgr_change_to_sampleSuc() { - /** - * @brief - * 1.进度条 - * 2.提示信息 - */ - ssd1306_basic_clear(); - uint8_t x = 0; - uint8_t y = 0; - - uint8_t xchange, ychange; - x = compute_x_pos_by_center(SCREEN_CENTER_X, font24x24_zh_lib.widthPixel * 4); - y = compute_y_pos_by_center(SCREEN_CENTER_Y, font24x24_zh_lib.heightPixel); - - ssd1306_basic_draw_str(x, y, &xchange, &ychange, "采集完成", &font24x24_zh_lib); - ssd1306_basic_gram_update(); - dsp_mgr_change_to_page(kPage_storagingSuc); -} - -/******************************************************************************* - * SCHEDULE * - *******************************************************************************/ - -APP_TIMER_DEF(m_dsp_mgr_schedule_tmr); -static void dsp_mgr_schedule_tmr_cb(void* p_context) { // - if (g_pageState.page == kPage_chargingPage) { - chargingPage_schedule(); - } else if (g_pageState.page == kPage_welcome) { - welcomePage_schedule(); - } else if (g_pageState.page == kPage_main) { - mainPage_schedule(); - } else if (g_pageState.page == kPage_preparePage) { - PreparePage_schedule(); - } else if (g_pageState.page == kPage_sampling) { - samplePage_schedule(); - } -} - -void dsp_mgr_init(void) { - static bool timer_inited = false; - board_screen_init(); - if (!timer_inited) { - ZERROR_CHECK(app_timer_create(&m_dsp_mgr_schedule_tmr, APP_TIMER_MODE_REPEATED, dsp_mgr_schedule_tmr_cb)); - } - // 此处周期决定采样一个页面显示的宽度 - ZERROR_CHECK(app_timer_start(m_dsp_mgr_schedule_tmr, APP_TIMER_TICKS(12), NULL)); - timer_inited = true; -} -void dsp_mgr_uninit(void) { - app_timer_stop(m_dsp_mgr_schedule_tmr); - board_screen_deinit(); -} diff --git a/app/src/service/display_mgr/display_manager.h b/app/src/service/display_mgr/display_manager.h deleted file mode 100644 index 0553b77..0000000 --- a/app/src/service/display_mgr/display_manager.h +++ /dev/null @@ -1,81 +0,0 @@ -#pragma once - -#include "znordic.h" -// -#include "app_timer.h" -#include "diskio_blkdev.h" -#include "ff.h" -#include "nrf_block_dev_sdc.h" -#include "nrf_delay.h" -#include "nrf_drv_pwm.h" -#include "nrf_drv_saadc.h" -#include "nrf_drv_twi.h" -#include "nrf_drv_wdt.h" -#include "nrf_gpio.h" - -/** - * @brief - * 页面流转 - * - * close <--------------------- - * | - * button ---> welcome ---> main ---> preparePage ---> sampling ---> storaging ---> storagingSuc - * ^ ---> samplingError | - * |-------------------------------------------| | - * |-----------------------------------------------------------| - * - */ - -typedef enum { - kPage_poweroff, - kPage_welcome, - kPage_main, - kPage_preparePage, - kPage_sampling, - kPage_samplingError, - kPage_storaging, - kPage_storagingSuc, - kPage_chargingPage, -} page_t; - -typedef struct { - /** - * @brief 页面状态 - */ - page_t page; // 当前页面 - page_t last_page; // 上一个页面 - uint32_t page_change_to_page_time; // 当前页面持续的时间 - - bool in_prompt; // 是否在提示状态 - char prompt[32]; // 提示内容 - - /** - * @brief - */ - -} PageState_t; - -void dsp_mgr_init(void); -void dsp_mgr_uninit(void); -void dsp_mgr_schedule(void); - -PageState_t* dsp_mgr_get_state(void); -uint32_t dsp_mgr_get_page_elapsed_time_s(void); - -void dsp_mgr_change_to_poweroff(); -void dsp_mgr_change_to_welcome(); -void dsp_mgr_change_to_main(); -void dsp_mgr_change_to_chargingPage(); - -// 保持静止页面 -void dsp_mgr_change_to_preparePage(); -void dsp_mgr_preparePage_set_progress(int progress); -int dsp_mgr_preparePage_get_progress(); - -// 采样中页面 -void dsp_mgr_change_to_sampling(int progress_s, int heartrate); - -// 采样出错页面 -void dsp_mgr_change_to_samplingError(); -// 采样成功页面 -void dsp_mgr_change_to_sampleSuc(); \ No newline at end of file diff --git a/app/src/service/display_mgr/font.h b/app/src/service/display_mgr/font.h deleted file mode 100644 index 179ea34..0000000 --- a/app/src/service/display_mgr/font.h +++ /dev/null @@ -1,275 +0,0 @@ -// https://www.23bei.com/tool-965.html - -#include -#if 0 -const uint8_t fontclocklib_code[] = { - 0x00, 0x00, 0x00, 0x00, 0x7F, 0x80, 0x01, 0xFF, 0xE0, 0x03, 0xFF, 0xF0, 0x07, 0x80, 0x78, 0x06, // - 0x00, 0x18, 0x04, 0x00, 0x08, 0x06, 0x00, 0x18, 0x07, 0x80, 0x78, 0x03, 0xFF, 0xF0, 0x01, 0xFF, // - 0xE0, 0x00, 0x7F, 0x80, // - 0x00, 0x00, 0x00, 0x02, 0x00, 0x10, 0x02, 0x00, 0x10, 0x02, 0x00, 0x10, 0x07, 0xFF, 0xF0, 0x0F, // - 0xFF, 0xF0, 0x0F, 0xFF, 0xF0, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, // - 0x00, 0x00, 0x00, 0x00, // - 0x03, 0x80, 0x70, 0x07, 0x80, 0xF0, 0x0D, 0x81, 0xB0, 0x08, 0x03, 0x30, 0x08, 0x06, 0x30, 0x08, // - 0x0C, 0x30, 0x0C, 0x38, 0x30, 0x0F, 0xF8, 0x30, 0x07, 0xF1, 0xF0, 0x03, 0xC1, 0xF0, 0x00, 0x00, // - 0x00, 0x00, 0x00, 0x00, // - 0x03, 0x81, 0xC0, 0x07, 0x81, 0xE0, 0x0F, 0x81, 0xF0, 0x08, 0x10, 0x10, 0x08, 0x10, 0x10, 0x0C, // - 0x30, 0x10, 0x0F, 0xF8, 0x30, 0x07, 0xEF, 0xF0, 0x03, 0xCF, 0xE0, 0x00, 0x03, 0xC0, 0x00, 0x00, // - 0x00, 0x00, 0x00, 0x00, // - 0x00, 0x06, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x3A, 0x00, 0x00, 0xE2, 0x00, 0x01, 0xC2, 0x10, 0x07, // - 0x02, 0x10, 0x0F, 0xFF, 0xF0, 0x1F, 0xFF, 0xF0, 0x1F, 0xFF, 0xF0, 0x00, 0x02, 0x10, 0x00, 0x02, // - 0x10, 0x00, 0x00, 0x00, // - 0x00, 0x01, 0xC0, 0x0F, 0xF9, 0xE0, 0x0F, 0xF9, 0xB0, 0x0C, 0x30, 0x10, 0x0C, 0x20, 0x10, 0x0C, // - 0x20, 0x10, 0x0C, 0x30, 0x70, 0x0C, 0x3F, 0xF0, 0x0C, 0x1F, 0xE0, 0x0C, 0x0F, 0x80, 0x00, 0x00, // - 0x00, 0x00, 0x00, 0x00, // - 0x00, 0x7F, 0x00, 0x03, 0xFF, 0xC0, 0x07, 0xFF, 0xE0, 0x07, 0x18, 0x70, 0x0C, 0x30, 0x30, 0x08, // - 0x20, 0x10, 0x08, 0x20, 0x10, 0x0E, 0x30, 0x30, 0x0E, 0x3F, 0xE0, 0x06, 0x1F, 0xE0, 0x00, 0x0F, // - 0x80, 0x00, 0x00, 0x00, // - 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x0F, 0x80, 0x00, 0x0E, 0x00, 0x00, 0x0C, 0x01, 0xF0, 0x0C, // - 0x0F, 0xF0, 0x0C, 0x3F, 0xF0, 0x0D, 0xF0, 0x00, 0x0F, 0xC0, 0x00, 0x0E, 0x00, 0x00, 0x0C, 0x00, // - 0x00, 0x00, 0x00, 0x00, // - 0x03, 0xC3, 0xC0, 0x07, 0xEF, 0xE0, 0x0F, 0xEF, 0xE0, 0x0C, 0x78, 0x30, 0x08, 0x30, 0x10, 0x08, // - 0x38, 0x10, 0x08, 0x18, 0x10, 0x0C, 0x3C, 0x30, 0x0F, 0xEF, 0xF0, 0x07, 0xE7, 0xE0, 0x03, 0x83, // - 0xC0, 0x00, 0x00, 0x00, // - 0x01, 0xF0, 0x00, 0x07, 0xF8, 0x60, 0x07, 0xFC, 0x70, 0x0E, 0x0C, 0x70, 0x08, 0x04, 0x10, 0x08, // - 0x04, 0x10, 0x08, 0x0C, 0x30, 0x0E, 0x19, 0xE0, 0x07, 0xFF, 0xE0, 0x03, 0xFF, 0x80, 0x00, 0xFE, // - 0x00, 0x00, 0x00, 0x00, // - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x70, 0x00, // - 0xE0, 0x70, 0x00, 0xE0, 0x70, 0x00, 0xE0, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // - 0x00, 0x00, 0x00, 0x00, // -}; - -static FontLibrary_t fontclocklib = { - .font = fontclocklib_code, - .fontIndex = "0123456789:", - .fontIndexLen = 12, - .fontCode = kgbk, - .isAscii = true, - .widthPixel = 24, - .heightPixel = 24, -}; -#endif - -// DB 00H 00H 07H F0H 0FH F8H 18H 0CH 10H 04H 18H 0CH 0FH F8H 07H F0H;"0",0 -// DB 10H 08H 10H 08H 3FH F8H 3FH F8H 00H 08H 00H 08H 00H 00H 00H 00H;"1",1 -// DB 1CH 18H 3CH 38H 20H 68H 20H C8H 23H 88H 3FH 18H 1CH 18H 00H 00H;"2",2 -// DB 18H 30H 38H 38H 22H 08H 22H 08H 27H 18H 3DH F0H 18H E0H 00H 00H;"3",3 -// DB 01H C0H 07H C0H 0EH 48H 18H 48H 3FH F8H 3FH F8H 00H 48H 00H 00H;"4",4 -// DB 3FH 30H 3FH 38H 23H 08H 22H 08H 23H 18H 21H F0H 20H E0H 00H 00H;"5",5 -// DB 0FH E0H 1FH F0H 33H 18H 22H 08H 33H 18H 31H F0H 00H E0H 00H 00H;"6",6 -// DB 38H 00H 38H 00H 21H F8H 27H F8H 3EH 00H 38H 00H 20H 00H 00H 00H;"7",7 -// DB 1CH 70H 3EH F8H 23H 88H 21H 08H 23H 88H 3EH F8H 1CH 70H 00H 00H;"8",8 -// DB 0EH 00H 1FH 18H 31H 98H 20H 88H 31H 98H 1FH F0H 0FH E0H 00H 00H;"9",9 -// DB 00H 00H 00H 00H 06H 18H 06H 18H 06H 18H 00H 00H 00H 00H 00H 00H;":",10 - -#if 0 -//32*32 -const uint8_t fontclocklib_code[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x40, 0x40, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFE, 0xFF, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0xFF, 0xFE, 0xF0, - 0x00, 0x00, 0x1F, 0xFF, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x06, 0x04, 0x04, 0x06, 0x07, 0x03, 0x01, 0x00, 0x00, /*"0",0*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x06, 0x07, 0x07, 0x07, 0x06, 0x04, 0x04, 0x04, 0x00, 0x00, /*"1",1*/ - 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0x40, 0x40, 0x40, 0x40, 0xC0, 0xC0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x1F, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC1, 0xFF, 0x7F, 0x3E, 0x00, - 0x00, 0x00, 0x00, 0x80, 0xC0, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x01, 0x00, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x07, 0x07, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x07, 0x07, 0x01, 0x00, /*"2",2*/ - 0x00, 0x00, 0x00, 0x80, 0x80, 0xC0, 0x40, 0x40, 0x40, 0xC0, 0xC0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x80, 0x80, 0x80, 0xC0, 0xE1, 0x7F, 0x3F, 0x1E, 0x00, 0x00, - 0x00, 0x00, 0xE0, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0xFF, 0xFE, 0x78, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x06, 0x04, 0x04, 0x04, 0x04, 0x06, 0x03, 0x03, 0x01, 0x00, 0x00, /*"3",3*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x70, 0x3C, 0x0E, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, - 0x00, 0x10, 0x1C, 0x1E, 0x13, 0x11, 0x10, 0x10, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x0F, 0x0F, 0x0F, 0x0F, 0x08, 0x08, 0x08, /*"4",4*/ - 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF, 0xC7, 0x60, 0x20, 0x20, 0x20, 0x60, 0xE0, 0xC0, 0x80, 0x00, 0x00, - 0x00, 0x00, 0xE0, 0xE1, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x7E, 0x00, 0x00, 0x00, 0x01, 0x03, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, 0x06, 0x03, 0x03, 0x01, 0x00, 0x00, /*"5",5*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x40, 0x40, 0x40, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFC, 0xFE, 0x8F, 0x81, 0xC0, 0x40, 0x40, 0x40, 0xC0, 0xC3, 0x83, 0x03, 0x00, - 0x00, 0x00, 0x3F, 0xFF, 0xFF, 0xC3, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x06, 0x04, 0x04, 0x04, 0x06, 0x03, 0x03, 0x01, 0x00, /*"6",6*/ - 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x03, 0x01, 0x00, 0x00, 0x80, 0xE0, 0x78, 0x1E, 0x07, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFC, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"7",7*/ - 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x40, 0x40, 0x40, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x3F, 0x7F, 0xF1, 0xE0, 0xC0, 0x80, 0x80, 0x80, 0xE1, 0x7F, 0x3F, 0x1E, 0x00, - 0x00, 0xF8, 0xFC, 0xFE, 0x07, 0x03, 0x01, 0x01, 0x01, 0x03, 0x07, 0x0F, 0xFE, 0xFC, 0xF8, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x06, 0x04, 0x04, 0x04, 0x04, 0x06, 0x03, 0x03, 0x01, 0x00, 0x00, /*"8",8*/ - 0x00, 0x00, 0x00, 0x80, 0x80, 0xC0, 0x40, 0x40, 0x40, 0x40, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0xFF, 0xFE, 0xF8, 0x00, - 0x00, 0x00, 0x81, 0x83, 0x87, 0x06, 0x04, 0x04, 0x04, 0x06, 0x83, 0xF3, 0xFF, 0x7F, 0x0F, 0x00, 0x00, 0x00, 0x03, 0x03, 0x07, 0x04, 0x04, 0x04, 0x06, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, /*"9",9*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xE0, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x81, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x07, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, /*":",10*/ -}; -static FontLibrary_t fontclocklib = { - .font = fontclocklib_code, - .fontIndex = "0123456789:", - .fontIndexLen = 12, - .fontCode = kgbk, - .isAscii = true, - .widthPixel = 16, - .heightPixel = 32, -}; -#endif - -// 24*24 -const uint8_t fontclocklib_code[] = { - - 0x00, 0x00, 0x80, 0xC0, 0xE0, 0x60, 0x20, 0x60, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFE, 0x00, 0x01, 0x07, 0x0F, 0x1E, 0x18, 0x10, 0x18, 0x1E, 0x0F, 0x07, 0x01, /*"0",0*/ - 0x00, 0x00, 0x80, 0x80, 0x80, 0xC0, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x1F, 0x1F, 0x1F, 0x10, 0x10, 0x10, 0x00, /*"1",1*/ - 0x00, 0x80, 0xC0, 0x60, 0x20, 0x20, 0x20, 0x60, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x03, 0x03, 0x03, 0x80, 0xC0, 0x60, 0x38, 0x3F, 0x1F, 0x07, 0x00, 0x00, 0x1C, 0x1E, 0x1B, 0x19, 0x18, 0x18, 0x18, 0x18, 0x1F, 0x1F, 0x00, /*"2",2*/ - 0x00, 0x80, 0xC0, 0xE0, 0x20, 0x20, 0x60, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x10, 0x10, 0x18, 0x3F, 0xEF, 0xE7, 0x80, 0x00, 0x00, 0x07, 0x0F, 0x1F, 0x10, 0x10, 0x10, 0x18, 0x1F, 0x0F, 0x07, 0x00, /*"3",3*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0xC0, 0xF0, 0xB8, 0x8E, 0x87, 0x81, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x1F, 0x1F, 0x1F, 0x10, 0x10, /*"4",4*/ - 0x00, 0x00, 0xE0, 0xE0, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, 0x00, 0x00, 0x3F, 0x3F, 0x18, 0x08, 0x08, 0x18, 0xF8, 0xF0, 0xE0, 0x00, 0x00, 0x07, 0x0F, 0x1B, 0x10, 0x10, 0x10, 0x1C, 0x1F, 0x0F, 0x03, 0x00, /*"5",5*/ - 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x60, 0x20, 0x20, 0xE0, 0xE0, 0xC0, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x31, 0x18, 0x08, 0x08, 0x18, 0xF8, 0xF0, 0xE0, 0x00, 0x01, 0x07, 0x0F, 0x1C, 0x18, 0x10, 0x10, 0x18, 0x0F, 0x0F, 0x03, /*"6",6*/ - 0x00, 0x00, 0xC0, 0xE0, 0xE0, 0x60, 0x60, 0x60, 0x60, 0xE0, 0xE0, 0x60, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0xE0, 0xF8, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x00, /*"7",7*/ - 0x00, 0x80, 0xC0, 0xE0, 0x60, 0x20, 0x20, 0x20, 0x60, 0xE0, 0xC0, 0x80, 0x00, 0x87, 0xEF, 0xEF, 0x3C, 0x18, 0x38, 0x30, 0x78, 0xEF, 0xCF, 0x83, 0x00, 0x07, 0x0F, 0x0F, 0x18, 0x10, 0x10, 0x10, 0x18, 0x1F, 0x0F, 0x07, /*"8",8*/ - 0x00, 0x00, 0xC0, 0xC0, 0xE0, 0x20, 0x20, 0x20, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x1F, 0x3F, 0x7F, 0x60, 0x40, 0x40, 0x60, 0x30, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x0C, 0x1C, 0x1C, 0x10, 0x10, 0x18, 0x0F, 0x0F, 0x03, 0x00, /*"9",9*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x0E, 0x0E, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x1C, 0x1C, 0x1C, 0x00, 0x00, 0x00, /*":",10*/ - -}; -static FontLibrary_t fontclocklib = { - .font = fontclocklib_code, - .fontIndex = "0123456789:", - .fontIndexLen = 12, - .fontCode = kgbk, - .isAscii = true, - .widthPixel = 12, - .heightPixel = 24, -}; - -const uint8_t font8x8_xo_code[] = { - 0x00, 0x3C, 0x7E, 0x7E, 0x7E, 0x7E, 0x3C, 0x00, /*实心圆,代表完成*/ - 0x00, 0x3C, 0x42, 0x42, 0x42, 0x42, 0x3C, 0x00, /*空心圆,代表未完成*/ - -}; - -static FontLibrary_t font8x8_xo_lib = { - .font = font8x8_xo_code, - .fontIndex = "ox", - .fontIndexLen = 2, - .fontCode = kgbk, - .isAscii = true, - .widthPixel = 8, - .heightPixel = 8, -}; - -const uint8_t font12x24_asiic_code[] = { - - 0x00, 0x00, 0xC0, 0xE0, 0x70, 0x30, 0x30, 0x60, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFE, 0x00, 0x00, 0x01, 0x07, 0x0E, 0x0C, 0x18, 0x18, 0x0C, 0x0F, 0x07, 0x00, 0x00, /*"0",0*/ - 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, /*"1",1*/ - 0x00, 0x80, 0xE0, 0x60, 0x30, 0x30, 0x30, 0x70, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x80, 0xC0, 0xE0, 0x38, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x08, 0x0E, 0x0F, 0x0B, 0x09, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, /*"2",2*/ - 0x00, 0x80, 0xC0, 0x60, 0x30, 0x30, 0x30, 0x30, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x18, 0x18, 0x38, 0x7F, 0xE7, 0x80, 0x00, 0x00, 0x03, 0x07, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x0E, 0x07, 0x01, 0x00, /*"3",3*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xF0, 0xB8, 0x8E, 0x87, 0x81, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x0F, 0x0F, 0x01, 0x01, 0x01, /*"4",4*/ - 0x00, 0x00, 0xE0, 0xE0, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x1C, 0x1F, 0x0D, 0x04, 0x04, 0x0C, 0x0C, 0x3C, 0xF8, 0xC0, 0x00, 0x01, 0x07, 0x0E, 0x08, 0x18, 0x18, 0x18, 0x0C, 0x0F, 0x07, 0x00, 0x00, /*"5",5*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF0, 0x30, 0x10, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xF8, 0x1E, 0x0F, 0x0D, 0x0C, 0x0C, 0x18, 0xF8, 0xF0, 0x00, 0x00, 0x03, 0x07, 0x0C, 0x18, 0x18, 0x18, 0x18, 0x0C, 0x0F, 0x03, 0x00, /*"6",6*/ - 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xA0, 0xE0, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xF8, 0x1E, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"7",7*/ - 0x00, 0x80, 0xE0, 0x60, 0x30, 0x30, 0x30, 0x20, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0xE3, 0xFF, 0x3C, 0x18, 0x18, 0x18, 0x3C, 0x3F, 0xE7, 0xC0, 0x00, 0x00, 0x07, 0x0F, 0x0C, 0x18, 0x18, 0x18, 0x18, 0x0C, 0x07, 0x03, 0x00, /*"8",8*/ - 0x00, 0xC0, 0xE0, 0x60, 0x30, 0x30, 0x30, 0x60, 0xE0, 0xC0, 0x00, 0x00, 0x02, 0x1F, 0x3D, 0x30, 0x60, 0x60, 0xE0, 0xF0, 0x7F, 0x1F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10, 0x1C, 0x0F, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, /*"9",9*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x0C, 0x1C, 0xF0, 0xE0, 0xE0, 0x38, 0x1C, 0x04, 0x00, 0x00, 0x00, 0x10, 0x1C, 0x0E, 0x03, 0x01, 0x03, 0x07, 0x0E, 0x18, 0x10, 0x00, /*"x",10*/ - 0x00, 0x30, 0xF0, 0xE0, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x70, 0x10, 0x00, 0x00, 0x00, 0x00, 0x83, 0xEF, 0x7C, 0x7E, 0xE7, 0x81, 0x00, 0x00, 0x00, 0x10, 0x1C, 0x1F, 0x07, 0x01, 0x00, 0x00, 0x01, 0x0F, 0x1E, 0x18, 0x00, /*"X",11*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, /*"[",12*/ - 0x00, 0x0C, 0x0C, 0x0C, 0x0C, 0xFC, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x60, 0x60, 0x7F, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, - /*"]",13*/}; - -static FontLibrary_t font12x24_asiic_lib = { - .font = font12x24_asiic_code, - .fontIndex = "0123456789xX[]", - .fontIndexLen = 15, - .fontCode = kgbk, - .isAscii = true, - .widthPixel = 12, - .heightPixel = 24, -}; - -const uint8_t font24x24_zh_code[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xF8, 0x38, 0x10, 0x10, 0xF0, 0x90, 0x10, 0x10, 0x10, 0x88, 0xF8, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x10, 0x0C, 0x06, 0xE7, 0x1C, 0x10, 0x10, 0x10, 0x10, 0x93, - 0x71, 0xFF, 0x39, 0x49, 0x89, 0x08, 0x08, 0x0C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x04, 0x02, 0x01, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x03, 0x07, 0x06, 0x06, 0x04, 0x04, 0x00, /*"保",0*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFC, 0xFC, 0xC0, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xC2, 0x63, 0x33, 0xFF, 0x0D, 0x09, 0x08, 0x48, - 0x48, 0x49, 0x48, 0x47, 0x4F, 0xFC, 0x24, 0x24, 0x26, 0x06, 0x04, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x08, 0x38, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x20, 0x60, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"持",1*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0xFC, 0x20, 0xA0, 0x20, 0x00, 0x80, 0x60, 0x3C, 0x2C, 0xA0, 0x70, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x0C, 0x94, 0x75, 0x55, 0x57, 0x15, 0xF4, 0x02, 0x90, - 0x92, 0x92, 0x92, 0xFF, 0x92, 0x8A, 0x49, 0x3F, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0F, 0x02, 0x01, 0x09, 0x18, 0x0F, 0x00, 0x00, 0x00, 0x20, 0x60, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"静",2*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xF8, 0x00, 0x00, 0x00, - 0xFF, 0x0F, 0x08, 0x08, 0x08, 0x0C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x18, 0x08, 0x08, 0x08, 0x0F, 0x08, 0x08, 0x0C, 0x0F, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, /*"止",3*/ - 0x00, 0x00, 0x00, 0x00, 0x40, 0x60, 0x60, 0x60, 0x20, 0x20, 0x20, 0x20, 0xA0, 0xE0, 0x30, 0x30, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0x60, 0x30, 0x0D, 0xFF, - 0x03, 0x00, 0x00, 0x10, 0x20, 0x60, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, /*"不",4*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xE0, 0x20, 0x20, 0x10, 0x10, 0x10, 0xF8, 0xF8, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x70, 0x61, 0x87, 0x82, 0x06, 0xFE, - 0x12, 0x11, 0x11, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x04, 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x02, 0x06, 0x0C, 0x0C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x10, 0x00, 0x00, /*"足",5*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0xE0, 0x30, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0xC4, 0x64, 0x1A, 0xFF, 0x12, 0x32, 0x00, 0x18, - 0x0F, 0x00, 0x00, 0x1F, 0x80, 0xE0, 0x3C, 0x08, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x40, 0x20, 0x30, 0x18, 0x0C, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"秒",6*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x20, 0x20, 0x38, 0xF8, 0x20, 0x20, 0x20, 0x60, 0x9C, 0x24, 0x10, 0x10, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x67, 0x7E, 0x00, - 0x10, 0x8C, 0x9B, 0xB9, 0xE4, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x23, 0x3F, 0x11, 0x13, 0x1D, 0x11, 0x1D, 0x17, 0x10, 0x18, 0x1F, 0x11, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, /*"蓝",7*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x10, 0x10, 0x10, 0x10, 0x10, 0xF0, 0x18, 0x18, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0F, 0x04, 0x84, 0x64, 0x34, 0x1E, - 0x06, 0xFF, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x02, 0x01, 0x00, 0x00, 0x10, 0x20, 0x70, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"牙",8*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x10, 0xF0, 0x70, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x0E, 0x08, 0x08, 0x08, 0x04, 0x04, 0x07, - 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x08, 0x08, 0x18, 0x18, 0x18, 0x10, 0x18, 0x18, 0x18, 0x18, 0x08, 0x08, 0x0C, 0x0E, 0x07, 0x00, 0x00, 0x00, /*"已",9*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x30, 0x10, 0xC0, 0xC0, 0x00, 0x00, 0x40, 0x20, 0x20, 0xA0, 0xF0, 0x30, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x67, 0x74, 0x2C, 0x26, 0x01, 0x00, 0x10, 0x50, - 0x48, 0x44, 0xC3, 0xC3, 0x62, 0x24, 0x2C, 0x0C, 0x18, 0x10, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x06, 0x02, 0x02, 0x01, 0x10, 0x18, 0x08, 0x08, 0x08, 0x0F, 0x0B, 0x08, 0x08, 0x08, 0x0C, 0x0C, 0x08, 0x00, 0x00, /*"经",10*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xC0, 0x00, 0x00, 0x40, 0x40, 0xC0, 0xE0, 0x5C, 0x2C, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x08, 0xF8, 0x08, 0x00, 0x40, 0x48, 0x4E, 0x4B, - 0x44, 0x45, 0xFF, 0x24, 0x24, 0x24, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0C, 0x04, 0x07, 0x04, 0x04, 0x08, 0x08, 0x08, 0x08, 0x10, 0x10, 0x17, 0x30, 0x30, 0x30, 0x30, 0x30, 0x10, 0x10, 0x00, 0x00, /*"连",11*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x88, 0x98, 0xD0, 0xC0, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x82, 0xC2, 0x62, 0xFF, 0x11, 0x91, 0x80, 0x80, 0x90, - 0x92, 0xF4, 0xB0, 0x98, 0x97, 0x89, 0x48, 0x48, 0x48, 0x40, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x18, 0x3F, 0x0F, 0x00, 0x00, 0x20, 0x20, 0x13, 0x12, 0x0C, 0x06, 0x0F, 0x08, 0x18, 0x30, 0x20, 0x00, 0x00, 0x00, /*"接",12*/ - 0x00, 0x00, 0x00, 0xE0, 0x40, 0x40, 0x80, 0x00, 0xF8, 0x88, 0x40, 0x20, 0x00, 0x80, 0x80, 0x40, 0x40, 0x20, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x80, 0x40, 0x25, 0x1A, 0xFF, 0x12, 0x12, 0x12, - 0x00, 0xE0, 0x3F, 0x08, 0x04, 0xFC, 0xFC, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x04, 0x02, 0x02, 0x02, 0x03, 0x02, 0x12, 0x08, 0x06, 0x01, 0x00, 0x00, 0x00, 0x7F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, /*"断",13*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x60, 0x60, 0xE0, 0x20, 0x20, 0x20, 0x20, 0xF0, 0x30, 0x30, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0xE8, 0x3F, 0x08, 0x08, - 0x04, 0x04, 0xFF, 0x04, 0x04, 0x04, 0x04, 0x04, 0x06, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x08, 0x04, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"开",14*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9C, 0xF8, 0x80, 0x80, 0x80, 0x80, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x7F, 0x81, 0x89, 0x49, 0xC8, 0xFF, 0x4C, - 0x44, 0x44, 0x40, 0x3C, 0x0F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0F, 0x18, 0x10, 0x10, 0x30, 0x30, 0x30, 0x10, 0x10, 0x1A, 0x1C, 0x00, 0x00, 0x00, /*"电",15*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x78, 0xA8, 0xA8, 0xA8, 0xA8, 0x88, 0xE4, 0x7C, 0x18, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x14, 0xF4, 0x94, 0x14, 0x52, 0xF2, - 0xAA, 0xAA, 0x8A, 0xFA, 0x3A, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x24, 0x25, 0x25, 0x25, 0x3F, 0x24, 0x24, 0x27, 0x30, 0x30, 0x30, 0x30, 0x20, 0x00, 0x00, 0x00, 0x00, /*"量",16*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0xC0, 0xC6, 0xFC, 0xA0, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x10, 0x08, 0x24, 0xE6, 0xA3, 0xA1, 0x94, 0xAF, - 0x10, 0x11, 0xF3, 0xF6, 0x2C, 0x0C, 0x18, 0x18, 0x18, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x21, 0x27, 0x24, 0x24, 0x34, 0x12, 0x16, 0x13, 0x10, 0x10, 0x10, 0x10, 0x30, 0x00, 0x00, 0x00, 0x00, /*"查",17*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x90, 0x90, 0xF0, 0xB8, 0x88, 0x8C, 0xCC, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0xC8, 0x78, 0xFC, 0xA7, 0xA4, - 0xA4, 0xA4, 0x14, 0x14, 0xF2, 0x22, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x10, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00, 0x00, 0x3F, 0x14, 0x14, 0x14, 0x12, 0x10, 0x30, 0x7F, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"看",18*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x60, 0x38, 0x10, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x38, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xC6, 0x65, 0x3C, 0x2C, 0x23, 0x01, 0x80, 0x02, - 0x22, 0x22, 0x22, 0x22, 0x3F, 0x91, 0x91, 0x91, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x04, 0x0C, 0x04, 0x06, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x03, 0x1F, 0x09, 0x09, 0x09, 0x08, 0x08, 0x0F, 0x01, 0x00, 0x00, 0x00, /*"结",19*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x30, 0xF0, 0x10, 0x90, 0x90, 0xF0, 0xF0, 0xD0, 0x10, 0x88, 0xF8, 0x78, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x60, 0x21, 0x27, 0xA4, 0x64, 0xFF, - 0x52, 0x92, 0x12, 0x13, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x10, 0x08, 0x04, 0x06, 0x03, 0x01, 0x00, 0x7F, 0x00, 0x00, 0x01, 0x02, 0x06, 0x0C, 0x18, 0x18, 0x18, 0x10, 0x00, 0x00, /*"果",20*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0xD0, 0x90, 0x18, 0x0C, 0x88, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x60, 0x20, 0x20, 0x20, 0x22, 0x22, 0x33, 0x11, - 0xFF, 0x11, 0x11, 0x11, 0x11, 0x10, 0x18, 0x18, 0x18, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x20, 0x60, 0x78, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*"手",21*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x86, 0xC2, 0x32, 0x0F, 0xFF, 0x21, 0x61, 0x01, 0x01, - 0xFF, 0x01, 0x01, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x04, 0x02, 0x01, 0x00, 0x00, 0x3F, 0x0F, 0x00, 0x08, 0x04, 0x03, 0x01, 0x00, 0x00, 0x00, 0x07, 0x06, 0x0C, 0x0C, 0x0C, 0x0F, 0x06, 0x00, /*"机",22*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x20, 0x20, 0x50, 0xD0, 0x88, 0x0C, 0x8C, 0x40, 0x70, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x11, 0xD0, 0x70, 0x32, 0xFC, 0x30, - 0x48, 0x88, 0x88, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x04, 0x02, 0x01, 0x00, 0x00, 0x30, 0x7F, 0x00, 0x00, 0x00, 0x01, 0x03, 0x06, 0x06, 0x0C, 0x0C, 0x04, 0x08, 0x00, 0x00, /*"采",23*/ - 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0xF0, 0x0C, 0x24, 0xA0, 0xA4, 0xEC, 0xE8, 0x90, 0x50, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xBF, 0x90, 0x90, 0xD2, 0xF2, - 0xCF, 0x4B, 0x4A, 0x49, 0x48, 0x48, 0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x10, 0x10, 0x08, 0x04, 0x06, 0x03, 0x01, 0x7F, 0x00, 0x01, 0x02, 0x04, 0x0C, 0x18, 0x18, 0x18, 0x10, 0x10, 0x00, 0x00, /*"集",24*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x7C, 0xC0, 0x80, 0x80, 0x88, 0x98, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xFE, 0x42, 0x42, 0x22, 0x22, 0xE1, 0x21, - 0x03, 0x1F, 0x70, 0x80, 0xE0, 0x3C, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x08, 0x06, 0x03, 0x00, 0x04, 0x08, 0x1C, 0x07, 0x00, 0x08, 0x04, 0x02, 0x01, 0x07, 0x0C, 0x18, 0x30, 0x70, 0x78, 0x00, 0x00, /*"成",25*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x81, 0x81, 0xC1, 0x7F, 0x20, 0x20, 0x20, 0x12, - 0x82, 0xE2, 0x3E, 0x07, 0x02, 0x01, 0x01, 0xFF, 0x0F, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x10, 0x10, 0x08, 0x04, 0x03, 0x01, 0x00, 0x04, 0x08, 0x38, 0x1C, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x00, /*"功",26*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x80, 0x80, 0x40, 0x48, 0x58, 0x50, 0x40, 0x20, 0x20, 0xA0, 0xE0, 0xC0, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x01, 0x40, 0x60, 0x24, 0xE4, 0x26, 0x22, - 0xF2, 0x12, 0x10, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x08, 0x04, 0x06, 0x03, 0x00, 0x00, 0x00, 0x1F, 0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x30, 0x3E, 0x10, 0x00, 0x00, /*"完",27*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x78, 0x10, 0x00, 0x80, 0x80, 0x40, 0x40, 0xA0, 0x38, 0x18, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x18, 0x0C, 0x03, 0xFD, 0x00, 0x00, 0x00, 0xE1, 0xFF, - 0x10, 0x88, 0x0F, 0x3C, 0xE4, 0x84, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x1F, 0x00, 0x00, 0x04, 0x0F, 0x03, 0x01, 0x00, 0x04, 0x0C, 0x00, 0x01, 0x06, 0x0C, 0x18, 0x3E, 0x30, 0x00, /*"低",28*/ -}; -static FontLibrary_t font24x24_zh_lib = { - .font = font24x24_zh_code, - .fontIndex = "保持静止不足秒蓝牙已经连接断开电量查看结果手机采集成功完低", - .fontIndexLen = 88, - .fontCode = kgbk, - .isAscii = false, - .widthPixel = 24, - .heightPixel = 24, -}; - -#if 0 -// const unsigned char gImage_heart_16x16[] = { -// /* 0X22,0X01,0X10,0X00,0X10,0X00, */ -// 0X00, 0XF8, 0XFC, 0XFE, 0XFE, 0XFE, 0XFE, 0XFC, 0XFC, 0XFE, 0XFE, 0XFE, 0XFE, 0XFC, 0XF8, 0X00, 0X00, 0X00, 0X03, 0X07, 0X0F, 0X1F, 0X3F, 0X7F, 0X7F, 0X3F, 0X1F, 0X0F, 0X07, 0X03, 0X00, 0X00, -// }; -#endif - -const unsigned char font_asicc_code_16x8[] = { - 0x00, 0xF0, 0x18, 0x08, 0x08, 0x18, 0xE0, 0x00, 0x00, 0x0F, 0x10, 0x20, 0x30, 0x18, 0x0F, 0x00, /*"0",0*/ - 0x00, 0x60, 0x20, 0xF0, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x3F, 0x00, 0x00, 0x00, /*"1",1*/ - 0x00, 0x30, 0x18, 0x08, 0x08, 0xD8, 0x70, 0x00, 0x00, 0x30, 0x38, 0x34, 0x33, 0x31, 0x30, 0x00, /*"2",2*/ - 0x00, 0x30, 0x18, 0x08, 0x88, 0xD8, 0x70, 0x00, 0x00, 0x18, 0x10, 0x20, 0x21, 0x13, 0x0E, 0x00, /*"3",3*/ - 0x00, 0x00, 0x80, 0x60, 0x30, 0xF8, 0x00, 0x00, 0x04, 0x07, 0x05, 0x04, 0x04, 0x3F, 0x04, 0x04, /*"4",4*/ - 0x00, 0xF0, 0x98, 0xC8, 0x88, 0x88, 0x08, 0x00, 0x08, 0x19, 0x30, 0x20, 0x30, 0x19, 0x0F, 0x00, /*"5",5*/ - 0x00, 0x80, 0xC0, 0xF0, 0x98, 0x80, 0x00, 0x00, 0x00, 0x1F, 0x31, 0x20, 0x20, 0x30, 0x1F, 0x06, /*"6",6*/ - 0x00, 0x08, 0x08, 0x08, 0x88, 0xE8, 0x38, 0x00, 0x00, 0x00, 0x30, 0x3E, 0x03, 0x00, 0x00, 0x00, /*"7",7*/ - 0x00, 0xF0, 0x88, 0x88, 0x88, 0xD8, 0x70, 0x00, 0x04, 0x1F, 0x31, 0x21, 0x21, 0x31, 0x1E, 0x00, /*"8",8*/ - 0xE0, 0xF0, 0x08, 0x08, 0x08, 0x98, 0xF0, 0x00, 0x00, 0x01, 0x23, 0x3A, 0x0F, 0x03, 0x00, 0x00, /*"9",9*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, /*"-",10*/ - 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0x11, 0x00, 0x00, 0x00, /*":",10*/ - - 0X00, 0XF8, 0XFC, 0XFE, 0XFE, 0XFE, 0XFE, 0XFC, 0X00, 0X00, 0X03, 0X07, 0X0F, 0X1F, 0X3F, 0X7F, /*?右半*/ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*" "*/ -}; - -static FontLibrary_t font_asicc16x8_lib = { - .font = font_asicc_code_16x8, - .fontIndex = "0123456789-:<> ", // <> 这两个符号是心形的左右半边 - .fontIndexLen = 16, - .fontCode = kgbk, - .isAscii = true, - .widthPixel = 8, - .heightPixel = 16, -}; diff --git a/app/src/service/heart_wave_sample_service/heart_ware_sample_data_mgr.c b/app/src/service/heart_wave_sample_service/heart_ware_sample_data_mgr.c deleted file mode 100644 index ecf7ab1..0000000 --- a/app/src/service/heart_wave_sample_service/heart_ware_sample_data_mgr.c +++ /dev/null @@ -1,107 +0,0 @@ -#include "basic_service/app_event.h" -#include "basic_service/app_event_distribute.h" -#include "board/board_ecg_sensor.h" -#include "nrfx_timer.h" - -static uint32_t m_frame_index = 0; // 帧绝对序号 -/*********************************************************************************************************************** - * ab buffer * - ***********************************************************************************************************************/ -#define FRAME_BUFFER_SIZE (256 / sizeof(one_frame_t)) - -static one_frame_t m_capture_buffer_a[FRAME_BUFFER_SIZE]; -static one_frame_t m_capture_buffer_b[FRAME_BUFFER_SIZE]; -static one_frame_t* m_capture_buffer; -static one_frame_t m_capture_buffer_index = 0; - -static void eeprom_cache_buffer_swap() { - if (m_capture_buffer == NULL) { - m_capture_buffer = m_capture_buffer_a; - m_capture_buffer_index = 0; - return; - } - - if (m_capture_buffer == m_capture_buffer_a) { - m_capture_buffer = m_capture_buffer_b; - } else { - m_capture_buffer = m_capture_buffer_a; - } - m_capture_buffer_index = 0; - return; -} - -/*********************************************************************************************************************** - * littlebuffer * - ***********************************************************************************************************************/ -static one_frame_t m_prepare_data_cache[LITTLE_DATA_BLOCK_FRAME_NUM]; -static uint32_t m_prepare_data_cache_index; - -static inline void preview_data_cache_push_data(one_frame_t data) { - if (m_prepare_data_cache_index >= LITTLE_DATA_BLOCK_FRAME_NUM) { - return; - } - m_prepare_data_cache[m_prepare_data_cache_index] = data; - m_prepare_data_cache_index++; -} - -static inline bool preview_data_cache_is_full(void) { - if (m_prepare_data_cache_index >= LITTLE_DATA_BLOCK_FRAME_NUM) { - return true; - } - return false; -} -static inline void preview_data_cache_clear(void) { m_prepare_data_cache_index = 0; } -static inline void preview_data_trigger_event() { - static app_event_t event; - event.eventType = kevent_capture_little_data_block_event; - for (uint32_t i = 0; i < LITTLE_DATA_BLOCK_FRAME_NUM; i++) { - event.val.little_data_block.data[i] = m_prepare_data_cache[i]; - } - event.val.little_data_block.timestamp = znordic_getpower_on_ms(); - event.val.little_data_block.frameIndex = m_frame_index - LITTLE_DATA_BLOCK_FRAME_NUM; - AppEvent_pushEvent(&event); -} - -/*********************************************************************************************************************** - * EXT * - ***********************************************************************************************************************/ - -void hwsd_mgr_push_one_frame(one_frame_t data) { - m_frame_index++; - - /*********************************************************************************************************************** - * EEPROM数据采样存储 * - ***********************************************************************************************************************/ - if (m_capture_buffer == NULL) eeprom_cache_buffer_swap(); - - if (m_capture_buffer_index < FRAME_BUFFER_SIZE) { - m_capture_buffer[m_capture_buffer_index++] = data; - } - - if (m_capture_buffer_index == FRAME_BUFFER_SIZE) { - app_event_t evt; - evt.eventType = kevent_capture_256data_event; - evt.val.capture_data_cache = (uint8_t*)m_capture_buffer; - eeprom_cache_buffer_swap(); - AppEvent_pushEvent(&evt); - } - - /******************************************************************************* - * 实时采样数据事件上报 * - *******************************************************************************/ - /** - * @brief 缓存数据,并触发小数据块事件 - */ - preview_data_cache_push_data(data); - if (preview_data_cache_is_full()) { - preview_data_trigger_event(); - preview_data_cache_clear(); - } -} - -void hwsd_mgr_reset_buffer(){ - m_frame_index = 0; - m_capture_buffer = NULL; - m_capture_buffer_index = 0; - preview_data_cache_clear(); -} diff --git a/app/src/service/heart_wave_sample_service/heart_ware_sample_data_mgr.h b/app/src/service/heart_wave_sample_service/heart_ware_sample_data_mgr.h deleted file mode 100644 index 71c04f3..0000000 --- a/app/src/service/heart_wave_sample_service/heart_ware_sample_data_mgr.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include - -#include "basic_service/app_event.h" -#include "basic_service/app_event_distribute.h" -#include "nrfx_timer.h" - -void hwsd_mgr_push_one_frame(one_frame_t data); -void hwsd_mgr_reset_buffer(); \ No newline at end of file diff --git a/app/src/service/heart_wave_sample_service/heart_wave_sample_data_pre_process.c b/app/src/service/heart_wave_sample_service/heart_wave_sample_data_pre_process.c deleted file mode 100644 index 39d3fbc..0000000 --- a/app/src/service/heart_wave_sample_service/heart_wave_sample_data_pre_process.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "heart_wave_sample_data_pre_process.h" -static one_frame_t m_datacache; -static one_frame_t m_displaydata; - -void hwsd_pre_processer_init() {} -void hwsd_pre_processer_process(one_frame_t framdata) { // - m_datacache = framdata; - m_displaydata = framdata; -} - -one_frame_t hwsd_pre_processer_get_display_data() { return m_displaydata; } -one_frame_t hwsd_pre_processer_get_storage_data() { return m_datacache; } diff --git a/app/src/service/heart_wave_sample_service/heart_wave_sample_data_pre_process.h b/app/src/service/heart_wave_sample_service/heart_wave_sample_data_pre_process.h deleted file mode 100644 index a188a77..0000000 --- a/app/src/service/heart_wave_sample_service/heart_wave_sample_data_pre_process.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include - -#include "basic_service/app_event.h" - -void hwsd_pre_processer_init(); -void hwsd_pre_processer_process(one_frame_t framdata); -one_frame_t hwsd_pre_processer_get_display_data(); -one_frame_t hwsd_pre_processer_get_storage_data(); diff --git a/app/src/service/heart_wave_sample_service/heart_wave_sample_service.c b/app/src/service/heart_wave_sample_service/heart_wave_sample_service.c deleted file mode 100644 index 41b0742..0000000 --- a/app/src/service/heart_wave_sample_service/heart_wave_sample_service.c +++ /dev/null @@ -1,77 +0,0 @@ -#include "heart_wave_sample_service.h" - -#include "basic_service/app_event.h" -#include "basic_service/app_event_distribute.h" -#include "board/ads129x/ads129x.h" -#include "board/app_board.h" -#include "board/board_ecg_sensor.h" -#include "heart_ware_sample_data_mgr.h" -#include "heart_wave_sample_data_pre_process.h" -#include "nrfx_timer.h" - -typedef enum { - kidle, - kprepare, - kcapture, -} capture_state_t; - -static capture_state_t m_prepare_capture_state = kidle; -static uint32_t m_start_capture_tp; - -/** - * @brief 处理ads129x数据,并上报 - * - * @param event - */ -static void on_ads129x_ready_irq(app_board_irq_event_t event) { -#if 1 - static ads129x_capture_data_t capture_data; - ads129x_read_data(&capture_data); - hwsd_mgr_push_one_frame(capture_data.ch1data); -#else - static int32_t data; - data += 1000; - if (data >= 60000) { - data = -60000; - } - hwsd_mgr_push_one_frame(data); -#endif -} - -void hwss_init(void) { // - app_board_reg_irq_listener(kon_irq_ads1291_ready_pin, on_ads129x_ready_irq); -} - -void hwss_start_prepare_capture(void) { - m_start_capture_tp = znordic_getpower_on_s(); - m_prepare_capture_state = kprepare; - hwsd_pre_processer_init(); - hwsd_mgr_reset_buffer(); - - ads129x_start_capture(false); -} -void hwss_start_capture(void) { - m_start_capture_tp = znordic_getpower_on_s(); - m_prepare_capture_state = kcapture; -} -void hwss_stop_capture(void) { - m_prepare_capture_state = kidle; - hwsd_mgr_reset_buffer(); - ads129x_stop_capture(); -} - -float hwss_read_val(void) { - __disable_irq(); - float val = hwsd_pre_processer_get_display_data(); - __enable_irq(); - return val; -} -float hwss_read_heart_rate(void) { // - return 0; -} -int hwss_has_captured_time_ms() { return (znordic_getpower_on_s() - m_start_capture_tp) * 1000; } - -bool hwss_lead_get_state_connected_state() { return true; } - -void hwss_subic_write_reg(uint8_t addr, uint8_t val) { ads129x_write_reg(addr, val); } -uint8_t hwss_subic_read_reg(uint8_t addr) { return ads129x_read_reg(addr); } \ No newline at end of file diff --git a/app/src/service/heart_wave_sample_service/heart_wave_sample_service.h b/app/src/service/heart_wave_sample_service/heart_wave_sample_service.h deleted file mode 100644 index 1e631fb..0000000 --- a/app/src/service/heart_wave_sample_service/heart_wave_sample_service.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once -#include -#include - -// 每256个字节触发一次回调 -typedef void (*heart_wave_sample_service_callback_t)(uint16_t *p_data, uint16_t length); - -void hwss_init(void); - -void hwss_start_capture(void); -void hwss_start_prepare_capture(void); -void hwss_stop_capture(void); -void hwss_subic_write_reg(uint8_t addr, uint8_t val); -uint8_t hwss_subic_read_reg(uint8_t addr); - - - - -float hwss_read_val(void); -float hwss_read_heart_rate(void); -int hwss_has_captured_time_ms(); -bool hwss_lead_get_state_connected_state(); \ No newline at end of file diff --git a/app/src/service/storage/sample_data_manager.c b/app/src/service/storage/sample_data_manager.c deleted file mode 100644 index 6e90080..0000000 --- a/app/src/service/storage/sample_data_manager.c +++ /dev/null @@ -1,92 +0,0 @@ -#include "sample_data_manager.h" - -#include - -#include "zeeprom_fs.h" -#include "znordic.h" -#include "aproject_config/config.h" - -static sample_data_fileinfo_t fileinfocache[MAX_FILE_NUM * 2]; -static uint8_t fileinfocache_count = 0; - -void sample_data_mgr_init() { zeeprom_fs_init(); } -void sample_data_mgr_uninit() { zeeprom_fs_uinit(); } - -sample_data_fileinfo_list_t* sample_data_mgr_get_fileinfo_list() { // - static sample_data_fileinfo_list_t fileinfo_list; - memset(&fileinfo_list, 0, sizeof(fileinfo_list)); - fileinfocache_count = 0; - - // 读取所有记录信息 - zeeprom_header_t* header = zeeprom_fs_get_header(); - - for (uint16_t i = 0; i < ZARRAY_SIZE(header->sectorinfos); i++) { - zeeprom_sector_info_t* sectorinfo = &header->sectorinfos[i]; - if (sectorinfo->usage == 1 && sectorinfo->sector_index_in_file == 0) { - // 读取文件信息 - if (fileinfocache_count >= ZARRAY_SIZE(fileinfocache)) { - ZLOGE("fileinfocache_count >= MAX_FILE_NUM"); - break; - } - - sample_data_fileinfo_t* fileinfo = &fileinfocache[fileinfocache_count]; - fileinfo->fileuuid = sectorinfo->fileuuid; - memcpy(fileinfo->filename, sectorinfo->filename, sizeof(fileinfo->filename)); - fileinfo->size = zeeprom_fs_get_filesize_by_fileuuid(fileinfo->fileuuid); - fileinfo->checksum = zeeprom_fs_get_checksum_by_fileuuid(fileinfo->fileuuid); - - fileinfo_list.fileinfo[fileinfo_list.count] = fileinfo; - fileinfo_list.count++; - fileinfocache_count++; - } - } - // 根据文件uuid排序,uuid最大的排在最前面 - for (uint16_t i = 0; i < fileinfo_list.count; i++) { - for (uint16_t j = i + 1; j < fileinfo_list.count; j++) { - if (fileinfo_list.fileinfo[i]->fileuuid < fileinfo_list.fileinfo[j]->fileuuid) { - sample_data_fileinfo_t* tmp = fileinfo_list.fileinfo[i]; - fileinfo_list.fileinfo[i] = fileinfo_list.fileinfo[j]; - fileinfo_list.fileinfo[j] = tmp; - } - } - } - return &fileinfo_list; -} - -bool sample_data_mgr_storage_is_full() { return zeeprom_fs_get_file_num() >= MAX_FILE_NUM; } -int32_t sample_data_mgr_get_file_num() { return zeeprom_fs_get_file_num(); } - -#if 1 -static const char* filename2str(uint8_t* filename) { - static char filename_str[32]; - sprintf(filename_str, "%02x%02x%02x%02x%02x%02x%02x%02x", filename[0], filename[1], filename[2], filename[3], filename[4], filename[5], filename[6], filename[7]); - return filename_str; -} -#endif - -void sample_data_mgr_dump_fileinfo_list() { - zeeprom_fs_dump_sector_state(); - sample_data_fileinfo_list_t* fileinfo_list = sample_data_mgr_get_fileinfo_list(); - ZLOGI_BLOCK("fileinfo_list->count=%d\n", fileinfo_list->count); - for (uint16_t i = 0; i < fileinfo_list->count; i++) { - sample_data_fileinfo_t* fileinfo = fileinfo_list->fileinfo[i]; - ZLOGI_BLOCK("[%d]: filename=%s, fileuuid=%d, size=%d", i, filename2str(fileinfo->filename), fileinfo->fileuuid, fileinfo->size); - } -} - -int32_t sample_data_mgr_open(sample_data_filename_t* filename, wrflag_t flag) { - /** - * @brief 查看文件数量 - */ - if (flag == kwrflag_write_only) { - if (zeeprom_fs_get_file_num() >= MAX_FILE_NUM) { - zeeprom_fs_delete_the_oldest_file(); - } - } - return zeeprom_fs_open((uint8_t*)filename, flag); -} -int32_t sample_data_mgr_close(int32_t fd) { return zeeprom_fs_close(fd); } -int32_t sample_data_mgr_write(int32_t fd, const uint8_t* data, int32_t size) { return zeeprom_fs_write(fd, data, size); } -int32_t sample_data_mgr_read(int32_t fd, uint8_t* data, int32_t size) { return zeeprom_fs_read(fd, data, size); } -int32_t sample_data_mgr_get_file_size_by_fd(int32_t fd) { return zeeprom_fs_get_filesize_by_fd(fd); } -int32_t sample_data_mgr_delete_file(sample_data_filename_t* filename) { return zeeprom_fs_delete_by_name((uint8_t*)filename); } diff --git a/app/src/service/storage/sample_data_manager.h b/app/src/service/storage/sample_data_manager.h deleted file mode 100644 index 3a70e22..0000000 --- a/app/src/service/storage/sample_data_manager.h +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once -#include -#include - -#include "aproject_config/config.h" -#include "zeeprom_fs.h" - -void sample_data_mgr_init(); - -typedef struct { - uint8_t year; - uint8_t month; - uint8_t day; - uint8_t hour; - uint8_t min; - uint8_t sec; - uint8_t placeholder[2]; -} sample_data_filename_t; - -typedef struct { - uint8_t filename[8]; - int32_t fileuuid; - int32_t size; - uint32_t checksum; -} sample_data_fileinfo_t; - -typedef struct { - sample_data_fileinfo_t* fileinfo[MAX_FILE_NUM]; - int count; -} sample_data_fileinfo_list_t; - -void sample_data_mgr_init(); -void sample_data_mgr_uninit(); - -sample_data_fileinfo_list_t* sample_data_mgr_get_fileinfo_list(); -bool sample_data_mgr_storage_is_full(); -int32_t sample_data_mgr_get_file_num(); - -int32_t sample_data_mgr_open(sample_data_filename_t* filename, wrflag_t flag); -int32_t sample_data_mgr_close(int32_t fd); - -int32_t sample_data_mgr_write(int32_t fd, const uint8_t* data, int32_t size); -int32_t sample_data_mgr_read(int32_t fd, uint8_t* data, int32_t size); -int32_t sample_data_mgr_get_file_size_by_fd(int32_t fd); - -int32_t sample_data_mgr_delete_file(sample_data_filename_t* filename); diff --git a/app/src/service/storage/storage_service.h b/app/src/service/storage/storage_service.h deleted file mode 100644 index 895d343..0000000 --- a/app/src/service/storage/storage_service.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once -#include "sample_data_manager.h" -#include "zeeprom_fs.h" diff --git a/app/src/service/storage/zeeprom_fs.c b/app/src/service/storage/zeeprom_fs.c deleted file mode 100644 index 1c6594a..0000000 --- a/app/src/service/storage/zeeprom_fs.c +++ /dev/null @@ -1,572 +0,0 @@ -#include "zeeprom_fs.h" - -#include "board/board_eeprom_driver.h" - -static zeeprom_header_t m_eeprom_header; -static bool m_is_init = false; - -static filehandler_t m_filehandler[2]; -static int m_fd_off; - -/******************************************************************************* - * 函数声明 * - *******************************************************************************/ - -static filehandler_t* filehandler_find(int fd); -static filehandler_t* filehandler_alloc(); -static void filehandler_rlease(int fd); - -static int32_t sector_mgr_find_earliest_file_created_index(); -static int32_t sector_mgr_free_sector(int32_t fileuuid); -static zeeprom_sector_info_t* sector_mgr_find_idle_sector(); -static bool sector_mgr_sector_is_open(int32_t fileuuid); -static zeeprom_sector_info_t* sector_mgr_force_find_idle_sector(); -static void sector_mgr_open_sector(int32_t fileuuid); -static void sector_mgr_close_sector(int32_t fileuuid); -// static zeeprom_sector_info_t* sector_mgr_find_fileheader(int32_t fileuuid); -static zeeprom_sector_info_t* sector_mgr_find_end_sector(int32_t fileuuid); -static zeeprom_sector_info_t* sector_mgr_find_sector(int32_t fileuuid, int32_t sector_index_in_file); -static int32_t sector_mgr_file_get_size(int32_t fileuuid); - -static zeeprom_sector_info_t* sector_mgr_find_fileheader_by_filename(uint8_t* fileid); -static int32_t sector_mgr_get_sector_offset(zeeprom_sector_info_t* sector); -static int32_t sector_mgr_get_sector_rom_add(zeeprom_sector_info_t* sector); -static int32_t sector_mgr_file_get_checksum(int32_t fileuuid); - -static void zeeprom_read(int32_t add, uint8_t* data, uint16_t len); -static void zeeprom_write(int32_t add, const uint8_t* data, uint16_t len); -static uint32_t compute_checksum(const uint8_t* data, uint16_t len); - -/******************************************************************************* - * CODE * - *******************************************************************************/ - -static bool m_eeprom_header_inited = false; -int zeeprom_fs_init() { // - board_eeprom_init(); - if (!m_eeprom_header_inited) { - zeeprom_read(0, (uint8_t*)&m_eeprom_header, sizeof(m_eeprom_header)); - uint32_t checksum_val = compute_checksum((uint8_t*)&m_eeprom_header, sizeof(m_eeprom_header) - sizeof(m_eeprom_header.sector_info_headers_checksum)); - if (checksum_val != m_eeprom_header.sector_info_headers_checksum) { - memset(&m_eeprom_header, 0, sizeof(m_eeprom_header)); - } - } - m_is_init = true; - m_eeprom_header_inited = true; - return 0; -} -int zeeprom_fs_uinit() { // - // zeeprom_write(0, (uint8_t*)&m_eeprom_header, sizeof(m_eeprom_header)); - board_eeprom_uninit(); - m_is_init = false; - return 0; -} - -zeeprom_header_t* zeeprom_fs_get_header() { return &m_eeprom_header; } - -int zeeprom_fs_open(uint8_t* filename, wrflag_t wrflag) { - ZASSERT(m_is_init); - /** - * @brief - * 1. 如果文件已经存在,则打开文件 - * 2. 如果文件不存在, 则创建文件 - * - * 创建文件: - * 1. 找到一个空闲扇区 - * 2. 初始化文件头 - */ - - filehandler_t* fileHander = filehandler_alloc(); - if (!fileHander) { - ZLOGI("fileHander_alloc fail"); - return -1; - } - - if (wrflag == kwrflag_write_only) { - /******************************************************************************* - * 写文件 * - *******************************************************************************/ - zeeprom_sector_info_t* sectorHeaderInfo = NULL; - zeeprom_fs_delete_by_name(filename); - - sectorHeaderInfo = sector_mgr_force_find_idle_sector(); - if (!sectorHeaderInfo) { - ZLOGE("sector_mgr_force_find_idle_sector fail"); - filehandler_rlease(fileHander->fd); - return -1; - } - - memset(sectorHeaderInfo, 0, sizeof(zeeprom_sector_info_t)); - sectorHeaderInfo->usage = 1; - sectorHeaderInfo->opened = 1; - memcpy(sectorHeaderInfo->filename, filename, 8); - sectorHeaderInfo->sector_index_in_file = 0; - sectorHeaderInfo->datalen = 0; - sectorHeaderInfo->sector_data_checksum = 0; - sectorHeaderInfo->fileuuid = m_eeprom_header.fileuuid_cnt++; - fileHander->fileuuid = sectorHeaderInfo->fileuuid; - fileHander->sector_header = sectorHeaderInfo; - fileHander->file_offset = 0; - fileHander->file_size = 0; - fileHander->checksum = 0; - return fileHander->fd; - - } else { - /******************************************************************************* - * 读文件 * - *******************************************************************************/ - zeeprom_sector_info_t* sectorHeaderInfo = sector_mgr_find_fileheader_by_filename(filename); - if (sectorHeaderInfo) { - fileHander->fileuuid = sectorHeaderInfo->fileuuid; - fileHander->file_offset = 0; - fileHander->fd = fileHander->fd; - fileHander->sector_header = sectorHeaderInfo; - fileHander->file_size = sector_mgr_file_get_size(fileHander->fileuuid); - fileHander->checksum = sector_mgr_file_get_checksum(fileHander->fileuuid); - ZLOGI("filesize:%d", fileHander->file_size); - memcpy(fileHander->filename, filename, 8); - memcpy(fileHander->usrdata, sectorHeaderInfo->usrdata, sizeof(sectorHeaderInfo->usrdata)); - sector_mgr_open_sector(fileHander->fileuuid); - return fileHander->fd; - } else { - filehandler_rlease(fileHander->fd); - return -1; - } - } -} - -int zeeprom_fs_write(int fileid, const uint8_t* data, int32_t size) { - ZASSERT(m_is_init); - - filehandler_t* fileHander = NULL; - zeeprom_sector_info_t* header_sinfo = NULL; - zeeprom_sector_info_t* endsector = NULL; - int32_t wadd = 0; - - ZASSERT(size == EEPROM_SECTOR_MIN_WR_SIZE); - - fileHander = filehandler_find(fileid); - if (!fileHander) { - ZLOGE("fileHander_find fail"); - return -1; - } - - header_sinfo = fileHander->sector_header; - if (!header_sinfo) { - ZLOGE("header_sinfo fail"); - return -1; - } - - endsector = sector_mgr_find_end_sector(fileHander->fileuuid); - if (!endsector) { - ZLOGE("sector_mgr_find_end_sector fail"); - return -1; - } - - if (endsector->datalen + size > EEPROM_SECTOR_SIZE) { - ZLOGE("endsector->datalen + size > EEPROM_SECTOR_SIZE"); - return -1; - } - - wadd = sector_mgr_get_sector_rom_add(endsector); - if (wadd < 0) { - ZLOGE("sector_mgr_get_sector_rom_add fail"); - return -1; - } - ZASSERT(wadd % EEPROM_SECTOR_MIN_WR_SIZE == 0); - ZASSERT(wadd >= EEPROM_SECTOR_SIZE); - zeeprom_write(wadd + endsector->datalen, data, size); - - endsector->datalen = endsector->datalen + size; - endsector->sector_data_checksum += compute_checksum(data, size); - fileHander->file_offset += size; - fileHander->file_size += size; - fileHander->checksum += compute_checksum(data, size); - - if (endsector->datalen == EEPROM_SECTOR_SIZE) { - zeeprom_sector_info_t* newsector = sector_mgr_force_find_idle_sector(); - if (!newsector) { - ZLOGE("sector_mgr_force_find_idle_sector fail"); - return -1; - } - - memset(newsector, 0, sizeof(zeeprom_sector_info_t)); - newsector->usage = 1; - newsector->opened = 1; - newsector->sector_data_checksum = 0; - memcpy(newsector->filename, header_sinfo->filename, 8); - newsector->sector_index_in_file = endsector->sector_index_in_file + 1; - newsector->datalen = 0; - newsector->fileuuid = header_sinfo->fileuuid; - } - return size; -} - -int zeeprom_fs_close(int fileid) { - ZASSERT(m_is_init); - - filehandler_t* fileHander = filehandler_find(fileid); - if (!fileHander) { - ZLOGE("zeeprom_fs_close fileHander_find fail"); - return -1; - } - - sector_mgr_close_sector(fileHander->fileuuid); - uint32_t checksum_val = compute_checksum((uint8_t*)&m_eeprom_header, sizeof(m_eeprom_header) - sizeof(m_eeprom_header.sector_info_headers_checksum)); - m_eeprom_header.sector_info_headers_checksum = checksum_val; - // zeeprom_write(0, (uint8_t*)&m_eeprom_header, sizeof(m_eeprom_header)); - - filehandler_rlease(fileid); - return 0; -} - -int zeeprom_fs_get_filesize_by_fd(int fd) { - ZASSERT(m_is_init); - filehandler_t* fileHander = filehandler_find(fd); - if (!fileHander) return 0; - return fileHander->file_size; -} - -int zeeprom_fs_read(int fileid, uint8_t* data, int32_t size) { - ZASSERT(m_is_init); - - /** - * @brief - * 找到当前扇区 - */ - ZASSERT(size == EEPROM_SECTOR_MIN_WR_SIZE); - filehandler_t* fileHander = filehandler_find(fileid); - if (!fileHander) return -1; - - if (fileHander->file_offset + size > fileHander->file_size) { - return -1; - } - - zeeprom_sector_info_t* header_sinfo = fileHander->sector_header; - if (!header_sinfo) { - return -1; - } - - int32_t sector_idx = fileHander->file_offset / EEPROM_SECTOR_SIZE; - int32_t sector_off = fileHander->file_offset % EEPROM_SECTOR_SIZE; - - zeeprom_sector_info_t* sector = sector_mgr_find_sector(fileHander->fileuuid, sector_idx); - if (!sector) { - return -1; - } - - int32_t radd = sector_mgr_get_sector_rom_add(sector); - ZASSERT(radd % EEPROM_SECTOR_MIN_WR_SIZE == 0); - radd += sector_off; - - zeeprom_read(radd, data, size); - fileHander->file_offset += size; - return size; -} - -int zeeprom_fs_delete(int32_t fileuuid) { - ZASSERT(m_is_init); - - sector_mgr_free_sector(fileuuid); - return 0; -} -int zeeprom_fs_delete_by_name(uint8_t* filename) { - ZASSERT(m_is_init); - - zeeprom_sector_info_t* sectorHeaderInfo = sector_mgr_find_fileheader_by_filename(filename); - if (sectorHeaderInfo) { - sector_mgr_free_sector(sectorHeaderInfo->fileuuid); - } - return 0; -} - -int zeeprom_fs_get_file_num() { - ZASSERT(m_is_init); - - int count = 0; - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - if (sinfo->usage == 1 && sinfo->sector_index_in_file == 0) { - count++; - } - } - return count; -} -int zeeprom_fs_delete_the_oldest_file() { - ZASSERT(m_is_init); - - int32_t earliest_file_created_index = sector_mgr_find_earliest_file_created_index(); - sector_mgr_free_sector(earliest_file_created_index); - return 0; -} - -int zeeprom_fs_get_filesize_by_fileuuid(int32_t fileuuid) { - ZASSERT(m_is_init); - return sector_mgr_file_get_size(fileuuid); -} - -int zeeprom_fs_get_checksum_by_fileuuid(int32_t fileuuid) { - ZASSERT(m_is_init); - return sector_mgr_file_get_checksum(fileuuid); -} - -static void zeeprom_read(int32_t add, uint8_t* data, uint16_t len) { // - int wrsize = EEPROM_SECTOR_MIN_WR_SIZE; - - int readTimes = len / wrsize; - int readRemain = len % wrsize; - - for (int i = 0; i < readTimes; i++) { - board_eeprom_read(add + i * wrsize, data + i * wrsize, wrsize); - } - if (readRemain > 0) { - board_eeprom_read(add + readTimes * wrsize, data + readTimes * wrsize, readRemain); - } -} -static void zeeprom_write(int32_t add, const uint8_t* data, uint16_t len) { - int wrsize = EEPROM_SECTOR_MIN_WR_SIZE; - - int writeTimes = len / wrsize; - int writeRemain = len % wrsize; - - for (int i = 0; i < writeTimes; i++) { - // int pageoff = add / wrsize + i; - int32_t writeadd = add + i * wrsize; - board_eeprom_write(writeadd, data + i * wrsize, wrsize); - } - if (writeRemain > 0) { - int32_t writeadd = add + writeTimes * wrsize; - board_eeprom_write(writeadd, data + writeTimes * wrsize, writeRemain); - } -} - -static uint32_t compute_checksum(const uint8_t* data, uint16_t len) { - uint32_t sum = 0; - for (int i = 0; i < len; i++) { - sum += data[i]; - } - return sum; -} -/******************************************************************************* - * filehandler * - *******************************************************************************/ -static filehandler_t* filehandler_find(int fd) { - for (int i = 0; i < ZARRAY_SIZE(m_filehandler); i++) { - if (m_filehandler[i].fd == fd) { - return &m_filehandler[i]; - } - } - return NULL; -} -static filehandler_t* filehandler_alloc() { - for (int i = 0; i < ZARRAY_SIZE(m_filehandler); i++) { - if (m_filehandler[i].fd == 0) { - m_filehandler[i].fd = ++m_fd_off; - return &m_filehandler[i]; - } - } - return NULL; -} -static void filehandler_rlease(int fd) { - for (int i = 0; i < ZARRAY_SIZE(m_filehandler); i++) { - if (m_filehandler[i].fd == fd) { - m_filehandler[i].fd = 0; - return; - } - } -} -/******************************************************************************* - * sector_mgr * - *******************************************************************************/ - -// 查找最早创建的文件的file_created_index -static int32_t sector_mgr_find_earliest_file_created_index() { - int32_t earliest_file_created_index = INT32_MAX; - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - if (sinfo->usage == 1) { - if (sinfo->fileuuid < earliest_file_created_index) { - earliest_file_created_index = sinfo->fileuuid; - } - } - } - return earliest_file_created_index; -} -// 删除文件 -static int32_t sector_mgr_free_sector(int32_t fileuuid) { - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { - sinfo->usage = 0; - } - } - return 0; -} -// -static zeeprom_sector_info_t* sector_mgr_find_idle_sector() { - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - if (sinfo->usage == 0) { - return sinfo; - } - } - return NULL; -} -static bool sector_mgr_sector_is_open(int32_t fileuuid) { - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { - return sinfo->opened; - } - } - return false; -} - -static zeeprom_sector_info_t* sector_mgr_force_find_idle_sector() { - /** - * @brief 查找空闲扇区 - */ - zeeprom_sector_info_t* ret_sinfo = sector_mgr_find_idle_sector(); - if (ret_sinfo) return ret_sinfo; - /** - * @brief 查找最早创建的文件 - */ - int32_t earliest_file_created_index = sector_mgr_find_earliest_file_created_index(); - if (sector_mgr_sector_is_open(earliest_file_created_index)) { - return NULL; - } - - /** - * @brief 删除最早创建的文件 - */ - sector_mgr_free_sector(earliest_file_created_index); - - /** - * @brief 重新查找空闲扇区 - */ - ret_sinfo = sector_mgr_find_idle_sector(); - if (ret_sinfo) return ret_sinfo; - - return NULL; -} - -static void sector_mgr_open_sector(int32_t fileuuid) { - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { - sinfo->opened = true; - } - } -} - -static void sector_mgr_close_sector(int32_t fileuuid) { - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { - sinfo->opened = false; - } - } -} - -// static zeeprom_sector_info_t* sector_mgr_find_fileheader(int32_t fileuuid) { -// for (int i = 0; i < MAX_SECTOR_NUM; i++) { -// zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; -// if (sinfo->usage == 1 && sinfo->sector_index_in_file == 0 && sinfo->fileuuid == fileuuid) { -// return sinfo; -// } -// } -// return NULL; -// } - -static zeeprom_sector_info_t* sector_mgr_find_sector(int32_t fileuuid, int32_t sector_index_in_file) { - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - if (sinfo->usage == 1 && sinfo->sector_index_in_file == sector_index_in_file && sinfo->fileuuid == fileuuid) { - return sinfo; - } - } - return NULL; -} - -static zeeprom_sector_info_t* sector_mgr_find_end_sector(int32_t fileuuid) { - int32_t maxsectorindex = 0; - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { - if (sinfo->sector_index_in_file >= maxsectorindex) { - maxsectorindex = sinfo->sector_index_in_file; - } - } - } - return sector_mgr_find_sector(fileuuid, maxsectorindex); -} - -static zeeprom_sector_info_t* sector_mgr_find_fileheader_by_filename(uint8_t* fileid) { - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - if (sinfo->usage == 1 && sinfo->sector_index_in_file == 0 && memcmp(sinfo->filename, fileid, 8) == 0) { - return sinfo; - } - } - return NULL; -} - -static int32_t sector_mgr_get_sector_offset(zeeprom_sector_info_t* sector) { - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - if (sinfo == sector) { - return i; - } - } - return -1; -} - -static int32_t sector_mgr_get_sector_rom_add(zeeprom_sector_info_t* sector) { - int32_t offset = sector_mgr_get_sector_offset(sector); - if (offset < 0) return -1; - return (offset + 1) * EEPROM_SECTOR_SIZE; -} - -static int32_t sector_mgr_file_get_size(int32_t fileuuid) { - int32_t filesize = 0; - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - - if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { - filesize += sinfo->datalen; - } - } - return filesize; -} - -static int32_t sector_mgr_file_get_checksum(int32_t fileuuid) { - int32_t checksum = 0; - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - - if (sinfo->usage == 1 && sinfo->fileuuid == fileuuid) { - checksum += sinfo->sector_data_checksum; - } - } - return checksum; -} - -static const char* filename2str(uint8_t* filename) { - static char filename_str[32]; - sprintf(filename_str, "%02x%02x%02x%02x%02x%02x%02x%02x", filename[0], filename[1], filename[2], filename[3], filename[4], filename[5], filename[6], filename[7]); - return filename_str; -} - -int zeeprom_fs_dump_sector_state() { - ZLOGI_BLOCK("zeeprom_fs_dump_sector_state\n"); - for (int i = 0; i < MAX_SECTOR_NUM; i++) { - zeeprom_sector_info_t* sinfo = &m_eeprom_header.sectorinfos[i]; - if (sinfo->usage == 1) { - ZLOGI_BLOCK("[%d]: usage=%d opened=%d", i, sinfo->usage, sinfo->opened); - ZLOGI_BLOCK(" fname=%s, index_in_file=%d, datalen=%d, fileuuid=%d", filename2str(sinfo->filename), sinfo->sector_index_in_file, sinfo->datalen, sinfo->fileuuid); - } else { - ZLOGI_BLOCK("[%d]: usage=%d", i, sinfo->usage); - } - } - return 0; -} diff --git a/app/src/service/storage/zeeprom_fs.h b/app/src/service/storage/zeeprom_fs.h deleted file mode 100644 index 642a53f..0000000 --- a/app/src/service/storage/zeeprom_fs.h +++ /dev/null @@ -1,108 +0,0 @@ -#pragma once -#include -/** - * @brief EEPROM简易文件系统代码框架 - * - * 整个存储区域分为两个区 [扇区头][文件数据区] - * - * ----------------- - * | | - * | 扇区头 | 8K * 1 - * | | - * ----------------- - * | | - * | N*数据扇区 | 8K * 31 - * | | - * ----------------- - * - * 扇区头存储 31* zeeprom_sector_info_t个结构体 - * 结构体:zeeprom_sector_info_t * 31 - * uint8_t usage; // 0:空闲 1:已使用 - * uint8_t opened; // 0:未打开 1:已打开 - * uint8_t filename[8]; // 文件名 - * int32_t sector_index_in_file; // 当前扇区中文件数据的起始地址 - * int32_t datalen; // 当前扇区中文件数据的长度 - * uint32_t checksum; // 文件数据的校验和 - * int32_t fileuuid; // 递增,根据这个index判断文件创建的先后顺序,同时也相当于文件唯一标识 - * uint8_t usrdata[20]; // 用户数据 - * - * - * 文件的概念: - * 1.一个文件由一个或多个扇区组成,每个扇区的大小为8K, - * 2.同一个文件依靠fileuuid进行判定 - * 3.如果想要读取文件大小,只需计算相同fileuuid的所有zeeprom_sector_info_t.datalen的和即可。 - * 4.文件顺序依靠sector_index_in_file进行判断 - * 5.文件名保存在sector_index_in_file为0的zeeprom_sector_info_t结构体中 - * - * 扇区头的特殊性: - * 1. 扇区头常驻内存中 - * 2. 如果期望掉电丢弃数据,扇区头不保存导flash中即可 - * - */ - -#define EEPROM_SIZE (256 * 1024) -#define EEPROM_SECTOR_MIN_WR_SIZE (256) -#define EEPROM_SECTOR_SIZE (8 * 1024) -#define MAX_SECTOR_NUM (EEPROM_SIZE / EEPROM_SECTOR_SIZE - 1) -#define EEPROM_FILE_SIZE (EEPROM_SECTOR_SIZE * MAX_SECTOR_NUM) - -// -#pragma pack(1) -typedef struct { - uint8_t usage; - uint8_t opened; - uint8_t filename[8]; // 注意文件名为固定八个字节的二进制数据,不是字符串 - int32_t sector_index_in_file; // 当前扇区中文件数据的起始地址 - int32_t datalen; // 当前扇区中文件数据的长度 - uint32_t sector_data_checksum; // 文件数据的校验和 - int32_t fileuuid; // 递增,根据这个index判断文件创建的先后顺序,同时也相当于文件唯一标识 - uint8_t usrdata[20]; -} zeeprom_sector_info_t; - -typedef struct { - uint8_t filename[8]; - uint8_t usrdata[20]; - - zeeprom_sector_info_t* sector_header; - int32_t file_offset; - int32_t file_size; - uint32_t checksum; - - int fd; - int32_t fileuuid; -} filehandler_t; - -typedef struct { - zeeprom_sector_info_t sectorinfos[MAX_SECTOR_NUM]; - int32_t fileuuid_cnt; // 递增,新创建文件时使用 - uint32_t sector_info_headers_checksum; // 扇区头的校验和 -} zeeprom_header_t; -#pragma pack() - -int zeeprom_fs_init(); -int zeeprom_fs_uinit(); - -typedef enum { - kwrflag_read_only, - kwrflag_write_only, -} wrflag_t; - -zeeprom_header_t* zeeprom_fs_get_header(); - -int zeeprom_fs_open(uint8_t* filename, wrflag_t flag); - -int zeeprom_fs_close(int fd); - -int zeeprom_fs_write(int fd, const uint8_t* data, int32_t size); -int zeeprom_fs_read(int fd, uint8_t* data, int32_t size); - -int zeeprom_fs_get_filesize_by_fd(int fd); - -int zeeprom_fs_get_file_num(); -int zeeprom_fs_delete_the_oldest_file(); -int zeeprom_fs_delete(int32_t fileuuid); -int zeeprom_fs_delete_by_name(uint8_t* filename); - -int zeeprom_fs_dump_sector_state(); -int zeeprom_fs_get_filesize_by_fileuuid(int32_t fileuuid); -int zeeprom_fs_get_checksum_by_fileuuid(int32_t fileuuid);