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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
/*  Copyright (C) 2024 Damien Gaignon, Martin.JM
 
    This file is part of Gadgetbridge.
 
    Gadgetbridge is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published
    by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
 
    Gadgetbridge is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.
 
    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets;
 
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
 
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiTLV;
 
public class Workout {
    public static final byte id = 0x17;
 
    public static class WorkoutCount {
        public static final byte id = 0x07;
 
        public static class Request extends HuaweiPacket {
            public Request(
                    ParamsProvider paramsProvider,
                    int start,
                    int end
            ) {
                super(paramsProvider);
 
                this.serviceId = Workout.id;
                this.commandId = id;
 
                this.tlv = new HuaweiTLV()
                        .put(0x81, new HuaweiTLV()
                                .put(0x03, start)
                                .put(0x04, end)
                        );
 
                this.complete = true;
            }
        }
 
        public static class Response extends HuaweiPacket {
            public static class WorkoutNumbers {
                public byte[] rawData;
 
                public short workoutNumber;
                public short dataCount;
                public short paceCount;
                public short segmentsCount = 0;
 
            }
 
            public short count;
            public List<WorkoutNumbers> workoutNumbers;
 
            public Response(ParamsProvider paramsProvider) {
                super(paramsProvider);
            }
 
            @Override
            public void parseTlv() throws ParseException {
                HuaweiTLV container = this.tlv.getObject(0x81);
 
                this.count = container.getShort(0x02);
                this.workoutNumbers = new ArrayList<>();
 
                if (this.count == 0)
                    return;
 
                List<HuaweiTLV> subContainers = container.getObjects(0x85);
                for (HuaweiTLV subContainerTlv : subContainers) {
                    WorkoutNumbers workoutNumber = new WorkoutNumbers();
                    workoutNumber.rawData = subContainerTlv.serialize();
                    workoutNumber.workoutNumber = subContainerTlv.getShort(0x06);
                    workoutNumber.dataCount = subContainerTlv.getShort(0x07);
                    workoutNumber.paceCount = subContainerTlv.getShort(0x08);
                    if(subContainerTlv.contains(0x09)) {
                        workoutNumber.segmentsCount = subContainerTlv.getShort(0x09);
                    }
                    this.workoutNumbers.add(workoutNumber);
                }
 
                // Has to be sorted for the timestamp-based sync start that we use in the HuaweiSupportProvider
                this.workoutNumbers.sort(Comparator.comparingInt(o -> o.workoutNumber));
            }
        }
    }
 
    public static class WorkoutTotals {
        public static final byte id = 0x08;
 
        public static class Request extends HuaweiPacket {
 
            public Request(ParamsProvider paramsProvider, short number) {
                super(paramsProvider);
 
                this.serviceId = Workout.id;
                this.commandId = id;
 
                this.tlv = new HuaweiTLV().put(0x81, new HuaweiTLV()
                        .put(0x02, number)
                );
 
                this.complete = true;
            }
        }
 
        public static class Response extends HuaweiPacket {
            public byte[] rawData;
 
            public short number;
            public byte status = -1; // TODO: enum?
            public int startTime;
            public int endTime;
            public int calories = -1;
            public int distance = -1;
            public int stepCount = -1;
            public int totalTime = -1;
            public int duration = -1;
            public byte type = -1; // TODO: enum?
            public short strokes = -1;
            public short avgStrokeRate = -1;
            public short poolLength = -1; // In cm
            public short laps = -1;
            public short avgSwolf = -1;
 
            public Integer maxAltitude = null;
            public Integer minAltitude = null;
            public Integer elevationGain = null;
            public Integer elevationLoss = null;
 
            public int workoutLoad = 0;
            public int workoutAerobicEffect = 0;
            public byte workoutAnaerobicEffect = -1;
            public short recoveryTime = 0;
 
            public byte minHeartRatePeak = 0;
            public byte maxHeartRatePeak = 0;
 
            public byte[] recoveryHeartRates = null;
 
            public byte swimType = -1;
 
            public int maxMET = 0;
 
            public byte hrZoneType = -1;
 
            public short runPaceZone1Min = -1;
            public short runPaceZone2Min = -1;
            public short runPaceZone3Min = -1;
            public short runPaceZone4Min = -1;
            public short runPaceZone5Min = -1;
            public short runPaceZone5Max = -1;
 
            public short runPaceZone1Time = -1;
            public short runPaceZone2Time = -1;
            public short runPaceZone3Time = -1;
            public short runPaceZone4Time = -1;
            public short runPaceZone5Time = -1;
 
            public byte algType = 0;
 
            public int trainingPoints = -1;
 
            public Response(ParamsProvider paramsProvider) {
                super(paramsProvider);
            }
 
            @Override
            public void parseTlv() throws ParseException {
                HuaweiTLV container = this.tlv.getObject(0x81);
 
                this.rawData = container.serialize();
                this.number = container.getShort(0x02);
                if (container.contains(0x03))
                    this.status = container.getByte(0x03);
                this.startTime = container.getInteger(0x04);
                this.endTime = container.getInteger(0x05);
 
                if (container.contains(0x06))
                    this.calories = container.getInteger(0x06);
                if (container.contains(0x07))
                    this.distance = container.getInteger(0x07);
                if (container.contains(0x08))
                    this.stepCount = container.getInteger(0x08);
                if (container.contains(0x09))
                    this.totalTime = container.getInteger(0x09);
                if (container.contains(0x0b))
                    this.elevationGain = container.getInteger(0x0b);
                if (container.contains(0x0c)) {
                    byte[] hrData = container.getBytes(0x0c);
                    minHeartRatePeak = hrData[0];
                    maxHeartRatePeak = hrData[1];
                }
                if (container.contains(0x0d))
                    this.workoutLoad = container.getInteger(0x0d);
                if (container.contains(0x0e))
                    this.workoutAerobicEffect = container.getInteger(0x0e);
                if (container.contains(0x10))
                    this.maxMET = container.getInteger(0x10);
                if (container.contains(0x11))
                    this.recoveryTime = container.getShort(0x11);
                if (container.contains(0x12))
                    this.duration = container.getInteger(0x12);
                if (container.contains(0x14))
                    this.type = container.getByte(0x14);
                if (container.contains(0x15))
                    this.swimType = container.getByte(0x15);
                if (container.contains(0x16))
                    this.strokes = container.getShort(0x16);
                if (container.contains(0x17))
                    this.avgStrokeRate = container.getShort(0x17);
                if (container.contains(0x18))
                    this.poolLength = container.getShort(0x18);
                if (container.contains(0x19))
                    this.laps = container.getShort(0x19);
                if (container.contains(0x1a))
                    this.avgSwolf = container.getShort(0x1a);
                if (container.contains(0x1b))
                    this.elevationLoss = container.getInteger(0x1b);
                if (container.contains(0x1c))
                    this.maxAltitude = container.getInteger(0x1c);
                if (container.contains(0x1d))
                    this.minAltitude = container.getInteger(0x1d);
                if (container.contains(0x20))
                    this.workoutAnaerobicEffect = container.getByte(0x20);
                if (container.contains(0x24))
                    this.hrZoneType = container.getByte(0x24);
                if (container.contains(0x50))
                    this.runPaceZone1Min = container.getShort(0x50);
                if (container.contains(0x51))
                    this.runPaceZone2Min = container.getShort(0x51);
                if (container.contains(0x52))
                    this.runPaceZone3Min = container.getShort(0x52);
                if (container.contains(0x53))
                    this.runPaceZone4Min = container.getShort(0x53);
                if (container.contains(0x54))
                    this.runPaceZone5Min = container.getShort(0x54);
                if (container.contains(0x55))
                    this.runPaceZone5Max = container.getShort(0x55);
                if (container.contains(0x56))
                    this.runPaceZone1Time = container.getShort(0x56);
                if (container.contains(0x57))
                    this.runPaceZone2Time = container.getShort(0x57);
                if (container.contains(0x58))
                    this.runPaceZone3Time = container.getShort(0x58);
                if (container.contains(0x59))
                    this.runPaceZone4Time = container.getShort(0x59);
                if (container.contains(0x5a))
                    this.runPaceZone5Time = container.getShort(0x5a);
                if (container.contains(0x5d))
                    this.algType = container.getByte(0x5d);
                if (container.contains(0x63))
                    this.trainingPoints = container.getShort(0x63);
                if (container.contains(0x66))
                    this.recoveryHeartRates = container.getBytes(0x66);
            }
        }
    }
 
    public static class WorkoutData {
        public static final int id = 0x0a;
 
        public static class Request extends HuaweiPacket {
 
            public Request(
                    ParamsProvider paramsProvider,
                    short workoutNumber,
                    short dataNumber
            ) {
                super(paramsProvider);
 
                this.serviceId = Workout.id;
                this.commandId = id;
 
                this.tlv = new HuaweiTLV().put(0x81, new HuaweiTLV()
                        .put(0x02, workoutNumber)
                        .put(0x03, dataNumber)
                );
 
                this.complete = true;
            }
        }
 
        public static class Response extends HuaweiPacket {
            public static class Header {
                public short workoutNumber;
                public short dataNumber;
                public int timestamp;
                public byte interval;
                public short dataCount;
                public byte dataLength;
                public short bitmap; // TODO: can this be enum-like?
 
                @Override
                public String toString() {
                    return "Header{" +
                            "workoutNumber=" + workoutNumber +
                            ", dataNumber=" + dataNumber +
                            ", timestamp=" + timestamp +
                            ", interval=" + interval +
                            ", dataCount=" + dataCount +
                            ", dataLength=" + dataLength +
                            ", bitmap=" + bitmap +
                            '}';
                }
            }
 
            public static class Data {
                // If unknown data is encountered, the whole tlv will be in here so it can be parsed again later
                public byte[] unknownData = null;
 
                public byte heartRate = -1;
                public short speed = -1;
                public byte stepRate = -1;
 
                public short cadence = -1;
                public short stepLength = -1;
                public short groundContactTime = -1;
                public byte impact = -1;
                public short swingAngle = -1;
                public byte foreFootLanding = -1;
                public byte midFootLanding = -1;
                public byte backFootLanding = -1;
                public byte eversionAngle = -1;
 
                public short swolf = -1;
                public short strokeRate = -1;
 
                public short calories = -1;
                public short cyclingPower = -1;
                public short frequency = -1;
                public Integer altitude = null;
 
                public int timestamp = -1; // Calculated timestamp for this data point
 
                @Override
                public String toString() {
                    return "Data{" +
                            "unknownData=" + Arrays.toString(unknownData) +
                            ", heartRate=" + heartRate +
                            ", speed=" + speed +
                            ", stepRate=" + stepRate +
                            ", cadence=" + cadence +
                            ", stepLength=" + stepLength +
                            ", groundContactTime=" + groundContactTime +
                            ", impact=" + impact +
                            ", swingAngle=" + swingAngle +
                            ", foreFootLanding=" + foreFootLanding +
                            ", midFootLanding=" + midFootLanding +
                            ", backFootLanding=" + backFootLanding +
                            ", eversionAngle=" + eversionAngle +
                            ", swolf=" + swolf +
                            ", strokeRate=" + strokeRate +
                            ", calories=" + calories +
                            ", cyclingPower=" + cyclingPower +
                            ", frequency=" + frequency +
                            ", altitude=" + altitude +
                            ", timestamp=" + timestamp +
                            '}';
                }
            }
 
            private final byte[] bitmapLengths = {1, 2, 1, 2, 2, 4, -1, 2, 2, 2};
            private final byte[] innerBitmapLengths = {2, 2, 2, 1, 2, 1, 1, 1, 1, 2, 2, 1, 2, 2, 2, 2, 1, 1, 1, 2};
 
            public short workoutNumber;
            public short dataNumber;
            public byte[] rawHeader;
            public byte[] rawData;
            public short innerBitmap;
 
            public Header header;
            public List<Data> dataList;
 
            public Response(ParamsProvider paramsProvider) {
                super(paramsProvider);
            }
 
            /**
             * This is to be able to easily reparse the error data, only accepts tlv bytes
             *
             * @param rawData The TLV bytes
             */
            public Response(byte[] rawData) throws ParseException {
                super(null);
                this.tlv = new HuaweiTLV().parse(rawData);
                this.parseTlv();
            }
 
            @Override
            public void parseTlv() throws ParseException {
                HuaweiTLV container = this.tlv.getObject(0x81);
 
                this.workoutNumber = container.getShort(0x02);
                this.dataNumber = container.getShort(0x03);
                this.rawHeader = container.getBytes(0x04);
                this.rawData = container.getBytes(0x05); // TODO: not sure if 5 can also be omitted
 
                if (container.contains(0x09))
                    innerBitmap = container.getShort(0x09);
                else
                    innerBitmap = 0x01FF; // This seems to be the default
 
                int innerDataLength = 0;
                for (byte i = 0; i < innerBitmapLengths.length; i++) {
                    if ((innerBitmap & (1 << i)) != 0) {
                        innerDataLength += innerBitmapLengths[i];
                    }
                }
 
                if (this.rawHeader.length != 14)
                    throw new LengthMismatchException("Workout data header length mismatch.");
 
                this.header = new Header();
                ByteBuffer buf = ByteBuffer.wrap(this.rawHeader);
                header.workoutNumber = buf.getShort();
                header.dataNumber = buf.getShort();
                header.timestamp = buf.getInt();
                header.interval = buf.get();
                header.dataCount = buf.getShort();
                header.dataLength = buf.get();
                header.bitmap = buf.getShort();
 
                // Check data lengths from header
                if (this.header.dataCount * this.header.dataLength != this.rawData.length)
                    throw new LengthMismatchException("Workout data length mismatch with header.");
 
                // Check data lengths from bitmap
                int dataLength = 0;
                for (byte i = 0; i < bitmapLengths.length; i++) {
                    if ((header.bitmap & (1 << i)) != 0) {
                        if (i == 6) {
                            dataLength += innerDataLength;
                        } else {
                            dataLength += bitmapLengths[i];
                        }
                    }
                }
                dataLength = dataLength * header.dataCount;
                if (dataLength != this.rawData.length)
                    throw new LengthMismatchException("Workout data length mismatch with bitmap.");
 
                this.dataList = new ArrayList<>();
                buf = ByteBuffer.wrap(this.rawData);
                for (short i = 0; i < header.dataCount; i++) {
                    Data data = new Data();
                    data.timestamp = header.timestamp + header.interval * i;
                    for (byte j = 0; j < bitmapLengths.length; j++) {
                        if ((header.bitmap & (1 << j)) != 0) {
                            switch (j) {
                                case 0:
                                    data.heartRate = buf.get();
                                    break;
                                case 1:
                                    data.speed = buf.getShort();
                                    break;
                                case 2:
                                    data.stepRate = buf.get();
                                    break;
                                case 3:
                                    data.swolf = buf.getShort();
                                    break;
                                case 4:
                                    data.strokeRate = buf.getShort();
                                    break;
                                case 5:
                                    data.altitude = buf.getInt();
                                    break;
                                case 6:
                                    // Inner data, parsing into data
                                    // TODO: function for readability?
                                    for (byte k = 0; k < innerBitmapLengths.length; k++) {
                                        if ((innerBitmap & (1 << k)) != 0) {
                                            switch (k) {
                                                case 0:
                                                    data.cadence = buf.getShort();
                                                    break;
                                                case 1:
                                                    data.stepLength = buf.getShort();
                                                    break;
                                                case 2:
                                                    data.groundContactTime = buf.getShort();
                                                    break;
                                                case 3:
                                                    data.impact = buf.get();
                                                    break;
                                                case 4:
                                                    data.swingAngle = buf.getShort();
                                                    break;
                                                case 5:
                                                    data.foreFootLanding = buf.get();
                                                    break;
                                                case 6:
                                                    data.midFootLanding = buf.get();
                                                    break;
                                                case 7:
                                                    data.backFootLanding = buf.get();
                                                    break;
                                                case 8:
                                                    data.eversionAngle = buf.get();
                                                    break;
                                                default:
                                                    data.unknownData = this.tlv.serialize();
                                                    // Fix alignment
                                                    for (int l = 0; l < innerBitmapLengths[k]; l++)
                                                        buf.get();
                                                    break;
                                            }
                                        }
                                    }
                                    break;
                                case 7:
                                    data.calories = buf.getShort();
                                    break;
                                case 8:
                                    data.frequency = buf.getShort();
                                    break;
                                case 9:
                                    data.cyclingPower = buf.getShort();
                                    break;
                                default:
                                    data.unknownData = this.tlv.serialize();
                                    // Fix alignment
                                    for (int k = 0; k < bitmapLengths[j]; k++)
                                        buf.get();
                                    break;
                            }
                        }
                    }
                    this.dataList.add(data);
                }
            }
        }
    }
 
    public static class WorkoutPace {
        public static final int id = 0x0c;
 
        public static class Request extends HuaweiPacket {
 
            public Request(
                    ParamsProvider paramsProvider,
                    short workoutNumber,
                    short paceNumber
            ) {
                super(paramsProvider);
 
                this.serviceId = Workout.id;
                this.commandId = id;
 
                this.tlv = new HuaweiTLV().put(0x81, new HuaweiTLV()
                        .put(0x02, workoutNumber)
                        .put(0x08, paceNumber)
                );
 
                this.complete = true;
            }
        }
 
        public static class Response extends HuaweiPacket {
            public static class Block {
                public short distance = -1;
                public byte type = -1;
                public int pace = -1;
                public short pointIndex = 0;
                public short correction = 0;
                public boolean hasCorrection = false;
 
                @Override
                public String toString() {
                    return "Block{" +
                            "distance=" + distance +
                            ", type=" + type +
                            ", pace=" + pace +
                            ", pointIndex=" + pointIndex +
                            ", correction=" + correction +
                            ", hasCorrection=" + hasCorrection +
                            '}';
                }
            }
 
            public short workoutNumber;
            public short paceNumber;
            public List<Block> blocks;
 
            public Response(ParamsProvider paramsProvider) {
                super(paramsProvider);
            }
 
            @Override
            public void parseTlv() throws ParseException {
                HuaweiTLV container = this.tlv.getObject(0x81);
 
                this.workoutNumber = container.getShort(0x02);
                this.paceNumber = container.getShort(0x08);
 
                this.blocks = new ArrayList<>();
                for (HuaweiTLV blockTlv : container.getObjects(0x83)) {
                    Block block = new Block();
                    block.distance = blockTlv.getShort(0x04);
                    block.type = blockTlv.getByte(0x05);
                    block.pace = blockTlv.getInteger(0x06);
                    if (blockTlv.contains(0x07))
                        block.pointIndex = blockTlv.getShort(0x07);
                    if (blockTlv.contains(0x09)) {
                        block.hasCorrection = true;
                        block.correction = blockTlv.getShort(0x09);
                    }
                    blocks.add(block);
                }
            }
        }
    }
 
    public static class WorkoutSwimSegments {
        public static final int id = 0x0e;
 
        public static class Request extends HuaweiPacket {
 
            public Request(
                    ParamsProvider paramsProvider,
                    short workoutNumber,
                    short segmentNumber
            ) {
                super(paramsProvider);
 
                this.serviceId = Workout.id;
                this.commandId = id;
 
                this.tlv = new HuaweiTLV().put(0x81, new HuaweiTLV()
                        .put(0x02, workoutNumber)
                        .put(0x08, segmentNumber)
                );
 
                this.complete = true;
            }
        }
 
        public static class Response extends HuaweiPacket {
            public static class Block {
                public short distance = -1;
                public byte type = -1;
                public int pace = -1;
                public short pointIndex = 0;
                public short segment = -1;
                public byte swimType= -1;
                public short strokes = -1;
                public short avgSwolf = -1;
                public int time= -1;
 
                @Override
                public String toString() {
                    final StringBuffer sb = new StringBuffer("Block{");
                    sb.append("distance=").append(distance);
                    sb.append(", type=").append(type);
                    sb.append(", pace=").append(pace);
                    sb.append(", pointIndex=").append(pointIndex);
                    sb.append(", segment=").append(segment);
                    sb.append(", swimType=").append(swimType);
                    sb.append(", strokes=").append(strokes);
                    sb.append(", awgSwolf=").append(avgSwolf);
                    sb.append(", time=").append(time);
                    sb.append('}');
                    return sb.toString();
                }
            }
 
            public short workoutNumber;
            public short segmentNumber;
            public List<Block> blocks;
 
            public Response(ParamsProvider paramsProvider) {
                super(paramsProvider);
            }
 
            @Override
            public void parseTlv() throws ParseException {
                HuaweiTLV container = this.tlv.getObject(0x81);
 
                this.workoutNumber = container.getShort(0x02);
                this.segmentNumber = container.getShort(0x08);
 
                this.blocks = new ArrayList<>();
                for (HuaweiTLV blockTlv : container.getObjects(0x83)) {
                    Block block = new Block();
 
                    block.distance = blockTlv.getShort(0x04);
                    block.type = blockTlv.getByte(0x05);
                    block.pace = blockTlv.getInteger(0x06);
                    if (blockTlv.contains(0x07))
                        block.pointIndex = blockTlv.getShort(0x07);
                    if (blockTlv.contains(0x09))
                        block.segment = blockTlv.getShort(0x09);
                    if (blockTlv.contains(0x0a))
                        block.swimType= blockTlv.getByte(0x0a);
                    if (blockTlv.contains(0x0b))
                        block.strokes = blockTlv.getShort(0x0b);
                    if (blockTlv.contains(0x0c))
                        block.avgSwolf = blockTlv.getShort(0x0c);
                    if (blockTlv.contains(0x0d))
                        block.time= blockTlv.getInteger(0x0d);
 
                    blocks.add(block);
                }
            }
        }
    }
 
    public static class NotifyHeartRate {
        public static final int id = 0x17;
 
        public static class Request extends HuaweiPacket {
            public Request(ParamsProvider paramsProvider) {
                super(paramsProvider);
 
                this.serviceId = Workout.id;
                this.commandId = id;
 
                this.tlv = new HuaweiTLV().put(0x01, 0x03);
 
                this.complete = true;
            }
        }
 
    }
}