package com.dji.sample.control.service.impl;
|
|
import com.dji.sample.component.websocket.model.BizCodeEnum;
|
import com.dji.sample.component.websocket.service.IWebSocketMessageService;
|
import com.dji.sample.component.websocketWmm.WebSocketServerPlayBack;
|
import com.dji.sample.control.model.dto.ResultNotifyDTO;
|
import com.dji.sample.manage.model.dto.DeviceDTO;
|
import com.dji.sample.manage.model.enums.UserTypeEnum;
|
import com.dji.sample.manage.service.IDeviceRedisService;
|
import com.dji.sdk.cloudapi.control.*;
|
import com.dji.sdk.cloudapi.control.api.AbstractControlService;
|
import com.dji.sdk.mqtt.MqttReply;
|
import com.dji.sdk.mqtt.drc.DrcUpData;
|
import com.dji.sdk.mqtt.drc.TopicDrcRequest;
|
import com.dji.sdk.mqtt.drc.TopicDrcResponse;
|
import com.dji.sdk.mqtt.events.EventsDataRequest;
|
import com.dji.sdk.mqtt.events.TopicEventsRequest;
|
import com.dji.sdk.mqtt.events.TopicEventsResponse;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.messaging.MessageHeaders;
|
import org.springframework.stereotype.Service;
|
|
import java.util.Optional;
|
|
/**
|
* @author sean
|
* @version 1.7
|
* @date 2023/7/4
|
*/
|
@Service
|
@Slf4j
|
public class SDKControlService extends AbstractControlService {
|
|
@Autowired
|
private IWebSocketMessageService webSocketMessageService;
|
|
@Autowired
|
private IDeviceRedisService deviceRedisService;
|
|
@Autowired
|
private ObjectMapper mapper;
|
|
@Override
|
public TopicEventsResponse<MqttReply> flyToPointProgress(TopicEventsRequest<FlyToPointProgress> request, MessageHeaders headers) {
|
String dockSn = request.getGateway();
|
|
Optional<DeviceDTO> deviceOpt = deviceRedisService.getDeviceOnline(dockSn);
|
if (deviceOpt.isEmpty()) {
|
log.error("The dock is offline.");
|
return null;
|
}
|
|
ObjectMapper mapper = new ObjectMapper();
|
String flyToPointProgress = "";
|
try {
|
|
flyToPointProgress = mapper.writeValueAsString(request.getData());
|
} catch (JsonProcessingException e) {
|
throw new RuntimeException("trans json failed.");
|
}
|
WebSocketServerPlayBack.sendInfo(BizCodeEnum.FLY_TO_POINT_PROGRESS, flyToPointProgress);
|
return new TopicEventsResponse<MqttReply>().setData(MqttReply.success());
|
}
|
|
@Override
|
public TopicEventsResponse<MqttReply> takeoffToPointProgress(TopicEventsRequest<TakeoffToPointProgress> request, MessageHeaders headers) {
|
String dockSn = request.getGateway();
|
|
Optional<DeviceDTO> deviceOpt = deviceRedisService.getDeviceOnline(dockSn);
|
if (deviceOpt.isEmpty()) {
|
log.error("The dock is offline.");
|
return null;
|
}
|
|
|
// TakeoffToPointProgress eventsReceiver = request.getData();
|
// webSocketMessageService.sendBatch(deviceOpt.get().getWorkspaceId(), UserTypeEnum.WEB.getVal(),
|
// BizCodeEnum.TAKE_OFF_TO_POINT_PROGRESS.getCode(),
|
// ResultNotifyDTO.builder().sn(dockSn)
|
// .message(eventsReceiver.getResult().toString())
|
// .result(eventsReceiver.getResult().getCode())
|
// .build());
|
|
ObjectMapper mapper = new ObjectMapper();
|
String takeoffToPointProgress = "";
|
try {
|
takeoffToPointProgress = mapper.writeValueAsString(request.getData());
|
} catch (JsonProcessingException e) {
|
throw new RuntimeException("trans json failed.");
|
}
|
WebSocketServerPlayBack.sendInfo(BizCodeEnum.TAKE_OFF_TO_POINT_PROGRESS, takeoffToPointProgress);
|
return new TopicEventsResponse<MqttReply>().setData(MqttReply.success());
|
}
|
|
@Override
|
public TopicEventsResponse<MqttReply> drcStatusNotify(TopicEventsRequest<DrcStatusNotify> request, MessageHeaders headers) {
|
String dockSn = request.getGateway();
|
|
Optional<DeviceDTO> deviceOpt = deviceRedisService.getDeviceOnline(dockSn);
|
if (deviceOpt.isEmpty()) {
|
return null;
|
}
|
|
ObjectMapper mapper = new ObjectMapper();
|
String drcStatusNotify = "";
|
try {
|
drcStatusNotify = mapper.writeValueAsString(request.getData());
|
} catch (JsonProcessingException e) {
|
throw new RuntimeException("trans json failed.");
|
}
|
WebSocketServerPlayBack.sendInfo(BizCodeEnum.DRC_STATUS_NOTIFY, drcStatusNotify);
|
return new TopicEventsResponse<MqttReply>().setData(MqttReply.success());
|
}
|
|
@Override
|
public TopicEventsResponse<MqttReply> joystickInvalidNotify(TopicEventsRequest<JoystickInvalidNotify> request, MessageHeaders headers) {
|
String dockSn = request.getGateway();
|
|
Optional<DeviceDTO> deviceOpt = deviceRedisService.getDeviceOnline(dockSn);
|
if (deviceOpt.isEmpty()) {
|
return null;
|
}
|
|
JoystickInvalidNotify eventsReceiver = request.getData();
|
webSocketMessageService.sendBatch(
|
deviceOpt.get().getWorkspaceId(), UserTypeEnum.WEB.getVal(), BizCodeEnum.JOYSTICK_INVALID_NOTIFY.getCode(),
|
ResultNotifyDTO.builder().sn(dockSn)
|
.message(eventsReceiver.getReason().getMessage())
|
.result(eventsReceiver.getReason().getVal()).build());
|
|
WebSocketServerPlayBack.sendInfo(request.toString());
|
return new TopicEventsResponse<MqttReply>().setData(MqttReply.success());
|
}
|
|
@Override
|
public TopicEventsResponse<MqttReply> cameraPhotoTakeProgress(TopicEventsRequest<EventsDataRequest<CameraPhotoTakeProgress>> request, MessageHeaders headers) {
|
|
WebSocketServerPlayBack.sendInfo(request.toString());
|
return new TopicEventsResponse<MqttReply>().setData(MqttReply.success());
|
}
|
|
@Override
|
public void droneControlUp(TopicDrcRequest<DrcUpData<DroneControlResponse>> request, MessageHeaders headers) {
|
WebSocketServerPlayBack.sendInfo(BizCodeEnum.DRONE_CONTROL_UP, request.getData().toString());
|
}
|
|
@Override
|
public void droneEmergencyStopUp(TopicDrcRequest<DrcUpData> request, MessageHeaders headers) {
|
WebSocketServerPlayBack.sendInfo(BizCodeEnum.DRONE_EMERGENCY_TOP_UP, request.getData().toString());
|
}
|
|
@Override
|
public void heartBeatUp(TopicDrcRequest<HeartBeatRequest> request, MessageHeaders headers) {
|
WebSocketServerPlayBack.sendInfo(BizCodeEnum.HEART_BEAT_UP, request.getData().toString());
|
}
|
|
@Override
|
public void delayInfoPush(TopicDrcRequest<DelayInfoPush> request, MessageHeaders headers) {
|
WebSocketServerPlayBack.sendInfo(BizCodeEnum.DELAY_INFO_PUSH, request.getData().toString());
|
}
|
|
@Override
|
public void osdInfoPush(TopicDrcRequest<OsdInfoPush> request, MessageHeaders headers) {
|
WebSocketServerPlayBack.sendInfo(BizCodeEnum.OSD_INFO_PUSH, request.getData().toString());
|
}
|
|
@Override
|
public void hsiInfoPush(TopicDrcRequest<HsiInfoPush> request, MessageHeaders headers) {
|
WebSocketServerPlayBack.sendInfo(BizCodeEnum.HSI_INFO_PUSH, request.getData().toString());
|
}
|
|
}
|