Commit f210b84b authored by 李远洪's avatar 李远洪

调通终端注册上报消息

parent 419a5b42
This diff is collapsed.
......@@ -290,7 +290,7 @@ class Location_msg(MessageBase):
def getMsgHeader(self):
# msgID = self.int2hexStringByBytes(102,2) #消息id
msgID = "0002"
msgBodyProperty = self.getMsgBodyProperty(len(self.getMsgBody())) #消息体属性
msgBodyProperty = self.getMsgBodyProperty(int(len(self.getMsgBody()) / 2)) #消息体属性
phoneNum = self.int2BCD(13146201119) #终端手机号
msgWaterCode = self.int2BCD(1) #消息流水号
subPkgContent = "" #消息包封装项
......@@ -394,19 +394,6 @@ class Location_msg(MessageBase):
if __name__ == "__main__":
print(Location_msg().getAlarmFlag())
print(Location_msg().getInfoTime())
......
#encoding:utf-8
import datetime
from lib.protocol.Base import Base
'''
......@@ -124,6 +126,19 @@ class MessageBase(Base):
data = "0" + data
return data
#######################################################
# 获取UTC时间转换位BCD格式
#######################################################
def getBCDTime(self,data="2020-02-04 18:57:04"):
now_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
data = data
data = data.replace("-","")
data = data.replace(" ","")
data = data.replace(":","")
data = data[2:]
data = self.int2BCD(int(data))
return data
if __name__ == "__main__":
# print(MessageBase().str2Hex("uvwxyz"))
# print(MessageBase().str2Ascsii("uvwxyz"))
......
#encoding:utf-8
'''
定义设置终端参数消息
'''
import datetime
from lib.protocol.message.MessageBase import MessageBase
class SetTerminalParam_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 = ""
paramTotalNums = self.int2hexStringByBytes(1) #参数总数
return msg
#######################################################
# 获取消息头
#######################################################
def getMsgHeader(self):
# msgID = self.int2hexStringByBytes(102,2) #消息id
msgID = "0002"
msgBodyProperty = self.getMsgBodyProperty(int(len(self.getMsgBody()) / 2)) #消息体属性
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
......@@ -44,9 +44,9 @@ class TerminalAuthenticate_msg(MessageBase):
def getMsgHeader(self):
# msgID = self.int2hexStringByBytes(102,2) #消息id
msgID = "0102"
msgBodyProperty = self.getMsgBodyProperty(len(self.getMsgBody())) #消息体属性
msgBodyProperty = self.getMsgBodyProperty(int(len(self.getMsgBody()) / 2)) #消息体属性
phoneNum = self.int2BCD(13146201119) #终端手机号
msgWaterCode = self.int2BCD(1) #消息流水号
msgWaterCode = self.int2hexStringByBytes(1,2) #消息流水号
subPkgContent = "" #消息包封装项
data = msgID + msgBodyProperty + phoneNum + msgWaterCode + subPkgContent
return data
......
......@@ -44,7 +44,7 @@ class TerminalCommonMsgRes_msg(MessageBase):
msgID = self.int2hexStringByBytes(102,2) #消息id
msgBodyProperty = self.getMsgBodyProperty() #消息体属性
phoneNum = self.int2BCD(13146201118) #终端手机号
msgWaterCode = self.int2BCD(1) #消息流水号
msgWaterCode = self.int2hexStringByBytes(1,2) #消息流水号
subPkgContent = "" #消息包封装项
data = msgID + msgBodyProperty + phoneNum + msgWaterCode + subPkgContent
return data
......
......@@ -39,9 +39,9 @@ class TerminalHeartbeat_msg(MessageBase):
def getMsgHeader(self):
# msgID = self.int2hexStringByBytes(102,2) #消息id
msgID = "0002"
msgBodyProperty = self.getMsgBodyProperty(len(self.getMsgBody())) #消息体属性
msgBodyProperty = self.getMsgBodyProperty(int(len(self.getMsgBody()) / 2)) #消息体属性
phoneNum = self.int2BCD(13146201119) #终端手机号
msgWaterCode = self.int2BCD(1) #消息流水号
msgWaterCode = self.int2hexStringByBytes(1,2) #消息流水号
subPkgContent = "" #消息包封装项
data = msgID + msgBodyProperty + phoneNum + msgWaterCode + subPkgContent
return data
......
......@@ -31,6 +31,8 @@ class TerminalRegister_msg(MessageBase):
#######################################################
def getMsgBody(self):
msg = ""
# msgNums = self.int2hexStringByBytes(1,2)
# msgNumber = self.int2hexStringByBytes(1,2)
#市县域 ID (标示终端安装车辆所在的省域,0 保留,由平台取默认值。省 域 ID 采用 GB/T 2260 中规定的行政区划代 码六位中前两)
provinceId = "0103"
#制造商 ID (5 个字节,终端制造商编码)
......@@ -45,6 +47,7 @@ class TerminalRegister_msg(MessageBase):
carSign = str("渝B23CX".encode("gbk"))
carSign = carSign[2:len(carSign) - 1]
carSign = self.str2Hex(carSign)
# msg = msg + msgNums + msgNumber
msg = msg + provinceId + manufacturerId + terminalType + terminalId + licencePlateColor + carSign
return msg
......@@ -54,9 +57,9 @@ class TerminalRegister_msg(MessageBase):
def getMsgHeader(self):
# msgID = self.int2hexStringByBytes(102,2) #消息id
msgID = "0100"
msgBodyProperty = self.getMsgBodyProperty(len(self.getMsgBody())) #消息体属性
msgBodyProperty = self.getMsgBodyProperty(int(len(self.getMsgBody()) / 2)) #消息体属性
phoneNum = self.int2BCD(13146201119) #终端手机号
msgWaterCode = self.int2BCD(1) #消息流水号
msgWaterCode = self.int2hexStringByBytes(1,2) #消息流水号
subPkgContent = "" #消息包封装项
data = msgID + msgBodyProperty + phoneNum + msgWaterCode + subPkgContent
return data
......
......@@ -2,6 +2,7 @@
import binascii
import socket
from lib.protocol.message.DataUpstreamTransport_msg import DataUpstreamTransport_msg
from lib.protocol.message.Location_msg import Location_msg
from lib.protocol.message.MessageBase import MessageBase
from lib.protocol.message.TerminalAuthenticate_msg import TerminalAuthenticate_msg
......@@ -17,8 +18,9 @@ port = 9001
# msg = TerminalHeartbeat_msg().generateMsg() #终端心跳
# msg = TerminalRegister_msg().generateMsg() #终端注册
# msg = TerminalCancle_msg().generateMsg() #终端注销
msg = TerminalAuthenticate_msg().generateMsg() #终端鉴权
# msg = TerminalAuthenticate_msg().generateMsg() #终端鉴权
# msg = Location_msg().generateMsg() #位置信息汇报
msg = DataUpstreamTransport_msg().generateMsg() #数据上行透传消息
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