Commit 2a514be0 authored by liyuanhong's avatar liyuanhong

修改了OBD 报文多出几个数据的问题,以及增加了模拟器信号不好的场景控制

parent 5903a330
......@@ -123,7 +123,7 @@ class OBDReport_CAN_protocol(ProtocolBase):
#####################################################
def generateBD_CAN_Pkg(self, data):
pkgLen = len(data)
pkgNum = (pkgLen / 2) / 100
pkgNum = (pkgLen / 2) / 83
# print("------------------------" + str(pkgNum))
pkgNumHex = self.int2hexString(int(pkgNum))
pkg = pkgNumHex + data
......
......@@ -43,7 +43,7 @@ class ProtocolSimulaterService():
为0表示正常发送,type为1表示数据写入本地
# 用来控制发送消息的方式(是正常发送,还是将发送的数据保存到本地,不发送)
'''
self.sendType = 1
self.sendType = 0
# 定义要发送的obd数据
self.OBDdata = {"fireStatus":1,"ACCStatus":0,"engineSpeed":300,"speed":0,"meterMileage":6000,"totailMileage":600,"totalOilExpen":30,"totalRunTime":10}
# 定义初始的obd数据,与上面的OBD数据保持一致,主要用于汽车行驶过程中数据变化量的计算
......
......@@ -161,6 +161,7 @@
<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>
<span style="margin-left:10px;"><button title="点击后,将会把上报的消息存到本地,不上报消息;用来模拟车机无信号的情况" type="button" class="btn btn-primary" onclick="storeMsg()" id="storeMsgBut">存储上报消息</button><label style="color:red;" id="storeMsgLab">未存储...</label></span>
</div>
</div>
</div>
......@@ -795,6 +796,83 @@ function changeDurTime(){
url = "/protocolTools/M_carSimulater_process/changeDurTime";
sendjson(data,url);
}
//控制发送数据是否保存到本地
function storeMsg(){
var butTxt = $("#storeMsgBut").text()
if(butTxt == "存储上报消息"){
var data = {}
var carId = $("#carId").val()
data["carId"] = carId
data["sendType"] = 1
//会话session数据
data["session"] = {}
var sessionId = $("#curSession").val()
data["session"]["sessionId"] = sessionId
url = "/protocolTools/M_carSimulater_process/controlStoreMsg";
var host = window.location.host;
$.ajax({
//url:"http://" + host + "/protocolTools/M_carSimulater_process/porcessSocketSetting",
url:"http://" + host + url,
type:"post",
data:JSON.stringify(data),
contentType:"application/json",
dataType:"json",
success:function(data){
if(data.status == 200){
$("#storeMsgBut").text("取消存储上报消息")
$("#storeMsgLab").text("存储中...")
var curTime = getCurTime();
var txt = $("#showFeedback").val()
txt = txt + "[" + curTime + "] " + data.message + "\n"
$("#showFeedback").val(txt)
}else{
var curTime = getCurTime();
var txt = $("#showFeedback").val()
txt = txt + "[" + curTime + "] " + data.message + "\n"
$("#showFeedback").val(txt)
alert(data.message);
}
}
});
}else{
var data = {}
var carId = $("#carId").val()
data["carId"] = carId
data["sendType"] = 0
//会话session数据
data["session"] = {}
var sessionId = $("#curSession").val()
data["session"]["sessionId"] = sessionId
url = "/protocolTools/M_carSimulater_process/controlStoreMsg";
var host = window.location.host;
$.ajax({
//url:"http://" + host + "/protocolTools/M_carSimulater_process/porcessSocketSetting",
url:"http://" + host + url,
type:"post",
data:JSON.stringify(data),
contentType:"application/json",
dataType:"json",
success:function(data){
if(data.status == 200){
$("#storeMsgBut").text("存储上报消息")
$("#storeMsgLab").text("未存储...")
//window.location.reload()
var curTime = getCurTime();
var txt = $("#showFeedback").val()
txt = txt + "[" + curTime + "] " + data.message + "\n"
$("#showFeedback").val(txt)
}else{
var curTime = getCurTime();
var txt = $("#showFeedback").val()
txt = txt + "[" + curTime + "] " + data.message + "\n"
$("#showFeedback").val(txt)
alert(data.message);
}
}
});
}
}
</script>
{% endblock %}
</div>
......
......@@ -963,3 +963,30 @@ def changeDurTime():
data["status"] = "4003"
data["message"] = "Error: 改变发送间隔失败!"
return Response(json.dumps(data), mimetype='application/json')
##########################################
# 【接口类型】控制是否存储消息到本地
##########################################
@M_carSimulater_process.route("/controlStoreMsg",methods=['POST'])
def controlStoreMsg():
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:
sendType = int(params["sendType"])
service.setSendType(sendType)
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')
\ 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