Browse Source

fix: OsdRouter在设备未注册的情况下报osd时产生大量日志

pull/40/head
Vincent 2 years ago
parent
commit
0850908d83
  1. 9
      src/main/java/com/dji/sdk/common/SDKManager.java
  2. 18
      src/main/java/com/dji/sdk/mqtt/osd/OsdRouter.java

9
src/main/java/com/dji/sdk/common/SDKManager.java

@ -8,6 +8,7 @@ import com.dji.sdk.exception.CloudSDKErrorEnum;
import com.dji.sdk.exception.CloudSDKException; import com.dji.sdk.exception.CloudSDKException;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
/** /**
@ -30,6 +31,14 @@ public class SDKManager {
"The device has not been registered, please call the 'SDKManager.registerDevice()' method to register the device first."); "The device has not been registered, please call the 'SDKManager.registerDevice()' method to register the device first.");
} }
public static Optional<GatewayManager> findDeviceSDK(String gatewaySn) {
if(SDK_MAP.containsKey(gatewaySn)){
return Optional.of(SDK_MAP.get(gatewaySn));
}else {
return Optional.empty();
}
}
public static GatewayManager registerDevice(String gatewaySn, String droneSn, public static GatewayManager registerDevice(String gatewaySn, String droneSn,
DeviceDomainEnum domain, DeviceTypeEnum type, DeviceSubTypeEnum subType, String gatewayThingVersion, String droneThingVersion) { DeviceDomainEnum domain, DeviceTypeEnum type, DeviceSubTypeEnum subType, String gatewayThingVersion, String droneThingVersion) {
return registerDevice(gatewaySn, droneSn, GatewayTypeEnum.find(DeviceEnum.find(domain, type, subType)), gatewayThingVersion, droneThingVersion); return registerDevice(gatewaySn, droneSn, GatewayTypeEnum.find(DeviceEnum.find(domain, type, subType)), gatewayThingVersion, droneThingVersion);

18
src/main/java/com/dji/sdk/mqtt/osd/OsdRouter.java

@ -15,10 +15,7 @@ import org.springframework.integration.mqtt.support.MqttHeaders;
import org.springframework.messaging.Message; import org.springframework.messaging.Message;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import static com.dji.sdk.mqtt.TopicConst.*; import static com.dji.sdk.mqtt.TopicConst.*;
@ -45,7 +42,12 @@ public class OsdRouter {
} }
}, null) }, null)
.<TopicOsdRequest>handle((response, headers) -> { .<TopicOsdRequest>handle((response, headers) -> {
GatewayManager gateway = SDKManager.getDeviceSDK(response.getGateway());
// fix: getDeviceSDK抛出异常导致在设备未注册的情况下报osd时产生大量日志 witcom@2023.09.22
//GatewayManager gateway = SDKManager.getDeviceSDK(response.getGateway());
return SDKManager.findDeviceSDK(response.getGateway())
.map(gateway-> {
OsdDeviceTypeEnum typeEnum = OsdDeviceTypeEnum.find(gateway.getType(), response.getFrom().equals(response.getGateway())); OsdDeviceTypeEnum typeEnum = OsdDeviceTypeEnum.find(gateway.getType(), response.getFrom().equals(response.getGateway()));
Map<String, Object> data = (Map<String, Object>) response.getData(); Map<String, Object> data = (Map<String, Object>) response.getData();
if (!typeEnum.isGateway()) { if (!typeEnum.isGateway()) {
@ -56,8 +58,12 @@ public class OsdRouter {
} }
return response.setData(Common.getObjectMapper().convertValue(data, typeEnum.getClassType())); return response.setData(Common.getObjectMapper().convertValue(data, typeEnum.getClassType()));
}) })
.orElse(null);
})
.<TopicOsdRequest>filter(Objects::nonNull)
.<TopicOsdRequest, OsdDeviceTypeEnum>route(response -> OsdDeviceTypeEnum.find(response.getData().getClass()), .<TopicOsdRequest, OsdDeviceTypeEnum>route(response -> OsdDeviceTypeEnum.find(response.getData().getClass()),
mapping -> Arrays.stream(OsdDeviceTypeEnum.values()).forEach(key -> mapping.channelMapping(key, key.getChannelName()))) mapping -> Arrays.stream(OsdDeviceTypeEnum.values())
.forEach(key -> mapping.channelMapping(key, key.getChannelName())))
.get(); .get();
} }

Loading…
Cancel
Save