Commit df74fb48 authored by liyuanhong's avatar liyuanhong

查询终端参数应答消息开发完成

parent 62293f11
......@@ -170,6 +170,19 @@ class ProtocolBase(Base):
UTCTime += self.int2hexString(int(timeArr[i]))
return UTCTime
#####################################################
#16进制转换为UTC时间格式
#####################################################
def hex2UTCTime(self,dataHex):
theTime = "20"
theTime = theTime + str(int(dataHex[:2],16))
theTime = theTime + "-" + str(int(dataHex[2:4],16))
theTime = theTime + "-" + str(int(dataHex[4:6],16))
theTime = theTime + " " + str(int(dataHex[6:8],16))
theTime = theTime + ":" + str(int(dataHex[8:10],16))
theTime = theTime + ":" + str(int(dataHex[10:],16))
return theTime
####################################################
# 将整数转换为有符号的整数
#####################################################
......@@ -182,3 +195,5 @@ if __name__ == "__main__":
# print(ProtocolBase().int2hexStringByBytes(1,6))
# print(ProtocolBase().num2signedNum(-5))
print(ProtocolBase().getUTCTimeHex("2020-01-03 13:05:13"))
print(ProtocolBase().hex2UTCTime("1401030d050d"))
print(ProtocolBase().hex2UTCTime("14020a07122b"))
......@@ -403,6 +403,10 @@ if __name__ == "__main__":
print(Location_msg().getAlarmFlag())
print(Location_msg().getInfoTime())
print(Location_msg().generateMsg())
lati = Location_msg().getLatitude(29.40268)
print(lati)
print(int("01c329ed",16) / 1000000)
print(int("0659dec5", 16) / 1000000)
This diff is collapsed.
......@@ -37,14 +37,14 @@ class TerminalHeartbeat_msg(MessageBase):
# 获取消息头
#######################################################
def getMsgHeader(self):
# msgID = self.int2hexStringByBytes(102,2) #消息id
# msgID = self.int2hexStringByBytes(102,2) #消息id
msgID = "0002"
subPkg = 0
msgBodyProperty = self.getMsgBodyProperty(msgBodyLen=int(len(self.getMsgBody()) / 2),subPkg=subPkg) #消息体属性
phoneNum = self.int2BCD(13146201119) #终端手机号
msgWaterCode = self.int2hexStringByBytes(1,2) #消息流水号
phoneNum = self.int2BCD(13146201119) #终端手机号
msgWaterCode = self.int2hexStringByBytes(1,2) #消息流水号
if subPkg != 8192:
subPkgContent = "" #消息包封装项
subPkgContent = "" #消息包封装项
else:
subPkgContent = self.getMsgPackage()
data = msgID + msgBodyProperty + phoneNum + msgWaterCode + subPkgContent
......
......@@ -4,7 +4,7 @@
定义平台通用应答消息解码类
'''
from lib.protocol.message.MessageBase import MessageBase
from lib.protocol.messageRes.ResponseBase import ResponseBase
from lib.protocol.messagePlateform.ResponseBase import ResponseBase
class DataDownStreamTransport_res(ResponseBase):
......
......@@ -4,7 +4,7 @@
定义平台版本信息包上传应答解码类
'''
from lib.protocol.message.MessageBase import MessageBase
from lib.protocol.messageRes.ResponseBase import ResponseBase
from lib.protocol.messagePlateform.ResponseBase import ResponseBase
class PlatefromVersionInfo_res(ResponseBase):
......@@ -72,7 +72,7 @@ class PlatefromVersionInfo_res(ResponseBase):
plateformCurrentTime = self.getBCD2GMTTime(body[:12]) #平台当前时间
carId = self.hexString2int(body[12:16]) #车型id
displacement = self.hexString2int(body[16:20]) #排量
isUpdate = body[20:]
isUpdate = body[20:] #是否升级,0x55 升级,其他不升级
json_body["plateformCurrentTime"] = plateformCurrentTime
json_body["carId"] = carId
json_body["displacement"] = displacement
......
......@@ -4,7 +4,7 @@
定义平台通用应答消息解码类
'''
from lib.protocol.message.MessageBase import MessageBase
from lib.protocol.messageRes.ResponseBase import ResponseBase
from lib.protocol.messagePlateform.ResponseBase import ResponseBase
class PlatformCommon_res(ResponseBase):
......
......@@ -4,7 +4,7 @@
定义平台通用应答消息解码类
'''
from lib.protocol.message.MessageBase import MessageBase
from lib.protocol.messageRes.ResponseBase import ResponseBase
from lib.protocol.messagePlateform.ResponseBase import ResponseBase
class TerminalRegister_res(ResponseBase):
......
#coding:utf-8
import binascii
import socket
from time import sleep
from lib.protocol.message.DataUpstreamTransport_msg import DataUpstreamTransport_msg
from lib.protocol.message.Location_msg import Location_msg
from lib.protocol.message.MessageBase import MessageBase
from lib.protocol.message.QueryTerminalParam_res import QueryTerminalParam_res
from lib.protocol.message.TerminalAuthenticate_msg import TerminalAuthenticate_msg
from lib.protocol.message.TerminalCommonMsgRes_msg import TerminalCommonMsgRes_msg
from lib.protocol.message.TerminalHeartbeat_msg import TerminalHeartbeat_msg
from lib.protocol.message.TerminalRegister_msg import TerminalRegister_msg
from lib.protocol.message.TerminalVersionInfo_msg import TerminalVersionInfo_msg
from lib.protocol.message.data.TerminalCancle_msg import TerminalCancle_msg
from lib.protocol.messageRes.PlatformCommon_res import PlatformCommon_res
from lib.protocol.messageRes.TerminalRegister_res import TerminalRegister_res
from lib.protocol.messagePlateform.PlatformCommon_res import PlatformCommon_res
from lib.protocol.messagePlateform.TerminalRegister_res import TerminalRegister_res
host = "10.100.9.17"
port = 9001
......@@ -24,11 +26,12 @@ port = 9001
# msg = TerminalCancle_msg().generateMsg() #终端注销
# msg = TerminalAuthenticate_msg().generateMsg() #终端鉴权
# msg = TerminalVersionInfo_msg().generateMsg() #终端版本信息上报
msg = Location_msg().generateMsg() #位置信息汇报
msg = QueryTerminalParam_res().generateMsg() #查询终端参数应答
# msg = Location_msg().generateMsg() #位置信息汇报
# msg = DataUpstreamTransport_msg().generateMsg() #数据上行透传消息
#发送单条消息
def sendSingleMsg():
def sendSingleMsg(msg):
print(msg)
BUF_SIZE = 1024
......@@ -43,8 +46,51 @@ def sendSingleMsg():
# print(TerminalRegister_res(data).getMsg())
client.close()
def closeSocket(soc):
soc.close
def connectSock():
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) # 在客户端开启心跳
client.connect((host, port))
return client
def sendMsg(client,msg):
print("发送的消息为:" + msg)
BUF_SIZE = 1024
client.send(binascii.a2b_hex(msg))
data = client.recv(BUF_SIZE)
if PlatformCommon_res(data).getMsg()["header"]["msgId"] == "0100": #终端注册应答
print("收到的消息:" + str(TerminalRegister_res(data).getMsg()))
else:
print("收到的消息:" + str(PlatformCommon_res(data).getMsg())) #平台通用应答
return client
def sendMultMsg():
pass
if __name__ == "__main__":
sendSingleMsg()
sendSingleMsg(msg)
'''
print("发送终端注册消息")
client = connectSock()
msg = TerminalRegister_msg().generateMsg() #终端注册
sendMsg(client,msg)
sleep(2)
print("发送终端心跳消息")
msg = TerminalHeartbeat_msg().generateMsg() # 终端心跳
sendMsg(client,msg)
sleep(2)
print("发送终端鉴权消息")
msg = TerminalAuthenticate_msg().generateMsg() # 终端鉴权
sendMsg(client,msg)
sleep(2)
closeSocket(client)
print("断开连接")
'''
......@@ -4,7 +4,7 @@ from flask import Blueprint ,Response,request
from configparser import ConfigParser
from lib.protocol.message.TerminalHeartbeat_msg import TerminalHeartbeat_msg
from lib.protocol.messageRes.PlatformCommon_res import PlatformCommon_res
from lib.protocol.messagePlateform.PlatformCommon_res import PlatformCommon_res
from lib.protocol.report.HeartBeatReport_protocol import HeartBeatReport_protocol
from lib.socket.ClientSocket import ClientSocket
......
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