GetSceneNotificationParser.java
1.33 KB
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
/*
* Copyright (C) 2015 The Telink Bluetooth Light Project
*
*/
package com.telink.bluetooth.light;
public final class GetSceneNotificationParser extends NotificationParser<GetSceneNotificationParser.SceneInfo> {
private GetSceneNotificationParser() {
}
public static GetSceneNotificationParser create() {
return new GetSceneNotificationParser();
}
@Override
public byte opcode() {
return Opcode.BLE_GATT_OP_CTRL_C1.getValue();
}
@Override
public SceneInfo parse(NotificationInfo notifyInfo) {
byte[] params = notifyInfo.params;
int offset = 8;
int total = params[offset];
if (total == 0)
return null;
offset = 0;
int index = params[offset++] & 0xFF;
int lum = params[offset++] & 0xFF;
int r = params[offset++] & 0xFF;
int g = params[offset++] & 0xFF;
int b = params[offset] & 0xFF;
SceneInfo sceneInfo = new SceneInfo();
sceneInfo.index = index;
sceneInfo.total = total;
sceneInfo.lum = lum;
sceneInfo.rgb = (r << 16) + (g << 8) + b;
return sceneInfo;
}
public final class SceneInfo {
public int index;
public int total;
public int lum;
public int rgb;
}
}