Commit 6b298fda authored by liyuanhong's avatar liyuanhong

车安优模拟器增加了急加速、急减速等事件发送

parent e8f26810
[socket]
host = 10.16.11.95
port = 9007
host = 10.100.12.32
port = 9001
{"time": {"dateTime": "2020-05-21 16:00:39", "date": "2020-05-21", "time": "16:00:39"}, "curDayTravel": {"todayTotalMilleage": 0, "todayTotalOil": 0, "todayTotalTime": 0, "theMilleage": 0, "theOil": 0, "theTime": 0}, "travelData": {"totalMilleage": 6508, "totalOil": 508, "totalTime": 400}}
\ No newline at end of file
{"time": {"dateTime": "2020-05-28 14:37:12", "date": "2020-05-28", "time": "14:37:12"}, "curDayTravel": {"todayTotalMilleage": 4444, "todayTotalOil": 409, "todayTotalTime": 269, "theMilleage": 1980, "theOil": 180, "theTime": 120}, "travelData": {"totalMilleage": 10952, "totalOil": 917, "totalTime": 669}}
\ No newline at end of file
{"time": {"dateTime": "2020-05-21 18:38:02", "date": "2020-05-21", "time": "18:38:02"}, "curDayTravel": {"todayTotalMilleage": 996, "todayTotalOil": 96, "todayTotalTime": 60, "theMilleage": 996, "theOil": 96, "theTime": 60}, "travelData": {"totalMilleage": 329502, "totalOil": 31062, "totalTime": 19552}, "event": {"threeRapid": {"totalRapidlyAccelerate": 14, "totalSharpSlowdown": 13, "totalSharpTurn": 13}}}
\ No newline at end of file
{"time": {"dateTime": "2020-05-28 10:09:51", "date": "2020-05-28", "time": "10:09:51"}, "curDayTravel": {"todayTotalMilleage": 5491, "todayTotalOil": 421, "todayTotalTime": 338, "theMilleage": 1497, "theOil": 102, "theTime": 93}, "travelData": {"totalMilleage": 341804, "totalOil": 32099, "totalTime": 20303}, "event": {"threeRapid": {"totalRapidlyAccelerate": 19, "totalSharpSlowdown": 18, "totalSharpTurn": 17}}}
\ No newline at end of file
......@@ -270,6 +270,50 @@ class EventClass(ProtocolBase):
data += self.int2hexStringByBytes(30,2) #第N秒内的第N个0.5秒内的平均加速度值
return data
# 0027 超速报警
def overSpeedAlarm(self,alarmType=0,durTime=360):
alarmTypeHex = self.int2hexStringByBytes(alarmType)
durTimeHex = self.int2hexStringByBytes(durTime,2)
data = alarmTypeHex + durTimeHex
return data
# 0028 疲劳驾驶报警
def tiredDrivingAlarm(self,alarmType=1,durTime=11000):
alarmTypeHex = self.int2hexStringByBytes(alarmType)
durTimeHex = self.int2hexStringByBytes(durTime, 2)
data = alarmTypeHex + durTimeHex
return data
# 0030 水温报警
def waterTemperatureAlarm(self,alarmType=0,curWaterTemperature=80):
alarmTypeHex = self.int2hexStringByBytes(alarmType)
curWaterTemperatureHex = self.int2hexStringByBytes(curWaterTemperature)
data = alarmTypeHex + curWaterTemperatureHex
return data
# 0031低水温高转速报警附带信息
def lowWaterTemperatureHighEngineSpeed(self,alarmType=0,curWaterTemperature=10,engineSpeed=5000):
alarmTypeHex = self.int2hexStringByBytes(alarmType)
curWaterTemperatureHex = self.int2hexStringByBytes(curWaterTemperature)
engineSpeedHex = self.int2hexStringByBytes(engineSpeed,2)
data = alarmTypeHex + curWaterTemperatureHex + engineSpeedHex
return data
# 0032 怠速时间过长报警
def idlingOverTime(self,alarmType=0,durTime=300,oilExpend=500):
alarmTypeHex = self.int2hexStringByBytes(alarmType)
durTimeHex = self.int2hexStringByBytes(durTime,2)
oilExpendHex = self.int2hexStringByBytes(oilExpend,2)
data = alarmTypeHex + durTimeHex + oilExpendHex
return data
# 0033 高速空挡滑行报警附带信息
def highSpeedNeutralGearSlide(self,alarmType=0,durTime=30):
alarmTypeHex = self.int2hexStringByBytes(alarmType)
durTimeHex = self.int2hexStringByBytes(durTime)
data = alarmTypeHex + durTimeHex
return data
# 0036 低档高速报警附
def lowGearHighSpeedAlarm(self,alarmType=1,durationTime=10):
......
#encoding:utf-8
'''
定义终端请求OBD适配信息
'''
from lib.protocol.message.MessageBase import MessageBase
class TerminalRequestOBDInfo_msg(MessageBase):
def __init__(self):
super().__init__() #不执行该方法,无法使用父类里面定义的属性
pass
#######################################################
# 生成一条完整的消息
#######################################################
def generateMsg(self):
msg = ""
msgHeader = self.getMsgHeader()
msgBody = self.getMsgBody()
checkCode = self.getCheckCode(msgHeader + msgBody)
msg = msg + self.IDENTIFY
info = msgHeader + msgBody + checkCode
info = self.replace7e7d(info)
msg = msg + info
msg = msg + self.IDENTIFY
return msg
# 生成一条完整的消息,针对图形界面,可传递参数
def generateMsg_GUI(self,msgID="0206",phoneNum="13146201119",msgWaterCode=1,encryptionType=0,subPkg=0):
msg = ""
msgBody = self.getMsgBody()
msgHeader = self.getMsgHeader_GUI(msgID, phoneNum, msgWaterCode, encryptionType, subPkg,msgBody)
checkCode = self.getCheckCode(msgHeader + msgBody)
msg = msg + self.IDENTIFY
info = msgHeader + msgBody + checkCode
info = self.replace7e7d(info)
msg = msg + info
msg = msg + self.IDENTIFY
return msg
# 生成一条完整的消息,数据随机产生
def generateMsg_random(self):
msgID="0206"
phoneNum=self.getRandomStr(11,"0123456789")
msgWaterCode=self.getRandomNum(1,65535)
encryptionType=0
subPkg=self.getRandomNum(intArr=[0,8192],mult=1)
msg = ""
msgHeader = self.getMsgHeader_GUI(msgID, phoneNum, msgWaterCode, encryptionType, subPkg)
msgBody = self.getMsgBody()
checkCode = self.getCheckCode(msgHeader + msgBody)
msg = msg + self.IDENTIFY
info = msgHeader + msgBody + checkCode
info = self.replace7e7d(info)
msg = msg + info
msg = msg + self.IDENTIFY
return msg
#######################################################
# 获取消息体
#######################################################
def getMsgBody(self):
msg = ""
return msg
#######################################################
# 获取消息头
#######################################################
def getMsgHeader(self):
# msgID = self.int2hexStringByBytes(102,2) #消息id
msgID = "0206"
subPkg = 0
msgBodyProperty = self.getMsgBodyProperty(msgBodyLen=int(len(self.getMsgBody()) / 2),subPkg=subPkg) #消息体属性
phoneNum = self.int2BCD(13146201118) #终端手机号
msgWaterCode = self.int2hexStringByBytes(6,2) #消息流水号
if subPkg != 8192:
subPkgContent = "" #消息包封装项
else:
subPkgContent = self.getMsgPackage()
data = msgID + msgBodyProperty + phoneNum + msgWaterCode + subPkgContent
return data
#获取消息体属性
def getMsgBodyProperty(self,msgBodyLen=128,encryptionType=0,subPkg=0):
if msgBodyLen >= 512:
raise RuntimeError('消息体长度超长!')
msgBodyLen = msgBodyLen #消息体长度
encryptionType = encryptionType << 10 #加密方式
subPkg = subPkg << 13 #分包
retain = 0 #保留位
data = msgBodyLen + encryptionType + subPkg + retain
dataHex = self.int2hexStringByBytes(data,2)
return dataHex
#获取消息体属性,针对图形界面,可传递参数
def getMsgBodyProperty_GUI(self,msgBodyLen=128,encryptionType=0,subPkg=0):
if msgBodyLen >= 512:
raise RuntimeError('消息体长度超长!')
msgBodyLen = msgBodyLen #消息体长度
encryptionType = encryptionType #加密方式
subPkg = subPkg #分包
retain = 0 #保留位
data = msgBodyLen + encryptionType + subPkg + retain
dataHex = self.int2hexStringByBytes(data,2)
return dataHex
if __name__ == "__main__":
print(TerminalRequestOBDInfo_msg().generateMsg())
print(TerminalRequestOBDInfo_msg().getMsgBodyProperty())
\ No newline at end of file
......@@ -95,34 +95,38 @@ class TerminalVersionInfo_msg(MessageBase):
totalOilExpend = self.int2hexStringByBytes(420000,4) #装上终端后车辆累计总耗油量(ml)
displacement = self.int2hexStringByBytes(1500,2) #排量
oilDensity = self.int2hexStringByBytes(92,2) #油品密度
OBDSerial = "0101" #OBD协议编号
oilCalculateType = "01" #油耗计算方式
msg = msg + softwareVersion + softwareVersionDate + CPUId + GSMType + GSM_IMEI
msg = msg + SIM_IMSI + SIM_ICCID + carType + VIN + totalMileage
msg = msg + totalOilExpend + displacement + oilDensity
msg = msg + totalOilExpend + displacement + oilDensity + OBDSerial + oilCalculateType
return msg
# 生成一条完整的消息,针对图形界面,可传递参数
def getMsgBody_GUI(self,softwareVersion="KZP200_V201001",softwareVersionDate="2020-02-10",CPUId="CPU-12345678",GMSType="GMS-TYPE-123456",\
GMS_IMEI="GMS_IMEI_123456",SIM_IMSI="SIM_13146201119",SIM_ICCID="SIM_ICCID13146201119",carType=22,VIN="VIN_1234567891234",\
totalMileage=389000,totalOilExpend=420000,displacement=1500,oilDensity=92):
totalMileage=389000,totalOilExpend=420000,displacement=1500,oilDensity=92,OBDSerial="0101",oilCalculateType="01"):
msg = ""
softwareVersion = self.GBKString2Hex(softwareVersion) #软件版本号
softwareVersionDate = self.GBKString2Hex(softwareVersionDate) #终端版本日期
CPUId = self.str2Hex(CPUId) #cpuId
GMSType = self.GBKString2Hex(GMSType) #GMS型号
GMS_IMEI = self.GBKString2Hex(GMS_IMEI) #GSM IMEI 号
SIM_IMSI = self.GBKString2Hex(SIM_IMSI) #终端 SIM 卡 IMSI 号
SIM_ICCID = self.GBKString2Hex(SIM_ICCID) #终端 SIM 卡 ICCID 号
carType = self.int2hexStringByBytes(carType,2) #车系车型 ID
VIN = self.GBKString2Hex(VIN) #汽车 VIN 码
totalMileage = self.int2hexStringByBytes(totalMileage,4) #装上终端后车辆累计总里程或车辆仪表里程(单位米)
softwareVersion = self.GBKString2Hex(softwareVersion) #软件版本号
softwareVersionDate = self.GBKString2Hex(softwareVersionDate) #终端版本日期
CPUId = self.str2Hex(CPUId) #cpuId
GMSType = self.GBKString2Hex(GMSType) #GMS型号
GMS_IMEI = self.GBKString2Hex(GMS_IMEI) #GSM IMEI 号
SIM_IMSI = self.GBKString2Hex(SIM_IMSI) #终端 SIM 卡 IMSI 号
SIM_ICCID = self.GBKString2Hex(SIM_ICCID) #终端 SIM 卡 ICCID 号
carType = self.int2hexStringByBytes(carType,2) #车系车型 ID
VIN = self.GBKString2Hex(VIN) #汽车 VIN 码
totalMileage = self.int2hexStringByBytes(totalMileage,4) #装上终端后车辆累计总里程或车辆仪表里程(单位米)
totalOilExpend = self.int2hexStringByBytes(totalOilExpend,4) #装上终端后车辆累计总耗油量(ml)
displacement = self.int2hexStringByBytes(displacement,2) #排量
oilDensity = self.int2hexStringByBytes(oilDensity,2) #油密度
OBDSerial = OBDSerial #OBD协议编号
oilCalculateType = oilCalculateType #油耗计算方式
msg = msg + softwareVersion + softwareVersionDate + CPUId + GMSType + GMS_IMEI
msg = msg + SIM_IMSI + SIM_ICCID + carType + VIN + totalMileage
msg = msg + totalOilExpend + displacement + oilDensity
msg = msg + totalOilExpend + displacement + oilDensity + OBDSerial + oilCalculateType
return msg
#######################################################
......
......@@ -341,35 +341,35 @@ class AlarmEvent_data(MessageBase):
# 获取水温报警附带信息
#####################################################
def getWaterTemperatureAlarm(self):
#报警属性 1 BYTE 1:报警触发(无下面的数据内容项) 0:报警解除(有下面的数据内容项)
# 报警属性 1 BYTE 1:报警触发(无下面的数据内容项) 0:报警解除(有下面的数据内容项)
alarmType = self.int2hexStringByBytes(1)
#持续时长 4 DWORD 单位秒
# 持续时长 4 DWORD 单位秒
timeOfDuration = self.int2hexStringByBytes(11000,4)
#最高温度 2 WORD 单位 0.1 度
# 最高温度 2 WORD 单位 0.1 度
maxTemperature = self.int2hexStringByBytes(700,2)
#平均温度 2 WORD 单位 0.1 度
# 平均温度 2 WORD 单位 0.1 度
averageTemperature = self.int2hexStringByBytes(55,2)
data = alarmType + timeOfDuration + maxTemperature + averageTemperature
return data
def getWaterTemperatureAlarm_GUI(self,data):
#报警属性 1 BYTE 1:报警触发(无下面的数据内容项) 0:报警解除(有下面的数据内容项)
# 报警属性 1 BYTE 1:报警触发(无下面的数据内容项) 0:报警解除(有下面的数据内容项)
alarmType = self.int2hexStringByBytes(int(data["alarmType"]))
#持续时长 4 DWORD 单位秒
# 持续时长 4 DWORD 单位秒
timeOfDuration = self.int2hexStringByBytes(int(data["timeOfDuration"]),4)
#最高温度 2 WORD 单位 0.1 度
# 最高温度 2 WORD 单位 0.1 度
maxTemperature = self.int2hexStringByBytes(int(data["maxTemperature"]),2)
#平均温度 2 WORD 单位 0.1 度
# 平均温度 2 WORD 单位 0.1 度
averageTemperature = self.int2hexStringByBytes(int(data["averageTemperature"]),2)
data = alarmType + timeOfDuration + maxTemperature + averageTemperature
return data
def getWaterTemperatureAlarm_random(self):
#报警属性 1 BYTE 1:报警触发(无下面的数据内容项) 0:报警解除(有下面的数据内容项)
# 报警属性 1 BYTE 1:报警触发(无下面的数据内容项) 0:报警解除(有下面的数据内容项)
alarmType = self.int2hexStringByBytes(self.getRandomNum(intArr=[0,1]))
#持续时长 4 DWORD 单位秒
# 持续时长 4 DWORD 单位秒
timeOfDuration = self.int2hexStringByBytes(self.getRandomNum(0,2147483648),4)
#最高温度 2 WORD 单位 0.1 度
# 最高温度 2 WORD 单位 0.1 度
maxTemperature = self.int2hexStringByBytes(self.getRandomNum(0,2500),2)
#平均温度 2 WORD 单位 0.1 度
# 平均温度 2 WORD 单位 0.1 度
averageTemperature = self.int2hexStringByBytes(self.getRandomNum(0,1500),2)
data = alarmType + timeOfDuration + maxTemperature + averageTemperature
return data
......
......@@ -149,11 +149,11 @@ class QueryTheTerminalParam_res(MessageBase,ResponseBase):
data = data + "00000017" + self.int2hexStringByBytes(int(len(content) / 2)) + content
paramNums = paramNums + 1
if "00000018" in queryParams:
content = self.str2Hex("9001")
content = self.int2hexStringByBytes(9001,4)
data = data + "00000018" + self.int2hexStringByBytes(int(len(content) / 2)) + content
paramNums = paramNums + 1
if "00000019" in queryParams:
content = self.str2Hex("9002")
content = self.int2hexStringByBytes(9002,4)
data = data + "00000019" + self.int2hexStringByBytes(int(len(content) / 2)) + content
paramNums = paramNums + 1
paramNums = self.int2hexStringByBytes(paramNums)
......
......@@ -76,12 +76,14 @@ class PlatefromVersionInfo_res(ResponseBase):
carId = self.hexString2int(body[12:16]) #车型id
displacement = self.hexString2int(body[16:20]) #排量
isUpdate = body[20:22] #是否升级,0x55 升级,其他不升级
oilDensity = self.hexString2int(body[22:]) #油密度
oilDensity = self.hexString2int(body[22:26]) #油密度
OBDCtrType = self.hexString2int(body[26:]) >> 7
json_body["plateformCurrentTime"] = plateformCurrentTime
json_body["carId"] = carId
json_body["displacement"] = displacement
json_body["isUpdate"] = isUpdate
json_body["oilDensity"] = oilDensity
json_body["OBDCtrType"] = OBDCtrType
return json_body
#######################################################
......
......@@ -13,7 +13,7 @@ from lib.protocol.report.SecurityStatusReport_protocol import SecurityStatusRepo
class EventReport_protocol(ProtocolBase):
#data = {"WATER_CODE":"0003","DEV_ID":"M121501010001","gpsInfo":{"UTCTime":"2020-04-14 11:03:20","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":"1586833400"},"securityData":{"securityStatus":107,"doorStatus":0,"lockStatus":0,"windowStatus":0,"lightStatus":0,"onoffStatusA":0,"onoffStatusB":112,"dataByte":249},"event":{}}
data = {}
def __init__(self,msgCount = 1,WATER_CODE = 26,DEV_ID = "M121501010001",locationType=1,eventType="0023",data={}):
def __init__(self,msgCount = 1,WATER_CODE = 26,DEV_ID = "M202003060520",locationType=1,eventType="0030",data={}):
super().__init__()
self.data = data
if len(data) == 0:
......@@ -24,7 +24,12 @@ class EventReport_protocol(ProtocolBase):
self.locationType = int(locationType) # 定位类型
#self.GPSPkg = GPSpkg & BaseStationPkg # GPS包或者基站包
self.GPSPkg = "1401091213260265b86206ed8c70026103280000752f03030405af017102610bb800003200000186a0001ed2a25e16fe3a"
timeStamp = time.time()
timeArray = time.localtime(int(timeStamp - 8 * 3600))
dateTimeM = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
timeHex = self.getUTCTime(dateTimeM)
self.GPSPkg = timeHex + "0265b86206ed8c70026103280000752f03030405af017102610bb800003200000186a0001ed2a25e16fe3a"
# self.GPSPkg = "1401091213260265b86206ed8c70026103280000752f03030405af017102610bb800003200000186a0001ed2a25e16fe3a"
self.BaseStationPkg = "1401140a0c050207e407e607e807ea07ec4eea4eec4eee4ef04efc4efe4f004f024f040024025e07d00007a125000927c60000ea610100"
self.eventType = eventType #事件类别
else:
......@@ -196,6 +201,18 @@ class EventReport_protocol(ProtocolBase):
return EventClass().defencesIllegalCloseDoorExtraInfo()
elif eventType == "0023": #碰撞告警
return EventClass().collisionAlarmExtraInfo()
elif eventType == "0027": #超速报警
return EventClass().overSpeedAlarm()
elif eventType == "0028": #疲劳驾驶报警
return EventClass().tiredDrivingAlarm()
elif eventType == "0030": #水温报警
return EventClass().waterTemperatureAlarm()
elif eventType == "0031": #低水温高转速报警
return EventClass().lowWaterTemperatureHighEngineSpeed()
elif eventType == "0032": #怠速时间过长报警
return EventClass().idlingOverTime()
elif eventType == "0033": #高速空挡滑行报警
return EventClass().highSpeedNeutralGearSlide()
elif eventType == "0036": #低档高速报警
return EventClass().lowGearHighSpeedAlarm()
elif eventType == "0037": #高档低速报警
......@@ -290,6 +307,28 @@ class EventReport_protocol(ProtocolBase):
data = data + "004A" + self.int2hexStringByBytes(int((len(theData) / 2)), 2) + theData
return data
#####################################################
# 将UTC时间转换为16进制,
# 例如:2020-01-02 20:30:00 (年取后面2字节)则将20,01,02,20,30,00 转换为对应的6个字节
# theTime:传入一个类似:2020-01-03 13:05:13的一个字符串
#####################################################
def getUTCTime(self,theTime):
# 获取当前时间,时间格式为:2020-01-03 13:05:13
# now_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
# 将2020-01-03 13:05:13时间格式转换为一个数组
# timeStr = "2020-01-03 13:05:13"
timeStr = theTime
timeArr = []
timeArr.append(timeStr[2:4])
timeArr.append(timeStr[5:7])
timeArr.append(timeStr[8:11])
timeArr.append(timeStr[11:13])
timeArr.append(timeStr[14:16])
timeArr.append(timeStr[17:19])
UTCTime = ""
for i in range(0, len(timeArr)):
UTCTime += self.int2hexString(int(timeArr[i]))
return UTCTime
if __name__ == "__main__":
data = {"a":1,"b":2,"c":{"d":3}}
......
......@@ -198,4 +198,4 @@ if __name__ == "__main__":
# print(ProtocolBase().hex2UTCTime("1401030d050d"))
# print(ProtocolBase().hex2UTCTime("14020a07122b"))
# print(ProtocolBase().crc16("4040007000064d20191201000200120114030503202d26d7fffff0000000000505000000143c00000bb80100000fa00000000a0000000000005e60723b723b39331e100055320000001312001007d0001e0000000000000096000000280096ffff3e0001f40000003e0000000000000000000000"))
# print(ProtocolBase().myCrc16("4040007000064d20191201000200120114030503202d26d7fffff0000000000505000000143c00000bb80100000fa00000000a0000000000005e60723b723b39331e100055320000001312001007d0001e0000000000000096000000280096ffff3e0001f40000003e0000000000000000000000"))
# print(ProtocolBase().myCrc16("4040007000064d20191201000200120114030503202d26d7fffff0000000000505000000143c00000bb80100000fa00000000a0000000000005e60723b723b39331e100055320000001312001007d0001e0000000000000096000000280096ffff3e0001f40000003e0000000000000000000000"))
\ No newline at end of file
......@@ -110,5 +110,6 @@ class ResponseBase(Base):
if __name__ == "__main__":
print(ResponseBase().hexDate2date("01c329ed065"))
print(ResponseBase().hexTimestamp2date("5e60723b"))
print(ResponseBase().hex2string("4d3530304142303330332e303130302c3131312e31302e32342e3133312c32312c7673742c767374323031332c4d3530304142303330332e303130302e42494e2c"))
......@@ -29,10 +29,10 @@ port = 9001
# msg = TerminalRegister_msg().generateMsg() #终端注册
# msg = TerminalCancle_msg().generateMsg() #终端注销
# msg = TerminalAuthenticate_msg().generateMsg() #终端鉴权
# msg = TerminalVersionInfo_msg().generateMsg() #终端版本信息上报
msg = TerminalVersionInfo_msg().generateMsg() #终端版本信息上报
# msg = QueryTerminalParam_res().generateMsg() #查询终端参数应答
# msg = QueryTerminalProperty_res().generateMsg() #查询终端属性应答消息
msg = Location_msg().generateMsg() #位置信息汇报
# msg = Location_msg().generateMsg() #位置信息汇报
# msg = DataUpstreamTransport_msg().generateMsg() #数据上行透传消息
# msg = TerminalUpdataResult_msg().generateMsg() #终端升级结果通知
# msg = LocationDataBatchUpdate_msg().generateMsg() #定位数据批量上传
......@@ -68,8 +68,8 @@ def sendSingleMsg(msg):
print(data)
print(PlatformCommon_res(data).getOriginalMsg())
print(PlatformCommon_res(data).getMsg()) #解析平台通用应答消息
# print(TerminalRegister_res(data).getMsg()) #解析终端注册应答消息
# print(PlatefromVersionInfo_res(data).getMsg()) #解析平台版本信息包上传应答
print(TerminalRegister_res(data).getMsg()) #解析终端注册应答消息
print(PlatefromVersionInfo_res(data).getMsg()) #解析平台版本信息包上传应答
client.close()
def closeSocket(soc):
......
......@@ -34,7 +34,7 @@ port = 9008
# host = "10.100.5.251"
# port = 9008
msg = GPSReport_protocol().generateGpsMsg() #GPS消息数据
# msg = GPSReport_protocol().generateGpsMsg() #GPS消息数据
# msg = OBDReport_protocol().generateOBDReportMsg() #OBD终端上报数据
# msg = OBDReport_CAN_protocol().generateOBDReportCANMsg() #OBD终端上报CAN数据
# msg = HeartBeatReport_protocol().generateHeartBeatMsg() #终端上报心跳协议
......@@ -42,7 +42,7 @@ msg = GPSReport_protocol().generateGpsMsg() #GPS消息
# msg = SecurityStatusReport_protocol().generateSecurityStatusMsg() #终端上报安防状态协议
# msg = BaseStationReport_protocol().generateBaseStationMsg() #终端上报基站定位协议
# msg = TroubleReport_protocol().generateTroubleMsg() #终端上报故障码数据包
# msg = EventReport_protocol().generateEventMsg() #终端上报事件数据包
msg = EventReport_protocol().generateEventMsg() #终端上报事件数据包
# msg = VersionReport_protocol().generateVersionMsg() #终端上报版本信息数据包
# msg = SleepReport_protocol().generateSleepMsg() #终端休眠数据包
# msg = CommonReport_protocol().generateCommonMsg() #通用应答消息
......
......@@ -13,10 +13,11 @@ import traceback
from time import sleep
from lib.protocol.message.Location_msg import Location_msg
from lib.protocol.message.TerminalCommonMsgRes_msg import TerminalCommonMsgRes_msg
from lib.protocol.message.TerminalRegister_msg import TerminalRegister_msg
from lib.protocol.message.TerminalRequestOBDInfo_msg import TerminalRequestOBDInfo_msg
from lib.protocol.message.TerminalVersionInfo_msg import TerminalVersionInfo_msg
from lib.protocol.message.response.QueryTheTerminalParam_res import QueryTheTerminalParam_res
from lib.protocol.messagePlateform.PlateformVersionInfo_res import PlatefromVersionInfo_res
from lib.socket.service.MessageSimulaterDataService import MessageSimulaterDataService
from lib.socket.service.websocket_service import Websocket_service
......@@ -60,6 +61,16 @@ class MessageSimulaterService():
"60C0": "3000", "60D0": "60", "62f0": "801", "60F0": "88", "60B0": "20", "60A0": "276",
"61F0": "3700", "60E0": "154", "670a": "3700000"}}}
def getSn(self):
return self.sn
def getWebsocket(self):
return self.websocket
def getTravelStatus(self):
return self.travelStatus
#设置套接字
def setSocket(self,data):
self.socket = data
......@@ -74,10 +85,14 @@ class MessageSimulaterService():
def setWebsocketId(self):
sleep(0.1)
self.websocketId = self.websocket.getCurrentClientId()
def getWebsocket(self):
return self.websocket
def setWebsocket(self,data):
self.websocket = data
def setSn(self,data):
self.sn = data
def getCurLatitude(self):
return self.gpsLine[self.gpsLineIndex]["lat"]
def getCurLongtitude(self):
return self.gpsLine[self.gpsLineIndex]["lng"]
def sendMsg(self,msg):
......@@ -410,7 +425,6 @@ class MessageSimulaterService():
d = str(binascii.b2a_hex(d))[2:][:-1]
type = self.getMsgFunId(d)
info = type + "<<<<:" + d
time.sleep(0.5)
self.websocket.sendMsgToClient(info,self.websocketId)
self.doResponse(d)
......@@ -470,10 +484,19 @@ class MessageSimulaterService():
self.sn = self.sn + 1
type = self.getMsgFunId(msg)
self.websocket.send(type + ">>>>查询终端参数消息应答:" + msg)
elif msgFunId == "8205":
dic = PlatefromVersionInfo_res(msg).getMsg()
OBDCtrType = int(json.loads(dic)["body"]["OBDCtrType"])
if OBDCtrType == 0:
obj = TerminalRequestOBDInfo_msg()
msg = obj.generateMsg_GUI(phoneNum=self.carId,msgWaterCode=self.sn)
self.sendMsg(msg)
self.sn = self.sn + 1
type = self.getMsgFunId(msg)
self.websocket.send(type + ">>>>终端请求OBD适配信息:" + msg)
elif msgFunId == "8206":
pass
#设置GPS轨迹
def setGpsLine(self,fileName):
with open("data/messageTools/GPSLines/" + fileName,"r",encoding="utf-8") as fi:
......
......@@ -125,6 +125,36 @@
<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="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>-->
</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="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>-->
</div>
</div>
</div>
<div style="width:100%;padding-bottom:60px;border-bottom: 1px solid #eee;">
<h3>日志:</h3>
<textarea id="showFeedback" style="width:100%;padding:5px;padding-bottom:60px;" rows="10"></textarea>
......@@ -599,5 +629,92 @@ function getAllUsers(){
}
});
})()
// -------------------------------- 事件控制js代码-------------------------------------------
//设置隐藏或显示事件控制区域
function isShowEventArea(e){
var value = $(e).val()
if(value == "0"){
$("#event_area").css("display","none")
}else{
$("#event_area").css("display","block")
}
}
//事件的选择与取消选择
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") == "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") == "insertAlarm_check"){
$("#insertAlarm_button").css("display","none")
}else if($(e).attr("id") == "lowVoltage_check"){
$("#lowVoltage_button").css("display","none")
}else 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")
}
}
}
//发送终端插入报警
function sendInsertAlarmEvent(){
var data = getPageData();
var host = window.location.host;
var url = "http://" + host + "/messageTools/M_simulater_process/sendTerminalInsertAlarm";
sendHttpMsg(data,url);
}
//发送低电压报警
function sendLowVoltageEvent(){
var data = getPageData();
var host = window.location.host;
var url = "http://" + host + "/messageTools/M_simulater_process/sendLowVoltageAlarm";
sendHttpMsg(data,url);
}
//发送急加速事件消息
function sendRapidlyAccelerateEvent(){
var data = getPageData();
var host = window.location.host;
var url = "http://" + host + "/messageTools/M_simulater_process/sendRapidAccelerateAlarm";
sendHttpMsg(data,url);
}
//发送急减速事件消息
function sendSharpSlowdownEvent(){
var data = getPageData();
var host = window.location.host;
var url = "http://" + host + "/messageTools/M_simulater_process/sendSharpSlowdownAlarm";
sendHttpMsg(data,url);
}
</script>
{% endblock %}
\ No newline at end of file
......@@ -630,18 +630,6 @@ function getAllUsers(){
});
})()
// -------------------------------- 实时控制js代码-------------------------------------------
//设置隐藏或显示实时控制区域
function isShowRealTimeCtrArea(e){
var value = $(e).val()
if(value == "0"){
$("#realTimeCtl_area").css("display","none")
}else{
$("#realTimeCtl_area").css("display","block")
}
}
// -------------------------------- 事件控制js代码-------------------------------------------
//设置隐藏或显示事件控制区域
function isShowEventArea(e){
......@@ -783,6 +771,15 @@ function sendSurplusOilAlarmEvent(){
}
// -------------------------------- 实时控制js代码-------------------------------------------
//设置隐藏或显示实时控制区域
function isShowRealTimeCtrArea(e){
var value = $(e).val()
if(value == "0"){
$("#realTimeCtl_area").css("display","none")
}else{
$("#realTimeCtl_area").css("display","block")
}
}
//改变车速
function changeSpeed(){
var data = {}
......
This diff is collapsed.
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