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
fe8cf72f
Commit
fe8cf72f
authored
Feb 08, 2020
by
李远洪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加了一个函数
parent
ea864fb4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
108 additions
and
9 deletions
+108
-9
lib/protocol/message/MessageBase.py
lib/protocol/message/MessageBase.py
+36
-4
lib/protocol/message/TerminalVersionInfo_msg.py
lib/protocol/message/TerminalVersionInfo_msg.py
+67
-0
lib/socket/messageTest.py
lib/socket/messageTest.py
+5
-5
No files found.
lib/protocol/message/MessageBase.py
View file @
fe8cf72f
...
...
@@ -156,16 +156,48 @@ class MessageBase(Base):
data
=
self
.
int2BCD
(
int
(
data
))
return
data
#######################################################
# 获取UTC时间转换位BCD格式
#######################################################
def
GBKString2Hex
(
self
,
data
):
data
=
str
(
"渝B23CX"
.
encode
(
"gbk"
))
data
=
data
[
2
:
len
(
data
)
-
1
]
print
(
data
)
print
(
type
(
data
))
print
(
type
(
"
\xd3\xe5
B23CX"
))
print
(
data
==
"
\xd3\xe5
B23CX"
)
print
(
data
)
print
(
b
"
\xd3\xe5
B23CX"
)
data
=
self
.
str2Hex
(
data
)
return
data
#######################################################
# 16进制转字符串
#######################################################
def
hex2Str
(
self
,
data
):
theStr
=
""
while
data
!=
""
:
tmp
=
data
[:
2
]
data
=
data
[
2
:]
theStr
=
theStr
+
chr
(
int
(
tmp
,
16
))
return
theStr
if
__name__
==
"__main__"
:
# print(MessageBase().str2Hex("uvwxyz"))
#
print(MessageBase().str2Ascsii("uvwxyz"))
print
(
MessageBase
()
.
int2hexStringByBytes
(
220400566542345564784802
,
20
))
print
(
MessageBase
()
.
str2Ascsii
(
"uvwxyz"
))
#
print(MessageBase().int2hexStringByBytes(220400566542345564784802,20))
print
(
MessageBase
()
.
str2Hex
(
"a865h643gfdj64fd7432"
))
print
(
MessageBase
()
.
str2Hex
(
"
\xd3\xe5
B23CX"
))
print
(
MessageBase
()
.
hex2Str
(
"61383635683634336766646a3634666437343332"
))
# print(MessageBase().str2Hex("\xd3\xe5B23CX"))
# print(MessageBase().getMsgBodyProperty())
# print(MessageBase().int2BCD(13146201117))
# print(MessageBase().getCheckCode("8001000501314620111800000000000200"))
# print(MessageBase().getMsgHeader())
# print(MessageBase().generateMsg())
# print(MessageBase().GBKString2Hex("渝B23CX"))
lib/protocol/message/TerminalVersionInfo_msg.py
0 → 100644
View file @
fe8cf72f
#encoding:utf-8
'''
定义终端版本信息主动上报
'''
from
lib.protocol.message.MessageBase
import
MessageBase
class
Ter
minalVersionInfo_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
=
""
return
msg
#######################################################
# 获取消息头
#######################################################
def
getMsgHeader
(
self
):
# msgID = self.int2hexStringByBytes(102,2) #消息id
msgID
=
"0205"
subPkg
=
0
msgBodyProperty
=
self
.
getMsgBodyProperty
(
msgBodyLen
=
int
(
len
(
self
.
getMsgBody
())
/
2
),
subPkg
=
subPkg
)
#消息体属性
phoneNum
=
self
.
int2BCD
(
13146201119
)
#终端手机号
msgWaterCode
=
self
.
int2hexStringByBytes
(
1
,
2
)
#消息流水号
if
subPkg
!=
8192
:
subPkgContent
=
""
#消息包封装项
else
:
subPkgContent
=
self
.
getMsgPackage
()
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
if
__name__
==
"__main__"
:
pass
\ No newline at end of file
lib/socket/messageTest.py
View file @
fe8cf72f
...
...
@@ -18,8 +18,8 @@ port = 9001
# msg = MessageBase().generateMsg()
# msg = TerminalCommonMsgRes_msg().generateMsg() #终端通用应答
msg
=
TerminalHeartbeat_msg
()
.
generateMsg
()
#终端心跳
#
msg = TerminalRegister_msg().generateMsg() #终端注册
#
msg = TerminalHeartbeat_msg().generateMsg() #终端心跳
msg
=
TerminalRegister_msg
()
.
generateMsg
()
#终端注册
# msg = TerminalCancle_msg().generateMsg() #终端注销
# msg = TerminalAuthenticate_msg().generateMsg() #终端鉴权
# msg = Location_msg().generateMsg() #位置信息汇报
...
...
@@ -35,13 +35,13 @@ client.send(binascii.a2b_hex(msg))
# client.send(bytes.fromhex(msg))
data
=
client
.
recv
(
BUF_SIZE
)
print
(
binascii
.
a2b_hex
(
msg
))
print
(
data
)
# print(binascii.b2a_hex(data))
# print(PlatformCommon_res(data).binary2ascii(data))
# print(PlatformCommon_res(data).getOriginalMsg())
print
(
PlatformCommon_res
(
data
)
.
getMsg
())
#
print(TerminalRegister_res(data).getMsg())
#
print(PlatformCommon_res(data).getMsg())
print
(
TerminalRegister_res
(
data
)
.
getMsg
())
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