Commit cb0493a0 authored by liyuanhong's avatar liyuanhong

修改了新硬件,消息长度不对的bug

parent 6c14a8a6
[socket]
host = v.vandyo.cn
port = 9018
......@@ -32,8 +32,8 @@ class DataUpstreamTransport_msg(MessageBase):
# 生成一条完整的消息,针对图形界面,可传递参数
def generateMsg_GUI(self,msgID="0100",phoneNum="13146201119",msgWaterCode=1,encryptionType=0,subPkg=0,msgType="F3",data={"infoTime":"2020-02-06 11:31:56"}):
msg = ""
msgHeader = self.getMsgHeader_GUI(msgID,phoneNum,msgWaterCode,encryptionType,subPkg)
msgBody = self.getMsgBody_GUI(msgType,data)
msgHeader = self.getMsgHeader_GUI(msgID, phoneNum, msgWaterCode, encryptionType, subPkg,msgBody)
checkCode = self.getCheckCode(msgHeader + msgBody)
msg = msg + self.IDENTIFY
info = msgHeader + msgBody + checkCode
......
......@@ -38,8 +38,9 @@ class Location_msg(MessageBase):
# 生成一条完整的消息,针对图形界面,可传递参数
def generateMsg_GUI(self,params):
msg = ""
msgHeader = self.getMsgHeader_GUI(params["msgID"],int(params["phoneNum"]),int(params["msgWaterCode"]),int(params["encryptionType"]),int(params["subPkg"]))
msgBody = self.getMsgBody_GUI(params)
msgHeader = self.getMsgHeader_GUI(params["msgID"], int(params["phoneNum"]), int(params["msgWaterCode"]),
int(params["encryptionType"]), int(params["subPkg"]),msgBody)
checkCode = self.getCheckCode(msgHeader + msgBody)
msg = msg + self.IDENTIFY
info = msgHeader + msgBody + checkCode
......
......@@ -47,10 +47,10 @@ class MessageBase(Base):
return data
#获取消息头,针对图形界面,可传递参数
def getMsgHeader_GUI(self,msgID,phoneNum,msgWaterCode,encryptionType,subPkg): #消息id
def getMsgHeader_GUI(self,msgID,phoneNum,msgWaterCode,encryptionType,subPkg,msgBody=""): #消息id
msgID = msgID
subPkg = subPkg
msgBodyProperty = self.getMsgBodyProperty_GUI(msgBodyLen=int(len(self.getMsgBody()) / 2),encryptionType=encryptionType,subPkg=subPkg) #消息体属性
msgBodyProperty = self.getMsgBodyProperty_GUI(msgBodyLen=int(len(msgBody) / 2),encryptionType=encryptionType,subPkg=subPkg) #消息体属性
phoneNum = self.int2BCD(phoneNum) #终端手机号
msgWaterCode = self.int2hexStringByBytes(msgWaterCode,2) #消息流水号
if subPkg != 8192:
......@@ -64,10 +64,10 @@ class MessageBase(Base):
def getMsgBodyProperty(self,msgBodyLen=128,encryptionType=0,subPkg=0):
if msgBodyLen >= 512:
raise RuntimeError('消息体长度超长!')
msgBodyLen = msgBodyLen #消息体长度
encryptionType = encryptionType #加密方式
subPkg = subPkg #分包
retain = 0 #保留位
msgBodyLen = msgBodyLen #消息体长度
encryptionType = encryptionType << 10 #加密方式
subPkg = subPkg << 13 #分包
retain = 0 #保留位
data = msgBodyLen + encryptionType + subPkg + retain
dataHex = self.int2hexStringByBytes(data,2)
return dataHex
......@@ -76,10 +76,10 @@ class MessageBase(Base):
def getMsgBodyProperty_GUI(self,msgBodyLen=128,encryptionType=0,subPkg=0):
if msgBodyLen >= 512:
raise RuntimeError('消息体长度超长!')
msgBodyLen = msgBodyLen #消息体长度
encryptionType = encryptionType #加密方式
subPkg = subPkg #分包
retain = 0 #保留位
msgBodyLen = msgBodyLen #消息体长度
encryptionType = encryptionType << 10 #加密方式
subPkg = subPkg << 13 #分包
retain = 0 #保留位
data = msgBodyLen + encryptionType + subPkg + retain
dataHex = self.int2hexStringByBytes(data,2)
return dataHex
......
......@@ -29,8 +29,8 @@ class PlateformUpdateRes_msg(MessageBase):
# 生成一条完整的消息,针对图形界面,可传递参数
def generateMsg_GUI(self,msgID="8FF1",phoneNum="13146201119",msgWaterCode=1,encryptionType=0,subPkg=0):
msg = ""
msgHeader = self.getMsgHeader_GUI(msgID,phoneNum,msgWaterCode,encryptionType,subPkg)
msgBody = self.getMsgBody()
msgHeader = self.getMsgHeader_GUI(msgID, phoneNum, msgWaterCode, encryptionType, subPkg,msgBody)
checkCode = self.getCheckCode(msgHeader + msgBody)
msg = msg + self.IDENTIFY
info = msgHeader + msgBody + checkCode
......
......@@ -29,8 +29,8 @@ class TerminalHeartbeat_msg(MessageBase):
# 生成一条完整的消息,针对图形界面,可传递参数
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()
msgHeader = self.getMsgHeader_GUI(msgID, phoneNum, msgWaterCode, encryptionType, subPkg,msgBody)
checkCode = self.getCheckCode(msgHeader + msgBody)
msg = msg + self.IDENTIFY
info = msgHeader + msgBody + checkCode
......@@ -87,8 +87,8 @@ class TerminalHeartbeat_msg(MessageBase):
if msgBodyLen >= 512:
raise RuntimeError('消息体长度超长!')
msgBodyLen = msgBodyLen #消息体长度
encryptionType = encryptionType #加密方式
subPkg = subPkg #分包
encryptionType = encryptionType << 10 #加密方式
subPkg = subPkg << 13 #分包
retain = 0 #保留位
data = msgBodyLen + encryptionType + subPkg + retain
dataHex = self.int2hexStringByBytes(data,2)
......
......@@ -31,8 +31,8 @@ class TerminalRegister_msg(MessageBase):
countyId=103,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,countyId,manufacturerId,terminalType,terminalId,licencePlateColor,carSign)
msgHeader = self.getMsgHeader_GUI(msgID, phoneNum, msgWaterCode, encryptionType, subPkg,msgBody)
checkCode = self.getCheckCode(msgHeader + msgBody)
msg = msg + self.IDENTIFY
info = msgHeader + msgBody + checkCode
......
......@@ -32,9 +32,9 @@ class TerminalVersionInfo_msg(MessageBase):
GMS_IMEI="GMS_IMEI_123456", SIM_IMSI="SIM_13146201119", SIM_ICCID="SIM_ICCID13146201119",carType=22, VIN="VIN_1234567891234", \
totalMileage=389000, totalOilExpend=420000,displacement=1500,oilDensity=80):
msg = ""
msgHeader = self.getMsgHeader_GUI(msgID,phoneNum,msgWaterCode,encryptionType,subPkg)
msgBody = self.getMsgBody_GUI(softwareVersion,softwareVersionDate,CPUId,GMSType,GMS_IMEI,SIM_IMSI,SIM_ICCID,carType,VIN,\
totalMileage,totalOilExpend,displacement,oilDensity)
msgHeader = self.getMsgHeader_GUI(msgID, phoneNum, msgWaterCode, encryptionType, subPkg,msgBody)
checkCode = self.getCheckCode(msgHeader + msgBody)
msg = msg + self.IDENTIFY
info = msgHeader + msgBody + checkCode
......
......@@ -29,8 +29,8 @@ class TextInfoUpload_msg(MessageBase):
# 生成一条完整的消息,针对图形界面,可传递参数
def generateMsg_GUI(self,msgID="8300",phoneNum="13146201119",msgWaterCode=1,encryptionType=0,subPkg=0):
msg = ""
msgHeader = self.getMsgHeader_GUI(msgID,phoneNum,msgWaterCode,encryptionType,subPkg)
msgBody = self.getMsgBody()
msgHeader = self.getMsgHeader_GUI(msgID, phoneNum, msgWaterCode, encryptionType, subPkg,msgBody)
checkCode = self.getCheckCode(msgHeader + msgBody)
msg = msg + self.IDENTIFY
info = msgHeader + msgBody + checkCode
......
......@@ -159,7 +159,7 @@ class ProtocolSimulaterService():
self.websocket.send(info)
self.doResponse(d)
#停止与页面交互的websockt服务
#启动与页面交互的websockt服务
def websocketService(self):
self.websocket = Websocket_service()
self.websocket.setHost("0.0.0.0")
......
......@@ -2,47 +2,31 @@
{% block title %}heartBeat_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;">
<H3 style="border-bottom: 1px solid #eee;">设置操作界面</H3>
<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>
//发送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();
}
$("#saveSocketSetting").click(function(){
var host = $("#host").val();
var port = $("#port").val();
var data = {};
data["msgID"] = msgID;
data["phoneNum"] = phoneNum;
data["msgWaterCode"] = msgWaterCode;
data["encryptionType"] = encryptionType;
data["subPkg"] = subPkg;
data["pkgCounts"] = pkgCounts;
data["host"] = host;
data["port"] = port;
var host = window.location.host;
$("#showFeedback").val("")
$.ajax({
url:"http://" + host + "/messageTools/message_process/porcessHeartBeatMsg",
url:"http://" + host + "/messageTools/M_simulater_process/porcessSocketSetting",
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 + "收到数据16进制: " + data.resultH + "\n";
theShow = theShow + "解析数据: " + JSON.stringify(data.parse) + "\n";
$("#showFeedback").val(theShow)
window.location.reload()
}else{
$("#showFeedback").val(data.message)
alert(data.message);
......@@ -51,6 +35,7 @@ $("#sendMsgBtn").click(function(){
});
});
function hasSubPkg(){
value = $("#subPkg").val()
if(value == "8192"){
......
......@@ -38,7 +38,58 @@
{% 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%;_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>是否加密:</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>
<div style="width:100%;padding-bottom:10px;border-bottom: 1px solid #eee;">
<h4>点击登录按钮发送报文:</h4>
<div style="display: block; width: 100%; border-width: 1px; border-style: solid; border-color: darkgray; border-radius: 10px; padding: 2px; margin-top: 5px;">
<h5><b>登录报文数据:</b>
<span style="border-width:1px;border-style:solid;border-color:darkgray;border-radius:10px;padding:1px 10px;">
<label><input name="login" type="radio" value="0" checked="checked" onclick="isShowLoginArea(this)"/>隐藏</label>
<label style="margin-left:10px;"><input name="login" type="radio" value="1" onclick="isShowLoginArea(this)"/>显示</label>
</span>
</h5>
<div id="login_area" style="display:none;">
<ul class="protocol_content" style="padding:0px;">
<li style="width:320px;"><label>CPU-ID:</label><input style="width:220px;" id="cpuId" type="text" class="form-control" value="CPU-ID001122334455667788"></li>
<li><label style="word-break:break-all;font-size:12px;">SIM卡IMSI号:</label><input id="imsi" type="text" class="form-control" value="IMSI13145678902"></li>
<li style="width:300px;"><label style="word-break:break-all;font-size:12px;">SIM卡CCID号:</label><input style="width:200px;" id="ccid" type="text" class="form-control" value="CCID1122334455667788"></li>
<li><label style="word-break:break-all;font-size:10px;">GSM模块IMEI码:</label><input id="imei" type="text" class="form-control" value="IMEI12233445566"></li>
</ul>
</div>
<ul class="protocol_content" style="padding:0px;">
<li style="width:320px;"><label style="word-break:break-all;font-size:12px;">车机版本信息:</label><input style="width:220px;" id="verInfo" type="text" class="form-control" value="M100AB01010.0000"></li>
<li><label>编译日期:</label><input id="compileDate" type="text" class="form-control" value="2020-03-23"></li>
<li style="width:300px;"><label style="word-break:break-all;font-size:12px;">GSM模块型号:</label><input style="width:200px;" id="GSM" type="text" class="form-control" value="GSM_123456"></li>
</ul>
</div>
</div>
<div style="display: block; width: 100%; border-width: 1px; border-style: solid; border-color: darkgray; border-radius: 10px; padding: 2px; margin-top: 5px;">
<h5><b>GPS行驶轨迹设置:</b></h5>
<div class="input-group" style="width:380px;padding-bottom:10px;margin-left:10px;display:inline;">
<form id="form" enctype="multipart/form-data">
<input type="file" id="fileAttach" name="file" class="form-control" style="display:inline;width:250px;"/>
<input type="button" onclick="uploadFile()" value="上传" class="form-control" style="display:inline;width:80px;font-weight: bolder;"/>
</form>
</div>
<span style="margin-left:10px;"><label>选择轨迹:</label><select id="selectGPSLine" class="form-control" style="width:250px;">
<option value="test">test</option>
</select></span>
<a style="margin-left:10px;font-weight:bold;" onclick="download_sample()">下载示例轨迹</a>
</div>
</div>
......
......@@ -28,11 +28,11 @@ def porcessSocketSetting():
try:
# d读取config文件
conf_R = ConfigParser()
conf_R.read("config/protocolTools/carSimulater.conf")
conf_R.read("config/messageTools/carSimulater.conf")
conf_W = conf_R
conf_W["socket"]["host"] = host
conf_W["socket"]["port"] = port
with open("config/protocolTools/carSimulater.conf", "w") as fi:
with open("config/messageTools/carSimulater.conf", "w") as fi:
conf_W.write(fi)
data["status"] = "200"
data["message"] = "Sucess: "
......
#coding:utf-8
from configparser import ConfigParser
from flask import Blueprint, render_template ,request
import re
......@@ -31,4 +32,10 @@ def M_simulaterSetting_page():
arg = {}
path = "messageTools/message/M_simulaterSetting_page.html"
arg["path"] = reqPath.split("/")
arg["socket"] = {}
# 读取config文件
conf_R = ConfigParser()
conf_R.read("config/messageTools/carSimulater.conf")
arg["socket"]["host"] = conf_R.get("socket", "host")
arg["socket"]["port"] = conf_R.getint("socket", "port")
return render_template(path,arg=arg)
\ No newline at end of file
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