1.1.0版本
This commit is contained in:
44
UniTAP/dev/ports/modules/edid/edid_utils.py
Normal file
44
UniTAP/dev/ports/modules/edid/edid_utils.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import os
|
||||
from enum import IntEnum
|
||||
|
||||
|
||||
class EdidFileType(IntEnum):
|
||||
BIN = 0
|
||||
HEX = 1
|
||||
|
||||
|
||||
def save_file(data: bytearray, path: str, file_type: EdidFileType):
|
||||
if file_type == EdidFileType.BIN:
|
||||
file_dpd = open(path + '.bin', 'bw+')
|
||||
file_dpd.write(data)
|
||||
file_dpd.close()
|
||||
elif file_type == EdidFileType.HEX:
|
||||
file = open(path + '.hex', 'w')
|
||||
str_for_save = ''
|
||||
for i in data:
|
||||
if i < 16:
|
||||
str_for_save += str(hex(i)).replace("0x", "0")
|
||||
else:
|
||||
str_for_save += str(hex(i)).replace("0x", "")
|
||||
file.write(str_for_save)
|
||||
file.close()
|
||||
|
||||
|
||||
def load_file(path: str) -> bytearray:
|
||||
filename, file_extension = os.path.splitext(path)
|
||||
if file_extension.find('.hex') != -1:
|
||||
file = open(path, 'r')
|
||||
data = file.read()
|
||||
file.close()
|
||||
i = 0
|
||||
size = len(data)
|
||||
byte_array = bytearray()
|
||||
while i < size:
|
||||
byte_array.append(int('0x' + data[i] + data[i + 1], 16))
|
||||
i += 2
|
||||
return byte_array
|
||||
elif file_extension.find('.bin') != -1:
|
||||
file = open(path, 'rb')
|
||||
data = file.read()
|
||||
file.close()
|
||||
return bytearray(data)
|
||||
Reference in New Issue
Block a user