Commit aee8262a authored by 高晓帆's avatar 高晓帆

fix

parent e36eb375
...@@ -24,7 +24,7 @@ const TOPIC_CLASS = { ...@@ -24,7 +24,7 @@ const TOPIC_CLASS = {
'/pattern/ack', // 车辆模式切换按钮-发送模式切换回复 '/pattern/ack', // 车辆模式切换按钮-发送模式切换回复
'/task/retranTimer', // 车辆任务重传定时器消息 '/task/retranTimer', // 车辆任务重传定时器消息
'/setting/singleTrackAck', // 设置单机循迹 '/setting/singleTrackAck', // 设置单机循迹
'/product', '/product',
'/info/popup', // 弹框确认信息 '/info/popup', // 弹框确认信息
'/setting/basicinfo', // 基本设置数据信息 '/setting/basicinfo', // 基本设置数据信息
'/setting/light', // 灯光 '/setting/light', // 灯光
...@@ -94,7 +94,7 @@ export default class Socket { ...@@ -94,7 +94,7 @@ export default class Socket {
self.isSendSync = true self.isSendSync = true
self.reconnect() self.reconnect()
} }
self.ws.onclose = function () { self.ws.onclose = function () {
!self.isClosed && self.reconnect() !self.isClosed && self.reconnect()
console.log('closed', new Date()) console.log('closed', new Date())
...@@ -111,7 +111,7 @@ export default class Socket { ...@@ -111,7 +111,7 @@ export default class Socket {
start() { start() {
this.heartTimer && clearTimeout(this.heartTimer) this.heartTimer && clearTimeout(this.heartTimer)
this.serverTimer && clearTimeout(this.serverTimer) this.serverTimer && clearTimeout(this.serverTimer)
this.heartTimer = setTimeout(() => { this.heartTimer = setTimeout(() => {
this.send({ this.send({
type: 'heartbeat', type: 'heartbeat',
...@@ -126,7 +126,7 @@ export default class Socket { ...@@ -126,7 +126,7 @@ export default class Socket {
} }
// 15s定时发送心跳 // 15s定时发送心跳
sendFixHeart () { sendFixHeart() {
this.sendFixHeartTimer && clearInterval(this.sendFixHeartTimer) this.sendFixHeartTimer && clearInterval(this.sendFixHeartTimer)
this.sendFixHeartTimer = setInterval(() => { this.sendFixHeartTimer = setInterval(() => {
this.send({ this.send({
...@@ -136,18 +136,18 @@ export default class Socket { ...@@ -136,18 +136,18 @@ export default class Socket {
}, 15000) }, 15000)
} }
resetTimeout () { resetTimeout() {
const self = this const self = this
if (this.timeoutTimer) { if (this.timeoutTimer) {
this.timeoutCount = 0 this.timeoutCount = 0
this.stateStore.dealNetworkTip({type: false}) this.stateStore.dealNetworkTip({ type: false })
clearInterval(this.timeoutTimer) clearInterval(this.timeoutTimer)
} }
this.timeoutTimer = setInterval(() => { this.timeoutTimer = setInterval(() => {
if (this.timeoutCount > NETWORK_COUNT) { if (this.timeoutCount > NETWORK_COUNT) {
this.stateStore.dealNetworkTip({type: true, count: this.timeoutCount}) this.stateStore.dealNetworkTip({ type: true, count: this.timeoutCount })
} }
this.timeoutCount ++ this.timeoutCount++
// 超时一定时间,认为车端程序未启动,跳转登录页面 // 超时一定时间,认为车端程序未启动,跳转登录页面
if (self.timeoutCount > TRUCK_MONITOR_EXIT) { if (self.timeoutCount > TRUCK_MONITOR_EXIT) {
this.dealTruckMointor({ this.dealTruckMointor({
...@@ -162,11 +162,11 @@ export default class Socket { ...@@ -162,11 +162,11 @@ export default class Socket {
}, 1000) }, 1000)
} }
reset () { reset() {
this.start() this.start()
} }
reconnect () { reconnect() {
if (this.lockReconnect) return if (this.lockReconnect) return
const self = this const self = this
// this.resetTimeout() // this.resetTimeout()
...@@ -176,7 +176,7 @@ export default class Socket { ...@@ -176,7 +176,7 @@ export default class Socket {
this.count = 0 this.count = 0
// return // return
} }
this.count ++ this.count++
this.lockReconnect = true this.lockReconnect = true
this.reconnectTimer && clearTimeout(this.reconnectTimer) this.reconnectTimer && clearTimeout(this.reconnectTimer)
...@@ -188,7 +188,7 @@ export default class Socket { ...@@ -188,7 +188,7 @@ export default class Socket {
}, 4000) }, 4000)
} }
send (msg) { send(msg) {
msg = JSON.stringify(msg) msg = JSON.stringify(msg)
console.log(`发送消息${msg}`, new Date()) console.log(`发送消息${msg}`, new Date())
this.ws && this.ws.send(msg) this.ws && this.ws.send(msg)
...@@ -212,7 +212,7 @@ export default class Socket { ...@@ -212,7 +212,7 @@ export default class Socket {
} }
} }
dealTruckMointor (msg) { dealTruckMointor(msg) {
this.stateStore.setTruckMonitor(msg) this.stateStore.setTruckMonitor(msg)
} }
...@@ -250,14 +250,14 @@ export default class Socket { ...@@ -250,14 +250,14 @@ export default class Socket {
let layers = JSON.parse(storeLayers) let layers = JSON.parse(storeLayers)
for (let i = 0; i < msg.length; i++) { for (let i = 0; i < msg.length; i++) {
let item = msg[i] let item = msg[i]
let {layerName, layerVersion} = item let { layerName, layerVersion } = item
let oldLayer = layers.find(item => item.layerName === layerName) let oldLayer = layers.find(item => item.layerName === layerName)
if (oldLayer) { if (oldLayer) {
let {layerVersion: oldLayerVersion} = oldLayer let { layerVersion: oldLayerVersion } = oldLayer
if (oldLayerVersion !== layerVersion) { if (oldLayerVersion !== layerVersion) {
syncMapLayers.push(layerName) syncMapLayers.push(layerName)
} else { } else {
initLayers.push({layerName, layerVersion}) initLayers.push({ layerName, layerVersion })
} }
} else { } else {
syncMapLayers.push(layerName) syncMapLayers.push(layerName)
...@@ -272,7 +272,7 @@ export default class Socket { ...@@ -272,7 +272,7 @@ export default class Socket {
if (initLayers.length) { if (initLayers.length) {
await this.root.indexDB.compareTable(initLayers) await this.root.indexDB.compareTable(initLayers)
initLayers.forEach(({layerName, layerVersion}) => { initLayers.forEach(({ layerName, layerVersion }) => {
this.initMapLayer(layerName, layerVersion) this.initMapLayer(layerName, layerVersion)
}) })
} }
...@@ -285,7 +285,7 @@ export default class Socket { ...@@ -285,7 +285,7 @@ export default class Socket {
} else { } else {
if (initLayers.length) { if (initLayers.length) {
await this.root.indexDB.compareTable(initLayers) await this.root.indexDB.compareTable(initLayers)
initLayers.forEach(({layerName, layerVersion}) => { initLayers.forEach(({ layerName, layerVersion }) => {
this.initMapLayer(layerName, layerVersion) this.initMapLayer(layerName, layerVersion)
}) })
} }
...@@ -303,26 +303,26 @@ export default class Socket { ...@@ -303,26 +303,26 @@ export default class Socket {
this.isSendSync = false this.isSendSync = false
this.heartCount = 0 this.heartCount = 0
} else { } else {
this.heartCount ++ this.heartCount++
} }
} }
} }
dealmapData(result, key) { dealmapData(result, key) {
const self = this const self = this
const {type, msg, version} = result const { type, msg, version } = result
let worker = this.root.worker.worker[key] let worker = this.root.worker.worker[key]
switch(type) { switch (type) {
case 'mapVersionAck': case 'mapVersionAck':
this.dealMapVersion(msg) this.dealMapVersion(msg)
break break
default: default:
let strData = window.atob(msg); let strData = window.atob(msg);
worker.postMessage({type, msg: strData, version}) worker.postMessage({ type, msg: strData, version })
break break
} }
worker.onmessage = ({ data }) => { worker.onmessage = ({ data }) => {
const {mapName, result, mapVersion} = data const { mapName, result, mapVersion } = data
self.mapStore.setData(mapName, result) self.mapStore.setData(mapName, result)
self.root.indexDB.storeData(mapName, result, mapVersion) self.root.indexDB.storeData(mapName, result, mapVersion)
self.sendVehicleSyncMsg() self.sendVehicleSyncMsg()
...@@ -330,46 +330,46 @@ export default class Socket { ...@@ -330,46 +330,46 @@ export default class Socket {
} }
dealpathData(result, key) { dealpathData(result, key) {
const {type, msg} = result const { type, msg } = result
let [, , name] = type.split('/') let [, , name] = type.split('/')
const worker = this.root.worker.worker[key] const worker = this.root.worker.worker[key]
switch(type) { switch (type) {
case '/vehicle/basicinfo': case '/vehicle/basicinfo':
const {avoidancePath, obstacle} = msg const { avoidancePath, obstacle } = msg
avoidancePath && worker.postMessage({name: 'avoidancePath', msg: avoidancePath}) avoidancePath && worker.postMessage({ name: 'avoidancePath', msg: avoidancePath })
obstacle && worker.postMessage({name: 'obstacle', msg: obstacle}) obstacle && worker.postMessage({ name: 'obstacle', msg: obstacle })
this.vehicleStore.setBasicInfo(msg) this.vehicleStore.setBasicInfo(msg)
break break
case '/vehicle/nextPathinfo': case '/vehicle/nextPathinfo':
let { available, path } = msg let { available, path } = msg
this.mapStore.setData('nextPathAvailable', available) this.mapStore.setData('nextPathAvailable', available)
path && worker.postMessage({name, msg: path}) path && worker.postMessage({ name, msg: path })
break break
default: default:
msg && worker.postMessage({name, msg}) msg && worker.postMessage({ name, msg })
break break
} }
worker.onmessage = ({data}) => { worker.onmessage = ({ data }) => {
const {name, dealedData} = data const { name, dealedData } = data
this.mapStore.setData(name === 'obstacle' ? 'obstacleData' : name, dealedData) this.mapStore.setData(name === 'obstacle' ? 'obstacleData' : name, dealedData)
} }
} }
dealvehicleData(result, key) { dealvehicleData(result, key) {
const {type, msg} = result const { type, msg } = result
const vehicleStoreToRefs = storeToRefs(this.vehicleStore) const vehicleStoreToRefs = storeToRefs(this.vehicleStore)
const {paraminfo, positioninfo} = vehicleStoreToRefs const { paraminfo, positioninfo } = vehicleStoreToRefs
const {deviceId} = paraminfo.value const { deviceId } = paraminfo.value
const worker = this.root.worker.worker[key] const worker = this.root.worker.worker[key]
const prePositionInfo = JSON.parse(JSON.stringify(positioninfo.value)) const prePositionInfo = JSON.parse(JSON.stringify(positioninfo.value))
worker.postMessage({type, msg, deviceId, pre: prePositionInfo}) worker.postMessage({ type, msg, deviceId, pre: prePositionInfo })
const diffWorker = this.root.worker.worker['vehicleDiff'] const diffWorker = this.root.worker.worker['vehicleDiff']
diffWorker.postMessage({pre: prePositionInfo, cur: msg}) diffWorker.postMessage({ pre: prePositionInfo, cur: msg })
worker.onmessage = ({data}) => { worker.onmessage = ({ data }) => {
const {vehicles, safeObj, trajObj, gps, currentBasic} = data const { vehicles, safeObj, trajObj, gps, currentBasic } = data
this.stateStore.setData('gps', gps) this.stateStore.setData('gps', gps)
currentBasic && this.vehicleStore.setData('currentBasic', currentBasic) currentBasic && this.vehicleStore.setData('currentBasic', currentBasic)
this.vehicleStore.$patch({ this.vehicleStore.$patch({
...@@ -379,7 +379,7 @@ export default class Socket { ...@@ -379,7 +379,7 @@ export default class Socket {
}) })
} }
diffWorker.onmessage = ({data}) => { diffWorker.onmessage = ({ data }) => {
this.vehicleStore.setData('deleteVehicles', data) this.vehicleStore.setData('deleteVehicles', data)
} }
...@@ -387,10 +387,14 @@ export default class Socket { ...@@ -387,10 +387,14 @@ export default class Socket {
} }
handleSettingAck(msg) { handleSettingAck(msg) {
let {type, code} = msg let { type, code } = msg
if (!SETTING_TYPE[type]) return if (!SETTING_TYPE[type]) return
let ackType = code === 0 ? 'success' : 'error' let ackType = code === 0 ? 'success' : 'error'
Message[ackType](`${SETTING_TYPE[type]}设置${code === 0 ? '成功' : '失败'}`) let text = SETTING_TYPE[type];
if (type == 4) {
text = '指令'
}
Message[ackType](`${text}设置${code === 0 ? '成功' : '失败'}`)
if (type == 6 && code === 0) { if (type == 6 && code === 0) {
let data = { let data = {
type: '/setting/req', type: '/setting/req',
...@@ -403,20 +407,20 @@ export default class Socket { ...@@ -403,20 +407,20 @@ export default class Socket {
} }
dealObstaclesAck(msg) { dealObstaclesAck(msg) {
let {code} = msg let { code } = msg
let type = code === 0 ? 'success' : 'error' let type = code === 0 ? 'success' : 'error'
let tip = code === 0 ? '成功' : '失败' let tip = code === 0 ? '成功' : '失败'
Message[type](`发送车端${tip}`) Message[type](`发送车端${tip}`)
} }
dealhmiData(result) { dealhmiData(result) {
const {type, msg} = result const { type, msg } = result
let [, , name] = type.split('/') let [, , name] = type.split('/')
// console.log(name, msg) // console.log(name, msg)
switch(type) { switch (type) {
// 车辆状态信息 // 车辆状态信息
case '/vehicle/statusinfo': case '/vehicle/statusinfo':
const {pattern, connStatus} = msg const { pattern, connStatus } = msg
this.stateStore.setData('wifi', connStatus) this.stateStore.setData('wifi', connStatus)
this.vehicleStore.setData('pattern', pattern) this.vehicleStore.setData('pattern', pattern)
this.vehicleStore.setData(name, msg) this.vehicleStore.setData(name, msg)
...@@ -443,19 +447,19 @@ export default class Socket { ...@@ -443,19 +447,19 @@ export default class Socket {
case '/setting/ignoreObstaclesAck': case '/setting/ignoreObstaclesAck':
this.dealObstaclesAck(msg) this.dealObstaclesAck(msg)
break break
default: default:
this.vehicleStore.setData(name, msg) this.vehicleStore.setData(name, msg)
break break
} }
} }
dealmapHmiData(result) { dealmapHmiData(result) {
const {type, msg} = result const { type, msg } = result
let [, , name] = type.split('/') let [, , name] = type.split('/')
switch(type) { switch (type) {
// 地图不平整度文件回复 // 地图不平整度文件回复
case '/setting/roughnessFileAck': case '/setting/roughnessFileAck':
const {type, fileName} = msg const { type, fileName } = msg
if (type === 1) { if (type === 1) {
this.mapStore.setData(name, fileName) this.mapStore.setData(name, fileName)
} }
...@@ -471,7 +475,7 @@ export default class Socket { ...@@ -471,7 +475,7 @@ export default class Socket {
const worker = this.root.worker.worker.time const worker = this.root.worker.worker.time
worker.postMessage('start') worker.postMessage('start')
worker.onmessage = ({data}) => { worker.onmessage = ({ data }) => {
self.stateStore.setData('currentTime', data) self.stateStore.setData('currentTime', data)
} }
} }
...@@ -479,7 +483,7 @@ export default class Socket { ...@@ -479,7 +483,7 @@ export default class Socket {
postParentMessage(data) { postParentMessage(data) {
if (data) { if (data) {
let loginInfo = data let loginInfo = data
if (window.top && loginInfo && data.code ===0) { if (window.top && loginInfo && data.code === 0) {
window.top.postMessage({ window.top.postMessage({
type: 'token', type: 'token',
data: { data: {
...@@ -500,8 +504,8 @@ export default class Socket { ...@@ -500,8 +504,8 @@ export default class Socket {
} }
dealloginData(result) { dealloginData(result) {
const {type, msg} = result const { type, msg } = result
switch(type) { switch (type) {
// 车端登录成功,有连结进来 车端就会发这个消息 // 车端登录成功,有连结进来 车端就会发这个消息
case '/truckmonitor/start': case '/truckmonitor/start':
// 收到车端登录成功的消息,则不需要判断收到心跳的次数 // 收到车端登录成功的消息,则不需要判断收到心跳的次数
...@@ -556,7 +560,7 @@ export default class Socket { ...@@ -556,7 +560,7 @@ export default class Socket {
} }
} }
const {type, msg} = result const { type, msg } = result
// console.log(`接收消息${type}`, new Date().format('yyyy-MM-dd hh:mm:ss')) // console.log(`接收消息${type}`, new Date().format('yyyy-MM-dd hh:mm:ss'))
if (!type) return if (!type) return
...@@ -572,7 +576,7 @@ export default class Socket { ...@@ -572,7 +576,7 @@ export default class Socket {
} }
} }
close () { close() {
this.isClosed = true this.isClosed = true
this.heartTimer && clearTimeout(this.heartTimer) this.heartTimer && clearTimeout(this.heartTimer)
this.serverTimer && clearTimeout(this.serverTimer) this.serverTimer && clearTimeout(this.serverTimer)
......
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