From f98b25a34d04c2acb9bf93e6cbd4e72fa2d81ba0 Mon Sep 17 00:00:00 2001
From: xieb <vip_xiaobin810@163.com>
Date: Sat, 13 Apr 2024 11:40:29 +0800
Subject: [PATCH] 航线规划修改
---
src/main/java/com/dji/sample/manage/controller/DeviceController.java | 104 +++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 83 insertions(+), 21 deletions(-)
diff --git a/src/main/java/com/dji/sample/manage/controller/DeviceController.java b/src/main/java/com/dji/sample/manage/controller/DeviceController.java
index ad2579a..9e8870e 100644
--- a/src/main/java/com/dji/sample/manage/controller/DeviceController.java
+++ b/src/main/java/com/dji/sample/manage/controller/DeviceController.java
@@ -1,20 +1,20 @@
package com.dji.sample.manage.controller;
+import com.dji.sample.common.error.CommonErrorEnum;
import com.dji.sample.common.model.PaginationData;
import com.dji.sample.common.model.ResponseResult;
import com.dji.sample.component.mqtt.model.ChannelName;
import com.dji.sample.component.mqtt.model.CommonTopicReceiver;
import com.dji.sample.component.mqtt.model.CommonTopicResponse;
-import com.dji.sample.component.websocket.service.ISendMessageService;
import com.dji.sample.manage.model.dto.DeviceDTO;
-import com.dji.sample.manage.model.receiver.FirmwareVersionReceiver;
+import com.dji.sample.manage.model.dto.DeviceFirmwareUpgradeDTO;
+import com.dji.sample.manage.model.enums.DeviceSetPropertyEnum;
import com.dji.sample.manage.model.receiver.StatusGatewayReceiver;
import com.dji.sample.manage.service.IDeviceService;
+import com.fasterxml.jackson.databind.JsonNode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.annotation.ServiceActivator;
-import org.springframework.integration.mqtt.support.MqttHeaders;
-import org.springframework.messaging.Message;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@@ -33,9 +33,6 @@
@Autowired
private IDeviceService deviceService;
- @Autowired
- private ISendMessageService sendMessageService;
-
/**
* Handles the message that the drone goes online.
* @param receiver The drone information is not empty.
@@ -49,6 +46,8 @@
CommonTopicResponse.builder()
.tid(receiver.getTid())
.bid(receiver.getBid())
+ .timestamp(System.currentTimeMillis())
+ .method(receiver.getMethod())
.build());
}
}
@@ -60,13 +59,15 @@
@ServiceActivator(inputChannel = ChannelName.INBOUND_STATUS_OFFLINE, outputChannel = ChannelName.OUTBOUND)
public void deviceOffline(CommonTopicReceiver<StatusGatewayReceiver> receiver) {
- boolean offline = deviceService.deviceOffline(receiver.getData().getSn());
+ boolean offline = deviceService.deviceOffline(receiver.getData());
if (offline) {
// Notify pilot that the device is offline successfully.
deviceService.publishStatusReply(receiver.getData().getSn(),
CommonTopicResponse.builder()
.tid(receiver.getTid())
.bid(receiver.getBid())
+ .timestamp(System.currentTimeMillis())
+ .method(receiver.getMethod())
.build());
}
@@ -78,24 +79,32 @@
* @return
*/
@GetMapping("/{workspace_id}/devices")
- public ResponseResult<List<DeviceDTO>> getDevices(@PathVariable("workspace_id") String workspaceId) {
- List<DeviceDTO> devicesList = deviceService.getDevicesTopoForWeb(workspaceId);
+ public ResponseResult<List<DeviceDTO>> getDevices(@PathVariable("workspace_id") String workspaceId,String reserveId) {
+ List<DeviceDTO> devicesList = deviceService.getDevicesTopoForWeb(workspaceId,reserveId);
return ResponseResult.success(devicesList);
}
- @ServiceActivator(inputChannel = ChannelName.INBOUND_OSD)
- public void osdRealTime(Message<?> message) {
- String topic = message.getHeaders().get(MqttHeaders.RECEIVED_TOPIC).toString();
- byte[] payload = (byte[])message.getPayload();
- deviceService.handleOSD(topic, payload);
+ @GetMapping("/{device_sn}/subscribeTopic")
+ public ResponseResult<List<DeviceDTO>> testBinding(@PathVariable("device_sn") String deviceSn) {
+ deviceService.subscribeTopicOnline(deviceSn);
+
+ return ResponseResult.success();
}
- @ServiceActivator(inputChannel = ChannelName.INBOUND_STATE_FIRMWARE_VERSION)
- public void updateFirmwareVersion(FirmwareVersionReceiver receiver) {
- deviceService.updateFirmwareVersion(receiver);
+ @GetMapping("/{device_sn}/unsubscribeTopic")
+ public ResponseResult<List<DeviceDTO>> testUnBinding(@PathVariable("device_sn") String deviceSn) {
+ deviceService.unsubscribeTopicOffline(deviceSn);
+
+ return ResponseResult.success();
}
+ /**
+ * After binding the device to the workspace, the device data can only be seen on the web.
+ * @param device
+ * @param deviceSn
+ * @return
+ */
@PostMapping("/{device_sn}/binding")
public ResponseResult bindDevice(@RequestBody DeviceDTO device, @PathVariable("device_sn") String deviceSn) {
device.setDeviceSn(deviceSn);
@@ -103,11 +112,17 @@
return isUpd ? ResponseResult.success() : ResponseResult.error();
}
+ /**
+ * Obtain device information according to device sn.
+ * @param workspaceId
+ * @param deviceSn
+ * @return
+ */
@GetMapping("/{workspace_id}/devices/{device_sn}")
public ResponseResult getDevice(@PathVariable("workspace_id") String workspaceId,
@PathVariable("device_sn") String deviceSn) {
Optional<DeviceDTO> deviceOpt = deviceService.getDeviceBySn(deviceSn);
- return deviceOpt.isEmpty() ? ResponseResult.error("device not found.") : ResponseResult.success(deviceOpt.get());
+ return deviceOpt.isEmpty() ? ResponseResult.error("设备未找到") : ResponseResult.success(deviceOpt.get());
}
/**
@@ -119,7 +134,7 @@
*/
@GetMapping("/{workspace_id}/devices/bound")
public ResponseResult<PaginationData<DeviceDTO>> getBoundDevicesWithDomain(
- @PathVariable("workspace_id") String workspaceId, String domain,
+ @PathVariable("workspace_id") String workspaceId, Integer domain,
@RequestParam(defaultValue = "1") Long page,
@RequestParam(value = "page_size", defaultValue = "50") Long pageSize) {
PaginationData<DeviceDTO> devices = deviceService.getBoundDevicesWithDomain(workspaceId, page, pageSize, domain);
@@ -127,12 +142,24 @@
return ResponseResult.success(devices);
}
+ /**
+ * Removing the binding state of the device.
+ * @param deviceSn
+ * @return
+ */
@DeleteMapping("/{device_sn}/unbinding")
public ResponseResult unbindingDevice(@PathVariable("device_sn") String deviceSn) {
deviceService.unbindDevice(deviceSn);
return ResponseResult.success();
}
+ /**
+ * Update device information.
+ * @param device
+ * @param workspaceId
+ * @param deviceSn
+ * @return
+ */
@PutMapping("/{workspace_id}/devices/{device_sn}")
public ResponseResult updateDevice(@RequestBody DeviceDTO device,
@PathVariable("workspace_id") String workspaceId,
@@ -141,4 +168,39 @@
boolean isUpd = deviceService.updateDevice(device);
return isUpd ? ResponseResult.success() : ResponseResult.error();
}
-}
\ No newline at end of file
+
+ /**
+ * Delivers offline firmware upgrade tasks.
+ * @param workspaceId
+ * @param upgradeDTOS
+ * @return
+ */
+ @PostMapping("/{workspace_id}/devices/ota")
+ public ResponseResult createOtaJob(@PathVariable("workspace_id") String workspaceId,
+ @RequestBody List<DeviceFirmwareUpgradeDTO> upgradeDTOS) {
+ return deviceService.createDeviceOtaJob(workspaceId, upgradeDTOS);
+ }
+
+ /**
+ * Set the property parameters of the drone.
+ * @param workspaceId
+ * @param dockSn
+ * @param param
+ * @return
+ */
+ @PutMapping("/{workspace_id}/devices/{device_sn}/property")
+ public ResponseResult devicePropertySet(@PathVariable("workspace_id") String workspaceId,
+ @PathVariable("device_sn") String dockSn,
+ @RequestBody JsonNode param) {
+ if (param.size() != 1) {
+ return ResponseResult.error(CommonErrorEnum.ILLEGAL_ARGUMENT);
+ }
+ String property = param.fieldNames().next();
+ Optional<DeviceSetPropertyEnum> propertyEnumOpt = DeviceSetPropertyEnum.find(property);
+ if (propertyEnumOpt.isEmpty()) {
+ return ResponseResult.error(CommonErrorEnum.ILLEGAL_ARGUMENT);
+ }
+ deviceService.devicePropertySet(workspaceId, dockSn, propertyEnumOpt.get(), param.get(property));
+ return ResponseResult.success();
+ }
+}
--
Gitblit v1.9.3