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
405993b9
Commit
405993b9
authored
Mar 23, 2020
by
liyuanhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
初步开发模拟器页面
parent
7dbe43dc
Changes
37
Hide whitespace changes
Inline
Side-by-side
Showing
37 changed files
with
701 additions
and
88 deletions
+701
-88
config/protocolTools/carSimulater.conf
config/protocolTools/carSimulater.conf
+4
-0
data/testData.txt
data/testData.txt
+0
-1
lib/protocol/appendix/EventClass.py
lib/protocol/appendix/EventClass.py
+1
-1
lib/protocol/m300/__init__.py
lib/protocol/m300/__init__.py
+0
-0
lib/protocol/m300Plateform/__init__.py
lib/protocol/m300Plateform/__init__.py
+0
-0
lib/protocol/report/BaseStationReport_protocol.py
lib/protocol/report/BaseStationReport_protocol.py
+1
-3
lib/protocol/report/EventReport_protocol.py
lib/protocol/report/EventReport_protocol.py
+1
-3
lib/protocol/report/GPSReport_protocol.py
lib/protocol/report/GPSReport_protocol.py
+1
-22
lib/protocol/report/HeartBeatReport_protocol.py
lib/protocol/report/HeartBeatReport_protocol.py
+1
-3
lib/protocol/report/LoginReport_protocol.py
lib/protocol/report/LoginReport_protocol.py
+2
-4
lib/protocol/report/OBDReport_CAN_protocol.py
lib/protocol/report/OBDReport_CAN_protocol.py
+4
-8
lib/protocol/report/OBDReport_protocol.py
lib/protocol/report/OBDReport_protocol.py
+1
-2
lib/protocol/report/ProtocolBase.py
lib/protocol/report/ProtocolBase.py
+0
-0
lib/protocol/report/SecurityStatusReport_protocol.py
lib/protocol/report/SecurityStatusReport_protocol.py
+1
-3
lib/protocol/report/SleepReport_protocol.py
lib/protocol/report/SleepReport_protocol.py
+60
-0
lib/protocol/report/TroubleReport_protocol.py
lib/protocol/report/TroubleReport_protocol.py
+1
-1
lib/protocol/report/VersionReport_protocol.py
lib/protocol/report/VersionReport_protocol.py
+63
-0
lib/protocol/reportPlateform/Common_res.py
lib/protocol/reportPlateform/Common_res.py
+63
-0
lib/protocol/reportPlateform/Login_res.py
lib/protocol/reportPlateform/Login_res.py
+63
-0
lib/protocol/reportPlateform/ResponseBase.py
lib/protocol/reportPlateform/ResponseBase.py
+90
-0
lib/socket/ClientSocket.py
lib/socket/ClientSocket.py
+6
-3
lib/socket/MyWebsocket_server.py
lib/socket/MyWebsocket_server.py
+1
-1
lib/socket/protocolTest_M500.py
lib/socket/protocolTest_M500.py
+13
-9
run.py
run.py
+4
-0
static/js/protocolTools/carsimulater.js
static/js/protocolTools/carsimulater.js
+14
-0
templates/base.html
templates/base.html
+1
-0
templates/protocolTools/index.html
templates/protocolTools/index.html
+3
-1
templates/protocolTools/report/GPS_protocol_page.html
templates/protocolTools/report/GPS_protocol_page.html
+36
-14
templates/protocolTools/report/M_carSimulater_page.html
templates/protocolTools/report/M_carSimulater_page.html
+66
-0
templates/protocolTools/report/M_setting_page.html
templates/protocolTools/report/M_setting_page.html
+42
-0
templates/protocolTools/report/OBD_CAN_protocol_page.html
templates/protocolTools/report/OBD_CAN_protocol_page.html
+1
-1
templates/protocolTools/report/heartBeat_protocol_page.html
templates/protocolTools/report/heartBeat_protocol_page.html
+1
-1
templates/protocolTools/report/login_protocol_page.html
templates/protocolTools/report/login_protocol_page.html
+1
-1
templates/protocolTools/report/securityStatus_protocol_page.html
...es/protocolTools/report/securityStatus_protocol_page.html
+1
-1
views/protocolTools/M_carSimulater_process.py
views/protocolTools/M_carSimulater_process.py
+106
-0
views/protocolTools/M_carSimulater_view.py
views/protocolTools/M_carSimulater_view.py
+41
-0
views/protocolTools/protocolReport_process.py
views/protocolTools/protocolReport_process.py
+7
-5
No files found.
config/protocolTools/carSimulater.conf
0 → 100644
View file @
405993b9
[
socket
]
host
=
10
.
100
.
12
.
32
port
=
9008
data/testData.txt
deleted
100644 → 0
View file @
7dbe43dc
这是一个测试数据文件
\ No newline at end of file
lib/protocol/appendix/EventClass.py
View file @
405993b9
#coding:utf-8
import
datetime
from
lib.protocol.ProtocolBase
import
ProtocolBase
from
lib.protocol.
report.
ProtocolBase
import
ProtocolBase
from
lib.protocol.report.GPSReport_protocol
import
GPSReport_protocol
from
lib.protocol.report.SecurityStatusReport_protocol
import
SecurityStatusReport_protocol
...
...
templates
/__init__.py
→
lib/protocol/m300
/__init__.py
View file @
405993b9
File moved
lib/protocol/m300Plateform/__init__.py
0 → 100644
View file @
405993b9
lib/protocol/report/BaseStationReport_protocol.py
View file @
405993b9
...
...
@@ -3,10 +3,8 @@
'''
定义一个终端上报基站定位数据包协议的类
'''
import
datetime
import
time
from
lib.protocol.ProtocolBase
import
ProtocolBase
from
lib.protocol.
report.
ProtocolBase
import
ProtocolBase
class
BaseStationReport_protocol
(
ProtocolBase
):
def
__init__
(
self
,
msgCount
=
1
,
WATER_CODE
=
"0002"
,
DEV_ID
=
"M121501010001"
,
infoTime
=
"2020-01-20 10:12:05"
,
operators
=
2
,
serverLAC
=
2020
,
serverCellID
=
2022
,
N1LAC
=
2024
,
N1CellID
=
2026
,
N2LAC
=
2028
,
N2CellID
=
20202
,
N3LAC
=
20204
,
N3CellID
=
20206
,
N4LAC
=
20208
,
N4CellID
=
20220
,
N5LAC
=
20222
,
N5CellID
=
20224
,
N6LAC
=
20226
,
N6CellID
=
20228
,
voltage
=
3.6
,
speed
=
60.6
,
engineSpeed
=
2000
,
totalMileage
=
500005
,
totalOilExpend
=
600006
,
totalRunTime
=
60001
,
statusBit
=
1
):
...
...
lib/protocol/report/EventReport_protocol.py
View file @
405993b9
#coding:utf-8
import
datetime
from
lib.protocol.ProtocolBase
import
ProtocolBase
from
lib.protocol.
report.
ProtocolBase
import
ProtocolBase
from
lib.protocol.appendix.EventClass
import
EventClass
from
lib.protocol.report.SecurityStatusReport_protocol
import
SecurityStatusReport_protocol
'''
终端上事件数据包
...
...
lib/protocol/report/GPSReport_protocol.py
View file @
405993b9
...
...
@@ -3,11 +3,9 @@
'''
定义一个GPS协议的类
'''
import
datetime
import
time
from
lib.util
import
dataUtil
from
lib.protocol.ProtocolBase
import
ProtocolBase
from
lib.protocol.
report.
ProtocolBase
import
ProtocolBase
'''
终端上报GPS定位数据包
...
...
@@ -171,16 +169,6 @@ class GPSReport_protocol(ProtocolBase):
hexStr
=
"0"
+
hexStr
return
hexStr
#####################################################
# 设备id转换为16进制字符串
#####################################################
# def devid2hexString(self,id):
# #获取第一个字符的ASCII值
# ascii = ord(id[0:1])
# #将10进制的ASCII值转换为16进制
# ascii = self.int2hexString(int(ascii))
# devid = str(ascii) + id[1:]
# return devid
#####################################################
# 获取消息体长度
...
...
@@ -191,15 +179,6 @@ class GPSReport_protocol(ProtocolBase):
hexData
=
"0"
+
hexData
return
hexData
#####################################################
# 获取流水号
#####################################################
# def getWaterCode(self,num):
# hexData = self.int2hexString(num)
# while len(hexData) < 4:
# hexData = "0" + hexData
# return hexData
#####################################################
# 获取功能id
#####################################################
...
...
lib/protocol/report/HeartBeatReport_protocol.py
View file @
405993b9
...
...
@@ -3,10 +3,8 @@
'''
定义一个心跳协议的类
'''
import
datetime
import
time
from
lib.protocol.ProtocolBase
import
ProtocolBase
from
lib.protocol.
report.
ProtocolBase
import
ProtocolBase
'''
终端心跳协议数据包
...
...
lib/protocol/report/LoginReport_protocol.py
View file @
405993b9
...
...
@@ -3,10 +3,8 @@
'''
定义一个终端登录协议的类
'''
import
datetime
import
time
from
lib.protocol.ProtocolBase
import
ProtocolBase
from
lib.protocol.
report.
ProtocolBase
import
ProtocolBase
class
LoginReport_protocol
(
ProtocolBase
):
def
__init__
(
self
,
WATER_CODE
=
"0002"
,
DEV_ID
=
"M121501010001"
,
cpuId
=
"CPU-ID001122334455667788"
,
imsi
=
"IMSI13145678902"
,
ccid
=
"CCID1122334455667788"
,
imei
=
"IMEI12233445566"
):
...
...
@@ -29,7 +27,7 @@ class LoginReport_protocol(ProtocolBase):
HEADER
=
"4040"
# 消息头
WATER_CODE
=
self
.
getWaterCode
(
self
.
WATER_CODE
)
# 消息流水号
DEV_ID
=
self
.
devid2hexString
(
self
.
DEV_ID
)
# 设备id
FUN_ID
=
"000
3
"
# 功能id(终端登录功能id)
FUN_ID
=
"000
2
"
# 功能id(终端登录功能id)
data
=
self
.
generateLoginData
()
# 数据段
...
...
lib/protocol/report/OBDReport_CAN_protocol.py
View file @
405993b9
...
...
@@ -3,10 +3,8 @@
'''
定义一个OBD终端上报CAN静态数据类
'''
import
datetime
import
time
from
lib.protocol.ProtocolBase
import
ProtocolBase
from
lib.protocol.
report.
ProtocolBase
import
ProtocolBase
class
OBDReport_CAN_protocol
(
ProtocolBase
):
...
...
@@ -183,7 +181,6 @@ class OBDReport_CAN_protocol(ProtocolBase):
B1S2oxygenSensorVoltage
=
self
.
getB1S2OxygenSensorVoltageHex
(
self
.
B1S2oxygenSensorVoltage
)
#B1-S1氧传感器输出电流
B1S1oxygenSensorElectricity
=
self
.
B1S1oxygenSensorElectricityHex
(
self
.
B1S1oxygenSensorElectricity
)
print
(
self
.
B1S2oxygenSensorElectricity
)
# B1-S2氧传感器输出电流
B1S2oxygenSensorElectricity
=
self
.
B1S2oxygenSensorElectricityHex
(
self
.
B1S2oxygenSensorElectricity
)
#瞬时油耗
...
...
@@ -376,9 +373,7 @@ class OBDReport_CAN_protocol(ProtocolBase):
# 获取仪表里程值的16进制数据
#####################################################
def
getMeterMileageHex
(
self
,
num
):
totalMeterStr
=
str
(
num
)
totalMeterStrHex
=
hex
(
int
(
totalMeterStr
))
totalMeterStrHex
=
self
.
leftPad
(
str
(
totalMeterStrHex
)[
2
:],
8
)
totalMeterStrHex
=
self
.
int2hexStringByBytes
(
num
,
4
)
return
totalMeterStrHex
####################################################
...
...
@@ -428,10 +423,11 @@ class OBDReport_CAN_protocol(ProtocolBase):
# 显示值为上报值 / 10
#####################################################
def
getSurplusOilHex
(
self
,
num
):
print
(
num
)
hexData
=
self
.
int2hexString
(
num
)
while
len
(
hexData
)
<
4
:
hexData
=
"0"
+
hexData
# hexData = "0" + hexData #bit15 == 0 百分比 % OBD都为百分比
print
(
hexData
)
return
hexData
####################################################
...
...
lib/protocol/report/OBDReport_protocol.py
View file @
405993b9
...
...
@@ -3,9 +3,8 @@
'''
定义一个终端上报OBD适配信息
'''
import
datetime
from
lib.protocol.ProtocolBase
import
ProtocolBase
from
lib.protocol.
report.
ProtocolBase
import
ProtocolBase
class
OBDReport_protocol
(
ProtocolBase
):
...
...
lib/protocol/ProtocolBase.py
→
lib/protocol/
report/
ProtocolBase.py
View file @
405993b9
File moved
lib/protocol/report/SecurityStatusReport_protocol.py
View file @
405993b9
...
...
@@ -3,10 +3,8 @@
'''
定义一个终端安防状态上报协议的类
'''
import
datetime
import
time
from
lib.protocol.ProtocolBase
import
ProtocolBase
from
lib.protocol.
report.
ProtocolBase
import
ProtocolBase
class
SecurityStatusReport_protocol
(
ProtocolBase
):
...
...
lib/protocol/report/SleepReport_protocol.py
0 → 100644
View file @
405993b9
#coding:utf-8
'''
定义一个终端休眠协议的类
'''
from
lib.protocol.report.ProtocolBase
import
ProtocolBase
class
SleepReport_protocol
(
ProtocolBase
):
def
__init__
(
self
,
msgCount
=
1
,
WATER_CODE
=
1000
,
DEV_ID
=
"M121501010001"
,
verInfo
=
"M100AB01010.0000"
,
compileDate
=
"2020-03-23"
,
GSM
=
"GSM_123456"
,
sleepType
=
"01"
,
sleepStatus
=
0
):
super
()
.
__init__
()
self
.
msgCount
=
int
(
msgCount
)
# 设置默认要发送的GPS数据包个数
self
.
WATER_CODE
=
int
(
WATER_CODE
);
# 设置默认消息流水号
self
.
DEV_ID
=
DEV_ID
# 设置默认设备id
self
.
sleepType
=
sleepType
#休眠类型
self
.
sleepStatus
=
sleepStatus
#休眠状态
#####################################################
# 生成 版本上报 消息
#####################################################
def
generateSleepMsg
(
self
):
self
.
getProtocalHeader
()
info
=
""
HEADER
=
"4040"
#消息头
WATER_CODE
=
self
.
getWaterCode
(
self
.
WATER_CODE
)
#消息流水号
DEV_ID
=
self
.
devid2hexString
(
self
.
DEV_ID
)
#设备id
FUN_ID
=
"0005"
# 功能id
data
=
""
#数据段
for
i
in
range
(
0
,
self
.
msgCount
):
data
+=
self
.
generateSleepPkg
(
self
.
generateSleepData
())
LENGTH
=
self
.
getMsgLength
(
int
(
len
(
WATER_CODE
+
DEV_ID
+
FUN_ID
+
data
)
/
2
))
# 消息长度
info
+=
HEADER
info
+=
LENGTH
info
+=
WATER_CODE
info
+=
DEV_ID
info
+=
FUN_ID
info
+=
data
CHECK_CODE
=
self
.
getCheckCode
(
info
)
# 校验字段
info
+=
CHECK_CODE
return
info
#####################################################
# 创建 版本信息 数据包,包含包个数
#####################################################
def
generateSleepPkg
(
self
,
data
):
return
data
#####################################################
# 创建 版本信息 数据段
#####################################################
def
generateSleepData
(
self
):
sleepTypeHex
=
self
.
sleepType
sleepStatusHex
=
self
.
int2hexString
(
self
.
sleepStatus
)
data
=
sleepTypeHex
+
sleepStatusHex
return
data
if
__name__
==
"__main__"
:
print
(
SleepReport_protocol
()
.
generateSleepMsg
())
\ No newline at end of file
lib/protocol/report/TroubleReport_protocol.py
View file @
405993b9
#coding:utf-8
from
lib.protocol.ProtocolBase
import
ProtocolBase
from
lib.protocol.
report.
ProtocolBase
import
ProtocolBase
'''
终端上报故障码数据包
...
...
lib/protocol/report/VersionReport_protocol.py
0 → 100644
View file @
405993b9
#coding:utf-8
'''
定义一个终端版本协议的类
'''
from
lib.protocol.report.ProtocolBase
import
ProtocolBase
class
VersionReport_protocol
(
ProtocolBase
):
def
__init__
(
self
,
msgCount
=
1
,
WATER_CODE
=
1000
,
DEV_ID
=
"M121501010001"
,
verInfo
=
"M100AB01010.0000"
,
compileDate
=
"2020-03-23"
,
GSM
=
"GSM_123456"
):
super
()
.
__init__
()
self
.
msgCount
=
int
(
msgCount
)
# 设置默认要发送的GPS数据包个数
self
.
WATER_CODE
=
int
(
WATER_CODE
);
# 设置默认消息流水号
self
.
DEV_ID
=
DEV_ID
# 设置默认设备id
self
.
verInfo
=
verInfo
# 设置默认UTC时间度戳
self
.
compileDate
=
compileDate
#编译日期
self
.
GSM
=
GSM
#GSM模块型号
#####################################################
# 生成 版本上报 消息
#####################################################
def
generateVersionMsg
(
self
):
self
.
getProtocalHeader
()
info
=
""
HEADER
=
"4040"
#消息头
WATER_CODE
=
self
.
getWaterCode
(
self
.
WATER_CODE
)
#消息流水号
DEV_ID
=
self
.
devid2hexString
(
self
.
DEV_ID
)
#设备id
FUN_ID
=
"00FF"
# 功能id
data
=
""
#数据段
for
i
in
range
(
0
,
self
.
msgCount
):
data
+=
self
.
generateVersionPkg
(
self
.
generateVersionData
())
LENGTH
=
self
.
getMsgLength
(
int
(
len
(
WATER_CODE
+
DEV_ID
+
FUN_ID
+
data
)
/
2
))
# 消息长度
info
+=
HEADER
info
+=
LENGTH
info
+=
WATER_CODE
info
+=
DEV_ID
info
+=
FUN_ID
info
+=
data
CHECK_CODE
=
self
.
getCheckCode
(
info
)
# 校验字段
info
+=
CHECK_CODE
return
info
#####################################################
# 创建 版本信息 数据包,包含包个数
#####################################################
def
generateVersionPkg
(
self
,
data
):
return
data
#####################################################
# 创建 版本信息 数据段
#####################################################
def
generateVersionData
(
self
):
data
=
""
verInfoHex
=
self
.
str2Hex
(
self
.
verInfo
)
# 设置默认UTC时间度戳
compileDateHex
=
self
.
str2Hex
(
self
.
compileDate
)
#编译日期
GSMHex
=
self
.
str2Hex
(
self
.
GSM
)
#GSM模块型号
data
=
verInfoHex
+
compileDateHex
+
GSMHex
return
data
if
__name__
==
"__main__"
:
print
(
VersionReport_protocol
()
.
generateVersionMsg
())
\ No newline at end of file
lib/protocol/reportPlateform/Common_res.py
0 → 100644
View file @
405993b9
#encoding:utf-8
'''
定义通用应答消息解码类
'''
import
json
from
lib.protocol.reportPlateform.ResponseBase
import
ResponseBase
class
Common_res
(
ResponseBase
):
def
__init__
(
self
,
msg
):
super
()
.
__init__
()
if
type
(
msg
)
==
bytes
:
self
.
msg
=
self
.
binary2ascii
(
msg
)
else
:
self
.
msg
=
msg
pass
#######################################################
# 获取解析后的消息
#######################################################
def
getMsg
(
self
):
json_msg
=
{}
json_msg
[
"header"
]
=
self
.
msg
[
0
:
4
]
json_msg
[
"msgLen"
]
=
self
.
getMsgLen
()
json_msg
[
"waterCode"
]
=
self
.
hexString2int
(
self
.
msg
[
8
:
12
])
json_msg
[
"devId"
]
=
self
.
hex2string
(
self
.
msg
[
12
:
14
])
+
self
.
msg
[
14
:
26
]
json_msg
[
"funcId"
]
=
self
.
msg
[
26
:
30
]
json_msg
[
"body"
]
=
self
.
getMsgBody
()
json_msg
[
"checkCode"
]
=
self
.
msg
[
-
4
:]
json_msg
[
"calculateCheckCode"
]
=
self
.
getCalculateCheckCode
()
#自己计算消息后得到的校验码
json_msg
=
json
.
dumps
(
json_msg
)
return
json_msg
#######################################################
# 获取消息长度
#######################################################
def
getMsgLen
(
self
):
msgLenHex
=
self
.
msg
[
4
:
8
]
msgLen
=
self
.
hexString2int
(
msgLenHex
)
return
msgLen
#######################################################
# 获取消息体
#######################################################
def
getMsgBody
(
self
):
data
=
{}
msgbody
=
self
.
msg
[
30
:][:
-
4
]
data
[
"funcId"
]
=
msgbody
[:
4
]
data
[
"status"
]
=
msgbody
[
4
:]
return
data
#######################################################
# 获取自己计算得到的校验码
#######################################################
def
getCalculateCheckCode
(
self
):
checkCode
=
self
.
crc16
(
self
.
msg
[:
-
4
])
return
checkCode
if
__name__
==
"__main__"
:
print
(
Common_res
(
"4040000e000a4d12150101000180000010001550"
)
.
getMsg
())
lib/protocol/reportPlateform/Login_res.py
0 → 100644
View file @
405993b9
#encoding:utf-8
'''
定义终端登录应答消息解码类
'''
import
json
from
lib.protocol.reportPlateform.ResponseBase
import
ResponseBase
class
Login_res
(
ResponseBase
):
def
__init__
(
self
,
msg
):
super
()
.
__init__
()
if
type
(
msg
)
==
bytes
:
self
.
msg
=
self
.
binary2ascii
(
msg
)
else
:
self
.
msg
=
msg
pass
#######################################################
# 获取解析后的消息
#######################################################
def
getMsg
(
self
):
json_msg
=
{}
json_msg
[
"header"
]
=
self
.
msg
[
0
:
4
]
json_msg
[
"msgLen"
]
=
self
.
getMsgLen
()
json_msg
[
"waterCode"
]
=
self
.
hexString2int
(
self
.
msg
[
8
:
12
])
json_msg
[
"devId"
]
=
self
.
hex2string
(
self
.
msg
[
12
:
14
])
+
self
.
msg
[
14
:
26
]
json_msg
[
"funcId"
]
=
self
.
msg
[
26
:
30
]
json_msg
[
"body"
]
=
self
.
getMsgBody
()
json_msg
[
"checkCode"
]
=
self
.
msg
[
-
4
:]
json_msg
[
"calculateCheckCode"
]
=
self
.
getCalculateCheckCode
()
# 自己计算消息后得到的校验码
json_msg
=
json
.
dumps
(
json_msg
)
return
json_msg
#######################################################
# 获取消息长度
#######################################################
def
getMsgLen
(
self
):
msgLenHex
=
self
.
msg
[
4
:
8
]
msgLen
=
self
.
hexString2int
(
msgLenHex
)
return
msgLen
#######################################################
# 获取消息体
#######################################################
def
getMsgBody
(
self
):
data
=
{}
msgbody
=
self
.
msg
[
30
:][:
-
4
]
data
[
"data"
]
=
msgbody
return
data
#######################################################
# 获取自己计算得到的校验码
#######################################################
def
getCalculateCheckCode
(
self
):
checkCode
=
self
.
crc16
(
self
.
msg
[:
-
4
])
return
checkCode
if
__name__
==
"__main__"
:
print
(
Login_res
(
"4040000e00024d1215010100018000000300482a"
)
.
getMsg
())
lib/protocol/reportPlateform/ResponseBase.py
0 → 100644
View file @
405993b9
#encoding:utf-8
import
binascii
from
lib.protocol.Base
import
Base
class
ResponseBase
(
Base
):
def
__init__
(
self
):
pass
#####################################################
# 数字转换为16进制字符串
#####################################################
def
int2hexString
(
self
,
num
):
hexStr
=
hex
(
num
)[
2
:]
if
(
len
(
hexStr
)
%
2
)
==
1
:
hexStr
=
"0"
+
hexStr
return
hexStr
#####################################################
# 数字转换为16进制字符串,通过传入字节数可自动补0
# 传入数据格式所占字节数
#####################################################
def
int2hexStringByBytes
(
self
,
num
,
bytescount
=
1
):
hexStr
=
hex
(
num
)[
2
:]
while
len
(
hexStr
)
<
(
bytescount
*
2
):
hexStr
=
"0"
+
hexStr
return
hexStr
#######################################################
# 16进制字符串转换为整数
#######################################################
def
hexString2int
(
self
,
data
):
val
=
int
(
data
,
16
)
return
val
#######################################################
# 16进制字符串转换为ascii字符串
#######################################################
def
hex2string
(
self
,
data
):
theStr
=
""
while
data
!=
""
:
tmp
=
data
[:
2
]
data
=
data
[
2
:]
theStr
=
theStr
+
chr
(
int
(
tmp
,
16
))
return
theStr
####################################################
# 定义生成校验字段的函数
# inputStr:需要传入一个已经转换为16进制的字符串
#####################################################
# add crc 16 check at the end of the string
def
crc16
(
self
,
inputStr
):
inputStrByte
=
bytes
.
fromhex
(
inputStr
)
crc
=
0xFFFF
for
i
in
range
(
0
,
len
(
inputStrByte
)):
for
j
in
range
(
0
,
8
):
c15
=
(
crc
>>
15
)
==
1
bit
=
((
inputStrByte
[
i
]
>>
(
7
-
j
))
&
1
)
==
1
crc
<<=
1
crc
&=
0xFFFF
if
c15
^
bit
:
crc
^=
0x1021
crc
=
str
(
hex
(
crc
))
crc
=
self
.
leftPad
(
crc
[
2
:],
4
)
# outputStr = inputStr + crc
outputStr
=
crc
return
outputStr
# pad zero to the left of the string if not long enough
def
leftPad
(
self
,
inputStr
,
strLen
):
if
(
strLen
>
len
(
inputStr
)):
outputStr
=
"0000000000000000000000000000000000000000"
+
inputStr
outputStr
=
outputStr
[
len
(
outputStr
)
-
strLen
:]
return
outputStr
else
:
return
inputStr
# pad zero to the right of the string if not long enough
def
rightPad
(
self
,
inputStr
,
strLen
):
if
(
strLen
>
len
(
inputStr
)):
outputStr
=
inputStr
+
"0000000000000000000000000000000000000000"
outputStr
=
outputStr
[:
strLen
]
return
outputStr
else
:
return
inputStr
lib/socket/ClientSocket.py
View file @
405993b9
...
...
@@ -18,6 +18,7 @@ class ClientSocket(SocketBase):
self
.
socketId
=
''
.
join
(
random
.
sample
(
string
.
ascii_letters
+
string
.
digits
,
8
))
self
.
port
=
port
self
.
host
=
host
self
.
timeOut
=
1
#设置连接超时时间
# 0代表未连接 , 1代表socket处于连接状态
self
.
status
=
0
self
.
BUF_SIZE
=
1024
...
...
@@ -28,6 +29,8 @@ class ClientSocket(SocketBase):
def
connect
(
self
):
self
.
client
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
self
.
client
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_KEEPALIVE
,
1
)
# 在客户端开启心跳
# 设置连接socket的超时时间
self
.
client
.
settimeout
(
self
.
timeOut
)
self
.
client
.
connect
((
self
.
host
,
self
.
port
))
self
.
status
=
1
...
...
@@ -35,15 +38,15 @@ class ClientSocket(SocketBase):
# 发送消息
#####################################################
def
send
(
self
,
msg
):
#
self.client.send(msg.encode())
# client.send(bytes.fromhex(msg)
)
#
设置发送消息的超时时间
self
.
client
.
settimeout
(
self
.
timeOut
)
self
.
client
.
send
(
binascii
.
a2b_hex
(
msg
))
def
receive
(
self
):
data
=
""
try
:
# 设置接收消息的超时时间
self
.
client
.
settimeout
(
1
)
self
.
client
.
settimeout
(
self
.
timeOut
)
data
=
self
.
client
.
recv
(
self
.
BUF_SIZE
)
except
BaseException
as
e
:
# traceback.print_exc()
...
...
lib/socket/MyWebsocket_server.py
View file @
405993b9
...
...
@@ -33,7 +33,7 @@ class MyWebsocket_server(SocketBase):
def
mysend
(
self
,
client
,
server
,
msg
):
print
(
msg
)
self
.
msgTimeout
=
12
server
.
send_message
(
client
,
"
哈哈哈哈哈
"
)
server
.
send_message
(
client
,
"
message send ...
"
)
if
(
msg
==
"_end"
):
#收到_end 控制码的时候,断开连接
server
.
server_close
()
print
(
"连接断开..."
)
...
...
lib/socket/protocolTest_M500.py
View file @
405993b9
...
...
@@ -8,27 +8,31 @@ from lib.protocol.report.HeartBeatReport_protocol import HeartBeatReport_protoco
from
lib.protocol.report.LoginReport_protocol
import
LoginReport_protocol
from
lib.protocol.report.SecurityStatusReport_protocol
import
SecurityStatusReport_protocol
from
lib.protocol.report.BaseStationReport_protocol
import
BaseStationReport_protocol
from
lib.protocol.report.SleepReport_protocol
import
SleepReport_protocol
from
lib.protocol.report.TroubleReport_protocol
import
TroubleReport_protocol
from
lib.protocol.report.EventReport_protocol
import
EventReport_protocol
# host = "10.100.12.34"
# port = 8712
from
lib.protocol.report.VersionReport_protocol
import
VersionReport_protocol
# host = "10.100.12.32"
# port = 9008
host
=
"10.100.5.251"
host
=
"10.100.12.32"
port
=
9008
# msg = GPSReport_protocol().generateGpsMsg() #GPS消息数据
# msg = OBDReport_protocol().generateOBDReportMsg() #OBD终端上报数据
# msg = OBDReport_CAN_protocol().generateOBDReportCANMsg() #OBD终端上报CAN数据
msg
=
HeartBeatReport_protocol
()
.
generateHeartBeatMsg
()
#终端上报心跳协议
# msg = LoginReport_protocol().generateLoginMsg() #终端上报登录协议
# host = "10.100.5.251"
# port = 9008
# msg = GPSReport_protocol().generateGpsMsg() #GPS消息数据
# msg = OBDReport_protocol().generateOBDReportMsg() #OBD终端上报数据
# msg = OBDReport_CAN_protocol().generateOBDReportCANMsg() #OBD终端上报CAN数据
# 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 = VersionReport_protocol().generateVersionMsg() #终端上报版本信息数据包
msg
=
SleepReport_protocol
()
.
generateSleepMsg
()
print
(
msg
)
BUF_SIZE
=
1024
...
...
run.py
View file @
405993b9
...
...
@@ -4,6 +4,8 @@ from views.protocolTools.setting_view import setting_view
from
views.protocolTools.setting_process
import
setting_process
from
views.protocolTools.protocolReport_view
import
protocolReport_view
from
views.protocolTools.protocolReport_process
import
protocolReport_process
from
views.protocolTools.M_carSimulater_view
import
M_carSimulater_view
from
views.protocolTools.M_carSimulater_process
import
M_carSimulater_process
from
views.protocolTools.test_view
import
test_view
from
views.messageTools.msgSetting_view
import
msgSetting_view
...
...
@@ -16,6 +18,8 @@ app.register_blueprint(setting_view,url_prefix = "/protocolTools/setting_view")
app
.
register_blueprint
(
setting_process
,
url_prefix
=
"/protocolTools/setting_process"
)
app
.
register_blueprint
(
protocolReport_view
,
url_prefix
=
"/protocolTools/protocolReport_view"
)
app
.
register_blueprint
(
protocolReport_process
,
url_prefix
=
"/protocolTools/protocolReport_process"
)
app
.
register_blueprint
(
M_carSimulater_view
,
url_prefix
=
"/protocolTools/M_carSimulater_view"
)
app
.
register_blueprint
(
M_carSimulater_process
,
url_prefix
=
"/protocolTools/M_carSimulater_process"
)
app
.
register_blueprint
(
test_view
,
url_prefix
=
"/protocolTools/test_view"
)
app
.
register_blueprint
(
msgSetting_view
,
url_prefix
=
"/messageTools/msgSetting_view"
)
...
...
static/js/protocolTools/carsimulater.js
0 → 100644
View file @
405993b9
/**
*carsimulater 页面顶部的tab切换
*/
function
carSimulaterTab
(
e
){
var
url
=
window
.
location
.
href
;
var
id
=
$
(
e
).
attr
(
"
id
"
);
if
(
id
==
"
carsimulater_tab
"
){
$
(
location
).
attr
(
'
href
'
,
"
http://
"
+
window
.
location
.
host
+
"
/protocolTools/M_carSimulater_view/M_carSimulater_page
"
);
}
else
if
(
id
==
"
setting_tab
"
){
$
(
location
).
attr
(
'
href
'
,
"
http://
"
+
window
.
location
.
host
+
"
/protocolTools/M_carSimulater_view/M_setting_page
"
);
}
else
{
alert
(
id
)
}
}
\ No newline at end of file
templates/base.html
View file @
405993b9
...
...
@@ -20,6 +20,7 @@
<div
style=
"width: 70%;margin: 0 auto"
>
<ul
class=
"nav nav-tabs"
style=
"font-size:18px;"
>
<li
role=
"presentation"
{%
if
arg.path[0]=
="protocolTools"
%}
class=
"active"
{%
endif
%}
><a
onclick=
"swichTap(this)"
id=
"protocolTools"
>
M500协议工具
</a></li>
<li
role=
"presentation"
{%
if
arg.path[0]=
="m300"
%}
class=
"active"
{%
endif
%}
><a
onclick=
"swichTap(this)"
id=
"m300"
>
M300协议工具
</a></li>
<li
role=
"presentation"
{%
if
arg.path[0]=
="messageTools"
%}
class=
"active"
{%
endif
%}
><a
onclick=
"swichTap(this)"
id=
"messageTools"
>
新硬件消息工具
</a></li>
</ul>
</div>
...
...
templates/protocolTools/index.html
View file @
405993b9
...
...
@@ -23,6 +23,8 @@
$
(
location
).
attr
(
'
href
'
,
"
http://
"
+
window
.
location
.
host
+
"
/protocolTools/setting_view/socketSetting_page
"
);
}
else
if
(
id
==
"
protocols_report
"
){
$
(
location
).
attr
(
'
href
'
,
"
http://
"
+
window
.
location
.
host
+
"
/protocolTools/protocolReport_view/GPS_protocol_page
"
);
}
else
if
(
id
==
"
car_simulater
"
){
$
(
location
).
attr
(
'
href
'
,
"
http://
"
+
window
.
location
.
host
+
"
/protocolTools/M_carSimulater_view/M_carSimulater_page
"
);
}
else
if
(
id
==
"
test
"
){
$
(
location
).
attr
(
'
href
'
,
"
http://
"
+
window
.
location
.
host
+
"
/protocolTools/test_view/test_page
"
);
}
else
if
(
id
==
"
icon
"
){
...
...
@@ -39,7 +41,7 @@
<li
id=
"protocols_query"
onclick=
"swichLeftTab(this)"
><a
{%
if
arg.path[1]=
="protocolQuery_view"
%}
class=
"active_left_tab"
{%
endif
%}
><span
class=
"glyphicon glyphicon-list-alt"
aria-hidden=
"true"
></span>
远程查询报文
<span
class=
"sr-only"
></span></a></li>
</ul>
<ul
class=
"nav nav-sidebar"
style=
"margin-top:20px;"
>
<li
id=
"
noid"
onclick=
"swichLeftTab(this)"
><a
{%
if
arg.path[1]=
="icon
"
%}
class=
"active_left_tab"
{%
endif
%}
><span
class=
"glyphicon glyphicon-hand-right"
aria-hidden=
"true"
></span>
车辆行为模拟
</a></li>
<li
id=
"
car_simulater"
onclick=
"swichLeftTab(this)"
><a
{%
if
arg.path[1]=
="M_carSimulater_view
"
%}
class=
"active_left_tab"
{%
endif
%}
><span
class=
"glyphicon glyphicon-hand-right"
aria-hidden=
"true"
></span>
车辆行为模拟
</a></li>
</ul>
<ul
class=
"nav nav-sidebar"
style=
"margin-top:20px;"
>
<li
id=
"test"
onclick=
"swichLeftTab(this)"
><a
{%
if
arg.path[1]=
="test_view"
%}
class=
"active_left_tab"
{%
endif
%}
><span
class=
"glyphicon glyphicon-text-size"
aria-hidden=
"true"
></span>
测试页面
</a></li>
...
...
templates/protocolTools/report/GPS_protocol_page.html
View file @
405993b9
...
...
@@ -60,22 +60,38 @@
<li><label>
PDOP精度:
</label><input
id=
"Pdop"
type=
"text"
class=
"form-control"
value=
"0.3"
></li>
<li><label>
HDOP精度:
</label><input
id=
"Hdop"
type=
"text"
class=
"form-control"
value=
"0.4"
></li>
<li><label>
VDOP精度:
</label><input
id=
"Vdop"
type=
"text"
class=
"form-control"
value=
"0.5"
></li>
<li><label>
状态位:
</label><input
id=
"statusBit"
type=
"text"
class=
"form-control"
value=
"175"
></li>
<!-- <li style="width:100%;background:#eeeeee;padding-top:5px;padding-bottom:5px;border-radius:5px;"><H4 style="display:inline-block;padding-left:10px;">状态位:</H4> <p style="display:inline;font-size:12px;">状态使用的是一个字段表示,因此以下4个字段会合并为一个值,值为4个数字相加</p>-->
<!-- <div style="width:100%;">-->
<!-- <span><label>电瓶电压:</label><input id="valtage1" type="text" class="form-control" value="36.9"></span>-->
<!-- <span><label>电瓶电压:</label><input id="valtage2" type="text" class="form-control" value="36.9"></span>-->
<!-- <span><label>电瓶电压:</label><input id="valtage3" type="text" class="form-control" value="36.9"></span>-->
<!-- <span><label>电瓶电压:</label><input id="valtage4" type="text" class="form-control" value="36.9"></span>-->
<!-- </div>-->
<!-- </li>-->
<li
style=
"width:100%;"
>
<h5><b>
状态位:
</b></h5>
<label
style=
"font-size:12px;"
>
当前定位是否有效:
</label><select
id=
"isLocationValid"
class=
"form-control"
style=
"width:100px;"
>
<option
value=
"1"
>
有效
</option>
<option
value=
"0"
>
无效
</option>
</select>
<label
style=
"font-size:12px;"
>
当前定位模式:
</label><select
id=
"locationMode"
class=
"form-control"
style=
"width:170px;"
>
<option
value=
"0"
>
自动模式
</option>
<option
value=
"2"
>
单GPS模式
</option>
<option
value=
"4"
>
单BDS模式
</option>
<option
value=
"6"
>
GPS+BDS双模式
</option>
</select>
<label
style=
"font-size:12px;"
>
定位类型:
</label><select
id=
"locationType"
class=
"form-control"
style=
"width:100px;"
>
<option
value=
"32"
>
2D定位
</option>
<option
value=
"48"
>
3D定位
</option>
</select>
<label
style=
"font-size:12px;"
>
统计里程模式:
</label><select
id=
"staticMileageMode"
class=
"form-control"
style=
"width:150px;"
>
<option
value=
"0"
>
GPS统计里程
</option>
<option
value=
"64"
>
OBD统计里程
</option>
</select>
<label
style=
"font-size:12px;"
>
车辆点熄火状态:
</label><select
id=
"fireStatus"
class=
"form-control"
style=
"width:100px;"
>
<option
value=
"0"
>
熄火
</option>
<option
value=
"128"
selected=
"selected"
>
点火
</option>
</select>
</li>
<li><label>
电瓶电压:
</label><input
id=
"valtage"
type=
"text"
class=
"form-control"
value=
"36.9"
></li>
<li><label>
OBD车速速:
</label><input
id=
"OBDSpeed"
type=
"text"
class=
"form-control"
value=
"60.9"
></li>
<li><label>
发动机转速:
</label><input
id=
"engineSpeed"
type=
"text"
class=
"form-control"
value=
"3000"
></li>
<li><label>
累计里程:
</label><input
id=
"GPSTotalMileage"
type=
"text"
class=
"form-control"
value=
"12800"
></li>
<li
style=
"width:320px;"
><label
style=
"width:150px"
>
累计油耗:
</label><input
id=
"totalOil"
type=
"text"
class=
"form-control"
value=
"100000"
></li>
<li
style=
"width:320px;"
><label
style=
"width:150px
"
>
累计行驶时间:
</label><input
id=
"totalTime"
type=
"text"
class=
"form-control"
value=
"2020002"
></li>
<li
style=
"width:320px;height:40px;"
><label
style=
"width:150px
"
>
GPS信息时间戳:
</label><input
id=
"GPSTimestamp"
type=
"text"
class=
"form-control"
></li>
<li
><label
>
累计油耗:
</label><input
id=
"totalOil"
type=
"text"
class=
"form-control"
value=
"100000"
></li>
<li
><label
style=
"font-size:12px;
"
>
累计行驶时间:
</label><input
id=
"totalTime"
type=
"text"
class=
"form-control"
value=
"2020002"
></li>
<li
><label
style=
"font-size:12px;
"
>
GPS信息时间戳:
</label><input
id=
"GPSTimestamp"
type=
"text"
class=
"form-control"
></li>
</ul>
<H3
style=
"border-bottom: 1px solid #eee;"
>
控制:
</H3>
<div
style=
"width:100%;padding:5px;margin-top:10px;"
>
...
...
@@ -106,7 +122,13 @@
var
Pdop
=
$
(
"
#Pdop
"
).
val
();
var
Hdop
=
$
(
"
#Hdop
"
).
val
();
var
Vdop
=
$
(
"
#Vdop
"
).
val
();
var
statusBit
=
$
(
"
#statusBit
"
).
val
();
var
isLocationValid
=
parseInt
(
$
(
"
#isLocationValid
"
).
val
());
var
locationMode
=
parseInt
(
$
(
"
#isLocationValid
"
).
val
());
var
locationType
=
parseInt
(
$
(
"
#locationType
"
).
val
());
var
staticMileageMode
=
parseInt
(
$
(
"
#staticMileageMode
"
).
val
());
var
fireStatus
=
parseInt
(
$
(
"
#fireStatus
"
).
val
());
var
statusBit
=
isLocationValid
+
locationMode
+
locationType
+
staticMileageMode
+
fireStatus
var
valtage
=
$
(
"
#valtage
"
).
val
();
var
OBDSpeed
=
$
(
"
#OBDSpeed
"
).
val
();
var
engineSpeed
=
$
(
"
#engineSpeed
"
).
val
();
...
...
@@ -152,7 +174,7 @@
msg
=
"
发送消息:
"
+
data
.
msgSend
+
"
\n
"
msg
=
msg
+
"
收到消息:
"
+
data
.
result
+
"
\n
"
msg
=
msg
+
"
收到消息16进制:
"
+
data
.
rev
+
"
\n
"
msg
=
msg
+
"
收到消息解析结果:
"
+
data
.
orgRev
+
"
\n
"
msg
=
msg
+
"
收到消息解析结果:
"
+
JSON
.
stringify
(
data
.
orgRev
)
+
"
\n
"
$
(
"
#showFeedback
"
).
val
(
msg
)
}
else
{
$
(
"
#showFeedback
"
).
val
(
data
.
message
)
...
...
templates/protocolTools/report/M_carSimulater_page.html
0 → 100644
View file @
405993b9
{% extends "protocolTools/index.html" %}
{% block title %}carSimulater{% endblock %}
{% block content_01 %}
<script
src=
"../../static/js/protocolTools/carsimulater.js"
></script>
<style>
.nav-pills
li
{
margin-bottom
:
5px
;
}
.form-control
{
display
:
inline
;
width
:
160px
;
}
.protocol_content
:after
{
clear
:
both
;
display
:
block
;
content
:
" "
;
}
.protocol_content
li
{
width
:
250px
;
_background
:
yellow
;
list-style
:
none
;
margin-top
:
5px
;
float
:
left
;
}
.protocol_content
label
{
width
:
90px
;
text-align
:
right
;
}
</style>
<div
id=
"container2"
style=
"width:83%;min-height:750px;float:left;_background:grey;margin-top:50px;"
>
{% block content_02 %}
<ul
class=
"nav nav-pills"
style=
"font-size:14px;"
>
<li
role=
"presentation"
><a
id=
"setting_tab"
{%
if
arg.path[2]=
="M_setting_page"
%}
class=
"link-tab"
{%
endif
%}
onclick=
"carSimulaterTab(this)"
>
设置
</b></a></li>
<li
role=
"presentation"
><a
id=
"carsimulater_tab"
{%
if
arg.path[2]=
="M_carSimulater_page"
%}
class=
"link-tab"
{%
endif
%}
onclick=
"carSimulaterTab(this)"
>
模拟器
</b></a></li>
</ul>
{% endblock %}
{% 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;"
>
<label>
车机Id:
</label><input
id=
"carId"
type=
"text"
class=
"form-control"
value=
"M121501010001"
>
</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"
>
1、连网
</button>
<button
id=
"login_B"
type=
"button"
class=
"btn btn-primary"
>
2、车机登录
</button>
<button
id=
"fire_B"
type=
"button"
class=
"btn btn-primary"
>
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=
"unFire_B"
type=
"button"
class=
"btn btn-primary"
>
6、熄火
</button>
<button
id=
"unConnect_B"
type=
"button"
class=
"btn btn-primary"
>
7、断网
</button>
<button
id=
"unConnectAll_B"
type=
"button"
class=
"btn btn-danger"
>
8、强制断网
</button>
</div>
<div
style=
"width:100%;padding-bottom:10px;border-bottom: 1px solid #eee;"
>
<h3>
日志:
</h3>
<textarea
id=
"showFeedback"
style=
"width:100%;padding:5px;"
rows=
"10"
></textarea>
</div>
</div>
<script>
</script>
{% endblock %}
</div>
{% endblock %}
\ No newline at end of file
templates/protocolTools/report/M_setting_page.html
0 → 100644
View file @
405993b9
{% extends "protocolTools/report/M_carSimulater_page.html" %}
{% block title %}GPS_protocol{% endblock %}
{% 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;"
>
<label>
主机地址:
</label><input
id=
"host"
type=
"text"
class=
"form-control"
value=
"{{ arg['socket']['host']}}"
>
<label
style=
"margin-left:10px;"
>
端口:
</label><input
id=
"port"
type=
"text"
class=
"form-control"
value=
"{{ arg['socket']['port']}}"
style=
"width:100px;"
>
<button
id=
"saveSocketSetting"
type=
"button"
class=
"btn btn-primary"
id=
"saveSetting"
>
保存
</button>
</div>
</div>
<script>
$
(
"
#saveSocketSetting
"
).
click
(
function
(){
var
host
=
$
(
"
#host
"
).
val
();
var
port
=
$
(
"
#port
"
).
val
();
var
data
=
{};
data
[
"
host
"
]
=
host
;
data
[
"
port
"
]
=
port
;
var
host
=
window
.
location
.
host
;
$
.
ajax
({
url
:
"
http://
"
+
host
+
"
/protocolTools/M_carSimulater_process/porcessSocketSetting
"
,
type
:
"
post
"
,
data
:
data
,
dataType
:
"
json
"
,
success
:
function
(
data
){
if
(
data
.
status
==
200
){
window
.
location
.
reload
()
}
else
{
$
(
"
#showFeedback
"
).
val
(
data
.
message
)
alert
(
data
.
message
);
}
}
});
});
</script>
{% endblock %}
\ No newline at end of file
templates/protocolTools/report/OBD_CAN_protocol_page.html
View file @
405993b9
...
...
@@ -203,7 +203,7 @@ $("#sendMsgBtn").click(function(){
msg
=
"
发送消息:
"
+
data
.
msgSend
+
"
\n
"
msg
=
msg
+
"
收到消息:
"
+
data
.
result
+
"
\n
"
msg
=
msg
+
"
收到消息16进制:
"
+
data
.
rev
+
"
\n
"
msg
=
msg
+
"
收到消息解析结果:
"
+
data
.
orgRev
+
"
\n
"
msg
=
msg
+
"
收到消息解析结果:
"
+
JSON
.
stringify
(
data
.
orgRev
)
+
"
\n
"
$
(
"
#showFeedback
"
).
val
(
msg
)
}
else
{
$
(
"
#showFeedback
"
).
val
(
data
.
message
)
...
...
templates/protocolTools/report/heartBeat_protocol_page.html
View file @
405993b9
...
...
@@ -43,7 +43,7 @@ $("#sendMsgBtn").click(function(){
msg
=
"
发送消息:
"
+
data
.
msgSend
+
"
\n
"
msg
=
msg
+
"
收到消息:
"
+
data
.
result
+
"
\n
"
msg
=
msg
+
"
收到消息16进制:
"
+
data
.
rev
+
"
\n
"
msg
=
msg
+
"
收到消息解析结果:
"
+
data
.
orgRev
+
"
\n
"
msg
=
msg
+
"
收到消息解析结果:
"
+
JSON
.
stringify
(
data
.
orgRev
)
+
"
\n
"
$
(
"
#showFeedback
"
).
val
(
msg
)
}
else
{
$
(
"
#showFeedback
"
).
val
(
data
.
message
)
...
...
templates/protocolTools/report/login_protocol_page.html
View file @
405993b9
...
...
@@ -55,7 +55,7 @@ $("#sendMsgBtn").click(function(){
msg
=
"
发送消息:
"
+
data
.
msgSend
+
"
\n
"
msg
=
msg
+
"
收到消息:
"
+
data
.
result
+
"
\n
"
msg
=
msg
+
"
收到消息16进制:
"
+
data
.
rev
+
"
\n
"
msg
=
msg
+
"
收到消息解析结果:
"
+
data
.
orgRev
+
"
\n
"
msg
=
msg
+
"
收到消息解析结果:
"
+
JSON
.
stringify
(
data
.
orgRev
)
+
"
\n
"
$
(
"
#showFeedback
"
).
val
(
msg
)
}
else
{
$
(
"
#showFeedback
"
).
val
(
data
.
message
)
...
...
templates/protocolTools/report/securityStatus_protocol_page.html
View file @
405993b9
...
...
@@ -345,7 +345,7 @@ $("#sendMsgBtn").click(function(){
msg
=
"
发送消息:
"
+
data
.
msgSend
+
"
\n
"
msg
=
msg
+
"
收到消息:
"
+
data
.
result
+
"
\n
"
msg
=
msg
+
"
收到消息16进制:
"
+
data
.
rev
+
"
\n
"
msg
=
msg
+
"
收到消息解析结果:
"
+
data
.
orgRev
+
"
\n
"
msg
=
msg
+
"
收到消息解析结果:
"
+
JSON
.
stringify
(
data
.
orgRev
)
+
"
\n
"
$
(
"
#showFeedback
"
).
val
(
msg
)
}
else
{
$
(
"
#showFeedback
"
).
val
(
data
.
message
)
...
...
views/protocolTools/M_carSimulater_process.py
0 → 100644
View file @
405993b9
#coding:utf-8
from
flask
import
Blueprint
,
Response
,
request
from
configparser
import
ConfigParser
from
lib.protocol.report.HeartBeatReport_protocol
import
HeartBeatReport_protocol
from
lib.protocol.report.LoginReport_protocol
import
LoginReport_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.SecurityStatusReport_protocol
import
SecurityStatusReport_protocol
from
lib.protocol.reportPlateform.Common_res
import
Common_res
from
lib.protocol.reportPlateform.Login_res
import
Login_res
from
lib.socket.ClientSocket
import
ClientSocket
import
json
import
traceback
import
binascii
M_carSimulater_process
=
Blueprint
(
'M_carSimulater_process'
,
__name__
)
#用来保存连接的信息
connects
=
[]
#用来保存车机线程
threads
=
[]
##########################################
# 【接口类型】设置socket信息
##########################################
@
M_carSimulater_process
.
route
(
"/porcessSocketSetting"
,
methods
=
[
'POST'
])
def
porcessSocketSetting
():
host
=
request
.
form
.
get
(
"host"
)
port
=
request
.
form
.
get
(
"port"
)
data
=
{}
if
(
host
==
None
or
port
==
None
):
data
[
"status"
]
=
"4003"
data
[
"message"
]
=
"Info: 请检查是否传入了空数据!"
return
Response
(
json
.
dumps
(
data
),
mimetype
=
'application/json'
)
else
:
try
:
# d读取config文件
conf_R
=
ConfigParser
()
conf_R
.
read
(
"config/protocolTools/carSimulater.conf"
)
conf_W
=
conf_R
conf_W
[
"socket"
][
"host"
]
=
host
conf_W
[
"socket"
][
"port"
]
=
port
with
open
(
"config/protocolTools/carSimulater.conf"
,
"w"
)
as
fi
:
conf_W
.
write
(
fi
)
data
[
"status"
]
=
"200"
data
[
"message"
]
=
"Sucess: "
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
(
"/createConect"
,
methods
=
[
'POST'
])
def
createConect
():
data
=
{}
try
:
conf_R
=
ConfigParser
()
conf_R
.
read
(
"config/protocolTools/carSimulater.conf"
)
if
len
(
connects
)
<
1
:
cliSocket
=
ClientSocket
(
conf_R
.
get
(
"socket"
,
"host"
),
conf_R
.
getint
(
"socket"
,
"port"
))
cliSocket
.
connect
()
connect
=
{}
socketName
=
"socket_"
+
str
(
len
(
connects
)
+
1
)
connect
[
"name"
]
=
socketName
connect
[
"obj"
]
=
cliSocket
connects
.
append
(
connect
)
data
[
"status"
]
=
"200"
data
[
"message"
]
=
"创建连接成功!"
else
:
data
[
"status"
]
=
"4003"
data
[
"message"
]
=
"已经创建了连接!"
except
BaseException
as
e
:
# 打印异常信息
traceback
.
print_exc
()
data
[
"status"
]
=
"4003"
data
[
"message"
]
=
"Error: 处理失败!"
##########################################
# 【接口类型】关闭一个连接
##########################################
@
M_carSimulater_process
.
route
(
"/closeConect"
,
methods
=
[
'POST'
])
def
closeConect
():
data
=
{}
try
:
if
len
(
connects
)
<
1
:
data
[
"status"
]
=
"4003"
data
[
"message"
]
=
"没有课关闭的连接!"
else
:
connects
[
0
][
"obj"
]
.
close
()
connects
.
pop
(
0
)
data
[
"status"
]
=
"200"
data
[
"message"
]
=
"关闭连接成功!"
except
BaseException
as
e
:
# 打印异常信息
traceback
.
print_exc
()
data
[
"status"
]
=
"4003"
data
[
"message"
]
=
"Error: 处理失败!"
\ No newline at end of file
views/protocolTools/M_carSimulater_view.py
0 → 100644
View file @
405993b9
#coding:utf-8
from
configparser
import
ConfigParser
from
flask
import
Blueprint
,
render_template
,
request
import
re
M_carSimulater_view
=
Blueprint
(
'M_carSimulater_view'
,
__name__
)
##########################################
# 【视图类型】访问心跳协议报文发送页面
##########################################
@
M_carSimulater_view
.
route
(
'/M_carSimulater_page'
)
def
M_carSimulater_page
():
#获取请求的路劲
url
=
request
.
url
reqPath
=
re
.
findall
(
"http://(.*)$"
,
url
)[
0
]
reqPath
=
re
.
findall
(
"/(.*)$"
,
reqPath
)[
0
]
arg
=
{}
path
=
"protocolTools/report/M_carSimulater_page.html"
arg
[
"path"
]
=
reqPath
.
split
(
"/"
)
return
render_template
(
path
,
arg
=
arg
)
##########################################
# 【视图类型】访问心跳协议报文发送页面
##########################################
@
M_carSimulater_view
.
route
(
'/M_setting_page'
)
def
M_setting_page
():
#获取请求的路劲
url
=
request
.
url
reqPath
=
re
.
findall
(
"http://(.*)$"
,
url
)[
0
]
reqPath
=
re
.
findall
(
"/(.*)$"
,
reqPath
)[
0
]
arg
=
{}
path
=
"protocolTools/report/M_setting_page.html"
arg
[
"path"
]
=
reqPath
.
split
(
"/"
)
arg
[
"socket"
]
=
{}
# 读取config文件
conf_R
=
ConfigParser
()
conf_R
.
read
(
"config/protocolTools/carSimulater.conf"
)
arg
[
"socket"
][
"host"
]
=
conf_R
.
get
(
"socket"
,
"host"
)
arg
[
"socket"
][
"port"
]
=
conf_R
.
getint
(
"socket"
,
"port"
)
return
render_template
(
path
,
arg
=
arg
)
\ No newline at end of file
views/protocolTools/protocolReport_process.py
View file @
405993b9
...
...
@@ -8,6 +8,8 @@ from lib.protocol.report.LoginReport_protocol import LoginReport_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.SecurityStatusReport_protocol
import
SecurityStatusReport_protocol
from
lib.protocol.reportPlateform.Common_res
import
Common_res
from
lib.protocol.reportPlateform.Login_res
import
Login_res
from
lib.socket.ClientSocket
import
ClientSocket
import
json
...
...
@@ -46,7 +48,7 @@ def porcessHeartBeatMsg():
data
[
"msgSend"
]
=
msg
data
[
"result"
]
=
socRecvo
data
[
"rev"
]
=
str
(
binascii
.
b2a_hex
(
socRecv
))[
2
:][:
-
1
]
data
[
"orgRev"
]
=
"*********返回的消息还未解析*********"
data
[
"orgRev"
]
=
json
.
loads
(
Common_res
(
data
[
"rev"
])
.
getMsg
())
except
BaseException
as
e
:
# 打印异常信息
traceback
.
print_exc
()
...
...
@@ -90,7 +92,7 @@ def porcessLoginBeatMsg():
data
[
"msgSend"
]
=
msg
data
[
"result"
]
=
socRecvo
data
[
"rev"
]
=
str
(
binascii
.
b2a_hex
(
socRecv
))[
2
:][:
-
1
]
data
[
"orgRev"
]
=
"*********返回的消息还未解析*********"
data
[
"orgRev"
]
=
data
[
"orgRev"
]
=
json
.
loads
(
Login_res
(
data
[
"rev"
])
.
getMsg
())
except
BaseException
as
e
:
# 打印异常信息
traceback
.
print_exc
()
...
...
@@ -150,7 +152,7 @@ def porcessGPSMsg():
data
[
"msgSend"
]
=
msg
data
[
"result"
]
=
socRecvo
data
[
"rev"
]
=
str
(
binascii
.
b2a_hex
(
socRecv
))[
2
:][:
-
1
]
data
[
"orgRev"
]
=
"*********返回的消息还未解析*********"
data
[
"orgRev"
]
=
json
.
loads
(
Common_res
(
data
[
"rev"
])
.
getMsg
())
except
BaseException
as
e
:
# 打印异常信息
traceback
.
print_exc
()
...
...
@@ -235,7 +237,7 @@ def porcessOBD_CAN_Msg():
data
[
"msgSend"
]
=
msg
data
[
"result"
]
=
socRecvo
data
[
"rev"
]
=
str
(
binascii
.
b2a_hex
(
socRecv
))[
2
:][:
-
1
]
data
[
"orgRev"
]
=
"*********返回的消息还未解析*********"
data
[
"orgRev"
]
=
json
.
loads
(
Common_res
(
data
[
"rev"
])
.
getMsg
())
except
BaseException
as
e
:
# 打印异常信息
traceback
.
print_exc
()
...
...
@@ -286,7 +288,7 @@ def porcessSecurityStatusMsg():
data
[
"msgSend"
]
=
msg
data
[
"result"
]
=
socRecvo
data
[
"rev"
]
=
str
(
binascii
.
b2a_hex
(
socRecv
))[
2
:][:
-
1
]
data
[
"orgRev"
]
=
"*********返回的消息还未解析*********"
data
[
"orgRev"
]
=
data
[
"orgRev"
]
=
json
.
loads
(
Common_res
(
data
[
"rev"
])
.
getMsg
())
except
BaseException
as
e
:
# 打印异常信息
traceback
.
print_exc
()
...
...
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