【类 型】:feat
【原 因】:把飞机的飞行数据 传到服务器数据库 ps:判断心跳解锁 开始记录数据 到加锁 把期间的数据上传 未完待续 【过 程】: 【影 响】: # 类型 包含: # feat:新功能(feature) # fix:修补bug # docs:文档(documentation) # style: 格式(不影响代码运行的变动) # refactor:重构(即不是新增功能,也不是修改bug的代码变动) # test:增加测试 # chore:构建过程或辅助工具的变动
This commit is contained in:
parent
647eb16956
commit
d4cd18256e
@ -303,6 +303,8 @@ const store = new Vuex.Store({
|
|||||||
const res = await api.get('getAirList')
|
const res = await api.get('getAirList')
|
||||||
res.data.airList.forEach(plane => {
|
res.data.airList.forEach(plane => {
|
||||||
plane.planeState = { // 飞机状态初始化字段
|
plane.planeState = { // 飞机状态初始化字段
|
||||||
|
flyDataMark: false, // 飞机解锁标记成真
|
||||||
|
flyDataSave: [], // 飞机加锁截至 待上传飞行数据之后 再清空此值
|
||||||
heartBeat: null, // 心跳
|
heartBeat: null, // 心跳
|
||||||
heartRandom: null, // 每次接收到心跳创建一个随机数 用于watch监听
|
heartRandom: null, // 每次接收到心跳创建一个随机数 用于watch监听
|
||||||
voltagBattery: null, // 电压信息
|
voltagBattery: null, // 电压信息
|
||||||
|
@ -178,3 +178,9 @@ export async function getFlyData (idArr, startTime, endTime) {
|
|||||||
const res = await api.post('getFlyDataByIdArr', params, 'Plane')
|
const res = await api.post('getFlyDataByIdArr', params, 'Plane')
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
*@abstract 上传保存飞机 飞行数据 检测心跳 解锁开始记录数据 加锁上传数据
|
||||||
|
*/
|
||||||
|
export async function saveFlyData () {
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -23,21 +23,19 @@ export default {
|
|||||||
* @Description: mqtt对象初始化
|
* @Description: mqtt对象初始化
|
||||||
*/
|
*/
|
||||||
function mqttConf () {
|
function mqttConf () {
|
||||||
if (!this.client) {
|
if (!this.client || (this.client && !this.client.connected)) {
|
||||||
// 链接mqtt
|
// 如果 client 不存在,或存在但未连接,重新连接
|
||||||
this.client = mqtt.connect(this.url, this.options)
|
this.client = mqtt.connect(this.url, this.options)
|
||||||
// mqtt服务器中断
|
|
||||||
this.client.on('error', () => {
|
this.client.on('error', () => {
|
||||||
store.dispatch('fetchLog', { content: '指令服务器异常中断' })
|
store.dispatch('fetchLog', { content: '指令服务器异常中断' })
|
||||||
})
|
})
|
||||||
// 端口之后复连
|
|
||||||
this.client.on('reconnect', () => {
|
this.client.on('reconnect', () => {
|
||||||
store.dispatch('fetchLog', { content: '重新连接指令服务器' })
|
store.dispatch('fetchLog', { content: '重新连接指令服务器' })
|
||||||
})
|
})
|
||||||
// 监听断开连接事件
|
|
||||||
this.client.on('offline', () => {
|
this.client.on('offline', () => {
|
||||||
store.dispatch('fetchLog', { content: '指令服务器异常中断' })
|
store.dispatch('fetchLog', { content: '指令服务器异常中断' })
|
||||||
store.state.app.mqttState = false // 标记mqtt链接失败 掉线
|
store.state.app.mqttState = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,8 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
|
/* mqtt */
|
||||||
|
mqtt.mqttConf()// 连接mqtt
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
/* init */
|
/* init */
|
||||||
@ -77,9 +79,6 @@ export default {
|
|||||||
* @param {*} res 飞机列表
|
* @param {*} res 飞机列表
|
||||||
*/
|
*/
|
||||||
airList (res) {
|
airList (res) {
|
||||||
/* mqtt */
|
|
||||||
mqtt.mqttDestroy()// 先断开mqtt
|
|
||||||
mqtt.mqttConf()// 连接mqtt
|
|
||||||
// 订阅飞机信息
|
// 订阅飞机信息
|
||||||
mqtt.doSubscribe('planeState/+', (mqttRes) => {
|
mqtt.doSubscribe('planeState/+', (mqttRes) => {
|
||||||
res.forEach(plane => {
|
res.forEach(plane => {
|
||||||
@ -91,8 +90,29 @@ export default {
|
|||||||
// 更新mqtt信息 选择性更新状态
|
// 更新mqtt信息 选择性更新状态
|
||||||
for (const key in jsonData) {
|
for (const key in jsonData) {
|
||||||
if (key === 'heartBeat') {
|
if (key === 'heartBeat') {
|
||||||
plane.planeState.heartRandom = Math.random()// 每次接收到心跳 heartRandom属性 创建一个随机数 用于watch监听
|
const oldMark = plane.planeState.flyDataMark
|
||||||
plane.planeState.heartBeat = jsonData.heartBeat // 按订阅信息 刷新飞机状态
|
const newMark = (Number(jsonData.heartBeat) & 128) !== 0
|
||||||
|
|
||||||
|
// 每次接收到心跳时,更新随机数以触发 watch 监听
|
||||||
|
plane.planeState.heartRandom = Math.random()
|
||||||
|
plane.planeState.heartBeat = jsonData.heartBeat
|
||||||
|
|
||||||
|
// 解锁状态变更检测:用于控制飞行数据的采集与上传
|
||||||
|
if (!oldMark && newMark) {
|
||||||
|
// 从加锁切换为解锁:开始记录飞行轨迹
|
||||||
|
plane.planeState.flyDataMark = true
|
||||||
|
} else if (oldMark && !newMark) {
|
||||||
|
// 从解锁切换为加锁:停止记录并上传飞行轨迹
|
||||||
|
plane.planeState.flyDataMark = false
|
||||||
|
|
||||||
|
const uploadData = [...plane.planeState.flyDataSave]
|
||||||
|
console.log(`上传飞机 ${plane.macadd} 的飞行数据:`, uploadData)
|
||||||
|
// TODO: 后续实现:上传飞行数据接口
|
||||||
|
// await api.post('uploadFlightPath', { macadd: plane.macadd, data: uploadData })
|
||||||
|
|
||||||
|
// 上传完成后清空记录缓存
|
||||||
|
plane.planeState.flyDataSave = []
|
||||||
|
}
|
||||||
} else if (key === 'position') {
|
} else if (key === 'position') {
|
||||||
// 如果是飞机位置信息 则不是直接刷新状态 而是累计 到数组 以便于画出飞机路径
|
// 如果是飞机位置信息 则不是直接刷新状态 而是累计 到数组 以便于画出飞机路径
|
||||||
const position = JSON.parse(jsonData.position)
|
const position = JSON.parse(jsonData.position)
|
||||||
@ -105,6 +125,10 @@ export default {
|
|||||||
if (plane.planeState.position.length > 1000) {
|
if (plane.planeState.position.length > 1000) {
|
||||||
plane.planeState.position.shift() // 删除最早的经纬度
|
plane.planeState.position.shift() // 删除最早的经纬度
|
||||||
}
|
}
|
||||||
|
// 如果是解锁状态,记录轨迹用于上传
|
||||||
|
if (plane.planeState.flyDataMark) {
|
||||||
|
plane.planeState.flyDataSave.push([position.lon / 10e6, position.lat / 10e6, Number(position.alt)])
|
||||||
|
}
|
||||||
} else if (key === 'homePosition') {
|
} else if (key === 'homePosition') {
|
||||||
const homePosition = JSON.parse(jsonData.homePosition)// home点反序列化再赋值
|
const homePosition = JSON.parse(jsonData.homePosition)// home点反序列化再赋值
|
||||||
homePosition.lon = homePosition.lon / 10e6
|
homePosition.lon = homePosition.lon / 10e6
|
||||||
|
Loading…
Reference in New Issue
Block a user