Commit 801bedcf authored by liyuanhong's avatar liyuanhong

M500 模拟器实时控制功能完成

parent f8bf25bc
...@@ -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):
......
...@@ -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>-->
......
...@@ -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>
......
...@@ -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
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