Commit 228503c5 authored by liyuanhong's avatar liyuanhong

完成M300 Obd协议开发、通用下行应答解析,终端登录下行应答解析,心跳页面、设置页面、版本页面,登录页面的开发

parent 268ca5ec
[socket]
host = 10.100.12.32
port = 9009
......@@ -7,12 +7,13 @@ from lib.protocol.m300.M300Base import M300Base
'''
class GPS_protocol_m300(M300Base):
def __init__(self,waterCode = "0003",DEV_ID = "M121501010001",dateInfo="2020-03-27 14:34:22",latitude=40.22077,longitude=116.23128 \
def __init__(self,waterCode = 3,DEV_ID = "M121501010001",encryptionType=0,dateInfo="2020-03-27 14:34:22",latitude=40.22077,longitude=116.23128 \
,positionStar=2,speed=66.0,direction=55.3,altitude=11.0,ACCStatus=0,valtage=36.0,OBDSpeed=66.4,valid=129 \
,tripMark=0):
super().__init__() # 不执行该方法,无法使用父类里面定义的属性
self.waterCode = waterCode #消息流水号
self.DEV_ID = DEV_ID #设备Id
self.encryptionType = encryptionType # 消息属性里面的是否加密字段
self.dateInfo = dateInfo #日期
self.latitude = latitude #维度
......@@ -35,11 +36,11 @@ class GPS_protocol_m300(M300Base):
def generateMsg(self):
msg = self.IDENTIFY
FUNID = "0020" #功能id
waterCode = self.waterCode #消息流水号
waterCode = self.int2hexStringByBytes(self.waterCode,2) #消息流水号
DEV_ID = self.devid2hexString(self.DEV_ID) #设备id
msgBody = self.getMsgBody() # 消息体
msgLen = int(len(msgBody) / 2)
property = self.getMsgProperty(msgBodyLen=msgLen,encryptionType=0)
property = self.getMsgProperty(msgBodyLen=msgLen,encryptionType=self.encryptionType)
checkCode = self.getCheckCode(FUNID + waterCode + DEV_ID + property + msgBody)
msg = msg + FUNID + waterCode + DEV_ID + property + msgBody + checkCode + self.IDENTIFY
return msg
......
......@@ -7,10 +7,11 @@ from lib.protocol.m300.M300Base import M300Base
'''
class Heartbeat_protocol_300(M300Base):
def __init__(self,waterCode = "0003",DEV_ID = "M121501010001"):
def __init__(self,waterCode = 3,DEV_ID = "M121501010001",encryptionType=0):
super().__init__() # 不执行该方法,无法使用父类里面定义的属性
self.waterCode = waterCode #消息流水号
self.DEV_ID = DEV_ID #设备Id
self.encryptionType = encryptionType #消息属性里面的是否加密字段
#################################################
# 生成消息
......@@ -18,11 +19,11 @@ class Heartbeat_protocol_300(M300Base):
def generateMsg(self):
msg = self.IDENTIFY
FUNID = "0004" #功能id
waterCode = self.waterCode #消息流水号
waterCode = self.int2hexStringByBytes(self.waterCode,2) #消息流水号
DEV_ID = self.devid2hexString(self.DEV_ID) #设备id
msgBody = self.getMsgBody() # 消息体
msgLen = int(len(msgBody) / 2)
property = self.getMsgProperty(msgBodyLen=msgLen,encryptionType=0)
property = self.getMsgProperty(msgBodyLen=msgLen,encryptionType=self.encryptionType)
checkCode = self.getCheckCode(FUNID + waterCode + DEV_ID + property + msgBody)
msg = msg + FUNID + waterCode + DEV_ID + property + msgBody + checkCode + self.IDENTIFY
return msg
......
......@@ -5,10 +5,11 @@ from lib.protocol.m300.M300Base import M300Base
'''
class Login_protocol_m300(M300Base):
def __init__(self,waterCode = "0003",DEV_ID = "M121501010001"):
def __init__(self,waterCode = 3,DEV_ID = "M121501010001",encryptionType=0):
super().__init__() # 不执行该方法,无法使用父类里面定义的属性
self.waterCode = waterCode #消息流水号
self.DEV_ID = DEV_ID #设备Id
self.encryptionType = encryptionType #消息属性里面的是否加密字段
#################################################
# 生成消息
......@@ -16,11 +17,11 @@ class Login_protocol_m300(M300Base):
def generateMsg(self):
msg = self.IDENTIFY
FUNID = "00FF" #功能id
waterCode = self.waterCode #消息流水号
waterCode = self.int2hexStringByBytes(self.waterCode,2) #消息流水号
DEV_ID = self.devid2hexString(self.DEV_ID) #设备id
msgBody = self.getMsgBody() # 消息体
msgLen = int(len(msgBody) / 2)
property = self.getMsgProperty(msgBodyLen=msgLen,encryptionType=0)
property = self.getMsgProperty(msgBodyLen=msgLen,encryptionType=self.encryptionType)
checkCode = self.getCheckCode(FUNID + waterCode + DEV_ID + property + msgBody)
msg = msg + FUNID + waterCode + DEV_ID + property + msgBody + checkCode + self.IDENTIFY
return msg
......
......@@ -7,9 +7,9 @@ from lib.protocol.m300.M300Base import M300Base
'''
class OBDCAN_protocol_m300(M300Base):
def __init__(self,waterCode = "0003",DEV_ID = "M121501010001",timeInfo="2020-03-30 17:00:59",prototolType="11",statusMask="01010101010101010101" \
def __init__(self,waterCode = 3,DEV_ID = "M121501010001",encryptionType=0,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",totalMilleage=3000,totalOil=300,troubleLightStatus=0 \
,dataFlowMask="fffffffd",votage=360,totalMilleageType=2,totalMilleage=3000,totalOil=300,troubleLightStatus=0 \
,troubleCodeNum=2,engineSpeed=3000,speed=60,airInletTemperature=88,coolingLiquidTemperature=76,envTemperature=65 \
,intakeManifoldPressure=20,oilPressure=276,atmosphericPressure=28,airFlow=550,valveLocation=51,acceleratorLocation=32 \
,engineRunTime=370,troubleMileage=4508,surplusOil=801,engineLoad=52,fuelTrim=89,fireAngle=154,dashboardTotailMilleage=3000 \
......@@ -17,6 +17,7 @@ class OBDCAN_protocol_m300(M300Base):
super().__init__() # 不执行该方法,无法使用父类里面定义的属性
self.waterCode = waterCode #消息流水号
self.DEV_ID = DEV_ID #设备Id
self.encryptionType = encryptionType #消息属性里面的是否加密字段
self.timeInfo = timeInfo #时间信息
self.prototolType = prototolType #协议类别
......@@ -68,11 +69,11 @@ class OBDCAN_protocol_m300(M300Base):
def generateMsg(self):
msg = self.IDENTIFY
FUNID = "0003" #功能id
waterCode = self.waterCode #消息流水号
waterCode = self.int2hexStringByBytes(self.waterCode,2) #消息流水号
DEV_ID = self.devid2hexString(self.DEV_ID) #设备id
msgBody = self.getMsgBody() # 消息体
msgLen = int(len(msgBody) / 2)
property = self.getMsgProperty(msgBodyLen=msgLen,encryptionType=0)
property = self.getMsgProperty(msgBodyLen=msgLen,encryptionType=self.encryptionType)
checkCode = self.getCheckCode(FUNID + waterCode + DEV_ID + property + msgBody)
msg = msg + FUNID + waterCode + DEV_ID + property + msgBody + checkCode + self.IDENTIFY
return msg
......@@ -82,7 +83,6 @@ class OBDCAN_protocol_m300(M300Base):
# 获取消息体
#################################################
def getMsgBody(self):
data = ""
dateInfo = self.getDateInfo(self.timeInfo) # 日期
prototolType = self.prototolType #协议类别
statusMask = self.statusMask #状态掩码
......@@ -97,7 +97,43 @@ class OBDCAN_protocol_m300(M300Base):
retain9 = self.int2hexStringByBytes(self.retain9)
retail10 = self.int2hexStringByBytes(self.retail10)
dataFlowMask = self.dataFlowMask
dataFlowMask = self.dataFlowMask #数据流掩码
votage = self.int2hexStringByBytes(self.votage,2) #电瓶电压
totalMilleageType = self.int2hexStringByBytes(self.totalMilleageType) #总里程类别
totalMilleage = self.int2hexStringByBytes(self.totalMilleage,4) #行驶里程,上传值单位为m(米)
totalOil = self.int2hexStringByBytes(self.totalOil,4) #总的燃油消耗量,上传值单位为ml(毫升)
troubleLightStatus = self.int2hexStringByBytes(self.troubleLightStatus) #故障灯状态(MIL)
troubleCodeNum = self.int2hexStringByBytes(self.troubleCodeNum) #故障码个数
engineSpeed = self.int2hexStringByBytes(self.engineSpeed,2) #发动机转速
speed = self.int2hexStringByBytes(self.speed) #车辆速度
airInletTemperature = self.int2hexStringByBytes(self.airInletTemperature) #进气口温度
coolingLiquidTemperature = self.int2hexStringByBytes(self.coolingLiquidTemperature) #冷却液温度
envTemperature = self.int2hexStringByBytes(self.envTemperature) #车辆环境温度
intakeManifoldPressure = self.int2hexStringByBytes(self.intakeManifoldPressure) #进气歧管压力
oilPressure = self.int2hexStringByBytes(self.oilPressure,2) #燃油压力
atmosphericPressure = self.int2hexStringByBytes(self.atmosphericPressure) #大气压力
airFlow = self.int2hexStringByBytes(self.airFlow,2) #空气流量
valveLocation = self.int2hexStringByBytes(self.valveLocation,2) #气门位置传感器
acceleratorLocation = self.int2hexStringByBytes(self.acceleratorLocation,2) #油门踏板位置
engineRunTime = self.int2hexStringByBytes(self.engineRunTime,2) #发动机运行时间
troubleMileage = self.int2hexStringByBytes(self.troubleMileage,4) #故障行驶里程
surplusOil = self.int2hexStringByBytes(self.surplusOil,2) #剩余油量
engineLoad = self.int2hexStringByBytes(self.engineLoad) #发动机负荷
fuelTrim = self.int2hexStringByBytes(self.fuelTrim,2) #长期燃油修正(组1)
fireAngle = self.int2hexStringByBytes(self.fireAngle,2) #点火提前角
dashboardTotailMilleage = self.int2hexStringByBytes(self.dashboardTotailMilleage,4) #仪表总里程
carTotalRunTime = self.int2hexStringByBytes(self.carTotalRunTime,4) #车辆总运行时间
retail = self.retail
tripMark = self.tripMark #驾驶循环标签
data = dateInfo + prototolType + statusMask + safeStatus + doorStatus
data = data + lockStatus + windowStatus + lightStatus + swichStatusA + swichStatusB
data = data + dataBit + retain9 + retail10 + dataFlowMask + votage
data = data + totalMilleageType + totalMilleage + totalOil + troubleLightStatus + troubleCodeNum
data = data + engineSpeed + speed + airInletTemperature + coolingLiquidTemperature + envTemperature
data = data + intakeManifoldPressure + oilPressure + atmosphericPressure + airFlow + valveLocation
data = data + acceleratorLocation + engineRunTime + troubleMileage + surplusOil + engineLoad
data = data + fuelTrim + fireAngle + dashboardTotailMilleage + carTotalRunTime + retail
data = data + tripMark
return data
#获取安全状态
......
......@@ -7,11 +7,12 @@ 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" \
def __init__(self,waterCode = 3,DEV_ID = "M121501010001",encryptionType=0,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.encryptionType = encryptionType #消息属性里面的是否加密字段
self.SWVersion = SWVersion #软件版本号
self.SWDate = SWDate #软件日期
......@@ -28,11 +29,11 @@ class VersionInfo_protocol_m300(M300Base):
def generateMsg(self):
msg = self.IDENTIFY
FUNID = "0007" #功能id
waterCode = self.waterCode #消息流水号
waterCode = self.int2hexStringByBytes(self.waterCode,2) #消息流水号
DEV_ID = self.devid2hexString(self.DEV_ID) #设备id
msgBody = self.getMsgBody() # 消息体
msgLen = int(len(msgBody) / 2)
property = self.getMsgProperty(msgBodyLen=msgLen,encryptionType=0)
property = self.getMsgProperty(msgBodyLen=msgLen,encryptionType=self.encryptionType)
checkCode = self.getCheckCode(FUNID + waterCode + DEV_ID + property + msgBody)
msg = msg + FUNID + waterCode + DEV_ID + property + msgBody + checkCode + self.IDENTIFY
return msg
......
#encoding:utf-8
'''
定义下行通用应答消息解码类
'''
import json
from lib.protocol.m300.M300Base import M300Base
from lib.protocol.m300Plateform.ResponseBase import ResponseBase
class M300Common_res(ResponseBase):
def __init__(self,msg):
super().__init__()
if type(msg) == bytes:
self.msg = self.binary2ascii(msg)
else:
self.msg = msg
self.msg = self.restore_7e7d(self.msg)
#######################################################
# 获取消息
#######################################################
def getMsg(self):
json_msg = {}
json_msg["FUNID"] = self.msg[2:6]
json_msg["waterCode"] = self.hexString2int(self.msg[6:10])
json_msg["DEV_ID"] = self.msg[10:24]
json_msg["property"] = self.getMsgProperty()
json_msg["body"] = self.getMsgBody()
json_msg["checkCode"] = self.msg[len(self.msg) - 4:len(self.msg) - 2]
json_msg["calculateCheckCode"] = self.getCalculateCheckCode() #自己计算消息后得到的校验码
json_msg = json.dumps(json_msg)
return json_msg
#######################################################
# 获取消息属性
######################################################
def getMsgProperty(self):
property = {}
data = self.msg[24:28]
data = self.hexString2int(data)
data = self.int2binStr(data)
encryptionType = data[2:6]
length = data[6:]
property["encryptionType"] = int(encryptionType,2)
property["length"] = int(length, 2)
return property
#######################################################
# 获取消息体
######################################################
def getMsgBody(self):
body = {}
data = self.msg[28:len(self.msg) - 4]
body["funId"] = data
return body
#######################################################
# 计算消息得到校验码
#######################################################
def getCalculateCheckCode(self):
data = self.removeIdentify(self.msg)
dataLen = len(data)
data = data[:dataLen - 2]
calculateCheckCode = M300Base().getCheckCode(data)
return calculateCheckCode
if __name__ == "__main__":
print(M300Common_res("7e800100034d12150101000100020003c87e").getMsg())
#encoding:utf-8
'''
定义下行通用应答消息解码类
'''
import json
from lib.protocol.m300.M300Base import M300Base
from lib.protocol.m300Plateform.ResponseBase import ResponseBase
class M300Login_res(ResponseBase):
def __init__(self,msg):
super().__init__()
if type(msg) == bytes:
self.msg = self.binary2ascii(msg)
else:
self.msg = msg
self.msg = self.restore_7e7d(self.msg)
#######################################################
# 获取消息
#######################################################
def getMsg(self):
json_msg = {}
json_msg["FUNID"] = self.msg[2:6]
json_msg["waterCode"] = self.hexString2int(self.msg[6:10])
json_msg["DEV_ID"] = self.msg[10:24]
json_msg["property"] = self.getMsgProperty()
json_msg["body"] = self.getMsgBody()
json_msg["checkCode"] = self.msg[len(self.msg) - 4:len(self.msg) - 2]
json_msg["calculateCheckCode"] = self.getCalculateCheckCode() #自己计算消息后得到的校验码
json_msg = json.dumps(json_msg)
return json_msg
#######################################################
# 获取消息属性
######################################################
def getMsgProperty(self):
property = {}
data = self.msg[24:28]
data = self.hexString2int(data)
data = self.int2binStr(data)
encryptionType = data[2:6]
length = data[6:]
property["encryptionType"] = int(encryptionType,2)
property["length"] = int(length, 2)
return property
#######################################################
# 获取消息体
######################################################
def getMsgBody(self):
body = {}
data = self.msg[28:len(self.msg) - 4]
body["status"] = data
return body
#######################################################
# 计算消息得到校验码
#######################################################
def getCalculateCheckCode(self):
data = self.removeIdentify(self.msg)
dataLen = len(data)
data = data[:dataLen - 2]
calculateCheckCode = M300Base().getCheckCode(data)
return calculateCheckCode
if __name__ == "__main__":
print(M300Common_res("7e800100034d12150101000100020003c87e").getMsg())
#encoding:utf-8
import binascii
import time
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
#######################################################
# 10进制转换为2进制字符串
#######################################################
def int2binStr(self,data,bytescount=1):
binStr = bin(data)
binStr = binStr[2:]
bytesLen = bytescount * 8
while len(binStr) < bytesLen:
binStr = "0" + binStr
return binStr
#######################################################
# 还原消息中被转换过的7e和7d
#######################################################
def restore_7e7d(self,data):
data = data.replace("7d02", "7e")
data = data.replace("7d01", "7d")
return data
#######################################################
# 去除标识位
#######################################################
def removeIdentify(self,data):
dataLen = len(data)
data = data[2:dataLen - 2]
return data
#######################################################
# utc 时间格式的16进制字符串转时间
######################################################
def hexDate2date(self,hexData):
UTCTime = "20"
UTCTime = UTCTime + str(self.hexString2int(hexData[:2]))
UTCTime = UTCTime + "-" + str(self.hexString2int(hexData[2:4]))
UTCTime = UTCTime + "-" + str(self.hexString2int(hexData[4:6]))
UTCTime = UTCTime + " " + str(self.hexString2int(hexData[6:8]))
UTCTime = UTCTime + ":" + str(self.hexString2int(hexData[8:10]))
UTCTime = UTCTime + ":" + str(self.hexString2int(hexData[10:12]))
return UTCTime
#######################################################
# 时间戳的16进制字符串转时间
######################################################
def hexTimestamp2date(self,hexData):
timeStamp = self.hexString2int(hexData)
timeArray = time.localtime(timeStamp)
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
return otherStyleTime
if __name__ == "__main__":
print(ResponseBase().hexDate2date("01c329ed065"))
print(ResponseBase().hexTimestamp2date("5e60723b"))
......@@ -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.OBDCAN_protocol_m300 import OBDCAN_protocol_m300
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
......@@ -18,19 +19,20 @@ from lib.protocol.report.EventReport_protocol import EventReport_protocol
# host = "10.100.12.34"
# port = 8712
# host = "10.100.12.32"
# port = 9009
host = "10.100.12.32"
port = 9009
# host = "10.100.5.251"
# port = 9009
host = "10.100.5.251"
port = 9009
# host = "10.100.5.251"
# port = 9009
# msg = Heartbeat_protocol_300().generateMsg() #心跳报文
# msg = GPS_protocol_m300().generateMsg() #GPS报文
msg = VersionInfo_protocol_m300().generateMsg() #终端版本报文
# msg = VersionInfo_protocol_m300().generateMsg() #终端版本报文
# msg = "7e000400e14d2019120315000000957e" #终端上报心跳协议
msg = OBDCAN_protocol_m300().generateMsg() #OBD CAN报文
print(msg)
......
......@@ -9,6 +9,7 @@ from views.protocolTools.M_carSimulater_process import M_carSimulater_process
from views.protocolTools.test_view import test_view
from views.m300Tools.P_m300Protocol_view import P_m300Protocol_view
from views.m300Tools.P_m300Protocol_process import P_m300Protocol_process
from views.messageTools.msgSetting_view import msgSetting_view
from views.messageTools.msgSetting_process import msgSetting_process
......@@ -25,6 +26,7 @@ app.register_blueprint(M_carSimulater_process,url_prefix = "/protocolTools/M_car
app.register_blueprint(test_view,url_prefix = "/protocolTools/test_view")
app.register_blueprint(P_m300Protocol_view,url_prefix = "/m300Tools/P_m300Protocol_view")
app.register_blueprint(P_m300Protocol_process,url_prefix = "/m300Tools/P_m300Protocol_process")
app.register_blueprint(msgSetting_view,url_prefix = "/messageTools/msgSetting_view")
app.register_blueprint(msgSetting_process,url_prefix = "/messageTools/msgSetting_process")
......
......@@ -6,8 +6,12 @@ function m300ProtocolManTab(e){
var id = $(e).attr("id");
if(id == "P_heartBeat_m300_msg"){
$(location).attr('href', "http://" + window.location.host + "/m300Tools/P_m300Protocol_view/P_heartBeat_m300_page");
}else if(id == "userDefined_protocol"){
$(location).attr('href', "http://" + window.location.host + "/protocolTools/protocolReport_view/userDefined_protocol_page");
}else if(id == "socketSetting"){
$(location).attr('href', "http://" + window.location.host + "/m300Tools/P_m300Protocol_view/socketSetting_page");
}else if(id == "P_login_m300_msg"){
$(location).attr('href', "http://" + window.location.host + "/m300Tools/P_m300Protocol_view/P_login_m300_page");
}else if(id == "P_version_m300_msg"){
$(location).attr('href', "http://" + window.location.host + "/m300Tools/P_m300Protocol_view/P_version_m300_page");
}else{
alert(id)
}
......
......@@ -32,25 +32,23 @@
<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="socketSetting" {% if arg.path[2]=="socketSetting_page" %} class="link-tab" {% endif %} onclick="m300ProtocolManTab(this)">设置</b></a></li>
<li role="presentation"><a id="P_heartBeat_m300_msg" {% if arg.path[2]=="P_heartBeat_m300_page" %} class="link-tab" {% endif %} onclick="m300ProtocolManTab(this)">心跳消息</b></a></li>
<li role="presentation"><a id="P_login_m300_msg" {% if arg.path[2]=="P_login_m300_page" %} class="link-tab" {% endif %} onclick="m300ProtocolManTab(this)">登录消息</b></a></li>
<li role="presentation"><a id="P_version_m300_msg" {% if arg.path[2]=="P_version_m300_page" %} class="link-tab" {% endif %} onclick="m300ProtocolManTab(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%;_background:green;padding:5px;padding-top:0px;">
<h3 style="border-bottom: 1px solid #eee;">设置消息头:</h3>
<label>消息ID:</label><input id="msgID" type="text" class="form-control" disabled="disabled" value="0002" style="width:80px;">
<label>终端手机号:</label><input id="phoneNum" type="text" class="form-control" value="13146201119" style="width:150px;">
<label>消息流水号:</label><input id="msgWaterCode" type="text" class="form-control" value="1" style="width:60px;">
<label>功能ID:</label><input id="FUNID" type="text" class="form-control" disabled="disabled" value="0004" style="width:80px;">
<label>消息序列号:</label><input id="waterCode" type="text" class="form-control" value="1" style="width:60px;">
<label>设备ID:</label><input id="DEV_ID" type="text" class="form-control" value="M202004070000" style="width:150px;">
<label>是否加密:</label><select style="width:100px;" id="encryptionType" class="form-control">
<option value="0">不加密</option>
<option value="1024">加密</option>
</select>
<label>有无分包:</label><select style="width:80px;" id="subPkg" class="form-control" onchange="hasSubPkg()">
<option value="0"></option>
<option value="8192"></option>
</select>
<label id="subPkg_label" style="color:grey;">分包个数:</label><input disabled="disabled" id="pkgCounts" type="text" class="form-control" value="0" style="width:60px;">
</div>
<H3 style="border-bottom: 1px solid #eee;">设置心跳消息内容:</H3>
<ul class="protocol_content" style="padding:0px;">
......@@ -71,40 +69,31 @@
<script>
//发送GPS数据
$("#sendMsgBtn").click(function(){
var msgID = $("#msgID").val();
var phoneNum = $("#phoneNum").val();
var msgWaterCode = $("#msgWaterCode").val();
var FUNID = $("#FUNID").val();
var waterCode = $("#waterCode").val();
var DEV_ID = $("#DEV_ID").val();
var encryptionType = $("#encryptionType").val();
var subPkg = $("#subPkg").val();
var pkgCounts = ""
if (subPkg != "8192"){
pkgCounts = "0"
}else{
pkgCounts = $("#pkgCounts").val();
}
var data = {};
data["msgID"] = msgID;
data["phoneNum"] = phoneNum;
data["msgWaterCode"] = msgWaterCode;
data["FUNID"] = FUNID;
data["waterCode"] = waterCode;
data["DEV_ID"] = DEV_ID;
data["encryptionType"] = encryptionType;
data["subPkg"] = subPkg;
data["pkgCounts"] = pkgCounts;
var host = window.location.host;
$("#showFeedback").val("")
$.ajax({
url:"http://" + host + "/messageTools/message_process/porcessHeartBeatMsg",
url:"http://" + host + "/m300Tools/P_m300Protocol_process/porcessHeartBeatMsg",
type:"post",
data:data,
dataType:"json",
success:function(data){
if(data.status == 200){
//window.location.reload()
var theShow = "原始数据: " + data.original + "\n";
var theShow = "原始数据: " + data.msgSend + "\n";
theShow = theShow + "收到数据: " + data.result + "\n";
theShow = theShow + "收到数据16进制: " + data.resultH + "\n";
theShow = theShow + "解析数据: " + JSON.stringify(data.parse) + "\n";
theShow = theShow + "收到数据16进制: " + data.rev + "\n";
theShow = theShow + "解析数据: " + JSON.stringify(data.orgRev) + "\n";
$("#showFeedback").val(theShow)
}else{
$("#showFeedback").val(data.message)
......@@ -113,17 +102,6 @@
}
});
});
function hasSubPkg(){
value = $("#subPkg").val()
if(value == "8192"){
$("#subPkg_label").css("color","black")
$("#pkgCounts").removeAttr("disabled")
}else{
$("#subPkg_label").css("color","grey")
$("#pkgCounts").attr("disabled","disabled")
}
}
</script>
{% endblock %}
</div>
......
{% extends "m300Tools/report/P_heartBeat_m300_page.html" %}
{% block title %}login_msg{% 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%;_background:green;padding:5px;padding-top:0px;">
<h3 style="border-bottom: 1px solid #eee;">设置消息头:</h3>
<label>功能ID:</label><input id="FUNID" type="text" class="form-control" disabled="disabled" value="00ff" style="width:80px;">
<label>消息序列号:</label><input id="waterCode" type="text" class="form-control" value="1" style="width:60px;">
<label>设备ID:</label><input id="DEV_ID" type="text" class="form-control" value="M202004070000" style="width:150px;">
<label>是否加密:</label><select style="width:100px;" id="encryptionType" class="form-control">
<option value="0">不加密</option>
<option value="1024">加密</option>
</select>
</div>
<H3 style="border-bottom: 1px solid #eee;">设置心跳消息内容:</H3>
<ul class="protocol_content" style="padding:0px;">
<label style="color:red;width:130px;">登录消息无消息体...</label>
</ul>
<H3 style="border-bottom: 1px solid #eee;">控制:</H3>
<div style="width:100%;padding:5px;margin-top:10px;">
<button type="button" class="btn btn-primary" id="sendMsgBtn">发送消息</button>
</div>
<H3 style="border-bottom: 1px solid #eee;">返回信息:</H3>
<div style="width:100%;padding:5px;margin-top:10px;">
<textarea id="showFeedback" style="width:100%;padding:5px;" rows="8"></textarea>
</div>
</div>
<script>
//发送GPS数据
$("#sendMsgBtn").click(function(){
var FUNID = $("#FUNID").val();
var waterCode = $("#waterCode").val();
var DEV_ID = $("#DEV_ID").val();
var encryptionType = $("#encryptionType").val();
var data = {};
data["FUNID"] = FUNID;
data["waterCode"] = waterCode;
data["DEV_ID"] = DEV_ID;
data["encryptionType"] = encryptionType;
var host = window.location.host;
$("#showFeedback").val("")
$.ajax({
url:"http://" + host + "/m300Tools/P_m300Protocol_process/porcessLoginMsg",
type:"post",
data:data,
dataType:"json",
success:function(data){
if(data.status == 200){
//window.location.reload()
var theShow = "原始数据: " + data.msgSend + "\n";
theShow = theShow + "收到数据: " + data.result + "\n";
theShow = theShow + "收到数据16进制: " + data.rev + "\n";
theShow = theShow + "解析数据: " + JSON.stringify(data.orgRev) + "\n";
$("#showFeedback").val(theShow)
}else{
$("#showFeedback").val(data.message)
alert(data.message);
}
}
});
});
</script>
{% endblock %}
\ No newline at end of file
{% extends "m300Tools/report/P_heartBeat_m300_page.html" %}
{% block title %}version_msg{% 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%;_background:green;padding:5px;padding-top:0px;">
<h3 style="border-bottom: 1px solid #eee;">设置消息头:</h3>
<label>功能ID:</label><input id="FUNID" type="text" class="form-control" disabled="disabled" value="0007" style="width:80px;">
<label>消息序列号:</label><input id="waterCode" type="text" class="form-control" value="1" style="width:60px;">
<label>设备ID:</label><input id="DEV_ID" type="text" class="form-control" value="M202004070000" style="width:150px;">
<label>是否加密:</label><select style="width:100px;" id="encryptionType" class="form-control">
<option value="0">不加密</option>
<option value="1024">加密</option>
</select>
</div>
<H3 style="border-bottom: 1px solid #eee;">设置心跳消息内容:</H3>
<ul class="protocol_content" style="padding:0px;">
<li><label>软件版本号:</label><input id="SWVersion" type="text" class="form-control" value="VSTA000GV100"></li>
<li><label>软件日期:</label><input id="SWDate" type="text" class="form-control" value="2020-03-30"></li>
<li><label>硬件版本:</label><input id="HWVersion" type="text" class="form-control" value="M1.0"></li>
<li><label>GSM 型号:</label><input id="GSMType" type="text" class="form-control" value="GSM_type_123456"></li>
<li><label>车系车型ID:</label><input id="carType" type="text" class="form-control" value="150D"></li>
<li><label style="word-break:break-all;font-size:12px;">发动机编码类别:</label><input id="engineCode" type="text" class="form-control" value="1"></li>
<li style="width:350px;"><label style="word-break:break-all;font-size:12px;">汽车VIN码或发动机ECU编码:</label><input style="width:250px;" id="VINCode" type="text" class="form-control" value="VIN_CODE_01234567890"></li>
</ul>
<H3 style="border-bottom: 1px solid #eee;">控制:</H3>
<div style="width:100%;padding:5px;margin-top:10px;">
<button type="button" class="btn btn-primary" id="sendMsgBtn">发送消息</button>
</div>
<H3 style="border-bottom: 1px solid #eee;">返回信息:</H3>
<div style="width:100%;padding:5px;margin-top:10px;">
<textarea id="showFeedback" style="width:100%;padding:5px;" rows="8"></textarea>
</div>
</div>
<script>
//发送GPS数据
$("#sendMsgBtn").click(function(){
var FUNID = $("#FUNID").val();
var waterCode = $("#waterCode").val();
var DEV_ID = $("#DEV_ID").val();
var encryptionType = $("#encryptionType").val();
var SWVersion = $("#SWVersion").val();
var SWDate = $("#SWDate").val();
var HWVersion = $("#HWVersion").val();
var GSMType = $("#GSMType").val();
var carType = $("#carType").val();
var engineCode = $("#engineCode").val();
var VINCode = $("#VINCode").val();
var data = {};
data["FUNID"] = FUNID;
data["waterCode"] = waterCode;
data["DEV_ID"] = DEV_ID;
data["encryptionType"] = encryptionType;
data["SWVersion"] = SWVersion;
data["SWDate"] = SWDate;
data["HWVersion"] = HWVersion;
data["GSMType"] = GSMType;
data["carType"] = carType;
data["engineCode"] = engineCode;
data["VINCode"] = VINCode;
var host = window.location.host;
$("#showFeedback").val("")
$.ajax({
url:"http://" + host + "/m300Tools/P_m300Protocol_process/porcessVersionMsg",
type:"post",
data:data,
dataType:"json",
success:function(data){
if(data.status == 200){
//window.location.reload()
var theShow = "原始数据: " + data.msgSend + "\n";
theShow = theShow + "收到数据: " + data.result + "\n";
theShow = theShow + "收到数据16进制: " + data.rev + "\n";
theShow = theShow + "解析数据: " + JSON.stringify(data.orgRev) + "\n";
$("#showFeedback").val(theShow)
}else{
$("#showFeedback").val(data.message)
alert(data.message);
}
}
});
});
</script>
{% endblock %}
\ No newline at end of file
{% extends "m300Tools/report/P_heartBeat_m300_page.html" %}
{% block title %}setting_page{% 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%;_background:green;padding:5px;padding-top:0px;">
<h3 style="border-bottom: 1px solid #eee;">连接设置:</h3>
<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;">
</div>
<H3 style="border-bottom: 1px solid #eee;">控制:</H3>
<div style="width:100%;padding:5px;margin-top:10px;">
<button type="button" class="btn btn-primary" id="saveSetting">保存设置</button>
</div>
</div>
<script>
//保存设置数据
$("#saveSetting").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 + "/m300Tools/P_m300Protocol_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
......@@ -62,7 +62,7 @@
var host = window.location.host;
$.ajax({
url:"http://" + host + "/protocolTools/setting_process/porcessSocketSetting",
url:"http://" + host + "/protocolTools/setting_process/socketSetting_page",
type:"post",
data:data,
dataType:"json",
......
#coding:utf-8
from flask import Blueprint ,Response,request
from configparser import ConfigParser
from lib.protocol.m300.Heartbeat_protocol_300 import Heartbeat_protocol_300
from lib.protocol.m300.Login_protocol_m300 import Login_protocol_m300
from lib.protocol.m300.VersionInfo_protocol_m300 import VersionInfo_protocol_m300
from lib.protocol.m300Plateform.M300Common_res import M300Common_res
from lib.protocol.m300Plateform.M300Login_res import M300Login_res
from lib.protocol.reportPlateform.Common_res import Common_res
from lib.socket.ClientSocket import ClientSocket
import json
import traceback
import binascii
P_m300Protocol_process = Blueprint('P_m300Protocol_process', __name__)
##########################################
# 【接口类型】保存设置
##########################################
@P_m300Protocol_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/m300Tools/m300Tools.conf")
conf_W = conf_R
conf_W["socket"]["host"] = host
conf_W["socket"]["port"] = port
with open("config/m300Tools/m300Tools.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')
##########################################
# 【接口类型】处理发送的心跳上报报文
##########################################
@P_m300Protocol_process.route("/porcessHeartBeatMsg",methods=['POST'])
def porcessHeartBeatMsg():
FUNID = request.form.get("FUNID")
waterCode = int(request.form.get("waterCode"))
DEV_ID = request.form.get("DEV_ID")
encryptionType = int(request.form.get("encryptionType"))
data = {}
if (waterCode == None or DEV_ID == None or encryptionType == None):
data["status"] = "4003"
data["message"] = "Info: 请检查是否传入了空数据!"
return Response(json.dumps(data), mimetype='application/json')
else:
try:
conf_R = ConfigParser()
conf_R.read("config/m300Tools/m300Tools.conf")
cliSocket = ClientSocket(conf_R.get("socket", "host"),conf_R.getint("socket", "port"))
cliSocket.connect()
heartBeatProtocolObj = Heartbeat_protocol_300(waterCode = waterCode,DEV_ID = DEV_ID,encryptionType=encryptionType)
msg = heartBeatProtocolObj.generateMsg()
cliSocket.send(msg)
socRecv = cliSocket.receive()
socRecvo = str(socRecv)
cliSocket.close()
data["status"] = "200"
data["message"] = "Sucess: "
data["msgSend"] = msg
data["result"] = socRecvo
data["rev"] = str(binascii.b2a_hex(socRecv))[2:][:-1]
data["orgRev"] = json.loads(M300Common_res(data["rev"]).getMsg())
except BaseException as e:
# 打印异常信息
traceback.print_exc()
data["status"] = "4003"
data["message"] = "Error: 处理失败!"
return Response(json.dumps(data), mimetype='application/json')
##########################################
# 【接口类型】处理发送的登录上报报文
##########################################
@P_m300Protocol_process.route("/porcessLoginMsg",methods=['POST'])
def porcessLoginMsg():
FUNID = request.form.get("FUNID")
waterCode = int(request.form.get("waterCode"))
DEV_ID = request.form.get("DEV_ID")
encryptionType = int(request.form.get("encryptionType"))
data = {}
if (waterCode == None or DEV_ID == None or encryptionType == None):
data["status"] = "4003"
data["message"] = "Info: 请检查是否传入了空数据!"
return Response(json.dumps(data), mimetype='application/json')
else:
try:
conf_R = ConfigParser()
conf_R.read("config/m300Tools/m300Tools.conf")
cliSocket = ClientSocket(conf_R.get("socket", "host"),conf_R.getint("socket", "port"))
cliSocket.connect()
protocolObj = Login_protocol_m300(waterCode = waterCode,DEV_ID = DEV_ID,encryptionType=encryptionType)
msg = protocolObj.generateMsg()
cliSocket.send(msg)
socRecv = cliSocket.receive()
socRecvo = str(socRecv)
cliSocket.close()
data["status"] = "200"
data["message"] = "Sucess: "
data["msgSend"] = msg
data["result"] = socRecvo
data["rev"] = str(binascii.b2a_hex(socRecv))[2:][:-1]
data["orgRev"] = json.loads(M300Login_res(data["rev"]).getMsg())
except BaseException as e:
# 打印异常信息
traceback.print_exc()
data["status"] = "4003"
data["message"] = "Error: 处理失败!"
return Response(json.dumps(data), mimetype='application/json')
##########################################
# 【接口类型】处理发送的登录上报报文
##########################################
@P_m300Protocol_process.route("/porcessVersionMsg",methods=['POST'])
def porcessVersionMsg():
FUNID = request.form.get("FUNID")
waterCode = int(request.form.get("waterCode"))
DEV_ID = request.form.get("DEV_ID")
encryptionType = int(request.form.get("encryptionType"))
SWVersion = request.form.get("SWVersion")
SWDate = request.form.get("SWDate")
HWVersion = request.form.get("HWVersion")
GSMType = request.form.get("GSMType")
carType = request.form.get("carType")
engineCode = int(request.form.get("engineCode"))
VINCode = request.form.get("VINCode")
data = {}
if (waterCode == None or DEV_ID == None or encryptionType == None or SWVersion == None or SWDate == None or HWVersion == None \
or GSMType == None or carType == None or engineCode == None or VINCode == None):
data["status"] = "4003"
data["message"] = "Info: 请检查是否传入了空数据!"
return Response(json.dumps(data), mimetype='application/json')
else:
try:
conf_R = ConfigParser()
conf_R.read("config/m300Tools/m300Tools.conf")
cliSocket = ClientSocket(conf_R.get("socket", "host"),conf_R.getint("socket", "port"))
cliSocket.connect()
protocolObj = VersionInfo_protocol_m300(waterCode = waterCode,DEV_ID = DEV_ID,encryptionType=encryptionType,SWVersion=SWVersion \
,SWDate=SWDate,HWVersion=HWVersion,GSMType=GSMType,carType=carType,engineCode=engineCode,VINCode=VINCode)
msg = protocolObj.generateMsg()
cliSocket.send(msg)
socRecv = cliSocket.receive()
socRecvo = str(socRecv)
cliSocket.close()
data["status"] = "200"
data["message"] = "Sucess: "
data["msgSend"] = msg
data["result"] = socRecvo
data["rev"] = str(binascii.b2a_hex(socRecv))[2:][:-1]
data["orgRev"] = json.loads(M300Common_res(data["rev"]).getMsg())
except BaseException as e:
# 打印异常信息
traceback.print_exc()
data["status"] = "4003"
data["message"] = "Error: 处理失败!"
return Response(json.dumps(data), mimetype='application/json')
\ No newline at end of file
......@@ -7,7 +7,27 @@ import re
P_m300Protocol_view = Blueprint('P_m300Protocol_view', __name__)
##########################################
# 【视图类型】访问侧车机模拟器页面
# 【视图类型】访问socket设置页面
##########################################
@P_m300Protocol_view.route('/socketSetting_page')
def socketSetting_page():
#获取请求的路劲
url = request.url
reqPath = re.findall("http://(.*)$",url)[0]
reqPath = re.findall("/(.*)$", reqPath)[0]
arg = {}
path = "m300Tools/report/socketSetting_page.html"
arg["path"] = reqPath.split("/")
arg["socket"] = {}
# 读取config文件
conf_R = ConfigParser()
conf_R.read("config/m300Tools/m300Tools.conf")
arg["socket"]["host"] = conf_R.get("socket", "host")
arg["socket"]["port"] = conf_R.getint("socket", "port")
return render_template(path,arg=arg)
##########################################
# 【视图类型】访问心跳协议页面
##########################################
@P_m300Protocol_view.route('/P_heartBeat_m300_page')
def P_heartBeat_m300_page():
......@@ -19,3 +39,31 @@ def P_heartBeat_m300_page():
path = "m300Tools/report/P_heartBeat_m300_page.html"
arg["path"] = reqPath.split("/")
return render_template(path,arg=arg)
##########################################
# 【视图类型】访问登录协议页面
##########################################
@P_m300Protocol_view.route('/P_login_m300_page')
def P_login_m300_page():
#获取请求的路劲
url = request.url
reqPath = re.findall("http://(.*)$",url)[0]
reqPath = re.findall("/(.*)$", reqPath)[0]
arg = {}
path = "m300Tools/report/P_login_m300_page.html"
arg["path"] = reqPath.split("/")
return render_template(path,arg=arg)
##########################################
# 【视图类型】访问版本协议页面
##########################################
@P_m300Protocol_view.route('/P_version_m300_page')
def P_version_m300_page():
#获取请求的路劲
url = request.url
reqPath = re.findall("http://(.*)$",url)[0]
reqPath = re.findall("/(.*)$", reqPath)[0]
arg = {}
path = "m300Tools/report/P_version_m300_page.html"
arg["path"] = reqPath.split("/")
return render_template(path,arg=arg)
\ No newline at end of file
......@@ -9,7 +9,7 @@ import traceback
setting_process = Blueprint('setting_process', __name__)
##########################################
# 【接口类型】处理发送的GPS上报报文
# 【接口类型】保持设置
##########################################
@setting_process.route("/porcessSocketSetting",methods=['POST'])
def porcessSocketSetting():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment