From cad2880edf6762776cbb302fbf861295df53ce62 Mon Sep 17 00:00:00 2001 From: ranchuan Date: Wed, 18 Dec 2024 16:30:13 +0800 Subject: [PATCH] =?UTF-8?q?--ram=20=E9=80=89=E9=A1=B9=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E5=9C=A8=E5=85=B6=E4=BB=96=E7=9B=AE=E5=BD=95=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=20bin=E7=9B=AE=E5=BD=95=E4=B8=AD=E7=9A=84.bin=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kunlun.py | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/kunlun.py b/kunlun.py index 412f061..dc451c6 100644 --- a/kunlun.py +++ b/kunlun.py @@ -296,7 +296,35 @@ def get_upload_cfg(key:str): return "all" +# 列出所有 .bin 文件 +def list_bin_file(): + path=os.path.curdir + items:list[str]=[] + l=os.listdir(path) + for item in l: + if(os.path.isfile(item)): + items.append(item) + l=os.listdir(bin_path()) + for item in l: + tmp=os.path.join(bin_path(),item) + if(os.path.isfile(tmp)): + items.append(item) + ret_list:list[str]=[] + for item in items: + if(item.endswith(".bin")): + ret_list.append(item) + return ret_list +# 获取ram文件的路径 +def ram_file_redirect(file:str): + if os.path.exists(file): + return file + else: + p=os.path.join(bin_path(),file) + if os.path.exists(p): + return p + myprint(f"文件不存在 {file}") + sys.exit(-1) def global_def(): global init_str @@ -345,8 +373,8 @@ def global_def(): upload_key='all' elif(args.ram_file is not None): function_type='ram' - ram_file=args.ram_file - iot_flash_file=ram_file + ram_file=ram_file_redirect(args.ram_file) + iot_flash_file=args.ram_file elif(args.bin_convert is not None): function_type='convert' iot_flash_file=args.bin_convert @@ -354,7 +382,11 @@ def global_def(): iot_flash_file=args.console function_type='console' elif(args.ftm): + iot_flash_file=time.strftime("%Y%m%d-%H%M%S") function_type='ftm' + elif(args.list): + iot_flash_file=time.strftime("%Y%m%d-%H%M%S") + function_type='list' @@ -375,7 +407,8 @@ def parser_init(): parser.add_argument('-i','--layout_index',action='store',type=int,help='解析接收到的flash文件或转换bin文件时使用的layout,不指定则不解析') parser.add_argument('--b_rate',action='store',type=int,default=115200,help='下载ram程序 上传flash数据 控制台 接收log等 使用的串口波特率') parser.add_argument('--nb_rate',action='store',type=int,default=1500000,help='下载flash程序使用的串口波特率') - parser.add_argument('--ftm',action='store_true',type=bool,default=False,help='进入工厂模式') + parser.add_argument('--ftm',action='store_true',default=False,help='进入工厂模式') + parser.add_argument('--list',action='store_true',default=False,help='列出所有.bin文件') @@ -412,7 +445,12 @@ if __name__ == '__main__': if(function_type=='convert'): bin_to_hex_file(iot_flash_file,calc_hex_name(),layout_index) sys.exit(0) - + if(function_type=="list"): + l=list_bin_file() + myprint("当前目录和bin目录的.bin文件如下") + for item in l: + myprint(item) + sys.exit(0) if(serial_com is None): myprint(f"请指定串口 {serial_com}") sys.exit(-1)