提交 b3200dda 作者: 翁进城

mqtt快捷指令

上级 fba2db77
export default {
无人机模式切换: 513,
云台控制指令can包透传: 514,
原地起飞控制: 515,
原地降落: 516,
返航: 517,
航线控制: 518,
摇杆控制: 519,
航线下载: 520,
航线上传: 521,
航线一键起飞: 522,
暂停航线任务: 523,
继续航线任务: 524,
结束航线任务: 525,
MAVLink数据包透传: 526,
激活无人机: 527,
NX控制: 528,
无人机参数设置: 530,
设备控制: 531, //无人机警灯、尾灯、降落伞、隐蔽控制
绑定任务id: 769,
链路切换: 770
};
import mqtt from 'mqtt';
import mqttOrders from "./mqttOrders";
function uint8array2json(uint8array) {
if (!uint8array || !uint8array.length) {
......@@ -21,6 +22,7 @@ export default {
type(如258): {}
} */
},
mqttOrders, //所有指令
},
mutations: {
setClient(state, data) {
......@@ -125,13 +127,37 @@ export default {
* @param {*} options
* @param {*} type
*/
publish({state}, {topic, message, callback, options = { qos: 0 }}) {
publish({ state }, { topic, data, callback, options = { qos: 0 } }) {
console.log('publish', topic, data)
state.client.publish(
topic,
new TextEncoder().encode(JSON.stringify(message)),
new TextEncoder().encode(JSON.stringify(data)),
options,
callback
);
},
/**
* 全部指令
* @param {*} param0
* @param {*} param1
* @param {String} param1.topic 发送的主题
* @param {String} param1.order 指令名称
* @param {Object} param1.data 指令对应的数据
* @param {Function} param1.callback 成功回调
*/
order({ dispatch }, { topic, order, data, callback }) {
if (mqttOrders[order] === undefined) {
throw "该命令不存在!";
}
dispatch("publish", {
topic,
data: {
type: mqttOrders[order],
data,
callback,
},
});
},
},
};
\ No newline at end of file
......@@ -3,8 +3,11 @@
<el-form>
<el-form-item label="无人机id">
<el-input v-model="deviceHardId"></el-input>
<el-button @click="onSubscribe">订阅</el-button>
</el-form-item>
<el-form-item label="操作">
<el-button @click="subscribe">订阅</el-button>
<el-button @click="unsubscribe">取消</el-button>
<el-button @click="publish({type: mqttOrders.继续航线任务})">继续飞行</el-button>
</el-form-item>
</el-form>
<div>
......@@ -24,6 +27,12 @@ export default {
computed: {
text(){
return this.$store.state.MMCMQTT.dataSet;
},
mqttOrders(){
return this.$store.state.MMCMQTT.mqttOrders;
},
topic(){
return `PX4/RECEIVE/${this.deviceHardId}`;
}
},
async created(){
......@@ -37,9 +46,9 @@ export default {
console.log('mqtt连接成功');
},
methods: {
onSubscribe(){
subscribe(){
this.$store.dispatch('MMCMQTT/subscribe', {
topic: `PX4/RECEIVE/${this.deviceHardId}`,
topic: this.topic,
callback(){
console.log('订阅成功')
}
......@@ -47,8 +56,19 @@ export default {
},
unsubscribe(){
this.$store.dispatch('MMCMQTT/unsubscribe', {
topic: `PX4/RECEIVE/${this.deviceHardId}`
topic: this.topic
})
},
publish({ type }){
this.$store.dispatch('MMCMQTT/publish', {
topic: this.topic,
data: {
type
},
callback(){
alert('发送成功')
}
})
}
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论