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()
#coding:utf-8
import datetime
from lib.protocol.ProtocolBase import ProtocolBase
from lib.protocol.report.GPSReport_protocol import GPSReport_protocol
from lib.protocol.report.SecurityStatusReport_protocol import SecurityStatusReport_protocol
class EventClass(ProtocolBase):
def __init__(self):
pass
# 3 点火事件附带信息
def fireExtraInfo(self):
allRapidlyAccelerateCount = self.int2hexStringByBytes(100, 2) # 急加速总次数
allSharpSlowdownCount = self.int2hexStringByBytes(101, 2) # 急减速总次数
allSharpTurn = self.int2hexStringByBytes(35, 2) # 急转弯总次数
securityData = SecurityStatusReport_protocol.generateSecurityStatusData() # 安防数据
data = allRapidlyAccelerateCount + allSharpSlowdownCount + allSharpTurn + securityData
return data
#4 熄火事件附带信息
def misFireExtraInfo(self):
allRapidlyAccelerateCount = self.int2hexStringByBytes(100,2) #急加速总次数
allSharpSlowdownCount = self.int2hexStringByBytes(101,2) #急减速总次数
allSharpTurn = self.int2hexStringByBytes(35,2) #急转弯总次数
securityData = SecurityStatusReport_protocol.generateSecurityStatusData() #安防数据
data = allRapidlyAccelerateCount + allSharpSlowdownCount + allSharpTurn + securityData
return data
#5 设防事件附带信息
def setUpDefencesExtraInfo(self):
securityData = SecurityStatusReport_protocol.generateSecurityStatusData() # 安防数据
return securityData
#6 撤防事件附带信息
def setDownDefencesExtraInfo(self):
securityData = SecurityStatusReport_protocol.generateSecurityStatusData() # 安防数据
return securityData
#7 锁车未成功事件附带信息
def lockCarFaillExtraInfo(self):
securityData = SecurityStatusReport_protocol.generateSecurityStatusData() # 安防数据
return securityData
#8 超时未设防事件附带信息
def noDefencesWithTimeoutExtraInfo(self):
securityData = SecurityStatusReport_protocol.generateSecurityStatusData() # 安防数据
return securityData
#9 设防玻璃未关事件附带信息
def defencesGlassNoCloseExtraInfo(self):
securityData = SecurityStatusReport_protocol.generateSecurityStatusData() # 安防数据
return securityData
#10 设防非法开门事件附带信息
def defencesIllegalCloseDoorExtraInfo(self):
securityData = SecurityStatusReport_protocol.generateSecurityStatusData() # 安防数据
return securityData
#11 设防非法点火事件附带信息
def defencesIllegalFireExtraInfo(self):
securityData = SecurityStatusReport_protocol.generateSecurityStatusData() # 安防数据
return securityData
#12 急加速报警附带信息
def rapidlyAccelerateExtraInfo(self):
totalRapidlyAccelerateCount = 100 #急加速总次数
totalSharpSlowdown = 200 #急减速总次数
totalSharpTurn = 50 #急转弯总次数
dataProperty = 2 #事件属性,1:表示事件发生时刻,前10秒的事件采样数据;2:表示事件发生时刻,后10秒的事件采样数据;
GPSSampleData = self.GPSDataFromSeconds(10) #GPS 采样点 ,N秒内的GPS采样数据,170个字节
CANSampleData = self.CANDataFromSeconds(10) #CAN采样点 ,N秒内的CAN采样数据,90个字节
SENSORSampleData = self.SENSORDataFromSeconds(20) #SENSOR采样点 ,N秒内的SENSOR采样数据
totalRapidlyAccelerateCount = self.int2hexStringByBytes(totalRapidlyAccelerateCount,2)
totalSharpSlowdown = self.int2hexStringByBytes(totalSharpSlowdown,2)
totalSharpTurn = self.int2hexStringByBytes(totalSharpTurn,2)
dataProperty = self.int2hexStringByBytes(dataProperty,1)
data = totalRapidlyAccelerateCount + totalSharpSlowdown + totalSharpTurn + dataProperty + GPSSampleData + CANSampleData + SENSORSampleData
return data
#13 急减速报警附带信息
def sharpSlowdownExtraInfo(self):
totalRapidlyAccelerateCount = 100 #急加速总次数
totalSharpSlowdown = 200 #急减速总次数
totalSharpTurn = 50 #急转弯总次数
dataProperty = 2 #事件属性,1:表示事件发生时刻,前10秒的事件采样数据;2:表示事件发生时刻,后10秒的事件采样数据;
GPSSampleData = self.GPSDataFromSeconds(10) #GPS 采样点 ,N秒内的GPS采样数据,170个字节
CANSampleData = self.CANDataFromSeconds(10) #CAN采样点 ,N秒内的CAN采样数据,90个字节
SENSORSampleData = self.SENSORDataFromSeconds(20) #SENSOR采样点 ,N秒内的SENSOR采样数据
totalRapidlyAccelerateCount = self.int2hexStringByBytes(totalRapidlyAccelerateCount,2)
totalSharpSlowdown = self.int2hexStringByBytes(totalSharpSlowdown,2)
totalSharpTurn = self.int2hexStringByBytes(totalSharpTurn,2)
dataProperty = self.int2hexStringByBytes(dataProperty,1)
data = totalRapidlyAccelerateCount + totalSharpSlowdown + totalSharpTurn + dataProperty + GPSSampleData + CANSampleData + SENSORSampleData
return data
#14 急转弯报警附带信息
def sharpTurnExtraInfo(self):
totalRapidlyAccelerateCount = 100 #急加速总次数
totalSharpSlowdown = 200 #急减速总次数
totalSharpTurn = 50 #急转弯总次数
dataProperty = 2 #事件属性,1:表示事件发生时刻,前10秒的事件采样数据;2:表示事件发生时刻,后10秒的事件采样数据;
GPSSampleData = self.GPSDataFromSeconds(10) #GPS 采样点 ,N秒内的GPS采样数据,170个字节
CANSampleData = self.CANDataFromSeconds(10) #CAN采样点 ,N秒内的CAN采样数据,90个字节
SENSORSampleData = self.SENSORDataFromSeconds(20) #SENSOR采样点 ,N秒内的SENSOR采样数据
totalRapidlyAccelerateCount = self.int2hexStringByBytes(totalRapidlyAccelerateCount,2)
totalSharpSlowdown = self.int2hexStringByBytes(totalSharpSlowdown,2)
totalSharpTurn = self.int2hexStringByBytes(totalSharpTurn,2)
dataProperty = self.int2hexStringByBytes(dataProperty,1)
data = totalRapidlyAccelerateCount + totalSharpSlowdown + totalSharpTurn + dataProperty + GPSSampleData + CANSampleData + SENSORSampleData
return data
#15 碰撞报警附带信息
def collisionAlarmExtraInfo(self):
totalCount = self.int2hexStringByBytes(7,2) #历史碰撞总次数
# 1:表示事件发生时刻,前10秒的事件采样数据;
# [碰撞报警前后10秒采样数据附带信息]
# 2:表示事件发生时刻,后10秒的事件采样数据;
# [碰撞报警前后10秒采样数据附带信息]
# 3:表示事件发生时刻,后120秒的事件采样数据;
# [碰撞报警后120秒采样数据附带信息]
dataProperty = self.int2hexString(1)
extraInfo = self.collisionSamplingData() #附带信息
data = totalCount + dataProperty + extraInfo
return data
#16 碰撞报警前后10秒采样数据附带信息
def collisionSamplingData(self):
GPSSampleData = self.GPSDataFromSeconds(10) #GPS 采样点 ,N秒内的GPS采样数据,170个字节
CANSampleData = self.CANDataFromSeconds(10) #CAN采样点 ,N秒内的CAN采样数据,90个字节
SENSORSampleData1 = self.SENSORDataFromSeconds(20) #SENSOR采样点 ,N秒内的SENSOR采样数据
SENSORSampleData2 = self.SENSORDataFromSeconds(40) #S碰撞时刻前后100毫秒内的SENSOR采样数据;50ms滑动窗车平面加速度;(2.5ms采样周期)碰撞前后100毫秒内的滑动窗SENSOR采样数据
SENSORStatus = self.int2hexString(1) #SENSOR状态,0:初始状态,1:学习状态,2:工作状态,其他:保留
# 角度范围: [0, 360);
# 学习状态时,相对车平面内的x正半轴方向逆时针旋转角度;
# 工作状态时,相对车头方向逆时针旋转角度。
collisionAngle = self.int2hexStringByBytes(60,2)
SENSORSampleData3 = self.SENSORDataFromSeconds(40) #碰撞时刻前后100毫秒内的SENSOR采样数据;50ms滑动窗垂直车平面加速度;(2.5ms采样周期),碰撞前后100毫秒内的滑动窗SENSOR采样数据
SENSORCheckFlag = self.int2hexString(1) #0:未初始化或者中心点偏离大于148mg,1:完成初始化或者中心点偏离小于100mg
carSlopeAngle = self.carSlopeAngleFromSeconds(10) #车辆倾斜角
data = GPSSampleData + CANSampleData + SENSORSampleData1 + SENSORSampleData2 + SENSORStatus + collisionAngle + SENSORSampleData3 + SENSORCheckFlag + carSlopeAngle
return data
#23 GPS采样数据项
def GPSSamplingData(self):
latitude = 40.22077 #纬度
longitude = 116.23128 #经度
speed = 60.9 #速度
directionAngle = 80.8 #方向角
elevation = 2999.9 #海拔
statusBit = 1 #状态位,Bit7:当前定位是否有效,0-无效,1-有效,其它Bit位预留
latitude = GPSReport_protocol().getLatitude(latitude)
longitude = GPSReport_protocol().getLongitude(longitude)
speed = GPSReport_protocol().getSpeed(speed)
directionAngle = GPSReport_protocol().getDirectionAngle(directionAngle)
elevation = GPSReport_protocol().geteElevation(elevation)
statusBit = GPSReport_protocol().getStatusBit(statusBit)
data = latitude + longitude + speed + directionAngle + elevation + statusBit
return data
#24 N秒内的GPS采样数据
def GPSDataFromSeconds(self,counts):
data = ""
for i in range(0,counts):
data += self.GPSSamplingData()
return data
#25 加速度CAN数据项
def CANSamplingData(self):
speed = 65 #车速
enginSpeed = 1000 #发动机转速
brakingStatus = 0 #刹车状态:1-刹车,0-未刹车,2-不支持;
acceleratorLocation = 50 #油门踏板位置
airDamper = 17 #节气门开度
troubleCount = 2 #故障码个数
speed = self.int2hexStringByBytes(speed,1)
enginSpeed = self.int2hexStringByBytes(enginSpeed,2)
brakingStatus = self.int2hexStringByBytes(brakingStatus,1)
acceleratorLocation = self.int2hexStringByBytes(acceleratorLocation,2)
airDamper = self.int2hexStringByBytes(airDamper,2)
troubleCount = self.int2hexStringByBytes(troubleCount,1)
data = speed + enginSpeed + brakingStatus + acceleratorLocation + airDamper + troubleCount
return data
#26 N秒内的CAN采样数据
def CANDataFromSeconds(self,counts):
data = ""
for i in range(0,counts):
data += self.CANSamplingData()
return data
#27 N秒内的SENSOR采样数据
def SENSORDataFromSeconds(self,counts):
data = ""
for i in range(0,counts):
data += self.int2hexStringByBytes(30,2) #第1秒内的第1个0.5秒内的平均加速度值
return data
#30 终端插入报警附带信息
def terminalInsertionAlarmExtraInfo(self,theTime=""):
if theTime != "":
return self.getUTCTimeHex(theTime)
else:
return self.getUTCTimeHex(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
#36 预点火事件附带信息
def preFiringExtraInfo(self):
bit0 = 1 #1:有点火电压波形,0:无点火电压波形
bit1 = 2 #2:有电压和噪声点火,0:无电压和噪声点火
bit2 = 4 #3:有gps车速和噪声点火,0:无gps车速和噪声点火
data = bit0 + bit1 + bit2
return self.int2hexString(data)
#39 SOS报警事件附加信息
def SOSAlarmEtraInfo(self,theTime):
if theTime != "":
return self.getUTCTimeHex(theTime)
else:
return self.getUTCTimeHex(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
#41 充电事件附带信息
def chargeEtraInfo(self):
SOC = self.int2hexString(0.3 * 100) #乘以100上传,平台除以100处理(显示小于1的小数值)
SOH = self.int2hexString(4 * 100) #乘以100上传,平台除以100处理
voltage = self.int2hexStringByBytes(3.6 * 10,2) #乘以10上传,平台除以10处理
chargeEventCode = self.int2hexString(3) #充电开始报警,和后续的充电结束报警为同一编号
data = SOC + SOH + voltage + chargeEventCode
return data
#45 终端拔出报警附带信息
def terminalPulloutAlarmExtraInfo(self,theTime=""):
if theTime != "":
return self.getUTCTimeHex(theTime)
else:
return self.getUTCTimeHex(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
#54 N秒内的车辆倾斜角
def carSlopeAngleFromSeconds(self,counts):
data = ""
for i in range(0,counts):
data += self.int2hexStringByBytes(60,2) #第1秒内倾斜角[0,180)
data += self.int2hexStringByBytes(self.num2signedNum(-50),2) #第1秒内侧倾角[-90, 90],大于0右倾,小于0左倾
return data
if __name__ == "__main__":
# print(EventClass().GPSDataFromSeconds(10))
# print(EventClass().CANSamplingData())
# print(EventClass().rapidlyAccelerateEtraInfo())
# print(EventClass().carSlopeAngleFromSeconds(10))
# print(EventClass().SENSORDataFromSeconds(40))
# print(EventClass().carSlopeAngleFromSeconds(10))
print(EventClass().collisionSamplingData())
\ No newline at end of file
......@@ -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