Commit 9bfdb547 authored by 李远洪's avatar 李远洪

完成了地理位置上报消息以及其中的各项附加数据

parent f210b84b
...@@ -6,8 +6,12 @@ ...@@ -6,8 +6,12 @@
import datetime import datetime
from lib.protocol.message.MessageBase import MessageBase from lib.protocol.message.MessageBase import MessageBase
from lib.protocol.message.data.AlarmEvent_data import AlarmEvent_data
from lib.protocol.message.data.CarSafeStatusInfo import CarSafeStatusInfo from lib.protocol.message.data.CarSafeStatusInfo import CarSafeStatusInfo
from lib.protocol.message.data.Circum_data import Circum_data
from lib.protocol.message.data.NewEnergyCar_data import NewEnergyCar_data
from lib.protocol.message.data.SaloonCarOBD_data import SaloonCarOBD_data from lib.protocol.message.data.SaloonCarOBD_data import SaloonCarOBD_data
from lib.protocol.message.data.TruckCarOBD_data import TruckCarOBD_data
class Location_msg(MessageBase): class Location_msg(MessageBase):
...@@ -61,7 +65,7 @@ class Location_msg(MessageBase): ...@@ -61,7 +65,7 @@ class Location_msg(MessageBase):
# 获取位置附加信息 # 获取位置附加信息
####################################################### #######################################################
def getLocationExtraInfo(self): def getLocationExtraInfo(self):
msg = "" data = ""
extraInfoId = self.int2hexStringByBytes(1) extraInfoId = self.int2hexStringByBytes(1)
# 里程,DWORD,1 / 10km,对应车上里程表读数;不支持OBD时,为基于GPS车速统计的车辆累计行驶总里程。 # 里程,DWORD,1 / 10km,对应车上里程表读数;不支持OBD时,为基于GPS车速统计的车辆累计行驶总里程。
extra_01 = "01" + self.int2hexStringByBytes(4) + self.int2hexStringByBytes(20202020,4) extra_01 = "01" + self.int2hexStringByBytes(4) + self.int2hexStringByBytes(20202020,4)
...@@ -83,18 +87,19 @@ class Location_msg(MessageBase): ...@@ -83,18 +87,19 @@ class Location_msg(MessageBase):
extra_EA = "EA" + self.int2hexStringByBytes(int(len(self.getBaseDataList()) / 2)) + self.getBaseDataList() extra_EA = "EA" + self.int2hexStringByBytes(int(len(self.getBaseDataList()) / 2)) + self.getBaseDataList()
#轿车 OBD 数据流 #轿车 OBD 数据流
extra_EB = "EB" + self.int2hexStringByBytes(int(len(SaloonCarOBD_data().generateSaloonCarOBDData()) / 2)) + SaloonCarOBD_data().generateSaloonCarOBDData() extra_EB = "EB" + self.int2hexStringByBytes(int(len(SaloonCarOBD_data().generateSaloonCarOBDData()) / 2)) + SaloonCarOBD_data().generateSaloonCarOBDData()
#TODO 以下需要去实现 #货车 OBD 数据流
# #货车 OBD 数据流 extra_EC = "EC" + self.int2hexStringByBytes(int(len(TruckCarOBD_data().generateTruckCarOBD_data()) / 2)) + TruckCarOBD_data().generateTruckCarOBD_data()
# extra_EC = "EC" #新能源 OBD 数据流
# #新能源 OBD 数据流 extra_ED = "ED" + self.int2hexStringByBytes(int(len(NewEnergyCar_data().generateNewEnergyCar_data()) / 2)) + NewEnergyCar_data().generateNewEnergyCar_data()
# extra_ED = "ED" #外设数据项列表
# #外设数据项列表 extra_EE = "EE" + self.int2hexStringByBytes(int(len(Circum_data().generateCircum_data()) / 2)) + Circum_data().generateCircum_data()
# extra_EE = "EE" #报警事件 ID 数据项列表
# #报警事件 ID 数据项列表 extra_FA = "FA" + self.int2hexStringByBytes(int(len(AlarmEvent_data().generateAlarmEvent_data()) / 2)) + AlarmEvent_data().generateAlarmEvent_data()
# extra_FA = "FA"
data = extra_01
data = extra_01 + extra_02 + extra_11 + extra_12 + extra_13 # data = extra_01 + extra_02 + extra_11 + extra_12 + extra_13
data = data + extra_2A + extra_30 + extra_31 + extra_EA # data = data + extra_2A + extra_30 + extra_31 + extra_EA + extra_EB
# data = data + extra_EC
extraInfoLen = self.int2hexStringByBytes(int(len(data) / 2)) extraInfoLen = self.int2hexStringByBytes(int(len(data) / 2))
data = extraInfoId + extraInfoLen + data data = extraInfoId + extraInfoLen + data
return data return data
......
#encoding:utf-8
'''
定义外设数据项
'''
from lib.protocol.message.MessageBase import MessageBase
class AlarmEvent_data(MessageBase):
def __init__(self):
super().__init__()
pass
#####################################################
# 创建轿车OBD数据
#####################################################
def generateAlarmEvent_data(self):
data = ""
#怠速过长报警 附带信息见 表 C6EXT1
idlingSpeedOver = "0106" + self.int2hexStringByBytes(9) + self.getIdlingSpeedOver()
#超速报警 附带信息见 表 C6EXT2
overspeedAlarm = "0107" + self.int2hexStringByBytes(9) + self.getOverspeedAlarm()
#疲劳驾驶报警 附带信息见 表 C6EXT3
fatigueDriving = "0108" + self.int2hexStringByBytes(5) + self.getFatigueDriving()
#水温报警 附带信息见 表 C6EXT4
waterTemperatureAlarm = "0109" + self.int2hexStringByBytes(9) + self.getWaterTemperatureAlarm()
data = data + idlingSpeedOver + overspeedAlarm + fatigueDriving + waterTemperatureAlarm
return data
#####################################################
# 获取怠速过长附带信息
#####################################################
def getIdlingSpeedOver(self):
#报警属性 1:报警触发(无下面的数据内容项)0:报警解除(有下面的数据内容项)
alarmType = self.int2hexStringByBytes(1)
#怠速持续时间 怠速持续的时间(含报警前的预判时间),单位为秒
idlingTimeOfDuration = self.int2hexStringByBytes(600,2)
#怠速耗油量 单位 mL
idlingOilExpend = self.int2hexStringByBytes(1200,2)
#怠速最高转速 单位 RPM
idlingEngineMaxSpeed = self.int2hexStringByBytes(5000,2)
#怠速最低转速 单位 RPM
idlingEngineMinSpeed = self.int2hexStringByBytes(500,2)
data = alarmType + idlingTimeOfDuration + idlingOilExpend + idlingEngineMaxSpeed + idlingEngineMinSpeed
return data
#####################################################
# 获取超速报警信息
#####################################################
def getOverspeedAlarm(self):
#报警属性 1 BYTE 1:报警触发(无下面的数据内容项) 0:报警解除(有下面的数据内容项)
alarmType = self.int2hexStringByBytes(0)
#超速持续时间 2 WORD 怠速持续的时间(含报警前的预判时间),单位为秒
overspeedTimeOfDuration = self.int2hexStringByBytes(700,2)
#最高车速 2 WORD 单位 0.1KM/H
maxSpeed = self.int2hexStringByBytes(145,2)
#平均车速 2 WORD 单位 0.1KM/H
averageSpeed = self.int2hexStringByBytes(70,2)
#超速行驶距离 2 WORD 单位米
overspeedDistance = self.int2hexStringByBytes(10000,2)
data = alarmType + overspeedTimeOfDuration + maxSpeed + averageSpeed + overspeedDistance
return data
#####################################################
# 获取疲劳驾驶报警附带信息
#####################################################
def getFatigueDriving(self):
#报警属性 1 BYTE 1:报警触发(无下面的数据内容项) 0:报警解除(有下面的数据内容项)
alarmType = self.int2hexStringByBytes(0)
#累计持续驾驶时间 4 DWORD 车辆点火行驶到报警解除的累计行驶时间,单位为秒
totalContinueDrivingTime = self.int2hexStringByBytes(21000,4)
data = alarmType + totalContinueDrivingTime
return data
#####################################################
# 获取疲劳驾驶报警附带信息
#####################################################
def getWaterTemperatureAlarm(self):
#报警属性 1 BYTE 1:报警触发(无下面的数据内容项) 0:报警解除(有下面的数据内容项)
alarmType = self.int2hexStringByBytes(1)
#持续时长 4 DWORD 单位秒
timeOfDuration = self.int2hexStringByBytes(11000,4)
#最高温度 2 WORD 单位 0.1 度
maxTemperature = self.int2hexStringByBytes(700,2)
#平均温度 2 WORD 单位 0.1 度
averageTemperature = self.int2hexStringByBytes(55,2)
data = alarmType + timeOfDuration + maxTemperature + averageTemperature
return data
if __name__ == "__main__":
print(AlarmEvent_data().generateAlarmEvent_data())
#encoding:utf-8
'''
定义外设数据项
'''
from lib.protocol.message.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.protocol.message.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
#encoding:utf-8
'''
定义轿车OBD数据
'''
from lib.protocol.message.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
...@@ -19,8 +19,8 @@ port = 9001 ...@@ -19,8 +19,8 @@ port = 9001
# msg = TerminalRegister_msg().generateMsg() #终端注册 # msg = TerminalRegister_msg().generateMsg() #终端注册
# msg = TerminalCancle_msg().generateMsg() #终端注销 # msg = TerminalCancle_msg().generateMsg() #终端注销
# msg = TerminalAuthenticate_msg().generateMsg() #终端鉴权 # msg = TerminalAuthenticate_msg().generateMsg() #终端鉴权
# msg = Location_msg().generateMsg() #位置信息汇报 msg = Location_msg().generateMsg() #位置信息汇报
msg = DataUpstreamTransport_msg().generateMsg() #数据上行透传消息 # msg = DataUpstreamTransport_msg().generateMsg() #数据上行透传消息
print(msg) print(msg)
BUF_SIZE = 1024 BUF_SIZE = 1024
......
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