Commit 3eaee87f authored by liyuanhong's avatar liyuanhong

M500压测程序,修改了报文的时间为当前时间

parent 11a031a4
...@@ -15,12 +15,12 @@ class SendMultMsgThread_m500(ThreadBase): ...@@ -15,12 +15,12 @@ class SendMultMsgThread_m500(ThreadBase):
self.msg = msg self.msg = msg
self.timeOut = 30 #socket超时时间 self.timeOut = 30 #socket超时时间
self.BUF_SIZE = 1024 #接收消息缓存 self.BUF_SIZE = 1024 #接收消息缓存
self.threadCount = 1000 #并发线程数 self.threadCount = 5 #并发线程数
self.totalTime = 0 #所有线程的运行总和 self.totalTime = 0 #所有线程的运行总和
self.threadArr = {} #保存每个线程的信息 self.threadArr = {} #保存每个线程的信息
self.failThreadCount = 0 #失败线程数 self.failThreadCount = 0 #失败线程数
self.durThreads = [] #持续发送线程数组,当数组为空,表示所有线程已经结束 self.durThreads = [] #持续发送线程数组,当数组为空,表示所有线程已经结束
dt = 1 * 10 * 60 dt = 1 * 1 * 60
self.durTime = dt #线程持续时间 self.durTime = dt #线程持续时间
self.connectTimeoutNum = 0 #连接超时线程数 self.connectTimeoutNum = 0 #连接超时线程数
self.sendTimeoutNum = 0 #发送超时线程数 self.sendTimeoutNum = 0 #发送超时线程数
...@@ -293,11 +293,22 @@ class SendMultMsgThread_m500(ThreadBase): ...@@ -293,11 +293,22 @@ class SendMultMsgThread_m500(ThreadBase):
hearbeat_msg = hearbeat_msg[:-4] + self.crc16(hearbeat_msg[:-4]) hearbeat_msg = hearbeat_msg[:-4] + self.crc16(hearbeat_msg[:-4])
msg = hearbeat_msg msg = hearbeat_msg
elif wh == 1: elif wh == 1:
GPS_msg = "4040003d00054d" + str(carId) + "001001140305031e0301c329ed0659dec501f402e8000000b4050a0b0c9305050258001400000fa0000000005e606f115e60723be44b" timeStamp = time.time()
timeArray = time.localtime(int(timeStamp - 8 * 3600))
dateTimeM = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
timeHex = self.getUTCTime(dateTimeM)
# GPS_msg = "4040003d00054d" + str(carId) + "001001140305031e0301c329ed0659dec501f402e8000000b4050a0b0c9305050258001400000fa0000000005e606f115e60723be44b"
GPS_msg = "4040003d00054d" + str(carId) + "001001" + timeHex + "01c329ed0659dec501f402e8000000b4050a0b0c9305050258001400000fa0000000005e606f115e60723be44b"
GPS_msg = GPS_msg[:-4] + self.crc16(GPS_msg[:-4]) GPS_msg = GPS_msg[:-4] + self.crc16(GPS_msg[:-4])
msg = GPS_msg msg = GPS_msg
elif wh == 2: elif wh == 2:
OBD_msg = "4040007000064d" + str(carId) + "00120114030503202d26d7fffff0000000000505000000143c00000bb80100000fa00000000a0000000000005e60723b723b39331e100055320000001312001007d0001e0000000000000096000000280096ffff3e0001f40000003e00000000000000000000007213" timeStamp = time.time()
timeArray = time.localtime(int(timeStamp - 8 * 3600))
dateTimeM = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
timeHex = self.getUTCTime(dateTimeM)
# OBD_msg = "4040007000064d" + str(carId) + "00120114030503202d26d7fffff0000000000505000000143c00000bb80100000fa00000000a0000000000005e60723b723b39331e100055320000001312001007d0001e0000000000000096000000280096ffff3e0001f40000003e00000000000000000000007213"
OBD_msg = "4040007000064d" + str(carId) + "001201" + timeHex + "26d7fffff0000000000505000000143c00000bb80100000fa00000000a0000000000005e60723b723b39331e100055320000001312001007d0001e0000000000000096000000280096ffff3e0001f40000003e00000000000000000000007213"
OBD_msg = OBD_msg[:-4] + self.crc16(OBD_msg[:-4]) OBD_msg = OBD_msg[:-4] + self.crc16(OBD_msg[:-4])
msg = OBD_msg msg = OBD_msg
return msg return msg
...@@ -356,11 +367,53 @@ class SendMultMsgThread_m500(ThreadBase): ...@@ -356,11 +367,53 @@ class SendMultMsgThread_m500(ThreadBase):
print(info_2) print(info_2)
return info_1 + "\n" +info_2 + "\n" return info_1 + "\n" +info_2 + "\n"
#####################################################
# 将UTC时间转换为16进制,
# 例如:2020-01-02 20:30:00 (年取后面2字节)则将20,01,02,20,30,00 转换为对应的6个字节
# theTime:传入一个类似:2020-01-03 13:05:13的一个字符串
#####################################################
def getUTCTime(self,theTime):
# 获取当前时间,时间格式为:2020-01-03 13:05:13
# now_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
# 将2020-01-03 13:05:13时间格式转换为一个数组
# timeStr = "2020-01-03 13:05:13"
timeStr = theTime
timeArr = []
timeArr.append(timeStr[2:4])
timeArr.append(timeStr[5:7])
timeArr.append(timeStr[8:11])
timeArr.append(timeStr[11:13])
timeArr.append(timeStr[14:16])
timeArr.append(timeStr[17:19])
UTCTime = ""
for i in range(0, len(timeArr)):
UTCTime += self.int2hexString(int(timeArr[i]))
return UTCTime
#####################################################
# 数字转换为16进制字符串
#####################################################
def int2hexString(self, num):
hexStr = hex(num)[2:]
if (len(hexStr) % 2) == 1:
hexStr = "0" + hexStr
return hexStr
#####################################################
# 数字转换为16进制字符串,通过传入字节数可自动补0
# 传入数据格式所占字节数
#####################################################
def int2hexStringByBytes(self, num,bytescount=1):
hexStr = hex(num)[2:]
while len(hexStr) < (bytescount * 2):
hexStr = "0" + hexStr
return hexStr
if __name__ == "__main__": if __name__ == "__main__":
t = SendMultMsgThread_m500() t = SendMultMsgThread_m500()
# t.setHost("10.100.12.32") # t.setHost("10.100.12.32")
t.setHost("10.100.5.251") t.setHost("10.100.12.32")
t.setPort(9008) #M500 t.setPort(9008) #M500
# t.setPort(9009) # M300 # t.setPort(9009) # M300
# t.startThread() # t.startThread()
......
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