Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
new-socketemulator
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李远洪
new-socketemulator
Commits
f210b84b
Commit
f210b84b
authored
Feb 06, 2020
by
李远洪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调通终端注册上报消息
parent
419a5b42
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
372 additions
and
22 deletions
+372
-22
lib/protocol/message/DataUpstreamTransport_msg.py
lib/protocol/message/DataUpstreamTransport_msg.py
+270
-0
lib/protocol/message/Location_msg.py
lib/protocol/message/Location_msg.py
+1
-14
lib/protocol/message/MessageBase.py
lib/protocol/message/MessageBase.py
+15
-0
lib/protocol/message/SetTerminalParam_msg.py
lib/protocol/message/SetTerminalParam_msg.py
+73
-0
lib/protocol/message/TerminalAuthenticate_msg.py
lib/protocol/message/TerminalAuthenticate_msg.py
+2
-2
lib/protocol/message/TerminalCommonMsgRes_msg.py
lib/protocol/message/TerminalCommonMsgRes_msg.py
+1
-1
lib/protocol/message/TerminalHeartbeat_msg.py
lib/protocol/message/TerminalHeartbeat_msg.py
+2
-2
lib/protocol/message/TerminalRegister_msg.py
lib/protocol/message/TerminalRegister_msg.py
+5
-2
lib/socket/messageTest.py
lib/socket/messageTest.py
+3
-1
No files found.
lib/protocol/message/DataUpstreamTransport_msg.py
0 → 100644
View file @
f210b84b
This diff is collapsed.
Click to expand it.
lib/protocol/message/Location_msg.py
View file @
f210b84b
...
@@ -290,7 +290,7 @@ class Location_msg(MessageBase):
...
@@ -290,7 +290,7 @@ class Location_msg(MessageBase):
def
getMsgHeader
(
self
):
def
getMsgHeader
(
self
):
# msgID = self.int2hexStringByBytes(102,2) #消息id
# msgID = self.int2hexStringByBytes(102,2) #消息id
msgID
=
"0002"
msgID
=
"0002"
msgBodyProperty
=
self
.
getMsgBodyProperty
(
len
(
self
.
getMsgBody
()
))
#消息体属性
msgBodyProperty
=
self
.
getMsgBodyProperty
(
int
(
len
(
self
.
getMsgBody
())
/
2
))
#消息体属性
phoneNum
=
self
.
int2BCD
(
13146201119
)
#终端手机号
phoneNum
=
self
.
int2BCD
(
13146201119
)
#终端手机号
msgWaterCode
=
self
.
int2BCD
(
1
)
#消息流水号
msgWaterCode
=
self
.
int2BCD
(
1
)
#消息流水号
subPkgContent
=
""
#消息包封装项
subPkgContent
=
""
#消息包封装项
...
@@ -394,19 +394,6 @@ class Location_msg(MessageBase):
...
@@ -394,19 +394,6 @@ class Location_msg(MessageBase):
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
print
(
Location_msg
()
.
getAlarmFlag
())
print
(
Location_msg
()
.
getAlarmFlag
())
print
(
Location_msg
()
.
getInfoTime
())
print
(
Location_msg
()
.
getInfoTime
())
...
...
lib/protocol/message/MessageBase.py
View file @
f210b84b
#encoding:utf-8
#encoding:utf-8
import
datetime
from
lib.protocol.Base
import
Base
from
lib.protocol.Base
import
Base
'''
'''
...
@@ -124,6 +126,19 @@ class MessageBase(Base):
...
@@ -124,6 +126,19 @@ class MessageBase(Base):
data
=
"0"
+
data
data
=
"0"
+
data
return
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__"
:
if
__name__
==
"__main__"
:
# print(MessageBase().str2Hex("uvwxyz"))
# print(MessageBase().str2Hex("uvwxyz"))
# print(MessageBase().str2Ascsii("uvwxyz"))
# print(MessageBase().str2Ascsii("uvwxyz"))
...
...
lib/protocol/message/SetTerminalParam_msg.py
0 → 100644
View file @
f210b84b
#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
lib/protocol/message/TerminalAuthenticate_msg.py
View file @
f210b84b
...
@@ -44,9 +44,9 @@ class TerminalAuthenticate_msg(MessageBase):
...
@@ -44,9 +44,9 @@ class TerminalAuthenticate_msg(MessageBase):
def
getMsgHeader
(
self
):
def
getMsgHeader
(
self
):
# msgID = self.int2hexStringByBytes(102,2) #消息id
# msgID = self.int2hexStringByBytes(102,2) #消息id
msgID
=
"0102"
msgID
=
"0102"
msgBodyProperty
=
self
.
getMsgBodyProperty
(
len
(
self
.
getMsgBody
()
))
#消息体属性
msgBodyProperty
=
self
.
getMsgBodyProperty
(
int
(
len
(
self
.
getMsgBody
())
/
2
))
#消息体属性
phoneNum
=
self
.
int2BCD
(
13146201119
)
#终端手机号
phoneNum
=
self
.
int2BCD
(
13146201119
)
#终端手机号
msgWaterCode
=
self
.
int2
BCD
(
1
)
#消息流水号
msgWaterCode
=
self
.
int2
hexStringByBytes
(
1
,
2
)
#消息流水号
subPkgContent
=
""
#消息包封装项
subPkgContent
=
""
#消息包封装项
data
=
msgID
+
msgBodyProperty
+
phoneNum
+
msgWaterCode
+
subPkgContent
data
=
msgID
+
msgBodyProperty
+
phoneNum
+
msgWaterCode
+
subPkgContent
return
data
return
data
...
...
lib/protocol/message/TerminalCommonMsgRes_msg.py
View file @
f210b84b
...
@@ -44,7 +44,7 @@ class TerminalCommonMsgRes_msg(MessageBase):
...
@@ -44,7 +44,7 @@ class TerminalCommonMsgRes_msg(MessageBase):
msgID
=
self
.
int2hexStringByBytes
(
102
,
2
)
#消息id
msgID
=
self
.
int2hexStringByBytes
(
102
,
2
)
#消息id
msgBodyProperty
=
self
.
getMsgBodyProperty
()
#消息体属性
msgBodyProperty
=
self
.
getMsgBodyProperty
()
#消息体属性
phoneNum
=
self
.
int2BCD
(
13146201118
)
#终端手机号
phoneNum
=
self
.
int2BCD
(
13146201118
)
#终端手机号
msgWaterCode
=
self
.
int2
BCD
(
1
)
#消息流水号
msgWaterCode
=
self
.
int2
hexStringByBytes
(
1
,
2
)
#消息流水号
subPkgContent
=
""
#消息包封装项
subPkgContent
=
""
#消息包封装项
data
=
msgID
+
msgBodyProperty
+
phoneNum
+
msgWaterCode
+
subPkgContent
data
=
msgID
+
msgBodyProperty
+
phoneNum
+
msgWaterCode
+
subPkgContent
return
data
return
data
...
...
lib/protocol/message/TerminalHeartbeat_msg.py
View file @
f210b84b
...
@@ -39,9 +39,9 @@ class TerminalHeartbeat_msg(MessageBase):
...
@@ -39,9 +39,9 @@ class TerminalHeartbeat_msg(MessageBase):
def
getMsgHeader
(
self
):
def
getMsgHeader
(
self
):
# msgID = self.int2hexStringByBytes(102,2) #消息id
# msgID = self.int2hexStringByBytes(102,2) #消息id
msgID
=
"0002"
msgID
=
"0002"
msgBodyProperty
=
self
.
getMsgBodyProperty
(
len
(
self
.
getMsgBody
()
))
#消息体属性
msgBodyProperty
=
self
.
getMsgBodyProperty
(
int
(
len
(
self
.
getMsgBody
())
/
2
))
#消息体属性
phoneNum
=
self
.
int2BCD
(
13146201119
)
#终端手机号
phoneNum
=
self
.
int2BCD
(
13146201119
)
#终端手机号
msgWaterCode
=
self
.
int2
BCD
(
1
)
#消息流水号
msgWaterCode
=
self
.
int2
hexStringByBytes
(
1
,
2
)
#消息流水号
subPkgContent
=
""
#消息包封装项
subPkgContent
=
""
#消息包封装项
data
=
msgID
+
msgBodyProperty
+
phoneNum
+
msgWaterCode
+
subPkgContent
data
=
msgID
+
msgBodyProperty
+
phoneNum
+
msgWaterCode
+
subPkgContent
return
data
return
data
...
...
lib/protocol/message/TerminalRegister_msg.py
View file @
f210b84b
...
@@ -31,6 +31,8 @@ class TerminalRegister_msg(MessageBase):
...
@@ -31,6 +31,8 @@ class TerminalRegister_msg(MessageBase):
#######################################################
#######################################################
def
getMsgBody
(
self
):
def
getMsgBody
(
self
):
msg
=
""
msg
=
""
# msgNums = self.int2hexStringByBytes(1,2)
# msgNumber = self.int2hexStringByBytes(1,2)
#市县域 ID (标示终端安装车辆所在的省域,0 保留,由平台取默认值。省 域 ID 采用 GB/T 2260 中规定的行政区划代 码六位中前两)
#市县域 ID (标示终端安装车辆所在的省域,0 保留,由平台取默认值。省 域 ID 采用 GB/T 2260 中规定的行政区划代 码六位中前两)
provinceId
=
"0103"
provinceId
=
"0103"
#制造商 ID (5 个字节,终端制造商编码)
#制造商 ID (5 个字节,终端制造商编码)
...
@@ -45,6 +47,7 @@ class TerminalRegister_msg(MessageBase):
...
@@ -45,6 +47,7 @@ class TerminalRegister_msg(MessageBase):
carSign
=
str
(
"渝B23CX"
.
encode
(
"gbk"
))
carSign
=
str
(
"渝B23CX"
.
encode
(
"gbk"
))
carSign
=
carSign
[
2
:
len
(
carSign
)
-
1
]
carSign
=
carSign
[
2
:
len
(
carSign
)
-
1
]
carSign
=
self
.
str2Hex
(
carSign
)
carSign
=
self
.
str2Hex
(
carSign
)
# msg = msg + msgNums + msgNumber
msg
=
msg
+
provinceId
+
manufacturerId
+
terminalType
+
terminalId
+
licencePlateColor
+
carSign
msg
=
msg
+
provinceId
+
manufacturerId
+
terminalType
+
terminalId
+
licencePlateColor
+
carSign
return
msg
return
msg
...
@@ -54,9 +57,9 @@ class TerminalRegister_msg(MessageBase):
...
@@ -54,9 +57,9 @@ class TerminalRegister_msg(MessageBase):
def
getMsgHeader
(
self
):
def
getMsgHeader
(
self
):
# msgID = self.int2hexStringByBytes(102,2) #消息id
# msgID = self.int2hexStringByBytes(102,2) #消息id
msgID
=
"0100"
msgID
=
"0100"
msgBodyProperty
=
self
.
getMsgBodyProperty
(
len
(
self
.
getMsgBody
()
))
#消息体属性
msgBodyProperty
=
self
.
getMsgBodyProperty
(
int
(
len
(
self
.
getMsgBody
())
/
2
))
#消息体属性
phoneNum
=
self
.
int2BCD
(
13146201119
)
#终端手机号
phoneNum
=
self
.
int2BCD
(
13146201119
)
#终端手机号
msgWaterCode
=
self
.
int2
BCD
(
1
)
#消息流水号
msgWaterCode
=
self
.
int2
hexStringByBytes
(
1
,
2
)
#消息流水号
subPkgContent
=
""
#消息包封装项
subPkgContent
=
""
#消息包封装项
data
=
msgID
+
msgBodyProperty
+
phoneNum
+
msgWaterCode
+
subPkgContent
data
=
msgID
+
msgBodyProperty
+
phoneNum
+
msgWaterCode
+
subPkgContent
return
data
return
data
...
...
lib/socket/messageTest.py
View file @
f210b84b
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
import
binascii
import
binascii
import
socket
import
socket
from
lib.protocol.message.DataUpstreamTransport_msg
import
DataUpstreamTransport_msg
from
lib.protocol.message.Location_msg
import
Location_msg
from
lib.protocol.message.Location_msg
import
Location_msg
from
lib.protocol.message.MessageBase
import
MessageBase
from
lib.protocol.message.MessageBase
import
MessageBase
from
lib.protocol.message.TerminalAuthenticate_msg
import
TerminalAuthenticate_msg
from
lib.protocol.message.TerminalAuthenticate_msg
import
TerminalAuthenticate_msg
...
@@ -17,8 +18,9 @@ port = 9001
...
@@ -17,8 +18,9 @@ port = 9001
# msg = TerminalHeartbeat_msg().generateMsg() #终端心跳
# msg = TerminalHeartbeat_msg().generateMsg() #终端心跳
# 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
()
#数据上行透传消息
print
(
msg
)
print
(
msg
)
BUF_SIZE
=
1024
BUF_SIZE
=
1024
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment