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
49c66c3e
Commit
49c66c3e
authored
Feb 04, 2020
by
李远洪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
开发位置信息汇报消息,完成60%
parent
84b6d267
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
523 additions
and
16 deletions
+523
-16
lib/protocol/message/Location_msg.py
lib/protocol/message/Location_msg.py
+387
-0
lib/socket/messageTest.py
lib/socket/messageTest.py
+3
-16
lib/util/dataUtil.py
lib/util/dataUtil.py
+108
-0
lib/util/locationUtil.py
lib/util/locationUtil.py
+24
-0
lib/util/logUtil.py
lib/util/logUtil.py
+1
-0
views/messageTools/__init__.py
views/messageTools/__init__.py
+0
-0
No files found.
lib/protocol/message/Location_msg.py
0 → 100644
View file @
49c66c3e
This diff is collapsed.
Click to expand it.
lib/socket/messageTest.py
View file @
49c66c3e
...
...
@@ -5,19 +5,6 @@ from lib.protocol.message.MessageBase import MessageBase
from
lib.protocol.message.TerminalHeartbeat_msg
import
TerminalHeartbeat_msg
from
lib.protocol.messageRes.PlatformCommon_res
import
PlatformCommon_res
def
back7e7d
(
data
):
data
=
data
.
replace
(
"7d02"
,
"7e"
)
data
=
data
.
replace
(
"7d01"
,
"7d"
)
return
data
def
binary2ascii
(
binData
):
strs
=
binascii
.
b2a_hex
(
binData
)
data
=
str
(
strs
)[
2
:]
return
data
host
=
"10.100.9.17"
port
=
9001
...
...
@@ -36,9 +23,9 @@ data = client.recv(BUF_SIZE)
print
(
data
)
print
(
binascii
.
b2a_hex
(
data
))
print
(
PlatformCommon_res
(
data
)
.
binary2ascii
(
data
))
print
(
PlatformCommon_res
(
data
)
.
getOriginalMsg
())
#
print(binascii.b2a_hex(data))
#
print(PlatformCommon_res(data).binary2ascii(data))
#
print(PlatformCommon_res(data).getOriginalMsg())
print
(
PlatformCommon_res
(
data
)
.
getMsg
())
client
.
close
()
lib/util/dataUtil.py
0 → 100644
View file @
49c66c3e
#coding:utf-8
'''
定义一个处理数据包的辅助方法集合
'''
from
binascii
import
*
from
crcmod
import
*
import
struct
#####################################################
# 定义生成校验字段的函数(自己翻译的函数,简化了很多步骤)
#####################################################
def
myCrc16
(
msg
):
msg
=
str2Ascsii
(
msg
)
crc
=
0xFFFF
for
i
in
range
(
0
,
len
(
msg
)):
for
j
in
range
(
0
,
8
):
cl5
=
((
crc
>>
15
&
1
)
==
1
)
bit
=
((
msg
[
i
]
>>
(
7
-
j
)
&
1
)
==
1
)
crc
<<=
1
# 通过与0xFFFF(即二进制:1111111111111111)做了一个或运算,将其转换为一个有符号的数
crc
&=
0xFFFF
if
(
cl5
^
bit
):
crc
^=
0x1021
;
crc
=
hex
(
crc
)
# 将10进制的crc转换为16进制
crc
=
str
(
crc
)[
2
:]
# 将16进制转换为字符串,并去掉前面的0x
return
crc
#####################################################
# 定义生成校验字段的函数
# inputStr:需要传入一个已经转换为16进制的字符串
#####################################################
# add crc 16 check at the end of the string
def
crc16
(
inputStr
):
inputStrByte
=
bytes
.
fromhex
(
inputStr
)
crc
=
0xFFFF
for
i
in
range
(
0
,
len
(
inputStrByte
)):
for
j
in
range
(
0
,
8
):
c15
=
(
crc
>>
15
)
==
1
bit
=
((
inputStrByte
[
i
]
>>
(
7
-
j
))
&
1
)
==
1
crc
<<=
1
crc
&=
0xFFFF
if
c15
^
bit
:
crc
^=
0x1021
crc
=
str
(
hex
(
crc
))
crc
=
leftPad
(
crc
[
2
:],
4
)
# outputStr = inputStr + crc
outputStr
=
crc
return
outputStr
# pad zero to the left of the string if not long enough
def
leftPad
(
inputStr
,
strLen
):
if
(
strLen
>
len
(
inputStr
)):
outputStr
=
"0000000000000000000000000000000000000000"
+
inputStr
outputStr
=
outputStr
[
len
(
outputStr
)
-
strLen
:]
return
outputStr
else
:
return
inputStr
# pad zero to the right of the string if not long enough
def
rightPad
(
inputStr
,
strLen
):
if
(
strLen
>
len
(
inputStr
)):
outputStr
=
inputStr
+
"0000000000000000000000000000000000000000"
outputStr
=
outputStr
[:
strLen
]
return
outputStr
else
:
return
inputStr
#####################################################
# 将字符串转换为16进制的数字字符串
#####################################################
def
str2Hex
(
s
):
s_hex
=
""
for
i
in
range
(
len
(
s
)):
s_hex
=
s_hex
+
hex
(
ord
(
s
[
i
]))[
2
:]
+
" "
return
s_hex
#####################################################
# 将字符串转换为16进制的数字字符串,并去掉空格
#####################################################
def
str2HexStrip
(
s
):
s
=
str2Hex
(
s
)
s2
=
s
.
replace
(
" "
,
""
)
return
s2
#####################################################
# 将字符串转换为对应的ascii值数组
#####################################################
def
str2Ascsii
(
s
):
asciiArr
=
[]
for
i
in
range
(
0
,
len
(
s
)):
asciiValue
=
ord
(
s
[
i
])
asciiArr
.
append
(
asciiValue
)
return
asciiArr
if
__name__
==
"__main__"
:
print
(
crc16
(
str2Hex
(
"aa"
)))
print
(
str2Hex
(
"aa"
))
print
(
str2HexStrip
(
"aa"
))
print
(
str2Ascsii
(
"aa"
))
print
(
myCrc16
(
"aa"
))
print
(
crc16
(
str2HexStrip
(
"aa"
)))
lib/util/locationUtil.py
0 → 100644
View file @
49c66c3e
#coding:utf-8
'''
定义一个获取经纬度的辅助方法集合
'''
import
json
#####################################################
# 获取文件的金纬度数据,返回一个经纬度数组
# path:传入文件路径
#####################################################
def
getLocationInfo
(
path
):
with
open
(
path
,
"r"
,
encoding
=
'utf-8'
)
as
fi
:
loc_data
=
fi
.
readlines
()
strData
=
""
for
lineD
in
loc_data
:
strData
+=
lineD
json_data
=
json
.
loads
(
strData
)
return
json_data
[
"locationInfo"
]
if
__name__
==
"__main__"
:
print
(
getLocationInfo
(
"../../data/protocolTools/GPSLine_1.json"
))
\ No newline at end of file
lib/util/logUtil.py
0 → 100644
View file @
49c66c3e
#coding:utf-8
views/messageTools/__init__.py
0 → 100644
View file @
49c66c3e
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