Commit d698737c authored by liyuanhong's avatar liyuanhong

M300模拟器完成3急事件开发

parent bb1cc051
{"time": {"dateTime": "2020-06-04 16:47:12", "date": "2020-06-04", "time": "16:47:12"}, "curDayTravel": {"todayTotalMilleage": 664, "todayTotalOil": 64, "todayTotalTime": 40, "theMilleage": 664, "theOil": 64, "theTime": 40}, "travelData": {"totalMilleage": 830, "totalOil": 80, "totalTime": 50}}
\ No newline at end of file
{"time": {"dateTime": "2020-06-05 11:21:47", "date": "2020-06-05", "time": "11:21:47"}, "curDayTravel": {"todayTotalMilleage": 4095, "todayTotalOil": 330, "todayTotalTime": 251, "theMilleage": 1088, "theOil": 68, "theTime": 68}, "travelData": {"totalMilleage": 4925, "totalOil": 410, "totalTime": 301}, "event": {"threeRapid": {"totalRapidlyAccelerate": 5, "totalSharpSlowdown": 2, "totalSharpTurn": 0}}}
\ No newline at end of file
#encoding:utf-8
from lib.protocol.m300.GPS_protocol_m300 import GPS_protocol_m300
from lib.protocol.m300.M300Base import M300Base
'''
定义驾驶行为协议类
'''
class TravelAct_protocol_m300(M300Base):
def __init__(self,waterCode = 3,DEV_ID = "M121501010001",encryptionType=0,actType=1,accelerateTotalTimes=2, \
decelerateTotalTimes=2,sharpTurnTotalTimes=2,acceleration=500,speed=60,gps={}):
super().__init__() # 不执行该方法,无法使用父类里面定义的属性
self.waterCode = waterCode # 消息流水号
self.DEV_ID = DEV_ID # 设备Id
self.encryptionType = encryptionType # 消息属性里面的是否加密字段
if len(gps) == 0:
self.GPSPkg = "14031b0e22160265b86206ed8c7002029402290000006e00016802988100000000000000"
else:
gpsObj = GPS_protocol_m300(3,"M121501010001",0,gps["dateInfo"],float(gps["latitude"]),float(gps["longitude"]),int(gps["positionStar"]),float(gps["speed"]), \
float(gps["direction"]),float(gps["altitude"]),int(gps["ACCStatus"]),float(gps["valtage"]),float(gps["OBDSpeed"]), \
int(gps["valid"]),int(gps["tripMark"]))
self.GPSPkg = gpsObj.getMsgBody()
self.actType = actType # 驾驶行为类别
self.accelerateTotalTimes = accelerateTotalTimes # 急加速总次数
self.decelerateTotalTimes = decelerateTotalTimes # 急减速总次数
self.sharpTurnTotalTimes = sharpTurnTotalTimes # 急转弯总次数
self.acceleration = acceleration # 事件发生时,加速度值
self.speed = speed # 事件发生时,车速度
self.tripMark = "0000" # 驾驶循环标签
#################################################
# 生成消息
#################################################
def generateMsg(self):
msg = self.IDENTIFY
FUNID = "0022" #功能id
waterCode = self.int2hexStringByBytes(self.waterCode,2) #消息流水号
DEV_ID = self.devid2hexString(self.DEV_ID) #设备id
msgBody = self.getMsgBody() # 消息体
msgLen = int(len(msgBody) / 2)
property = self.getMsgProperty(msgBodyLen=msgLen,encryptionType=self.encryptionType)
checkCode = self.getCheckCode(FUNID + waterCode + DEV_ID + property + msgBody)
msg = msg + FUNID + waterCode + DEV_ID + property + msgBody + checkCode + self.IDENTIFY
return msg
#################################################
# 获取消息体
#################################################
def getMsgBody(self):
gps = self.GPSPkg
actType = self.int2hexStringByBytes(self.actType)
accelerateTotalTimes = self.int2hexStringByBytes(self.accelerateTotalTimes,4)
decelerateTotalTimes = self.int2hexStringByBytes(self.decelerateTotalTimes,4)
sharpTurnTotalTimes = self.int2hexStringByBytes(self.sharpTurnTotalTimes,4)
acceleration = self.int2hexStringByBytes(self.acceleration,2)
speed = self.int2hexStringByBytes(self.speed)
tripMark = self.tripMark
data = gps + actType + accelerateTotalTimes + decelerateTotalTimes + sharpTurnTotalTimes
data = data + acceleration + speed + tripMark
return data
......@@ -6,6 +6,7 @@ from lib.protocol.m300.Alarm_protocol_m300 import Alarm_protocol_m300
from lib.protocol.m300.GPS_protocol_m300 import GPS_protocol_m300
from lib.protocol.m300.Heartbeat_protocol_300 import Heartbeat_protocol_300
from lib.protocol.m300.OBDCAN_protocol_m300 import OBDCAN_protocol_m300
from lib.protocol.m300.TravelAct_protocol_m300 import TravelAct_protocol_m300
from lib.protocol.m300.VersionInfo_protocol_m300 import VersionInfo_protocol_m300
from lib.protocol.report.GPSReport_protocol import GPSReport_protocol
from lib.protocol.report.OBDReport_CAN_protocol import OBDReport_CAN_protocol
......@@ -34,7 +35,8 @@ port = 9009
# msg = VersionInfo_protocol_m300().generateMsg() #终端版本报文
# msg = "7e000400e14d2019120315000000957e" #终端上报心跳协议
# msg = OBDCAN_protocol_m300().generateMsg() #OBD CAN报文
msg = Alarm_protocol_m300().generateMsg() #OBD CAN报文
# msg = Alarm_protocol_m300().generateMsg() #报警报文
msg = TravelAct_protocol_m300().generateMsg() #驾驶行为报文
print(msg)
......
......@@ -43,6 +43,28 @@ class M300SimulaterDataService():
data["travelData"]["totalMilleage"] = 0 #行驶总里程
data["travelData"]["totalOil"] = 0 #行驶总油耗
data["travelData"]["totalTime"] = 0 #行驶总时间
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
#设今日行驶总里程,同时写入文件
......@@ -84,6 +106,31 @@ class M300SimulaterDataService():
self.data["travelData"]["totalTime"] = 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):
self.data["time"]["dateTime"] = data
......
......@@ -61,6 +61,10 @@ class M300SimulaterService():
return self.gpsLine[self.gpsLineIndex]["lat"]
def getCurLongtitude(self):
return self.gpsLine[self.gpsLineIndex]["lng"]
def getCarData(self):
return self.carData
def getSpeed(self):
return int(self.data["travelData"]["carSpeed"])
#设置套接字
......@@ -74,6 +78,8 @@ class M300SimulaterService():
self.carId = data
def setData(self,data):
self.data = data
def setCarData(self,data):
self.carData = data
def setWebsocketId(self):
sleep(0.1)
self.websocketId = self.websocket.getCurrentClientId()
......@@ -169,7 +175,8 @@ class M300SimulaterService():
self.OBDdataOri["totalOil"] = conJson["travelData"]["totalOil"]
self.OBDdata["carTotalRunTime"] = conJson["travelData"]["totalTime"]
self.OBDdataOri["carTotalRunTime"] = conJson["travelData"]["totalTime"]
self.carData = conJson
self.carData = self.carDataObj.fixDataTemplate(conJson)
# self.carData = conJson
############################# 发送点火数据 ############################
fireOnParams = {"FUNID": "0021", "waterCode": "1", "DEV_ID": "M202004070000", "encryptionType": "0",
......
......@@ -20,6 +20,8 @@ function m300ProtocolManTab(e){
$(location).attr('href', "http://" + window.location.host + "/m300Tools/P_m300Protocol_view/P_CAN_m300_page");
}else if(id == "P_alarm_m300_msg"){
$(location).attr('href', "http://" + window.location.host + "/m300Tools/P_m300Protocol_view/P_alarm_m300_page");
}else if(id == "P_travelAct_m300_msg"){
$(location).attr('href', "http://" + window.location.host + "/m300Tools/P_m300Protocol_view/P_travelAct_m300_page");
}else{
alert(id)
}
......
......@@ -107,44 +107,26 @@
<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>
</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>-->
<!-- <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 style="margin-left:10px;"><input name="eventshow" type="radio" value="1" onclick="isShowEventArea(this)"/>显示</label>-->
<!-- </span>-->
<!-- </h5>-->
<!-- <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;">-->
<!-- <label style="padding: 0px 10px;"><input type="checkbox" id="insertAlarm_check" onclick="eventSelect(this)" checked />终端插入报警 </label>-->
<!-- <label style="padding: 0px 10px;"><input type="checkbox" id="lowVoltage_check" onclick="eventSelect(this)" checked />汽车电瓶低电压报警 </label>-->
<!-- <label style="padding: 0px 10px;"><input type="checkbox" id="powerOff_check" onclick="eventSelect(this)" checked />终端主电断电报警 </label>-->
<!-- <label style="padding: 0px 10px;"><input type="checkbox" id="rapidlyAccelerateEvent_check" onclick="eventSelect(this)" checked />急加速 </label>-->
<!-- <label style="padding: 0px 10px;"><input type="checkbox" id="sharpSlowdownEvent_check" onclick="eventSelect(this)" checked />急减速 </label>-->
<!-- <label style="padding: 0px 10px;"><input type="checkbox" id="sharpTurnEvent_check" onclick="eventSelect(this)" checked />急转弯 </label>-->
<!-- <label style="padding: 0px 10px;"><input type="checkbox" id="collisionAlarmEvent_check" onclick="eventSelect(this)" checked />碰撞报警 </label>-->
<!-- <label style="padding: 0px 10px;"><input type="checkbox" id="setUpDefencesEvent_check" onclick="eventSelect(this)" checked />设防 </label>-->
<!-- <label style="padding: 0px 10px;"><input type="checkbox" id="setDownDefencesEvent_check" onclick="eventSelect(this)" checked />撤防 </label>-->
<!-- <label style="padding: 0px 10px;"><input type="checkbox" id="lowGearHighSpeed_check" onclick="eventSelect(this)" checked />低档高速报警 </label>-->
<!-- <label style="padding: 0px 10px;"><input type="checkbox" id="highGearLowSpeed_check" onclick="eventSelect(this)" checked />高档低速报警 </label>-->
<!-- <label style="padding: 0px 10px;"><input type="checkbox" id="surplusOil_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>-->
<!-- <span id="lowVoltage_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendLowVoltageEvent(this)">汽车电瓶低电压报警</button></label></span>-->
<!-- <span id="powerOff_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendPowerOffEvent(this)">终端主电断电报警</button></label></span>-->
<!-- <span id="rapidlyAccelerateEvent_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendRapidlyAccelerateEvent(this)">急加速</button></label></span>-->
<!-- <span id="sharpSlowdownEvent_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendSharpSlowdownEvent(this)">急减速</button></label></span>-->
<!-- <span id="sharpTurnEvent_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendSharpTurnEvent(this)">急转弯</button></label></span>-->
<!-- <span id="collisionAlarmEvent_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendCollisionAlarmEvent(this)">碰撞报警</button></label></span>-->
<!-- <span id="setUpDefencesEvent_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendSetUpDefencesEvent(this)">设防</button></label></span>-->
<!-- <span id="setDownDefencesEvent_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendSetDownDefencesEvent(this)">撤防</button></label></span>-->
<!-- <span id="lowGearHighSpeed_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendLowGearHighSpeedEvent(this)">低挡高速</button></label></span>-->
<!-- <span id="highGearLowSpeed_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendHighGearLowSpeedEvent(this)">高档低速</button></label></span>-->
<!-- <span id="surplusOil_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendSurplusOilAlarmEvent(this)">剩余油量异常</button></label></span>-->
<!-- </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;">
<h5><b>事件发送:</b>
<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 style="margin-left:10px;"><input name="eventshow" type="radio" value="1" onclick="isShowEventArea(this)"/>显示</label>
</span>
</h5>
<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;">
<label style="padding: 0px 10px;"><input type="checkbox" id="rapidlyAccelerateEvent_check" onclick="eventSelect(this)" checked />急加速 </label>
<label style="padding: 0px 10px;"><input type="checkbox" id="sharpSlowdownEvent_check" onclick="eventSelect(this)" checked />急减速 </label>
<label style="padding: 0px 10px;"><input type="checkbox" id="sharpTurnEvent_check" onclick="eventSelect(this)" checked />急转弯 </label>
</div>
<div style="padding:10px;">
<span id="rapidlyAccelerateEvent_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendRapidlyAccelerateEvent(this)">急加速</button></label></span>
<span id="sharpSlowdownEvent_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendSharpSlowdownEvent(this)">急减速</button></label></span>
<span id="sharpTurnEvent_button" style="display:inline;"><button type="button" class="btn btn-primary" onclick="sendSharpTurnEvent(this)">急转弯</button></label></span>
</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;">
<h5><b>实时控制:</b>
<span style="border-width:1px;border-style:solid;border-color:darkgray;border-radius:10px;padding:1px 10px;">
......@@ -642,132 +624,42 @@ function isShowEventArea(e){
//事件的选择与取消选择
function eventSelect(e){
if($(e).is(':checked')){
if($(e).attr("id") == "insertAlarm_check"){
$("#insertAlarm_button").css("display","inline")
}else if($(e).attr("id") == "lowVoltage_check"){
$("#lowVoltage_button").css("display","inline")
}else if($(e).attr("id") == "powerOff_check"){
$("#powerOff_button").css("display","inline")
}else if($(e).attr("id") == "rapidlyAccelerateEvent_check"){
if($(e).attr("id") == "rapidlyAccelerateEvent_check"){
$("#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 if($(e).attr("id") == "collisionAlarmEvent_check"){
$("#collisionAlarmEvent_button").css("display","inline")
}else if($(e).attr("id") == "setUpDefencesEvent_check"){
$("#setUpDefencesEvent_button").css("display","inline")
}else if($(e).attr("id") == "setDownDefencesEvent_check"){
$("#setDownDefencesEvent_button").css("display","inline")
}else if($(e).attr("id") == "lowGearHighSpeed_check"){
$("#lowGearHighSpeed_button").css("display","inline")
}else if($(e).attr("id") == "highGearLowSpeed_check"){
$("#highGearLowSpeed_button").css("display","inline")
}else if($(e).attr("id") == "surplusOil_check"){
$("#surplusOil_button").css("display","inline")
}
}else{
if($(e).attr("id") == "insertAlarm_check"){
$("#insertAlarm_button").css("display","none")
}else if($(e).attr("id") == "lowVoltage_check"){
$("#lowVoltage_button").css("display","none")
}else if($(e).attr("id") == "powerOff_check"){
$("#powerOff_button").css("display","none")
}else if($(e).attr("id") == "rapidlyAccelerateEvent_check"){
if($(e).attr("id") == "rapidlyAccelerateEvent_check"){
$("#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")
}else if($(e).attr("id") == "collisionAlarmEvent_check"){
$("#collisionAlarmEvent_button").css("display","none")
}else if($(e).attr("id") == "setUpDefencesEvent_check"){
$("#setUpDefencesEvent_button").css("display","none")
}else if($(e).attr("id") == "setDownDefencesEvent_check"){
$("#setDownDefencesEvent_button").css("display","none")
}else if($(e).attr("id") == "lowGearHighSpeed_check"){
$("#lowGearHighSpeed_button").css("display","none")
}else if($(e).attr("id") == "highGearLowSpeed_check"){
$("#highGearLowSpeed_button").css("display","none")
}else if($(e).attr("id") == "surplusOil_check"){
$("#surplusOil_button").css("display","none")
}
}
}
//发送终端插入报警
function sendInsertAlarmEvent(){
var data = getPageData()
url = "/protocolTools/M_carSimulater_process/sendInsertAlarmEvent";
sendjson(data,url);
}
//发送汽车电瓶低电压报警
function sendLowVoltageEvent(){
var data = getPageData()
url = "/protocolTools/M_carSimulater_process/sendLowVoltageEvent";
sendjson(data,url);
}
//发送汽车电瓶低电压报警
function sendPowerOffEvent(){
var data = getPageData()
url = "/protocolTools/M_carSimulater_process/sendPowerOffEvent";
sendjson(data,url);
}
}
}
//发送急加速事件消息
function sendRapidlyAccelerateEvent(){
var data = getPageData()
url = "/protocolTools/M_carSimulater_process/sendRapidlyAccelerateEvent";
url = "/m300Tools/M_m300Simulater_process/sendAccelerateEvent",
sendjson(data,url);
}
//发送急减速事件消息
function sendSharpSlowdownEvent(){
var data = getPageData()
url = "/protocolTools/M_carSimulater_process/sendSharpSlowdownEvent";
url = "/m300Tools/M_m300Simulater_process/sendDecelerateEvent",
sendjson(data,url);
}
//发送急转弯事件消息
function sendSharpTurnEvent(){
var data = getPageData()
url = "/protocolTools/M_carSimulater_process/sendSharpTurnEvent";
url = "/m300Tools/M_m300Simulater_process/sendSharpTurnEvent",
sendjson(data,url);
}
//发送碰撞告警事件
function sendCollisionAlarmEvent(){
var data = getPageData()
url = "/protocolTools/M_carSimulater_process/sendCollisionAlarmEvent";
sendjson(data,url);
}
//发送设防事件消息
function sendSetUpDefencesEvent(){
var data = getPageData()
url = "/protocolTools/M_carSimulater_process/sendSetUpDefencesEvent";
sendjson(data,url);
}
//发送撤防事件消息
function sendSetDownDefencesEvent(){
var data = getPageData()
url = "/protocolTools/M_carSimulater_process/sendSetDownDefencesEvent";
sendjson(data,url);
}
//发送低档高速报警事件消息
function sendLowGearHighSpeedEvent(){
var data = getPageData()
url = "/protocolTools/M_carSimulater_process/sendLowGearHighSpeedEvent";
sendjson(data,url);
}
//发送高档低速报警事件消息
function sendHighGearLowSpeedEvent(){
var data = getPageData()
url = "/protocolTools/M_carSimulater_process/sendHighGearLowSpeedEvent";
sendjson(data,url);
}
//发送剩余油量异常告警事件消息
function sendSurplusOilAlarmEvent(){
var data = getPageData()
url = "/protocolTools/M_carSimulater_process/sendSurplusOilAlarmEvent";
sendjson(data,url);
}
// -------------------------------- 实时控制js代码-------------------------------------------
//改变车速
function changeSpeed(){
......
......@@ -40,6 +40,7 @@
<li role="presentation"><a id="P_GPS_m300_msg" {% if arg.path[2]=="P_GPS_m300_page" %} class="link-tab" {% endif %} onclick="m300ProtocolManTab(this)">GPS消息</b></a></li>
<li role="presentation"><a id="P_CAN_m300_msg" {% if arg.path[2]=="P_CAN_m300_page" %} class="link-tab" {% endif %} onclick="m300ProtocolManTab(this)">CAN消息</b></a></li>
<li role="presentation"><a id="P_alarm_m300_msg" {% if arg.path[2]=="P_alarm_m300_page" %} class="link-tab" {% endif %} onclick="m300ProtocolManTab(this)">报警消息</b></a></li>
<li role="presentation"><a id="P_travelAct_m300_msg" {% if arg.path[2]=="P_travelAct_m300_page" %} class="link-tab" {% endif %} onclick="m300ProtocolManTab(this)">驾驶行为消息</b></a></li>
</ul>
{% endblock %}
{% block content_1 %}
......
{% extends "m300Tools/report/P_heartBeat_m300_page.html" %}
{% block title %}travelAct_msg{% endblock %}
{% block content_1 %}
<div id="container3" style="width:100%;min-height:750px;float:left;_background:green;margin-top:10px;_border-top: 1px solid #eee;">
<div style="width:100%;_background:green;padding:5px;padding-top:0px;">
<h3 style="border-bottom: 1px solid #eee;">设置消息头:</h3>
<label>功能ID:</label><input id="FUNID" type="text" class="form-control" disabled="disabled" value="0007" style="width:80px;">
<label>消息序列号:</label><input id="waterCode" type="text" class="form-control" value="1" style="width:60px;">
<label>设备ID:</label><input id="DEV_ID" type="text" class="form-control" value="M202004070000" style="width:150px;">
<label>是否加密:</label><select style="width:100px;" id="encryptionType" class="form-control">
<option value="0">不加密</option>
<option value="1024">加密</option>
</select>
</div>
<H3 style="border-bottom: 1px solid #eee;">设置驾驶行为消息内容:</H3>
<div style="width:100%;border-width:1px;border-style:solid;border-color:darkgray;border-radius:10px;padding:2px;">
<h5>GPS报警信息<span style="margin-left:10px;border-width:1px;border-style:solid;border-color:darkgray;border-radius:10px;padding:1px 10px;">
<label><input name="gps_radio" type="radio" value="0" checked="checked" onclick="isShowGPS_area(this)"/>隐藏</label>
<label style="margin-left:10px;"><input name="gps_radio" type="radio" value="1" onclick="isShowGPS_area(this)"/>显示</label>
</span></h5>
<ul class="protocol_content" style="padding:0px;display:none;" id="GPS_area">
<li><label>日期:</label><input id="dateInfo" type="text" class="form-control" value=""></li>
<li style="width:495px;"><label>维度:</label><span>
<input id="latitude" type="text" class="form-control" value="40.22077">
<select style="width:80px;" id="latitudeType" class="form-control">
<option value="0">北纬</option>
<option value="1">南纬</option></select>
</span></li>
<li style="width:495px;"><label>经度:</label><span>
<input id="longitude" type="text" class="form-control" value="116.23128">
<select style="width:80px;" id="longitudeType" class="form-control">
<option value="0">东经</option>
<option value="1">西经</option></select>
</span></li>
<li><label>定位星数:</label><input id="positionStar" type="text" class="form-control" value="2"></li>
<li><label>速度:</label><input id="speed" type="text" class="form-control" value="66.0"></li>
<li><label>方向角:</label><input id="direction" type="text" class="form-control" value="55.3"></li>
<li><label>海拔高度:</label><input id="altitude" type="text" class="form-control" value="11.0"></li>
<li><label>ACC状态:</label><select style="width:155px;" id="ACCStatus" class="form-control">
<option value="0"></option>
<option value="1" selected="selected"></option></select></li>
<li><label style="word-break:break-all;font-size:10px;">汽车电瓶电压:</label><input id="valtage" type="text" class="form-control" value="36.0"></li>
<li><label style="word-break:break-all;font-size:10px;">汽车OBD速度:</label><input id="OBDSpeed" type="text" class="form-control" value="66.4"></li>
<li><label style="word-break:break-all;font-size:10px;">GPS定位是否有效:</label><select style="width:155px;" id="valid_1" class="form-control">
<option value="0"></option>
<option value="1" selected="selected"></option></select></li>
<li><label style="word-break:break-all;font-size:10px;">车机是否处于修车模式:</label><select style="width:155px;" id="valid_2" class="form-control">
<option value="0"></option>
<option value="128"></option></select></li>
<li><label style="word-break:break-all;font-size:10px;">驾驶循环标签:</label><input id="tripMark" type="text" class="form-control" value="0"></li>
</ul>
</div>
<ul class="protocol_content" style="padding:0px;">
<li><label style="word-break:break-all;font-size:10px;">驾驶行为类别:</label><select id="actType" class="form-control">
<option value="1">急加速</option>
<option value="2">急减速</option>
<option value="3">急转弯</option></select>
</li>
<li><label style="word-break:break-all;font-size:10px;">急加速总次数:</label><input id="accelerateTotalTimes" type="text" class="form-control" value="2"></li>
<li><label style="word-break:break-all;font-size:10px;">急减速总次数:</label><input id="decelerateTotalTimes" type="text" class="form-control" value="2"></li>
<li><label style="word-break:break-all;font-size:10px;">急转弯总次数:</label><input id="sharpTurnTotalTimes" type="text" class="form-control" value="2"></li>
<li><label style="word-break:break-all;font-size:10px;">事件发生时加速度值(mg):</label><input id="acceleration" type="text" class="form-control" value="500"></li>
<li><label style="word-break:break-all;font-size:10px;">事件发生时车辆速度:</label><input id="TC_speed" type="text" class="form-control" value="60"></li>
</ul>
<H3 style="border-bottom: 1px solid #eee;">控制:</H3>
<div style="width:100%;padding:5px;margin-top:10px;">
<button type="button" class="btn btn-primary" id="sendMsgBtn">发送消息</button>
</div>
<H3 style="border-bottom: 1px solid #eee;">返回信息:</H3>
<div style="width:100%;padding:5px;margin-top:10px;">
<textarea id="showFeedback" style="width:100%;padding:5px;" rows="8"></textarea>
</div>
</div>
<script>
//发送GPS数据
$("#sendMsgBtn").click(function(){
var FUNID = $("#FUNID").val();
var waterCode = $("#waterCode").val();
var DEV_ID = $("#DEV_ID").val();
var encryptionType = $("#encryptionType").val();
var gps = getGpsData()
var actType = $("#actType").val();
var accelerateTotalTimes = $("#accelerateTotalTimes").val();
var decelerateTotalTimes = $("#decelerateTotalTimes").val();
var sharpTurnTotalTimes = $("#sharpTurnTotalTimes").val();
var acceleration = $("#acceleration").val();
var speed = $("#TC_speed").val();
var data = {};
data["FUNID"] = FUNID;
data["waterCode"] = waterCode;
data["DEV_ID"] = DEV_ID;
data["encryptionType"] = encryptionType;
data["gps"] = gps;
data["actType"] = actType;
data["accelerateTotalTimes"] = accelerateTotalTimes;
data["decelerateTotalTimes"] = decelerateTotalTimes;
data["sharpTurnTotalTimes"] = sharpTurnTotalTimes;
data["acceleration"] = acceleration;
data["speed"] = speed;
//console.log(JSON.stringify(data))
var host = window.location.host;
$("#showFeedback").val("")
$.ajax({
url:"http://" + host + "/m300Tools/P_m300Protocol_process/porcessTravelActMsg",
type:"post",
data:JSON.stringify(data),
contentType:"application/json",
dataType:"json",
success:function(data){
if(data.status == 200){
//window.location.reload()
var theShow = "原始数据: " + data.msgSend + "\n";
theShow = theShow + "收到数据: " + data.result + "\n";
theShow = theShow + "收到数据16进制: " + data.rev + "\n";
theShow = theShow + "解析数据: " + JSON.stringify(data.orgRev) + "\n";
$("#showFeedback").val(theShow)
}else{
$("#showFeedback").val(data.message)
alert(data.message);
}
}
});
});
//获取GPS数据
function getGpsData(){
var dateInfo = $("#dateInfo").val();
var latitude = parseFloat($("#latitude").val());
var latitudeType = parseInt($("#latitudeType").val());
if(latitudeType == 1){
latitude = latitude + 2147483648 / 1000000
}
var longitude = parseFloat($("#longitude").val());
var longitudeType = parseInt($("#longitudeType").val());
if(longitudeType == 1){
longitude = longitude + 2147483648 / 1000000
}
var positionStar = $("#positionStar").val();
var speed = $("#speed").val();
var direction = $("#direction").val();
var altitude = $("#altitude").val();
var ACCStatus = $("#ACCStatus").val();
var valtage = $("#valtage").val();
var OBDSpeed = $("#OBDSpeed").val();
var valid_1 = parseInt($("#valid_1").val());
var valid_2 = parseInt($("#valid_2").val());
var valid = valid_1 + valid_2
var tripMark = $("#tripMark").val();
var data = {};
data["dateInfo"] = dateInfo;
data["latitude"] = latitude;
data["longitude"] = longitude;
data["positionStar"] = positionStar;
data["speed"] = speed;
data["direction"] = direction;
data["altitude"] = altitude;
data["ACCStatus"] = ACCStatus;
data["valtage"] = valtage;
data["OBDSpeed"] = OBDSpeed;
data["valid"] = valid;
data["tripMark"] = tripMark;
return data
}
//gps区域的显示与隐藏
function isShowGPS_area(e){
var val = $(e).val()
if(val == "0"){
$("#GPS_area").css("display","none")
}else{
$("#GPS_area").css("display","block")
}
}
//设置当前时间到UTC时间输入框
(function(){
var curTime = getCurTime();
$("#dateInfo").val(curTime);
})();
</script>
{% endblock %}
\ No newline at end of file
......@@ -8,6 +8,7 @@ from configparser import ConfigParser
import json
import traceback
from lib.protocol.m300.TravelAct_protocol_m300 import TravelAct_protocol_m300
from lib.socket.ClientSocket import ClientSocket
from lib.socket.service.M300SimulaterService import M300SimulaterService
from lib.util import fileUtil
......@@ -358,6 +359,180 @@ def getConnects():
data["message"] = "Error: 获取在线人数失败失败!"
return Response(json.dumps(data), mimetype='application/json')
#-------------------------------------- 报警上报逻辑 --------------------------------------
##########################################
# 【接口类型】发送急加速事件
##########################################
@M_m300Simulater_process.route("/sendAccelerateEvent",methods=['POST'])
def sendAccelerateEvent():
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 = {"FUNID": "0007", "waterCode": "1", "DEV_ID": "M202004070000", "encryptionType": "0",
"gps": {"dateInfo": "2020-06-05 11:28:33", "latitude": 40.22077, "longitude": 116.23128,
"positionStar": "2", "speed": "66.0", "direction": "55.3", "altitude": "11.0", "ACCStatus": "1",
"valtage": "36.0", "OBDSpeed": "66.4", "valid": 1, "tripMark": "0"}, "actType": "1",
"accelerateTotalTimes": "2", "decelerateTotalTimes": "2", "sharpTurnTotalTimes": "2",
"acceleration": "500", "speed": "60"}
carData = service.getCarData()
carData["event"]["threeRapid"]["totalRapidlyAccelerate"] = carData["event"]["threeRapid"]["totalRapidlyAccelerate"] + 1
service.setCarData(carData)
timeStamp = time.time() - 8 * 3600
timeArray = time.localtime(timeStamp)
curTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
jdata["gps"]["dateInfo"] = curTime
jdata["gps"]["latitude"] = service.getCurLatitude()
jdata["gps"]["longitude"] = service.getCurLongtitude()
jdata["gps"]["speed"] = service.getSpeed()
jdata["gps"]["OBDSpeed"] = service.getSpeed()
jdata["gps"]["direction"] = service.getDirAngle()
jdata["accelerateTotalTimes"] = carData["event"]["threeRapid"]["totalRapidlyAccelerate"]
jdata["decelerateTotalTimes"] = carData["event"]["threeRapid"]["totalSharpSlowdown"]
jdata["sharpTurnTotalTimes"] = carData["event"]["threeRapid"]["totalSharpTurn"]
jdata["DEV_ID"] = params["carId"]
obj = TravelAct_protocol_m300(waterCode=int(jdata["waterCode"]), DEV_ID=jdata["DEV_ID"],encryptionType=int(jdata["encryptionType"]), \
actType=int(jdata["actType"]),accelerateTotalTimes=int(jdata["accelerateTotalTimes"]),decelerateTotalTimes=int(jdata["decelerateTotalTimes"]), \
sharpTurnTotalTimes=int(jdata["sharpTurnTotalTimes"]),acceleration=int(jdata["acceleration"]), speed=int(jdata["speed"]),gps=jdata["gps"])
msg = obj.generateMsg()
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_m300Simulater_process.route("/sendDecelerateEvent",methods=['POST'])
def sendDecelerateEvent():
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 = {"FUNID": "0007", "waterCode": "1", "DEV_ID": "M202004070000", "encryptionType": "0",
"gps": {"dateInfo": "2020-06-05 11:28:33", "latitude": 40.22077, "longitude": 116.23128,
"positionStar": "2", "speed": "66.0", "direction": "55.3", "altitude": "11.0", "ACCStatus": "1",
"valtage": "36.0", "OBDSpeed": "66.4", "valid": 1, "tripMark": "0"}, "actType": "2",
"accelerateTotalTimes": "2", "decelerateTotalTimes": "2", "sharpTurnTotalTimes": "2",
"acceleration": "500", "speed": "60"}
carData = service.getCarData()
carData["event"]["threeRapid"]["totalSharpSlowdown"] = carData["event"]["threeRapid"]["totalSharpSlowdown"] + 1
service.setCarData(carData)
timeStamp = time.time() - 8 * 3600
timeArray = time.localtime(timeStamp)
curTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
jdata["gps"]["dateInfo"] = curTime
jdata["gps"]["latitude"] = service.getCurLatitude()
jdata["gps"]["longitude"] = service.getCurLongtitude()
jdata["gps"]["speed"] = service.getSpeed()
jdata["gps"]["OBDSpeed"] = service.getSpeed()
jdata["gps"]["direction"] = service.getDirAngle()
jdata["accelerateTotalTimes"] = carData["event"]["threeRapid"]["totalRapidlyAccelerate"]
jdata["decelerateTotalTimes"] = carData["event"]["threeRapid"]["totalSharpSlowdown"]
jdata["sharpTurnTotalTimes"] = carData["event"]["threeRapid"]["totalSharpTurn"]
jdata["DEV_ID"] = params["carId"]
obj = TravelAct_protocol_m300(waterCode=int(jdata["waterCode"]), DEV_ID=jdata["DEV_ID"],encryptionType=int(jdata["encryptionType"]), \
actType=int(jdata["actType"]),accelerateTotalTimes=int(jdata["accelerateTotalTimes"]),decelerateTotalTimes=int(jdata["decelerateTotalTimes"]), \
sharpTurnTotalTimes=int(jdata["sharpTurnTotalTimes"]),acceleration=int(jdata["acceleration"]), speed=int(jdata["speed"]),gps=jdata["gps"])
msg = obj.generateMsg()
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_m300Simulater_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 = {"FUNID": "0007", "waterCode": "1", "DEV_ID": "M202004070000", "encryptionType": "0",
"gps": {"dateInfo": "2020-06-05 11:28:33", "latitude": 40.22077, "longitude": 116.23128,
"positionStar": "2", "speed": "66.0", "direction": "55.3", "altitude": "11.0", "ACCStatus": "1",
"valtage": "36.0", "OBDSpeed": "66.4", "valid": 1, "tripMark": "0"}, "actType": "3",
"accelerateTotalTimes": "2", "decelerateTotalTimes": "2", "sharpTurnTotalTimes": "2",
"acceleration": "500", "speed": "60"}
carData = service.getCarData()
carData["event"]["threeRapid"]["totalSharpSlowdown"] = carData["event"]["threeRapid"]["totalSharpSlowdown"] + 1
service.setCarData(carData)
timeStamp = time.time() - 8 * 3600
timeArray = time.localtime(timeStamp)
curTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
jdata["gps"]["dateInfo"] = curTime
jdata["gps"]["latitude"] = service.getCurLatitude()
jdata["gps"]["longitude"] = service.getCurLongtitude()
jdata["gps"]["speed"] = service.getSpeed()
jdata["gps"]["OBDSpeed"] = service.getSpeed()
jdata["gps"]["direction"] = service.getDirAngle()
jdata["accelerateTotalTimes"] = carData["event"]["threeRapid"]["totalRapidlyAccelerate"]
jdata["decelerateTotalTimes"] = carData["event"]["threeRapid"]["totalSharpSlowdown"]
jdata["sharpTurnTotalTimes"] = carData["event"]["threeRapid"]["totalSharpTurn"]
jdata["DEV_ID"] = params["carId"]
obj = TravelAct_protocol_m300(waterCode=int(jdata["waterCode"]), DEV_ID=jdata["DEV_ID"],encryptionType=int(jdata["encryptionType"]), \
actType=int(jdata["actType"]),accelerateTotalTimes=int(jdata["accelerateTotalTimes"]),decelerateTotalTimes=int(jdata["decelerateTotalTimes"]), \
sharpTurnTotalTimes=int(jdata["sharpTurnTotalTimes"]),acceleration=int(jdata["acceleration"]), speed=int(jdata["speed"]),gps=jdata["gps"])
msg = obj.generateMsg()
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')
#--------------------------------------- 实时控制逻辑 ---------------------------------------
......
......@@ -8,6 +8,7 @@ from lib.protocol.m300.GPS_protocol_m300 import GPS_protocol_m300
from lib.protocol.m300.Heartbeat_protocol_300 import Heartbeat_protocol_300
from lib.protocol.m300.Login_protocol_m300 import Login_protocol_m300
from lib.protocol.m300.OBDCAN_protocol_m300 import OBDCAN_protocol_m300
from lib.protocol.m300.TravelAct_protocol_m300 import TravelAct_protocol_m300
from lib.protocol.m300.VersionInfo_protocol_m300 import VersionInfo_protocol_m300
from lib.protocol.m300Plateform.M300Common_res import M300Common_res
from lib.protocol.m300Plateform.M300Login_res import M300Login_res
......@@ -406,3 +407,42 @@ def porcessAlarmMsg():
data["status"] = "4003"
data["message"] = "Error: 处理失败!"
return Response(json.dumps(data), mimetype='application/json')
##########################################
# 【接口类型】处理发送的驾驶行为报文
##########################################
@P_m300Protocol_process.route("/porcessTravelActMsg",methods=['POST'])
def porcessTravelActMsg():
params = request.get_data()
params = json.loads(params.decode("utf-8"))
data = {}
if (hasJsonDataIsNone(params)):
data["status"] = "4003"
data["message"] = "Info: 请检查是否传入了空数据!"
return Response(json.dumps(data), mimetype='application/json')
else:
try:
conf_R = ConfigParser()
conf_R.read("config/m300Tools/m300Tools.conf")
cliSocket = ClientSocket(conf_R.get("socket", "host"),conf_R.getint("socket", "port"))
cliSocket.connect()
protocolObj = TravelAct_protocol_m300(waterCode=int(params["waterCode"]), DEV_ID=params["DEV_ID"],encryptionType=int(params["encryptionType"]), \
actType=int(params["actType"]),accelerateTotalTimes=int(params["accelerateTotalTimes"]),decelerateTotalTimes=int(params["decelerateTotalTimes"]), \
sharpTurnTotalTimes=int(params["sharpTurnTotalTimes"]),acceleration=int(params["acceleration"]), speed=int(params["speed"]),gps=params["gps"])
msg = protocolObj.generateMsg()
cliSocket.send(msg)
socRecv = cliSocket.receive()
socRecvo = str(socRecv)
cliSocket.close()
data["status"] = "200"
data["message"] = "Sucess: "
data["msgSend"] = msg
data["result"] = socRecvo
data["rev"] = str(binascii.b2a_hex(socRecv))[2:][:-1]
data["orgRev"] = json.loads(M300Common_res(data["rev"]).getMsg())
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
......@@ -123,3 +123,17 @@ def P_alarm_m300_page():
path = "m300Tools/report/P_alarm_m300_page.html"
arg["path"] = reqPath.split("/")
return render_template(path,arg=arg)
##########################################
# 【视图类型】访问OBD CAN协议页面
##########################################
@P_m300Protocol_view.route('/P_travelAct_m300_page')
def P_travelAct_m300_page():
#获取请求的路劲
url = request.url
reqPath = re.findall("http://(.*)$",url)[0]
reqPath = re.findall("/(.*)$", reqPath)[0]
arg = {}
path = "m300Tools/report/P_travelAct_m300_page.html"
arg["path"] = reqPath.split("/")
return render_template(path,arg=arg)
\ 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