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
517b34c9
Commit
517b34c9
authored
May 11, 2020
by
liyuanhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完成M500 故障码上报报文开发
parent
801bedcf
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
1 deletion
+89
-1
lib/protocol/report/TroubleCodeReport_protocol.py
lib/protocol/report/TroubleCodeReport_protocol.py
+84
-0
lib/socket/protocolTest_M500.py
lib/socket/protocolTest_M500.py
+3
-1
lib/socket/service/websocket_service.py
lib/socket/service/websocket_service.py
+2
-0
No files found.
lib/protocol/report/TroubleCodeReport_protocol.py
0 → 100644
View file @
517b34c9
#coding:utf-8
from
lib.protocol.report.ProtocolBase
import
ProtocolBase
'''
终端上报故障码数据包
'''
class
TroubleCode_protocol
(
ProtocolBase
):
def
__init__
(
self
,
msgCount
=
1
,
WATER_CODE
=
1000
,
DEV_ID
=
"M121501010001"
,
UTCTime
=
"2020-01-09 18:19:38"
,
troubleCodeNum
=
2
,
troubleCode
=
[{
"systemId"
:
"00"
,
"content1"
:
"00"
,
"content2"
:
"01"
,
"status"
:
0
},{
"systemId"
:
"00"
,
"content1"
:
"00"
,
"content2"
:
"02"
,
"status"
:
0
}],
MILStatus
=
1
):
super
()
.
__init__
()
self
.
msgCount
=
int
(
msgCount
)
# 设置默认要发送的GPS数据包个数
self
.
WATER_CODE
=
int
(
WATER_CODE
);
# 设置默认消息流水号
self
.
DEV_ID
=
DEV_ID
# 设置默认设备id
self
.
UTCTime
=
UTCTime
# 设置默认UTC时间
self
.
troubleCodeNum
=
troubleCodeNum
# 故障码个数
self
.
troubleCode
=
troubleCode
# 故障码内容
self
.
MILStatus
=
MILStatus
# MIL状态
#####################################################
# 生成故障码消息
#####################################################
def
generateMsg
(
self
):
info
=
""
HEADER
=
"4040"
#消息头
WATER_CODE
=
self
.
getWaterCode
(
self
.
WATER_CODE
)
#消息流水号
DEV_ID
=
self
.
devid2hexString
(
self
.
DEV_ID
)
#设备id
FUN_ID
=
"001A"
# 功能id(GPS功能id)
data
=
""
#数据段
for
i
in
range
(
0
,
self
.
msgCount
):
data
+=
self
.
generateData
()
LENGTH
=
self
.
getMsgLength
(
int
(
len
(
WATER_CODE
+
DEV_ID
+
FUN_ID
+
data
)
/
2
))
# 消息长度
info
+=
HEADER
info
+=
LENGTH
info
+=
WATER_CODE
info
+=
DEV_ID
info
+=
FUN_ID
info
+=
data
CHECK_CODE
=
self
.
getCheckCode
(
info
)
# 校验字段
info
+=
CHECK_CODE
return
info
#####################################################
# 创建故障码包数据段
#####################################################
def
generateData
(
self
):
data
=
""
# UTCTime = self.getUTCTime("2020-01-03 13:05:13")
UTCTime
=
self
.
getUTCTime
(
self
.
UTCTime
)
#时间信息
troubleCodeNum
=
self
.
int2hexStringByBytes
(
self
.
troubleCodeNum
)
#故障码个数
troubleCodeContent
=
""
for
i
in
range
(
0
,
len
(
self
.
troubleCode
)):
troubleCodeContent
=
troubleCodeContent
+
self
.
troubleCode
[
i
][
"systemId"
]
troubleCodeContent
=
troubleCodeContent
+
self
.
troubleCode
[
i
][
"content1"
]
troubleCodeContent
=
troubleCodeContent
+
self
.
troubleCode
[
i
][
"content2"
]
troubleCodeContent
=
troubleCodeContent
+
self
.
int2hexStringByBytes
(
int
(
self
.
troubleCode
[
i
][
"status"
]))
MILStatus
=
self
.
int2hexStringByBytes
(
self
.
MILStatus
)
data
=
data
+
UTCTime
+
troubleCodeNum
+
troubleCodeContent
+
MILStatus
return
data
#####################################################
# 将UTC时间转换为16进制,
# 例如:2020-01-02 20:30:00 (年取后面2字节)则将20,01,02,20,30,00 转换为对应的6个字节
# theTime:传入一个类似:2020-01-03 13:05:13的一个字符串
#####################################################
def
getUTCTime
(
self
,
theTime
):
# 获取当前时间,时间格式为:2020-01-03 13:05:13
# now_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
# 将2020-01-03 13:05:13时间格式转换为一个数组
# timeStr = "2020-01-03 13:05:13"
timeStr
=
theTime
timeArr
=
[]
timeArr
.
append
(
timeStr
[
2
:
4
])
timeArr
.
append
(
timeStr
[
5
:
7
])
timeArr
.
append
(
timeStr
[
8
:
11
])
timeArr
.
append
(
timeStr
[
11
:
13
])
timeArr
.
append
(
timeStr
[
14
:
16
])
timeArr
.
append
(
timeStr
[
17
:
19
])
UTCTime
=
""
for
i
in
range
(
0
,
len
(
timeArr
)):
UTCTime
+=
self
.
int2hexString
(
int
(
timeArr
[
i
]))
return
UTCTime
\ No newline at end of file
lib/socket/protocolTest_M500.py
View file @
517b34c9
...
...
@@ -4,6 +4,7 @@ import os
import
socket
import
sys
from
lib.protocol.report.TroubleCodeReport_protocol
import
TroubleCode_protocol
from
lib.protocol.report.VoltageDataReport_protocol
import
VoltageDataReport_protocol
curdir
=
os
.
getcwd
()
...
...
@@ -40,11 +41,12 @@ port = 9008
# msg = SecurityStatusReport_protocol().generateSecurityStatusMsg() #终端上报安防状态协议
# msg = BaseStationReport_protocol().generateBaseStationMsg() #终端上报基站定位协议
# msg = TroubleReport_protocol().generateTroubleMsg() #终端上报故障码数据包
msg
=
EventReport_protocol
()
.
generateEventMsg
()
#终端上报事件数据包
#
msg = EventReport_protocol().generateEventMsg() #终端上报事件数据包
# msg = VersionReport_protocol().generateVersionMsg() #终端上报版本信息数据包
# msg = SleepReport_protocol().generateSleepMsg() #终端休眠数据包
# msg = CommonReport_protocol().generateCommonMsg() #通用应答消息
# msg = VoltageDataReport_protocol().generateMsg() #终端上报电瓶电压采样数据
msg
=
TroubleCode_protocol
()
.
generateMsg
()
#终端上报故障码数据包
print
(
msg
)
BUF_SIZE
=
1024
...
...
lib/socket/service/websocket_service.py
View file @
517b34c9
...
...
@@ -96,6 +96,8 @@ class Websocket_service(SocketBase):
data
[
"msg"
]
=
"收到消息:"
+
msg
data
=
json
.
dumps
(
data
)
self
.
server
.
send_message
(
self
.
clients
[
clientId
],
data
)
print
(
self
.
clients
)
print
(
self
.
server
)
if
__name__
==
"__main__"
:
...
...
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