Commit 49c66c3e authored by 李远洪's avatar 李远洪

开发位置信息汇报消息,完成60%

parent 84b6d267
This diff is collapsed.
......@@ -5,19 +5,6 @@ from lib.protocol.message.MessageBase import MessageBase
from lib.protocol.message.TerminalHeartbeat_msg import TerminalHeartbeat_msg
from lib.protocol.messageRes.PlatformCommon_res import PlatformCommon_res
def back7e7d(data):
data = data.replace("7d02", "7e")
data = data.replace("7d01", "7d")
return data
def binary2ascii(binData):
strs = binascii.b2a_hex(binData)
data = str(strs)[2:]
return data
host = "10.100.9.17"
port = 9001
......@@ -36,9 +23,9 @@ data = client.recv(BUF_SIZE)
print(data)
print(binascii.b2a_hex(data))
print(PlatformCommon_res(data).binary2ascii(data))
print(PlatformCommon_res(data).getOriginalMsg())
# print(binascii.b2a_hex(data))
# print(PlatformCommon_res(data).binary2ascii(data))
# print(PlatformCommon_res(data).getOriginalMsg())
print(PlatformCommon_res(data).getMsg())
client.close()
#coding:utf-8
'''
定义一个处理数据包的辅助方法集合
'''
from binascii import *
from crcmod import *
import struct
#####################################################
# 定义生成校验字段的函数(自己翻译的函数,简化了很多步骤)
#####################################################
def myCrc16(msg):
msg = str2Ascsii(msg)
crc = 0xFFFF
for i in range(0, len(msg)):
for j in range(0, 8):
cl5 = ((crc >> 15 & 1) == 1)
bit = ((msg[i] >> (7 - j) & 1) == 1)
crc <<= 1
# 通过与0xFFFF(即二进制:1111111111111111)做了一个或运算,将其转换为一个有符号的数
crc &= 0xFFFF
if (cl5 ^ bit):
crc ^= 0x1021;
crc = hex(crc) # 将10进制的crc转换为16进制
crc = str(crc)[2:] # 将16进制转换为字符串,并去掉前面的0x
return crc
#####################################################
# 定义生成校验字段的函数
# inputStr:需要传入一个已经转换为16进制的字符串
#####################################################
# add crc 16 check at the end of the string
def crc16(inputStr):
inputStrByte = bytes.fromhex(inputStr)
crc = 0xFFFF
for i in range(0, len(inputStrByte)):
for j in range(0, 8):
c15 = (crc >> 15) == 1
bit = ((inputStrByte[i] >> (7 - j)) & 1) == 1
crc <<= 1
crc &= 0xFFFF
if c15 ^ bit:
crc ^= 0x1021
crc = str(hex(crc))
crc = leftPad(crc[2:], 4)
# outputStr = inputStr + crc
outputStr = crc
return outputStr
# pad zero to the left of the string if not long enough
def leftPad(inputStr, strLen):
if (strLen > len(inputStr)):
outputStr = "0000000000000000000000000000000000000000" + inputStr
outputStr = outputStr[len(outputStr) - strLen:]
return outputStr
else:
return inputStr
# pad zero to the right of the string if not long enough
def rightPad(inputStr, strLen):
if (strLen > len(inputStr)):
outputStr = inputStr + "0000000000000000000000000000000000000000"
outputStr = outputStr[: strLen]
return outputStr
else:
return inputStr
#####################################################
# 将字符串转换为16进制的数字字符串
#####################################################
def str2Hex(s):
s_hex=""
for i in range(len(s)):
s_hex=s_hex+hex(ord(s[i]))[2:]+" "
return s_hex
#####################################################
# 将字符串转换为16进制的数字字符串,并去掉空格
#####################################################
def str2HexStrip(s):
s = str2Hex(s)
s2 = s.replace(" ","")
return s2
#####################################################
# 将字符串转换为对应的ascii值数组
#####################################################
def str2Ascsii(s):
asciiArr = []
for i in range(0,len(s)):
asciiValue = ord(s[i])
asciiArr.append(asciiValue)
return asciiArr
if __name__ == "__main__":
print(crc16(str2Hex("aa")))
print(str2Hex("aa"))
print(str2HexStrip("aa"))
print(str2Ascsii("aa"))
print(myCrc16("aa"))
print(crc16(str2HexStrip("aa")))
#coding:utf-8
'''
定义一个获取经纬度的辅助方法集合
'''
import json
#####################################################
# 获取文件的金纬度数据,返回一个经纬度数组
# path:传入文件路径
#####################################################
def getLocationInfo(path):
with open(path,"r",encoding='utf-8') as fi:
loc_data = fi.readlines()
strData = ""
for lineD in loc_data:
strData += lineD
json_data = json.loads(strData)
return json_data["locationInfo"]
if __name__ == "__main__":
print(getLocationInfo("../../data/protocolTools/GPSLine_1.json"))
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment