Commit 634a7493 authored by liyuanhong's avatar liyuanhong

提交

parent 6f1aebda
......@@ -17,7 +17,7 @@ class SendMultMsgThread():
self.msg = msg
self.timeOut = 1 #socket超时时间
self.BUF_SIZE = 1024 #接收消息缓存
self.threadCount = 10 #并发线程数
self.threadCount = 10000 #并发线程数
self.totalTime = 0 #所有线程的运行总和
self.threadArr = {} #保存每个线程的信息
self.failThreadCount = 0 #失败线程数
......@@ -88,9 +88,9 @@ class SendMultMsgThread():
threadName = "thread" + str(i)
# theThread = threading.Thread(target=self.sendMsg, args=("7e0002000001314620111800065b7e",threadName,)) # 数据写死,心跳
# theThread = threading.Thread(target=self.sendMsg,args=("7e0200010908597573774756702ed057ac0016fb16010f4f5208e98691021700400024951202144709EA6600010400000000000204001e7c1f0003050A0001f400000405020001d4c000050400057d0240000604000119400007040007530000100c0004006403f203f203f203f2001114ffffffffffffffffffff00200000000000000000001202002400130106001D0101310160e07e", threadName,)) # 数据写死
theThread = threading.Thread(target=self.sendMsg, \
args=(TerminalRegister_msg().generateMsg_random(), threadName,)) #终端注册
theThread = threading.Thread(target=self.sendMsg,args=("4040007000094d20191201000200120114030409123426d7fffff0000000000505000000143c00000bb80100000fa00000000a0000000000005e5f68e768e739331e100055320000001312001007d0001e0000000000000096000000280096ffff3e0001f40000003e00000000000000000000000f9a", threadName,)) # 数据写死
# theThread = threading.Thread(target=self.sendMsg, \
# args=(TerminalRegister_msg().generateMsg_random(), threadName,)) #终端注册
# theThread = threading.Thread(target=self.sendMsg, \
# args=(Location_msg().generateMsg_random(), threadName,)) #地理位置
threadInfo = {}
......@@ -100,7 +100,7 @@ class SendMultMsgThread():
theThread.start()
timeEnd = int(time.time() * 1000)
timeExpend = timeEnd - timeStart
time.sleep(3)
time.sleep(6)
print("耗时:" + str(timeExpend) + " 毫秒")
print("并发数据每秒发送:" + str(int(self.threadCount / (timeExpend / 1000))))
print("平均响应时间:" + str(self.totalTime / self.threadCount) + "毫秒")
......@@ -119,6 +119,8 @@ class SendMultMsgThread():
if __name__ == "__main__":
t = SendMultMsgThread()
t.setHost("10.100.12.32")
t.setPort(9008)
# t.setMsg("7e0002000001314620111800065b7e")
# t.setMsg("7e020001020131462011190001fffc7fff001c010401c0a6380659ad7a02090042003b200204185704310102EA6600010400000000000204001e7c1f0003050A0001f400000405020001d4c000050400057d0240000604000119400007040007530000100c0004006403f203f203f203f2001114ffffffffffffffffffff00200000000000000000001202002400130106001D0101EB7960C0020bb860D0013c62f00203216050014c60F0015860B001146330011c646001416490012060A00201146014010160100102610002022661100201f561F0020e746210040000119c6040012c60700200e660E00203206701010067020100670301016704024e20670502000067060200416707040000017d02097e")
t.startThread()
......
#coding:utf-8
import binascii
import json
import socket
import threading
import time
from lib.multiThread.ThreadBase import ThreadBase
from lib.protocol.message.Location_msg import Location_msg
from lib.protocol.message.TerminalRegister_msg import TerminalRegister_msg
class SendMultMsgThread():
def __init__(self,host="10.100.11.20",port=9001,msg=""):
self.host = host
self.port = port
self.msg = msg
self.timeOut = 1 #socket超时时间
self.BUF_SIZE = 1024 #接收消息缓存
self.threadCount = 10 #并发线程数
self.totalTime = 0 #所有线程的运行总和
self.threadArr = {} #保存每个线程的信息
self.failThreadCount = 0 #失败线程数
pass
############################################
# 设置host
############################################
def setHost(self,host):
self.host = host
############################################
# 设置端口号
############################################
def setPort(self,port):
self.port = port
############################################
# 设置消息
############################################
def setMsg(self,msg):
self.msg = msg
############################################
# 设置并发线程数
############################################
def setThreadCount(self,threadCount):
self.threadCount = threadCount
############################################
# 发送一条消息
############################################
def sendMsg(self,msg,threadName):
msg = msg
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) # 在客户端开启心跳
client.settimeout(self.timeOut)
startTime = int(time.time() * 1000)
try:
client.connect((self.host, self.port))
client.send(binascii.a2b_hex(msg))
except BaseException as e:
client.close()
self.threadArr[threadName]["status"] = 1
self.failThreadCount = self.failThreadCount + 1
print("连接超时,socket断开")
return
try:
data = client.recv(self.BUF_SIZE)
# print(data)
except BaseException as e:
# traceback.print_exc()
client.close()
# raise RuntimeError('socket 接收消息超时!')
self.threadArr[threadName]["status"] = 1
self.failThreadCount = self.failThreadCount + 1
print('socket 接收消息超时!')
return
endTime = int(time.time() * 1000)
timeExpend = endTime - startTime
self.threadArr[threadName]["timeExp"] = timeExpend
self.totalTime = self.totalTime + timeExpend
client.close()
############################################
# 启动并发线程
############################################
def startThread(self):
timeStart = int(time.time() * 1000)
for i in range(0,self.threadCount):
threadName = "thread" + str(i)
# theThread = threading.Thread(target=self.sendMsg, args=("7e0002000001314620111800065b7e",threadName,)) # 数据写死,心跳
# theThread = threading.Thread(target=self.sendMsg,args=("7e0200010908597573774756702ed057ac0016fb16010f4f5208e98691021700400024951202144709EA6600010400000000000204001e7c1f0003050A0001f400000405020001d4c000050400057d0240000604000119400007040007530000100c0004006403f203f203f203f2001114ffffffffffffffffffff00200000000000000000001202002400130106001D0101310160e07e", threadName,)) # 数据写死
# theThread = threading.Thread(target=self.sendMsg, \
# args=(TerminalRegister_msg().generateMsg_random(), threadName,)) #终端注册
theThread = threading.Thread(target=self.sendMsg, \
args=(Location_msg().generateMsg_random(), threadName,)) #地理位置
threadInfo = {}
threadInfo["name"] = threadName
threadInfo["status"] = 0
self.threadArr[threadName] = threadInfo
theThread.start()
timeEnd = int(time.time() * 1000)
timeExpend = timeEnd - timeStart
time.sleep(20)
print("耗时:" + str(timeExpend) + " 毫秒")
print("并发数据每秒发送:" + str(int(self.threadCount / (timeExpend / 1000))))
print("平均响应时间:" + str(self.totalTime / self.threadCount) + "毫秒")
print("发送总数:" + str(self.threadCount))
print("响应失败数:" + str(self.failThreadCount))
self.writeToFile("../../data/threadDetails.json",self.threadArr)
# print(json.dumps( self.threadArr))
def writeToFile(self,path,data):
with open(path, "w", encoding='utf-8') as fi:
json.dump(data, fi)
# fi.write(data)
if __name__ == "__main__":
t = SendMultMsgThread()
# t.setMsg("7e0002000001314620111800065b7e")
# t.setMsg("7e020001020131462011190001fffc7fff001c010401c0a6380659ad7a02090042003b200204185704310102EA6600010400000000000204001e7c1f0003050A0001f400000405020001d4c000050400057d0240000604000119400007040007530000100c0004006403f203f203f203f2001114ffffffffffffffffffff00200000000000000000001202002400130106001D0101EB7960C0020bb860D0013c62f00203216050014c60F0015860B001146330011c646001416490012060A00201146014010160100102610002022661100201f561F0020e746210040000119c6040012c60700200e660E00203206701010067020100670301016704024e20670502000067060200416707040000017d02097e")
t.startThread()
#coding:utf-8
import binascii
import json
import socket
import threading
import time
from random import random
from lib.multiThread.ThreadBase import ThreadBase
from lib.protocol.message.Location_msg import Location_msg
from lib.protocol.message.TerminalRegister_msg import TerminalRegister_msg
class SendMultMsgThread():
def __init__(self,host="10.100.11.20",port=9001,msg=""):
self.host = host
self.port = port
self.msg = msg
self.timeOut = 1 #socket超时时间
self.BUF_SIZE = 1024 #接收消息缓存
self.threadCount = 10 #并发线程数
self.totalTime = 0 #所有线程的运行总和
self.threadArr = {} #保存每个线程的信息
self.failThreadCount = 0 #失败线程数
pass
############################################
# 设置host
############################################
def setHost(self,host):
self.host = host
############################################
# 设置端口号
############################################
def setPort(self,port):
self.port = port
############################################
# 设置消息
############################################
def setMsg(self,msg):
self.msg = msg
############################################
# 设置并发线程数
############################################
def setThreadCount(self,threadCount):
self.threadCount = threadCount
############################################
# 发送一条消息
############################################
def sendMsg(self,msg,threadName):
msg = msg
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) # 在客户端开启心跳
client.settimeout(self.timeOut)
startTime = int(time.time() * 1000)
try:
client.connect((self.host, self.port))
client.send(binascii.a2b_hex(msg))
except BaseException as e:
client.close()
self.threadArr[threadName]["status"] = 1
self.failThreadCount = self.failThreadCount + 1
print("连接超时,socket断开")
return
try:
data = client.recv(self.BUF_SIZE)
# print(data)
except BaseException as e:
# traceback.print_exc()
client.close()
# raise RuntimeError('socket 接收消息超时!')
self.threadArr[threadName]["status"] = 1
self.failThreadCount = self.failThreadCount + 1
print('socket 接收消息超时!')
return
endTime = int(time.time() * 1000)
timeExpend = endTime - startTime
self.threadArr[threadName]["timeExp"] = timeExpend
self.totalTime = self.totalTime + timeExpend
client.close()
############################################
# 持续发送消息
############################################
def sendMsgContinuous(self):
pass
############################################
# 启动并发线程
############################################
def startThread(self):
timeStart = int(time.time() * 1000)
for i in range(0,self.threadCount):
threadName = "thread" + str(i)
carid = 201912000000 + i
theThread = threading.Thread(target=self.sendMsg, args=("7e0002000001314620111800065b7e",threadName,)) # 数据写死,心跳
threadInfo = {}
threadInfo["name"] = threadName
threadInfo["status"] = 0
self.threadArr[threadName] = threadInfo
theThread.start()
timeEnd = int(time.time() * 1000)
timeExpend = timeEnd - timeStart
time.sleep(20)
print("耗时:" + str(timeExpend) + " 毫秒")
print("并发数据每秒发送:" + str(int(self.threadCount / (timeExpend / 1000))))
print("平均响应时间:" + str(self.totalTime / self.threadCount) + "毫秒")
print("发送总数:" + str(self.threadCount))
print("响应失败数:" + str(self.failThreadCount))
self.writeToFile("../../data/threadDetails.json",self.threadArr)
def writeToFile(self,path,data):
with open(path, "w", encoding='utf-8') as fi:
json.dump(data, fi)
# fi.write(data)
#获取随机消息数据
def getRandomMsg(self,carId):
#carid = 201912010002
wh = random.randint(0,3)
msg = ""
if wh == 0:
hearbeat_msg = "4040000b000c4d" + carId + "0003b59f"
msg = hearbeat_msg
elif wh == 1:
GPS_msg = "4040003d000e4d" + carId + "0010011403040a0e0501c329ed0659dec501f402e8000000b4050a0b0c9305050258001400000fa0000000005e5f68e75e5f7f6d9ec9"
msg = GPS_msg
elif wh == 2:
OBD_msg = "4040007000034d" + carId + "0012011403040a101b26d7fffff0000000000505000000143c00000bb80100000fa00000000a000000000000000003e803e839331e100055320000001312001007d0001e0000000000000096000000280096ffff3e0001f40000003e00000000000000000000006487"
msg = OBD_msg
return msg
if __name__ == "__main__":
t = SendMultMsgThread()
# t.setMsg("7e0002000001314620111800065b7e")
# t.setMsg("7e020001020131462011190001fffc7fff001c010401c0a6380659ad7a02090042003b200204185704310102EA6600010400000000000204001e7c1f0003050A0001f400000405020001d4c000050400057d0240000604000119400007040007530000100c0004006403f203f203f203f2001114ffffffffffffffffffff00200000000000000000001202002400130106001D0101EB7960C0020bb860D0013c62f00203216050014c60F0015860B001146330011c646001416490012060A00201146014010160100102610002022661100201f561F0020e746210040000119c6040012c60700200e660E00203206701010067020100670301016704024e20670502000067060200416707040000017d02097e")
t.startThread()
This diff is collapsed.
......@@ -55,7 +55,8 @@ class Location_msg(MessageBase):
phoneNum = self.getRandomStr(11, "0123456789")
msgWaterCode = self.getRandomNum(1, 65535)
encryptionType = 0
subPkg = self.getRandomNum(intArr=[0, 8192])
# subPkg = self.getRandomNum(intArr=[0, 8192])
subPkg = 0
msgHeader = self.getMsgHeader_GUI(msgID,phoneNum,msgWaterCode,encryptionType,subPkg)
msgBody = self.getMsgBody_random()
checkCode = self.getCheckCode(msgHeader + msgBody)
......@@ -79,8 +80,8 @@ class Location_msg(MessageBase):
# 获取消息体,针对图形界面,可传递参数
def getMsgBody_GUI(self,baseInfo,extraInfo):
msg = ""
locationBaseInfo = self.getLocationBaseInfo(baseInfo) #位置基本信息
locationExtraInfo = self.getLocationExtraInfo(extraInfo) #位置附加信息
locationBaseInfo = self.getLocationBaseInfo_GUI(baseInfo) #位置基本信息
locationExtraInfo = self.getLocationExtraInfo_GUI(extraInfo) #位置附加信息
msg = locationBaseInfo + locationExtraInfo
return msg
# 获取消息体,数据随机产生
......@@ -180,6 +181,44 @@ class Location_msg(MessageBase):
# data = data +extra_FA
return data
def getLocationExtraInfo_GUI(self):
data = ""
# 里程,DWORD,1 / 10km,对应车上里程表读数;不支持OBD时,为基于GPS车速统计的车辆累计行驶总里程。
extra_01 = "01" + self.int2hexStringByBytes(4) + self.int2hexStringByBytes(20202020,4)
#油量,WORD,1/10L,对应车上油量表读数
extra_02 = "02" + self.int2hexStringByBytes(2) + self.int2hexStringByBytes(5200,2)
#超速报警附加信息
extra_11 = "11" + self.int2hexStringByBytes(int(len(self.getOverSpeedAlarmExtraInfo()) / 2)) + self.getOverSpeedAlarmExtraInfo()
#进出区域/路线报警附加信息见
extra_12 = "12" + self.int2hexStringByBytes(6) + self.getInOutAreaAlarmExtraInfo()
#路段行驶时间不足/过长报警附加信息见
extra_13 = "13" + self.int2hexStringByBytes(7) + self.getDrivingLongOrShortAlarmExtraInfo()
#IO 状态位
extra_2A = "2A" + self.int2hexStringByBytes(2) + self.getStatusBit()
#BYTE,无线通信网络信号强度
extra_30 = "30" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(33)
#BYTE,GNSS 定位卫星数
extra_31 = "31" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(2)
#基础数据项列表
extra_EA = "EA" + self.int2hexStringByBytes(int(len(self.getBaseDataList()) / 2)) + self.getBaseDataList()
#轿车 OBD 数据流
extra_EB = "EB" + self.int2hexStringByBytes(int(len(SaloonCarOBD_data().generateSaloonCarOBDData()) / 2)) + SaloonCarOBD_data().generateSaloonCarOBDData()
#货车 OBD 数据流
extra_EC = "EC" + self.int2hexStringByBytes(int(len(TruckCarOBD_data().generateTruckCarOBD_data()) / 2)) + TruckCarOBD_data().generateTruckCarOBD_data()
#新能源 OBD 数据流
extra_ED = "ED" + self.int2hexStringByBytes(int(len(NewEnergyCar_data().generateNewEnergyCar_data()) / 2)) + NewEnergyCar_data().generateNewEnergyCar_data()
#外设数据项列表
extra_EE = "EE" + self.int2hexStringByBytes(int(len(Circum_data().generateCircum_data()) / 2)) + Circum_data().generateCircum_data()
#报警事件 ID 数据项列表
extra_FA = "FA" + self.int2hexStringByBytes(int(len(AlarmEvent_data().generateAlarmEvent_data()) / 2)) + AlarmEvent_data().generateAlarmEvent_data()
data = extra_11 + extra_31 + extra_EA + extra_EC
# data = extra_01 + extra_02 + extra_11 + extra_12 + extra_13
# data = data + extra_2A + extra_30 + extra_31 + extra_EA + extra_EB
# data = data +extra_FA
return data
# 获取位置附加信息,数据随机产生
def getLocationExtraInfo_random(self):
data = ""
......
......@@ -29,8 +29,7 @@ port = 9001
# msg = TerminalVersionInfo_msg().generateMsg() #终端版本信息上报
# msg = QueryTerminalParam_res().generateMsg() #查询终端参数应答
# msg = QueryTerminalProperty_res().generateMsg() #查询终端属性应答消息
# msg = Location_msg().generateMsg() #位置信息汇报
msg = Location_msg().generateMsg_random()
msg = Location_msg().generateMsg() #位置信息汇报
# msg = DataUpstreamTransport_msg().generateMsg() #数据上行透传消息
# msg = TerminalUpdataResult_msg().generateMsg() #终端升级结果通知
# msg = LocationDataBatchUpdate_msg().generateMsg() #定位数据批量上传
......
......@@ -20,12 +20,12 @@ port = 9008
# msg = GPSReport_protocol().generateGpsMsg() #GPS消息数据
# msg = OBDReport_protocol().generateOBDReportMsg() #OBD终端上报数据
# msg = OBDReport_CAN_protocol().generateOBDReportCANMsg() #OBD终端上报CAN数据
# msg = HeartBeatReport_protocol().generateHeartBeatMsg() #终端上报心跳协议
msg = HeartBeatReport_protocol().generateHeartBeatMsg() #终端上报心跳协议
# msg = LoginReport_protocol().generateLoginMsg() #终端上报登录协议
# msg = SecurityStatusReport_protocol().generateSecurityStatusMsg() #终端上报安防状态协议
# msg = BaseStationReport_protocol().generateBaseStationMsg() #终端上报基站定位协议
# msg = TroubleReport_protocol().generateTroubleMsg() #终端上报故障码数据包
msg = EventReport_protocol().generateEventMsg()
# msg = EventReport_protocol().generateEventMsg()
print(msg)
BUF_SIZE = 1024
......@@ -37,5 +37,6 @@ client.send(binascii.a2b_hex(msg))
# client.send(bytes.fromhex(msg))
data = client.recv(BUF_SIZE)
print(data)
print(binascii.b2a_hex(data))
client.close()
......@@ -18,10 +18,48 @@
<label id="subPkg_label" style="color:grey;">分包个数:</label><input disabled="disabled" id="pkgCounts" type="text" class="form-control" value="0" style="width:60px;">
</div>
<H3 style="border-bottom: 1px solid #eee;">基础消息内容:</H3>
<ul class="protocol_content" style="padding:0px;">
<li><label>省域ID:</label><input id="provinceId" type="text" class="form-control" value="50"></li>
<li><label>市县域ID:</label><input id="countyId" type="text" class="form-control" value="103"></li>
</ul>
<div style="width:100%;border-width:1px;border-style:solid;border-color:darkgray;border-radius:10px;padding:2px;">
<label>报警标志:</label><br>
<ul class="protocol_content" style="padding:0px;">
<li style="width:160px;"><label>紧急报警:</label><select style="width:65px;" id="emergencyAlarm" class="form-control">
<option value="0"></option>
<option value="1"></option></select></li>
<li style="width:160px;"><label>超速报警:</label><select style="width:65px;" id="overspeedAlarm" class="form-control">
<option value="0"></option>
<option value="2"></option></select></li>
<li style="width:160px;"><label>疲劳驾驶:</label><select style="width:65px;" id="fatigueDriving" class="form-control">
<option value="0"></option>
<option value="4"></option></select></li>
<li style="width:160px;"><label>危险预警:</label><select style="width:65px;" id="dangerAlarm" class="form-control">
<option value="0"></option>
<option value="8"></option></select></li>
<li style="width:160px;"><label style="word-break:break-all;font-size:10px;">GNSS模块发生故障:</label><select style="width:65px;" id="GNSSTrouble" class="form-control">
<option value="0"></option>
<option value="16"></option></select></li>
<li style="width:160px;"><label style="word-break:break-all;font-size:10px;">GNSS天线未接或被剪断:</label><select style="width:65px;" id="GNSSAntennaeLost" class="form-control">
<option value="0"></option>
<option value="32"></option></select></li>
<li style="width:160px;"><label style="word-break:break-all;font-size:10px;">GNSS天线短路:</label><select style="width:65px;" id="GNSSAntennaeShortOut" class="form-control">
<option value="0"></option>
<option value="64"></option></select></li>
<li style="width:160px;"><label style="word-break:break-all;font-size:10px;">终端主电源欠压:</label><select style="width:65px;" id="TerminalMainPowerLackVoltage" class="form-control">
<option value="0"></option>
<option value="128"></option></select></li>
<li style="width:160px;"><label style="word-break:break-all;font-size:10px;">终端主电源掉电:</label><select style="width:65px;" id="TerminalMainPowerLostConnect" class="form-control">
<option value="0"></option>
<option value="256"></option></select></li>
<li style="width:160px;"><label style="word-break:break-all;font-size:10px;">终端LCD或显示器故障:</label><select style="width:65px;" id="TerMinalLCDTrouble" class="form-control">
<option value="0"></option>
<option value="512"></option></select></li>
<li style="width:160px;"><label style="word-break:break-all;font-size:10px;">TTS模块故障:</label><select style="width:65px;" id="TTSTrouble" class="form-control">
<option value="0"></option>
<option value="1024"></option></select></li>
<li style="width:160px;"><label>摄像头故障:</label><select style="width:65px;" id="cameraTrouble" class="form-control">
<option value="0"></option>
<option value="2048"></option></select></li>
</ul>
</div>
<H3 style="border-bottom: 1px solid #eee;">附加消息内容:</H3>
<ul class="protocol_content" style="padding:0px;">
<li><label>省域ID:</label><input id="provinceId2" type="text" class="form-control" value="50"></li>
......
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