From e920117a256759e37db30f4700a9095400921e36 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E5=BD=AD=E7=A3=8A?= <1624952103@qq.com> Date: Sat, 7 Dec 2024 09:25:23 +0000 Subject: [PATCH] Merge #1504 into sdk602patch0911 from refs/changes/1504/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit -优化debug界面电池信息与佩戴信息存储 --- .../battery/service/battery_service.cpp | 36 +++++++++++-------- .../debug_output_notification.cpp | 7 +++- .../drivers/peripheral/cywee/src/main_dml.c | 30 ++++++++-------- 3 files changed, 42 insertions(+), 31 deletions(-) diff --git a/code/sdk/application/battery/service/battery_service.cpp b/code/sdk/application/battery/service/battery_service.cpp index 0e19fd5bf..9096afe1d 100644 --- a/code/sdk/application/battery/service/battery_service.cpp +++ b/code/sdk/application/battery/service/battery_service.cpp @@ -45,6 +45,7 @@ extern "C" { #include "cywee_service.h" +#define BAT_FILE_COUNT 180 bool batteryservice_get_voltage_by_channel(float *voltage, uint8_t channel); battery_info_t *get_current_battery_info(void); @@ -103,41 +104,39 @@ static uint32_t len = 0; void battery_file_check(BATTERY_DATA_T newStruct, const char *filename) { FILE *fp; - BATTERY_DATA_T data[200]; - uint8_t count = 0; + uint16_t count = 0; // uint8_t oldest = 0; fp = fopen(filename, "r+b"); if(!fp) + { fp = fopen(filename, "wb"); + } fseek(fp, 0, SEEK_END); count = ftell(fp) / sizeof(BATTERY_DATA_T); fseek(fp, 0, SEEK_SET); - // PRINT("battery data count %d \n",count); - if (count >= 180) + + if (count >= BAT_FILE_COUNT) { - fread(data, sizeof(BATTERY_DATA_T), count, fp); + BATTERY_DATA_T data[BAT_FILE_COUNT] = {0}; - for (int i = 0; i < count - 1; i++) + fseek(fp,(count - BAT_FILE_COUNT + 1) * sizeof(BATTERY_DATA_T), SEEK_SET); + fread(data, sizeof(BATTERY_DATA_T), BAT_FILE_COUNT - 1, fp); + data[BAT_FILE_COUNT - 1] = newStruct; + + if(count > BAT_FILE_COUNT) { - // if (data[i].tm < data[oldest].tm) - // { - // oldest = i; - // } - data[i] = data[i + 1]; + fp = freopen(filename, "wb", fp); } - data[count - 1] = newStruct; - fseek(fp, 0, SEEK_SET); - fwrite(data, sizeof(BATTERY_DATA_T), count, fp); + fwrite(data, sizeof(BATTERY_DATA_T), BAT_FILE_COUNT, fp); } else { fseek(fp, 0, SEEK_END); fwrite(&newStruct, sizeof(BATTERY_DATA_T), 1, fp); } - fclose(fp); } @@ -148,6 +147,10 @@ void battery_get_data_t(BATTERY_DATA_T **data,uint16_t *length) return; *length = len; *data = (BATTERY_DATA_T *)malloc(len); + + if(*data == NULL) + return; + memcpy_s(*data,len,bat_t,len); free(bat_t); } @@ -159,6 +162,9 @@ void battery_get_data(void) return; bat_t = (BATTERY_DATA_T *)malloc(len); + if(bat_t == NULL) + return; + FILE *fp; fp = fopen("/user/userdata/bat_data.bin", "rb"); diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp index 0bf26fa02..fe5e7a6de 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp @@ -507,7 +507,12 @@ namespace OHOS } else if(get_battery_percent_flag == 2) { - if(len >= 120) + if(len >= 180) + { + index = 120; + len = 180; + } + else if(len >= 120 && len < 180) index = 120; else return result; diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c index 489c24dc4..f90ba62a5 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main_dml.c +++ b/code/sdk/drivers/peripheral/cywee/src/main_dml.c @@ -34,6 +34,8 @@ #define SLEEP_STATUS_LENGTH 50 +#define WEAR_FILE_COUNT 50 + static gsenson_t gxyz_t; static uint8_t gsenson_falg=0; @@ -1914,9 +1916,7 @@ void cywee_custom_save_nap_data(void) void wear_file_check(SLEEP_STAT_T newStruct, const char *filename) { FILE *fp; - SLEEP_STAT_T data[50]; - uint8_t count = 0; - // uint8_t oldest = 0; + uint16_t count = 0; fp = fopen(filename, "r+b"); if(!fp) fp = fopen(filename, "wb"); @@ -1924,24 +1924,24 @@ void wear_file_check(SLEEP_STAT_T newStruct, const char *filename) fseek(fp, 0, SEEK_END); count = ftell(fp) / sizeof(SLEEP_STAT_T); fseek(fp, 0, SEEK_SET); - // PRINT("battery data count %d \n",count); - if (count >= 50) + + if (count >= WEAR_FILE_COUNT) { - fread(data, sizeof(SLEEP_STAT_T), count, fp); + SLEEP_STAT_T data[WEAR_FILE_COUNT] = {0}; + + fseek(fp,(count - WEAR_FILE_COUNT + 1) * sizeof(SLEEP_STAT_T), SEEK_SET); + fread(data, sizeof(SLEEP_STAT_T), WEAR_FILE_COUNT - 1, fp); - for (int i = 0; i < count - 1; i++) + data[WEAR_FILE_COUNT - 1] = newStruct; + + if(count > WEAR_FILE_COUNT) { - // if (data[i].tm < data[oldest].tm) - // { - // oldest = i; - // } - data[i] = data[i + 1]; + fp = freopen(filename, "wb", fp); } - data[count - 1] = newStruct; - fseek(fp, 0, SEEK_SET); - fwrite(data, sizeof(SLEEP_STAT_T), count, fp); + + fwrite(data, sizeof(SLEEP_STAT_T), WEAR_FILE_COUNT, fp); } else { -- 2.17.1