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
29c73da2
Commit
29c73da2
authored
Feb 07, 2020
by
李远洪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
终端应答消息解析类完成
parent
9bfdb547
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
120 additions
and
7 deletions
+120
-7
lib/protocol/message/TerminalCommonMsgRes_msg.py
lib/protocol/message/TerminalCommonMsgRes_msg.py
+1
-1
lib/protocol/messageRes/TerminalRegister_res.py
lib/protocol/messageRes/TerminalRegister_res.py
+109
-0
lib/socket/messageTest.py
lib/socket/messageTest.py
+10
-6
No files found.
lib/protocol/message/TerminalCommonMsgRes_msg.py
View file @
29c73da2
...
@@ -42,7 +42,7 @@ class TerminalCommonMsgRes_msg(MessageBase):
...
@@ -42,7 +42,7 @@ class TerminalCommonMsgRes_msg(MessageBase):
#######################################################
#######################################################
def
getMsgHeader
(
self
):
def
getMsgHeader
(
self
):
msgID
=
self
.
int2hexStringByBytes
(
102
,
2
)
#消息id
msgID
=
self
.
int2hexStringByBytes
(
102
,
2
)
#消息id
msgBodyProperty
=
self
.
getMsgBodyProperty
()
#消息体属性
msgBodyProperty
=
self
.
getMsgBodyProperty
(
int
(
len
(
self
.
getMsgBody
())
/
2
)
)
#消息体属性
phoneNum
=
self
.
int2BCD
(
13146201118
)
#终端手机号
phoneNum
=
self
.
int2BCD
(
13146201118
)
#终端手机号
msgWaterCode
=
self
.
int2hexStringByBytes
(
1
,
2
)
#消息流水号
msgWaterCode
=
self
.
int2hexStringByBytes
(
1
,
2
)
#消息流水号
subPkgContent
=
""
#消息包封装项
subPkgContent
=
""
#消息包封装项
...
...
lib/protocol/messageRes/TerminalRegister_res.py
0 → 100644
View file @
29c73da2
#encoding:utf-8
'''
定义平台通用应答消息解码类
'''
from
lib.protocol.message.MessageBase
import
MessageBase
from
lib.protocol.messageRes.ResponseBase
import
ResponseBase
class
TerminalRegister_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
.
getMsgHeader
()
json_msg
[
"body"
]
=
self
.
getMsgBody
()
json_msg
[
"checkCode"
]
=
self
.
getCheckCode
()
json_msg
[
"calculateCheckCode"
]
=
self
.
getCalculateCheckCode
()
#自己计算消息后得到的校验码
return
json_msg
#######################################################
# 获取消息头
#######################################################
def
getMsgHeader
(
self
):
json_header
=
{}
data
=
self
.
removeIdentify
(
self
.
msg
)
data
=
self
.
restore_7e7d
(
data
)
header
=
data
[:
24
]
msgId
=
header
[:
4
]
#消息id
msgBodyProperty
=
header
[
4
:
8
]
#消息体属性
phoneNum
=
header
[
8
:
20
]
#终端手机号
msgWaterCode
=
header
[
20
:
24
]
#消息流水号
json_header
[
"msgId"
]
=
int
(
msgId
,
16
)
json_header
[
"msgBodyProperty"
]
=
self
.
getMsgBodyProperty
(
msgBodyProperty
)
json_header
[
"phoneNum"
]
=
phoneNum
[
1
:]
json_header
[
"msgWaterCode"
]
=
int
(
msgWaterCode
,
16
)
return
json_header
#获取消息体属性
def
getMsgBodyProperty
(
self
,
data
):
data
=
self
.
int2binStr
(
int
(
data
),
2
)
data
=
self
.
restore_7e7d
(
data
)
json_data
=
{}
subPkg
=
data
[
2
:
3
]
#分包
encryptionType
=
data
[
3
:
6
]
#加密方式
msgBodyLen
=
data
[
6
:]
#消息体长度
json_data
[
"subPkg"
]
=
int
(
subPkg
,
2
)
json_data
[
"encryptionType"
]
=
int
(
encryptionType
,
2
)
json_data
[
"msgBodyLen"
]
=
int
(
msgBodyLen
,
2
)
return
json_data
#######################################################
# 获取消息体
#######################################################
def
getMsgBody
(
self
):
json_body
=
{}
data
=
self
.
removeIdentify
(
self
.
msg
)
data
=
self
.
restore_7e7d
(
data
)
dataLen
=
len
(
data
)
body
=
data
[
24
:
dataLen
-
2
]
resWaterCode
=
body
[:
4
]
#应答流水号
result
=
body
[
4
:
6
]
#结果
authenticationCode
=
body
[
6
:]
#鉴权码
json_body
[
"resWaterCode"
]
=
int
(
resWaterCode
,
16
)
json_body
[
"result"
]
=
int
(
result
,
16
)
json_body
[
"authenticationCode"
]
=
authenticationCode
return
json_body
#######################################################
# 获取校验码
#######################################################
def
getCheckCode
(
self
):
data
=
self
.
removeIdentify
(
self
.
msg
)
data
=
self
.
restore_7e7d
(
data
)
dataLen
=
len
(
data
)
checkCode
=
data
[
dataLen
-
2
:]
return
checkCode
#######################################################
# 计算消息得到校验码
#######################################################
def
getCalculateCheckCode
(
self
):
data
=
self
.
removeIdentify
(
self
.
msg
)
data
=
self
.
restore_7e7d
(
data
)
dataLen
=
len
(
data
)
data
=
data
[:
dataLen
-
2
]
calculateCheckCode
=
MessageBase
()
.
getCheckCode
(
data
)
return
calculateCheckCode
#######################################################
# 获取最原始的消息数据(没有替换7e,7d之前的状态)
#######################################################
def
getOriginalMsg
(
self
):
data
=
self
.
removeIdentify
(
self
.
msg
)
data
=
self
.
restore_7e7d
(
data
)
data
=
"7e"
+
data
+
"7e"
return
data
\ No newline at end of file
lib/socket/messageTest.py
View file @
29c73da2
...
@@ -6,20 +6,23 @@ from lib.protocol.message.DataUpstreamTransport_msg import DataUpstreamTransport
...
@@ -6,20 +6,23 @@ from lib.protocol.message.DataUpstreamTransport_msg import DataUpstreamTransport
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
from
lib.protocol.message.TerminalCommonMsgRes_msg
import
TerminalCommonMsgRes_msg
from
lib.protocol.message.TerminalHeartbeat_msg
import
TerminalHeartbeat_msg
from
lib.protocol.message.TerminalHeartbeat_msg
import
TerminalHeartbeat_msg
from
lib.protocol.message.TerminalRegister_msg
import
TerminalRegister_msg
from
lib.protocol.message.TerminalRegister_msg
import
TerminalRegister_msg
from
lib.protocol.message.data.TerminalCancle_msg
import
TerminalCancle_msg
from
lib.protocol.message.data.TerminalCancle_msg
import
TerminalCancle_msg
from
lib.protocol.messageRes.PlatformCommon_res
import
PlatformCommon_res
from
lib.protocol.messageRes.PlatformCommon_res
import
PlatformCommon_res
from
lib.protocol.messageRes.TerminalRegister_res
import
TerminalRegister_res
host
=
"10.100.9.17"
host
=
"10.100.9.17"
port
=
9001
port
=
9001
# msg = MessageBase().generateMsg()
# msg = MessageBase().generateMsg()
# msg = TerminalCommonMsgRes_msg().generateMsg() #终端通用应答
# 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() #数据上行透传消息
# msg = DataUpstreamTransport_msg().generateMsg() #数据上行透传消息
print
(
msg
)
print
(
msg
)
...
@@ -38,6 +41,7 @@ print(data)
...
@@ -38,6 +41,7 @@ print(data)
# print(binascii.b2a_hex(data))
# print(binascii.b2a_hex(data))
# print(PlatformCommon_res(data).binary2ascii(data))
# print(PlatformCommon_res(data).binary2ascii(data))
# print(PlatformCommon_res(data).getOriginalMsg())
# print(PlatformCommon_res(data).getOriginalMsg())
print
(
PlatformCommon_res
(
data
)
.
getMsg
())
# print(PlatformCommon_res(data).getMsg())
print
(
TerminalRegister_res
(
data
)
.
getMsg
())
client
.
close
()
client
.
close
()
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