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

fix

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