Commit 29757da2 authored by liyuanhong's avatar liyuanhong

自定义消息页面开发完成

parent 405993b9
[socket]
host = 10.100.12.32
host = 10.100.5.251
port = 9008
......@@ -74,6 +74,8 @@ class ClientSocket(SocketBase):
return self.socketId
def getSocketStatus(self):
return self.status
def setTimeOut(self,data):
self.timeOut = data
if __name__ == "__main__":
client = ClientSocket()
......
#coding: utf-8
import logging
import threading
import time
from time import sleep
from lib.socket.SocketBase import SocketBase
from lib.socket.websocket_server import WebsocketServer
class MyWebsocket_server(SocketBase):
class Websocket_service(SocketBase):
def __init__(self,host="127.0.0.1",port=5005):
self.connectTimeout = 5 #设置socket服务启动之后的连接超时时间
self.connectTimeoutstatus = 0 #设置socket服务启动之后是否有连接,0为为收到连接,1:为已经收到了连接
self.msgTimeout = 12 #设置12秒没有收到任何消息之后,就关闭连接
self.host = host
self.port = port
self.connectNums = 0 #连接数
def setConnectTimeout(self,data):
self.connectTimeout = data
def setMsgTimeout(self,data):
self.msgTimeout = data
def setHost(self,data):
self.host = data
def setPort(self,data):
self.port = data
def startWebsocketServer(self):
......@@ -31,8 +42,6 @@ class MyWebsocket_server(SocketBase):
#收到消息之后的恢复消息方法
def mysend(self,client,server,msg):
print(msg)
self.msgTimeout = 12
server.send_message(client,"message send ...")
if(msg == "_end"): #收到_end 控制码的时候,断开连接
server.server_close()
......@@ -50,9 +59,12 @@ class MyWebsocket_server(SocketBase):
# 超过时间没有客户端连接,自动断开连接方法
###################################################
def doConnectTomeout(self,server):
while self.connectTimeout > 0:
startTime = int(time.time())
endTime = int(time.time())
while endTime - startTime < self.connectTimeout:
self.connectTimeout -= 1
sleep(1)
endTime = int(time.time())
sleep(0.1)
if self.connectTimeoutstatus == 0:
server.server_close()
print("连接断开...")
......@@ -78,17 +90,8 @@ class MyWebsocket_server(SocketBase):
server.server_close()
print("连接断开...")
if __name__ == "__main__":
w = Websocket_service()
w.setHost("127.0.0.1")
w.setPort(5005)
w.startWebsocketServer()
\ No newline at end of file
......@@ -6,6 +6,8 @@ function protocolManTab(e){
var id = $(e).attr("id");
if(id == "heartBeat_protocol"){
$(location).attr('href', "http://" + window.location.host + "/protocolTools/protocolReport_view/heartBeat_protocol_page");
}else if(id == "userDefined_protocol"){
$(location).attr('href', "http://" + window.location.host + "/protocolTools/protocolReport_view/userDefined_protocol_page");
}else if(id == "login_protocol"){
$(location).attr('href', "http://" + window.location.host + "/protocolTools/protocolReport_view/login_protocol_page");
}else if(id == "GPS_protocol"){
......@@ -17,4 +19,5 @@ function protocolManTab(e){
}else{
alert(id)
}
}
\ No newline at end of file
}
......@@ -31,6 +31,7 @@
<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="userDefined_protocol" {% if arg.path[2]=="userDefined_protocol_page" %} class="link-tab" {% endif %} onclick="protocolManTab(this)">自定义报文</b></a></li>
<li role="presentation"><a id="heartBeat_protocol" {% if arg.path[2]=="heartBeat_protocol_page" %} class="link-tab" {% endif %} onclick="protocolManTab(this)">心跳报文</b></a></li>
<li role="presentation"><a id="login_protocol" {% if arg.path[2]=="login_protocol_page" %} class="link-tab" {% endif %} onclick="protocolManTab(this)">终端登录报文</b></a></li>
<li role="presentation"><a id="GPS_protocol" {% if arg.path[2]=="GPS_protocol_page" %} class="link-tab" {% endif %} onclick="protocolManTab(this)">GPS报文</b></a></li>
......
......@@ -42,14 +42,14 @@
</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="connect_B" type="button" class="btn btn-primary" onclick="connect()">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>
<button id="unConnect_B" type="button" class="btn btn-primary" onclick="stopConnect()">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>
......@@ -58,9 +58,37 @@
</div>
<script>
<script>
function connect(){
data = {};
url = "/protocolTools/M_carSimulater_process/createConect";
send(data,url);
}
function stopConnect(){
data = {};
url = "/protocolTools/M_carSimulater_process/closeConect";
send(data,url);
}
</script>
function send(data,url){
var host = window.location.host;
$.ajax({
//url:"http://" + host + "/protocolTools/M_carSimulater_process/porcessSocketSetting",
url:"http://" + host + url,
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 %}
</div>
{% endblock %}
\ No newline at end of file
{% extends "protocolTools/report/GPS_protocol_page.html" %}
{% block title %}heartBeat_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;">
<H3 style="border-bottom: 1px solid #eee;">输入消息内容:</H3>
<div style="width:100%;padding:5px;margin-top:10px;">
<textarea id="msg" style="width:100%;padding:5px;" rows="5"></textarea>
</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="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>
//发送心跳数据包
$("#sendMsgBtn").click(function(){
var msg = $("#msg").val();
var data = {};
data["msg"] = msg;
var host = window.location.host;
$("#showFeedback").val("")
$.ajax({
url:"http://" + host + "/protocolTools/protocolReport_process/porcessUserdefinedMsg",
type:"post",
data:data,
dataType:"json",
success:function(data){
if(data.status == 200){
//window.location.reload()
msg = "发送消息:" + data.msgSend + "\n"
msg = msg + "收到消息:" + data.result + "\n"
msg = msg + "收到消息16进制:" + data.rev + "\n"
msg = msg + "收到消息解析结果:" + JSON.stringify(data.orgRev) + "\n"
$("#showFeedback").val(msg)
}else{
$("#showFeedback").val(data.message)
alert(data.message);
}
}
});
});
</script>
{% endblock %}
\ No newline at end of file
......@@ -82,6 +82,7 @@ def createConect():
traceback.print_exc()
data["status"] = "4003"
data["message"] = "Error: 处理失败!"
return Response(json.dumps(data), mimetype='application/json')
##########################################
......@@ -103,4 +104,5 @@ def closeConect():
# 打印异常信息
traceback.print_exc()
data["status"] = "4003"
data["message"] = "Error: 处理失败!"
\ No newline at end of file
data["message"] = "Error: 处理失败!"
return Response(json.dumps(data), mimetype='application/json')
\ No newline at end of file
......@@ -7,7 +7,7 @@ import re
M_carSimulater_view = Blueprint('M_carSimulater_view', __name__)
##########################################
# 【视图类型】访问心跳协议报文发送页面
# 【视图类型】访问侧车机模拟器页面
##########################################
@M_carSimulater_view.route('/M_carSimulater_page')
def M_carSimulater_page():
......@@ -21,7 +21,7 @@ def M_carSimulater_page():
return render_template(path,arg=arg)
##########################################
# 【视图类型】访问心跳协议报文发送页面
# 【视图类型】访问模拟器设置页面
##########################################
@M_carSimulater_view.route('/M_setting_page')
def M_setting_page():
......
......@@ -18,6 +18,42 @@ import binascii
protocolReport_process = Blueprint('protocolReport_process', __name__)
##########################################
# 【接口类型】处理发送的自定义报文
##########################################
@protocolReport_process.route("/porcessUserdefinedMsg",methods=['POST'])
def porcessUserdefinedMsg():
msg = request.form.get("msg")
data = {}
if (msg == None):
data["status"] = "4003"
data["message"] = "Info: 请检查是否传入了空数据!"
return Response(json.dumps(data), mimetype='application/json')
else:
try:
conf_R = ConfigParser()
conf_R.read("config/protocolTools/protocolTools.conf")
cliSocket = ClientSocket(conf_R.get("socket", "host"),conf_R.getint("socket", "port"))
cliSocket.connect()
cliSocket.send(msg)
cliSocket.setTimeOut(500)
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(Common_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')
##########################################
# 【接口类型】处理发送的心跳上报报文
##########################################
......
......@@ -5,6 +5,20 @@ import re
protocolReport_view = Blueprint('protocolReport_view', __name__)
##########################################
# 【视图类型】访问自定义报文发送页面
##########################################
@protocolReport_view.route('/userDefined_protocol_page')
def userDefined_protocol_page():
#获取请求的路劲
url = request.url
reqPath = re.findall("http://(.*)$",url)[0]
reqPath = re.findall("/(.*)$", reqPath)[0]
arg = {}
path = "protocolTools/report/userDefined_protocol_page.html"
arg["path"] = reqPath.split("/")
return render_template(path,arg=arg)
##########################################
# 【视图类型】访问心跳协议报文发送页面
##########################################
......
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