Commit 84c7ef62 authored by liyuanhong's avatar liyuanhong

完成M300 和M500 GPRS消息应答功能

parent 5faea552
{"time": {"dateTime": "2020-05-14 01:29:40", "date": "2020-05-14", "time": "01:29:40"}, "curDayTravel": {"todayTotalMilleage": 9487, "todayTotalOil": 757, "todayTotalTime": 582, "theMilleage": 528, "theOil": 48, "theTime": 32}, "travelData": {"totalMilleage": 262817, "totalOil": 24827, "totalTime": 15522}, "event": {"threeRapid": {"totalRapidlyAccelerate": 14, "totalSharpSlowdown": 13, "totalSharpTurn": 13}}}
\ No newline at end of file
{"time": {"dateTime": "2020-05-15 11:41:18", "date": "2020-05-15", "time": "11:41:18"}, "curDayTravel": {"todayTotalMilleage": 0, "todayTotalOil": 0, "todayTotalTime": 0, "theMilleage": 0, "theOil": 0, "theTime": 0}, "travelData": {"totalMilleage": 262817, "totalOil": 24827, "totalTime": 15522}, "event": {"threeRapid": {"totalRapidlyAccelerate": 14, "totalSharpSlowdown": 13, "totalSharpTurn": 13}}}
\ No newline at end of file
......@@ -184,7 +184,7 @@ class EventClass(ProtocolBase):
return data
#0023 碰撞报警附带信息
def collisionAlarmExtraInfo(self,totalCount=7,dataProperty=1):
def collisionAlarmExtraInfo(self,totalCount=7,dataProperty=2):
totalCount = self.int2hexStringByBytes(totalCount,2) #历史碰撞总次数
# 1:表示事件发生时刻,前10秒的事件采样数据;
# [碰撞报警前后10秒采样数据附带信息]
......@@ -267,7 +267,7 @@ class EventClass(ProtocolBase):
def SENSORDataFromSeconds(self,counts):
data = ""
for i in range(0,counts):
data += self.int2hexStringByBytes(30,2) #第1秒内的第1个0.5秒内的平均加速度值
data += self.int2hexStringByBytes(30,2) #第N秒内的第N个0.5秒内的平均加速度值
return data
......
......@@ -3,7 +3,7 @@
from lib.protocol.m300.M300Base import M300Base
'''
定义心跳议类
定义终端版本协议类
'''
class VersionInfo_protocol_m300(M300Base):
......
#encoding:utf-8
from lib.protocol.m300.M300Base import M300Base
'''
定义终端版本协议类
'''
class GPRS_protocol_response_m300(M300Base):
dataTest = [{"serverIndex":"1","serverAddressType":0,"serverAddress":"10.100.12.31","comPort":"9008","comType":0,"APN":"tnet", \
"username":"yuanhong","password":"123456"},{"serverIndex":"2","serverAddressType":0,"serverAddress":"10.100.12.31","comPort":"9008","comType":0,"APN":"tnet", \
"username":"yuanhong","password":"123456"},{"serverIndex":"3","serverAddressType":0,"serverAddress":"10.100.12.31","comPort":"9008","comType":0,"APN":"tnet", \
"username":"yuanhong","password":"123456"}]
def __init__(self,waterCode = 3,DEV_ID = "M121501010001",encryptionType=0,data=[{"serverIndex":"1","serverAddressType":0,"serverAddress":"10.100.12.31","comPort":"9008","comType":0,"APN":"tnet", \
"username":"yuanhong","password":"123456"},{"serverIndex":"2","serverAddressType":0,"serverAddress":"10.100.12.31","comPort":"9008","comType":0,"APN":"tnet", \
"username":"yuanhong","password":"123456"},{"serverIndex":"3","serverAddressType":0,"serverAddress":"10.100.12.31","comPort":"9008","comType":0,"APN":"tnet", \
"username":"yuanhong","password":"123456"}]):
super().__init__() # 不执行该方法,无法使用父类里面定义的属性
self.waterCode = waterCode #消息流水号
self.DEV_ID = DEV_ID #设备Id
self.encryptionType = encryptionType #消息属性里面的是否加密字段
self.data = data
#################################################
# 生成消息
#################################################
def generateMsg(self):
msg = self.IDENTIFY
FUNID = "0104" #功能id
waterCode = self.int2hexStringByBytes(self.waterCode,2) #消息流水号
DEV_ID = self.devid2hexString(self.DEV_ID) #设备id
msgBody = self.getMsgBody() # 消息体
msgLen = int(len(msgBody) / 2)
property = self.getMsgProperty(msgBodyLen=msgLen,encryptionType=self.encryptionType)
checkCode = self.getCheckCode(FUNID + waterCode + DEV_ID + property + msgBody)
msg = msg + FUNID + waterCode + DEV_ID + property + msgBody + checkCode + self.IDENTIFY
return msg
#################################################
# 获取消息体
#################################################
def getMsgBody(self):
dataHex = ""
for i in range(0,len(self.data)):
dataHex = dataHex + self.str2Hex(self.data[i]["serverIndex"]) #服务器索引号,从1开始
dataHex = dataHex + "2c" #逗号
dataHex = dataHex + self.str2Hex(str(self.data[i]["serverAddressType"])) #服务器地址类型:0-IP地址,1-域名
dataHex = dataHex + "2c" #逗号
dataHex = dataHex + self.str2Hex(self.data[i]["serverAddress"]) #服务器地址
dataHex = dataHex + "2c" #逗号
dataHex = dataHex + self.str2Hex(self.data[i]["comPort"]) #TCP/UDP端口
dataHex = dataHex + "2c" #逗号
dataHex = dataHex + self.str2Hex(str(self.data[i]["comType"])) #通讯模式:0-TCP,1-UDP
dataHex = dataHex + "2c" #逗号
dataHex = dataHex + self.str2Hex(self.data[i]["APN"]) #APN名称
dataHex = dataHex + "2c" #逗号
dataHex = dataHex + self.str2Hex(self.data[i]["username"]) #用户名
dataHex = dataHex + "2c" #逗号
dataHex = dataHex + self.str2Hex(self.data[i]["password"]) #密码
dataHex = dataHex + "0d" #分隔符:0x0D
dataHex = dataHex + "0a" #分隔符:0x0A
return dataHex
if __name__ == "__main__":
print(GPRS_protocol_response_m300().generateMsg())
\ No newline at end of file
......@@ -13,7 +13,7 @@ from lib.protocol.report.SecurityStatusReport_protocol import SecurityStatusRepo
class EventReport_protocol(ProtocolBase):
#data = {"WATER_CODE":"0003","DEV_ID":"M121501010001","gpsInfo":{"UTCTime":"2020-04-14 11:03:20","latitude":"40.22077","longitude":"116.23128","speed":"80.8","directionAngle":"80.8","elevation":"2999.9","positionStar":"3","Pdop":"0.3","Hdop":"0.4","Vdop":"0.5","statusBit":162,"valtage":"36.9","OBDSpeed":"60.9","engineSpeed":"3000","GPSTotalMileage":"12800","totalOil":"100000","totalTime":"2020002","GPSTimestamp":"1586833400"},"securityData":{"securityStatus":107,"doorStatus":0,"lockStatus":0,"windowStatus":0,"lightStatus":0,"onoffStatusA":0,"onoffStatusB":112,"dataByte":249},"event":{}}
data = {}
def __init__(self,msgCount = 1,WATER_CODE = 26,DEV_ID = "M121501010001",locationType=1,eventType="0036",data={}):
def __init__(self,msgCount = 1,WATER_CODE = 26,DEV_ID = "M121501010001",locationType=1,eventType="0023",data={}):
super().__init__()
self.data = data
if len(data) == 0:
......@@ -194,6 +194,8 @@ class EventReport_protocol(ProtocolBase):
return EventClass().defencesGlassNoCloseExtraInfo()
elif eventType == "0017": #设防非法开门报警
return EventClass().defencesIllegalCloseDoorExtraInfo()
elif eventType == "0023": #碰撞告警
return EventClass().collisionAlarmExtraInfo()
elif eventType == "0036": #低档高速报警
return EventClass().lowGearHighSpeedAlarm()
elif eventType == "0037": #高档低速报警
......
This diff is collapsed.
......@@ -7,7 +7,7 @@
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):
def __init__(self,msgCount = 1,WATER_CODE = 1000,DEV_ID = "M121501010001",sleepType="01",sleepStatus=0):
super().__init__()
self.msgCount = int(msgCount) # 设置默认要发送的GPS数据包个数
......@@ -48,7 +48,7 @@ class SleepReport_protocol(ProtocolBase):
return data
#####################################################
# 创建 版本信息 数据段
# 创建 车机休眠数据段 数据段
#####################################################
def generateSleepData(self):
sleepTypeHex = self.sleepType
......
#coding:utf-8
'''
定义一个查询GPRS应答数据包
'''
from lib.protocol.report.ProtocolBase import ProtocolBase
class Update_response(ProtocolBase):
dataDefault = [{"serverIndex":"1","serverAddressType":0,"serverAddress":"10.100.12.31","comPort":"9008","comType":0,"APN":"tnet", \
"username":"yuanhong","password":"123456"},{"serverIndex":"1","serverAddressType":0,"serverAddress":"10.100.12.31","comPort":"9008","comType":0,"APN":"tnet", \
"username":"yuanhong","password":"123456"},{"serverIndex":"1","serverAddressType":0,"serverAddress":"10.100.12.31","comPort":"9008","comType":0,"APN":"tnet", \
"username":"yuanhong","password":"123456"}]
def __init__(self,msgCount = 1,WATER_CODE = 1000,DEV_ID = "M121501010001",data=[{"serverIndex":"1","serverAddressType":0,"serverAddress":"10.100.12.31","comPort":"9008","comType":0,"APN":"tnet", \
"username":"yuanhong","password":"123456"},{"serverIndex":"2","serverAddressType":0,"serverAddress":"10.100.12.31","comPort":"9008","comType":0,"APN":"tnet", \
"username":"yuanhong","password":"123456"},{"serverIndex":"3","serverAddressType":0,"serverAddress":"10.100.12.31","comPort":"9008","comType":0,"APN":"tnet", \
"username":"yuanhong","password":"123456"}]):
super().__init__()
self.msgCount = int(msgCount)
self.WATER_CODE = int(WATER_CODE); # 设置默认消息流水号
self.DEV_ID = DEV_ID # 设置默认设备id
self.data = data
#####################################################
# 生成 GPRS应答 消息
#####################################################
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 = "8105" # 功能id
data = "" #数据段
data += 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
#####################################################
# 创建 GPRS应答 数据段
#####################################################
def generateUpdateData(self):
dataHex = ""
for i in range(0,len(self.data)):
dataHex = dataHex + self.str2Hex(self.data[i]["serverIndex"]) #服务器索引号,从1开始
dataHex = dataHex + "2c" #逗号
dataHex = dataHex + self.str2Hex(str(self.data[i]["serverAddressType"])) #服务器地址类型:0-IP地址,1-域名
dataHex = dataHex + "2c" #逗号
dataHex = dataHex + self.str2Hex(self.data[i]["serverAddress"]) #服务器地址
dataHex = dataHex + "2c" #逗号
dataHex = dataHex + self.str2Hex(self.data[i]["comPort"]) #TCP/UDP端口
dataHex = dataHex + "2c" #逗号
dataHex = dataHex + self.str2Hex(str(self.data[i]["comType"])) #通讯模式:0-TCP,1-UDP
dataHex = dataHex + "2c" #逗号
dataHex = dataHex + self.str2Hex(self.data[i]["APN"]) #APN名称
dataHex = dataHex + "2c" #逗号
dataHex = dataHex + self.str2Hex(self.data[i]["username"]) #用户名
dataHex = dataHex + "2c" #逗号
dataHex = dataHex + self.str2Hex(self.data[i]["password"]) #密码
dataHex = dataHex + "0d" #分隔符:0x0D
dataHex = dataHex + "0a" #分隔符:0x0A
return dataHex
if __name__ == "__main__":
print(Update_response().generateMsg())
......@@ -4,6 +4,7 @@ import os
import socket
import sys
from lib.protocol.report.SensorSampling_protocol import SensorSampling_protocol
from lib.protocol.report.TroubleCodeReport_protocol import TroubleCode_protocol
from lib.protocol.report.VoltageDataReport_protocol import VoltageDataReport_protocol
......@@ -35,7 +36,7 @@ port = 9008
# msg = GPSReport_protocol().generateGpsMsg() #GPS消息数据
# msg = OBDReport_protocol().generateOBDReportMsg() #OBD终端上报数据
msg = OBDReport_CAN_protocol().generateOBDReportCANMsg() #OBD终端上报CAN数据
# msg = OBDReport_CAN_protocol().generateOBDReportCANMsg() #OBD终端上报CAN数据
# msg = HeartBeatReport_protocol().generateHeartBeatMsg() #终端上报心跳协议
# msg = LoginReport_protocol().generateLoginMsg() #终端上报登录协议
# msg = SecurityStatusReport_protocol().generateSecurityStatusMsg() #终端上报安防状态协议
......@@ -47,6 +48,7 @@ msg = OBDReport_CAN_protocol().generateOBDReportCANMsg() #OBD终端
# msg = CommonReport_protocol().generateCommonMsg() #通用应答消息
# msg = VoltageDataReport_protocol().generateMsg() #终端上报电瓶电压采样数据
# msg = TroubleCode_protocol().generateMsg() #终端上报故障码数据包
msg = SensorSampling_protocol().generateMsg() #1.2.37终端上报Sensor采样数据
print(msg)
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