【类 型】:feat

【原  因】:把飞机的飞行数据 传到服务器数据库  ps:判断心跳解锁 开始记录数据 到加锁  把期间的数据上传  未完待续
【过  程】:
【影  响】:

# 类型 包含:
# feat:新功能(feature)
# fix:修补bug
# docs:文档(documentation)
# style: 格式(不影响代码运行的变动)
# refactor:重构(即不是新增功能,也不是修改bug的代码变动)
# test:增加测试
# chore:构建过程或辅助工具的变动
This commit is contained in:
air 2025-06-13 22:58:49 +08:00
parent 647eb16956
commit d4cd18256e
4 changed files with 41 additions and 11 deletions

View File

@ -303,6 +303,8 @@ const store = new Vuex.Store({
const res = await api.get('getAirList')
res.data.airList.forEach(plane => {
plane.planeState = { // 飞机状态初始化字段
flyDataMark: false, // 飞机解锁标记成真
flyDataSave: [], // 飞机加锁截至 待上传飞行数据之后 再清空此值
heartBeat: null, // 心跳
heartRandom: null, // 每次接收到心跳创建一个随机数 用于watch监听
voltagBattery: null, // 电压信息

View File

@ -178,3 +178,9 @@ export async function getFlyData (idArr, startTime, endTime) {
const res = await api.post('getFlyDataByIdArr', params, 'Plane')
return res
}
/**
*@abstract 上传保存飞机 飞行数据 检测心跳 解锁开始记录数据 加锁上传数据
*/
export async function saveFlyData () {
}

View File

@ -23,21 +23,19 @@ export default {
* @Description: mqtt对象初始化
*/
function mqttConf () {
if (!this.client) {
// 链接mqtt
if (!this.client || (this.client && !this.client.connected)) {
// 如果 client 不存在,或存在但未连接,重新连接
this.client = mqtt.connect(this.url, this.options)
// mqtt服务器中断
this.client.on('error', () => {
store.dispatch('fetchLog', { content: '指令服务器异常中断' })
})
// 端口之后复连
this.client.on('reconnect', () => {
store.dispatch('fetchLog', { content: '重新连接指令服务器' })
})
// 监听断开连接事件
this.client.on('offline', () => {
store.dispatch('fetchLog', { content: '指令服务器异常中断' })
store.state.app.mqttState = false // 标记mqtt链接失败 掉线
store.state.app.mqttState = false
})
}
}

View File

@ -55,6 +55,8 @@ export default {
}
},
mounted () {
/* mqtt */
mqtt.mqttConf()// mqtt
},
created () {
/* init */
@ -77,9 +79,6 @@ export default {
* @param {*} res 飞机列表
*/
airList (res) {
/* mqtt */
mqtt.mqttDestroy()// mqtt
mqtt.mqttConf()// mqtt
//
mqtt.doSubscribe('planeState/+', (mqttRes) => {
res.forEach(plane => {
@ -91,8 +90,29 @@ export default {
// mqtt
for (const key in jsonData) {
if (key === 'heartBeat') {
plane.planeState.heartRandom = Math.random()// heartRandom watch
plane.planeState.heartBeat = jsonData.heartBeat //
const oldMark = plane.planeState.flyDataMark
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') {
// 便
const position = JSON.parse(jsonData.position)
@ -105,6 +125,10 @@ export default {
if (plane.planeState.position.length > 1000) {
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') {
const homePosition = JSON.parse(jsonData.homePosition)// home
homePosition.lon = homePosition.lon / 10e6