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
package nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets;
 
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiTLV;
 
public class P2P {
    public static final byte id = 0x34;
 
    public static class P2PCommand {
        public static final byte id = 0x01;
 
        public static class Request extends HuaweiPacket {
 
 
            public Request(ParamsProvider paramsProvider,
                           byte cmdId,
                           short sequenceId,
                           String srcPackage,
                           String dstPackage,
                           String srcFingerprint,
                           String dstFingerprint,
                           byte[] sendData,
                           int sendCode) {
                super(paramsProvider);
                this.serviceId = P2P.id;
                this.commandId = id;
 
                this.tlv = new HuaweiTLV()
                           .put(0x01, cmdId)
                        .put(0x02, sequenceId)
                        .put(0x03, srcPackage)
                        .put(0x04, dstPackage);
                if(cmdId == 0x2) {
                    this.tlv.put(0x05, srcFingerprint);
                    this.tlv.put(0x06, dstFingerprint);
                }
                if(sendData != null && sendData.length > 0)
                    this.tlv.put(0x07, sendData);
                if(cmdId == 0x3) {
                    this.tlv.put(0x08, sendCode);
                }
            }
        }
 
        public static class Response extends HuaweiPacket {
            public byte cmdId;
            public short sequenceId;
            public String srcPackage;
            public String dstPackage;
            public String srcFingerprint = null;
            public String dstFingerprint = null;
            public byte[] respData = null;
            public int respCode = 0;
            public Response (ParamsProvider paramsProvider) {
                super(paramsProvider);
            }
 
            @Override
            public void parseTlv() throws HuaweiPacket.ParseException {
                cmdId = this.tlv.getByte(0x01);
                sequenceId = this.tlv.getShort(0x02);
                srcPackage = this.tlv.getString(0x03);
                dstPackage = this.tlv.getString(0x04);
                if(this.tlv.contains(0x05))
                    srcFingerprint = this.tlv.getString(0x05);
                if(this.tlv.contains(0x06))
                    dstFingerprint = this.tlv.getString(0x06);
                if(this.tlv.contains(0x07))
                    respData = this.tlv.getBytes(0x07);
                // NOTE: P2P service uses different data types in responseCode(TLV 0x08).
                // It sends byte from wearable but send integer to wearable
                // So we have a change that other device can send different type.
                if(this.tlv.contains(0x08))
                    respCode = this.tlv.getByte(0x08);
            }
 
        }
    }
 
}