Commit 7c5aabee authored by liyuanhong's avatar liyuanhong

完成了新硬件并发脚本开发

parent 7a63999d
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#encoding:utf-8
'''
定义终端心跳消息
'''
from lib.Mnew.MessageBase import MessageBase
class TerminalHeartbeat_msg(MessageBase):
def __init__(self):
super().__init__() #不执行该方法,无法使用父类里面定义的属性
self.phoneNum = 201912000000
def setPhoneNum(self, data):
self.phoneNum = data
#######################################################
# 生成一条完整的消息
#######################################################
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="0002",phoneNum="13146201119",msgWaterCode=1,encryptionType=0,subPkg=0):
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 generateMsg_random(self):
msgID="0002"
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 = "0002"
subPkg = 0
msgBodyProperty = self.getMsgBodyProperty(msgBodyLen=int(len(self.getMsgBody()) / 2),subPkg=subPkg) #消息体属性
phoneNum = self.int2BCD(self.phoneNum) #终端手机号
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 #加密方式
subPkg = subPkg #分包
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(TerminalHeartbeat_msg().generateMsg())
print(TerminalHeartbeat_msg().getMsgBodyProperty())
\ No newline at end of file
#encoding:utf-8
'''
定义终端注册消息
'''
from lib.Mnew.MessageBase import MessageBase
class TerminalRegister_msg(MessageBase):
def __init__(self):
super().__init__() #不执行该方法,无法使用父类里面定义的属性
self.phoneNum = 201912000000
def setPhoneNum(self, data):
self.phoneNum = data
#######################################################
# 生成一条完整的消息
#######################################################
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="0100",phoneNum="13146201119",msgWaterCode=1,encryptionType=0,subPkg=0,provinceId=50,\
countyId=103,manufacturerId="11010",terminalType="a865h643gfdj64fd7432",terminalId="H6uyt08", \
licencePlateColor=1,carSign="渝B23CX"):
msg = ""
msgHeader = self.getMsgHeader_GUI(msgID,phoneNum,msgWaterCode,encryptionType,subPkg)
msgBody = self.getMsgBody_GUI(provinceId,countyId,manufacturerId,terminalType,terminalId,licencePlateColor,carSign)
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 = "0100"
phoneNum = self.getRandomStr(11, "0123456789")
msgWaterCode = self.getRandomNum(1, 65535)
encryptionType = 0
subPkg = self.getRandomNum(intArr=[0, 8192])
provinceId = self.getRandomNum(10,99)
countyId = self.getRandomNum(100,990)
manufacturerId = self.getRandomStr(5,"0123456789")
terminalType = self.getRandomStr(20)
terminalId = self.getRandomStr(7)
licencePlateColor = self.getRandomNum(intArr=[1,2,3,4,9])
carSign = self.getRandomStr(5)
msg = ""
msgHeader = self.getMsgHeader_GUI(msgID, phoneNum, msgWaterCode, encryptionType, subPkg)
msgBody = self.getMsgBody_GUI(provinceId, countyId, manufacturerId, terminalType, terminalId, licencePlateColor,
carSign)
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 = ""
# msgNums = self.int2hexStringByBytes(1,2)
# msgNumber = self.int2hexStringByBytes(1,2)
#省域 ID (标示终端安装车辆所在的省域,0 保留,由平台取默认值。省 域 ID 采用 GB/T 2260 中规定的行政区划代 码六位中前两)
provinceId = self.int2hexStringByBytes(50,2)
#市县域 ID
countyId = self.int2hexStringByBytes(103,2)
#制造商 ID (5 个字节,终端制造商编码)
manufacturerId = self.str2Hex("man03")
#终端型号 (20 个字节,此终端型号由制造商自行定义,位数不足时,后 补“0X00”。)
terminalType = self.str2Hex("a865h643gfdj64fd7432")
#终端 ID (7 个字节,由大写字母和数字组成,此终端 ID 由制造商自行 定义,位数不足时,后补“0X00”)
terminalId = self.str2Hex("H6uyt08")
#车牌颜色 (车牌颜色,按照 JT/T415-2006 的 5.4.12。未上牌时,取值 为 0) 1:蓝色 2:黄色 3:黑色 4:白色 9:其他
licencePlateColor = self.int2hexStringByBytes(2)
#车辆标识 (车牌颜色为 0 时,表示车辆 VIN;否则,表示公安交通管理 部门颁发的机动车号牌)
carSign = self.GBKString2Hex("渝B23CX")
# msg = msg + msgNums + msgNumber
msg = msg + provinceId + countyId + manufacturerId + terminalType + terminalId + licencePlateColor + carSign
return msg
# 获取消息体,针对图形界面,可传递参数
def getMsgBody_GUI(self,provinceId=50,countyId=103,manufacturerId="11010",terminalType="a865h643gfdj64fd7432",terminalId="H6uyt08", \
licencePlateColor=1,carSign="渝B23CX"):
msg = ""
# msgNums = self.int2hexStringByBytes(1,2)
# msgNumber = self.int2hexStringByBytes(1,2)
#省域 ID (标示终端安装车辆所在的省域,0 保留,由平台取默认值。省 域 ID 采用 GB/T 2260 中规定的行政区划代 码六位中前两)
provinceId = self.int2hexStringByBytes(provinceId,2)
# 市县域 ID
countyId = self.int2hexStringByBytes(countyId, 2)
#制造商 ID (5 个字节,终端制造商编码)
manufacturerId = self.str2Hex(manufacturerId)
#终端型号 (20 个字节,此终端型号由制造商自行定义,位数不足时,后 补“0X00”。)
terminalType = self.str2Hex(terminalType)
#终端 ID (7 个字节,由大写字母和数字组成,此终端 ID 由制造商自行 定义,位数不足时,后补“0X00”)
terminalId = self.str2Hex(terminalId)
#车牌颜色 (车牌颜色,按照 JT/T415-2006 的 5.4.12。未上牌时,取值 为 0) 1:蓝色 2:黄色 3:黑色 4:白色 9:其他
licencePlateColor = self.int2hexStringByBytes(licencePlateColor)
#车辆标识 (车牌颜色为 0 时,表示车辆 VIN;否则,表示公安交通管理 部门颁发的机动车号牌)
carSign = self.GBKString2Hex(carSign)
# msg = msg + msgNums + msgNumber
msg = msg + provinceId + countyId + manufacturerId + terminalType + terminalId + licencePlateColor + carSign
return msg
#######################################################
# 获取消息头
#######################################################
def getMsgHeader(self):
# msgID = self.int2hexStringByBytes(102,2) #消息id
msgID = "0100"
msgBodyProperty = self.getMsgBodyProperty(int(len(self.getMsgBody()) / 2)) #消息体属性
phoneNum = self.int2BCD(self.phoneNum) #终端手机号
msgWaterCode = self.int2hexStringByBytes(1,2) #消息流水号
subPkgContent = "" #消息包封装项
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 #加密方式
subPkg = subPkg #分包
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(TerminalRegister_msg().generateMsg())
\ No newline at end of file
#encoding:utf-8
'''
定义终端版本信息主动上报
'''
from lib.Mnew.MessageBase import MessageBase
class TerminalVersionInfo_msg(MessageBase):
def __init__(self):
super().__init__() #不执行该方法,无法使用父类里面定义的属性
self.phoneNum = 201912000000
def setPhoneNum(self, data):
self.phoneNum = data
#######################################################
# 生成一条完整的消息
#######################################################
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="0205",phoneNum="13146201119",msgWaterCode=1,encryptionType=0,subPkg=0, \
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
):
msg = ""
msgHeader = self.getMsgHeader_GUI(msgID,phoneNum,msgWaterCode,encryptionType,subPkg)
msgBody = self.getMsgBody_GUI(softwareVersion,softwareVersionDate,CPUId,GMSType,GMS_IMEI,SIM_IMSI,SIM_ICCID,carType,VIN,\
totalMileage,totalOilExpend)
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 = "0205"
phoneNum = self.getRandomStr(11, "0123456789")
msgWaterCode = self.getRandomNum(1, 65535)
encryptionType = 0
subPkg = self.getRandomNum(intArr=[0, 8192])
softwareVersion = "KZP200_" + self.getRandomStr(7)
softwareVersionDate = self.getRandomDate(type=1)
CPUId = "CPU-" + self.getRandomStr(8,"0123456789")
GMSType = "GMS-TYPE-" + self.getRandomStr(6,"0123456789")
GMS_IMEI = "GMS_IMEI_" + self.getRandomStr(6,"0123456789")
SIM_IMSI = "SIM_" + self.getRandomStr(11,"0123456789")
SIM_ICCID = "SIM_ICCID" + self.getRandomStr(11,"0123456789")
carType = self.getRandomNum(0,65535)
VIN = "VIN_" + self.getRandomStr(13,"0123456789")
totalMileage = self.getRandomNum(30000,6000000)
totalOilExpend = self.getRandomNum(30000,6000000)
msg = ""
msgHeader = self.getMsgHeader_GUI(msgID, phoneNum, msgWaterCode, encryptionType, subPkg)
msgBody = self.getMsgBody_GUI(softwareVersion, softwareVersionDate, CPUId, GMSType, GMS_IMEI, SIM_IMSI,
SIM_ICCID, carType, VIN, \
totalMileage, totalOilExpend)
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 = ""
softwareVersion = self.GBKString2Hex("KZP200_V201001") #软件版本号
softwareVersionDate = self.GBKString2Hex("2020-02-10") #终端版本日期
CPUId = self.str2Hex("CPU-12345678") #cpuId
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
VIN = self.GBKString2Hex("VIN_1234567891234") #汽车 VIN 码
totalMileage = self.int2hexStringByBytes(389000,4) #装上终端后车辆累计总里程或车辆仪表里程(单位米)
totalOilExpend = self.int2hexStringByBytes(420000,4) #装上终端后车辆累计总耗油量(ml)
msg = msg + softwareVersion + softwareVersionDate + CPUId + GSMType + GSM_IMEI
msg = msg + SIM_IMSI + SIM_ICCID + carType + VIN + totalMileage
msg = msg + totalOilExpend
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):
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) #装上终端后车辆累计总里程或车辆仪表里程(单位米)
totalOilExpend = self.int2hexStringByBytes(totalOilExpend,4) #装上终端后车辆累计总耗油量(ml)
msg = msg + softwareVersion + softwareVersionDate + CPUId + GMSType + GMS_IMEI
msg = msg + SIM_IMSI + SIM_ICCID + carType + VIN + totalMileage
msg = msg + totalOilExpend
return msg
#######################################################
# 获取消息头
#######################################################
def getMsgHeader(self):
# msgID = self.int2hexStringByBytes(102,2) #消息id
msgID = "0205"
subPkg = 0
msgBodyProperty = self.getMsgBodyProperty(msgBodyLen=int(len(self.getMsgBody()) / 2),subPkg=subPkg) #消息体属性
phoneNum = self.int2BCD(self.phoneNum) #终端手机号
msgWaterCode = self.int2hexStringByBytes(1,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 #加密方式
subPkg = subPkg #分包
retain = 0 #保留位
data = msgBodyLen + encryptionType + subPkg + retain
dataHex = self.int2hexStringByBytes(data,2)
return dataHex
if __name__ == "__main__":
pass
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
#encoding:utf-8
'''
定义外设数据项
'''
from lib.Mnew.MessageBase import MessageBase
class Circum_data(MessageBase):
def __init__(self):
super().__init__()
pass
#####################################################
# 创建轿车OBD数据
#####################################################
def generateCircum_data(self):
data = ""
data_1 = "3001" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(20)
data_2 = "3002" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(21)
data = data_1 + data_2
return data
\ No newline at end of file
#encoding:utf-8
'''
定义新能源车 OBD 数据
'''
from lib.Mnew.MessageBase import MessageBase
class NewEnergyCar_data(MessageBase):
def __init__(self):
super().__init__()
pass
#####################################################
# 创建轿车OBD数据
#####################################################
def generateNewEnergyCar_data(self):
data = ""
#续航里程 , 0.1km 显示值为上传值/10
enduranceMileage = "7001" + self.int2hexStringByBytes(4) + self.int2hexStringByBytes(22000,4)
#剩余电量 , 0% - 100%
surplusPower = "7002" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(55)
#车速 , Km/h 0 - 240
speed = "7003" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(74)
#充电状态
#0x0: 初始值
# 0x1: 未充电
# 0x2: 交流充电中
# 0x3: 直流充电中
# 0x4: 充电完成 0x5: Void 0x6: Void 0x7: 无效值
chargeStatus = "7004" + self.int2hexStringByBytes(1) + "01"
#充电桩状态 , 0x01:插入 0x00:未插入
chargingPileStatus = "7005" + self.int2hexStringByBytes(1) + "00"
#动力电池充放电电流 0.01A 0x0-0xFFFF
batteryStream = "7006" + self.int2hexStringByBytes(2) + self.int2hexStringByBytes(30,2)
#单体电芯最高电压 0.001V 0x0-0xFFFF
batteryMaxVoltage_1 = "7007" + self.int2hexStringByBytes(2) + self.int2hexStringByBytes(7000,2)
# 单体电芯最高电压 0.001V 0x0-0xFFFF
batteryMaxVoltage_2 = "7008" + self.int2hexStringByBytes(2) + self.int2hexStringByBytes(7000, 2)
#驱动电机当前转速 Rpm
electromotorSpeed = "7009" + self.int2hexStringByBytes(2) + self.int2hexStringByBytes(5000,2)
#驱动电机当前转矩 Nm
electromotorTorque = "700a" + self.int2hexStringByBytes(2) + self.int2hexStringByBytes(2000,2)
#驱动电机当前温度 C 上传值减去 40
electromotorTemperature = "700b" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(90)
#直流母线电压 0.001V 0x0-0xFFFF
DCBusVotage = "700c" + self.int2hexStringByBytes(2) + self.int2hexStringByBytes(3000,2)
#直流母线电流 0.01A 0x0-0xFFFF
DCBusStream = "700d" + self.int2hexStringByBytes(2) + self.int2hexStringByBytes(36,2)
#动力电池可用能量 0.01Kwh 0x0-0xFFFF
batteryAvailablePower = "700e" + self.int2hexStringByBytes(2) + self.int2hexStringByBytes(30000,2)
#1 号单体电池电压 V
batteryVotage_1 = "7021" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(6)
batteryVotage_2 = "7022" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(6)
batteryVotage_3 = "7023" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(6)
batteryVotage_4 = "7024" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(6)
batteryVotage_5 = "7025" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(6)
batteryVotage_6 = "7026" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(6)
batteryVotage_7 = "7027" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(6)
batteryVotage_8 = "7028" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(6)
batteryVotage_9 = "7029" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(6)
batteryVotage_10 = "702A" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(6)
data = data + enduranceMileage + surplusPower + speed + chargeStatus + chargingPileStatus
data = data + batteryStream + batteryMaxVoltage_1 + batteryMaxVoltage_2 + electromotorSpeed + electromotorTorque
data = data + electromotorTemperature + DCBusVotage + DCBusStream + batteryAvailablePower + batteryVotage_1
data = data + batteryVotage_2 + batteryVotage_3 + batteryVotage_4 + batteryVotage_5 + batteryVotage_6
data = data + batteryVotage_7 + batteryVotage_8 + batteryVotage_9 + batteryVotage_10
return data
if __name__ == "__main__":
print(NewEnergyCar_data().generateNewEnergyCar_data())
\ No newline at end of file
This diff is collapsed.
#encoding:utf-8
'''
定义终端注销消息
'''
from lib.Mnew.MessageBase import MessageBase
class TerminalCancle_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 getMsgBody(self):
msg = ""
return msg
#######################################################
# 获取消息头
#######################################################
def getMsgHeader(self):
# msgID = self.int2hexStringByBytes(102,2) #消息id
msgID = "0003"
msgBodyProperty = self.getMsgBodyProperty(len(self.getMsgBody())) #消息体属性
phoneNum = self.int2BCD(13146201119) #终端手机号
msgWaterCode = self.int2hexStringByBytes(1,2) #消息流水号
subPkgContent = "" #消息包封装项
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 #加密方式
subPkg = subPkg #分包
retain = 0 #保留位
data = msgBodyLen + encryptionType + subPkg + retain
dataHex = self.int2hexStringByBytes(data,2)
return dataHex
\ No newline at end of file
#encoding:utf-8
'''
定义轿车OBD数据
'''
from lib.Mnew.MessageBase import MessageBase
class TruckCarOBD_data(MessageBase):
def __init__(self):
super().__init__()
pass
#####################################################
# 创建轿车OBD数据
#####################################################
def generateTruckCarOBD_data(self):
data = ""
#发动机转速 , 0 - 8000 rpm
engineSpeed = "60C0" + self.int2hexStringByBytes(2) + self.int2hexStringByBytes(3000,2)
#车速 , 0 - 240 Km/h
carSpeed = "60D0" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(60)
#剩余油量 ,剩余油量,单位 L 或%Bit15=0 百分比%,OBD 都为百分比Bit15=1 单位 L,显示值为上传值/10
surplusOil = "62f0" + self.int2hexStringByBytes(2) + self.getSurplusOil()
#冷却液温度 ,-40.0℃ 到 +210℃,上传值减去 40
coolingLiquidTemperature = "6050" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(76)
#进气口温度 ,-40.0℃ 到 +210℃,上传值减去 40
airInletTemperature = "60F0" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(88)
#进气(岐管绝对)压力 , 0 - 250kpa
intakeManifoldPressure = "60B0" + self.int2hexStringByBytes(2) + self.int2hexStringByBytes(20)
#大气压力 , 0 - 125kpa
atmosphericPressure = "6330" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(28)
#环境温度 , -40.0℃ 到 +210℃,上传值减去 40
envTemperature = "6460" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(65)
#加速踏板位置 , 0% - 100%
acceleratorLocation = "6490" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(32)
#燃油压力 , 0 - 500kpa
oilPressure = "60A0" + self.int2hexStringByBytes(2) + self.int2hexStringByBytes(276,2)
#故障码个数
troubleCodeNum = "6010" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(2)
#OBD 离合器开关 ,0x00/0x01 关/开
clutchSwitch = "5001" + self.int2hexStringByBytes(1) + "01"
#OBD 制动刹车开关 , 0x00/0x01 关/开
brakeSwich = "5002" + self.int2hexStringByBytes(1) + "01"
#OBD 驻车刹车开关 , 0x00/0x01 关/开
parkingBrakeSwitch = "5003" + self.int2hexStringByBytes(1) + "01"
#OBD 节流阀位置 , 0% - 100%
throttleLocation = "5004" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(33)
#OBD 油料使用率 , 0 - 3212.75L/h
oilUsageRate = "5005" + self.int2hexStringByBytes(2) + self.int2hexStringByBytes(1000,2)
#OBD 燃油温度 , 起始值-273℃ 范围(-273 到+1735)
oilTemperature = "5006" + self.int2hexStringByBytes(2) + self.int2hexStringByBytes(299,2)
#OBD 机油温度 , 起始值-273℃ 范围(-273 到+1735)
engineOilTemperature = "5007" + self.int2hexStringByBytes(2) + self.int2hexStringByBytes(300,2)
#OBD 发动机润滑油压力 , 0 - 1000kpa
engineOilPresure = "5008" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(120)
#OBD 制动器踏板位置 , 0% - 100%
brekeLocation = "5009" + self.int2hexStringByBytes(1) + self.int2hexStringByBytes(31)
#OBD 空气流量 , 0.1 G/S
airFlow = "500A" + self.int2hexStringByBytes(2) + self.int2hexStringByBytes(800,2)
data = data + engineSpeed + carSpeed + surplusOil + coolingLiquidTemperature + airInletTemperature
data = data + intakeManifoldPressure + atmosphericPressure + envTemperature + acceleratorLocation + oilPressure
data = data + troubleCodeNum + clutchSwitch + brakeSwich + parkingBrakeSwitch + throttleLocation
data = data + oilUsageRate + oilTemperature + engineOilTemperature + engineOilPresure + brekeLocation
data = data + airFlow
return data
#####################################################
# 获取剩余油量
#####################################################
def getSurplusOil(self):
# 剩余油量 ,剩余油量,单位 L 或%Bit15=0 百分比%,OBD 都为百分比Bit15=1 单位 L,显示值为上传值/10 (32768)
units = 32768
surplusOil = 800
data = units + surplusOil
dataHex = self.int2hexStringByBytes(data,2)
return dataHex
if __name__ == "__main__":
print(TruckCarOBD_data().generateTruckCarOBD_data())
\ No newline at end of file
This diff is collapsed.
#coding:utf-8
import binascii
import json
import socket
import threading
import time
from lib.multiThread.ThreadBase import ThreadBase
from lib.protocol.message.Location_msg import Location_msg
from lib.protocol.message.TerminalRegister_msg import TerminalRegister_msg
class SendMultMsgThread():
def __init__(self,host="10.100.11.20",port=9001,msg=""):
self.host = host
self.port = port
self.msg = msg
self.timeOut = 1 #socket超时时间
self.BUF_SIZE = 1024 #接收消息缓存
self.threadCount = 10000 #并发线程数
self.totalTime = 0 #所有线程的运行总和
self.threadArr = {} #保存每个线程的信息
self.failThreadCount = 0 #失败线程数
pass
############################################
# 设置host
############################################
def setHost(self,host):
self.host = host
############################################
# 设置端口号
############################################
def setPort(self,port):
self.port = port
############################################
# 设置消息
############################################
def setMsg(self,msg):
self.msg = msg
############################################
# 设置并发线程数
############################################
def setThreadCount(self,threadCount):
self.threadCount = threadCount
############################################
# 发送一条消息
############################################
def sendMsg(self,msg,threadName):
msg = msg
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) # 在客户端开启心跳
client.settimeout(self.timeOut)
startTime = int(time.time() * 1000)
try:
client.connect((self.host, self.port))
client.send(binascii.a2b_hex(msg))
except BaseException as e:
client.close()
self.threadArr[threadName]["status"] = 1
self.failThreadCount = self.failThreadCount + 1
print("连接超时,socket断开")
return
try:
data = client.recv(self.BUF_SIZE)
# print(data)
except BaseException as e:
# traceback.print_exc()
client.close()
# raise RuntimeError('socket 接收消息超时!')
self.threadArr[threadName]["status"] = 1
self.failThreadCount = self.failThreadCount + 1
print('socket 接收消息超时!')
return
endTime = int(time.time() * 1000)
timeExpend = endTime - startTime
self.threadArr[threadName]["timeExp"] = timeExpend
self.totalTime = self.totalTime + timeExpend
client.close()
############################################
# 启动并发线程
############################################
def startThread(self):
timeStart = int(time.time() * 1000)
for i in range(0,self.threadCount):
threadName = "thread" + str(i)
# theThread = threading.Thread(target=self.sendMsg, args=("7e0002000001314620111800065b7e",threadName,)) # 数据写死,心跳
theThread = threading.Thread(target=self.sendMsg,args=("4040007000094d20191201000200120114030409123426d7fffff0000000000505000000143c00000bb80100000fa00000000a0000000000005e5f68e768e739331e100055320000001312001007d0001e0000000000000096000000280096ffff3e0001f40000003e00000000000000000000000f9a", threadName,)) # 数据写死
# theThread = threading.Thread(target=self.sendMsg, \
# args=(TerminalRegister_msg().generateMsg_random(), threadName,)) #终端注册
# theThread = threading.Thread(target=self.sendMsg, \
# args=(Location_msg().generateMsg_random(), threadName,)) #地理位置
threadInfo = {}
threadInfo["name"] = threadName
threadInfo["status"] = 0
self.threadArr[threadName] = threadInfo
theThread.start()
timeEnd = int(time.time() * 1000)
timeExpend = timeEnd - timeStart
time.sleep(6)
print("耗时:" + str(timeExpend) + " 毫秒")
print("并发数据每秒发送:" + str(int(self.threadCount / (timeExpend / 1000))))
print("平均响应时间:" + str(self.totalTime / self.threadCount) + "毫秒")
print("发送总数:" + str(self.threadCount))
print("响应失败数:" + str(self.failThreadCount))
self.writeToFile("../../data/threadDetails.json",self.threadArr)
# print(json.dumps( self.threadArr))
def writeToFile(self,path,data):
with open(path, "w", encoding='utf-8') as fi:
json.dump(data, fi)
# fi.write(data)
if __name__ == "__main__":
t = SendMultMsgThread()
t.setHost("10.100.12.32")
t.setPort(9008)
# t.setMsg("7e0002000001314620111800065b7e")
# t.setMsg("7e020001020131462011190001fffc7fff001c010401c0a6380659ad7a02090042003b200204185704310102EA6600010400000000000204001e7c1f0003050A0001f400000405020001d4c000050400057d0240000604000119400007040007530000100c0004006403f203f203f203f2001114ffffffffffffffffffff00200000000000000000001202002400130106001D0101EB7960C0020bb860D0013c62f00203216050014c60F0015860B001146330011c646001416490012060A00201146014010160100102610002022661100201f561F0020e746210040000119c6040012c60700200e660E00203206701010067020100670301016704024e20670502000067060200416707040000017d02097e")
t.startThread()
...@@ -302,30 +302,6 @@ class SendMultMsgThread_m500(ThreadBase): ...@@ -302,30 +302,6 @@ class SendMultMsgThread_m500(ThreadBase):
msg = OBD_msg msg = OBD_msg
return msg return msg
# 获取随机消息数据(新硬件车机)
def getRandomMsg_new(self, carId):
# carId = 201912010002
wh = random.randint(0, 2)
msg = ""
wh = 0
if wh == 0:
hearbeat_msg = "4040000e00044d" + str(carId) + "8000000300cf91"
hearbeat_msg = hearbeat_msg + self.getCheckCode(hearbeat_msg[2:]) + "7e"
hearbeat_msg = self.replace7e7d(hearbeat_msg)
msg = hearbeat_msg
elif wh == 1:
GPS_msg = "4040003d00054d" + str(
carId) + "001001140305031e0301c329ed0659dec501f402e8000000b4050a0b0c9305050258001400000fa0000000005e606f115e60723be44b"
GPS_msg = GPS_msg[:-4] + self.crc16(GPS_msg[:-4])
msg = GPS_msg
elif wh == 2:
OBD_msg = "4040007000064d" + str(
carId) + "00120114030503202d26d7fffff0000000000505000000143c00000bb80100000fa00000000a0000000000005e60723b723b39331e100055320000001312001007d0001e0000000000000096000000280096ffff3e0001f40000003e00000000000000000000007213"
OBD_msg = OBD_msg[:-4] + self.crc16(OBD_msg[:-4])
msg = OBD_msg
return msg
#################################################### ####################################################
# 定义生成校验字段的函数(M500 校验方式) # 定义生成校验字段的函数(M500 校验方式)
# inputStr:需要传入一个已经转换为16进制的字符串 # inputStr:需要传入一个已经转换为16进制的字符串
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
''' '''
启动压力测试脚本 启动压力测试脚本
''' '''
from lib.pressure.SendMultMsgNewThread import SendMultMsgNewThread
from lib.pressure.SendMultMsgThread_m300 import SendMultMsgThread_m300 from lib.pressure.SendMultMsgThread_m300 import SendMultMsgThread_m300
from lib.pressure.SendMultMsgThread_m500 import SendMultMsgThread_m500 from lib.pressure.SendMultMsgThread_m500 import SendMultMsgThread_m500
...@@ -12,9 +13,9 @@ def startM300(): ...@@ -12,9 +13,9 @@ def startM300():
# t.setHost("10.100.12.32") # t.setHost("10.100.12.32")
t.setHost("10.100.5.251") t.setHost("10.100.5.251")
t.setPort(9009) # M300 t.setPort(9009) # M300
t.setThreadCount(3500) t.setThreadCount(3)
t.setTimeOut(30) t.setTimeOut(30)
t.setDurTime(1 * 20 * 60) t.setDurTime(1 * 1.5 * 60)
t.setSetStartCarNumber(0) t.setSetStartCarNumber(0)
# t.startThread() # t.startThread()
t.startThreadContinuous() t.startThreadContinuous()
...@@ -26,11 +27,23 @@ def startM500(): ...@@ -26,11 +27,23 @@ def startM500():
t.setPort(9008) #M500 t.setPort(9008) #M500
t.setThreadCount(4) #设置线程数 t.setThreadCount(4) #设置线程数
t.setTimeOut(30) #设置超时时间 t.setTimeOut(30) #设置超时时间
t.setDurTime(1 * 1 * 60) #设置持续时间 t.setDurTime(1 * 1.5 * 60) #设置持续时间
t.setSetStartCarNumber(0) #设置开始的车机号,每启动一个线程自动加1 t.setSetStartCarNumber(0) #设置开始的车机号,每启动一个线程自动加1
# t.startThread() # t.startThread()
t.startThreadContinuous() t.startThreadContinuous()
def startMNew():
t = SendMultMsgNewThread()
t.setHost("10.100.11.20")
t.setPort(9001) # 车安优
t.setThreadCount(3)
t.setTimeOut(30)
t.setDurTime(1 * 1 * 60)
t.setSetStartCarNumber(0)
t.startThreadContinuous()
if __name__ == "__main__": if __name__ == "__main__":
startM500() # startM300()
\ No newline at end of file # startM500()
startMNew()
\ 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