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
546db7bf
Commit
546db7bf
authored
Apr 02, 2020
by
liyuanhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
汽车点熄火功能完成
parent
aec863d3
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
103 additions
and
32 deletions
+103
-32
lib/protocol/appendix/EventClass.py
lib/protocol/appendix/EventClass.py
+12
-4
lib/protocol/report/EventReport_protocol.py
lib/protocol/report/EventReport_protocol.py
+13
-12
lib/protocol/report/GPSReport_protocol.py
lib/protocol/report/GPSReport_protocol.py
+4
-1
lib/protocol/report/SecurityStatusReport_protocol.py
lib/protocol/report/SecurityStatusReport_protocol.py
+7
-0
lib/socket/service/ProtocolSimulaterService.py
lib/socket/service/ProtocolSimulaterService.py
+36
-9
templates/protocolTools/report/M_carSimulater_page.html
templates/protocolTools/report/M_carSimulater_page.html
+16
-0
views/protocolTools/M_carSimulater_process.py
views/protocolTools/M_carSimulater_process.py
+15
-6
No files found.
lib/protocol/appendix/EventClass.py
View file @
546db7bf
...
...
@@ -8,14 +8,20 @@ from lib.protocol.report.SecurityStatusReport_protocol import SecurityStatusRepo
class
EventClass
(
ProtocolBase
):
def
__init__
(
self
):
pass
self
.
GPSPkg
=
"1401091213260265b86206ed8c70026103280000752f03030405af017102610bb800003200000186a0001ed2a25e16fe3a"
self
.
BaseStationPkg
=
"1401140a0c050207e407e607e807ea07ec4eea4eec4eee4ef04efc4efe4f004f024f040024025e07d00007a125000927c60000ea610100"
def
setGPSpkg
(
self
,
data
):
self
.
GPSPkg
=
data
# 3 点火事件附带信息
def
fireExtraInfo
(
self
):
allRapidlyAccelerateCount
=
self
.
int2hexStringByBytes
(
15
,
2
)
# 急加速总次数
allSharpSlowdownCount
=
self
.
int2hexStringByBytes
(
15
,
2
)
# 急减速总次数
allSharpTurn
=
self
.
int2hexStringByBytes
(
15
,
2
)
# 急转弯总次数
securityData
=
SecurityStatusReport_protocol
()
.
generateSecurityStatusData
()
# 安防数据
securityObj
=
SecurityStatusReport_protocol
()
securityObj
.
setGPSPkg
(
self
.
GPSPkg
)
securityData
=
securityObj
.
generateSecurityStatusData
()
# 安防数据
data
=
allRapidlyAccelerateCount
+
allSharpSlowdownCount
+
allSharpTurn
+
securityData
return
data
...
...
@@ -24,7 +30,9 @@ class EventClass(ProtocolBase):
allRapidlyAccelerateCount
=
self
.
int2hexStringByBytes
(
100
,
2
)
#急加速总次数
allSharpSlowdownCount
=
self
.
int2hexStringByBytes
(
101
,
2
)
#急减速总次数
allSharpTurn
=
self
.
int2hexStringByBytes
(
35
,
2
)
#急转弯总次数
securityData
=
SecurityStatusReport_protocol
()
.
generateSecurityStatusData
()
#安防数据
securityObj
=
SecurityStatusReport_protocol
()
securityObj
.
setGPSPkg
(
self
.
GPSPkg
)
securityData
=
securityObj
.
generateSecurityStatusData
()
#安防数据
data
=
allRapidlyAccelerateCount
+
allSharpSlowdownCount
+
allSharpTurn
+
securityData
return
data
...
...
lib/protocol/report/EventReport_protocol.py
View file @
546db7bf
...
...
@@ -20,10 +20,7 @@ class EventReport_protocol(ProtocolBase):
self
.
locationType
=
int
(
locationType
)
# 定位类型
#self.GPSPkg = GPSpkg & BaseStationPkg # GPS包或者基站包
# self.GPSPkg = "1401091213260265b86206ed8c70026103280000752f03030405af017102610bb800003200000186a0001ed2a25e16fe3a"
self
.
latitude
=
40.22077
self
.
longitude
=
116.23128
self
.
timestamp
=
int
(
time
.
time
())
self
.
GPSPkg
=
"1401091213260265b86206ed8c70026103280000752f03030405af017102610bb800003200000186a0001ed2a25e16fe3a"
self
.
BaseStationPkg
=
"1401140a0c050207e407e607e807ea07ec4eea4eec4eee4ef04efc4efe4f004f024f040024025e07d00007a125000927c60000ea610100"
self
.
eventType
=
eventType
#事件类别
...
...
@@ -33,6 +30,12 @@ class EventReport_protocol(ProtocolBase):
self
.
longitude
=
data
def
setEventType
(
self
,
data
):
self
.
eventType
=
data
def
setLocationType
(
self
,
data
):
self
.
locationType
=
data
def
setGPSPkg
(
self
,
data
):
self
.
GPSPkg
=
data
def
setBaseStationPkg
(
self
,
data
):
self
.
BaseStationPkg
=
data
...
...
@@ -83,12 +86,6 @@ class EventReport_protocol(ProtocolBase):
#####################################################
def
generateEventData
(
self
):
data
=
""
gpsObj
=
GPSReport_protocol
()
gpsObj
.
setLatitude
(
self
.
latitude
)
gpsObj
.
setLatitude
(
self
.
longitude
)
gpsObj
.
setGPSTimestamp
(
self
.
timestamp
)
self
.
GPSPkg
=
gpsObj
.
generateGpsData
()
locationType
=
self
.
int2hexString
(
self
.
locationType
)
#定位类型
locationData
=
""
#GPS包或基站包
if
self
.
locationType
==
1
:
...
...
@@ -137,9 +134,13 @@ class EventReport_protocol(ProtocolBase):
elif
eventType
==
"000F"
:
#汽车预点火上报
return
EventClass
()
.
preFiringExtraInfo
()
elif
eventType
==
"0010"
:
#汽车点火上报
return
EventClass
()
.
fireExtraInfo
()
eventObj
=
EventClass
()
eventObj
.
setGPSpkg
(
self
.
GPSPkg
)
return
eventObj
.
fireExtraInfo
()
elif
eventType
==
"0011"
:
#汽车熄火上报
return
EventClass
()
.
misFireExtraInfo
()
eventObj
=
EventClass
()
eventObj
.
setGPSpkg
(
self
.
GPSPkg
)
return
eventObj
.
misFireExtraInfo
()
elif
eventType
==
"0012"
:
#汽车设防上报
return
EventClass
()
.
setUpDefencesExtraInfo
()
elif
eventType
==
"0013"
:
#汽车撤防上报
...
...
lib/protocol/report/GPSReport_protocol.py
View file @
546db7bf
...
...
@@ -3,6 +3,7 @@
'''
定义一个GPS协议的类
'''
import
datetime
from
lib.util
import
dataUtil
from
lib.protocol.report.ProtocolBase
import
ProtocolBase
...
...
@@ -495,7 +496,9 @@ if __name__ == "__main__":
GPSReport_protocol
()
.
generateGpsMsg
()
# Gps_protocol().getLatitude(40.22077)
# print(Gps_protocol().getHexTime())
# print(Gps_protocol().getUTCTime(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
print
(
GPSReport_protocol
()
.
getUTCTime
(
datetime
.
datetime
.
now
()
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)))
print
(
datetime
.
datetime
.
now
()
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
))
print
(
datetime
.
datetime
.
now
())
# Gps_protocol().generateGpsData()
# Gps_protocol().getLatitude(40.22077)
# Gps_protocol().getLongitude(116.23128)
...
...
lib/protocol/report/SecurityStatusReport_protocol.py
View file @
546db7bf
...
...
@@ -29,6 +29,13 @@ class SecurityStatusReport_protocol(ProtocolBase):
self
.
onoffStatusB
=
int
(
onoffStatusB
)
#开关状态B
self
.
dataByte
=
int
(
dataByte
)
#数据字节
def
setLocationType
(
self
,
data
):
self
.
locationType
=
data
def
setGPSPkg
(
self
,
data
):
self
.
GPSPkg
=
data
def
setBaseStationPkg
(
self
,
data
):
self
.
BaseStationPkg
=
data
#####################################################
# 生成安全状态消息
#####################################################
...
...
lib/socket/service/ProtocolSimulaterService.py
View file @
546db7bf
...
...
@@ -83,6 +83,7 @@ class ProtocolSimulaterService():
type
=
self
.
getMsgFunId
(
OBDMsg
)
info
=
type
+
">>>>:"
+
OBDMsg
self
.
websocket
.
send
(
info
)
sleep
(
0.1
)
self
.
sendMsg
(
gpsMsg
)
type
=
self
.
getMsgFunId
(
gpsMsg
)
info
=
type
+
">>>>:"
+
gpsMsg
...
...
@@ -153,6 +154,7 @@ class ProtocolSimulaterService():
########################################################
def
stopTravel
(
self
):
self
.
travelStatus
=
0
self
.
serviceStatus
=
0
#获取收到消息的功能id
def
getMsgFunId
(
self
,
msg
):
...
...
@@ -187,14 +189,19 @@ class ProtocolSimulaterService():
#点火,发送点火事件
def
fireOn
(
self
):
fireOnEventObj
=
EventReport_protocol
(
DEV_ID
=
self
.
carId
)
fireOnEventObj
.
setLatitude
(
self
.
gpsLine
[
0
][
"lat
"
])
fireOnEventObj
.
set
Longtitude
(
self
.
gpsLine
[
0
][
"lng"
]
)
gpsData
=
self
.
genGPSData
(
self
.
gpsLine
[
0
][
"lat"
],
self
.
gpsLine
[
0
][
"lng
"
])
fireOnEventObj
.
set
GPSPkg
(
gpsData
)
fireOnEventObj
.
setEventType
(
"0010"
)
firOnEventMsg
=
fireOnEventObj
.
generateEventMsg
()
type
=
self
.
getMsgFunId
(
firOnEventMsg
)
self
.
sendMsg
(
firOnEventMsg
)
self
.
websocket
.
send
(
type
+
">>>>:"
+
firOnEventMsg
)
sleep
(
0.1
)
gpsMsg
=
self
.
genGPSMsg
(
self
.
gpsLine
[
0
][
"lat"
],
self
.
gpsLine
[
0
][
"lng"
])
type
=
self
.
getMsgFunId
(
gpsMsg
)
self
.
sendMsg
(
gpsMsg
)
self
.
websocket
.
send
(
type
+
">>>>:"
+
gpsMsg
)
sleep
(
0.1
)
OBDMsg
=
self
.
genOBDMsg
()
type
=
self
.
getMsgFunId
(
OBDMsg
)
self
.
sendMsg
(
OBDMsg
)
...
...
@@ -203,23 +210,43 @@ class ProtocolSimulaterService():
# 熄火,发送熄火事件
def
fireOff
(
self
):
fireOffEventObj
=
EventReport_protocol
(
DEV_ID
=
self
.
carId
)
fireOffEventObj
.
setLatitude
(
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lat
"
])
fireOffEventObj
.
set
Longtitude
(
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lng"
]
)
gpsData
=
self
.
genGPSData
(
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lat"
],
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lng
"
])
fireOffEventObj
.
set
GPSPkg
(
gpsData
)
fireOffEventObj
.
setEventType
(
"0011"
)
fireOffEventObj
=
fireOffEventObj
.
generateEventMsg
()
type
=
self
.
getMsgFunId
(
fireOffEventObj
)
self
.
sendMsg
(
fireOffEventObj
)
self
.
websocket
.
send
(
type
+
">>>>:"
+
fireOffEventObj
)
fireOffEventMsg
=
fireOffEventObj
.
generateEventMsg
()
type
=
self
.
getMsgFunId
(
fireOffEventMsg
)
self
.
sendMsg
(
fireOffEventMsg
)
self
.
websocket
.
send
(
type
+
">>>>:"
+
fireOffEventMsg
)
sleep
(
0.1
)
gpsMsg
=
self
.
genGPSMsg
(
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lat"
],
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lng"
])
type
=
self
.
getMsgFunId
(
gpsMsg
)
self
.
sendMsg
(
gpsMsg
)
self
.
websocket
.
send
(
type
+
">>>>:"
+
gpsMsg
)
#根据特定参数,生成GPS消息
def
genGPSMsg
(
self
,
latitude
,
longtitude
):
gpsObj
=
GPSReport_protocol
(
DEV_ID
=
self
.
carId
)
gpsObj
.
setLatitude
(
latitude
)
gpsObj
.
setLongitude
(
longtitude
)
timeS
=
time
.
time
()
timeS
=
int
(
time
.
time
())
-
8
*
3600
timeArray
=
time
.
localtime
(
timeS
)
UTCTime
=
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
,
timeArray
)
gpsObj
.
setUTCTime
(
UTCTime
)
gpsObj
.
setGPSTimestamp
(
timeS
)
msg
=
gpsObj
.
generateGpsMsg
()
return
msg
#根据特定参数,生成GPS消息体,不包含消息头
def
genGPSData
(
self
,
latitude
,
longtitude
):
gpsObj
=
GPSReport_protocol
(
DEV_ID
=
self
.
carId
)
gpsObj
.
setLatitude
(
latitude
)
gpsObj
.
setLongitude
(
longtitude
)
timeS
=
int
(
time
.
time
())
-
8
*
3600
timeArray
=
time
.
localtime
(
timeS
)
UTCTime
=
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
,
timeArray
)
gpsObj
.
setUTCTime
(
UTCTime
)
gpsObj
.
setGPSTimestamp
(
timeS
)
data
=
gpsObj
.
generateGpsData
()
return
data
# 根据特定参数,生成OBD CAN消息
def
genOBDMsg
(
self
,
fireStatus
=
1
,
ACCStatus
=
0
,
engineSpeed
=
300
,
speed
=
0
,
meterMileage
=
6000
,
\
...
...
templates/protocolTools/report/M_carSimulater_page.html
View file @
546db7bf
...
...
@@ -168,7 +168,15 @@ function fire(){
}
//行驶
function
startTravel
(){
var
carId
=
$
(
"
#carId
"
).
val
()
var
WATER_CODE
=
$
(
"
#WATER_CODE
"
).
val
()
var
durTime
=
$
(
"
#durTime
"
).
val
()
var
gpsLine
=
$
(
"
#selectGPSLine
"
).
val
()
var
data
=
{};
data
[
"
carId
"
]
=
carId
data
[
"
WATER_CODE
"
]
=
WATER_CODE
data
[
"
durTime
"
]
=
durTime
data
[
"
gpsLine
"
]
=
gpsLine
url
=
"
/protocolTools/M_carSimulater_process/startTravel
"
;
send
(
data
,
url
);
$
(
"
#curStatus
"
).
val
(
"
行驶
"
)
...
...
@@ -182,7 +190,15 @@ function stopTravel(){
}
//熄火
function
unFire
(){
var
carId
=
$
(
"
#carId
"
).
val
()
var
WATER_CODE
=
$
(
"
#WATER_CODE
"
).
val
()
var
durTime
=
$
(
"
#durTime
"
).
val
()
var
gpsLine
=
$
(
"
#selectGPSLine
"
).
val
()
var
data
=
{};
data
[
"
carId
"
]
=
carId
data
[
"
WATER_CODE
"
]
=
WATER_CODE
data
[
"
durTime
"
]
=
durTime
data
[
"
gpsLine
"
]
=
gpsLine
url
=
"
/protocolTools/M_carSimulater_process/unFire
"
;
send
(
data
,
url
);
$
(
"
#curStatus
"
).
val
(
"
熄火
"
)
...
...
views/protocolTools/M_carSimulater_process.py
View file @
546db7bf
...
...
@@ -69,6 +69,7 @@ def createConect():
service
=
ProtocolSimulaterService
()
service
.
setSocket
(
cliSocket
)
service
.
setTimeout
(
timeout
)
service
.
setSocket
(
cliSocket
)
service
.
startWebsocketService
()
connects
[
0
][
"service"
]
=
service
data
[
"status"
]
=
"200"
...
...
@@ -93,8 +94,6 @@ def login():
data
=
{}
try
:
service
=
connects
[
0
][
"service"
]
clientSocket
=
connects
[
0
][
"obj"
]
service
.
setSocket
(
clientSocket
)
service
.
setCarId
(
params
[
"carId"
])
loginObj
=
LoginReport_protocol
(
params
[
"WATER_CODE"
],
params
[
"carId"
],
params
[
"login"
][
"cpuId"
],
\
params
[
"login"
][
"imsi"
],
params
[
"login"
][
"ccid"
],
params
[
"login"
][
"imei"
])
...
...
@@ -121,14 +120,13 @@ def login():
def
fire
():
durTime
=
int
(
request
.
form
.
get
(
"durTime"
))
gpsLine
=
request
.
form
.
get
(
"gpsLine"
)
carId
=
request
.
form
.
get
(
"carId"
)
data
=
{}
try
:
service
=
connects
[
0
][
"service"
]
service
.
set
SendDur
(
durTime
)
#设置车机多久循环发送一次消息
service
.
set
CarId
(
carId
)
service
.
setGpsLine
(
gpsLine
)
service
.
fireOn
()
service
.
startService
()
connects
[
0
][
"service"
]
=
service
data
[
"status"
]
=
"200"
data
[
"message"
]
=
"点火成功!"
except
BaseException
as
e
:
...
...
@@ -143,9 +141,14 @@ def fire():
##########################################
@
M_carSimulater_process
.
route
(
"/startTravel"
,
methods
=
[
'POST'
])
def
startTravel
():
durTime
=
int
(
request
.
form
.
get
(
"durTime"
))
gpsLine
=
request
.
form
.
get
(
"gpsLine"
)
data
=
{}
try
:
service
=
connects
[
0
][
"service"
]
service
.
setSendDur
(
durTime
)
#设置车机多久循环发送一次消息
service
.
setGpsLine
(
gpsLine
)
service
.
startService
()
service
.
startTravel
()
data
[
"status"
]
=
"200"
data
[
"message"
]
=
"行驶成功!"
...
...
@@ -179,10 +182,14 @@ def stopTravel():
##########################################
@
M_carSimulater_process
.
route
(
"/unFire"
,
methods
=
[
'POST'
])
def
unFire
():
gpsLine
=
request
.
form
.
get
(
"gpsLine"
)
carId
=
request
.
form
.
get
(
"carId"
)
data
=
{}
try
:
connects
[
0
][
"service"
]
.
setGpsLine
(
gpsLine
)
connects
[
0
][
"service"
]
.
setCarId
(
carId
)
connects
[
0
][
"service"
]
.
fireOff
()
connects
[
0
][
"service"
]
.
stop
Service
()
connects
[
0
][
"service"
]
.
stop
Travel
()
data
[
"status"
]
=
"200"
data
[
"message"
]
=
"熄火成功!"
except
BaseException
as
e
:
...
...
@@ -203,6 +210,7 @@ def closeConect():
data
[
"status"
]
=
"4003"
data
[
"message"
]
=
"没有可关闭的连接!"
else
:
connects
[
0
][
"service"
]
.
stopTravel
()
connects
[
0
][
"service"
]
.
stopWebsocketService
()
connects
[
0
][
"service"
]
.
stopService
()
connects
[
0
][
"service"
]
.
closeSocket
()
...
...
@@ -224,6 +232,7 @@ def reset():
data
=
{}
try
:
for
t
in
connects
:
t
[
"service"
]
.
stopTravel
()
t
[
"service"
]
.
stopWebsocketService
()
t
[
"service"
]
.
stopService
()
t
[
"service"
]
.
closeSocket
()
...
...
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