Skip to content

Instantly share code, notes, and snippets.

@Hootrix
Last active March 14, 2021 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hootrix/3ecdeb81664093439a76c2b476d8c331 to your computer and use it in GitHub Desktop.
Save Hootrix/3ecdeb81664093439a76c2b476d8c331 to your computer and use it in GitHub Desktop.
华扬盛世身高体重数据解析
import re as regex
s = b'\xbb\xbc\xbd\xc7\x01\x07\05\x02\x06\x04\x08\x08)'# (175.2, 64.88)
# s = b'\xbb\xbc\xbd\xc7\x01\x07\x06\x06\x06\x05\x02!'# (176.6, 65.2)
# s = b'\xbb\xbc\xbd\xc7\x01\x07\x06\x06\x06\x05\x02!' # (176.6, 65.2)
# s = b'\xfb\x01\x00\x03\t\x01\x00\x05\x03' # 103.0, 10.53
# s = b'\xfb\x01\x00\x03\t\x00\x06\x08\x06' # (103.0, 06.86)
def hyss_hw_parse(series_data,start_position_list = ['c7','fb']):
'''
解析华扬盛世身高体重数据
series_data 串口数据
example:
b'\xbb\xbc\xbd\xc7\x01\x07\x06\x06\x06\x05\x02!'
身高 176.6 体重 65.2
串口数据身高长度固定
start_position 数据开始标记
'''
data = str(series_data).strip().replace('\\x','').replace("b\'",'')
height = '0'
weight = '0'
for start_position in start_position_list:
if start_position in data:
series_data = data[data.find(start_position)+len(start_position):]
# print(series_data)
for index,i in enumerate(series_data):
# print(index,i)
if (index+1)%2 == 0:
# print(index,i)
if index < 9:
if i.isnumeric():height += i
if index == 5: height += '.'
else:
if i.isnumeric():weight += i
if index == 11: weight += '.'
# print(index,i)
return round(float(height),2),round(float(weight),2)
print(hyss_hw_parse(s))
# print('%d'%s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment