Commit e1f21335 authored by liyuanhong's avatar liyuanhong

M500图形模拟器增加急左变道和急右变道功能

parent 997b7fc0
......@@ -197,7 +197,7 @@ class EventClass(ProtocolBase):
data = totalCount + dataProperty + extraInfo
return data
#16 碰撞报警前后10秒采样数据附带信息
#0023-ex 碰撞报警前后10秒采样数据附带信息
def collisionSamplingData(self):
GPSSampleData = self.GPSDataFromSeconds(10) #GPS 采样点 ,N秒内的GPS采样数据,170个字节
CANSampleData = self.CANDataFromSeconds(10) #CAN采样点 ,N秒内的CAN采样数据,90个字节
......@@ -267,7 +267,7 @@ class EventClass(ProtocolBase):
def SENSORDataFromSeconds(self,counts):
data = ""
for i in range(0,counts):
data += self.int2hexStringByBytes(30,2) #第N秒内的第N个0.5秒内的平均加速度值
data += self.int2hexStringByBytes(30,2) # 第N秒内的第N个0.5秒内的平均加速度值
return data
# 0027 超速报警
......@@ -284,6 +284,58 @@ class EventClass(ProtocolBase):
data = alarmTypeHex + durTimeHex
return data
# 002A 急变道报警
def rapidChangeLanes(self,nums=1,direction=1,lng=106.54041,lat=29.40268):
numHex = self.int2hexStringByBytes(nums,2) # 急变道总次数
directionHex = self.int2hexStringByBytes(direction) # 急变道方向
dataAttrHex = self.int2hexStringByBytes(1) # 数据属性
gpsesHex = self.getGpsSampleData002A(lng,lat)
temp1 = gpsesHex
for i in range(0,9):
gpsesHex = gpsesHex + temp1
CANesHex = self.getCanSampleData002A()
temp2 = CANesHex
for i in range(0,9):
CANesHex = CANesHex + temp2
sensorStatusHex = self.int2hexStringByBytes(2)
sensorDataHex = self.getSensorSampleData()
data = numHex + directionHex + dataAttrHex + gpsesHex + CANesHex + sensorStatusHex + sensorDataHex
return data
pass
# 002A -ex Gps采样数据项
def getGpsSampleData002A(self,lng=106.54041,lat=29.40268):
lngHex = self.int2hexStringByBytes(int(lng * 1000000),4)
latHex = self.int2hexStringByBytes(int(lat * 1000000),4)
speecHex = self.int2hexStringByBytes(60,2)
directionHex = self.int2hexStringByBytes(590,2)
altitudeHex = self.int2hexStringByBytes(10000,4)
statusHexBit = self.int2hexStringByBytes(1)
data = lngHex + latHex + speecHex + directionHex + altitudeHex + statusHexBit
return data
# 002A - ex CAN采样数据项
def getCanSampleData002A(self):
speedHex = self.int2hexStringByBytes(60)
engineSpeedHex = self.int2hexStringByBytes(3000,2)
brakeHex = self.int2hexStringByBytes(0)
acceleratorLocationHex = self.int2hexStringByBytes(50,2)
airDamperHex = self.int2hexStringByBytes(100,2)
troubleCodeNumHex = self.int2hexStringByBytes(0)
data = speedHex + engineSpeedHex + brakeHex + acceleratorLocationHex + airDamperHex + troubleCodeNumHex
return data
# 002A - ex sensor采样点
def getSensorSampleData(self):
xHex = self.int2hexStringByBytes(10,2)
yHex = self.int2hexStringByBytes(10, 2)
sensorHex = xHex + yHex
temp = sensorHex
for i in range(0,19):
sensorHex = sensorHex + temp
return sensorHex
# 0030 水温报警
def waterTemperatureAlarm(self,alarmType=0,curWaterTemperature=80):
alarmTypeHex = self.int2hexStringByBytes(alarmType)
......
......@@ -288,34 +288,41 @@ class EventReport_protocol(ProtocolBase):
int(eventData["0022"]["direction"]),
int(eventData["0022"]["dataProperty"]))
data = data + "0022" + self.int2hexStringByBytes(int((len(theData) / 2)), 2) + theData
if ("0023" in eventData.keys()): #碰撞告警
if ("0023" in eventData.keys()): # 碰撞告警
eventObj = EventClass()
theData = eventObj.collisionAlarmExtraInfo(int(eventData["0023"]["totalCount"]),
int(eventData["0023"]["dataProperty"]),)
data = data + "0023" + self.int2hexStringByBytes(int((len(theData) / 2)), 2) + theData
if ("0027" in eventData.keys()): #超速告警
if ("0027" in eventData.keys()): # 超速告警
eventObj = EventClass()
theData = eventObj.overSpeedAlarm(int(eventData["0027"]["alarmType"]),
int(eventData["0027"]["durationTime"]))
data = data + "0027" + self.int2hexStringByBytes(int((len(theData) / 2)), 2) + theData
if ("0028" in eventData.keys()): #疲劳驾驶告警
if ("0028" in eventData.keys()): # 疲劳驾驶告警
eventObj = EventClass()
theData = eventObj.tiredDrivingAlarm(int(eventData["0028"]["alarmType"]),
int(eventData["0028"]["durationTime"]),)
data = data + "0028" + self.int2hexStringByBytes(int((len(theData) / 2)), 2) + theData
if ("0032" in eventData.keys()): #怠速时间过长报警
if ("002A" in eventData.keys()): # 急变道告警
eventObj = EventClass()
theData = eventObj.rapidChangeLanes(int(eventData["002A"]["nums"]),
int(eventData["002A"]["direction"]),
float(eventData["002A"]["lng"]),
float(eventData["002A"]["lat"]))
data = data + "002A" + self.int2hexStringByBytes(int((len(theData) / 2)), 2) + theData
if ("0032" in eventData.keys()): # 怠速时间过长报警
eventObj = EventClass()
theData = eventObj.idlingOverTime(int(eventData["0032"]["alarmType"]),int(eventData["0032"]["durationTime"]),int(eventData["0032"]["oilExpend"]))
data = data + "0032" + self.int2hexStringByBytes(int((len(theData) / 2)), 2) + theData
if ("0036" in eventData.keys()): #低档高速报警
if ("0036" in eventData.keys()): # 低档高速报警
eventObj = EventClass()
theData = eventObj.lowGearHighSpeedAlarm(int(eventData["0036"]["alarmType"]),int(eventData["0036"]["durationTime"]))
data = data + "0036" + self.int2hexStringByBytes(int((len(theData) / 2)), 2) + theData
if ("0037" in eventData.keys()): #高档低速报警
if ("0037" in eventData.keys()): # 高档低速报警
eventObj = EventClass()
theData = eventObj.lowGearHighSpeedAlarm(int(eventData["0037"]["alarmType"]),int(eventData["0037"]["durationTime"]))
data = data + "0037" + self.int2hexStringByBytes(int((len(theData) / 2)), 2) + theData
if ("004A" in eventData.keys()): #高档低速报警
if ("004A" in eventData.keys()): # 高档低速报警
eventObj = EventClass()
theData = eventObj.surplusOilAlarm(int(eventData["004A"]["surplusOilType"]),int(eventData["004A"]["value"]))
data = data + "004A" + self.int2hexStringByBytes(int((len(theData) / 2)), 2) + theData
......
......@@ -116,6 +116,10 @@ class ProtocolSimulaterService():
return self.carData
def getTravelDirection(self):
return self.travelDirection
def getLatitude(self):
return self.gpsLine[self.gpsLineIndex]["lat"]
def getLongitude(self):
return self.gpsLine[self.gpsLineIndex]["lng"]
#######################################################
# type 为0表示正常发送,type为1表示数据写入本地
......
......@@ -18,7 +18,7 @@
<div class="top_nav">
<div style="background:#222222;height:50px;">
<a href="#" style="color: #eeeeee;font-size:18px;position: absolute;left: 10px;margin-top: 5px;text-decoration:none;"><img style="height:40px;" src="../../static/img/victory.png"><b>测试工具平台</b></a>
<a style="position: absolute;right: 20px;margin-top: 5px;" href="http://10.100.11.5/liyuanhong/new-socketemulator"><img style="height: 40px;" src="../../static/img/gitlab.png"></a>
<!-- <a style="position: absolute;right: 20px;margin-top: 5px;" href="http://10.100.11.5/liyuanhong/new-socketemulator"><img style="height: 40px;" src="../../static/img/gitlab.png"></a>-->
</div>
<div style="width: 70%;margin: 0 auto">
<ul class="nav nav-tabs" style="font-size:18px;">
......
......@@ -304,7 +304,7 @@
showDir:true,
strokeColor: "#28F", //线颜色
// strokeOpacity: 1, //线透明度
strokeWeight: 3, //线宽
strokeWeight: 5, //线宽
// strokeStyle: "solid" //线样式
});
$("#pointNums").text(lineLen);
......@@ -336,7 +336,7 @@
showDir:true,
strokeColor: "#28F", //线颜色
// strokeOpacity: 1, //线透明度
strokeWeight: 3, //线宽
strokeWeight: 5, //线宽
// strokeStyle: "solid" //线样式
});
......@@ -381,7 +381,7 @@
function showInputLine(){
var lineInputTxt = $("#lineData1").val();
var lineInputShowArr = [];
try{
try{ //json格式的gpsline
$.parseJSON(lineInputTxt);
lineInputShowArr = $.parseJSON(lineInputTxt)["GPSLine"];
var lineInputShowArr1 = []
......@@ -392,7 +392,7 @@
lineInputShowArr1.push(temp);
}
lineInputShowArr = lineInputShowArr1;
}catch(e){
}catch(e){ //非json格式的gpsline
var lineInputArr = lineInputTxt.split("\n");
for(var i = 0;i < lineInputArr.length;i++){
lineInputShowArr.push(lineInputArr[i].split(","));
......@@ -415,7 +415,7 @@
showDir:true,
strokeColor: "#28F", //线颜色
// strokeOpacity: 1, //线透明度
strokeWeight: 6, //线宽
strokeWeight: 5, //线宽
// strokeStyle: "solid" //线样式
});
map.setCenter(centerPoint);
......@@ -471,16 +471,29 @@
dataType:"json",
success:function(data){
if(data.status == 200){
var modGpsLines = data["gpsLines"];
var modGpsLines = data["GPSLine"];
if(showLineObj != undefined){
map.remove(showLineObj);
}
/**
for(var j = 0;j < modGpsLines.length;j++){
var cvtGps = coordtransform.wgs84togcj02(parseFloat(modGpsLines[j][0]), parseFloat(modGpsLines[j][1]));
cvtGps[0] = cvtGps[0].toFixed(6);
cvtGps[1] = cvtGps[1].toFixed(6);
modGpsLines[j] = cvtGps;
}
*/
var lineInputShowArr1 = []
for(var j = 0;j < modGpsLines.length;j++){
var temp = [];
temp[0] = parseFloat(modGpsLines[j]["lng"]);
temp[1] = parseFloat(modGpsLines[j]["lat"]);
var cvtGps = coordtransform.wgs84togcj02(temp[0], temp[1]);
temp[0] = cvtGps[0].toFixed(6);
temp[1] = cvtGps[1].toFixed(6);
lineInputShowArr1.push(temp);
}
modGpsLines = lineInputShowArr1;
var centerPoint = modGpsLines[parseInt(modGpsLines.length / 2)];
// 绘制轨迹
showLineObj = new AMap.Polyline({
......@@ -489,7 +502,7 @@
showDir:true,
strokeColor: "#28F", //线颜色
// strokeOpacity: 1, //线透明度
strokeWeight: 6, //线宽
strokeWeight: 5, //线宽
// strokeStyle: "solid" //线样式
});
map.setCenter(centerPoint);
......
......@@ -154,6 +154,8 @@
<label style="padding: 0px 10px;"><input type="checkbox" id="tiredDriving_check" onclick="eventSelect(this)" checked />疲劳驾驶 </label>
<label style="padding: 0px 10px;"><input type="checkbox" id="idlingOverTime_check" onclick="eventSelect(this)" checked />怠速过长 </label>
<label style="padding: 0px 10px;"><input type="checkbox" id="idlingOverTimeOver_check" onclick="eventSelect(this)" checked />怠速过长(解除) </label>
<label style="padding: 0px 10px;"><input type="checkbox" id="rapidChangeLeftLanes_check" onclick="eventSelect(this)" checked />急左变道 </label>
<label style="padding: 0px 10px;"><input type="checkbox" id="rapidChangeRightLanes_check" onclick="eventSelect(this)" checked />急右变道 </label>
</div>
<div style="padding:10px;">
<span id="insertAlarm_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendInsertAlarmEvent(this)">终端插入报警</button></label></span>
......@@ -173,6 +175,8 @@
<span id="tiredDriving_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendTiredDrivingAlarmEvent(this)">疲劳驾驶</button></label></span>
<span id="idlingOverTime_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendIdlingOverTimeEvent(this)" title="300秒,300毫升">怠速过长</button></label></span>
<span id="idlingOverTimeOver_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendIdlingOverTimeOverEvent(this)" title="500秒,500毫升">怠速过长(解除)</button></label></span>
<span id="rapidChangeLeftLanes_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendRapidChangeLeftLanesEvent(this)">急左变道</button></label></span>
<span id="rapidChangeRightLanes_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendRapidChangeRightLanesEvent(this)">急右变道</button></label></span>
</div>
</div>
</div>
......@@ -800,7 +804,12 @@ function eventSelect(e){
$("#idlingOverTime_button").css("display","inline")
}else if($(e).attr("id") == "idlingOverTimeOver_check"){
$("#idlingOverTimeOver_button").css("display","inline")
}else if($(e).attr("id") == "rapidChangeLeftLanes_check"){
$("#rapidChangeLeftLanes_button").css("display","inline")
}else if($(e).attr("id") == "rapidChangeRightLanes_check"){
$("#rapidChangeRightLanes_button").css("display","inline")
}
}else{
if($(e).attr("id") == "insertAlarm_check"){
$("#insertAlarm_button").css("display","none")
......@@ -836,6 +845,10 @@ function eventSelect(e){
$("#idlingOverTime_button").css("display","none")
}else if($(e).attr("id") == "idlingOverTimeOver_check"){
$("#idlingOverTimeOver_button").css("display","none")
}else if($(e).attr("id") == "rapidChangeLeftLanes_check"){
$("#rapidChangeLeftLanes_button").css("display","none")
}else if($(e).attr("id") == "rapidChangeRightLanes_check"){
$("#rapidChangeRightLanes_button").css("display","none")
}
}
}
......@@ -941,7 +954,18 @@ function sendIdlingOverTimeOverEvent(){
url = "/protocolTools/M_carSimulater_process/sendIdlingOverTimeOverEvent";
sendjson(data,url);
}
//急左变道告警
function sendRapidChangeLeftLanesEvent(){
var data = getPageData()
url = "/protocolTools/M_carSimulater_process/sendRapidChangeLeftLanes";
sendjson(data,url);
}
//急右变道告警
function sendRapidChangeRightLanesEvent(){
var data = getPageData()
url = "/protocolTools/M_carSimulater_process/sendRapidChangeRightLanes";
sendjson(data,url);
}
// -------------------------------- 实时控制js代码-------------------------------------------
//设置隐藏或显示实时控制区域
function isShowRealTimeCtrArea(e){
......
......@@ -63,14 +63,14 @@ def getGPSLineData():
content = fi.read()
conJson = json.loads(content)
gpsLines = conJson["GPSLine"]
theGpsLines = []
for item in gpsLines:
tem = []
tem.append(float(item["lng"].replace("\n","")))
tem.append(float(item["lat"].replace("\n","")))
theGpsLines.append(tem)
# theGpsLines = []
# for item in gpsLines:
# tem = []
# tem.append(float(item["lng"].replace("\n","")))
# tem.append(float(item["lat"].replace("\n","")))
data["status"] = "200"
data["gpsLines"] = theGpsLines
# data["gpsLines"] = theGpsLines
data["GPSLine"] = gpsLines
elif (type == 1):
with open("data/m300Tools/GPSLines/" + gpsLine, "r", encoding="utf-8") as fi:
content = fi.read()
......
......@@ -1268,6 +1268,105 @@ def sendIdlingOverTimeOverEvent():
data["message"] = "Error: 发送怠速解除告警事件失败!"
return Response(json.dumps(data), mimetype='application/json')
##########################################
# 【接口类型】发送急左变道报警
##########################################
@M_carSimulater_process.route("/sendRapidChangeLeftLanes",methods=['POST'])
def sendRapidChangeLeftLanes():
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": {
"002A": {"nums":1,"direction":1,"lng":106.54041,"lat":29.40268}}}
jdata["DEV_ID"] = params["carId"]
lng = service.getLongitude()
lat = service.getLatitude()
jdata["event"]["002A"]["lng"] = lng
jdata["event"]["002A"]["lat"] = lat
obj = EventReport_protocol(data=jdata)
obj.setEventType("002A")
msg = obj.generateEventMsg()
service.serviceSendMsg(msg, "急左变道告警事件")
service.setSn(service.getSn() + 1)
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("/sendRapidChangeRightLanes",methods=['POST'])
def sendRapidChangeRightLanes():
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": {
"002A": {"nums":1,"direction":0,"lng":106.54041,"lat":29.40268}}}
jdata["DEV_ID"] = params["carId"]
lng = service.getLongitude()
lat = service.getLatitude()
jdata["event"]["002A"]["lng"] = lng
jdata["event"]["002A"]["lat"] = lat
obj = EventReport_protocol(data=jdata)
obj.setEventType("002A")
msg = obj.generateEventMsg()
service.serviceSendMsg(msg, "急右变道告警事件")
service.setSn(service.getSn() + 1)
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')
#--------------------------------------- 实时控制逻辑 ---------------------------------------
##########################################
# 【接口类型】改变车速
......
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