Commit 5e32a5bf authored by liyuanhong's avatar liyuanhong

首次提交

parents
Pipeline #127 canceled with stages
.idea/*
venv/*
\ No newline at end of file
# 模拟程序说明文档
#### (一)、模拟车机程序部署方法
1、安装了python3 和 pip 包管理工具
2、使用 :pip install -r requirements.txt 安装依赖库
3、编辑start.py 设置为自己想要的参数
4、python3 start.py即可启动模拟服务(window下双击即可启动)
#### (二)、运行机制
1、启动程序后,模拟车机会在:data/GSPLines 目录下面随机选择一条轨迹行驶
2、行驶完成后会自动熄火停止,并在指定的时间后开始下一次随机轨迹的选择行驶
3、直到设定的模拟器持续时间用完,整个模拟程序退出
\ No newline at end of file
{
"name":"GPS轨迹1",
"GPSLine":[
{
"lng":106.586571,
"lat":29.569133
},
{
"lng":106.586935,
"lat":29.569215
},
{
"lng":106.587114,
"lat":29.569215
},
{
"lng":106.587424,
"lat":29.569231
},
{
"lng":106.587685,
"lat":29.569278
},
{
"lng":106.587981,
"lat":29.569298
},
{
"lng":106.588098,
"lat":29.569341
},
{
"lng":106.588287,
"lat":29.569392
},
{
"lng":106.588435,
"lat":29.569439
},
{
"lng":106.588565,
"lat":29.569506
},
{
"lng":106.588646,
"lat":29.569565
},
{
"lng":106.588763,
"lat":29.569651
},
{
"lng":106.588884,
"lat":29.569745
},
{
"lng":106.589073,
"lat":29.569832
},
{
"lng":106.589374,
"lat":29.569977
},
{
"lng":106.589688,
"lat":29.570114
},
{
"lng":106.589993,
"lat":29.570228
},
{
"lng":106.590146,
"lat":29.570271
},
{
"lng":106.590357,
"lat":29.570291
},
{
"lng":106.590573,
"lat":29.570264
},
{
"lng":106.590802,
"lat":29.570248
},
{
"lng":106.59095,
"lat":29.570205
},
{
"lng":106.59108,
"lat":29.570256
},
{
"lng":106.591273,
"lat":29.570421
},
{
"lng":106.591507,
"lat":29.570578
},
{
"lng":106.591673,
"lat":29.570703
},
{
"lng":106.591772,
"lat":29.570774
},
{
"lng":106.591974,
"lat":29.570943
},
{
"lng":106.592145,
"lat":29.57108
},
{
"lng":106.592342,
"lat":29.571261
},
{
"lng":106.592383,
"lat":29.571332
},
{
"lng":106.592527,
"lat":29.571493
},
{
"lng":106.592679,
"lat":29.571642
},
{
"lng":106.592765,
"lat":29.571748
},
{
"lng":106.592877,
"lat":29.571834
},
{
"lng":106.593007,
"lat":29.571901
},
{
"lng":106.593182,
"lat":29.571936
},
{
"lng":106.593308,
"lat":29.571936
},
{
"lng":106.593407,
"lat":29.571874
},
{
"lng":106.593591,
"lat":29.571815
},
{
"lng":106.593784,
"lat":29.571795
},
{
"lng":106.593847,
"lat":29.571862
}
]
}
{"name": "gpsLine", "GPSLine": [{"lng": "106.279711", "lat": "29.585448\n"}, {"lng": "106.279711", "lat": "29.585448\n"}, {"lng": "106.279711", "lat": "29.585448\n"}, {"lng": "106.279711", "lat": "29.585448\n"}, {"lng": "106.279711", "lat": "29.585448\n"}, {"lng": "106.279711", "lat": "29.585448\n"}, {"lng": "106.279711", "lat": "29.585448\n"}, {"lng": "106.279711", "lat": "29.585448\n"}, {"lng": "106.279711", "lat": "29.585448\n"}, {"lng": "106.279711", "lat": "29.585448\n"}, {"lng": "106.279711", "lat": "29.585448\n"}, {"lng": "106.287903", "lat": "29.586623\n"}, {"lng": "106.289041", "lat": "29.586608\n"}, {"lng": "106.293958", "lat": "29.586631\n"}, {"lng": "106.296643", "lat": "29.586603\n"}, {"lng": "106.29702", "lat": "29.586588\n"}, {"lng": "106.297076", "lat": "29.586625\n"}]}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
{"time": {"dateTime": "2020-04-16 13:47:50", "date": "2020-04-16", "time": "13:47:50"}, "curDayTravel": {"todayTotalMilleage": 84048, "todayTotalOil": 102, "todayTotalTime": 102, "theMilleage": 1632, "theOil": 1, "theTime": 1}, "travelData": {"totalMilleage": 103664, "totalOil": 151, "totalTime": 151}}
\ No newline at end of file
#coding:utf-8
'''
定义基类,供所有协议类继承
'''
class Base():
def __init__(self):
pass
#####################################################
# 生成协议头
#####################################################
def getProtocalHeader(self):
# print("生成协议头方法")
pass
This diff is collapsed.
This diff is collapsed.
#coding:utf-8
'''
定义一个通用应答数据包
'''
from lib.protocol.report.ProtocolBase import ProtocolBase
class CommonReport_protocol(ProtocolBase):
def __init__(self,msgCount = 1,WATER_CODE = 1000,DEV_ID = "M121501010001",resId="8205",status="00"):
super().__init__()
self.msgCount = int(msgCount)
self.WATER_CODE = int(WATER_CODE); # 设置默认消息流水号
self.DEV_ID = DEV_ID # 设置默认设备id
self.resId = resId #应答的功能ID
self.status = status #应答状态
def setResId(self,data):
self.resId = data
def setStatus(self,data):
self.status = data
#####################################################
# 生成 通用应答 消息
#####################################################
def generateCommonMsg(self):
self.getProtocalHeader()
info = ""
HEADER = "4040" #消息头
WATER_CODE = self.getWaterCode(self.WATER_CODE) #消息流水号
DEV_ID = self.devid2hexString(self.DEV_ID) #设备id
FUN_ID = "0000" # 功能id
data = "" #数据段
for i in range(0,self.msgCount):
data += self.generateCommonPkg(self.generateCommonData())
LENGTH = self.getMsgLength(int(len(WATER_CODE + DEV_ID + FUN_ID + data)/2)) # 消息长度
info += HEADER
info += LENGTH
info += WATER_CODE
info += DEV_ID
info += FUN_ID
info += data
CHECK_CODE = self.getCheckCode(info) # 校验字段
info += CHECK_CODE
return info
#####################################################
# 创建 版本信息 数据包,包含包个数
#####################################################
def generateCommonPkg(self,data):
return data
#####################################################
# 创建 版本信息 数据段
#####################################################
def generateCommonData(self):
data = ""
resId = self.resId
status = self.status
data = resId + status
return data
if __name__ == "__main__":
print(CommonReport_protocol().generateCommonMsg())
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
#coding:utf-8
'''
定义一个心跳协议的类
'''
from lib.protocol.report.ProtocolBase import ProtocolBase
'''
终端心跳协议数据包
'''
class HeartBeatReport_protocol(ProtocolBase):
def __init__(self,WATER_CODE = "0003",DEV_ID = "M121501010001"):
super().__init__()
self.WATER_CODE = int(WATER_CODE); # 设置默认消息流水号
self.DEV_ID = DEV_ID # 设置默认设备id
#####################################################
# 生成心跳消息
#####################################################
def generateHeartBeatMsg(self):
self.getProtocalHeader()
info = ""
HEADER = "4040" # 消息头
WATER_CODE = self.getWaterCode(self.WATER_CODE) # 消息流水号
DEV_ID = self.devid2hexString(self.DEV_ID) # 设备id
FUN_ID = "0003" # 功能id(心跳功能id)
data = "" # 数据段
LENGTH = self.getMsgLength(int(len(WATER_CODE + DEV_ID + FUN_ID + data) / 2)) # 消息长度
info += HEADER
info += LENGTH
info += WATER_CODE
info += DEV_ID
info += FUN_ID
info += data
CHECK_CODE = self.getCheckCode(info) # 校验字段
info += CHECK_CODE
return info
if __name__ == "__main__":
pass
\ No newline at end of file
#coding:utf-8
'''
定义一个终端登录协议的类
'''
from lib.protocol.report.ProtocolBase import ProtocolBase
class LoginReport_protocol(ProtocolBase):
def __init__(self,WATER_CODE = "0002",DEV_ID = "M121501010001",cpuId="CPU-ID001122334455667788",imsi="IMSI13145678902",ccid="CCID1122334455667788",imei="IMEI12233445566"):
super().__init__()
self.WATER_CODE = int(WATER_CODE); # 设置默认消息流水号
self.DEV_ID = DEV_ID # 设置默认设备id
self.cpuId = cpuId #设置默认cupId值
self.imsi = imsi #设置默认imsi值
self.ccid = ccid #设置默认ccid值
self.imei = imei #设置默认imei值
#####################################################
# 生成终端登录消息
#####################################################
def generateLoginMsg(self):
self.getProtocalHeader()
info = ""
HEADER = "4040" # 消息头
WATER_CODE = self.getWaterCode(self.WATER_CODE) # 消息流水号
DEV_ID = self.devid2hexString(self.DEV_ID) # 设备id
FUN_ID = "0002" # 功能id(终端登录功能id)
data = self.generateLoginData() # 数据段
LENGTH = self.getMsgLength(int(len(WATER_CODE + DEV_ID + FUN_ID + data) / 2)) # 消息长度
info += HEADER
info += LENGTH
info += WATER_CODE
info += DEV_ID
info += FUN_ID
info += data
CHECK_CODE = self.getCheckCode(info) # 校验字段
info += CHECK_CODE
return info
#####################################################
# 创建终端登录数据段
#####################################################
def generateLoginData(self):
data = ""
CPU_ID = self.getCPU_IDHex(self.cpuId) #CPU-ID
IMSI = self.getIMSIHex(self.imsi) #IMSI
CCID = self.getCCIDHex(self.ccid) #CCID
IMEI = self.getIMEIHex(self.imei) #IMEI
data = data + CPU_ID + IMSI +CCID +IMEI
return data
#####################################################
# 获取CPU_ID对应的16进制数据
#####################################################
def getCPU_IDHex(self,data):
return self.str2Hex(data)
#####################################################
# 获取IMSI对应的16进制数据
#####################################################
def getIMSIHex(self,data):
return self.str2Hex(data)
#####################################################
# 获取CCID对应的16进制数据
#####################################################
def getCCIDHex(self,data):
return self.str2Hex(data)
#####################################################
# 获取IMDE对应的16进制数据
#####################################################
def getIMEIHex(self,data):
return self.str2Hex(data)
if __name__ == "__main__":
print(LoginReport_protocol().generateLoginData())
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
#encoding:utf-8
from lib.protocol.Base import Base
'''
定义协议类的基类
'''
class ProtocolBase(Base):
def __init__(self):
pass
#####################################################
# 数字转换为16进制字符串
#####################################################
def int2hexString(self, num):
hexStr = hex(num)[2:]
if (len(hexStr) % 2) == 1:
hexStr = "0" + hexStr
return hexStr
#####################################################
# 数字转换为16进制字符串,通过传入字节数可自动补0
# 传入数据格式所占字节数
#####################################################
def int2hexStringByBytes(self, num,bytescount=1):
hexStr = hex(num)[2:]
while len(hexStr) < (bytescount * 2):
hexStr = "0" + hexStr
return hexStr
#####################################################
# 设备id转换为16进制字符串
#####################################################
def devid2hexString(self, id):
# 获取第一个字符的ASCII值
ascii = ord(id[0:1])
# 将10进制的ASCII值转换为16进制
ascii = self.int2hexString(int(ascii))
devid = str(ascii) + id[1:]
return devid
####################################################
# 获取消息体长度
#####################################################
def getMsgLength(self,num):
hexData = self.int2hexString(num)
while len(hexData) < 4:
hexData = "0" + hexData
return hexData
#####################################################
# 获取流水号
#####################################################
def getWaterCode(self,num):
hexData = self.int2hexString(num)
while len(hexData) < 4:
hexData = "0" + hexData
return hexData
#####################################################
# 获取校验码
#####################################################
def getCheckCode(self,data):
return self.crc16(data)
#####################################################
# 定义生成校验字段的函数(自己翻译的函数,简化了很多步骤)
# 通过我实现的方式
#####################################################
def myCrc16(self,msg):
msg = self.str2Ascsii(msg)
crc = 0xFFFF
for i in range(0, len(msg)):
for j in range(0, 8):
cl5 = ((crc >> 15 & 1) == 1)
bit = ((msg[i] >> (7 - j) & 1) == 1)
crc <<= 1
# 通过与0xFFFF(即二进制:1111111111111111)做了一个或运算,将其转换为一个有符号的数
crc &= 0xFFFF
if (cl5 ^ bit):
crc ^= 0x1021;
crc = hex(crc) # 将10进制的crc转换为16进制
crc = str(crc)[2:] # 将16进制转换为字符串,并去掉前面的0x
return crc
#####################################################
# 将字符串转换为对应的ascii值数组
#####################################################
def str2Ascsii(self,s):
asciiArr = []
for i in range(0, len(s)):
asciiValue = ord(s[i])
asciiArr.append(asciiValue)
return asciiArr
#####################################################
# 将字符串转换为对应的ascii字母对应的16进制字符串
#####################################################
def str2Hex(self,s):
sHex = ""
tem = ""
for i in s:
tem = ord(i)
sHex += hex(tem)[2:]
return sHex
####################################################
# 定义生成校验字段的函数
# inputStr:需要传入一个已经转换为16进制的字符串
#####################################################
# add crc 16 check at the end of the string
def crc16(self,inputStr):
inputStrByte = bytes.fromhex(inputStr)
crc = 0xFFFF
for i in range(0, len(inputStrByte)):
for j in range(0, 8):
c15 = (crc >> 15) == 1
bit = ((inputStrByte[i] >> (7 - j)) & 1) == 1
crc <<= 1
crc &= 0xFFFF
if c15 ^ bit:
crc ^= 0x1021
crc = str(hex(crc))
crc = self.leftPad(crc[2:], 4)
# outputStr = inputStr + crc
outputStr = crc
return outputStr
# pad zero to the left of the string if not long enough
def leftPad(self,inputStr, strLen):
if (strLen > len(inputStr)):
outputStr = "0000000000000000000000000000000000000000" + inputStr
outputStr = outputStr[len(outputStr) - strLen:]
return outputStr
else:
return inputStr
# pad zero to the right of the string if not long enough
def rightPad(self,inputStr, strLen):
if (strLen > len(inputStr)):
outputStr = inputStr + "0000000000000000000000000000000000000000"
outputStr = outputStr[: strLen]
return outputStr
else:
return inputStr
#####################################################
# 将UTC时间转换为16进制,
# 例如:2020-01-02 20:30:00 (年取后面2字节)则将20,01,02,20,30,00 转换为对应的6个字节
# theTime:传入一个类似:2020-01-03 13:05:13的一个字符串
#####################################################
def getUTCTimeHex(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:10])
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
#####################################################
#16进制转换为UTC时间格式
#####################################################
def hex2UTCTime(self,dataHex):
theTime = "20"
theTime = theTime + str(int(dataHex[:2],16))
theTime = theTime + "-" + str(int(dataHex[2:4],16))
theTime = theTime + "-" + str(int(dataHex[4:6],16))
theTime = theTime + " " + str(int(dataHex[6:8],16))
theTime = theTime + ":" + str(int(dataHex[8:10],16))
theTime = theTime + ":" + str(int(dataHex[10:],16))
return theTime
####################################################
# 将整数转换为有符号的整数
#####################################################
def num2signedNum(self,num):
return num & 0xff
if __name__ == "__main__":
# print(ProtocolBase().str2Hex("a"))
# print(ProtocolBase().int2hexStringByBytes(1,6))
# print(ProtocolBase().num2signedNum(-5))
print(ProtocolBase().getUTCTimeHex("2020-01-03 13:05:13"))
# print(ProtocolBase().hex2UTCTime("1401030d050d"))
# print(ProtocolBase().hex2UTCTime("14020a07122b"))
# print(ProtocolBase().crc16("4040007000064d20191201000200120114030503202d26d7fffff0000000000505000000143c00000bb80100000fa00000000a0000000000005e60723b723b39331e100055320000001312001007d0001e0000000000000096000000280096ffff3e0001f40000003e0000000000000000000000"))
# print(ProtocolBase().myCrc16("4040007000064d20191201000200120114030503202d26d7fffff0000000000505000000143c00000bb80100000fa00000000a0000000000005e60723b723b39331e100055320000001312001007d0001e0000000000000096000000280096ffff3e0001f40000003e0000000000000000000000"))
This diff is collapsed.
#coding:utf-8
'''
定义一个终端休眠协议的类
'''
from lib.protocol.report.ProtocolBase import ProtocolBase
class SleepReport_protocol(ProtocolBase):
def __init__(self,msgCount = 1,WATER_CODE = 1000,DEV_ID = "M121501010001",verInfo="M100AB01010.0000",compileDate="2020-03-23",GSM="GSM_123456",sleepType="01",sleepStatus=0):
super().__init__()
self.msgCount = int(msgCount) # 设置默认要发送的GPS数据包个数
self.WATER_CODE = int(WATER_CODE); # 设置默认消息流水号
self.DEV_ID = DEV_ID # 设置默认设备id
self.sleepType = sleepType #休眠类型
self.sleepStatus = sleepStatus #休眠状态
#####################################################
# 生成 版本上报 消息
#####################################################
def generateSleepMsg(self):
self.getProtocalHeader()
info = ""
HEADER = "4040" #消息头
WATER_CODE = self.getWaterCode(self.WATER_CODE) #消息流水号
DEV_ID = self.devid2hexString(self.DEV_ID) #设备id
FUN_ID = "00FF" # 功能id
data = "" #数据段
for i in range(0,self.msgCount):
data += self.generateSleepPkg(self.generateSleepData())
LENGTH = self.getMsgLength(int(len(WATER_CODE + DEV_ID + FUN_ID + data)/2)) # 消息长度
info += HEADER
info += LENGTH
info += WATER_CODE
info += DEV_ID
info += FUN_ID
info += data
CHECK_CODE = self.getCheckCode(info) # 校验字段
info += CHECK_CODE
return info
#####################################################
# 创建 版本信息 数据包,包含包个数
#####################################################
def generateSleepPkg(self,data):
return data
#####################################################
# 创建 版本信息 数据段
#####################################################
def generateSleepData(self):
sleepTypeHex = self.sleepType
sleepStatusHex = self.int2hexString(self.sleepStatus)
data = sleepTypeHex + sleepStatusHex
return data
if __name__ == "__main__":
print(SleepReport_protocol().generateSleepMsg())
\ No newline at end of file
#coding:utf-8
from lib.protocol.report.ProtocolBase import ProtocolBase
'''
终端上报故障码数据包
'''
class TroubleReport_protocol(ProtocolBase):
def __init__(self,WATER_CODE = 26,DEV_ID = "M121501010001",infoTime="2020-01-20 11:55:58",troubleCount=1,byte0="02",byte1=2,byte2=3,byte3=1,MILStatus=1):
super().__init__()
self.WATER_CODE = int(WATER_CODE); # 设置默认消息流水号
self.DEV_ID = DEV_ID # 设置默认设备id
self.infoTime = infoTime #时间信息
self.troubleCount = int(troubleCount) #故障码个数
self.byte0 = byte0 #系统id
self.byte1 = int(byte1) #故障码内容
self.byte2 = int(byte2) #故障码内容
self.byte3 = int(byte3) #故障码状态
self.MILStatus = int(MILStatus) #MIL状态
#####################################################
# 生成故障码消息
#####################################################
def generateTroubleMsg(self):
self.getProtocalHeader()
info = ""
HEADER = "4040" # 消息头
WATER_CODE = self.getWaterCode(self.WATER_CODE) # 消息流水号
DEV_ID = self.devid2hexString(self.DEV_ID) # 设备id
FUN_ID = "001A" # 功能id(GPS功能id)
data = self.generateTroubleData(self.troubleCount) # 数据段
# 消息长度
LENGTH = self.getMsgLength(int(len(WATER_CODE + DEV_ID + FUN_ID + data) / 2))
info += HEADER
info += LENGTH
info += WATER_CODE
info += DEV_ID
info += FUN_ID
info += data
CHECK_CODE = self.getCheckCode(info)
info += CHECK_CODE # 校验字段
return info
#####################################################
# 创建故障码数据段
#####################################################
def generateTroubleData(self,troubleCount):
data = ""
infoTime = self.getUTCTimeHex(self.infoTime) #时间信息
data += infoTime
data += self.int2hexString(troubleCount)
for i in range(0,troubleCount):
data = data + self.generateTroubleCode()
data = data + self.int2hexString(self.MILStatus)
return data
#####################################################
# 生成一个故障码数据
#####################################################
def generateTroubleCode(self):
byte0 = self.byte0 #系统ID
byte1 = self.getByte1Hex(self.byte1) #故障码内容
byte2 = self.getByte2Hex(self.byte2) #故障码内容
byte3 = self.getByte3Hex(self.byte3) #故障码状态
data = byte0 + byte1 +byte2 + byte3
return data
#####################################################
# 获取系统ID的16进制数据
# 0x00: 发动机故障码
# 0x01: 变速箱故障码
# 0x02: ABS故障码
# 0x03: 安全气囊故障码
# 其它预留
#####################################################
def getByte0Hex(self, data):
return "02"
#####################################################
# 获取故障码内容的16进制数据
#####################################################
def getByte1Hex(self,data):
hexData = self.int2hexString(data)
return hexData
#####################################################
# 获取故障码内容的16进制数据
#####################################################
def getByte2Hex(self, data):
hexData = self.int2hexString(data)
return hexData
#####################################################
# 获取故障码状态的16进制数据
#####################################################
def getByte3Hex(self, data):
hexData = self.int2hexString(data)
return hexData
#coding:utf-8
'''
定义一个终端版本协议的类
'''
from lib.protocol.report.ProtocolBase import ProtocolBase
class VersionReport_protocol(ProtocolBase):
def __init__(self,msgCount = 1,WATER_CODE = 1000,DEV_ID = "M121501010001",verInfo="M100AB01010.0000",compileDate="2020-03-23",GSM="GSM_123456"):
super().__init__()
self.msgCount = int(msgCount) # 设置默认要发送的GPS数据包个数
self.WATER_CODE = int(WATER_CODE); # 设置默认消息流水号
self.DEV_ID = DEV_ID # 设置默认设备id
self.verInfo = verInfo # 设置默认UTC时间度戳
self.compileDate = compileDate #编译日期
self.GSM = GSM #GSM模块型号
#####################################################
# 生成 版本上报 消息
#####################################################
def generateVersionMsg(self):
self.getProtocalHeader()
info = ""
HEADER = "4040" #消息头
WATER_CODE = self.getWaterCode(self.WATER_CODE) #消息流水号
DEV_ID = self.devid2hexString(self.DEV_ID) #设备id
FUN_ID = "0005" # 功能id
data = "" #数据段
for i in range(0,self.msgCount):
data += self.generateVersionPkg(self.generateVersionData())
LENGTH = self.getMsgLength(int(len(WATER_CODE + DEV_ID + FUN_ID + data)/2)) # 消息长度
info += HEADER
info += LENGTH
info += WATER_CODE
info += DEV_ID
info += FUN_ID
info += data
CHECK_CODE = self.getCheckCode(info) # 校验字段
info += CHECK_CODE
return info
#####################################################
# 创建 版本信息 数据包,包含包个数
#####################################################
def generateVersionPkg(self,data):
return data
#####################################################
# 创建 版本信息 数据段
#####################################################
def generateVersionData(self):
data = ""
verInfoHex = self.str2Hex(self.verInfo) # 设置默认UTC时间度戳
compileDateHex = self.str2Hex(self.compileDate) #编译日期
GSMHex = self.str2Hex(self.GSM) #GSM模块型号
data = verInfoHex + compileDateHex + GSMHex
return data
if __name__ == "__main__":
print(VersionReport_protocol().generateVersionMsg())
\ No newline at end of file
#coding:utf-8
'''
定义一个上报电瓶采样协议的类
'''
from lib.protocol.report.ProtocolBase import ProtocolBase
class VoltageDataReport_protocol(ProtocolBase):
def __init__(self,WATER_CODE = "0002",DEV_ID = "M121501010001",sampleNums=1,sampleData=[{"sampleTime":"2020-04-09 16:20:22","voltage":12}]):
super().__init__()
self.WATER_CODE = int(WATER_CODE); # 设置默认消息流水号
self.DEV_ID = DEV_ID # 设置默认设备id
self.sampleNums = sampleNums #采样个数
self.sampleData = sampleData #采样数据
#####################################################
# 生成终端登录消息
#####################################################
def generateMsg(self):
self.getProtocalHeader()
info = ""
HEADER = "4040" # 消息头
WATER_CODE = self.getWaterCode(self.WATER_CODE) # 消息流水号
DEV_ID = self.devid2hexString(self.DEV_ID) # 设备id
FUN_ID = "000A" # 功能id(终端登录功能id)
data = self.generateData() # 数据段
LENGTH = self.getMsgLength(int(len(WATER_CODE + DEV_ID + FUN_ID + data) / 2)) # 消息长度
info += HEADER
info += LENGTH
info += WATER_CODE
info += DEV_ID
info += FUN_ID
info += data
CHECK_CODE = self.getCheckCode(info) # 校验字段
info += CHECK_CODE
return info
#####################################################
# 创建终端登录数据段
#####################################################
def generateData(self):
data = ""
sampleNums = self.int2hexStringByBytes(self.sampleNums)
data = data + sampleNums
for i in range(0,self.sampleNums):
sampleData = self.getUTCTimeHex(self.sampleData[i]["sampleTime"]) + self.int2hexStringByBytes(int(self.sampleData[i]["voltage"]),2)
data = data + sampleData
return data
if __name__ == "__main__":
print(VoltageDataReport_protocol().generateMsg())
\ No newline at end of file
#coding:utf-8
'''
定义一个通用应答数据包
'''
from lib.protocol.report.ProtocolBase import ProtocolBase
class Common_response(ProtocolBase):
def __init__(self,msgCount = 1,WATER_CODE = 1000,DEV_ID = "M121501010001",resId="8205",status="00"):
super().__init__()
self.msgCount = int(msgCount)
self.WATER_CODE = int(WATER_CODE); # 设置默认消息流水号
self.DEV_ID = DEV_ID # 设置默认设备id
self.resId = resId #应答的功能ID
self.status = status #应答状态
def setResId(self,data):
self.resId = data
def setStatus(self,data):
self.status = data
#####################################################
# 生成 通用应答 消息
#####################################################
def generateCommonMsg(self):
self.getProtocalHeader()
info = ""
HEADER = "4040" #消息头
WATER_CODE = self.getWaterCode(self.WATER_CODE) #消息流水号
DEV_ID = self.devid2hexString(self.DEV_ID) #设备id
FUN_ID = "0000" # 功能id
data = "" #数据段
for i in range(0,self.msgCount):
data += self.generateCommonPkg(self.generateCommonData())
LENGTH = self.getMsgLength(int(len(WATER_CODE + DEV_ID + FUN_ID + data)/2)) # 消息长度
info += HEADER
info += LENGTH
info += WATER_CODE
info += DEV_ID
info += FUN_ID
info += data
CHECK_CODE = self.getCheckCode(info) # 校验字段
info += CHECK_CODE
return info
#####################################################
# 创建 通用应答 数据包,包含包个数
#####################################################
def generateCommonPkg(self,data):
return data
#####################################################
# 创建 通用应答 数据段
#####################################################
def generateCommonData(self):
data = ""
resId = self.resId
status = self.status
data = resId + status
return data
if __name__ == "__main__":
print(Common_response().generateCommonMsg())
\ No newline at end of file
#coding:utf-8
'''
定义一个升级应答数据包
'''
from lib.protocol.report.ProtocolBase import ProtocolBase
class Update_response(ProtocolBase):
def __init__(self,msgCount = 1,WATER_CODE = 1000,DEV_ID = "M121501010001",status="00"):
super().__init__()
self.msgCount = int(msgCount)
self.WATER_CODE = int(WATER_CODE); # 设置默认消息流水号
self.DEV_ID = DEV_ID # 设置默认设备id
self.status = status #应答状态
def setStatus(self,data):
self.status = data
#####################################################
# 生成 升级应答 消息
#####################################################
def generateUpdateMsg(self):
self.getProtocalHeader()
info = ""
HEADER = "4040" #消息头
WATER_CODE = self.getWaterCode(self.WATER_CODE) #消息流水号
DEV_ID = self.devid2hexString(self.DEV_ID) #设备id
FUN_ID = "0300" # 功能id
data = "" #数据段
for i in range(0,self.msgCount):
data += self.generateUpdatePkg(self.generateUpdateData())
LENGTH = self.getMsgLength(int(len(WATER_CODE + DEV_ID + FUN_ID + data)/2)) # 消息长度
info += HEADER
info += LENGTH
info += WATER_CODE
info += DEV_ID
info += FUN_ID
info += data
CHECK_CODE = self.getCheckCode(info) # 校验字段
info += CHECK_CODE
return info
#####################################################
# 创建 升级应答 数据包,包含包个数
#####################################################
def generateUpdatePkg(self,data):
return data
#####################################################
# 创建 升级应答 数据段
#####################################################
def generateUpdateData(self):
data = ""
status = self.status
data = status
return data
if __name__ == "__main__":
print(Update_response().generateUpdateMsg())
\ No newline at end of file
#encoding:utf-8
'''
定义通用应答消息解码类
'''
import json
from lib.protocol.reportPlateform.ResponseBase import ResponseBase
class Common_res(ResponseBase):
def __init__(self,msg):
super().__init__()
if type(msg) == bytes:
self.msg = self.binary2ascii(msg)
else:
self.msg = msg
pass
#######################################################
# 获取解析后的消息
#######################################################
def getMsg(self):
json_msg = {}
json_msg["header"] = self.msg[0:4]
json_msg["msgLen"] = self.getMsgLen()
json_msg["waterCode"] = self.hexString2int(self.msg[8:12])
json_msg["devId"] = self.hex2string(self.msg[12:14]) + self.msg[14:26]
json_msg["funcId"] = self.msg[26:30]
json_msg["body"] = self.getMsgBody()
json_msg["checkCode"] = self.msg[-4:]
json_msg["calculateCheckCode"] = self.getCalculateCheckCode() #自己计算消息后得到的校验码
json_msg = json.dumps(json_msg)
return json_msg
#######################################################
# 获取消息长度
#######################################################
def getMsgLen(self):
msgLenHex = self.msg[4:8]
msgLen = self.hexString2int(msgLenHex)
return msgLen
#######################################################
# 获取消息体
#######################################################
def getMsgBody(self):
data = {}
msgbody = self.msg[30:][:-4]
data["funcId"] = msgbody[:4]
data["status"] = msgbody[4:]
return data
#######################################################
# 获取自己计算得到的校验码
#######################################################
def getCalculateCheckCode(self):
checkCode = self.crc16(self.msg[:-4])
return checkCode
if __name__ == "__main__":
print(Common_res("4040000e000a4d12150101000180000010001550").getMsg())
#encoding:utf-8
'''
定义终端登录应答消息解码类
'''
import json
from lib.protocol.reportPlateform.ResponseBase import ResponseBase
class Login_res(ResponseBase):
def __init__(self, msg):
super().__init__()
if type(msg) == bytes:
self.msg = self.binary2ascii(msg)
else:
self.msg = msg
pass
#######################################################
# 获取解析后的消息
#######################################################
def getMsg(self):
json_msg = {}
json_msg["header"] = self.msg[0:4]
json_msg["msgLen"] = self.getMsgLen()
json_msg["waterCode"] = self.hexString2int(self.msg[8:12])
json_msg["devId"] = self.hex2string(self.msg[12:14]) + self.msg[14:26]
json_msg["funcId"] = self.msg[26:30]
json_msg["body"] = self.getMsgBody()
json_msg["checkCode"] = self.msg[-4:]
json_msg["calculateCheckCode"] = self.getCalculateCheckCode() # 自己计算消息后得到的校验码
json_msg = json.dumps(json_msg)
return json_msg
#######################################################
# 获取消息长度
#######################################################
def getMsgLen(self):
msgLenHex = self.msg[4:8]
msgLen = self.hexString2int(msgLenHex)
return msgLen
#######################################################
# 获取消息体
#######################################################
def getMsgBody(self):
data = {}
msgbody = self.msg[30:][:-4]
data["data"] = msgbody
return data
#######################################################
# 获取自己计算得到的校验码
#######################################################
def getCalculateCheckCode(self):
checkCode = self.crc16(self.msg[:-4])
return checkCode
if __name__ == "__main__":
print(Login_res("4040000e00024d1215010100018000000300482a").getMsg())
#encoding:utf-8
import binascii
import time
from lib.protocol.Base import Base
class ResponseBase(Base):
def __init__(self):
pass
#####################################################
# 数字转换为16进制字符串
#####################################################
def int2hexString(self, num):
hexStr = hex(num)[2:]
if (len(hexStr) % 2) == 1:
hexStr = "0" + hexStr
return hexStr
#####################################################
# 数字转换为16进制字符串,通过传入字节数可自动补0
# 传入数据格式所占字节数
#####################################################
def int2hexStringByBytes(self, num,bytescount=1):
hexStr = hex(num)[2:]
while len(hexStr) < (bytescount * 2):
hexStr = "0" + hexStr
return hexStr
#######################################################
# 16进制字符串转换为整数
#######################################################
def hexString2int(self, data):
val = int(data,16)
return val
#######################################################
# 16进制字符串转换为ascii字符串
#######################################################
def hex2string(self,data):
theStr = ""
while data != "":
tmp = data[:2]
data = data[2:]
theStr = theStr + chr(int(tmp, 16))
return theStr
####################################################
# 定义生成校验字段的函数
# inputStr:需要传入一个已经转换为16进制的字符串
#####################################################
# add crc 16 check at the end of the string
def crc16(self,inputStr):
inputStrByte = bytes.fromhex(inputStr)
crc = 0xFFFF
for i in range(0, len(inputStrByte)):
for j in range(0, 8):
c15 = (crc >> 15) == 1
bit = ((inputStrByte[i] >> (7 - j)) & 1) == 1
crc <<= 1
crc &= 0xFFFF
if c15 ^ bit:
crc ^= 0x1021
crc = str(hex(crc))
crc = self.leftPad(crc[2:], 4)
# outputStr = inputStr + crc
outputStr = crc
return outputStr
# pad zero to the left of the string if not long enough
def leftPad(self,inputStr, strLen):
if (strLen > len(inputStr)):
outputStr = "0000000000000000000000000000000000000000" + inputStr
outputStr = outputStr[len(outputStr) - strLen:]
return outputStr
else:
return inputStr
# pad zero to the right of the string if not long enough
def rightPad(self,inputStr, strLen):
if (strLen > len(inputStr)):
outputStr = inputStr + "0000000000000000000000000000000000000000"
outputStr = outputStr[: strLen]
return outputStr
else:
return inputStr
#######################################################
# utc 时间格式的16进制字符串转时间
######################################################
def hexDate2date(self,hexData):
UTCTime = "20"
UTCTime = UTCTime + str(self.hexString2int(hexData[:2]))
UTCTime = UTCTime + "-" + str(self.hexString2int(hexData[2:4]))
UTCTime = UTCTime + "-" + str(self.hexString2int(hexData[4:6]))
UTCTime = UTCTime + " " + str(self.hexString2int(hexData[6:8]))
UTCTime = UTCTime + ":" + str(self.hexString2int(hexData[8:10]))
UTCTime = UTCTime + ":" + str(self.hexString2int(hexData[10:12]))
return UTCTime
#######################################################
# 时间戳的16进制字符串转时间
######################################################
def hexTimestamp2date(self,hexData):
timeStamp = self.hexString2int(hexData)
timeArray = time.localtime(timeStamp)
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
return otherStyleTime
if __name__ == "__main__":
print(ResponseBase().hexDate2date("01c329ed065"))
print(ResponseBase().hexTimestamp2date("5e60723b"))
#coding:utf-8
#########################################################
#
# 定义基类,供所有类继承
#
#########################################################
class Base():
def __init__(self):
pass
#coding:utf-8
import socket
from time import sleep
from lib.socket.SocketBase import SocketBase
import binascii
import random
import string
import traceback
'''
定义客户端socket类
'''
class ClientSocket(SocketBase):
def __init__(self, host="127.0.0.1", port=5000):
#socke连接的标识,生成一个长度为8的随机字符串
self.socketId = ''.join(random.sample(string.ascii_letters + string.digits, 8))
self.port = port
self.host = host
self.timeOut = 1 #设置连接超时时间
# 0代表未连接 , 1代表socket处于连接状态
self.status = 0
self.BUF_SIZE = 1024
#####################################################
# 连接服务器
#####################################################
def connect(self):
self.client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.client.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) # 在客户端开启心跳
# 设置连接socket的超时时间
self.client.settimeout(self.timeOut)
self.client.connect((self.host, self.port))
self.status = 1
#####################################################
# 发送消息
#####################################################
def send(self, msg):
# 设置发送消息的超时时间
self.client.settimeout(self.timeOut)
self.client.send(binascii.a2b_hex(msg))
def receive(self):
data = ""
try:
# 设置接收消息的超时时间
self.client.settimeout(self.timeOut)
data = self.client.recv(self.BUF_SIZE)
except BaseException as e:
# traceback.print_exc()
self.client.close()
self.status = 0
raise RuntimeError('socket 接收消息超时!')
return data
#####################################################
# 断开socket
#####################################################
def close(self):
# self.client.send("_end".encode()) //发送一个socket断开的命令
self.client.close()
self.status = 0
#设置服务器域名
def setHost(self,host):
self.host = host
#设置要连接的服务器端口
def setPort(self,port):
self.port = port
#获取该连接的socket ID号
def getSocketId(self):
return self.socketId
def getSocketStatus(self):
return self.status
def setTimeOut(self,data):
self.timeOut = data
if __name__ == "__main__":
client = ClientSocket()
client.connect()
for i in range(0,10):
client.send("world" + str(i))
sleep(1)
print(i)
client.close()
\ No newline at end of file
#encoding:utf-8
#########################################################
#
# 定义socket的基类
#
#########################################################
from lib.socket.Base import Base
class SocketBase(Base):
def __init__(self):
pass
This diff is collapsed.
#coding:utf-8
##################################################
# 定义M500 车机行驶过程中产生的数据类
##################################################
import datetime
import json
import time
class ProtocolSimulaterDataService():
def __init__(self,path="/data/protocolTools/carData/",fileName="default.json"):
self.data = {}
self.path = path #保存车机数据文件地址
self.fileName = fileName #保存车机数据文件
def setPath(self,data):
self.path = data
def setFileName(self,data):
self.fileName = data
def setData(self,data):
self.data = data
####################################################
# 生成一个默认数据模板
####################################################
def genDataTemplate(self):
data = {}
timeStamp = time.time()
timeArray = time.localtime(timeStamp)
data["time"] = {} #定义时间数据项
data["time"]["dateTime"] = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
data["time"]["date"] = time.strftime("%Y-%m-%d", timeArray)
data["time"]["time"] = time.strftime("%H:%M:%S", timeArray)
data["curDayTravel"] = {} #定义当天行驶数据项
data["curDayTravel"]["todayTotalMilleage"] = 0 #今日行驶总里程
data["curDayTravel"]["todayTotalOil"] = 0 #今日行驶总油耗
data["curDayTravel"]["todayTotalTime"] = 0 #今日行驶总时间
data["curDayTravel"]["theMilleage"] = 0 #本次行驶总里程
data["curDayTravel"]["theOil"] = 0 #本次行驶总油耗
data["curDayTravel"]["theTime"] = 0 #本次行驶总时间
data["travelData"] = {} #定义所有行驶数据
data["travelData"]["totalMilleage"] = 0 #行驶总里程
data["travelData"]["totalOil"] = 0 #行驶总油耗
data["travelData"]["totalTime"] = 0 #行驶总时间
return data
#设今日行驶总里程,同时写入文件
def setTodayTotalMilleage(self,data):
self.data["curDayTravel"]["todayTotalMilleage"] = data
self.writeToFile(self.path + self.fileName,self.data)
#设今日行驶总油耗,同时写入文件
def setTodayTodayTotalOil(self,data):
self.data["curDayTravel"]["todayTotalOil"] = data
self.writeToFile(self.path + self.fileName,self.data)
#设今日行驶总时间,同时写入文件
def setTodayTodayTotalTime(self,data):
self.data["curDayTravel"]["todayTotalTime"] = data
self.writeToFile(self.path + self.fileName,self.data)
#设本次行驶总里程,同时写入文件
def setTheMilleage(self,data):
self.data["curDayTravel"]["theMilleage"] = data
self.writeToFile(self.path + self.fileName,self.data)
#设本次行驶总油耗,同时写入文件
def setTheOil(self,data):
self.data["curDayTravel"]["theOil"] = data
self.writeToFile(self.path + self.fileName,self.data)
#设本次行驶总时间,同时写入文件
def setTheTime(self,data):
self.data["curDayTravel"]["theTime"] = data
self.writeToFile(self.path + self.fileName,self.data)
#设总里程,同时写入文件
def setTotalMilleage(self,data):
self.data["travelData"]["totalMilleage"] = data
self.writeToFile(self.path + self.fileName,self.data)
#设总油耗,同时写入文件
def setTotalOil(self,data):
self.data["travelData"]["totalOil"] = data
self.writeToFile(self.path + self.fileName,self.data)
#设总时间,同时写入文件
def setTotalTime(self,data):
self.data["travelData"]["totalTime"] = data
self.writeToFile(self.path + self.fileName,self.data)
#设今日日期时间
def setDateTime2file(self,data):
self.data["time"]["dateTime"] = data
self.writeToFile(self.path + self.fileName,self.data)
#设今日日期
def setData2file(self,data):
self.data["time"]["date"] = data
self.writeToFile(self.path + self.fileName,self.data)
#设今日时间
def setTime2file(self,data):
self.data["time"]["time"] = data
self.writeToFile(self.path + self.fileName,self.data)
####################################################
# 将数据写入文件
####################################################
def writeToFile(self,path,data):
with open(path,"w",encoding="utf-8") as fi:
data = json.dumps(data)
fi.write(data)
####################################################
# 从文件读取数据
####################################################
def readFromFile(self,path):
with open(path, "r", encoding="utf-8") as fi:
content = fi.read()
conJson = json.loads(content)
timeStamp = time.time()
timeArray = time.localtime(timeStamp)
dateTimeM = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
dateM = time.strftime("%Y-%m-%d", timeArray)
timeM = time.strftime("%H:%M:%S", timeArray)
if dateM == conJson["time"]["date"]:
pass
else: #如果不是当天日期,则将日期设置为当天
conJson["time"]["dateTime"] = dateTimeM
conJson["time"]["date"] = dateM
conJson["time"]["time"] = timeM
data["curDayTravel"]["todayTotalMilleage"] = 0 # 今日行驶总里程
data["curDayTravel"]["todayTotalOil"] = 0 # 今日行驶总油耗
data["curDayTravel"]["todayTotalTime"] = 0 # 今日行驶总时间
self.setTodayTotalMilleage(0)
self.setTodayTodayTotalOil(0)
self.setTodayTodayTotalTime(0)
self.setDateTime2file(dateTimeM)
self.setData2file(dateM)
self.setTime2file(timeM)
self.data = conJson
if __name__ == "__main__":
print(ProtocolSimulaterDataService().genDataTemplate())
data = ProtocolSimulaterDataService().genDataTemplate()
ProtocolSimulaterDataService().writeToFile("../../../data/protocolTools/carData/M202003060520.json",data)
\ No newline at end of file
This diff is collapsed.
# utf-8
#GPS轨迹转换,将数据库导入的gps轨迹转换为程序可使用的GPs
import json
with open('gps.txt', "r", encoding="utf-8") as f:
con = f.readlines()
data = {}
data["name"] = "gpsLine"
data["GPSLine"] = []
for i in range(0, len(con)):
location = con[i].split(",")
location[0].replace("\\n", "")
location[0].replace("\\r", "")
location[0].replace(" ", "")
location[1].replace("\\n", "")
location[1].replace("\\r", "")
location[1].replace(" ", "")
jLocation = {}
jLocation["lng"] = location[0]
jLocation["lat"] = location[1]
data["GPSLine"].append(jLocation)
with open('gpsLine.txt', "w", encoding="utf-8") as f2:
data = json.dumps(data)
f2.write(data)
#coding:utf-8
'''
定义一个处理数据包的辅助方法集合
'''
from binascii import *
from crcmod import *
import struct
#####################################################
# 定义生成校验字段的函数(自己翻译的函数,简化了很多步骤)
#####################################################
def myCrc16(msg):
msg = str2Ascsii(msg)
crc = 0xFFFF
for i in range(0, len(msg)):
for j in range(0, 8):
cl5 = ((crc >> 15 & 1) == 1)
bit = ((msg[i] >> (7 - j) & 1) == 1)
crc <<= 1
# 通过与0xFFFF(即二进制:1111111111111111)做了一个或运算,将其转换为一个有符号的数
crc &= 0xFFFF
if (cl5 ^ bit):
crc ^= 0x1021;
crc = hex(crc) # 将10进制的crc转换为16进制
crc = str(crc)[2:] # 将16进制转换为字符串,并去掉前面的0x
return crc
#####################################################
# 定义生成校验字段的函数
# inputStr:需要传入一个已经转换为16进制的字符串
#####################################################
# add crc 16 check at the end of the string
def crc16(inputStr):
inputStrByte = bytes.fromhex(inputStr)
crc = 0xFFFF
for i in range(0, len(inputStrByte)):
for j in range(0, 8):
c15 = (crc >> 15) == 1
bit = ((inputStrByte[i] >> (7 - j)) & 1) == 1
crc <<= 1
crc &= 0xFFFF
if c15 ^ bit:
crc ^= 0x1021
crc = str(hex(crc))
crc = leftPad(crc[2:], 4)
# outputStr = inputStr + crc
outputStr = crc
return outputStr
# pad zero to the left of the string if not long enough
def leftPad(inputStr, strLen):
if (strLen > len(inputStr)):
outputStr = "0000000000000000000000000000000000000000" + inputStr
outputStr = outputStr[len(outputStr) - strLen:]
return outputStr
else:
return inputStr
# pad zero to the right of the string if not long enough
def rightPad(inputStr, strLen):
if (strLen > len(inputStr)):
outputStr = inputStr + "0000000000000000000000000000000000000000"
outputStr = outputStr[: strLen]
return outputStr
else:
return inputStr
#####################################################
# 将字符串转换为16进制的数字字符串
#####################################################
def str2Hex(s):
s_hex=""
for i in range(len(s)):
s_hex=s_hex+hex(ord(s[i]))[2:]+" "
return s_hex
#####################################################
# 将字符串转换为16进制的数字字符串,并去掉空格
#####################################################
def str2HexStrip(s):
s = str2Hex(s)
s2 = s.replace(" ","")
return s2
#####################################################
# 将字符串转换为对应的ascii值数组
#####################################################
def str2Ascsii(s):
asciiArr = []
for i in range(0,len(s)):
asciiValue = ord(s[i])
asciiArr.append(asciiValue)
return asciiArr
if __name__ == "__main__":
# print(crc16(str2Hex("aa")))
# print(str2Hex("aa"))
# print(str2HexStrip("aa"))
# print(str2Ascsii("aa"))
print(myCrc16("4040007000064d20191201000200120114030503202d26d7fffff0000000000505000000143c00000bb80100000fa00000000a0000000000005e60723b723b39331e100055320000001312001007d0001e0000000000000096000000280096ffff3e0001f40000003e0000000000000000000000"))
# print(crc16(str2HexStrip("aa")))
[2020-04-16 17:34:23] 建立了连接
[2020-04-16 17:34:23] 进行了登录操作
[2020-04-16 17:34:24] 发送了版本信息
[2020-04-16 17:34:24] 当前设置了GPS轨迹:6_先涛的车轨迹(短).txt
[2020-04-16 17:34:24] 发送了点火事件
[2020-04-16 17:34:26] 维度:29.585448 经度:106.279711
[2020-04-16 17:34:28] 维度:29.585448 经度:106.279711
[2020-04-16 17:34:29] 维度:29.585448 经度:106.279711
[2020-04-16 17:34:30] 维度:29.585448 经度:106.279711
[2020-04-16 17:34:31] 维度:29.585448 经度:106.279711
[2020-04-16 17:34:32] 维度:29.585448 经度:106.279711
[2020-04-16 17:34:33] 维度:29.585448 经度:106.279711
[2020-04-16 17:34:34] 维度:29.585448 经度:106.279711
[2020-04-16 17:34:35] 维度:29.585448 经度:106.279711
[2020-04-16 17:34:36] 维度:29.585448 经度:106.279711
[2020-04-16 17:34:38] 维度:29.585448 经度:106.279711
[2020-04-16 17:34:39] 维度:29.586623 经度:106.287903
[2020-04-16 17:34:40] 维度:29.586608 经度:106.289041
[2020-04-16 17:34:41] 维度:29.586631 经度:106.293958
[2020-04-16 17:34:42] 维度:29.586603 经度:106.296643
[2020-04-16 17:34:43] 维度:29.586588 经度:106.29702
[2020-04-16 17:34:44] 维度:29.586625 经度:106.297076
[2020-04-16 17:34:45] 发送了熄火事件:
[2020-04-16 17:34:46] 发送了熄火事件:
[2020-04-16 17:34:46] 执行了停止行驶服务
[2020-04-16 17:34:46] gps轨迹跑完,自动停止行驶!
------------------------------------------------------------------------
[2020-04-16 17:34:46] 请稍后240秒,正在切换轨迹行驶...
[2020-04-16 17:38:46] 建立了连接
[2020-04-16 17:38:47] 进行了登录操作
[2020-04-16 17:38:47] 发送了版本信息
[2020-04-16 17:38:48] 当前设置了GPS轨迹:1_sample(短).json
[2020-04-16 17:38:48] 发送了点火事件
[2020-04-16 17:38:49] 维度:29.569215 经度:106.586935
[2020-04-16 17:38:50] 维度:29.569215 经度:106.587114
[2020-04-16 17:38:51] 维度:29.569231 经度:106.587424
[2020-04-16 17:38:52] 维度:29.569278 经度:106.587685
[2020-04-16 17:38:53] 维度:29.569298 经度:106.587981
[2020-04-16 17:38:54] 维度:29.569341 经度:106.588098
[2020-04-16 17:38:56] 维度:29.569392 经度:106.588287
[2020-04-16 17:38:57] 维度:29.569439 经度:106.588435
[2020-04-16 17:38:58] 维度:29.569506 经度:106.588565
[2020-04-16 17:38:59] 维度:29.569565 经度:106.588646
[2020-04-16 17:39:00] 维度:29.569651 经度:106.588763
[2020-04-16 17:39:01] 维度:29.569745 经度:106.588884
[2020-04-16 17:39:02] 维度:29.569832 经度:106.589073
[2020-04-16 17:39:03] 维度:29.569977 经度:106.589374
[2020-04-16 17:39:05] 维度:29.570114 经度:106.589688
[2020-04-16 17:39:06] 维度:29.570228 经度:106.589993
[2020-04-16 17:39:07] 维度:29.570271 经度:106.590146
[2020-04-16 17:39:08] 维度:29.570291 经度:106.590357
[2020-04-16 17:39:09] 维度:29.570264 经度:106.590573
[2020-04-16 17:39:10] 维度:29.570248 经度:106.590802
[2020-04-16 17:39:11] 维度:29.570205 经度:106.59095
[2020-04-16 17:39:12] 维度:29.570256 经度:106.59108
[2020-04-16 17:39:13] 维度:29.570421 经度:106.591273
[2020-04-16 17:39:15] 维度:29.570578 经度:106.591507
[2020-04-16 17:39:16] 维度:29.570703 经度:106.591673
[2020-04-16 17:39:17] 维度:29.570774 经度:106.591772
[2020-04-16 17:39:18] 维度:29.570943 经度:106.591974
[2020-04-16 17:39:19] 维度:29.57108 经度:106.592145
[2020-04-16 17:39:20] 维度:29.571261 经度:106.592342
[2020-04-16 17:39:21] 维度:29.571332 经度:106.592383
[2020-04-16 17:39:22] 维度:29.571493 经度:106.592527
[2020-04-16 17:39:23] 维度:29.571642 经度:106.592679
[2020-04-16 17:39:25] 维度:29.571748 经度:106.592765
[2020-04-16 17:39:26] 维度:29.571834 经度:106.592877
[2020-04-16 17:39:27] 维度:29.571901 经度:106.593007
[2020-04-16 17:39:28] 维度:29.571936 经度:106.593182
[2020-04-16 17:39:29] 维度:29.571936 经度:106.593308
[2020-04-16 17:39:30] 维度:29.571874 经度:106.593407
[2020-04-16 17:39:31] 维度:29.571815 经度:106.593591
[2020-04-16 17:39:32] 维度:29.571795 经度:106.593784
[2020-04-16 17:39:34] 维度:29.571862 经度:106.593847
[2020-04-16 17:39:35] 发送了熄火事件:
[2020-04-16 17:39:35] 发送了熄火事件:
[2020-04-16 17:39:35] 执行了停止行驶服务
[2020-04-16 17:39:35] gps轨迹跑完,自动停止行驶!
------------------------------------------------------------------------
[2020-04-16 17:39:35] 请稍后240秒,正在切换轨迹行驶...
[2020-04-16 17:43:35] 建立了连接
[2020-04-16 17:43:36] 进行了登录操作
[2020-04-16 17:43:36] 发送了版本信息
[2020-04-16 17:43:37] 当前设置了GPS轨迹:1_sample(短).json
[2020-04-16 17:43:37] 发送了点火事件
[2020-04-16 17:43:38] 维度:29.569215 经度:106.586935
[2020-04-16 17:43:39] 维度:29.569215 经度:106.587114
[2020-04-16 17:43:40] 维度:29.569231 经度:106.587424
[2020-04-16 17:43:42] 维度:29.569278 经度:106.587685
[2020-04-16 17:43:43] 维度:29.569298 经度:106.587981
[2020-04-16 17:43:44] 维度:29.569341 经度:106.588098
[2020-04-16 17:43:45] 维度:29.569392 经度:106.588287
[2020-04-16 17:43:46] 维度:29.569439 经度:106.588435
[2020-04-16 17:43:47] 维度:29.569506 经度:106.588565
[2020-04-16 17:43:48] 维度:29.569565 经度:106.588646
[2020-04-16 17:43:49] 维度:29.569651 经度:106.588763
[2020-04-16 17:43:50] 维度:29.569745 经度:106.588884
[2020-04-16 17:43:52] 维度:29.569832 经度:106.589073
[2020-04-16 17:43:53] 维度:29.569977 经度:106.589374
[2020-04-16 17:43:54] 维度:29.570114 经度:106.589688
[2020-04-16 17:43:55] 维度:29.570228 经度:106.589993
[2020-04-16 17:43:56] 维度:29.570271 经度:106.590146
[2020-04-16 17:43:57] 维度:29.570291 经度:106.590357
[2020-04-16 17:43:58] 维度:29.570264 经度:106.590573
[2020-04-16 17:43:59] 维度:29.570248 经度:106.590802
[2020-04-16 17:44:00] 维度:29.570205 经度:106.59095
[2020-04-16 17:44:02] 维度:29.570256 经度:106.59108
[2020-04-16 17:44:03] 维度:29.570421 经度:106.591273
[2020-04-16 17:44:04] 维度:29.570578 经度:106.591507
[2020-04-16 17:44:05] 维度:29.570703 经度:106.591673
[2020-04-16 17:44:06] 维度:29.570774 经度:106.591772
[2020-04-16 17:44:07] 维度:29.570943 经度:106.591974
[2020-04-16 17:44:08] 维度:29.57108 经度:106.592145
[2020-04-16 17:44:09] 维度:29.571261 经度:106.592342
[2020-04-16 17:44:10] 维度:29.571332 经度:106.592383
[2020-04-16 17:44:12] 维度:29.571493 经度:106.592527
[2020-04-16 17:44:13] 维度:29.571642 经度:106.592679
[2020-04-16 17:44:14] 维度:29.571748 经度:106.592765
[2020-04-16 17:44:15] 维度:29.571834 经度:106.592877
[2020-04-16 17:44:16] 维度:29.571901 经度:106.593007
[2020-04-16 17:44:17] 维度:29.571936 经度:106.593182
[2020-04-16 17:44:18] 维度:29.571936 经度:106.593308
[2020-04-16 17:44:19] 维度:29.571874 经度:106.593407
[2020-04-16 17:44:21] 维度:29.571815 经度:106.593591
[2020-04-16 17:44:22] 维度:29.571795 经度:106.593784
[2020-04-16 17:44:23] 维度:29.571862 经度:106.593847
[2020-04-16 17:44:24] 发送了熄火事件:
[2020-04-16 17:44:24] 发送了熄火事件:
[2020-04-16 17:44:24] 执行了停止行驶服务
[2020-04-16 17:44:24] gps轨迹跑完,自动停止行驶!
------------------------------------------------------------------------
[2020-04-16 17:44:24] 请稍后240秒,正在切换轨迹行驶...
[2020-04-16 17:48:24] 建立了连接
[2020-04-16 17:48:25] 进行了登录操作
[2020-04-16 17:48:27] 发送了版本信息
[2020-04-16 17:48:27] 当前设置了GPS轨迹:1_sample(短).json
[2020-04-16 17:48:27] 发送了点火事件
[2020-04-16 17:48:29] 发送了熄火事件:
[2020-04-16 17:48:29] 执行了停止行驶服务
[2020-04-16 17:48:29] 本次车机模拟程序跑完........
#utf-8
from lib.socket.service.AutoCarService import AutoCarService
def startSimulaterService():
autoCarObj = AutoCarService()
autoCarObj.setHost("10.100.12.32") # 设置主机地址
autoCarObj.setPort(9008) # 设置端口号
autoCarObj.setSendDur(1) # 设置发送消息的间隔时间
autoCarObj.setTimeout(30) # 设置socket超时时间
autoCarObj.setChangeGPSLineTime(1 * 4 * 60) # 设置跑完一条轨迹后,进入下一条轨迹的时间(请设置至少大于4分钟的时间)
autoCarObj.setServiceTime(1 * 10 * 60) # 设置整个服务的持续时间
autoCarObj.setOilExpend(10) # 设置1L 油跑多少公里
autoCarObj.setSpeed(60) #设置车速,每小时多少公里
autoCarObj.startService()
if __name__ == "__main__":
startSimulaterService()
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