Commit 546db7bf authored by liyuanhong's avatar liyuanhong

汽车点熄火功能完成

parent aec863d3
...@@ -8,14 +8,20 @@ from lib.protocol.report.SecurityStatusReport_protocol import SecurityStatusRepo ...@@ -8,14 +8,20 @@ from lib.protocol.report.SecurityStatusReport_protocol import SecurityStatusRepo
class EventClass(ProtocolBase): class EventClass(ProtocolBase):
def __init__(self): def __init__(self):
pass self.GPSPkg = "1401091213260265b86206ed8c70026103280000752f03030405af017102610bb800003200000186a0001ed2a25e16fe3a"
self.BaseStationPkg = "1401140a0c050207e407e607e807ea07ec4eea4eec4eee4ef04efc4efe4f004f024f040024025e07d00007a125000927c60000ea610100"
def setGPSpkg(self,data):
self.GPSPkg = data
# 3 点火事件附带信息 # 3 点火事件附带信息
def fireExtraInfo(self): def fireExtraInfo(self):
allRapidlyAccelerateCount = self.int2hexStringByBytes(15, 2) # 急加速总次数 allRapidlyAccelerateCount = self.int2hexStringByBytes(15, 2) # 急加速总次数
allSharpSlowdownCount = self.int2hexStringByBytes(15, 2) # 急减速总次数 allSharpSlowdownCount = self.int2hexStringByBytes(15, 2) # 急减速总次数
allSharpTurn = self.int2hexStringByBytes(15, 2) # 急转弯总次数 allSharpTurn = self.int2hexStringByBytes(15, 2) # 急转弯总次数
securityData = SecurityStatusReport_protocol().generateSecurityStatusData() # 安防数据 securityObj = SecurityStatusReport_protocol()
securityObj.setGPSPkg(self.GPSPkg)
securityData = securityObj.generateSecurityStatusData() # 安防数据
data = allRapidlyAccelerateCount + allSharpSlowdownCount + allSharpTurn + securityData data = allRapidlyAccelerateCount + allSharpSlowdownCount + allSharpTurn + securityData
return data return data
...@@ -24,7 +30,9 @@ class EventClass(ProtocolBase): ...@@ -24,7 +30,9 @@ class EventClass(ProtocolBase):
allRapidlyAccelerateCount = self.int2hexStringByBytes(100,2) #急加速总次数 allRapidlyAccelerateCount = self.int2hexStringByBytes(100,2) #急加速总次数
allSharpSlowdownCount = self.int2hexStringByBytes(101,2) #急减速总次数 allSharpSlowdownCount = self.int2hexStringByBytes(101,2) #急减速总次数
allSharpTurn = self.int2hexStringByBytes(35,2) #急转弯总次数 allSharpTurn = self.int2hexStringByBytes(35,2) #急转弯总次数
securityData = SecurityStatusReport_protocol().generateSecurityStatusData() #安防数据 securityObj = SecurityStatusReport_protocol()
securityObj.setGPSPkg(self.GPSPkg)
securityData = securityObj.generateSecurityStatusData() #安防数据
data = allRapidlyAccelerateCount + allSharpSlowdownCount + allSharpTurn + securityData data = allRapidlyAccelerateCount + allSharpSlowdownCount + allSharpTurn + securityData
return data return data
......
...@@ -20,10 +20,7 @@ class EventReport_protocol(ProtocolBase): ...@@ -20,10 +20,7 @@ class EventReport_protocol(ProtocolBase):
self.locationType = int(locationType) # 定位类型 self.locationType = int(locationType) # 定位类型
#self.GPSPkg = GPSpkg & BaseStationPkg # GPS包或者基站包 #self.GPSPkg = GPSpkg & BaseStationPkg # GPS包或者基站包
# self.GPSPkg = "1401091213260265b86206ed8c70026103280000752f03030405af017102610bb800003200000186a0001ed2a25e16fe3a" self.GPSPkg = "1401091213260265b86206ed8c70026103280000752f03030405af017102610bb800003200000186a0001ed2a25e16fe3a"
self.latitude = 40.22077
self.longitude = 116.23128
self.timestamp = int(time.time())
self.BaseStationPkg = "1401140a0c050207e407e607e807ea07ec4eea4eec4eee4ef04efc4efe4f004f024f040024025e07d00007a125000927c60000ea610100" self.BaseStationPkg = "1401140a0c050207e407e607e807ea07ec4eea4eec4eee4ef04efc4efe4f004f024f040024025e07d00007a125000927c60000ea610100"
self.eventType = eventType #事件类别 self.eventType = eventType #事件类别
...@@ -33,6 +30,12 @@ class EventReport_protocol(ProtocolBase): ...@@ -33,6 +30,12 @@ class EventReport_protocol(ProtocolBase):
self.longitude = data self.longitude = data
def setEventType(self,data): def setEventType(self,data):
self.eventType = data self.eventType = data
def setLocationType(self,data):
self.locationType = data
def setGPSPkg(self,data):
self.GPSPkg = data
def setBaseStationPkg(self,data):
self.BaseStationPkg = data
...@@ -83,12 +86,6 @@ class EventReport_protocol(ProtocolBase): ...@@ -83,12 +86,6 @@ class EventReport_protocol(ProtocolBase):
##################################################### #####################################################
def generateEventData(self): def generateEventData(self):
data = "" data = ""
gpsObj = GPSReport_protocol()
gpsObj.setLatitude(self.latitude)
gpsObj.setLatitude(self.longitude)
gpsObj.setGPSTimestamp(self.timestamp)
self.GPSPkg = gpsObj.generateGpsData()
locationType = self.int2hexString(self.locationType) #定位类型 locationType = self.int2hexString(self.locationType) #定位类型
locationData = "" #GPS包或基站包 locationData = "" #GPS包或基站包
if self.locationType == 1: if self.locationType == 1:
...@@ -137,9 +134,13 @@ class EventReport_protocol(ProtocolBase): ...@@ -137,9 +134,13 @@ class EventReport_protocol(ProtocolBase):
elif eventType == "000F": #汽车预点火上报 elif eventType == "000F": #汽车预点火上报
return EventClass().preFiringExtraInfo() return EventClass().preFiringExtraInfo()
elif eventType == "0010": #汽车点火上报 elif eventType == "0010": #汽车点火上报
return EventClass().fireExtraInfo() eventObj = EventClass()
eventObj.setGPSpkg(self.GPSPkg)
return eventObj.fireExtraInfo()
elif eventType == "0011": #汽车熄火上报 elif eventType == "0011": #汽车熄火上报
return EventClass().misFireExtraInfo() eventObj = EventClass()
eventObj.setGPSpkg(self.GPSPkg)
return eventObj.misFireExtraInfo()
elif eventType == "0012": #汽车设防上报 elif eventType == "0012": #汽车设防上报
return EventClass().setUpDefencesExtraInfo() return EventClass().setUpDefencesExtraInfo()
elif eventType == "0013": #汽车撤防上报 elif eventType == "0013": #汽车撤防上报
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
''' '''
定义一个GPS协议的类 定义一个GPS协议的类
''' '''
import datetime
from lib.util import dataUtil from lib.util import dataUtil
from lib.protocol.report.ProtocolBase import ProtocolBase from lib.protocol.report.ProtocolBase import ProtocolBase
...@@ -495,7 +496,9 @@ if __name__ == "__main__": ...@@ -495,7 +496,9 @@ if __name__ == "__main__":
GPSReport_protocol().generateGpsMsg() GPSReport_protocol().generateGpsMsg()
# Gps_protocol().getLatitude(40.22077) # Gps_protocol().getLatitude(40.22077)
# print(Gps_protocol().getHexTime()) # print(Gps_protocol().getHexTime())
# print(Gps_protocol().getUTCTime(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))) print(GPSReport_protocol().getUTCTime(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
print(datetime.datetime.now())
# Gps_protocol().generateGpsData() # Gps_protocol().generateGpsData()
# Gps_protocol().getLatitude(40.22077) # Gps_protocol().getLatitude(40.22077)
# Gps_protocol().getLongitude(116.23128) # Gps_protocol().getLongitude(116.23128)
......
...@@ -29,6 +29,13 @@ class SecurityStatusReport_protocol(ProtocolBase): ...@@ -29,6 +29,13 @@ class SecurityStatusReport_protocol(ProtocolBase):
self.onoffStatusB = int(onoffStatusB) #开关状态B self.onoffStatusB = int(onoffStatusB) #开关状态B
self.dataByte = int(dataByte) #数据字节 self.dataByte = int(dataByte) #数据字节
def setLocationType(self,data):
self.locationType = data
def setGPSPkg(self,data):
self.GPSPkg = data
def setBaseStationPkg(self,data):
self.BaseStationPkg = data
##################################################### #####################################################
# 生成安全状态消息 # 生成安全状态消息
##################################################### #####################################################
......
...@@ -83,6 +83,7 @@ class ProtocolSimulaterService(): ...@@ -83,6 +83,7 @@ class ProtocolSimulaterService():
type = self.getMsgFunId(OBDMsg) type = self.getMsgFunId(OBDMsg)
info = type + ">>>>:" + OBDMsg info = type + ">>>>:" + OBDMsg
self.websocket.send(info) self.websocket.send(info)
sleep(0.1)
self.sendMsg(gpsMsg) self.sendMsg(gpsMsg)
type = self.getMsgFunId(gpsMsg) type = self.getMsgFunId(gpsMsg)
info = type + ">>>>:" + gpsMsg info = type + ">>>>:" + gpsMsg
...@@ -153,6 +154,7 @@ class ProtocolSimulaterService(): ...@@ -153,6 +154,7 @@ class ProtocolSimulaterService():
######################################################## ########################################################
def stopTravel(self): def stopTravel(self):
self.travelStatus = 0 self.travelStatus = 0
self.serviceStatus = 0
#获取收到消息的功能id #获取收到消息的功能id
def getMsgFunId(self,msg): def getMsgFunId(self,msg):
...@@ -187,14 +189,19 @@ class ProtocolSimulaterService(): ...@@ -187,14 +189,19 @@ class ProtocolSimulaterService():
#点火,发送点火事件 #点火,发送点火事件
def fireOn(self): def fireOn(self):
fireOnEventObj = EventReport_protocol(DEV_ID=self.carId) fireOnEventObj = EventReport_protocol(DEV_ID=self.carId)
fireOnEventObj.setLatitude(self.gpsLine[0]["lat"]) gpsData = self.genGPSData(self.gpsLine[0]["lat"], self.gpsLine[0]["lng"])
fireOnEventObj.setLongtitude(self.gpsLine[0]["lng"]) fireOnEventObj.setGPSPkg(gpsData)
fireOnEventObj.setEventType("0010") fireOnEventObj.setEventType("0010")
firOnEventMsg = fireOnEventObj.generateEventMsg() firOnEventMsg = fireOnEventObj.generateEventMsg()
type = self.getMsgFunId(firOnEventMsg) type = self.getMsgFunId(firOnEventMsg)
self.sendMsg(firOnEventMsg) self.sendMsg(firOnEventMsg)
self.websocket.send(type + ">>>>:" + firOnEventMsg) self.websocket.send(type + ">>>>:" + firOnEventMsg)
sleep(0.1) sleep(0.1)
gpsMsg = self.genGPSMsg(self.gpsLine[0]["lat"],self.gpsLine[0]["lng"])
type = self.getMsgFunId(gpsMsg)
self.sendMsg(gpsMsg)
self.websocket.send(type + ">>>>:" + gpsMsg)
sleep(0.1)
OBDMsg = self.genOBDMsg() OBDMsg = self.genOBDMsg()
type = self.getMsgFunId(OBDMsg) type = self.getMsgFunId(OBDMsg)
self.sendMsg(OBDMsg) self.sendMsg(OBDMsg)
...@@ -203,23 +210,43 @@ class ProtocolSimulaterService(): ...@@ -203,23 +210,43 @@ class ProtocolSimulaterService():
# 熄火,发送熄火事件 # 熄火,发送熄火事件
def fireOff(self): def fireOff(self):
fireOffEventObj = EventReport_protocol(DEV_ID=self.carId) fireOffEventObj = EventReport_protocol(DEV_ID=self.carId)
fireOffEventObj.setLatitude(self.gpsLine[self.gpsLineIndex]["lat"]) gpsData = self.genGPSData(self.gpsLine[self.gpsLineIndex]["lat"],self.gpsLine[self.gpsLineIndex]["lng"])
fireOffEventObj.setLongtitude(self.gpsLine[self.gpsLineIndex]["lng"]) fireOffEventObj.setGPSPkg(gpsData)
fireOffEventObj.setEventType("0011") fireOffEventObj.setEventType("0011")
fireOffEventObj = fireOffEventObj.generateEventMsg() fireOffEventMsg = fireOffEventObj.generateEventMsg()
type = self.getMsgFunId(fireOffEventObj) type = self.getMsgFunId(fireOffEventMsg)
self.sendMsg(fireOffEventObj) self.sendMsg(fireOffEventMsg)
self.websocket.send(type + ">>>>:" + fireOffEventObj) self.websocket.send(type + ">>>>:" + fireOffEventMsg)
sleep(0.1)
gpsMsg = self.genGPSMsg(self.gpsLine[self.gpsLineIndex]["lat"], self.gpsLine[self.gpsLineIndex]["lng"])
type = self.getMsgFunId(gpsMsg)
self.sendMsg(gpsMsg)
self.websocket.send(type + ">>>>:" + gpsMsg)
#根据特定参数,生成GPS消息 #根据特定参数,生成GPS消息
def genGPSMsg(self,latitude,longtitude): def genGPSMsg(self,latitude,longtitude):
gpsObj = GPSReport_protocol(DEV_ID=self.carId) gpsObj = GPSReport_protocol(DEV_ID=self.carId)
gpsObj.setLatitude(latitude) gpsObj.setLatitude(latitude)
gpsObj.setLongitude(longtitude) gpsObj.setLongitude(longtitude)
timeS = time.time() 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) gpsObj.setGPSTimestamp(timeS)
msg = gpsObj.generateGpsMsg() msg = gpsObj.generateGpsMsg()
return msg return msg
#根据特定参数,生成GPS消息体,不包含消息头
def genGPSData(self,latitude,longtitude):
gpsObj = GPSReport_protocol(DEV_ID=self.carId)
gpsObj.setLatitude(latitude)
gpsObj.setLongitude(longtitude)
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, \
......
...@@ -168,7 +168,15 @@ function fire(){ ...@@ -168,7 +168,15 @@ function fire(){
} }
//行驶 //行驶
function startTravel(){ function startTravel(){
var carId = $("#carId").val()
var WATER_CODE = $("#WATER_CODE").val()
var durTime = $("#durTime").val()
var gpsLine = $("#selectGPSLine").val()
var data = {}; var data = {};
data["carId"] = carId
data["WATER_CODE"] = WATER_CODE
data["durTime"] = durTime
data["gpsLine"] = gpsLine
url = "/protocolTools/M_carSimulater_process/startTravel"; url = "/protocolTools/M_carSimulater_process/startTravel";
send(data,url); send(data,url);
$("#curStatus").val("行驶") $("#curStatus").val("行驶")
...@@ -182,7 +190,15 @@ function stopTravel(){ ...@@ -182,7 +190,15 @@ function stopTravel(){
} }
//熄火 //熄火
function unFire(){ function unFire(){
var carId = $("#carId").val()
var WATER_CODE = $("#WATER_CODE").val()
var durTime = $("#durTime").val()
var gpsLine = $("#selectGPSLine").val()
var data = {}; var data = {};
data["carId"] = carId
data["WATER_CODE"] = WATER_CODE
data["durTime"] = durTime
data["gpsLine"] = gpsLine
url = "/protocolTools/M_carSimulater_process/unFire"; url = "/protocolTools/M_carSimulater_process/unFire";
send(data,url); send(data,url);
$("#curStatus").val("熄火") $("#curStatus").val("熄火")
......
...@@ -69,6 +69,7 @@ def createConect(): ...@@ -69,6 +69,7 @@ def createConect():
service = ProtocolSimulaterService() service = ProtocolSimulaterService()
service.setSocket(cliSocket) service.setSocket(cliSocket)
service.setTimeout(timeout) service.setTimeout(timeout)
service.setSocket(cliSocket)
service.startWebsocketService() service.startWebsocketService()
connects[0]["service"] = service connects[0]["service"] = service
data["status"] = "200" data["status"] = "200"
...@@ -93,8 +94,6 @@ def login(): ...@@ -93,8 +94,6 @@ def login():
data = {} data = {}
try: try:
service = connects[0]["service"] service = connects[0]["service"]
clientSocket = connects[0]["obj"]
service.setSocket(clientSocket)
service.setCarId(params["carId"]) service.setCarId(params["carId"])
loginObj = LoginReport_protocol(params["WATER_CODE"],params["carId"],params["login"]["cpuId"], \ loginObj = LoginReport_protocol(params["WATER_CODE"],params["carId"],params["login"]["cpuId"], \
params["login"]["imsi"],params["login"]["ccid"],params["login"]["imei"]) params["login"]["imsi"],params["login"]["ccid"],params["login"]["imei"])
...@@ -121,14 +120,13 @@ def login(): ...@@ -121,14 +120,13 @@ def login():
def fire(): def fire():
durTime = int(request.form.get("durTime")) durTime = int(request.form.get("durTime"))
gpsLine = request.form.get("gpsLine") gpsLine = request.form.get("gpsLine")
carId = request.form.get("carId")
data = {} data = {}
try: try:
service = connects[0]["service"] service = connects[0]["service"]
service.setSendDur(durTime) #设置车机多久循环发送一次消息 service.setCarId(carId)
service.setGpsLine(gpsLine) service.setGpsLine(gpsLine)
service.fireOn() service.fireOn()
service.startService()
connects[0]["service"] = service
data["status"] = "200" data["status"] = "200"
data["message"] = "点火成功!" data["message"] = "点火成功!"
except BaseException as e: except BaseException as e:
...@@ -143,9 +141,14 @@ def fire(): ...@@ -143,9 +141,14 @@ def fire():
########################################## ##########################################
@M_carSimulater_process.route("/startTravel",methods=['POST']) @M_carSimulater_process.route("/startTravel",methods=['POST'])
def startTravel(): def startTravel():
durTime = int(request.form.get("durTime"))
gpsLine = request.form.get("gpsLine")
data = {} data = {}
try: try:
service = connects[0]["service"] service = connects[0]["service"]
service.setSendDur(durTime) #设置车机多久循环发送一次消息
service.setGpsLine(gpsLine)
service.startService()
service.startTravel() service.startTravel()
data["status"] = "200" data["status"] = "200"
data["message"] = "行驶成功!" data["message"] = "行驶成功!"
...@@ -179,10 +182,14 @@ def stopTravel(): ...@@ -179,10 +182,14 @@ def stopTravel():
########################################## ##########################################
@M_carSimulater_process.route("/unFire",methods=['POST']) @M_carSimulater_process.route("/unFire",methods=['POST'])
def unFire(): def unFire():
gpsLine = request.form.get("gpsLine")
carId = request.form.get("carId")
data = {} data = {}
try: try:
connects[0]["service"].setGpsLine(gpsLine)
connects[0]["service"].setCarId(carId)
connects[0]["service"].fireOff() connects[0]["service"].fireOff()
connects[0]["service"].stopService() connects[0]["service"].stopTravel()
data["status"] = "200" data["status"] = "200"
data["message"] = "熄火成功!" data["message"] = "熄火成功!"
except BaseException as e: except BaseException as e:
...@@ -203,6 +210,7 @@ def closeConect(): ...@@ -203,6 +210,7 @@ def closeConect():
data["status"] = "4003" data["status"] = "4003"
data["message"] = "没有可关闭的连接!" data["message"] = "没有可关闭的连接!"
else: else:
connects[0]["service"].stopTravel()
connects[0]["service"].stopWebsocketService() connects[0]["service"].stopWebsocketService()
connects[0]["service"].stopService() connects[0]["service"].stopService()
connects[0]["service"].closeSocket() connects[0]["service"].closeSocket()
...@@ -224,6 +232,7 @@ def reset(): ...@@ -224,6 +232,7 @@ def reset():
data = {} data = {}
try: try:
for t in connects: for t in connects:
t["service"].stopTravel()
t["service"].stopWebsocketService() t["service"].stopWebsocketService()
t["service"].stopService() t["service"].stopService()
t["service"].closeSocket() t["service"].closeSocket()
......
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