Commit bf0c5e45 authored by liyuanhong's avatar liyuanhong

M500模拟器增加固定在当前位置的功能

parent 1f519742
{"time": {"dateTime": "2020-07-10 10:37:16", "date": "2020-07-10", "time": "10:37:16"}, "curDayTravel": {"todayTotalMilleage": 2573, "todayTotalOil": 248, "todayTotalTime": 155, "theMilleage": 581, "theOil": 56, "theTime": 35}, "travelData": {"totalMilleage": 566997, "totalOil": 51642, "totalTime": 34013}, "event": {"threeRapid": {"totalRapidlyAccelerate": 43, "totalSharpSlowdown": 31, "totalSharpTurn": 34}}}
\ No newline at end of file
{"time": {"dateTime": "2020-07-10 10:37:16", "date": "2020-07-10", "time": "10:37:16"}, "curDayTravel": {"todayTotalMilleage": 6554, "todayTotalOil": 539, "todayTotalTime": 401, "theMilleage": 1904, "theOil": 119, "theTime": 119}, "travelData": {"totalMilleage": 570978, "totalOil": 51933, "totalTime": 34259}, "event": {"threeRapid": {"totalRapidlyAccelerate": 43, "totalSharpSlowdown": 31, "totalSharpTurn": 34}}}
\ No newline at end of file
......@@ -40,6 +40,7 @@ class ProtocolSimulaterService():
self.sn = 0 #消息流水号
self.travelDirection = 0 #行驶方向,0表示正向行驶,1表示反向行驶
self.directAngle = 60 #汽车方向角
self.fixPosition = 0 #是否固定当前GPS,0:否,1:是
'''
为0表示正常发送,type为1表示数据写入本地
# 用来控制发送消息的方式(是正常发送,还是将发送的数据保存到本地,不发送)
......@@ -94,7 +95,8 @@ class ProtocolSimulaterService():
self.travelDirection = data
def setVoltage(self,data):
self.data["other"]["valtage"] = data
def setFixPosition(self,data):
self.fixPosition = data
def getWebsocket(self):
......@@ -160,6 +162,7 @@ class ProtocolSimulaterService():
longitude = self.gpsLine[self.gpsLineIndex]["lng"]
# print("经度:" + str(longitude) + " 维度:" + str(latitude))
gpsMsg = self.genGPSMsg(latitude, longitude)
if self.fixPosition == 0: #是否固定当前位置的判断
if self.travelDirection == 0:
self.gpsLineIndex = self.gpsLineIndex + 1 #正向行驶
else:
......
......@@ -194,6 +194,7 @@
</span>
<span style="margin-left:10px;display: inline-block;"><button type="button" class="btn btn-primary" onclick="changeTravelDirection()">改变行驶方向</button></span>
<span style="margin-left:10px;display: inline-block;"><label>电瓶电压(v) :</label><input style="width:80px;margin-right:5px;" id="change_voltage" type="text" class="form-control" value="12"><button type="button" class="btn btn-primary" onclick="changeVoltage()">改变电瓶电压</button></span>
<span style="margin-left:10px;display: inline-block;"><button title="点击后,车机将会在当前位置发送gps和obd数据" type="button" class="btn btn-primary" onclick="fixCurPosition(this)">固定在当前位置</button></span>
</div>
</div>
</div>
......@@ -1051,7 +1052,6 @@ function storeMsg(){
}
});
}
}
//控制GPS是否有效
function changeGPSValid(e){
......@@ -1108,7 +1108,37 @@ function changeVoltage(){
url = "/protocolTools/M_carSimulater_process/changeValtage";
sendjson(data,url);
}
//控制是否固定在当前位置
function fixCurPosition(e){
var butTxt = $(e).text()
if(butTxt == "固定在当前位置"){
var data = {}
var carId = $("#carId").val()
data["carId"] = carId
data["fixPosition"] = 1
//会话session数据
data["session"] = {}
var sessionId = $("#curSession").val()
data["session"]["sessionId"] = sessionId
url = "/protocolTools/M_carSimulater_process/fixCurPosition";
var host = window.location.host;
sendjson(data,url);
$(e).text("取消固定在当前位置")
}else{
var data = {}
var carId = $("#carId").val()
data["carId"] = carId
data["fixPosition"] = 0
//会话session数据
data["session"] = {}
var sessionId = $("#curSession").val()
data["session"]["sessionId"] = sessionId
url = "/protocolTools/M_carSimulater_process/fixCurPosition";
var host = window.location.host;
sendjson(data,url);
$(e).text("取消固定在当前位置")
}
}
// -------------------------------- 其他操作js代码-------------------------------------------
//设置隐藏或显示其他操作区域
function isShowOtheroperCtrArea(e){
......
......@@ -1484,6 +1484,38 @@ def changeValtage():
data["message"] = "Error: 改变电瓶电压失败!"
return Response(json.dumps(data), mimetype='application/json')
##########################################
# 【接口类型】固定或者取消固定当前GPS点
##########################################
@M_carSimulater_process.route("/fixCurPosition",methods=['POST'])
def fixCurPosition():
params = request.get_data()
params = json.loads(params.decode("utf-8"))
sessionId = params["session"]["sessionId"]
fixPosition = params["fixPosition"]
data = {}
if not sessionId in connects.keys():
data["status"] = "4003"
data["message"] = "Error: 未启动服务,不可设置是否固定gps点!"
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: 汽车还未行驶,不可设置是否固定gps点!"
elif travelStatus == 1:
try:
service.setFixPosition(fixPosition)
data["status"] = "200"
data["message"] = "设置是否固定gps点成功!"
except BaseException as e:
# 打印异常信息
traceback.print_exc()
data["status"] = "4003"
data["message"] = "Error: 设置是否固定gps点失败!"
return Response(json.dumps(data), mimetype='application/json')
#--------------------------------------- 其他操作逻辑 ---------------------------------------
##########################################
# 【接口类型】处理发送的故障码报文
......
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