Commit df74fb48 authored by liyuanhong's avatar liyuanhong

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

parent 62293f11
...@@ -170,6 +170,19 @@ class ProtocolBase(Base): ...@@ -170,6 +170,19 @@ class ProtocolBase(Base):
UTCTime += self.int2hexString(int(timeArr[i])) UTCTime += self.int2hexString(int(timeArr[i]))
return UTCTime 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__": ...@@ -182,3 +195,5 @@ if __name__ == "__main__":
# print(ProtocolBase().int2hexStringByBytes(1,6)) # print(ProtocolBase().int2hexStringByBytes(1,6))
# print(ProtocolBase().num2signedNum(-5)) # print(ProtocolBase().num2signedNum(-5))
print(ProtocolBase().getUTCTimeHex("2020-01-03 13:05:13")) print(ProtocolBase().getUTCTimeHex("2020-01-03 13:05:13"))
print(ProtocolBase().hex2UTCTime("1401030d050d"))
print(ProtocolBase().hex2UTCTime("14020a07122b"))
...@@ -403,6 +403,10 @@ if __name__ == "__main__": ...@@ -403,6 +403,10 @@ if __name__ == "__main__":
print(Location_msg().getAlarmFlag()) print(Location_msg().getAlarmFlag())
print(Location_msg().getInfoTime()) print(Location_msg().getInfoTime())
print(Location_msg().generateMsg()) 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.
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
定义平台通用应答消息解码类 定义平台通用应答消息解码类
''' '''
from lib.protocol.message.MessageBase import MessageBase 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): class DataDownStreamTransport_res(ResponseBase):
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
定义平台版本信息包上传应答解码类 定义平台版本信息包上传应答解码类
''' '''
from lib.protocol.message.MessageBase import MessageBase 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): class PlatefromVersionInfo_res(ResponseBase):
...@@ -72,7 +72,7 @@ class PlatefromVersionInfo_res(ResponseBase): ...@@ -72,7 +72,7 @@ class PlatefromVersionInfo_res(ResponseBase):
plateformCurrentTime = self.getBCD2GMTTime(body[:12]) #平台当前时间 plateformCurrentTime = self.getBCD2GMTTime(body[:12]) #平台当前时间
carId = self.hexString2int(body[12:16]) #车型id carId = self.hexString2int(body[12:16]) #车型id
displacement = self.hexString2int(body[16:20]) #排量 displacement = self.hexString2int(body[16:20]) #排量
isUpdate = body[20:] isUpdate = body[20:] #是否升级,0x55 升级,其他不升级
json_body["plateformCurrentTime"] = plateformCurrentTime json_body["plateformCurrentTime"] = plateformCurrentTime
json_body["carId"] = carId json_body["carId"] = carId
json_body["displacement"] = displacement json_body["displacement"] = displacement
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
定义平台通用应答消息解码类 定义平台通用应答消息解码类
''' '''
from lib.protocol.message.MessageBase import MessageBase 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): class PlatformCommon_res(ResponseBase):
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
定义平台通用应答消息解码类 定义平台通用应答消息解码类
''' '''
from lib.protocol.message.MessageBase import MessageBase 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): class TerminalRegister_res(ResponseBase):
......
#coding:utf-8 #coding:utf-8
import binascii import binascii
import socket import socket
from time import sleep
from lib.protocol.message.DataUpstreamTransport_msg import DataUpstreamTransport_msg from lib.protocol.message.DataUpstreamTransport_msg import DataUpstreamTransport_msg
from lib.protocol.message.Location_msg import Location_msg from lib.protocol.message.Location_msg import Location_msg
from lib.protocol.message.MessageBase import MessageBase 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.TerminalAuthenticate_msg import TerminalAuthenticate_msg
from lib.protocol.message.TerminalCommonMsgRes_msg import TerminalCommonMsgRes_msg from lib.protocol.message.TerminalCommonMsgRes_msg import TerminalCommonMsgRes_msg
from lib.protocol.message.TerminalHeartbeat_msg import TerminalHeartbeat_msg from lib.protocol.message.TerminalHeartbeat_msg import TerminalHeartbeat_msg
from lib.protocol.message.TerminalRegister_msg import TerminalRegister_msg from lib.protocol.message.TerminalRegister_msg import TerminalRegister_msg
from lib.protocol.message.TerminalVersionInfo_msg import TerminalVersionInfo_msg from lib.protocol.message.TerminalVersionInfo_msg import TerminalVersionInfo_msg
from lib.protocol.message.data.TerminalCancle_msg import TerminalCancle_msg from lib.protocol.message.data.TerminalCancle_msg import TerminalCancle_msg
from lib.protocol.messageRes.PlatformCommon_res import PlatformCommon_res from lib.protocol.messagePlateform.PlatformCommon_res import PlatformCommon_res
from lib.protocol.messageRes.TerminalRegister_res import TerminalRegister_res from lib.protocol.messagePlateform.TerminalRegister_res import TerminalRegister_res
host = "10.100.9.17" host = "10.100.9.17"
port = 9001 port = 9001
...@@ -24,11 +26,12 @@ port = 9001 ...@@ -24,11 +26,12 @@ port = 9001
# msg = TerminalCancle_msg().generateMsg() #终端注销 # msg = TerminalCancle_msg().generateMsg() #终端注销
# msg = TerminalAuthenticate_msg().generateMsg() #终端鉴权 # msg = TerminalAuthenticate_msg().generateMsg() #终端鉴权
# msg = TerminalVersionInfo_msg().generateMsg() #终端版本信息上报 # msg = TerminalVersionInfo_msg().generateMsg() #终端版本信息上报
msg = Location_msg().generateMsg() #位置信息汇报 msg = QueryTerminalParam_res().generateMsg() #查询终端参数应答
# msg = Location_msg().generateMsg() #位置信息汇报
# msg = DataUpstreamTransport_msg().generateMsg() #数据上行透传消息 # msg = DataUpstreamTransport_msg().generateMsg() #数据上行透传消息
#发送单条消息 #发送单条消息
def sendSingleMsg(): def sendSingleMsg(msg):
print(msg) print(msg)
BUF_SIZE = 1024 BUF_SIZE = 1024
...@@ -43,8 +46,51 @@ def sendSingleMsg(): ...@@ -43,8 +46,51 @@ def sendSingleMsg():
# print(TerminalRegister_res(data).getMsg()) # print(TerminalRegister_res(data).getMsg())
client.close() 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__": 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 ...@@ -4,7 +4,7 @@ from flask import Blueprint ,Response,request
from configparser import ConfigParser from configparser import ConfigParser
from lib.protocol.message.TerminalHeartbeat_msg import TerminalHeartbeat_msg 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.protocol.report.HeartBeatReport_protocol import HeartBeatReport_protocol
from lib.socket.ClientSocket import ClientSocket 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