46 lines
1004 B
Python
46 lines
1004 B
Python
|
|
from datetime import datetime
|
||
|
|
|
||
|
|
def wordData2HexStr(data):
|
||
|
|
ret = ' '.join(data[i:i+2].hex() for i in range(0, len(data), 2))
|
||
|
|
return ret.upper()
|
||
|
|
|
||
|
|
def nowStr():
|
||
|
|
now = datetime.now()
|
||
|
|
ret = now.strftime('%Y/%m/%d %H:%M:%S.') + f"{now.microsecond // 1000:03d}"
|
||
|
|
return ret
|
||
|
|
|
||
|
|
def nowStr1():
|
||
|
|
now = datetime.now()
|
||
|
|
ret = now.strftime('%Y%m%d%H%M%S')
|
||
|
|
return ret
|
||
|
|
|
||
|
|
def checkValue(data: bytes) -> int:
|
||
|
|
crc = 0xFFFF
|
||
|
|
length = len(data)
|
||
|
|
if length % 2 != 0:
|
||
|
|
return 0
|
||
|
|
|
||
|
|
for i in range(0, length, 2):
|
||
|
|
val = data[i] * 256 + data[i + 1]
|
||
|
|
crc = crc ^ val
|
||
|
|
return crc
|
||
|
|
|
||
|
|
def params_to_int(params: str) -> int:
|
||
|
|
binary_list = params.split(',')
|
||
|
|
binary_string = ''.join(binary_list)
|
||
|
|
decimal = int(binary_string, 2)
|
||
|
|
return decimal
|
||
|
|
|
||
|
|
def decompressBySection(val):
|
||
|
|
if val < 21:
|
||
|
|
ret = val*2
|
||
|
|
elif val < 181:
|
||
|
|
ret = val + 20
|
||
|
|
elif val < 256:
|
||
|
|
ret = (val-180)*3 + 200
|
||
|
|
else:
|
||
|
|
ret = 425
|
||
|
|
return ret
|
||
|
|
|
||
|
|
|
||
|
|
|