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
4ccba252
Commit
4ccba252
authored
Apr 01, 2020
by
liyuanhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
地理位置上报界面逻辑完成
parent
6556b53e
Changes
21
Show whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
770 additions
and
89 deletions
+770
-89
config/protocolTools/carSimulater.conf
config/protocolTools/carSimulater.conf
+1
-1
config/protocolTools/protocolTools.conf
config/protocolTools/protocolTools.conf
+1
-1
data/protocolTools/GPSLines/1_sample.json
data/protocolTools/GPSLines/1_sample.json
+1
-1
lib/protocol/appendix/EventClass.py
lib/protocol/appendix/EventClass.py
+26
-6
lib/protocol/m300/Login_protocol_m300.py
lib/protocol/m300/Login_protocol_m300.py
+36
-0
lib/protocol/m300/OBDCAN_protocol_m300.py
lib/protocol/m300/OBDCAN_protocol_m300.py
+59
-0
lib/protocol/m300/VersionInfo_protocol_m300.py
lib/protocol/m300/VersionInfo_protocol_m300.py
+56
-0
lib/protocol/message/Location_msg.py
lib/protocol/message/Location_msg.py
+4
-4
lib/protocol/report/EventReport_protocol.py
lib/protocol/report/EventReport_protocol.py
+29
-3
lib/protocol/report/GPSReport_protocol.py
lib/protocol/report/GPSReport_protocol.py
+2
-4
lib/protocol/report/OBDReport_CAN_protocol.py
lib/protocol/report/OBDReport_CAN_protocol.py
+19
-47
lib/protocol/report/SecurityStatusReport_protocol.py
lib/protocol/report/SecurityStatusReport_protocol.py
+4
-4
lib/socket/messageTest.py
lib/socket/messageTest.py
+1
-1
lib/socket/protocolTest_M300.py
lib/socket/protocolTest_M300.py
+3
-1
lib/socket/protocolTest_M500.py
lib/socket/protocolTest_M500.py
+9
-3
lib/socket/service/ProtocolSimulaterService.py
lib/socket/service/ProtocolSimulaterService.py
+121
-5
lib/util/fileUtil.py
lib/util/fileUtil.py
+68
-0
templates/messageTools/message/location_msg_page.html
templates/messageTools/message/location_msg_page.html
+167
-1
templates/protocolTools/report/M_carSimulater_page.html
templates/protocolTools/report/M_carSimulater_page.html
+70
-4
views/protocolTools/M_carSimulater_process.py
views/protocolTools/M_carSimulater_process.py
+91
-3
views/protocolTools/M_carSimulater_view.py
views/protocolTools/M_carSimulater_view.py
+2
-0
No files found.
config/protocolTools/carSimulater.conf
View file @
4ccba252
[
socket
]
host
=
10
.
100
.
5
.
251
host
=
10
.
100
.
12
.
32
port
=
9008
config/protocolTools/protocolTools.conf
View file @
4ccba252
[
socket
]
host
=
10
.
100
.
5
.
251
host
=
10
.
100
.
12
.
32
port
=
9008
data/protocolTools/GPSLine
_1
.json
→
data/protocolTools/GPSLine
s/1_sample
.json
View file @
4ccba252
{
"name"
:
"GPS轨迹1"
,
"
locationInfo
"
:[
"
GPSLine
"
:[
{
"lng"
:
106.586571
,
"lat"
:
29.569133
...
...
lib/protocol/appendix/EventClass.py
View file @
4ccba252
...
...
@@ -12,10 +12,10 @@ class EventClass(ProtocolBase):
# 3 点火事件附带信息
def
fireExtraInfo
(
self
):
allRapidlyAccelerateCount
=
self
.
int2hexStringByBytes
(
1
00
,
2
)
# 急加速总次数
allSharpSlowdownCount
=
self
.
int2hexStringByBytes
(
1
01
,
2
)
# 急减速总次数
allSharpTurn
=
self
.
int2hexStringByBytes
(
3
5
,
2
)
# 急转弯总次数
securityData
=
SecurityStatusReport_protocol
.
generateSecurityStatusData
()
# 安防数据
allRapidlyAccelerateCount
=
self
.
int2hexStringByBytes
(
1
5
,
2
)
# 急加速总次数
allSharpSlowdownCount
=
self
.
int2hexStringByBytes
(
1
5
,
2
)
# 急减速总次数
allSharpTurn
=
self
.
int2hexStringByBytes
(
1
5
,
2
)
# 急转弯总次数
securityData
=
SecurityStatusReport_protocol
()
.
generateSecurityStatusData
()
# 安防数据
data
=
allRapidlyAccelerateCount
+
allSharpSlowdownCount
+
allSharpTurn
+
securityData
return
data
...
...
@@ -24,7 +24,7 @@ class EventClass(ProtocolBase):
allRapidlyAccelerateCount
=
self
.
int2hexStringByBytes
(
100
,
2
)
#急加速总次数
allSharpSlowdownCount
=
self
.
int2hexStringByBytes
(
101
,
2
)
#急减速总次数
allSharpTurn
=
self
.
int2hexStringByBytes
(
35
,
2
)
#急转弯总次数
securityData
=
SecurityStatusReport_protocol
.
generateSecurityStatusData
()
#安防数据
securityData
=
SecurityStatusReport_protocol
()
.
generateSecurityStatusData
()
#安防数据
data
=
allRapidlyAccelerateCount
+
allSharpSlowdownCount
+
allSharpTurn
+
securityData
return
data
...
...
@@ -238,7 +238,20 @@ class EventClass(ProtocolBase):
else
:
return
self
.
getUTCTimeHex
(
datetime
.
datetime
.
now
()
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
))
#54 N秒内的车辆倾斜角
#50 低档高速报警附
def
lowGearHighSpeedAlarm
(
self
,
alarmType
=
1
,
durationTime
=
10
):
alarmTypeHex
=
self
.
int2hexStringByBytes
(
alarmType
)
durationTimeHex
=
self
.
int2hexStringByBytes
(
durationTime
,
2
)
data
=
alarmTypeHex
+
durationTimeHex
return
data
#51 高档低速报警附带信息
def
highGearLowSpeedAlarm
(
self
,
alarmType
=
1
,
durationTime
=
10
):
alarmTypeHex
=
self
.
int2hexStringByBytes
(
alarmType
)
durationTimeHex
=
self
.
int2hexStringByBytes
(
durationTime
,
2
)
data
=
alarmTypeHex
+
durationTimeHex
return
data
def
carSlopeAngleFromSeconds
(
self
,
counts
):
data
=
""
for
i
in
range
(
0
,
counts
):
...
...
@@ -246,6 +259,13 @@ class EventClass(ProtocolBase):
data
+=
self
.
int2hexStringByBytes
(
self
.
num2signedNum
(
-
50
),
2
)
#第1秒内侧倾角[-90, 90],大于0右倾,小于0左倾
return
data
#69 剩余油量异常告警附带信息
def
surplusOilAlarm
(
self
,
surplusOilType
=
0
,
value
=
30
):
surplusOilTypeHex
=
self
.
int2hexStringByBytes
(
surplusOilType
)
valueHex
=
self
.
int2hexStringByBytes
(
value
,
2
)
data
=
surplusOilTypeHex
+
valueHex
return
data
if
__name__
==
"__main__"
:
# print(EventClass().GPSDataFromSeconds(10))
...
...
lib/protocol/m300/Login_protocol_m300.py
0 → 100644
View file @
4ccba252
from
lib.protocol.m300.M300Base
import
M300Base
'''
定义终端登录协议类
'''
class
Login_protocol_m300
(
M300Base
):
def
__init__
(
self
,
waterCode
=
"0003"
,
DEV_ID
=
"M121501010001"
):
super
()
.
__init__
()
# 不执行该方法,无法使用父类里面定义的属性
self
.
waterCode
=
waterCode
#消息流水号
self
.
DEV_ID
=
DEV_ID
#设备Id
#################################################
# 生成消息
#################################################
def
generateMsg
(
self
):
msg
=
self
.
IDENTIFY
FUNID
=
"00FF"
#功能id
waterCode
=
self
.
waterCode
#消息流水号
DEV_ID
=
self
.
devid2hexString
(
self
.
DEV_ID
)
#设备id
msgBody
=
self
.
getMsgBody
()
# 消息体
msgLen
=
int
(
len
(
msgBody
)
/
2
)
property
=
self
.
getMsgProperty
(
msgBodyLen
=
msgLen
,
encryptionType
=
0
)
checkCode
=
self
.
getCheckCode
(
FUNID
+
waterCode
+
DEV_ID
+
property
+
msgBody
)
msg
=
msg
+
FUNID
+
waterCode
+
DEV_ID
+
property
+
msgBody
+
checkCode
+
self
.
IDENTIFY
return
msg
#################################################
# 获取消息体
#################################################
def
getMsgBody
(
self
):
data
=
""
return
data
if
__name__
==
"__main__"
:
print
(
Login_protocol_m300
()
.
generateMsg
())
\ No newline at end of file
lib/protocol/m300/OBDCAN_protocol_m300.py
0 → 100644
View file @
4ccba252
#encoding:utf-8
from
lib.protocol.m300.M300Base
import
M300Base
'''
定义OBD CAN类
'''
class
OBDCAN_protocol_m300
(
M300Base
):
def
__init__
(
self
,
waterCode
=
"0003"
,
DEV_ID
=
"M121501010001"
,
timeInfo
=
"2020-03-30 17:00:59"
,
prototolType
=
"11"
,
statusMask
=
"01010101010101010101"
\
,
safeStatus
=
0
,
doorStatus
=
0
,
lockStatus
=
0
,
windowStatus
=
0
,
lightStatus
=
0
,
swichStatusA
=
0
,
swichStatusB
=
0
,
dataBit
=
0
\
,
dataFlowMask
=
"fffffffd"
,
votage
=
360
,
totalMilleageType
=
"02"
,):
super
()
.
__init__
()
# 不执行该方法,无法使用父类里面定义的属性
self
.
waterCode
=
waterCode
#消息流水号
self
.
DEV_ID
=
DEV_ID
#设备Id
self
.
timeInfo
=
timeInfo
#时间信息
self
.
prototolType
=
prototolType
#协议类别
self
.
statusMask
=
statusMask
#状态掩码
self
.
safeStatus
=
safeStatus
#安全状态
self
.
doorStatus
=
doorStatus
#门状态
self
.
lockStatus
=
lockStatus
#锁状态
self
.
windowStatus
=
windowStatus
#窗户状态
self
.
lightStatus
=
lightStatus
#灯状态
self
.
swichStatusA
=
swichStatusA
#开关状态A
self
.
swichStatusB
=
swichStatusB
# 开关状态B
self
.
dataBit
=
dataBit
#数据字节
self
.
dataFlowMask
=
dataFlowMask
#数据流掩码
self
.
votage
=
votage
#电瓶电压
self
.
totalMilleageType
=
totalMilleageType
#总里程类别
#################################################
# 生成消息
#################################################
def
generateMsg
(
self
):
msg
=
self
.
IDENTIFY
FUNID
=
"0004"
#功能id
waterCode
=
self
.
waterCode
#消息流水号
DEV_ID
=
self
.
devid2hexString
(
self
.
DEV_ID
)
#设备id
msgBody
=
self
.
getMsgBody
()
# 消息体
msgLen
=
int
(
len
(
msgBody
)
/
2
)
property
=
self
.
getMsgProperty
(
msgBodyLen
=
msgLen
,
encryptionType
=
0
)
checkCode
=
self
.
getCheckCode
(
FUNID
+
waterCode
+
DEV_ID
+
property
+
msgBody
)
msg
=
msg
+
FUNID
+
waterCode
+
DEV_ID
+
property
+
msgBody
+
checkCode
+
self
.
IDENTIFY
return
msg
#################################################
# 获取消息体
#################################################
def
getMsgBody
(
self
):
data
=
""
return
data
if
__name__
==
"__main__"
:
print
(
OBDCAN_protocol_m300
()
.
generateMsg
())
lib/protocol/m300/VersionInfo_protocol_m300.py
0 → 100644
View file @
4ccba252
#encoding:utf-8
from
lib.protocol.m300.M300Base
import
M300Base
'''
定义心跳议类
'''
class
VersionInfo_protocol_m300
(
M300Base
):
def
__init__
(
self
,
waterCode
=
"0003"
,
DEV_ID
=
"M121501010001"
,
SWVersion
=
"VSTA000GV100"
,
SWDate
=
"2020-03-30"
,
HWVersion
=
"M1.0"
\
,
GSMType
=
"GSM_type_123456"
,
carType
=
"150D"
,
engineCode
=
1
,
VINCode
=
"VIN_CODE_01234567890"
):
super
()
.
__init__
()
# 不执行该方法,无法使用父类里面定义的属性
self
.
waterCode
=
waterCode
#消息流水号
self
.
DEV_ID
=
DEV_ID
#设备Id
self
.
SWVersion
=
SWVersion
#软件版本号
self
.
SWDate
=
SWDate
#软件日期
self
.
HWVersion
=
HWVersion
#硬件版本
self
.
GSMType
=
GSMType
#GSM 型号
self
.
carType
=
carType
#车系车型ID: 150D
self
.
engineCode
=
engineCode
#发动机编码类别
self
.
VINCode
=
VINCode
#汽车VIN码 或 发动机ECU编码
#################################################
# 生成消息
#################################################
def
generateMsg
(
self
):
msg
=
self
.
IDENTIFY
FUNID
=
"0007"
#功能id
waterCode
=
self
.
waterCode
#消息流水号
DEV_ID
=
self
.
devid2hexString
(
self
.
DEV_ID
)
#设备id
msgBody
=
self
.
getMsgBody
()
# 消息体
msgLen
=
int
(
len
(
msgBody
)
/
2
)
property
=
self
.
getMsgProperty
(
msgBodyLen
=
msgLen
,
encryptionType
=
0
)
checkCode
=
self
.
getCheckCode
(
FUNID
+
waterCode
+
DEV_ID
+
property
+
msgBody
)
msg
=
msg
+
FUNID
+
waterCode
+
DEV_ID
+
property
+
msgBody
+
checkCode
+
self
.
IDENTIFY
return
msg
#################################################
# 获取消息体
#################################################
def
getMsgBody
(
self
):
SWVersion
=
self
.
str2Hex
(
self
.
SWVersion
)
SWDate
=
self
.
str2Hex
(
self
.
SWDate
)
HWVersion
=
self
.
str2Hex
(
self
.
HWVersion
)
GSMType
=
self
.
str2Hex
(
self
.
GSMType
)
carType
=
self
.
str2Hex
(
self
.
carType
)
engineCode
=
self
.
int2hexStringByBytes
(
self
.
engineCode
)
VINCode
=
self
.
str2Hex
(
self
.
VINCode
)
data
=
SWVersion
+
SWDate
+
HWVersion
+
GSMType
+
carType
+
engineCode
+
VINCode
return
data
if
__name__
==
"__main__"
:
print
(
VersionInfo_protocol_m300
()
.
generateMsg
())
\ No newline at end of file
lib/protocol/message/Location_msg.py
View file @
4ccba252
...
...
@@ -176,10 +176,10 @@ class Location_msg(MessageBase):
#报警事件 ID 数据项列表
extra_FA
=
"FA"
+
self
.
int2hexStringByBytes
(
int
(
len
(
AlarmEvent_data
()
.
generateAlarmEvent_data
())
/
2
))
+
AlarmEvent_data
()
.
generateAlarmEvent_data
()
# data = extra_01 + extra_02 + extra_11 + extra_31 + extra_EA + extra_EB + extra_FA
data
=
extra_01
+
extra_02
+
extra_11
+
extra_31
+
extra_EA
+
extra_EB
# data = extra_11 + extra_31 + extra_EA + extra_EB + extra_FA
data
=
extra_11
+
extra_31
+
extra_EA
+
extra_FA
#
data = extra_11 + extra_31 + extra_EA + extra_FA
# data = extra_EB + extra_FA
# data = extra_01 + extra_02 + extra_11 + extra_12 + extra_13
# data = data + extra_2A + extra_30 + extra_31 + extra_EA + extra_EB
# data = data +extra_FA
...
...
@@ -568,7 +568,7 @@ class Location_msg(MessageBase):
# msgID = self.int2hexStringByBytes(102,2) #消息id
msgID
=
"0200"
msgBodyProperty
=
self
.
getMsgBodyProperty
(
int
(
len
(
self
.
getMsgBody
())
/
2
))
#消息体属性
phoneNum
=
self
.
int2BCD
(
1314620111
9
)
#终端手机号
phoneNum
=
self
.
int2BCD
(
1314620111
0
)
#终端手机号
msgWaterCode
=
self
.
int2hexStringByBytes
(
1
,
2
)
#消息流水号
subPkgContent
=
""
#消息包封装项
data
=
msgID
+
msgBodyProperty
+
phoneNum
+
msgWaterCode
+
subPkgContent
...
...
lib/protocol/report/EventReport_protocol.py
View file @
4ccba252
#coding:utf-8
import
time
from
lib.protocol.report.GPSReport_protocol
import
GPSReport_protocol
from
lib.protocol.report.ProtocolBase
import
ProtocolBase
from
lib.protocol.appendix.EventClass
import
EventClass
...
...
@@ -9,7 +11,7 @@ from lib.protocol.appendix.EventClass import EventClass
class
EventReport_protocol
(
ProtocolBase
):
def
__init__
(
self
,
msgCount
=
1
,
WATER_CODE
=
26
,
DEV_ID
=
"M121501010001"
,
locationType
=
1
,
eventType
=
"00
0F
"
):
def
__init__
(
self
,
msgCount
=
1
,
WATER_CODE
=
26
,
DEV_ID
=
"M121501010001"
,
locationType
=
1
,
eventType
=
"00
36
"
):
super
()
.
__init__
()
self
.
msgCount
=
msgCount
#数据包个数
...
...
@@ -18,11 +20,22 @@ class EventReport_protocol(ProtocolBase):
self
.
locationType
=
int
(
locationType
)
# 定位类型
#self.GPSPkg = GPSpkg & BaseStationPkg # GPS包或者基站包
self
.
GPSPkg
=
"1401091213260265b86206ed8c70026103280000752f03030405af017102610bb800003200000186a0001ed2a25e16fe3a"
# self.GPSPkg = "1401091213260265b86206ed8c70026103280000752f03030405af017102610bb800003200000186a0001ed2a25e16fe3a"
self
.
latitude
=
40.22077
self
.
longitude
=
116.23128
self
.
timestamp
=
int
(
time
.
time
())
self
.
BaseStationPkg
=
"1401140a0c050207e407e607e807ea07ec4eea4eec4eee4ef04efc4efe4f004f024f040024025e07d00007a125000927c60000ea610100"
self
.
eventType
=
eventType
#事件类别
def
setLatitude
(
self
,
data
):
self
.
latitude
=
data
def
setLongtitude
(
self
,
data
):
self
.
longitude
=
data
def
setEventType
(
self
,
data
):
self
.
eventType
=
data
#####################################################
# 生成事件信息消息
#####################################################
...
...
@@ -70,6 +83,12 @@ 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
:
...
...
@@ -133,3 +152,10 @@ class EventReport_protocol(ProtocolBase):
return
EventClass
()
.
defencesGlassNoCloseExtraInfo
()
elif
eventType
==
"0017"
:
#设防非法开门报警
return
EventClass
()
.
defencesIllegalCloseDoorExtraInfo
()
elif
eventType
==
"0036"
:
#低档高速报警
return
EventClass
()
.
lowGearHighSpeedAlarm
()
elif
eventType
==
"0037"
:
#高档低速报警
return
EventClass
()
.
highGearLowSpeedAlarm
()
elif
eventType
==
"004A"
:
#剩余油量异常告警
return
EventClass
()
.
surplusOilAlarm
()
lib/protocol/report/GPSReport_protocol.py
View file @
4ccba252
...
...
@@ -112,8 +112,6 @@ class GPSReport_protocol(ProtocolBase):
pkg
=
pkgNumHex
+
data
return
pkg
#####################################################
# 创建GPS数据段
#####################################################
...
...
@@ -323,8 +321,8 @@ class GPSReport_protocol(ProtocolBase):
# (按照低位在前高位在后的方式去计算)
#####################################################
def
getStatusBit
(
self
,
num
):
fireStatus
=
128
#点火状态,128表示点火,0表示熄火
mileageWay
=
0
#0里程统计模式,表示GPS里程,64表示OBD里程
fireStatus
=
0
#点火状态,128表示点火,0表示熄火
mileageWay
=
64
#0里程统计模式,表示GPS里程,64表示OBD里程
locationWay
=
32
#定位类型,32表示2D定位,48表示3D定位
locationMode
=
0
#定位模式,0表示自动模式,2表示单GPS模式,4表示单BDS模式,6表示GPS+BDS双模式
isLocationValid
=
1
#当前定位是否有效,1表示有效,0表示无效
...
...
lib/protocol/report/OBDReport_CAN_protocol.py
View file @
4ccba252
...
...
@@ -59,6 +59,25 @@ class OBDReport_CAN_protocol(ProtocolBase):
self
.
GPSSpeed
=
float
(
GPSSpeed
)
# 设置GPS车速
self
.
GPSMileage
=
int
(
GPSMileage
)
# 设置GPS里程
def
setFireStatus
(
self
,
data
):
#点火状态
self
.
fireStatus
=
data
def
setACCStatus
(
self
,
data
):
#ACC状态
self
.
ACCStatus
=
data
def
setEngineSpeed
(
self
,
data
):
#发动机转速
self
.
engineSpeed
=
data
def
setSpeed
(
self
,
data
):
#车辆速度
self
.
speed
=
data
def
setMeterMileage
(
self
,
data
):
#汽车仪表里程值
self
.
meterMileage
=
data
def
setTotalMileage
(
self
,
data
):
#总里程
self
.
totalMileage
=
data
def
setTroubleMileage
(
self
,
data
):
#故障行驶里程
self
.
troubleMileage
=
data
def
setTotalOilExpend
(
self
,
data
):
#总油耗
self
.
totalOilExpend
=
data
def
setSurplusOil
(
self
,
data
):
#剩余油量
self
.
surplusOil
=
data
#####################################################
# 生成OBD终端上报CAN配置信息
...
...
@@ -210,51 +229,6 @@ class OBDReport_CAN_protocol(ProtocolBase):
data
=
data
+
momentOilExpend
+
meterOilExpend
+
engineAbsoluteLoad
+
steeringWheelAngle
+
torquePercentage
data
=
data
+
gearsLocation
+
GPSSpeed
+
GPSMileage
+
retain
# print("1___" + infoTime)
# print("2___" + dataFlowCode)
# print("3___" + protocolType)
# print("4___" + fireStatus)
# print("5___" + ACCStatus)
# print("6___" + voltage)
# print("7___" + troubleLightStatus)
# print("8___" + toubleCodeCount)
# print("9___" + engineSpeed)
# print("10___" + speed)
# print("11___" + meterMileage)
# print("12___" + mileageStatisticsStyle)
# print("13___" + totalMileage)
# print("14___" + troubleMileage)
# print("15___" + totalOilExpend)
# print("16___" + surplusOil)
# print("17___" + totalRunTime)
# print("18___" + totalEngineTime)
# print("19___" + airIntoAisleTemperture)
# print("20___" + coolingLiquidTemperture)
# print("21___" + envTemperture)
# print("22___" + ariIntoPress)
# print("23___" + oilPressure)
# print("24___" + atmosphericPressure)
# print("25___" + airFlow)
# print("26___" + valveLocationSensor)
# print("27___" + acceleratorLocation)
# print("28___" + engineLoad)
# print("29___" + fuelTrim)
# print("30___" + fireAngle)
# print("31___" + B1S1oxygenSensorVoltage)
# print("32___" + B1S2oxygenSensorVoltage)
# print("33___" + B1S1oxygenSensorElectricity)
# print("34___" + B1S2oxygenSensorElectricity)
# print("35___" + momentOilExpend)
# print("36___" + meterOilExpend)
# print("37___" + engineAbsoluteLoad)
# print("38___" + steeringWheelAngle)
# print("39___" + torquePercentage)
# print("40___" + gearsLocation)
# print("41___" + GPSSpeed)
# print("42___" + GPSMileage)
# print("43___" + retain)
return
data
####################################################
...
...
@@ -423,11 +397,9 @@ class OBDReport_CAN_protocol(ProtocolBase):
# 显示值为上报值 / 10
#####################################################
def
getSurplusOilHex
(
self
,
num
):
print
(
num
)
hexData
=
self
.
int2hexString
(
num
)
while
len
(
hexData
)
<
4
:
hexData
=
"0"
+
hexData
print
(
hexData
)
return
hexData
####################################################
...
...
lib/protocol/report/SecurityStatusReport_protocol.py
View file @
4ccba252
...
...
@@ -8,7 +8,7 @@ from lib.protocol.report.ProtocolBase import ProtocolBase
class
SecurityStatusReport_protocol
(
ProtocolBase
):
def
__init__
(
self
,
msgCount
=
1
,
WATER_CODE
=
14
,
DEV_ID
=
"M121501010001"
,
locationType
=
1
,
GPSpkg
=
""
,
statusCode
=
"ffffffffffffffffffff"
,
securityStatus
=
194
,
doorStatus
=
0
,
lockStatus
=
0
,
windowStatus
=
0
,
lightStatus
=
0
,
onoffStatusA
=
0
,
onoffStatusB
=
0
,
dataByte
=
0
):
def
__init__
(
self
,
msgCount
=
1
,
WATER_CODE
=
14
,
DEV_ID
=
"M121501010001"
,
locationType
=
1
,
GPSpkg
=
""
,
statusCode
=
"ffffffffffffffffffff"
,
securityStatus
=
32
,
doorStatus
=
0
,
lockStatus
=
0
,
windowStatus
=
0
,
lightStatus
=
0
,
onoffStatusA
=
0
,
onoffStatusB
=
0
,
dataByte
=
0
):
super
()
.
__init__
()
self
.
msgCount
=
int
(
msgCount
)
self
.
WATER_CODE
=
int
(
WATER_CODE
)
...
...
@@ -108,10 +108,10 @@ class SecurityStatusReport_protocol(ProtocolBase):
# 按照高位在前,低位在后的规则
#####################################################
def
getSecurityStatusHex
(
self
,
data
):
accStatus
=
1
#acc状态,1:开 0:关
defenseStatus
=
2
#设防撤防状态,2:设防 0:撤防
accStatus
=
0
#acc状态,1:开 0:关
defenseStatus
=
0
#设防撤防状态,2:设防 0:撤防
brakeStatus
=
0
#脚刹状态,4:踩下 0:松开
acceleratorStatus
=
8
#是否踩油门,8:踩下 0:松开
acceleratorStatus
=
0
#是否踩油门,8:踩下 0:松开
handBrakeStatus
=
0
#手刹状态,16:拉起手刹 0:松开手刹
mainSafetyBelt
=
32
#主驾驶安全带,32:插入安全带 0:松开安全带
subSafetyBelt
=
64
#副驾驶安全带,64:插入安全带 0:松开安全带
...
...
lib/socket/messageTest.py
View file @
4ccba252
lib/socket/protocolTest_M300.py
View file @
4ccba252
...
...
@@ -4,6 +4,7 @@ import socket
from
lib.protocol.m300.GPS_protocol_m300
import
GPS_protocol_m300
from
lib.protocol.m300.Heartbeat_protocol_300
import
Heartbeat_protocol_300
from
lib.protocol.m300.VersionInfo_protocol_m300
import
VersionInfo_protocol_m300
from
lib.protocol.report.GPSReport_protocol
import
GPSReport_protocol
from
lib.protocol.report.OBDReport_CAN_protocol
import
OBDReport_CAN_protocol
from
lib.protocol.report.OBDReport_CAN_protocol
import
OBDReport_CAN_protocol
...
...
@@ -27,7 +28,8 @@ host = "10.100.5.251"
port
=
9009
# msg = Heartbeat_protocol_300().generateMsg() #心跳报文
msg
=
GPS_protocol_m300
()
.
generateMsg
()
#GPS报文
# msg = GPS_protocol_m300().generateMsg() #GPS报文
msg
=
VersionInfo_protocol_m300
()
.
generateMsg
()
#终端版本报文
# msg = "7e000400e14d2019120315000000957e" #终端上报心跳协议
...
...
lib/socket/protocolTest_M500.py
View file @
4ccba252
#coding:utf-8
import
binascii
import
os
import
socket
import
sys
curdir
=
os
.
getcwd
()
cpath
=
curdir
+
"
\\
..
\\
..
\\
"
sys
.
path
.
append
(
cpath
)
from
lib.protocol.report.CommonReport_protocol
import
CommonReport_protocol
from
lib.protocol.report.GPSReport_protocol
import
GPSReport_protocol
...
...
@@ -27,15 +33,15 @@ port = 9008
# msg = GPSReport_protocol().generateGpsMsg() #GPS消息数据
# msg = OBDReport_protocol().generateOBDReportMsg() #OBD终端上报数据
# msg = OBDReport_CAN_protocol().generateOBDReportCANMsg() #OBD终端上报CAN数据
msg
=
HeartBeatReport_protocol
()
.
generateHeartBeatMsg
()
#终端上报心跳协议
#
msg = HeartBeatReport_protocol().generateHeartBeatMsg() #终端上报心跳协议
# msg = LoginReport_protocol().generateLoginMsg() #终端上报登录协议
# msg = SecurityStatusReport_protocol().generateSecurityStatusMsg() #终端上报安防状态协议
# msg = BaseStationReport_protocol().generateBaseStationMsg() #终端上报基站定位协议
# msg = TroubleReport_protocol().generateTroubleMsg() #终端上报故障码数据包
# msg = EventReport_protocol().generateEventMsg()
msg
=
EventReport_protocol
()
.
generateEventMsg
()
#终端上报事件数据包
# msg = VersionReport_protocol().generateVersionMsg() #终端上报版本信息数据包
# msg = SleepReport_protocol().generateSleepMsg() #终端休眠数据包
msg
=
CommonReport_protocol
()
.
generateCommonMsg
()
#通用应答消息
#
msg = CommonReport_protocol().generateCommonMsg() #通用应答消息
print
(
msg
)
BUF_SIZE
=
1024
...
...
lib/socket/service/ProtocolSimulaterService.py
View file @
4ccba252
...
...
@@ -4,10 +4,15 @@
M500车机模拟服务类
'''
import
binascii
import
json
import
threading
import
time
import
traceback
from
time
import
sleep
from
lib.protocol.report.EventReport_protocol
import
EventReport_protocol
from
lib.protocol.report.GPSReport_protocol
import
GPSReport_protocol
from
lib.protocol.report.OBDReport_CAN_protocol
import
OBDReport_CAN_protocol
from
lib.protocol.report.response.Common_response
import
Common_response
from
lib.protocol.report.response.Update_response
import
Update_response
from
lib.socket.service.websocket_service
import
Websocket_service
...
...
@@ -20,6 +25,16 @@ class ProtocolSimulaterService():
self
.
serviceStatus
=
0
#服务状态,0表示未启动,1表示启动
self
.
websocket
=
None
#网页与服务的通信socket
self
.
timeout
=
1
#socket的超时时间
self
.
gpsLine
=
[]
#GPS 轨迹
self
.
gpsLineIndex
=
0
#GPS 轨迹索引
self
.
travelStatus
=
0
#0,表示为行驶,1表示开始行驶
self
.
carId
=
""
#车机号
self
.
OBDdata
=
[
#定义要发送的obd数据
{
"fireStatus"
:
1
,
"ACCStatus"
:
0
,
"engineSpeed"
:
300
,
"speed"
:
0
,
"meterMileage"
:
6000
,
"totailMileage"
:
600
,
"totalOilExpen"
:
30
},
{
"fireStatus"
:
1
,
"ACCStatus"
:
0
,
"engineSpeed"
:
300
,
"speed"
:
0
,
"meterMileage"
:
6000
,
"totailMileage"
:
600
,
"totalOilExpen"
:
30
},
{
"fireStatus"
:
1
,
"ACCStatus"
:
0
,
"engineSpeed"
:
300
,
"speed"
:
0
,
"meterMileage"
:
6000
,
"totailMileage"
:
600
,
"totalOilExpen"
:
30
},
]
self
.
OBDdataIndex
=
0
#发发送OBD数据的索引
#设置套接字
def
setSocket
(
self
,
data
):
...
...
@@ -28,7 +43,8 @@ class ProtocolSimulaterService():
self
.
sendDur
=
data
def
setTimeout
(
self
,
data
):
self
.
timeout
=
data
def
setCarId
(
self
,
data
):
self
.
carId
=
data
def
getWebsocket
(
self
):
return
self
.
websocket
...
...
@@ -46,12 +62,33 @@ class ProtocolSimulaterService():
def
serviceSend
(
self
):
while
self
.
serviceStatus
==
1
:
msg
=
"4040000b00034d1215010100010003f50b"
self
.
sendMsg
(
msg
)
type
=
self
.
getMsgFunId
(
msg
)
info
=
type
+
">>>>:"
+
msg
# msg = "4040000b00034d1215010100010003f50b"
gpsMsg
=
""
OBDMsg
=
""
if
self
.
travelStatus
==
0
:
latitude
=
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lat"
]
longitude
=
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lng"
]
gpsMsg
=
self
.
genGPSMsg
(
latitude
,
longitude
)
elif
self
.
travelStatus
==
1
:
if
self
.
gpsLineIndex
<
len
(
self
.
gpsLine
):
OBDMsg
=
self
.
genOBDMsg
()
latitude
=
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lat"
]
longitude
=
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lng"
]
gpsMsg
=
self
.
genGPSMsg
(
latitude
,
longitude
)
self
.
gpsLineIndex
=
self
.
gpsLineIndex
+
1
elif
self
.
gpsLineIndex
==
len
(
self
.
gpsLine
):
self
.
websocket
.
send
(
"gps轨迹跑完,自动停止行驶!"
)
if
OBDMsg
!=
""
:
self
.
sendMsg
(
OBDMsg
)
type
=
self
.
getMsgFunId
(
OBDMsg
)
info
=
type
+
">>>>:"
+
OBDMsg
self
.
websocket
.
send
(
info
)
self
.
sendMsg
(
gpsMsg
)
type
=
self
.
getMsgFunId
(
gpsMsg
)
info
=
type
+
">>>>:"
+
gpsMsg
self
.
websocket
.
send
(
info
)
sleep
(
self
.
sendDur
)
def
serviceRev
(
self
):
self
.
serviceStatus
=
2
#2代表只启动了接收消息的进程,1代表了接收和发送都启动了
while
self
.
serviceStatus
!=
0
:
...
...
@@ -86,6 +123,10 @@ class ProtocolSimulaterService():
#停止定时发送消息的服务
def
stopService
(
self
):
self
.
serviceStatus
=
0
self
.
gpsLine
=
[]
self
.
gpsLineIndex
=
0
self
.
travelStatus
=
0
def
closeSocket
(
self
):
try
:
self
.
socket
.
close
()
...
...
@@ -93,6 +134,7 @@ class ProtocolSimulaterService():
# 打印异常信息
traceback
.
print_exc
()
#停止websocket服务
def
stopWebsocketService
(
self
):
try
:
self
.
websocket
.
close
()
...
...
@@ -101,6 +143,17 @@ class ProtocolSimulaterService():
# 打印异常信息
traceback
.
print_exc
()
########################################################
# 开始行驶
########################################################
def
startTravel
(
self
):
self
.
travelStatus
=
1
########################################################
# 停止行驶
########################################################
def
stopTravel
(
self
):
self
.
travelStatus
=
0
#获取收到消息的功能id
def
getMsgFunId
(
self
,
msg
):
funId
=
msg
[
26
:
30
]
...
...
@@ -124,6 +177,69 @@ class ProtocolSimulaterService():
type
=
self
.
getMsgFunId
(
msg
)
self
.
websocket
.
send
(
type
+
">>>>升级_平台通知终端远程升级应答:"
+
msg
)
#设置GPS轨迹
def
setGpsLine
(
self
,
fileName
):
with
open
(
"data/protocolTools/GPSLines/"
+
fileName
,
"r"
,
encoding
=
"utf-8"
)
as
fi
:
content
=
fi
.
read
()
conJson
=
json
.
loads
(
content
)
self
.
gpsLine
=
conJson
[
"GPSLine"
]
#点火,发送点火事件
def
fireOn
(
self
):
fireOnEventObj
=
EventReport_protocol
(
DEV_ID
=
self
.
carId
)
fireOnEventObj
.
setLatitude
(
self
.
gpsLine
[
0
][
"lat"
])
fireOnEventObj
.
setLongtitude
(
self
.
gpsLine
[
0
][
"lng"
])
fireOnEventObj
.
setEventType
(
"0010"
)
firOnEventMsg
=
fireOnEventObj
.
generateEventMsg
()
type
=
self
.
getMsgFunId
(
firOnEventMsg
)
self
.
sendMsg
(
firOnEventMsg
)
self
.
websocket
.
send
(
type
+
">>>>:"
+
firOnEventMsg
)
sleep
(
0.1
)
OBDMsg
=
self
.
genOBDMsg
()
type
=
self
.
getMsgFunId
(
OBDMsg
)
self
.
sendMsg
(
OBDMsg
)
self
.
websocket
.
send
(
type
+
">>>>:"
+
OBDMsg
)
# 熄火,发送熄火事件
def
fireOff
(
self
):
fireOffEventObj
=
EventReport_protocol
(
DEV_ID
=
self
.
carId
)
fireOffEventObj
.
setLatitude
(
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lat"
])
fireOffEventObj
.
setLongtitude
(
self
.
gpsLine
[
self
.
gpsLineIndex
][
"lng"
])
fireOffEventObj
.
setEventType
(
"0011"
)
fireOffEventObj
=
fireOffEventObj
.
generateEventMsg
()
type
=
self
.
getMsgFunId
(
fireOffEventObj
)
self
.
sendMsg
(
fireOffEventObj
)
self
.
websocket
.
send
(
type
+
">>>>:"
+
fireOffEventObj
)
#根据特定参数,生成GPS消息
def
genGPSMsg
(
self
,
latitude
,
longtitude
):
gpsObj
=
GPSReport_protocol
(
DEV_ID
=
self
.
carId
)
gpsObj
.
setLatitude
(
latitude
)
gpsObj
.
setLongitude
(
longtitude
)
timeS
=
time
.
time
()
gpsObj
.
setGPSTimestamp
(
timeS
)
msg
=
gpsObj
.
generateGpsMsg
()
return
msg
# 根据特定参数,生成OBD CAN消息
def
genOBDMsg
(
self
,
fireStatus
=
1
,
ACCStatus
=
0
,
engineSpeed
=
300
,
speed
=
0
,
meterMileage
=
6000
,
\
totailMileage
=
600
,
totalOilExpend
=
30
):
OBDObj
=
OBDReport_CAN_protocol
(
DEV_ID
=
self
.
carId
)
OBDObj
.
setFireStatus
(
1
)
OBDObj
.
setACCStatus
(
0
)
OBDObj
.
setEngineSpeed
(
300
)
OBDObj
.
setSpeed
(
0
)
OBDObj
.
setMeterMileage
(
600
)
OBDObj
.
setTotalMileage
(
600
)
OBDObj
.
setTotalOilExpend
(
30
)
msg
=
OBDObj
.
generateOBDReportCANMsg
()
return
msg
...
...
lib/util/fileUtil.py
0 → 100644
View file @
4ccba252
#coding:utf-8
'''
文件操作辅助类
'''
import
os
###############################################
# 获取目录下的所有文件名
###############################################
def
getDirFiles
(
filePath
):
files
=
os
.
listdir
(
filePath
)
return
files
###############################################
# 获取目录下的所有文件名,去掉前缀
###############################################
def
getDirFilesNoPrefix
(
filePath
):
files
=
os
.
listdir
(
filePath
)
for
i
in
range
(
0
,
len
(
files
)):
files
[
i
]
=
removeFilePrefix
(
files
[
i
])
return
files
###############################################
# 获取目录下的所有文件名,以map形式
###############################################
def
getDirFilesListMap
(
filePath
):
files
=
os
.
listdir
(
filePath
)
filesMap
=
{}
for
i
in
range
(
len
(
files
)
-
1
,
-
1
,
-
1
):
filesMap
[
files
[
i
]]
=
removeSuffix
(
removeFilePrefix
(
files
[
i
]))
return
filesMap
###############################################
# 文件名去掉前缀
###############################################
def
removeFilePrefix
(
fileName
):
noPrefixFileName
=
fileName
.
split
(
"_"
)[
1
]
return
noPrefixFileName
###############################################
# 获取当前目录前缀最大的文件
###############################################
def
getMaxPrefixFile
(
filePath
):
theFileName
=
getDirFiles
(
filePath
)[
-
1
]
return
theFileName
###############################################
# 获取当前目录前缀最大的文件的前缀
###############################################
def
getMaxPrefixFilePre
(
filePath
):
theFileName
=
getDirFiles
(
filePath
)[
-
1
]
thePrefix
=
theFileName
.
split
(
"_"
)[
0
]
return
thePrefix
###############################################
# 去掉文件后缀
###############################################
def
removeSuffix
(
fileName
):
theFileName
=
fileName
.
split
(
"."
)[
0
]
return
theFileName
if
__name__
==
"__main__"
:
print
(
getDirFiles
(
"../../data/protocolTools/GPSLines"
))
print
(
getMaxPrefixFile
(
"../../data/protocolTools/GPSLines"
))
print
(
getMaxPrefixFilePre
(
"../../data/protocolTools/GPSLines"
))
print
(
getDirFilesNoPrefix
(
"../../data/protocolTools/GPSLines"
))
print
(
getDirFilesListMap
(
"../../data/protocolTools/GPSLines"
))
templates/messageTools/message/location_msg_page.html
View file @
4ccba252
...
...
@@ -1155,7 +1155,7 @@ function getbaseInfo_001D(){
return
data
;
}
//获取附加信息E
A
//获取附加信息E
B
function
getExtra_EB
(){
var
data
=
{};
var
engineSpeed
=
$
(
"
#engineSpeed
"
).
val
();
...
...
@@ -1214,6 +1214,172 @@ function getExtra_EB(){
return
data
;
}
//获取附加信息FA
function
getExtra_FA
(){
var
data
=
{};
if
(
$
(
"
#ignition
"
).
is
(
'
:checked
'
)){
var
ignition
=
$
(
"
#ignition
"
).
val
();
data
[
"
ignition
"
]
=
ignition
;
}
if
(
$
(
"
#flameout
"
).
is
(
'
:checked
'
)){
var
flameout
=
$
(
"
#flameout
"
).
val
();
data
[
"
flameout
"
]
=
flameout
;
}
if
(
$
(
"
#setUpDefences
"
).
is
(
'
:checked
'
)){
var
setUpDefences
=
$
(
"
#setUpDefences
"
).
val
();
data
[
"
setUpDefences
"
]
=
setUpDefences
;
}
if
(
$
(
"
#withdrawGarrision
"
).
is
(
'
:checked
'
)){
var
withdrawGarrision
=
$
(
"
#withdrawGarrision
"
).
val
();
data
[
"
withdrawGarrision
"
]
=
withdrawGarrision
;
}
if
(
$
(
"
#doorOpen
"
).
is
(
'
:checked
'
)){
var
doorOpen
=
$
(
"
#doorOpen
"
).
val
();
data
[
"
doorOpen
"
]
=
doorOpen
;
}
if
(
$
(
"
#doorClose
"
).
is
(
'
:checked
'
)){
var
doorClose
=
$
(
"
#doorClose
"
).
val
();
data
[
"
doorClose
"
]
=
doorClose
;
}
if
(
$
(
"
#systemStart
"
).
is
(
'
:checked
'
)){
var
systemStart
=
$
(
"
#systemStart
"
).
val
();
data
[
"
systemStart
"
]
=
systemStart
;
}
if
(
$
(
"
#trailCarAlarm
"
).
is
(
'
:checked
'
)){
var
trailCarAlarm
=
$
(
"
#trailCarAlarm
"
).
val
();
data
[
"
trailCarAlarm
"
]
=
trailCarAlarm
;
}
if
(
$
(
"
#locationTooLong
"
).
is
(
'
:checked
'
)){
var
locationTooLong
=
$
(
"
#locationTooLong
"
).
val
();
data
[
"
locationTooLong
"
]
=
locationTooLong
;
}
if
(
$
(
"
#terminalPullOut
"
).
is
(
'
:checked
'
)){
var
terminalPullOut
=
$
(
"
#terminalPullOut
"
).
val
();
data
[
"
terminalPullOut
"
]
=
terminalPullOut
;
}
if
(
$
(
"
#terminalInsert
"
).
is
(
'
:checked
'
)){
var
terminalInsert
=
$
(
"
#terminalInsert
"
).
val
();
data
[
"
terminalInsert
"
]
=
terminalInsert
;
}
if
(
$
(
"
#lowVoltage
"
).
is
(
'
:checked
'
)){
var
lowVoltage
=
$
(
"
#lowVoltage
"
).
val
();
data
[
"
lowVoltage
"
]
=
lowVoltage
;
}
if
(
$
(
"
#idlingSpeedOver
"
).
is
(
'
:checked
'
)){
var
idlingSpeedOver
=
getIdlingSpeedOver
();
//方法获取
data
[
"
idlingSpeedOver
"
]
=
idlingSpeedOver
;
}
if
(
$
(
"
#overspeedAlarm_AE
"
).
is
(
'
:checked
'
)){
var
overspeedAlarm
=
getOverspeedAlarm
()
data
[
"
overspeedAlarm
"
]
=
overspeedAlarm
;
}
if
(
$
(
"
#fatigueDriving_AE
"
).
is
(
'
:checked
'
)){
var
fatigueDriving
=
getFatigueDriving
();
data
[
"
fatigueDriving
"
]
=
fatigueDriving
;
}
if
(
$
(
"
#waterTemperatureAlarm_AE
"
).
is
(
'
:checked
'
)){
var
waterTemperatureAlarm
=
getWaterTemperatureAlarm
();
data
[
"
waterTemperatureAlarm
"
]
=
waterTemperatureAlarm
;
}
if
(
$
(
"
#highSpeedNeutralGear
"
).
is
(
'
:checked
'
)){
var
highSpeedNeutralGear
=
$
(
"
#highSpeedNeutralGear
"
).
val
();
data
[
"
highSpeedNeutralGear
"
]
=
highSpeedNeutralGear
;
}
if
(
$
(
"
#oilExpendNotSurport
"
).
is
(
'
:checked
'
)){
var
oilExpendNotSurport
=
$
(
"
#oilExpendNotSurport
"
).
val
();
data
[
"
oilExpendNotSurport
"
]
=
oilExpendNotSurport
;
}
if
(
$
(
"
#OBDNotSurport
"
).
is
(
'
:checked
'
)){
var
OBDNotSurport
=
$
(
"
#OBDNotSurport
"
).
val
();
data
[
"
OBDNotSurport
"
]
=
OBDNotSurport
;
}
if
(
$
(
"
#lowWaterTemperatureHighSpeed
"
).
is
(
'
:checked
'
)){
var
lowWaterTemperatureHighSpeed
=
$
(
"
#lowWaterTemperatureHighSpeed
"
).
val
();
data
[
"
lowWaterTemperatureHighSpeed
"
]
=
lowWaterTemperatureHighSpeed
;
}
if
(
$
(
"
#buslineNotSleep
"
).
is
(
'
:checked
'
)){
var
buslineNotSleep
=
$
(
"
#buslineNotSleep
"
).
val
();
data
[
"
buslineNotSleep
"
]
=
buslineNotSleep
;
}
if
(
$
(
"
#buslineNotSleep
"
).
is
(
'
:checked
'
)){
var
illegalOpenDoor
=
$
(
"
#illegalOpenDoor
"
).
val
();
data
[
"
illegalOpenDoor
"
]
=
illegalOpenDoor
;
}
if
(
$
(
"
#illegalFire
"
).
is
(
'
:checked
'
)){
var
illegalFire
=
$
(
"
#illegalFire
"
).
val
();
data
[
"
illegalFire
"
]
=
illegalFire
;
}
if
(
$
(
"
#rapidAccelerateAlarm
"
).
is
(
'
:checked
'
)){
var
rapidAccelerateAlarm
=
$
(
"
#rapidAccelerateAlarm
"
).
val
();
data
[
"
rapidAccelerateAlarm
"
]
=
rapidAccelerateAlarm
;
}
if
(
$
(
"
#sharpSlowdownAlarm
"
).
is
(
'
:checked
'
)){
var
sharpSlowdownAlarm
=
$
(
"
#sharpSlowdownAlarm
"
).
val
();
data
[
"
sharpSlowdownAlarm
"
]
=
sharpSlowdownAlarm
;
}
if
(
$
(
"
#sharpBendAlarm
"
).
is
(
'
:checked
'
)){
var
sharpBendAlarm
=
$
(
"
#sharpBendAlarm
"
).
val
();
data
[
"
sharpBendAlarm
"
]
=
sharpBendAlarm
;
}
if
(
$
(
"
#crashAlarm
"
).
is
(
'
:checked
'
)){
var
crashAlarm
=
$
(
"
#crashAlarm
"
).
val
();
data
[
"
crashAlarm
"
]
=
crashAlarm
;
}
if
(
$
(
"
#rapidChangeLines
"
).
is
(
'
:checked
'
)){
var
rapidChangeLines
=
$
(
"
#rapidChangeLines
"
).
val
();
data
[
"
rapidChangeLines
"
]
=
rapidChangeLines
;
}
return
data
;
}
function
getIdlingSpeedOver
(){
//获取怠速过长附带信息
idlingSpeedOver
=
{}
var
alarmType
=
$
(
"
#alarmType
"
).
val
();
var
idlingTimeOfDuration
=
$
(
"
#idlingTimeOfDuration
"
).
val
();
var
idlingOilExpend
=
$
(
"
#idlingOilExpend
"
).
val
();
var
idlingEngineMaxSpeed
=
$
(
"
#idlingEngineMaxSpeed
"
).
val
();
var
idlingEngineMinSpeed
=
$
(
"
#idlingEngineMinSpeed
"
).
val
();
idlingSpeedOver
[
"
alarmType
"
]
=
alarmType
;
idlingSpeedOver
[
"
idlingTimeOfDuration
"
]
=
idlingTimeOfDuration
;
idlingSpeedOver
[
"
idlingOilExpend
"
]
=
idlingOilExpend
;
idlingSpeedOver
[
"
idlingEngineMaxSpeed
"
]
=
idlingEngineMaxSpeed
;
idlingSpeedOver
[
"
idlingEngineMinSpeed
"
]
=
idlingEngineMinSpeed
;
return
idlingSpeedOver
}
function
getOverspeedAlarm
(){
//获取超速报警信息
overspeedAlarm
=
{}
var
alarmType
=
$
(
"
#alarmType_cs
"
).
val
();
var
overspeedTimeOfDuration
=
$
(
"
#overspeedTimeOfDuration
"
).
val
();
var
maxSpeed
=
$
(
"
#maxSpeed
"
).
val
();
var
averageSpeed
=
$
(
"
#averageSpeed
"
).
val
();
var
overspeedDistance
=
$
(
"
#overspeedDistance
"
).
val
();
overspeedAlarm
[
"
alarmType
"
]
=
alarmType
;
overspeedAlarm
[
"
overspeedTimeOfDuration
"
]
=
overspeedTimeOfDuration
;
overspeedAlarm
[
"
maxSpeed
"
]
=
maxSpeed
;
overspeedAlarm
[
"
averageSpeed
"
]
=
averageSpeed
;
overspeedAlarm
[
"
overspeedDistance
"
]
=
overspeedDistance
;
return
overspeedAlarm
}
function
getFatigueDriving
(){
//获取疲劳驾驶报警附带信息
fatigueDriving
=
{}
var
alarmType
=
$
(
"
#alarmType_pljs
"
).
val
();
var
totalContinueDrivingTime
=
$
(
"
#totalContinueDrivingTime
"
).
val
();
fatigueDriving
[
"
alarmType
"
]
=
alarmType
;
fatigueDriving
[
"
totalContinueDrivingTime
"
]
=
totalContinueDrivingTime
;
return
fatigueDriving
}
function
getWaterTemperatureAlarm
(){
//获取水温报警附带信息
fatigueDriving
=
{}
var
alarmType
=
$
(
"
#alarmType_sw
"
).
val
();
var
timeOfDuration
=
$
(
"
#timeOfDuration_sw
"
).
val
();
var
maxTemperature
=
$
(
"
#maxTemperature
"
).
val
();
var
averageTemperature
=
$
(
"
#averageTemperature
"
).
val
();
fatigueDriving
[
"
alarmType
"
]
=
alarmType
;
fatigueDriving
[
"
timeOfDuration
"
]
=
timeOfDuration
;
fatigueDriving
[
"
maxTemperature
"
]
=
maxTemperature
;
fatigueDriving
[
"
averageTemperature
"
]
=
averageTemperature
;
return
fatigueDriving
}
function
hasSubPkg
(){
var
value
=
$
(
"
#subPkg
"
).
val
()
if
(
value
==
"
8192
"
){
...
...
templates/protocolTools/report/M_carSimulater_page.html
View file @
4ccba252
...
...
@@ -38,7 +38,7 @@
{% block content_1 %}
<div
id=
"container3"
style=
"width:100%;min-height:750px;float:left;_background:green;margin-top:10px;_border-top: 1px solid #eee;"
>
<div
style=
"width:100%;padding-bottom:10px;border-bottom: 1px solid #eee;"
>
<span><label>
车机Id:
</label><input
id=
"carId"
type=
"text"
class=
"form-control"
value=
"M
121501010001
"
></span>
<span><label>
车机Id:
</label><input
id=
"carId"
type=
"text"
class=
"form-control"
value=
"M
202003060520
"
></span>
<span><label>
消息流水号:
</label><input
id=
"WATER_CODE"
style=
"width:60px;"
type=
"text"
class=
"form-control"
value=
"1"
></span>
<span><label>
上报间隔(秒):
</label><input
id=
"durTime"
style=
"width:60px;"
type=
"text"
class=
"form-control"
value=
"5"
></span>
<span><label>
设置超时时间:
</label><input
style=
"width:80px;"
id=
"timeout"
type=
"text"
class=
"form-control"
value=
"36000"
></span>
...
...
@@ -53,7 +53,7 @@
<li
style=
"width:300px;"
><label
style=
"word-break:break-all;font-size:12px;"
>
SIM卡CCID号:
</label><input
style=
"width:200px;"
id=
"ccid"
type=
"text"
class=
"form-control"
value=
"CCID1122334455667788"
></li>
<li><label
style=
"word-break:break-all;font-size:10px;"
>
GSM模块IMEI码:
</label><input
id=
"imei"
type=
"text"
class=
"form-control"
value=
"IMEI12233445566"
></li>
</ul>
<h5><b>
版本报文数据:
</b></h5>
<ul
class=
"protocol_content"
style=
"padding:0px;"
>
<li
style=
"width:320px;"
><label
style=
"word-break:break-all;font-size:12px;"
>
车机版本信息:
</label><input
style=
"width:220px;"
id=
"verInfo"
type=
"text"
class=
"form-control"
value=
"M100AB01010.0000"
></li>
<li><label>
编译日期:
</label><input
id=
"compileDate"
type=
"text"
class=
"form-control"
value=
"2020-03-23"
></li>
...
...
@@ -61,13 +61,31 @@
</ul>
</div>
</div>
<div
style=
"display: block; width: 100%; border-width: 1px; border-style: solid; border-color: darkgray; border-radius: 10px; padding: 2px; margin-top: 5px;"
>
<h5><b>
GPS行驶轨迹设置:
</b></h5>
<div
class=
"input-group"
style=
"width:380px;padding-bottom:10px;margin-left:10px;display:inline;"
>
<form
id=
"form"
enctype=
"multipart/form-data"
>
<input
type=
"file"
id=
"fileAttach"
name=
"file"
class=
"form-control"
style=
"display:inline;width:250px;"
/>
<input
type=
"button"
onclick=
"uploadFile()"
value=
"上传"
class=
"form-control"
style=
"display:inline;width:80px;font-weight: bolder;"
/>
</form>
</div>
<span
style=
"margin-left:10px;"
><label>
选择轨迹:
</label><select
id=
"selectGPSLine"
class=
"form-control"
style=
"width:250px;"
>
{% for key,value in arg["gpsLines"].items() %}
<option
value=
"{{ key }}"
>
{{ value }}
</option>
{% endfor %}
</select></span>
<a
style=
"margin-left:10px;font-weight:bold;"
onclick=
"download_sample()"
>
下载示例轨迹
</a>
<!-- <label><input style="margin-left:30px;" type="checkbox" id="ignition" />轨迹管理</label>-->
<!-- <div style="display: block;margin:10px; width: 95%; border-width: 1px; border-style: solid; border-color: darkgray; border-radius: 10px; padding: 2px; margin-top: 5px;">-->
<!-- </div>-->
</div>
<div
style=
"width:100%;padding-bottom:10px;border-bottom: 1px solid #eee;"
>
<h3>
操作:
</h3>
<button
id=
"connect_B"
type=
"button"
class=
"btn btn-primary"
onclick=
"connect()"
>
1、连网
</button>
<button
id=
"fire_B"
type=
"button"
class=
"btn btn-primary"
onclick=
"login()"
>
2、登录
</button>
<button
id=
"login_B"
type=
"button"
class=
"btn btn-primary"
onclick=
"fire()"
>
3、点火
</button>
<button
id=
"run_B"
type=
"button"
class=
"btn btn-primary"
>
4、行驶
</button>
<button
id=
"stopRun_B"
type=
"button"
class=
"btn btn-primary"
>
5、停止行驶
</button>
<button
id=
"run_B"
type=
"button"
class=
"btn btn-primary"
onclick=
"startTravel()"
>
4、行驶
</button>
<button
id=
"stopRun_B"
type=
"button"
class=
"btn btn-primary"
onclick=
"stopTravel()"
>
5、停止行驶
</button>
<button
id=
"unFire_B"
type=
"button"
class=
"btn btn-primary"
onclick=
"unFire()"
>
6、熄火
</button>
<button
id=
"unConnect_B"
type=
"button"
class=
"btn btn-primary"
onclick=
"stopConnect()"
>
7、断网
</button>
<button
id=
"unConnectAll_B"
type=
"button"
class=
"btn btn-danger"
onclick=
"reset()"
>
复位
</button>
...
...
@@ -138,14 +156,30 @@ function fire(){
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/fire
"
;
send
(
data
,
url
);
$
(
"
#curStatus
"
).
val
(
"
点火
"
)
}
//行驶
function
startTravel
(){
var
data
=
{};
url
=
"
/protocolTools/M_carSimulater_process/startTravel
"
;
send
(
data
,
url
);
$
(
"
#curStatus
"
).
val
(
"
行驶
"
)
}
//停止行驶
function
stopTravel
(){
var
data
=
{};
url
=
"
/protocolTools/M_carSimulater_process/stopTravel
"
;
send
(
data
,
url
);
$
(
"
#curStatus
"
).
val
(
"
点火
"
)
}
//熄火
function
unFire
(){
var
data
=
{};
...
...
@@ -298,6 +332,38 @@ function myclose(){
console
.
log
(
"
执行了socket服务的关闭操作...
"
);
}
///////////////////////////////// websocket 代码结束 /////////////////////////////////
function
uploadFile
(){
var
form
=
new
FormData
(
document
.
getElementById
(
"
form
"
));
var
host
=
window
.
location
.
host
;
$
.
ajax
({
url
:
"
http://
"
+
host
+
"
/protocolTools/M_carSimulater_process/fileUplad
"
,
type
:
"
post
"
,
data
:
form
,
cache
:
false
,
processData
:
false
,
contentType
:
false
,
success
:
function
(
data
){
//提交成功
if
(
data
.
status
==
"
200
"
)
{
$
(
"
#fileAttach
"
).
val
(
""
)
$
(
"
#selectGPSLine
"
).
prepend
(
"
<option value=
"
+
data
.
file
.
filenameOri
+
"
>
"
+
data
.
file
.
filename
+
"
</option>
"
)
alert
(
"
sucess
"
)
}
else
{
alert
(
"
fail
"
)
}
},
error
:
function
(
data
){
var
result
=
document
.
getElementById
(
"
Result
"
);
result
.
innerHTML
=
"
服务器错误
"
;
}
});
}
function
download_sample
(){
var
host
=
window
.
location
.
host
;
window
.
location
.
href
=
"
http://
"
+
host
+
"
/protocolTools/M_carSimulater_process/sampleDowload
"
}
</script>
{% endblock %}
</div>
...
...
views/protocolTools/M_carSimulater_process.py
View file @
4ccba252
#coding:utf-8
from
time
import
sleep
from
flask
import
Blueprint
,
Response
,
request
from
flask
import
Blueprint
,
Response
,
request
,
send_from_directory
from
configparser
import
ConfigParser
from
lib.protocol.report.LoginReport_protocol
import
LoginReport_protocol
from
lib.protocol.report.VersionReport_protocol
import
VersionReport_protocol
from
lib.socket.ClientSocket
import
ClientSocket
import
json
import
traceback
from
lib.socket.service.ProtocolSimulaterService
import
ProtocolSimulaterService
from
lib.util
import
fileUtil
M_carSimulater_process
=
Blueprint
(
'M_carSimulater_process'
,
__name__
)
...
...
@@ -95,6 +95,7 @@ def login():
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"
])
loginMsg
=
loginObj
.
generateLoginMsg
()
...
...
@@ -119,10 +120,13 @@ def login():
@
M_carSimulater_process
.
route
(
"/fire"
,
methods
=
[
'POST'
])
def
fire
():
durTime
=
int
(
request
.
form
.
get
(
"durTime"
))
gpsLine
=
request
.
form
.
get
(
"gpsLine"
)
data
=
{}
try
:
service
=
connects
[
0
][
"service"
]
service
.
setSendDur
(
durTime
)
#设置车机多久循环发送一次消息
service
.
setGpsLine
(
gpsLine
)
service
.
fireOn
()
service
.
startService
()
connects
[
0
][
"service"
]
=
service
data
[
"status"
]
=
"200"
...
...
@@ -134,6 +138,42 @@ def fire():
data
[
"message"
]
=
"Error: 点火失败!"
return
Response
(
json
.
dumps
(
data
),
mimetype
=
'application/json'
)
##########################################
# 【接口类型】行驶
##########################################
@
M_carSimulater_process
.
route
(
"/startTravel"
,
methods
=
[
'POST'
])
def
startTravel
():
data
=
{}
try
:
service
=
connects
[
0
][
"service"
]
service
.
startTravel
()
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'
)
##########################################
# 【接口类型】停止行驶
##########################################
@
M_carSimulater_process
.
route
(
"/stopTravel"
,
methods
=
[
'POST'
])
def
stopTravel
():
data
=
{}
try
:
service
=
connects
[
0
][
"service"
]
service
.
stopTravel
()
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'
)
##########################################
# 【接口类型】熄火
##########################################
...
...
@@ -141,6 +181,7 @@ def fire():
def
unFire
():
data
=
{}
try
:
connects
[
0
][
"service"
]
.
fireOff
()
connects
[
0
][
"service"
]
.
stopService
()
data
[
"status"
]
=
"200"
data
[
"message"
]
=
"熄火成功!"
...
...
@@ -163,6 +204,7 @@ def closeConect():
data
[
"message"
]
=
"没有可关闭的连接!"
else
:
connects
[
0
][
"service"
]
.
stopWebsocketService
()
connects
[
0
][
"service"
]
.
stopService
()
connects
[
0
][
"service"
]
.
closeSocket
()
connects
.
pop
(
0
)
data
[
"status"
]
=
"200"
...
...
@@ -194,3 +236,49 @@ def reset():
data
[
"status"
]
=
"4003"
data
[
"message"
]
=
"Error: 复位失败!"
return
Response
(
json
.
dumps
(
data
),
mimetype
=
'application/json'
)
##########################################
# 【接口类型】文件上传操作
##########################################
@
M_carSimulater_process
.
route
(
"/fileUplad"
,
methods
=
[
'POST'
])
def
fileUplad
():
# 获取前端传输的文件(对象)
f
=
request
.
files
.
get
(
'file'
)
file_content
=
f
.
read
()
try
:
file_content
=
file_content
.
decode
(
"utf-8"
)
except
BaseException
as
e
:
pass
try
:
file_content
=
file_content
.
decode
(
"gbk"
)
except
BaseException
as
e
:
pass
maxPrefix
=
int
(
fileUtil
.
getMaxPrefixFilePre
(
"data/protocolTools/GPSLines"
))
filenameOrg
=
f
.
filename
filename
=
str
(
maxPrefix
+
1
)
+
"_"
+
filenameOrg
fileData
=
{}
fileData
[
"filename"
]
=
fileUtil
.
removeSuffix
(
filenameOrg
)
fileData
[
"filenameOri"
]
=
filename
# 验证文件格式(简单设定几个格式)
types
=
[
'json'
,
'txt'
]
data
=
{}
if
filename
.
split
(
'.'
)[
-
1
]
in
types
:
# 保存图片
with
open
(
"data/protocolTools/GPSLines/"
+
filename
,
"w"
,
encoding
=
"utf-8"
)
as
fi
:
fi
.
write
(
file_content
)
# 返回给前端结果
data
[
"status"
]
=
"200"
data
[
"message"
]
=
"文件上传成功"
data
[
"file"
]
=
fileData
else
:
data
[
"status"
]
=
"4003"
data
[
"message"
]
=
"文件上传失败"
return
Response
(
json
.
dumps
(
data
),
mimetype
=
'application/json'
)
@
M_carSimulater_process
.
route
(
"/sampleDowload"
)
def
sampleDowload
():
return
send_from_directory
(
r"data/protocolTools/GPSLines"
,
filename
=
"1_sample.json"
,
as_attachment
=
True
)
views/protocolTools/M_carSimulater_view.py
View file @
4ccba252
...
...
@@ -3,6 +3,7 @@ from configparser import ConfigParser
from
flask
import
Blueprint
,
render_template
,
request
import
re
from
lib.util
import
fileUtil
M_carSimulater_view
=
Blueprint
(
'M_carSimulater_view'
,
__name__
)
...
...
@@ -18,6 +19,7 @@ def M_carSimulater_page():
arg
=
{}
path
=
"protocolTools/report/M_carSimulater_page.html"
arg
[
"path"
]
=
reqPath
.
split
(
"/"
)
arg
[
"gpsLines"
]
=
fileUtil
.
getDirFilesListMap
(
"data/protocolTools/GPSLines"
)
return
render_template
(
path
,
arg
=
arg
)
##########################################
...
...
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