Commit 17d49215 authored by liyuanhong's avatar liyuanhong

终端登录图形界面开发完成

parent 6109db68
......@@ -258,12 +258,12 @@ class Location_msg(MessageBase):
#######################################################
# 获取海拔高度
#######################################################
def getElevation(self,data=520):
def getElevation(self,data=521):
dataHex = self.int2hexStringByBytes(data, 2)
return dataHex
#######################################################
# 获取海拔高
# 获取
#######################################################
def getSpeed(self,data=66):
dataHex = self.int2hexStringByBytes(data, 2)
......@@ -297,7 +297,7 @@ class Location_msg(MessageBase):
msgID = "0200"
msgBodyProperty = self.getMsgBodyProperty(int(len(self.getMsgBody()) / 2)) #消息体属性
phoneNum = self.int2BCD(13146201119) #终端手机号
msgWaterCode = self.int2BCD(1) #消息流水号
msgWaterCode = self.int2hexStringByBytes(1,2) #消息流水号
subPkgContent = "" #消息包封装项
data = msgID + msgBodyProperty + phoneNum + msgWaterCode + subPkgContent
return data
......
......@@ -44,6 +44,20 @@ class MessageBase(Base):
data = msgID + msgBodyProperty + phoneNum + msgWaterCode + subPkgContent
return data
#获取消息头,针对图形界面,可传递参数
def getMsgHeader_GUI(self,msgID,phoneNum,msgWaterCode,encryptionType,subPkg): #消息id
msgID = msgID
subPkg = subPkg
msgBodyProperty = self.getMsgBodyProperty_GUI(msgBodyLen=int(len(self.getMsgBody()) / 2),encryptionType=encryptionType,subPkg=subPkg) #消息体属性
phoneNum = self.int2BCD(phoneNum) #终端手机号
msgWaterCode = self.int2hexStringByBytes(msgWaterCode,2) #消息流水号
if subPkg != 8192:
subPkgContent = "" #消息包封装项
else:
subPkgContent = self.getMsgPackage()
data = msgID + msgBodyProperty + phoneNum + msgWaterCode + subPkgContent
return data
#获取消息体属性
def getMsgBodyProperty(self,msgBodyLen=128,encryptionType=0,subPkg=0):
if msgBodyLen >= 512:
......@@ -56,6 +70,18 @@ class MessageBase(Base):
dataHex = self.int2hexStringByBytes(data,2)
return dataHex
#获取消息体属性,针对图形界面,可传递参数
def getMsgBodyProperty_GUI(self,msgBodyLen=128,encryptionType=0,subPkg=0):
if msgBodyLen >= 512:
raise RuntimeError('消息体长度超长!')
msgBodyLen = msgBodyLen #消息体长度
encryptionType = encryptionType #加密方式
subPkg = subPkg #分包
retain = 0 #保留位
data = msgBodyLen + encryptionType + subPkg + retain
dataHex = self.int2hexStringByBytes(data,2)
return dataHex
#获取消息封装项
def getMsgPackage(self):
pkgCounts = 2 #消息报包总数
......
......@@ -26,6 +26,19 @@ class TerminalHeartbeat_msg(MessageBase):
msg = msg + self.IDENTIFY
return msg
# 生成一条完整的消息,针对图形界面,可传递参数
def generateMsg_GUI(self,msgID="0002",phoneNum="13146201119",msgWaterCode=1,encryptionType=0,subPkg=0):
msg = ""
msgHeader = self.getMsgHeader_GUI(msgID,phoneNum,msgWaterCode,encryptionType,subPkg)
msgBody = self.getMsgBody()
checkCode = self.getCheckCode(msgHeader + msgBody)
msg = msg + self.IDENTIFY
info = msgHeader + msgBody + checkCode
info = self.replace7e7d(info)
msg = msg + info
msg = msg + self.IDENTIFY
return msg
#######################################################
# 获取消息体
#######################################################
......@@ -62,6 +75,18 @@ class TerminalHeartbeat_msg(MessageBase):
dataHex = self.int2hexStringByBytes(data,2)
return dataHex
#获取消息体属性,针对图形界面,可传递参数
def getMsgBodyProperty_GUI(self,msgBodyLen=128,encryptionType=0,subPkg=0):
if msgBodyLen >= 512:
raise RuntimeError('消息体长度超长!')
msgBodyLen = msgBodyLen #消息体长度
encryptionType = encryptionType #加密方式
subPkg = subPkg #分包
retain = 0 #保留位
data = msgBodyLen + encryptionType + subPkg + retain
dataHex = self.int2hexStringByBytes(data,2)
return dataHex
if __name__ == "__main__":
print(TerminalHeartbeat_msg().generateMsg())
......
......@@ -26,6 +26,21 @@ class TerminalRegister_msg(MessageBase):
msg = msg + self.IDENTIFY
return msg
# 生成一条完整的消息,针对图形界面,可传递参数
def generateMsg_GUI(self,msgID="0100",phoneNum="13146201119",msgWaterCode=1,encryptionType=0,subPkg=0,provinceId="0103",\
manufacturerId="11010",terminalType="a865h643gfdj64fd7432",terminalId="H6uyt08", \
licencePlateColor=1,carSign="渝B23CX"):
msg = ""
msgHeader = self.getMsgHeader_GUI(msgID,phoneNum,msgWaterCode,encryptionType,subPkg)
msgBody = self.getMsgBody_GUI(provinceId,manufacturerId,terminalType,terminalId,licencePlateColor,carSign)
checkCode = self.getCheckCode(msgHeader + msgBody)
msg = msg + self.IDENTIFY
info = msgHeader + msgBody + checkCode
info = self.replace7e7d(info)
msg = msg + info
msg = msg + self.IDENTIFY
return msg
#######################################################
# 获取消息体
#######################################################
......@@ -51,6 +66,30 @@ class TerminalRegister_msg(MessageBase):
msg = msg + provinceId + manufacturerId + terminalType + terminalId + licencePlateColor + carSign
return msg
# 获取消息体,针对图形界面,可传递参数
def getMsgBody_GUI(self,provinceId="0103",manufacturerId="11010",terminalType="a865h643gfdj64fd7432",terminalId="H6uyt08", \
licencePlateColor=1,carSign="渝B23CX"):
msg = ""
# msgNums = self.int2hexStringByBytes(1,2)
# msgNumber = self.int2hexStringByBytes(1,2)
#市县域 ID (标示终端安装车辆所在的省域,0 保留,由平台取默认值。省 域 ID 采用 GB/T 2260 中规定的行政区划代 码六位中前两)
provinceId = "0103"
#制造商 ID (5 个字节,终端制造商编码)
manufacturerId = self.str2Hex("11010")
#终端型号 (20 个字节,此终端型号由制造商自行定义,位数不足时,后 补“0X00”。)
terminalType = self.str2Hex("a865h643gfdj64fd7432")
#终端 ID (7 个字节,由大写字母和数字组成,此终端 ID 由制造商自行 定义,位数不足时,后补“0X00”)
terminalId = self.str2Hex("H6uyt08")
#车牌颜色 (车牌颜色,按照 JT/T415-2006 的 5.4.12。未上牌时,取值 为 0) 1:蓝色 2:黄色 3:黑色 4:白色 9:其他
licencePlateColor = self.int2hexStringByBytes(1)
#车辆标识 (车牌颜色为 0 时,表示车辆 VIN;否则,表示公安交通管理 部门颁发的机动车号牌)
carSign = str("渝B23CX".encode("gbk"))
carSign = carSign[2:len(carSign) - 1]
carSign = self.str2Hex(carSign)
# msg = msg + msgNums + msgNumber
msg = msg + provinceId + manufacturerId + terminalType + terminalId + licencePlateColor + carSign
return msg
#######################################################
# 获取消息头
#######################################################
......@@ -76,5 +115,17 @@ class TerminalRegister_msg(MessageBase):
dataHex = self.int2hexStringByBytes(data,2)
return dataHex
#获取消息体属性,针对图形界面,可传递参数
def getMsgBodyProperty_GUI(self,msgBodyLen=128,encryptionType=0,subPkg=0):
if msgBodyLen >= 512:
raise RuntimeError('消息体长度超长!')
msgBodyLen = msgBodyLen #消息体长度
encryptionType = encryptionType #加密方式
subPkg = subPkg #分包
retain = 0 #保留位
data = msgBodyLen + encryptionType + subPkg + retain
dataHex = self.int2hexStringByBytes(data,2)
return dataHex
if __name__ == "__main__":
print(TerminalRegister_msg().generateMsg())
\ No newline at end of file
#coding:utf-8
import binascii
import socket
from time import sleep
from lib.protocol.LocationDataBatchUpdate_msg import LocationDataBatchUpdate_msg
from lib.protocol.message.DataUpstreamTransport_msg import DataUpstreamTransport_msg
from lib.protocol.message.LocationDataBatchUpdate_msg import LocationDataBatchUpdate_msg
from lib.protocol.message.Location_msg import Location_msg
from lib.protocol.message.MessageBase import MessageBase
from lib.protocol.message.QueryTerminalParam_res import QueryTerminalParam_res
from lib.protocol.message.QueryTerminalProperty_res import QueryTerminalProperty_res
from lib.protocol.message.TerminalAuthenticate_msg import TerminalAuthenticate_msg
from lib.protocol.message.TerminalCommonMsgRes_msg import TerminalCommonMsgRes_msg
from lib.protocol.message.TerminalHeartbeat_msg import TerminalHeartbeat_msg
from lib.protocol.message.TerminalRegister_msg import TerminalRegister_msg
from lib.protocol.message.TerminalUpdateResult_msg import TerminalUpdataResult_msg
from lib.protocol.message.TerminalVersionInfo_msg import TerminalVersionInfo_msg
from lib.protocol.message.data.TerminalCancle_msg import TerminalCancle_msg
from lib.protocol.messagePlateform.PlatformCommon_res import PlatformCommon_res
from lib.protocol.messagePlateform.TerminalRegister_res import TerminalRegister_res
......@@ -25,7 +18,7 @@ port = 9001
# msg = MessageBase().generateMsg()
# msg = TerminalCommonMsgRes_msg().generateMsg() #终端通用应答
# msg = TerminalHeartbeat_msg().generateMsg() #终端心跳
# msg = TerminalRegister_msg().generateMsg() #终端注册
msg = TerminalRegister_msg().generateMsg() #终端注册
# msg = TerminalCancle_msg().generateMsg() #终端注销
# msg = TerminalAuthenticate_msg().generateMsg() #终端鉴权
# msg = TerminalVersionInfo_msg().generateMsg() #终端版本信息上报
......@@ -34,7 +27,7 @@ port = 9001
# msg = Location_msg().generateMsg() #位置信息汇报
# msg = DataUpstreamTransport_msg().generateMsg() #数据上行透传消息
# msg = TerminalUpdataResult_msg().generateMsg() #终端升级结果通知
msg = LocationDataBatchUpdate_msg().generateMsg() #定位数据批量上传
# msg = LocationDataBatchUpdate_msg().generateMsg() #定位数据批量上传
#发送单条消息
def sendSingleMsg(msg):
......@@ -48,8 +41,8 @@ def sendSingleMsg(msg):
# client.send(bytes.fromhex(msg))
data = client.recv(BUF_SIZE)
print(data)
print(PlatformCommon_res(data).getMsg()) #终端通用应答消息
# print(TerminalRegister_res(data).getMsg()) #终端注册应答消息
print(PlatformCommon_res(data).getMsg()) #解析平台通用应答消息
# print(TerminalRegister_res(data).getMsg()) #解析终端注册应答消息
client.close()
def closeSocket(soc):
......
/**
*messages 页面顶部的协议切换
*/
function messageManTab(e){
var url = window.location.href;
var id = $(e).attr("id");
if(id == "terminalHeartBeat_msg"){
$(location).attr('href', "http://" + window.location.host + "/messageTools/message_view/heartBeat_msg_page");
}else if(id == "terminalRegister_msg"){
$(location).attr('href', "http://" + window.location.host + "/messageTools/message_view/terminalRegister_msg_page");
}else{
alert(id)
}
}
\ No newline at end of file
{% extends "messageTools/index.html" %}
{% block title %}heartBeat_msg{% endblock %}
{% block content_01 %}
<script src="../../static/js/protocolTools/protocols.js"></script>
<script src="../../static/js/messageTools/messages.js"></script>
<style>
.nav-pills li {
margin-bottom:5px;
......@@ -27,22 +27,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="heartBeat_protocol" {% if arg.path[2]=="heartBeat_msg_page" %} class="link-tab" {% endif %} onclick="protocolManTab(this)">心跳消息</b></a></li>
<li role="presentation"><a id="style_index2" {% if arg.path[2]=="2" %} class="link-tab" {% endif %} onclick="protocolManTab(this)">其他报文</b></a></li>
<li role="presentation"><a id="terminalHeartBeat_msg" {% if arg.path[2]=="heartBeat_msg_page" %} class="link-tab" {% endif %} onclick="messageManTab(this)">心跳消息</b></a></li>
<li role="presentation"><a id="terminalRegister_msg" {% if arg.path[2]=="terminalRegister_msg_page" %} class="link-tab" {% endif %} onclick="messageManTab(this)">终端注册</b></a></li>
<li role="presentation"><a id="style_index2" {% if arg.path[2]=="2" %} class="link-tab" {% endif %} onclick="messageManTab(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" value="0002" style="width:80px;">
<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>是否加密:</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">
<label>有无分包:</label><select style="width:80px;" id="subPkg" class="form-control" onchange="hasSubPkg()">
<option value="0"></option>
<option value="8192"></option>
</select>
......@@ -107,6 +108,17 @@
}
});
});
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 "messageTools/message/heartBeat_msg_page.html" %}
{% block title %}terminalRegister_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="msgID" type="text" class="form-control" disabled="disabled" value="0100" 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>是否加密:</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;">
<li><label>市县域ID:</label><input id="provinceId" type="text" class="form-control" value="0103"></li>
<li><label>制造商ID:</label><input id="manufacturerId" type="text" class="form-control" value="11010"></li>
<li style="width:500px;"><label>终端型号:</label><input style="width:320px;" id="terminalType" type="text" class="form-control" value="a865h643gfdj64fd7432"></li>
<li><label>终端ID:</label><input id="terminalId" type="text" class="form-control" value="H6uyt08"></li>
<li><label>车牌颜色:</label><input id="licencePlateColor" type="text" class="form-control" value="1"></li>
<li><label>车辆标识:</label><input id="carSign" type="text" class="form-control" value="渝B23CX"></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 msgID = $("#msgID").val();
var phoneNum = $("#phoneNum").val();
var msgWaterCode = $("#msgWaterCode").val();
var encryptionType = $("#encryptionType").val();
var subPkg = $("#subPkg").val();
var pkgCounts = ""
if (subPkg != "8192"){
pkgCounts = "0"
}else{
pkgCounts = $("#pkgCounts").val();
}
var provinceId = $("#provinceId").val();
var manufacturerId = $("#manufacturerId").val();
var terminalType = $("#terminalType").val();
var terminalId = $("#terminalId").val();
var licencePlateColor = $("#licencePlateColor").val();
var carSign = $("#carSign").val();
var data = {};
data["msgID"] = msgID;
data["phoneNum"] = phoneNum;
data["msgWaterCode"] = msgWaterCode;
data["encryptionType"] = encryptionType;
data["subPkg"] = subPkg;
data["pkgCounts"] = pkgCounts;
data["provinceId"] = provinceId;
data["manufacturerId"] = manufacturerId;
data["terminalType"] = terminalType;
data["terminalId"] = terminalId;
data["licencePlateColor"] = licencePlateColor;
data["carSign"] = carSign;
var host = window.location.host;
$.ajax({
url:"http://" + host + "/messageTools/message_process/porcessTerminalRegisterMsg",
type:"post",
data:data,
dataType:"json",
success:function(data){
if(data.status == 200){
//window.location.reload()
var theShow = "原始数据: " + data.original + "\n";
theShow = theShow + "收到数据: " + data.result + "\n";
theShow = theShow + "解析数据: " + JSON.stringify(data.parse) + "\n";
$("#showFeedback").val(theShow)
}else{
$("#showFeedback").val(data.message)
alert(data.message);
}
}
});
});
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 %}
\ No newline at end of file
......@@ -4,6 +4,7 @@ from flask import Blueprint ,Response,request
from configparser import ConfigParser
from lib.protocol.message.TerminalHeartbeat_msg import TerminalHeartbeat_msg
from lib.protocol.message.TerminalRegister_msg import TerminalRegister_msg
from lib.protocol.messagePlateform.PlatformCommon_res import PlatformCommon_res
from lib.protocol.report.HeartBeatReport_protocol import HeartBeatReport_protocol
......@@ -20,11 +21,11 @@ message_process = Blueprint('message_process', __name__)
@message_process.route("/porcessHeartBeatMsg",methods=['POST'])
def porcessHeartBeatMsg():
msgID = request.form.get("msgID")
phoneNum = request.form.get("phoneNum")
msgWaterCode = request.form.get("msgWaterCode")
encryptionType = request.form.get("encryptionType")
subPkg = request.form.get("subPkg")
pkgCounts = request.form.get("pkgCounts")
phoneNum = int(request.form.get("phoneNum"))
msgWaterCode = int(request.form.get("msgWaterCode"))
encryptionType = int(request.form.get("encryptionType"))
subPkg = int(request.form.get("subPkg"))
pkgCounts = int(request.form.get("pkgCounts"))
data = {}
......@@ -39,7 +40,58 @@ def porcessHeartBeatMsg():
cliSocket = ClientSocket(conf_R.get("socket", "host"),conf_R.getint("socket", "port"))
cliSocket.connect()
heartBeatmsgObj = TerminalHeartbeat_msg()
msg = heartBeatmsgObj.generateMsg()
msg = heartBeatmsgObj.generateMsg_GUI(msgID,phoneNum,msgWaterCode,encryptionType,subPkg)
cliSocket.send(msg)
socRecv_1 = cliSocket.receive()
socRecv_2 = str(socRecv_1)
cliSocket.close()
data["status"] = "200"
data["message"] = "Sucess: "
data["original"] = msg
data["result"] = socRecv_2
data["parse"] = PlatformCommon_res(socRecv_1).getMsg()
except BaseException as e:
# 打印异常信息
traceback.print_exc()
data["status"] = "4003"
data["message"] = "Error: 处理失败!"
return Response(json.dumps(data), mimetype='application/json')
##########################################
# 【接口类型】处理发送的终端注册消息
##########################################
@message_process.route("/porcessTerminalRegisterMsg",methods=['POST'])
def porcessTerminalRegisterMsg():
msgID = request.form.get("msgID")
phoneNum = int(request.form.get("phoneNum"))
msgWaterCode = int(request.form.get("msgWaterCode"))
encryptionType = int(request.form.get("encryptionType"))
subPkg = int(request.form.get("subPkg"))
pkgCounts = int(request.form.get("pkgCounts"))
provinceId = request.form.get("provinceId")
manufacturerId = request.form.get("manufacturerId")
terminalType = request.form.get("terminalType")
terminalId = request.form.get("terminalId")
licencePlateColor = int(request.form.get("licencePlateColor"))
carSign = request.form.get("carSign")
data = {}
if (msgID == None or phoneNum == None or msgWaterCode == None or encryptionType == None or subPkg == None \
or pkgCounts == None or provinceId == None or manufacturerId == None or terminalType == None \
or terminalId == None or licencePlateColor == None or carSign == None):
data["status"] = "4003"
data["message"] = "Info: 请检查是否传入了空数据!"
return Response(json.dumps(data), mimetype='application/json')
else:
try:
conf_R = ConfigParser()
conf_R.read("config/messageTools/messageTools.conf")
cliSocket = ClientSocket(conf_R.get("socket", "host"),conf_R.getint("socket", "port"))
cliSocket.connect()
terminalRegisterObj = TerminalRegister_msg()
msg = terminalRegisterObj.generateMsg_GUI(msgID,phoneNum,msgWaterCode,encryptionType,subPkg,provinceId,\
manufacturerId,terminalType,terminalId,licencePlateColor,carSign)
cliSocket.send(msg)
socRecv_1 = cliSocket.receive()
socRecv_2 = str(socRecv_1)
......
......@@ -18,3 +18,17 @@ def heartBeat_msg_page():
path = "messageTools/message/heartBeat_msg_page.html"
arg["path"] = reqPath.split("/")
return render_template(path,arg=arg)
##########################################
# 【视图类型】访问终端注册消息发送页面
##########################################
@message_view.route('/terminalRegister_msg_page')
def terminalRegister_msg_page():
#获取请求的路劲
url = request.url
reqPath = re.findall("http://(.*)$",url)[0]
reqPath = re.findall("/(.*)$", reqPath)[0]
arg = {}
path = "messageTools/message/terminalRegister_msg_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