Commit 02b4babe authored by liyuanhong's avatar liyuanhong

位置上报界面完成

parent dec8403f
......@@ -16,18 +16,19 @@ class SendMultMsgThread():
self.host = host
self.port = port
self.msg = msg
self.timeOut = 60 #socket超时时间
self.timeOut = 120 #socket超时时间
self.BUF_SIZE = 1024 #接收消息缓存
self.threadCount = 1000 #并发线程数
self.threadCount = 10000 #并发线程数
self.totalTime = 0 #所有线程的运行总和
self.threadArr = {} #保存每个线程的信息
self.failThreadCount = 0 #失败线程数
self.durThreads = [] #持续发送线程数组,当数组为空,表示所有线程已经结束
self.durTime = 60 #线程持续时间
self.durTime = 120 #线程持续时间
self.connectTimeoutNum = 0 #连接超时线程数
self.sendTimeoutNum = 0 #发送超时线程数
self.reviceTimeoutNum = 0 #接收超时线程数
self.sucessNum = 0 #成功线程数
self.messageCon = [] #用来统计每个线程所发的消息数
pass
############################################
......@@ -96,6 +97,7 @@ class SendMultMsgThread():
client.settimeout(self.timeOut)
startTime = int(time.time())
endTime = int(time.time())
msgCon = 0 #统计线程发的消息数量
self.durThreads.append(threadName)
try:
client.connect((self.host, self.port))
......@@ -108,12 +110,15 @@ class SendMultMsgThread():
timeExpend = endTime - startTime
self.threadArr[threadName]["timeExp"] = timeExpend
self.connectTimeoutNum = self.connectTimeoutNum + 1
self.messageCon.append(msgCon)
self.threadArr[threadName]["msgCon"] = msgCon
print(threadName + ":" + "连接超时,socket断开")
return
while (endTime - startTime) < self.durTime:
msg = self.getRandomMsg(carId)
try:
client.send(binascii.a2b_hex(msg))
msgCon = msgCon + 1
except BaseException as e:
client.close()
self.durThreads.remove(threadName)
......@@ -123,6 +128,8 @@ class SendMultMsgThread():
timeExpend = endTime - startTime
self.threadArr[threadName]["timeExp"] = timeExpend
self.sendTimeoutNum = self.sendTimeoutNum + 1
self.messageCon.append(msgCon)
self.threadArr[threadName]["msgCon"] = msgCon
print(threadName + ":" + "发送超时,socket断开")
return
try:
......@@ -133,6 +140,8 @@ class SendMultMsgThread():
self.threadArr[threadName]["status"] = 1
self.failThreadCount = self.failThreadCount + 1
self.reviceTimeoutNum = self.connectTimeoutNum + 1
self.messageCon.append(msgCon)
self.threadArr[threadName]["msgCon"] = msgCon
print(threadName + ":" + 'socket 接收消息超时!')
endTime = int(time.time())
timeExpend = endTime - startTime
......@@ -144,6 +153,8 @@ class SendMultMsgThread():
endTime = int(time.time())
timeExpend = endTime - startTime
self.threadArr[threadName]["timeExp"] = timeExpend
self.messageCon.append(msgCon)
self.threadArr[threadName]["msgCon"] = msgCon
client.close()
self.sucessNum = self.sucessNum + 1
self.durThreads.remove(threadName)
......@@ -189,14 +200,20 @@ class SendMultMsgThread():
timeEnd = int(time.time() * 1000)
timeExpend = timeEnd - timeStart
print("耗时:" + str(timeExpend) + " 毫秒产生了" + str(self.threadCount) + "线程")
time.sleep(0.5) #防止启动的时候溜掉某些启动比较慢的线程
while len(self.durThreads) != 0:
print("剩余线程数:" + str(len(self.durThreads)))
time.sleep(5)
time.sleep(2) #防止线程慢的时候,某些线程被漏统计的情况
print("-------------------------- 统计信息 --------------------------")
totalMsg = 0
for i in self.messageCon:
totalMsg = totalMsg + i
print("耗时:" + str(timeExpend) + " 毫秒产生了" + str(self.threadCount) + "线程")
print("设置socket超时时间:" + str(self.timeOut))
print("设置线程持续时间:" + str(self.durTime))
print("成功线程数:" + str(self.sucessNum))
print("消息总数:" + str(totalMsg))
print("连接失败:" + str(self.connectTimeoutNum))
print("发送失败:" + str(self.sendTimeoutNum))
print("接收失败:" + str(self.reviceTimeoutNum))
......
......@@ -334,7 +334,11 @@ class DataUpstreamTransport_msg(MessageBase):
#故障码
troubleCode = ""
for i in range(0,troubleCodeNums):
troubleCode = troubleCode + self.int2hexStringByBytes(i,4)
tbc0 = self.int2hexStringByBytes(i)
tbc1 = self.int2hexStringByBytes(1)
tbc2 = self.int2hexStringByBytes(2)
tbc3 = self.int2hexStringByBytes(3)
troubleCode = troubleCode + tbc0 + tbc1 + tbc2 + tbc3
data = infoTime + latitude + longitude + troubleCodeNumsHex + troubleCode
return data
......
......@@ -174,7 +174,8 @@ class Location_msg(MessageBase):
extra_FA = "FA" + self.int2hexStringByBytes(int(len(AlarmEvent_data().generateAlarmEvent_data()) / 2)) + AlarmEvent_data().generateAlarmEvent_data()
# data = extra_01 + extra_02 + extra_11 + extra_31 + extra_EA + extra_EB + extra_FA
data = extra_11 + extra_31 + extra_EA + extra_EB + extra_FA
# data = extra_11 + extra_31 + extra_EA + extra_EB + extra_FA
data = extra_11 + extra_31 + extra_EA + extra_FA
# data = extra_01 + extra_02 + extra_11 + extra_12 + extra_13
# data = data + extra_2A + extra_30 + extra_31 + extra_EA + extra_EB
......@@ -508,7 +509,7 @@ class Location_msg(MessageBase):
#######################################################
# 获取度信息
# 获取度信息
#######################################################
def getLatitude(self,data=29.40268):
data = int(data * 1000000)
......@@ -516,7 +517,7 @@ class Location_msg(MessageBase):
return dataHex
#######################################################
# 获取度信息
# 获取度信息
#######################################################
def getLongtitude(self,data=106.54041):
data = int(data * 1000000)
......
......@@ -49,14 +49,14 @@ class AlarmEvent_data(MessageBase):
crashAlarm = "0114" + self.int2hexStringByBytes(0) #碰撞报警
rapidChangeLines = "0115" + self.int2hexStringByBytes(0) #急变道报警
# data = buslineNotSleep
data = data + ignition + flameout + setUpDefences + withdrawGarrision + doorOpen
data = data + doorClose + systemStart + trailCarAlarm + locationTooLong + terminalPullOut
data = data + terminalInsert + lowVoltage + idlingSpeedOver + overspeedAlarm + fatigueDriving
data = data + waterTemperatureAlarm + highSpeedNeutralGear + oilExpendNotSurport + OBDNotSurport + lowWaterTemperatureHighSpeed
data = data + buslineNotSleep + illegalOpenDoor + illegalFire + rapidAccelerateAlarm + sharpSlowdownAlarm
data = data + sharpBendAlarm + crashAlarm + rapidChangeLines
data = ignition
# data = data + ignition + flameout + setUpDefences + withdrawGarrision + doorOpen
# data = data + doorClose + systemStart + trailCarAlarm + locationTooLong + terminalPullOut
# data = data + terminalInsert + lowVoltage + idlingSpeedOver + overspeedAlarm + fatigueDriving
# data = data + waterTemperatureAlarm + highSpeedNeutralGear + oilExpendNotSurport + OBDNotSurport + lowWaterTemperatureHighSpeed
# data = data + buslineNotSleep + illegalOpenDoor + illegalFire + rapidAccelerateAlarm + sharpSlowdownAlarm
# data = data + sharpBendAlarm + crashAlarm + rapidChangeLines
return data
# 创建报警事件数据,数据随机产生
......@@ -213,7 +213,7 @@ class AlarmEvent_data(MessageBase):
return data
#####################################################
# 获取疲劳驾驶报警附带信息
# 获取水温报警附带信息
#####################################################
def getWaterTemperatureAlarm(self):
#报警属性 1 BYTE 1:报警触发(无下面的数据内容项) 0:报警解除(有下面的数据内容项)
......
......@@ -82,7 +82,7 @@ class CarSafeStatusInfo(MessageBase):
lbDoorStatus = 0 #左后门,4:开 0:关
rbDoorStatus = 0 #右后门,8:开 0:关
trunk = 0 #后备箱,16:开 0:关
enginCover = 32 #发送机盖:32:开 0:关
enginCover = 0 #发动机盖:32:开 0:关
retain1 = 0 #预留字段
retain2 = 0 #预留字段
......@@ -101,7 +101,7 @@ class CarSafeStatusInfo(MessageBase):
lfDoorLockStatus = 0 #左前门锁状态,1:开 0:关
rfDoorLockStatus = 0 #右前门锁状态,2:开 0:关
lbDoorLockStatus = 0 #左后门锁状态,4:开 0:关
rbDoorLockStatus = 0 #后门锁状态,8:开 0:关
rbDoorLockStatus = 0 #后门锁状态,8:开 0:关
retain1 = 0
retain2 = 0
retain3 = 0
......
......@@ -29,8 +29,8 @@ port = 9001
# msg = TerminalVersionInfo_msg().generateMsg() #终端版本信息上报
# msg = QueryTerminalParam_res().generateMsg() #查询终端参数应答
# msg = QueryTerminalProperty_res().generateMsg() #查询终端属性应答消息
msg = Location_msg().generateMsg() #位置信息汇报
# msg = DataUpstreamTransport_msg().generateMsg() #数据上行透传消息
# msg = Location_msg().generateMsg() #位置信息汇报
msg = DataUpstreamTransport_msg().generateMsg() #数据上行透传消息
# msg = TerminalUpdataResult_msg().generateMsg() #终端升级结果通知
# msg = LocationDataBatchUpdate_msg().generateMsg() #定位数据批量上传
# msg = TextInfoUpload_msg().generateMsg() #文本信息上传
......
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