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
df74fb48
Commit
df74fb48
authored
Feb 10, 2020
by
liyuanhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
查询终端参数应答消息开发完成
parent
62293f11
Changes
12
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
341 additions
and
15 deletions
+341
-15
lib/protocol/ProtocolBase.py
lib/protocol/ProtocolBase.py
+15
-0
lib/protocol/message/Location_msg.py
lib/protocol/message/Location_msg.py
+4
-0
lib/protocol/message/QueryTerminalParam_res.py
lib/protocol/message/QueryTerminalParam_res.py
+261
-0
lib/protocol/message/TerminalHeartbeat_msg.py
lib/protocol/message/TerminalHeartbeat_msg.py
+4
-4
lib/protocol/messagePlateform/DataDownStreamTransport_res.py
lib/protocol/messagePlateform/DataDownStreamTransport_res.py
+1
-1
lib/protocol/messagePlateform/PlateformVersionInfo_res.py
lib/protocol/messagePlateform/PlateformVersionInfo_res.py
+2
-2
lib/protocol/messagePlateform/PlatformCommon_res.py
lib/protocol/messagePlateform/PlatformCommon_res.py
+1
-1
lib/protocol/messagePlateform/ResponseBase.py
lib/protocol/messagePlateform/ResponseBase.py
+0
-0
lib/protocol/messagePlateform/TerminalRegister_res.py
lib/protocol/messagePlateform/TerminalRegister_res.py
+1
-1
lib/protocol/messagePlateform/__init__.py
lib/protocol/messagePlateform/__init__.py
+0
-0
lib/socket/messageTest.py
lib/socket/messageTest.py
+51
-5
views/messageTools/message_process.py
views/messageTools/message_process.py
+1
-1
No files found.
lib/protocol/ProtocolBase.py
View file @
df74fb48
...
@@ -170,6 +170,19 @@ class ProtocolBase(Base):
...
@@ -170,6 +170,19 @@ class ProtocolBase(Base):
UTCTime
+=
self
.
int2hexString
(
int
(
timeArr
[
i
]))
UTCTime
+=
self
.
int2hexString
(
int
(
timeArr
[
i
]))
return
UTCTime
return
UTCTime
#####################################################
#16进制转换为UTC时间格式
#####################################################
def
hex2UTCTime
(
self
,
dataHex
):
theTime
=
"20"
theTime
=
theTime
+
str
(
int
(
dataHex
[:
2
],
16
))
theTime
=
theTime
+
"-"
+
str
(
int
(
dataHex
[
2
:
4
],
16
))
theTime
=
theTime
+
"-"
+
str
(
int
(
dataHex
[
4
:
6
],
16
))
theTime
=
theTime
+
" "
+
str
(
int
(
dataHex
[
6
:
8
],
16
))
theTime
=
theTime
+
":"
+
str
(
int
(
dataHex
[
8
:
10
],
16
))
theTime
=
theTime
+
":"
+
str
(
int
(
dataHex
[
10
:],
16
))
return
theTime
####################################################
####################################################
# 将整数转换为有符号的整数
# 将整数转换为有符号的整数
#####################################################
#####################################################
...
@@ -182,3 +195,5 @@ if __name__ == "__main__":
...
@@ -182,3 +195,5 @@ if __name__ == "__main__":
# print(ProtocolBase().int2hexStringByBytes(1,6))
# print(ProtocolBase().int2hexStringByBytes(1,6))
# print(ProtocolBase().num2signedNum(-5))
# print(ProtocolBase().num2signedNum(-5))
print
(
ProtocolBase
()
.
getUTCTimeHex
(
"2020-01-03 13:05:13"
))
print
(
ProtocolBase
()
.
getUTCTimeHex
(
"2020-01-03 13:05:13"
))
print
(
ProtocolBase
()
.
hex2UTCTime
(
"1401030d050d"
))
print
(
ProtocolBase
()
.
hex2UTCTime
(
"14020a07122b"
))
lib/protocol/message/Location_msg.py
View file @
df74fb48
...
@@ -403,6 +403,10 @@ if __name__ == "__main__":
...
@@ -403,6 +403,10 @@ if __name__ == "__main__":
print
(
Location_msg
()
.
getAlarmFlag
())
print
(
Location_msg
()
.
getAlarmFlag
())
print
(
Location_msg
()
.
getInfoTime
())
print
(
Location_msg
()
.
getInfoTime
())
print
(
Location_msg
()
.
generateMsg
())
print
(
Location_msg
()
.
generateMsg
())
lati
=
Location_msg
()
.
getLatitude
(
29.40268
)
print
(
lati
)
print
(
int
(
"01c329ed"
,
16
)
/
1000000
)
print
(
int
(
"0659dec5"
,
16
)
/
1000000
)
lib/protocol/message/QueryTerminalParam_res.py
0 → 100644
View file @
df74fb48
This diff is collapsed.
Click to expand it.
lib/protocol/message/TerminalHeartbeat_msg.py
View file @
df74fb48
lib/protocol/message
Res
/DataDownStreamTransport_res.py
→
lib/protocol/message
Plateform
/DataDownStreamTransport_res.py
View file @
df74fb48
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
定义平台通用应答消息解码类
定义平台通用应答消息解码类
'''
'''
from
lib.protocol.message.MessageBase
import
MessageBase
from
lib.protocol.message.MessageBase
import
MessageBase
from
lib.protocol.message
Res
.ResponseBase
import
ResponseBase
from
lib.protocol.message
Plateform
.ResponseBase
import
ResponseBase
class
DataDownStreamTransport_res
(
ResponseBase
):
class
DataDownStreamTransport_res
(
ResponseBase
):
...
...
lib/protocol/message
Res
/PlateformVersionInfo_res.py
→
lib/protocol/message
Plateform
/PlateformVersionInfo_res.py
View file @
df74fb48
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
定义平台版本信息包上传应答解码类
定义平台版本信息包上传应答解码类
'''
'''
from
lib.protocol.message.MessageBase
import
MessageBase
from
lib.protocol.message.MessageBase
import
MessageBase
from
lib.protocol.message
Res
.ResponseBase
import
ResponseBase
from
lib.protocol.message
Plateform
.ResponseBase
import
ResponseBase
class
PlatefromVersionInfo_res
(
ResponseBase
):
class
PlatefromVersionInfo_res
(
ResponseBase
):
...
@@ -72,7 +72,7 @@ class PlatefromVersionInfo_res(ResponseBase):
...
@@ -72,7 +72,7 @@ class PlatefromVersionInfo_res(ResponseBase):
plateformCurrentTime
=
self
.
getBCD2GMTTime
(
body
[:
12
])
#平台当前时间
plateformCurrentTime
=
self
.
getBCD2GMTTime
(
body
[:
12
])
#平台当前时间
carId
=
self
.
hexString2int
(
body
[
12
:
16
])
#车型id
carId
=
self
.
hexString2int
(
body
[
12
:
16
])
#车型id
displacement
=
self
.
hexString2int
(
body
[
16
:
20
])
#排量
displacement
=
self
.
hexString2int
(
body
[
16
:
20
])
#排量
isUpdate
=
body
[
20
:]
isUpdate
=
body
[
20
:]
#是否升级,0x55 升级,其他不升级
json_body
[
"plateformCurrentTime"
]
=
plateformCurrentTime
json_body
[
"plateformCurrentTime"
]
=
plateformCurrentTime
json_body
[
"carId"
]
=
carId
json_body
[
"carId"
]
=
carId
json_body
[
"displacement"
]
=
displacement
json_body
[
"displacement"
]
=
displacement
...
...
lib/protocol/message
Res
/PlatformCommon_res.py
→
lib/protocol/message
Plateform
/PlatformCommon_res.py
View file @
df74fb48
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
定义平台通用应答消息解码类
定义平台通用应答消息解码类
'''
'''
from
lib.protocol.message.MessageBase
import
MessageBase
from
lib.protocol.message.MessageBase
import
MessageBase
from
lib.protocol.message
Res
.ResponseBase
import
ResponseBase
from
lib.protocol.message
Plateform
.ResponseBase
import
ResponseBase
class
PlatformCommon_res
(
ResponseBase
):
class
PlatformCommon_res
(
ResponseBase
):
...
...
lib/protocol/message
Res
/ResponseBase.py
→
lib/protocol/message
Plateform
/ResponseBase.py
View file @
df74fb48
File moved
lib/protocol/message
Res
/TerminalRegister_res.py
→
lib/protocol/message
Plateform
/TerminalRegister_res.py
View file @
df74fb48
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
定义平台通用应答消息解码类
定义平台通用应答消息解码类
'''
'''
from
lib.protocol.message.MessageBase
import
MessageBase
from
lib.protocol.message.MessageBase
import
MessageBase
from
lib.protocol.message
Res
.ResponseBase
import
ResponseBase
from
lib.protocol.message
Plateform
.ResponseBase
import
ResponseBase
class
TerminalRegister_res
(
ResponseBase
):
class
TerminalRegister_res
(
ResponseBase
):
...
...
lib/protocol/message
Res
/__init__.py
→
lib/protocol/message
Plateform
/__init__.py
View file @
df74fb48
File moved
lib/socket/messageTest.py
View file @
df74fb48
#coding:utf-8
#coding:utf-8
import
binascii
import
binascii
import
socket
import
socket
from
time
import
sleep
from
lib.protocol.message.DataUpstreamTransport_msg
import
DataUpstreamTransport_msg
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.QueryTerminalParam_res
import
QueryTerminalParam_res
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.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.TerminalVersionInfo_msg
import
TerminalVersionInfo_msg
from
lib.protocol.message.TerminalVersionInfo_msg
import
TerminalVersionInfo_msg
from
lib.protocol.message.data.TerminalCancle_msg
import
TerminalCancle_msg
from
lib.protocol.message.data.TerminalCancle_msg
import
TerminalCancle_msg
from
lib.protocol.message
Res
.PlatformCommon_res
import
PlatformCommon_res
from
lib.protocol.message
Plateform
.PlatformCommon_res
import
PlatformCommon_res
from
lib.protocol.message
Res
.TerminalRegister_res
import
TerminalRegister_res
from
lib.protocol.message
Plateform
.TerminalRegister_res
import
TerminalRegister_res
host
=
"10.100.9.17"
host
=
"10.100.9.17"
port
=
9001
port
=
9001
...
@@ -24,11 +26,12 @@ port = 9001
...
@@ -24,11 +26,12 @@ port = 9001
# msg = TerminalCancle_msg().generateMsg() #终端注销
# msg = TerminalCancle_msg().generateMsg() #终端注销
# msg = TerminalAuthenticate_msg().generateMsg() #终端鉴权
# msg = TerminalAuthenticate_msg().generateMsg() #终端鉴权
# msg = TerminalVersionInfo_msg().generateMsg() #终端版本信息上报
# msg = TerminalVersionInfo_msg().generateMsg() #终端版本信息上报
msg
=
Location_msg
()
.
generateMsg
()
#位置信息汇报
msg
=
QueryTerminalParam_res
()
.
generateMsg
()
#查询终端参数应答
# msg = Location_msg().generateMsg() #位置信息汇报
# msg = DataUpstreamTransport_msg().generateMsg() #数据上行透传消息
# msg = DataUpstreamTransport_msg().generateMsg() #数据上行透传消息
#发送单条消息
#发送单条消息
def
sendSingleMsg
():
def
sendSingleMsg
(
msg
):
print
(
msg
)
print
(
msg
)
BUF_SIZE
=
1024
BUF_SIZE
=
1024
...
@@ -43,8 +46,51 @@ def sendSingleMsg():
...
@@ -43,8 +46,51 @@ def sendSingleMsg():
# print(TerminalRegister_res(data).getMsg())
# print(TerminalRegister_res(data).getMsg())
client
.
close
()
client
.
close
()
def
closeSocket
(
soc
):
soc
.
close
def
connectSock
():
client
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
client
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_KEEPALIVE
,
1
)
# 在客户端开启心跳
client
.
connect
((
host
,
port
))
return
client
def
sendMsg
(
client
,
msg
):
print
(
"发送的消息为:"
+
msg
)
BUF_SIZE
=
1024
client
.
send
(
binascii
.
a2b_hex
(
msg
))
data
=
client
.
recv
(
BUF_SIZE
)
if
PlatformCommon_res
(
data
)
.
getMsg
()[
"header"
][
"msgId"
]
==
"0100"
:
#终端注册应答
print
(
"收到的消息:"
+
str
(
TerminalRegister_res
(
data
)
.
getMsg
()))
else
:
print
(
"收到的消息:"
+
str
(
PlatformCommon_res
(
data
)
.
getMsg
()))
#平台通用应答
return
client
def
sendMultMsg
():
pass
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
sendSingleMsg
()
sendSingleMsg
(
msg
)
'''
print("发送终端注册消息")
client = connectSock()
msg = TerminalRegister_msg().generateMsg() #终端注册
sendMsg(client,msg)
sleep(2)
print("发送终端心跳消息")
msg = TerminalHeartbeat_msg().generateMsg() # 终端心跳
sendMsg(client,msg)
sleep(2)
print("发送终端鉴权消息")
msg = TerminalAuthenticate_msg().generateMsg() # 终端鉴权
sendMsg(client,msg)
sleep(2)
closeSocket(client)
print("断开连接")
'''
views/messageTools/message_process.py
View file @
df74fb48
...
@@ -4,7 +4,7 @@ from flask import Blueprint ,Response,request
...
@@ -4,7 +4,7 @@ from flask import Blueprint ,Response,request
from
configparser
import
ConfigParser
from
configparser
import
ConfigParser
from
lib.protocol.message.TerminalHeartbeat_msg
import
TerminalHeartbeat_msg
from
lib.protocol.message.TerminalHeartbeat_msg
import
TerminalHeartbeat_msg
from
lib.protocol.message
Res
.PlatformCommon_res
import
PlatformCommon_res
from
lib.protocol.message
Plateform
.PlatformCommon_res
import
PlatformCommon_res
from
lib.protocol.report.HeartBeatReport_protocol
import
HeartBeatReport_protocol
from
lib.protocol.report.HeartBeatReport_protocol
import
HeartBeatReport_protocol
from
lib.socket.ClientSocket
import
ClientSocket
from
lib.socket.ClientSocket
import
ClientSocket
...
...
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