wangzhibo
4 天以前 ae6f40460dcd56af6c5f60ba52c883854c3bac55
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package nodomain.freeyourgadget.gadgetbridge.devices.huawei;
 
public class HuaweiSportHRZones {
    private final HeartRateZonesConfig otherHRZonesConfig;
    private final HeartRateZonesConfig sittingHRZonesConfig;
    private final HeartRateZonesConfig uprightHRZonesConfig;
    private final HeartRateZonesConfig swimmingHRZonesConfig;
 
    public HuaweiSportHRZones(int age) {
        this.uprightHRZonesConfig = new HeartRateZonesConfig(HeartRateZonesConfig.TYPE_UPRIGHT, age);
        this.sittingHRZonesConfig = new HeartRateZonesConfig(HeartRateZonesConfig.TYPE_SITTING, age);
        this.swimmingHRZonesConfig = new HeartRateZonesConfig(HeartRateZonesConfig.TYPE_SWIMMING, age);
        this.otherHRZonesConfig = new HeartRateZonesConfig(HeartRateZonesConfig.TYPE_OTHER, age);
    }
 
    public HeartRateZonesConfig getHRZonesConfigByType(int type) {
        if (type == HeartRateZonesConfig.TYPE_SITTING) {
            return this.sittingHRZonesConfig;
        } else if (type == HeartRateZonesConfig.TYPE_SWIMMING) {
            return this.swimmingHRZonesConfig;
        } else if (type == HeartRateZonesConfig.TYPE_OTHER) {
            return this.otherHRZonesConfig;
        }
        return this.uprightHRZonesConfig;
    }
 
    public byte[] getHRZonesData() {
        HeartRateZonesConfig uprightConfig = getHRZonesConfigByType(HeartRateZonesConfig.TYPE_UPRIGHT);
        HeartRateZonesConfig sittingConfig = getHRZonesConfigByType(HeartRateZonesConfig.TYPE_SITTING);
        HeartRateZonesConfig swimmingConfig = getHRZonesConfigByType(HeartRateZonesConfig.TYPE_SWIMMING);
        HeartRateZonesConfig otherConfig = getHRZonesConfigByType(HeartRateZonesConfig.TYPE_OTHER);
 
        if (!uprightConfig.isValid() || !sittingConfig.isValid() || !swimmingConfig.isValid() || !otherConfig.isValid()) {
            return null;
        }
        HuaweiTLV tlv = new HuaweiTLV();
        if (uprightConfig.hasValidMHRData()) {
            tlv.put(0x2, (byte) uprightConfig.getMHRWarmUp())
                    .put(0x3, (byte) uprightConfig.getMHRFatBurning())
                    .put(0x4, (byte) uprightConfig.getMHRAerobic())
                    .put(0x5, (byte) uprightConfig.getMHRAnaerobic())
                    .put(0x6, (byte) uprightConfig.getMHRExtreme())
                    .put(0x7, (byte) uprightConfig.getMaxHRThreshold())
                    .put(0x8, (byte) (uprightConfig.getWarningEnable() ? 1 : 0))
                    .put(0x9, (byte) uprightConfig.getWarningHRLimit())
                    .put(0xa, (byte) uprightConfig.getCalculateMethod())
                    .put(0xb, (byte) uprightConfig.getMaxHRThreshold());
        }
        tlv.put(0xc, (byte) uprightConfig.getRestHeartRate());
        if (uprightConfig.hasValidHRRData()) {
            tlv.put(0xd, (byte) uprightConfig.getHRRBasicAerobic())
                    .put(0xe, (byte) uprightConfig.getHRRAdvancedAerobic())
                    .put(0xf, (byte) uprightConfig.getHRRLactate())
                    .put(0x10, (byte) uprightConfig.getHRRBasicAnaerobic())
                    .put(0x11, (byte) uprightConfig.getHRRAdvancedAnaerobic());
 
        }
        if (uprightConfig.hasValidLTHRData()) {
            tlv.put(0x3f, (byte) uprightConfig.getLTHRThresholdHeartRate())
                    .put(0x40, (byte) uprightConfig.getLTHRAnaerobic())
                    .put(0x41, (byte) uprightConfig.getLTHRLactate())
                    .put(0x42, (byte) uprightConfig.getLTHRAdvancedAerobic())
                    .put(0x43, (byte) uprightConfig.getLTHRBasicAerobic())
                    .put(0x44, (byte) uprightConfig.getLTHRWarmUp());
        }
 
        if (sittingConfig.hasValidMHRData()) {
            tlv.put(0x12, (byte) (sittingConfig.getWarningEnable() ? 1 : 0))
                    .put(0x13, (byte) sittingConfig.getCalculateMethod())
                    .put(0x14, (byte) sittingConfig.getWarningHRLimit())
                    .put(0x15, (byte) sittingConfig.getMHRWarmUp())
                    .put(0x16, (byte) sittingConfig.getMHRFatBurning())
                    .put(0x17, (byte) sittingConfig.getMHRAerobic())
                    .put(0x18, (byte) sittingConfig.getMHRAnaerobic())
                    .put(0x19, (byte) sittingConfig.getMHRExtreme())
                    .put(0x1a, (byte) sittingConfig.getMaxHRThreshold());
        }
        if (sittingConfig.hasValidHRRData()) {
            tlv.put(0x1b, (byte) sittingConfig.getRestHeartRate())
                    .put(0x1c, (byte) sittingConfig.getHRRBasicAerobic())
                    .put(0x1d, (byte) sittingConfig.getHRRAdvancedAerobic())
                    .put(0x1e, (byte) sittingConfig.getHRRLactate())
                    .put(0x1f, (byte) sittingConfig.getHRRBasicAnaerobic())
                    .put(0x20, (byte) sittingConfig.getHRRAdvancedAnaerobic());
        }
 
        if (swimmingConfig.hasValidMHRData()) {
            tlv.put(0x21, (byte) (swimmingConfig.getWarningEnable() ? 1 : 0))
                    .put(0x22, (byte) swimmingConfig.getCalculateMethod())
                    .put(0x23, (byte) swimmingConfig.getWarningHRLimit())
                    .put(0x24, (byte) swimmingConfig.getMHRWarmUp())
                    .put(0x25, (byte) swimmingConfig.getMHRFatBurning())
                    .put(0x26, (byte) swimmingConfig.getMHRAerobic())
                    .put(0x27, (byte) swimmingConfig.getMHRAnaerobic())
                    .put(0x28, (byte) swimmingConfig.getMHRExtreme())
                    .put(0x29, (byte) swimmingConfig.getMaxHRThreshold());
        }
        if (swimmingConfig.hasValidHRRData()) {
            tlv.put(0x2a, (byte) swimmingConfig.getRestHeartRate())
                    .put(0x2b, (byte) swimmingConfig.getHRRBasicAerobic())
                    .put(0x2c, (byte) swimmingConfig.getHRRAdvancedAerobic())
                    .put(0x2d, (byte) swimmingConfig.getHRRLactate())
                    .put(0x2e, (byte) swimmingConfig.getHRRBasicAnaerobic())
                    .put(0x2f, (byte) swimmingConfig.getHRRAdvancedAnaerobic());
        }
 
        if (otherConfig.hasValidMHRData()) {
            tlv.put(0x30, (byte) (otherConfig.getWarningEnable() ? 1 : 0))
                    .put(0x31, (byte) otherConfig.getCalculateMethod())
                    .put(0x32, (byte) otherConfig.getWarningHRLimit())
                    .put(0x33, (byte) otherConfig.getMHRWarmUp())
                    .put(0x34, (byte) otherConfig.getMHRFatBurning())
                    .put(0x35, (byte) otherConfig.getMHRAerobic())
                    .put(0x36, (byte) otherConfig.getMHRAnaerobic())
                    .put(0x37, (byte) otherConfig.getMHRExtreme())
                    .put(0x38, (byte) otherConfig.getMaxHRThreshold());
        }
        if (otherConfig.hasValidHRRData()) {
            tlv.put(0x39, (byte) otherConfig.getRestHeartRate())
                    .put(0x3a, (byte) otherConfig.getHRRBasicAerobic())
                    .put(0x3b, (byte) otherConfig.getHRRAdvancedAerobic())
                    .put(0x3c, (byte) otherConfig.getHRRLactate())
                    .put(0x3d, (byte) otherConfig.getHRRBasicAnaerobic())
                    .put(0x3e, (byte) otherConfig.getHRRAdvancedAnaerobic());
        }
 
        return tlv.serialize();
    }
 
 
}