package com.example.math.controller; import com.alibaba.fastjson2.JSONObject; import com.example.math.constants.DJIMethonConstants; import com.example.math.entity.dto.BreakPoint; import com.example.math.entity.dto.ExecutableConditions; import com.example.math.entity.dto.FileDto; import com.example.math.entity.dto.FlightTask; import com.example.math.entity.dto.ReadyConditions; import com.example.math.entity.dto.SimulateMission; import com.example.math.mqtt.MqttConfig; import com.example.math.mqtt.SpringUtil; //import com.example.math.task.FirstTask; import com.example.math.utils.RedisUtils; import com.example.math.utils.SslUtils; import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.ArchiveInputStream; import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; 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.Controller; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.sql.Date; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.UUID; /** * * * http://localhost:9999/operate/debug_mode_open 打开调试模式 * http://localhost:9999/operate/debug_mode_close 关闭调试模式 * * http://localhost:9999/operate/cover_open 开仓 * http://localhost:9999/operate/cover_close 关仓 * * http://localhost:9999/operate/drone_open 开机 * http://localhost:9999/operate/drone_close 关机 * * * http://localhost:9999/operate/flighttask_prepare?fid=12345611 下发任务 * http://localhost:9999/operate/flighttask_execute 执行任务 * * * http://localhost:9999/operate/return_home 一键返航 * * http://localhost:9999/operate/live_start_push 开始直播 * * http://localhost:9999/operate/live_start_push1?one=1581F6Q8D248900G5PYE&two=81-0-0&three=normal-0 开始直播 * http://localhost:9999/operate/live_start_push?one=7CTDM7H00B5EM1&two=165-0-7&three=normal-0 * * live_stop_push * http://localhost:9999/operate/live_stop_push?one=7CTDM7H00B5EM1&two=165-0-7&three=normal-0 * http://localhost:9999/operate/live_stop_push?one=1581F6Q8D248900G5PYE&two=81-0-0&three=normal-0 * * http://localhost:9999/operate/live_lens_change?video_type=normal * * * * @param airPortSn 机场sn号 * * @param airPortSn 速度 String maxsSpeed * * @param height 高度 * * @param latitude 纬度 * * @param longitude 经度 * String airPortSn, String maxsSpeed, String height, String latitude, String longitude * String airPortSn, String maxsSpeed, String height, String latitude, String longitude * http://localhost:8089/operate/flyToPoint?airPortSn=7CTDM7H00B5EM1&maxsSpeed=10&height=50&latitude=26.927594103004807&longitude=112.62790494935818 * http://localhost:8089/operate/flyToPoint?airPortSn=7CTDM7H00B5EM1&maxsSpeed=10&height=100&latitude=26.926174098&longitude=112.629257343 * http://localhost:8089/operate/flyToPoint?airPortSn=7CTDM7H00B5EM1&maxsSpeed=10&height=100&latitude=26.926870569&longitude=112.628649594 * http://localhost:8089/operate/flyToPoint?airPortSn=7CTDM7H00B5EM1&maxsSpeed=10&height=100&latitude=26.926953317&longitude=112.629688156 * * http://localhost:8089/operate/ * * */ @RequestMapping(path="/operate") @Controller public class OperateController { @Autowired private MqttConfig providerClient; @RequestMapping("/sendMessage") @ResponseBody public String sendMessage(Integer qos,Boolean retained,String topic,String message){ try { if(qos == null){ qos = 2; } if(retained == null){ retained = true; } if(topic == null){ topic = "firsttest"; } if(message == null){ message = "msg is " + System.currentTimeMillis(); } providerClient.publish(qos, retained, topic, message); return "发送成功"; } catch (Exception e) { e.printStackTrace(); return "发送失败"; } } /** * 开仓 * @param qos * @param retained * @param topic * @param message * @return */ @RequestMapping("/cover_open") @ResponseBody public String cover_open(Integer qos,Boolean retained,String topic,String message){ try { if(qos == null){ qos = 2; } if(retained == null){ retained = true; } if(topic == null){ topic = "thing/product/7CTDM7H00B5EM1/services"; } if(message == null){ Map content = new HashMap<>(); content.put("method","cover_open"); content.put("tid","85e4e49f-526c-4f5d-b307-c5bdf504a635"); content.put("bid","9163cba9-e2a0-4946-af25-c9f2384c895e"); content.put("timestamp",System.currentTimeMillis()); content.put("data",new HashMap<>()); message = JSONObject.toJSONString(content); } System.out.println(message); providerClient.publish(qos, retained, topic, message); return "发送成功"; } catch (Exception e) { e.printStackTrace(); return "发送失败"; } } /** * 关仓 * @param qos * @param retained * @param topic * @param message * @return */ @RequestMapping("/cover_close") @ResponseBody public String cover_close(Integer qos,Boolean retained,String topic,String message){ try { if(qos == null){ qos = 2; } if(retained == null){ retained = true; } if(topic == null){ topic = "thing/product/7CTDM7H00B5EM1/services"; } if(message == null){ Map content = new HashMap<>(); content.put("tid","826ee109-79b0-491f-b9d5-b88ca00bc509"); content.put("bid","519c2540-ae9f-432c-a899-97053054929b"); content.put("timestamp",System.currentTimeMillis()); content.put("data",new HashMap<>()); content.put("method","cover_close"); message = JSONObject.toJSONString(content); } System.out.println(message); providerClient.publish(qos, retained, topic, message); return "发送成功"; } catch (Exception e) { e.printStackTrace(); return "发送失败"; } } /** * 开机 * @param qos * @param retained * @param topic * @param message * @return */ @RequestMapping("/drone_open") @ResponseBody public String drone_open(Integer qos,Boolean retained,String topic,String message){ try { if(qos == null){ qos = 2; } if(retained == null){ retained = true; } if(topic == null){ topic = "thing/product/7CTDM7H00B5EM1/services"; } if(message == null){ Map content = new HashMap<>(); content.put("tid","826ee109-79b0-491f-b9d5-b88ca00bc509"); content.put("bid","519c2540-ae9f-432c-a899-97053054929b"); content.put("timestamp",System.currentTimeMillis()); content.put("data",new HashMap<>()); content.put("method","drone_open"); message = JSONObject.toJSONString(content); } System.out.println(message); providerClient.publish(qos, retained, topic, message); return "发送成功"; } catch (Exception e) { e.printStackTrace(); return "发送失败"; } } /** * 关机 * @param qos * @param retained * @param topic * @param message * @return */ @RequestMapping("/drone_close") @ResponseBody public String drone_close(Integer qos,Boolean retained,String topic,String message){ try { if(qos == null){ qos = 2; } if(retained == null){ retained = true; } if(topic == null){ topic = "thing/product/7CTDM7H00B5EM1/services"; } if(message == null){ Map content = new HashMap<>(); content.put("tid","826ee109-79b0-491f-b9d5-b88ca00bc509"); content.put("bid","519c2540-ae9f-432c-a899-97053054929b"); content.put("timestamp",System.currentTimeMillis()); content.put("data",new HashMap<>()); content.put("method","drone_close"); message = JSONObject.toJSONString(content); } System.out.println(message); providerClient.publish(qos, retained, topic, message); return "发送成功"; } catch (Exception e) { e.printStackTrace(); return "发送失败"; } } /** * 开启调试模式 * @param qos * @param retained * @param topic * @param message * @return */ @RequestMapping("/debug_mode_open") @ResponseBody public String debug_mode_open(Integer qos,Boolean retained,String topic,String message){ try { if(qos == null){ qos = 2; } if(retained == null){ retained = true; } if(topic == null){ topic = "thing/product/7CTDM7H00B5EM1/services"; } if(message == null){ Map content = new HashMap<>(); content.put("tid",""); content.put("bid",""); content.put("timestamp",System.currentTimeMillis()); content.put("method","debug_mode_open"); content.put("data",new HashMap<>()); message = JSONObject.toJSONString(content); } System.out.println(message); providerClient.publish(qos, retained, topic, message); return "发送成功"; } catch (Exception e) { e.printStackTrace(); return "发送失败"; } } /** * 关闭debug模式 * @param qos * @param retained * @param topic * @param message * @return */ @RequestMapping("/debug_mode_close") @ResponseBody public String debug_mode_close(Integer qos,Boolean retained,String topic,String message){ try { if(qos == null){ qos = 2; } if(retained == null){ retained = true; } if(topic == null){ topic = "thing/product/7CTDM7H00B5EM1/services"; } if(message == null){ Map content = new HashMap<>(); content.put("tid",""); content.put("bid",""); content.put("timestamp",System.currentTimeMillis()); content.put("method","debug_mode_close"); content.put("data",new HashMap<>()); message = JSONObject.toJSONString(content); } System.out.println(message); providerClient.publish(qos, retained, topic, message); return "发送成功"; } catch (Exception e) { e.printStackTrace(); return "发送失败"; } } @RequestMapping("/return_home") @ResponseBody public String return_home(Integer qos,Boolean retained,String topic,String message){ try { if(qos == null){ qos = 2; } if(retained == null){ retained = true; } if(topic == null){ topic = "thing/product/7CTDM7H00BXZD1/services"; } if(message == null){ Map content = new HashMap<>(); content.put("tid",""); content.put("bid",""); content.put("timestamp",System.currentTimeMillis()); content.put("method","return_home"); content.put("data",new HashMap<>()); message = JSONObject.toJSONString(content); } System.out.println(message); providerClient.publish(qos, retained, topic, message); return "发送成功"; } catch (Exception e) { e.printStackTrace(); return "发送失败"; } } private static String flight_id = "12345707"; @RequestMapping("/flighttask_prepare") @ResponseBody public String flighttask_prepare(Integer qos,Boolean retained,String topic,String message, String fid){ if(fid == null){ System.out.println("需要传id"); } flight_id = fid; try { if(qos == null){ qos = 2; } if(retained == null){ retained = true; } if(topic == null){ topic = "thing/product/7CTDM7H00B5EM1/services"; } if(message == null){ Map content = new HashMap<>(); FileDto file = new FileDto(); file.setUrl("https://ta-tech-image.oss-cn-shanghai.aliyuncs.com/test_line/50%2B20.kmz"); file.setFingerprint("5301fac50e52af16c7b6c15e5d4bc41c"); ReadyConditions readyConditions = new ReadyConditions(); readyConditions.setBattery_capacity(30); readyConditions.setBegin_time(System.currentTimeMillis() - 300*1000); readyConditions.setEnd_time(System.currentTimeMillis() + 300*1000); ExecutableConditions executableConditions = new ExecutableConditions(); executableConditions.setStorage_capacity(10); BreakPoint breakPoint = new BreakPoint(); breakPoint.setWayline_id(0); breakPoint.setState(0); breakPoint.setProgress(0.34); breakPoint.setIndex(1); SimulateMission simulateMission = new SimulateMission(); simulateMission.setIs_enable(0); simulateMission.setLongitude(112.62790937463406); simulateMission.setLatitude(26.9275951462299); FlightTask flightTask = new FlightTask(); flightTask.setFlight_id(flight_id); // flightTask.setExecute_time(System.currentTimeMillis()+ 30*1000); // flightTask.setTask_type(2); // flightTask.setRth_altitude(60); flightTask.setRth_mode(1); flightTask.setOut_of_control_action(0); flightTask.setExit_wayline_when_rc_lost(1); flightTask.setWayline_precision_type(1); flightTask.setFile(file); flightTask.setReady_conditions(readyConditions); flightTask.setExecutable_conditions(executableConditions); flightTask.setBreak_point(breakPoint); flightTask.setSimulate_mission(simulateMission); String tid = UUID.randomUUID().toString(); String bid = UUID.randomUUID().toString(); content.put("tid",tid); content.put("bid",bid); // content.put("tid","9c69531e-b118-4a31-b586-1f2251ef77f4"); // content.put("bid","8b46b451-21bd-496e-86a5-d2524fab0fa2"); content.put("timestamp",System.currentTimeMillis()); content.put("method","flighttask_prepare"); content.put("data",flightTask); message = JSONObject.toJSONString(content); } System.out.println(message); providerClient.publish(qos, retained, topic, message); return "发送成功"; } catch (Exception e) { e.printStackTrace(); return "发送失败"; } } /** * 执行任务 * @param qos * @param retained * @param topic * @param message * @return */ @RequestMapping("/flighttask_execute") @ResponseBody public String flighttask_execute(Integer qos,Boolean retained,String topic,String message){ try { if(qos == null){ qos = 2; } if(retained == null){ retained = true; } if(topic == null){ topic = "thing/product/7CTDM7H00B5EM1/services"; } if(message == null){ Map content = new HashMap<>(); Map data = new HashMap<>(); data.put("flight_id",flight_id); String tid = UUID.randomUUID().toString(); String bid = UUID.randomUUID().toString(); content.put("tid",tid); content.put("bid",bid); // content.put("tid","9c69531e-b118-4a31-b586-1f2251ef77f4"); // content.put("bid","8b46b451-21bd-496e-86a5-d2524fab0fa2"); content.put("timestamp",System.currentTimeMillis()); content.put("method","flighttask_execute"); content.put("data",data); message = JSONObject.toJSONString(content); } System.out.println(message); providerClient.publish(qos, retained, topic, message); return "发送成功"; } catch (Exception e) { e.printStackTrace(); return "发送失败"; } } /** * 取消任务 * @param qos * @param retained * @param topic * @param message * @return */ @RequestMapping("/flighttask_undo") @ResponseBody public String flighttask_undo(Integer qos,Boolean retained,String topic,String message){ try { if(qos == null){ qos = 2; } if(retained == null){ retained = true; } if(topic == null){ topic = "thing/product/7CTDM7H00B5EM1/services"; } if(message == null){ Map content = new HashMap<>(); Map data = new HashMap<>(); data.put("flight_id","xxxxx"); content.put("tid",""); content.put("bid",""); content.put("timestamp",System.currentTimeMillis()); content.put("method","flighttask_undo"); content.put("data",new HashMap<>()); message = JSONObject.toJSONString(content); } System.out.println(message); providerClient.publish(qos, retained, topic, message); return "发送成功"; } catch (Exception e) { e.printStackTrace(); return "发送失败"; } } @RequestMapping("/fileupload_list") @ResponseBody public String fileupload_list(Integer qos,Boolean retained,String topic,String message){ try { if(qos == null){ qos = 2; } if(retained == null){ retained = true; } if(topic == null){ topic = "thing/product/7CTXM9Q00B02H2/services"; } if(message == null){ Map content = new HashMap<>(); content.put("tid",""); content.put("bid",""); content.put("timestamp",System.currentTimeMillis()); content.put("method","fileupload_list"); content.put("data", new HashMap<>()); message = JSONObject.toJSONString(content); } System.out.println(message); providerClient.publish(qos, retained, topic, message); return "发送成功"; } catch (Exception e) { e.printStackTrace(); return "发送失败"; } } @RequestMapping("/live_start_push") @ResponseBody public String live_start_push(Integer qos,Boolean retained,String topic,String message, String one, String two, String three){ String vid = one + "/" + two + "/" + three; try { if(qos == null){ qos = 2; } if(retained == null){ retained = true; } if(topic == null){ topic = "thing/product/7CTDM7H00B5EM1/services"; } if(message == null){ Map content = new HashMap<>(); Map data = new HashMap<>(); data.put("url_type", 1); data.put("url", "rtmp://live.push.t-aaron.com/dji/hyslj002"); data.put("video_quality", 1); data.put("video_id", vid); content.put("tid",UUID.randomUUID().toString()); content.put("bid",UUID.randomUUID().toString()); content.put("timestamp",System.currentTimeMillis()); content.put("method","live_start_push"); content.put("data", data); message = JSONObject.toJSONString(content); } System.out.println(message); providerClient.publish(qos, retained, topic, message); return "发送成功"; } catch (Exception e) { e.printStackTrace(); return "发送失败"; } } @RequestMapping("/live_start_push1") @ResponseBody public String live_start_push1(Integer qos,Boolean retained,String topic,String message, String one, String two, String three){ String vid = one + "/" + two + "/" + three; try { if(qos == null){ qos = 2; } if(retained == null){ retained = true; } if(topic == null){ topic = "thing/product/7CTDM7H00B5EM1/services"; } if(message == null){ Map content = new HashMap<>(); Map data = new HashMap<>(); data.put("url_type", 1); data.put("url", "rtmp://live.push.t-aaron.com/dji/hyslj001"); data.put("video_quality", 3); data.put("video_id", vid); content.put("tid",UUID.randomUUID().toString()); content.put("bid",UUID.randomUUID().toString()); content.put("timestamp",System.currentTimeMillis()); content.put("method","live_start_push"); content.put("data", data); message = JSONObject.toJSONString(content); } System.out.println(message); providerClient.publish(qos, retained, topic, message); return "发送成功"; } catch (Exception e) { e.printStackTrace(); return "发送失败"; } } @RequestMapping("/live_stop_push") @ResponseBody public String live_stop_push(Integer qos,Boolean retained,String topic,String message, String one, String two, String three){ String vid = one + "/" + two + "/" + three; try { if(qos == null){ qos = 2; } if(retained == null){ retained = true; } if(topic == null){ topic = "thing/product/7CTDM7H00B5EM1/services"; } if(message == null){ Map content = new HashMap<>(); Map data = new HashMap<>(); data.put("video_id", vid); content.put("tid",UUID.randomUUID().toString()); content.put("bid",UUID.randomUUID().toString()); content.put("timestamp",System.currentTimeMillis()); content.put("method","live_stop_push"); content.put("data", data); message = JSONObject.toJSONString(content); } System.out.println(message); providerClient.publish(qos, retained, topic, message); return "发送成功"; } catch (Exception e) { e.printStackTrace(); return "发送失败"; } } @RequestMapping("/live_set_quality") @ResponseBody public String live_set_quality(Integer qos,Boolean retained,String topic,String message,int video_quality, String one, String two, String three){ String vid = one + "/" + two + "/" + three; try { if(qos == null){ qos = 2; } if(retained == null){ retained = true; } if(topic == null){ topic = "thing/product/7CTDM7H00B5EM1/services"; } if(message == null){ Map content = new HashMap<>(); Map data = new HashMap<>(); data.put("video_id", vid); data.put("video_quality", video_quality); content.put("tid",UUID.randomUUID().toString()); content.put("bid",UUID.randomUUID().toString()); content.put("timestamp",System.currentTimeMillis()); content.put("method","live_set_quality"); content.put("data", data); message = JSONObject.toJSONString(content); } System.out.println(message); providerClient.publish(qos, retained, topic, message); return "发送成功"; } catch (Exception e) { e.printStackTrace(); return "发送失败"; } } @RequestMapping("/live_lens_change") @ResponseBody public String live_lens_change(Integer qos,Boolean retained,String topic,String message,String video_type, String one, String two, String three){ String vid = one + "/" + two + "/" + three; try { if(qos == null){ qos = 2; } if(retained == null){ retained = true; } if(topic == null){ topic = "thing/product/7CTDM7H00B5EM1/services"; } if(message == null){ Map content = new HashMap<>(); Map data = new HashMap<>(); data.put("video_id", vid); data.put("video_type", video_type); content.put("tid",UUID.randomUUID().toString()); content.put("bid",UUID.randomUUID().toString()); content.put("timestamp",System.currentTimeMillis()); content.put("method","live_lens_change"); content.put("data", data); message = JSONObject.toJSONString(content); } System.out.println(message); providerClient.publish(qos, retained, topic, message); return "发送成功"; } catch (Exception e) { e.printStackTrace(); return "发送失败"; } } private static int aaa = 1; @RequestMapping("/live_camera_change") @ResponseBody public String live_camera_change(Integer qos,Boolean retained,String topic,String message, String one, String two, String three, int aaa){ String vid = one + "/" + two + "/" + three; try { if(qos == null){ qos = 2; } if(retained == null){ retained = true; } if(topic == null){ topic = "thing/product/7CTDM7H00B5EM1/services"; } if(message == null){ Map content = new HashMap<>(); Map data = new HashMap<>(); data.put("video_id", vid); data.put("camera_position", aaa); content.put("tid",UUID.randomUUID().toString()); content.put("bid",UUID.randomUUID().toString()); content.put("timestamp",System.currentTimeMillis()); content.put("method","live_camera_change"); content.put("data", data); message = JSONObject.toJSONString(content); } System.out.println(message); providerClient.publish(qos, retained, topic, message); return "发送成功"; } catch (Exception e) { e.printStackTrace(); return "发送失败"; } } /** * 一键起飞 * @param airPortSn 机场sn号 * @return JsonResult */ @ResponseBody @RequestMapping("/takeoffToPoint") public String takeoffToPoint(String airPortSn){ //获取机场的飞机状态+坐标 RedisUtils redisUtils = SpringUtil.getBean(RedisUtils.class); Map airportRedis = redisUtils.hmget("DJIAirport" + airPortSn); if (CollectionUtils.isEmpty(airportRedis) || Objects.isNull(airportRedis.get("longitude"))){ } try { Integer qos = 2; Boolean retained = true; //topic主题 sn是机场sn号 thing/product/%s/services String topic = String.format(someTopic, airPortSn); //封装数据 Map content = new HashMap<>(); Map data = new HashMap<>(); //坐标 data.put("target_latitude", Double.parseDouble(airportRedis.get("latitude").toString())); data.put("target_longitude", Double.parseDouble(airportRedis.get("longitude").toString())); //高度 data.put("target_height", 50); //安全起飞高度 data.put("security_takeoff_height", 50); //返航模式设置值 必填 "0":"智能高度","1":"设定高度" data.put("rth_mode", 0); //返航高度 data.put("rth_altitude", 50); //"0":"悬停","1":"着陆(降落)","2":"返航" data.put("rc_lost_action", 0); //【必填】指点飞行失控动作 "0":"继续执行指点飞行任务","1":"退出指点飞行任务,执行普通失控行为" data.put("commander_mode_lost_action", 1); //【必填】指点飞行模式设置值 "0":"智能高度飞行","1":"设定高度飞行" data.put("commander_flight_mode", 1); //【必填】指点飞行高度 float data.put("commander_flight_height", 50); //一键起飞任务 UUID data.put("flight_id", UUID.randomUUID().toString()); //一键起飞的飞行过程中能达到的最大速度 data.put("max_speed", 20); String tid = UUID.randomUUID().toString(); content.put("tid", tid); String bid = UUID.randomUUID().toString(); content.put("bid", bid); content.put("timestamp",System.currentTimeMillis()); content.put("method", DJIMethonConstants.TAKEOFF_TO_POINT); 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 "发送失败"; } } @Autowired private static String airPortSn = "7CTXMC900B054P"; /** * 飞行控制权抢夺 /flightAuthorityGrab * @return JsonResult */ @ResponseBody @RequestMapping("/flightAuthorityGrab") public String flightAuthorityGrab(){ try { Integer qos = 2; Boolean retained = true; //topic主题 sn是机场sn号 thing/product/%s/services //TODO 此处用的是无人的SN号 待测试 String topic = String.format(someTopic, airPortSn); //封装数据 Map content = new HashMap<>(); Map data = new HashMap<>(); content.put("tid", UUID.randomUUID().toString()); content.put("bid", UUID.randomUUID().toString()); content.put("timestamp",System.currentTimeMillis()); content.put("method", DJIMethonConstants.FLIGHT_AUTHORITY_GRAB); 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 "发送失败"; } } /** * 负载控制权抢夺 /payloadAuthorityGrab * @return JsonResult */ @ResponseBody @RequestMapping("/payloadAuthorityGrab") public String payloadAuthorityGrab(String cameraIndex){ try { Integer qos = 2; Boolean retained = true; //topic主题 sn是机场sn号 thing/product/%s/services //TODO 此处用的是无人的SN号 待测试 String topic = String.format(someTopic, airPortSn); //封装数据 Map content = new HashMap<>(); Map 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", DJIMethonConstants.PAYLOAD_AUTHORITY_GRAB); 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 "发送失败"; } } @Value("${spring.mqtt.username}") private String username; @Value("${spring.mqtt.password}") private String password; @Value("${spring.mqtt.url}") private String address; @Value("${spring.mqtt.newUrl}") private String newAddress; @Value("${spring.mqtt.client.id}") private String clientId; /** * 进入指令飞行控制模式 * @param airPortSn 机场sn号 * @return JsonResult */ @ResponseBody @RequestMapping("/drcModeEnter") public String drcModeEnter(){ try { Integer qos = 1; Boolean retained = true; //topic主题 sn是机场sn号 thing/product/%s/services //TODO 此处用的是无人的SN号 待测试 String topic = String.format(someTopic, airPortSn); //封装数据 Map content = new HashMap<>(); Map data = new HashMap<>(); //负载枚举值 镜头负载 data.put("hsi_frequency", 20); //Broker 连接信息 Map mqttBroker = new HashMap<>(); //服务器连接地址 mqttBroker.put("address", newAddress); //客户端ID mqttBroker.put("client_id", "DRC-7CTDM7H00BXZD1"); //enable_tls mqttBroker.put("enable_tls", false); //expire_time 当前时间+3000秒 mqttBroker.put("expire_time", System.currentTimeMillis()/1000 + 3600); //密码 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", 20); 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 "发送失败"; } } @RequestMapping("/droneEmergencyStop") public String droneEmergencyStop(String airPortSn){ try { Integer qos = 2; Boolean retained = true; //topic主题 sn是机场sn号 thing/product/%s/services //TODO 此处用的是无人的SN号 待测试 String topic = String.format("thing/product/%s/drc/down", airPortSn); //封装数据 Map content = new HashMap<>(); Map data = new HashMap<>(); content.put("method", DJIMethonConstants.DRONE_EMERGENCY_STOP); 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 sn 机场sn号 * @param flightId 任务id * 一键返航 * @return */ @RequestMapping("/returnHome") public String returnHome(String sn, String flightId){ try { //sn = "7CTDM7H00B5EM1"; Integer qos = 2; Boolean retained = true; //topic主题 sn是机场sn号 thing/product/%s/services String topic = String.format("thing/product/%s/services", sn); //参数封装 Map content = new HashMap<>(); content.put("tid", UUID.randomUUID().toString()); content.put("bid", UUID.randomUUID().toString()); content.put("timestamp",System.currentTimeMillis()); content.put("method", DJIMethonConstants.RETURN_HOME); content.put("data",new HashMap<>()); 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 "发送失败"; } } private static String someTopic = "thing/product/%s/services"; /** * flyto 飞向目标点 * @param airPortSn 机场sn号 * @param airPortSn 速度 String maxsSpeed * @param height 高度 * @param latitude 纬度 * @param longitude 经度 * @return */ @ResponseBody @RequestMapping("/flyToPoint") public String flyToPoint(String airPortSn, Integer maxsSpeed, Integer height, Double latitude, Double longitude){ try { Integer qos = 2; Boolean retained = true; //topic主题 sn是机场sn号 thing/product/%s/services String topic = String.format(someTopic, airPortSn); Map content = new HashMap<>(); Map data = new HashMap<>(); //目标点id data.put("fly_to_id", UUID.randomUUID().toString()); //max_speed flyto 的飞行过程中能达到的最大速度 max":15,"min":0,"unit_name":"米每秒 / m/s" data.put("max_speed", maxsSpeed); //points 目标点列表 List> list = new ArrayList<>(); Map map = new HashMap<>(); //高度 map.put("height", height); //经度 map.put("longitude", longitude); //纬度 map.put("latitude", latitude); list.add(map); data.put("points", list); content.put("tid",UUID.randomUUID().toString()); content.put("bid",UUID.randomUUID().toString()); content.put("timestamp",System.currentTimeMillis()); content.put("method", DJIMethonConstants.FLY_TO_POINT); 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 "发送失败"; } } /** * flyto 飞向目标点 * @param airPortSn 机场sn号 * @param airPortSn 速度 String maxsSpeed */ @ResponseBody @RequestMapping("/flyToPointStop") public String flyToPointStop(String airPortSn){ try { Integer qos = 2; Boolean retained = true; //topic主题 sn是机场sn号 thing/product/%s/services String topic = String.format(someTopic, airPortSn); Map content = new HashMap<>(); Map data = new HashMap<>(); content.put("tid",UUID.randomUUID().toString()); content.put("bid",UUID.randomUUID().toString()); content.put("timestamp",System.currentTimeMillis()); content.put("method", DJIMethonConstants.FLY_TO_POINT_STOP); 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 "发送失败"; } } /** * flyto 更新 flyto 目标点 * @param airPortSn 机场sn号 * @param airPortSn 速度 String maxsSpeed * @param height 高度 * @param latitude 纬度 * @param longitude 经度 * @return */ @ResponseBody @RequestMapping("/flyToPointUpdate") public String flyToPointUpdate(String airPortSn, String maxsSpeed, String height, String latitude, String longitude){ try { Integer qos = 2; Boolean retained = true; //topic主题 sn是机场sn号 thing/product/%s/services String topic = String.format(someTopic, airPortSn); Map content = new HashMap<>(); Map data = new HashMap<>(); //max_speed flyto 的飞行过程中能达到的最大速度 max":15,"min":0,"unit_name":"米每秒 / m/s" data.put("max_speed", maxsSpeed); //points 目标点列表 List> list = new ArrayList<>(); Map map = new HashMap<>(); //高度 map.put("height", height); //经度 map.put("longitude", longitude); //纬度 map.put("latitude", latitude); list.add(map); data.put("points", list); content.put("tid",UUID.randomUUID().toString()); content.put("bid",UUID.randomUUID().toString()); content.put("timestamp",System.currentTimeMillis()); content.put("method", DJIMethonConstants.FLY_TO_POINT_UPDATE); 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 "发送失败"; } } /** * flyto 更新 flyto 目标点 * @return */ @ResponseBody @RequestMapping("/login") public String login(){ String httpUrl = "http://192.168.50.106:8090/third/getToken"; //链接 HttpURLConnection connection = null; InputStream is = null; BufferedReader br = null; StringBuffer result = new StringBuffer(); try { //创建连接 URL url = new URL(httpUrl); if("https".equalsIgnoreCase(url.getProtocol())){ SslUtils.ignoreSsl(); } connection = (HttpURLConnection) url.openConnection(); //设置请求方式 connection.setRequestMethod("GET"); connection.setRequestProperty("accept", "*/*"); connection.setRequestProperty("connection", "Keep-Alive"); connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"); connection.setRequestProperty("Content-Type", "application/json;charset=utf-8"); connection.setRequestProperty("Authorization", "Basic YWRtaW46cHVibGlj"); connection.setRequestProperty("Cookie", "jenkins-timestamper-offset=-28800000; order=id%20desc; serverType=nginx; ltd_end=-1; pro_end=-1; memSize=7768; bt_user_info=%7B%22status%22%3Atrue%2C%22msg%22%3A%22%u83B7%u53D6%u6210%u529F%21%22%2C%22data%22%3A%7B%22username%22%3A%22139****4314%22%7D%7D; sites_path=/www/wwwroot; distribution=centos8; p-1=1; lang=en-US; force=0; b6e922e8cf76dea67efb3a9292724aee=acc59469-46e3-4576-b216-81b907d80a7f.rB3Plw7uc301E0qFoEBeoP_fL4w; load_search=undefined; remember-me=YWRtaW46MTY1ODIxMDYwODA2MDoxY2ZhOTBhMzFlN2IzZTg1YzM5MWQ3Y2M4MWEzYzVlZmYzM2UzOGQ4MTVjZDZhNTUwNjQ4YjFhMjVlYTM3NWJj; JSESSIONID.fc8332ab=node01bo1jsydkd8ql1oo3srksa2k6w288.node0; screenResolution=1920x1080; b2651c13496a99bc2899b024b99bca4f=b4e55bb9-4a3e-44b6-ae8b-c054e7115182.SEaDzMgHxI4d2CGoGwNPnj3L2y4; request_token=hH1LwVtazrgz4sMI4CE1SwEVpCYgiQcHNp4EfyvPni9C32PJ; soft_remarks=%7B%22list%22%3A%5B%22%u4F01%u4E1A%u7248%u3001%u4E13%u4E1A%u7248%u63D2%u4EF6%22%2C%2215%u5929%u65E0%u7406%u7531%u9000%u6B3E%22%2C%22%u53EF%u66F4%u6362IP%22%2C%22%u5E74%u4ED8%u8D60%u90012%u5F20SSL%u8BC1%u4E66%22%2C%22%u5E74%u4ED8%u8D60%u90011000%u6761%u77ED%u4FE1%22%2C%22%u4F4E%u81F32.43%u5143/%u5929%22%2C%22%u5546%u7528%u9632%u706B%u5899%u6388%u6743%22%2C%22%u5E74%u4ED8%u53EF%u5165%u4F01%u4E1A%u7248%u670D%u52A1%u7FA4%22%2C%22%u4EA7%u54C1%u6388%u6743%u8BC1%u4E66%22%5D%2C%22pro_list%22%3A%5B%22%u4E13%u4E1A%u7248%u63D2%u4EF6%22%2C%2215%u5929%u65E0%u7406%u7531%u9000%u6B3E%22%2C%22%u53EF%u66F4%u6362IP%22%2C%22%u4F4E%u81F31.18%u5143/%u5929%22%2C%22%u5546%u7528%u9632%u706B%u5899%u6388%u6743%22%2C%22%u4EA7%u54C1%u6388%u6743%u8BC1%u4E66%22%5D%2C%22kfqq%22%3A%223007255432%22%2C%22kf%22%3A%22http%3A//q.url.cn/CDfQPS%3F_type%3Dwpa%26qidian%3Dtrue%22%2C%22qun%22%3A%22%22%2C%22kf_list%22%3A%5B%7B%22qq%22%3A%223007255432%22%2C%22kf%22%3A%22http%3A//q.url.cn/CDfQPS%3F_type%3Dwpa%26qidian%3Dtrue%22%7D%2C%7B%22qq%22%3A%222927440070%22%2C%22kf%22%3A%22http%3A//wpa.qq.com/msgrd%3Fv%3D3%26uin%3D2927440070%26site%3Dqq%26menu%3Dyes%26from%3Dmessage%26isappinstalled%3D0%22%7D%5D%2C%22wx_list%22%3A%5B%7B%22ps%22%3A%22%u552E%u524D%u54A8%u8BE2%22%2C%22kf%22%3A%22https%3A//work.weixin.qq.com/kfid/kfc72fcbde93e26a6f3%22%7D%5D%7D; load_page=null; load_type=null"); //设置连接超时时间 connection.setReadTimeout(30000); //开始连接 connection.connect(); //获取响应数据 if (connection.getResponseCode() == 200) { //获取返回的数据 is = connection.getInputStream(); if (null != is) { br = new BufferedReader(new InputStreamReader(is, "UTF-8")); String temp = null; while (null != (temp = br.readLine())) { result.append(temp); } } } } catch (Exception e) { e.printStackTrace(); } finally { if (null != br) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } if (null != is) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } //关闭远程连接 connection.disconnect(); } return result.toString(); } public static void main(String[] args) { String capacityPercent = "32767.00"; if(Objects.nonNull(capacityPercent)){ double v = Double.parseDouble(capacityPercent.toString()); if (v > 100){ System.out.printf("++++++"+ capacityPercent); } } } }