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
f210b84b
Commit
f210b84b
authored
Feb 06, 2020
by
李远洪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调通终端注册上报消息
parent
419a5b42
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
372 additions
and
22 deletions
+372
-22
lib/protocol/message/DataUpstreamTransport_msg.py
lib/protocol/message/DataUpstreamTransport_msg.py
+270
-0
lib/protocol/message/Location_msg.py
lib/protocol/message/Location_msg.py
+1
-14
lib/protocol/message/MessageBase.py
lib/protocol/message/MessageBase.py
+15
-0
lib/protocol/message/SetTerminalParam_msg.py
lib/protocol/message/SetTerminalParam_msg.py
+73
-0
lib/protocol/message/TerminalAuthenticate_msg.py
lib/protocol/message/TerminalAuthenticate_msg.py
+2
-2
lib/protocol/message/TerminalCommonMsgRes_msg.py
lib/protocol/message/TerminalCommonMsgRes_msg.py
+1
-1
lib/protocol/message/TerminalHeartbeat_msg.py
lib/protocol/message/TerminalHeartbeat_msg.py
+2
-2
lib/protocol/message/TerminalRegister_msg.py
lib/protocol/message/TerminalRegister_msg.py
+5
-2
lib/socket/messageTest.py
lib/socket/messageTest.py
+3
-1
No files found.
lib/protocol/message/DataUpstreamTransport_msg.py
0 → 100644
View file @
f210b84b
#encoding:utf-8
'''
定义数据上行透传消息
'''
import
datetime
from
lib.protocol.message.MessageBase
import
MessageBase
class
DataUpstreamTransport_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
=
""
#透传消息类型
#0xF1 驾驶行程数据(熄火发送)
# 0xF2 故障码数据(状态改变发送)
# 0xF3 休眠进入(进入休眠模式发送)
# 0xF4 休眠唤醒(退出休眠模式发送)
msgType
=
"F1"
msgContent
=
""
if
msgType
==
"F1"
:
msgContent
=
self
.
getDrivingData
()
#驾驶行程数据(熄火发送)
elif
msgType
==
"F2"
:
msgContent
=
self
.
getTroubleCodeData
()
#故障码数据(状态改变发送)
elif
msgType
==
"F3"
:
msgContent
=
self
.
getIntoSleepData
()
#休眠进入(进入休眠模式发送)
elif
msgType
==
"F4"
:
msgContent
=
self
.
getOutSleepData
()
#休眠唤醒(退出休眠模式发送)
msg
=
msgType
+
msgContent
return
msg
#######################################################
# 获取消息头
#######################################################
def
getMsgHeader
(
self
):
# msgID = self.int2hexStringByBytes(102,2) #消息id
msgID
=
"0900"
msgBodyProperty
=
self
.
getMsgBodyProperty
(
int
(
len
(
self
.
getMsgBody
())
/
2
))
#消息体属性
phoneNum
=
self
.
int2BCD
(
13146201119
)
#终端手机号
msgWaterCode
=
self
.
int2hexStringByBytes
(
1
,
2
)
#消息流水号
subPkgContent
=
""
#消息包封装项
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
#######################################################
# 获取驾驶行程数据
#######################################################
def
getDrivingData
(
self
):
time_1
=
"0001"
+
self
.
int2hexStringByBytes
(
6
)
+
self
.
getBCDTime
(
"2020-02-05 22:07:30"
)
time_2
=
"0002"
+
self
.
int2hexStringByBytes
(
6
)
+
self
.
getBCDTime
(
datetime
.
datetime
.
now
()
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
))
fireLatitude
=
"0003"
+
self
.
int2hexStringByBytes
(
4
)
+
self
.
getFireLatitude
(
29.40268
)
#点火纬度
fireLongitude
=
"0004"
+
self
.
int2hexStringByBytes
(
4
)
+
self
.
getFireLongitude
(
106.54041
)
#点火经度
unFireLatitude
=
"0005"
+
self
.
int2hexStringByBytes
(
4
)
+
self
.
getUnFireLatitude
(
29.40268
)
#熄火纬度
unFireLongitude
=
"0006"
+
self
.
int2hexStringByBytes
(
4
)
+
self
.
getUnFireLongitude
(
106.54041
)
# 熄火经度
drivingCircleLabel
=
"0007"
+
self
.
int2hexStringByBytes
(
2
)
+
self
.
int2hexStringByBytes
(
123
,
2
)
#驾驶循环标签
#一个驾驶循环总里程类型:
# 0x01:GPS 总里程(累计)
# 0x02:J1939 里程算法 1
# 0x03:J1939 里程算法 2
# 0x04:J1939 里程算法 3
# 0x05:J1939 里程算法 4
# 0x06:J1939 里程算法 5
# 0x07:OBD 仪表里程
# 0x08:OBD 速度里程
# 0x09:J1939 里程算法 6
# 0x0A:J1939 里程算法 7
# 0x0B:J1939 里程算法 8
# 0x0C:J1939 里程算法 9
drivingCircleTotalMileageType
=
"0008"
+
self
.
int2hexStringByBytes
(
1
)
+
"01"
#一个驾驶循环总里程,单位米
drivingCircleTotalMileage
=
"0009"
+
self
.
int2hexStringByBytes
(
4
)
+
self
.
int2hexStringByBytes
(
38090
,
4
)
#一个驾驶循环总耗油,单位毫升(ml)
drivingCircleTotalOil
=
"000A"
+
self
.
int2hexStringByBytes
(
4
)
+
self
.
int2hexStringByBytes
(
75400
,
4
)
#一个驾驶循环总时长,单位秒
drivingCircleTotalTime
=
"000B"
+
self
.
int2hexStringByBytes
(
4
)
+
self
.
int2hexStringByBytes
(
726000
,
4
)
#一个驾驶循环超速累计时长,单位秒
drivingCircleOverSpeedTotalTime
=
"000C"
+
self
.
int2hexStringByBytes
(
2
)
+
self
.
int2hexStringByBytes
(
54000
,
2
)
#一个驾驶循环超速次数,单位次
drivingCircleOverSpeedTotalTimes
=
"000D"
+
self
.
int2hexStringByBytes
(
2
)
+
self
.
int2hexStringByBytes
(
101
,
2
)
#一个驾驶循环平均车速,单位 KM/H
drivingCircleAverageSpeed
=
"000E"
+
self
.
int2hexStringByBytes
(
1
)
+
self
.
int2hexStringByBytes
(
65
)
#一个驾驶循环最大车速,单位 KM/H
drivingCircleMaxSpeed
=
"000F"
+
self
.
int2hexStringByBytes
(
1
)
+
self
.
int2hexStringByBytes
(
123
)
#一个驾驶循环怠速时长,单位秒
drivingCircleIdlingTime
=
"0010"
+
self
.
int2hexStringByBytes
(
4
)
+
self
.
int2hexStringByBytes
(
12600000
,
4
)
#一个驾驶循环脚刹次数支持与否,1 为支持
drivingCircleFootBrakeIsSupport
=
"0011"
+
self
.
int2hexStringByBytes
(
1
)
+
self
.
int2hexStringByBytes
(
1
)
#一个驾驶循环脚刹总次数,单位次
drivingCircleFootBrakeTatalTimes
=
"0012"
+
self
.
int2hexStringByBytes
(
1
)
+
self
.
int2hexStringByBytes
(
32
)
#一个驾驶循环急加速次数
drivingCircleRapidlyAccelerateTimes
=
"0013"
+
self
.
int2hexStringByBytes
(
4
)
+
self
.
int2hexStringByBytes
(
79
,
4
)
#一个驾驶循环急减速次数
drivingCircleSharpSlowdownTimes
=
"0014"
+
self
.
int2hexStringByBytes
(
4
)
+
self
.
int2hexStringByBytes
(
10
,
4
)
#一个驾驶循环急转弯次数
drivingCircleSharpCurveTimes
=
"0015"
+
self
.
int2hexStringByBytes
(
4
)
+
self
.
int2hexStringByBytes
(
33
,
4
)
#速度为-20Km/H 的里程,单位:m
speedIn20
=
"0016"
+
self
.
int2hexStringByBytes
(
4
)
+
self
.
int2hexStringByBytes
(
1068
,
4
)
#速度为 20-40Km/H 的里程,单位:m
speedIn20_40
=
"0017"
+
self
.
int2hexStringByBytes
(
4
)
+
self
.
int2hexStringByBytes
(
2020
,
4
)
#速度为 40-60Km/H 的里程,单位:m
speedIn40_60
=
"0018"
+
self
.
int2hexStringByBytes
(
4
)
+
self
.
int2hexStringByBytes
(
30400
,
4
)
#速度为 60-80Km/H 的里程,单位:m
speedIn60_80
=
"0019"
+
self
.
int2hexStringByBytes
(
4
)
+
self
.
int2hexStringByBytes
(
37000
,
4
)
#速度为 80-100Km/H 的里程,单位:m
speedIn80_100
=
"001A"
+
self
.
int2hexStringByBytes
(
4
)
+
self
.
int2hexStringByBytes
(
10400
,
4
)
#速度为 100-120Km/H 的里程,单位:m
speedIn100_120
=
"001B"
+
self
.
int2hexStringByBytes
(
4
)
+
self
.
int2hexStringByBytes
(
5000
,
4
)
#速度为 120Km/H 以上的里程,单位:m
speedOut120
=
"001C"
+
self
.
int2hexStringByBytes
(
4
)
+
self
.
int2hexStringByBytes
(
3200
,
4
)
#急加速总次数
rapidlyAccelerateTimes
=
"001D"
+
self
.
int2hexStringByBytes
(
4
)
+
self
.
int2hexStringByBytes
(
3000
,
4
)
#急减速总次数
rapidlySharpSlowdownTimes
=
"001E"
+
self
.
int2hexStringByBytes
(
4
)
+
self
.
int2hexStringByBytes
(
3507
,
4
)
#急转弯总次数
sharpCurveTimes
=
"001F"
+
self
.
int2hexStringByBytes
(
4
)
+
self
.
int2hexStringByBytes
(
580
,
4
)
data
=
time_1
+
time_2
+
fireLatitude
+
fireLongitude
+
unFireLatitude
data
=
data
+
unFireLongitude
+
drivingCircleLabel
+
drivingCircleTotalMileageType
+
drivingCircleTotalMileage
+
drivingCircleTotalOil
data
=
data
+
drivingCircleTotalTime
+
drivingCircleOverSpeedTotalTime
+
drivingCircleOverSpeedTotalTimes
+
drivingCircleAverageSpeed
+
drivingCircleMaxSpeed
data
=
data
+
drivingCircleIdlingTime
+
drivingCircleFootBrakeIsSupport
+
drivingCircleFootBrakeTatalTimes
+
drivingCircleRapidlyAccelerateTimes
+
drivingCircleSharpSlowdownTimes
data
=
data
+
drivingCircleSharpCurveTimes
+
speedIn20
+
speedIn20_40
+
speedIn40_60
+
speedIn60_80
data
=
data
+
speedIn80_100
+
speedIn100_120
+
speedOut120
+
rapidlyAccelerateTimes
+
rapidlySharpSlowdownTimes
data
=
data
+
sharpCurveTimes
return
data
#######################################################
# 获取点火纬度,单位:0.000001 度,Bit31=0/1 北纬/南纬
#######################################################
def
getFireLatitude
(
self
,
data
=
29.40268
):
orientation
=
0
#0:北纬 1:南纬 (2147483648)
data
=
int
(
data
*
1000000
)
data
=
data
+
orientation
dataHex
=
self
.
int2hexStringByBytes
(
data
,
4
)
return
dataHex
#######################################################
# 点火经度,单位:0.000001 度,Bit31=0/1 东经/西经
#######################################################
def
getFireLongitude
(
self
,
data
=
106.54041
):
orientation
=
0
#0:东经 1:西经 (2147483648)
data
=
int
(
data
*
1000000
)
data
=
data
+
orientation
dataHex
=
self
.
int2hexStringByBytes
(
data
,
4
)
return
dataHex
#######################################################
# 获取熄火纬度,单位:0.000001 度,Bit31=0/1 北纬/南纬
#######################################################
def
getUnFireLatitude
(
self
,
data
=
29.40268
):
orientation
=
0
#0:北纬 1:南纬 (2147483648)
data
=
int
(
data
*
1000000
)
data
=
data
+
orientation
dataHex
=
self
.
int2hexStringByBytes
(
data
,
4
)
return
dataHex
#######################################################
# 点火经度,单位:0.000001 度,Bit31=0/1 东经/西经
#######################################################
def
getUnFireLongitude
(
self
,
data
=
106.54041
):
orientation
=
0
#0:东经 1:西经 (2147483648)
data
=
int
(
data
*
1000000
)
data
=
data
+
orientation
dataHex
=
self
.
int2hexStringByBytes
(
data
,
4
)
return
dataHex
#######################################################
# 获取故障码数据
#######################################################
def
getTroubleCodeData
(
self
):
infoTime
=
self
.
getBCDTime
(
"2020-02-06 11:31:56"
)
#单位:0.000001 度,Bit31=0/1 北纬/南纬
latitude
=
self
.
getLatitude
(
29.40268
)
#单位:0.000001 度,Bit31=0/1 东经/西经
longitude
=
self
.
getLongitude
(
106.54041
)
#为 0 表示无故障码,非 0 为故障码个数
troubleCodeNums
=
3
troubleCodeNumsHex
=
self
.
int2hexStringByBytes
(
troubleCodeNums
)
#故障码
troubleCode
=
""
for
i
in
range
(
0
,
troubleCodeNums
):
systemId
=
self
.
int2hexStringByBytes
(
1
)
code1
=
self
.
int2hexStringByBytes
(
10
)
code2
=
self
.
int2hexStringByBytes
(
20
)
code3
=
self
.
int2hexStringByBytes
(
30
)
troubleCode
=
systemId
+
code1
+
code2
+
code3
data
=
infoTime
+
latitude
+
longitude
+
troubleCodeNumsHex
+
troubleCode
return
data
#获取维度
def
getLatitude
(
self
,
data
=
29.40268
):
orientation
=
0
#0:北纬 1:南纬 (2147483648)
data
=
int
(
data
*
1000000
)
data
=
data
+
orientation
dataHex
=
self
.
int2hexStringByBytes
(
data
,
4
)
return
dataHex
#获取经度
def
getLongitude
(
self
,
data
=
106.54041
):
orientation
=
0
#0:东经 1:西经 (2147483648)
data
=
int
(
data
*
1000000
)
data
=
data
+
orientation
dataHex
=
self
.
int2hexStringByBytes
(
data
,
4
)
return
dataHex
#######################################################
# 获取进入休眠数据包
#######################################################
def
getIntoSleepData
(
self
):
infoTime
=
self
.
getBCDTime
(
"2020-02-06 11:31:56"
)
msg
=
infoTime
return
msg
#######################################################
# 获取休眠唤醒数据包
#######################################################
def
getOutSleepData
(
self
):
infoTime
=
self
.
getBCDTime
(
"2020-02-06 11:31:56"
)
#休眠唤醒类型
# 0x01:休眠定时唤醒
# 0x02:CAN1
# 0x04:CAN2
# 0x08:gSensor 0x10:电压变
outSleepType
=
"01"
#车辆电压,单位 0.1V
carVoltage
=
self
.
int2hexStringByBytes
(
360
,
2
)
#振动唤醒加速度值,单位 mg
vibrateOutSleepSpeedUpVal
=
self
.
int2hexStringByBytes
(
3700
,
2
)
data
=
infoTime
+
outSleepType
+
carVoltage
+
vibrateOutSleepSpeedUpVal
return
data
if
__name__
==
"__main__"
:
print
(
DataUpstreamTransport_msg
()
.
generateMsg
())
lib/protocol/message/Location_msg.py
View file @
f210b84b
...
@@ -290,7 +290,7 @@ class Location_msg(MessageBase):
...
@@ -290,7 +290,7 @@ class Location_msg(MessageBase):
def
getMsgHeader
(
self
):
def
getMsgHeader
(
self
):
# msgID = self.int2hexStringByBytes(102,2) #消息id
# msgID = self.int2hexStringByBytes(102,2) #消息id
msgID
=
"0002"
msgID
=
"0002"
msgBodyProperty
=
self
.
getMsgBodyProperty
(
len
(
self
.
getMsgBody
()
))
#消息体属性
msgBodyProperty
=
self
.
getMsgBodyProperty
(
int
(
len
(
self
.
getMsgBody
())
/
2
))
#消息体属性
phoneNum
=
self
.
int2BCD
(
13146201119
)
#终端手机号
phoneNum
=
self
.
int2BCD
(
13146201119
)
#终端手机号
msgWaterCode
=
self
.
int2BCD
(
1
)
#消息流水号
msgWaterCode
=
self
.
int2BCD
(
1
)
#消息流水号
subPkgContent
=
""
#消息包封装项
subPkgContent
=
""
#消息包封装项
...
@@ -394,19 +394,6 @@ class Location_msg(MessageBase):
...
@@ -394,19 +394,6 @@ class Location_msg(MessageBase):
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
print
(
Location_msg
()
.
getAlarmFlag
())
print
(
Location_msg
()
.
getAlarmFlag
())
print
(
Location_msg
()
.
getInfoTime
())
print
(
Location_msg
()
.
getInfoTime
())
...
...
lib/protocol/message/MessageBase.py
View file @
f210b84b
#encoding:utf-8
#encoding:utf-8
import
datetime
from
lib.protocol.Base
import
Base
from
lib.protocol.Base
import
Base
'''
'''
...
@@ -124,6 +126,19 @@ class MessageBase(Base):
...
@@ -124,6 +126,19 @@ class MessageBase(Base):
data
=
"0"
+
data
data
=
"0"
+
data
return
data
return
data
#######################################################
# 获取UTC时间转换位BCD格式
#######################################################
def
getBCDTime
(
self
,
data
=
"2020-02-04 18:57:04"
):
now_time
=
datetime
.
datetime
.
now
()
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)
data
=
data
data
=
data
.
replace
(
"-"
,
""
)
data
=
data
.
replace
(
" "
,
""
)
data
=
data
.
replace
(
":"
,
""
)
data
=
data
[
2
:]
data
=
self
.
int2BCD
(
int
(
data
))
return
data
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
# print(MessageBase().str2Hex("uvwxyz"))
# print(MessageBase().str2Hex("uvwxyz"))
# print(MessageBase().str2Ascsii("uvwxyz"))
# print(MessageBase().str2Ascsii("uvwxyz"))
...
...
lib/protocol/message/SetTerminalParam_msg.py
0 → 100644
View file @
f210b84b
#encoding:utf-8
'''
定义设置终端参数消息
'''
import
datetime
from
lib.protocol.message.MessageBase
import
MessageBase
class
SetTerminalParam_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
=
""
paramTotalNums
=
self
.
int2hexStringByBytes
(
1
)
#参数总数
return
msg
#######################################################
# 获取消息头
#######################################################
def
getMsgHeader
(
self
):
# msgID = self.int2hexStringByBytes(102,2) #消息id
msgID
=
"0002"
msgBodyProperty
=
self
.
getMsgBodyProperty
(
int
(
len
(
self
.
getMsgBody
())
/
2
))
#消息体属性
phoneNum
=
self
.
int2BCD
(
13146201119
)
#终端手机号
msgWaterCode
=
self
.
int2hexStringByBytes
(
1
,
2
)
#消息流水号
subPkgContent
=
""
#消息包封装项
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
lib/protocol/message/TerminalAuthenticate_msg.py
View file @
f210b84b
...
@@ -44,9 +44,9 @@ class TerminalAuthenticate_msg(MessageBase):
...
@@ -44,9 +44,9 @@ class TerminalAuthenticate_msg(MessageBase):
def
getMsgHeader
(
self
):
def
getMsgHeader
(
self
):
# msgID = self.int2hexStringByBytes(102,2) #消息id
# msgID = self.int2hexStringByBytes(102,2) #消息id
msgID
=
"0102"
msgID
=
"0102"
msgBodyProperty
=
self
.
getMsgBodyProperty
(
len
(
self
.
getMsgBody
()
))
#消息体属性
msgBodyProperty
=
self
.
getMsgBodyProperty
(
int
(
len
(
self
.
getMsgBody
())
/
2
))
#消息体属性
phoneNum
=
self
.
int2BCD
(
13146201119
)
#终端手机号
phoneNum
=
self
.
int2BCD
(
13146201119
)
#终端手机号
msgWaterCode
=
self
.
int2
BCD
(
1
)
#消息流水号
msgWaterCode
=
self
.
int2
hexStringByBytes
(
1
,
2
)
#消息流水号
subPkgContent
=
""
#消息包封装项
subPkgContent
=
""
#消息包封装项
data
=
msgID
+
msgBodyProperty
+
phoneNum
+
msgWaterCode
+
subPkgContent
data
=
msgID
+
msgBodyProperty
+
phoneNum
+
msgWaterCode
+
subPkgContent
return
data
return
data
...
...
lib/protocol/message/TerminalCommonMsgRes_msg.py
View file @
f210b84b
...
@@ -44,7 +44,7 @@ class TerminalCommonMsgRes_msg(MessageBase):
...
@@ -44,7 +44,7 @@ class TerminalCommonMsgRes_msg(MessageBase):
msgID
=
self
.
int2hexStringByBytes
(
102
,
2
)
#消息id
msgID
=
self
.
int2hexStringByBytes
(
102
,
2
)
#消息id
msgBodyProperty
=
self
.
getMsgBodyProperty
()
#消息体属性
msgBodyProperty
=
self
.
getMsgBodyProperty
()
#消息体属性
phoneNum
=
self
.
int2BCD
(
13146201118
)
#终端手机号
phoneNum
=
self
.
int2BCD
(
13146201118
)
#终端手机号
msgWaterCode
=
self
.
int2
BCD
(
1
)
#消息流水号
msgWaterCode
=
self
.
int2
hexStringByBytes
(
1
,
2
)
#消息流水号
subPkgContent
=
""
#消息包封装项
subPkgContent
=
""
#消息包封装项
data
=
msgID
+
msgBodyProperty
+
phoneNum
+
msgWaterCode
+
subPkgContent
data
=
msgID
+
msgBodyProperty
+
phoneNum
+
msgWaterCode
+
subPkgContent
return
data
return
data
...
...
lib/protocol/message/TerminalHeartbeat_msg.py
View file @
f210b84b
...
@@ -39,9 +39,9 @@ class TerminalHeartbeat_msg(MessageBase):
...
@@ -39,9 +39,9 @@ class TerminalHeartbeat_msg(MessageBase):
def
getMsgHeader
(
self
):
def
getMsgHeader
(
self
):
# msgID = self.int2hexStringByBytes(102,2) #消息id
# msgID = self.int2hexStringByBytes(102,2) #消息id
msgID
=
"0002"
msgID
=
"0002"
msgBodyProperty
=
self
.
getMsgBodyProperty
(
len
(
self
.
getMsgBody
()
))
#消息体属性
msgBodyProperty
=
self
.
getMsgBodyProperty
(
int
(
len
(
self
.
getMsgBody
())
/
2
))
#消息体属性
phoneNum
=
self
.
int2BCD
(
13146201119
)
#终端手机号
phoneNum
=
self
.
int2BCD
(
13146201119
)
#终端手机号
msgWaterCode
=
self
.
int2
BCD
(
1
)
#消息流水号
msgWaterCode
=
self
.
int2
hexStringByBytes
(
1
,
2
)
#消息流水号
subPkgContent
=
""
#消息包封装项
subPkgContent
=
""
#消息包封装项
data
=
msgID
+
msgBodyProperty
+
phoneNum
+
msgWaterCode
+
subPkgContent
data
=
msgID
+
msgBodyProperty
+
phoneNum
+
msgWaterCode
+
subPkgContent
return
data
return
data
...
...
lib/protocol/message/TerminalRegister_msg.py
View file @
f210b84b
...
@@ -31,6 +31,8 @@ class TerminalRegister_msg(MessageBase):
...
@@ -31,6 +31,8 @@ class TerminalRegister_msg(MessageBase):
#######################################################
#######################################################
def
getMsgBody
(
self
):
def
getMsgBody
(
self
):
msg
=
""
msg
=
""
# msgNums = self.int2hexStringByBytes(1,2)
# msgNumber = self.int2hexStringByBytes(1,2)
#市县域 ID (标示终端安装车辆所在的省域,0 保留,由平台取默认值。省 域 ID 采用 GB/T 2260 中规定的行政区划代 码六位中前两)
#市县域 ID (标示终端安装车辆所在的省域,0 保留,由平台取默认值。省 域 ID 采用 GB/T 2260 中规定的行政区划代 码六位中前两)
provinceId
=
"0103"
provinceId
=
"0103"
#制造商 ID (5 个字节,终端制造商编码)
#制造商 ID (5 个字节,终端制造商编码)
...
@@ -45,6 +47,7 @@ class TerminalRegister_msg(MessageBase):
...
@@ -45,6 +47,7 @@ class TerminalRegister_msg(MessageBase):
carSign
=
str
(
"渝B23CX"
.
encode
(
"gbk"
))
carSign
=
str
(
"渝B23CX"
.
encode
(
"gbk"
))
carSign
=
carSign
[
2
:
len
(
carSign
)
-
1
]
carSign
=
carSign
[
2
:
len
(
carSign
)
-
1
]
carSign
=
self
.
str2Hex
(
carSign
)
carSign
=
self
.
str2Hex
(
carSign
)
# msg = msg + msgNums + msgNumber
msg
=
msg
+
provinceId
+
manufacturerId
+
terminalType
+
terminalId
+
licencePlateColor
+
carSign
msg
=
msg
+
provinceId
+
manufacturerId
+
terminalType
+
terminalId
+
licencePlateColor
+
carSign
return
msg
return
msg
...
@@ -54,9 +57,9 @@ class TerminalRegister_msg(MessageBase):
...
@@ -54,9 +57,9 @@ class TerminalRegister_msg(MessageBase):
def
getMsgHeader
(
self
):
def
getMsgHeader
(
self
):
# msgID = self.int2hexStringByBytes(102,2) #消息id
# msgID = self.int2hexStringByBytes(102,2) #消息id
msgID
=
"0100"
msgID
=
"0100"
msgBodyProperty
=
self
.
getMsgBodyProperty
(
len
(
self
.
getMsgBody
()
))
#消息体属性
msgBodyProperty
=
self
.
getMsgBodyProperty
(
int
(
len
(
self
.
getMsgBody
())
/
2
))
#消息体属性
phoneNum
=
self
.
int2BCD
(
13146201119
)
#终端手机号
phoneNum
=
self
.
int2BCD
(
13146201119
)
#终端手机号
msgWaterCode
=
self
.
int2
BCD
(
1
)
#消息流水号
msgWaterCode
=
self
.
int2
hexStringByBytes
(
1
,
2
)
#消息流水号
subPkgContent
=
""
#消息包封装项
subPkgContent
=
""
#消息包封装项
data
=
msgID
+
msgBodyProperty
+
phoneNum
+
msgWaterCode
+
subPkgContent
data
=
msgID
+
msgBodyProperty
+
phoneNum
+
msgWaterCode
+
subPkgContent
return
data
return
data
...
...
lib/socket/messageTest.py
View file @
f210b84b
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
import
binascii
import
binascii
import
socket
import
socket
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.TerminalAuthenticate_msg
import
TerminalAuthenticate_msg
from
lib.protocol.message.TerminalAuthenticate_msg
import
TerminalAuthenticate_msg
...
@@ -17,8 +18,9 @@ port = 9001
...
@@ -17,8 +18,9 @@ port = 9001
# msg = TerminalHeartbeat_msg().generateMsg() #终端心跳
# msg = TerminalHeartbeat_msg().generateMsg() #终端心跳
# msg = TerminalRegister_msg().generateMsg() #终端注册
# msg = TerminalRegister_msg().generateMsg() #终端注册
# msg = TerminalCancle_msg().generateMsg() #终端注销
# msg = TerminalCancle_msg().generateMsg() #终端注销
msg
=
TerminalAuthenticate_msg
()
.
generateMsg
()
#终端鉴权
#
msg = TerminalAuthenticate_msg().generateMsg() #终端鉴权
# msg = Location_msg().generateMsg() #位置信息汇报
# msg = Location_msg().generateMsg() #位置信息汇报
msg
=
DataUpstreamTransport_msg
()
.
generateMsg
()
#数据上行透传消息
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