// 无人机实时数据各链路融合
export default {
  computed: {
    // mqtt实时数据
    mqttDataSet() {
      return this.$store.state.MMCMQTT?.dataSet?.[this.uav?.hardId];
    },
    // 地面站实时数据
    gsDataSet() {
      return this.$store.state.MMCGroundStation?.dataSet?.[this.uav?.hardId];
    },
    mqttUrl() {
      return this.$store.getters["MMCFlightControlCenter/mqttUrl"];
    },
  },
  watch: {
    mqttDataSet(newVal) {
      if (this.uav?.network === 1) {
        if (newVal) {
          this.$store.dispatch(
            "MMCFlightControlCenter/uav/updateByMQTT",
            newVal
          );
        }
      }
    },
    gsDataSet(newVal) {
      if (this.uav?.network == 0) {
        if (newVal) {
          this.$store.dispatch(
            "MMCFlightControlCenter/uav/updateByMQTT",
            newVal
          );
        }
      }
    },
  },
  async created() {
    // 模拟飞机数据上报
    // this.$store.dispatch("MMCFlightControlCenter/uav/test", { open: true });
    // 启动mqtt服务
    try {
      this.$store
        .dispatch("MMCMQTT/init", {
          url: this.mqttUrl,
        })
        .then(() => {
          console.log("mqtt连接成功");
        });
    } catch (e) {
      console.log("mqtt失败", e);
    }

    // 由于地面站是广播形式的数据传输, 非常消耗性能, 把连接地面站ws的操作挪到了订阅中去, 取消订阅时就断开ws
  },
};
