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
801bedcf
Commit
801bedcf
authored
May 08, 2020
by
liyuanhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
M500 模拟器实时控制功能完成
parent
f8bf25bc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
153 additions
and
2 deletions
+153
-2
lib/socket/service/ProtocolSimulaterService.py
lib/socket/service/ProtocolSimulaterService.py
+7
-0
templates/protocolTools/index.html
templates/protocolTools/index.html
+1
-1
templates/protocolTools/report/M_carSimulater_page.html
templates/protocolTools/report/M_carSimulater_page.html
+51
-1
views/protocolTools/M_carSimulater_process.py
views/protocolTools/M_carSimulater_process.py
+94
-0
No files found.
lib/socket/service/ProtocolSimulaterService.py
View file @
801bedcf
...
@@ -66,6 +66,13 @@ class ProtocolSimulaterService():
...
@@ -66,6 +66,13 @@ class ProtocolSimulaterService():
self
.
carData
=
data
self
.
carData
=
data
def
setServiceStatus
(
self
,
data
):
def
setServiceStatus
(
self
,
data
):
self
.
serviceStatus
=
data
self
.
serviceStatus
=
data
def
setCarSpeed
(
self
,
data
):
self
.
data
[
"travelData"
][
"carSpeed"
]
=
data
def
setOilExpend
(
self
,
data
):
self
.
data
[
"travelData"
][
"oilExpend"
]
=
data
def
setSendDur
(
self
,
data
):
self
.
sendDur
=
int
(
data
)
def
getWebsocket
(
self
):
def
getWebsocket
(
self
):
...
...
templates/protocolTools/index.html
View file @
801bedcf
...
@@ -41,7 +41,7 @@
...
@@ -41,7 +41,7 @@
<!-- <li id="protocols_query" onclick="swichLeftTab(this)"><a {% if arg.path[1]=="protocolQuery_view" %} class="active_left_tab" {% endif %}><span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span> 远程查询报文<span class="sr-only"></span></a></li>-->
<!-- <li id="protocols_query" onclick="swichLeftTab(this)"><a {% if arg.path[1]=="protocolQuery_view" %} class="active_left_tab" {% endif %}><span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span> 远程查询报文<span class="sr-only"></span></a></li>-->
</ul>
</ul>
<ul
class=
"nav nav-sidebar"
style=
"margin-top:20px;"
>
<ul
class=
"nav nav-sidebar"
style=
"margin-top:20px;"
>
<li
id=
"car_simulater"
onclick=
"swichLeftTab(this)"
><a
{%
if
arg.path[1]=
="M_carSimulater_view"
%}
class=
"active_left_tab"
{%
endif
%}
><span
class=
"glyphicon glyphicon-hand-right"
aria-hidden=
"true"
></span>
车
辆行为模拟
</a></li>
<li
id=
"car_simulater"
onclick=
"swichLeftTab(this)"
><a
{%
if
arg.path[1]=
="M_carSimulater_view"
%}
class=
"active_left_tab"
{%
endif
%}
><span
class=
"glyphicon glyphicon-hand-right"
aria-hidden=
"true"
></span>
车
机模拟器
</a></li>
</ul>
</ul>
<!-- <ul class="nav nav-sidebar" style="margin-top:20px;">-->
<!-- <ul class="nav nav-sidebar" style="margin-top:20px;">-->
<!-- <li id="test" onclick="swichLeftTab(this)"><a {% if arg.path[1]=="test_view" %} class="active_left_tab" {% endif %}><span class="glyphicon glyphicon-text-size" aria-hidden="true"></span> 测试页面</a></li>-->
<!-- <li id="test" onclick="swichLeftTab(this)"><a {% if arg.path[1]=="test_view" %} class="active_left_tab" {% endif %}><span class="glyphicon glyphicon-text-size" aria-hidden="true"></span> 测试页面</a></li>-->
...
...
templates/protocolTools/report/M_carSimulater_page.html
View file @
801bedcf
...
@@ -157,7 +157,11 @@
...
@@ -157,7 +157,11 @@
</span>
</span>
</h5>
</h5>
<div
id=
"realTimeCtl_area"
style=
"display:none;"
>
<div
id=
"realTimeCtl_area"
style=
"display:none;"
>
实时控制
<div
style=
"padding:10px;"
>
<span
style=
"margin-left:10px"
><label>
车速度(Km/h):
</label><input
style=
"width:80px;margin-right:5px;"
id=
"change_speed"
type=
"text"
class=
"form-control"
value=
"60"
><button
type=
"button"
class=
"btn btn-primary"
onclick=
"changeSpeed()"
>
改变车速
</button></span>
<span
style=
"margin-left:10px"
><label>
油耗(Km/L):
</label><input
style=
"width:80px;margin-right:5px;"
id=
"change_oilExpend"
type=
"text"
class=
"form-control"
value=
"10"
><button
type=
"button"
class=
"btn btn-primary"
onclick=
"changeOilExpend()"
>
改变油耗
</button></span>
<span
style=
"margin-left:10px"
><label>
上报间隔(秒):
</label><input
style=
"width:80px;margin-right:5px;"
id=
"change_durTime"
type=
"text"
class=
"form-control"
value=
"5"
><button
type=
"button"
class=
"btn btn-primary"
onclick=
"changeDurTime()"
>
改变上报间隔
</button></span>
</div>
</div>
</div>
</div>
</div>
<div
style=
"width:100%;padding-bottom:60px;border-bottom: 1px solid #eee;"
>
<div
style=
"width:100%;padding-bottom:60px;border-bottom: 1px solid #eee;"
>
...
@@ -745,6 +749,52 @@ function sendSurplusOilAlarmEvent(){
...
@@ -745,6 +749,52 @@ function sendSurplusOilAlarmEvent(){
sendjson
(
data
,
url
);
sendjson
(
data
,
url
);
}
}
// -------------------------------- 实时控制js代码-------------------------------------------
//改变车速
function
changeSpeed
(){
var
data
=
{}
var
carId
=
$
(
"
#carId
"
).
val
()
var
speed
=
$
(
"
#change_speed
"
).
val
()
data
[
"
carId
"
]
=
carId
data
[
"
speed
"
]
=
speed
//会话session数据
data
[
"
session
"
]
=
{}
var
sessionId
=
$
(
"
#curSession
"
).
val
()
data
[
"
session
"
][
"
sessionId
"
]
=
sessionId
url
=
"
/protocolTools/M_carSimulater_process/changeCarSpeed
"
;
$
(
"
#carSpeed
"
).
val
(
speed
)
sendjson
(
data
,
url
);
}
//改变油耗
function
changeOilExpend
(){
var
data
=
{}
var
carId
=
$
(
"
#carId
"
).
val
()
var
oilExpend
=
$
(
"
#change_oilExpend
"
).
val
()
data
[
"
carId
"
]
=
carId
data
[
"
oilExpend
"
]
=
oilExpend
//会话session数据
data
[
"
session
"
]
=
{}
var
sessionId
=
$
(
"
#curSession
"
).
val
()
data
[
"
session
"
][
"
sessionId
"
]
=
sessionId
url
=
"
/protocolTools/M_carSimulater_process/changeOilExpend
"
;
$
(
"
#oilExpend
"
).
val
(
oilExpend
)
sendjson
(
data
,
url
);
}
//改变发送间隔
function
changeDurTime
(){
var
data
=
{}
var
carId
=
$
(
"
#carId
"
).
val
()
var
durTime
=
$
(
"
#change_durTime
"
).
val
()
data
[
"
carId
"
]
=
carId
data
[
"
durTime
"
]
=
durTime
//会话session数据
data
[
"
session
"
]
=
{}
var
sessionId
=
$
(
"
#curSession
"
).
val
()
data
[
"
session
"
][
"
sessionId
"
]
=
sessionId
$
(
"
#durTime
"
).
val
(
durTime
)
url
=
"
/protocolTools/M_carSimulater_process/changeDurTime
"
;
sendjson
(
data
,
url
);
}
</script>
</script>
{% endblock %}
{% endblock %}
</div>
</div>
...
...
views/protocolTools/M_carSimulater_process.py
View file @
801bedcf
...
@@ -868,4 +868,98 @@ def sendSurplusOilAlarmEvent():
...
@@ -868,4 +868,98 @@ def sendSurplusOilAlarmEvent():
traceback
.
print_exc
()
traceback
.
print_exc
()
data
[
"status"
]
=
"4003"
data
[
"status"
]
=
"4003"
data
[
"message"
]
=
"Error: 发送剩余油量异常告警事件失败!"
data
[
"message"
]
=
"Error: 发送剩余油量异常告警事件失败!"
return
Response
(
json
.
dumps
(
data
),
mimetype
=
'application/json'
)
#--------------------------------------- 实时控制逻辑 ---------------------------------------
##########################################
# 【接口类型】改变车速
##########################################
@
M_carSimulater_process
.
route
(
"/changeCarSpeed"
,
methods
=
[
'POST'
])
def
changeCarSpeed
():
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"
]
travelStatus
=
service
.
getTravelStatus
()
#获取汽车行驶状态
if
travelStatus
==
0
or
travelStatus
==
2
:
data
[
"status"
]
=
"4003"
data
[
"message"
]
=
"Error: 汽车还未行驶,不可改变车速!"
elif
travelStatus
==
1
:
try
:
service
.
setCarSpeed
(
params
[
"speed"
])
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
(
"/changeOilExpend"
,
methods
=
[
'POST'
])
def
changeOilExpend
():
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"
]
travelStatus
=
service
.
getTravelStatus
()
#获取汽车行驶状态
if
travelStatus
==
0
or
travelStatus
==
2
:
data
[
"status"
]
=
"4003"
data
[
"message"
]
=
"Error: 汽车还未行驶,不可改变油耗!"
elif
travelStatus
==
1
:
try
:
service
.
setOilExpend
(
params
[
"oilExpend"
])
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
(
"/changeDurTime"
,
methods
=
[
'POST'
])
def
changeDurTime
():
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"
]
travelStatus
=
service
.
getTravelStatus
()
#获取汽车行驶状态
if
travelStatus
==
0
or
travelStatus
==
2
:
data
[
"status"
]
=
"4003"
data
[
"message"
]
=
"Error: 汽车还未行驶,不可改变发送间隔!"
elif
travelStatus
==
1
:
try
:
service
.
setSendDur
(
params
[
"durTime"
])
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'
)
return
Response
(
json
.
dumps
(
data
),
mimetype
=
'application/json'
)
\ No newline at end of file
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