Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
autoCar
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
李远洪
autoCar
Commits
d3c9a7c6
Commit
d3c9a7c6
authored
Apr 26, 2020
by
liyuanhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加了方向角随GPS轨迹自动变化的功能
parent
0ab2f500
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
201 additions
and
227 deletions
+201
-227
lib/socket/service/AutoCarService.py
lib/socket/service/AutoCarService.py
+30
-0
result.txt
result.txt
+170
-226
start.py
start.py
+1
-1
No files found.
lib/socket/service/AutoCarService.py
View file @
d3c9a7c6
...
...
@@ -6,6 +6,7 @@
import
binascii
import
datetime
import
json
import
math
import
os
import
random
import
threading
...
...
@@ -39,6 +40,7 @@ class AutoCarService():
self
.
sn
=
1
#消息流水号
self
.
oilExpend
=
10
#设置汽车每升能跑多少公里
self
.
carSpeed
=
60
#设置车速度
self
.
directAngle
=
59
#定义默认方向角
# 定义要发送的obd数据
self
.
OBDdata
=
{
"fireStatus"
:
1
,
"ACCStatus"
:
0
,
"engineSpeed"
:
300
,
"speed"
:
0
,
"meterMileage"
:
6000
,
"totailMileage"
:
600
,
"totalOilExpen"
:
30
,
"totalRunTime"
:
10
}
# 定义初始的obd数据,与上面的OBD数据保持一致,主要用于汽车行驶过程中数据变化量的计算
...
...
@@ -323,6 +325,7 @@ class AutoCarService():
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
)
...
...
@@ -335,6 +338,7 @@ class AutoCarService():
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
)
...
...
@@ -433,6 +437,32 @@ class AutoCarService():
with
open
(
path
,
"w"
,
encoding
=
'utf-8'
)
as
fi
:
fi
.
write
(
data
)
###########################################################
# 获取方向角
###########################################################
def
getDirAngle
(
self
):
dire
=
self
.
directAngle
if
self
.
gpsLineIndex
==
0
:
return
int
(
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
int
(
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
testOpenfile
(
self
):
with
open
(
"data/protocolTools/carData/"
+
self
.
carId
+
".json"
,
"r"
,
encoding
=
"utf-8"
)
as
fi
:
...
...
result.txt
View file @
d3c9a7c6
This diff is collapsed.
Click to expand it.
start.py
View file @
d3c9a7c6
...
...
@@ -11,7 +11,7 @@ def startSimulaterService():
autoCarObj
.
setSendDur
(
1
)
# 设置发送消息的间隔时间
autoCarObj
.
setTimeout
(
30
)
# 设置socket超时时间
autoCarObj
.
setChangeGPSLineTime
(
1
*
2
*
60
)
# 设置跑完一条轨迹后,进入下一条轨迹的时间(请设置至少大于4分钟的时间)
autoCarObj
.
setServiceTime
(
1
*
4
*
60
)
# 设置整个服务的持续时间
autoCarObj
.
setServiceTime
(
1
*
5
*
60
)
# 设置整个服务的持续时间
autoCarObj
.
setOilExpend
(
10
)
# 设置1L 油跑多少公里
autoCarObj
.
setSpeed
(
80
)
#设置车速,每小时多少公里
...
...
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