wangmengmeng
2024-12-24 24432a361d5c6bd6f3d8c008693e9f1155d62517
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.dji.sdk.config.version;
 
import com.dji.sdk.annotations.CloudSDKVersion;
 
import java.util.Arrays;
import java.util.Objects;
 
/**
 * SDK information corresponding to the gateway device
 * @author sean
 * @version 1.7
 * @date 2023/5/19
 */
public class GatewayManager {
 
    private String gatewaySn;
    private GatewayThingVersion gatewayThingVersion;
    private DroneThingVersionEnum droneThingVersion;
    private GatewayTypeEnum type;
    private CloudSDKVersionEnum sdkVersion;
    private String droneSn;
 
    private GatewayManager(String gatewaySn, String droneSn, GatewayTypeEnum gatewayType) {
        this.gatewaySn = gatewaySn;
        this.type = gatewayType;
        this.droneSn = droneSn;
    }
 
    public GatewayManager(String gatewaySn, String droneSn, GatewayTypeEnum gatewayType, String gatewayThingVersion, String droneThingVersion) {
        this(gatewaySn, droneSn, gatewayType);
        this.gatewayThingVersion = new GatewayThingVersion(gatewayType, gatewayThingVersion);
        if (GatewayTypeEnum.RC == gatewayType) {
            this.sdkVersion = CloudSDKVersionEnum.V0_0_1;
            return;
        }
        if (Objects.isNull(droneThingVersion)) {
            this.sdkVersion = this.gatewayThingVersion.getCloudSDKVersion();
            return;
        }
        this.droneThingVersion = DroneThingVersionEnum.find(droneThingVersion);
        this.sdkVersion = this.gatewayThingVersion.getCloudSDKVersion().isSupported(this.droneThingVersion.getCloudSDKVersion()) ?
                this.droneThingVersion.getCloudSDKVersion() : this.gatewayThingVersion.getCloudSDKVersion();
    }
 
    public String getGatewaySn() {
        return gatewaySn;
    }
 
    public GatewayThingVersion getGatewayThingVersion() {
        return gatewayThingVersion;
    }
 
    public DroneThingVersionEnum getDroneThingVersion() {
        return droneThingVersion;
    }
 
    public GatewayTypeEnum getType() {
        return type;
    }
 
    public CloudSDKVersionEnum getSdkVersion() {
        return sdkVersion;
    }
 
    public String getDroneSn() {
        return droneSn;
    }
 
    public boolean isTypeSupport(CloudSDKVersion version) {
        return null != version && Arrays.stream(version.exclude()).noneMatch(typeEnum -> typeEnum == this.getType())
                && (version.include().length == 0
                    || Arrays.stream(version.include()).anyMatch(typeEnum -> typeEnum == this.getType()));
    }
 
    public boolean isVersionSupport(CloudSDKVersion version) {
        return null != version && this.getSdkVersion().isSupported(version.since()) && !isDeprecated(version);
    }
 
    public boolean isDeprecated(CloudSDKVersion version) {
        return null != version && this.getSdkVersion().isDeprecated(version.deprecated());
    }
 
    public boolean isPropertyValid(CloudSDKVersion version) {
        return null == version ||
                (!this.getSdkVersion().isDeprecated(version.since())
                        && this.getSdkVersion().isSupported(version.since()));
    }
}