添加运行日志保存服务 1523/3 1523/head
authorhcj <1224667075@qq.com>
Tue, 17 Dec 2024 08:23:49 +0000 (16:23 +0800)
committerhcj <1224667075@qq.com>
Tue, 17 Dec 2024 08:23:49 +0000 (16:23 +0800)
code/sdk/application/brandy/brandy_standard/thread_pri_init.c
code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp
code/sdk/drivers/peripheral/config/include/ConfigModel.h
code/sdk/drivers/peripheral/config/include/ConfigModelC.h
code/sdk/drivers/peripheral/config/src/ConfigModel.cpp
code/sdk/drivers/peripheral/utils/CMakeLists.txt
code/sdk/drivers/peripheral/utils/custom_save_runtime.c [new file with mode: 0644]
code/sdk/drivers/peripheral/utils/custom_save_runtime.h [new file with mode: 0644]
code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c

index e915f6e..99d5caf 100755 (executable)
 \r
 #ifdef ENABLE_CUSTOM_I2C\r
 #include "custom_utils.h"\r
+#include "custom_save_runtime.h"\r
+\r
 #endif\r
 \r
 #ifdef SUPPORT_A5133_SERVICE\r
@@ -429,7 +431,8 @@ static void thread_main(const void *unused)
      * \r
     */\r
     ConfigModelInit();\r
-\r
+    \r
+    uapi_runtime_log_service_init();\r
 \r
 #if DSP_EXIST == YES\r
     audio_init();\r
index fe5e7a6..0ec8a7d 100644 (file)
@@ -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;
index f752a51..88f2e78 100644 (file)
@@ -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();                                        // 私有构造函数,确保无法在外部实例化
index de2fb6a..19c2f23 100644 (file)
@@ -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
 }
index 46d350d..224d84b 100644 (file)
@@ -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
 }
index da240fa..b5c8549 100644 (file)
@@ -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 (file)
index 0000000..0cc3b21
--- /dev/null
@@ -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 <dirent.h>
+
+#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 (file)
index 0000000..dba2b36
--- /dev/null
@@ -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 <stdint.h>
+#include <stdio.h>
+#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
index d361544..51c3d7d 100644 (file)
@@ -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;
     }