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
84c7ef62
Commit
84c7ef62
authored
May 15, 2020
by
liyuanhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完成M300 和M500 GPRS消息应答功能
parent
5faea552
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
341 additions
and
8 deletions
+341
-8
data/protocolTools/carData/M202003060520.json
data/protocolTools/carData/M202003060520.json
+1
-1
lib/protocol/appendix/EventClass.py
lib/protocol/appendix/EventClass.py
+2
-2
lib/protocol/m300/VersionInfo_protocol_m300.py
lib/protocol/m300/VersionInfo_protocol_m300.py
+1
-1
lib/protocol/m300/response/GPRS_protocol_response_m300.py
lib/protocol/m300/response/GPRS_protocol_response_m300.py
+66
-0
lib/protocol/m300/response/__init__.py
lib/protocol/m300/response/__init__.py
+0
-0
lib/protocol/report/EventReport_protocol.py
lib/protocol/report/EventReport_protocol.py
+3
-1
lib/protocol/report/SensorSampling_protocol.py
lib/protocol/report/SensorSampling_protocol.py
+188
-0
lib/protocol/report/SleepReport_protocol.py
lib/protocol/report/SleepReport_protocol.py
+2
-2
lib/protocol/report/response/GPRS_response.py
lib/protocol/report/response/GPRS_response.py
+75
-0
lib/socket/protocolTest_M500.py
lib/socket/protocolTest_M500.py
+3
-1
No files found.
data/protocolTools/carData/M202003060520.json
View file @
84c7ef62
{
"time"
:
{
"dateTime"
:
"2020-05-14 01:29:40"
,
"date"
:
"2020-05-14"
,
"time"
:
"01:29:40"
},
"curDayTravel"
:
{
"todayTotalMilleage"
:
9487
,
"todayTotalOil"
:
757
,
"todayTotalTime"
:
582
,
"theMilleage"
:
528
,
"theOil"
:
48
,
"theTime"
:
32
},
"travelData"
:
{
"totalMilleage"
:
262817
,
"totalOil"
:
24827
,
"totalTime"
:
15522
},
"event"
:
{
"threeRapid"
:
{
"totalRapidlyAccelerate"
:
14
,
"totalSharpSlowdown"
:
13
,
"totalSharpTurn"
:
13
}}}
{
"time"
:
{
"dateTime"
:
"2020-05-15 11:41:18"
,
"date"
:
"2020-05-15"
,
"time"
:
"11:41:18"
},
"curDayTravel"
:
{
"todayTotalMilleage"
:
0
,
"todayTotalOil"
:
0
,
"todayTotalTime"
:
0
,
"theMilleage"
:
0
,
"theOil"
:
0
,
"theTime"
:
0
},
"travelData"
:
{
"totalMilleage"
:
262817
,
"totalOil"
:
24827
,
"totalTime"
:
15522
},
"event"
:
{
"threeRapid"
:
{
"totalRapidlyAccelerate"
:
14
,
"totalSharpSlowdown"
:
13
,
"totalSharpTurn"
:
13
}}}
\ No newline at end of file
\ No newline at end of file
lib/protocol/appendix/EventClass.py
View file @
84c7ef62
...
@@ -184,7 +184,7 @@ class EventClass(ProtocolBase):
...
@@ -184,7 +184,7 @@ class EventClass(ProtocolBase):
return
data
return
data
#0023 碰撞报警附带信息
#0023 碰撞报警附带信息
def
collisionAlarmExtraInfo
(
self
,
totalCount
=
7
,
dataProperty
=
1
):
def
collisionAlarmExtraInfo
(
self
,
totalCount
=
7
,
dataProperty
=
2
):
totalCount
=
self
.
int2hexStringByBytes
(
totalCount
,
2
)
#历史碰撞总次数
totalCount
=
self
.
int2hexStringByBytes
(
totalCount
,
2
)
#历史碰撞总次数
# 1:表示事件发生时刻,前10秒的事件采样数据;
# 1:表示事件发生时刻,前10秒的事件采样数据;
# [碰撞报警前后10秒采样数据附带信息]
# [碰撞报警前后10秒采样数据附带信息]
...
@@ -267,7 +267,7 @@ class EventClass(ProtocolBase):
...
@@ -267,7 +267,7 @@ class EventClass(ProtocolBase):
def
SENSORDataFromSeconds
(
self
,
counts
):
def
SENSORDataFromSeconds
(
self
,
counts
):
data
=
""
data
=
""
for
i
in
range
(
0
,
counts
):
for
i
in
range
(
0
,
counts
):
data
+=
self
.
int2hexStringByBytes
(
30
,
2
)
#第
1秒内的第1
个0.5秒内的平均加速度值
data
+=
self
.
int2hexStringByBytes
(
30
,
2
)
#第
N秒内的第N
个0.5秒内的平均加速度值
return
data
return
data
...
...
lib/protocol/m300/VersionInfo_protocol_m300.py
View file @
84c7ef62
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
from
lib.protocol.m300.M300Base
import
M300Base
from
lib.protocol.m300.M300Base
import
M300Base
'''
'''
定义
心跳
议类
定义
终端版本协
议类
'''
'''
class
VersionInfo_protocol_m300
(
M300Base
):
class
VersionInfo_protocol_m300
(
M300Base
):
...
...
lib/protocol/m300/response/GPRS_protocol_response_m300.py
0 → 100644
View file @
84c7ef62
#encoding:utf-8
from
lib.protocol.m300.M300Base
import
M300Base
'''
定义终端版本协议类
'''
class
GPRS_protocol_response_m300
(
M300Base
):
dataTest
=
[{
"serverIndex"
:
"1"
,
"serverAddressType"
:
0
,
"serverAddress"
:
"10.100.12.31"
,
"comPort"
:
"9008"
,
"comType"
:
0
,
"APN"
:
"tnet"
,
\
"username"
:
"yuanhong"
,
"password"
:
"123456"
},{
"serverIndex"
:
"2"
,
"serverAddressType"
:
0
,
"serverAddress"
:
"10.100.12.31"
,
"comPort"
:
"9008"
,
"comType"
:
0
,
"APN"
:
"tnet"
,
\
"username"
:
"yuanhong"
,
"password"
:
"123456"
},{
"serverIndex"
:
"3"
,
"serverAddressType"
:
0
,
"serverAddress"
:
"10.100.12.31"
,
"comPort"
:
"9008"
,
"comType"
:
0
,
"APN"
:
"tnet"
,
\
"username"
:
"yuanhong"
,
"password"
:
"123456"
}]
def
__init__
(
self
,
waterCode
=
3
,
DEV_ID
=
"M121501010001"
,
encryptionType
=
0
,
data
=
[{
"serverIndex"
:
"1"
,
"serverAddressType"
:
0
,
"serverAddress"
:
"10.100.12.31"
,
"comPort"
:
"9008"
,
"comType"
:
0
,
"APN"
:
"tnet"
,
\
"username"
:
"yuanhong"
,
"password"
:
"123456"
},{
"serverIndex"
:
"2"
,
"serverAddressType"
:
0
,
"serverAddress"
:
"10.100.12.31"
,
"comPort"
:
"9008"
,
"comType"
:
0
,
"APN"
:
"tnet"
,
\
"username"
:
"yuanhong"
,
"password"
:
"123456"
},{
"serverIndex"
:
"3"
,
"serverAddressType"
:
0
,
"serverAddress"
:
"10.100.12.31"
,
"comPort"
:
"9008"
,
"comType"
:
0
,
"APN"
:
"tnet"
,
\
"username"
:
"yuanhong"
,
"password"
:
"123456"
}]):
super
()
.
__init__
()
# 不执行该方法,无法使用父类里面定义的属性
self
.
waterCode
=
waterCode
#消息流水号
self
.
DEV_ID
=
DEV_ID
#设备Id
self
.
encryptionType
=
encryptionType
#消息属性里面的是否加密字段
self
.
data
=
data
#################################################
# 生成消息
#################################################
def
generateMsg
(
self
):
msg
=
self
.
IDENTIFY
FUNID
=
"0104"
#功能id
waterCode
=
self
.
int2hexStringByBytes
(
self
.
waterCode
,
2
)
#消息流水号
DEV_ID
=
self
.
devid2hexString
(
self
.
DEV_ID
)
#设备id
msgBody
=
self
.
getMsgBody
()
# 消息体
msgLen
=
int
(
len
(
msgBody
)
/
2
)
property
=
self
.
getMsgProperty
(
msgBodyLen
=
msgLen
,
encryptionType
=
self
.
encryptionType
)
checkCode
=
self
.
getCheckCode
(
FUNID
+
waterCode
+
DEV_ID
+
property
+
msgBody
)
msg
=
msg
+
FUNID
+
waterCode
+
DEV_ID
+
property
+
msgBody
+
checkCode
+
self
.
IDENTIFY
return
msg
#################################################
# 获取消息体
#################################################
def
getMsgBody
(
self
):
dataHex
=
""
for
i
in
range
(
0
,
len
(
self
.
data
)):
dataHex
=
dataHex
+
self
.
str2Hex
(
self
.
data
[
i
][
"serverIndex"
])
#服务器索引号,从1开始
dataHex
=
dataHex
+
"2c"
#逗号
dataHex
=
dataHex
+
self
.
str2Hex
(
str
(
self
.
data
[
i
][
"serverAddressType"
]))
#服务器地址类型:0-IP地址,1-域名
dataHex
=
dataHex
+
"2c"
#逗号
dataHex
=
dataHex
+
self
.
str2Hex
(
self
.
data
[
i
][
"serverAddress"
])
#服务器地址
dataHex
=
dataHex
+
"2c"
#逗号
dataHex
=
dataHex
+
self
.
str2Hex
(
self
.
data
[
i
][
"comPort"
])
#TCP/UDP端口
dataHex
=
dataHex
+
"2c"
#逗号
dataHex
=
dataHex
+
self
.
str2Hex
(
str
(
self
.
data
[
i
][
"comType"
]))
#通讯模式:0-TCP,1-UDP
dataHex
=
dataHex
+
"2c"
#逗号
dataHex
=
dataHex
+
self
.
str2Hex
(
self
.
data
[
i
][
"APN"
])
#APN名称
dataHex
=
dataHex
+
"2c"
#逗号
dataHex
=
dataHex
+
self
.
str2Hex
(
self
.
data
[
i
][
"username"
])
#用户名
dataHex
=
dataHex
+
"2c"
#逗号
dataHex
=
dataHex
+
self
.
str2Hex
(
self
.
data
[
i
][
"password"
])
#密码
dataHex
=
dataHex
+
"0d"
#分隔符:0x0D
dataHex
=
dataHex
+
"0a"
#分隔符:0x0A
return
dataHex
if
__name__
==
"__main__"
:
print
(
GPRS_protocol_response_m300
()
.
generateMsg
())
\ No newline at end of file
lib/protocol/m300/response/__init__.py
0 → 100644
View file @
84c7ef62
lib/protocol/report/EventReport_protocol.py
View file @
84c7ef62
...
@@ -13,7 +13,7 @@ from lib.protocol.report.SecurityStatusReport_protocol import SecurityStatusRepo
...
@@ -13,7 +13,7 @@ from lib.protocol.report.SecurityStatusReport_protocol import SecurityStatusRepo
class
EventReport_protocol
(
ProtocolBase
):
class
EventReport_protocol
(
ProtocolBase
):
#data = {"WATER_CODE":"0003","DEV_ID":"M121501010001","gpsInfo":{"UTCTime":"2020-04-14 11:03:20","latitude":"40.22077","longitude":"116.23128","speed":"80.8","directionAngle":"80.8","elevation":"2999.9","positionStar":"3","Pdop":"0.3","Hdop":"0.4","Vdop":"0.5","statusBit":162,"valtage":"36.9","OBDSpeed":"60.9","engineSpeed":"3000","GPSTotalMileage":"12800","totalOil":"100000","totalTime":"2020002","GPSTimestamp":"1586833400"},"securityData":{"securityStatus":107,"doorStatus":0,"lockStatus":0,"windowStatus":0,"lightStatus":0,"onoffStatusA":0,"onoffStatusB":112,"dataByte":249},"event":{}}
#data = {"WATER_CODE":"0003","DEV_ID":"M121501010001","gpsInfo":{"UTCTime":"2020-04-14 11:03:20","latitude":"40.22077","longitude":"116.23128","speed":"80.8","directionAngle":"80.8","elevation":"2999.9","positionStar":"3","Pdop":"0.3","Hdop":"0.4","Vdop":"0.5","statusBit":162,"valtage":"36.9","OBDSpeed":"60.9","engineSpeed":"3000","GPSTotalMileage":"12800","totalOil":"100000","totalTime":"2020002","GPSTimestamp":"1586833400"},"securityData":{"securityStatus":107,"doorStatus":0,"lockStatus":0,"windowStatus":0,"lightStatus":0,"onoffStatusA":0,"onoffStatusB":112,"dataByte":249},"event":{}}
data
=
{}
data
=
{}
def
__init__
(
self
,
msgCount
=
1
,
WATER_CODE
=
26
,
DEV_ID
=
"M121501010001"
,
locationType
=
1
,
eventType
=
"00
36
"
,
data
=
{}):
def
__init__
(
self
,
msgCount
=
1
,
WATER_CODE
=
26
,
DEV_ID
=
"M121501010001"
,
locationType
=
1
,
eventType
=
"00
23
"
,
data
=
{}):
super
()
.
__init__
()
super
()
.
__init__
()
self
.
data
=
data
self
.
data
=
data
if
len
(
data
)
==
0
:
if
len
(
data
)
==
0
:
...
@@ -194,6 +194,8 @@ class EventReport_protocol(ProtocolBase):
...
@@ -194,6 +194,8 @@ class EventReport_protocol(ProtocolBase):
return
EventClass
()
.
defencesGlassNoCloseExtraInfo
()
return
EventClass
()
.
defencesGlassNoCloseExtraInfo
()
elif
eventType
==
"0017"
:
#设防非法开门报警
elif
eventType
==
"0017"
:
#设防非法开门报警
return
EventClass
()
.
defencesIllegalCloseDoorExtraInfo
()
return
EventClass
()
.
defencesIllegalCloseDoorExtraInfo
()
elif
eventType
==
"0023"
:
#碰撞告警
return
EventClass
()
.
collisionAlarmExtraInfo
()
elif
eventType
==
"0036"
:
#低档高速报警
elif
eventType
==
"0036"
:
#低档高速报警
return
EventClass
()
.
lowGearHighSpeedAlarm
()
return
EventClass
()
.
lowGearHighSpeedAlarm
()
elif
eventType
==
"0037"
:
#高档低速报警
elif
eventType
==
"0037"
:
#高档低速报警
...
...
lib/protocol/report/SensorSampling_protocol.py
0 → 100644
View file @
84c7ef62
# coding:utf-8
'''
定义一个Sensor 采样协议的类
'''
from
lib.protocol.report.GPSReport_protocol
import
GPSReport_protocol
from
lib.protocol.report.ProtocolBase
import
ProtocolBase
class
SensorSampling_protocol
(
ProtocolBase
):
testData
=
{
"time"
:
"2020-05-15 14:42:24"
,
"dataType"
:
"01"
,
"data"
:{}}
def
__init__
(
self
,
WATER_CODE
=
1000
,
DEV_ID
=
"M121501010001"
,
data
=
{
"time"
:
"2020-05-15 14:42:24"
,
"dataType"
:
"01"
,
"data"
:{}}):
super
()
.
__init__
()
self
.
WATER_CODE
=
int
(
WATER_CODE
)
# 设置默认消息流水号
self
.
DEV_ID
=
DEV_ID
# 设置默认设备id
self
.
time
=
data
[
"time"
]
# 时间
self
.
dataType
=
data
[
"dataType"
]
# 采样数据类型
#####################################################
# 生成 采样数据 消息
#####################################################
def
generateMsg
(
self
):
self
.
getProtocalHeader
()
info
=
""
HEADER
=
"4040"
#消息头
WATER_CODE
=
self
.
getWaterCode
(
self
.
WATER_CODE
)
#消息流水号
DEV_ID
=
self
.
devid2hexString
(
self
.
DEV_ID
)
#设备id
FUN_ID
=
"0031"
# 功能id
data
=
""
#数据段
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
):
timeHex
=
self
.
getUTCTime
(
self
.
time
)
dataTypeHex
=
self
.
dataType
dataContentHex
=
self
.
getMicroCollisionData
()
dataLenHex
=
self
.
int2hexStringByBytes
(
int
(
len
(
dataContentHex
)
/
2
),
2
)
data
=
timeHex
+
dataTypeHex
+
dataLenHex
+
dataContentHex
return
data
#####################################################
# 获取微碰撞数据包
#####################################################
def
getMicroCollisionData
(
self
,
totalConut
=
2
,
dataType
=
1
):
totalConutHex
=
self
.
int2hexStringByBytes
(
totalConut
,
2
)
#历史碰撞总次数
dataTypeHex
=
self
.
int2hexStringByBytes
(
dataType
)
# 1:表示事件发生时刻,前5秒的事件采样数据;
# [微碰撞前后5秒附带数据]
# 2:表示事件发生时刻,后5秒的事件采样数据;
# [微碰撞前后5秒附带数据]
# 3:表示事件发生时刻,后120秒的速度采样数据;
# [碰撞报警后120秒采样数据附带信息]
data
=
totalConutHex
+
dataTypeHex
if
dataType
==
1
or
dataType
==
2
:
GPSSampleData
=
self
.
GPSDataFromSeconds
(
5
)
# GPS 采样点 ,5秒内的GPS采样数据,85个字节
CANSampleData
=
self
.
CANDataFromSeconds
(
5
)
# CAN采样点 ,5秒内的CAN采样数据,90个字节
SENSORSampleData1
=
self
.
SENSORDataFromSeconds
(
10
)
# SENSOR采样点 ,10秒内的SENSOR采样数据
collisonFBSampleData_50
=
self
.
collisonFBSampleData
(
20
)
#碰撞时刻前后50毫秒内的SENSOR采样数据
collisonFBSampleData_100
=
self
.
collisonFBSampleData
(
40
)
# 碰撞时刻前后100毫秒内的SENSOR采样数据
collisonFBSampleData_125
=
self
.
collisonFBSampleData_xyz
(
50
)
#碰撞时刻前后125毫秒内的SENSOR采样数据
data
=
data
+
GPSSampleData
+
CANSampleData
+
SENSORSampleData1
+
collisonFBSampleData_50
+
collisonFBSampleData_100
+
collisonFBSampleData_125
else
:
pass
return
data
#####################################################
# 秒内的GPS采样数据
#####################################################
def
GPSDataFromSeconds
(
self
,
counts
):
data
=
""
for
i
in
range
(
0
,
counts
):
data
+=
self
.
GPSSamplingData
()
return
data
#####################################################
# N秒内的CAN采样数据
#####################################################
def
CANDataFromSeconds
(
self
,
counts
):
data
=
""
for
i
in
range
(
0
,
counts
):
data
+=
self
.
CANSamplingData
()
return
data
#####################################################
#23 GPS采样数据项
#####################################################
def
GPSSamplingData
(
self
):
latitude
=
40.22077
#纬度
longitude
=
116.23128
#经度
speed
=
60.9
#速度
directionAngle
=
80.8
#方向角
elevation
=
2999.9
#海拔
statusBit
=
1
#状态位,Bit7:当前定位是否有效,0-无效,1-有效,其它Bit位预留
latitude
=
GPSReport_protocol
()
.
getLatitude
(
latitude
)
longitude
=
GPSReport_protocol
()
.
getLongitude
(
longitude
)
speed
=
GPSReport_protocol
()
.
getSpeed
(
speed
)
directionAngle
=
GPSReport_protocol
()
.
getDirectionAngle
(
directionAngle
)
elevation
=
GPSReport_protocol
()
.
geteElevation
(
elevation
)
statusBit
=
GPSReport_protocol
()
.
getStatusBit
(
statusBit
)
data
=
latitude
+
longitude
+
speed
+
directionAngle
+
elevation
+
statusBit
return
data
#####################################################
#加速度CAN数据项
#####################################################
def
CANSamplingData
(
self
):
speed
=
65
#车速
enginSpeed
=
1000
#发动机转速
brakingStatus
=
0
#刹车状态:1-刹车,0-未刹车,2-不支持;
acceleratorLocation
=
50
#油门踏板位置
airDamper
=
17
#节气门开度
troubleCount
=
2
#故障码个数
speed
=
self
.
int2hexStringByBytes
(
speed
,
1
)
enginSpeed
=
self
.
int2hexStringByBytes
(
enginSpeed
,
2
)
brakingStatus
=
self
.
int2hexStringByBytes
(
brakingStatus
,
1
)
acceleratorLocation
=
self
.
int2hexStringByBytes
(
acceleratorLocation
,
2
)
airDamper
=
self
.
int2hexStringByBytes
(
airDamper
,
2
)
troubleCount
=
self
.
int2hexStringByBytes
(
troubleCount
,
1
)
data
=
speed
+
enginSpeed
+
brakingStatus
+
acceleratorLocation
+
airDamper
+
troubleCount
return
data
#####################################################
# N秒内的SENSOR采样数据
#####################################################
def
SENSORDataFromSeconds
(
self
,
counts
):
data
=
""
for
i
in
range
(
0
,
counts
):
data
+=
self
.
int2hexStringByBytes
(
30
,
2
)
#第N秒内的第1个0.5秒内的平均加速度值
return
data
#####################################################
# 碰撞时刻前后N毫秒内的SENSOR采样数据
#####################################################
def
collisonFBSampleData
(
self
,
counts
):
data
=
""
for
i
in
range
(
0
,
counts
):
data
+=
self
.
int2hexStringByBytes
(
30
,
2
)
# 第N个2.5毫秒采样点的采样加速度值
return
data
#####################################################
# 碰撞时刻前后N毫秒内的SENSOR采样数据 (xyz)
#####################################################
def
collisonFBSampleData_xyz
(
self
,
counts
):
data
=
""
for
i
in
range
(
0
,
counts
):
data
+=
self
.
int2hexStringByBytes
(
20
,
2
)
# 第N个2.5毫秒采样点的x轴加速度值
data
+=
self
.
int2hexStringByBytes
(
30
,
2
)
# 第N个2.5毫秒采样点的y轴加速度值
data
+=
self
.
int2hexStringByBytes
(
2
,
2
)
# 第N个2.5毫秒采样点的z轴加速度值
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
if
__name__
==
"__main__"
:
print
(
SensorSampling_protocol
()
.
generateMsg
())
lib/protocol/report/SleepReport_protocol.py
View file @
84c7ef62
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
from
lib.protocol.report.ProtocolBase
import
ProtocolBase
from
lib.protocol.report.ProtocolBase
import
ProtocolBase
class
SleepReport_protocol
(
ProtocolBase
):
class
SleepReport_protocol
(
ProtocolBase
):
def
__init__
(
self
,
msgCount
=
1
,
WATER_CODE
=
1000
,
DEV_ID
=
"M121501010001"
,
verInfo
=
"M100AB01010.0000"
,
compileDate
=
"2020-03-23"
,
GSM
=
"GSM_123456"
,
sleepType
=
"01"
,
sleepStatus
=
0
):
def
__init__
(
self
,
msgCount
=
1
,
WATER_CODE
=
1000
,
DEV_ID
=
"M121501010001"
,
sleepType
=
"01"
,
sleepStatus
=
0
):
super
()
.
__init__
()
super
()
.
__init__
()
self
.
msgCount
=
int
(
msgCount
)
# 设置默认要发送的GPS数据包个数
self
.
msgCount
=
int
(
msgCount
)
# 设置默认要发送的GPS数据包个数
...
@@ -48,7 +48,7 @@ class SleepReport_protocol(ProtocolBase):
...
@@ -48,7 +48,7 @@ class SleepReport_protocol(ProtocolBase):
return
data
return
data
#####################################################
#####################################################
# 创建
版本信息
数据段
# 创建
车机休眠数据段
数据段
#####################################################
#####################################################
def
generateSleepData
(
self
):
def
generateSleepData
(
self
):
sleepTypeHex
=
self
.
sleepType
sleepTypeHex
=
self
.
sleepType
...
...
lib/protocol/report/response/GPRS_response.py
0 → 100644
View file @
84c7ef62
#coding:utf-8
'''
定义一个查询GPRS应答数据包
'''
from
lib.protocol.report.ProtocolBase
import
ProtocolBase
class
Update_response
(
ProtocolBase
):
dataDefault
=
[{
"serverIndex"
:
"1"
,
"serverAddressType"
:
0
,
"serverAddress"
:
"10.100.12.31"
,
"comPort"
:
"9008"
,
"comType"
:
0
,
"APN"
:
"tnet"
,
\
"username"
:
"yuanhong"
,
"password"
:
"123456"
},{
"serverIndex"
:
"1"
,
"serverAddressType"
:
0
,
"serverAddress"
:
"10.100.12.31"
,
"comPort"
:
"9008"
,
"comType"
:
0
,
"APN"
:
"tnet"
,
\
"username"
:
"yuanhong"
,
"password"
:
"123456"
},{
"serverIndex"
:
"1"
,
"serverAddressType"
:
0
,
"serverAddress"
:
"10.100.12.31"
,
"comPort"
:
"9008"
,
"comType"
:
0
,
"APN"
:
"tnet"
,
\
"username"
:
"yuanhong"
,
"password"
:
"123456"
}]
def
__init__
(
self
,
msgCount
=
1
,
WATER_CODE
=
1000
,
DEV_ID
=
"M121501010001"
,
data
=
[{
"serverIndex"
:
"1"
,
"serverAddressType"
:
0
,
"serverAddress"
:
"10.100.12.31"
,
"comPort"
:
"9008"
,
"comType"
:
0
,
"APN"
:
"tnet"
,
\
"username"
:
"yuanhong"
,
"password"
:
"123456"
},{
"serverIndex"
:
"2"
,
"serverAddressType"
:
0
,
"serverAddress"
:
"10.100.12.31"
,
"comPort"
:
"9008"
,
"comType"
:
0
,
"APN"
:
"tnet"
,
\
"username"
:
"yuanhong"
,
"password"
:
"123456"
},{
"serverIndex"
:
"3"
,
"serverAddressType"
:
0
,
"serverAddress"
:
"10.100.12.31"
,
"comPort"
:
"9008"
,
"comType"
:
0
,
"APN"
:
"tnet"
,
\
"username"
:
"yuanhong"
,
"password"
:
"123456"
}]):
super
()
.
__init__
()
self
.
msgCount
=
int
(
msgCount
)
self
.
WATER_CODE
=
int
(
WATER_CODE
);
# 设置默认消息流水号
self
.
DEV_ID
=
DEV_ID
# 设置默认设备id
self
.
data
=
data
#####################################################
# 生成 GPRS应答 消息
#####################################################
def
generateMsg
(
self
):
self
.
getProtocalHeader
()
info
=
""
HEADER
=
"4040"
#消息头
WATER_CODE
=
self
.
getWaterCode
(
self
.
WATER_CODE
)
#消息流水号
DEV_ID
=
self
.
devid2hexString
(
self
.
DEV_ID
)
#设备id
FUN_ID
=
"8105"
# 功能id
data
=
""
#数据段
data
+=
self
.
generateUpdateData
()
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
#####################################################
# 创建 GPRS应答 数据段
#####################################################
def
generateUpdateData
(
self
):
dataHex
=
""
for
i
in
range
(
0
,
len
(
self
.
data
)):
dataHex
=
dataHex
+
self
.
str2Hex
(
self
.
data
[
i
][
"serverIndex"
])
#服务器索引号,从1开始
dataHex
=
dataHex
+
"2c"
#逗号
dataHex
=
dataHex
+
self
.
str2Hex
(
str
(
self
.
data
[
i
][
"serverAddressType"
]))
#服务器地址类型:0-IP地址,1-域名
dataHex
=
dataHex
+
"2c"
#逗号
dataHex
=
dataHex
+
self
.
str2Hex
(
self
.
data
[
i
][
"serverAddress"
])
#服务器地址
dataHex
=
dataHex
+
"2c"
#逗号
dataHex
=
dataHex
+
self
.
str2Hex
(
self
.
data
[
i
][
"comPort"
])
#TCP/UDP端口
dataHex
=
dataHex
+
"2c"
#逗号
dataHex
=
dataHex
+
self
.
str2Hex
(
str
(
self
.
data
[
i
][
"comType"
]))
#通讯模式:0-TCP,1-UDP
dataHex
=
dataHex
+
"2c"
#逗号
dataHex
=
dataHex
+
self
.
str2Hex
(
self
.
data
[
i
][
"APN"
])
#APN名称
dataHex
=
dataHex
+
"2c"
#逗号
dataHex
=
dataHex
+
self
.
str2Hex
(
self
.
data
[
i
][
"username"
])
#用户名
dataHex
=
dataHex
+
"2c"
#逗号
dataHex
=
dataHex
+
self
.
str2Hex
(
self
.
data
[
i
][
"password"
])
#密码
dataHex
=
dataHex
+
"0d"
#分隔符:0x0D
dataHex
=
dataHex
+
"0a"
#分隔符:0x0A
return
dataHex
if
__name__
==
"__main__"
:
print
(
Update_response
()
.
generateMsg
())
lib/socket/protocolTest_M500.py
View file @
84c7ef62
...
@@ -4,6 +4,7 @@ import os
...
@@ -4,6 +4,7 @@ import os
import
socket
import
socket
import
sys
import
sys
from
lib.protocol.report.SensorSampling_protocol
import
SensorSampling_protocol
from
lib.protocol.report.TroubleCodeReport_protocol
import
TroubleCode_protocol
from
lib.protocol.report.TroubleCodeReport_protocol
import
TroubleCode_protocol
from
lib.protocol.report.VoltageDataReport_protocol
import
VoltageDataReport_protocol
from
lib.protocol.report.VoltageDataReport_protocol
import
VoltageDataReport_protocol
...
@@ -35,7 +36,7 @@ port = 9008
...
@@ -35,7 +36,7 @@ port = 9008
# msg = GPSReport_protocol().generateGpsMsg() #GPS消息数据
# msg = GPSReport_protocol().generateGpsMsg() #GPS消息数据
# msg = OBDReport_protocol().generateOBDReportMsg() #OBD终端上报数据
# msg = OBDReport_protocol().generateOBDReportMsg() #OBD终端上报数据
msg
=
OBDReport_CAN_protocol
()
.
generateOBDReportCANMsg
()
#OBD终端上报CAN数据
#
msg = OBDReport_CAN_protocol().generateOBDReportCANMsg() #OBD终端上报CAN数据
# msg = HeartBeatReport_protocol().generateHeartBeatMsg() #终端上报心跳协议
# msg = HeartBeatReport_protocol().generateHeartBeatMsg() #终端上报心跳协议
# msg = LoginReport_protocol().generateLoginMsg() #终端上报登录协议
# msg = LoginReport_protocol().generateLoginMsg() #终端上报登录协议
# msg = SecurityStatusReport_protocol().generateSecurityStatusMsg() #终端上报安防状态协议
# msg = SecurityStatusReport_protocol().generateSecurityStatusMsg() #终端上报安防状态协议
...
@@ -47,6 +48,7 @@ msg = OBDReport_CAN_protocol().generateOBDReportCANMsg() #OBD终端
...
@@ -47,6 +48,7 @@ msg = OBDReport_CAN_protocol().generateOBDReportCANMsg() #OBD终端
# msg = CommonReport_protocol().generateCommonMsg() #通用应答消息
# msg = CommonReport_protocol().generateCommonMsg() #通用应答消息
# msg = VoltageDataReport_protocol().generateMsg() #终端上报电瓶电压采样数据
# msg = VoltageDataReport_protocol().generateMsg() #终端上报电瓶电压采样数据
# msg = TroubleCode_protocol().generateMsg() #终端上报故障码数据包
# msg = TroubleCode_protocol().generateMsg() #终端上报故障码数据包
msg
=
SensorSampling_protocol
()
.
generateMsg
()
#1.2.37终端上报Sensor采样数据
print
(
msg
)
print
(
msg
)
BUF_SIZE
=
1024
BUF_SIZE
=
1024
...
...
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