Commit 44bb56da authored by liyuanhong's avatar liyuanhong

优化了M500 模拟器

parent 0198e4ba
{"time": {"dateTime": "2020-04-14 11:32:27", "date": "2020-04-14", "time": "11:32:27"}, "curDayTravel": {"todayTotalMilleage": 4375, "todayTotalOil": 400, "todayTotalTime": 265, "theMilleage": 640, "theOil": 40, "theTime": 40}, "travelData": {"totallMilleage": 0, "totalOil": 0, "totalTime": 0}}
\ No newline at end of file
......@@ -34,13 +34,13 @@ class MessageBase(Base):
# 获取消息头
#######################################################
def getMsgHeader(self):
msgID = self.int2hexStringByBytes(102,2) #消息id
msgID = self.int2hexStringByBytes(102,2) #消息id
subPkg = 0
msgBodyProperty = self.getMsgBodyProperty(subPkg=subPkg) #消息体属性
phoneNum = self.int2BCD(13146201118) #终端手机号
msgWaterCode = self.int2hexStringByBytes(1) #消息流水号
msgBodyProperty = self.getMsgBodyProperty(subPkg=subPkg) #消息体属性
phoneNum = self.int2BCD(13146201118) #终端手机号
msgWaterCode = self.int2hexStringByBytes(1) #消息流水号
if subPkg != 8192:
subPkgContent = "" #消息包封装项
subPkgContent = "" #消息包封装项
else:
subPkgContent = self.getMsgPackage()
data = msgID + msgBodyProperty + phoneNum + msgWaterCode + subPkgContent
......
......@@ -138,6 +138,7 @@ class GPSReport_protocol(ProtocolBase):
Vdop = self.getVdop(self.Vdop)
#状态字节
statusBit = self.getStatusBit(self.statusBit)
print(statusBit)
#电压
valtage = self.getValtage(self.valtage)
#OBD车速
......@@ -335,12 +336,7 @@ class GPSReport_protocol(ProtocolBase):
# 获取电压16进制值,2字节表示
#####################################################
def getValtage(self,num):
valtageStr = str(num)
valtageStr = valtageStr.replace(".", "")
while (len(valtageStr) < 4):
valtageStr = "0" + valtageStr
valtageHex = hex(int(valtageStr))
valtageHex = self.leftPad(str(valtageHex)[2:], 4)
valtageHex = self.int2hexStringByBytes(int(num *100),2)
return valtageHex
#####################################################
......
#coding:utf-8
##################################################
# 定义M500 车机行驶过程中产生的数据类
##################################################
import datetime
import json
import time
class MessageSimulaterDataService():
def __init__(self,path="/data/protocolTools/carData/",fileName="default.json"):
self.data = {}
self.path = path #保存车机数据文件地址
self.fileName = fileName #保存车机数据文件
def setPath(self,data):
self.path = data
def setFileName(self,data):
self.fileName = data
def setData(self,data):
self.data = data
####################################################
# 生成一个默认数据模板
####################################################
def genDataTemplate(self):
data = {}
timeStamp = time.time()
timeArray = time.localtime(timeStamp)
data["time"] = {} #定义时间数据项
data["time"]["dateTime"] = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
data["time"]["date"] = time.strftime("%Y-%m-%d", timeArray)
data["time"]["time"] = time.strftime("%H:%M:%S", timeArray)
data["curDayTravel"] = {} #定义当天行驶数据项
data["curDayTravel"]["todayTotalMilleage"] = 0 #今日行驶总里程
data["curDayTravel"]["todayTotalOil"] = 0 #今日行驶总油耗
data["curDayTravel"]["todayTotalTime"] = 0 #今日行驶总时间
data["curDayTravel"]["theMilleage"] = 0 #本次行驶总里程
data["curDayTravel"]["theOil"] = 0 #本次行驶总油耗
data["curDayTravel"]["theTime"] = 0 #本次行驶总时间
data["travelData"] = {} #定义所有行驶数据
data["travelData"]["totallMilleage"] = 0 #行驶总里程
data["travelData"]["totalOil"] = 0 #行驶总油耗
data["travelData"]["totalTime"] = 0 #行驶总时间
return data
#设今日行驶总里程,同时写入文件
def setTodayTotalMilleage(self,data):
self.data["curDayTravel"]["todayTotalMilleage"] = data
self.writeToFile(self.path + self.fileName,self.data)
#设今日行驶总油耗,同时写入文件
def setTodayTodayTotalOil(self,data):
self.data["curDayTravel"]["todayTotalOil"] = data
self.writeToFile(self.path + self.fileName,self.data)
#设今日行驶总时间,同时写入文件
def setTodayTodayTotalTime(self,data):
self.data["curDayTravel"]["todayTotalTime"] = data
self.writeToFile(self.path + self.fileName,self.data)
#设本次行驶总里程,同时写入文件
def setTheMilleage(self,data):
self.data["curDayTravel"]["theMilleage"] = data
self.writeToFile(self.path + self.fileName,self.data)
#设本次行驶总油耗,同时写入文件
def setTheOil(self,data):
self.data["curDayTravel"]["theOil"] = data
self.writeToFile(self.path + self.fileName,self.data)
#设本次行驶总时间,同时写入文件
def setTheTime(self,data):
self.data["curDayTravel"]["theTime"] = data
self.writeToFile(self.path + self.fileName,self.data)
#设今日日期时间
def setDateTime2file(self,data):
self.data["time"]["dateTime"] = data
self.writeToFile(self.path + self.fileName,self.data)
#设今日日期
def setData2file(self,data):
self.data["time"]["date"] = data
self.writeToFile(self.path + self.fileName,self.data)
#设今日时间
def setTime2file(self,data):
self.data["time"]["time"] = data
self.writeToFile(self.path + self.fileName,self.data)
####################################################
# 将数据写入文件
####################################################
def writeToFile(self,path,data):
with open(path,"w",encoding="utf-8") as fi:
data = json.dumps(data)
fi.write(data)
####################################################
# 从文件读取数据
####################################################
def readFromFile(self,path):
with open(path, "r", encoding="utf-8") as fi:
content = fi.read()
conJson = json.loads(content)
timeStamp = time.time()
timeArray = time.localtime(timeStamp)
dateTimeM = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
dateM = time.strftime("%Y-%m-%d", timeArray)
timeM = time.strftime("%H:%M:%S", timeArray)
if dateM == conJson["time"]["date"]:
pass
else: #如果不是当天日期,则将日期设置为当天
conJson["time"]["dateTime"] = dateTimeM
conJson["time"]["date"] = dateM
conJson["time"]["time"] = timeM
data["curDayTravel"]["todayTotalMilleage"] = 0 # 今日行驶总里程
data["curDayTravel"]["todayTotalOil"] = 0 # 今日行驶总油耗
data["curDayTravel"]["todayTotalTime"] = 0 # 今日行驶总时间
self.setTodayTotalMilleage(0)
self.setTodayTodayTotalOil(0)
self.setTodayTodayTotalTime(0)
self.setDateTime2file(dateTimeM)
self.setData2file(dateM)
self.setTime2file(timeM)
self.data = conJson
if __name__ == "__main__":
print(MessageSimulaterDataService().genDataTemplate())
data = MessageSimulaterDataService().genDataTemplate()
MessageSimulaterDataService().writeToFile("../../../data/protocolTools/carData/M202003060520.json",data)
\ No newline at end of file
#coding:utf-8
'''
新硬件车机模拟服务类
'''
import binascii
import json
import os
import threading
import time
import traceback
from time import sleep
from lib.socket.service.websocket_service import Websocket_service
class MessageSimulaterService():
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.timeout = 1 #socket的超时时间
self.gpsLine = [] #GPS 轨迹
self.gpsLineIndex = 0 #GPS 轨迹索引
self.travelStatus = 0 #0,表示为行驶,1表示开始行驶
self.carId = "" #车机号
self.sn = 0 #消息流水号
self.travelDirection = 0 #行驶方向,0表示正向行驶,1表示反向行驶
# 定义要发送的obd数据
self.OBDdata = {}
# 定义初始的obd数据,与上面的OBD数据保持一致,主要用于汽车行驶过程中数据变化量的计算
self.OBDdataOri = {}
#设置套接字
def setSocket(self,data):
self.socket = data
def setSendDur(self,data):
self.sendDur = data
def setTimeout(self,data):
self.timeout = data
def setCarId(self,data):
self.carId = data
def setData(self,data):
self.data = data
def getWebsocket(self):
return self.websocket
def sendMsg(self,msg):
self.socket.setTimeOut(self.timeout)
self.socket.send(msg)
def revMsg(self):
self.socket.setTimeOut(self.timeout)
return self.socket.receive()
#websocket向网页发送消息,可指定消息的描述类型
def serviceSendMsg(self,msg):
self.sendMsg(msg)
type = self.getMsgFunId(msg)
self.websocket.send(">>>>" + type + ":" + msg)
########################################################
#启动与页面交互的websockt服务
########################################################
def websocketService(self):
self.websocket = Websocket_service()
self.websocket.setHost("0.0.0.0")
self.websocket.setPort(5007)
self.websocket.startWebsocketServer()
......@@ -40,7 +40,7 @@ class ProtocolSimulaterDataService():
data["curDayTravel"]["theOil"] = 0 #本次行驶总油耗
data["curDayTravel"]["theTime"] = 0 #本次行驶总时间
data["travelData"] = {} #定义所有行驶数据
data["travelData"]["totallMilleage"] = 0 #行驶总里程
data["travelData"]["totalMilleage"] = 0 #行驶总里程
data["travelData"]["totalOil"] = 0 #行驶总油耗
data["travelData"]["totalTime"] = 0 #行驶总时间
return data
......@@ -71,6 +71,19 @@ class ProtocolSimulaterDataService():
self.data["curDayTravel"]["theTime"] = data
self.writeToFile(self.path + self.fileName,self.data)
#设总里程,同时写入文件
def setTotalMilleage(self,data):
self.data["travelData"]["totalMilleage"] = data
self.writeToFile(self.path + self.fileName,self.data)
#设总油耗,同时写入文件
def setTotalOil(self,data):
self.data["travelData"]["totalOil"] = data
self.writeToFile(self.path + self.fileName,self.data)
#设总时间,同时写入文件
def setTotalTime(self,data):
self.data["travelData"]["totalTime"] = data
self.writeToFile(self.path + self.fileName,self.data)
#设今日日期时间
def setDateTime2file(self,data):
self.data["time"]["dateTime"] = data
......
......@@ -113,25 +113,26 @@ class ProtocolSimulaterService():
self.OBDdata["totalOilExpen"], self.OBDdata["totalRunTime"])
self.OBDdata["engineSpeed"] = 3000
self.OBDdata["speed"] = int(self.data["travelData"]["carSpeed"])
self.OBDdata["meterMileage"] = self.OBDdata["meterMileage"] + int(
self.sendDur * (self.OBDdata["speed"] * 1000 / 3600))
self.OBDdata["totailMileage"] = self.OBDdata["totailMileage"] + int(
self.sendDur * (self.OBDdata["speed"] * 1000 / 3600))
self.OBDdata["meterMileage"] = self.OBDdata["meterMileage"] + int(self.sendDur * (self.OBDdata["speed"] * 1000 / 3600))
self.OBDdata["totailMileage"] = self.OBDdata["totailMileage"] + int(self.sendDur * (self.OBDdata["speed"] * 1000 / 3600))
oilExpend = int(self.data["travelData"]["oilExpend"])
self.OBDdata["totalOilExpen"] = self.OBDdata["totalOilExpen"] + int(
(self.sendDur * (self.OBDdata["speed"] * 1000 / 3600)) * (1000 / (oilExpend * 1000)))
self.OBDdata["totalOilExpen"] = self.OBDdata["totalOilExpen"] + int((self.sendDur * (self.OBDdata["speed"] * 1000 / 3600)) * (1000 / (oilExpend * 1000)))
self.OBDdata["totalRunTime"] = self.OBDdata["totalRunTime"] + self.sendDur
latitude = self.gpsLine[self.gpsLineIndex]["lat"]
longitude = self.gpsLine[self.gpsLineIndex]["lng"]
gpsMsg = self.genGPSMsg(latitude, longitude)
self.carDataObj.setTodayTotalMilleage(self.carData["curDayTravel"]["todayTotalMilleage"] + self.OBDdata["totailMileage"] - self.OBDdataOri["totailMileage"])
self.carDataObj.setTheMilleage(self.carData["curDayTravel"]["theMilleage"] + self.OBDdata["totailMileage"] -self.OBDdataOri["totailMileage"])
self.OBDdataOri["totailMileage"] = self.OBDdata["totailMileage"]
self.carDataObj.setTotalMilleage(self.carData["travelData"]["totalMilleage"] + self.OBDdata["totailMileage"] - self.OBDdataOri["totailMileage"])
temp = self.OBDdata["totailMileage"]
self.OBDdataOri["totailMileage"] = temp
self.carDataObj.setTodayTodayTotalOil(self.carData["curDayTravel"]["todayTotalOil"] + self.OBDdata["totalOilExpen"] - self.OBDdataOri["totalOilExpen"])
self.carDataObj.setTheOil(self.carData["curDayTravel"]["theOil"] + self.OBDdata["totalOilExpen"] - self.OBDdataOri["totalOilExpen"])
self.carDataObj.setTotalOil(self.carData["travelData"]["totalOil"] + self.OBDdata["totalOilExpen"] - self.OBDdataOri["totalOilExpen"])
self.OBDdataOri["totalOilExpen"] = self.OBDdata["totalOilExpen"]
self.carDataObj.setTodayTodayTotalTime(self.carData["curDayTravel"]["todayTotalTime"] + self.OBDdata["totalRunTime"] - self.OBDdataOri["totalRunTime"])
self.carDataObj.setTheTime(self.carData["curDayTravel"]["theTime"] + self.OBDdata["totalRunTime"] - self.OBDdataOri["totalRunTime"])
self.carDataObj.setTotalTime(self.carData["travelData"]["totalTime"] + self.OBDdata["totalRunTime"] - self.OBDdataOri["totalRunTime"])
self.OBDdataOri["totalRunTime"] = self.OBDdata["totalRunTime"]
if OBDMsg != "":
self.sendMsg(OBDMsg)
......@@ -269,11 +270,13 @@ class ProtocolSimulaterService():
self.carDataObj = ProtocolSimulaterDataService("data/protocolTools/carData/", dataFile)
self.carDataObj.setData(conJson)
if dateM == conJson["time"]["date"]:
pass
self.OBDdata["totailMileage"] = conJson["travelData"]["totalMilleage"]
self.OBDdataOri["totailMileage"] = conJson["travelData"]["totalMilleage"]
self.OBDdata["totalOilExpen"] = conJson["travelData"]["totalOil"]
self.OBDdataOri["totalOilExpen"] = conJson["travelData"]["totalOil"]
self.OBDdata["totalRunTime"] = conJson["travelData"]["totalTime"]
self.OBDdataOri["totalRunTime"] = conJson["travelData"]["totalTime"]
else: #如果不是当天日期,则将日期设置为当天,并写入车辆数据文件
conJson["time"]["dateTime"] = dateTimeM
conJson["time"]["date"] = dateM
conJson["time"]["time"] = timeM
conJson["curDayTravel"]["todayTotalMilleage"] = 0 # 今日行驶总里程
conJson["curDayTravel"]["todayTotalOil"] = 0 # 今日行驶总油耗
conJson["curDayTravel"]["todayTotalTime"] = 0 # 今日行驶总时间
......@@ -300,7 +303,9 @@ class ProtocolSimulaterService():
self.sn = self.sn + 1
self.websocket.send(type + ">>>>:" + gpsMsg)
sleep(0.1)
OBDMsg = self.genOBDMsg()
OBDMsg = self.genOBDMsg(self.OBDdata["fireStatus"],1,self.OBDdata["engineSpeed"], \
self.OBDdata["speed"],self.OBDdata["meterMileage"],self.OBDdata["totailMileage"], \
self.OBDdata["totalOilExpen"],self.OBDdata["totalRunTime"])
type = self.getMsgFunId(OBDMsg)
self.sendMsg(OBDMsg)
self.sn = self.sn + 1
......
......@@ -38,20 +38,10 @@
{% 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;">
<div style="width:100%;padding-bottom:10px;border-bottom: 1px solid #eee;">
<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;">
<label>上报间隔:</label><input id="durTime" type="text" class="form-control" value="5" style="width:80px;" />
<label>设置超时时间:</label><input id="timeout" type="text" class="form-control" value="3600" style="width:80px;" />
</div>
<div style="width:100%;padding-bottom:10px;border-bottom: 1px solid #eee;">
<h4>点击登录按钮发送报文:</h4>
......@@ -63,18 +53,33 @@
</span>
</h5>
<div id="login_area" style="display:none;">
<h5><b>登录报文:</b></h5>
<ul class="protocol_content" style="padding:0px;">
<li><label>省域ID:</label><input id="provinceId" type="text" class="form-control" value="50"></li>
<li><label>市县域ID:</label><input id="countyId" type="text" class="form-control" value="103"></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>
<h5><b>版本报文:</b></h5>
<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>
<li><label style="word-break:break-all;font-size:12px;">软件版本号:</label><input id="softwareVersion" type="text" class="form-control" value="KZP200_V201001"></li>
<li><label style="word-break:break-all;font-size:12px;">终端版本日期:</label><input id="softwareVersionDate" type="text" class="form-control" value="2020-02-10"></li>
<li><label>cpuId:</label><input id="CPUId" type="text" class="form-control" value="CPU-12345678"></li>
<li><label>GMS型号:</label><input id="GMSType" type="text" class="form-control" value="GMS-TYPE-123456"></li>
<li><label style="word-break:break-all;font-size:12px;">GSM IMEI号:</label><input id="GMS_IMEI" type="text" class="form-control" value="GMS_IMEI_123456"></li>
<li><label style="word-break:break-all;font-size:12px;">终端 SIM卡IMSI 号:</label><input id="SIM_IMSI" type="text" class="form-control" value="SIM_13146201119"></li>
<li><label style="word-break:break-all;font-size:12px;">终端 SIM卡ICCID号:</label><input id="SIM_ICCID" type="text" class="form-control" value="SIM_ICCID13146201119"></li>
<li><label style="word-break:break-all;font-size:12px;">车系车型ID:</label><input id="carType" type="text" class="form-control" value="22"></li>
<li><label style="word-break:break-all;font-size:12px;">汽车VIN码:</label><input id="VIN" type="text" class="form-control" value="VIN_1234567891234"></li>
<li><label style="word-break:break-all;font-size:12px;">装上终端后车辆累计总里程:</label><input id="totalMileage" type="text" class="form-control" value="389000"></li>
<li><label style="word-break:break-all;font-size:12px;">装上终端后车辆累计总耗油:</label><input id="totalOilExpend" type="text" class="form-control" value="420000"></li>
<li><label style="word-break:break-all;font-size:12px;">排量:</label><input id="displacement" type="text" class="form-control" value="1500"></li>
<li><label style="word-break:break-all;font-size:12px;">油密度:</label><input id="oilDensity" type="text" class="form-control" value="92"></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;">
......@@ -90,67 +95,142 @@
</select></span>
<a style="margin-left:10px;font-weight:bold;" onclick="download_sample()">下载示例轨迹</a>
</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>行驶参数设置:</b></h5>
<span><label>速度(Km/h):</label><input type="text" id="carSpeed" class="form-control" style="display:inline;width:80px;" value="60"/></span>
<span><label>油耗(Km/L):</label><input type="text" id="oilExpend" class="form-control" style="display:inline;width:80px;" value="10"/></span>
<span><label>是否循环行驶:</label><select style="width:80px;" id="travelLoop" class="form-control">
<option value="0"></option>
<option value="1"></option></select><label style="font-size:9px;width: 100px;">开启后会在所选择的轨迹上来回行驶</label></span>
</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" onclick="connect()">1、连网</button>
<button id="fire_B" type="button" class="btn btn-primary" onclick="login()">2、登录</button>
<button id="login_B" type="button" class="btn btn-primary" onclick="fire()">3、点火</button>
<button id="run_B" type="button" class="btn btn-primary" onclick="startTravel()">4、行驶</button>
<button id="stopRun_B" type="button" class="btn btn-primary" onclick="stopTravel()">5、停止行驶</button>
<button id="unFire_B" type="button" class="btn btn-primary" onclick="unFire()">6、熄火</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" onclick="reset()">复位</button>
<button id="clear_B" type="button" class="btn btn-warning" onclick="clearlog()">清空日志</button>
<span style="margin-left:20px;"><label>当前状态:</label><input id="curStatus" value="断网" disabled="disabled" class="form-control" style="font-weight: bold;width:85px;color:red;border-width: 1px; border-style: solid; border-color: darkgray; border-radius: 10px;"></span>
</div>
</div>
{% endblock %}
</div>
<script>
//连网
function connect(){
var data = getPageData();
var host = window.location.host;
var url = "http://" + host + "/messageTools/M_simulater_process/porcessConnect";
sendMsg(data,url);
}
//发送GPS数据
function sendMsg(data,url){
var data = data;
var url = url;
var host = window.location.host;
console.log(data);
<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 data = {};
data["msgID"] = msgID;
data["phoneNum"] = phoneNum;
data["msgWaterCode"] = msgWaterCode;
data["encryptionType"] = encryptionType;
data["subPkg"] = subPkg;
data["pkgCounts"] = pkgCounts;
var host = window.location.host;
$("#showFeedback").val("")
$.ajax({
url:"http://" + host + "/messageTools/message_process/porcessHeartBeatMsg",
type:"post",
data:data,
dataType:"json",
success:function(data){
if(data.status == 200){
//window.location.reload()
$("#showFeedback").val("")
$.ajax({
url:url,
type:"post",
data:JSON.stringify(data),
contentType:"application/json",
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)
}else{
$("#showFeedback").val(data.message)
alert(data.message);
}
$("#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")
}
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>
}
//获取页面数据
function getPageData(){
var phoneNum = $("#phoneNum").val();
var durTime = $("#durTime").val();
var timeout = $("#timeout").val();
var data = {};
data["phoneNum"] = phoneNum;
data["durTime"] = durTime;
data["timeout"] = timeout;
var provinceId = $("#provinceId").val();
var countyId = $("#countyId").val();
var manufacturerId = $("#manufacturerId").val();
var terminalType = $("#terminalType").val();
var terminalId = $("#terminalId").val();
var licencePlateColor = $("#licencePlateColor").val();
var carSign = $("#carSign").val();
data["login"] = {};
data["login"]["provinceId"] = provinceId;
data["login"]["countyId"] = countyId;
data["login"]["manufacturerId"] = manufacturerId;
data["login"]["terminalType"] = terminalType;
data["login"]["terminalId"] = terminalId;
data["login"]["licencePlateColor"] = licencePlateColor;
data["login"]["carSign"] = carSign;
var softwareVersion = $("#softwareVersion").val();
var softwareVersionDate = $("#softwareVersionDate").val();
var CPUId = $("#CPUId").val();
var GMSType = $("#GMSType").val();
var GMS_IMEI = $("#GMS_IMEI").val();
var SIM_IMSI = $("#SIM_IMSI").val();
var SIM_ICCID = $("#SIM_ICCID").val();
var carType = $("#carType").val();
var VIN = $("#VIN").val();
var totalMileage = $("#totalMileage").val();
var totalOilExpend = $("#totalOilExpend").val();
var displacement = $("#displacement").val();
var oilDensity = $("#oilDensity").val();
data["version"] = {}
data["version"]["softwareVersion"] = softwareVersion;
data["version"]["softwareVersionDate"] = softwareVersionDate;
data["version"]["CPUId"] = CPUId;
data["version"]["GMSType"] = GMSType;
data["version"]["GMS_IMEI"] = GMS_IMEI;
data["version"]["SIM_IMSI"] = SIM_IMSI;
data["version"]["SIM_ICCID"] = SIM_ICCID;
data["version"]["carType"] = carType;
data["version"]["VIN"] = VIN;
data["version"]["totalMileage"] = totalMileage;
data["version"]["totalOilExpend"] = totalOilExpend;
data["version"]["displacement"] = displacement;
data["version"]["oilDensity"] = oilDensity;
return data;
}
//控制登录数据区域的显示与隐藏
function isShowLoginArea(e){
var value = $(e).val()
if(value == "0"){
$("#login_area").css("display","none")
}else{
$("#login_area").css("display","block")
}
}
</script>
{% endblock %}
\ No newline at end of file
......@@ -7,6 +7,9 @@ from configparser import ConfigParser
import json
import traceback
from lib.socket.ClientSocket import ClientSocket
from lib.socket.service.MessageSimulaterService import MessageSimulaterService
M_simulater_process = Blueprint('M_simulater_process', __name__)
connects = [] #用来保存连接的信息
......@@ -41,4 +44,43 @@ def porcessSocketSetting():
traceback.print_exc()
data["status"] = "4003"
data["message"] = "Error: 处理失败!"
return Response(json.dumps(data), mimetype='application/json')
##########################################
# 【接口类型】车机联网
##########################################
@M_simulater_process.route("/porcessConnect",methods=['POST'])
def porcessConnect():
params = request.get_data()
params = json.loads(params.decode("utf-8"))
print(params)
data = {}
try:
conf_R = ConfigParser()
conf_R.read("config/messageTools/carSimulater.conf")
if len(connects) < 1:
cliSocket = ClientSocket(conf_R.get("socket", "host"), conf_R.getint("socket", "port"))
cliSocket.setTimeOut(timeout)
cliSocket.connect()
connect = {}
socketName = "socket_" + str(len(connects) + 1)
connect["name"] = socketName
connects.append(connect)
service = MessageSimulaterService()
service.setSocket(cliSocket)
service.setTimeout(timeout)
service.setData(params)
service.setSocket(cliSocket)
service.startWebsocketService()
connects[0]["service"] = service
data["status"] = "200"
data["message"] = "创建连接成功!"
else:
data["status"] = "4003"
data["message"] = "已经创建了连接!"
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