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
b38924ce
Commit
b38924ce
authored
May 06, 2020
by
liyuanhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完成了低电压报警和终端主电路断电报警,以及多人同时使用其他人无法接受消息的bug
parent
6f53b121
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
120 additions
and
6 deletions
+120
-6
lib/socket/service/ProtocolSimulaterService.py
lib/socket/service/ProtocolSimulaterService.py
+5
-1
templates/protocolTools/report/M_carSimulater_page.html
templates/protocolTools/report/M_carSimulater_page.html
+27
-5
views/protocolTools/M_carSimulater_process.py
views/protocolTools/M_carSimulater_process.py
+88
-0
No files found.
lib/socket/service/ProtocolSimulaterService.py
View file @
b38924ce
...
...
@@ -64,6 +64,8 @@ class ProtocolSimulaterService():
self
.
sn
=
data
def
setCarData
(
self
,
data
):
self
.
carData
=
data
def
setServiceStatus
(
self
,
data
):
self
.
serviceStatus
=
data
def
getWebsocket
(
self
):
...
...
@@ -87,7 +89,7 @@ class ProtocolSimulaterService():
self
.
socket
.
setTimeOut
(
self
.
timeout
)
return
self
.
socket
.
receive
()
#发送消息,可指定消息的描述类型
def
serviceSendMsg
(
self
,
msg
,
type
):
#type字段目前废掉没有实际意
义
def
serviceSendMsg
(
self
,
msg
,
type
):
#type字段目前废掉没有实际意
self
.
sendMsg
(
msg
)
type
=
self
.
getMsgFunId
(
msg
)
self
.
websocket
.
sendMsgToClient
(
">>>>"
+
type
+
":"
+
msg
,
self
.
websocketId
)
...
...
@@ -211,6 +213,8 @@ class ProtocolSimulaterService():
# 为websocket服务添加一个新的客户端连接
def
addNewWebsocket
(
self
):
t2
=
threading
.
Thread
(
target
=
self
.
serviceRev
,
args
=
())
t2
.
start
()
t3
=
threading
.
Thread
(
target
=
self
.
setWebsocketId
,
args
=
())
t3
.
start
()
...
...
templates/protocolTools/report/M_carSimulater_page.html
View file @
b38924ce
...
...
@@ -40,7 +40,7 @@
<div
id=
"container3"
style=
"width:100%;min-height:750px;float:left;_background:green;margin-top:10px;_border-top: 1px solid #eee;"
>
<div
style=
"width:100%;padding-bottom:10px;border-bottom: 1px solid #eee;"
>
<span><label>
车机Id:
</label><input
id=
"carId"
type=
"text"
class=
"form-control"
value=
"M202003060520"
></span>
<span><label>
消息流水号:
</label><input
id=
"WATER_CODE"
style=
"width:60px;"
type=
"text"
class=
"form-control"
value=
"1"
></span>
<span
style=
"display:none;"
><label>
消息流水号:
</label><input
id=
"WATER_CODE"
style=
"width:60px;"
type=
"text"
class=
"form-control"
value=
"1"
></span>
<span><label>
上报间隔(秒):
</label><input
id=
"durTime"
style=
"width:60px;"
type=
"text"
class=
"form-control"
value=
"5"
></span>
<span><label>
设置超时时间:
</label><input
style=
"width:80px;"
id=
"timeout"
type=
"text"
class=
"form-control"
value=
"36000"
></span>
</div>
...
...
@@ -124,11 +124,11 @@
</h5>
<div
id=
"event_area"
style=
"display:none;"
>
<div
style=
"margin-top:10px;width:100%;border-width:1px;border-style:solid;border-color:darkgray;border-radius:10px;padding:2px;background:skyblue;"
>
<label
style=
"padding: 0px 10px;"
><input
type=
"checkbox"
id=
"lowVoltage_check"
onclick=
"eventSelect(this)"
/>
汽车电瓶低电压报警
</label>
<label
style=
"padding: 0px 10px;"
><input
type=
"checkbox"
id=
"powerOff_check"
onclick=
"eventSelect(this)"
/>
终端主电断电报警
</label>
<label
style=
"padding: 0px 10px;"
><input
type=
"checkbox"
id=
"rapidlyAccelerateEvent_check"
onclick=
"eventSelect(this)"
/>
急加速
</label>
<label
style=
"padding: 0px 10px;"
><input
type=
"checkbox"
id=
"sharpSlowdownEvent_check"
onclick=
"eventSelect(this)"
/>
急减速
</label>
<label
style=
"padding: 0px 10px;"
><input
type=
"checkbox"
id=
"sharpTurnEvent_check"
onclick=
"eventSelect(this)"
/>
急转弯
</label>
<label
style=
"padding: 0px 10px;"
><input
type=
"checkbox"
id=
"0003"
onclick=
"eventSelect(this)"
/>
汽车电瓶低电压报警
</label>
<label
style=
"padding: 0px 10px;"
><input
type=
"checkbox"
id=
"0004"
onclick=
"eventSelect(this)"
/>
终端主电断电报警
</label>
<label
style=
"padding: 0px 10px;"
><input
type=
"checkbox"
id=
"0012"
onclick=
"eventSelect(this)"
/>
设防
</label>
<label
style=
"padding: 0px 10px;"
><input
type=
"checkbox"
id=
"0013"
onclick=
"eventSelect(this)"
/>
撤防
</label>
<label
style=
"padding: 0px 10px;"
><input
type=
"checkbox"
id=
"0036"
onclick=
"eventSelect(this)"
/>
低档高速报警
</label>
...
...
@@ -136,6 +136,8 @@
<label
style=
"padding: 0px 10px;"
><input
type=
"checkbox"
id=
"004A"
onclick=
"eventSelect(this)"
/>
剩余油量异常告警
</label>
</div>
<div
style=
"padding:10px;"
>
<span
id=
"lowVoltage_button"
style=
"display:none;"
><button
type=
"button"
class=
"btn btn-primary"
onclick=
"sendLowVoltageEvent(this)"
>
汽车电瓶低电压报警
</button></label></span>
<span
id=
"powerOff_button"
style=
"display:none;"
><button
type=
"button"
class=
"btn btn-primary"
onclick=
"sendPowerOffEvent(this)"
>
终端主电断电报警
</button></label></span>
<span
id=
"rapidlyAccelerateEvent_button"
style=
"display:none;"
><button
type=
"button"
class=
"btn btn-primary"
onclick=
"sendRapidlyAccelerateEvent(this)"
>
急加速
</button></label></span>
<span
id=
"sharpSlowdownEvent_button"
style=
"display:none;"
><button
type=
"button"
class=
"btn btn-primary"
onclick=
"sendSharpSlowdownEvent(this)"
>
急减速
</button></label></span>
<span
id=
"sharpTurnEvent_button"
style=
"display:none;"
><button
type=
"button"
class=
"btn btn-primary"
onclick=
"sendSharpTurnEvent(this)"
>
急转弯
</button></label></span>
...
...
@@ -632,7 +634,11 @@ function isShowEventArea(e){
//事件的选择与取消选择
function
eventSelect
(
e
){
if
(
$
(
e
).
is
(
'
:checked
'
)){
if
(
$
(
e
).
attr
(
"
id
"
)
==
"
rapidlyAccelerateEvent_check
"
){
if
(
$
(
e
).
attr
(
"
id
"
)
==
"
lowVoltage_check
"
){
$
(
"
#lowVoltage_button
"
).
css
(
"
display
"
,
"
inline
"
)
}
else
if
(
$
(
e
).
attr
(
"
id
"
)
==
"
powerOff_check
"
){
$
(
"
#powerOff_button
"
).
css
(
"
display
"
,
"
inline
"
)
}
else
if
(
$
(
e
).
attr
(
"
id
"
)
==
"
rapidlyAccelerateEvent_check
"
){
$
(
"
#rapidlyAccelerateEvent_button
"
).
css
(
"
display
"
,
"
inline
"
)
}
else
if
(
$
(
e
).
attr
(
"
id
"
)
==
"
sharpSlowdownEvent_check
"
){
$
(
"
#sharpSlowdownEvent_button
"
).
css
(
"
display
"
,
"
inline
"
)
...
...
@@ -640,7 +646,11 @@ function eventSelect(e){
$
(
"
#sharpTurnEvent_button
"
).
css
(
"
display
"
,
"
inline
"
)
}
}
else
{
if
(
$
(
e
).
attr
(
"
id
"
)
==
"
rapidlyAccelerateEvent_check
"
){
if
(
$
(
e
).
attr
(
"
id
"
)
==
"
lowVoltage_check
"
){
$
(
"
#lowVoltage_button
"
).
css
(
"
display
"
,
"
none
"
)
}
else
if
(
$
(
e
).
attr
(
"
id
"
)
==
"
powerOff_check
"
){
$
(
"
#powerOff_button
"
).
css
(
"
display
"
,
"
none
"
)
}
else
if
(
$
(
e
).
attr
(
"
id
"
)
==
"
rapidlyAccelerateEvent_check
"
){
$
(
"
#rapidlyAccelerateEvent_button
"
).
css
(
"
display
"
,
"
none
"
)
}
else
if
(
$
(
e
).
attr
(
"
id
"
)
==
"
sharpSlowdownEvent_check
"
){
$
(
"
#sharpSlowdownEvent_button
"
).
css
(
"
display
"
,
"
none
"
)
...
...
@@ -649,6 +659,18 @@ function eventSelect(e){
}
}
}
//发送汽车电瓶低电压报警
function
sendLowVoltageEvent
(){
var
data
=
getPageData
()
url
=
"
/protocolTools/M_carSimulater_process/sendLowVoltageEvent
"
;
sendjson
(
data
,
url
);
}
//发送汽车电瓶低电压报警
function
sendPowerOffEvent
(){
var
data
=
getPageData
()
url
=
"
/protocolTools/M_carSimulater_process/sendPowerOffEvent
"
;
sendjson
(
data
,
url
);
}
//发送急加速事件消息
function
sendRapidlyAccelerateEvent
(){
var
data
=
getPageData
()
...
...
views/protocolTools/M_carSimulater_process.py
View file @
b38924ce
...
...
@@ -76,6 +76,10 @@ def createConect():
service
.
setSocket
(
cliSocket
)
service
.
setTimeout
(
timeout
)
service
.
setData
(
params
)
gpsLine
=
params
[
"gpsLine"
]
carId
=
params
[
"carId"
]
service
.
setCarId
(
carId
)
service
.
setGpsLine
(
gpsLine
)
global
websocket
if
websocket
==
None
:
service
.
startWebsocketService
()
#如果没有创建websocket服务,则启动新的websocket服务
...
...
@@ -385,6 +389,90 @@ def getConnects():
return
Response
(
json
.
dumps
(
data
),
mimetype
=
'application/json'
)
#--------------------------------------- 发送事件逻辑 ---------------------------------------
##########################################
# 【接口类型】发送汽车电瓶低电压事件
##########################################
@
M_carSimulater_process
.
route
(
"/sendLowVoltageEvent"
,
methods
=
[
'POST'
])
def
sendLowVoltageEvent
():
params
=
request
.
get_data
()
params
=
json
.
loads
(
params
.
decode
(
"utf-8"
))
sessionId
=
params
[
"session"
][
"sessionId"
]
data
=
{}
if
not
sessionId
in
connects
.
keys
():
data
[
"status"
]
=
"4003"
data
[
"message"
]
=
"Error: 未启动服务,不可发送事件!"
return
Response
(
json
.
dumps
(
data
),
mimetype
=
'application/json'
)
service
=
connects
[
sessionId
][
"service"
]
try
:
jdata
=
{
"WATER_CODE"
:
"0003"
,
"DEV_ID"
:
"M121501010001"
,
"gpsInfo"
:
{
"UTCTime"
:
"2020-04-30 14:59:33"
,
"latitude"
:
"40.22077"
,
"longitude"
:
"116.23128"
,
"speed"
:
"80.8"
,
"directionAngle"
:
"80.8"
,
"elevation"
:
"2999.9"
,
"positionStar"
:
"3"
,
"Pdop"
:
"0.3"
,
"Hdop"
:
"0.4"
,
"Vdop"
:
"0.5"
,
"statusBit"
:
162
,
"valtage"
:
"36.9"
,
"OBDSpeed"
:
"60.9"
,
"engineSpeed"
:
"3000"
,
"GPSTotalMileage"
:
"12800"
,
"totalOil"
:
"100000"
,
"totalTime"
:
"2020002"
,
"GPSTimestamp"
:
"1588229973"
},
"securityData"
:
{
"securityStatus"
:
107
,
"doorStatus"
:
0
,
"lockStatus"
:
0
,
"windowStatus"
:
0
,
"lightStatus"
:
0
,
"onoffStatusA"
:
0
,
"onoffStatusB"
:
112
,
"dataByte"
:
249
},
"event"
:
{
"0003"
:
{}}}
jdata
[
"DEV_ID"
]
=
params
[
"carId"
]
obj
=
EventReport_protocol
(
data
=
jdata
)
gpsData
=
service
.
genGPSData2
()
obj
.
setGPSPkg
(
gpsData
)
obj
.
setEventType
(
"0003"
)
msg
=
obj
.
generateEventMsg
()
service
.
serviceSendMsg
(
msg
,
"电瓶低电压事件"
)
service
.
setSn
(
service
.
getSn
()
+
1
)
data
[
"status"
]
=
"200"
data
[
"message"
]
=
"发送电瓶低电压事件成功!"
except
BaseException
as
e
:
# 打印异常信息
traceback
.
print_exc
()
data
[
"status"
]
=
"4003"
data
[
"message"
]
=
"Error: 发送电瓶低电压事件失败!"
return
Response
(
json
.
dumps
(
data
),
mimetype
=
'application/json'
)
##########################################
# 【接口类型】发送终端主电断电报警事件
##########################################
@
M_carSimulater_process
.
route
(
"/sendPowerOffEvent"
,
methods
=
[
'POST'
])
def
sendPowerOffEvent
():
params
=
request
.
get_data
()
params
=
json
.
loads
(
params
.
decode
(
"utf-8"
))
sessionId
=
params
[
"session"
][
"sessionId"
]
data
=
{}
if
not
sessionId
in
connects
.
keys
():
data
[
"status"
]
=
"4003"
data
[
"message"
]
=
"Error: 未启动服务,不可发送事件!"
return
Response
(
json
.
dumps
(
data
),
mimetype
=
'application/json'
)
service
=
connects
[
sessionId
][
"service"
]
try
:
jdata
=
{
"WATER_CODE"
:
"0003"
,
"DEV_ID"
:
"M121501010001"
,
"gpsInfo"
:
{
"UTCTime"
:
"2020-04-30 14:59:33"
,
"latitude"
:
"40.22077"
,
"longitude"
:
"116.23128"
,
"speed"
:
"80.8"
,
"directionAngle"
:
"80.8"
,
"elevation"
:
"2999.9"
,
"positionStar"
:
"3"
,
"Pdop"
:
"0.3"
,
"Hdop"
:
"0.4"
,
"Vdop"
:
"0.5"
,
"statusBit"
:
162
,
"valtage"
:
"36.9"
,
"OBDSpeed"
:
"60.9"
,
"engineSpeed"
:
"3000"
,
"GPSTotalMileage"
:
"12800"
,
"totalOil"
:
"100000"
,
"totalTime"
:
"2020002"
,
"GPSTimestamp"
:
"1588229973"
},
"securityData"
:
{
"securityStatus"
:
107
,
"doorStatus"
:
0
,
"lockStatus"
:
0
,
"windowStatus"
:
0
,
"lightStatus"
:
0
,
"onoffStatusA"
:
0
,
"onoffStatusB"
:
112
,
"dataByte"
:
249
},
"event"
:
{
"0004"
:
{}}}
jdata
[
"DEV_ID"
]
=
params
[
"carId"
]
obj
=
EventReport_protocol
(
data
=
jdata
)
gpsData
=
service
.
genGPSData2
()
obj
.
setGPSPkg
(
gpsData
)
obj
.
setEventType
(
"0004"
)
msg
=
obj
.
generateEventMsg
()
service
.
serviceSendMsg
(
msg
,
"终端主电断电报警"
)
service
.
setSn
(
service
.
getSn
()
+
1
)
data
[
"status"
]
=
"200"
data
[
"message"
]
=
"发送终端主电断电报警事件成功!"
except
BaseException
as
e
:
# 打印异常信息
traceback
.
print_exc
()
data
[
"status"
]
=
"4003"
data
[
"message"
]
=
"Error: 发送终端主电断电报警事件失败!"
return
Response
(
json
.
dumps
(
data
),
mimetype
=
'application/json'
)
##########################################
# 【接口类型】发送急加速事件
##########################################
...
...
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