Commit c6cea661 authored by liyuanhong's avatar liyuanhong

添加了M300模拟程序的导航

parent 2776862b
[socket]
host = 10.100.12.32
port = 9009
{"time": {"dateTime": "2020-05-19 11:09:47", "date": "2020-05-19", "time": "11:09:47"}, "curDayTravel": {"todayTotalMilleage": 40924, "todayTotalOil": 3769, "todayTotalTime": 2477, "theMilleage": 1452, "theOil": 132, "theTime": 88}, "travelData": {"totalMilleage": 324661, "totalOil": 30616, "totalTime": 19259}, "event": {"threeRapid": {"totalRapidlyAccelerate": 14, "totalSharpSlowdown": 13, "totalSharpTurn": 13}}}
\ No newline at end of file
{"time": {"dateTime": "2020-05-20 16:26:10", "date": "2020-05-20", "time": "16:26:10"}, "curDayTravel": {"todayTotalMilleage": 3845, "todayTotalOil": 350, "todayTotalTime": 233, "theMilleage": 3845, "theOil": 350, "theTime": 233}, "travelData": {"totalMilleage": 328506, "totalOil": 30966, "totalTime": 19492}, "event": {"threeRapid": {"totalRapidlyAccelerate": 14, "totalSharpSlowdown": 13, "totalSharpTurn": 13}}}
\ No newline at end of file
#encoding:utf-8
from lib.protocol.m300.GPS_protocol_m300 import GPS_protocol_m300
from lib.protocol.m300.M300Base import M300Base
from lib.protocol.m300.OBDCAN_protocol_m300 import OBDCAN_protocol_m300
'''
定义报警协议类
......@@ -9,6 +10,7 @@ from lib.protocol.m300.M300Base import M300Base
class Alarm_protocol_m300(M300Base):
def __init__(self,waterCode = 3,DEV_ID = "M121501010001",encryptionType=0,alarmType="0001",data = {}):
super().__init__() # 不执行该方法,无法使用父类里面定义的属性
self.data = data
self.waterCode = waterCode #消息流水号
self.DEV_ID = DEV_ID #设备Id
self.encryptionType = encryptionType # 消息属性里面的是否加密字段
......@@ -19,8 +21,18 @@ class Alarm_protocol_m300(M300Base):
self.GSMPkg = "0000000000"
self.CANStatus = "ffffffffffffffffffff00000000000000000000"
else:
pass
GPSData = data["GPSData"]
GSMData = data["GSMData"]
OBDData = data["OBDCANData"]
self.alarm = data["alarm"]
self.GPSPkg = GPS_protocol_m300(dateInfo=GPSData["dateInfo"],latitude=float(GPSData["latitude"]),longitude=float(GPSData["longitude"]) \
,positionStar=int(GPSData["positionStar"]),speed=float(GPSData["speed"]),direction=float(GPSData["direction"]), \
altitude=float(GPSData["altitude"]),ACCStatus=int(GPSData["ACCStatus"]),valtage=float(GPSData["valtage"]),OBDSpeed=float(GPSData["OBDSpeed"]), \
valid=int(GPSData["valid"]) ,tripMark=int(GPSData["tripMark"])).getMsgBody()
self.GSMPkg = self.getGSMPkg(operatorType=int(GSMData["operatorType"]),LAC=GSMData["LAC"],CellId=GSMData["CellId"])
self.CANStatus = OBDCAN_protocol_m300(statusMask=OBDData["statusMask"],safeStatus=int(OBDData["safeStatus"]),doorStatus=int(OBDData["doorStatus"]), \
lockStatus=int(OBDData["lockStatus"]),windowStatus=int(OBDData["windowStatus"]),lightStatus=int(OBDData["lightStatus"]), \
swichStatusA=int(OBDData["swichStatusA"]),swichStatusB=int(OBDData["swichStatusB"])).getMsgBody()[14:48] + "000000"
#################################################
# 生成消息
......@@ -30,7 +42,10 @@ class Alarm_protocol_m300(M300Base):
FUNID = "0021" #功能id
waterCode = self.int2hexStringByBytes(self.waterCode,2) #消息流水号
DEV_ID = self.devid2hexString(self.DEV_ID) #设备id
msgBody = self.getMsgBody() # 消息体
if len(self.data) == 0:
msgBody = self.getMsgBody() # 消息体
else:
msgBody = self.getMsgBody_GUI() # 消息体
msgLen = int(len(msgBody) / 2)
property = self.getMsgProperty(msgBodyLen=msgLen,encryptionType=self.encryptionType)
checkCode = self.getCheckCode(FUNID + waterCode + DEV_ID + property + msgBody)
......@@ -53,6 +68,33 @@ class Alarm_protocol_m300(M300Base):
alarmContent = "0002" + self.int2hexStringByBytes(int(len(extra)/2)) + extra
return GPSPkg + GSMPkg + CANStatus + alarmContent
def getMsgBody_GUI(self):
GPSPkg = self.GPSPkg
GSMPkg = self.GSMPkg
CANStatus = self.CANStatus
alarmContent = ""
if (list(self.alarm.keys())[0] == "0001"): #汽车点火上报
extra = ""
alarmContent = "0001" + self.int2hexStringByBytes(int(len(extra)/2)) + extra
elif (list(self.alarm.keys())[0] == "0002"): #汽车熄火上报
extra = ""
alarmContent = "0002" + self.int2hexStringByBytes(int(len(extra)/2)) + extra
return GPSPkg + GSMPkg + CANStatus + alarmContent
#################################################
# 获取GSM信息
##############################################
def getGSMPkg(self,operatorType=1,LAC="1234",CellId="5678"):
#运营商类别 1-移动 2-联通 3-电信
operatorType = self.int2hexStringByBytes(operatorType)
# u16 服务器 LAC + CellID,比如 1234 5678
# LAC和CellID各占两个字节
LAC = self.int2hexStringByBytes(int(LAC),2)
CellId = self.int2hexStringByBytes(int(CellId),2)
data = operatorType + LAC + CellId
return data
if __name__ == "__main__":
print(Alarm_protocol_m300().generateMsg())
......
......@@ -8,7 +8,7 @@ from lib.protocol.m300.M300Base import M300Base
class VersionInfo_protocol_m300(M300Base):
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"):
,GSMType="GSM_type_123456",carType="150",engineCode=1,VINCode="VIN_CODE_01234567890"):
super().__init__() # 不执行该方法,无法使用父类里面定义的属性
self.waterCode = waterCode #消息流水号
self.DEV_ID = DEV_ID #设备Id
......@@ -18,7 +18,7 @@ class VersionInfo_protocol_m300(M300Base):
self.SWDate = SWDate #软件日期
self.HWVersion = HWVersion #硬件版本
self.GSMType = GSMType #GSM 型号
self.carType = carType #车系车型ID: 150D
self.carType = int(carType) #车系车型ID: 150D
self.engineCode = engineCode #发动机编码类别
self.VINCode = VINCode #汽车VIN码 或 发动机ECU编码
......@@ -47,7 +47,7 @@ class VersionInfo_protocol_m300(M300Base):
SWDate = self.str2Hex(self.SWDate)
HWVersion = self.str2Hex(self.HWVersion)
GSMType = self.str2Hex(self.GSMType)
carType = self.str2Hex(self.carType)
carType = self.int2hexStringByBytes(self.carType,2)
engineCode = self.int2hexStringByBytes(self.engineCode)
VINCode = self.str2Hex(self.VINCode)
data = SWVersion + SWDate + HWVersion + GSMType + carType + engineCode + VINCode
......
......@@ -12,8 +12,8 @@ class GPRS_protocol_response_m300(M300Base):
"username":"yuanhong","password":"123456"},{"serverIndex":"3","serverAddressType":0,"serverAddress":"10.100.12.31","comPort":"9008","comType":0,"APN":"tnet", \
"username":"yuanhong","password":"123456"}]
def __init__(self,waterCode = 3,DEV_ID = "M121501010001",encryptionType=0,data=[{"serverIndex":"1","serverAddressType":0,"serverAddress":"10.100.12.31","comPort":"9008","comType":0,"APN":"tnet", \
"username":"yuanhong","password":"123456"},{"serverIndex":"2","serverAddressType":0,"serverAddress":"10.100.12.31","comPort":"9008","comType":0,"APN":"tnet", \
"username":"yuanhong","password":"123456"},{"serverIndex":"3","serverAddressType":0,"serverAddress":"10.100.12.31","comPort":"9008","comType":0,"APN":"tnet", \
"username":"yuanhong","password":"123456"},{"serverIndex":"2","serverAddressType":0,"serverAddress":"10.100.12.32","comPort":"9008","comType":0,"APN":"tnet", \
"username":"yuanhong","password":"123456"},{"serverIndex":"3","serverAddressType":0,"serverAddress":"10.100.12.33","comPort":"9008","comType":0,"APN":"tnet", \
"username":"yuanhong","password":"123456"}]):
super().__init__() # 不执行该方法,无法使用父类里面定义的属性
self.waterCode = waterCode #消息流水号
......@@ -42,6 +42,8 @@ class GPRS_protocol_response_m300(M300Base):
#################################################
def getMsgBody(self):
dataHex = ""
lenHex = self.int2hexStringByBytes(len(self.data))
dataHex = dataHex + lenHex
for i in range(0,len(self.data)):
dataHex = dataHex + self.str2Hex(self.data[i]["serverIndex"]) #服务器索引号,从1开始
dataHex = dataHex + "2c" #逗号
......
......@@ -2,6 +2,7 @@
import binascii
import socket
from lib.protocol.m300.Alarm_protocol_m300 import Alarm_protocol_m300
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
......@@ -32,7 +33,8 @@ port = 9009
# msg = GPS_protocol_m300().generateMsg() #GPS报文
# msg = VersionInfo_protocol_m300().generateMsg() #终端版本报文
# msg = "7e000400e14d2019120315000000957e" #终端上报心跳协议
msg = OBDCAN_protocol_m300().generateMsg() #OBD CAN报文
# msg = OBDCAN_protocol_m300().generateMsg() #OBD CAN报文
msg = Alarm_protocol_m300().generateMsg() #OBD CAN报文
print(msg)
......
This diff is collapsed.
#coding:utf-8
'''
M300车机模拟服务简易测试程序,用于做临时测试
'''
import binascii
import json
import math
import os
import threading
import time
import traceback
from time import sleep
from lib.protocol.m300.Alarm_protocol_m300 import Alarm_protocol_m300
from lib.protocol.m300.GPS_protocol_m300 import GPS_protocol_m300
from lib.protocol.m300.Login_protocol_m300 import Login_protocol_m300
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.m300.response.GPRS_protocol_response_m300 import GPRS_protocol_response_m300
from lib.protocol.message.Location_msg import Location_msg
from lib.protocol.message.TerminalCommonMsgRes_msg import TerminalCommonMsgRes_msg
from lib.protocol.message.TerminalRegister_msg import TerminalRegister_msg
from lib.protocol.message.TerminalVersionInfo_msg import TerminalVersionInfo_msg
from lib.socket.ClientSocket import ClientSocket
from lib.socket.service.M300SimulaterDataService import M300SimulaterDataService
from lib.socket.service.MessageSimulaterDataService import MessageSimulaterDataService
from lib.socket.service.websocket_service import Websocket_service
class M300SimulaterService():
def __init__(self):
self.data = {} #用来接收模拟器传过来的参数
self.carData = {} #保存车辆行驶数据
self.carDataObj = None #管理车辆行驶数据对象
self.socket = None
self.sendDur = 5 #设置默认多久发一条消息
self.serviceStatus = 0 #服务状态,0表示未启动,1表示启动
self.websocket = None #网页与服务的通信socket
self.websocketId = "" #当前连接的webSocketId
self.timeout = 3600 #socket的超时时间
self.gpsLine = [] #GPS 轨迹
self.gpsLineIndex = 0 #GPS 轨迹索引
self.travelStatus = 0 #0,表示未行驶,1表示开始行驶同时开启了接收消息服务,2表示值开启了接收消息的服务
self.carId = "M121501010001" #车机号
self.sn = 1 #消息流水号
self.travelDirection = 0 #行驶方向,0表示正向行驶,1表示反向行驶
self.directAngle = 60 #汽车方向角
#######################################################
# type 为0表示正常发送,type为1表示数据写入本地
#######################################################
def sendMsg(self,msg):
self.socket.setTimeOut(self.timeout)
self.socket.send(msg)
type = self.getMsgFunId(msg)
print("发送消息:" + type + ">>>>" + msg)
def revMsg(self):
self.socket.setTimeOut(self.timeout)
return self.socket.receive()
#发送消息,可指定消息的描述类型
def serviceSendMsg(self,msg,type): #type字段目前废掉没有实际意
self.sendMsg(msg)
def connect(self,host,port):
cliSocket = ClientSocket(host, port)
cliSocket.setTimeOut(self.timeout)
cliSocket.connect()
self.socket = cliSocket
self.startRevService()
def login(self):
loginObj = Login_protocol_m300(waterCode = self.sn,DEV_ID = self.carId,encryptionType=0)
loginMsg = loginObj.generateMsg()
self.sendMsg(loginMsg)
self.sn = self.sn +1
time.sleep(1)
versionObj = VersionInfo_protocol_m300(waterCode = self.sn,DEV_ID = self.carId,encryptionType=0,SWVersion="VSTA000GV100", \
SWDate="2020-03-30",HWVersion="M1.0",GSMType="GSM_type_123456",carType="150", \
engineCode=1,VINCode="VIN_CODE_01234567890")
versionMsg = versionObj.generateMsg()
self.sendMsg(versionMsg)
self.sn = self.sn + 1
time.sleep(1)
def serviceRev(self):
self.serviceStatus = 2 #2代表只启动了接收消息的进程,1代表了接收和发送都启动了
while self.serviceStatus != 0:
self.socket.setTimeOut(self.timeout)
d = self.revMsg()
d = str(binascii.b2a_hex(d))[2:][:-1]
type = self.getMsgFunId(d)
print("收到消息:" + type + "<<<<" + d)
self.doResponse(d)
#启动接收消息服务
def startRevService(self):
t2 = threading.Thread(target=self.serviceRev, args=())
t2.start()
#获取收到消息的功能id
def getMsgFunId(self,msg):
funId = msg[2:6]
return funId
#收到 某些类型的消息后执行回复操作
def doResponse(self,msg):
msgFunId = self.getMsgFunId(msg)
if msgFunId == "8104":
msg = GPRS_protocol_response_m300().generateMsg()
self.sendMsg(msg)
self.sn = self.sn + 1
if __name__ == "__main__":
service = M300SimulaterService()
service.connect("10.100.12.32",9009)
time.sleep(1)
service.login()
......@@ -71,7 +71,7 @@ class MessageSimulaterService():
def setData(self,data):
self.data = data
def setWebsocketId(self):
sleep(1)
sleep(0.1)
self.websocketId = self.websocket.getCurrentClientId()
def getWebsocket(self):
return self.websocket
......
......@@ -376,16 +376,6 @@ class ProtocolSimulaterService():
self.OBDdataOri["totalRunTime"] = conJson["travelData"]["totalTime"]
self.carData = self.carDataObj.fixDataTemplate(conJson)
# fireOnEventObj = EventReport_protocol(DEV_ID=self.carId,WATER_CODE=self.sn)
# gpsData = self.genGPSData(self.gpsLine[0]["lat"], self.gpsLine[0]["lng"])
# fireOnEventObj.setGPSPkg(gpsData)
# fireOnEventObj.setEventType("0010")
# firOnEventMsg = fireOnEventObj.generateEventMsg()
# type = self.getMsgFunId(firOnEventMsg)
# self.sendMsg(firOnEventMsg)
# self.sn = self.sn + 1
# self.websocket.sendMsgToClient(type + ">>>>:" + firOnEventMsg,self.websocketId)
jdata = {"WATER_CODE": "0003", "DEV_ID": "M121501010001",
"gpsInfo": {"UTCTime": "2020-04-30 14:59:33", "latitude": "40.22077", "longitude": "116.23128",
"speed": "80.8", "directionAngle": "80.8", "elevation": "2999.9", "positionStar": "3",
......@@ -432,16 +422,6 @@ class ProtocolSimulaterService():
if gpsLineIndex >= len(self.gpsLine):
gpsLineIndex = gpsLineIndex - 1
# fireOffEventObj = EventReport_protocol(DEV_ID=self.carId)
# gpsData = self.genGPSData(self.gpsLine[gpsLineIndex]["lat"],self.gpsLine[gpsLineIndex]["lng"])
# fireOffEventObj.setGPSPkg(gpsData)
# fireOffEventObj.setEventType("0011")
# fireOffEventMsg = fireOffEventObj.generateEventMsg()
# type = self.getMsgFunId(fireOffEventMsg)
# self.sendMsg(fireOffEventMsg)
# self.sn = self.sn + 1
# self.websocket.sendMsgToClient(type + ">>>>:" + fireOffEventMsg,self.websocketId)
jdata = {"WATER_CODE": "0003", "DEV_ID": "M121501010001",
"gpsInfo": {"UTCTime": "2020-04-30 14:59:33", "latitude": "40.22077", "longitude": "116.23128",
"speed": "80.8", "directionAngle": "80.8", "elevation": "2999.9", "positionStar": "3",
......
......@@ -10,6 +10,8 @@ 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.m300Tools.M_m300Simulater_view import M_m300Simulater_view
from views.m300Tools.M_m300Simulater_process import M_m300Simulater_process
from views.messageTools.msgSetting_view import msgSetting_view
from views.messageTools.msgSetting_process import msgSetting_process
......@@ -29,6 +31,8 @@ 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(M_m300Simulater_view,url_prefix = "/m300Tools/M_m300Simulater_view")
app.register_blueprint(M_m300Simulater_process,url_prefix = "/m300Tools/M_m300Simulater_process")
app.register_blueprint(msgSetting_view,url_prefix = "/messageTools/msgSetting_view")
app.register_blueprint(msgSetting_process,url_prefix = "/messageTools/msgSetting_process")
......
/**
*m300simulater 页面顶部的tab切换
*/
function m300SimulaterTab(e){
var url = window.location.href;
var id = $(e).attr("id");
if(id == "m300simulater_tab"){
$(location).attr('href', "http://" + window.location.host + "/m300Tools/M_m300Simulater_view/M_m300Simulater_page");
}else if(id == "m300_setting_tab"){
$(location).attr('href', "http://" + window.location.host + "/m300Tools/M_m300Simulater_view/M_m300Setting_page");
}else{
alert(id)
}
}
\ No newline at end of file
......@@ -21,8 +21,8 @@
var id = $(e).attr("id")
if(id == "m300_msg_send"){
$(location).attr('href', "http://" + window.location.host + "/m300Tools/P_m300Protocol_view/P_heartBeat_m300_page");
}else if(id == "icon"){
$(location).attr('href', "http://" + window.location.host + "/tab1/icon");
}else if(id == "m300_simulater"){
$(location).attr('href', "http://" + window.location.host + "/m300Tools/M_m300Simulater_view/M_m300Simulater_page");
}
}
</script>
......@@ -33,7 +33,7 @@
<li id="m300_msg_send" onclick="swichLeftTab(this)"><a {% if arg.path[1]=="P_m300Protocol_view" %} class="active_left_tab" {% endif %}><span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span> m300单消息发送<span class="sr-only"></span></a></li>
</ul>
<ul class="nav nav-sidebar" style="margin-top:20px;">
<li><a><span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span> 其他页面</a></li>
<li id="m300_simulater" onclick="swichLeftTab(this)"><a {% if arg.path[1]=="M_m300Simulater_view" %} class="active_left_tab" {% endif %}><span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span> m300模拟器</a></li>
</ul>
</div>
{% endblock %}
......
{% extends "m300Tools/report/M_m300Simulater_page.html" %}
{% block title %}m300Setting_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%;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 + "/m300Tools/M_m300Simulater_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
This diff is collapsed.
......@@ -16,18 +16,18 @@
<H3 style="border-bottom: 1px solid #eee;">设置GPS消息内容:</H3>
<ul class="protocol_content" style="padding:0px;">
<li><label>日期:</label><input id="dateInfo" type="text" class="form-control" value=""></li>
<li style="width:495px;"><label>维度:</label><sapn>
<li style="width:495px;"><label>维度:</label><span>
<input id="latitude" type="text" class="form-control" value="40.22077">
<select style="width:80px;" id="latitudeType" class="form-control">
<option value="0">北纬</option>
<option value="1">南纬</option></select>
</sapn></li>
<li style="width:495px;"><label>经度:</label><sapn>
</span></li>
<li style="width:495px;"><label>经度:</label><span>
<input id="longitude" type="text" class="form-control" value="116.23128">
<select style="width:80px;" id="longitudeType" class="form-control">
<option value="0">东经</option>
<option value="1">西经</option></select>
</sapn></li>
</span></li>
<li><label>定位星数:</label><input id="positionStar" type="text" class="form-control" value="2"></li>
<li><label>速度:</label><input id="speed" type="text" class="form-control" value="66.0"></li>
<li><label>方向角:</label><input id="direction" type="text" class="form-control" value="55.3"></li>
......
......@@ -19,7 +19,7 @@
<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>车系车型ID:</label><input id="carType" type="text" class="form-control" value="150"></li>
<li><label style="word-break:break-all;font-size:10px;">发动机编码类别:</label><input id="engineCode" type="text" class="form-control" value="1"></li>
<li style="width:350px;"><label style="word-break:break-all;font-size:10px;">汽车VIN码或发动机ECU编码:</label><input style="width:250px;" id="VINCode" type="text" class="form-control" value="VIN_CODE_01234567890"></li>
</ul>
......
#coding:utf-8
from flask import Blueprint ,Response,request
from configparser import ConfigParser
import json
import traceback
M_m300Simulater_process = Blueprint('M_m300Simulater_process', __name__)
connects = {} #用来保存连接的信息s
websocket = None #保存创建的websocket
##########################################
# 【接口类型】设置socket信息
##########################################
@M_m300Simulater_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/m300Simulater.conf")
conf_W = conf_R
conf_W["socket"]["host"] = host
conf_W["socket"]["port"] = port
with open("config/m300Tools/m300Simulater.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')
\ No newline at end of file
#coding:utf-8
from configparser import ConfigParser
from flask import Blueprint, render_template ,request
import re
from lib.util import fileUtil
M_m300Simulater_view = Blueprint('M_m300Simulater_view', __name__)
##########################################
# 【视图类型】访问车机模拟器页面
##########################################
@M_m300Simulater_view.route('/M_m300Simulater_page')
def M_m300Simulater_page():
#获取请求的路劲
url = request.url
reqPath = re.findall("http://(.*)$",url)[0]
reqPath = re.findall("/(.*)$", reqPath)[0]
arg = {}
path = "m300Tools/report/M_m300Simulater_page.html"
arg["path"] = reqPath.split("/")
arg["gpsLines"] = fileUtil.getDirFilesListMap("data/protocolTools/GPSLines")
return render_template(path,arg=arg)
##########################################
# 【视图类型】访问模拟器设置页面
##########################################
@M_m300Simulater_view.route('/M_m300Setting_page')
def M_m300Setting_page():
#获取请求的路劲
url = request.url
reqPath = re.findall("http://(.*)$",url)[0]
reqPath = re.findall("/(.*)$", reqPath)[0]
arg = {}
path = "m300Tools/report/M_m300Setting_page.html"
arg["path"] = reqPath.split("/")
arg["socket"] = {}
# 读取config文件
conf_R = ConfigParser()
conf_R.read("config/m300Tools/m300Simulater.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
......@@ -3,6 +3,7 @@
from flask import Blueprint ,Response,request
from configparser import ConfigParser
from lib.protocol.m300.Alarm_protocol_m300 import Alarm_protocol_m300
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.Login_protocol_m300 import Login_protocol_m300
......@@ -16,6 +17,8 @@ import json
import traceback
import binascii
from lib.util.jsonUtil import hasJsonDataIsNone
P_m300Protocol_process = Blueprint('P_m300Protocol_process', __name__)
##########################################
......@@ -364,4 +367,42 @@ def porcessCANMsg():
traceback.print_exc()
data["status"] = "4003"
data["message"] = "Error: 处理失败!"
return Response(json.dumps(data), mimetype='application/json')
##########################################
# 【接口类型】处理发送的报警报文
##########################################
@P_m300Protocol_process.route("/porcessAlarmMsg",methods=['POST'])
def porcessAlarmMsg():
params = request.get_data()
params = json.loads(params.decode("utf-8"))
data = {}
if (hasJsonDataIsNone(params)):
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 = Alarm_protocol_m300(waterCode=int(params["waterCode"]),DEV_ID=params["DEV_ID"],encryptionType=int(params["encryptionType"]), \
alarmType=list(params["alarm"].keys())[0],data=params)
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
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