【类 型】:feat 向飞机请求返回 电池容量
【原 因】: 【过 程】:监测飞机状态 电池容量null 时 向飞机请求 返回电池容量 【影 响】: # 类型 包含: # feat:新功能(feature) # fix:修补bug # docs:文档(documentation) # style: 格式(不影响代码运行的变动) # refactor:重构(即不是新增功能,也不是修改bug的代码变动) # test:增加测试 # chore:构建过程或辅助工具的变动
This commit is contained in:
parent
300a107ae6
commit
4d46c3cdac
@ -10,6 +10,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import mqtt from '@/utils/mqtt'
|
||||
import MapBox from '@/components/MapBox'
|
||||
import ControllerTabs from '@/components/ControllerTabs'
|
||||
import PlaneStatus from '@/components/PlaneStatus'
|
||||
@ -100,6 +101,10 @@ export default {
|
||||
plane: {
|
||||
handler (val) {
|
||||
this.makePlane(val)// 有飞机数据之后 在地图上创建飞机
|
||||
if (val.planeState.battCapacity === null) {
|
||||
console.log(val.planeState.battCapacity)
|
||||
mqtt.publishFun(`cmd/${this.plane.macadd}`, '{"getBattCapacity":1}')// 发送设置飞机状态主题 请求飞控返回 电池总容量
|
||||
}
|
||||
},
|
||||
deep: true
|
||||
},
|
||||
|
@ -81,25 +81,37 @@ export default {
|
||||
mqtt.doSubscribe('planeState/+', (mqttRes) => {
|
||||
res.forEach(plane => {
|
||||
if (mqttRes.topic.indexOf(plane.macadd) > -1) {
|
||||
try {
|
||||
// 反序列化 mqtt信息
|
||||
const jsonData = JSON.parse(mqttRes.msg.trim())
|
||||
|
||||
// 更新mqtt信息 选择性更新状态
|
||||
for (const key in jsonData) {
|
||||
if (key === 'heartBeat') { // 每次接收到心跳 heartRandom属性 创建一个随机数 用于watch监听
|
||||
if (key === 'heartBeat') {
|
||||
// 每次接收到心跳 heartRandom属性 创建一个随机数 用于watch监听
|
||||
plane.planeState.heartRandom = Math.random()
|
||||
}
|
||||
if (key === 'position') { // 如果是飞机位置信息 则不是直接刷新状态 而是累计 到数组 以便于画出飞机路径
|
||||
let position = jsonData.position
|
||||
position = position.replace(/([a-zA-Z0-9]+):/g, '"$1":')// mcu过来的json格式修正一下 键没有引号 改成"lng":
|
||||
position = JSON.parse(position)
|
||||
} else if (key === 'position') {
|
||||
// 如果是飞机位置信息 则不是直接刷新状态 而是累计 到数组 以便于画出飞机路径
|
||||
const position = JSON.parse(jsonData.position)
|
||||
plane.planeState.position.push([position.lng / 10e6, position.lat / 10e6, Number(position.alt)])
|
||||
if (plane.planeState.position.length > 1000) {
|
||||
plane.planeState.position.shift()// 删除最早的经纬度
|
||||
plane.planeState.position.shift() // 删除最早的经纬度
|
||||
}
|
||||
} else if (key === 'parameter') {
|
||||
// 如果是 get飞控参数 判断设置对应值
|
||||
const parameter = JSON.parse(jsonData.parameter.trim())
|
||||
for (const k in parameter) {
|
||||
if (k === 'BATT_CAPACITY') {
|
||||
plane.planeState.battCapacity = parameter.BATT_CAPACITY
|
||||
}
|
||||
}
|
||||
} else {
|
||||
plane.planeState[key] = jsonData[key]// 按订阅信息 刷新飞机状态
|
||||
plane.planeState[key] = jsonData[key] // 按订阅信息 刷新飞机状态
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error parsing JSON or processing message:', error)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user