From 4ecd5f9d11ad043394e326c913f166f2395c309f Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Tue, 17 Dec 2024 16:23:49 +0800 Subject: [PATCH] =?utf8?q?=E6=B7=BB=E5=8A=A0=E8=BF=90=E8=A1=8C=E6=97=A5?= =?utf8?q?=E5=BF=97=E4=BF=9D=E5=AD=98=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../brandy/brandy_standard/thread_pri_init.c | 5 +- .../debug_output_notification.cpp | 33 +++ .../peripheral/config/include/ConfigModel.h | 4 + .../peripheral/config/include/ConfigModelC.h | 5 + .../peripheral/config/src/ConfigModel.cpp | 10 + .../drivers/peripheral/utils/CMakeLists.txt | 2 + .../peripheral/utils/custom_save_runtime.c | 223 ++++++++++++++++++ .../peripheral/utils/custom_save_runtime.h | 46 ++++ .../peripheral/utils/custom_utils_at_cmd.c | 6 +- 9 files changed, 332 insertions(+), 2 deletions(-) create mode 100644 code/sdk/drivers/peripheral/utils/custom_save_runtime.c create mode 100644 code/sdk/drivers/peripheral/utils/custom_save_runtime.h diff --git a/code/sdk/application/brandy/brandy_standard/thread_pri_init.c b/code/sdk/application/brandy/brandy_standard/thread_pri_init.c index e915f6e3e..99d5caf34 100755 --- a/code/sdk/application/brandy/brandy_standard/thread_pri_init.c +++ b/code/sdk/application/brandy/brandy_standard/thread_pri_init.c @@ -106,6 +106,8 @@ #ifdef ENABLE_CUSTOM_I2C #include "custom_utils.h" +#include "custom_save_runtime.h" + #endif #ifdef SUPPORT_A5133_SERVICE @@ -429,7 +431,8 @@ static void thread_main(const void *unused) * */ ConfigModelInit(); - + + uapi_runtime_log_service_init(); #if DSP_EXIST == YES audio_init(); 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 fe5e7a6de..0ec8a7dc5 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 @@ -60,6 +60,8 @@ #include "displaybrightness/include/DisplayBrightnessModel.h" #include "ppg_service.h" #include "diag_log.h" + +#include "ConfigModelC.h" namespace OHOS { /**************************************************************************************************** */ @@ -168,6 +170,9 @@ namespace OHOS //心率广播 debugOutputItemInfo[index++] = {index, "hrs_ble_swtich"}; + debugOutputItemInfo[index++] = {index, "save_runtime_log_swtich"}; + + usedLen = index; /* -------------------------------- Add data -------------------------------- */ for (uint8_t i = 0; i < usedLen; i++) @@ -816,6 +821,21 @@ namespace OHOS } return true; //进行UI刷新 } + else if (viewId == "runtime_log_is_save") + { + if (toggleButtonOffline) { + if (toggleButtonOffline->GetState() == false) { + set_save_runtime_log_switch(1); + } + else { + set_save_runtime_log_switch(0); + } + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"组件不存在"); + } + return true; //进行UI刷新 + } + else if (viewId == NEXTORPREPAGELABELBUTTON) { // std::string str; @@ -956,6 +976,19 @@ namespace OHOS } } break; + case 19: + // str = get_hrs_ble_status(); + str = "runtime_log_is_save"; + if(toggleButtonOffline) + { + if(toggleButtonOffline->IsVisible() == false) + { + toggleButtonOffline->SetState(get_save_runtime_log_switch()); + toggleButtonOffline->SetViewId("runtime_log_is_save"); + toggleButtonOffline->SetVisible(true); + } + } + break; default: str = "--"; break; diff --git a/code/sdk/drivers/peripheral/config/include/ConfigModel.h b/code/sdk/drivers/peripheral/config/include/ConfigModel.h index f752a514b..88f2e7885 100644 --- a/code/sdk/drivers/peripheral/config/include/ConfigModel.h +++ b/code/sdk/drivers/peripheral/config/include/ConfigModel.h @@ -153,6 +153,8 @@ namespace OHOS CONFIGMODEL_ITEM_SPORTS_GOAL_DISTANCE_TIME, //运动目标距离 CONFIGMODEL_ITEM_URAT_AT_CONTROL_STATUS,//串口控制状态 + + CONFIGMODEL_ITEM_SAVE_RUNTIMR_LOG_STATUS,//运行日志保存 CONFIGMODEL_ITEM_MAX, @@ -417,6 +419,8 @@ namespace OHOS {ConfigDataType::DATATYPE_INT, "goal_duration_time", "1" },// CONFIGMODEL_ITEM_SPORTS_GOAL_DURATION, //运动目标时长 30(分钟) {ConfigDataType::DATATYPE_INT, "goal_distance_time", "1" },// CONFIGMODEL_ITEM_SPORTS_GOAL_DISTANCE, //运动目标距离 8.0(km) {ConfigDataType::DATATYPE_INT, "urat_at_status", "false" },//CONFIGMODEL_ITEM_URAT_AT_CONTROL_STATUS // 串口AT 默认 关闭 + {ConfigDataType::DATATYPE_INT, "runtime_log_status", "0" },//CONFIGMODEL_ITEM_SAVE_RUNTIMR_LOG_STATUS,//运行日志保存 + }; ConfigModel(); // 私有构造函数,确保无法在外部实例化 diff --git a/code/sdk/drivers/peripheral/config/include/ConfigModelC.h b/code/sdk/drivers/peripheral/config/include/ConfigModelC.h index de2fb6ad2..19c2f23bd 100644 --- a/code/sdk/drivers/peripheral/config/include/ConfigModelC.h +++ b/code/sdk/drivers/peripheral/config/include/ConfigModelC.h @@ -138,6 +138,11 @@ bool mmi_play_vibrate_is_permitted(void); /*停止音乐播放*/ void mmi_stop_music_play(void); +void set_save_runtime_log_switch(int value); + +int get_save_runtime_log_switch(void); + + #ifdef __cplusplus #if __cplusplus } diff --git a/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp b/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp index 46d350db0..224d84b7f 100644 --- a/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp +++ b/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp @@ -1611,6 +1611,16 @@ void mmi_stop_music_play(void) stopPlayingMusic(); } + +void set_save_runtime_log_switch(int value) +{ + OHOS::ConfigModel::GetInstance()->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_SAVE_RUNTIMR_LOG_STATUS,value); +} + +int get_save_runtime_log_switch(void) +{ + return OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_SAVE_RUNTIMR_LOG_STATUS); +} #ifdef __cplusplus #if __cplusplus } diff --git a/code/sdk/drivers/peripheral/utils/CMakeLists.txt b/code/sdk/drivers/peripheral/utils/CMakeLists.txt index da240fa01..b5c85496a 100644 --- a/code/sdk/drivers/peripheral/utils/CMakeLists.txt +++ b/code/sdk/drivers/peripheral/utils/CMakeLists.txt @@ -13,6 +13,8 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/pdu.c ${CMAKE_CURRENT_SOURCE_DIR}/microtar.c ${CMAKE_CURRENT_SOURCE_DIR}/custom_resfile_check.c + ${CMAKE_CURRENT_SOURCE_DIR}/custom_save_runtime.c + ) set(PUBLIC_HEADER diff --git a/code/sdk/drivers/peripheral/utils/custom_save_runtime.c b/code/sdk/drivers/peripheral/utils/custom_save_runtime.c new file mode 100644 index 000000000..0cc3b21a1 --- /dev/null +++ b/code/sdk/drivers/peripheral/utils/custom_save_runtime.c @@ -0,0 +1,223 @@ +/** + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n + * + * Description: Test adc source \n + * Author: @CompanyNameTag \n + * History: \n + * 2022-08-16, Create file. \n + */ +#include "pinctrl.h" +#include "debug_print.h" +#include "soc_osal.h" +#include "tcxo.h" +#include "irmalloc.h" +#include "errcode.h" +#include "common_def.h" + +#include "chip_core_irq.h" +#include "chip_io.h" +#include "gpio.h" +#include "pm_veto.h" + +#include "rtc.h" +#include "timer.h" +#include "systick.h" + +#include "tcxo.h" + +#include "cmsis_os2.h" + +#include "los_printf.h" + +#include "custom_utils.h" + +#include "BluetoothModelC.h" + +#include "PhoneServiceC.h" + +#include "ui_serviceC.h" + +#include "bletest.h" + +#include "safemodemanager/include/SafeModeManagerModelC.h" +#include "set_dial/include/SetDialModelC.h" + +#include "alarmclocktimerconfig/include/AlarmClockTimerConfig.h" + +#include + +#define RUNTIME_LOG_SAVE_PATH EXC_TAR_PATH + + + +typedef struct +{ + uint16_t cmd; + uint32_t time; +} custom_cmd_t; + +static unsigned long g_custom_runtime_log_cmd_queue= 0xFFFFFFFF; +static uint8_t custom_running_log_state_stat=0; +static bool g_runtime_log_queue_created = 0; + +static char save_path[128]={0}; + + +errcode_t uapi_save_runtime_log(uint16_t cmd) +{ + int ret; + + custom_cmd_t mail = {0}; + mail.cmd = (uint16_t)cmd; + mail.time= (uint32_t)get_local_timestamp(); + + if(custom_running_log_state_stat==0 || g_runtime_log_queue_created==0) + { + return ERRCODE_FAIL; + } + ret = osal_msg_queue_write_copy(g_custom_runtime_log_cmd_queue, (void *)&mail, sizeof(custom_cmd_t), 0); + + if (ret != OSAL_SUCCESS) + { + PRINT("Error custom_cmd Check MSG 0x%02X send failed! err=0x%x! \r\n", cmd, ret); + return ERRCODE_FAIL; + } + + return ERRCODE_SUCC; +} + +#define RUNTIME_FILE_PATH "%s/%s_runtime_%d.bin" + +void create_runtime_log_path(char *path,uint16_t max_len,uint8_t count) +{ + char buildversion[64]={0}; + uapi_get_buildversion((uint8_t*)&buildversion[0],sizeof(buildversion)); + + sprintf_s(path,max_len,RUNTIME_FILE_PATH,RUNTIME_LOG_SAVE_PATH,buildversion,count); +} + + +uint8_t uapi_runtime_file_count(char *folderpath) +{ + DIR *dir; + struct dirent *entry; + uint8_t count = 0; + + dir = opendir(folderpath); + if (dir == NULL) + { + PRINT("open %s failed \n",folderpath); + return 0; + } + + while ((entry = readdir(dir))!= NULL) //遍历tar文件找到时间戳最老的文件名 + { + if (strstr(entry->d_name, "_runtime_")!= NULL) + { + count++; + + } + } + + closedir(dir); + return count; +} + + +static void custom_save_runtime_log_service_task(void const *arg) +{ + + int32_t ret; + custom_cmd_t mail; + uint32_t msgsize = (uint32_t)sizeof(custom_cmd_t); + custom_running_log_state_stat = true; + int code=0; + + while (1) + { + ret = osal_msg_queue_read_copy(g_custom_runtime_log_cmd_queue, (void *)&mail, &msgsize, + OSAL_MSGQ_WAIT_FOREVER); + if (ret != OSAL_SUCCESS) + { + continue; + } + + FILE *fp=fopen(save_path,"ab+"); + if(fp) + { + int ret= fwrite(&mail.cmd,sizeof(mail.cmd),1,fp); + if(ret!=1) + { + printf("[custom_save_runtime_log_service_task],save_fail%d \n",__LINE__); + + uint8_t file_count= uapi_runtime_file_count(RUNTIME_LOG_SAVE_PATH); + create_runtime_log_path(save_path,128,file_count); + + } + ret= fwrite(&mail.time,sizeof(mail.time),1,fp); + if(ret!=1) + { + printf("[custom_save_runtime_log_service_task],save_fail%d \n",__LINE__); + + uint8_t file_count= uapi_runtime_file_count(RUNTIME_LOG_SAVE_PATH); + create_runtime_log_path(save_path,128,file_count); + + } + } + else + { + printf("[custom_save_runtime_log_service_task],save_fail%d \n",__LINE__); + uint8_t file_count= uapi_runtime_file_count(RUNTIME_LOG_SAVE_PATH); + create_runtime_log_path(save_path,128,file_count); + + } + fclose(fp); + + } +} +#define CUSTOM_RUNTIME_LOG_COUNT 1000 + +#define CUSTOM_RUNTIME_LOG_TASK_SIZE 0x1000 +#define CUSTOM_CMD_BOARD_TASK_PRIO 7 + +void create_runtime_log_queue(void) +{ + if (osal_msg_queue_create("custom_runtime_log_queue", CUSTOM_RUNTIME_LOG_COUNT, &g_custom_runtime_log_cmd_queue, + 0, sizeof(custom_cmd_t)) != ERRCODE_SUCC) + { + printf("[custom_cmd][service] app create mail fail\n"); + g_runtime_log_queue_created = 0; + }else{ + g_runtime_log_queue_created = 1; + } +} +errcode_t uapi_runtime_log_service_init(void) +{ + + PRINT("uapi_custom_cmd_service_init !\r\n"); + + if(get_save_runtime_log_switch()==0) + return ERRCODE_FAIL; + + + app_task_definition_t taskcfg = {0}; + taskcfg.create_queue_handle = create_runtime_log_queue; + taskcfg.attr.name = "custom_runtime_log_service"; + taskcfg.attr.priority = osPriorityNormal; + taskcfg.attr.stack_size = CUSTOM_RUNTIME_LOG_TASK_SIZE; + taskcfg.func = custom_save_runtime_log_service_task; + taskcfg.use_mem = USE_EXTEND_MEM; + + errcode_t ret = uapi_create_osThread_custom(&taskcfg); + uint8_t file_count= uapi_runtime_file_count(RUNTIME_LOG_SAVE_PATH); + create_runtime_log_path(save_path,128,file_count); + + + if (ret != ERRCODE_SUCC) + { + PRINT("create custom_cmd_service failed %d!\r\n", ret); + return ERRCODE_FAIL; + } + + return ERRCODE_SUCC; +} diff --git a/code/sdk/drivers/peripheral/utils/custom_save_runtime.h b/code/sdk/drivers/peripheral/utils/custom_save_runtime.h new file mode 100644 index 000000000..dba2b365d --- /dev/null +++ b/code/sdk/drivers/peripheral/utils/custom_save_runtime.h @@ -0,0 +1,46 @@ +/** + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n + * + * Description: Provides at cmd register func \n + * Author: @CompanyNameTag \n + * History: \n + * 2022-07-20, Create file. \n + */ +#ifndef CUSTOM_RUNTIME_LOG_H +#define CUSTOM_RUNTIME_LOG_H + +#include +#include +#include "errcode.h" +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + + +typedef enum { + //开机关机 + RUNTIME_LOG_POWER_MIN =0x0000, + //蓝牙 + RUNTIME_LOG_POWER_BLE_MIN=0x0100, + //cat1 + RUNTIME_LOG_POWER_CAT1_MIN=0x0200, + + +} runtime_log_cmd_Id; + + + + +errcode_t uapi_save_runtime_log(uint16_t cmd); + +errcode_t uapi_runtime_log_service_init(void); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif diff --git a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c index d36154488..51c3d7dc9 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c @@ -1069,6 +1069,7 @@ static uint32_t PBAP_LS(uint8_t *para, uint32_t paraLen, char *strCommonCmd) #include "battery_service.h" #include "cywee_hal.h" #include "broadcast_feature.h" +#include "custom_save_runtime.h" static uint32_t BLE_TEST(uint8_t *para, uint32_t paraLen, char *strCommonCmd) { @@ -1150,7 +1151,10 @@ static uint32_t BLE_TEST(uint8_t *para, uint32_t paraLen, char *strCommonCmd) case 19: uapi_ble_connect_param_update(type_2); break; - + case 20: + uapi_save_runtime_log(0x0001); + break; + default: break; } -- 2.17.1