Update diag.py

This commit is contained in:
Bjoern Kerler 2021-08-07 14:54:00 +02:00 committed by GitHub
parent ff6159f9e4
commit 6ab7925aae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

60
diag.py
View file

@ -1190,54 +1190,48 @@ class DiagTools(metaclass=LogBase):
sys.exit() sys.exit()
print(diag.efsreadfile(args.src,args.dst)) print(diag.efsreadfile(args.src,args.dst))
elif cmd=="nvread": elif cmd=="nvread":
if "0x" in args.nvread: if "0x" in args.nvitem:
nvitem = int(args.nvread, 16) nvitem = int(args.nvitem, 16)
else: else:
nvitem = int(args.nvread) nvitem = int(args.nvitem)
diag.print_nvitem(nvitem) diag.print_nvitem(nvitem)
elif cmd=="nvreadsub": elif cmd=="nvreadsub":
if not "," in args.nvreadsub: if args.nvitem is None or args.nvindex is None:
print("NvReadSub usage: item,index") print("Usage: nvreadsub [nvitem] [nvindex]")
sys.exit() exit(1)
nv = args.nvreadsub.split(",") nv = args.nvreadsub.split(",")
if len(nv)>1: if "0x" in args.nvitem:
if "0x" in nv[0]: nvitem = int(args.nvitem, 16)
nvitem = int(nv[0], 16) else:
else: nvitem = int(args.nvitem)
nvitem = int(nv[0]) if "0x" in nv[1]:
if "0x" in nv[1]: nvindex = int(args.nvindex], 16)
nvindex = int(nv[1], 16) else:
else: nvindex = int(args.nvindex)
nvindex = int(nv[1])
diag.print_nvitemsub(nvitem,nvindex) diag.print_nvitemsub(nvitem,nvindex)
elif cmd=="nvwrite": elif cmd=="nvwrite":
if not "," in args.nvwrite: if args.data is None:
print("NvWrite requires data to write") print("NvWrite requires data to write")
sys.exit() sys.exit()
nv = args.nvwrite.split(",") if "0x" in args.nvitem:
if "0x" in args.nvwrite: nvitem = int(args.nvitem, 16)
nvitem = int(nv[0], 16)
else: else:
nvitem = int(nv[0]) nvitem = int(args.nvitem)
data = unhexlify(nv[1]) data = unhexlify(args.data)
diag.write_nvitem(nvitem, data) diag.write_nvitem(nvitem, data)
elif cmd=="nvwritesub": elif cmd=="nvwritesub":
if not "," in args.nvwritesub: if args.nvitem is None or args.nvindex is None or args.data is None:
print("NvWriteSub requires item, index and data to write") print("NvWriteSub requires item, index and data to write")
sys.exit() sys.exit()
nv = args.nvwritesub.split(",") if "0x" in args.nvitem:
if len(nv)<3: nvitem = int(args.nvitem, 16)
print("NvWriteSub requires item, index and data to write")
sys.exit()
if "0x" in args.nvwritesub:
nvitem = int(nv[0], 16)
else: else:
nvitem = int(nv[0]) nvitem = int(args.nvitem)
if "0x" in args.nvwritesub: if "0x" in args.nvindex:
nvindex = int(nv[1], 16) nvindex = int(args.nvindex, 16)
else: else:
nvindex = int(nv[1]) nvindex = int(args.nvindex)
data = unhexlify(nv[2]) data = unhexlify(args.data)
diag.write_nvitemsub(nvitem, nvindex, data) diag.write_nvitemsub(nvitem, nvindex, data)
elif cmd=="nvbackup": elif cmd=="nvbackup":
diag.backup_nvitems(args.filename, "error.log") diag.backup_nvitems(args.filename, "error.log")