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
3cd2b654
Commit
3cd2b654
authored
Jul 13, 2020
by
liyuanhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
车安优模拟器增加改变行驶方向、固定gps、查询当前gps功能
parent
62c059fa
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
188 additions
and
10 deletions
+188
-10
data/messageTools/carData/012201500010.json
data/messageTools/carData/012201500010.json
+1
-1
lib/socket/service/MessageSimulaterService.py
lib/socket/service/MessageSimulaterService.py
+16
-4
templates/messageTools/message/M_simulater_page.html
templates/messageTools/message/M_simulater_page.html
+74
-5
views/messageTools/M_simulater_process.py
views/messageTools/M_simulater_process.py
+97
-0
No files found.
data/messageTools/carData/012201500010.json
View file @
3cd2b654
{
"time"
:
{
"dateTime"
:
"2020-07-13 14:17:20"
,
"date"
:
"2020-07-13"
,
"time"
:
"14:17:20"
},
"curDayTravel"
:
{
"todayTotalMilleage"
:
166
,
"todayTotalOil"
:
16
,
"todayTotalTime"
:
10
,
"theMilleage"
:
166
,
"theOil"
:
16
,
"theTime"
:
10
},
"travelData"
:
{
"totalMilleage"
:
111977
,
"totalOil"
:
10125
,
"totalTime"
:
6861
}}
\ No newline at end of file
{
"time"
:
{
"dateTime"
:
"2020-07-13 14:17:20"
,
"date"
:
"2020-07-13"
,
"time"
:
"14:17:20"
},
"curDayTravel"
:
{
"todayTotalMilleage"
:
4044
,
"todayTotalOil"
:
264
,
"todayTotalTime"
:
252
,
"theMilleage"
:
630
,
"theOil"
:
45
,
"theTime"
:
39
},
"travelData"
:
{
"totalMilleage"
:
115855
,
"totalOil"
:
10373
,
"totalTime"
:
7103
}}
\ No newline at end of file
lib/socket/service/MessageSimulaterService.py
View file @
3cd2b654
...
...
@@ -40,6 +40,7 @@ class MessageSimulaterService():
self
.
sn
=
0
#消息流水号
self
.
travelDirection
=
0
#行驶方向,0表示正向行驶,1表示反向行驶
self
.
directAngle
=
59
#定义默认方向角
self
.
fixCurPosition
=
0
#是否固定当前GPS点,0:不固定 1:固定
# 定义要发送的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
,
...
...
@@ -72,6 +73,12 @@ class MessageSimulaterService():
return
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lat"
]
def
getCurLongtitude
(
self
):
return
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lng"
]
def
getTravelDirection
(
self
):
return
self
.
travelDirection
def
getGpsLine
(
self
):
return
self
.
gpsLine
def
getGpsLineIndex
(
self
):
return
self
.
gpsLineIndex
...
...
@@ -99,6 +106,10 @@ class MessageSimulaterService():
self
.
data
[
"travelData"
][
"oilExpend"
]
=
data
def
setSendDur
(
self
,
data
):
self
.
sendDur
=
data
def
setTravelDirection
(
self
,
data
):
self
.
travelDirection
=
data
def
setFixCurPosition
(
self
,
data
):
self
.
fixCurPosition
=
data
def
sendMsg
(
self
,
msg
):
self
.
socket
.
setTimeOut
(
self
.
timeout
)
...
...
@@ -302,10 +313,11 @@ class MessageSimulaterService():
plusMilleage
=
plusMilleage
-
int
(
plusMilleage
/
100
)
*
100
obdObj
=
Location_msg
()
obdMsg
=
obdObj
.
generateMsg_GUI
(
self
.
OBDdata
)
if
self
.
travelDirection
==
0
:
self
.
gpsLineIndex
=
self
.
gpsLineIndex
+
1
# 正向行驶
else
:
self
.
gpsLineIndex
=
self
.
gpsLineIndex
-
1
# 反向行驶
if
self
.
fixCurPosition
==
0
:
if
self
.
travelDirection
==
0
:
self
.
gpsLineIndex
=
self
.
gpsLineIndex
+
1
# 正向行驶
else
:
self
.
gpsLineIndex
=
self
.
gpsLineIndex
-
1
# 反向行驶
elif
self
.
gpsLineIndex
==
len
(
self
.
gpsLine
)
or
self
.
gpsLineIndex
==
-
1
:
#如果反向行驶和反向行驶刚好跑完
if
int
(
self
.
data
[
"travelData"
][
"travelLoop"
])
==
0
:
#没有设置循环行驶
self
.
gpsLineIndex
=
self
.
gpsLineIndex
-
1
...
...
templates/messageTools/message/M_simulater_page.html
View file @
3cd2b654
...
...
@@ -179,6 +179,8 @@
<span
style=
"margin-left:10px"
><label>
车速度(Km/h):
</label><input
style=
"width:80px;margin-right:5px;"
id=
"change_speed"
type=
"text"
class=
"form-control"
value=
"60"
><button
type=
"button"
class=
"btn btn-primary"
onclick=
"changeSpeed()"
>
改变车速
</button></span>
<span
style=
"margin-left:10px"
><label>
油耗(Km/L):
</label><input
style=
"width:80px;margin-right:5px;"
id=
"change_oilExpend"
type=
"text"
class=
"form-control"
value=
"10"
><button
type=
"button"
class=
"btn btn-primary"
onclick=
"changeOilExpend()"
>
改变油耗
</button></span>
<span
style=
"margin-left:10px"
><label>
上报间隔(秒):
</label><input
style=
"width:80px;margin-right:5px;"
id=
"change_durTime"
type=
"text"
class=
"form-control"
value=
"5"
><button
type=
"button"
class=
"btn btn-primary"
onclick=
"changeDurTime()"
>
改变上报间隔
</button></span>
<span
style=
"margin-left:10px;display: inline-block;"
><button
type=
"button"
class=
"btn btn-primary"
onclick=
"changeTravelDirection()"
>
反向行驶
</button></span>
<span
style=
"margin-left:10px;display: inline-block;"
><button
type=
"button"
class=
"btn btn-primary"
onclick=
"fixCurPosition(this)"
>
固定在当前位置
</button></span>
</div>
</div>
</div>
...
...
@@ -187,9 +189,10 @@
<textarea
id=
"showFeedback"
style=
"width:100%;padding:5px;padding-bottom:60px;"
rows=
"10"
></textarea>
</div>
<div
style=
"width:100%;padding-bottom:10px;border-bottom: 1px solid #eee;"
>
<h4>
查询今日车机行驶数据
</h4>
<h4>
数据查询
</h4>
<span>
<button
id=
"searchCarData"
type=
"button"
class=
"btn btn-primary"
id=
"saveSetting"
>
查询
</button>
<button
id=
"searchCarData"
type=
"button"
class=
"btn btn-primary"
id=
"saveSetting"
>
查询今日行驶数据
</button>
<button
id=
"searchCarGPS"
type=
"button"
class=
"btn btn-primary"
>
查询车辆当前GPS点
</button>
</span>
</div>
<H3
style=
"border-bottom: 1px solid #eee;"
>
返回信息:
</H3>
...
...
@@ -581,6 +584,32 @@ $("#searchCarData").click(function(){
});
});
//查询当前车辆GPS
$
(
"
#searchCarGPS
"
).
click
(
function
(){
var
carId
=
$
(
"
#carId
"
).
val
();
var
sessionId
=
$
(
"
#curSession
"
).
val
()
var
data
=
{};
data
[
"
carId
"
]
=
carId
;
data
[
"
sessionId
"
]
=
sessionId
;
var
host
=
window
.
location
.
host
;
$
.
ajax
({
url
:
"
http://
"
+
host
+
"
/messageTools/M_simulater_process/searchCurCarGPS
"
,
type
:
"
post
"
,
data
:
data
,
dataType
:
"
json
"
,
success
:
function
(
data
){
if
(
data
.
status
==
200
){
msg
=
data
.
message
$
(
"
#searchCardataShow
"
).
val
(
msg
)
}
else
{
$
(
"
#searchCardataShow
"
).
val
(
data
.
message
)
alert
(
data
.
message
);
}
}
});
});
//设置隐藏或显示日志
function
isLogShow
(
e
){
if
(
$
(
e
).
is
(
'
:checked
'
)){
...
...
@@ -887,10 +916,50 @@ function changeDurTime(){
var
url
=
"
http://
"
+
host
+
"
/messageTools/M_simulater_process/changeDurTime
"
;
sendHttpMsg
(
data
,
url
);
}
//反向行驶
function
changeTravelDirection
(){
var
data
=
{}
var
carId
=
$
(
"
#phoneNum
"
).
val
()
data
[
"
carId
"
]
=
carId
//会话session数据
data
[
"
session
"
]
=
{}
var
sessionId
=
$
(
"
#curSession
"
).
val
()
data
[
"
session
"
][
"
sessionId
"
]
=
sessionId
var
host
=
window
.
location
.
host
;
var
url
=
"
http://
"
+
host
+
"
/messageTools/M_simulater_process/changeTravelDirection
"
;
sendHttpMsg
(
data
,
url
);
}
function
fixCurPosition
(
e
){
var
butTxt
=
$
(
e
).
text
()
if
(
butTxt
==
"
固定在当前位置
"
){
var
data
=
{}
var
carId
=
$
(
"
#carId
"
).
val
()
data
[
"
carId
"
]
=
carId
data
[
"
fixPosition
"
]
=
1
//会话session数据
data
[
"
session
"
]
=
{}
var
sessionId
=
$
(
"
#curSession
"
).
val
()
data
[
"
session
"
][
"
sessionId
"
]
=
sessionId
var
host
=
window
.
location
.
host
;
var
url
=
"
http://
"
+
host
+
"
/messageTools/M_simulater_process/fixCurPosition
"
;
sendHttpMsg
(
data
,
url
);
$
(
e
).
text
(
"
取消固定在当前位置
"
)
}
else
{
var
data
=
{}
var
carId
=
$
(
"
#carId
"
).
val
()
data
[
"
carId
"
]
=
carId
data
[
"
fixPosition
"
]
=
0
//会话session数据
data
[
"
session
"
]
=
{}
var
sessionId
=
$
(
"
#curSession
"
).
val
()
data
[
"
session
"
][
"
sessionId
"
]
=
sessionId
var
host
=
window
.
location
.
host
;
var
url
=
"
http://
"
+
host
+
"
/messageTools/M_simulater_process/fixCurPosition
"
;
sendHttpMsg
(
data
,
url
);
$
(
e
).
text
(
"
固定在当前位置
"
)
}
}
</script>
{% endblock %}
\ No newline at end of file
views/messageTools/M_simulater_process.py
View file @
3cd2b654
...
...
@@ -360,6 +360,35 @@ def getConnects():
data
[
"message"
]
=
"Error: 获取在线人数失败失败!"
return
Response
(
json
.
dumps
(
data
),
mimetype
=
'application/json'
)
##########################################
# 【接口类型】查询当前车辆GPS点
##########################################
@
M_simulater_process
.
route
(
"/searchCurCarGPS"
,
methods
=
[
'POST'
])
def
searchCurCarGPS
():
carId
=
request
.
form
.
get
(
"carId"
)
sessionId
=
request
.
form
.
get
(
"sessionId"
)
data
=
{}
if
not
sessionId
in
connects
.
keys
():
data
[
"status"
]
=
"4003"
data
[
"message"
]
=
"Error: 未启动服务,不可查询当前车辆GPS点!"
return
Response
(
json
.
dumps
(
data
),
mimetype
=
'application/json'
)
service
=
connects
[
sessionId
][
"service"
]
try
:
gpsLine
=
service
.
getGpsLine
()
gpsIndex
=
service
.
getGpsLineIndex
()
latitude
=
gpsLine
[
gpsIndex
][
"lat"
]
longitude
=
gpsLine
[
gpsIndex
][
"lng"
]
gpsLen
=
len
(
gpsLine
)
data
[
"status"
]
=
"200"
data
[
"message"
]
=
"GPS总长度:"
+
str
(
gpsLen
)
+
"
\n
"
+
"当前GPS位置:"
+
str
(
gpsIndex
)
+
"
\n
"
+
"当前经度:"
\
+
str
(
longitude
)
+
" 当前维度:"
+
str
(
latitude
)
except
BaseException
as
e
:
# 打印异常信息
traceback
.
print_exc
()
data
[
"status"
]
=
"4003"
data
[
"message"
]
=
"Error: 查询车机数据失败失败!"
return
Response
(
json
.
dumps
(
data
),
mimetype
=
'application/json'
)
#-------------------------------------- 报警上报逻辑 --------------------------------------
##########################################
# 【接口类型】发送终端插入报警事件
...
...
@@ -1059,4 +1088,72 @@ def changeDurTime():
traceback
.
print_exc
()
data
[
"status"
]
=
"4003"
data
[
"message"
]
=
"Error: 改变发送间隔失败!"
return
Response
(
json
.
dumps
(
data
),
mimetype
=
'application/json'
)
##########################################
# 【接口类型】改变行驶方向
##########################################
@
M_simulater_process
.
route
(
"/changeTravelDirection"
,
methods
=
[
'POST'
])
def
changeTravelDirection
():
params
=
request
.
get_data
()
params
=
json
.
loads
(
params
.
decode
(
"utf-8"
))
sessionId
=
params
[
"session"
][
"sessionId"
]
data
=
{}
if
not
sessionId
in
connects
.
keys
():
data
[
"status"
]
=
"4003"
data
[
"message"
]
=
"Error: 未启动服务,不可改变行驶方向!"
return
Response
(
json
.
dumps
(
data
),
mimetype
=
'application/json'
)
service
=
connects
[
sessionId
][
"service"
]
travelStatus
=
service
.
getTravelStatus
()
#获取汽车行驶状态
if
travelStatus
==
0
or
travelStatus
==
2
:
data
[
"status"
]
=
"4003"
data
[
"message"
]
=
"Error: 汽车还未行驶,不可改变行驶方向!"
elif
travelStatus
==
1
:
try
:
if
service
.
travelDirection
==
0
:
service
.
setTravelDirection
(
1
)
else
:
service
.
setTravelDirection
(
0
)
data
[
"status"
]
=
"200"
data
[
"message"
]
=
"改变行驶方向成功!"
except
BaseException
as
e
:
# 打印异常信息
traceback
.
print_exc
()
data
[
"status"
]
=
"4003"
data
[
"message"
]
=
"Error: 改变行驶方向失败!"
return
Response
(
json
.
dumps
(
data
),
mimetype
=
'application/json'
)
##########################################
# 【接口类型】固定gps点
##########################################
@
M_simulater_process
.
route
(
"/fixCurPosition"
,
methods
=
[
'POST'
])
def
fixCurPosition
():
params
=
request
.
get_data
()
params
=
json
.
loads
(
params
.
decode
(
"utf-8"
))
sessionId
=
params
[
"session"
][
"sessionId"
]
data
=
{}
if
not
sessionId
in
connects
.
keys
():
data
[
"status"
]
=
"4003"
data
[
"message"
]
=
"Error: 未启动服务,不可固定gps点!"
return
Response
(
json
.
dumps
(
data
),
mimetype
=
'application/json'
)
service
=
connects
[
sessionId
][
"service"
]
travelStatus
=
service
.
getTravelStatus
()
#获取汽车行驶状态
if
travelStatus
==
0
or
travelStatus
==
2
:
data
[
"status"
]
=
"4003"
data
[
"message"
]
=
"Error: 汽车还未行驶,不可固定gps点!"
elif
travelStatus
==
1
:
try
:
service
.
setFixCurPosition
(
int
(
params
[
"fixPosition"
]))
data
[
"status"
]
=
"200"
if
int
(
params
[
"fixPosition"
])
==
0
:
data
[
"message"
]
=
"固定gps点成功!"
else
:
data
[
"message"
]
=
"取消固定gps点成功!"
except
BaseException
as
e
:
# 打印异常信息
traceback
.
print_exc
()
data
[
"status"
]
=
"4003"
data
[
"message"
]
=
"Error: 固定gps点失败!"
return
Response
(
json
.
dumps
(
data
),
mimetype
=
'application/json'
)
\ No newline at end of file
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