Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
autoCarTimer
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
李远洪
autoCarTimer
Commits
f46ce3c4
Commit
f46ce3c4
authored
Apr 26, 2020
by
liyuanhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加了根据GPs轨迹自动算出方向角的功能
parent
a35b1949
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
497 additions
and
3 deletions
+497
-3
data/protocolTools/carData/M202003060520.json
data/protocolTools/carData/M202003060520.json
+1
-1
lib/socket/service/AutoCarTimerService.py
lib/socket/service/AutoCarTimerService.py
+31
-0
result.txt
result.txt
+464
-1
start.py
start.py
+1
-1
No files found.
data/protocolTools/carData/M202003060520.json
View file @
f46ce3c4
{
"time"
:
{
"dateTime"
:
"2020-04-22 15:12:03"
,
"date"
:
"2020-04-22"
,
"time"
:
"15:12:03"
},
"curDayTravel"
:
{
"todayTotalMilleage"
:
17116
,
"todayTotalOil"
:
1556
,
"todayTotalTime"
:
778
,
"theMilleage"
:
21912
,
"theOil"
:
1992
,
"theTime"
:
996
},
"travelData"
:
{
"totalMilleage"
:
21912
,
"totalOil"
:
1992
,
"totalTime"
:
996
}}
{
"time"
:
{
"dateTime"
:
"2020-04-26 17:03:02"
,
"date"
:
"2020-04-26"
,
"time"
:
"17:03:02"
},
"curDayTravel"
:
{
"todayTotalMilleage"
:
14190
,
"todayTotalOil"
:
1290
,
"todayTotalTime"
:
645
,
"theMilleage"
:
36102
,
"theOil"
:
3282
,
"theTime"
:
1641
},
"travelData"
:
{
"totalMilleage"
:
36102
,
"totalOil"
:
3282
,
"totalTime"
:
1641
}}
\ No newline at end of file
\ No newline at end of file
lib/socket/service/AutoCarTimerService.py
View file @
f46ce3c4
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
import
binascii
import
binascii
import
datetime
import
datetime
import
json
import
json
import
math
import
os
import
os
import
random
import
random
import
threading
import
threading
...
@@ -37,6 +38,7 @@ class AutoCarTimerService():
...
@@ -37,6 +38,7 @@ class AutoCarTimerService():
self
.
sn
=
1
#消息流水号
self
.
sn
=
1
#消息流水号
self
.
oilExpend
=
10
#设置汽车每升能跑多少公里
self
.
oilExpend
=
10
#设置汽车每升能跑多少公里
self
.
carSpeed
=
60
#设置车速度
self
.
carSpeed
=
60
#设置车速度
self
.
directAngle
=
59
#设置默认方向角
# 定义要发送的obd数据
# 定义要发送的obd数据
self
.
OBDdata
=
{
"fireStatus"
:
1
,
"ACCStatus"
:
0
,
"engineSpeed"
:
300
,
"speed"
:
0
,
"meterMileage"
:
6000
,
"totailMileage"
:
600
,
"totalOilExpen"
:
30
,
"totalRunTime"
:
10
}
self
.
OBDdata
=
{
"fireStatus"
:
1
,
"ACCStatus"
:
0
,
"engineSpeed"
:
300
,
"speed"
:
0
,
"meterMileage"
:
6000
,
"totailMileage"
:
600
,
"totalOilExpen"
:
30
,
"totalRunTime"
:
10
}
# 定义初始的obd数据,与上面的OBD数据保持一致,主要用于汽车行驶过程中数据变化量的计算
# 定义初始的obd数据,与上面的OBD数据保持一致,主要用于汽车行驶过程中数据变化量的计算
...
@@ -126,6 +128,7 @@ class AutoCarTimerService():
...
@@ -126,6 +128,7 @@ class AutoCarTimerService():
print
(
info
)
print
(
info
)
self
.
writeToFile
(
"result.txt"
,
info
+
"
\n
"
,
1
)
self
.
writeToFile
(
"result.txt"
,
info
+
"
\n
"
,
1
)
elif
self
.
gpsLineIndex
==
len
(
self
.
gpsLine
):
elif
self
.
gpsLineIndex
==
len
(
self
.
gpsLine
):
self
.
gpsLineIndex
=
self
.
gpsLineIndex
-
1
# self.fireOff()
# self.fireOff()
self
.
stopTravelService
()
self
.
stopTravelService
()
info
=
self
.
getCurTime
()
+
" gps轨迹跑完,自动停止行驶!"
info
=
self
.
getCurTime
()
+
" gps轨迹跑完,自动停止行驶!"
...
@@ -280,6 +283,7 @@ class AutoCarTimerService():
...
@@ -280,6 +283,7 @@ class AutoCarTimerService():
gpsObj
=
GPSReport_protocol
(
DEV_ID
=
self
.
carId
,
WATER_CODE
=
self
.
sn
)
gpsObj
=
GPSReport_protocol
(
DEV_ID
=
self
.
carId
,
WATER_CODE
=
self
.
sn
)
gpsObj
.
setLatitude
(
latitude
)
gpsObj
.
setLatitude
(
latitude
)
gpsObj
.
setLongitude
(
longtitude
)
gpsObj
.
setLongitude
(
longtitude
)
gpsObj
.
setDirectionAngle
(
self
.
getDirAngle
())
timeS
=
int
(
time
.
time
())
-
8
*
3600
timeS
=
int
(
time
.
time
())
-
8
*
3600
timeArray
=
time
.
localtime
(
timeS
)
timeArray
=
time
.
localtime
(
timeS
)
UTCTime
=
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
,
timeArray
)
UTCTime
=
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
,
timeArray
)
...
@@ -292,6 +296,7 @@ class AutoCarTimerService():
...
@@ -292,6 +296,7 @@ class AutoCarTimerService():
gpsObj
=
GPSReport_protocol
(
DEV_ID
=
self
.
carId
,
WATER_CODE
=
self
.
sn
)
gpsObj
=
GPSReport_protocol
(
DEV_ID
=
self
.
carId
,
WATER_CODE
=
self
.
sn
)
gpsObj
.
setLatitude
(
latitude
)
gpsObj
.
setLatitude
(
latitude
)
gpsObj
.
setLongitude
(
longtitude
)
gpsObj
.
setLongitude
(
longtitude
)
gpsObj
.
setDirectionAngle
(
self
.
getDirAngle
())
timeS
=
int
(
time
.
time
())
-
8
*
3600
timeS
=
int
(
time
.
time
())
-
8
*
3600
timeArray
=
time
.
localtime
(
timeS
)
timeArray
=
time
.
localtime
(
timeS
)
UTCTime
=
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
,
timeArray
)
UTCTime
=
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
,
timeArray
)
...
@@ -429,6 +434,32 @@ class AutoCarTimerService():
...
@@ -429,6 +434,32 @@ class AutoCarTimerService():
else
:
else
:
return
False
return
False
###########################################################
# 获取方向角
###########################################################
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
)
########################################################
########################################################
# 启动模拟程序服务
# 启动模拟程序服务
########################################################
########################################################
...
...
result.txt
View file @
f46ce3c4
This diff is collapsed.
Click to expand it.
start.py
View file @
f46ce3c4
...
@@ -19,7 +19,7 @@ def startSimulaterService():
...
@@ -19,7 +19,7 @@ def startSimulaterService():
如果想要每天的9点自动执行一次轨迹行驶,则设置:year=0,month=0,day=0,hour=9,minute=0,second=0
如果想要每天的9点自动执行一次轨迹行驶,则设置:year=0,month=0,day=0,hour=9,minute=0,second=0
如果想要每天的9点30自动执行一次轨迹行驶,则设置:year=0,month=0,day=0,hour=9,minute=30,second=0
如果想要每天的9点30自动执行一次轨迹行驶,则设置:year=0,month=0,day=0,hour=9,minute=30,second=0
'''
'''
autoCarObj
.
startService
(
year
=
0
,
month
=
0
,
day
=
0
,
hour
=
0
,
minute
=
24
,
second
=
0
)
autoCarObj
.
startService
(
year
=
0
,
month
=
0
,
day
=
0
,
hour
=
0
,
minute
=
0
,
second
=
1
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
startSimulaterService
()
startSimulaterService
()
...
...
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