223 lines
8.3 KiB
Java
223 lines
8.3 KiB
Java
|
|
//package com.example.math.utils;
|
||
|
|
//
|
||
|
|
//import com.alibaba.fastjson.JSONObject;
|
||
|
|
//import com.example.math.constants.DJIMethonConstants;
|
||
|
|
//import com.example.math.mqtt.MqttConfig;
|
||
|
|
//import lombok.extern.slf4j.Slf4j;
|
||
|
|
//import org.eclipse.paho.client.mqttv3.MqttDeliveryToken;
|
||
|
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||
|
|
//import org.springframework.beans.factory.annotation.Value;
|
||
|
|
//import org.springframework.stereotype.Component;
|
||
|
|
//import org.springframework.web.bind.annotation.ResponseBody;
|
||
|
|
//
|
||
|
|
//import javax.annotation.Resource;
|
||
|
|
//import java.util.HashMap;
|
||
|
|
//import java.util.Map;
|
||
|
|
//import java.util.UUID;
|
||
|
|
//
|
||
|
|
///**
|
||
|
|
// * 远程大疆的工具类
|
||
|
|
// */
|
||
|
|
//@Component
|
||
|
|
//@Slf4j
|
||
|
|
//public class DJIUtils {
|
||
|
|
//
|
||
|
|
// @Resource
|
||
|
|
// private MqttConfig providerClient;
|
||
|
|
//
|
||
|
|
// @Value("${spring.newMqtt.username}")
|
||
|
|
// private String username;
|
||
|
|
//
|
||
|
|
// @Value("${spring.newMqtt.password}")
|
||
|
|
// private String password;
|
||
|
|
//
|
||
|
|
// @Value("${spring.newMqtt.url}")
|
||
|
|
// private String address;
|
||
|
|
//
|
||
|
|
// @Value("${spring.newMqtt.newUrl}")
|
||
|
|
// private String newAddress;
|
||
|
|
//
|
||
|
|
// @Value("${spring.newMqtt.client.id}")
|
||
|
|
// private String clientId;
|
||
|
|
//
|
||
|
|
// @Autowired
|
||
|
|
// private RedisUtils redisUtils;
|
||
|
|
//
|
||
|
|
// public static String filePath = "";
|
||
|
|
// public static String fileMd5 = "";
|
||
|
|
//
|
||
|
|
// //topic固定参数
|
||
|
|
// private static String someTopic = "thing/product/%s/services";
|
||
|
|
//
|
||
|
|
//
|
||
|
|
// //topic固定参数
|
||
|
|
// private static String propertySet = "thing/product/%s/property/set";
|
||
|
|
//
|
||
|
|
//
|
||
|
|
// //机场 无人机 镜头清晰度
|
||
|
|
// private static String camera = "normal-0";
|
||
|
|
//
|
||
|
|
//
|
||
|
|
//
|
||
|
|
//
|
||
|
|
// public static int seq = 0;
|
||
|
|
//
|
||
|
|
// /**
|
||
|
|
// * 飞行控制权抢夺 /flightAuthorityGrab
|
||
|
|
// * @param airPortSn 机场sn号
|
||
|
|
// * @return JsonResult
|
||
|
|
// */
|
||
|
|
// public String flightAuthorityGrab(String airPortSn){
|
||
|
|
// try {
|
||
|
|
// log.info("飞行控制权抢夺 flight_authority_grab is start");
|
||
|
|
// Integer qos = 1;
|
||
|
|
// Boolean retained = false;
|
||
|
|
// //topic主题 sn是机场sn号 thing/product/%s/services
|
||
|
|
// //TODO 此处用的是无人的SN号 待测试
|
||
|
|
// String topic = String.format(someTopic, airPortSn);
|
||
|
|
// //封装数据
|
||
|
|
// Map<String,Object> content = new HashMap<>();
|
||
|
|
// Map<String,Object> data = new HashMap<>();
|
||
|
|
// String tid = UUID.randomUUID().toString();
|
||
|
|
// content.put("tid", tid);
|
||
|
|
// content.put("bid", UUID.randomUUID().toString());
|
||
|
|
// content.put("timestamp",System.currentTimeMillis());
|
||
|
|
// content.put("method", "flight_authority_grab");
|
||
|
|
// content.put("data", data);
|
||
|
|
// String message = JSONObject.toJSONString(content);
|
||
|
|
// System.out.println(message);
|
||
|
|
// MqttDeliveryToken publish = providerClient.publish(qos, retained, topic, message);
|
||
|
|
// log.info("飞行控制权抢夺 flight_authority_grab is end topic is {}, message is {}, token is {} ", topic, message, publish);
|
||
|
|
// return "发送成功";
|
||
|
|
// } catch (Exception e) {
|
||
|
|
// e.printStackTrace();
|
||
|
|
// return "发送成功";
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
//
|
||
|
|
// /**
|
||
|
|
// * 负载控制权抢夺 /payloadAuthorityGrab
|
||
|
|
// * @param airPortSn 机场sn号
|
||
|
|
// * @param cameraIndex 镜头参数
|
||
|
|
// * @return JsonResult
|
||
|
|
// */
|
||
|
|
// public String payloadAuthorityGrab(String cameraIndex, String airPortSn){
|
||
|
|
// try {
|
||
|
|
// Integer qos = 2;
|
||
|
|
// Boolean retained = false;
|
||
|
|
// //topic主题 sn是机场sn号 thing/product/%s/services
|
||
|
|
// //TODO 此处用的是无人的SN号 待测试
|
||
|
|
// String topic = String.format(someTopic, airPortSn);
|
||
|
|
// //封装数据
|
||
|
|
// Map<String,Object> content = new HashMap<>();
|
||
|
|
// Map<String,Object> data = new HashMap<>();
|
||
|
|
// //负载枚举值 镜头负载
|
||
|
|
// data.put("payload_index", cameraIndex);
|
||
|
|
// content.put("tid", UUID.randomUUID().toString());
|
||
|
|
// content.put("bid", UUID.randomUUID().toString());
|
||
|
|
// content.put("timestamp",System.currentTimeMillis());
|
||
|
|
// content.put("method", "payload_authority_grab");
|
||
|
|
// content.put("data", data);
|
||
|
|
// String message = JSONObject.toJSONString(content);
|
||
|
|
// System.out.println(message);
|
||
|
|
// MqttDeliveryToken publish = providerClient.publish(qos, retained, topic, message);
|
||
|
|
// return "发送成功";
|
||
|
|
// } catch (Exception e) {
|
||
|
|
// e.printStackTrace();
|
||
|
|
// return "发送失败";
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
//
|
||
|
|
//
|
||
|
|
// /**
|
||
|
|
// * 进入指令飞行控制模式
|
||
|
|
// * @return JsonResult
|
||
|
|
// */
|
||
|
|
// public String drcModeEnter(String airPortSn){
|
||
|
|
// try {
|
||
|
|
// seq = 0;
|
||
|
|
// Integer qos = 1;
|
||
|
|
// Boolean retained = false;
|
||
|
|
// //topic主题 sn是机场sn号 thing/product/%s/services
|
||
|
|
// //TODO 此处用的是无人的SN号 待测试
|
||
|
|
// String topic = String.format(someTopic, airPortSn);
|
||
|
|
// //封装数据
|
||
|
|
// Map<String,Object> content = new HashMap<>();
|
||
|
|
// Map<String,Object> data = new HashMap<>();
|
||
|
|
// //负载枚举值 镜头负载
|
||
|
|
// data.put("hsi_frequency", 1);
|
||
|
|
//
|
||
|
|
// //Broker 连接信息
|
||
|
|
// Map<String,Object> mqttBroker = new HashMap<>();
|
||
|
|
// //服务器连接地址
|
||
|
|
// mqttBroker.put("address", newAddress);
|
||
|
|
// //客户端ID
|
||
|
|
// mqttBroker.put("client_id", "DRC" + "-" + airPortSn);
|
||
|
|
// //enable_tls
|
||
|
|
// mqttBroker.put("enable_tls", false);
|
||
|
|
// //expire_time 当前时间+3000秒
|
||
|
|
// mqttBroker.put("expire_time", System.currentTimeMillis()/1000 + 36000);
|
||
|
|
// //密码
|
||
|
|
// mqttBroker.put("password", password);
|
||
|
|
// //用户名
|
||
|
|
// mqttBroker.put("username", username);
|
||
|
|
// data.put("mqtt_broker", mqttBroker);
|
||
|
|
// //设置 OSD 上报频率 {"max":30,"min":1,"unit_name":"赫兹 / Hz"}
|
||
|
|
// data.put("osd_frequency", 1);
|
||
|
|
//
|
||
|
|
// content.put("tid", UUID.randomUUID().toString());
|
||
|
|
// content.put("bid", UUID.randomUUID().toString());
|
||
|
|
// content.put("timestamp",System.currentTimeMillis());
|
||
|
|
// content.put("method", DJIMethonConstants.DRC_MODE_ENTER);
|
||
|
|
// content.put("data", data);
|
||
|
|
// String message = com.alibaba.fastjson.JSONObject.toJSONString(content);
|
||
|
|
// System.out.println(message);
|
||
|
|
// MqttDeliveryToken publish = providerClient.publish(qos, retained, topic, message);
|
||
|
|
// return "发送成功";
|
||
|
|
// } catch (Exception e) {
|
||
|
|
// e.printStackTrace();
|
||
|
|
// return "发送失败";
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
//
|
||
|
|
//
|
||
|
|
//
|
||
|
|
// /**
|
||
|
|
// * 退出指令飞行控制模式
|
||
|
|
// * @param airPortSn 机场sn号
|
||
|
|
// * @return JsonResult
|
||
|
|
// */
|
||
|
|
// @ResponseBody
|
||
|
|
// public String drcModeExit(String airPortSn){
|
||
|
|
// try {
|
||
|
|
// log.info("退出指令飞行控制模式 drc_mode_exit is start");
|
||
|
|
// Integer qos = 1;
|
||
|
|
// Boolean retained = false;
|
||
|
|
// //topic主题 sn是机场sn号 thing/product/%s/services
|
||
|
|
// //TODO 此处用的是无人的SN号 待测试
|
||
|
|
// String topic = String.format(someTopic, airPortSn);
|
||
|
|
// //封装数据
|
||
|
|
// Map<String,Object> content = new HashMap<>();
|
||
|
|
// Map<String,Object> data = new HashMap<>();
|
||
|
|
// content.put("tid", UUID.randomUUID().toString());
|
||
|
|
// content.put("bid", UUID.randomUUID().toString());
|
||
|
|
// content.put("timestamp",System.currentTimeMillis());
|
||
|
|
// content.put("method", DJIMethonConstants.DRC_MODE_EXIT);
|
||
|
|
// content.put("data", data);
|
||
|
|
// String message = JSONObject.toJSONString(content);
|
||
|
|
// System.out.println(message);
|
||
|
|
// MqttDeliveryToken publish = providerClient.publish(qos, retained, topic, message);
|
||
|
|
//// log.info("退出指令飞行控制模式 drc_mode_exit is end topic is {}, message is {}, token is {} ", topic, message, publish);
|
||
|
|
// return "发送成功";
|
||
|
|
// } catch (Exception e) {
|
||
|
|
// e.printStackTrace();
|
||
|
|
// return "发送失败";
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
//
|
||
|
|
//
|
||
|
|
//
|
||
|
|
//
|
||
|
|
//}
|
||
|
|
//
|