Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
GW_pressureTest
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李远洪
GW_pressureTest
Commits
3eaee87f
Commit
3eaee87f
authored
May 20, 2020
by
liyuanhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
M500压测程序,修改了报文的时间为当前时间
parent
11a031a4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
5 deletions
+58
-5
lib/pressure/SendMultMsgThread_m500.py
lib/pressure/SendMultMsgThread_m500.py
+58
-5
No files found.
lib/pressure/SendMultMsgThread_m500.py
View file @
3eaee87f
...
...
@@ -15,12 +15,12 @@ class SendMultMsgThread_m500(ThreadBase):
self
.
msg
=
msg
self
.
timeOut
=
30
#socket超时时间
self
.
BUF_SIZE
=
1024
#接收消息缓存
self
.
threadCount
=
1000
#并发线程数
self
.
threadCount
=
5
#并发线程数
self
.
totalTime
=
0
#所有线程的运行总和
self
.
threadArr
=
{}
#保存每个线程的信息
self
.
failThreadCount
=
0
#失败线程数
self
.
durThreads
=
[]
#持续发送线程数组,当数组为空,表示所有线程已经结束
dt
=
1
*
1
0
*
60
dt
=
1
*
1
*
60
self
.
durTime
=
dt
#线程持续时间
self
.
connectTimeoutNum
=
0
#连接超时线程数
self
.
sendTimeoutNum
=
0
#发送超时线程数
...
...
@@ -293,11 +293,22 @@ class SendMultMsgThread_m500(ThreadBase):
hearbeat_msg
=
hearbeat_msg
[:
-
4
]
+
self
.
crc16
(
hearbeat_msg
[:
-
4
])
msg
=
hearbeat_msg
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
])
msg
=
GPS_msg
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
])
msg
=
OBD_msg
return
msg
...
...
@@ -356,11 +367,53 @@ class SendMultMsgThread_m500(ThreadBase):
print
(
info_2
)
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__"
:
t
=
SendMultMsgThread_m500
()
# t.setHost("10.100.12.32")
t
.
setHost
(
"10.100.
5.251
"
)
t
.
setHost
(
"10.100.
12.32
"
)
t
.
setPort
(
9008
)
#M500
# t.setPort(9009) # M300
# t.startThread()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment