From: Caisking <3449750381@qq.com> Date: Thu, 19 Dec 2024 07:52:36 +0000 (+0800) Subject: 工具:优化功耗解析界面txt文件的生成路径 X-Git-Tag: v1.3.113-repair_tp~137 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=4d86f6e2c8bda5e2231220931fda51f4a5a34119;p=mirrors%2FFD230.git 工具:优化功耗解析界面txt文件的生成路径 --- diff --git a/tools/log_parser/runtimeanalysis.py b/tools/log_parser/runtimeanalysis.py index 480c62428..4ef7b3c13 100644 --- a/tools/log_parser/runtimeanalysis.py +++ b/tools/log_parser/runtimeanalysis.py @@ -1,63 +1,74 @@ -import os -import sys - -path = r"." - - -txtname = sys.argv[-1] - -# 字母要小写 -str_bin_list =[ - ['0001',"开机 "], - ['0002',"关机 "], - ['0003',"重启 "], - ['0004',"ota升级 "], - ['0005',"恢复出厂设置 "], - ['0801',"屏幕亮 "], - ['0802',"屏幕灭 "], - ['0a01',"充电开始 "], - ['0a02',"充电停止 "], - ['0e01',"本地音乐开始播放 "], - ['0e02',"本地音乐开始暂停 "], - ['0e03',"本地音乐播放停止 "], - ['0f01',"闹钟铃声开始播放 "], - ['0f02',"闹钟铃声播放停止 "], - ['0f03',"倒计时铃声开始播放 "], - ['0f04',"倒计时铃声播放停止 "], - ['0f05',"查找手表铃声开始播放 "], - ['0f06',"查找手表铃声播放停止 "], - ['1101',"录音开始 "], - ['1102',"录音停止 "], - ['1103',"AI录音开始 "], - ['1104',"AI录音停止 "] - ] - - -f_out = open("runtimeout.txt","w+") - -with open(txtname,"rb+")as file: - data_1 = file.read(2) - data_2 = file.read(4) - while data_1: - # data_1_bin = data_1.hex() - data_1_bin = ''.join('{:02x}'.format(b) for b in data_1[::-1]) # 大端显示的16进制字符串 - data_2_bin = ''.join('{:02x}'.format(b) for b in data_2[::-1]) # 大端显示的16进制字符串 - coutn=0 - for l in str_bin_list: - coutn+=1 - if l[0]==data_1_bin: - f_out.write(l[1]) - break - f_out.write(data_1_bin) - f_out.write(' ') - f_out.write(data_2_bin) - f_out.write('\n') - - data_1 = file.read(2) - data_2 = file.read(4) - # data_1_int=int(data_1) - -file.close() -f_out.close() +import os +import sys +# 定义输出目录的路径 +output_dir = os.path.join("tools", "log_parser") +# 如果输出目录不存在,则创建该目录 +os.makedirs(output_dir, exist_ok=True) + +# 定义输出文件的完整路径 +output_file_path = os.path.join(output_dir, "runtimeout.txt") + +# 定义默认的输入文件路径 +default_txtname = "default_input.txt" # 请将此处的文件名替换为你的默认输入文件名 + +# 从命令行参数中获取输入文件名称,如果没有提供则使用默认文件 +txtname = sys.argv[-1] if len(sys.argv) > 1 else default_txtname + +# 字符串与其对应的消息的映射 +str_bin_list = [ + ['0001', "开机 "], + ['0002', "关机 "], + ['0003', "重启 "], + ['0004', "ota升级 "], + ['0005', "恢复出厂设置 "], + ['0801', "屏幕亮 "], + ['0802', "屏幕灭 "], + ['0a01', "充电开始 "], + ['0a02', "充电停止 "], + ['0e01', "本地音乐开始播放 "], + ['0e02', "本地音乐开始暂停 "], + ['0e03', "本地音乐播放停止 "], + ['0f01', "闹钟铃声开始播放 "], + ['0f02', "闹钟铃声播放停止 "], + ['0f03', "倒计时铃声开始播放 "], + ['0f04', "倒计时铃声播放停止 "], + ['0f05', "查找手表铃声开始播放 "], + ['0f06', "查找手表铃声播放停止 "], + ['1101', "录音开始 "], + ['1102', "录音停止 "], + ['1103', "AI录音开始 "], + ['1104', "AI录音停止 "] +] + +# 打开输出文件以写入 +with open(output_file_path, "w+") as f_out: + # 打开输入文件以读取 + with open(txtname, "rb") as file: + data_1 = file.read(2) + data_2 = file.read(4) + while data_1: + # 转换数据为大端16进制字符串 + data_1_bin = ''.join('{:02x}'.format(b) for b in data_1[::-1]) + data_2_bin = ''.join('{:02x}'.format(b) for b in data_2[::-1]) + found = False + + # 遍历查找字符串 + for l in str_bin_list: + if l[0] == data_1_bin: + f_out.write(l[1]) + found = True + break + + if not found: + f_out.write(data_1_bin) # 如果没有找到对应的字符串,则写入二进制字符串 + f_out.write(' ') + f_out.write(data_2_bin) + f_out.write('\n') + + # 读取下一组数据 + data_1 = file.read(2) + data_2 = file.read(4) + +# 使用with语句自动关闭文件 \ No newline at end of file