Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
new-socketemulator
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
李远洪
new-socketemulator
Commits
f0bb02f9
Commit
f0bb02f9
authored
Mar 16, 2020
by
liyuanhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
M300 压测程序完成
parent
c4fd6987
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
306 additions
and
60 deletions
+306
-60
lib/multiThread/SendMultMsgThread_m300.py
lib/multiThread/SendMultMsgThread_m300.py
+255
-32
lib/multiThread/SendMultMsgThread_m500.py
lib/multiThread/SendMultMsgThread_m500.py
+8
-26
lib/socket/messageTest.py
lib/socket/messageTest.py
+2
-2
lib/socket/protocolTest_M300.py
lib/socket/protocolTest_M300.py
+41
-0
lib/socket/protocolTest_M500.py
lib/socket/protocolTest_M500.py
+0
-0
No files found.
lib/multiThread/SendMultMsgThread_m300.py
View file @
f0bb02f9
This diff is collapsed.
Click to expand it.
lib/multiThread/SendMultMsgThread_m500.py
View file @
f0bb02f9
...
@@ -18,12 +18,12 @@ class SendMultMsgThread():
...
@@ -18,12 +18,12 @@ class SendMultMsgThread():
self
.
msg
=
msg
self
.
msg
=
msg
self
.
timeOut
=
30
#socket超时时间
self
.
timeOut
=
30
#socket超时时间
self
.
BUF_SIZE
=
1024
#接收消息缓存
self
.
BUF_SIZE
=
1024
#接收消息缓存
self
.
threadCount
=
7
000
#并发线程数
self
.
threadCount
=
1
000
#并发线程数
self
.
totalTime
=
0
#所有线程的运行总和
self
.
totalTime
=
0
#所有线程的运行总和
self
.
threadArr
=
{}
#保存每个线程的信息
self
.
threadArr
=
{}
#保存每个线程的信息
self
.
failThreadCount
=
0
#失败线程数
self
.
failThreadCount
=
0
#失败线程数
self
.
durThreads
=
[]
#持续发送线程数组,当数组为空,表示所有线程已经结束
self
.
durThreads
=
[]
#持续发送线程数组,当数组为空,表示所有线程已经结束
dt
=
1
*
30
*
60
dt
=
1
*
1
*
60
self
.
durTime
=
dt
#线程持续时间
self
.
durTime
=
dt
#线程持续时间
self
.
connectTimeoutNum
=
0
#连接超时线程数
self
.
connectTimeoutNum
=
0
#连接超时线程数
self
.
sendTimeoutNum
=
0
#发送超时线程数
self
.
sendTimeoutNum
=
0
#发送超时线程数
...
@@ -289,33 +289,17 @@ class SendMultMsgThread():
...
@@ -289,33 +289,17 @@ class SendMultMsgThread():
msg
=
OBD_msg
msg
=
OBD_msg
return
msg
return
msg
#获取随机消息数据(M300车机)
def
getRandomMsg_M300
(
self
,
carId
):
# carId = 201912010002
wh
=
random
.
randint
(
0
,
2
)
msg
=
""
if
wh
==
0
:
hearbeat_msg
=
"4040000e00044d"
+
str
(
carId
)
+
"8000000300cf91"
hearbeat_msg
=
hearbeat_msg
[:
-
4
]
+
self
.
crc16
(
hearbeat_msg
[:
-
4
])
msg
=
hearbeat_msg
elif
wh
==
1
:
GPS_msg
=
"4040003d00054d"
+
str
(
carId
)
+
"001001140305031e0301c329ed0659dec501f402e8000000b4050a0b0c9305050258001400000fa0000000005e606f115e60723be44b"
GPS_msg
=
GPS_msg
[:
-
4
]
+
self
.
crc16
(
GPS_msg
[:
-
4
])
msg
=
GPS_msg
elif
wh
==
2
:
OBD_msg
=
"4040007000064d"
+
str
(
carId
)
+
"00120114030503202d26d7fffff0000000000505000000143c00000bb80100000fa00000000a0000000000005e60723b723b39331e100055320000001312001007d0001e0000000000000096000000280096ffff3e0001f40000003e00000000000000000000007213"
OBD_msg
=
OBD_msg
[:
-
4
]
+
self
.
crc16
(
OBD_msg
[:
-
4
])
msg
=
OBD_msg
return
msg
# 获取随机消息数据(新硬件车机)
# 获取随机消息数据(新硬件车机)
def
getRandomMsg_new
(
self
,
carId
):
def
getRandomMsg_new
(
self
,
carId
):
# carId = 201912010002
# carId = 201912010002
wh
=
random
.
randint
(
0
,
2
)
wh
=
random
.
randint
(
0
,
2
)
msg
=
""
msg
=
""
wh
=
0
if
wh
==
0
:
if
wh
==
0
:
hearbeat_msg
=
"4040000e00044d"
+
str
(
carId
)
+
"8000000300cf91"
hearbeat_msg
=
"4040000e00044d"
+
str
(
carId
)
+
"8000000300cf91"
hearbeat_msg
=
hearbeat_msg
[:
-
4
]
+
self
.
crc16
(
hearbeat_msg
[:
-
4
])
hearbeat_msg
=
hearbeat_msg
+
self
.
getCheckCode
(
hearbeat_msg
[
2
:])
+
"7e"
hearbeat_msg
=
self
.
replace7e7d
(
hearbeat_msg
)
msg
=
hearbeat_msg
msg
=
hearbeat_msg
elif
wh
==
1
:
elif
wh
==
1
:
GPS_msg
=
"4040003d00054d"
+
str
(
GPS_msg
=
"4040003d00054d"
+
str
(
...
@@ -330,7 +314,7 @@ class SendMultMsgThread():
...
@@ -330,7 +314,7 @@ class SendMultMsgThread():
return
msg
return
msg
####################################################
####################################################
# 定义生成校验字段的函数
# 定义生成校验字段的函数
(M500 校验方式)
# inputStr:需要传入一个已经转换为16进制的字符串
# inputStr:需要传入一个已经转换为16进制的字符串
#####################################################
#####################################################
# add crc 16 check at the end of the string
# add crc 16 check at the end of the string
...
@@ -358,7 +342,6 @@ class SendMultMsgThread():
...
@@ -358,7 +342,6 @@ class SendMultMsgThread():
return
outputStr
return
outputStr
else
:
else
:
return
inputStr
return
inputStr
# pad zero to the right of the string if not long enough
# pad zero to the right of the string if not long enough
def
rightPad
(
self
,
inputStr
,
strLen
):
def
rightPad
(
self
,
inputStr
,
strLen
):
if
(
strLen
>
len
(
inputStr
)):
if
(
strLen
>
len
(
inputStr
)):
...
@@ -385,14 +368,13 @@ class SendMultMsgThread():
...
@@ -385,14 +368,13 @@ class SendMultMsgThread():
return
info_1
+
"
\n
"
+
info_2
+
"
\n
"
return
info_1
+
"
\n
"
+
info_2
+
"
\n
"
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
t
=
SendMultMsgThread
()
t
=
SendMultMsgThread
()
# t.setHost("10.100.12.32")
# t.setHost("10.100.12.32")
t
.
setHost
(
"10.100.5.251"
)
t
.
setHost
(
"10.100.5.251"
)
t
.
setPort
(
9008
)
t
.
setPort
(
9008
)
#M500
# t.setPort(9009) # M300
# t.startThread()
# t.startThread()
t
.
startThreadContinuous
()
t
.
startThreadContinuous
()
...
...
lib/socket/messageTest.py
View file @
f0bb02f9
...
@@ -22,14 +22,14 @@ port = 9001
...
@@ -22,14 +22,14 @@ port = 9001
# msg = MessageBase().generateMsg()
# msg = MessageBase().generateMsg()
# msg = TerminalCommonMsgRes_msg().generateMsg() #终端通用应答
# msg = TerminalCommonMsgRes_msg().generateMsg() #终端通用应答
#
msg = TerminalHeartbeat_msg().generateMsg() #终端心跳
msg
=
TerminalHeartbeat_msg
()
.
generateMsg
()
#终端心跳
# msg = TerminalRegister_msg().generateMsg() #终端注册
# msg = TerminalRegister_msg().generateMsg() #终端注册
# msg = TerminalCancle_msg().generateMsg() #终端注销
# msg = TerminalCancle_msg().generateMsg() #终端注销
# msg = TerminalAuthenticate_msg().generateMsg() #终端鉴权
# msg = TerminalAuthenticate_msg().generateMsg() #终端鉴权
# msg = TerminalVersionInfo_msg().generateMsg() #终端版本信息上报
# msg = TerminalVersionInfo_msg().generateMsg() #终端版本信息上报
# msg = QueryTerminalParam_res().generateMsg() #查询终端参数应答
# msg = QueryTerminalParam_res().generateMsg() #查询终端参数应答
# msg = QueryTerminalProperty_res().generateMsg() #查询终端属性应答消息
# msg = QueryTerminalProperty_res().generateMsg() #查询终端属性应答消息
msg
=
Location_msg
()
.
generateMsg
()
#位置信息汇报
#
msg = Location_msg().generateMsg() #位置信息汇报
# msg = DataUpstreamTransport_msg().generateMsg() #数据上行透传消息
# msg = DataUpstreamTransport_msg().generateMsg() #数据上行透传消息
# msg = TerminalUpdataResult_msg().generateMsg() #终端升级结果通知
# msg = TerminalUpdataResult_msg().generateMsg() #终端升级结果通知
# msg = LocationDataBatchUpdate_msg().generateMsg() #定位数据批量上传
# msg = LocationDataBatchUpdate_msg().generateMsg() #定位数据批量上传
...
...
lib/socket/protocolTest_M300.py
0 → 100644
View file @
f0bb02f9
#coding:utf-8
import
binascii
import
socket
from
lib.protocol.report.GPSReport_protocol
import
GPSReport_protocol
from
lib.protocol.report.OBDReport_CAN_protocol
import
OBDReport_CAN_protocol
from
lib.protocol.report.OBDReport_CAN_protocol
import
OBDReport_CAN_protocol
from
lib.protocol.report.HeartBeatReport_protocol
import
HeartBeatReport_protocol
from
lib.protocol.report.LoginReport_protocol
import
LoginReport_protocol
from
lib.protocol.report.SecurityStatusReport_protocol
import
SecurityStatusReport_protocol
from
lib.protocol.report.BaseStationReport_protocol
import
BaseStationReport_protocol
from
lib.protocol.report.TroubleReport_protocol
import
TroubleReport_protocol
from
lib.protocol.report.EventReport_protocol
import
EventReport_protocol
# host = "10.100.12.34"
# port = 8712
# host = "10.100.12.32"
# port = 9009
# host = "10.100.5.251"
# port = 9009
host
=
"10.100.5.251"
port
=
9009
msg
=
"7e000400e14d2019120315000000957e"
#终端上报心跳协议
print
(
msg
)
BUF_SIZE
=
1024
client
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
client
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_KEEPALIVE
,
1
)
# 在客户端开启心跳
client
.
connect
((
host
,
port
))
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
()
lib/socket/protocolTest.py
→
lib/socket/protocolTest
_M500
.py
View file @
f0bb02f9
File moved
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