Commit fc54f847 authored by liyuanhong's avatar liyuanhong

修改了点熄火,三急事件次数写死的bug

parent cc33f022
...@@ -40,10 +40,10 @@ class EventClass(ProtocolBase): ...@@ -40,10 +40,10 @@ class EventClass(ProtocolBase):
return self.int2hexString(data) return self.int2hexString(data)
# 0010 点火事件附带信息 # 0010 点火事件附带信息
def fireExtraInfo(self): def fireExtraInfo(self,allRapidlyAccelerateCount=15,allSharpSlowdownCount=15,allSharpTurn=15):
allRapidlyAccelerateCount = self.int2hexStringByBytes(15, 2) # 急加速总次数 allRapidlyAccelerateCount = self.int2hexStringByBytes(allRapidlyAccelerateCount, 2) # 急加速总次数
allSharpSlowdownCount = self.int2hexStringByBytes(15, 2) # 急减速总次数 allSharpSlowdownCount = self.int2hexStringByBytes(allSharpSlowdownCount, 2) # 急减速总次数
allSharpTurn = self.int2hexStringByBytes(15, 2) # 急转弯总次数 allSharpTurn = self.int2hexStringByBytes(allSharpTurn, 2) # 急转弯总次数
securityObj = SecurityStatusReport_protocol() securityObj = SecurityStatusReport_protocol()
securityObj.setGPSPkg(self.GPSPkg) securityObj.setGPSPkg(self.GPSPkg)
securityData = "" securityData = ""
...@@ -55,10 +55,10 @@ class EventClass(ProtocolBase): ...@@ -55,10 +55,10 @@ class EventClass(ProtocolBase):
return data return data
# 0011 熄火事件附带信息 # 0011 熄火事件附带信息
def misFireExtraInfo(self): def misFireExtraInfo(self,allRapidlyAccelerateCount=15,allSharpSlowdownCount=15,allSharpTurn=15):
allRapidlyAccelerateCount = self.int2hexStringByBytes(100,2) #急加速总次数 allRapidlyAccelerateCount = self.int2hexStringByBytes(allRapidlyAccelerateCount,2) #急加速总次数
allSharpSlowdownCount = self.int2hexStringByBytes(101,2) #急减速总次数 allSharpSlowdownCount = self.int2hexStringByBytes(allSharpSlowdownCount,2) #急减速总次数
allSharpTurn = self.int2hexStringByBytes(35,2) #急转弯总次数 allSharpTurn = self.int2hexStringByBytes(allSharpTurn,2) #急转弯总次数
securityObj = SecurityStatusReport_protocol() securityObj = SecurityStatusReport_protocol()
securityObj.setGPSPkg(self.GPSPkg) securityObj.setGPSPkg(self.GPSPkg)
securityData = "" securityData = ""
......
...@@ -216,13 +216,13 @@ class EventReport_protocol(ProtocolBase): ...@@ -216,13 +216,13 @@ class EventReport_protocol(ProtocolBase):
eventObj = EventClass() eventObj = EventClass()
eventObj.setGPSpkg(self.GPSPkg) eventObj.setGPSpkg(self.GPSPkg)
eventObj.setSecurityData(self.securityPkg) eventObj.setSecurityData(self.securityPkg)
theData = eventObj.fireExtraInfo() theData = eventObj.fireExtraInfo(int(eventData["0010"]["allRapidlyAccelerateCount"]), int(eventData["0010"]["allSharpSlowdownCount"]), int(eventData["0010"]["allSharpTurn"]))
data = data + "0010" + self.int2hexStringByBytes(int((len(theData) / 2)), 2) + theData data = data + "0010" + self.int2hexStringByBytes(int((len(theData) / 2)), 2) + theData
if ("0011" in eventData.keys()): #汽车熄火上报 if ("0011" in eventData.keys()): #汽车熄火上报
eventObj = EventClass() eventObj = EventClass()
eventObj.setGPSpkg(self.GPSPkg) eventObj.setGPSpkg(self.GPSPkg)
eventObj.setSecurityData(self.securityPkg) eventObj.setSecurityData(self.securityPkg)
theData = eventObj.fireExtraInfo() theData = eventObj.misFireExtraInfo(int(eventData["0011"]["allRapidlyAccelerateCount"]), int(eventData["0011"]["allSharpSlowdownCount"]), int(eventData["0011"]["allSharpTurn"]))
data = data + "0011" + self.int2hexStringByBytes(int((len(theData) / 2)), 2) + theData data = data + "0011" + self.int2hexStringByBytes(int((len(theData) / 2)), 2) + theData
if ("0012" in eventData.keys()): #汽车设防上报 if ("0012" in eventData.keys()): #汽车设防上报
eventObj = EventClass() eventObj = EventClass()
......
...@@ -61,7 +61,7 @@ class ProtocolSimulaterService(): ...@@ -61,7 +61,7 @@ class ProtocolSimulaterService():
def setData(self,data): def setData(self,data):
self.data = data self.data = data
def setWebsocketId(self): def setWebsocketId(self):
sleep(1) sleep(0.1)
self.websocketId = self.websocket.getCurrentClientId() self.websocketId = self.websocket.getCurrentClientId()
def setWebsocket(self,data): def setWebsocket(self,data):
self.websocket = data self.websocket = data
...@@ -356,15 +356,42 @@ class ProtocolSimulaterService(): ...@@ -356,15 +356,42 @@ class ProtocolSimulaterService():
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 = self.carDataObj.fixDataTemplate(conJson) self.carData = self.carDataObj.fixDataTemplate(conJson)
fireOnEventObj = EventReport_protocol(DEV_ID=self.carId,WATER_CODE=self.sn)
gpsData = self.genGPSData(self.gpsLine[0]["lat"], self.gpsLine[0]["lng"]) # fireOnEventObj = EventReport_protocol(DEV_ID=self.carId,WATER_CODE=self.sn)
fireOnEventObj.setGPSPkg(gpsData) # gpsData = self.genGPSData(self.gpsLine[0]["lat"], self.gpsLine[0]["lng"])
fireOnEventObj.setEventType("0010") # fireOnEventObj.setGPSPkg(gpsData)
firOnEventMsg = fireOnEventObj.generateEventMsg() # fireOnEventObj.setEventType("0010")
type = self.getMsgFunId(firOnEventMsg) # firOnEventMsg = fireOnEventObj.generateEventMsg()
self.sendMsg(firOnEventMsg) # type = self.getMsgFunId(firOnEventMsg)
# self.sendMsg(firOnEventMsg)
# self.sn = self.sn + 1
# self.websocket.sendMsgToClient(type + ">>>>:" + firOnEventMsg,self.websocketId)
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": {
"0010": {"allRapidlyAccelerateCount": "5", "allSharpSlowdownCount": "6", "allSharpTurn": "4",
"dataProperty": "1"}}}
jdata["event"]["0010"]["allRapidlyAccelerateCount"] = self.carData["event"]["threeRapid"]["totalRapidlyAccelerate"]
jdata["event"]["0010"]["allSharpSlowdownCount"] = self.carData["event"]["threeRapid"]["totalSharpSlowdown"]
jdata["event"]["0010"]["allSharpTurn"] = self.carData["event"]["threeRapid"]["totalSharpTurn"]
jdata["DEV_ID"] = self.carId
obj = EventReport_protocol(data=jdata)
gpsData = self.genGPSData2()
obj.setGPSPkg(gpsData)
obj.setEventType("0010")
msg = obj.generateEventMsg()
type = self.getMsgFunId(msg)
self.sendMsg(msg)
self.sn = self.sn + 1 self.sn = self.sn + 1
self.websocket.sendMsgToClient(type + ">>>>:" + firOnEventMsg,self.websocketId) self.websocket.sendMsgToClient(type + ">>>>:" + msg, self.websocketId)
sleep(0.1) sleep(0.1)
gpsMsg = self.genGPSMsg(self.gpsLine[0]["lat"],self.gpsLine[0]["lng"]) gpsMsg = self.genGPSMsg(self.gpsLine[0]["lat"],self.gpsLine[0]["lng"])
type = self.getMsgFunId(gpsMsg) type = self.getMsgFunId(gpsMsg)
...@@ -385,14 +412,42 @@ class ProtocolSimulaterService(): ...@@ -385,14 +412,42 @@ class ProtocolSimulaterService():
gpsLineIndex = self.gpsLineIndex gpsLineIndex = self.gpsLineIndex
if gpsLineIndex >= len(self.gpsLine): if gpsLineIndex >= len(self.gpsLine):
gpsLineIndex = gpsLineIndex - 1 gpsLineIndex = gpsLineIndex - 1
fireOffEventObj = EventReport_protocol(DEV_ID=self.carId)
gpsData = self.genGPSData(self.gpsLine[gpsLineIndex]["lat"],self.gpsLine[gpsLineIndex]["lng"]) # fireOffEventObj = EventReport_protocol(DEV_ID=self.carId)
fireOffEventObj.setGPSPkg(gpsData) # gpsData = self.genGPSData(self.gpsLine[gpsLineIndex]["lat"],self.gpsLine[gpsLineIndex]["lng"])
fireOffEventObj.setEventType("0011") # fireOffEventObj.setGPSPkg(gpsData)
fireOffEventMsg = fireOffEventObj.generateEventMsg() # fireOffEventObj.setEventType("0011")
type = self.getMsgFunId(fireOffEventMsg) # fireOffEventMsg = fireOffEventObj.generateEventMsg()
self.sendMsg(fireOffEventMsg) # type = self.getMsgFunId(fireOffEventMsg)
self.websocket.sendMsgToClient(type + ">>>>:" + fireOffEventMsg,self.websocketId) # self.sendMsg(fireOffEventMsg)
# self.sn = self.sn + 1
# self.websocket.sendMsgToClient(type + ">>>>:" + fireOffEventMsg,self.websocketId)
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": {
"0011": {"allRapidlyAccelerateCount": "5", "allSharpSlowdownCount": "6", "allSharpTurn": "4",
"dataProperty": "1"}}}
jdata["event"]["0011"]["allRapidlyAccelerateCount"] = self.carData["event"]["threeRapid"]["totalRapidlyAccelerate"]
jdata["event"]["0011"]["allSharpSlowdownCount"] = self.carData["event"]["threeRapid"]["totalSharpSlowdown"]
jdata["event"]["0011"]["allSharpTurn"] = self.carData["event"]["threeRapid"]["totalSharpTurn"]
jdata["DEV_ID"] = self.carId
obj = EventReport_protocol(data=jdata)
gpsData = self.genGPSData2()
obj.setGPSPkg(gpsData)
obj.setEventType("0011")
msg = obj.generateEventMsg()
type = self.getMsgFunId(msg)
self.sendMsg(msg)
self.sn = self.sn + 1
self.websocket.sendMsgToClient(type + ">>>>:" + msg, self.websocketId)
sleep(0.1) sleep(0.1)
gpsMsg = self.genGPSMsg(self.gpsLine[gpsLineIndex]["lat"], self.gpsLine[gpsLineIndex]["lng"]) gpsMsg = self.genGPSMsg(self.gpsLine[gpsLineIndex]["lat"], self.gpsLine[gpsLineIndex]["lng"])
type = self.getMsgFunId(gpsMsg) type = self.getMsgFunId(gpsMsg)
......
...@@ -3,6 +3,7 @@ import json ...@@ -3,6 +3,7 @@ import json
import logging import logging
import threading import threading
import time import time
import traceback
from time import sleep from time import sleep
from lib.socket.SocketBase import SocketBase from lib.socket.SocketBase import SocketBase
...@@ -90,8 +91,8 @@ class Websocket_service(SocketBase): ...@@ -90,8 +91,8 @@ class Websocket_service(SocketBase):
#给指定客户端发送消息 #给指定客户端发送消息
def sendMsgToClient(self,msg,clientId): def sendMsgToClient(self,msg,clientId):
print(self.clients) # print(self.clients)
print(self.server) # print(self.server)
data = {} data = {}
data["code"] = "0002" data["code"] = "0002"
data["client"] = self.currentClient data["client"] = self.currentClient
...@@ -100,6 +101,7 @@ class Websocket_service(SocketBase): ...@@ -100,6 +101,7 @@ class Websocket_service(SocketBase):
self.server.send_message(self.clients[clientId],data) self.server.send_message(self.clients[clientId],data)
if __name__ == "__main__": if __name__ == "__main__":
w = Websocket_service() w = Websocket_service()
w.setHost("127.0.0.1") w.setHost("127.0.0.1")
......
...@@ -505,6 +505,8 @@ def sendRapidlyAccelerateEvent(): ...@@ -505,6 +505,8 @@ def sendRapidlyAccelerateEvent():
"0020": {"allRapidlyAccelerateCount": "5", "allSharpSlowdownCount": "6", "allSharpTurn": "4", "0020": {"allRapidlyAccelerateCount": "5", "allSharpSlowdownCount": "6", "allSharpTurn": "4",
"dataProperty": "1"}}} "dataProperty": "1"}}}
carData = service.getCarData() carData = service.getCarData()
carData["event"]["threeRapid"]["totalRapidlyAccelerate"] = carData["event"]["threeRapid"]["totalRapidlyAccelerate"] + 1
service.setCarData(carData)
jdata["event"]["0020"]["allRapidlyAccelerateCount"] = carData["event"]["threeRapid"]["totalRapidlyAccelerate"] jdata["event"]["0020"]["allRapidlyAccelerateCount"] = carData["event"]["threeRapid"]["totalRapidlyAccelerate"]
jdata["event"]["0020"]["allSharpSlowdownCount"] = carData["event"]["threeRapid"]["totalSharpSlowdown"] jdata["event"]["0020"]["allSharpSlowdownCount"] = carData["event"]["threeRapid"]["totalSharpSlowdown"]
jdata["event"]["0020"]["allSharpTurn"] = carData["event"]["threeRapid"]["totalSharpTurn"] jdata["event"]["0020"]["allSharpTurn"] = carData["event"]["threeRapid"]["totalSharpTurn"]
...@@ -516,8 +518,6 @@ def sendRapidlyAccelerateEvent(): ...@@ -516,8 +518,6 @@ def sendRapidlyAccelerateEvent():
msg = obj.generateEventMsg() msg = obj.generateEventMsg()
service.serviceSendMsg(msg, "急加速事件") service.serviceSendMsg(msg, "急加速事件")
service.setSn(service.getSn() + 1) 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:
...@@ -559,6 +559,8 @@ def sendSharpSlowdownEvent(): ...@@ -559,6 +559,8 @@ def sendSharpSlowdownEvent():
"0021": {"allRapidlyAccelerateCount": "5", "allSharpSlowdownCount": "6", "allSharpTurn": "4", "0021": {"allRapidlyAccelerateCount": "5", "allSharpSlowdownCount": "6", "allSharpTurn": "4",
"dataProperty": "1"}}} "dataProperty": "1"}}}
carData = service.getCarData() carData = service.getCarData()
carData["event"]["threeRapid"]["totalSharpSlowdown"] = carData["event"]["threeRapid"]["totalSharpSlowdown"] + 1
service.setCarData(carData)
jdata["event"]["0021"]["allRapidlyAccelerateCount"] = carData["event"]["threeRapid"]["totalRapidlyAccelerate"] jdata["event"]["0021"]["allRapidlyAccelerateCount"] = carData["event"]["threeRapid"]["totalRapidlyAccelerate"]
jdata["event"]["0021"]["allSharpSlowdownCount"] = carData["event"]["threeRapid"]["totalSharpSlowdown"] jdata["event"]["0021"]["allSharpSlowdownCount"] = carData["event"]["threeRapid"]["totalSharpSlowdown"]
jdata["event"]["0021"]["allSharpTurn"] = carData["event"]["threeRapid"]["totalSharpTurn"] jdata["event"]["0021"]["allSharpTurn"] = carData["event"]["threeRapid"]["totalSharpTurn"]
...@@ -570,8 +572,6 @@ def sendSharpSlowdownEvent(): ...@@ -570,8 +572,6 @@ def sendSharpSlowdownEvent():
msg = obj.generateEventMsg() msg = obj.generateEventMsg()
service.serviceSendMsg(msg, "急减速事件") service.serviceSendMsg(msg, "急减速事件")
service.setSn(service.getSn() + 1) service.setSn(service.getSn() + 1)
carData["event"]["threeRapid"]["totalSharpSlowdown"] = carData["event"]["threeRapid"]["totalSharpSlowdown"] + 1
service.setCarData(carData)
data["status"] = "200" data["status"] = "200"
data["message"] = "发送急减速事件成功!" data["message"] = "发送急减速事件成功!"
except BaseException as e: except BaseException as e:
...@@ -613,6 +613,8 @@ def sendSharpTurnEvent(): ...@@ -613,6 +613,8 @@ def sendSharpTurnEvent():
"0022": {"allRapidlyAccelerateCount": "5", "allSharpSlowdownCount": "6", "allSharpTurn": "4", "0022": {"allRapidlyAccelerateCount": "5", "allSharpSlowdownCount": "6", "allSharpTurn": "4",
"direction":"0","dataProperty": "1"}}} "direction":"0","dataProperty": "1"}}}
carData = service.getCarData() carData = service.getCarData()
carData["event"]["threeRapid"]["totalSharpTurn"] = carData["event"]["threeRapid"]["totalSharpTurn"] + 1
service.setCarData(carData)
jdata["event"]["0022"]["allRapidlyAccelerateCount"] = carData["event"]["threeRapid"]["totalRapidlyAccelerate"] jdata["event"]["0022"]["allRapidlyAccelerateCount"] = carData["event"]["threeRapid"]["totalRapidlyAccelerate"]
jdata["event"]["0022"]["allSharpSlowdownCount"] = carData["event"]["threeRapid"]["totalSharpSlowdown"] jdata["event"]["0022"]["allSharpSlowdownCount"] = carData["event"]["threeRapid"]["totalSharpSlowdown"]
jdata["event"]["0022"]["allSharpTurn"] = carData["event"]["threeRapid"]["totalSharpTurn"] jdata["event"]["0022"]["allSharpTurn"] = carData["event"]["threeRapid"]["totalSharpTurn"]
...@@ -624,8 +626,6 @@ def sendSharpTurnEvent(): ...@@ -624,8 +626,6 @@ def sendSharpTurnEvent():
msg = obj.generateEventMsg() msg = obj.generateEventMsg()
service.serviceSendMsg(msg, "急转弯事件") service.serviceSendMsg(msg, "急转弯事件")
service.setSn(service.getSn() + 1) service.setSn(service.getSn() + 1)
carData["event"]["threeRapid"]["totalSharpTurn"] = carData["event"]["threeRapid"]["totalSharpTurn"] + 1
service.setCarData(carData)
data["status"] = "200" data["status"] = "200"
data["message"] = "发送急转弯事件成功!" data["message"] = "发送急转弯事件成功!"
except BaseException as e: except BaseException as e:
......
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