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
32ef4e2f
Commit
32ef4e2f
authored
Apr 26, 2020
by
liyuanhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
M500 和新车机模拟器,增加了方向角的功能
parent
c2a364ff
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
132 additions
and
9 deletions
+132
-9
data/messageTools/carData/012201500010.json
data/messageTools/carData/012201500010.json
+1
-1
lib/protocol/message/MessageBase.py
lib/protocol/message/MessageBase.py
+1
-1
lib/protocol/report/GPSReport_protocol.py
lib/protocol/report/GPSReport_protocol.py
+5
-4
lib/socket/service/MessageSimulaterService.py
lib/socket/service/MessageSimulaterService.py
+57
-0
lib/socket/service/ProtocolSimulaterService.py
lib/socket/service/ProtocolSimulaterService.py
+68
-3
No files found.
data/messageTools/carData/012201500010.json
View file @
32ef4e2f
{
"time"
:
{
"dateTime"
:
"2020-04-24 11:28:51"
,
"date"
:
"2020-04-24"
,
"time"
:
"11:28:51"
},
"curDayTravel"
:
{
"todayTotalMilleage"
:
3675
,
"todayTotalOil"
:
434
,
"todayTotalTime"
:
277
,
"theMilleage"
:
640
,
"theOil"
:
40
,
"theTime"
:
40
},
"travelData"
:
{
"totalMilleage"
:
3675
,
"totalOil"
:
434
,
"totalTime"
:
277
}}
\ No newline at end of file
{
"time"
:
{
"dateTime"
:
"2020-04-26 16:03:38"
,
"date"
:
"2020-04-26"
,
"time"
:
"16:03:38"
},
"curDayTravel"
:
{
"todayTotalMilleage"
:
4191
,
"todayTotalOil"
:
381
,
"todayTotalTime"
:
254
,
"theMilleage"
:
4191
,
"theOil"
:
381
,
"theTime"
:
254
},
"travelData"
:
{
"totalMilleage"
:
7866
,
"totalOil"
:
815
,
"totalTime"
:
531
}}
\ No newline at end of file
lib/protocol/message/MessageBase.py
View file @
32ef4e2f
...
...
@@ -223,7 +223,7 @@ class MessageBase(Base):
dataHex
=
""
strLen
=
len
(
data
)
for
i
in
range
(
0
,
strLen
):
if
re
.
search
(
"[0-9a-zA-Z]"
,
data
[
i
])
!=
None
:
if
re
.
search
(
"[0-9a-zA-Z
-_
]"
,
data
[
i
])
!=
None
:
dataHex
=
dataHex
+
self
.
str2Hex
(
data
[
i
])
else
:
temp
=
str
(
data
[
i
]
.
encode
(
"gbk"
))
.
replace
(
"
\\
x"
,
""
)
...
...
lib/protocol/report/GPSReport_protocol.py
View file @
32ef4e2f
...
...
@@ -258,10 +258,11 @@ class GPSReport_protocol(ProtocolBase):
# 方向角2个字节表示
#####################################################
def
getDirectionAngle
(
self
,
num
):
angleStr
=
str
(
num
)
angleStr
=
angleStr
.
replace
(
"."
,
""
)
# 去掉经度小数点
angleHex
=
hex
(
int
(
angleStr
))
angleHex
=
self
.
leftPad
(
str
(
angleHex
)[
2
:],
4
)
# angleStr = str(num)
# angleStr = angleStr.replace(".", "")
# angleHex = hex(int(angleStr))
# angleHex = self.leftPad(str(angleHex)[2:], 4)
angleHex
=
self
.
int2hexStringByBytes
(
int
(
num
*
10
),
2
)
return
angleHex
#####################################################
...
...
lib/socket/service/MessageSimulaterService.py
View file @
32ef4e2f
...
...
@@ -5,6 +5,7 @@
'''
import
binascii
import
json
import
math
import
os
import
threading
import
time
...
...
@@ -34,6 +35,7 @@ class MessageSimulaterService():
self
.
carId
=
""
#车机号
self
.
sn
=
0
#消息流水号
self
.
travelDirection
=
0
#行驶方向,0表示正向行驶,1表示反向行驶
self
.
directAngle
=
59
#定义默认方向角
# 定义要发送的obd数据
self
.
OBDdata
=
{
"msgID"
:
"0200"
,
"phoneNum"
:
"13146201119"
,
"msgWaterCode"
:
"1"
,
"encryptionType"
:
"0"
,
"subPkg"
:
"0"
,
"pkgCounts"
:
"0"
,
"baseInfo"
:
{
"alarmFlag"
:
0
,
"status"
:
262402
,
"latitude"
:
29.569133
,
"longtitude"
:
106.586571
,
...
...
@@ -172,6 +174,7 @@ class MessageSimulaterService():
fireOnParams
[
"baseInfo"
][
"infoTime"
]
=
curTime
fireOnParams
[
"baseInfo"
][
"latitude"
]
=
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lat"
]
fireOnParams
[
"baseInfo"
][
"longtitude"
]
=
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lng"
]
fireOnParams
[
"baseInfo"
][
"directionAngle"
]
=
self
.
getDirAngle
()
msgObj
=
Location_msg
()
msg
=
msgObj
.
generateMsg_GUI
(
fireOnParams
)
self
.
sendMsg
(
msg
)
...
...
@@ -185,6 +188,7 @@ class MessageSimulaterService():
self
.
OBDdata
[
"baseInfo"
][
"infoTime"
]
=
curTime
self
.
OBDdata
[
"baseInfo"
][
"latitude"
]
=
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lat"
]
self
.
OBDdata
[
"baseInfo"
][
"longtitude"
]
=
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lng"
]
self
.
OBDdata
[
"baseInfo"
][
"directionAngle"
]
=
self
.
getDirAngle
()
self
.
OBDdata
[
"extraInfo"
][
"EB"
][
"60C0"
]
=
0
#发动机转速
self
.
OBDdata
[
"extraInfo"
][
"EB"
][
"60D0"
]
=
0
#车速
self
.
OBDdata
[
"extraInfo"
][
"EB"
][
"670a"
]
=
self
.
carData
[
"travelData"
][
"totalOil"
]
#总油耗
...
...
@@ -222,6 +226,7 @@ class MessageSimulaterService():
gpsParams
[
"baseInfo"
][
"infoTime"
]
=
curTime
gpsParams
[
"baseInfo"
][
"latitude"
]
=
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lat"
]
gpsParams
[
"baseInfo"
][
"longtitude"
]
=
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lng"
]
gpsParams
[
"baseInfo"
][
"directionAngle"
]
=
self
.
getDirAngle
()
gpsObj
=
Location_msg
()
gpsMsg
=
gpsObj
.
generateMsg_GUI
(
gpsParams
)
elif
self
.
travelStatus
==
1
:
#行驶服务启动
...
...
@@ -242,6 +247,7 @@ class MessageSimulaterService():
gpsParams
[
"baseInfo"
][
"infoTime"
]
=
curTime
gpsParams
[
"baseInfo"
][
"latitude"
]
=
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lat"
]
gpsParams
[
"baseInfo"
][
"longtitude"
]
=
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lng"
]
gpsParams
[
"baseInfo"
][
"directionAngle"
]
=
self
.
getDirAngle
()
gpsObj
=
Location_msg
()
gpsMsg
=
gpsObj
.
generateMsg_GUI
(
gpsParams
)
...
...
@@ -250,6 +256,7 @@ class MessageSimulaterService():
self
.
OBDdata
[
"baseInfo"
][
"infoTime"
]
=
curTime
self
.
OBDdata
[
"baseInfo"
][
"latitude"
]
=
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lat"
]
self
.
OBDdata
[
"baseInfo"
][
"longtitude"
]
=
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lng"
]
self
.
OBDdata
[
"baseInfo"
][
"directionAngle"
]
=
self
.
getDirAngle
()
self
.
OBDdata
[
"extraInfo"
][
"EB"
][
"60C0"
]
=
3000
# 发动机转速
speed
=
int
(
self
.
data
[
"travelData"
][
"carSpeed"
])
oilExpend
=
int
(
self
.
data
[
"travelData"
][
"oilExpend"
])
...
...
@@ -293,6 +300,7 @@ class MessageSimulaterService():
gpsParams
[
"baseInfo"
][
"infoTime"
]
=
curTime
gpsParams
[
"baseInfo"
][
"latitude"
]
=
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lat"
]
gpsParams
[
"baseInfo"
][
"longtitude"
]
=
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lng"
]
gpsParams
[
"baseInfo"
][
"directionAngle"
]
=
self
.
getDirAngle
()
gpsObj
=
Location_msg
()
gpsMsg
=
gpsObj
.
generateMsg_GUI
(
gpsParams
)
...
...
@@ -301,6 +309,7 @@ class MessageSimulaterService():
self
.
OBDdata
[
"baseInfo"
][
"infoTime"
]
=
curTime
self
.
OBDdata
[
"baseInfo"
][
"latitude"
]
=
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lat"
]
self
.
OBDdata
[
"baseInfo"
][
"longtitude"
]
=
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lng"
]
self
.
OBDdata
[
"baseInfo"
][
"directionAngle"
]
=
self
.
getDirAngle
()
self
.
OBDdata
[
"extraInfo"
][
"EB"
][
"60C0"
]
=
3000
# 发动机转速
speed
=
int
(
self
.
data
[
"travelData"
][
"carSpeed"
])
oilExpend
=
int
(
self
.
data
[
"travelData"
][
"oilExpend"
])
...
...
@@ -360,6 +369,7 @@ class MessageSimulaterService():
fireOffParams
[
"baseInfo"
][
"infoTime"
]
=
curTime
fireOffParams
[
"baseInfo"
][
"latitude"
]
=
self
.
gpsLine
[
gpsLineIndex
][
"lat"
]
fireOffParams
[
"baseInfo"
][
"longtitude"
]
=
self
.
gpsLine
[
gpsLineIndex
][
"lng"
]
fireOffParams
[
"baseInfo"
][
"directionAngle"
]
=
self
.
getDirAngle
()
msgObj
=
Location_msg
()
msg
=
msgObj
.
generateMsg_GUI
(
fireOffParams
)
self
.
sendMsg
(
msg
)
...
...
@@ -501,3 +511,50 @@ class MessageSimulaterService():
def
stopTravel
(
self
):
self
.
travelStatus
=
0
self
.
serviceStatus
=
0
###########################################################
#获取方向角
###########################################################
def
getDirAngle
(
self
):
dire
=
self
.
directAngle
if
self
.
travelDirection
==
0
:
if
self
.
gpsLineIndex
==
0
:
return
self
.
directAngle
lngCut
=
(
float
(
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lng"
])
-
float
(
self
.
gpsLine
[
self
.
gpsLineIndex
-
1
][
"lng"
]))
*
1000000
latCut
=
(
float
(
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lat"
])
-
float
(
self
.
gpsLine
[
self
.
gpsLineIndex
-
1
][
"lat"
]))
*
1000000
if
latCut
==
0
:
#除数维度不能为0
latCut
=
1
if
lngCut
==
0
or
latCut
==
0
:
return
self
.
directAngle
val
=
lngCut
/
latCut
dire
=
math
.
atan2
(
1
,
val
)
*
180
/
math
.
pi
if
lngCut
>
0
and
latCut
>
0
:
dire
=
90
-
dire
if
lngCut
<
0
and
latCut
>
0
:
dire
=
270
+
180
-
dire
elif
latCut
<
0
and
lngCut
>
0
:
dire
=
270
-
dire
elif
lngCut
<
0
and
latCut
<
0
:
dire
=
180
+
90
-
dire
self
.
directAngle
=
dire
elif
self
.
travelDirection
==
1
:
if
self
.
gpsLineIndex
==
(
len
(
self
.
gpsLine
)
-
1
):
return
self
.
directAngle
lngCut
=
(
float
(
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lng"
])
-
float
(
self
.
gpsLine
[
self
.
gpsLineIndex
+
1
][
"lng"
]))
*
1000000
latCut
=
(
float
(
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lat"
])
-
float
(
self
.
gpsLine
[
self
.
gpsLineIndex
+
1
][
"lat"
]))
*
1000000
if
latCut
==
0
:
#除数维度不能为0
latCut
=
1
if
lngCut
==
0
or
latCut
==
0
:
return
self
.
directAngle
val
=
lngCut
/
latCut
dire
=
math
.
atan2
(
1
,
val
)
*
180
/
math
.
pi
if
lngCut
>
0
and
latCut
>
0
:
dire
=
90
-
dire
if
lngCut
<
0
and
latCut
>
0
:
dire
=
270
+
180
-
dire
elif
latCut
<
0
and
lngCut
>
0
:
dire
=
270
-
dire
elif
lngCut
<
0
and
latCut
<
0
:
dire
=
180
+
90
-
dire
self
.
directAngle
=
dire
return
int
(
dire
)
lib/socket/service/ProtocolSimulaterService.py
View file @
32ef4e2f
...
...
@@ -5,6 +5,7 @@ M500车机模拟服务类
'''
import
binascii
import
json
import
math
import
os
import
threading
import
time
...
...
@@ -36,6 +37,7 @@ class ProtocolSimulaterService():
self
.
carId
=
""
#车机号
self
.
sn
=
0
#消息流水号
self
.
travelDirection
=
0
#行驶方向,0表示正向行驶,1表示反向行驶
self
.
directAngle
=
60
#汽车方向角
# 定义要发送的obd数据
self
.
OBDdata
=
{
"fireStatus"
:
1
,
"ACCStatus"
:
0
,
"engineSpeed"
:
300
,
"speed"
:
0
,
"meterMileage"
:
6000
,
"totailMileage"
:
600
,
"totalOilExpen"
:
30
,
"totalRunTime"
:
10
}
# 定义初始的obd数据,与上面的OBD数据保持一致,主要用于汽车行驶过程中数据变化量的计算
...
...
@@ -338,10 +340,11 @@ class ProtocolSimulaterService():
self
.
websocket
.
send
(
type
+
">>>>:"
+
gpsMsg
)
#根据特定参数,生成GPS消息
def
genGPSMsg
(
self
,
latitude
,
longtitude
):
def
genGPSMsg
(
self
,
latitude
,
longtitude
,
direct
=
0
):
gpsObj
=
GPSReport_protocol
(
DEV_ID
=
self
.
carId
,
WATER_CODE
=
self
.
sn
)
gpsObj
.
setLatitude
(
latitude
)
gpsObj
.
setLongitude
(
longtitude
)
gpsObj
.
setDirectionAngle
(
self
.
getDirAngle
())
timeS
=
int
(
time
.
time
())
-
8
*
3600
timeArray
=
time
.
localtime
(
timeS
)
UTCTime
=
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
,
timeArray
)
...
...
@@ -381,8 +384,70 @@ class ProtocolSimulaterService():
msg
=
OBDObj
.
generateOBDReportCANMsg
()
return
msg
###########################################################
#获取方向角
###########################################################
def
getDirAngle
(
self
):
dire
=
self
.
directAngle
if
self
.
travelDirection
==
0
:
if
self
.
gpsLineIndex
==
0
:
return
self
.
directAngle
lngCut
=
(
float
(
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lng"
])
-
float
(
self
.
gpsLine
[
self
.
gpsLineIndex
-
1
][
"lng"
]))
*
1000000
latCut
=
(
float
(
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lat"
])
-
float
(
self
.
gpsLine
[
self
.
gpsLineIndex
-
1
][
"lat"
]))
*
1000000
if
latCut
==
0
:
#除数维度不能为0
latCut
=
1
if
lngCut
==
0
or
latCut
==
0
:
return
self
.
directAngle
val
=
lngCut
/
latCut
dire
=
math
.
atan2
(
1
,
val
)
*
180
/
math
.
pi
if
lngCut
>
0
and
latCut
>
0
:
dire
=
90
-
dire
if
lngCut
<
0
and
latCut
>
0
:
dire
=
270
+
180
-
dire
elif
latCut
<
0
and
lngCut
>
0
:
dire
=
270
-
dire
elif
lngCut
<
0
and
latCut
<
0
:
dire
=
180
+
90
-
dire
self
.
directAngle
=
dire
elif
self
.
travelDirection
==
1
:
if
self
.
gpsLineIndex
==
(
len
(
self
.
gpsLine
)
-
1
):
return
self
.
directAngle
lngCut
=
(
float
(
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lng"
])
-
float
(
self
.
gpsLine
[
self
.
gpsLineIndex
+
1
][
"lng"
]))
*
1000000
latCut
=
(
float
(
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lat"
])
-
float
(
self
.
gpsLine
[
self
.
gpsLineIndex
+
1
][
"lat"
]))
*
1000000
if
latCut
==
0
:
#除数维度不能为0
latCut
=
1
if
lngCut
==
0
or
latCut
==
0
:
return
self
.
directAngle
val
=
lngCut
/
latCut
dire
=
math
.
atan2
(
1
,
val
)
*
180
/
math
.
pi
if
lngCut
>
0
and
latCut
>
0
:
dire
=
90
-
dire
if
lngCut
<
0
and
latCut
>
0
:
dire
=
270
+
180
-
dire
elif
latCut
<
0
and
lngCut
>
0
:
dire
=
270
-
dire
elif
lngCut
<
0
and
latCut
<
0
:
dire
=
180
+
90
-
dire
self
.
directAngle
=
dire
return
int
(
dire
)
#测试方向角转换的函数(测试用)
def
getDirAngleTest
(
self
):
lngCut
=
(
116.410665
-
116.423888
)
*
1000000
latCut
=
(
39.929267
-
39.930484
)
*
1000000
val
=
lngCut
/
latCut
dire
=
math
.
atan2
(
1
,
val
)
*
180
/
math
.
pi
if
lngCut
<
0
and
latCut
>
0
:
pass
dire
=
270
+
180
-
dire
elif
latCut
<
0
and
lngCut
>
0
:
dire
=
270
-
dire
elif
lngCut
<
0
and
latCut
<
0
:
dire
=
180
+
90
-
dire
if
__name__
==
"__main__"
:
ProtocolSimulaterService
()
.
getDirAngleTest
()
...
...
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