Commit adbf5cc3 authored by liyuanhong's avatar liyuanhong

M500 模拟器更新了单向跑完,点击熄火失败的bug

parent c9fa1e49
...@@ -281,6 +281,7 @@ class MessageSimulaterService(): ...@@ -281,6 +281,7 @@ class MessageSimulaterService():
self.gpsLineIndex = self.gpsLineIndex - 1 # 反向行驶 self.gpsLineIndex = self.gpsLineIndex - 1 # 反向行驶
elif self.gpsLineIndex == len(self.gpsLine) or self.gpsLineIndex == -1: #如果反向行驶和反向行驶刚好跑完 elif self.gpsLineIndex == len(self.gpsLine) or self.gpsLineIndex == -1: #如果反向行驶和反向行驶刚好跑完
if int(self.data["travelData"]["travelLoop"]) == 0: #没有设置循环行驶 if int(self.data["travelData"]["travelLoop"]) == 0: #没有设置循环行驶
self.gpsLineIndex = self.gpsLineIndex - 1
self.stopTravel() self.stopTravel()
self.websocket.sendMsgToClient("gps轨迹跑完,自动停止行驶!",self.websocketId) self.websocket.sendMsgToClient("gps轨迹跑完,自动停止行驶!",self.websocketId)
else: #设置了循环行驶 else: #设置了循环行驶
......
...@@ -19,7 +19,7 @@ class ProtocolSimulaterDataService(): ...@@ -19,7 +19,7 @@ class ProtocolSimulaterDataService():
def setFileName(self,data): def setFileName(self,data):
self.fileName = data self.fileName = data
def setData(self,data): def setData(self,data):
self.data = data self.data = self.fixDataTemplate(data)
#################################################### ####################################################
# 生成一个默认数据模板 # 生成一个默认数据模板
...@@ -44,8 +44,27 @@ class ProtocolSimulaterDataService(): ...@@ -44,8 +44,27 @@ class ProtocolSimulaterDataService():
data["travelData"]["totalOil"] = 0 #行驶总油耗 data["travelData"]["totalOil"] = 0 #行驶总油耗
data["travelData"]["totalTime"] = 0 #行驶总时间 data["travelData"]["totalTime"] = 0 #行驶总时间
data["event"] = {} data["event"] = {}
data["event"]["threeRapid"] = {} #急加速,急减速,急转弯基本数据
data["event"]["threeRapid"]["totalRapidlyAccelerate"] = 0 #急加速总次数
data["event"]["threeRapid"]["totalSharpSlowdown"] = 0 #急减速总次数
data["event"]["threeRapid"]["totalSharpTurn"] = 0 #急转弯总次数
return data
####################################################
# 修复默认数据模板
# 用于在升级模拟器的时候,对增加的字段进行初始化
####################################################
def fixDataTemplate(self,data):
if not "event" in data:
data["event"] = {}
data["event"]["threeRapid"] = {}
data["event"]["threeRapid"]["totalRapidlyAccelerate"] = 0 # 急加速总次数
data["event"]["threeRapid"]["totalSharpSlowdown"] = 0 # 急减速总次数
data["event"]["threeRapid"]["totalSharpTurn"] = 0 # 急转弯总次数
if not "threeRapid" in data["event"]:
data["event"]["threeRapid"] = {}
data["event"]["threeRapid"]["totalRapidlyAccelerate"] = 0 #急加速总次数
data["event"]["threeRapid"]["totalSharpSlowdown"] = 0 #急减速总次数
data["event"]["threeRapid"]["totalSharpTurn"] = 0 #急转弯总次数
return data return data
#设今日行驶总里程,同时写入文件 #设今日行驶总里程,同时写入文件
...@@ -87,6 +106,31 @@ class ProtocolSimulaterDataService(): ...@@ -87,6 +106,31 @@ class ProtocolSimulaterDataService():
self.data["travelData"]["totalTime"] = data self.data["travelData"]["totalTime"] = data
self.writeToFile(self.path + self.fileName,self.data) self.writeToFile(self.path + self.fileName,self.data)
#设置急加速总次数,同时写入文件
def setTotalRapidlyAccelerateCount(self,data):
if not "event" in data:
data["event"] = {}
if not "threeRapid" in data["event"]:
data["event"]["threeRapid"] = {}
data["event"]["threeRapid"]["totalRapidlyAccelerate"] = data
self.writeToFile(self.path + self.fileName, self.data)
# 设置急减速总次数,同时写入文件
def setTotalSharpSlowdown(self,data):
if not "event" in data:
data["event"] = {}
if not "threeRapid" in data["event"]:
data["event"]["threeRapid"] = {}
data["event"]["threeRapid"]["totalSharpSlowdown"] = data
self.writeToFile(self.path + self.fileName, self.data)
# 设置急转弯总次数,同时写入文件
def setTotalSharpTurn(self,data):
if not "event" in data:
data["event"] = {}
if not "threeRapid" in data["event"]:
data["event"]["threeRapid"] = {}
data["event"]["threeRapid"]["totalSharpTurn"] = data
self.writeToFile(self.path + self.fileName, self.data)
#设今日日期时间 #设今日日期时间
def setDateTime2file(self,data): def setDateTime2file(self,data):
self.data["time"]["dateTime"] = data self.data["time"]["dateTime"] = data
...@@ -100,6 +144,12 @@ class ProtocolSimulaterDataService(): ...@@ -100,6 +144,12 @@ class ProtocolSimulaterDataService():
self.data["time"]["time"] = data self.data["time"]["time"] = data
self.writeToFile(self.path + self.fileName,self.data) self.writeToFile(self.path + self.fileName,self.data)
####################################################
# 将数据持久化到已经设定好的文件
####################################################
def setData2file(self):
self.writeToFile(self.path + self.fileName,self.data)
#################################################### ####################################################
# 将数据写入文件 # 将数据写入文件
...@@ -136,6 +186,7 @@ class ProtocolSimulaterDataService(): ...@@ -136,6 +186,7 @@ class ProtocolSimulaterDataService():
self.setDateTime2file(dateTimeM) self.setDateTime2file(dateTimeM)
self.setData2file(dateM) self.setData2file(dateM)
self.setTime2file(timeM) self.setTime2file(timeM)
conJson = self.fixDataTemplate(conJson) #每次读取,都会对数据进行修复
self.data = conJson self.data = conJson
......
...@@ -60,6 +60,10 @@ class ProtocolSimulaterService(): ...@@ -60,6 +60,10 @@ class ProtocolSimulaterService():
self.websocketId = self.websocket.getCurrentClientId() self.websocketId = self.websocket.getCurrentClientId()
def setWebsocket(self,data): def setWebsocket(self,data):
self.websocket = data self.websocket = data
def setSn(self,data):
self.sn = data
def setCarData(self,data):
self.carData = data
def getWebsocket(self): def getWebsocket(self):
...@@ -70,6 +74,10 @@ class ProtocolSimulaterService(): ...@@ -70,6 +74,10 @@ class ProtocolSimulaterService():
return self.gpsLine return self.gpsLine
def getTravelStatus(self): def getTravelStatus(self):
return self.travelStatus return self.travelStatus
def getSn(self):
return self.sn
def getCarData(self):
return self.carData
def sendMsg(self,msg): def sendMsg(self,msg):
...@@ -106,6 +114,7 @@ class ProtocolSimulaterService(): ...@@ -106,6 +114,7 @@ class ProtocolSimulaterService():
self.OBDdata["totalRunTime"] = self.OBDdata["totalRunTime"] + self.sendDur self.OBDdata["totalRunTime"] = self.OBDdata["totalRunTime"] + self.sendDur
latitude = self.gpsLine[self.gpsLineIndex]["lat"] latitude = self.gpsLine[self.gpsLineIndex]["lat"]
longitude = self.gpsLine[self.gpsLineIndex]["lng"] longitude = self.gpsLine[self.gpsLineIndex]["lng"]
# print("经度:" + str(longitude) + " 维度:" + str(latitude))
gpsMsg = self.genGPSMsg(latitude, longitude) gpsMsg = self.genGPSMsg(latitude, longitude)
if self.travelDirection == 0: if self.travelDirection == 0:
self.gpsLineIndex = self.gpsLineIndex + 1 #正向行驶 self.gpsLineIndex = self.gpsLineIndex + 1 #正向行驶
...@@ -113,6 +122,7 @@ class ProtocolSimulaterService(): ...@@ -113,6 +122,7 @@ class ProtocolSimulaterService():
self.gpsLineIndex = self.gpsLineIndex - 1 #反向行驶 self.gpsLineIndex = self.gpsLineIndex - 1 #反向行驶
elif self.gpsLineIndex == len(self.gpsLine) or self.gpsLineIndex == -1: #如果反向行驶和反向行驶刚好跑完 elif self.gpsLineIndex == len(self.gpsLine) or self.gpsLineIndex == -1: #如果反向行驶和反向行驶刚好跑完
if int(self.data["travelData"]["travelLoop"]) == 0: #没有设置循环行驶 if int(self.data["travelData"]["travelLoop"]) == 0: #没有设置循环行驶
self.gpsLineIndex = self.gpsLineIndex - 1
self.stopTravel() self.stopTravel()
self.websocket.sendMsgToClient("gps轨迹跑完,自动停止行驶!",self.websocketId) self.websocket.sendMsgToClient("gps轨迹跑完,自动停止行驶!",self.websocketId)
else: #设置了循环行驶 else: #设置了循环行驶
...@@ -316,7 +326,7 @@ class ProtocolSimulaterService(): ...@@ -316,7 +326,7 @@ class ProtocolSimulaterService():
self.OBDdataOri["totalOilExpen"] = conJson["travelData"]["totalOil"] self.OBDdataOri["totalOilExpen"] = conJson["travelData"]["totalOil"]
self.OBDdata["totalRunTime"] = conJson["travelData"]["totalTime"] self.OBDdata["totalRunTime"] = conJson["travelData"]["totalTime"]
self.OBDdataOri["totalRunTime"] = conJson["travelData"]["totalTime"] self.OBDdataOri["totalRunTime"] = conJson["travelData"]["totalTime"]
self.carData = conJson self.carData = self.carDataObj.fixDataTemplate(conJson)
fireOnEventObj = EventReport_protocol(DEV_ID=self.carId,WATER_CODE=self.sn) fireOnEventObj = EventReport_protocol(DEV_ID=self.carId,WATER_CODE=self.sn)
gpsData = self.genGPSData(self.gpsLine[0]["lat"], self.gpsLine[0]["lng"]) gpsData = self.genGPSData(self.gpsLine[0]["lat"], self.gpsLine[0]["lng"])
fireOnEventObj.setGPSPkg(gpsData) fireOnEventObj.setGPSPkg(gpsData)
...@@ -387,6 +397,19 @@ class ProtocolSimulaterService(): ...@@ -387,6 +397,19 @@ class ProtocolSimulaterService():
gpsObj.setGPSTimestamp(timeS) gpsObj.setGPSTimestamp(timeS)
data = gpsObj.generateGpsData() data = gpsObj.generateGpsData()
return data return data
#根据当前所在GPS点,生成GPS消息体,不包含消息头
def genGPSData2(self):
gpsObj = GPSReport_protocol(DEV_ID=self.carId,WATER_CODE=self.sn)
gpsObj.setLatitude(self.gpsLine[self.gpsLineIndex]["lat"])
gpsObj.setLongitude(self.gpsLine[self.gpsLineIndex]["lng"])
gpsObj.setDirectionAngle(self.getDirAngle())
timeS = int(time.time()) - 8 * 3600
timeArray = time.localtime(timeS)
UTCTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
gpsObj.setUTCTime(UTCTime)
gpsObj.setGPSTimestamp(timeS)
data = gpsObj.generateGpsData()
return data
# 根据特定参数,生成OBD CAN消息 # 根据特定参数,生成OBD CAN消息
def genOBDMsg(self,fireStatus=1,ACCStatus=0,engineSpeed=300,speed=0,meterMileage=6000, \ def genOBDMsg(self,fireStatus=1,ACCStatus=0,engineSpeed=300,speed=0,meterMileage=6000, \
......
...@@ -115,43 +115,44 @@ ...@@ -115,43 +115,44 @@
<span style="margin-left:20px;"><label>当前状态:</label><input id="curStatus" value="断网" disabled="disabled" class="form-control" style="font-weight: bold;width:85px;color:red;border-width: 1px; border-style: solid; border-color: darkgray; border-radius: 10px;"></span> <span style="margin-left:20px;"><label>当前状态:</label><input id="curStatus" value="断网" disabled="disabled" class="form-control" style="font-weight: bold;width:85px;color:red;border-width: 1px; border-style: solid; border-color: darkgray; border-radius: 10px;"></span>
<span style="width:80px;padding-left:10px;"><label style="width:70px"><input type="checkbox" id="ignition" onclick="isLogShow(this)"/>隐藏日志</label> </span> <span style="width:80px;padding-left:10px;"><label style="width:70px"><input type="checkbox" id="ignition" onclick="isLogShow(this)"/>隐藏日志</label> </span>
</div> </div>
<!-- <div style="display: block; width: 100%; border-width: 1px; border-style: solid; border-color: darkgray; border-radius: 10px; padding: 2px; margin-top: 5px;">--> <div style="display: block; width: 100%; border-width: 1px; border-style: solid; border-color: darkgray; border-radius: 10px; padding: 2px; margin-top: 5px;">
<!-- <h5><b>事件发送:</b>--> <h5><b>事件发送:</b>
<!-- <span style="border-width:1px;border-style:solid;border-color:darkgray;border-radius:10px;padding:1px 10px;">--> <span style="border-width:1px;border-style:solid;border-color:darkgray;border-radius:10px;padding:1px 10px;">
<!-- <label><input name="eventshow" type="radio" value="0" checked="checked" onclick="isShowEventArea(this)"/>隐藏</label>--> <label><input name="eventshow" type="radio" value="0" checked="checked" onclick="isShowEventArea(this)"/>隐藏</label>
<!-- <label style="margin-left:10px;"><input name="eventshow" type="radio" value="1" onclick="isShowEventArea(this)"/>显示</label>--> <label style="margin-left:10px;"><input name="eventshow" type="radio" value="1" onclick="isShowEventArea(this)"/>显示</label>
<!-- </span>--> </span>
<!-- </h5>--> </h5>
<!-- <div id="event_area" style="display:none;">--> <div id="event_area" style="display:none;">
<!-- <div style="margin-top:10px;width:100%;border-width:1px;border-style:solid;border-color:darkgray;border-radius:10px;padding:2px;background:skyblue;">--> <div style="margin-top:10px;width:100%;border-width:1px;border-style:solid;border-color:darkgray;border-radius:10px;padding:2px;background:skyblue;">
<!-- <label style="padding: 0px 10px;"><input type="checkbox" id="rapidlyAccelerateEvent_check" onclick="eventSelect(this)"/>急加速 </label>--> <label style="padding: 0px 10px;"><input type="checkbox" id="rapidlyAccelerateEvent_check" onclick="eventSelect(this)"/>急加速 </label>
<!-- <label style="padding: 0px 10px;"><input type="checkbox" id="bbb" onclick="eventSelect(this)"/>急减速 </label>--> <label style="padding: 0px 10px;"><input type="checkbox" id="sharpSlowdownEvent_check" onclick="eventSelect(this)"/>急减速 </label>
<!-- <label style="padding: 0px 10px;"><input type="checkbox" id="ccc" onclick="eventSelect(this)"/>急转弯 </label>--> <label style="padding: 0px 10px;"><input type="checkbox" id="sharpTurnEvent_check" onclick="eventSelect(this)"/>急转弯 </label>
<!-- <label style="padding: 0px 10px;"><input type="checkbox" id="0003" onclick="eventSelect(this)"/>汽车电瓶低电压报警 </label>--> <label style="padding: 0px 10px;"><input type="checkbox" id="0003" onclick="eventSelect(this)"/>汽车电瓶低电压报警 </label>
<!-- <label style="padding: 0px 10px;"><input type="checkbox" id="0004" onclick="eventSelect(this)"/>终端主电断电报警 </label>--> <label style="padding: 0px 10px;"><input type="checkbox" id="0004" onclick="eventSelect(this)"/>终端主电断电报警 </label>
<!-- <label style="padding: 0px 10px;"><input type="checkbox" id="0012" onclick="eventSelect(this)"/>设防 </label>--> <label style="padding: 0px 10px;"><input type="checkbox" id="0012" onclick="eventSelect(this)"/>设防 </label>
<!-- <label style="padding: 0px 10px;"><input type="checkbox" id="0013" onclick="eventSelect(this)"/>撤防 </label>--> <label style="padding: 0px 10px;"><input type="checkbox" id="0013" onclick="eventSelect(this)"/>撤防 </label>
<!-- <label style="padding: 0px 10px;"><input type="checkbox" id="0036" onclick="eventSelect(this)"/>低档高速报警 </label>--> <label style="padding: 0px 10px;"><input type="checkbox" id="0036" onclick="eventSelect(this)"/>低档高速报警 </label>
<!-- <label style="padding: 0px 10px;"><input type="checkbox" id="0037" onclick="eventSelect(this)"/>高档低速报警 </label>--> <label style="padding: 0px 10px;"><input type="checkbox" id="0037" onclick="eventSelect(this)"/>高档低速报警 </label>
<!-- <label style="padding: 0px 10px;"><input type="checkbox" id="004A" onclick="eventSelect(this)"/>剩余油量异常告警 </label>--> <label style="padding: 0px 10px;"><input type="checkbox" id="004A" onclick="eventSelect(this)"/>剩余油量异常告警 </label>
<!-- </div>--> </div>
<!-- <div style="padding:10px;">--> <div style="padding:10px;">
<!-- <span id="rapidlyAccelerateEvent_button" style="display:none;"><button id="a" type="button" class="btn btn-primary" onclick="sendRapidlyAccelerateEvent(this)">急加速</button></label></span>--> <span id="rapidlyAccelerateEvent_button" style="display:none;"><button type="button" class="btn btn-primary" onclick="sendRapidlyAccelerateEvent(this)">急加速</button></label></span>
<!-- <span><label>在线人数:</label><input disabled=disabled type="text" id="b" class="form-control" style="display:inline;width:80px;" value="1"/></span>--> <span id="sharpSlowdownEvent_button" style="display:none;"><button type="button" class="btn btn-primary" onclick="sendSharpSlowdownEvent(this)">急减速</button></label></span>
<!-- </div>--> <span id="sharpTurnEvent_button" style="display:none;"><button type="button" class="btn btn-primary" onclick="sendSharpTurnEvent(this)">急转弯</button></label></span>
<!-- </div>--> </div>
<!-- </div>--> </div>
<!-- <div style="display: block; width: 100%; border-width: 1px; border-style: solid; border-color: darkgray; border-radius: 10px; padding: 2px; margin-top: 5px;">--> </div>
<!-- <h5><b>实时控制:</b>--> <div style="display: block; width: 100%; border-width: 1px; border-style: solid; border-color: darkgray; border-radius: 10px; padding: 2px; margin-top: 5px;">
<!-- <span style="border-width:1px;border-style:solid;border-color:darkgray;border-radius:10px;padding:1px 10px;">--> <h5><b>实时控制:</b>
<!-- <label><input name="realtime" type="radio" value="0" checked="checked" onclick="isShowRealTimeCtrArea(this)"/>隐藏</label>--> <span style="border-width:1px;border-style:solid;border-color:darkgray;border-radius:10px;padding:1px 10px;">
<!-- <label style="margin-left:10px;"><input name="realtime" type="radio" value="1" onclick="isShowRealTimeCtrArea(this)"/>显示</label>--> <label><input name="realtime" type="radio" value="0" checked="checked" onclick="isShowRealTimeCtrArea(this)"/>隐藏</label>
<!-- </span>--> <label style="margin-left:10px;"><input name="realtime" type="radio" value="1" onclick="isShowRealTimeCtrArea(this)"/>显示</label>
<!-- </h5>--> </span>
<!-- <div id="realTimeCtl_area" style="display:none;">--> </h5>
<!-- 实时控制--> <div id="realTimeCtl_area" style="display:none;">
<!-- </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;">
<h3>日志:</h3> <h3>日志:</h3>
<textarea id="showFeedback" style="width:100%;padding:5px;padding-bottom:60px;" rows="10"></textarea> <textarea id="showFeedback" style="width:100%;padding:5px;padding-bottom:60px;" rows="10"></textarea>
...@@ -633,10 +634,18 @@ function eventSelect(e){ ...@@ -633,10 +634,18 @@ function eventSelect(e){
if($(e).is(':checked')){ if($(e).is(':checked')){
if($(e).attr("id") == "rapidlyAccelerateEvent_check"){ if($(e).attr("id") == "rapidlyAccelerateEvent_check"){
$("#rapidlyAccelerateEvent_button").css("display","inline") $("#rapidlyAccelerateEvent_button").css("display","inline")
}else if($(e).attr("id") == "sharpSlowdownEvent_check"){
$("#sharpSlowdownEvent_button").css("display","inline")
}else if($(e).attr("id") == "sharpTurnEvent_check"){
$("#sharpTurnEvent_button").css("display","inline")
} }
}else{ }else{
if($(e).attr("id") == "rapidlyAccelerateEvent_check"){ if($(e).attr("id") == "rapidlyAccelerateEvent_check"){
$("#rapidlyAccelerateEvent_button").css("display","none") $("#rapidlyAccelerateEvent_button").css("display","none")
}else if($(e).attr("id") == "sharpSlowdownEvent_check"){
$("#sharpSlowdownEvent_button").css("display","none")
}else if($(e).attr("id") == "sharpTurnEvent_check"){
$("#sharpTurnEvent_button").css("display","none")
} }
} }
} }
...@@ -646,7 +655,18 @@ function sendRapidlyAccelerateEvent(){ ...@@ -646,7 +655,18 @@ function sendRapidlyAccelerateEvent(){
url = "/protocolTools/M_carSimulater_process/sendRapidlyAccelerateEvent"; url = "/protocolTools/M_carSimulater_process/sendRapidlyAccelerateEvent";
sendjson(data,url); sendjson(data,url);
} }
//发送急减速事件消息
function sendSharpSlowdownEvent(){
var data = getPageData()
url = "/protocolTools/M_carSimulater_process/sendSharpSlowdownEvent";
sendjson(data,url);
}
//发送急转弯事件消息
function sendSharpTurnEvent(){
var data = getPageData()
url = "/protocolTools/M_carSimulater_process/sendSharpTurnEvent";
sendjson(data,url);
}
</script> </script>
{% endblock %} {% endblock %}
......
...@@ -399,6 +399,7 @@ ...@@ -399,6 +399,7 @@
//发送电瓶采样数据包 //发送电瓶采样数据包
$("#sendMsgBtn").click(function(){ $("#sendMsgBtn").click(function(){
var data = getData(); var data = getData();
//console.log(JSON.stringify(data))
var host = window.location.host; var host = window.location.host;
$("#showFeedback").val(""); $("#showFeedback").val("");
$.ajax({ $.ajax({
......
...@@ -113,11 +113,13 @@ def login(): ...@@ -113,11 +113,13 @@ def login():
params["login"]["imsi"],params["login"]["ccid"],params["login"]["imei"]) params["login"]["imsi"],params["login"]["ccid"],params["login"]["imei"])
loginMsg = loginObj.generateLoginMsg() loginMsg = loginObj.generateLoginMsg()
service.serviceSendMsg(loginMsg,"登录") service.serviceSendMsg(loginMsg,"登录")
service.setSn(service.getSn() +1)
sleep(0.2) sleep(0.2)
versionObj = VersionReport_protocol(1,params["WATER_CODE"],params["carId"],params["version"]["verInfo"], \ versionObj = VersionReport_protocol(1,params["WATER_CODE"],params["carId"],params["version"]["verInfo"], \
params["version"]["compileDate"],params["version"]["GSM"]) params["version"]["compileDate"],params["version"]["GSM"])
versionMsg = versionObj.generateVersionMsg() versionMsg = versionObj.generateVersionMsg()
service.serviceSendMsg(versionMsg,"版本") service.serviceSendMsg(versionMsg,"版本")
service.setSn(service.getSn() + 1)
data["status"] = "200" data["status"] = "200"
data["message"] = "登录成功!" data["message"] = "登录成功!"
except BaseException as e: except BaseException as e:
...@@ -253,7 +255,6 @@ def closeConect(): ...@@ -253,7 +255,6 @@ def closeConect():
traceback.print_exc() traceback.print_exc()
data["status"] = "4003" data["status"] = "4003"
data["message"] = "Error: 关闭连接失败!" data["message"] = "Error: 关闭连接失败!"
print(connects)
return Response(json.dumps(data), mimetype='application/json') return Response(json.dumps(data), mimetype='application/json')
########################################## ##########################################
...@@ -384,6 +385,9 @@ def getConnects(): ...@@ -384,6 +385,9 @@ def getConnects():
return Response(json.dumps(data), mimetype='application/json') return Response(json.dumps(data), mimetype='application/json')
#--------------------------------------- 发送事件逻辑 --------------------------------------- #--------------------------------------- 发送事件逻辑 ---------------------------------------
##########################################
# 【接口类型】发送急加速事件
##########################################
@M_carSimulater_process.route("/sendRapidlyAccelerateEvent",methods=['POST']) @M_carSimulater_process.route("/sendRapidlyAccelerateEvent",methods=['POST'])
def sendRapidlyAccelerateEvent(): def sendRapidlyAccelerateEvent():
params = request.get_data() params = request.get_data()
...@@ -400,10 +404,32 @@ def sendRapidlyAccelerateEvent(): ...@@ -400,10 +404,32 @@ def sendRapidlyAccelerateEvent():
if travelStatus == 0 or travelStatus == 2: if travelStatus == 0 or travelStatus == 2:
data["status"] = "4003" data["status"] = "4003"
data["message"] = "Error: 汽车还未行驶,不可发送急加速事件!" data["message"] = "Error: 汽车还未行驶,不可发送急加速事件!"
elif travelStatus == 2: elif travelStatus == 1:
try: try:
obj = EventReport_protocol() jdata = {"WATER_CODE": "0003", "DEV_ID": "M121501010001",
"gpsInfo": {"UTCTime": "2020-04-30 14:59:33", "latitude": "40.22077", "longitude": "116.23128",
"speed": "80.8", "directionAngle": "80.8", "elevation": "2999.9", "positionStar": "3",
"Pdop": "0.3", "Hdop": "0.4", "Vdop": "0.5", "statusBit": 162, "valtage": "36.9",
"OBDSpeed": "60.9", "engineSpeed": "3000", "GPSTotalMileage": "12800", "totalOil": "100000",
"totalTime": "2020002", "GPSTimestamp": "1588229973"},
"securityData": {"securityStatus": 107, "doorStatus": 0, "lockStatus": 0, "windowStatus": 0,
"lightStatus": 0, "onoffStatusA": 0, "onoffStatusB": 112, "dataByte": 249}, "event": {
"0020": {"allRapidlyAccelerateCount": "5", "allSharpSlowdownCount": "6", "allSharpTurn": "4",
"dataProperty": "1"}}}
carData = service.getCarData()
jdata["event"]["0020"]["allRapidlyAccelerateCount"] = carData["event"]["threeRapid"]["totalRapidlyAccelerate"]
jdata["event"]["0020"]["allSharpSlowdownCount"] = carData["event"]["threeRapid"]["totalSharpSlowdown"]
jdata["event"]["0020"]["allSharpTurn"] = carData["event"]["threeRapid"]["totalSharpTurn"]
jdata["DEV_ID"] = params["carId"]
obj = EventReport_protocol(data=jdata)
gpsData = service.genGPSData2()
obj.setGPSPkg(gpsData)
obj.setEventType("0020")
msg = obj.generateEventMsg() msg = obj.generateEventMsg()
service.serviceSendMsg(msg, "急加速事件")
service.setSn(service.getSn() + 1)
carData["event"]["threeRapid"]["totalRapidlyAccelerate"] = carData["event"]["threeRapid"]["totalRapidlyAccelerate"] + 1
service.setCarData(carData)
data["status"] = "200" data["status"] = "200"
data["message"] = "发送急加速事件成功!" data["message"] = "发送急加速事件成功!"
except BaseException as e: except BaseException as e:
...@@ -412,3 +438,111 @@ def sendRapidlyAccelerateEvent(): ...@@ -412,3 +438,111 @@ def sendRapidlyAccelerateEvent():
data["status"] = "4003" data["status"] = "4003"
data["message"] = "Error: 发送急加速事件失败!" data["message"] = "Error: 发送急加速事件失败!"
return Response(json.dumps(data), mimetype='application/json') return Response(json.dumps(data), mimetype='application/json')
##########################################
# 【接口类型】发送急减速事件
##########################################
@M_carSimulater_process.route("/sendSharpSlowdownEvent",methods=['POST'])
def sendSharpSlowdownEvent():
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:
jdata = {"WATER_CODE": "0003", "DEV_ID": "M121501010001",
"gpsInfo": {"UTCTime": "2020-04-30 14:59:33", "latitude": "40.22077", "longitude": "116.23128",
"speed": "80.8", "directionAngle": "80.8", "elevation": "2999.9", "positionStar": "3",
"Pdop": "0.3", "Hdop": "0.4", "Vdop": "0.5", "statusBit": 162, "valtage": "36.9",
"OBDSpeed": "60.9", "engineSpeed": "3000", "GPSTotalMileage": "12800", "totalOil": "100000",
"totalTime": "2020002", "GPSTimestamp": "1588229973"},
"securityData": {"securityStatus": 107, "doorStatus": 0, "lockStatus": 0, "windowStatus": 0,
"lightStatus": 0, "onoffStatusA": 0, "onoffStatusB": 112, "dataByte": 249}, "event": {
"0021": {"allRapidlyAccelerateCount": "5", "allSharpSlowdownCount": "6", "allSharpTurn": "4",
"dataProperty": "1"}}}
carData = service.getCarData()
jdata["event"]["0021"]["allRapidlyAccelerateCount"] = carData["event"]["threeRapid"]["totalRapidlyAccelerate"]
jdata["event"]["0021"]["allSharpSlowdownCount"] = carData["event"]["threeRapid"]["totalSharpSlowdown"]
jdata["event"]["0021"]["allSharpTurn"] = carData["event"]["threeRapid"]["totalSharpTurn"]
jdata["DEV_ID"] = params["carId"]
obj = EventReport_protocol(data=jdata)
gpsData = service.genGPSData2()
obj.setGPSPkg(gpsData)
obj.setEventType("0020")
msg = obj.generateEventMsg()
service.serviceSendMsg(msg, "急减速事件")
service.setSn(service.getSn() + 1)
carData["event"]["threeRapid"]["allSharpSlowdownCount"] = carData["event"]["threeRapid"]["totalSharpSlowdown"] + 1
service.setCarData(carData)
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("/sendSharpTurnEvent",methods=['POST'])
def sendSharpTurnEvent():
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:
jdata = {"WATER_CODE": "0003", "DEV_ID": "M121501010001",
"gpsInfo": {"UTCTime": "2020-04-30 14:59:33", "latitude": "40.22077", "longitude": "116.23128",
"speed": "80.8", "directionAngle": "80.8", "elevation": "2999.9", "positionStar": "3",
"Pdop": "0.3", "Hdop": "0.4", "Vdop": "0.5", "statusBit": 162, "valtage": "36.9",
"OBDSpeed": "60.9", "engineSpeed": "3000", "GPSTotalMileage": "12800", "totalOil": "100000",
"totalTime": "2020002", "GPSTimestamp": "1588229973"},
"securityData": {"securityStatus": 107, "doorStatus": 0, "lockStatus": 0, "windowStatus": 0,
"lightStatus": 0, "onoffStatusA": 0, "onoffStatusB": 112, "dataByte": 249}, "event": {
"0022": {"allRapidlyAccelerateCount": "5", "allSharpSlowdownCount": "6", "allSharpTurn": "4",
"direction":"0","dataProperty": "1"}}}
carData = service.getCarData()
jdata["event"]["0022"]["allRapidlyAccelerateCount"] = carData["event"]["threeRapid"]["totalRapidlyAccelerate"]
jdata["event"]["0022"]["allSharpSlowdownCount"] = carData["event"]["threeRapid"]["totalSharpSlowdown"]
jdata["event"]["0022"]["allSharpTurn"] = carData["event"]["threeRapid"]["totalSharpTurn"]
jdata["DEV_ID"] = params["carId"]
obj = EventReport_protocol(data=jdata)
gpsData = service.genGPSData2()
obj.setGPSPkg(gpsData)
obj.setEventType("0020")
msg = obj.generateEventMsg()
service.serviceSendMsg(msg, "急转弯事件")
service.setSn(service.getSn() + 1)
carData["event"]["threeRapid"]["allSharpTurn"] = carData["event"]["threeRapid"]["totalSharpTurn"] + 1
service.setCarData(carData)
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