方案生成字节数据修改
This commit is contained in:
@@ -142,6 +142,19 @@ def scheme_to_byte(j:json):
|
||||
# int转数组
|
||||
def arr_from_int(num:int):
|
||||
return bytearray([num&0xff,(num>>8)&0xff,(num>>16)&0xff,(num>>24)&0xff])
|
||||
# uchar转数组
|
||||
def arr_from_uchar(num:int):
|
||||
return bytearray([num&0xff])
|
||||
# u16转数组
|
||||
def arr_from_u16(num:int):
|
||||
return bytearray([num&0xff,(num>>8)&0xff])
|
||||
# 填充指定个数的byte
|
||||
def arr_byte_copy(byte:int,num:int):
|
||||
t=bytearray()
|
||||
for i in range(num):
|
||||
t.append(byte)
|
||||
return t
|
||||
|
||||
|
||||
|
||||
# 提取方案中的范围数据, 先max后min
|
||||
@@ -168,14 +181,59 @@ def scheme_get_task_range(j:json):
|
||||
t+=arr_from_int(0)
|
||||
return t
|
||||
|
||||
|
||||
|
||||
# 提取方案中的范围数据, 先max后min
|
||||
# 这个减少了存储空间占用
|
||||
def scheme_get_task_range_small(j:json):
|
||||
t=bytearray()
|
||||
t+=arr_from_uchar(j["TaskID"])
|
||||
t+=arr_from_uchar(j["TaskIndex"])
|
||||
t+=arr_from_uchar(j["ReturnCount"])
|
||||
t+=arr_from_uchar(j["ExecuteErrCode"])
|
||||
index=0
|
||||
for i in j["TestStandard"]:
|
||||
t+=arr_from_u16(i["Max"])
|
||||
t+=arr_from_u16(i["Min"])
|
||||
if (index<len(j["ResultErrCode"])):
|
||||
t+=arr_from_uchar(j["ResultErrCode"][index])
|
||||
else:
|
||||
t+=arr_from_uchar(0)
|
||||
index+=1
|
||||
# 不足16的部分填充为16
|
||||
n=16-len(j["TestStandard"])
|
||||
for i in range(n):
|
||||
t+=arr_from_u16(65535)
|
||||
t+=arr_from_u16(0)
|
||||
t+=arr_from_uchar(0)
|
||||
return t
|
||||
|
||||
|
||||
# 提取方案中的错误码
|
||||
def scheme_get_errinfo(j:json):
|
||||
t=bytearray()
|
||||
t+=arr_from_uchar(j["MajorErrCode"])
|
||||
t+=arr_from_uchar(len(j["SubErrCode"]))
|
||||
for i in j["SubErrCode"]:
|
||||
t+=arr_from_uchar(i)
|
||||
n=30-len(j["SubErrCode"])
|
||||
for i in range(n):
|
||||
t+=arr_from_uchar(0)
|
||||
return t
|
||||
|
||||
# 根据方案生成主板用的字节数据
|
||||
def scheme_to_host(j:json):
|
||||
t=bytearray()
|
||||
t+=arr_from_int(j["PlanID"])
|
||||
t+=arr_from_int(j["TimeOutM"])
|
||||
t+=arr_from_int(len(j["TaskArray"]))
|
||||
t+=arr_from_int(len(j["MajorErrInfo"]))
|
||||
for i in j["MajorErrInfo"]:
|
||||
t+=scheme_get_errinfo(i)
|
||||
n=21-len(j["MajorErrInfo"])
|
||||
t+=arr_byte_copy(0,n*32)
|
||||
for i in j["TaskArray"]:
|
||||
t+=scheme_get_task_range(i)
|
||||
t+=scheme_get_task_range_small(i)
|
||||
return t
|
||||
|
||||
|
||||
@@ -244,7 +302,8 @@ class handle:
|
||||
d=scheme_to_byte(json_obj)
|
||||
# print("len=",len(d),d.hex(","))
|
||||
d+=scheme_to_host(json_obj)
|
||||
# print("len=",len(d),d.hex(","))
|
||||
# print("scheme data:",d.hex(","))
|
||||
print("scheme size:{d}".format(d=len(d)))
|
||||
self.data=d
|
||||
self.name=f.name.split('/')[-1]
|
||||
self.stat=0
|
||||
|
Reference in New Issue
Block a user