Commit d57114d3 authored by liyuanhong's avatar liyuanhong

模拟器行驶参数开发完成

parent d3f73f3a
{"name": "gpsLine", "GPSLine": [{"lng": "106.279711", "lat": "29.585448\n"}, {"lng": "106.279711", "lat": "29.585448\n"}, {"lng": "106.279711", "lat": "29.585448\n"}, {"lng": "106.279711", "lat": "29.585448\n"}, {"lng": "106.279711", "lat": "29.585448\n"}, {"lng": "106.279711", "lat": "29.585448\n"}, {"lng": "106.279711", "lat": "29.585448\n"}, {"lng": "106.279711", "lat": "29.585448\n"}, {"lng": "106.279711", "lat": "29.585448\n"}, {"lng": "106.279711", "lat": "29.585448\n"}, {"lng": "106.279711", "lat": "29.585448\n"}, {"lng": "106.287903", "lat": "29.586623\n"}, {"lng": "106.289041", "lat": "29.586608\n"}, {"lng": "106.293958", "lat": "29.586631\n"}, {"lng": "106.296643", "lat": "29.586603\n"}, {"lng": "106.29702", "lat": "29.586588\n"}, {"lng": "106.297076", "lat": "29.586625\n"}, {"lng": "106.297116", "lat": "29.586675\n"}, {"lng": "106.297148", "lat": "29.58674\n"}, {"lng": "106.297161", "lat": "29.586818\n"}, {"lng": "106.297168", "lat": "29.586906\n"}, {"lng": "106.297275", "lat": "29.58793\n"}, {"lng": "106.297461", "lat": "29.588408\n"}, {"lng": "106.297783", "lat": "29.588835\n"}, {"lng": "106.298863", "lat": "29.589848\n"}, {"lng": "106.299571", "lat": "29.59043\n"}, {"lng": "106.30007", "lat": "29.590666\n"}, {"lng": "106.300655", "lat": "29.59083\n"}, {"lng": "106.301408", "lat": "29.59091\n"}, {"lng": "106.301695", "lat": "29.590925\n"}, {"lng": "106.303111", "lat": "29.590928\n"}, {"lng": "106.30319", "lat": "29.590958\n"}, {"lng": "106.30325", "lat": "29.591001\n"}, {"lng": "106.303288", "lat": "29.59106\n"}, {"lng": "106.303306", "lat": "29.591125\n"}, {"lng": "106.303311", "lat": "29.591196\n"}, {"lng": "106.303321", "lat": "29.59202\n"}, {"lng": "106.303418", "lat": "29.594665\n"}, {"lng": "106.303493", "lat": "29.596323\n"}, {"lng": "106.30351", "lat": "29.597693\n"}]}
\ No newline at end of file
......@@ -20,6 +20,7 @@ from lib.socket.service.websocket_service import Websocket_service
class ProtocolSimulaterService():
def __init__(self):
self.data = {} #用来接收模拟器传过来的参数
self.socket = None
self.sendDur = 5 #设置默认多久发一条消息
self.serviceStatus = 0 #服务状态,0表示未启动,1表示启动
......@@ -30,9 +31,9 @@ class ProtocolSimulaterService():
self.travelStatus = 0 #0,表示为行驶,1表示开始行驶
self.carId = "" #车机号
self.sn = 0 #消息流水号
self.travelDirection = 0 #行驶方向,0表示正向行驶,1表示反向行驶
# 定义要发送的obd数据
self.OBDdata = {"fireStatus":1,"ACCStatus":0,"engineSpeed":300,"speed":0,"meterMileage":6000,"totailMileage":600,"totalOilExpen":30,"totalRunTime":10}
self.OBDdataIndex = 0 #发发送OBD数据的索引
#设置套接字
def setSocket(self,data):
......@@ -43,9 +44,12 @@ class ProtocolSimulaterService():
self.timeout = data
def setCarId(self,data):
self.carId = data
def setData(self,data):
self.data = data
def getWebsocket(self):
return self.websocket
def sendMsg(self,msg):
self.socket.setTimeOut(self.timeout)
self.socket.send(msg)
......@@ -60,7 +64,6 @@ class ProtocolSimulaterService():
def serviceSend(self):
while self.serviceStatus == 1:
# msg = "4040000b00034d1215010100010003f50b"
gpsMsg = ""
OBDMsg = ""
if self.travelStatus == 0:
......@@ -68,23 +71,53 @@ class ProtocolSimulaterService():
longitude = self.gpsLine[self.gpsLineIndex]["lng"]
gpsMsg = self.genGPSMsg(latitude,longitude)
elif self.travelStatus == 1:
if self.gpsLineIndex < len(self.gpsLine):
if self.gpsLineIndex < len(self.gpsLine) and self.gpsLineIndex != -1:
OBDMsg = self.genOBDMsg(self.OBDdata["fireStatus"],self.OBDdata["ACCStatus"],self.OBDdata["engineSpeed"], \
self.OBDdata["speed"],self.OBDdata["meterMileage"],self.OBDdata["totailMileage"], \
self.OBDdata["totalOilExpen"],self.OBDdata["totalRunTime"])
self.OBDdata["engineSpeed"] = 3000
self.OBDdata["speed"] = 60
self.OBDdata["speed"] = int(self.data["travelData"]["carSpeed"])
self.OBDdata["meterMileage"] = self.OBDdata["meterMileage"] + int(self.sendDur * (self.OBDdata["speed"] * 1000 / 3600))
self.OBDdata["totailMileage"] = self.OBDdata["totailMileage"] + int(self.sendDur * (self.OBDdata["speed"] * 1000 / 3600))
self.OBDdata["totalOilExpen"] = self.OBDdata["totalOilExpen"] + int((self.sendDur * (self.OBDdata["speed"] * 1000 / 3600)) * (1000 / (15 *1000)))
oilExpend = int(self.data["travelData"]["oilExpend"])
self.OBDdata["totalOilExpen"] = self.OBDdata["totalOilExpen"] + int((self.sendDur * (self.OBDdata["speed"] * 1000 / 3600)) * (1000 / (oilExpend *1000)))
self.OBDdata["totalRunTime"] = self.OBDdata["totalRunTime"] + self.sendDur
latitude = self.gpsLine[self.gpsLineIndex]["lat"]
longitude = self.gpsLine[self.gpsLineIndex]["lng"]
gpsMsg = self.genGPSMsg(latitude, longitude)
self.gpsLineIndex = self.gpsLineIndex + 1
elif self.gpsLineIndex == len(self.gpsLine):
self.stopTravel()
self.websocket.send("gps轨迹跑完,自动停止行驶!")
if self.travelDirection == 0:
self.gpsLineIndex = self.gpsLineIndex + 1 #正向行驶
else:
self.gpsLineIndex = self.gpsLineIndex - 1 #反向行驶
elif self.gpsLineIndex == len(self.gpsLine) or self.gpsLineIndex == -1:
if int(self.data["travelData"]["travelLoop"]) == 0:
self.stopTravel()
self.websocket.send("gps轨迹跑完,自动停止行驶!")
else:
if self.travelDirection == 0:
self.gpsLineIndex = self.gpsLineIndex - 1
self.travelDirection = 1
self.websocket.send("gps轨迹正向行驶跑完,变换行驶方向......")
else:
self.gpsLineIndex = self.gpsLineIndex + 1
self.travelDirection = 0
self.websocket.send("gps轨迹反向行驶跑完,变换行驶方向......")
OBDMsg = self.genOBDMsg(self.OBDdata["fireStatus"], self.OBDdata["ACCStatus"],self.OBDdata["engineSpeed"], \
self.OBDdata["speed"], self.OBDdata["meterMileage"],self.OBDdata["totailMileage"], \
self.OBDdata["totalOilExpen"], self.OBDdata["totalRunTime"])
self.OBDdata["engineSpeed"] = 3000
self.OBDdata["speed"] = int(self.data["travelData"]["carSpeed"])
self.OBDdata["meterMileage"] = self.OBDdata["meterMileage"] + int(
self.sendDur * (self.OBDdata["speed"] * 1000 / 3600))
self.OBDdata["totailMileage"] = self.OBDdata["totailMileage"] + int(
self.sendDur * (self.OBDdata["speed"] * 1000 / 3600))
oilExpend = int(self.data["travelData"]["oilExpend"])
self.OBDdata["totalOilExpen"] = self.OBDdata["totalOilExpen"] + int(
(self.sendDur * (self.OBDdata["speed"] * 1000 / 3600)) * (1000 / (oilExpend * 1000)))
self.OBDdata["totalRunTime"] = self.OBDdata["totalRunTime"] + self.sendDur
latitude = self.gpsLine[self.gpsLineIndex]["lat"]
longitude = self.gpsLine[self.gpsLineIndex]["lng"]
gpsMsg = self.genGPSMsg(latitude, longitude)
if OBDMsg != "":
self.sendMsg(OBDMsg)
self.sn = self.sn + 1
......
......@@ -20,8 +20,8 @@
<li><label>硬件版本:</label><input id="HWVersion" type="text" class="form-control" value="M1.0"></li>
<li><label>GSM 型号:</label><input id="GSMType" type="text" class="form-control" value="GSM_type_123456"></li>
<li><label>车系车型ID:</label><input id="carType" type="text" class="form-control" value="150D"></li>
<li><label style="word-break:break-all;font-size:12px;">发动机编码类别:</label><input id="engineCode" type="text" class="form-control" value="1"></li>
<li style="width:350px;"><label style="word-break:break-all;font-size:12px;">汽车VIN码或发动机ECU编码:</label><input style="width:250px;" id="VINCode" type="text" class="form-control" value="VIN_CODE_01234567890"></li>
<li><label style="word-break:break-all;font-size:10px;">发动机编码类别:</label><input id="engineCode" type="text" class="form-control" value="1"></li>
<li style="width:350px;"><label style="word-break:break-all;font-size:10px;">汽车VIN码或发动机ECU编码:</label><input style="width:250px;" id="VINCode" type="text" class="form-control" value="VIN_CODE_01234567890"></li>
</ul>
<H3 style="border-bottom: 1px solid #eee;">控制:</H3>
<div style="width:100%;padding:5px;margin-top:10px;">
......
......@@ -79,6 +79,14 @@
<!-- <div style="display: block;margin:10px; width: 95%; border-width: 1px; border-style: solid; border-color: darkgray; border-radius: 10px; padding: 2px; margin-top: 5px;">-->
<!-- </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;">
<h5><b>行驶参数设置:</b></h5>
<span><label>速度(Km/h):</label><input type="text" id="carSpeed" class="form-control" style="display:inline;width:80px;" value="60"/></span>
<span><label>油耗(Km/L):</label><input type="text" id="oilExpend" class="form-control" style="display:inline;width:80px;" value="10"/></span>
<span><label>是否循环行驶:</label><select style="width:80px;" id="travelLoop" class="form-control">
<option value="0"></option>
<option value="1"></option></select><label style="font-size:9px;width: 100px;">开启后会在所选择的轨迹上来回行驶</label></span>
</div>
<div style="width:100%;padding-bottom:10px;border-bottom: 1px solid #eee;">
<h3>操作:</h3>
<button id="connect_B" type="button" class="btn btn-primary" onclick="connect()">1、连网</button>
......@@ -98,33 +106,18 @@
</div>
</div>
<script>
//连接
function connect(){
//通过函数获取页面参数
function getPageData(){
var data = {};
var carId = $("#carId").val()
var WATER_CODE = $("#WATER_CODE").val()
var durTime = $("#durTime").val()
var timeout = $("#timeout").val()
data = {};
data["carId"] = carId
data["WATER_CODE"] = WATER_CODE
data["durTime"] = durTime
data["timeout"] = timeout
url = "/protocolTools/M_carSimulater_process/createConect";
send(data,url);
//setTimeout(function(){
// WebSocketTest()
//},1000); //1秒之后启动websocket连接
WebSocketTest()
$("#curStatus").val("连网")
}
//登录
function login(){
var data = {};
var carId = $("#carId").val()
var WATER_CODE = $("#WATER_CODE").val()
var durTime = $("#durTime").val()
//登录数据
data["login"] = {}
var cpuId = $("#cpuId").val()
......@@ -142,43 +135,50 @@ function login(){
var GSM = $("#GSM").val()
data["version"]["verInfo"] = verInfo
data["version"]["compileDate"] = compileDate
$("#curStatus").val("登录")
data["version"]["GSM"] = GSM
data["carId"] = carId
data["WATER_CODE"] = WATER_CODE
data["durTime"] = durTime
//GPS轨迹数据
var gpsLine = $("#selectGPSLine").val()
data["gpsLine"] = gpsLine
//行驶参数数据
data["travelData"] = {}
var carSpeed = $("#carSpeed").val()
var oilExpend = $("#oilExpend").val()
var travelLoop = $("#travelLoop").val()
data["travelData"]["carSpeed"] = carSpeed
data["travelData"]["oilExpend"] = oilExpend
data["travelData"]["travelLoop"] = travelLoop
return data;
}
//连接
function connect(){
var data = getPageData()
url = "/protocolTools/M_carSimulater_process/createConect";
sendjson(data,url);
//setTimeout(function(){
// WebSocketTest()
//},1000); //1秒之后启动websocket连接
WebSocketTest()
$("#curStatus").val("连网")
}
//登录
function login(){
var data = getPageData()
$("#curStatus").val("登录")
url = "/protocolTools/M_carSimulater_process/login";
sendjson(data,url);
}
//点火
function fire(){
var carId = $("#carId").val()
var WATER_CODE = $("#WATER_CODE").val()
var durTime = $("#durTime").val()
var gpsLine = $("#selectGPSLine").val()
var data = {};
data["carId"] = carId
data["WATER_CODE"] = WATER_CODE
data["durTime"] = durTime
data["gpsLine"] = gpsLine
var data = getPageData()
url = "/protocolTools/M_carSimulater_process/fire";
send(data,url);
sendjson(data,url);
$("#curStatus").val("点火")
}
//行驶
function startTravel(){
var carId = $("#carId").val()
var WATER_CODE = $("#WATER_CODE").val()
var durTime = $("#durTime").val()
var gpsLine = $("#selectGPSLine").val()
var data = {};
data["carId"] = carId
data["WATER_CODE"] = WATER_CODE
data["durTime"] = durTime
data["gpsLine"] = gpsLine
var data = getPageData()
url = "/protocolTools/M_carSimulater_process/startTravel";
send(data,url);
sendjson(data,url);
$("#curStatus").val("行驶")
}
//停止行驶
......@@ -190,17 +190,9 @@ function stopTravel(){
}
//熄火
function unFire(){
var carId = $("#carId").val()
var WATER_CODE = $("#WATER_CODE").val()
var durTime = $("#durTime").val()
var gpsLine = $("#selectGPSLine").val()
var data = {};
data["carId"] = carId
data["WATER_CODE"] = WATER_CODE
data["durTime"] = durTime
data["gpsLine"] = gpsLine
var data = getPageData()
url = "/protocolTools/M_carSimulater_process/unFire";
send(data,url);
sendjson(data,url);
$("#curStatus").val("熄火")
}
//断开连接
......
......@@ -52,7 +52,9 @@ def porcessSocketSetting():
##########################################
@M_carSimulater_process.route("/createConect",methods=['POST'])
def createConect():
timeout = int(request.form.get("timeout"))
params = request.get_data()
params = json.loads(params.decode("utf-8"))
timeout = int(params["timeout"])
data = {}
try:
conf_R = ConfigParser()
......@@ -69,6 +71,7 @@ def createConect():
service = ProtocolSimulaterService()
service.setSocket(cliSocket)
service.setTimeout(timeout)
service.setData(params)
service.setSocket(cliSocket)
service.startWebsocketService()
connects[0]["service"] = service
......@@ -118,9 +121,11 @@ def login():
##########################################
@M_carSimulater_process.route("/fire",methods=['POST'])
def fire():
durTime = int(request.form.get("durTime"))
gpsLine = request.form.get("gpsLine")
carId = request.form.get("carId")
params = request.get_data()
params = json.loads(params.decode("utf-8"))
durTime = int(params["durTime"])
gpsLine = params["gpsLine"]
carId = params["carId"]
data = {}
try:
service = connects[0]["service"]
......@@ -141,8 +146,10 @@ def fire():
##########################################
@M_carSimulater_process.route("/startTravel",methods=['POST'])
def startTravel():
durTime = int(request.form.get("durTime"))
gpsLine = request.form.get("gpsLine")
params = request.get_data()
params = json.loads(params.decode("utf-8"))
durTime = int(params["durTime"])
gpsLine = params["gpsLine"]
data = {}
try:
service = connects[0]["service"]
......@@ -182,8 +189,10 @@ def stopTravel():
##########################################
@M_carSimulater_process.route("/unFire",methods=['POST'])
def unFire():
gpsLine = request.form.get("gpsLine")
carId = request.form.get("carId")
params = request.get_data()
params = json.loads(params.decode("utf-8"))
gpsLine = params["gpsLine"]
carId = params["carId"]
data = {}
try:
connects[0]["service"].setGpsLine(gpsLine)
......
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