Skip to content

Instantly share code, notes, and snippets.

@pinetum
Created July 13, 2021 07:54
Show Gist options
  • Save pinetum/b7b9acfae5875d68bab028020396717c to your computer and use it in GitHub Desktop.
Save pinetum/b7b9acfae5875d68bab028020396717c to your computer and use it in GitHub Desktop.
hexString = ""
hexString = hexString[2:-2]
hexString = hexString.replace("7d01", "7d")
hexString = hexString.replace("7d02", "7e")
payload = bytearray.fromhex(hexString)
msg_type = payload[0:2]
msg_attr = payload[2:4]
device_id = payload[4:10]
msg_id = payload[10:12]
alarm_status = payload[12:16]
status = payload[16:20]
lat = payload[20:24]
lon = payload[24:28]
height = payload[28:30]
speed = payload[30:32]
direction = payload[32:34]
time = payload[34:40]
index = 40
while(index != len(payload)-1):
key = payload[index]
length = payload[index+1]
data = payload[index+2:index+2+length]
if key == 0x01:
print("里程:{}".format(int.from_bytes(data, byteorder='big', signed=False)))
if key == 0xCC:
print("IMEI:{}".format(data.decode("utf-8")))
if key == 0x30:
print("RSSI:{}".format(int.from_bytes(data, byteorder='big', signed=False)))
if key == 0x9F:
print("基地台:{}".format(data.decode("utf-8").split(',')))
if key == 0x81:
print("RPM:{}".format(int.from_bytes(data, byteorder='big', signed=False)))
if key == 0x82:
print("Battery:{}".format(0.1*int.from_bytes(data, byteorder='big', signed=False)))
if key == 0x83:
print("engineLoad:{}%".format(int.from_bytes(data, byteorder='big', signed=False)))
if key == 0x84:
print("waterTemp:{}".format(-40+int.from_bytes(data, byteorder='big', signed=False)))
if key == 0x8B:
print("VIN:{}".format(data.decode("utf-8")))
if key == 0x8C:
print("ODO:{}km".format(0.1*int.from_bytes(data, byteorder='big', signed=False)))
if key == 0xA0:
print("故障:{}".format(data.decode("utf-8")))
index = index + length + 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment