Commit e8f26810 authored by liyuanhong's avatar liyuanhong

修改了复位后,导致模拟器无法使用的问题

parent c6cea661
[socket] [socket]
host = 10.100.11.20 host = 10.100.12.32
port = 9001 port = 9001
[socket] [socket]
host = 10.100.11.20 host = 10.16.11.95
port = 9001 port = 9007
{"time": {"dateTime": "2020-05-13 16:33:29", "date": "2020-05-13", "time": "16:33:29"}, "curDayTravel": {"todayTotalMilleage": 2407, "todayTotalOil": 232, "todayTotalTime": 145, "theMilleage": 1411, "theOil": 136, "theTime": 85}, "travelData": {"totalMilleage": 6508, "totalOil": 508, "totalTime": 400}} {"time": {"dateTime": "2020-05-21 16:00:39", "date": "2020-05-21", "time": "16:00:39"}, "curDayTravel": {"todayTotalMilleage": 0, "todayTotalOil": 0, "todayTotalTime": 0, "theMilleage": 0, "theOil": 0, "theTime": 0}, "travelData": {"totalMilleage": 6508, "totalOil": 508, "totalTime": 400}}
\ No newline at end of file \ No newline at end of file
{"time": {"dateTime": "2020-05-20 16:26:10", "date": "2020-05-20", "time": "16:26:10"}, "curDayTravel": {"todayTotalMilleage": 3845, "todayTotalOil": 350, "todayTotalTime": 233, "theMilleage": 3845, "theOil": 350, "theTime": 233}, "travelData": {"totalMilleage": 328506, "totalOil": 30966, "totalTime": 19492}, "event": {"threeRapid": {"totalRapidlyAccelerate": 14, "totalSharpSlowdown": 13, "totalSharpTurn": 13}}} {"time": {"dateTime": "2020-05-21 18:38:02", "date": "2020-05-21", "time": "18:38:02"}, "curDayTravel": {"todayTotalMilleage": 996, "todayTotalOil": 96, "todayTotalTime": 60, "theMilleage": 996, "theOil": 96, "theTime": 60}, "travelData": {"totalMilleage": 329502, "totalOil": 31062, "totalTime": 19552}, "event": {"threeRapid": {"totalRapidlyAccelerate": 14, "totalSharpSlowdown": 13, "totalSharpTurn": 13}}}
\ No newline at end of file \ No newline at end of file
#encoding:utf-8
'''
定义查询指定终端参数应答消息
'''
from lib.protocol.message.MessageBase import MessageBase
from lib.protocol.messagePlateform.ResponseBase import ResponseBase
class QueryTheTerminalParam_res(MessageBase,ResponseBase):
def __init__(self):
super().__init__() #不执行该方法,无法使用父类里面定义的属性
self.msgRes = "" #需要回复的消息的16进制报文
pass
#######################################################
# 设置需要回复的消息
#######################################################
def setMsgRes(self,data):
self.msgRes = data
#######################################################
# 获取需要回复消息的消息体
#######################################################
def getMsgResBody(self):
data = self.msgRes[28:][:-4]
data = self.restore_7e7d(data)
return data
#######################################################
# 获取需要回复消息的消息流水号
#######################################################
def getQueryWaterCode(self):
wc = self.msgRes[22:26]
return wc
#######################################################
# 获取需要回复消息的消息手机号
#######################################################
def getQueryPhoneNum(self):
phoneNum = self.msgRes[10:22]
return phoneNum
#######################################################
# 将消息体转换为需要查询的终端参数
#######################################################
def getQueryParams(self):
body = self.getMsgResBody()
params = []
param = body[0:8]
body = body[8:]
while param != "":
params.append(param)
param = body[0:8]
body = body[8:]
return params
#######################################################
# 生成一条完整的消息
#######################################################
def generateMsg(self):
msg = ""
msgHeader = self.getMsgHeader()
msgBody = self.getMsgBody()
checkCode = self.getCheckCode(msgHeader + msgBody)
msg = msg + self.IDENTIFY
info = msgHeader + msgBody + checkCode
info = self.replace7e7d(info)
msg = msg + info
msg = msg + self.IDENTIFY
return msg
#######################################################
# 获取消息体
#######################################################
def getMsgBody(self):
msg = ""
resWaterCode = self.getQueryWaterCode() #应答流水号,对应的终端参数查询消息的流水号
resParamCounts = self.int2hexStringByBytes(len(self.getQueryParams())) #应答参数个数
paramList = self.getParamList() #参数项列表
msg = resWaterCode + resParamCounts + paramList
return msg
#######################################################
# 获取消息头
#######################################################
def getMsgHeader(self):
msgID = "0104"
subPkg = 0
msgBodyProperty = self.getMsgBodyProperty(msgBodyLen=int(len(self.getMsgBody()) / 2),subPkg=subPkg) #消息体属性
phoneNum = self.int2BCD(self.getQueryPhoneNum()) #终端手机号
msgWaterCode = self.int2hexStringByBytes(1,2) #消息流水号
if subPkg != 8192:
subPkgContent = "" #消息包封装项
else:
subPkgContent = self.getMsgPackage()
data = msgID + msgBodyProperty + phoneNum + msgWaterCode + subPkgContent
return data
#获取消息体属性
def getMsgBodyProperty(self,msgBodyLen=128,encryptionType=0,subPkg=0):
if msgBodyLen >= 512:
raise RuntimeError('消息体长度超长!')
msgBodyLen = msgBodyLen #消息体长度
encryptionType = encryptionType #加密方式
subPkg = subPkg #分包
retain = 0 #保留位
data = msgBodyLen + encryptionType + subPkg + retain
dataHex = self.int2hexStringByBytes(data,2)
return dataHex
#######################################################
# 获取参数项列表
#######################################################
def getParamList(self):
queryParams = self.getQueryParams()
paramNums = 0 #参数总数
data = ""
if "00000010" in queryParams:
content = self.str2Hex("tnet")
data = data + "00000010" + self.int2hexStringByBytes(int(len(content) / 2)) + content
paramNums = paramNums + 1
if "00000011" in queryParams:
content = self.str2Hex("yuanhong")
data = data + "00000011" + self.int2hexStringByBytes(int(len(content) / 2)) + content
paramNums = paramNums + 1
if "00000012" in queryParams:
content = self.str2Hex("123456")
data = data + "00000012" + self.int2hexStringByBytes(int(len(content) / 2)) + content
paramNums = paramNums + 1
if "00000013" in queryParams:
content = self.str2Hex("10.100.12.30")
data = data + "00000013" + self.int2hexStringByBytes(int(len(content) / 2)) + content
paramNums = paramNums + 1
if "00000014" in queryParams:
content = self.str2Hex("CDMA")
data = data + "00000014" + self.int2hexStringByBytes(int(len(content) / 2)) + content
paramNums = paramNums + 1
if "00000015" in queryParams:
content = self.str2Hex("yuanhong2")
data = data + "00000015" + self.int2hexStringByBytes(int(len(content) / 2)) + content
paramNums = paramNums + 1
if "00000016" in queryParams:
content = self.str2Hex("1234567")
data = data + "00000016" + self.int2hexStringByBytes(int(len(content) / 2)) + content
paramNums = paramNums + 1
if "00000017" in queryParams:
content = self.str2Hex("10.100.12.31")
data = data + "00000017" + self.int2hexStringByBytes(int(len(content) / 2)) + content
paramNums = paramNums + 1
if "00000018" in queryParams:
content = self.str2Hex("9001")
data = data + "00000018" + self.int2hexStringByBytes(int(len(content) / 2)) + content
paramNums = paramNums + 1
if "00000019" in queryParams:
content = self.str2Hex("9002")
data = data + "00000019" + self.int2hexStringByBytes(int(len(content) / 2)) + content
paramNums = paramNums + 1
paramNums = self.int2hexStringByBytes(paramNums)
data = paramNums + data
return data
if __name__ == "__main__":
obj = QueryTheTerminalParam_res()
obj.setMsgRes("7e8106002901220150001000060a00000010000000110000001200000013000000180000001400000015000000160000001700000019c17e")
body = obj.getMsgResBody()
print(obj.getQueryParams())
print(obj.getQueryWaterCode())
print(obj.generateMsg())
\ No newline at end of file
...@@ -85,6 +85,14 @@ class ResponseBase(Base): ...@@ -85,6 +85,14 @@ class ResponseBase(Base):
return msgId return msgId
#######################################################
# 16进制转换为GBK字符串
#######################################################
def hex2GBKString_res(self,dataHex):
dataStr = self.hex2Str(dataHex)
data = bytes(map(ord,str(dataStr)))
data = data.decode("gbk")
return data
......
...@@ -17,7 +17,10 @@ from lib.protocol.messagePlateform.PlateformVersionInfo_res import PlatefromVers ...@@ -17,7 +17,10 @@ from lib.protocol.messagePlateform.PlateformVersionInfo_res import PlatefromVers
from lib.protocol.messagePlateform.PlatformCommon_res import PlatformCommon_res from lib.protocol.messagePlateform.PlatformCommon_res import PlatformCommon_res
from lib.protocol.messagePlateform.TerminalRegister_res import TerminalRegister_res from lib.protocol.messagePlateform.TerminalRegister_res import TerminalRegister_res
host = "10.100.11.20" # host = "10.100.11.20"
# port = 9001
host = "10.100.12.32"
port = 9001 port = 9001
# msg = MessageBase().generateMsg() # msg = MessageBase().generateMsg()
......
...@@ -16,6 +16,7 @@ from lib.protocol.message.Location_msg import Location_msg ...@@ -16,6 +16,7 @@ from lib.protocol.message.Location_msg import Location_msg
from lib.protocol.message.TerminalCommonMsgRes_msg import TerminalCommonMsgRes_msg from lib.protocol.message.TerminalCommonMsgRes_msg import TerminalCommonMsgRes_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.response.QueryTheTerminalParam_res import QueryTheTerminalParam_res
from lib.socket.service.MessageSimulaterDataService import MessageSimulaterDataService from lib.socket.service.MessageSimulaterDataService import MessageSimulaterDataService
from lib.socket.service.websocket_service import Websocket_service from lib.socket.service.websocket_service import Websocket_service
...@@ -461,13 +462,14 @@ class MessageSimulaterService(): ...@@ -461,13 +462,14 @@ class MessageSimulaterService():
######################################################## ########################################################
def doResponse(self,msg): def doResponse(self,msg):
msgFunId = self.getMsgFunId(msg) msgFunId = self.getMsgFunId(msg)
resWaterCode = msg[22:26] if msgFunId == "8106":
if msgFunId == "8105": obj = QueryTheTerminalParam_res()
msg = TerminalCommonMsgRes_msg(resId="8105",phoneNum=self.carId,resWaterCode=resWaterCode,sn=self.sn).generateMsg() obj.setMsgRes(msg)
msg = obj.generateMsg()
self.sendMsg(msg) self.sendMsg(msg)
self.sn = self.sn + 1 self.sn = self.sn + 1
type = self.getMsgFunId(msg) type = self.getMsgFunId(msg)
self.websocket.send(type + ">>>>终端控制消息应答:" + msg) self.websocket.send(type + ">>>>查询终端参数消息应答:" + msg)
elif msgFunId == "8206": elif msgFunId == "8206":
pass pass
......
...@@ -91,8 +91,6 @@ class Websocket_service(SocketBase): ...@@ -91,8 +91,6 @@ class Websocket_service(SocketBase):
#给指定客户端发送消息 #给指定客户端发送消息
def sendMsgToClient(self,msg,clientId): def sendMsgToClient(self,msg,clientId):
# print(self.clients)
# print(self.server)
data = {} data = {}
data["code"] = "0002" data["code"] = "0002"
data["client"] = self.currentClient data["client"] = self.currentClient
......
...@@ -32,7 +32,7 @@ def startWebsocketServer(): ...@@ -32,7 +32,7 @@ def startWebsocketServer():
# server.shutdown() # server.shutdown()
server.server_close() server.server_close()
server = WebsocketServer(5005, host='127.0.0.1', loglevel=logging.INFO) server = WebsocketServer(5005, host='0.0.0.0', loglevel=logging.INFO)
server.set_fn_new_client(new_client) server.set_fn_new_client(new_client)
server.set_fn_message_received(mysend) server.set_fn_message_received(mysend)
server.run_forever() server.run_forever()
......
...@@ -253,10 +253,10 @@ def reset(): ...@@ -253,10 +253,10 @@ def reset():
service.fireOff() service.fireOff()
except BaseException as e1: except BaseException as e1:
pass pass
service.stopWebsocketService()
service.stopTravel() service.stopTravel()
service.stopService() service.stopService()
service.socket.close() service.socket.close()
websocket.close()
websocket = None websocket = None
connects = {} connects = {}
data["status"] = "200" data["status"] = "200"
......
...@@ -254,7 +254,6 @@ def closeConect(): ...@@ -254,7 +254,6 @@ def closeConect():
else: else:
service = connects[sessionId]["service"] service = connects[sessionId]["service"]
service.stopTravel() service.stopTravel()
# service.stopWebsocketService()
service.stopService() service.stopService()
service.closeSocket() service.closeSocket()
connects.pop(sessionId) connects.pop(sessionId)
...@@ -285,9 +284,9 @@ def reset(): ...@@ -285,9 +284,9 @@ def reset():
service.fireOff() service.fireOff()
except BaseException as e1: except BaseException as e1:
pass pass
service.stopWebsocketService()
service.stopService() service.stopService()
service.closeSocket() service.closeSocket()
websocket.close()
websocket = None websocket = None
connects = {} connects = {}
data["status"] = "200" data["status"] = "200"
......
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