|
@ -1,5 +1,6 @@ |
|
|
package org.dromara.sample.manage.service.impl; |
|
|
package org.dromara.sample.manage.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
import org.dromara.common.sdk.cloudapi.device.*; |
|
|
import org.dromara.common.sdk.cloudapi.device.*; |
|
|
import org.dromara.common.sdk.cloudapi.device.api.AbstractDeviceService; |
|
|
import org.dromara.common.sdk.cloudapi.device.api.AbstractDeviceService; |
|
|
import org.dromara.common.sdk.cloudapi.psdk.PsdkUiResource; |
|
|
import org.dromara.common.sdk.cloudapi.psdk.PsdkUiResource; |
|
@ -67,6 +68,12 @@ public class SDKDeviceService extends AbstractDeviceService { |
|
|
|
|
|
|
|
|
Optional<DeviceDTO> deviceOpt = deviceRedisService.getDeviceOnline(deviceSn); |
|
|
Optional<DeviceDTO> deviceOpt = deviceRedisService.getDeviceOnline(deviceSn); |
|
|
Optional<DeviceDTO> gatewayOpt = deviceRedisService.getDeviceOnline(request.getFrom()); |
|
|
Optional<DeviceDTO> gatewayOpt = deviceRedisService.getDeviceOnline(request.getFrom()); |
|
|
|
|
|
if(deviceOpt.isEmpty() || ObjectUtil.isNull(deviceOpt.get().getWorkspaceId())){ |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
if(gatewayOpt.isEmpty() || ObjectUtil.isNull(gatewayOpt.get().getWorkspaceId())){ |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
GatewayManager gatewayManager = SDKManager.registerDevice(request.getFrom(), deviceSn, |
|
|
GatewayManager gatewayManager = SDKManager.registerDevice(request.getFrom(), deviceSn, |
|
|
request.getData().getDomain(), request.getData().getType(), |
|
|
request.getData().getDomain(), request.getData().getType(), |
|
|
request.getData().getSubType(), request.getData().getThingVersion(), updateTopoSubDevice.getThingVersion()); |
|
|
request.getData().getSubType(), request.getData().getThingVersion(), updateTopoSubDevice.getThingVersion()); |
|
@ -109,18 +116,27 @@ public class SDKDeviceService extends AbstractDeviceService { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public TopicStatusResponse<MqttReply> updateTopoOffline(TopicStatusRequest<UpdateTopo> request, MessageHeaders headers) { |
|
|
public TopicStatusResponse<MqttReply> updateTopoOffline(TopicStatusRequest<UpdateTopo> request, MessageHeaders headers) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GatewayManager gatewayManager = SDKManager.registerDevice(request.getFrom(), null, |
|
|
GatewayManager gatewayManager = SDKManager.registerDevice(request.getFrom(), null, |
|
|
request.getData().getDomain(), request.getData().getType(), |
|
|
request.getData().getDomain(), request.getData().getType(), |
|
|
request.getData().getSubType(), request.getData().getThingVersion(), null); |
|
|
request.getData().getSubType(), request.getData().getThingVersion(), null); |
|
|
|
|
|
Optional<DeviceDTO> deviceOpt = deviceRedisService.getDeviceOnline(request.getFrom()); |
|
|
|
|
|
if(deviceOpt.isEmpty()){ |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
if(ObjectUtil.isNull(deviceOpt.get().getWorkspaceId())){ |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
deviceService.gatewayOnlineSubscribeTopic(gatewayManager); |
|
|
deviceService.gatewayOnlineSubscribeTopic(gatewayManager); |
|
|
// Only the remote controller is logged in and the aircraft is not connected.
|
|
|
// Only the remote controller is logged in and the aircraft is not connected.
|
|
|
Optional<DeviceDTO> deviceOpt = deviceRedisService.getDeviceOnline(request.getFrom()); |
|
|
|
|
|
if (deviceOpt.isEmpty()) { |
|
|
if (deviceOpt.isEmpty()) { |
|
|
// When connecting for the first time
|
|
|
// When connecting for the first time
|
|
|
DeviceDTO gatewayDevice = deviceGatewayConvertToDevice(request.getFrom(), request.getData()); |
|
|
DeviceDTO gatewayDevice = deviceGatewayConvertToDevice(request.getFrom(), request.getData()); |
|
|
Optional<DeviceDTO> gatewayDeviceOpt = onlineSaveDevice(gatewayDevice, null, null); |
|
|
Optional<DeviceDTO> gatewayDeviceOpt = onlineSaveDevice(gatewayDevice, null, null); |
|
|
if (gatewayDeviceOpt.isEmpty()) { |
|
|
if (gatewayDeviceOpt.isEmpty()) { |
|
|
return null; |
|
|
return new TopicStatusResponse<MqttReply>().setData(MqttReply.success()); |
|
|
} |
|
|
} |
|
|
deviceService.pushDeviceOnlineTopo(gatewayDeviceOpt.get().getWorkspaceId(), request.getFrom(), null); |
|
|
deviceService.pushDeviceOnlineTopo(gatewayDeviceOpt.get().getWorkspaceId(), request.getFrom(), null); |
|
|
return new TopicStatusResponse<MqttReply>().setData(MqttReply.success()); |
|
|
return new TopicStatusResponse<MqttReply>().setData(MqttReply.success()); |
|
@ -142,15 +158,14 @@ public class SDKDeviceService extends AbstractDeviceService { |
|
|
if (deviceOpt.isEmpty() || !StringUtils.hasText(deviceOpt.get().getWorkspaceId())) { |
|
|
if (deviceOpt.isEmpty() || !StringUtils.hasText(deviceOpt.get().getWorkspaceId())) { |
|
|
deviceOpt = deviceService.getDeviceBySn(from); |
|
|
deviceOpt = deviceService.getDeviceBySn(from); |
|
|
if (deviceOpt.isEmpty()) { |
|
|
if (deviceOpt.isEmpty()) { |
|
|
log.error("请重新启动无人机。"); |
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
if(!StringUtils.hasText(deviceOpt.get().getWorkspaceId())){ |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
DeviceDTO device = deviceOpt.get(); |
|
|
DeviceDTO device = deviceOpt.get(); |
|
|
if (!StringUtils.hasText(device.getWorkspaceId())) { |
|
|
|
|
|
log.error("请先绑好码头。"); |
|
|
|
|
|
} |
|
|
|
|
|
if (StringUtils.hasText(device.getChildDeviceSn())) { |
|
|
if (StringUtils.hasText(device.getChildDeviceSn())) { |
|
|
deviceService.getDeviceBySn(device.getChildDeviceSn()).ifPresent(device::setChildren); |
|
|
deviceService.getDeviceBySn(device.getChildDeviceSn()).ifPresent(device::setChildren); |
|
|
} |
|
|
} |
|
|