【类 型】:feat 向飞机请求返回 电池容量

【原  因】:
【过  程】:监测飞机状态 电池容量null 时 向飞机请求 返回电池容量
【影  响】:

# 类型 包含:
# feat:新功能(feature)
# fix:修补bug
# docs:文档(documentation)
# style: 格式(不影响代码运行的变动)
# refactor:重构(即不是新增功能,也不是修改bug的代码变动)
# test:增加测试
# chore:构建过程或辅助工具的变动
This commit is contained in:
szdot 2024-07-20 18:42:47 +08:00
parent 300a107ae6
commit 4d46c3cdac
2 changed files with 33 additions and 16 deletions

View File

@ -10,6 +10,7 @@
</template> </template>
<script> <script>
import mqtt from '@/utils/mqtt'
import MapBox from '@/components/MapBox' import MapBox from '@/components/MapBox'
import ControllerTabs from '@/components/ControllerTabs' import ControllerTabs from '@/components/ControllerTabs'
import PlaneStatus from '@/components/PlaneStatus' import PlaneStatus from '@/components/PlaneStatus'
@ -100,6 +101,10 @@ export default {
plane: { plane: {
handler (val) { handler (val) {
this.makePlane(val)// this.makePlane(val)//
if (val.planeState.battCapacity === null) {
console.log(val.planeState.battCapacity)
mqtt.publishFun(`cmd/${this.plane.macadd}`, '{"getBattCapacity":1}')//
}
}, },
deep: true deep: true
}, },

View File

@ -81,24 +81,36 @@ export default {
mqtt.doSubscribe('planeState/+', (mqttRes) => { mqtt.doSubscribe('planeState/+', (mqttRes) => {
res.forEach(plane => { res.forEach(plane => {
if (mqttRes.topic.indexOf(plane.macadd) > -1) { if (mqttRes.topic.indexOf(plane.macadd) > -1) {
// mqtt try {
const jsonData = JSON.parse(mqttRes.msg.trim()) // mqtt
// mqtt const jsonData = JSON.parse(mqttRes.msg.trim())
for (const key in jsonData) {
if (key === 'heartBeat') { // heartRandom watch // mqtt
plane.planeState.heartRandom = Math.random() for (const key in jsonData) {
} if (key === 'heartBeat') {
if (key === 'position') { // 便 // heartRandom watch
let position = jsonData.position plane.planeState.heartRandom = Math.random()
position = position.replace(/([a-zA-Z0-9]+):/g, '"$1":')// mcujson "lng": } else if (key === 'position') {
position = JSON.parse(position) // 便
plane.planeState.position.push([position.lng / 10e6, position.lat / 10e6, Number(position.alt)]) const position = JSON.parse(jsonData.position)
if (plane.planeState.position.length > 1000) { plane.planeState.position.push([position.lng / 10e6, position.lat / 10e6, Number(position.alt)])
plane.planeState.position.shift()// if (plane.planeState.position.length > 1000) {
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] //
} }
} else {
plane.planeState[key] = jsonData[key]//
} }
} catch (error) {
console.error('Error parsing JSON or processing message:', error)
} }
} }
}) })