Commit 869ff14d authored by liyuanhong's avatar liyuanhong

M500 模拟器,增加了实时改变剩余油耗功能

parent 0939bd4a
{"time": {"dateTime": "2020-05-29 14:34:14", "date": "2020-05-29", "time": "14:34:14"}, "curDayTravel": {"todayTotalMilleage": 1469, "todayTotalOil": 134, "todayTotalTime": 89, "theMilleage": 307, "theOil": 22, "theTime": 19}, "travelData": {"totalMilleage": 343273, "totalOil": 32233, "totalTime": 20392}, "event": {"threeRapid": {"totalRapidlyAccelerate": 19, "totalSharpSlowdown": 18, "totalSharpTurn": 17}}}
\ No newline at end of file
{"time": {"dateTime": "2020-06-02 14:55:40", "date": "2020-06-02", "time": "14:55:40"}, "curDayTravel": {"todayTotalMilleage": 1174, "todayTotalOil": 109, "todayTotalTime": 71, "theMilleage": 1174, "theOil": 109, "theTime": 71}, "travelData": {"totalMilleage": 344447, "totalOil": 32342, "totalTime": 20463}, "event": {"threeRapid": {"totalRapidlyAccelerate": 19, "totalSharpSlowdown": 18, "totalSharpTurn": 17}}}
\ No newline at end of file
......@@ -98,5 +98,7 @@ class ResponseBase(Base):
if __name__ == "__main__":
# print(ResponseBase().int2binStr(7,2))
print(ResponseBase().getMsgId("7e0002000001314620111800065b7e"))
print(ResponseBase().getMsgId("7e80010005013146201118e1480006000200767e"))
\ No newline at end of file
# print(ResponseBase().getMsgId("7e0002000001314620111800065b7e"))
# print(ResponseBase().getMsgId("7e80010005013146201118e1480006000200767e"))
print(ResponseBase().hex2string("7975616e686f6e67"))
print(ResponseBase().hexString2int("00001f43 "))
\ No newline at end of file
......@@ -7,7 +7,7 @@ from lib.protocol.report.ProtocolBase import ProtocolBase
class TroubleReport_protocol(ProtocolBase):
def __init__(self,WATER_CODE = 26,DEV_ID = "M121501010001",infoTime="2020-01-20 11:55:58",troubleCount=1,byte0="02",byte1=2,byte2=3,byte3=1,MILStatus=1):
def __init__(self,WATER_CODE = 26,DEV_ID = "M121501010001",infoTime="2020-01-20 11:55:58",troubleCount=1,byte0="02",byte1=2,byte2=3,byte3=0,MILStatus=1):
super().__init__()
self.WATER_CODE = int(WATER_CODE); # 设置默认消息流水号
self.DEV_ID = DEV_ID # 设置默认设备id
......
......@@ -48,9 +48,9 @@ class ProtocolSimulaterService():
self.GPSValid = 1 #用来控制GPS数据是有效还是无效 0:无效 1:有效
self.lngLatIsOk = 1 #用来控制经纬度是否都为0 0:都为0 1:正常
# 定义要发送的obd数据
self.OBDdata = {"fireStatus":1,"ACCStatus":0,"engineSpeed":300,"speed":0,"meterMileage":6000,"totailMileage":600,"totalOilExpen":30,"totalRunTime":10}
self.OBDdata = {"fireStatus":1,"ACCStatus":0,"engineSpeed":300,"speed":0,"meterMileage":6000,"totailMileage":600,"totalOilExpen":30,"totalRunTime":10,"surplusOil":505}
# 定义初始的obd数据,与上面的OBD数据保持一致,主要用于汽车行驶过程中数据变化量的计算
self.OBDdataOri = {"fireStatus": 1, "ACCStatus": 0, "engineSpeed": 300, "speed": 0, "meterMileage": 6000,"totailMileage": 600, "totalOilExpen": 30, "totalRunTime": 10}
self.OBDdataOri = {"fireStatus": 1, "ACCStatus": 0, "engineSpeed": 300, "speed": 0, "meterMileage": 6000,"totailMileage": 600, "totalOilExpen": 30, "totalRunTime": 10,"surplusOil":50.5}
#设置套接字
def setSocket(self,data):
......@@ -78,6 +78,8 @@ class ProtocolSimulaterService():
self.data["travelData"]["carSpeed"] = data
def setOilExpend(self,data):
self.data["travelData"]["oilExpend"] = data
def setSurplusOil(self,data):
self.OBDdata["surplusOil"] = data
def setSendDur(self,data):
self.sendDur = int(data)
def setSendType(self,data):
......@@ -531,6 +533,7 @@ class ProtocolSimulaterService():
OBDObj.setTotalMileage(totailMileage) # 设置总里程值
OBDObj.setTotalOilExpend(totalOilExpend) # 设置总耗油量
OBDObj.setTotalRunTime(totalRunTime) # 设置车辆运行时间
OBDObj.setSurplusOil(self.OBDdata["surplusOil"]) # 设置剩余油量
msg = OBDObj.generateOBDReportCANMsg()
return msg
......
......@@ -162,10 +162,11 @@
</h5>
<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>
<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>
<span style="margin-left:10px;display: inline-block;"><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;display: inline-block;"><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;display: inline-block;"><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;display: inline-block;"><button title="点击后,将会把上报的消息存到本地,不上报消息;用来模拟车机无信号的情况" type="button" class="btn btn-primary" onclick="storeMsg()" id="storeMsgBut">存储上报消息</button><label style="color:red;" id="storeMsgLab">未存储...</label></span>
<span style="margin-left:10px;display: inline-block;"><label>剩余油量(%):</label><input style="width:80px;margin-right:5px;" id="change_surplusOil" type="text" class="form-control" value="50.5"><button type="button" class="btn btn-primary" onclick="changeSurplusOil()">改变剩余油量</button></span>
<span style="margin-top:10px;display:inline-block;border-width:1px;border-style:solid;border-color:darkgray;border-radius:10px;padding:1px 10px;margin-left:10px;">
<label><input name="GPSValie" value="1" type="radio" onclick="changeGPSValid(this)" checked="checked">GPS有效</label>
<label style="margin-left:10px;color:red;"><input name="GPSValie" value="0" type="radio" onclick="changeGPSValid(this)">GPS无效</label>
......@@ -825,6 +826,20 @@ function changeDurTime(){
url = "/protocolTools/M_carSimulater_process/changeDurTime";
sendjson(data,url);
}
//改变剩余油耗
function changeSurplusOil(){
var data = {}
var carId = $("#carId").val()
var surplusOil = parseInt(parseFloat($("#change_surplusOil").val()) * 10)
data["carId"] = carId
data["surplusOil"] = surplusOil
//会话session数据
data["session"] = {}
var sessionId = $("#curSession").val()
data["session"]["sessionId"] = sessionId
url = "/protocolTools/M_carSimulater_process/changeSurplusOil";
sendjson(data,url);
}
//控制发送数据是否保存到本地
function storeMsg(){
var butTxt = $("#storeMsgBut").text()
......
......@@ -1085,6 +1085,37 @@ def controlStoreMsg():
data["message"] = "Error: 控制是否存储消息到本地失败!"
return Response(json.dumps(data), mimetype='application/json')
##########################################
# 【接口类型】改变剩余油量
##########################################
@M_carSimulater_process.route("/changeSurplusOil",methods=['POST'])
def changeSurplusOil():
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.setSurplusOil(int(params["surplusOil"]))
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')
##########################################
# 【接口类型】控制GPS 是有效还是无效
##########################################
......
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