Commit 189f96aa authored by liyuanhong's avatar liyuanhong

完成GPS随机数据参数以及部分附加信息随机产生

parent 0d9b38ea
#模拟程序说明文档
####(一)、框架结构说明
\ No newline at end of file
......@@ -4,6 +4,7 @@
定义位置信息汇报消息
'''
import datetime
from random import random
from lib.protocol.message.MessageBase import MessageBase
from lib.protocol.message.data.AlarmEvent_data import AlarmEvent_data
......@@ -34,6 +35,37 @@ class Location_msg(MessageBase):
msg = msg + self.IDENTIFY
return msg
# 生成一条完整的消息,针对图形界面,可传递参数
def generateMsg_GUI(self,msgID="0200",phoneNum="13146201119",msgWaterCode=1,encryptionType=0,subPkg=0, \
):
msg = ""
msgHeader = self.getMsgHeader_GUI(msgID,phoneNum,msgWaterCode,encryptionType,subPkg)
msgBody = self.getMsgBody_GUI()
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):
msg = ""
msgID = "0200"
phoneNum = self.getRandomStr(11, "0123456789")
msgWaterCode = self.getRandomNum(1, 65535)
encryptionType = 0
subPkg = self.getRandomNum(intArr=[0, 8192])
msgHeader = self.getMsgHeader_GUI(msgID,phoneNum,msgWaterCode,encryptionType,subPkg)
msgBody = self.getMsgBody_random()
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
#######################################################
# 获取消息体
#######################################################
......@@ -44,6 +76,21 @@ class Location_msg(MessageBase):
msg = locationBaseInfo + locationExtraInfo
return msg
# 获取消息体,针对图形界面,可传递参数
def getMsgBody_GUI(self,baseInfo,extraInfo):
msg = ""
locationBaseInfo = self.getLocationBaseInfo(baseInfo) #位置基本信息
locationExtraInfo = self.getLocationExtraInfo(extraInfo) #位置附加信息
msg = locationBaseInfo + locationExtraInfo
return msg
# 获取消息体,数据随机产生
def getMsgBody_random(self):
msg = ""
locationBaseInfo = self.getLocationBaseInfo_random() #位置基本信息
locationExtraInfo = self.getLocationExtraInfo_random() #位置附加信息
msg = locationBaseInfo + locationExtraInfo
return msg
#######################################################
# 获取位置基本信息
#######################################################
......@@ -61,6 +108,36 @@ class Location_msg(MessageBase):
msg = alarmFlag + status + latitude + longtitude + elevation + speed + directionAngle + infoTime
return msg
# 获取位置基本信息,针对图形界面,可传递参数
def getLocationBaseInfo_GUI(self,baseInfo):
msg = ""
alarmFlag = self.int2hexStringByBytes(baseInfo["alarmFlag"],4) #报警标志
status = self.int2hexStringByBytes(baseInfo["status"],4) #状态
latitude = self.getLatitude(baseInfo["latitude"]) #纬度
longtitude = self.getLongtitude(baseInfo["longtitude"]) #经度
elevation = self.getElevation(baseInfo["elevation"]) #海拔高度
speed = self.getSpeed(baseInfo["speed"]) #速度
directionAngle = self.getDirectionAngle(baseInfo["directionAngle"]) #获取方向角度
infoTime = self.getInfoTime(baseInfo["infoTime"]) #获取时间
msg = alarmFlag + status + latitude + longtitude + elevation + speed + directionAngle + infoTime
return msg
# 获取位置基本信息,数据随机产生
def getLocationBaseInfo_random(self):
msg = ""
alarmFlag = self.int2hexStringByBytes(self.getRandomNum(intArr=[0,1,2,4,8,16,32,64, \
128,256,512,1024,2048,4096,8192,16384,262144,524288,1048576,2097152,4194304, \
8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648],mult=29),4) #报警标志
status = self.int2hexStringByBytes(self.getRandomNum(intArr=[0,1,2,4,8,16,32,256, \
512,768,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152],mult=21),4) #状态
latitude = self.getLatitude(self.getRandomNum(s=0,e=90000000) / 1000000) #纬度
longtitude = self.getLongtitude(self.getRandomNum(s=0,e=180000000) / 1000000) #经度
elevation = self.getElevation(self.getRandomNum(s=0,e=6000)) #海拔高度
speed = self.getSpeed(self.getRandomNum(s=0,e=150)) #速度
directionAngle = self.getDirectionAngle(self.getRandomNum(s=0,e=359)) #获取方向角度
infoTime = self.getInfoTime(self.getRandomDate()) #获取时间
msg = alarmFlag + status + latitude + longtitude + elevation + speed + directionAngle + infoTime
return msg
#######################################################
# 获取位置附加信息
#######################################################
......@@ -96,7 +173,6 @@ class Location_msg(MessageBase):
extra_FA = "FA" + self.int2hexStringByBytes(int(len(AlarmEvent_data().generateAlarmEvent_data()) / 2)) + AlarmEvent_data().generateAlarmEvent_data()
# data = extra_01 + extra_02 + extra_11 + extra_31 + extra_EA + extra_EB + extra_FA
print(extra_11)
data = extra_11 + extra_31 + extra_EA + extra_EB
# data = extra_01 + extra_02 + extra_11 + extra_12 + extra_13
......@@ -104,6 +180,60 @@ class Location_msg(MessageBase):
# data = data +extra_FA
return data
# 获取位置附加信息,数据随机产生
def getLocationExtraInfo_random(self):
data = ""
# 里程,DWORD,1 / 10km,对应车上里程表读数;不支持OBD时,为基于GPS车速统计的车辆累计行驶总里程。
extra_01 = "01" + self.int2hexStringByBytes(4) + self.int2hexStringByBytes(self.getRandomNum(0,4294967295),4)
#油量,WORD,1/10L,对应车上油量表读数
extra_02 = "02" + self.int2hexStringByBytes(2) + self.int2hexStringByBytes(self.getRandomNum(0,65535),2)
#超速报警附加信息
extra_11 = "11" + self.int2hexStringByBytes(int(len(self.getOverSpeedAlarmExtraInfo_random()) / 2)) + self.getOverSpeedAlarmExtraInfo_random()
#进出区域/路线报警附加信息见
extra_12 = "12" + self.int2hexStringByBytes(6) + self.getInOutAreaAlarmExtraInfo_random()
#路段行驶时间不足/过长报警附加信息见
extra_13 = "13" + self.int2hexStringByBytes(7) + self.getDrivingLongOrShortAlarmExtraInfo_ramdom()
#IO 状态位
extra_2A = "2A" + self.int2hexStringByBytes(2) + self.getStatusBit_random()
#BYTE,无线通信网络信号强度
extra_30 = "30" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(self.getRandomNum(0,255))
#BYTE,GNSS 定位卫星数
extra_31 = "31" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(self.getRandomNum(0,255))
#基础数据项列表
extra_EA = "EA" + self.int2hexStringByBytes(int(len(self.getBaseDataList()) / 2)) + self.getBaseDataList()
#轿车 OBD 数据流
extra_EB = "EB" + self.int2hexStringByBytes(int(len(SaloonCarOBD_data().generateSaloonCarOBDData()) / 2)) + SaloonCarOBD_data().generateSaloonCarOBDData()
#货车 OBD 数据流
# extra_EC = "EC" + self.int2hexStringByBytes(int(len(TruckCarOBD_data().generateTruckCarOBD_data()) / 2)) + TruckCarOBD_data().generateTruckCarOBD_data()
#新能源 OBD 数据流
# extra_ED = "ED" + self.int2hexStringByBytes(int(len(NewEnergyCar_data().generateNewEnergyCar_data()) / 2)) + NewEnergyCar_data().generateNewEnergyCar_data()
#外设数据项列表
# extra_EE = "EE" + self.int2hexStringByBytes(int(len(Circum_data().generateCircum_data()) / 2)) + Circum_data().generateCircum_data()
#报警事件 ID 数据项列表
extra_FA = "FA" + self.int2hexStringByBytes(int(len(AlarmEvent_data().generateAlarmEvent_data()) / 2)) + AlarmEvent_data().generateAlarmEvent_data()
arr = []
arr.append(extra_01)
arr.append(extra_02)
arr.append(extra_11)
arr.append(extra_12)
arr.append(extra_13)
arr.append(extra_2A)
arr.append(extra_30)
arr.append(extra_31)
arr.append(extra_EA)
arr.append(extra_EB)
arr.append(extra_FA)
mult = self.getRandomNum(0,11)
temp = []
for i in range(0, mult):
con = self.getRandomNum(intArr=arr,mult=1)
if con in temp:
con = ""
temp.append(con)
data = data + con
return data
#获取超速报警附加信息
def getOverSpeedAlarmExtraInfo(self):
......@@ -120,6 +250,16 @@ class Location_msg(MessageBase):
areaId = self.int2hexStringByBytes(2020,4)
msg = self.int2hexStringByBytes(locationType) + areaId
return msg
#获取超速报警附加信息,数据随机产生
def getOverSpeedAlarmExtraInfo_random(self):
locationType = self.getRandomNum(intArr=[0,1,2,3,4])
areaId = "" #若位置类型为 0,无该字段
if locationType == 0:
pass
else:
areaId = self.int2hexStringByBytes(self.getRandomNum(0,4294967295),4)
msg = self.int2hexStringByBytes(locationType) + areaId
return msg
#获取进出区域/路线报警附加信息
def getInOutAreaAlarmExtraInfo(self):
......@@ -137,6 +277,17 @@ class Location_msg(MessageBase):
direction = 0 #0-进,1-出
msg = self.int2hexStringByBytes(locationType) + areaId + self.int2hexStringByBytes(direction)
return msg
#获取进出区域/路线报警附加信息,数据随机参数
def getInOutAreaAlarmExtraInfo_random(self):
locationType = self.getRandomNum(intArr=[0,1,2,3,4])
areaId = ""
if locationType == 0:
areaId = "00000000"
else:
areaId = self.int2hexStringByBytes(self.getRandomNum(1,4294967295), 4)
direction = self.getRandomNum(intArr=[0,1]) #0-进,1-出
msg = self.int2hexStringByBytes(locationType) + areaId + self.int2hexStringByBytes(direction)
return msg
#路线行驶时间不足/过长报警附加信息消息
def getDrivingLongOrShortAlarmExtraInfo(self):
......@@ -145,6 +296,13 @@ class Location_msg(MessageBase):
result = self.int2hexStringByBytes(0) #结果,0-不足,1-过长
msg = areaId + drivingTime + result
return msg
#路线行驶时间不足/过长报警附加信息消息,数据随机产生
def getDrivingLongOrShortAlarmExtraInfo_ramdom(self):
areaId = self.int2hexStringByBytes(self.getRandomNum(0,4294967295), 4) #路段Id
drivingTime = self.int2hexStringByBytes(self.getRandomNum(0,65535),2) #路段行驶时间(单位:秒)
result = self.int2hexStringByBytes(self.getRandomNum(intArr=[0,1])) #结果,0-不足,1-过长
msg = areaId + drivingTime + result
return msg
#获取状态位
def getStatusBit(self):
......@@ -154,6 +312,10 @@ class Location_msg(MessageBase):
data = deepSleepStatus + sleepStatus + retain
dataHex = self.int2hexStringByBytes(data,2)
return dataHex
#获取状态位,数据随机产生
def getStatusBit_random(self):
dataHex = self.int2hexStringByBytes(self.getRandomNum(intArr=[0,1,2],mult=2),2)
return dataHex
#基础数据项列表
def getBaseDataList(self):
......@@ -178,6 +340,42 @@ class Location_msg(MessageBase):
data = data + dataId_0006 + dataId_0007 + dataId_0010 + dataId_0011 + dataId_0012
data = data + dataId_0013 + dataId_001D
return data
#基础数据项列表,数据随机产生
def getBaseDataList_random(self):
dataId_0001 = "0001" + self.int2hexStringByBytes(4) + self.getExpandStatusBit_random()
dataId_0002 = "0002" + self.int2hexStringByBytes(4) + self.getExpandAlarmBit_random()
dataId_0003 = "0003" + self.int2hexStringByBytes(5) + self.getTotalMileage_random()
dataId_0004 = "0004" + self.int2hexStringByBytes(5) + self.getTotalOil_random()
dataId_0005 = "0005" + self.int2hexStringByBytes(4) + self.int2hexStringByBytes(self.getRandomNum(0,4294967295),4)
dataId_0006 = "0006" + self.int2hexStringByBytes(4) + self.int2hexStringByBytes(self.getRandomNum(0,4294967295),4)
dataId_0007 = "0007" + self.int2hexStringByBytes(4) + self.int2hexStringByBytes(self.getRandomNum(0,4294967295),4)
dataId_0010 = "0010" + self.int2hexStringByBytes(int(len(self.getSpeedupInOneSeconds_random()) / 2)) + self.getSpeedupInOneSeconds_random()
dataId_0011 = "0011" + self.int2hexStringByBytes(int(len(CarSafeStatusInfo().generateSecurityStatusData_random()) / 2)) + CarSafeStatusInfo().generateSecurityStatusData_random()
dataId_0012 = "0012" + self.int2hexStringByBytes(2) + self.int2hexStringByBytes(self.getRandomNum(0,65535),2)
dataId_0013 = "0013" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(self.getRandomNum(0,255))
dataId_001D = "001D" + self.int2hexStringByBytes(1) + self.getRandomNum(intArr=["00","01","02"])
arr = []
arr.append(dataId_0001)
arr.append(dataId_0002)
arr.append(dataId_0003)
arr.append(dataId_0004)
arr.append(dataId_0005)
arr.append(dataId_0006)
arr.append(dataId_0007)
arr.append(dataId_0010)
arr.append(dataId_0011)
arr.append(dataId_0012)
arr.append(dataId_0013)
arr.append(dataId_001D)
mult = self.getRandomNum(0,12)
temp = []
for i in range(0, mult):
con = int(self.getRandomNum(intArr=arr))
if con in temp:
con = ""
temp.append(con)
data = data + con
return data
'''扩展状态标志位,见 表 C1EXT1'''
......@@ -187,6 +385,9 @@ class Location_msg(MessageBase):
data = defenseUndefenseRep + retain
dataHex = self.int2hexStringByBytes(data,4)
return dataHex
def getExpandStatusBit_random(self):
dataHex = self.int2hexStringByBytes(self.getRandomNum(intArr=[0,1]),4)
return dataHex
'''扩展报警标志位,见 表 C1EXT2'''
def getExpandAlarmBit(self):
waterTemperatureAlarm = 1 #1:水温报警 (1)
......@@ -212,18 +413,33 @@ class Location_msg(MessageBase):
data = data + RTCTroubleAlarm + retain21_31
dataHex = self.int2hexStringByBytes(data,4)
return dataHex
def getExpandAlarmBit_random(self):
data = self.getRandomNum(intArr=[0,1,2,4,8,16,1024,2048, \
4096,8192,16384,131072,262144,524288,1048576],mult=14)
dataHex = self.int2hexStringByBytes(data,4)
return dataHex
'''行驶总里程'''
def getTotalMileage(self):
caculateType = "0A"
totalMileage = self.int2hexStringByBytes(128000,4) #行驶总里程(单位米)
data = caculateType + totalMileage
return data
def getTotalMileage_random(self):
caculateType = self.getRandomNum(intArr=["01","02","03","04","05","06","07","09","0A","0B","0C"],)
totalMileage = self.int2hexStringByBytes(self.getRandomNum(0,4294967295),4) #行驶总里程(单位米)
data = caculateType + totalMileage
return data
'''行驶总油耗'''
def getTotalOil(self):
caculateType = "02"
totalOil = self.int2hexStringByBytes(120000,4) #总油耗(单位 mL)
data = caculateType + totalOil
return data
def getTotalOil_random(self):
caculateType = self.getRandomNum(intArr=["01","02","03","04","05","0B","0C"],)
totalOil = self.int2hexStringByBytes(self.getRandomNum(0,4294967295),4) #总油耗(单位 mL)
data = caculateType + totalOil
return data
'''此刻 1 秒内的加速度数据,见 表 C1EXT3'''
def getSpeedupInOneSeconds(self):
data = ""
......@@ -235,8 +451,16 @@ class Location_msg(MessageBase):
for i in range(0,pointCount):
data = data + self.int2hexStringByBytes(speedupVal + 10,2)
return data
def getSpeedupInOneSeconds_random(self):
data = ""
pointCount = self.getRandomNum(0,50) #采集的点个数 N
collectIntercal = self.getRandomNum(0,10000) #采集间隔(单位 ms),上传值为该采集间隔时间内的加速度均值
data = data + self.int2hexStringByBytes(pointCount,2)
data = data + self.int2hexStringByBytes(collectIntercal,2) #采集点加速度均值
for i in range(0,pointCount):
speedupVal = self.getRandomNum(0,65535)
data = data + self.int2hexStringByBytes(speedupVal,2)
return data
#######################################################
......@@ -433,13 +657,14 @@ class Location_msg(MessageBase):
if __name__ == "__main__":
print(Location_msg().getAlarmFlag())
print(Location_msg().getInfoTime())
print(Location_msg().generateMsg())
lati = Location_msg().getLatitude(29.40268)
print(lati)
print(int("01c329ed",16) / 1000000)
print(int("0659dec5", 16) / 1000000)
# print(Location_msg().getAlarmFlag())
# print(Location_msg().getInfoTime())
# print(Location_msg().generateMsg())
# lati = Location_msg().getLatitude(29.40268)
# print(lati)
# print(int("01c329ed",16) / 1000000)
# print(int("0659dec5", 16) / 1000000)
print(Location_msg().getLocationBaseInfo_random())
......@@ -126,15 +126,17 @@ class MessageBase(Base):
tmpR = data
tmp = tmpR[0:2]
tmpA = tmpR[0:2]
tmpR = tmpR[2:]
data = ""
while tmpR != "":
while tmpA != "":
if tmp == "7d":
tmp = "7d01"
elif tmp == "7e":
tmp = "7d02"
data = data + tmp
tmp = tmpR[0:2]
tmpA = tmpR[0:2]
tmpR = tmpR[2:]
return data
......@@ -233,18 +235,35 @@ class MessageBase(Base):
data = random.randint(s, e)
else:
if mult == 0:
data = int(random.choice(intArr))
if type(intArr[0]) == int:
data = int(random.choice(intArr))
elif type(intArr[0]) == str:
data = random.choice(intArr)
else:
if len(intArr) < mult:
raise RuntimeError('个数超过数组长度!')
temp = []
data = 0
for i in range(0,mult):
num = int(random.choice(intArr))
while num in temp:
if type(intArr[0]) == int:
if len(intArr) < mult:
raise RuntimeError('个数超过数组长度!')
temp = []
data = 0
for i in range(0,mult):
num = int(random.choice(intArr))
temp.append(num)
data = data + num
if num in temp:
# num = int(random.choice(intArr))
num = 0
temp.append(num)
data = data + num
elif type(intArr[0]) == str:
if len(intArr) < mult:
raise RuntimeError('个数超过数组长度!')
temp = []
data = ""
for i in range(0,mult):
num = random.choice(intArr)
if num in temp:
# num = int(random.choice(intArr))
num = 0
temp.append(num)
data = data + num
return data
#######################################################
......
......@@ -84,8 +84,8 @@ class TerminalVersionInfo_msg(MessageBase):
softwareVersion = self.GBKString2Hex("KZP200_V201001") #软件版本号
softwareVersionDate = self.GBKString2Hex("2020-02-10") #终端版本日期
CPUId = self.str2Hex("CPU-12345678") #cpuId
GMSType = self.GBKString2Hex("GMS-TYPE-123456") #GMS型号
GMS_IMEI = self.GBKString2Hex("GMS_IMEI_123456") #GSM IMEI 号
GSMType = self.GBKString2Hex("GSM-TYPE-123456") #GSM型号
GSM_IMEI = self.GBKString2Hex("GSM_IMEI_123456") #GSM IMEI 号
SIM_IMSI = self.GBKString2Hex("SIM_13146201119") #终端 SIM 卡 IMSI 号
SIM_ICCID = self.GBKString2Hex("SIM_ICCID13146201119") #终端 SIM 卡 ICCID 号
carType = self.int2hexStringByBytes(22,2) #车系车型 ID
......@@ -93,7 +93,7 @@ class TerminalVersionInfo_msg(MessageBase):
totalMileage = self.int2hexStringByBytes(389000,4) #装上终端后车辆累计总里程或车辆仪表里程(单位米)
totalOilExpend = self.int2hexStringByBytes(420000,4) #装上终端后车辆累计总耗油量(ml)
msg = msg + softwareVersion + softwareVersionDate + CPUId + GMSType + GMS_IMEI
msg = msg + softwareVersion + softwareVersionDate + CPUId + GSMType + GSM_IMEI
msg = msg + SIM_IMSI + SIM_ICCID + carType + VIN + totalMileage
msg = msg + totalOilExpend
return msg
......
......@@ -29,6 +29,24 @@ class CarSafeStatusInfo(MessageBase):
retain3 = "00" # 预留
data = data + statusCode + securityStatus + doorStatus + lockStatus + windowStatus + lightStatus + onoffStatusA + onoffStatusB + retain1 + retain2 + retain3
return data
#创建安防状态数据,数据随机产生
def generateSecurityStatusData_random(self):
data = ""
statusCode = "ffffffffffffffffffff" #状态掩码
securityStatus = self.getSecurityStatusHex_random() #安全状态
doorStatus = self.getDoorStatusHex_random() #门状态
lockStatus = self.getLockStatusHex_random() #锁状态
windowStatus = self.getWindowStatusHex_random() #窗户状态
lightStatus = self.getLightStatusHex_random() #灯光状态
onoffStatusA = self.getOnoffStatusAHex_random() #开关状态A
onoffStatusB = self.getOnoffStatusBHex_random() #开关状态B
retain1 = "00" #预留
retain2 = "00" #预留
retain3 = "00" # 预留
data = data + statusCode + securityStatus + doorStatus + lockStatus + windowStatus + lightStatus + onoffStatusA + onoffStatusB + retain1 + retain2 + retain3
return data
......@@ -50,6 +68,10 @@ class CarSafeStatusInfo(MessageBase):
val = accStatus +defenseStatus +brakeStatus +acceleratorStatus + handBrakeStatus + mainSafetyBelt + subSafetyBelt + retain
hexData = self.int2hexStringByBytes(val)
return hexData
def getSecurityStatusHex_random(self):
val = self.getRandomNum(intArr=[0,1,2,4,8,16,32,64],mult=7)
hexData = self.int2hexStringByBytes(val)
return hexData
#####################################################
# 获取门状态16进制数据
......@@ -67,6 +89,10 @@ class CarSafeStatusInfo(MessageBase):
val = lfDoorStatus + rfDoorStatus + lbDoorStatus +rbDoorStatus + trunk + enginCover + retain1 +retain2
hexData = self.int2hexStringByBytes(val)
return hexData
def getDoorStatusHex_random(self):
val = self.getRandomNum(intArr=[0,1,2,4,8,16,32],mult=6)
hexData = self.int2hexStringByBytes(val)
return hexData
#####################################################
# 获取锁状态16进制数据
......@@ -84,6 +110,10 @@ class CarSafeStatusInfo(MessageBase):
val = lfDoorLockStatus + rfDoorLockStatus + lbDoorLockStatus + rbDoorLockStatus + retain1 +retain2 + retain3 +retain4
hexData = self.int2hexStringByBytes(val)
return hexData
def getLockStatusHex_random(self):
val = self.getRandomNum(intArr=[0,1,2,4,8],mult=4)
hexData = self.int2hexStringByBytes(val)
return hexData
#####################################################
# 获取窗户状态16进制数据
......@@ -101,6 +131,10 @@ class CarSafeStatusInfo(MessageBase):
val = lfWindowStatus + rfWindowStatus + lbWindowStatus + rbWindowStatus + topWindowStatus + lTurnLight + rTurnLight + readLight
hexData = self.int2hexStringByBytes(val)
return hexData
def getWindowStatusHex_random(self):
val = self.getRandomNum(intArr=[0,1,2,4,8,16,32,64,128],mult=8)
hexData = self.int2hexStringByBytes(val)
return hexData
#####################################################
# 获取灯光状态16进制数据
......@@ -118,6 +152,10 @@ class CarSafeStatusInfo(MessageBase):
val = lowHeadlight + highHeadlight + ffogLight + bfogLight + dangerLight + backCarLight + autoLight + widthLight
hexData = self.int2hexStringByBytes(val)
return hexData
def getLightStatusHex_random(self):
val = self.getRandomNum(intArr=[0,1,2,4,8,16,32,64,128],mult=8)
hexData = self.int2hexStringByBytes(val)
return hexData
#####################################################
# 获取开关状态A16进制数据
......@@ -135,6 +173,10 @@ class CarSafeStatusInfo(MessageBase):
val = machineOilWarning + oilWarning + wiperWarning + loudsspeakerWaring + airConditionerWaring + backMirrorWaring + retain1 + retain2
hexData = self.int2hexStringByBytes(val)
return hexData
def getOnoffStatusAHex_random(self):
val = self.getRandomNum(intArr=[0,1,2,4,8,16,32],mult=6)
hexData = self.int2hexStringByBytes(val)
return hexData
#####################################################
# 获取开关状态B16进制数据
......@@ -149,4 +191,8 @@ class CarSafeStatusInfo(MessageBase):
val = retain1 + retain2 + retain3 + retain4 + gears
hexData = self.int2hexStringByBytes(val)
return hexData
def getOnoffStatusBHex_random(self):
val = self.getRandomNum(intArr=[0,16,32,48,64,80,96,112,128,144,160,176])
hexData = self.int2hexStringByBytes(val)
return hexData
\ No newline at end of file
#coding:utf-8
import binascii
import socket
import traceback
from lib.protocol.message.DataUpstreamTransport_msg import DataUpstreamTransport_msg
from lib.protocol.message.LocationDataBatchUpdate_msg import LocationDataBatchUpdate_msg
......@@ -29,7 +30,8 @@ port = 9001
# msg = QueryTerminalParam_res().generateMsg() #查询终端参数应答
# msg = QueryTerminalProperty_res().generateMsg() #查询终端属性应答消息
# msg = Location_msg().generateMsg() #位置信息汇报
msg = DataUpstreamTransport_msg().generateMsg() #数据上行透传消息
msg = Location_msg().generateMsg_random()
# msg = DataUpstreamTransport_msg().generateMsg() #数据上行透传消息
# msg = TerminalUpdataResult_msg().generateMsg() #终端升级结果通知
# msg = LocationDataBatchUpdate_msg().generateMsg() #定位数据批量上传
# msg = TextInfoUpload_msg().generateMsg() #文本信息上传
......@@ -48,6 +50,7 @@ def sendSingleMsg(msg):
client.send(binascii.a2b_hex(msg))
# client.send(bytes.fromhex(msg))
except BaseException as e:
traceback.print_exc()
client.close()
print("连接超时,socket断开")
return
......@@ -55,15 +58,15 @@ def sendSingleMsg(msg):
data = client.recv(BUF_SIZE)
# print(data)
except BaseException as e:
# traceback.print_exc()
traceback.print_exc()
client.close()
# raise RuntimeError('socket 接收消息超时!')
print('socket 接收消息超时!')
return
print(data)
print(PlatformCommon_res(data).getOriginalMsg())
# print(PlatformCommon_res(data).getMsg()) #解析平台通用应答消息
print(TerminalRegister_res(data).getMsg()) #解析终端注册应答消息
print(PlatformCommon_res(data).getMsg()) #解析平台通用应答消息
# print(TerminalRegister_res(data).getMsg()) #解析终端注册应答消息
# print(PlatefromVersionInfo_res(data).getMsg()) #解析平台版本信息包上传应答
client.close()
......
......@@ -12,6 +12,8 @@ function messageManTab(e){
$(location).attr('href', "http://" + window.location.host + "/messageTools/message_view/terminalVersionInfoUpload_msg_page");
}else if(id == "dataUpstreamTransport_msg"){
$(location).attr('href', "http://" + window.location.host + "/messageTools/message_view/dataUpstreamTransport_msg_page");
}else if(id == "location_msg"){
$(location).attr('href', "http://" + window.location.host + "/messageTools/message_view/location_msg_page");
}else{
alert(id)
}
......
......@@ -36,6 +36,7 @@
<li role="presentation"><a id="terminalRegister_msg" {% if arg.path[2]=="terminalRegister_msg_page" %} class="link-tab" {% endif %} onclick="messageManTab(this)">终端注册</b></a></li>
<li role="presentation"><a id="terminalVersionInfoUpload_msg" {% if arg.path[2]=="terminalVersionInfoUpload_msg_page" %} class="link-tab" {% endif %} onclick="messageManTab(this)">终端版本信息主动上报</b></a></li>
<li role="presentation"><a id="dataUpstreamTransport_msg" {% if arg.path[2]=="dataUpstreamTransport_msg_page" or arg.path[2]=="dataUpstreamTransport_msg_f2_page" or arg.path[2]=="dataUpstreamTransport_msg_f3_page" or arg.path[2]=="dataUpstreamTransport_msg_f4_page" %} class="link-tab" {% endif %} onclick="messageManTab(this)">数据上行透传</b></a></li>
<li role="presentation"><a id="location_msg" {% if arg.path[2]=="location_msg_page" %} class="link-tab" {% endif %} onclick="messageManTab(this)">位置信息汇报</b></a></li>
<li role="presentation"><a id="style_index2" {% if arg.path[2]=="2" %} class="link-tab" {% endif %} onclick="messageManTab(this)">其他报文</b></a></li>
</ul>
{% endblock %}
......
{% extends "messageTools/message/heartBeat_msg_page.html" %}
{% block title %}location_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="msgID" type="text" class="form-control" disabled="disabled" value="0100" style="width:80px;">
<label>终端手机号:</label><input id="phoneNum" type="text" class="form-control" value="13146201119" style="width:150px;">
<label>消息流水号:</label><input id="msgWaterCode" type="text" class="form-control" value="1" style="width:60px;">
<label>是否加密:</label><select style="width:100px;" id="encryptionType" class="form-control">
<option value="0">不加密</option>
<option value="1024">加密</option>
</select>
<label>有无分包:</label><select style="width:80px;" id="subPkg" class="form-control" onchange="hasSubPkg()">
<option value="0"></option>
<option value="8192"></option>
</select>
<label id="subPkg_label" style="color:grey;">分包个数:</label><input disabled="disabled" id="pkgCounts" type="text" class="form-control" value="0" style="width:60px;">
</div>
<H3 style="border-bottom: 1px solid #eee;">基础消息内容:</H3>
<ul class="protocol_content" style="padding:0px;">
<li><label>省域ID:</label><input id="provinceId" type="text" class="form-control" value="50"></li>
<li><label>市县域ID:</label><input id="countyId" type="text" class="form-control" value="103"></li>
</ul>
<H3 style="border-bottom: 1px solid #eee;">附加消息内容:</H3>
<ul class="protocol_content" style="padding:0px;">
<li><label>省域ID:</label><input id="provinceId2" type="text" class="form-control" value="50"></li>
<li><label>市县域ID:</label><input id="countyId2" type="text" class="form-control" value="103"></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 msgID = $("#msgID").val();
var phoneNum = $("#phoneNum").val();
var msgWaterCode = $("#msgWaterCode").val();
var encryptionType = $("#encryptionType").val();
var subPkg = $("#subPkg").val();
var pkgCounts = ""
if (subPkg != "8192"){
pkgCounts = "0"
}else{
pkgCounts = $("#pkgCounts").val();
}
var provinceId = $("#provinceId").val();
var countyId = $("#countyId").val();
var manufacturerId = $("#manufacturerId").val();
var terminalType = $("#terminalType").val();
var terminalId = $("#terminalId").val();
var licencePlateColor = $("#licencePlateColor").val();
var carSign = $("#carSign").val();
var data = {};
data["msgID"] = msgID;
data["phoneNum"] = phoneNum;
data["msgWaterCode"] = msgWaterCode;
data["encryptionType"] = encryptionType;
data["subPkg"] = subPkg;
data["pkgCounts"] = pkgCounts;
data["provinceId"] = provinceId;
data["countyId"] = countyId;
data["manufacturerId"] = manufacturerId;
data["terminalType"] = terminalType;
data["terminalId"] = terminalId;
data["licencePlateColor"] = licencePlateColor;
data["carSign"] = carSign;
var host = window.location.host;
$.ajax({
url:"http://" + host + "/messageTools/message_process/porcessTerminalRegisterMsg",
type:"post",
data:data,
dataType:"json",
success:function(data){
if(data.status == 200){
//window.location.reload()
var theShow = "原始数据: " + data.original + "\n";
theShow = theShow + "收到数据: " + data.result + "\n";
theShow = theShow + "解析数据: " + JSON.stringify(data.parse) + "\n";
$("#showFeedback").val(theShow)
}else{
$("#showFeedback").val(data.message)
alert(data.message);
}
}
});
});
function hasSubPkg(){
value = $("#subPkg").val()
if(value == "8192"){
$("#subPkg_label").css("color","black")
$("#pkgCounts").removeAttr("disabled")
}else{
$("#subPkg_label").css("color","grey")
$("#pkgCounts").attr("disabled","disabled")
}
}
</script>
{% endblock %}
\ No newline at end of file
......@@ -101,4 +101,18 @@ def dataUpstreamTransport_msg_f4_page():
arg = {}
path = "messageTools/message/dataUpstreamTransport_msg_f4_page.html"
arg["path"] = reqPath.split("/")
return render_template(path,arg=arg)
##########################################
# 【视图类型】位置信息汇报
##########################################
@message_view.route('/location_msg_page')
def location_msg_page():
#获取请求的路劲
url = request.url
reqPath = re.findall("http://(.*)$",url)[0]
reqPath = re.findall("/(.*)$", reqPath)[0]
arg = {}
path = "messageTools/message/location_msg_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